diff --git a/gst-libs/gst/gl/gstglfilter.c b/gst-libs/gst/gl/gstglfilter.c index 2c518e3143..1e18e410ee 100644 --- a/gst-libs/gst/gl/gstglfilter.c +++ b/gst-libs/gst/gl/gstglfilter.c @@ -1031,6 +1031,28 @@ gst_gl_filter_render_to_target (GstGLFilter * filter, gboolean resize, filter->fbo, filter->depthbuffer, target, _glcb2, &cb); } +static void +_get_attributes (GstGLFilter * filter) +{ + if (!filter->default_shader) + return; + + if (filter->valid_attributes) + return; + + if (filter->draw_attr_position_loc == -1) + filter->draw_attr_position_loc = + gst_gl_shader_get_attribute_location (filter->default_shader, + "a_position"); + + if (filter->draw_attr_texture_loc == -1) + filter->draw_attr_texture_loc = + gst_gl_shader_get_attribute_location (filter->default_shader, + "a_texcoord"); + + filter->valid_attributes = TRUE; +} + static void _draw_with_shader_cb (gint width, gint height, guint texture, gpointer stuff) { @@ -1045,6 +1067,7 @@ _draw_with_shader_cb (gint width, gint height, guint texture, gpointer stuff) } #endif + _get_attributes (filter); gst_gl_shader_use (filter->default_shader); gl->ActiveTexture (GL_TEXTURE1); @@ -1057,23 +1080,6 @@ _draw_with_shader_cb (gint width, gint height, guint texture, gpointer stuff) gst_gl_filter_draw_texture (filter, texture, width, height); } -static void -_get_attributes (GstGLFilter * filter) -{ - if (!filter->default_shader) - return; - - if (filter->draw_attr_position_loc == -1) - filter->draw_attr_position_loc = - gst_gl_shader_get_attribute_location (filter->default_shader, - "a_position"); - - if (filter->draw_attr_texture_loc == -1) - filter->draw_attr_texture_loc = - gst_gl_shader_get_attribute_location (filter->default_shader, - "a_texcoord"); -} - /** * gst_gl_filter_render_to_target_with_shader: * @filter: a #GstGLFilter @@ -1094,8 +1100,9 @@ void gst_gl_filter_render_to_target_with_shader (GstGLFilter * filter, gboolean resize, GLuint input, GLuint target, GstGLShader * shader) { + if (filter->default_shader != shader) + filter->valid_attributes = FALSE; filter->default_shader = shader; - _get_attributes (filter); gst_gl_filter_render_to_target (filter, resize, input, target, _draw_with_shader_cb, filter); diff --git a/gst-libs/gst/gl/gstglfilter.h b/gst-libs/gst/gl/gstglfilter.h index 94ab333945..a818bab24f 100644 --- a/gst-libs/gst/gl/gstglfilter.h +++ b/gst-libs/gst/gl/gstglfilter.h @@ -71,6 +71,7 @@ struct _GstGLFilter GLuint out_tex_id; GstGLShader *default_shader; + gboolean valid_attributes; GLuint vao; GLuint vbo_indices;