Blender V4.3
gpu_py_matrix.cc File Reference
#include <Python.h>
#include "BLI_utildefines.h"
#include "../mathutils/mathutils.hh"
#include "../generic/py_capi_utils.hh"
#include "GPU_matrix.hh"
#include "gpu_py.hh"
#include "gpu_py_matrix.hh"

Go to the source code of this file.

Classes

struct  BPyGPU_MatrixStackContext
 

Macros

#define USE_GPU_PY_MATRIX_API
 

Functions

Helper Functions
static bool pygpu_stack_is_push_model_view_ok_or_error ()
 
static bool pygpu_stack_is_push_projection_ok_or_error ()
 
static bool pygpu_stack_is_pop_model_view_ok_or_error ()
 
static bool pygpu_stack_is_pop_projection_ok_or_error ()
 
Manage Stack
 PyDoc_STRVAR (pygpu_matrix_push_doc, ".. function:: push()\n" "\n" " Add to the model-view matrix stack.\n")
 
static PyObject * pygpu_matrix_push (PyObject *)
 
 PyDoc_STRVAR (pygpu_matrix_pop_doc, ".. function:: pop()\n" "\n" " Remove the last model-view matrix from the stack.\n")
 
static PyObject * pygpu_matrix_pop (PyObject *)
 
 PyDoc_STRVAR (pygpu_matrix_push_projection_doc, ".. function:: push_projection()\n" "\n" " Add to the projection matrix stack.\n")
 
static PyObject * pygpu_matrix_push_projection (PyObject *)
 
 PyDoc_STRVAR (pygpu_matrix_pop_projection_doc, ".. function:: pop_projection()\n" "\n" " Remove the last projection matrix from the stack.\n")
 
static PyObject * pygpu_matrix_pop_projection (PyObject *)
 
Manipulate State
 PyDoc_STRVAR (pygpu_matrix_multiply_matrix_doc, ".. function:: multiply_matrix(matrix)\n" "\n" " Multiply the current stack matrix.\n" "\n" " :arg matrix: A 4x4 matrix.\n" " :type matrix: :class:`mathutils.Matrix`\n")
 
static PyObject * pygpu_matrix_multiply_matrix (PyObject *, PyObject *value)
 
 PyDoc_STRVAR (pygpu_matrix_scale_doc, ".. function:: scale(scale)\n" "\n" " Scale the current stack matrix.\n" "\n" " :arg scale: Scale the current stack matrix with 2 or 3 floats.\n" " :type scale: Sequence[float]\n")
 
static PyObject * pygpu_matrix_scale (PyObject *, PyObject *value)
 
 PyDoc_STRVAR (pygpu_matrix_scale_uniform_doc, ".. function:: scale_uniform(scale)\n" "\n" " :arg scale: Scale the current stack matrix.\n" " :type scale: float\n")
 
static PyObject * pygpu_matrix_scale_uniform (PyObject *, PyObject *value)
 
 PyDoc_STRVAR (pygpu_matrix_translate_doc, ".. function:: translate(offset)\n" "\n" " Scale the current stack matrix.\n" "\n" " :arg offset: Translate the current stack matrix with 2 or 3 floats.\n" " :type offset: Sequence[float]\n")
 
static PyObject * pygpu_matrix_translate (PyObject *, PyObject *value)
 
Write State
 PyDoc_STRVAR (pygpu_matrix_reset_doc, ".. function:: reset()\n" "\n" " Empty stack and set to identity.\n")
 
static PyObject * pygpu_matrix_reset (PyObject *)
 
 PyDoc_STRVAR (pygpu_matrix_load_identity_doc, ".. function:: load_identity()\n" "\n" " Load an identity matrix into the stack.\n")
 
static PyObject * pygpu_matrix_load_identity (PyObject *)
 
 PyDoc_STRVAR (pygpu_matrix_load_matrix_doc, ".. function:: load_matrix(matrix)\n" "\n" " Load a matrix into the stack.\n" "\n" " :arg matrix: A 4x4 matrix.\n" " :type matrix: :class:`mathutils.Matrix`\n")
 
