[vlc-devel] [PATCH 11/16] opengl: apply orientation in fragment shader

Romain Vimont rom1v at videolabs.io
Tue Mar 17 17:26:44 CET 2020


Apply all texture coordinates transformation in the fragment shader.

This is necessary to be able to implement a renderer independent of the
input picture (i.e. without even knowing the details) by using a single
GLSL function "vlc_texture(vec2 pic_coords)".
---
 modules/video_output/opengl/fragment_shaders.c | 8 +++++---
 modules/video_output/opengl/renderer.c         | 4 +---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/modules/video_output/opengl/fragment_shaders.c b/modules/video_output/opengl/fragment_shaders.c
index e245af4f9a..c228712865 100644
--- a/modules/video_output/opengl/fragment_shaders.c
+++ b/modules/video_output/opengl/fragment_shaders.c
@@ -488,7 +488,9 @@ opengl_fragment_shader_init(struct vlc_gl_renderer *renderer, GLenum tex_target,
 
     ADDF("%s", renderer->glsl_precision_header);
 
-    ADD("varying vec2 PicCoords;\n");
+    ADD("varying vec2 PicCoords;\n"
+        "uniform mat4 TransformMatrix;\n"
+        "uniform mat4 OrientationMatrix;\n");
     for (unsigned i = 0; i < interop->tex_count; ++i)
         ADDF("uniform %s Texture%u;\n"
              "uniform mat3 TexCoordsMap%u;\n", sampler, i, i);
@@ -585,8 +587,8 @@ opengl_fragment_shader_init(struct vlc_gl_renderer *renderer, GLenum tex_target,
 
     ADD("uniform vec4 FillColor;\n"
         "void main(void) {\n"
-        /* Homogeneous coordinates */
-        " vec3 pic_hcoords = vec3(PicCoords, 1.0);\n"
+        /* Homogeneous (oriented) coordinates */
+        " vec3 pic_hcoords = vec3((TransformMatrix * OrientationMatrix * vec4(PicCoords, 0.0, 1.0)).st, 1.0);\n"
         " vec2 tex_coords;\n");
 
     unsigned color_count;
diff --git a/modules/video_output/opengl/renderer.c b/modules/video_output/opengl/renderer.c
index 53f6d4c342..6d90e7ebcb 100644
--- a/modules/video_output/opengl/renderer.c
+++ b/modules/video_output/opengl/renderer.c
@@ -178,13 +178,11 @@ BuildVertexShader(const struct vlc_gl_renderer *renderer)
         "attribute vec2 PicCoordsIn;\n"
         "varying vec2 PicCoords;\n"
         "attribute vec3 VertexPosition;\n"
-        "uniform mat4 TransformMatrix;\n"
-        "uniform mat4 OrientationMatrix;\n"
         "uniform mat4 ProjectionMatrix;\n"
         "uniform mat4 ZoomMatrix;\n"
         "uniform mat4 ViewMatrix;\n"
         "void main() {\n"
-        " PicCoords = vec4(TransformMatrix * OrientationMatrix * vec4(PicCoordsIn, 0.0, 1.0)).st;\n"
+        " PicCoords = PicCoordsIn;\n"
         " gl_Position = ProjectionMatrix * ZoomMatrix * ViewMatrix\n"
         "               * vec4(VertexPosition, 1.0);\n"
         "}";
-- 
2.25.1



More information about the vlc-devel mailing list