| 
									
										
										
										
											2022-02-11 09:07:11 +11:00
										 |  |  | /* SPDX-License-Identifier: GPL-2.0-or-later */ | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup bpygpu | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This file defines the gpu.matrix stack API. | 
					
						
							| 
									
										
										
										
											2017-08-20 17:23:49 +10:00
										 |  |  |  * | 
					
						
							|  |  |  |  * \warning While these functions attempt to ensure correct stack usage. | 
					
						
							|  |  |  |  * Mixing Python and C functions may still crash on invalid use. | 
					
						
							| 
									
										
										
										
											2018-09-05 21:10:42 -03:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-07-20 22:52:31 +10:00
										 |  |  |  * - Use `bpygpu_` for local API. | 
					
						
							|  |  |  |  * - Use `BPyGPU` for public API. | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <Python.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_utildefines.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "../mathutils/mathutils.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "../generic/py_capi_utils.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 17:23:49 +10:00
										 |  |  | #define USE_GPU_PY_MATRIX_API
 | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | #include "GPU_matrix.h"
 | 
					
						
							| 
									
										
										
										
											2017-08-20 17:23:49 +10:00
										 |  |  | #undef USE_GPU_PY_MATRIX_API
 | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-05 21:10:42 -03:00
										 |  |  | #include "gpu_py_matrix.h" /* own include */
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  | /** \name Helper Functions
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static bool pygpu_stack_is_push_model_view_ok_or_error(void) | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  | { | 
					
						
							|  |  |  |   if (GPU_matrix_stack_level_get_model_view() >= GPU_PY_MATRIX_STACK_LEN) { | 
					
						
							|  |  |  |     PyErr_SetString( | 
					
						
							|  |  |  |         PyExc_RuntimeError, | 
					
						
							|  |  |  |         "Maximum model-view stack depth " STRINGIFY(GPU_PY_MATRIX_STACK_DEPTH) " reached"); | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static bool pygpu_stack_is_push_projection_ok_or_error(void) | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  | { | 
					
						
							|  |  |  |   if (GPU_matrix_stack_level_get_projection() >= GPU_PY_MATRIX_STACK_LEN) { | 
					
						
							|  |  |  |     PyErr_SetString( | 
					
						
							|  |  |  |         PyExc_RuntimeError, | 
					
						
							|  |  |  |         "Maximum projection stack depth " STRINGIFY(GPU_PY_MATRIX_STACK_DEPTH) " reached"); | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return true; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static bool pygpu_stack_is_pop_model_view_ok_or_error(void) | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  | { | 
					
						
							|  |  |  |   if (GPU_matrix_stack_level_get_model_view() == 0) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_RuntimeError, "Minimum model-view stack depth reached"); | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static bool pygpu_stack_is_pop_projection_ok_or_error(void) | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  | { | 
					
						
							|  |  |  |   if (GPU_matrix_stack_level_get_projection() == 0) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_RuntimeError, "Minimum projection stack depth reached"); | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | /** \name Manage Stack
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | PyDoc_STRVAR(pygpu_matrix_push_doc, | 
					
						
							| 
									
										
										
										
											2018-11-15 16:54:17 +01:00
										 |  |  |              ".. function:: push()\n" | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2017-08-20 17:23:49 +10:00
										 |  |  |              "   Add to the model-view matrix stack.\n"); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_matrix_push(PyObject *UNUSED(self)) | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |   if (!pygpu_stack_is_push_model_view_ok_or_error()) { | 
					
						
							| 
									
										
										
										
											2017-08-20 17:23:49 +10:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-07-15 15:27:15 +02:00
										 |  |  |   GPU_matrix_push(); | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | PyDoc_STRVAR(pygpu_matrix_pop_doc, | 
					
						
							| 
									
										
										
										
											2018-11-15 16:54:17 +01:00
										 |  |  |              ".. function:: pop()\n" | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2017-08-20 17:23:49 +10:00
										 |  |  |              "   Remove the last model-view matrix from the stack.\n"); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_matrix_pop(PyObject *UNUSED(self)) | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |   if (!pygpu_stack_is_pop_model_view_ok_or_error()) { | 
					
						
							| 
									
										
										
										
											2017-08-20 17:23:49 +10:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-07-15 15:27:15 +02:00
										 |  |  |   GPU_matrix_pop(); | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | PyDoc_STRVAR(pygpu_matrix_push_projection_doc, | 
					
						
							| 
									
										
										
										
											2018-11-15 16:54:17 +01:00
										 |  |  |              ".. function:: push_projection()\n" | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   Add to the projection matrix stack.\n"); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_matrix_push_projection(PyObject *UNUSED(self)) | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |   if (!pygpu_stack_is_push_projection_ok_or_error()) { | 
					
						
							| 
									
										
										
										
											2017-08-20 17:23:49 +10:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-07-15 15:27:15 +02:00
										 |  |  |   GPU_matrix_push_projection(); | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | PyDoc_STRVAR(pygpu_matrix_pop_projection_doc, | 
					
						
							| 
									
										
										
										
											2018-11-15 16:54:17 +01:00
										 |  |  |              ".. function:: pop_projection()\n" | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   Remove the last projection matrix from the stack.\n"); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_matrix_pop_projection(PyObject *UNUSED(self)) | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |   if (!pygpu_stack_is_pop_projection_ok_or_error()) { | 
					
						
							| 
									
										
										
										
											2017-08-20 17:23:49 +10:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-07-15 15:27:15 +02:00
										 |  |  |   GPU_matrix_pop_projection(); | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  | /** \name Stack (Context Manager)
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Safer alternative to ensure balanced push/pop calls. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct { | 
					
						
							| 
									
										
										
										
											2021-06-24 15:56:58 +10:00
										 |  |  |   PyObject_HEAD /* Required Python macro. */ | 
					
						
							| 
									
										
										
										
											2021-06-24 17:10:22 +10:00
										 |  |  |   int type; | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  |   int level; | 
					
						
							| 
									
										
										
										
											2018-09-05 21:10:42 -03:00
										 |  |  | } BPyGPU_MatrixStackContext; | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | enum { | 
					
						
							|  |  |  |   PYGPU_MATRIX_TYPE_MODEL_VIEW = 1, | 
					
						
							|  |  |  |   PYGPU_MATRIX_TYPE_PROJECTION = 2, | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_matrix_stack_context_enter(BPyGPU_MatrixStackContext *self); | 
					
						
							|  |  |  | static PyObject *pygpu_matrix_stack_context_exit(BPyGPU_MatrixStackContext *self, PyObject *args); | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyMethodDef pygpu_matrix_stack_context__tp_methods[] = { | 
					
						
							|  |  |  |     {"__enter__", (PyCFunction)pygpu_matrix_stack_context_enter, METH_NOARGS}, | 
					
						
							|  |  |  |     {"__exit__", (PyCFunction)pygpu_matrix_stack_context_exit, METH_VARARGS}, | 
					
						
							| 
									
										
										
										
											2019-02-03 14:01:45 +11:00
										 |  |  |     {NULL}, | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyTypeObject PyGPUMatrixStackContext_Type = { | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  |     PyVarObject_HEAD_INIT(NULL, 0).tp_name = "GPUMatrixStackContext", | 
					
						
							| 
									
										
										
										
											2018-09-05 21:10:42 -03:00
										 |  |  |     .tp_basicsize = sizeof(BPyGPU_MatrixStackContext), | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  |     .tp_flags = Py_TPFLAGS_DEFAULT, | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |     .tp_methods = pygpu_matrix_stack_context__tp_methods, | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_matrix_stack_context_enter(BPyGPU_MatrixStackContext *self) | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  | { | 
					
						
							|  |  |  |   /* sanity - should never happen */ | 
					
						
							|  |  |  |   if (self->level != -1) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_RuntimeError, "Already in use"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  |   if (self->type == PYGPU_MATRIX_TYPE_MODEL_VIEW) { | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |     if (!pygpu_stack_is_push_model_view_ok_or_error()) { | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-07-15 15:27:15 +02:00
										 |  |  |     GPU_matrix_push(); | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  |     self->level = GPU_matrix_stack_level_get_model_view(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else if (self->type == PYGPU_MATRIX_TYPE_PROJECTION) { | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |     if (!pygpu_stack_is_push_projection_ok_or_error()) { | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-07-15 15:27:15 +02:00
										 |  |  |     GPU_matrix_push_projection(); | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  |     self->level = GPU_matrix_stack_level_get_projection(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2021-03-24 12:38:08 +11:00
										 |  |  |     BLI_assert_unreachable(); | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  |   } | 
					
						
							|  |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_matrix_stack_context_exit(BPyGPU_MatrixStackContext *self, | 
					
						
							|  |  |  |                                                  PyObject *UNUSED(args)) | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  | { | 
					
						
							|  |  |  |   /* sanity - should never happen */ | 
					
						
							|  |  |  |   if (self->level == -1) { | 
					
						
							|  |  |  |     fprintf(stderr, "Not yet in use\n"); | 
					
						
							|  |  |  |     goto finally; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  |   if (self->type == PYGPU_MATRIX_TYPE_MODEL_VIEW) { | 
					
						
							|  |  |  |     const int level = GPU_matrix_stack_level_get_model_view(); | 
					
						
							|  |  |  |     if (level != self->level) { | 
					
						
							|  |  |  |       fprintf(stderr, "Level push/pop mismatch, expected %d, got %d\n", self->level, level); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (level != 0) { | 
					
						
							| 
									
										
										
										
											2018-07-15 15:27:15 +02:00
										 |  |  |       GPU_matrix_pop(); | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else if (self->type == PYGPU_MATRIX_TYPE_PROJECTION) { | 
					
						
							|  |  |  |     const int level = GPU_matrix_stack_level_get_projection(); | 
					
						
							|  |  |  |     if (level != self->level) { | 
					
						
							|  |  |  |       fprintf(stderr, "Level push/pop mismatch, expected %d, got %d", self->level, level); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (level != 0) { | 
					
						
							| 
									
										
										
										
											2018-07-15 15:27:15 +02:00
										 |  |  |       GPU_matrix_pop_projection(); | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2021-03-24 12:38:08 +11:00
										 |  |  |     BLI_assert_unreachable(); | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  |   } | 
					
						
							|  |  |  | finally: | 
					
						
							|  |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_matrix_push_pop_impl(int type) | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-05 21:10:42 -03:00
										 |  |  |   BPyGPU_MatrixStackContext *ret = PyObject_New(BPyGPU_MatrixStackContext, | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |                                                 &PyGPUMatrixStackContext_Type); | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  |   ret->type = type; | 
					
						
							|  |  |  |   ret->level = -1; | 
					
						
							|  |  |  |   return (PyObject *)ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-05 21:10:42 -03:00
										 |  |  | PyDoc_STRVAR( | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |     pygpu_matrix_push_pop_doc, | 
					
						
							| 
									
										
										
										
											2018-11-15 16:54:17 +01:00
										 |  |  |     ".. function:: push_pop()\n" | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  |     "\n" | 
					
						
							|  |  |  |     "   Context manager to ensure balanced push/pop calls, even in the case of an error.\n"); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_matrix_push_pop(PyObject *UNUSED(self)) | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |   return pygpu_matrix_push_pop_impl(PYGPU_MATRIX_TYPE_MODEL_VIEW); | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-05 21:10:42 -03:00
										 |  |  | PyDoc_STRVAR( | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |     pygpu_matrix_push_pop_projection_doc, | 
					
						
							| 
									
										
										
										
											2018-11-15 16:54:17 +01:00
										 |  |  |     ".. function:: push_pop_projection()\n" | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  |     "\n" | 
					
						
							|  |  |  |     "   Context manager to ensure balanced push/pop calls, even in the case of an error.\n"); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_matrix_push_pop_projection(PyObject *UNUSED(self)) | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |   return pygpu_matrix_push_pop_impl(PYGPU_MATRIX_TYPE_PROJECTION); | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | /** \name Manipulate State
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | PyDoc_STRVAR(pygpu_matrix_multiply_matrix_doc, | 
					
						
							| 
									
										
										
										
											2018-11-15 16:54:17 +01:00
										 |  |  |              ".. function:: multiply_matrix(matrix)\n" | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   Multiply the current stack matrix.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :param matrix: A 4x4 matrix.\n" | 
					
						
							|  |  |  |              "   :type matrix: :class:`mathutils.Matrix`\n"); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_matrix_multiply_matrix(PyObject *UNUSED(self), PyObject *value) | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | { | 
					
						
							|  |  |  |   MatrixObject *pymat; | 
					
						
							|  |  |  |   if (!Matrix_Parse4x4(value, &pymat)) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-07-15 15:27:15 +02:00
										 |  |  |   GPU_matrix_mul(pymat->matrix); | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | PyDoc_STRVAR(pygpu_matrix_scale_doc, | 
					
						
							| 
									
										
										
										
											2018-11-15 16:54:17 +01:00
										 |  |  |              ".. function:: scale(scale)\n" | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |              "\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"); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_matrix_scale(PyObject *UNUSED(self), PyObject *value) | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | { | 
					
						
							|  |  |  |   float scale[3]; | 
					
						
							|  |  |  |   int len; | 
					
						
							|  |  |  |   if ((len = mathutils_array_parse( | 
					
						
							|  |  |  |            scale, 2, 3, value, "gpu.matrix.scale(): invalid vector arg")) == -1) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if (len == 2) { | 
					
						
							| 
									
										
										
										
											2018-07-15 15:27:15 +02:00
										 |  |  |     GPU_matrix_scale_2fv(scale); | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2018-07-15 15:27:15 +02:00
										 |  |  |     GPU_matrix_scale_3fv(scale); | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |   } | 
					
						
							|  |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | PyDoc_STRVAR(pygpu_matrix_scale_uniform_doc, | 
					
						
							| 
									
										
										
										
											2018-11-15 16:54:17 +01:00
										 |  |  |              ".. function:: scale_uniform(scale)\n" | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   :param scale: Scale the current stack matrix.\n" | 
					
						
							| 
									
										
										
										
											2018-11-15 17:21:04 +01:00
										 |  |  |              "   :type scale: float\n"); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_matrix_scale_uniform(PyObject *UNUSED(self), PyObject *value) | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | { | 
					
						
							|  |  |  |   float scalar; | 
					
						
							|  |  |  |   if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) { | 
					
						
							|  |  |  |     PyErr_Format(PyExc_TypeError, "expected a number, not %.200s", Py_TYPE(value)->tp_name); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-07-15 15:27:15 +02:00
										 |  |  |   GPU_matrix_scale_1f(scalar); | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | PyDoc_STRVAR(pygpu_matrix_translate_doc, | 
					
						
							| 
									
										
										
										
											2018-11-15 16:54:17 +01:00
										 |  |  |              ".. function:: translate(offset)\n" | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |              "\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"); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_matrix_translate(PyObject *UNUSED(self), PyObject *value) | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | { | 
					
						
							|  |  |  |   float offset[3]; | 
					
						
							|  |  |  |   int len; | 
					
						
							|  |  |  |   if ((len = mathutils_array_parse( | 
					
						
							|  |  |  |            offset, 2, 3, value, "gpu.matrix.translate(): invalid vector arg")) == -1) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if (len == 2) { | 
					
						
							| 
									
										
										
										
											2018-07-15 15:27:15 +02:00
										 |  |  |     GPU_matrix_translate_2fv(offset); | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2018-07-15 15:27:15 +02:00
										 |  |  |     GPU_matrix_translate_3fv(offset); | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |   } | 
					
						
							|  |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Write State
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | PyDoc_STRVAR(pygpu_matrix_reset_doc, | 
					
						
							| 
									
										
										
										
											2018-11-15 16:54:17 +01:00
										 |  |  |              ".. function:: reset()\n" | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   Empty stack and set to identity.\n"); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_matrix_reset(PyObject *UNUSED(self)) | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-15 15:27:15 +02:00
										 |  |  |   GPU_matrix_reset(); | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | PyDoc_STRVAR(pygpu_matrix_load_identity_doc, | 
					
						
							| 
									
										
										
										
											2018-11-15 16:54:17 +01:00
										 |  |  |              ".. function:: load_identity()\n" | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   Empty stack and set to identity.\n"); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_matrix_load_identity(PyObject *UNUSED(self)) | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-15 15:27:15 +02:00
										 |  |  |   GPU_matrix_identity_set(); | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | PyDoc_STRVAR(pygpu_matrix_load_matrix_doc, | 
					
						
							| 
									
										
										
										
											2018-11-15 16:54:17 +01:00
										 |  |  |              ".. function:: load_matrix(matrix)\n" | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   Load a matrix into the stack.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :param matrix: A 4x4 matrix.\n" | 
					
						
							|  |  |  |              "   :type matrix: :class:`mathutils.Matrix`\n"); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_matrix_load_matrix(PyObject *UNUSED(self), PyObject *value) | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | { | 
					
						
							|  |  |  |   MatrixObject *pymat; | 
					
						
							|  |  |  |   if (!Matrix_Parse4x4(value, &pymat)) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-07-15 15:27:15 +02:00
										 |  |  |   GPU_matrix_set(pymat->matrix); | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | PyDoc_STRVAR(pygpu_matrix_load_projection_matrix_doc, | 
					
						
							| 
									
										
										
										
											2018-11-15 16:54:17 +01:00
										 |  |  |              ".. function:: load_projection_matrix(matrix)\n" | 
					
						
							| 
									
										
										
										
											2018-09-21 15:06:22 -03:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   Load a projection matrix into the stack.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :param matrix: A 4x4 matrix.\n" | 
					
						
							|  |  |  |              "   :type matrix: :class:`mathutils.Matrix`\n"); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_matrix_load_projection_matrix(PyObject *UNUSED(self), PyObject *value) | 
					
						
							| 
									
										
										
										
											2018-09-21 15:06:22 -03:00
										 |  |  | { | 
					
						
							|  |  |  |   MatrixObject *pymat; | 
					
						
							|  |  |  |   if (!Matrix_Parse4x4(value, &pymat)) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   GPU_matrix_projection_set(pymat->matrix); | 
					
						
							|  |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Read State
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | PyDoc_STRVAR(pygpu_matrix_get_projection_matrix_doc, | 
					
						
							| 
									
										
										
										
											2018-11-15 16:54:17 +01:00
										 |  |  |              ".. function:: get_projection_matrix()\n" | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   Return a copy of the projection matrix.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :return: A 4x4 projection matrix.\n" | 
					
						
							|  |  |  |              "   :rtype: :class:`mathutils.Matrix`\n"); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_matrix_get_projection_matrix(PyObject *UNUSED(self)) | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | { | 
					
						
							|  |  |  |   float matrix[4][4]; | 
					
						
							| 
									
										
										
										
											2018-11-15 17:10:32 +01:00
										 |  |  |   GPU_matrix_projection_get(matrix); | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |   return Matrix_CreatePyObject(&matrix[0][0], 4, 4, NULL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | PyDoc_STRVAR(pygpu_matrix_get_model_view_matrix_doc, | 
					
						
							| 
									
										
										
										
											2018-11-15 17:10:32 +01:00
										 |  |  |              ".. function:: get_model_view_matrix()\n" | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2018-11-15 17:10:32 +01:00
										 |  |  |              "   Return a copy of the model-view matrix.\n" | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   :return: A 4x4 view matrix.\n" | 
					
						
							|  |  |  |              "   :rtype: :class:`mathutils.Matrix`\n"); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_matrix_get_model_view_matrix(PyObject *UNUSED(self)) | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | { | 
					
						
							|  |  |  |   float matrix[4][4]; | 
					
						
							| 
									
										
										
										
											2018-11-15 17:10:32 +01:00
										 |  |  |   GPU_matrix_model_view_get(matrix); | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |   return Matrix_CreatePyObject(&matrix[0][0], 4, 4, NULL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | PyDoc_STRVAR(pygpu_matrix_get_normal_matrix_doc, | 
					
						
							| 
									
										
										
										
											2018-11-15 16:54:17 +01:00
										 |  |  |              ".. function:: get_normal_matrix()\n" | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   Return a copy of the normal matrix.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :return: A 3x3 normal matrix.\n" | 
					
						
							|  |  |  |              "   :rtype: :class:`mathutils.Matrix`\n"); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_matrix_get_normal_matrix(PyObject *UNUSED(self)) | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | { | 
					
						
							|  |  |  |   float matrix[3][3]; | 
					
						
							| 
									
										
										
										
											2018-07-15 15:27:15 +02:00
										 |  |  |   GPU_matrix_normal_get(matrix); | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |   return Matrix_CreatePyObject(&matrix[0][0], 3, 3, NULL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Module
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static struct PyMethodDef pygpu_matrix__tp_methods[] = { | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |     /* Manage Stack */ | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |     {"push", (PyCFunction)pygpu_matrix_push, METH_NOARGS, pygpu_matrix_push_doc}, | 
					
						
							|  |  |  |     {"pop", (PyCFunction)pygpu_matrix_pop, METH_NOARGS, pygpu_matrix_pop_doc}, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-05 21:10:42 -03:00
										 |  |  |     {"push_projection", | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      (PyCFunction)pygpu_matrix_push_projection, | 
					
						
							| 
									
										
										
										
											2018-09-05 21:10:42 -03:00
										 |  |  |      METH_NOARGS, | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      pygpu_matrix_push_projection_doc}, | 
					
						
							| 
									
										
										
										
											2018-09-05 21:10:42 -03:00
										 |  |  |     {"pop_projection", | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      (PyCFunction)pygpu_matrix_pop_projection, | 
					
						
							| 
									
										
										
										
											2018-09-05 21:10:42 -03:00
										 |  |  |      METH_NOARGS, | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      pygpu_matrix_pop_projection_doc}, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  |     /* Stack (Context Manager) */ | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |     {"push_pop", (PyCFunction)pygpu_matrix_push_pop, METH_NOARGS, pygpu_matrix_push_pop_doc}, | 
					
						
							| 
									
										
										
										
											2018-09-05 21:10:42 -03:00
										 |  |  |     {"push_pop_projection", | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      (PyCFunction)pygpu_matrix_push_pop_projection, | 
					
						
							| 
									
										
										
										
											2018-09-05 21:10:42 -03:00
										 |  |  |      METH_NOARGS, | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      pygpu_matrix_push_pop_projection_doc}, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |     /* Manipulate State */ | 
					
						
							| 
									
										
										
										
											2018-09-05 21:10:42 -03:00
										 |  |  |     {"multiply_matrix", | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      (PyCFunction)pygpu_matrix_multiply_matrix, | 
					
						
							| 
									
										
										
										
											2018-09-05 21:10:42 -03:00
										 |  |  |      METH_O, | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      pygpu_matrix_multiply_matrix_doc}, | 
					
						
							|  |  |  |     {"scale", (PyCFunction)pygpu_matrix_scale, METH_O, pygpu_matrix_scale_doc}, | 
					
						
							|  |  |  |     {"scale_uniform", | 
					
						
							|  |  |  |      (PyCFunction)pygpu_matrix_scale_uniform, | 
					
						
							|  |  |  |      METH_O, | 
					
						
							|  |  |  |      pygpu_matrix_scale_uniform_doc}, | 
					
						
							|  |  |  |     {"translate", (PyCFunction)pygpu_matrix_translate, METH_O, pygpu_matrix_translate_doc}, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | /* TODO */ | 
					
						
							|  |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |     {"rotate", (PyCFunction)pygpu_matrix_rotate, METH_O, pygpu_matrix_rotate_doc}, | 
					
						
							|  |  |  |     {"rotate_axis", (PyCFunction)pygpu_matrix_rotate_axis, METH_O, pygpu_matrix_rotate_axis_doc}, | 
					
						
							|  |  |  |     {"look_at", (PyCFunction)pygpu_matrix_look_at, METH_O, pygpu_matrix_look_at_doc}, | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Write State */ | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |     {"reset", (PyCFunction)pygpu_matrix_reset, METH_NOARGS, pygpu_matrix_reset_doc}, | 
					
						
							| 
									
										
										
										
											2018-09-05 21:10:42 -03:00
										 |  |  |     {"load_identity", | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      (PyCFunction)pygpu_matrix_load_identity, | 
					
						
							| 
									
										
										
										
											2018-09-05 21:10:42 -03:00
										 |  |  |      METH_NOARGS, | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      pygpu_matrix_load_identity_doc}, | 
					
						
							|  |  |  |     {"load_matrix", (PyCFunction)pygpu_matrix_load_matrix, METH_O, pygpu_matrix_load_matrix_doc}, | 
					
						
							| 
									
										
										
										
											2018-09-21 15:06:22 -03:00
										 |  |  |     {"load_projection_matrix", | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      (PyCFunction)pygpu_matrix_load_projection_matrix, | 
					
						
							| 
									
										
										
										
											2018-09-21 15:06:22 -03:00
										 |  |  |      METH_O, | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      pygpu_matrix_load_projection_matrix_doc}, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |     /* Read State */ | 
					
						
							| 
									
										
										
										
											2018-09-05 21:10:42 -03:00
										 |  |  |     {"get_projection_matrix", | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      (PyCFunction)pygpu_matrix_get_projection_matrix, | 
					
						
							| 
									
										
										
										
											2018-09-05 21:10:42 -03:00
										 |  |  |      METH_NOARGS, | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      pygpu_matrix_get_projection_matrix_doc}, | 
					
						
							| 
									
										
										
										
											2018-11-15 17:10:32 +01:00
										 |  |  |     {"get_model_view_matrix", | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      (PyCFunction)pygpu_matrix_get_model_view_matrix, | 
					
						
							| 
									
										
										
										
											2018-11-15 17:10:32 +01:00
										 |  |  |      METH_NOARGS, | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      pygpu_matrix_get_model_view_matrix_doc}, | 
					
						
							| 
									
										
										
										
											2018-09-05 21:10:42 -03:00
										 |  |  |     {"get_normal_matrix", | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      (PyCFunction)pygpu_matrix_get_normal_matrix, | 
					
						
							| 
									
										
										
										
											2018-09-05 21:10:42 -03:00
										 |  |  |      METH_NOARGS, | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      pygpu_matrix_get_normal_matrix_doc}, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-03 14:01:45 +11:00
										 |  |  |     {NULL, NULL, 0, NULL}, | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | PyDoc_STRVAR(pygpu_matrix__tp_doc, "This module provides access to the matrix stack."); | 
					
						
							|  |  |  | static PyModuleDef pygpu_matrix_module_def = { | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |     PyModuleDef_HEAD_INIT, | 
					
						
							|  |  |  |     .m_name = "gpu.matrix", | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |     .m_doc = pygpu_matrix__tp_doc, | 
					
						
							|  |  |  |     .m_methods = pygpu_matrix__tp_methods, | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-11 13:53:20 -03:00
										 |  |  | PyObject *bpygpu_matrix_init(void) | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | { | 
					
						
							|  |  |  |   PyObject *submodule; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |   submodule = PyModule_Create(&pygpu_matrix_module_def); | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |   if (PyType_Ready(&PyGPUMatrixStackContext_Type) < 0) { | 
					
						
							| 
									
										
										
										
											2017-08-20 19:31:59 +10:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 00:01:19 +10:00
										 |  |  |   return submodule; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** \} */ |