PyAPI: Add exceptions to stack push/pop

Raise exception when stack limits are reached.
This commit is contained in:
2017-08-20 17:23:49 +10:00
parent 33b265c4fb
commit 8037f3602f
3 changed files with 67 additions and 6 deletions

View File

@@ -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

View File

@@ -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;
}
/** \} */