23#define USE_GPU_PY_MATRIX_API
25#undef USE_GPU_PY_MATRIX_API
39 "Maximum model-view stack depth " STRINGIFY(GPU_PY_MATRIX_STACK_DEPTH)
" reached");
50 "Maximum projection stack depth " STRINGIFY(GPU_PY_MATRIX_STACK_DEPTH)
" reached");
59 PyErr_SetString(PyExc_RuntimeError,
"Minimum model-view stack depth reached");
68 PyErr_SetString(PyExc_RuntimeError,
"Minimum projection stack depth reached");
82 pygpu_matrix_push_doc,
83 ".. function:: push()\n"
85 " Add to the model-view matrix stack.\n");
100 ".. function:: pop()\n"
102 " Remove the last model-view matrix from the stack.\n");
116 pygpu_matrix_push_projection_doc,
117 ".. function:: push_projection()\n"
119 " Add to the projection matrix stack.\n");
133 pygpu_matrix_pop_projection_doc,
134 ".. function:: pop_projection()\n"
136 " Remove the last projection matrix from the stack.\n");
173# pragma clang diagnostic push
174# pragma clang diagnostic ignored "-Wcast-function-type"
176# pragma GCC diagnostic push
177# pragma GCC diagnostic ignored "-Wcast-function-type"
189# pragma clang diagnostic pop
191# pragma GCC diagnostic pop
196 PyVarObject_HEAD_INIT(
nullptr, 0)
197 "GPUMatrixStackContext",
252 if (
self->level != -1) {
253 PyErr_SetString(PyExc_RuntimeError,
"Already in use");
283 if (
self->level == -1) {
284 fprintf(stderr,
"Not yet in use\n");
290 if (level !=
self->level) {
291 fprintf(stderr,
"Level push/pop mismatch, expected %d, got %d\n",
self->level, level);
299 if (level !=
self->level) {
300 fprintf(stderr,
"Level push/pop mismatch, expected %d, got %d",
self->level, level);
319 return (PyObject *)
ret;
324 pygpu_matrix_push_pop_doc,
325 ".. function:: push_pop()\n"
327 " Context manager to ensure balanced push/pop calls, even in the case of an error.\n");
337 pygpu_matrix_push_pop_projection_doc,
338 ".. function:: push_pop_projection()\n"
340 " Context manager to ensure balanced push/pop calls, even in the case of an error.\n");
354 pygpu_matrix_multiply_matrix_doc,
355 ".. function:: multiply_matrix(matrix)\n"
357 " Multiply the current stack matrix.\n"
359 " :arg matrix: A 4x4 matrix.\n"
360 " :type matrix: :class:`mathutils.Matrix`\n");
375 pygpu_matrix_scale_doc,
376 ".. function:: scale(scale)\n"
378 " Scale the current stack matrix.\n"
380 " :arg scale: Scale the current stack matrix with 2 or 3 floats.\n"
381 " :type scale: Sequence[float]\n");
389 scale, 2, 3, value,
"gpu.matrix.scale(): invalid vector arg")) == -1)
404 pygpu_matrix_scale_uniform_doc,
405 ".. function:: scale_uniform(scale)\n"
407 " :arg scale: Scale the current stack matrix.\n"
408 " :type scale: float\n");
414 if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) {
415 PyErr_Format(PyExc_TypeError,
"expected a number, not %.200s", Py_TYPE(value)->tp_name);
424 pygpu_matrix_translate_doc,
425 ".. function:: translate(offset)\n"
427 " Scale the current stack matrix.\n"
429 " :arg offset: Translate the current stack matrix with 2 or 3 floats.\n"
430 " :type offset: Sequence[float]\n");
436 offset, 2, 3, value,
"gpu.matrix.translate(): invalid vector arg")) == -1)
457 pygpu_matrix_reset_doc,
458 ".. function:: reset()\n"
460 " Empty stack and set to identity.\n");
471 pygpu_matrix_load_identity_doc,
472 ".. function:: load_identity()\n"
474 " Load an identity matrix into the stack.\n");
485 pygpu_matrix_load_matrix_doc,
486 ".. function:: load_matrix(matrix)\n"
488 " Load a matrix into the stack.\n"
490 " :arg matrix: A 4x4 matrix.\n"
491 " :type matrix: :class:`mathutils.Matrix`\n");
506 pygpu_matrix_load_projection_matrix_doc,
507 ".. function:: load_projection_matrix(matrix)\n"
509 " Load a projection matrix into the stack.\n"
511 " :arg matrix: A 4x4 matrix.\n"
512 " :type matrix: :class:`mathutils.Matrix`\n");
533 pygpu_matrix_get_projection_matrix_doc,
534 ".. function:: get_projection_matrix()\n"
536 " Return a copy of the projection matrix.\n"
538 " :return: A 4x4 projection matrix.\n"
539 " :rtype: :class:`mathutils.Matrix`\n");
551 pygpu_matrix_get_model_view_matrix_doc,
552 ".. function:: get_model_view_matrix()\n"
554 " Return a copy of the model-view matrix.\n"
556 " :return: A 4x4 view matrix.\n"
557 " :rtype: :class:`mathutils.Matrix`\n");
569 pygpu_matrix_get_normal_matrix_doc,
570 ".. function:: get_normal_matrix()\n"
572 " Return a copy of the normal matrix.\n"
574 " :return: A 3x3 normal matrix.\n"
575 " :rtype: :class:`mathutils.Matrix`\n");
593# pragma clang diagnostic push
594# pragma clang diagnostic ignored "-Wcast-function-type"
596# pragma GCC diagnostic push
597# pragma GCC diagnostic ignored "-Wcast-function-type"
609 pygpu_matrix_push_projection_doc},
613 pygpu_matrix_pop_projection_doc},
617 {
"push_pop_projection",
620 pygpu_matrix_push_pop_projection_doc},
626 pygpu_matrix_multiply_matrix_doc},
631 pygpu_matrix_scale_uniform_doc},
636 {
"rotate", (PyCFunction)pygpu_matrix_rotate, METH_O, pygpu_matrix_rotate_doc},
637 {
"rotate_axis", (PyCFunction)pygpu_matrix_rotate_axis, METH_O, pygpu_matrix_rotate_axis_doc},
638 {
"look_at", (PyCFunction)pygpu_matrix_look_at, METH_O, pygpu_matrix_look_at_doc},
646 pygpu_matrix_load_identity_doc},
648 {
"load_projection_matrix",
651 pygpu_matrix_load_projection_matrix_doc},
654 {
"get_projection_matrix",
657 pygpu_matrix_get_projection_matrix_doc},
658 {
"get_model_view_matrix",
661 pygpu_matrix_get_model_view_matrix_doc},
662 {
"get_normal_matrix",
665 pygpu_matrix_get_normal_matrix_doc},
667 {
nullptr,
nullptr, 0,
nullptr},
672# pragma clang diagnostic pop
674# pragma GCC diagnostic pop
680 pygpu_matrix__tp_doc,
681 "This module provides access to the matrix stack.");
685 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 *)
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[]
@ PYGPU_MATRIX_TYPE_MODEL_VIEW
@ PYGPU_MATRIX_TYPE_PROJECTION
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)