glcolorconvert: mangle gl_FragColor for GL3
authorMatthew Waters <matthew@centricular.com>
Wed, 11 Nov 2015 12:39:35 +0000 (23:39 +1100)
committerMatthew Waters <matthew@centricular.com>
Wed, 11 Nov 2015 12:42:02 +0000 (23:42 +1100)
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

index d14fed9..abd817c 100644 (file)
@@ -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;