Blender  V3.3
Classes | Macros
gpu_py_matrix.c File Reference
#include <Python.h>
#include "BLI_utildefines.h"
#include "../mathutils/mathutils.h"
#include "../generic/py_capi_utils.h"
#include "GPU_matrix.h"
#include "gpu_py_matrix.h"

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 (void)
 
static bool pygpu_stack_is_push_projection_ok_or_error (void)
 
static bool pygpu_stack_is_pop_model_view_ok_or_error (void)
 
static bool pygpu_stack_is_pop_projection_ok_or_error (void)
 
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 *UNUSED(self))
 
 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 *UNUSED(self))
 
 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 *UNUSED(self))
 
 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 *UNUSED(self))
 
Manipulate State
 PyDoc_STRVAR (pygpu_matrix_multiply_matrix_doc, ".. function:: multiply_matrix(matrix)\n" "\n" " Multiply the current stack matrix.\n" "\n" " :param matrix: A 4x4 matrix.\n" " :type matrix: :class:`mathutils.Matrix`\n")
 
static PyObject * pygpu_matrix_multiply_matrix (PyObject *UNUSED(self), PyObject *value)
 
 PyDoc_STRVAR (pygpu_matrix_scale_doc, ".. function:: scale(scale)\n" "\n" " Scale the current stack matrix.\n" "\n" " :param scale: Scale the current stack matrix.\n" " :type scale: sequence of 2 or 3 floats\n")
 
static PyObject * pygpu_matrix_scale (PyObject *UNUSED(self), PyObject *value)
 
 PyDoc_STRVAR (pygpu_matrix_scale_uniform_doc, ".. function:: scale_uniform(scale)\n" "\n" " :param scale: Scale the current stack matrix.\n" " :type scale: float\n")
 
static PyObject * pygpu_matrix_scale_uniform (PyObject *UNUSED(self), PyObject *value)
 
 PyDoc_STRVAR (pygpu_matrix_translate_doc, ".. function:: translate(offset)\n" "\n" " Scale the current stack matrix.\n" "\n" " :param offset: Translate the current stack matrix.\n" " :type offset: sequence of 2 or 3 floats\n")
 
static PyObject * pygpu_matrix_translate (PyObject *UNUSED(self), 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 *UNUSED(self))
 
 PyDoc_STRVAR (pygpu_matrix_load_identity_doc, ".. function:: load_identity()\n" "\n" " Empty stack and set to identity.\n")
 
static PyObject * pygpu_matrix_load_identity (PyObject *UNUSED(self))
 
 PyDoc_STRVAR (pygpu_matrix_load_matrix_doc, ".. function:: load_matrix(matrix)\n" "\n" " Load a matrix into the stack.\n" "\n" " :param matrix: A 4x4 matrix.\n" " :type matrix: :class:`mathutils.Matrix`\n")
 
static PyObject * pygpu_matrix_load_matrix (PyObject *UNUSED(self), 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" " :param matrix: A 4x4 matrix.\n" " :type matrix: :class:`mathutils.Matrix`\n")
 
static PyObject * pygpu_matrix_load_projection_matrix (PyObject *UNUSED(self), 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 *UNUSED(self))
 
 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 *UNUSED(self))
 
 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 *UNUSED(self))
 

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_stack_context_exit (BPyGPU_MatrixStackContext *self, PyObject *UNUSED(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 *UNUSED(self))
 
 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 *UNUSED(self))
 

Module

static struct 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 (void)
 

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.

Definition in file gpu_py_matrix.c.

Macro Definition Documentation

◆ USE_GPU_PY_MATRIX_API

#define USE_GPU_PY_MATRIX_API

Definition at line 23 of file gpu_py_matrix.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
PYGPU_MATRIX_TYPE_MODEL_VIEW 
PYGPU_MATRIX_TYPE_PROJECTION 

Definition at line 146 of file gpu_py_matrix.c.

Function Documentation

◆ bpygpu_matrix_init()

PyObject* bpygpu_matrix_init ( void  )

Definition at line 536 of file gpu_py_matrix.c.

References NULL, 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" " Empty stack and set to identity.\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" " :param 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" " :param 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" " :param 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" " :param scale: Scale the current stack matrix.\n" " :type scale: sequence of 2 or 3 floats\n"   
)

◆ PyDoc_STRVAR() [17/18]

PyDoc_STRVAR ( pygpu_matrix_scale_uniform_doc  ,
".. function:: scale_uniform(scale)\n" "\n" " :param 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" " :param offset: Translate the current stack matrix.\n" " :type offset: sequence of 2 or 3 floats\n"   
)

◆ pygpu_matrix_get_model_view_matrix()

static PyObject* pygpu_matrix_get_model_view_matrix ( PyObject *  UNUSEDself)
static

Definition at line 432 of file gpu_py_matrix.c.

References GPU_matrix_model_view_get, Matrix_CreatePyObject(), and NULL.

◆ pygpu_matrix_get_normal_matrix()

static PyObject* pygpu_matrix_get_normal_matrix ( PyObject *  UNUSEDself)
static

