diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-10-29 03:08:55 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-10-29 03:08:55 +0300 |
commit | c750ebe113e70c6b7e9efad2219e12546519d44b (patch) | |
tree | 3204e8a0d519759c204e4941a2dfc8464ba856c5 /source/blender/python/gpu/gpu_py_vertex_format.c | |
parent | 02035c34b735990f3685950621eff24c25d0e91c (diff) |
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
Diffstat (limited to 'source/blender/python/gpu/gpu_py_vertex_format.c')
-rw-r--r-- | source/blender/python/gpu/gpu_py_vertex_format.c | 86 |
1 files changed, 3 insertions, 83 deletions
diff --git a/source/blender/python/gpu/gpu_py_vertex_format.c b/source/blender/python/gpu/gpu_py_vertex_format.c index 81a1cd2f19a..0f863d04227 100644 --- a/source/blender/python/gpu/gpu_py_vertex_format.c +++ b/source/blender/python/gpu/gpu_py_vertex_format.c @@ -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; -} - /** \} */ |