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.
This commit is contained in:
Germano Cavalcante 2017-10-17 12:06:52 -02:00
parent 06ff970f27
commit 0a435d49ba
Notes: blender-bot 2023-02-14 19:34:21 +01:00
Referenced by issue blender/blender-addons#53074, mesh_snap_utilities_line does not start
1 changed files with 11 additions and 16 deletions

View File

@ -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);
}