[vlc-devel] [PATCH] opengl: renderer: improve cube generation

Romain Vimont rom1v at videolabs.io
Mon Jul 6 10:52:26 CEST 2020


It looks equivalent, LGTM.

On 2020-07-06 09:59, Alexandre Janniaux wrote:
> 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.
> ---
>   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 aa51f8b3a38..3a790671ce8 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), // FRONT
> +        CUBEFACE(Z_FACE, +1), // BACK
> +        CUBEFACE(X_FACE, -1), // LEFT
> +        CUBEFACE(X_FACE, +1), // RIGHT
> +        CUBEFACE(Y_FACE, -1), // BOTTOM
> +        CUBEFACE(Y_FACE, +1), // 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-devel mailing list