static PyObject * pygpu_matrix_load_matrix (PyObject *, PyObject *value)
 
 PyDoc_STRVAR (pygpu_matrix_load_projection_matrix_doc, ".. function:: load_projection_matrix(matrix)\n" "\n" " Load a projection matrix into the stack.\n" "\n" " :arg matrix: A 4x4 matrix.\n" " :type matrix: :class:`mathutils.Matrix`\n")
 
static PyObject * pygpu_matrix_load_projection_matrix (PyObject *, PyObject *value)
 
Read State
 PyDoc_STRVAR (pygpu_matrix_get_projection_matrix_doc, ".. function:: get_projection_matrix()\n" "\n" " Return a copy of the projection matrix.\n" "\n" " :return: A 4x4 projection matrix.\n" " :rtype: :class:`mathutils.Matrix`\n")
 
static PyObject * pygpu_matrix_get_projection_matrix (PyObject *)
 
 PyDoc_STRVAR (pygpu_matrix_get_model_view_matrix_doc, ".. function:: get_model_view_matrix()\n" "\n" " Return a copy of the model-view matrix.\n" "\n" " :return: A 4x4 view matrix.\n" " :rtype: :class:`mathutils.Matrix`\n")
 
static PyObject * pygpu_matrix_get_model_view_matrix (PyObject *)
 
 PyDoc_STRVAR (pygpu_matrix_get_normal_matrix_doc, ".. function:: get_normal_matrix()\n" "\n" " Return a copy of the normal matrix.\n" "\n" " :return: A 3x3 normal matrix.\n" " :rtype: :class:`mathutils.Matrix`\n")
 
static PyObject * pygpu_matrix_get_normal_matrix (PyObject *)
 

Stack (Context Manager)

Safer alternative to ensure balanced push/pop calls.

enum  { PYGPU_MATRIX_TYPE_MODEL_VIEW = 1 , PYGPU_MATRIX_TYPE_PROJECTION = 2 }
 
static PyMethodDef pygpu_matrix_stack_context__tp_methods []
 
static PyTypeObject PyGPUMatrixStackContext_Type
 
static PyObject * pygpu_matrix_stack_context_enter (BPyGPU_MatrixStackContext *self)
 
static PyObject * pygpu_matrix_stack_context_exit (BPyGPU_MatrixStackContext *self, PyObject *args)
 
static PyObject * pygpu_matrix_push_pop_impl (int type)
 
 PyDoc_STRVAR (pygpu_matrix_push_pop_doc, ".. function:: push_pop()\n" "\n" " Context manager to ensure balanced push/pop calls, even in the case of an error.\n")
 
static PyObject * pygpu_matrix_push_pop (PyObject *)
 
 PyDoc_STRVAR (pygpu_matrix_push_pop_projection_doc, ".. function:: push_pop_projection()\n" "\n" " Context manager to ensure balanced push/pop calls, even in the case of an error.\n")
 
static PyObject * pygpu_matrix_push_pop_projection (PyObject *)
 

Module

static PyMethodDef pygpu_matrix__tp_methods []
 
static PyModuleDef pygpu_matrix_module_def
 
 PyDoc_STRVAR (pygpu_matrix__tp_doc, "This module provides access to the matrix stack.")
 
PyObject * bpygpu_matrix_init ()
 

Detailed Description

This file defines the gpu.matrix stack API.

Warning
While these functions attempt to ensure correct stack usage. Mixing Python and C functions may still crash on invalid use.
  • Use bpygpu_ for local API.
  • Use BPyGPU for public API.

Definition in file gpu_py_matrix.cc.

Macro Definition Documentation

◆ USE_GPU_PY_MATRIX_API

#define USE_GPU_PY_MATRIX_API

Definition at line 25 of file gpu_py_matrix.cc.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
PYGPU_MATRIX_TYPE_MODEL_VIEW 
PYGPU_MATRIX_TYPE_PROJECTION 

