[Bf-blender-cvs] [fc3d771801a] blender2.8: GPUShader: shader.uniform_float parameters
Jacques Lucke
noreply at git.blender.org
Tue Oct 23 10:20:13 CEST 2018
Commit: fc3d771801ab3a864ae73cf881037063abcf89ce
Author: Jacques Lucke
Date: Tue Oct 23 10:17:38 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBfc3d771801ab3a864ae73cf881037063abcf89ce
GPUShader: shader.uniform_float parameters
Allow to pass in single numbers, sequences and mathutils.* types into `shader.uniform_float`.
Reviewers: mano-wii
Differential Revision: https://developer.blender.org/D3820
===================================================================
M source/blender/python/gpu/gpu_py_shader.c
M source/blender/python/mathutils/mathutils.c
===================================================================
diff --git a/source/blender/python/gpu/gpu_py_shader.c b/source/blender/python/gpu/gpu_py_shader.c
index 061c844a54d..83ed8ce7362 100644
--- a/source/blender/python/gpu/gpu_py_shader.c
+++ b/source/blender/python/gpu/gpu_py_shader.c
@@ -34,6 +34,7 @@
#include "../generic/py_capi_utils.h"
#include "../generic/python_utildefines.h"
+#include "../mathutils/mathutils.h"
#include "gpu_py_shader.h" /* own include */
#include "gpu_py_vertex_format.h"
@@ -412,14 +413,14 @@ static PyObject *bpygpu_shader_uniform_bool(
}
PyDoc_STRVAR(bpygpu_shader_uniform_float_doc,
-".. method:: uniform_float(name, seq)\n"
+".. method:: uniform_float(name, value)\n"
"\n"
" Specify the value of a uniform variable for the current program object.\n"
"\n"
" :param name: name of the uniform variable whose location is to be queried.\n"
" :type name: str\n"
-" :param seq: values that will be used to update the specified uniform variable.\n"
-" :type seq: sequence of numbers\n"
+" :param value: values that will be used to update the specified uniform variable.\n"
+" :type value: single number or sequence of numbers\n"
);
static PyObject *bpygpu_shader_uniform_float(
BPyGPUShader *self, PyObject *args)
@@ -440,35 +441,22 @@ static PyObject *bpygpu_shader_uniform_float(
float values[16];
int length;
- int ret;
- {
- PyObject *seq_fast = PySequence_Fast(params.seq, error_prefix);
- if (seq_fast == NULL) {
- PyErr_Format(PyExc_TypeError,
- "%s: expected a sequence, got %s",
- error_prefix, Py_TYPE(params.seq)->tp_name);
- ret = -1;
- }
- else {
- length = PySequence_Fast_GET_SIZE(seq_fast);
- if ((length == 0) || (length > 16) ||
- (4 < length && length < 9) ||
- (9 < length && length < 16))
- {
- PyErr_Format(PyExc_TypeError,
- "%s: invalid sequence length. expected 1..4, 9 or 16, got %d",
- error_prefix, length);
- ret = -1;
- }
- else {
- ret = PyC_AsArray_FAST(
- values, seq_fast, length, &PyFloat_Type,
- false, error_prefix);
- }
- Py_DECREF(seq_fast);
- }
+
+ if (PyFloat_Check(params.seq)) {
+ values[0] = (float)PyFloat_AsDouble(params.seq);
+ length = 1;
}
- if (ret == -1) {
+ else if (PyLong_Check(params.seq)) {
+ values[0] = (float)PyLong_AsDouble(params.seq);
+ length = 1;
+ }
+ else {
+ length = mathutils_array_parse(values, 2, 16, params.seq, "");
+ }
+
+ if (!ELEM(length, 1, 2, 3, 4, 9, 16)) {
+ PyErr_SetString(PyExc_TypeError,
+ "Expected a single float or a sequence of floats of length 1..4, 9 or 16.");
return NULL;
}
diff --git a/source/blender/python/mathutils/mathutils.c b/source/blender/python/mathutils/mathutils.c
index 07905d2be89..a3e8089c936 100644
--- a/source/blender/python/mathutils/mathutils.c
+++ b/source/blender/python/mathutils/mathutils.c
@@ -136,7 +136,9 @@ int mathutils_array_parse(float *array, int array_min, int array_max, PyObject *
if ((size = VectorObject_Check(value) ? ((VectorObject *)value)->size : 0) ||
(size = EulerObject_Check(value) ? 3 : 0) ||
(size = QuaternionObject_Check(value) ? 4 : 0) ||
- (size = ColorObject_Check(value) ? 3 : 0))
+ (size = ColorObject_Check(value) ? 3 : 0) ||
+ (size = MatrixObject_Check(value) ? ((MatrixObject *)value)->num_col
+ * ((MatrixObject *)value)->num_row : 0))
{
if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
return -1;
More information about the Bf-blender-cvs
mailing list