19 #include "../mathutils/mathutils.h"
21 #include "../generic/py_capi_utils.h"
23 #define USE_GPU_PY_MATRIX_API
25 #undef USE_GPU_PY_MATRIX_API
38 "Maximum model-view stack depth " STRINGIFY(GPU_PY_MATRIX_STACK_DEPTH)
" reached");
49 "Maximum projection stack depth " STRINGIFY(GPU_PY_MATRIX_STACK_DEPTH)
" reached");
58 PyErr_SetString(PyExc_RuntimeError,
"Minimum model-view stack depth reached");
67 PyErr_SetString(PyExc_RuntimeError,
"Minimum projection stack depth reached");
80 ".. function:: push()\n"
82 " Add to the model-view matrix stack.\n");
93 ".. function:: pop()\n"
95 " Remove the last model-view matrix from the stack.\n");
106 ".. function:: push_projection()\n"
108 " Add to the projection matrix stack.\n");
119 ".. function:: pop_projection()\n"
121 " Remove the last projection matrix from the stack.\n");
161 PyVarObject_HEAD_INIT(
NULL, 0).tp_name =
"GPUMatrixStackContext",
163 .tp_flags = Py_TPFLAGS_DEFAULT,
170 if (
self->level != -1) {
171 PyErr_SetString(PyExc_RuntimeError,
"Already in use");
199 if (
self->level == -1) {
200 fprintf(stderr,
"Not yet in use\n");
206 if (level !=
self->level) {
207 fprintf(stderr,
"Level push/pop mismatch, expected %d, got %d\n",
self->level, level);
215 if (level !=
self->level) {
216 fprintf(stderr,
"Level push/pop mismatch, expected %d, got %d",
self->level, level);
235 return (PyObject *)
ret;
239 pygpu_matrix_push_pop_doc,
240 ".. function:: push_pop()\n"
242 " Context manager to ensure balanced push/pop calls, even in the case of an error.\n");
249 pygpu_matrix_push_pop_projection_doc,
250 ".. function:: push_pop_projection()\n"
252 " Context manager to ensure balanced push/pop calls, even in the case of an error.\n");
265 ".. function:: multiply_matrix(matrix)\n"
267 " Multiply the current stack matrix.\n"
269 " :param matrix: A 4x4 matrix.\n"
270 " :type matrix: :class:`mathutils.Matrix`\n");
282 ".. function:: scale(scale)\n"
284 " Scale the current stack matrix.\n"
286 " :param scale: Scale the current stack matrix.\n"
287 " :type scale: sequence of 2 or 3 floats\n");
293 scale, 2, 3, value,
"gpu.matrix.scale(): invalid vector arg")) == -1) {
306 ".. function:: scale_uniform(scale)\n"
308 " :param scale: Scale the current stack matrix.\n"
309 " :type scale: float\n");
313 if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) {
314 PyErr_Format(PyExc_TypeError,
"expected a number, not %.200s", Py_TYPE(value)->tp_name);
322 ".. function:: translate(offset)\n"
324 " Scale the current stack matrix.\n"
326 " :param offset: Translate the current stack matrix.\n"
327 " :type offset: sequence of 2 or 3 floats\n");
333 offset, 2, 3, value,
"gpu.matrix.translate(): invalid vector arg")) == -1) {
352 ".. function:: reset()\n"
354 " Empty stack and set to identity.\n");
362 ".. function:: load_identity()\n"
364 " Empty stack and set to identity.\n");
372 ".. function:: load_matrix(matrix)\n"
374 " Load a matrix into the stack.\n"
376 " :param matrix: A 4x4 matrix.\n"
377 " :type matrix: :class:`mathutils.Matrix`\n");
389 ".. function:: load_projection_matrix(matrix)\n"
391 " Load a projection matrix into the stack.\n"
393 " :param matrix: A 4x4 matrix.\n"
394 " :type matrix: :class:`mathutils.Matrix`\n");
412 ".. function:: get_projection_matrix()\n"
414 " Return a copy of the projection matrix.\n"
416 " :return: A 4x4 projection matrix.\n"
417 " :rtype: :class:`mathutils.Matrix`\n");
426 ".. function:: get_model_view_matrix()\n"
428 " Return a copy of the model-view matrix.\n"
430 " :return: A 4x4 view matrix.\n"
431 " :rtype: :class:`mathutils.Matrix`\n");
440 ".. function:: get_normal_matrix()\n"
442 " Return a copy of the normal matrix.\n"
444 " :return: A 3x3 normal matrix.\n"
445 " :rtype: :class:`mathutils.Matrix`\n");
467 pygpu_matrix_push_projection_doc},
471 pygpu_matrix_pop_projection_doc},
475 {
"push_pop_projection",
478 pygpu_matrix_push_pop_projection_doc},
484 pygpu_matrix_multiply_matrix_doc},
489 pygpu_matrix_scale_uniform_doc},
494 {
"rotate", (PyCFunction)pygpu_matrix_rotate, METH_O, pygpu_matrix_rotate_doc},
495 {
"rotate_axis", (PyCFunction)pygpu_matrix_rotate_axis, METH_O, pygpu_matrix_rotate_axis_doc},
496 {
"look_at", (PyCFunction)pygpu_matrix_look_at, METH_O, pygpu_matrix_look_at_doc},
504 pygpu_matrix_load_identity_doc},
506 {
"load_projection_matrix",
509 pygpu_matrix_load_projection_matrix_doc},
512 {
"get_projection_matrix",
515 pygpu_matrix_get_projection_matrix_doc},
516 {
"get_model_view_matrix",
519 pygpu_matrix_get_model_view_matrix_doc},
520 {
"get_normal_matrix",
523 pygpu_matrix_get_normal_matrix_doc},
528 PyDoc_STRVAR(pygpu_matrix__tp_doc,
"This module provides access to the matrix stack.");
530 PyModuleDef_HEAD_INIT,
531 .m_name =
"gpu.matrix",
532 .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()
int GPU_matrix_stack_level_get_model_view()
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))
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))
@ PYGPU_MATRIX_TYPE_MODEL_VIEW
@ PYGPU_MATRIX_TYPE_PROJECTION
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))
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
int mathutils_array_parse(float *array, int array_num_min, int array_num_max, PyObject *value, const char *error_prefix)
PyObject * Matrix_CreatePyObject(const float *mat, const ushort col_num, const ushort row_num, PyTypeObject *base_type)
int Matrix_Parse4x4(PyObject *o, void *p)