[vlc-commits] d3d11: quad: improve cube generation

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


vlc | branch: master | Alexandre Janniaux <ajanni at videolabs.io> | Wed Jul  8 11:27:14 2020 +0200| [ec0b151f397bf4470f58aa55daa9f7b2068113a4] | committer: Alexandre Janniaux

d3d11: quad: 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=ec0b151f397bf4470f58aa55daa9f7b2068113a4
---

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

diff --git a/modules/video_output/win32/d3d11_quad.c b/modules/video_output/win32/d3d11_quad.c
index 8ec8f16e27..cf747db09d 100644
--- a/modules/video_output/win32/d3d11_quad.c
+++ b/modules/video_output/win32/d3d11_quad.c
@@ -462,38 +462,30 @@ static void SetupQuadSphere(d3d_vertex_t *dst_data, const RECT *output,
 static void SetupQuadCube(d3d_vertex_t *dst_data, const RECT *output,
                           const d3d_quad_t *quad, WORD *triangle_pos)
 {
+#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 float 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
+
     const float scaleX = (float)(output->right - output->left) / quad->i_width;
     const float scaleY = (float)(output->bottom - output->top) / quad->i_height;
 



More information about the vlc-commits mailing list