[vlc-devel] [PATCH 03/10] opengl: generate the extensions from the sampler
Romain Vimont
rom1v at videolabs.io
Wed May 20 16:08:14 CEST 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 | 10 ++++++++++
modules/video_output/opengl/renderer.c | 6 ++----
modules/video_output/opengl/sampler.c | 2 ++
modules/video_output/opengl/sampler.h | 7 +++++++
4 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/modules/video_output/opengl/fragment_shaders.c b/modules/video_output/opengl/fragment_shaders.c
index a85b6e409101..c775daa050b1 100644
--- a/modules/video_output/opengl/fragment_shaders.c
+++ b/modules/video_output/opengl/fragment_shaders.c
@@ -707,6 +707,16 @@ opengl_fragment_shader_init(struct vlc_gl_sampler *sampler, GLenum tex_target,
if (vlc_memstream_close(&ms) != 0)
return VLC_EGENERIC;
+ if (tex_target == GL_TEXTURE_EXTERNAL_OES)
+ {
+ sampler->shader.extensions =
+ strdup("#extension GL_OES_EGL_image_external : require\n");
+ if (!sampler->shader.extensions)
+ {
+ free(ms.ptr);
+ 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 095245f6e51f..97653a3ad501 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 42f9851de94b..8b20e4d2e012 100644
--- a/modules/video_output/opengl/sampler.c
+++ b/modules/video_output/opengl/sampler.c
@@ -55,6 +55,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
@@ -125,6 +126,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 9b0614403ff8..93af7b1759d1 100644
--- a/modules/video_output/opengl/sampler.h
+++ b/modules/video_output/opengl/sampler.h
@@ -91,6 +91,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.27.0.rc0
More information about the vlc-devel
mailing list