From 0c1a77ca6cd8add4b0c855cc6a4c33f1f13a0561 Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Thu, 30 Jan 2014 07:49:20 +1100 Subject: [PATCH] [874/906] filter: implement draw_texture for GLES2 (taken from gleffects) --- gst-libs/gst/gl/gstglfilter.c | 99 ++++++++++++++++--------- gst-libs/gst/gl/gstglfilter.h | 7 +- gst/gl/effects/gstgleffectbulge.c | 5 +- gst/gl/effects/gstgleffectfisheye.c | 5 +- gst/gl/effects/gstgleffectglow.c | 20 +++-- gst/gl/effects/gstgleffectidentity.c | 6 +- gst/gl/effects/gstgleffectlumatocurve.c | 5 +- gst/gl/effects/gstgleffectmirror.c | 6 +- gst/gl/effects/gstgleffectrgbtocurve.c | 5 +- gst/gl/effects/gstgleffectsin.c | 5 +- gst/gl/effects/gstgleffectsquare.c | 5 +- gst/gl/effects/gstgleffectsqueeze.c | 6 +- gst/gl/effects/gstgleffectstretch.c | 5 +- gst/gl/effects/gstgleffecttunnel.c | 5 +- gst/gl/effects/gstgleffecttwirl.c | 5 +- gst/gl/effects/gstgleffectxray.c | 35 +++++---- gst/gl/gstgleffects.c | 69 ----------------- gst/gl/gstgleffects.h | 7 -- 18 files changed, 139 insertions(+), 161 deletions(-) diff --git a/gst-libs/gst/gl/gstglfilter.c b/gst-libs/gst/gl/gstglfilter.c index 40862dcd43..d6a0b9d67d 100644 --- a/gst-libs/gst/gl/gstglfilter.c +++ b/gst-libs/gst/gl/gstglfilter.c @@ -1089,8 +1089,8 @@ gst_gl_filter_render_to_target (GstGLFilter * filter, gboolean resize, in_height = out_height; } - GST_LOG ("rendering to target. in:%ux%u out:%ux%u", in_width, in_height, - out_width, out_height); + GST_LOG ("rendering to target. in %u, %ux%u out %u, %ux%u", input, in_width, + in_height, target, out_width, out_height); gst_gl_context_use_fbo (filter->context, out_width, out_height, @@ -1099,22 +1099,23 @@ gst_gl_filter_render_to_target (GstGLFilter * filter, gboolean resize, in_width, 0, in_height, GST_GL_DISPLAY_PROJECTION_ORTHO2D, data); } -#if GST_GL_HAVE_OPENGL static void _draw_with_shader_cb (gint width, gint height, guint texture, gpointer stuff) { GstGLFilter *filter = GST_GL_FILTER (stuff); GstGLFuncs *gl = filter->context->gl_vtable; - gl->MatrixMode (GL_PROJECTION); - gl->LoadIdentity (); +#if GST_GL_HAVE_OPENGL + if (gst_gl_context_get_gl_api (filter->context) & GST_GL_API_OPENGL) { + gl->MatrixMode (GL_PROJECTION); + gl->LoadIdentity (); + } +#endif gst_gl_shader_use (filter->default_shader); gl->ActiveTexture (GL_TEXTURE1); - gl->Enable (GL_TEXTURE_2D); gl->BindTexture (GL_TEXTURE_2D, texture); - gl->Disable (GL_TEXTURE_2D); gst_gl_shader_set_uniform_1i (filter->default_shader, "tex", 1); gst_gl_shader_set_uniform_1f (filter->default_shader, "width", width); @@ -1143,9 +1144,6 @@ void gst_gl_filter_render_to_target_with_shader (GstGLFilter * filter, gboolean resize, GLuint input, GLuint target, GstGLShader * shader) { - g_return_if_fail (gst_gl_context_get_gl_api (filter->context) & - GST_GL_API_OPENGL); - filter->default_shader = shader; gst_gl_filter_render_to_target (filter, resize, input, target, _draw_with_shader_cb, filter); @@ -1164,36 +1162,69 @@ void gst_gl_filter_draw_texture (GstGLFilter * filter, GLuint texture, guint width, guint height) { - GstGLFuncs *gl = filter->context->gl_vtable; - - GLfloat verts[] = { -1.0f, -1.0f, - 1.0f, -1.0f, - 1.0f, 1.0f, - -1.0f, 1.0f - }; - GLfloat texcoords[] = { 0.0f, 0.0f, - 1.0f, 0.0f, - 1.0f, 1.0f, - 0.0f, 1.0f - }; + GstGLContext *context = filter->context; + GstGLFuncs *gl = context->gl_vtable; GST_DEBUG ("drawing texture:%u dimensions:%ux%u", texture, width, height); - gl->ActiveTexture (GL_TEXTURE0); - gl->Enable (GL_TEXTURE_2D); - gl->BindTexture (GL_TEXTURE_2D, texture); +#if GST_GL_HAVE_OPENGL + if (gst_gl_context_get_gl_api (context) & GST_GL_API_OPENGL) { + GLfloat verts[] = { -1.0f, -1.0f, + 1.0f, -1.0f, + 1.0f, 1.0f, + -1.0f, 1.0f + }; + GLfloat texcoords[] = { 0.0f, 0.0f, + 1.0f, 0.0f, + 1.0f, 1.0f, + 0.0f, 1.0f + }; - gl->ClientActiveTexture (GL_TEXTURE0); + gl->ActiveTexture (GL_TEXTURE0); - gl->EnableClientState (GL_VERTEX_ARRAY); - gl->EnableClientState (GL_TEXTURE_COORD_ARRAY); + gl->Enable (GL_TEXTURE_2D); + gl->BindTexture (GL_TEXTURE_2D, texture); - gl->VertexPointer (2, GL_FLOAT, 0, &verts); - gl->TexCoordPointer (2, GL_FLOAT, 0, &texcoords); + gl->ClientActiveTexture (GL_TEXTURE0); - gl->DrawArrays (GL_TRIANGLE_FAN, 0, 4); + gl->EnableClientState (GL_VERTEX_ARRAY); + gl->EnableClientState (GL_TEXTURE_COORD_ARRAY); - gl->DisableClientState (GL_VERTEX_ARRAY); - gl->DisableClientState (GL_TEXTURE_COORD_ARRAY); + gl->VertexPointer (2, GL_FLOAT, 0, &verts); + gl->TexCoordPointer (2, GL_FLOAT, 0, &texcoords); + + gl->DrawArrays (GL_TRIANGLE_FAN, 0, 4); + + gl->DisableClientState (GL_VERTEX_ARRAY); + gl->DisableClientState (GL_TEXTURE_COORD_ARRAY); + } +#endif +#if GST_GL_HAVE_GLES2 + if (gst_gl_context_get_gl_api (context) & GST_GL_API_GLES2) { + const GLfloat vVertices[] = { + -1.0f, -1.0f, 0.0f, + 0.0f, 0.0f, + 1.0, -1.0f, 0.0f, + 1.0f, 0.0f, + 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f + }; + + GLushort indices[] = { 0, 1, 2, 0, 2, 3 }; + + /* glClear (GL_COLOR_BUFFER_BIT); */ + + /* Load the vertex position */ + gl->VertexAttribPointer (filter->draw_attr_position_loc, 3, GL_FLOAT, + GL_FALSE, 5 * sizeof (GLfloat), vVertices); + + /* Load the texture coordinate */ + gl->VertexAttribPointer (filter->draw_attr_texture_loc, 2, GL_FLOAT, + GL_FALSE, 5 * sizeof (GLfloat), &vVertices[3]); + + gl->EnableVertexAttribArray (filter->draw_attr_position_loc); + gl->EnableVertexAttribArray (filter->draw_attr_texture_loc); + + gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices); + } +#endif } -#endif /* GST_GL_HAVE_OPENGL */ diff --git a/gst-libs/gst/gl/gstglfilter.h b/gst-libs/gst/gl/gstglfilter.h index e5dec42bdd..6e7702279e 100644 --- a/gst-libs/gst/gl/gstglfilter.h +++ b/gst-libs/gst/gl/gstglfilter.h @@ -82,6 +82,11 @@ struct _GstGLFilter GstGLContext *context; GstGLContext *other_context; + +#if GST_GL_HAVE_GLES2 + GLint draw_attr_position_loc; + GLint draw_attr_texture_loc; +#endif }; /** @@ -125,12 +130,10 @@ gboolean gst_gl_filter_filter_texture (GstGLFilter * filter, GstBuffer * inbuf, void gst_gl_filter_render_to_target (GstGLFilter *filter, gboolean resize, GLuint input, GLuint target, GLCB func, gpointer data); -#if GST_GL_HAVE_OPENGL void gst_gl_filter_render_to_target_with_shader (GstGLFilter * filter, gboolean resize, GLuint input, GLuint target, GstGLShader *shader); void gst_gl_filter_draw_texture (GstGLFilter *filter, GLuint texture, guint width, guint height); -#endif /* GST_GL_HAVE_OPENGL */ G_END_DECLS diff --git a/gst/gl/effects/gstgleffectbulge.c b/gst/gl/effects/gstgleffectbulge.c index b27ce994a7..b0c1b4170e 100644 --- a/gst/gl/effects/gstgleffectbulge.c +++ b/gst/gl/effects/gstgleffectbulge.c @@ -29,7 +29,8 @@ gst_gl_effects_bulge_callback (gint width, gint height, guint texture, { GstGLShader *shader; GstGLEffects *effects = GST_GL_EFFECTS (data); - GstGLContext *context = GST_GL_FILTER (effects)->context; + GstGLFilter *filter = GST_GL_FILTER (effects); + GstGLContext *context = filter->context; GstGLFuncs *gl = context->gl_vtable; shader = g_hash_table_lookup (effects->shaderstable, "bulge0"); @@ -61,7 +62,7 @@ gst_gl_effects_bulge_callback (gint width, gint height, guint texture, gst_gl_shader_set_uniform_1f (shader, "width", (gfloat) width / 2.0f); gst_gl_shader_set_uniform_1f (shader, "height", (gfloat) height / 2.0f); - gst_gl_effects_draw_texture (effects, texture, width, height); + gst_gl_filter_draw_texture (filter, texture, width, height); } void diff --git a/gst/gl/effects/gstgleffectfisheye.c b/gst/gl/effects/gstgleffectfisheye.c index 5ec6695742..4ee6416e96 100644 --- a/gst/gl/effects/gstgleffectfisheye.c +++ b/gst/gl/effects/gstgleffectfisheye.c @@ -29,7 +29,8 @@ gst_gl_effects_fisheye_callback (gint width, gint height, guint texture, { GstGLShader *shader; GstGLEffects *effects = GST_GL_EFFECTS (data); - GstGLContext *context = GST_GL_FILTER (effects)->context; + GstGLFilter *filter = GST_GL_FILTER (effects); + GstGLContext *context = filter->context; GstGLFuncs *gl = context->gl_vtable; shader = g_hash_table_lookup (effects->shaderstable, "fisheye0"); @@ -61,7 +62,7 @@ gst_gl_effects_fisheye_callback (gint width, gint height, guint texture, gst_gl_shader_set_uniform_1f (shader, "width", (gfloat) width / 2.0f); gst_gl_shader_set_uniform_1f (shader, "height", (gfloat) height / 2.0f); - gst_gl_effects_draw_texture (effects, texture, width, height); + gst_gl_filter_draw_texture (filter, texture, width, height); } void diff --git a/gst/gl/effects/gstgleffectglow.c b/gst/gl/effects/gstgleffectglow.c index 441963365e..b79f54fcf5 100644 --- a/gst/gl/effects/gstgleffectglow.c +++ b/gst/gl/effects/gstgleffectglow.c @@ -32,7 +32,8 @@ gst_gl_effects_glow_step_one (gint width, gint height, guint texture, { GstGLShader *shader; GstGLEffects *effects = GST_GL_EFFECTS (data); - GstGLContext *context = GST_GL_FILTER (effects)->context; + GstGLFilter *filter = GST_GL_FILTER (effects); + GstGLContext *context = filter->context; GstGLFuncs *gl = context->gl_vtable; shader = g_hash_table_lookup (effects->shaderstable, "glow0"); @@ -62,7 +63,7 @@ gst_gl_effects_glow_step_one (gint width, gint height, guint texture, gst_gl_shader_set_uniform_1i (shader, "tex", 0); - gst_gl_effects_draw_texture (effects, texture, width, height); + gst_gl_filter_draw_texture (filter, texture, width, height); } static void @@ -71,7 +72,8 @@ gst_gl_effects_glow_step_two (gint width, gint height, guint texture, { GstGLShader *shader; GstGLEffects *effects = GST_GL_EFFECTS (data); - GstGLContext *context = GST_GL_FILTER (effects)->context; + GstGLFilter *filter = GST_GL_FILTER (effects); + GstGLContext *context = filter->context; GstGLFuncs *gl = context->gl_vtable; shader = g_hash_table_lookup (effects->shaderstable, "glow1"); @@ -108,7 +110,7 @@ gst_gl_effects_glow_step_two (gint width, gint height, guint texture, gst_gl_shader_set_uniform_1fv (shader, "kernel", 7, gauss_kernel); gst_gl_shader_set_uniform_1f (shader, "height", height); - gst_gl_effects_draw_texture (effects, texture, width, height); + gst_gl_filter_draw_texture (filter, texture, width, height); } void @@ -117,7 +119,8 @@ gst_gl_effects_glow_step_three (gint width, gint height, guint texture, { GstGLShader *shader; GstGLEffects *effects = GST_GL_EFFECTS (data); - GstGLContext *context = GST_GL_FILTER (effects)->context; + GstGLFilter *filter = GST_GL_FILTER (effects); + GstGLContext *context = filter->context; GstGLFuncs *gl = context->gl_vtable; shader = g_hash_table_lookup (effects->shaderstable, "glow2"); @@ -149,7 +152,7 @@ gst_gl_effects_glow_step_three (gint width, gint height, guint texture, gst_gl_shader_set_uniform_1fv (shader, "kernel", 7, gauss_kernel); gst_gl_shader_set_uniform_1f (shader, "width", width); - gst_gl_effects_draw_texture (effects, texture, width, height); + gst_gl_filter_draw_texture (filter, texture, width, height); } void @@ -158,7 +161,8 @@ gst_gl_effects_glow_step_four (gint width, gint height, guint texture, { GstGLShader *shader; GstGLEffects *effects = GST_GL_EFFECTS (data); - GstGLContext *context = GST_GL_FILTER (effects)->context; + GstGLFilter *filter = GST_GL_FILTER (effects); + GstGLContext *context = filter->context; GstGLFuncs *gl = context->gl_vtable; shader = g_hash_table_lookup (effects->shaderstable, "glow3"); @@ -197,7 +201,7 @@ gst_gl_effects_glow_step_four (gint width, gint height, guint texture, gst_gl_shader_set_uniform_1f (shader, "beta", (gfloat) 1 / 3.5f); gst_gl_shader_set_uniform_1i (shader, "blend", 1); - gst_gl_effects_draw_texture (effects, texture, width, height); + gst_gl_filter_draw_texture (filter, texture, width, height); } void diff --git a/gst/gl/effects/gstgleffectidentity.c b/gst/gl/effects/gstgleffectidentity.c index ba5cd44f4e..9814fec44a 100644 --- a/gst/gl/effects/gstgleffectidentity.c +++ b/gst/gl/effects/gstgleffectidentity.c @@ -65,9 +65,9 @@ gst_gl_effects_identity_callback (gint width, gint height, guint texture, error = NULL; gst_gl_shader_use (NULL); } else { - effects->draw_attr_position_loc = + filter->draw_attr_position_loc = gst_gl_shader_get_attribute_location (shader, "a_position"); - effects->draw_attr_texture_loc = + filter->draw_attr_texture_loc = gst_gl_shader_get_attribute_location (shader, "a_texCoord"); } } @@ -82,7 +82,7 @@ gst_gl_effects_identity_callback (gint width, gint height, guint texture, } #endif - gst_gl_effects_draw_texture (effects, texture, width, height); + gst_gl_filter_draw_texture (filter, texture, width, height); } void diff --git a/gst/gl/effects/gstgleffectlumatocurve.c b/gst/gl/effects/gstgleffectlumatocurve.c index f895eb42f1..e45a81b148 100644 --- a/gst/gl/effects/gstgleffectlumatocurve.c +++ b/gst/gl/effects/gstgleffectlumatocurve.c @@ -30,7 +30,8 @@ gst_gl_effects_luma_to_curve (GstGLEffects * effects, gint curve_index, gint width, gint height, GLuint texture) { GstGLShader *shader; - GstGLContext *context = GST_GL_FILTER (effects)->context; + GstGLFilter *filter = GST_GL_FILTER (effects); + GstGLContext *context = filter->context; GstGLFuncs *gl = context->gl_vtable; shader = g_hash_table_lookup (effects->shaderstable, "lumamap0"); @@ -86,7 +87,7 @@ gst_gl_effects_luma_to_curve (GstGLEffects * effects, gl->Disable (GL_TEXTURE_1D); - gst_gl_effects_draw_texture (effects, texture, width, height); + gst_gl_filter_draw_texture (filter, texture, width, height); } static void diff --git a/gst/gl/effects/gstgleffectmirror.c b/gst/gl/effects/gstgleffectmirror.c index fea2b3255b..5d77fa9799 100644 --- a/gst/gl/effects/gstgleffectmirror.c +++ b/gst/gl/effects/gstgleffectmirror.c @@ -63,9 +63,9 @@ gst_gl_effects_mirror_callback (gint width, gint height, guint texture, GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND, ("%s", gst_gl_context_get_error ()), (NULL)); } else { - effects->draw_attr_position_loc = + filter->draw_attr_position_loc = gst_gl_shader_get_attribute_location (shader, "a_position"); - effects->draw_attr_texture_loc = + filter->draw_attr_texture_loc = gst_gl_shader_get_attribute_location (shader, "a_texCoord"); } } @@ -107,7 +107,7 @@ gst_gl_effects_mirror_callback (gint width, gint height, guint texture, } #endif - gst_gl_effects_draw_texture (effects, texture, width, height); + gst_gl_filter_draw_texture (filter, texture, width, height); } void diff --git a/gst/gl/effects/gstgleffectrgbtocurve.c b/gst/gl/effects/gstgleffectrgbtocurve.c index d389ce9a3a..293875f77c 100644 --- a/gst/gl/effects/gstgleffectrgbtocurve.c +++ b/gst/gl/effects/gstgleffectrgbtocurve.c @@ -30,7 +30,8 @@ gst_gl_effects_rgb_to_curve (GstGLEffects * effects, gint curve_index, gint width, gint height, GLuint texture) { GstGLShader *shader; - GstGLContext *context = GST_GL_FILTER (effects)->context; + GstGLFilter *filter = GST_GL_FILTER (effects); + GstGLContext *context = filter->context; GstGLFuncs *gl = context->gl_vtable; shader = g_hash_table_lookup (effects->shaderstable, "rgbmap0"); @@ -86,7 +87,7 @@ gst_gl_effects_rgb_to_curve (GstGLEffects * effects, gl->Disable (GL_TEXTURE_1D); - gst_gl_effects_draw_texture (effects, texture, width, height); + gst_gl_filter_draw_texture (filter, texture, width, height); } static void diff --git a/gst/gl/effects/gstgleffectsin.c b/gst/gl/effects/gstgleffectsin.c index 4e77b9eeed..1b229d242a 100644 --- a/gst/gl/effects/gstgleffectsin.c +++ b/gst/gl/effects/gstgleffectsin.c @@ -29,7 +29,8 @@ gst_gl_effects_sin_callback (gint width, gint height, guint texture, { GstGLShader *shader; GstGLEffects *effects = GST_GL_EFFECTS (data); - GstGLContext *context = GST_GL_FILTER (effects)->context; + GstGLFilter *filter = GST_GL_FILTER (effects); + GstGLContext *context = filter->context; GstGLFuncs *gl = context->gl_vtable; shader = g_hash_table_lookup (effects->shaderstable, "sin0"); @@ -58,7 +59,7 @@ gst_gl_effects_sin_callback (gint width, gint height, guint texture, gst_gl_shader_set_uniform_1i (shader, "tex", 0); - gst_gl_effects_draw_texture (effects, texture, width, height); + gst_gl_filter_draw_texture (filter, texture, width, height); } void diff --git a/gst/gl/effects/gstgleffectsquare.c b/gst/gl/effects/gstgleffectsquare.c index c5cd0cf7b8..127e39ffad 100644 --- a/gst/gl/effects/gstgleffectsquare.c +++ b/gst/gl/effects/gstgleffectsquare.c @@ -29,7 +29,8 @@ gst_gl_effects_square_callback (gint width, gint height, guint texture, { GstGLShader *shader; GstGLEffects *effects = GST_GL_EFFECTS (data); - GstGLContext *context = GST_GL_FILTER (effects)->context; + GstGLFilter *filter = GST_GL_FILTER (effects); + GstGLContext *context = filter->context; GstGLFuncs *gl = context->gl_vtable; shader = g_hash_table_lookup (effects->shaderstable, "square0"); @@ -61,7 +62,7 @@ gst_gl_effects_square_callback (gint width, gint height, guint texture, gst_gl_shader_set_uniform_1f (shader, "width", (gfloat) width / 2.0f); gst_gl_shader_set_uniform_1f (shader, "height", (gfloat) height / 2.0f); - gst_gl_effects_draw_texture (effects, texture, width, height); + gst_gl_filter_draw_texture (filter, texture, width, height); } void diff --git a/gst/gl/effects/gstgleffectsqueeze.c b/gst/gl/effects/gstgleffectsqueeze.c index 3c10589a27..14a9bcbc44 100644 --- a/gst/gl/effects/gstgleffectsqueeze.c +++ b/gst/gl/effects/gstgleffectsqueeze.c @@ -63,9 +63,9 @@ gst_gl_effects_squeeze_callback (gint width, gint height, guint texture, GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND, ("%s", gst_gl_context_get_error ()), (NULL)); } else { - effects->draw_attr_position_loc = + filter->draw_attr_position_loc = gst_gl_shader_get_attribute_location (shader, "a_position"); - effects->draw_attr_texture_loc = + filter->draw_attr_texture_loc = gst_gl_shader_get_attribute_location (shader, "a_texCoord"); } } @@ -106,7 +106,7 @@ gst_gl_effects_squeeze_callback (gint width, gint height, guint texture, } #endif - gst_gl_effects_draw_texture (effects, texture, width, height); + gst_gl_filter_draw_texture (filter, texture, width, height); } void diff --git a/gst/gl/effects/gstgleffectstretch.c b/gst/gl/effects/gstgleffectstretch.c index ab1cfaca8a..0b8b9d1c6f 100644 --- a/gst/gl/effects/gstgleffectstretch.c +++ b/gst/gl/effects/gstgleffectstretch.c @@ -29,7 +29,8 @@ gst_gl_effects_stretch_callback (gint width, gint height, guint texture, { GstGLShader *shader; GstGLEffects *effects = GST_GL_EFFECTS (data); - GstGLContext *context = GST_GL_FILTER (effects)->context; + GstGLFilter *filter = GST_GL_FILTER (effects); + GstGLContext *context = filter->context; GstGLFuncs *gl = context->gl_vtable; shader = g_hash_table_lookup (effects->shaderstable, "stretch0"); @@ -61,7 +62,7 @@ gst_gl_effects_stretch_callback (gint width, gint height, guint texture, gst_gl_shader_set_uniform_1f (shader, "width", (gfloat) width / 2.0f); gst_gl_shader_set_uniform_1f (shader, "height", (gfloat) height / 2.0f); - gst_gl_effects_draw_texture (effects, texture, width, height); + gst_gl_filter_draw_texture (filter, texture, width, height); } void diff --git a/gst/gl/effects/gstgleffecttunnel.c b/gst/gl/effects/gstgleffecttunnel.c index 0db786c1bc..21886337ef 100644 --- a/gst/gl/effects/gstgleffecttunnel.c +++ b/gst/gl/effects/gstgleffecttunnel.c @@ -29,7 +29,8 @@ gst_gl_effects_tunnel_callback (gint width, gint height, guint texture, { GstGLShader *shader; GstGLEffects *effects = GST_GL_EFFECTS (data); - GstGLContext *context = GST_GL_FILTER (effects)->context; + GstGLFilter *filter = GST_GL_FILTER (effects); + GstGLContext *context = filter->context; GstGLFuncs *gl = context->gl_vtable; shader = g_hash_table_lookup (effects->shaderstable, "tunnel0"); @@ -61,7 +62,7 @@ gst_gl_effects_tunnel_callback (gint width, gint height, guint texture, gst_gl_shader_set_uniform_1f (shader, "width", (gfloat) width / 2.0f); gst_gl_shader_set_uniform_1f (shader, "height", (gfloat) height / 2.0f); - gst_gl_effects_draw_texture (effects, texture, width, height); + gst_gl_filter_draw_texture (filter, texture, width, height); } void diff --git a/gst/gl/effects/gstgleffecttwirl.c b/gst/gl/effects/gstgleffecttwirl.c index 06594c05fe..22ce874a75 100644 --- a/gst/gl/effects/gstgleffecttwirl.c +++ b/gst/gl/effects/gstgleffecttwirl.c @@ -29,7 +29,8 @@ gst_gl_effects_twirl_callback (gint width, gint height, guint texture, { GstGLShader *shader; GstGLEffects *effects = GST_GL_EFFECTS (data); - GstGLContext *context = GST_GL_FILTER (effects)->context; + GstGLFilter *filter = GST_GL_FILTER (effects); + GstGLContext *context = filter->context; GstGLFuncs *gl = context->gl_vtable; shader = g_hash_table_lookup (effects->shaderstable, "twirl0"); @@ -61,7 +62,7 @@ gst_gl_effects_twirl_callback (gint width, gint height, guint texture, gst_gl_shader_set_uniform_1f (shader, "width", (gfloat) width / 2.0f); gst_gl_shader_set_uniform_1f (shader, "height", (gfloat) height / 2.0f); - gst_gl_effects_draw_texture (effects, texture, width, height); + gst_gl_filter_draw_texture (filter, texture, width, height); } void diff --git a/gst/gl/effects/gstgleffectxray.c b/gst/gl/effects/gstgleffectxray.c index 6dfd81bd04..bd70abf8cc 100644 --- a/gst/gl/effects/gstgleffectxray.c +++ b/gst/gl/effects/gstgleffectxray.c @@ -44,7 +44,8 @@ gst_gl_effects_xray_step_two (gint width, gint height, guint texture, { GstGLShader *shader; GstGLEffects *effects = GST_GL_EFFECTS (data); - GstGLContext *context = GST_GL_FILTER (effects)->context; + GstGLFilter *filter = GST_GL_FILTER (effects); + GstGLContext *context = filter->context; GstGLFuncs *gl = context->gl_vtable; shader = g_hash_table_lookup (effects->shaderstable, "xray1"); @@ -81,7 +82,7 @@ gst_gl_effects_xray_step_two (gint width, gint height, guint texture, gst_gl_shader_set_uniform_1fv (shader, "kernel", 9, gauss_kernel); gst_gl_shader_set_uniform_1f (shader, "width", width); - gst_gl_effects_draw_texture (effects, texture, width, height); + gst_gl_filter_draw_texture (filter, texture, width, height); } static void @@ -90,7 +91,8 @@ gst_gl_effects_xray_step_three (gint width, gint height, guint texture, { GstGLShader *shader; GstGLEffects *effects = GST_GL_EFFECTS (data); - GstGLContext *context = GST_GL_FILTER (effects)->context; + GstGLFilter *filter = GST_GL_FILTER (effects); + GstGLContext *context = filter->context; GstGLFuncs *gl = context->gl_vtable; shader = g_hash_table_lookup (effects->shaderstable, "xray2"); @@ -122,7 +124,7 @@ gst_gl_effects_xray_step_three (gint width, gint height, guint texture, gst_gl_shader_set_uniform_1fv (shader, "kernel", 9, gauss_kernel); gst_gl_shader_set_uniform_1f (shader, "height", height); - gst_gl_effects_draw_texture (effects, texture, width, height); + gst_gl_filter_draw_texture (filter, texture, width, height); } /* multipass separable sobel */ @@ -132,7 +134,8 @@ gst_gl_effects_xray_desaturate (gint width, gint height, guint texture, { GstGLShader *shader; GstGLEffects *effects = GST_GL_EFFECTS (data); - GstGLContext *context = GST_GL_FILTER (effects)->context; + GstGLFilter *filter = GST_GL_FILTER (effects); + GstGLContext *context = filter->context; GstGLFuncs *gl = context->gl_vtable; shader = g_hash_table_lookup (effects->shaderstable, "xray_desat"); @@ -162,7 +165,7 @@ gst_gl_effects_xray_desaturate (gint width, gint height, guint texture, gl->Disable (GL_TEXTURE_2D); gst_gl_shader_set_uniform_1i (shader, "tex", 1); - gst_gl_effects_draw_texture (effects, texture, width, height); + gst_gl_filter_draw_texture (filter, texture, width, height); } static void @@ -171,7 +174,8 @@ gst_gl_effects_xray_sobel_hconv (gint width, gint height, guint texture, { GstGLShader *shader; GstGLEffects *effects = GST_GL_EFFECTS (data); - GstGLContext *context = GST_GL_FILTER (effects)->context; + GstGLFilter *filter = GST_GL_FILTER (effects); + GstGLContext *context = filter->context; GstGLFuncs *gl = context->gl_vtable; shader = g_hash_table_lookup (effects->shaderstable, "xray_sob_hconv"); @@ -203,7 +207,7 @@ gst_gl_effects_xray_sobel_hconv (gint width, gint height, guint texture, gst_gl_shader_set_uniform_1i (shader, "tex", 1); gst_gl_shader_set_uniform_1f (shader, "width", width); - gst_gl_effects_draw_texture (effects, texture, width, height); + gst_gl_filter_draw_texture (filter, texture, width, height); } static void @@ -212,7 +216,8 @@ gst_gl_effects_xray_sobel_vconv (gint width, gint height, guint texture, { GstGLShader *shader; GstGLEffects *effects = GST_GL_EFFECTS (data); - GstGLContext *context = GST_GL_FILTER (effects)->context; + GstGLFilter *filter = GST_GL_FILTER (effects); + GstGLContext *context = filter->context; GstGLFuncs *gl = context->gl_vtable; shader = g_hash_table_lookup (effects->shaderstable, "xray_sob_vconv"); @@ -244,7 +249,7 @@ gst_gl_effects_xray_sobel_vconv (gint width, gint height, guint texture, gst_gl_shader_set_uniform_1i (shader, "tex", 1); gst_gl_shader_set_uniform_1f (shader, "height", height); - gst_gl_effects_draw_texture (effects, texture, width, height); + gst_gl_filter_draw_texture (filter, texture, width, height); } static void @@ -253,7 +258,8 @@ gst_gl_effects_xray_sobel_length (gint width, gint height, guint texture, { GstGLShader *shader; GstGLEffects *effects = GST_GL_EFFECTS (data); - GstGLContext *context = GST_GL_FILTER (effects)->context; + GstGLFilter *filter = GST_GL_FILTER (effects); + GstGLContext *context = filter->context; GstGLFuncs *gl = context->gl_vtable; shader = g_hash_table_lookup (effects->shaderstable, "xray_sob_len"); @@ -284,7 +290,7 @@ gst_gl_effects_xray_sobel_length (gint width, gint height, guint texture, gst_gl_shader_set_uniform_1i (shader, "tex", 1); gst_gl_shader_set_uniform_1i (shader, "invert", TRUE); - gst_gl_effects_draw_texture (effects, texture, width, height); + gst_gl_filter_draw_texture (filter, texture, width, height); } /* end of sobel passes */ @@ -295,7 +301,8 @@ gst_gl_effects_xray_step_five (gint width, gint height, guint texture, { GstGLShader *shader; GstGLEffects *effects = GST_GL_EFFECTS (data); - GstGLContext *context = GST_GL_FILTER (effects)->context; + GstGLFilter *filter = GST_GL_FILTER (effects); + GstGLContext *context = filter->context; GstGLFuncs *gl = context->gl_vtable; shader = g_hash_table_lookup (effects->shaderstable, "xray4"); @@ -333,7 +340,7 @@ gst_gl_effects_xray_step_five (gint width, gint height, guint texture, gst_gl_shader_set_uniform_1f (shader, "alpha", (gfloat) 0.5f); gst_gl_shader_set_uniform_1i (shader, "blend", 1); - gst_gl_effects_draw_texture (effects, texture, width, height); + gst_gl_filter_draw_texture (filter, texture, width, height); } void diff --git a/gst/gl/gstgleffects.c b/gst/gl/gstgleffects.c index a10fe59d6e..4f7338ab95 100644 --- a/gst/gl/gstgleffects.c +++ b/gst/gl/gstgleffects.c @@ -267,75 +267,6 @@ gst_gl_effects_class_init (GstGLEffectsClass * klass) "Filippo Argiolas "); } -void -gst_gl_effects_draw_texture (GstGLEffects * effects, GLuint tex, guint width, - guint height) -{ - GstGLContext *context = GST_GL_FILTER (effects)->context; - GstGLFuncs *gl = context->gl_vtable; - -#if GST_GL_HAVE_OPENGL - if (gst_gl_context_get_gl_api (context) & GST_GL_API_OPENGL) { - GLfloat verts[] = { -1.0f, -1.0f, - 1.0f, -1.0f, - 1.0f, 1.0f, - -1.0f, 1.0f - }; - GLfloat texcoords[] = { 0.0f, 0.0f, - 1.0f, 0.0f, - 1.0f, 1.0f, - 0.0f, 1.0f - }; - - gl->ActiveTexture (GL_TEXTURE0); - - gl->Enable (GL_TEXTURE_2D); - gl->BindTexture (GL_TEXTURE_2D, tex); - - gl->EnableClientState (GL_VERTEX_ARRAY); - gl->EnableClientState (GL_TEXTURE_COORD_ARRAY); - - gl->VertexPointer (2, GL_FLOAT, 0, &verts); - gl->TexCoordPointer (2, GL_FLOAT, 0, &texcoords); - - gl->DrawArrays (GL_TRIANGLE_FAN, 0, 4); - - gl->DisableClientState (GL_VERTEX_ARRAY); - gl->DisableClientState (GL_TEXTURE_COORD_ARRAY); - } -#endif -#if GST_GL_HAVE_GLES2 - if (gst_gl_context_get_gl_api (context) & GST_GL_API_GLES2) { - const GLfloat vVertices[] = { - -1.0f, -1.0f, 0.0f, - 0.0f, 0.0f, - 1.0, -1.0f, 0.0f, - 1.0f, 0.0f, - 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f - }; - - GLushort indices[] = { 0, 1, 2, 0, 2, 3 }; - - /* glClear (GL_COLOR_BUFFER_BIT); */ - - /* Load the vertex position */ - gl->VertexAttribPointer (effects->draw_attr_position_loc, 3, GL_FLOAT, - GL_FALSE, 5 * sizeof (GLfloat), vVertices); - - /* Load the texture coordinate */ - gl->VertexAttribPointer (effects->draw_attr_texture_loc, 2, GL_FLOAT, - GL_FALSE, 5 * sizeof (GLfloat), &vVertices[3]); - - gl->EnableVertexAttribArray (effects->draw_attr_position_loc); - gl->EnableVertexAttribArray (effects->draw_attr_texture_loc); - - gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices); - } -#endif - - gst_gl_context_clear_shader (context); -} - static void set_horizontal_swap (GstGLContext * context, gpointer data) { diff --git a/gst/gl/gstgleffects.h b/gst/gl/gstgleffects.h index adc35af654..71bec2582a 100644 --- a/gst/gl/gstgleffects.h +++ b/gst/gl/gstgleffects.h @@ -66,11 +66,6 @@ struct _GstGLEffects GHashTable *shaderstable; gboolean horizontal_swap; /* switch left to right */ - -#if GST_GL_HAVE_GLES2 - GLint draw_attr_position_loc; - GLint draw_attr_texture_loc; -#endif }; struct _GstGLEffectsClass @@ -88,8 +83,6 @@ enum GType gst_gl_effects_get_type (void); -void gst_gl_effects_draw_texture (GstGLEffects * effects, GLuint tex, guint width, guint height); - void gst_gl_effects_identity (GstGLEffects *effects); void gst_gl_effects_mirror (GstGLEffects *effects); void gst_gl_effects_squeeze (GstGLEffects *effects);