[vlc-devel] [PATCH 08/41] opengl: apply orientation in fragment shader

Romain Vimont rom1v at videolabs.io
Fri Feb 7 17:41:54 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, 7 insertions(+), 5 deletions(-)

diff --git a/modules/video_output/opengl/fragment_shaders.c b/modules/video_output/opengl/fragment_shaders.c
index 259da9d600..51c5ca6055 100644
--- a/modules/video_output/opengl/fragment_shaders.c
+++ b/modules/video_output/opengl/fragment_shaders.c
@@ -492,7 +492,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);
@@ -588,8 +590,10 @@ opengl_fragment_shader_init(struct vlc_gl_renderer *renderer, GLenum tex_target,
 
     ADD("uniform vec4 FillColor;\n"
         "void main(void) {\n");
+    /* Oriented picture coordinates */
+    ADDF(" vec2 pic_txcoords = (TransformMatrix * OrientationMatrix * vec4(%s, 0.0, 1.0)).st;\n", coord_name);
     /* Homogeneous coordinates */
-    ADDF(" vec3 pic_hcoords = vec3(%s, 1.0);\n", coord_name);
+    ADD(" vec3 pic_hcoords = vec3(pic_txcoords, 1.0);\n");
     ADD(" vec2 tex_coords;\n");
 
     if (tex_target == GL_TEXTURE_RECTANGLE)
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.0



More information about the vlc-devel mailing list