From 0a435d49bae553d49afb9d4f16f2eacc763d86ca Mon Sep 17 00:00:00 2001 From: Germano Date: Tue, 17 Oct 2017 12:06:52 -0200 Subject: 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. --- source/blender/python/generic/bgl.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'source/blender/python') 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); } -- cgit v1.2.3