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
This commit is contained in:
@@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
#include "../generic/py_capi_utils.h"
|
#include "../generic/py_capi_utils.h"
|
||||||
#include "../generic/python_utildefines.h"
|
#include "../generic/python_utildefines.h"
|
||||||
|
#include "../mathutils/mathutils.h"
|
||||||
|
|
||||||
#include "gpu_py_shader.h" /* own include */
|
#include "gpu_py_shader.h" /* own include */
|
||||||
#include "gpu_py_vertex_format.h"
|
#include "gpu_py_vertex_format.h"
|
||||||
@@ -412,14 +413,14 @@ static PyObject *bpygpu_shader_uniform_bool(
|
|||||||
}
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(bpygpu_shader_uniform_float_doc,
|
PyDoc_STRVAR(bpygpu_shader_uniform_float_doc,
|
||||||
".. method:: uniform_float(name, seq)\n"
|
".. method:: uniform_float(name, value)\n"
|
||||||
"\n"
|
"\n"
|
||||||
" Specify the value of a uniform variable for the current program object.\n"
|
" Specify the value of a uniform variable for the current program object.\n"
|
||||||
"\n"
|
"\n"
|
||||||
" :param name: name of the uniform variable whose location is to be queried.\n"
|
" :param name: name of the uniform variable whose location is to be queried.\n"
|
||||||
" :type name: str\n"
|
" :type name: str\n"
|
||||||
" :param seq: values that will be used to update the specified uniform variable.\n"
|
" :param value: values that will be used to update the specified uniform variable.\n"
|
||||||
" :type seq: sequence of numbers\n"
|
" :type value: single number or sequence of numbers\n"
|
||||||
);
|
);
|
||||||
static PyObject *bpygpu_shader_uniform_float(
|
static PyObject *bpygpu_shader_uniform_float(
|
||||||
BPyGPUShader *self, PyObject *args)
|
BPyGPUShader *self, PyObject *args)
|
||||||
@@ -440,35 +441,22 @@ static PyObject *bpygpu_shader_uniform_float(
|
|||||||
|
|
||||||
float values[16];
|
float values[16];
|
||||||
int length;
|
int length;
|
||||||
int ret;
|
|
||||||
{
|
if (PyFloat_Check(params.seq)) {
|
||||||
PyObject *seq_fast = PySequence_Fast(params.seq, error_prefix);
|
values[0] = (float)PyFloat_AsDouble(params.seq);
|
||||||
if (seq_fast == NULL) {
|
length = 1;
|
||||||
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 (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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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) ||
|
if ((size = VectorObject_Check(value) ? ((VectorObject *)value)->size : 0) ||
|
||||||
(size = EulerObject_Check(value) ? 3 : 0) ||
|
(size = EulerObject_Check(value) ? 3 : 0) ||
|
||||||
(size = QuaternionObject_Check(value) ? 4 : 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) {
|
if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
Reference in New Issue
Block a user