diff options
author | Mike Erwin <significant.bit@gmail.com> | 2017-03-22 00:27:17 +0300 |
---|---|---|
committer | Mike Erwin <significant.bit@gmail.com> | 2017-03-22 00:27:17 +0300 |
commit | 7aad5cf573a964753b37573c5a2ea12af5d5952a (patch) | |
tree | ef9cbae18c8240000ad6fb13822db3ebdcfed968 /source/blender/gpu/GPU_matrix.h | |
parent | 20d02be6b81db1bb99df1e82cff1c2575db40ae4 (diff) |
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
Diffstat (limited to 'source/blender/gpu/GPU_matrix.h')
-rw-r--r-- | source/blender/gpu/GPU_matrix.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/source/blender/gpu/GPU_matrix.h b/source/blender/gpu/GPU_matrix.h index 5af8e69a693..dd65d39822c 100644 --- a/source/blender/gpu/GPU_matrix.h +++ b/source/blender/gpu/GPU_matrix.h @@ -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 */ |