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:
parent
02035c34b7
commit
c750ebe113
Notes:
blender-bot
2023-02-14 05:08:18 +01:00
Referenced by issue #57500, Denoiser Artefacts Referenced by issue #57504, Blender 2.80 crash while dragging cursor and start scaling Referenced by issue #57511, When sculpt with Dyntopo and tiling is enabled, blender crash Referenced by issue #57492, Enable tiling with dynotopo sculpting mode make blender crash.
|
@ -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)
|
||||
{
|
||||
const char *error_prefix = "GPUVertBuf.__new__";
|
||||
|
||||
struct {
|
||||
PyObject *py_fmt;
|
||||
uint len;
|
||||
} params;
|
||||
|
||||
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(
|
||||
args, kwds, &_parser,
|
||||
¶ms.py_fmt,
|
||||
&BPyGPUVertFormat_Type, ¶ms.py_fmt,
|
||||
¶ms.len))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GPUVertFormat *fmt, fmt_stack;
|
||||
|
||||
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);
|
||||
const GPUVertFormat *fmt = &((BPyGPUVertFormat *)params.py_fmt)->fmt;
|
||||
GPUVertBuf *vbo = GPU_vertbuf_create_with_format(fmt);
|
||||
|
||||
GPU_vertbuf_data_alloc(vbo, params.len);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
|
|
@ -37,7 +37,5 @@ typedef struct BPyGPUVertFormat {
|
|||
} BPyGPUVertFormat;
|
||||
|
||||
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__ */
|
||||
|
|
Loading…
Reference in New Issue