[Bf-blender-cvs] [05893686159] blender2.8: GPUShader: shader.uniform_float, matrix parsing

Campbell Barton noreply at git.blender.org
Wed Oct 24 09:48:42 CEST 2018


Commit: 058936861591d16703f67e5c4b1dd8cb593630ed
Author: Campbell Barton
Date:   Wed Oct 24 18:45:47 2018 +1100
Branches: blender2.8
https://developer.blender.org/rB058936861591d16703f67e5c4b1dd8cb593630ed

GPUShader: shader.uniform_float, matrix parsing

Add checks to parse 3x3 or 4x4 matrices,
also use error from `mathutils_array_parse` instead of overwriting.

===================================================================

M	source/blender/python/gpu/gpu_py_shader.c

===================================================================

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)) {



More information about the Bf-blender-cvs mailing list