Definition at line 165 of file gpu_py_matrix.cc.

Function Documentation

◆ bpygpu_matrix_init()

PyObject * bpygpu_matrix_init ( )

Definition at line 678 of file gpu_py_matrix.cc.

References pygpu_matrix_module_def, and PyGPUMatrixStackContext_Type.

Referenced by BPyInit_gpu().

◆ PyDoc_STRVAR() [1/18]

PyDoc_STRVAR ( pygpu_matrix__tp_doc ,
"This module provides access to the matrix stack."  )

◆ PyDoc_STRVAR() [2/18]

PyDoc_STRVAR ( pygpu_matrix_get_model_view_matrix_doc ,
".. function:: get_model_view_matrix()\n" "\n" " Return a copy of the model-view matrix.\n" "\n" " :return: A 4x4 view matrix.\n" " :rtype: :class:`mathutils.Matrix`\n"  )

◆ PyDoc_STRVAR() [3/18]

PyDoc_STRVAR ( pygpu_matrix_get_normal_matrix_doc ,
".. function:: get_normal_matrix()\n" "\n" " Return a copy of the normal matrix.\n" "\n" " :return: A 3x3 normal matrix.\n" " :rtype: :class:`mathutils.Matrix`\n"  )

◆ PyDoc_STRVAR() [4/18]

PyDoc_STRVAR ( pygpu_matrix_get_projection_matrix_doc ,
".. function:: get_projection_matrix()\n" "\n" " Return a copy of the projection matrix.\n" "\n" " :return: A 4x4 projection matrix.\n" " :rtype: :class:`mathutils.Matrix`\n"  )

◆ PyDoc_STRVAR() [5/18]

PyDoc_STRVAR ( pygpu_matrix_load_identity_doc ,
".. function:: load_identity()\n" "\n" " Load an identity matrix into the stack.\n"  )

◆ PyDoc_STRVAR() [6/18]

PyDoc_STRVAR ( pygpu_matrix_load_matrix_doc ,
".. function:: load_matrix(matrix)\n" "\n" " Load a matrix into the stack.\n" "\n" " :arg matrix: A 4x4 matrix.\n" " :type matrix: :class:`mathutils.Matrix`\n"  )

◆ PyDoc_STRVAR() [7/18]

PyDoc_STRVAR ( pygpu_matrix_load_projection_matrix_doc ,
".. function:: load_projection_matrix(matrix)\n" "\n" " Load a projection matrix into the stack.\n" "\n" " :arg matrix: A 4x4 matrix.\n" " :type matrix: :class:`mathutils.Matrix`\n"  )

◆ PyDoc_STRVAR() [8/18]

PyDoc_STRVAR ( pygpu_matrix_multiply_matrix_doc ,
".. function:: multiply_matrix(matrix)\n" "\n" " Multiply the current stack matrix.\n" "\n" " :arg matrix: A 4x4 matrix.\n" " :type matrix: :class:`mathutils.Matrix`\n"  )

◆ PyDoc_STRVAR() [9/18]

PyDoc_STRVAR ( pygpu_matrix_pop_doc ,
".. function:: pop()\n" "\n" " Remove the last model-view matrix from the stack.\n"  )

◆ PyDoc_STRVAR() [10/18]

PyDoc_STRVAR ( pygpu_matrix_pop_projection_doc ,
".. function:: pop_projection()\n" "\n" " Remove the last projection matrix from the stack.\n"  )

◆ PyDoc_STRVAR() [11/18]

PyDoc_STRVAR ( pygpu_matrix_push_doc ,
".. function:: push()\n" "\n" " Add to the model-view matrix stack.\n"  )

◆ PyDoc_STRVAR() [12/18]

