[vlc-commits] opengl: generate the extensions from the sampler
Romain Vimont
git at videolan.org
Thu Jun 4 11:04:36 CEST 2020
vlc | branch: master | Romain Vimont <rom1v at videolabs.io> | Wed Feb 5 17:03:42 2020 +0100| [a10c00e335224eb6a9ce0bf2bf4a3d7286154b89] | committer: Alexandre Janniaux
opengl: generate the extensions from the sampler
The sampler handles the input pictures, so it is also responsible for
generating the necessary GLSL extensions code (if any).
Signed-off-by: Alexandre Janniaux <ajanni at videolabs.io>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a10c00e335224eb6a9ce0bf2bf4a3d7286154b89
---
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 | 11 +++++++++++
4 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/modules/video_output/opengl/fragment_shaders.c b/modules/video_output/opengl/fragment_shaders.c
index 228ab7fd8b..a379b9d754 100644
--- a/modules/video_output/opengl/fragment_shaders.c
+++ b/modules/video_output/opengl/fragment_shaders.c
@@ -710,6 +710,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 095245f6e5..97653a3ad5 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 42f9851de9..8b20e4d2e0 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 e69f0c1885..ec5b041401 100644
--- a/modules/video_output/opengl/sampler.h
+++ b/modules/video_output/opengl/sampler.h
@@ -91,6 +91,17 @@ struct vlc_gl_sampler {
struct vlc_gl_interop *interop;
struct {
+ /**
+ * Piece of fragment shader code declaration OpenGL extensions.
+ *
+ * It is initialized by the sampler, and may be NULL if no extensions
+ * are required.
+ *
+ * If non-NULL, users of this sampler must inject this provided code
+ * into their fragment shader, immediately after the "version" line.
+ */
+ char *extensions;
+
/**
* Piece of fragment shader code providing the GLSL function
* vlc_texture(vec2 coords).
More information about the vlc-commits
mailing list