From b30deff7e1b76863abe4e7997bc1ceb05f4fa16e Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Wed, 11 Nov 2015 23:39:35 +1100 Subject: [PATCH] glcolorconvert: mangle gl_FragColor for GL3 Some drivers don't provide the compatibility definition and we need to provide our own 'out vec4' variable to put the results of the fragment shader into. https://bugzilla.gnome.org/show_bug.cgi?id=757938 --- gst-libs/gst/gl/gstglcolorconvert.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/gst-libs/gst/gl/gstglcolorconvert.c b/gst-libs/gst/gl/gstglcolorconvert.c index d14fed922b..abd817c64f 100644 --- a/gst-libs/gst/gl/gstglcolorconvert.c +++ b/gst-libs/gst/gl/gstglcolorconvert.c @@ -1515,6 +1515,19 @@ _mangle_varying_attribute (const gchar * str, guint shader_type, return g_strdup (str); } +static gchar * +_mangle_frag_color (const gchar * str) +{ + GRegex *regex; + gchar *ret; + + regex = g_regex_new ("gl_FragColor", 0, 0, NULL); + ret = g_regex_replace_literal (regex, str, -1, 0, "fragColor", 0, NULL); + g_regex_unref (regex); + + return ret; +} + static void _mangle_version_profile_from_gl_api (GstGLAPI gl_api, GstGLSLVersion * version, GstGLSLProfile * profile) @@ -1543,6 +1556,11 @@ _mangle_shader (const gchar * str, guint shader_type, GstGLTextureTarget from, g_free (tmp); tmp = _mangle_varying_attribute (tmp2, shader_type, gl_api); g_free (tmp2); + if (shader_type == GL_FRAGMENT_SHADER && gl_api & GST_GL_API_OPENGL3) { + tmp2 = _mangle_frag_color (tmp); + g_free (tmp); + tmp = tmp2; + } _mangle_version_profile_from_gl_api (gl_api, version, profile); return tmp; } @@ -1605,6 +1623,11 @@ _create_shader (GstGLColorConvert * convert) if (info->templ->uniforms) g_string_append (str, info->templ->uniforms); + if (gl_api & GST_GL_API_OPENGL3) { + g_string_append_c (str, '\n'); + g_string_append (str, "out vec4 fragColor;\n"); + } + for (i = 0; i < MAX_FUNCTIONS; i++) { if (info->templ->functions[i] == NULL) break;