[Bf-blender-cvs] [c750ebe113e] blender2.8: PyAPI: remove GPUVertFormat() creation from a list

Campbell Barton noreply at git.blender.org
Mon Oct 29 01:11:22 CET 2018


Commit: c750ebe113e70c6b7e9efad2219e12546519d44b
Author: Campbell Barton
Date:   Mon Oct 29 11:08:55 2018 +1100
Branches: blender2.8
https://developer.blender.org/rBc750ebe113e70c6b7e9efad2219e12546519d44b

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

===================================================================

M	source/blender/python/gpu/gpu_py_vertex_buffer.c
M	source/blender/python/gpu/gpu_py_vertex_format.c
M	source/blender/python/gpu/gpu_py_vertex_format.h

===================================================================

diff --git a/source/blender/python/gpu/gpu_py_vertex_buffer.c b/source/blender/python/gpu/gpu_py_vertex_buffer.c
index 440cefe553e..1f888597b34 100644
--- a/source/blender/python/gpu/gpu_py_vertex_buffer.c
+++ b/source/blender/python/gpu/gpu_py_vertex_buffer.c
@@ -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,
-	        &params.py_fmt,
+	        &BPyGPUVertFormat_Type, &params.py_fmt,
 	        &params.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);
 
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;
-}
-
 /** \} */
diff --git a/source/blender/python/gpu/gpu_py_vertex_format.h b/source/blender/python/gpu/gpu_py_vertex_format.h
index f1f1961b0ad..5b0bf1addc2 100644
--- a/source/blender/python/gpu/gpu_py_vertex_format.h
+++ b/source/blender/python/gpu/gpu_py_vertex_format.h
@@ -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__ */



More information about the Bf-blender-cvs mailing list