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",
shader);
if (shader) {
GError *error = NULL;
gst_gl_shader_set_vertex_source (shader, vertex_shader_source);
gst_gl_shader_set_fragment_source (shader, identity_fragment_source);
gst_gl_shader_compile (shader, &error);
if (error) {
GST_ERROR ("%s", error->message);
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");
}
if (!gst_gl_shader_compile_with_default_vf_and_check (shader,
&filter->draw_attr_position_loc,
&filter->draw_attr_texture_loc)) {
/* gst gl context error is already set */
GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND,
("Failed to initialize identity shader, %s",
gst_gl_context_get_error ()), (NULL));
return;
}
}
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 (USING_GLES2 (context)) {
if (shader) {
GError *error = NULL;
gst_gl_shader_set_vertex_source (shader, vertex_shader_source);
gst_gl_shader_set_fragment_source (shader,
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);
if (!gst_gl_shader_compile_with_default_v_and_check (shader,
mirror_fragment_source_gles2, &filter->draw_attr_position_loc,
&filter->draw_attr_texture_loc)) {
/* gst gl context error is already set */
GST_ELEMENT_ERROR (effects, RESOURCE, NOT_FOUND,
("%s", gst_gl_context_get_error ()), (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");
}
("Failed to initialize squeeze shader, %s",
gst_gl_context_get_error ()), (NULL));
return;
}
}
#endif

View file

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

View file

@ -64,27 +64,6 @@ fill_gaussian_kernel (float *kernel, int size, float sigma)
/* *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 */
#if GST_GL_HAVE_OPENGL
const gchar *mirror_fragment_source_opengl =

View file

@ -21,8 +21,6 @@
#ifndef __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
extern const gchar *mirror_fragment_source_opengl;
extern const gchar *squeeze_fragment_source_opengl;