[vlc-devel] [PATCH 07/13] opengl: extract sampler and texture lookup names

Romain Vimont rom1v at videolabs.io
Fri Mar 5 13:34:44 UTC 2021


The type and function to use depends on the texture target.

Extract the mapping to a separate function to be able to reuse it.
---
 modules/video_output/opengl/sampler.c | 40 +++++++++++++++------------
 1 file changed, 23 insertions(+), 17 deletions(-)

diff --git a/modules/video_output/opengl/sampler.c b/modules/video_output/opengl/sampler.c
index 4a928690bc..6dea5204a0 100644
--- a/modules/video_output/opengl/sampler.c
+++ b/modules/video_output/opengl/sampler.c
@@ -715,6 +715,28 @@ InitOrientationMatrix(GLfloat matrix[static 4*4],
     }
 }
 
+static void
+GetNames(GLenum tex_target, const char **glsl_sampler, const char **texture)
+{
+    switch (tex_target)
+    {
+        case GL_TEXTURE_EXTERNAL_OES:
+            *glsl_sampler = "samplerExternalOES";
+            *texture = "texture2D";
+            break;
+        case GL_TEXTURE_2D:
+            *glsl_sampler = "sampler2D";
+            *texture = "texture2D";
+            break;
+        case GL_TEXTURE_RECTANGLE:
+            *glsl_sampler = "sampler2DRect";
+            *texture = "texture2DRect";
+            break;
+        default:
+            vlc_assert_unreachable();
+    }
+}
+
 static int
 opengl_fragment_shader_init(struct vlc_gl_sampler *sampler, GLenum tex_target,
                             const video_format_t *fmt)
@@ -754,23 +776,7 @@ opengl_fragment_shader_init(struct vlc_gl_sampler *sampler, GLenum tex_target,
     }
 
     const char *glsl_sampler, *lookup;
-    switch (tex_target)
-    {
-        case GL_TEXTURE_EXTERNAL_OES:
-            glsl_sampler = "samplerExternalOES";
-            lookup = "texture2D";
-            break;
-        case GL_TEXTURE_2D:
-            glsl_sampler = "sampler2D";
-            lookup  = "texture2D";
-            break;
-        case GL_TEXTURE_RECTANGLE:
-            glsl_sampler = "sampler2DRect";
-            lookup  = "texture2DRect";
-            break;
-        default:
-            vlc_assert_unreachable();
-    }
+    GetNames(tex_target, &glsl_sampler, &lookup);
 
     struct vlc_memstream ms;
     if (vlc_memstream_open(&ms) != 0)
-- 
2.30.1



More information about the vlc-devel mailing list