[Bf-blender-cvs] [1d8ba9d6184] blender2.8: PyAPI: Make GPUVertFormat() argument optional

Campbell Barton noreply at git.blender.org
Thu Oct 25 23:07:10 CEST 2018


Commit: 1d8ba9d6184bf0e1e1e8fb7b8f41ec74b6ed39f8
Author: Campbell Barton
Date:   Fri Oct 26 08:06:05 2018 +1100
Branches: blender2.8
https://developer.blender.org/rB1d8ba9d6184bf0e1e1e8fb7b8f41ec74b6ed39f8

PyAPI: Make GPUVertFormat() argument optional

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

M	release/scripts/modules/gpu_extras/presets.py
M	source/blender/python/gpu/gpu_py_vertex_format.c

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

diff --git a/release/scripts/modules/gpu_extras/presets.py b/release/scripts/modules/gpu_extras/presets.py
index 444e3ea24d0..ad623c456e0 100644
--- a/release/scripts/modules/gpu_extras/presets.py
+++ b/release/scripts/modules/gpu_extras/presets.py
@@ -31,7 +31,7 @@ def draw_circle_2d(position, color, radius, segments):
         seg = 32
         mul = (1.0 / (seg - 1)) * (pi * 2)
         verts = [(sin(i * mul), cos(i * mul)) for i in range(seg)]
-        fmt = GPUVertFormat(format=[])
+        fmt = GPUVertFormat()
         pos_id = fmt.attr_add(id="pos", comp_type='F32', len=2, fetch_mode='FLOAT')
         vbo = GPUVertBuf(len=len(verts), format=fmt)
         vbo.attr_fill(id=pos_id, data=verts)
diff --git a/source/blender/python/gpu/gpu_py_vertex_format.c b/source/blender/python/gpu/gpu_py_vertex_format.c
index d42bb557cd9..81a1cd2f19a 100644
--- a/source/blender/python/gpu/gpu_py_vertex_format.c
+++ b/source/blender/python/gpu/gpu_py_vertex_format.c
@@ -196,10 +196,11 @@ static bool bpygpu_vertformat_attr_add_from_tuple(
 
 static PyObject *bpygpu_VertFormat_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds)
 {
-	PyListObject *format_list;
+	const char *error_prefix = "GPUVertFormat.__new__";
+	PyListObject *format_list = NULL;
 
 	static const char *_keywords[] = {"format", NULL};
-	static _PyArg_Parser _parser = {"O!:VertFormat.__new__", _keywords, 0};
+	static _PyArg_Parser _parser = {"|O!:GPUVertFormat.__new__", _keywords, 0};
 	if (!_PyArg_ParseTupleAndKeywordsFast(
 	        args, kwds, &_parser,
 	        &PyList_Type, &format_list))
@@ -209,7 +210,7 @@ static PyObject *bpygpu_VertFormat_new(PyTypeObject *UNUSED(type), PyObject *arg
 
 	BPyGPUVertFormat *ret = (BPyGPUVertFormat *)BPyGPUVertFormat_CreatePyObject(NULL);
 
-	if (!bpygpu_vertformat_from_PyList(format_list, "VertFormat.__new__", &ret->fmt)) {
+	if (format_list && !bpygpu_vertformat_from_PyList(format_list, error_prefix, &ret->fmt)) {
 		Py_DECREF(ret);
 		return NULL;
 	}



More information about the Bf-blender-cvs mailing list