[vlc-devel] [PATCH 04/10] opengl: move sampler initialization to constructor

Romain Vimont rom1v at videolabs.io
Wed May 20 16:08:15 CEST 2020


Move opengl_fragment_shader_init() call from renderer to sampler.

This function initializes parts of the sampler.
---
 modules/video_output/opengl/renderer.c | 10 ++--------
 modules/video_output/opengl/sampler.c  | 17 ++++++++++++++---
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/modules/video_output/opengl/renderer.c b/modules/video_output/opengl/renderer.c
index 97653a3ad501..a8f71fea037a 100644
--- a/modules/video_output/opengl/renderer.c
+++ b/modules/video_output/opengl/renderer.c
@@ -270,12 +270,6 @@ BuildFragmentShader(struct vlc_gl_renderer *renderer)
 {
     struct vlc_gl_sampler *sampler = renderer->sampler;
     const struct vlc_gl_interop *interop = sampler->interop;
-    int ret =
-        opengl_fragment_shader_init(sampler, interop->tex_target,
-                                    interop->sw_fmt.i_chroma,
-                                    interop->sw_fmt.space);
-    if (ret != VLC_SUCCESS)
-        return NULL;
 
     static const char *template =
         "#version %u\n"
@@ -291,8 +285,8 @@ BuildFragmentShader(struct vlc_gl_renderer *renderer)
                            ? sampler->shader.extensions : "";
 
     char *code;
-    ret = asprintf(&code, template, renderer->glsl_version, extensions,
-                   renderer->glsl_precision_header, sampler->shader.body);
+    int ret = asprintf(&code, template, renderer->glsl_version, extensions,
+                       renderer->glsl_precision_header, sampler->shader.body);
     if (ret < 0)
         return NULL;
 
diff --git a/modules/video_output/opengl/sampler.c b/modules/video_output/opengl/sampler.c
index 8b20e4d2e012..a3f1405bd704 100644
--- a/modules/video_output/opengl/sampler.c
+++ b/modules/video_output/opengl/sampler.c
@@ -37,6 +37,7 @@
 #include "gl_api.h"
 #include "gl_common.h"
 #include "gl_util.h"
+#include "internal.h"
 #include "interop.h"
 
 struct vlc_gl_sampler *
@@ -81,6 +82,16 @@ vlc_gl_sampler_New(struct vlc_gl_interop *interop)
     }
 #endif
 
+    int ret =
+        opengl_fragment_shader_init(sampler, interop->tex_target,
+                                    interop->sw_fmt.i_chroma,
+                                    interop->sw_fmt.space);
+    if (ret != VLC_SUCCESS)
+    {
+        free(sampler);
+        return NULL;
+    }
+
     /* Texture size */
     for (unsigned j = 0; j < interop->tex_count; j++) {
         const GLsizei w = interop->fmt.i_visible_width  * interop->texs[j].w.num
@@ -98,9 +109,9 @@ vlc_gl_sampler_New(struct vlc_gl_interop *interop)
 
     if (!interop->handle_texs_gen)
     {
-        int ret = vlc_gl_interop_GenerateTextures(interop, sampler->tex_width,
-                                                  sampler->tex_height,
-                                                  sampler->textures);
+        ret = vlc_gl_interop_GenerateTextures(interop, sampler->tex_width,
+                                              sampler->tex_height,
+                                              sampler->textures);
         if (ret != VLC_SUCCESS)
         {
             free(sampler);
-- 
2.27.0.rc0



More information about the vlc-devel mailing list