Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <mail@jlucke.com>2018-10-23 11:17:38 +0300
committerJacques Lucke <mail@jlucke.com>2018-10-23 11:19:08 +0300
commitfc3d771801ab3a864ae73cf881037063abcf89ce (patch)
tree076bc07f068a378e0e6cfd857e76160eb9ac1570 /source/blender/python/gpu
parent13cfb641c6d91f4418d00cfbba616448a15aab22 (diff)
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
Diffstat (limited to 'source/blender/python/gpu')
-rw-r--r--source/blender/python/gpu/gpu_py_shader.c50
1 files changed, 19 insertions, 31 deletions
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;
}