[Bf-blender-cvs] [62ffbc7d7ff] master: PyGPU: Allow single bool in 'GPUShader.uniform_bool' method

Germano Cavalcante noreply at git.blender.org
Thu Sep 22 03:31:29 CEST 2022


Commit: 62ffbc7d7ffabc823d9f43618c9877ec357ec485
Author: Germano Cavalcante
Date:   Wed Sep 21 21:53:51 2022 -0300
Branches: master
https://developer.blender.org/rB62ffbc7d7ffabc823d9f43618c9877ec357ec485

PyGPU: Allow single bool in 'GPUShader.uniform_bool' method

As with the other uniform methods, a single value is expected.

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

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 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;
   }



More information about the Bf-blender-cvs mailing list