33 #include "../mathutils/mathutils.h"
35 #include "../generic/py_capi_utils.h"
37 #define USE_GPU_PY_MATRIX_API
39 #undef USE_GPU_PY_MATRIX_API
52 "Maximum model-view stack depth " STRINGIFY(GPU_PY_MATRIX_STACK_DEPTH)
" reached");
63 "Maximum projection stack depth " STRINGIFY(GPU_PY_MATRIX_STACK_DEPTH)
" reached");
72 PyErr_SetString(PyExc_RuntimeError,
"Minimum model-view stack depth reached");
81 PyErr_SetString(PyExc_RuntimeError,
"Minimum projection stack depth reached");
94 ".. function:: push()\n"
96 " Add to the model-view matrix stack.\n");
107 ".. function:: pop()\n"
109 " Remove the last model-view matrix from the stack.\n");
120 ".. function:: push_projection()\n"
122 " Add to the projection matrix stack.\n");
133 ".. function:: pop_projection()\n"
135 " Remove the last projection matrix from the stack.\n");
175 PyVarObject_HEAD_INIT(
NULL, 0).tp_name =
"GPUMatrixStackContext",
177 .tp_flags = Py_TPFLAGS_DEFAULT,
184 if (
self->level != -1) {
185 PyErr_SetString(PyExc_RuntimeError,
"Already in use");
213 if (
self->level == -1) {
214 fprintf(stderr,
"Not yet in use\n");
220 if (level !=
self->level) {
221 fprintf(stderr,
"Level push/pop mismatch, expected %d, got %d\n",
self->level, level);
229 if (level !=
self->level) {
230 fprintf(stderr,
"Level push/pop mismatch, expected %d, got %d",
self->level, level);
249 return (PyObject *)
ret;
253 pygpu_matrix_push_pop_doc,
254 ".. function:: push_pop()\n"
256 " Context manager to ensure balanced push/pop calls, even in the case of an error.\n");
263 pygpu_matrix_push_pop_projection_doc,
264 ".. function:: push_pop_projection()\n"
266 " Context manager to ensure balanced push/pop calls, even in the case of an error.\n");
279 ".. function:: multiply_matrix(matrix)\n"
281 " Multiply the current stack matrix.\n"
283 " :param matrix: A 4x4 matrix.\n"
284 " :type matrix: :class:`mathutils.Matrix`\n");
296 ".. function:: scale(scale)\n"
298 " Scale the current stack matrix.\n"
300 " :param scale: Scale the current stack matrix.\n"
301 " :type scale: sequence of 2 or 3 floats\n");
307 scale, 2, 3, value,
"gpu.matrix.scale(): invalid vector arg")) == -1) {
320 ".. function:: scale_uniform(scale)\n"
322 " :param scale: Scale the current stack matrix.\n"
323 " :type scale: float\n");
327 if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) {
328 PyErr_Format(PyExc_TypeError,
"expected a number, not %.200s", Py_TYPE(value)->tp_name);
336 ".. function:: translate(offset)\n"
338 " Scale the current stack matrix.\n"
340 " :param offset: Translate the current stack matrix.\n"
341 " :type offset: sequence of 2 or 3 floats\n");
347 offset, 2, 3, value,
"gpu.matrix.translate(): invalid vector arg")) == -1) {
366 ".. function:: reset()\n"
368 " Empty stack and set to identity.\n");
376 ".. function:: load_identity()\n"
378 " Empty stack and set to identity.\n");
386 ".. function:: load_matrix(matrix)\n"
388 " Load a matrix into the stack.\n"
390 " :param matrix: A 4x4 matrix.\n"
391 " :type matrix: :class:`mathutils.Matrix`\n");
403 ".. function:: load_projection_matrix(matrix)\n"
405 " Load a projection matrix into the stack.\n"
407 " :param matrix: A 4x4 matrix.\n"
408 " :type matrix: :class:`mathutils.Matrix`\n");
426 ".. function:: get_projection_matrix()\n"
428 " Return a copy of the projection matrix.\n"
430 " :return: A 4x4 projection matrix.\n"
431 " :rtype: :class:`mathutils.Matrix`\n");
440 ".. function:: get_model_view_matrix()\n"
442 " Return a copy of the model-view matrix.\n"
444 " :return: A 4x4 view matrix.\n"
445 " :rtype: :class:`mathutils.Matrix`\n");
454 ".. function:: get_normal_matrix()\n"
456 " Return a copy of the normal matrix.\n"
458 " :return: A 3x3 normal matrix.\n"
459 " :rtype: :class:`mathutils.Matrix`\n");
481 pygpu_matrix_push_projection_doc},
485 pygpu_matrix_pop_projection_doc},
489 {
"push_pop_projection",
492 pygpu_matrix_push_pop_projection_doc},
498 pygpu_matrix_multiply_matrix_doc},
503 pygpu_matrix_scale_uniform_doc},
508 {
"rotate", (PyCFunction)pygpu_matrix_rotate, METH_O, pygpu_matrix_rotate_doc},
509 {
"rotate_axis", (PyCFunction)pygpu_matrix_rotate_axis, METH_O, pygpu_matrix_rotate_axis_doc},
510 {
"look_at", (PyCFunction)pygpu_matrix_look_at, METH_O, pygpu_matrix_look_at_doc},
518 pygpu_matrix_load_identity_doc},
520 {
"load_projection_matrix",
523 pygpu_matrix_load_projection_matrix_doc},
526 {
"get_projection_matrix",
529 pygpu_matrix_get_projection_matrix_doc},
530 {
"get_model_view_matrix",
533 pygpu_matrix_get_model_view_matrix_doc},
534 {
"get_normal_matrix",
537 pygpu_matrix_get_normal_matrix_doc},
542 PyDoc_STRVAR(pygpu_matrix__tp_doc,
"This module provides access to the matrix stack.");
544 PyModuleDef_HEAD_INIT,
545 .m_name =
"gpu.matrix",
546 .m_doc = pygpu_matrix__tp_doc,
#define BLI_assert_unreachable()
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
void GPU_matrix_pop(void)
#define GPU_matrix_normal_get(x)
void GPU_matrix_translate_2fv(const float vec[2])
#define GPU_matrix_model_view_get(x)
void GPU_matrix_pop_projection(void)
void GPU_matrix_scale_2fv(const float vec[2])
#define GPU_matrix_set(x)
#define GPU_matrix_mul(x)
void GPU_matrix_scale_3fv(const float vec[3])
void GPU_matrix_push(void)
void GPU_matrix_scale_1f(float factor)
#define GPU_matrix_projection_get(x)
void GPU_matrix_reset(void)
#define GPU_matrix_projection_set(x)
void GPU_matrix_translate_3fv(const float vec[3])
void GPU_matrix_identity_set(void)
void GPU_matrix_push_projection(void)
int GPU_matrix_stack_level_get_projection(void)
int GPU_matrix_stack_level_get_model_view(void)
static PyObject * pygpu_matrix_translate(PyObject *UNUSED(self), PyObject *value)
static PyObject * pygpu_matrix_pop(PyObject *UNUSED(self))
static bool pygpu_stack_is_pop_model_view_ok_or_error(void)
static PyObject * pygpu_matrix_get_projection_matrix(PyObject *UNUSED(self))
static PyObject * pygpu_matrix_get_model_view_matrix(PyObject *UNUSED(self))
@ PYGPU_MATRIX_TYPE_MODEL_VIEW
@ PYGPU_MATRIX_TYPE_PROJECTION
PyDoc_STRVAR(pygpu_matrix_push_doc, ".. function:: push()\n" "\n" " Add to the model-view matrix stack.\n")
static PyObject * pygpu_matrix_stack_context_exit(BPyGPU_MatrixStackContext *self, PyObject *args)
static bool pygpu_stack_is_push_projection_ok_or_error(void)
static PyObject * pygpu_matrix_push_projection(PyObject *UNUSED(self))
static PyObject * pygpu_matrix_push_pop_impl(int type)
static bool pygpu_stack_is_pop_projection_ok_or_error(void)
static PyObject * pygpu_matrix_load_identity(PyObject *UNUSED(self))
static PyMethodDef pygpu_matrix_stack_context__tp_methods[]
static PyObject * pygpu_matrix_multiply_matrix(PyObject *UNUSED(self), PyObject *value)
static PyObject * pygpu_matrix_load_projection_matrix(PyObject *UNUSED(self), PyObject *value)
static PyObject * pygpu_matrix_scale(PyObject *UNUSED(self), PyObject *value)
static bool pygpu_stack_is_push_model_view_ok_or_error(void)
static PyObject * pygpu_matrix_load_matrix(PyObject *UNUSED(self), PyObject *value)
static struct PyMethodDef pygpu_matrix__tp_methods[]
static PyObject * pygpu_matrix_push_pop(PyObject *UNUSED(self))
PyObject * bpygpu_matrix_init(void)
static PyModuleDef pygpu_matrix_module_def
static PyObject * pygpu_matrix_push_pop_projection(PyObject *UNUSED(self))
static PyTypeObject PyGPUMatrixStackContext_Type
static PyObject * pygpu_matrix_get_normal_matrix(PyObject *UNUSED(self))
static PyObject * pygpu_matrix_pop_projection(PyObject *UNUSED(self))
static PyObject * pygpu_matrix_push(PyObject *UNUSED(self))
static PyObject * pygpu_matrix_stack_context_enter(BPyGPU_MatrixStackContext *self)
static PyObject * pygpu_matrix_scale_uniform(PyObject *UNUSED(self), PyObject *value)
static PyObject * pygpu_matrix_reset(PyObject *UNUSED(self))
int mathutils_array_parse(float *array, int array_min, int array_max, PyObject *value, const char *error_prefix)
int Matrix_Parse4x4(PyObject *o, void *p)
PyObject * Matrix_CreatePyObject(const float *mat, const ushort num_col, const ushort num_row, PyTypeObject *base_type)