23#define USE_GPU_PY_MATRIX_API
25#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");
175# pragma clang diagnostic push
176# pragma clang diagnostic ignored "-Wcast-function-type"
178# pragma GCC diagnostic push
179# pragma GCC diagnostic ignored "-Wcast-function-type"
191# pragma clang diagnostic pop
193# pragma GCC diagnostic pop
199 pygpu_matrix_stack_context__tp_doc,
200 "Context manager for matrix stack push/pop.");
203 PyVarObject_HEAD_INIT(
nullptr, 0)
204 "MatrixStackContext",
223 pygpu_matrix_stack_context__tp_doc,
259 if (self->
level != -1) {
260 PyErr_SetString(PyExc_RuntimeError,
"Already in use");
290 if (self->
level == -1) {
291 fprintf(stderr,
"Not yet in use\n");
297 if (level != self->
level) {
298 fprintf(stderr,
"Level push/pop mismatch, expected %d, got %d\n", self->
level, level);
306 if (level != self->
level) {
307 fprintf(stderr,
"Level push/pop mismatch, expected %d, got %d", self->
level, level);
326 return reinterpret_cast<PyObject *
>(
ret);
331 pygpu_matrix_push_pop_doc,
332 ".. function:: push_pop()\n"
334 " Context manager to ensure balanced push/pop calls, even in the case of an error.\n"
336 " :return: The context manager.\n"
337 " :rtype: :class:`gpu.types.MatrixStackContext`\n");
347 pygpu_matrix_push_pop_projection_doc,
348 ".. function:: push_pop_projection()\n"
350 " Context manager to ensure balanced push/pop calls, even in the case of an error.\n"
352 " :return: The context manager.\n"
353 " :rtype: :class:`gpu.types.MatrixStackContext`\n");
367 pygpu_matrix_multiply_matrix_doc,
368 ".. function:: multiply_matrix(matrix)\n"
370 " Multiply the current stack matrix.\n"
372 " :param matrix: A 4x4 matrix.\n"
373 " :type matrix: :class:`mathutils.Matrix`\n");
388 pygpu_matrix_scale_doc,
389 ".. function:: scale(scale)\n"
391 " Scale the current stack matrix.\n"
393 " :param scale: Scale the current stack matrix with 2 or 3 floats.\n"
394 " :type scale: Sequence[float]\n");
402 scale, 2, 3, value,
"gpu.matrix.scale(): invalid vector arg")) == -1)
417 pygpu_matrix_scale_uniform_doc,
418 ".. function:: scale_uniform(scale)\n"
420 " Scale the current stack matrix uniformly.\n"
422 " :param scale: Uniform scale factor.\n"
423 " :type scale: float\n");
429 if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) {
430 PyErr_Format(PyExc_TypeError,
"expected a number, not %.200s", Py_TYPE(value)->tp_name);
439 pygpu_matrix_translate_doc,
440 ".. function:: translate(offset)\n"
442 " Translate the current stack matrix.\n"
444 " :param offset: Translate the current stack matrix with 2 or 3 floats.\n"
445 " :type offset: Sequence[float]\n");
451 offset, 2, 3, value,
"gpu.matrix.translate(): invalid vector arg")) == -1)
472 pygpu_matrix_reset_doc,
473 ".. function:: reset()\n"
475 " Empty stack and set to identity.\n");
486 pygpu_matrix_load_identity_doc,
487 ".. function:: load_identity()\n"
489 " Load an identity matrix into the stack.\n");
500 pygpu_matrix_load_matrix_doc,
501 ".. function:: load_matrix(matrix)\n"
503 " Load a matrix into the stack.\n"
505 " :param matrix: A 4x4 matrix.\n"
506 " :type matrix: :class:`mathutils.Matrix`\n");
521 pygpu_matrix_load_projection_matrix_doc,
522 ".. function:: load_projection_matrix(matrix)\n"
524 " Load a projection matrix into the stack.\n"
526 " :param matrix: A 4x4 matrix.\n"
527 " :type matrix: :class:`mathutils.Matrix`\n");
548 pygpu_matrix_get_projection_matrix_doc,
549 ".. function:: get_projection_matrix()\n"
551 " Return a copy of the projection matrix.\n"
553 " :return: A 4x4 projection matrix.\n"
554 " :rtype: :class:`mathutils.Matrix`\n");
566 pygpu_matrix_get_model_view_matrix_doc,
567 ".. function:: get_model_view_matrix()\n"
569 " Return a copy of the model-view matrix.\n"
571 " :return: A 4x4 view matrix.\n"
572 " :rtype: :class:`mathutils.Matrix`\n");
584 pygpu_matrix_get_normal_matrix_doc,
585 ".. function:: get_normal_matrix()\n"
587 " Return a copy of the normal matrix.\n"
589 " :return: A 3x3 normal matrix.\n"
590 " :rtype: :class:`mathutils.Matrix`\n");
608# pragma clang diagnostic push
609# pragma clang diagnostic ignored "-Wcast-function-type"
611# pragma GCC diagnostic push
612# pragma GCC diagnostic ignored "-Wcast-function-type"
618 {
"push",
reinterpret_cast<PyCFunction
>(
pygpu_matrix_push), METH_NOARGS, pygpu_matrix_push_doc},
619 {
"pop",
reinterpret_cast<PyCFunction
>(
pygpu_matrix_pop), METH_NOARGS, pygpu_matrix_pop_doc},
624 pygpu_matrix_push_projection_doc},
628 pygpu_matrix_pop_projection_doc},
634 pygpu_matrix_push_pop_doc},
635 {
"push_pop_projection",
638 pygpu_matrix_push_pop_projection_doc},
644 pygpu_matrix_multiply_matrix_doc},
645 {
"scale",
static_cast<PyCFunction
>(
pygpu_matrix_scale), METH_O, pygpu_matrix_scale_doc},
649 pygpu_matrix_scale_uniform_doc},
653 pygpu_matrix_translate_doc},
657 {
"rotate", (PyCFunction)pygpu_matrix_rotate, METH_O, pygpu_matrix_rotate_doc},
658 {
"rotate_axis", (PyCFunction)pygpu_matrix_rotate_axis, METH_O, pygpu_matrix_rotate_axis_doc},
659 {
"look_at", (PyCFunction)pygpu_matrix_look_at, METH_O, pygpu_matrix_look_at_doc},
666 pygpu_matrix_reset_doc},
670 pygpu_matrix_load_identity_doc},
674 pygpu_matrix_load_matrix_doc},
675 {
"load_projection_matrix",
678 pygpu_matrix_load_projection_matrix_doc},
681 {
"get_projection_matrix",
684 pygpu_matrix_get_projection_matrix_doc},
685 {
"get_model_view_matrix",
688 pygpu_matrix_get_model_view_matrix_doc},
689 {
"get_normal_matrix",
692 pygpu_matrix_get_normal_matrix_doc},
694 {
nullptr,
nullptr, 0,
nullptr},
699# pragma clang diagnostic pop
701# pragma GCC diagnostic pop
707 pygpu_matrix__tp_doc,
708 "This module provides access to the matrix stack.");
712 pygpu_matrix__tp_doc,
#define BLI_assert_unreachable()
#define BPYGPU_IS_INIT_OR_ERROR_OBJ
float3x3 scale(float3x3 mat, float2 scale)
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
static PyObject * pygpu_matrix_push(PyObject *)
static PyObject * pygpu_matrix_stack_context_enter(BPyGPU_MatrixStackContext *self)
int GPU_matrix_stack_level_get_projection()
static PyObject * pygpu_matrix_push_pop(PyObject *)
void GPU_matrix_scale_1f(float factor)
PyTypeObject PyGPUMatrixStackContext_Type
void GPU_matrix_scale_2fv(const float vec[2])
void GPU_matrix_identity_set()
static PyObject * pygpu_matrix_reset(PyObject *)
void GPU_matrix_scale_3fv(const float vec[3])
PyDoc_STRVAR(bpy_bm_new_doc, ".. function:: new(*, use_operators=True)\n" "\n" " :param use_operators: Support calling operators in :mod:`bmesh.ops` (uses some " "extra memory per vert/edge/face).\n" " :type use_operators: bool\n" " :return: Return a new, empty BMesh.\n" " :rtype: :class:`bmesh.types.BMesh`\n")
static PyObject * pygpu_matrix_get_projection_matrix(PyObject *)
void GPU_matrix_mul(const float m[4][4])
PyObject * bpygpu_matrix_init()
static PyObject * pygpu_matrix_push_pop_impl(int type)
void GPU_matrix_translate_3fv(const float vec[3])
static bool pygpu_stack_is_push_model_view_ok_or_error()
PyObject * Matrix_CreatePyObject(const float *mat, const ushort col_num, const ushort row_num, PyTypeObject *base_type)
static bool pygpu_stack_is_pop_projection_ok_or_error()
static PyObject * pygpu_matrix_push_projection(PyObject *)
int mathutils_array_parse(float *array, int array_num_min, int array_num_max, PyObject *value, const char *error_prefix)
static PyObject * pygpu_matrix_pop(PyObject *)
static PyObject * pygpu_matrix_get_model_view_matrix(PyObject *)
static PyObject * pygpu_matrix_load_matrix(PyObject *, PyObject *value)
void GPU_matrix_projection_set(const float m[4][4])
static PyObject * pygpu_matrix_load_identity(PyObject *)
static PyMethodDef pygpu_matrix_stack_context__tp_methods[]
void GPU_matrix_pop_projection()
@ PYGPU_MATRIX_TYPE_PROJECTION
@ PYGPU_MATRIX_TYPE_MODEL_VIEW
int Matrix_Parse4x4(PyObject *o, void *p)
const float(* GPU_matrix_normal_get(float m[3][3]))[3]
int GPU_matrix_stack_level_get_model_view()
static bool pygpu_stack_is_pop_model_view_ok_or_error()
static PyObject * pygpu_matrix_scale(PyObject *, PyObject *value)
void GPU_matrix_translate_2fv(const float vec[2])
static PyObject * pygpu_matrix_scale_uniform(PyObject *, PyObject *value)
static PyObject * pygpu_matrix_push_pop_projection(PyObject *)
const float(* GPU_matrix_projection_get(float m[4][4]))[4]
static PyObject * pygpu_matrix_get_normal_matrix(PyObject *)
static PyObject * pygpu_matrix_load_projection_matrix(PyObject *, PyObject *value)
void GPU_matrix_push_projection()
static PyMethodDef pygpu_matrix__tp_methods[]
void GPU_matrix_set(const float m[4][4])
static PyObject * pygpu_matrix_translate(PyObject *, PyObject *value)
static PyModuleDef pygpu_matrix_module_def
static PyObject * pygpu_matrix_stack_context_exit(BPyGPU_MatrixStackContext *self, PyObject *args)
static PyObject * pygpu_matrix_multiply_matrix(PyObject *, PyObject *value)
static bool pygpu_stack_is_push_projection_ok_or_error()
static PyObject * pygpu_matrix_pop_projection(PyObject *)
const float(* GPU_matrix_model_view_get(float m[4][4]))[4]