gleffects: support gl3 whereever gles2 is supported

This commit is contained in:
Matthew Waters 2014-11-12 23:48:32 +11:00 committed by Tim-Philipp Müller
parent 7ffe6fa93e
commit a82db7eb9e
4 changed files with 17 additions and 36 deletions

View file

@ -44,8 +44,7 @@ gst_gl_effects_identity_callback (gint width, gint height, guint texture,
gl->LoadIdentity (); gl->LoadIdentity ();
} }
#endif #endif
#if GST_GL_HAVE_GLES2 if (USING_GLES2 (context) || USING_OPENGL3 (context)) {
if (USING_GLES2 (context)) {
GstGLShader *shader = GstGLShader *shader =
g_hash_table_lookup (effects->shaderstable, "identity0"); g_hash_table_lookup (effects->shaderstable, "identity0");
@ -67,12 +66,10 @@ gst_gl_effects_identity_callback (gint width, gint height, guint texture,
gst_gl_shader_use (shader); gst_gl_shader_use (shader);
gl->ActiveTexture (GL_TEXTURE0); gl->ActiveTexture (GL_TEXTURE0);
gl->Enable (GL_TEXTURE_2D);
gl->BindTexture (GL_TEXTURE_2D, texture); gl->BindTexture (GL_TEXTURE_2D, texture);
gst_gl_shader_set_uniform_1i (shader, "tex", 0); gst_gl_shader_set_uniform_1i (shader, "tex", 0);
} }
#endif
gst_gl_filter_draw_texture (filter, texture, width, height); gst_gl_filter_draw_texture (filter, texture, width, height);
} }

View file

