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:
@@ -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)))
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
* \ingroup gpu
|
||||
*/
|
||||
|
||||
#define SUPPRESS_GENERIC_MATRIX_API
|
||||
#include "GPU_matrix.h"
|
||||
|
||||
#include "BLI_math_matrix.h"
|
||||
|
||||
Reference in New Issue
Block a user