PyDoc_STRVAR ( pygpu_matrix_push_pop_doc ,
".. function:: push_pop()\n" "\n" " Context manager to ensure balanced push/pop calls,
even in the case of an error.\n"  )

◆ PyDoc_STRVAR() [13/18]

PyDoc_STRVAR ( pygpu_matrix_push_pop_projection_doc ,
".. function:: push_pop_projection()\n" "\n" " Context manager to ensure balanced push/pop calls,
even in the case of an error.\n"  )

◆ PyDoc_STRVAR() [14/18]

PyDoc_STRVAR ( pygpu_matrix_push_projection_doc ,
".. function:: push_projection()\n" "\n" " Add to the projection matrix stack.\n"  )

◆ PyDoc_STRVAR() [15/18]

PyDoc_STRVAR ( pygpu_matrix_reset_doc ,
".. function:: reset()\n" "\n" " Empty stack and set to identity.\n"  )

◆ PyDoc_STRVAR() [16/18]

PyDoc_STRVAR ( pygpu_matrix_scale_doc ,
".. function:: scale(scale)\n" "\n" " Scale the current stack matrix.\n" "\n" " :arg scale: Scale the current stack matrix with 2 or 3 floats.\n" " :type scale: Sequence\n" [float] )

◆ PyDoc_STRVAR() [17/18]

PyDoc_STRVAR ( pygpu_matrix_scale_uniform_doc ,
".. function:: scale_uniform(scale)\n" "\n" " :arg scale: Scale the current stack matrix.\n" " :type scale: float\n"  )

◆ PyDoc_STRVAR() [18/18]

PyDoc_STRVAR ( pygpu_matrix_translate_doc ,
".. function:: translate(offset)\n" "\n" " Scale the current stack matrix.\n" "\n" " :arg offset: Translate the current stack matrix with 2 or 3 floats.\n" " :type offset: Sequence\n" [float] )

◆ pygpu_matrix_get_model_view_matrix()

static PyObject * pygpu_matrix_get_model_view_matrix ( PyObject * )
static

◆ pygpu_matrix_get_normal_matrix()

static PyObject * pygpu_matrix_get_normal_matrix ( PyObject * )
static

◆ pygpu_matrix_get_projection_matrix()

static PyObject * pygpu_matrix_get_projection_matrix ( PyObject * )
static

◆ pygpu_matrix_load_identity()

static PyObject * pygpu_matrix_load_identity ( PyObject * )
static

Definition at line 468 of file gpu_py_matrix.cc.

References BPYGPU_IS_INIT_OR_ERROR_OBJ, and GPU_matrix_identity_set().

◆ pygpu_matrix_load_matrix()

static PyObject * pygpu_matrix_load_matrix ( PyObject * ,
PyObject * value )
static

Definition at line 485 of file gpu_py_matrix.cc.

References BPYGPU_IS_INIT_OR_ERROR_OBJ, GPU_matrix_set, and Matrix_Parse4x4().

◆ pygpu_matrix_load_projection_matrix()

static PyObject * pygpu_matrix_load_projection_matrix ( PyObject * ,
PyObject * value )
static

◆ pygpu_matrix_multiply_matrix()

static PyObject * pygpu_matrix_multiply_matrix ( PyObject * ,
PyObject * value )
static

Definition at line 354 of file gpu_py_matrix.cc.

References BPYGPU_IS_INIT_OR_ERROR_OBJ, GPU_matrix_mul, and Matrix_Parse4x4().

◆ pygpu_matrix_pop()

static PyObject * pygpu_matrix_pop ( PyObject * )
static

◆ pygpu_matrix_pop_projection()

static PyObject * pygpu_matrix_pop_projection ( PyObject * )
static

◆ pygpu_matrix_push()

static PyObject * pygpu_matrix_push ( PyObject * )
static

◆ pygpu_matrix_push_pop()

static PyObject * pygpu_matrix_push_pop ( PyObject * )
static

◆ pygpu_matrix_push_pop_impl()

static PyObject * pygpu_matrix_push_pop_impl ( int type)
static

Definition at line 306 of file gpu_py_matrix.cc.

References PyGPUMatrixStackContext_Type, and ret.

Referenced by pygpu_matrix_push_pop(), and pygpu_matrix_push_pop_projection().

◆ pygpu_matrix_push_pop_projection()

static PyObject * pygpu_matrix_push_pop_projection ( PyObject * )
static

Definition at line 334 of file gpu_py_matrix.cc.

References pygpu_matrix_push_pop_impl(), and PYGPU_MATRIX_TYPE_PROJECTION.

◆ pygpu_matrix_push_projection()

static PyObject * pygpu_matrix_push_projection ( PyObject * )
static

◆ pygpu_matrix_reset()

static PyObject * pygpu_matrix_reset ( PyObject * )
static

Definition at line 454 of file gpu_py_matrix.cc.

References BPYGPU_IS_INIT_OR_ERROR_OBJ, and GPU_matrix_reset().

◆ pygpu_matrix_scale()

static PyObject * pygpu_matrix_scale ( PyObject * ,
PyObject * value )
static

◆ pygpu_matrix_scale_uniform()

static PyObject * pygpu_matrix_scale_uniform ( PyObject * ,
PyObject * value )
static

Definition at line 402 of file gpu_py_matrix.cc.

References BPYGPU_IS_INIT_OR_ERROR_OBJ, and GPU_matrix_scale_1f().

◆ pygpu_matrix_stack_context_enter()

◆ pygpu_matrix_stack_context_exit()

◆ pygpu_matrix_translate()

static PyObject * pygpu_matrix_translate ( PyObject * ,
PyObject * value )
static

◆ pygpu_stack_is_pop_model_view_ok_or_error()

static bool pygpu_stack_is_pop_model_view_ok_or_error ( )
static

Definition at line 58 of file gpu_py_matrix.cc.

References GPU_matrix_stack_level_get_model_view().

Referenced by pygpu_matrix_pop().

◆ pygpu_stack_is_pop_projection_ok_or_error()

static bool pygpu_stack_is_pop_projection_ok_or_error ( )
static

Definition at line 67 of file gpu_py_matrix.cc.

References GPU_matrix_stack_level_get_projection().

Referenced by pygpu_matrix_pop_projection().

◆ pygpu_stack_is_push_model_view_ok_or_error()

static bool pygpu_stack_is_push_model_view_ok_or_error ( )
static

◆ pygpu_stack_is_push_projection_ok_or_error()

static bool pygpu_stack_is_push_projection_ok_or_error ( )
static

Variable Documentation

◆ pygpu_matrix__tp_methods

PyMethodDef pygpu_matrix__tp_methods[]
static

Definition at line 589 of file gpu_py_matrix.cc.

◆ pygpu_matrix_module_def

PyModuleDef pygpu_matrix_module_def
static
Initial value:
= {
PyModuleDef_HEAD_INIT,
"gpu.matrix",
pygpu_matrix__tp_doc,
0,
nullptr,
nullptr,
nullptr,
nullptr,
}
static PyMethodDef pygpu_matrix__tp_methods[]

Definition at line 666 of file gpu_py_matrix.cc.

Referenced by bpygpu_matrix_init().

◆ pygpu_matrix_stack_context__tp_methods

PyMethodDef pygpu_matrix_stack_context__tp_methods[]
static
Initial value:
= {
{"__enter__", (PyCFunction)pygpu_matrix_stack_context_enter, METH_NOARGS},
{"__exit__", (PyCFunction)pygpu_matrix_stack_context_exit, METH_VARARGS},
{nullptr},
}
static PyObject * pygpu_matrix_stack_context_exit(BPyGPU_MatrixStackContext *self, PyObject *args)
static PyObject * pygpu_matrix_stack_context_enter(BPyGPU_MatrixStackContext *self)

Definition at line 178 of file gpu_py_matrix.cc.

◆ PyGPUMatrixStackContext_Type

PyTypeObject PyGPUMatrixStackContext_Type
static

Definition at line 188 of file gpu_py_matrix.cc.

Referenced by bpygpu_matrix_init(), and pygpu_matrix_push_pop_impl().