diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-08-20 10:23:49 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-08-20 10:26:51 +0300 |
commit | 8037f3602f12080a1692746e5ee0b6c46c7c3d76 (patch) | |
tree | cbad4e4bffc75d264b21f2c9133ad28f22bd78de /source/blender/gpu | |
parent | 33b265c4fb532523b8707d99799bf36b25b7b1e3 (diff) |
PyAPI: Add exceptions to stack push/pop
Raise exception when stack limits are reached.
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/GPU_matrix.h | 10 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_matrix.c | 23 |
2 files changed, 33 insertions, 0 deletions
diff --git a/source/blender/gpu/GPU_matrix.h b/source/blender/gpu/GPU_matrix.h index 219c7b1c6c1..4e136ed34b2 100644 --- a/source/blender/gpu/GPU_matrix.h +++ b/source/blender/gpu/GPU_matrix.h @@ -113,6 +113,16 @@ const float (*gpuGetNormalMatrixInverse(float m[3][3]))[3]; void gpuBindMatrices(const Gwn_ShaderInterface*); bool gpuMatricesDirty(void); /* since last bind */ + +/* Python API needs to be able to inspect the stack so errors raise exceptions instead of crashing. */ +#ifdef USE_GPU_PY_MATRIX_API +int GPU_matrix_stack_level_get_model_view(void); +int GPU_matrix_stack_level_get_projection(void); +/* static assert ensures this doesn't change! */ +#define GPU_PY_MATRIX_STACK_LEN 31 +#endif /* USE_GPU_PY_MATRIX_API */ + + #ifdef __cplusplus } #endif diff --git a/source/blender/gpu/intern/gpu_matrix.c b/source/blender/gpu/intern/gpu_matrix.c index f03a076a9fd..7f024a18ba7 100644 --- a/source/blender/gpu/intern/gpu_matrix.c +++ b/source/blender/gpu/intern/gpu_matrix.c @@ -30,7 +30,9 @@ */ #define SUPPRESS_GENERIC_MATRIX_API +#define USE_GPU_PY_MATRIX_API /* only so values are declared */ #include "GPU_matrix.h" +#undef USE_GPU_PY_MATRIX_API #include "BLI_math_matrix.h" #include "BLI_math_rotation.h" @@ -622,3 +624,24 @@ bool gpuMatricesDirty(void) { return state.dirty; } + + +/* -------------------------------------------------------------------- */ + +/** \name Python API Helpers + * \{ */ +BLI_STATIC_ASSERT(GPU_PY_MATRIX_STACK_LEN + 1 == MATRIX_STACK_DEPTH, "define mismatch"); + +/* Return int since caller is may subtract. */ + +int GPU_matrix_stack_level_get_model_view(void) +{ + return (int)state.model_view_stack.top; +} + +int GPU_matrix_stack_level_get_projection(void) +{ + return (int)state.projection_stack.top; +} + +/** \} */ |