Definition at line 446 of file gpu_py_matrix.c.

◆ pygpu_matrix_get_projection_matrix()

static PyObject* pygpu_matrix_get_projection_matrix ( PyObject *  UNUSEDself)
static

Definition at line 418 of file gpu_py_matrix.c.

References GPU_matrix_projection_get, Matrix_CreatePyObject(), and NULL.

◆ pygpu_matrix_load_identity()

static PyObject* pygpu_matrix_load_identity ( PyObject *  UNUSEDself)
static

Definition at line 365 of file gpu_py_matrix.c.

References GPU_matrix_identity_set().

◆ pygpu_matrix_load_matrix()

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

Definition at line 378 of file gpu_py_matrix.c.

References GPU_matrix_set, Matrix_Parse4x4(), and NULL.

◆ pygpu_matrix_load_projection_matrix()

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

Definition at line 395 of file gpu_py_matrix.c.

References GPU_matrix_projection_set, Matrix_Parse4x4(), and NULL.

◆ pygpu_matrix_multiply_matrix()

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

Definition at line 271 of file gpu_py_matrix.c.

References GPU_matrix_mul, Matrix_Parse4x4(), and NULL.

◆ pygpu_matrix_pop()

static PyObject* pygpu_matrix_pop ( PyObject *  UNUSEDself)
static

◆ pygpu_matrix_pop_projection()

static PyObject* pygpu_matrix_pop_projection ( PyObject *  UNUSEDself)
static

◆ pygpu_matrix_push()

static PyObject* pygpu_matrix_push ( PyObject *  UNUSEDself)
static

◆ pygpu_matrix_push_pop()

static PyObject* pygpu_matrix_push_pop ( PyObject *  UNUSEDself)
static

Definition at line 243 of file gpu_py_matrix.c.

References pygpu_matrix_push_pop_impl(), and PYGPU_MATRIX_TYPE_MODEL_VIEW.

◆ pygpu_matrix_push_pop_impl()

static PyObject* pygpu_matrix_push_pop_impl ( int  type)
static

Definition at line 229 of file gpu_py_matrix.c.

References PyGPUMatrixStackContext_Type, ret, and type.

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 *  UNUSEDself)
static

Definition at line 253 of file gpu_py_matrix.c.

References pygpu_matrix_push_pop_impl(), and PYGPU_MATRIX_TYPE_PROJECTION.

◆ pygpu_matrix_push_projection()

static PyObject* pygpu_matrix_push_projection ( PyObject *  UNUSEDself)
static

◆ pygpu_matrix_reset()

static PyObject* pygpu_matrix_reset ( PyObject *  UNUSEDself)
static

Definition at line 355 of file gpu_py_matrix.c.

References GPU_matrix_reset().

◆ pygpu_matrix_scale()

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

◆ pygpu_matrix_scale_uniform()

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

Definition at line 310 of file gpu_py_matrix.c.

References GPU_matrix_scale_1f(), and NULL.

◆ pygpu_matrix_stack_context_enter()

static PyObject * pygpu_matrix_stack_context_enter ( BPyGPU_MatrixStackContext self)
static

◆ pygpu_matrix_stack_context_exit() [1/2]

static PyObject* pygpu_matrix_stack_context_exit ( BPyGPU_MatrixStackContext self,
PyObject *  args 
)
static

◆ pygpu_matrix_stack_context_exit() [2/2]

static PyObject* pygpu_matrix_stack_context_exit ( BPyGPU_MatrixStackContext self,
PyObject *  UNUSEDargs 
)
static

◆ pygpu_matrix_translate()

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

◆ pygpu_stack_is_pop_model_view_ok_or_error()

static bool pygpu_stack_is_pop_model_view_ok_or_error ( void  )
static

Definition at line 55 of file gpu_py_matrix.c.

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 ( void  )
static

Definition at line 64 of file gpu_py_matrix.c.

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 ( void  )
static

◆ pygpu_stack_is_push_projection_ok_or_error()

static bool pygpu_stack_is_push_projection_ok_or_error ( void  )
static

Variable Documentation

◆ pygpu_matrix__tp_methods

struct PyMethodDef pygpu_matrix__tp_methods[]
static

Definition at line 446 of file gpu_py_matrix.c.

◆ pygpu_matrix_module_def

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

Definition at line 529 of file gpu_py_matrix.c.

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},
{NULL},
}
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 154 of file gpu_py_matrix.c.

◆ PyGPUMatrixStackContext_Type

PyTypeObject PyGPUMatrixStackContext_Type
static
Initial value:
= {
PyVarObject_HEAD_INIT(NULL, 0).tp_name = "GPUMatrixStackContext",
.tp_basicsize = sizeof(BPyGPU_MatrixStackContext),
.tp_flags = Py_TPFLAGS_DEFAULT,
}
static PyMethodDef pygpu_matrix_stack_context__tp_methods[]

Definition at line 160 of file gpu_py_matrix.c.

Referenced by bpygpu_matrix_init(), and pygpu_matrix_push_pop_impl().