gleffects: properly initialize the shaders across contexts implementing multiple API's

This commit is contained in:
Matthew Waters 2015-05-26 12:47:40 +10:00
parent cb482f13be
commit db9e0cf5c7

View file

@ -534,17 +534,15 @@ gst_gl_effects_get_fragment_shader (GstGLEffects * effects,
const gchar * shader_name, const gchar * shader_source_gles2, const gchar * shader_name, const gchar * shader_source_gles2,
const gchar * shader_source_opengl) const gchar * shader_source_opengl)
{ {
GstGLShader *shader; GstGLShader *shader = NULL;
GstGLFilter *filter = GST_GL_FILTER (effects); GstGLFilter *filter = GST_GL_FILTER (effects);
GstGLContext *context = GST_GL_BASE_FILTER (filter)->context; GstGLContext *context = GST_GL_BASE_FILTER (filter)->context;
shader = g_hash_table_lookup (effects->shaderstable, shader_name); shader = g_hash_table_lookup (effects->shaderstable, shader_name);
if (!shader) { if (!shader) {
shader = gst_gl_shader_new (context); if (!shader && (USING_GLES2 (context) || USING_OPENGL3 (context))) {
g_hash_table_insert (effects->shaderstable, (gchar *) shader_name, shader); shader = gst_gl_shader_new (context);
if (USING_GLES2 (context) || USING_OPENGL3 (context)) {
if (!gst_gl_shader_compile_with_default_v_and_check (shader, if (!gst_gl_shader_compile_with_default_v_and_check (shader,
shader_source_gles2, &filter->draw_attr_position_loc, shader_source_gles2, &filter->draw_attr_position_loc,
&filter->draw_attr_texture_loc)) { &filter->draw_attr_texture_loc)) {
@ -552,21 +550,29 @@ gst_gl_effects_get_fragment_shader (GstGLEffects * effects,
GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND, GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND,
("Failed to initialize %s shader, %s", ("Failed to initialize %s shader, %s",
shader_name, gst_gl_context_get_error ()), (NULL)); shader_name, gst_gl_context_get_error ()), (NULL));
return NULL; gst_object_unref (shader);
shader = NULL;
} }
} }
#if GST_GL_HAVE_OPENGL #if GST_GL_HAVE_OPENGL
if (USING_OPENGL (context)) { if (!shader && USING_OPENGL (context)) {
shader = gst_gl_shader_new (context);
if (!gst_gl_shader_compile_and_check (shader, if (!gst_gl_shader_compile_and_check (shader,
shader_source_opengl, GST_GL_SHADER_FRAGMENT_SOURCE)) { shader_source_opengl, GST_GL_SHADER_FRAGMENT_SOURCE)) {
gst_gl_context_set_error (context, "Failed to initialize %s shader", gst_gl_context_set_error (context, "Failed to initialize %s shader",
shader_name); shader_name);
GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND, ("%s", GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND, ("%s",
gst_gl_context_get_error ()), (NULL)); gst_gl_context_get_error ()), (NULL));
return NULL; gst_object_unref (shader);
shader = NULL;
} }
} }
#endif #endif
if (!shader)
return NULL;
g_hash_table_insert (effects->shaderstable, (gchar *) shader_name, shader);
} }
return shader; return shader;