Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGermano Cavalcante <mano-wii>2021-02-22 14:26:45 +0300
committerGermano Cavalcante <germano.costa@ig.com.br>2021-02-22 14:35:52 +0300
commit086d70e910a09185e220169342367a0c95ade0fc (patch)
treeafbb7111ce365bcd61fd6cd307e34c01accb6b19 /source/blender/python/gpu/gpu_py_element.c
parent78c3caf3c1b87f449837b11c903ddeaf00afe7b9 (diff)
GPU Python: Use 'PyC_ParseStringEnum' to parse items
Currently the GPU module for python has different ways to handle enums. - Organizing items in `PyC_StringEnumItems` arrays and parsing them with `PyC_ParseStringEnum`. - Using dedicated functions for each type of enum (`bpygpu_ParsePrimType`, `pygpu_ParseVertCompType` and `pygpu_ParseVertFetchMode`). Although apparently more efficient (especially `pygpu_ParseVertCompType` which transforms strings into integers for simple comparison), these dedicated functions duplicate functionality, increase the complexity of the code and consequently make it less readable. Reviewed By: campbellbarton Differential Revision: https://developer.blender.org/D10456
Diffstat (limited to 'source/blender/python/gpu/gpu_py_element.c')
-rw-r--r--source/blender/python/gpu/gpu_py_element.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/source/blender/python/gpu/gpu_py_element.c b/source/blender/python/gpu/gpu_py_element.c
index f43338c42d2..0e5094cbbc0 100644
--- a/source/blender/python/gpu/gpu_py_element.c
+++ b/source/blender/python/gpu/gpu_py_element.c
@@ -32,6 +32,7 @@
#include "../generic/py_capi_utils.h"
#include "../generic/python_utildefines.h"
+#include "gpu_py.h"
#include "gpu_py_api.h"
#include "gpu_py_element.h" /* own include */
@@ -46,10 +47,8 @@ static PyObject *pygpu_IndexBuf__tp_new(PyTypeObject *UNUSED(type), PyObject *ar
const char *error_prefix = "IndexBuf.__new__";
bool ok = true;
- struct {
- GPUPrimType type_id;
- PyObject *seq;
- } params;
+ struct PyC_StringEnum prim_type = {bpygpu_primtype_items, GPU_PRIM_NONE};
+ PyObject *seq;
uint verts_per_prim;
uint index_len;
@@ -58,11 +57,11 @@ static PyObject *pygpu_IndexBuf__tp_new(PyTypeObject *UNUSED(type), PyObject *ar
static const char *_keywords[] = {"type", "seq", NULL};
static _PyArg_Parser _parser = {"$O&O:IndexBuf.__new__", _keywords, 0};
if (!_PyArg_ParseTupleAndKeywordsFast(
- args, kwds, &_parser, bpygpu_ParsePrimType, &params.type_id, &params.seq)) {
+ args, kwds, &_parser, PyC_ParseStringEnum, &prim_type, &seq)) {
return NULL;
}
- verts_per_prim = GPU_indexbuf_primitive_len(params.type_id);
+ verts_per_prim = GPU_indexbuf_primitive_len(prim_type.value_found);
if (verts_per_prim == -1) {
PyErr_Format(PyExc_ValueError,
"The argument 'type' must be "
@@ -70,10 +69,10 @@ static PyObject *pygpu_IndexBuf__tp_new(PyTypeObject *UNUSED(type), PyObject *ar
return NULL;
}
- if (PyObject_CheckBuffer(params.seq)) {
+ if (PyObject_CheckBuffer(seq)) {
Py_buffer pybuffer;
- if (PyObject_GetBuffer(params.seq, &pybuffer, PyBUF_FORMAT | PyBUF_ND) == -1) {
+ if (PyObject_GetBuffer(seq, &pybuffer, PyBUF_FORMAT | PyBUF_ND) == -1) {
/* PyObject_GetBuffer already handles error messages. */
return NULL;
}
@@ -97,7 +96,7 @@ static PyObject *pygpu_IndexBuf__tp_new(PyTypeObject *UNUSED(type), PyObject *ar
/* The `vertex_len` parameter is only used for asserts in the Debug build. */
/* Not very useful in python since scripts are often tested in Release build. */
/* Use `INT_MAX` instead of the actual number of vertices. */
- GPU_indexbuf_init(&builder, params.type_id, index_len, INT_MAX);
+ GPU_indexbuf_init(&builder, prim_type.value_found, index_len, INT_MAX);
#if 0
uint *buf = pybuffer.buf;
@@ -111,7 +110,7 @@ static PyObject *pygpu_IndexBuf__tp_new(PyTypeObject *UNUSED(type), PyObject *ar
PyBuffer_Release(&pybuffer);
}
else {
- PyObject *seq_fast = PySequence_Fast(params.seq, error_prefix);
+ PyObject *seq_fast = PySequence_Fast(seq, error_prefix);
if (seq_fast == NULL) {
return false;
@@ -126,7 +125,7 @@ static PyObject *pygpu_IndexBuf__tp_new(PyTypeObject *UNUSED(type), PyObject *ar
/* The `vertex_len` parameter is only used for asserts in the Debug build. */
/* Not very useful in python since scripts are often tested in Release build. */
/* Use `INT_MAX` instead of the actual number of vertices. */
- GPU_indexbuf_init(&builder, params.type_id, index_len, INT_MAX);
+ GPU_indexbuf_init(&builder, prim_type.value_found, index_len, INT_MAX);
if (verts_per_prim == 1) {
for (uint i = 0; i < seq_len; i++) {