diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-10-18 08:40:31 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-10-18 08:40:31 +0300 |
commit | 54f9a6e5da06e671f7640c9ec3ac3c305644beb6 (patch) | |
tree | 6d9968f97e56bdb0758cfea123a1ca00c2bd799a /source/blender/python | |
parent | 0bcb61b2fe94d389332f91762cf07c2691c9fb93 (diff) | |
parent | 92611dada67fcc151c894462749031be1de27191 (diff) |
Merge branch 'master' into blender2.8
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/generic/bgl.c | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/source/blender/python/generic/bgl.c b/source/blender/python/generic/bgl.c index 5c938ef2ee3..9672b824843 100644 --- a/source/blender/python/generic/bgl.c +++ b/source/blender/python/generic/bgl.c @@ -476,34 +476,29 @@ int BGL_typeSize(int type) return -1; } -static int gl_buffer_type_from_py_format_char(char *typestr) +static int gl_buffer_type_from_py_buffer(Py_buffer *pybuffer) { + char *typestr = pybuffer->format; + Py_ssize_t itemsize = pybuffer->itemsize; + if (ELEM(typestr[0], '<', '>', '|')) { typestr += 1; } - char format = typestr[0]; - char byte_num = typestr[1]; - switch (format) { + switch (typestr[0]) { case 't': case 'b': case 'h': - if (!byte_num) return GL_BYTE; - ATTR_FALLTHROUGH; case 'i': - if (!byte_num) return GL_SHORT; - ATTR_FALLTHROUGH; case 'l': - if (!byte_num || byte_num == '4') return GL_INT; - if (byte_num == '1') return GL_BYTE; - if (byte_num == '2') return GL_SHORT; + if (itemsize == 1) return GL_BYTE; + if (itemsize == 2) return GL_SHORT; + if (itemsize == 4) return GL_INT; break; case 'f': - if (!byte_num) return GL_FLOAT; - ATTR_FALLTHROUGH; case 'd': - if (!byte_num || byte_num == '8') return GL_DOUBLE; - if (byte_num == '4') return GL_FLOAT; + if (itemsize == 4) return GL_FLOAT; + if (itemsize == 8) return GL_DOUBLE; break; } return -1; /* UNKNOWN */ @@ -801,7 +796,7 @@ static PyObject *Buffer_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject return NULL; } - if (type != gl_buffer_type_from_py_format_char(pybuffer.format)) { + if (type != gl_buffer_type_from_py_buffer(&pybuffer)) { PyErr_Format(PyExc_TypeError, "`GL_TYPE` and `typestr` of object with buffer interface do not match. '%s'", pybuffer.format); } |