diff options
Diffstat (limited to 'source/blender/python/gpu/gpu_py_batch.c')
-rw-r--r-- | source/blender/python/gpu/gpu_py_batch.c | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/source/blender/python/gpu/gpu_py_batch.c b/source/blender/python/gpu/gpu_py_batch.c index 0e4cc4d2219..9989077670b 100644 --- a/source/blender/python/gpu/gpu_py_batch.c +++ b/source/blender/python/gpu/gpu_py_batch.c @@ -38,12 +38,14 @@ #include "../generic/py_capi_utils.h" +#include "gpu_py.h" #include "gpu_py_api.h" -#include "gpu_py_batch.h" /* own include */ #include "gpu_py_element.h" #include "gpu_py_shader.h" #include "gpu_py_vertex_buffer.h" +#include "gpu_py_batch.h" /* own include */ + /* -------------------------------------------------------------------- */ /** \name Utility Functions * \{ */ @@ -69,50 +71,44 @@ static PyObject *pygpu_batch__tp_new(PyTypeObject *UNUSED(type), PyObject *args, const char *exc_str_missing_arg = "GPUBatch.__new__() missing required argument '%s' (pos %d)"; - struct { - GPUPrimType type_id; - BPyGPUVertBuf *py_vertbuf; - BPyGPUIndexBuf *py_indexbuf; - } params = {GPU_PRIM_NONE, NULL, NULL}; + struct PyC_StringEnum prim_type = {bpygpu_primtype_items, GPU_PRIM_NONE}; + BPyGPUVertBuf *py_vertbuf = NULL; + BPyGPUIndexBuf *py_indexbuf = NULL; static const char *_keywords[] = {"type", "buf", "elem", NULL}; static _PyArg_Parser _parser = {"|$O&O!O!:GPUBatch.__new__", _keywords, 0}; if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &_parser, - bpygpu_ParsePrimType, - ¶ms.type_id, + PyC_ParseStringEnum, + &prim_type, &BPyGPUVertBuf_Type, - ¶ms.py_vertbuf, + &py_vertbuf, &BPyGPUIndexBuf_Type, - ¶ms.py_indexbuf)) { + &py_indexbuf)) { return NULL; } - if (params.type_id == GPU_PRIM_NONE) { - PyErr_Format(PyExc_TypeError, exc_str_missing_arg, _keywords[0], 1); - return NULL; - } + BLI_assert(prim_type.value_found != GPU_PRIM_NONE); - if (params.py_vertbuf == NULL) { + if (py_vertbuf == NULL) { PyErr_Format(PyExc_TypeError, exc_str_missing_arg, _keywords[1], 2); return NULL; } - GPUBatch *batch = GPU_batch_create(params.type_id, - params.py_vertbuf->buf, - params.py_indexbuf ? params.py_indexbuf->elem : NULL); + GPUBatch *batch = GPU_batch_create( + prim_type.value_found, py_vertbuf->buf, py_indexbuf ? py_indexbuf->elem : NULL); BPyGPUBatch *ret = (BPyGPUBatch *)BPyGPUBatch_CreatePyObject(batch); #ifdef USE_GPU_PY_REFERENCES - ret->references = PyList_New(params.py_indexbuf ? 2 : 1); - PyList_SET_ITEM(ret->references, 0, (PyObject *)params.py_vertbuf); - Py_INCREF(params.py_vertbuf); + ret->references = PyList_New(py_indexbuf ? 2 : 1); + PyList_SET_ITEM(ret->references, 0, (PyObject *)py_vertbuf); + Py_INCREF(py_vertbuf); - if (params.py_indexbuf != NULL) { - PyList_SET_ITEM(ret->references, 1, (PyObject *)params.py_indexbuf); - Py_INCREF(params.py_indexbuf); + if (py_indexbuf != NULL) { + PyList_SET_ITEM(ret->references, 1, (PyObject *)py_indexbuf); + Py_INCREF(py_indexbuf); } PyObject_GC_Track(ret); |