[vlc-devel] [PATCH 09/17] opengl: define identity matrices in gl_util.h

Romain Vimont rom1v at videolabs.io
Thu Apr 2 14:24:22 CEST 2020


This will allow to use them from several files.
---
 modules/video_output/opengl/gl_util.h  | 13 ++++++++++++
 modules/video_output/opengl/renderer.c | 28 +++++++++-----------------
 2 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/modules/video_output/opengl/gl_util.h b/modules/video_output/opengl/gl_util.h
index 051c034d3f..a01d87c335 100644
--- a/modules/video_output/opengl/gl_util.h
+++ b/modules/video_output/opengl/gl_util.h
@@ -29,6 +29,19 @@
 #include <vlc_common.h>
 #include "gl_common.h"
 
+static const float MATRIX4_IDENTITY[4*4] = {
+    1, 0, 0, 0,
+    0, 1, 0, 0,
+    0, 0, 1, 0,
+    0, 0, 0, 1,
+};
+
+static const float MATRIX3_IDENTITY[3*3] = {
+    1, 0, 0,
+    0, 1, 0,
+    0, 0, 1,
+};
+
 /** Return the smallest larger or equal power of 2 */
 static inline unsigned vlc_align_pot(unsigned x)
 {
diff --git a/modules/video_output/opengl/renderer.c b/modules/video_output/opengl/renderer.c
index 1295e9f237..c8d1d3170d 100644
--- a/modules/video_output/opengl/renderer.c
+++ b/modules/video_output/opengl/renderer.c
@@ -44,13 +44,6 @@
 
 #define SPHERE_RADIUS 1.f
 
-static const GLfloat identity[] = {
-    1.0f, 0.0f, 0.0f, 0.0f,
-    0.0f, 1.0f, 0.0f, 0.0f,
-    0.0f, 0.0f, 1.0f, 0.0f,
-    0.0f, 0.0f, 0.0f, 1.0f
-};
-
 static void getZoomMatrix(float zoom, GLfloat matrix[static 16]) {
 
     const GLfloat m[] = {
@@ -96,9 +89,12 @@ static void getViewpointMatrixes(struct vlc_gl_renderer *renderer,
     }
     else
     {
-        memcpy(renderer->var.ProjectionMatrix, identity, sizeof(identity));
-        memcpy(renderer->var.ZoomMatrix, identity, sizeof(identity));
-        memcpy(renderer->var.ViewMatrix, identity, sizeof(identity));
+        memcpy(renderer->var.ProjectionMatrix, MATRIX4_IDENTITY,
+                                               sizeof(MATRIX4_IDENTITY));
+        memcpy(renderer->var.ZoomMatrix, MATRIX4_IDENTITY,
+                                         sizeof(MATRIX4_IDENTITY));
+        memcpy(renderer->var.ViewMatrix, MATRIX4_IDENTITY,
+                                         sizeof(MATRIX4_IDENTITY));
     }
 
 }
@@ -106,7 +102,7 @@ static void getViewpointMatrixes(struct vlc_gl_renderer *renderer,
 static void getOrientationTransformMatrix(video_orientation_t orientation,
                                           GLfloat matrix[static 16])
 {
-    memcpy(matrix, identity, sizeof(identity));
+    memcpy(matrix, MATRIX4_IDENTITY, sizeof(MATRIX4_IDENTITY));
 
     const int k_cos_pi = -1;
     const int k_cos_pi_2 = 0;
@@ -185,15 +181,11 @@ InitStereoMatrix(GLfloat matrix_out[static 3*3],
      * would be sufficient).
      */
 
+    memcpy(matrix_out, MATRIX3_IDENTITY, sizeof(MATRIX3_IDENTITY));
+
 #define COL(x) (x*3)
 #define ROW(x) (x)
 
-    /* Initialize to identity 3x3 */
-    memset(matrix_out, 0, 3 * 3 * sizeof(float));
-    matrix_out[COL(0) + ROW(0)] = 1;
-    matrix_out[COL(1) + ROW(1)] = 1;
-    matrix_out[COL(2) + ROW(2)] = 1;
-
     switch (multiview_mode)
     {
         case MULTIVIEW_STEREO_SBS:
@@ -880,7 +872,7 @@ static void DrawWithShaders(struct vlc_gl_renderer *renderer)
     if (interop->ops && interop->ops->get_transform_matrix)
         tm = interop->ops->get_transform_matrix(interop);
     if (!tm)
-        tm = identity;
+        tm = MATRIX4_IDENTITY;
 
     vt->UniformMatrix4fv(sampler->uloc.TransformMatrix, 1, GL_FALSE, tm);
 
-- 
2.26.0



More information about the vlc-devel mailing list