GPUShader: shader.uniform_float, matrix parsing

Add checks to parse 3x3 or 4x4 matrices,
also use error from `mathutils_array_parse` instead of overwriting.
This commit is contained in:
2018-10-24 18:45:47 +11:00
parent c8ab88fb89
commit 0589368615

View File

@@ -450,8 +450,24 @@ static PyObject *bpygpu_shader_uniform_float(
values[0] = (float)PyLong_AsDouble(params.seq);
length = 1;
}
else if (MatrixObject_Check(params.seq)) {
MatrixObject *mat = (MatrixObject *)params.seq;
if (BaseMath_ReadCallback(mat) == -1) {
return NULL;
}
if ((mat->num_row != mat->num_col) || !ELEM(mat->num_row, 3, 4)) {
PyErr_SetString(PyExc_ValueError,
"Expected 3x3 or 4x4 matrix");
return NULL;
}
length = mat->num_row * mat->num_col;
memcpy(values, mat->matrix, sizeof(float) * length);
}
else {
length = mathutils_array_parse(values, 2, 16, params.seq, "");
if (length == -1) {
return NULL;
}
}
if (!ELEM(length, 1, 2, 3, 4, 9, 16)) {