[vlc-devel] [PATCH 32/41] opengl: generate the extensions from the sampler

Romain Vimont rom1v at videolabs.io
Fri Feb 7 17:42:18 CET 2020


The sampler handles the input pictures, so it is also responsible for
generating the necessary GLSL extensions code (if any).
---
 modules/video_output/opengl/fragment_shaders.c | 7 +++++++
 modules/video_output/opengl/renderer.c         | 6 ++----
 modules/video_output/opengl/sampler.c          | 2 ++
 modules/video_output/opengl/sampler.h          | 7 +++++++
 4 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/modules/video_output/opengl/fragment_shaders.c b/modules/video_output/opengl/fragment_shaders.c
index eb84a9ec0f..c07bf55c0e 100644
--- a/modules/video_output/opengl/fragment_shaders.c
+++ b/modules/video_output/opengl/fragment_shaders.c
@@ -667,6 +667,13 @@ opengl_fragment_shader_init(struct vlc_gl_sampler *sampler, GLenum tex_target,
     if (vlc_memstream_close(&ms) != 0)
         return VLC_EGENERIC;
 
+    if (interop->tex_target == GL_TEXTURE_EXTERNAL_OES)
+    {
+        sampler->shader.extensions =
+            strdup("#extension GL_OES_EGL_image_external : require\n");
+        if (!sampler->shader.extensions)
+            return VLC_EGENERIC;
+    }
     sampler->shader.body = ms.ptr;
 
     sampler->pf_fetch_locations = sampler_base_fetch_locations;
diff --git a/modules/video_output/opengl/renderer.c b/modules/video_output/opengl/renderer.c
index 9440238080..942b8f3355 100644
--- a/modules/video_output/opengl/renderer.c
+++ b/modules/video_output/opengl/renderer.c
@@ -287,10 +287,8 @@ BuildFragmentShader(struct vlc_gl_renderer *renderer)
         " gl_FragColor = vlc_texture(PicCoords);\n"
         "}\n";
 
-    /* TODO move extensions back to fragment_shaders.c */
-    const char *extensions = interop->tex_target == GL_TEXTURE_EXTERNAL_OES
-                           ? "#extension GL_OES_EGL_image_external : require\n"
-                           : "";
+    const char *extensions = sampler->shader.extensions
+                           ? sampler->shader.extensions : "";
 
     char *code;
     ret = asprintf(&code, template, renderer->glsl_version, extensions,
diff --git a/modules/video_output/opengl/sampler.c b/modules/video_output/opengl/sampler.c
index 915f8c19c5..2ddee0f407 100644
--- a/modules/video_output/opengl/sampler.c
+++ b/modules/video_output/opengl/sampler.c
@@ -44,6 +44,7 @@ vlc_gl_sampler_New(struct vlc_gl_interop *interop)
     sampler->gl = interop->gl;
     sampler->vt = interop->vt;
 
+    sampler->shader.extensions = NULL;
     sampler->shader.body = NULL;
 
 #ifdef HAVE_LIBPLACEBO
@@ -105,6 +106,7 @@ vlc_gl_sampler_Delete(struct vlc_gl_sampler *sampler)
         pl_context_destroy(&sampler->pl_ctx);
 #endif
 
+    free(sampler->shader.extensions);
     free(sampler->shader.body);
 
     free(sampler);
diff --git a/modules/video_output/opengl/sampler.h b/modules/video_output/opengl/sampler.h
index 0640715a3c..a9676f4dd3 100644
--- a/modules/video_output/opengl/sampler.h
+++ b/modules/video_output/opengl/sampler.h
@@ -92,6 +92,13 @@ struct vlc_gl_sampler {
     struct vlc_gl_interop *interop;
 
     struct {
+        /* GLSL declaration for extensions.
+         *
+         * If not-NULL, it must be injected immediately after the "version"
+         * line.
+         */
+        char *extensions;
+
         /* Piece of code necessary to declare and implement the GLSL function
          * vlc_texture(vec2 coords).
          *
-- 
2.25.0



More information about the vlc-devel mailing list