PyAPI: remove GPUVertFormat() creation from a list
We already have `attr_add` method, best not have two ways to do the same thing. See: D3830
This commit is contained in:
@@ -144,14 +144,6 @@ static int bpygpu_ParseVertFetchMode(PyObject *o, void *p)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int get_default_fetch_mode(GPUVertCompType type)
|
||||
{
|
||||
switch (type) {
|
||||
case GPU_COMP_F32: return GPU_FETCH_FLOAT;
|
||||
default: return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
|
||||
@@ -160,62 +152,13 @@ static int get_default_fetch_mode(GPUVertCompType type)
|
||||
/** \name VertFormat Type
|
||||
* \{ */
|
||||
|
||||
static bool bpygpu_vertformat_attr_add_simple(
|
||||
GPUVertFormat *format, const char *name, GPUVertCompType comp_type, int length)
|
||||
{
|
||||
if (length <= 0) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"length of an attribute must greater than 0");
|
||||
return false;
|
||||
}
|
||||
|
||||
int fetch_mode = get_default_fetch_mode(comp_type);
|
||||
if (fetch_mode == -1) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"no default fetch mode found");
|
||||
return false;
|
||||
}
|
||||
|
||||
GPU_vertformat_attr_add(format, name, comp_type, length, fetch_mode);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool bpygpu_vertformat_attr_add_from_tuple(
|
||||
GPUVertFormat *format, PyObject *data)
|
||||
{
|
||||
const char *name;
|
||||
GPUVertCompType comp_type;
|
||||
int length;
|
||||
|
||||
if (!PyArg_ParseTuple(data, "sO&i", &name, bpygpu_ParseVertCompType, &comp_type, &length)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return bpygpu_vertformat_attr_add_simple(format, name, comp_type, length);
|
||||
}
|
||||
|
||||
static PyObject *bpygpu_VertFormat_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds)
|
||||
{
|
||||
const char *error_prefix = "GPUVertFormat.__new__";
|
||||
PyListObject *format_list = NULL;
|
||||
|
||||
static const char *_keywords[] = {"format", NULL};
|
||||
static _PyArg_Parser _parser = {"|O!:GPUVertFormat.__new__", _keywords, 0};
|
||||
if (!_PyArg_ParseTupleAndKeywordsFast(
|
||||
args, kwds, &_parser,
|
||||
&PyList_Type, &format_list))
|
||||
{
|
||||
if (PyTuple_GET_SIZE(args) || (kwds && PyDict_Size(kwds))) {
|
||||
PyErr_SetString(PyExc_ValueError, "This function takes no arguments");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BPyGPUVertFormat *ret = (BPyGPUVertFormat *)BPyGPUVertFormat_CreatePyObject(NULL);
|
||||
|
||||
if (format_list && !bpygpu_vertformat_from_PyList(format_list, error_prefix, &ret->fmt)) {
|
||||
Py_DECREF(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (PyObject *)ret;
|
||||
return BPyGPUVertFormat_CreatePyObject(NULL);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(bpygpu_VertFormat_attr_add_doc,
|
||||
@@ -296,27 +239,4 @@ PyObject *BPyGPUVertFormat_CreatePyObject(GPUVertFormat *fmt)
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
bool bpygpu_vertformat_from_PyList(
|
||||
const PyListObject *list, const char *error_prefix, GPUVertFormat *r_fmt)
|
||||
{
|
||||
BLI_assert(PyList_Check(list));
|
||||
|
||||
Py_ssize_t amount = Py_SIZE(list);
|
||||
|
||||
for (Py_ssize_t i = 0; i < amount; i++) {
|
||||
PyObject *element = PyList_GET_ITEM(list, i);
|
||||
if (!PyTuple_Check(element)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s expected a list of tuples", error_prefix);
|
||||
|
||||
return false;
|
||||
}
|
||||
if (!bpygpu_vertformat_attr_add_from_tuple(r_fmt, element)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
Reference in New Issue
Block a user