@ -45,8 +45,7 @@ gst_gl_effects_mirror_callback (gint width, gint height, guint texture,
shader = gst_gl_shader_new (context); shader = gst_gl_shader_new (context);
g_hash_table_insert (effects->shaderstable, (gchar *) "mirror0", shader); g_hash_table_insert (effects->shaderstable, (gchar *) "mirror0", shader);
#if GST_GL_HAVE_GLES2 if (USING_GLES2 (context) || USING_OPENGL3 (context)) {
if (USING_GLES2 (context)) {
if (!gst_gl_shader_compile_with_default_v_and_check (shader, if (!gst_gl_shader_compile_with_default_v_and_check (shader,
mirror_fragment_source_gles2, &filter->draw_attr_position_loc, mirror_fragment_source_gles2, &filter->draw_attr_position_loc,
&filter->draw_attr_texture_loc)) { &filter->draw_attr_texture_loc)) {
@ -57,7 +56,6 @@ gst_gl_effects_mirror_callback (gint width, gint height, guint texture,
return; return;
} }
} }
#endif
#if GST_GL_HAVE_OPENGL #if GST_GL_HAVE_OPENGL
if (USING_OPENGL (context)) { if (USING_OPENGL (context)) {
if (!gst_gl_shader_compile_and_check (shader, if (!gst_gl_shader_compile_and_check (shader,
@ -82,18 +80,12 @@ gst_gl_effects_mirror_callback (gint width, gint height, guint texture,
gst_gl_shader_use (shader); gst_gl_shader_use (shader);
gl->ActiveTexture (GL_TEXTURE0); gl->ActiveTexture (GL_TEXTURE0);
gl->Enable (GL_TEXTURE_2D); if (USING_OPENGL (context))
gl->Enable (GL_TEXTURE_2D);
gl->BindTexture (GL_TEXTURE_2D, texture); gl->BindTexture (GL_TEXTURE_2D, texture);
gst_gl_shader_set_uniform_1i (shader, "tex", 0); gst_gl_shader_set_uniform_1i (shader, "tex", 0);
#if GST_GL_HAVE_OPENGL
if (USING_OPENGL (filter->context)) {
gst_gl_shader_set_uniform_1f (shader, "width", (gfloat) width / 2.0f);
gst_gl_shader_set_uniform_1f (shader, "height", (gfloat) height / 2.0f);
}
#endif
gst_gl_filter_draw_texture (filter, texture, width, height); gst_gl_filter_draw_texture (filter, texture, width, height);
} }

View file

@ -45,8 +45,7 @@ gst_gl_effects_squeeze_callback (gint width, gint height, guint texture,
shader = gst_gl_shader_new (context); shader = gst_gl_shader_new (context);
g_hash_table_insert (effects->shaderstable, (gchar *) "squeeze0", shader); g_hash_table_insert (effects->shaderstable, (gchar *) "squeeze0", shader);
#if GST_GL_HAVE_GLES2 if (USING_GLES2 (context) || USING_OPENGL3 (context)) {
if (USING_GLES2 (context)) {
if (!gst_gl_shader_compile_with_default_v_and_check (shader, if (!gst_gl_shader_compile_with_default_v_and_check (shader,
squeeze_fragment_source_gles2, &filter->draw_attr_position_loc, squeeze_fragment_source_gles2, &filter->draw_attr_position_loc,
&filter->draw_attr_texture_loc)) { &filter->draw_attr_texture_loc)) {
@ -57,7 +56,6 @@ gst_gl_effects_squeeze_callback (gint width, gint height, guint texture,
return; return;
} }
} }
#endif
#if GST_GL_HAVE_OPENGL #if GST_GL_HAVE_OPENGL
if (USING_OPENGL (context)) { if (USING_OPENGL (context)) {
if (!gst_gl_shader_compile_and_check (shader, if (!gst_gl_shader_compile_and_check (shader,
@ -81,18 +79,12 @@ gst_gl_effects_squeeze_callback (gint width, gint height, guint texture,
gst_gl_shader_use (shader); gst_gl_shader_use (shader);
gl->ActiveTexture (GL_TEXTURE0); gl->ActiveTexture (GL_TEXTURE0);
gl->Enable (GL_TEXTURE_2D); if (USING_OPENGL (context))
gl->Enable (GL_TEXTURE_2D);
gl->BindTexture (GL_TEXTURE_2D, texture); gl->BindTexture (GL_TEXTURE_2D, texture);
gst_gl_shader_set_uniform_1i (shader, "tex", 0); gst_gl_shader_set_uniform_1i (shader, "tex", 0);
#if GST_GL_HAVE_OPENGL
if (USING_OPENGL (filter->context)) {
gst_gl_shader_set_uniform_1f (shader, "width", (gfloat) width / 2.0f);
gst_gl_shader_set_uniform_1f (shader, "height", (gfloat) height / 2.0f);
}
#endif
gst_gl_filter_draw_texture (filter, texture, width, height); gst_gl_filter_draw_texture (filter, texture, width, height);
} }

View file

@ -78,19 +78,19 @@ const gchar *mirror_fragment_source_opengl =
" gl_FragColor = color * gl_Color;" " gl_FragColor = color * gl_Color;"
"}"; "}";
#endif #endif
#if GST_GL_HAVE_GLES2
const gchar *mirror_fragment_source_gles2 = const gchar *mirror_fragment_source_gles2 =
"precision mediump float;" "#ifdef GL_ES\n"
"varying vec2 v_texCoord;" "precision mediump float;\n"
"#endif\n"
"varying vec2 v_texcoord;"
"uniform sampler2D tex;" "uniform sampler2D tex;"
"void main () {" "void main () {"
" vec2 texturecoord = v_texCoord.xy;" " vec2 texturecoord = v_texcoord.xy;"
" float normcoord = texturecoord.x - 0.5;" " float normcoord = texturecoord.x - 0.5;"
" normcoord *= sign (normcoord);" " normcoord *= sign (normcoord);"
" texturecoord.x = normcoord + 0.5;" " texturecoord.x = normcoord + 0.5;"
" gl_FragColor = texture2D (tex, texturecoord);" " gl_FragColor = texture2D (tex, texturecoord);"
"}"; "}";
#endif
/* Squeeze effect */ /* Squeeze effect */
#if GST_GL_HAVE_OPENGL #if GST_GL_HAVE_OPENGL
@ -106,13 +106,14 @@ const gchar *squeeze_fragment_source_opengl =
" gl_FragColor = texture2D (tex, texturecoord);" " gl_FragColor = texture2D (tex, texturecoord);"
"}"; "}";
#endif #endif
#if GST_GL_HAVE_GLES2
const gchar *squeeze_fragment_source_gles2 = const gchar *squeeze_fragment_source_gles2 =
"precision mediump float;" "#ifdef GL_ES\n"
"varying vec2 v_texCoord;" "precision mediump float;\n"
"#endif\n"
"varying vec2 v_texcoord;"
"uniform sampler2D tex;" "uniform sampler2D tex;"
"void main () {" "void main () {"
" vec2 texturecoord = v_texCoord.xy;" " vec2 texturecoord = v_texcoord.xy;"
" vec2 normcoord = texturecoord - 0.5;" " vec2 normcoord = texturecoord - 0.5;"
" float r = length (normcoord);" " float r = length (normcoord);"
" r = pow(r, 0.40)*1.3;" " r = pow(r, 0.40)*1.3;"
@ -120,7 +121,6 @@ const gchar *squeeze_fragment_source_gles2 =
" texturecoord = (normcoord + 0.5);" " texturecoord = (normcoord + 0.5);"
" gl_FragColor = texture2D (tex, texturecoord);" " gl_FragColor = texture2D (tex, texturecoord);"
"}"; "}";
#endif
/* Stretch Effect */ /* Stretch Effect */
const gchar *stretch_fragment_source = const gchar *stretch_fragment_source =