[Bf-blender-cvs] [9d3813e] blender2.8: Gawain: convenience functions for uniform color

Mike Erwin noreply at git.blender.org
Sat Aug 27 20:14:23 CEST 2016


Commit: 9d3813e602b83c3aa61068e9c592eee4786636af
Author: Mike Erwin
Date:   Sat Aug 27 14:10:37 2016 -0400
Branches: blender2.8
https://developer.blender.org/rB9d3813e602b83c3aa61068e9c592eee4786636af

Gawain: convenience functions for uniform color

Application code can pass ubytes, Gawain converts to float vec4 expected by shader.

For now the conversion is simple linear. We can add sRGB support later if needed.

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

M	source/blender/gpu/GPU_immediate.h
M	source/blender/gpu/intern/gpu_immediate.c

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

diff --git a/source/blender/gpu/GPU_immediate.h b/source/blender/gpu/GPU_immediate.h
index 08362c3..6bcfdc7 100644
--- a/source/blender/gpu/GPU_immediate.h
+++ b/source/blender/gpu/GPU_immediate.h
@@ -91,3 +91,8 @@ void immVertex3fv(unsigned attrib_id, const float data[3]);
 
 // provide values that don't change for the entire draw call
 void immUniform4f(const char* name, float x, float y, float z, float w);
+
+// these set "uniform vec4 color"
+// TODO: treat as sRGB?
+void immUniformColor3ubv(const unsigned char data[3]);
+void immUniformColor4ubv(const unsigned char data[4]);
diff --git a/source/blender/gpu/intern/gpu_immediate.c b/source/blender/gpu/intern/gpu_immediate.c
index d250bcc..7d32ba3 100644
--- a/source/blender/gpu/intern/gpu_immediate.c
+++ b/source/blender/gpu/intern/gpu_immediate.c
@@ -729,3 +729,15 @@ void immUniform4f(const char* name, float x, float y, float z, float w)
 
 	glUniform4f(loc, x, y, z, w);
 	}
+
+void immUniformColor3ubv(const unsigned char rgb[3])
+	{
+	const float scale = 1.0f / 255.0f;
+	immUniform4f("color", scale * rgb[0], scale * rgb[1], scale * rgb[2], 1.0f);
+	}
+
+void immUniformColor4ubv(const unsigned char rgba[4])
+	{
+	const float scale = 1.0f / 255.0f;
+	immUniform4f("color", scale * rgba[0], scale * rgba[1], scale * rgba[2], rgba[3]);
+	}




More information about the Bf-blender-cvs mailing list