glshader: fix default external-oes shaders
authorMatthew Waters <matthew@centricular.com>
Tue, 7 May 2019 08:36:01 +0000 (18:36 +1000)
committerTim-Philipp Müller <tim@centricular.com>
Thu, 8 Aug 2019 10:00:16 +0000 (11:00 +0100)
In glsl, #extension directives need to before other non-preprocesser
directives.  We were placing the precision qualifier before that.  Fix
by moving the #extension to the first line in the shader.

Fixes: https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/issues/601

gst-libs/gst/gl/gstglshaderstrings.c

index 4d7ac3d..ecc5da1 100644 (file)
@@ -84,8 +84,10 @@ const gchar *gst_gl_shader_string_fragment_default =
     MEDIUMP_PRECISION
     DEFAULT_FRAGMENT_BODY;
 
+#define EXTERNAL_FRAGMENT_HEADER \
+    "#extension GL_OES_EGL_image_external : require\n"
+
 #define EXTERNAL_FRAGMENT_BODY \
-    "#extension GL_OES_EGL_image_external : require\n" \
     "varying vec2 v_texcoord;\n" \
     "uniform samplerExternalOES tex;\n" \
     "void main()\n" \
@@ -93,6 +95,7 @@ const gchar *gst_gl_shader_string_fragment_default =
     "  gl_FragColor = texture2D(tex, v_texcoord);\n" \
     "}"
 const gchar *gst_gl_shader_string_fragment_external_oes_default =
+    EXTERNAL_FRAGMENT_HEADER
     MEDIUMP_PRECISION
     EXTERNAL_FRAGMENT_BODY;
 /* *INDENT-ON* */
@@ -168,5 +171,6 @@ gst_gl_shader_string_fragment_external_oes_get_default (GstGLContext * context,
   const gchar *precision =
       gst_gl_shader_string_get_highest_precision (context, version, profile);
 
-  return g_strdup_printf ("%s%s", precision, EXTERNAL_FRAGMENT_BODY);
+  return g_strdup_printf ("%s%s%s", EXTERNAL_FRAGMENT_HEADER, precision,
+      EXTERNAL_FRAGMENT_BODY);
 }