25#define USE_GPU_PY_MATRIX_API
27#undef USE_GPU_PY_MATRIX_API
41 "Maximum model-view stack depth " STRINGIFY(GPU_PY_MATRIX_STACK_DEPTH)
" reached");
52 "Maximum projection stack depth " STRINGIFY(GPU_PY_MATRIX_STACK_DEPTH)
" reached");
61 PyErr_SetString(PyExc_RuntimeError,
"Minimum model-view stack depth reached");
70 PyErr_SetString(PyExc_RuntimeError,
"Minimum projection stack depth reached");
84 pygpu_matrix_push_doc,
85 ".. function:: push()\n"
87 " Add to the model-view matrix stack.\n");
101 pygpu_matrix_pop_doc,
102 ".. function:: pop()\n"
104 " Remove the last model-view matrix from the stack.\n");
118 pygpu_matrix_push_projection_doc,
119 ".. function:: push_projection()\n"
121 " Add to the projection matrix stack.\n");
135 pygpu_matrix_pop_projection_doc,
136 ".. function:: pop_projection()\n"
138 " Remove the last projection matrix from the stack.\n");
173#if (defined(__GNUC__) && !defined(__clang__))
174# pragma GCC diagnostic push
175# pragma GCC diagnostic ignored "-Wcast-function-type"
184#if (defined(__GNUC__) && !defined(__clang__))
185# pragma GCC diagnostic pop
189 PyVarObject_HEAD_INIT(
nullptr, 0)
190 "GPUMatrixStackContext",
245 if (
self->level != -1) {
246 PyErr_SetString(PyExc_RuntimeError,
"Already in use");
276 if (
self->level == -1) {
277 fprintf(stderr,
"Not yet in use\n");
283 if (level !=
self->level) {
284 fprintf(stderr,
"Level push/pop mismatch, expected %d, got %d\n",
self->level, level);
292 if (level !=
self->level) {
293 fprintf(stderr,
"Level push/pop mismatch, expected %d, got %d",
self->level, level);
312 return (PyObject *)
ret;
317 pygpu_matrix_push_pop_doc,
318 ".. function:: push_pop()\n"
320 " Context manager to ensure balanced push/pop calls, even in the case of an error.\n");
330 pygpu_matrix_push_pop_projection_doc,
331 ".. function:: push_pop_projection()\n"
333 " Context manager to ensure balanced push/pop calls, even in the case of an error.\n");
347 pygpu_matrix_multiply_matrix_doc,
348 ".. function:: multiply_matrix(matrix)\n"
350 " Multiply the current stack matrix.\n"
352 " :arg matrix: A 4x4 matrix.\n"
353 " :type matrix: :class:`mathutils.Matrix`\n");
368 pygpu_matrix_scale_doc,
369 ".. function:: scale(scale)\n"
371 " Scale the current stack matrix.\n"
373 " :arg scale: Scale the current stack matrix with 2 or 3 floats.\n"
374 " :type scale: Sequence[float]\n");
382 scale, 2, 3, value,
"gpu.matrix.scale(): invalid vector arg")) == -1)
397 pygpu_matrix_scale_uniform_doc,
398 ".. function:: scale_uniform(scale)\n"
400 " :arg scale: Scale the current stack matrix.\n"
401 " :type scale: float\n");
407 if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) {
408 PyErr_Format(PyExc_TypeError,
"expected a number, not %.200s", Py_TYPE(value)->tp_name);
417 pygpu_matrix_translate_doc,
418 ".. function:: translate(offset)\n"
420 " Scale the current stack matrix.\n"
422 " :arg offset: Translate the current stack matrix with 2 or 3 floats.\n"
423 " :type offset: Sequence[float]\n");
429 offset, 2, 3, value,
"gpu.matrix.translate(): invalid vector arg")) == -1)
450 pygpu_matrix_reset_doc,
451 ".. function:: reset()\n"
453 " Empty stack and set to identity.\n");
464 pygpu_matrix_load_identity_doc,
465 ".. function:: load_identity()\n"
467 " Load an identity matrix into the stack.\n");
478 pygpu_matrix_load_matrix_doc,
479 ".. function:: load_matrix(matrix)\n"
481 " Load a matrix into the stack.\n"
483 " :arg matrix: A 4x4 matrix.\n"
484 " :type matrix: :class:`mathutils.Matrix`\n");
499 pygpu_matrix_load_projection_matrix_doc,
500 ".. function:: load_projection_matrix(matrix)\n"
502 " Load a projection matrix into the stack.\n"
504 " :arg matrix: A 4x4 matrix.\n"
505 " :type matrix: :class:`mathutils.Matrix`\n");
526 pygpu_matrix_get_projection_matrix_doc,
527 ".. function:: get_projection_matrix()\n"
529 " Return a copy of the projection matrix.\n"
531 " :return: A 4x4 projection matrix.\n"
532 " :rtype: :class:`mathutils.Matrix`\n");
544 pygpu_matrix_get_model_view_matrix_doc,
545 ".. function:: get_model_view_matrix()\n"
547 " Return a copy of the model-view matrix.\n"
549 " :return: A 4x4 view matrix.\n"
550 " :rtype: :class:`mathutils.Matrix`\n");
562 pygpu_matrix_get_normal_matrix_doc,
563 ".. function:: get_normal_matrix()\n"
565 " Return a copy of the normal matrix.\n"
567 " :return: A 3x3 normal matrix.\n"
568 " :rtype: :class:`mathutils.Matrix`\n");
584#if (defined(__GNUC__) && !defined(__clang__))
585# pragma GCC diagnostic push
586# pragma GCC diagnostic ignored "-Wcast-function-type"
597 pygpu_matrix_push_projection_doc},
601 pygpu_matrix_pop_projection_doc},
605 {
"push_pop_projection",
608 pygpu_matrix_push_pop_projection_doc},
614 pygpu_matrix_multiply_matrix_doc},
619 pygpu_matrix_scale_uniform_doc},
624 {
"rotate", (PyCFunction)pygpu_matrix_rotate, METH_O, pygpu_matrix_rotate_doc},
625 {
"rotate_axis", (PyCFunction)pygpu_matrix_rotate_axis, METH_O, pygpu_matrix_rotate_axis_doc},
626 {
"look_at", (PyCFunction)pygpu_matrix_look_at, METH_O, pygpu_matrix_look_at_doc},
634 pygpu_matrix_load_identity_doc},
636 {
"load_projection_matrix",
639 pygpu_matrix_load_projection_matrix_doc},
642 {
"get_projection_matrix",
645 pygpu_matrix_get_projection_matrix_doc},
646 {
"get_model_view_matrix",
649 pygpu_matrix_get_model_view_matrix_doc},
650 {
"get_normal_matrix",
653 pygpu_matrix_get_normal_matrix_doc},
655 {
nullptr,
nullptr, 0,
nullptr},
658#if (defined(__GNUC__) && !defined(__clang__))
659# pragma GCC diagnostic pop
664 pygpu_matrix__tp_doc,
665 "This module provides access to the matrix stack.");
667 PyModuleDef_HEAD_INIT,
669 pygpu_matrix__tp_doc,
#define BLI_assert_unreachable()
#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_identity_set()
void GPU_matrix_scale_2fv(const float vec[2])
#define GPU_matrix_set(x)
void GPU_matrix_push_projection()
#define GPU_matrix_mul(x)
void GPU_matrix_scale_3fv(const float vec[3])
void GPU_matrix_scale_1f(float factor)
void GPU_matrix_pop_projection()
#define GPU_matrix_projection_get(x)
#define GPU_matrix_projection_set(x)
void GPU_matrix_translate_3fv(const float vec[3])
int GPU_matrix_stack_level_get_projection()
int GPU_matrix_stack_level_get_model_view()
#define BPYGPU_IS_INIT_OR_ERROR_OBJ
static PyObject * pygpu_matrix_load_projection_matrix(PyObject *, PyObject *value)
static bool pygpu_stack_is_push_model_view_ok_or_error()
static PyObject * pygpu_matrix_push_pop_impl(int type)
static PyObject * pygpu_matrix_pop(PyObject *)
static PyObject * pygpu_matrix_push_projection(PyObject *)
static bool pygpu_stack_is_pop_model_view_ok_or_error()
PyDoc_STRVAR(pygpu_matrix_push_doc, ".. function:: push()\n" "\n" " Add to the model-view matrix stack.\n")
static PyObject * pygpu_matrix_multiply_matrix(PyObject *, PyObject *value)
static PyObject * pygpu_matrix_load_identity(PyObject *)
static PyObject * pygpu_matrix_load_matrix(PyObject *, PyObject *value)
static PyObject * pygpu_matrix_scale(PyObject *, PyObject *value)
static PyMethodDef pygpu_matrix_stack_context__tp_methods[]
static PyObject * pygpu_matrix_push_pop_projection(PyObject *)
static bool pygpu_stack_is_pop_projection_ok_or_error()
static PyObject * pygpu_matrix_pop_projection(PyObject *)
static PyModuleDef pygpu_matrix_module_def
static PyObject * pygpu_matrix_get_normal_matrix(PyObject *)
static PyObject * pygpu_matrix_stack_context_exit(BPyGPU_MatrixStackContext *self, PyObject *args)
static PyTypeObject PyGPUMatrixStackContext_Type
static PyObject * pygpu_matrix_get_projection_matrix(PyObject *)
@ PYGPU_MATRIX_TYPE_MODEL_VIEW
@ PYGPU_MATRIX_TYPE_PROJECTION
static PyObject * pygpu_matrix_get_model_view_matrix(PyObject *)
static PyObject * pygpu_matrix_translate(PyObject *, PyObject *value)
PyObject * bpygpu_matrix_init()
static PyObject * pygpu_matrix_reset(PyObject *)
static PyObject * pygpu_matrix_stack_context_enter(BPyGPU_MatrixStackContext *self)
static PyObject * pygpu_matrix_push_pop(PyObject *)
static bool pygpu_stack_is_push_projection_ok_or_error()
static PyObject * pygpu_matrix_push(PyObject *)
static PyObject * pygpu_matrix_scale_uniform(PyObject *, PyObject *value)
static PyMethodDef pygpu_matrix__tp_methods[]
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)