gleffects: use new helper functions to avoid duplicating the same vertex shader text

And also use the default fragment shader text for the identity effect
This commit is contained in:
Julien Isorce 2014-04-30 15:28:35 +01:00 committed by Tim-Philipp Müller
parent cebcc837de
commit 2b8de2d1bc
5 changed files with 24 additions and 82 deletions

View file

@ -54,23 +54,14 @@ gst_gl_effects_identity_callback (gint width, gint height, guint texture,
g_hash_table_insert (effects->shaderstable, (gchar *) "identity0", g_hash_table_insert (effects->shaderstable, (gchar *) "identity0",
shader); shader);
if (shader) { if (!gst_gl_shader_compile_with_default_vf_and_check (shader,
GError *error = NULL; &filter->draw_attr_position_loc,
gst_gl_shader_set_vertex_source (shader, vertex_shader_source); &filter->draw_attr_texture_loc)) {
gst_gl_shader_set_fragment_source (shader, identity_fragment_source); /* gst gl context error is already set */
GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND,
gst_gl_shader_compile (shader, &error); ("Failed to initialize identity shader, %s",
if (error) { gst_gl_context_get_error ()), (NULL));
GST_ERROR ("%s", error->message); return;
g_error_free (error);
error = NULL;
gst_gl_shader_use (NULL);
} else {
filter->draw_attr_position_loc =
gst_gl_shader_get_attribute_location (shader, "a_position");
filter->draw_attr_texture_loc =
gst_gl_shader_get_attribute_location (shader, "a_texCoord");
}
} }
} }
gst_gl_shader_use (shader); gst_gl_shader_use (shader);

View file

@ -47,27 +47,14 @@ gst_gl_effects_mirror_callback (gint width, gint height, guint texture,
#if GST_GL_HAVE_GLES2 #if GST_GL_HAVE_GLES2
if (USING_GLES2 (context)) { if (USING_GLES2 (context)) {
if (shader) { if (!gst_gl_shader_compile_with_default_v_and_check (shader,
GError *error = NULL; mirror_fragment_source_gles2, &filter->draw_attr_position_loc,
gst_gl_shader_set_vertex_source (shader, vertex_shader_source); &filter->draw_attr_texture_loc)) {
gst_gl_shader_set_fragment_source (shader, /* gst gl context error is already set */
mirror_fragment_source_gles2);
gst_gl_shader_compile (shader, &error);
if (error) {
gst_gl_context_set_error (context,
"Failed to initialize mirror shader, %s", error->message);
g_error_free (error);
error = NULL;
gst_gl_shader_use (NULL);
GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND, GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND,
("%s", gst_gl_context_get_error ()), (NULL)); ("Failed to initialize squeeze shader, %s",
} else { gst_gl_context_get_error ()), (NULL));
filter->draw_attr_position_loc = return;
gst_gl_shader_get_attribute_location (shader, "a_position");
filter->draw_attr_texture_loc =
gst_gl_shader_get_attribute_location (shader, "a_texCoord");
}
} }
} }
#endif #endif

View file

@ -47,27 +47,14 @@ gst_gl_effects_squeeze_callback (gint width, gint height, guint texture,
#if GST_GL_HAVE_GLES2 #if GST_GL_HAVE_GLES2
if (USING_GLES2 (context)) { if (USING_GLES2 (context)) {
if (shader) { if (!gst_gl_shader_compile_with_default_v_and_check (shader,
GError *error = NULL; squeeze_fragment_source_gles2, &filter->draw_attr_position_loc,
gst_gl_shader_set_vertex_source (shader, vertex_shader_source); &filter->draw_attr_texture_loc)) {
gst_gl_shader_set_fragment_source (shader, /* gst gl context error is already set */
squeeze_fragment_source_gles2);
gst_gl_shader_compile (shader, &error);
if (error) {
gst_gl_context_set_error (context,
"Failed to initialize squeeze shader, %s", error->message);
g_error_free (error);
error = NULL;
gst_gl_shader_use (NULL);
GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND, GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND,
("%s", gst_gl_context_get_error ()), (NULL)); ("Failed to initialize squeeze shader, %s",
} else { gst_gl_context_get_error ()), (NULL));
filter->draw_attr_position_loc = return;
gst_gl_shader_get_attribute_location (shader, "a_position");
filter->draw_attr_texture_loc =
gst_gl_shader_get_attribute_location (shader, "a_texCoord");
}
} }
} }
#endif #endif

View file

@ -64,27 +64,6 @@ fill_gaussian_kernel (float *kernel, int size, float sigma)
/* *INDENT-OFF* */ /* *INDENT-OFF* */
/* Vertex shader */
const gchar *vertex_shader_source =
"attribute vec4 a_position;"
"attribute vec2 a_texCoord;"
"varying vec2 v_texCoord;"
"void main()"
"{"
" gl_Position = a_position;"
" v_texCoord = a_texCoord;"
"}";
/* Identity effect */
const gchar *identity_fragment_source =
"precision mediump float;"
"varying vec2 v_texCoord;"
"uniform sampler2D tex;"
"void main()"
"{"
" gl_FragColor = texture2D(tex, v_texCoord);"
"}";
/* Mirror effect */ /* Mirror effect */
#if GST_GL_HAVE_OPENGL #if GST_GL_HAVE_OPENGL
const gchar *mirror_fragment_source_opengl = const gchar *mirror_fragment_source_opengl =

View file

@ -21,8 +21,6 @@
#ifndef __GST_GL_EFFECTS_SOURCES_H__ #ifndef __GST_GL_EFFECTS_SOURCES_H__
#define __GST_GL_EFFECTS_SOURCES_H__ #define __GST_GL_EFFECTS_SOURCES_H__
extern const gchar *vertex_shader_source;
extern const gchar *identity_fragment_source;
#if GST_GL_HAVE_OPENGL #if GST_GL_HAVE_OPENGL
extern const gchar *mirror_fragment_source_opengl; extern const gchar *mirror_fragment_source_opengl;
extern const gchar *squeeze_fragment_source_opengl; extern const gchar *squeeze_fragment_source_opengl;