diff options
author | Germano <germano.costa@ig.com.br> | 2017-10-17 17:06:52 +0300 |
---|---|---|
committer | Germano <germano.costa@ig.com.br> | 2017-10-17 17:06:52 +0300 |
commit | 0a435d49bae553d49afb9d4f16f2eacc763d86ca (patch) | |
tree | 04b2fa95fa69d4f9830c99388255e9b5a98e5c3b | |
parent | 06ff970f27dc1d482792c8f976e2173c9f90befa (diff) |
Fix T53074: Use the pybuffer->itemsize to get the corresponding GLtype
It seems that `typestr` does not always define the final size of the element. And it varies by operating system.
Then use the `typestr` only to know the itemtype is `float` type or not.
-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 a0185b0f4fa..072021c6ac9 100644 --- a/source/blender/python/generic/bgl.c +++ b/source/blender/python/generic/bgl.c @@ -472,34 +472,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 */ @@ -797,7 +792,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); } |