[vlc-commits] [Git][videolan/vlc][master] vout: opengl: fix shader compilation

Steve Lhomme (@robUx4) gitlab at videolan.org
Tue Jun 24 12:08:25 UTC 2025



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
78c4ce60 by François Cartegnie at 2025-06-24T11:51:00+00:00
vout: opengl: fix shader compilation

GLSL 100 does not support sampler3D.
Shader only uses a sampler2D.

- - - - -


4 changed files:

- modules/video_output/opengl/gl_api.c
- modules/video_output/opengl/gl_api.h
- modules/video_output/opengl/sampler.c
- modules/video_output/opengl/sampler.h


Changes:

=====================================
modules/video_output/opengl/gl_api.c
=====================================
@@ -202,5 +202,15 @@ vlc_gl_api_Init(struct vlc_gl_api *api, vlc_gl_t *gl)
             api->glsl_version = 120;
     }
 
+    if (api->is_gles)
+    {
+        if (api->glsl_version < 300)
+            api->supports_sampler3D = vlc_gl_HasExtension(&extension_vt, "GL_OES_texture_3D");
+        else
+            api->supports_sampler3D = true;
+    }
+    else
+        api->supports_sampler3D = false;
+
     return VLC_SUCCESS;
 }


=====================================
modules/video_output/opengl/gl_api.h
=====================================
@@ -46,6 +46,9 @@ struct vlc_gl_api {
 
     /* Multisampling for anti-aliasing */
     bool supports_multisample;
+
+    /* sampler3D feature and syntax support */
+    bool supports_sampler3D;
 };
 
 int


=====================================
modules/video_output/opengl/sampler.c
=====================================
@@ -581,17 +581,24 @@ InitShaderExtensions(struct vlc_gl_sampler *sampler, GLenum tex_target)
     const char *ext_yuv_target =
         "#extension GL_EXT_YUV_target : require\n";
 
+    const char *image_ext = "";
     if (tex_target == GL_TEXTURE_EXTERNAL_OES)
     {
         if (is_yuv)
-            sampler->shader.extensions = strdup(ext_yuv_target);
+            image_ext = ext_yuv_target;
         else
-            sampler->shader.extensions = strdup(image_external);
-        if (!sampler->shader.extensions)
-            return VLC_EGENERIC;
+            image_ext = image_external;
+    }
+
+    int ret = asprintf(&sampler->shader.extensions,
+        "#extension GL_OES_texture_3D : enable\n"
+        "%s", image_ext);
+    if (ret <= 0)
+    {
+        if (ret == 0)
+            FREENULL(sampler->shader.extensions);
+        return VLC_EGENERIC;
     }
-    else
-        sampler->shader.extensions = NULL;
 
     return VLC_SUCCESS;
 }
@@ -1056,16 +1063,14 @@ vlc_gl_sampler_New(struct vlc_gl_t *gl, const struct vlc_gl_api *api,
 
     int glsl_version;
     if (api->is_gles) {
-#define GLES_COMMON_PRECISION \
-            "precision highp float;\n" \
-            "precision highp sampler2D;\n" \
-            "precision highp sampler3D;\n"
 
-        if (priv->unsigned_sampler)
-            sampler->shader.precision = GLES_COMMON_PRECISION
-                "precision highp usampler2D;\n";
-        else
-            sampler->shader.precision = GLES_COMMON_PRECISION;
+        if (asprintf(&sampler->shader.precision,
+            "precision highp float;\n"
+            "precision highp sampler2D;\n"
+            "%s%s",
+            api->supports_sampler3D ? "precision highp sampler3D;\n" : "",
+            priv->unsigned_sampler ? "precision highp usampler2D;\n" : "" ) <= 0 )
+            goto error;
 
         if (api->glsl_version >= 300) {
             sampler->shader.version = strdup("#version 300 es\n");
@@ -1074,8 +1079,12 @@ vlc_gl_sampler_New(struct vlc_gl_t *gl, const struct vlc_gl_api *api,
             sampler->shader.version = strdup("#version 100\n");
             glsl_version = 100;
         }
+        if (!sampler->shader.version)
+            goto error;
     } else {
-        sampler->shader.precision = "";
+        sampler->shader.precision = strdup("// no precision\n");
+        if (!sampler->shader.precision)
+            goto error;
         /* GLSL version 420+ breaks backwards compatibility with pre-GLSL 130
          * syntax, which we use in our vertex/fragment shaders. */
         glsl_version = __MIN(api->glsl_version, 410);
@@ -1160,6 +1169,7 @@ vlc_gl_sampler_Delete(struct vlc_gl_sampler *sampler)
     pl_log_destroy(&priv->pl_log);
 #endif
 
+    free(sampler->shader.precision);
     free(sampler->shader.extensions);
     free(sampler->shader.body);
     free(sampler->shader.version);


=====================================
modules/video_output/opengl/sampler.h
=====================================
@@ -97,7 +97,7 @@ struct vlc_gl_sampler {
         /**
          * Precision preamble that is appropriate for this shader.
          */
-        const char *precision;
+        char *precision;
 
         /**
          * Piece of fragment shader code declaration OpenGL extensions.



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/78c4ce60eddbda174935a8a99924d4693113f759

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/78c4ce60eddbda174935a8a99924d4693113f759
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list