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:
@@ -222,43 +222,23 @@ static int bpygpu_attr_fill(GPUVertBuf *buf, int id, PyObject *py_seq_data, cons
|
|||||||
|
|
||||||
static PyObject *bpygpu_VertBuf_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds)
|
static PyObject *bpygpu_VertBuf_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
const char *error_prefix = "GPUVertBuf.__new__";
|
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
PyObject *py_fmt;
|
PyObject *py_fmt;
|
||||||
uint len;
|
uint len;
|
||||||
} params;
|
} params;
|
||||||
|
|
||||||
static const char *_keywords[] = {"format", "len", NULL};
|
static const char *_keywords[] = {"format", "len", NULL};
|
||||||
static _PyArg_Parser _parser = {"OI:GPUVertBuf.__new__", _keywords, 0};
|
static _PyArg_Parser _parser = {"O!I:GPUVertBuf.__new__", _keywords, 0};
|
||||||
if (!_PyArg_ParseTupleAndKeywordsFast(
|
if (!_PyArg_ParseTupleAndKeywordsFast(
|
||||||
args, kwds, &_parser,
|
args, kwds, &_parser,
|
||||||
¶ms.py_fmt,
|
&BPyGPUVertFormat_Type, ¶ms.py_fmt,
|
||||||
¶ms.len))
|
¶ms.len))
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
GPUVertFormat *fmt, fmt_stack;
|
const GPUVertFormat *fmt = &((BPyGPUVertFormat *)params.py_fmt)->fmt;
|
||||||
|
GPUVertBuf *vbo = GPU_vertbuf_create_with_format(fmt);
|
||||||
if (BPyGPUVertFormat_Check(params.py_fmt)) {
|
|
||||||
fmt = &((BPyGPUVertFormat *)params.py_fmt)->fmt;
|
|
||||||
}
|
|
||||||
else if (PyList_Check(params.py_fmt)) {
|
|
||||||
fmt = &fmt_stack;
|
|
||||||
GPU_vertformat_clear(fmt);
|
|
||||||
if (!bpygpu_vertformat_from_PyList(
|
|
||||||
(PyListObject *)params.py_fmt, error_prefix, fmt))
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
PyErr_SetString(PyExc_TypeError, "format not understood");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct GPUVertBuf *vbo = GPU_vertbuf_create_with_format(fmt);
|
|
||||||
|
|
||||||
GPU_vertbuf_data_alloc(vbo, params.len);
|
GPU_vertbuf_data_alloc(vbo, params.len);
|
||||||
|
|
||||||
|
|||||||
@@ -144,14 +144,6 @@ static int bpygpu_ParseVertFetchMode(PyObject *o, void *p)
|
|||||||
return 1;
|
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
|
/** \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)
|
static PyObject *bpygpu_VertFormat_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
const char *error_prefix = "GPUVertFormat.__new__";
|
if (PyTuple_GET_SIZE(args) || (kwds && PyDict_Size(kwds))) {
|
||||||
PyListObject *format_list = NULL;
|
PyErr_SetString(PyExc_ValueError, "This function takes no arguments");
|
||||||
|
|
||||||
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))
|
|
||||||
{
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
return BPyGPUVertFormat_CreatePyObject(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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(bpygpu_VertFormat_attr_add_doc,
|
PyDoc_STRVAR(bpygpu_VertFormat_attr_add_doc,
|
||||||
@@ -296,27 +239,4 @@ PyObject *BPyGPUVertFormat_CreatePyObject(GPUVertFormat *fmt)
|
|||||||
return (PyObject *)self;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** \} */
|
/** \} */
|
||||||
|
|||||||
@@ -37,7 +37,5 @@ typedef struct BPyGPUVertFormat {
|
|||||||
} BPyGPUVertFormat;
|
} BPyGPUVertFormat;
|
||||||
|
|
||||||
PyObject *BPyGPUVertFormat_CreatePyObject(struct GPUVertFormat *fmt);
|
PyObject *BPyGPUVertFormat_CreatePyObject(struct GPUVertFormat *fmt);
|
||||||
bool bpygpu_vertformat_from_PyList(
|
|
||||||
const PyListObject *list, const char *error_prefix, GPUVertFormat *r_fmt);
|
|
||||||
|
|
||||||
#endif /* __GPU_PY_VERTEX_FORMAT_H__ */
|
#endif /* __GPU_PY_VERTEX_FORMAT_H__ */
|
||||||
|
|||||||
Reference in New Issue
Block a user