Changeset View
Changeset View
Standalone View
Standalone View
source/blender/python/gpu/gpu_py.c
- This file was moved from source/blender/python/gpu/gpu_py_api.c.
| Show All 28 Lines | |||||
| */ | */ | ||||
| #include <Python.h> | #include <Python.h> | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "../generic/python_utildefines.h" | #include "../generic/python_utildefines.h" | ||||
| #include "GPU_init_exit.h" | |||||
| #include "GPU_primitive.h" | |||||
| #include "gpu_py_matrix.h" | #include "gpu_py_matrix.h" | ||||
| #include "gpu_py_select.h" | #include "gpu_py_select.h" | ||||
| #include "gpu_py_types.h" | #include "gpu_py_types.h" | ||||
| #include "gpu_py_api.h" /* own include */ | #include "gpu_py.h" /* own include */ | ||||
| /* -------------------------------------------------------------------- */ | |||||
| /** \name Utils to invalidate functions | |||||
| * \{ */ | |||||
| bool bpygpu_is_initialized(void) | |||||
| { | |||||
| if (!GPU_is_initialized()) { | |||||
| PyErr_SetString( | |||||
| PyExc_SystemError, | |||||
brecht: This is too vague. Could be something more specific like:
```
GPU functions for drawing are… | |||||
| "GPU functions for drawing are not available in background mode"); | |||||
| return false; | |||||
| } | |||||
| return true; | |||||
| } | |||||
Not Done Inline ActionsThis seems to permanently disable the GPU module when Python tries to import it. But it can be initialized later on still, so this seems wrong. Maybe it is better to disallow important the module at the top level. @Bastien Montagne (mont29) say in the task it wasn't necessary, but to me that seems like the cleaner solution? brecht: This seems to permanently disable the GPU module when Python tries to import it. But it can be… | |||||
Done Inline ActionsI agree, I didn't think of this. With a small change in the C code the python files can be initialized before the GPU. mano-wii: I agree, I didn't think of this. With a small change in the C code the python files can be… | |||||
| /** \} */ | |||||
| /* -------------------------------------------------------------------- */ | |||||
| /** \name Primitive Type Utils | |||||
| * \{ */ | |||||
| int bpygpu_ParsePrimType(PyObject *o, void *p) | |||||
| { | |||||
| Py_ssize_t mode_id_len; | |||||
| const char *mode_id = _PyUnicode_AsStringAndSize(o, &mode_id_len); | |||||
| if (mode_id == NULL) { | |||||
| PyErr_Format(PyExc_ValueError, | |||||
| "expected a string, got %s", | |||||
| Py_TYPE(o)->tp_name); | |||||
| return 0; | |||||
| } | |||||
| #define MATCH_ID(id) \ | |||||
| if (mode_id_len == strlen(STRINGIFY(id))) { \ | |||||
| if (STREQ(mode_id, STRINGIFY(id))) { \ | |||||
| mode = GPU_PRIM_##id; \ | |||||
| goto success; \ | |||||
| } \ | |||||
| } ((void)0) | |||||
| GPUPrimType mode; | |||||
| MATCH_ID(POINTS); | |||||
| MATCH_ID(LINES); | |||||
| MATCH_ID(TRIS); | |||||
| MATCH_ID(LINE_STRIP); | |||||
| MATCH_ID(LINE_LOOP); | |||||
| MATCH_ID(TRI_STRIP); | |||||
| MATCH_ID(TRI_FAN); | |||||
| MATCH_ID(LINE_STRIP_ADJ); | |||||
| #undef MATCH_ID | |||||
| PyErr_Format(PyExc_ValueError, | |||||
| "unknown type literal: '%s'", | |||||
| mode_id); | |||||
| return 0; | |||||
| success: | |||||
| (*(GPUPrimType *)p) = mode; | |||||
| return 1; | |||||
| } | |||||
| /** \} */ | |||||
| /* -------------------------------------------------------------------- */ | |||||
| /** \name GPU Module | |||||
| * \{ */ | |||||
| PyDoc_STRVAR(GPU_doc, | PyDoc_STRVAR(GPU_doc, | ||||
| "This module provides Python wrappers for the GPU implementation in Blender. " | "This module provides Python wrappers for the GPU implementation in Blender. " | ||||
| "Some higher level functions can be found in the `gpu_extras` module. " | "Some higher level functions can be found in the `gpu_extras` module. " | ||||
| "\n\n" | "\n\n" | ||||
| "Submodules:\n" | "Submodules:\n" | ||||
| "\n" | "\n" | ||||
| ".. toctree::\n" | ".. toctree::\n" | ||||
| Show All 28 Lines | PyObject *BPyInit_gpu(void) | ||||
| PyModule_AddObject(mod, "select", (submodule = BPyInit_gpu_select())); | PyModule_AddObject(mod, "select", (submodule = BPyInit_gpu_select())); | ||||
| PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); | PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); | ||||
| PyModule_AddObject(mod, "shader", (submodule = BPyInit_gpu_shader())); | PyModule_AddObject(mod, "shader", (submodule = BPyInit_gpu_shader())); | ||||
| PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); | PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); | ||||
| return mod; | return mod; | ||||
| } | } | ||||
| /** \} */ | |||||
This is too vague. Could be something more specific like: