OpenGL: generic inputs for new matrix API

For functions that expect a 4x4 matrix, you can pass in that, or array[16], or float*, or... Casting at each call site can get annoying, and obscures the logic.

The C11 section still needs work, but the non-C11 macros help on the system I tested on (Mac/clang).

Part of T49450
This commit is contained in:
Mike Erwin
2017-03-21 17:27:17 -04:00
parent 20d02be6b8
commit 7aad5cf573
3 changed files with 42 additions and 27 deletions

View File

@@ -48,33 +48,6 @@
* */
void cpack(unsigned int x);
#ifdef WITH_GL_PROFILE_COMPAT
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
# define glMultMatrixf(x) \
glMultMatrixf(_Generic((x), \
float *: (float *)(x), \
float [16]: (float *)(x), \
float (*)[4]: (float *)(x), \
float [4][4]: (float *)(x), \
const float *: (float *)(x), \
const float [16]: (float *)(x), \
const float (*)[4]: (float *)(x), \
const float [4][4]: (float *)(x)) \
)
# define glLoadMatrixf(x) \
glLoadMatrixf(_Generic((x), \
float *: (float *)(x), \
float [16]: (float *)(x), \
float (*)[4]: (float *)(x), \
float [4][4]: (float *)(x)) \
)
#else
# define glMultMatrixf(x) glMultMatrixf((float *)(x))
# define glLoadMatrixf(x) glLoadMatrixf((float *)(x))
#endif /* C11 */
#endif /* WITH_GL_PROFILE_COMPAT */
/* hacking pointsize and linewidth */
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
# define glPointSize(f) glPointSize(U.pixelsize * _Generic((f), double: (float)(f), default: (f)))

View File

@@ -143,4 +143,45 @@ bool gpuMatricesDirty(void); /* since last bind */
}
#endif
#ifndef SUPPRESS_GENERIC_MATRIX_API
/* make matrix inputs generic, to avoid warnings */
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
# define gpuMultMatrix3D(x) \
gpuMultMatrix3D(_Generic((x), \
float *: (const float (*)[4])(x), \
float [16]: (const float (*)[4])(x), \
float (*)[4]: (const float (*)[4])(x), \
float [4][4]: (const float (*)[4])(x), \
const float *: (const float (*)[4])(x), \
const float [16]: (const float (*)[4])(x), \
const float (*)[4]: (const float (*)[4])(x), \
const float [4][4]: (const float (*)[4])(x)) \
)
# define gpuLoadMatrix3D(x) \
gpuLoadMatrix3D(_Generic((x), \
float *: (const float (*)[4])(x), \
float [16]: (const float (*)[4])(x), \
float (*)[4]: (const float (*)[4])(x), \
float [4][4]: (const float (*)[4])(x), \
const float *: (const float (*)[4])(x), \
const float [16]: (const float (*)[4])(x), \
const float (*)[4]: (const float (*)[4])(x), \
const float [4][4]: (const float (*)[4])(x)) \
)
/* TODO: finish this in a simpler way --^ */
#else
# define gpuMultMatrix3D(x) gpuMultMatrix3D((const float (*)[4])(x))
# define gpuLoadMatrix3D(x) gpuLoadMatrix3D((const float (*)[4])(x))
# define gpuMultMatrix2D(x) gpuMultMatrix2D((const float (*)[3])(x))
# define gpuLoadMatrix2D(x) gpuLoadMatrix2D((const float (*)[3])(x))
# define gpuGetModelViewMatrix3D(x) gpuGetModelViewMatrix3D((float (*)[4])(x))
# define gpuGetProjectionMatrix3D(x) gpuGetProjectionMatrix3D((float (*)[4])(x))
# define gpuGetModelViewProjectionMatrix3D(x) gpuGetModelViewProjectionMatrix3D((float (*)[4])(x))
# define gpuGetNormalMatrix(x) gpuGetNormalMatrix((float (*)[3])(x))
# define gpuGetNormalMatrixInverse(x) gpuGetNormalMatrixInverse((float (*)[3])(x))
#endif /* C11 */
#endif /* SUPPRESS_GENERIC_MATRIX_API */
#endif /* GPU_MATRIX_H */

View File

@@ -29,6 +29,7 @@
* \ingroup gpu
*/
#define SUPPRESS_GENERIC_MATRIX_API
#include "GPU_matrix.h"
#include "BLI_math_matrix.h"