From 058936861591d16703f67e5c4b1dd8cb593630ed Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 24 Oct 2018 18:45:47 +1100 Subject: GPUShader: shader.uniform_float, matrix parsing Add checks to parse 3x3 or 4x4 matrices, also use error from `mathutils_array_parse` instead of overwriting. --- source/blender/python/gpu/gpu_py_shader.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'source/blender/python/gpu') diff --git a/source/blender/python/gpu/gpu_py_shader.c b/source/blender/python/gpu/gpu_py_shader.c index 83ed8ce7362..f62e9b775b1 100644 --- a/source/blender/python/gpu/gpu_py_shader.c +++ b/source/blender/python/gpu/gpu_py_shader.c @@ -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)) { -- cgit v1.2.3