[Bf-blender-cvs] [425cfdd5be1] blender2.8: GPU Python API: shader.uniform_float

Dalai Felinto noreply at git.blender.org
Thu Sep 20 21:56:20 CEST 2018


Commit: 425cfdd5be12a0c167bd55eeb1ac84d37b7f2ead
Author: Dalai Felinto
Date:   Thu Sep 20 19:51:02 2018 +0000
Branches: blender2.8
https://developer.blender.org/rB425cfdd5be12a0c167bd55eeb1ac84d37b7f2ead

GPU Python API: shader.uniform_float

The existing alternative is to use a buffer and call
uniform_vector_float which is overkill for such a simple operation.

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

M	source/blender/gpu/GPU_shader.h
M	source/blender/gpu/intern/gpu_shader.c
M	source/blender/python/gpu/gpu_py_shader.c

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

diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h
index f4fc568c6ff..21d5b5871fa 100644
--- a/source/blender/gpu/GPU_shader.h
+++ b/source/blender/gpu/GPU_shader.h
@@ -93,6 +93,7 @@ void GPU_shader_uniform_vector_int(
 
 void GPU_shader_uniform_buffer(GPUShader *shader, int location, struct GPUUniformBuffer *ubo);
 void GPU_shader_uniform_texture(GPUShader *shader, int location, struct GPUTexture *tex);
+void GPU_shader_uniform_float(GPUShader *shader, int location, float value);
 void GPU_shader_uniform_int(GPUShader *shader, int location, int value);
 void GPU_shader_geometry_stage_primitive_io(GPUShader *shader, int input, int output, int number);
 
diff --git a/source/blender/gpu/intern/gpu_shader.c b/source/blender/gpu/intern/gpu_shader.c
index 97be9c79811..0f9e0b2008e 100644
--- a/source/blender/gpu/intern/gpu_shader.c
+++ b/source/blender/gpu/intern/gpu_shader.c
@@ -582,6 +582,14 @@ int GPU_shader_get_program(GPUShader *shader)
 	return (int)shader->program;
 }
 
+void GPU_shader_uniform_float(GPUShader *UNUSED(shader), int location, float value)
+{
+	if (location == -1)
+		return;
+
+	glUniform1f(location, value);
+}
+
 void GPU_shader_uniform_vector(GPUShader *UNUSED(shader), int location, int length, int arraysize, const float *value)
 {
 	if (location == -1 || value == NULL)
diff --git a/source/blender/python/gpu/gpu_py_shader.c b/source/blender/python/gpu/gpu_py_shader.c
index 76fe38c57e9..3a9122297cd 100644
--- a/source/blender/python/gpu/gpu_py_shader.c
+++ b/source/blender/python/gpu/gpu_py_shader.c
@@ -323,6 +323,34 @@ static PyObject *bpygpu_shader_uniform_vector_int(
 	Py_RETURN_NONE;
 }
 
+PyDoc_STRVAR(bpygpu_shader_uniform_float_doc,
+	".. method:: uniform_float(location, value)\n"
+	"\n"
+	"   Set uniform value.\n"
+	"\n"
+	"   :param location: builtin identifier.\n"
+	"   :type location: `int`\n"
+	"   :param value: uniform value.\n"
+	"   :type value: `float`\n"
+);
+static PyObject *bpygpu_shader_uniform_float(
+	BPyGPUShader *self, PyObject *args)
+{
+	int location;
+	float value;
+
+	if (!PyArg_ParseTuple(
+		args, "if:GPUShader.uniform_float",
+		&location, &value))
+	{
+		return NULL;
+	}
+
+	GPU_shader_uniform_float(self->shader, location, value);
+
+	Py_RETURN_NONE;
+}
+
 PyDoc_STRVAR(bpygpu_shader_uniform_int_doc,
 ".. method:: uniform_int(location, value)\n"
 "\n"
@@ -408,6 +436,9 @@ static struct PyMethodDef bpygpu_shader_methods[] = {
 	{"uniform_vector_int",
 	 (PyCFunction)bpygpu_shader_uniform_vector_int,
 	 METH_VARARGS, bpygpu_shader_uniform_vector_int_doc},
+	{"uniform_float",
+	 (PyCFunction)bpygpu_shader_uniform_float,
+	 METH_VARARGS, bpygpu_shader_uniform_float_doc},
 	{"uniform_int",
 	 (PyCFunction)bpygpu_shader_uniform_int,
 	 METH_VARARGS, bpygpu_shader_uniform_int_doc},



More information about the Bf-blender-cvs mailing list