[vlc-devel] [PATCH v2] opengl: insert shader headers at compile time

Romain Vimont rom1v at videolabs.io
Wed Jun 24 11:45:28 CEST 2020


The fields were used to move the dependency to OpenGL/GLES to runtime
and avoid opengl_tex_converter_t to be compiled twice on linux. Since
they were split into interop and samplers and that the interop doesn't
generate GLSL, the runtime dependency is not useful anymore.

It is not used for dynamic adaptation of shaders to the available GLSL
version too, so remove it for now.

Somehow revert of 524a003fb01e75f81f68ab61bd55b43e97c49fe9
---
 modules/video_output/opengl/renderer.c | 31 ++++++++++++++------------
 modules/video_output/opengl/renderer.h |  6 -----
 2 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/modules/video_output/opengl/renderer.c b/modules/video_output/opengl/renderer.c
index 335ca27e48..6f7d42ee7a 100644
--- a/modules/video_output/opengl/renderer.c
+++ b/modules/video_output/opengl/renderer.c
@@ -169,12 +169,23 @@ InitStereoMatrix(GLfloat matrix_out[static 3*3],
 #undef ROW
 }
 
+/* https://en.wikipedia.org/wiki/OpenGL_Shading_Language#Versions */
+#ifdef USE_OPENGL_ES2
+# define SHADER_VERSION "#version 100\n"
+  /* In OpenGL ES, the fragment language has no default precision qualifier for
+   * floating point types. */
+# define FRAGMENT_SHADER_PRECISION "precision highp float;\n"
+#else
+# define SHADER_VERSION "#version 120\n"
+# define FRAGMENT_SHADER_PRECISION
+#endif
+
 static char *
 BuildVertexShader(const struct vlc_gl_renderer *renderer)
 {
     /* Basic vertex shader */
     static const char *template =
-        "#version %u\n"
+        SHADER_VERSION
         "attribute vec2 PicCoordsIn;\n"
         "varying vec2 PicCoords;\n"
         "attribute vec3 VertexPosition;\n"
@@ -188,8 +199,8 @@ BuildVertexShader(const struct vlc_gl_renderer *renderer)
         "               * vec4(VertexPosition, 1.0);\n"
         "}";
 
-    char *code;
-    if (asprintf(&code, template, renderer->glsl_version) < 0)
+    char *code = strdup(template);
+    if (!code)
         return NULL;
 
     if (renderer->dump_shaders)
@@ -204,9 +215,9 @@ BuildFragmentShader(struct vlc_gl_renderer *renderer)
     struct vlc_gl_sampler *sampler = renderer->sampler;
 
     static const char *template =
-        "#version %u\n"
+        SHADER_VERSION
         "%s" /* extensions */
-        "%s" /* precision header */
+        FRAGMENT_SHADER_PRECISION
         "%s" /* vlc_texture definition */
         "varying vec2 PicCoords;\n"
         "void main() {\n"
@@ -217,8 +228,7 @@ BuildFragmentShader(struct vlc_gl_renderer *renderer)
                            ? sampler->shader.extensions : "";
 
     char *code;
-    int ret = asprintf(&code, template, renderer->glsl_version, extensions,
-                       renderer->glsl_precision_header, sampler->shader.body);
+    int ret = asprintf(&code, template, extensions, sampler->shader.body);
     if (ret < 0)
         return NULL;
 
@@ -328,13 +338,6 @@ vlc_gl_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
     renderer->api = api;
     renderer->vt = vt;
     renderer->dump_shaders = var_InheritInteger(gl, "verbose") >= 4;
-#if defined(USE_OPENGL_ES2)
-    renderer->glsl_version = 100;
-    renderer->glsl_precision_header = "precision highp float;\n";
-#else
-    renderer->glsl_version = 120;
-    renderer->glsl_precision_header = "";
-#endif
 
     int ret = opengl_link_program(renderer);
     if (ret != VLC_SUCCESS)
diff --git a/modules/video_output/opengl/renderer.h b/modules/video_output/opengl/renderer.h
index 6f4029504f..7130cfb262 100644
--- a/modules/video_output/opengl/renderer.h
+++ b/modules/video_output/opengl/renderer.h
@@ -50,12 +50,6 @@ struct vlc_gl_renderer
     /* True to dump shaders */
     bool dump_shaders;
 
-    /* GLSL version, set by the caller. 100 for GLSL ES, 120 for desktop GLSL */
-    unsigned glsl_version;
-    /* Precision header, set by the caller. In OpenGLES, the fragment language
-     * has no default precision qualifier for floating point types. */
-    const char *glsl_precision_header;
-
     GLuint program_id;
 
     struct {
-- 
2.27.0



More information about the vlc-devel mailing list