[vlc-commits] opengl: renderer: improve cube generation

Alexandre Janniaux git at videolan.org
Wed Jul 8 17:52:40 CEST 2020


vlc | branch: master | Alexandre Janniaux <ajanni at videolabs.io> | Sun Jul  5 19:45:25 2020 +0200| [33fdde57ea8a14c1067aa92c932694d962d7151c] | committer: Alexandre Janniaux

opengl: renderer: improve cube generation

The cube coordinates were defined one by one, giving little possibility
for readable refactoring or little explanation for those not knowing how
the cube is built.

Instead, provide a helper macro generating the coordinates and other
helper macros in order to select the correct face to generate. It will
ease future refactoring, in particular to rotate the cube.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=33fdde57ea8a14c1067aa92c932694d962d7151c
---

 modules/video_output/opengl/renderer.c | 50 ++++++++++++++--------------------
 1 file changed, 21 insertions(+), 29 deletions(-)

diff --git a/modules/video_output/opengl/renderer.c b/modules/video_output/opengl/renderer.c
index aa51f8b3a3..4563f88043 100644
--- a/modules/video_output/opengl/renderer.c
+++ b/modules/video_output/opengl/renderer.c
@@ -543,38 +543,30 @@ static int BuildCube(float padW, float padH,
         return VLC_ENOMEM;
     }
 
+#define CUBEFACE(swap, value) \
+    swap(value, -1.f,  1.f), \
+    swap(value, -1.f, -1.f), \
+    swap(value,  1.f,  1.f), \
+    swap(value,  1.f, -1.f)
+
+#define X_FACE(v, a, b) (v), (b), (a)
+#define Y_FACE(v, a, b) (a), (v), (b)
+#define Z_FACE(v, a, b) (a), (b), (v)
+
     static const GLfloat coord[] = {
-        -1.0,    1.0,    -1.0f, // front
-        -1.0,    -1.0,   -1.0f,
-        1.0,     1.0,    -1.0f,
-        1.0,     -1.0,   -1.0f,
-
-        -1.0,    1.0,    1.0f, // back
-        -1.0,    -1.0,   1.0f,
-        1.0,     1.0,    1.0f,
-        1.0,     -1.0,   1.0f,
-
-        -1.0,    1.0,    -1.0f, // left
-        -1.0,    -1.0,   -1.0f,
-        -1.0,     1.0,    1.0f,
-        -1.0,     -1.0,   1.0f,
-
-        1.0f,    1.0,    -1.0f, // right
-        1.0f,   -1.0,    -1.0f,
-        1.0f,   1.0,     1.0f,
-        1.0f,   -1.0,    1.0f,
-
-        -1.0,    -1.0,    1.0f, // bottom
-        -1.0,    -1.0,   -1.0f,
-        1.0,     -1.0,    1.0f,
-        1.0,     -1.0,   -1.0f,
-
-        -1.0,    1.0,    1.0f, // top
-        -1.0,    1.0,   -1.0f,
-        1.0,     1.0,    1.0f,
-        1.0,     1.0,   -1.0f,
+        CUBEFACE(Z_FACE, -1.f), // FRONT
+        CUBEFACE(Z_FACE, +1.f), // BACK
+        CUBEFACE(X_FACE, -1.f), // LEFT
+        CUBEFACE(X_FACE, +1.f), // RIGHT
+        CUBEFACE(Y_FACE, -1.f), // BOTTOM
+        CUBEFACE(Y_FACE, +1.f), // TOP
     };
 
+#undef X_FACE
+#undef Y_FACE
+#undef Z_FACE
+#undef CUBEFACE
+
     memcpy(*vertexCoord, coord, *nbVertices * 3 * sizeof(GLfloat));
 
     float col[] = {0.f, 1.f/3, 2.f/3, 1.f};



More information about the vlc-commits mailing list