diff options
author | Germano Cavalcante <germano.costa@ig.com.br> | 2022-09-22 03:53:51 +0300 |
---|---|---|
committer | Germano Cavalcante <germano.costa@ig.com.br> | 2022-09-22 04:30:57 +0300 |
commit | 62ffbc7d7ffabc823d9f43618c9877ec357ec485 (patch) | |
tree | b7225a4ae3d8404f996d302ad1594b63c3995856 /source/blender/python/gpu/gpu_py_shader.c | |
parent | 20dc8393192fcf5e5183816134436c1e871b852d (diff) |
PyGPU: Allow single bool in 'GPUShader.uniform_bool' method
As with the other uniform methods, a single value is expected.
Diffstat (limited to 'source/blender/python/gpu/gpu_py_shader.c')
-rw-r--r-- | source/blender/python/gpu/gpu_py_shader.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/source/blender/python/gpu/gpu_py_shader.c b/source/blender/python/gpu/gpu_py_shader.c index 43b50dbbef0..a57b00e671e 100644 --- a/source/blender/python/gpu/gpu_py_shader.c +++ b/source/blender/python/gpu/gpu_py_shader.c @@ -302,14 +302,14 @@ static PyObject *pygpu_shader_uniform_vector_int(BPyGPUShader *self, PyObject *a } PyDoc_STRVAR(pygpu_shader_uniform_bool_doc, - ".. method:: uniform_bool(name, seq)\n" + ".. method:: uniform_bool(name, value)\n" "\n" " Specify the value of a uniform variable for the current program object.\n" "\n" " :arg name: Name of the uniform variable whose value is to be changed.\n" " :type name: str\n" - " :arg seq: Value that will be used to update the specified uniform variable.\n" - " :type seq: sequence of bools\n"); + " :arg value: Value that will be used to update the specified uniform variable.\n" + " :type value: bool or sequence of bools\n"); static PyObject *pygpu_shader_uniform_bool(BPyGPUShader *self, PyObject *args) { const char *error_prefix = "GPUShader.uniform_bool"; @@ -325,15 +325,14 @@ static PyObject *pygpu_shader_uniform_bool(BPyGPUShader *self, PyObject *args) int values[4]; int length; - int ret; - { + int ret = -1; + if (PySequence_Check(params.seq)) { 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); @@ -342,7 +341,6 @@ static PyObject *pygpu_shader_uniform_bool(BPyGPUShader *self, PyObject *args) "%s: invalid sequence length. expected 1..4, got %d", error_prefix, length); - ret = -1; } else { ret = PyC_AsArray_FAST( @@ -351,6 +349,15 @@ static PyObject *pygpu_shader_uniform_bool(BPyGPUShader *self, PyObject *args) Py_DECREF(seq_fast); } } + else if (((values[0] = (int)PyLong_AsLong(params.seq)) != -1) && ELEM(values[0], 0, 1)) { + length = 1; + ret = 0; + } + else { + PyErr_Format( + PyExc_ValueError, "expected a bool or sequence, got %s", Py_TYPE(params.seq)->tp_name); + } + if (ret == -1) { return NULL; } |