[Bf-blender-cvs] [a55c5db] blender2.8: Gawain: flesh out immediate mode
Mike Erwin
noreply at git.blender.org
Sun Aug 7 07:07:18 CEST 2016
Commit: a55c5dbcc4b2ad7bd64386819681bcf1ac722a5b
Author: Mike Erwin
Date: Sat Aug 6 17:32:19 2016 -0400
Branches: blender2.8
https://developer.blender.org/rBa55c5dbcc4b2ad7bd64386819681bcf1ac722a5b
Gawain: flesh out immediate mode
More ways to send values via immAttrib:
2D float vectors
3 & 4 component ubytes (for colors mostly)
New immVertex functions that act more like familiar glVertex. We’ll
find a balance between making this API convenient and keeping it small.
2f and 3f are enough for now.
===================================================================
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 aeed133..c48abbb6 100644
--- a/source/blender/gpu/GPU_immediate.h
+++ b/source/blender/gpu/GPU_immediate.h
@@ -62,6 +62,14 @@ void immBegin(GLenum primitive, unsigned vertex_ct);
void immEnd(void);
void immAttrib1f(unsigned attrib_id, float x);
+void immAttrib2f(unsigned attrib_id, float x, float y);
void immAttrib3f(unsigned attrib_id, float x, float y, float z);
+void immAttrib3ub(unsigned attrib_id, unsigned char r, unsigned char g, unsigned char b);
+void immAttrib4ub(unsigned attrib_id, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
+
void immEndVertex(void); // and move on to the next vertex
+
+// provide 2D or 3D attribute value and end the current vertex, similar to glVertex:
+void immVertex2f(unsigned attrib_id, float x, float y);
+void immVertex3f(unsigned attrib_id, float x, float y, float z);
diff --git a/source/blender/gpu/intern/gpu_immediate.c b/source/blender/gpu/intern/gpu_immediate.c
index e9d19ae..2e47630 100644
--- a/source/blender/gpu/intern/gpu_immediate.c
+++ b/source/blender/gpu/intern/gpu_immediate.c
@@ -377,6 +377,27 @@ void immAttrib1f(unsigned attrib_id, float x)
data[0] = x;
}
+void immAttrib2f(unsigned attrib_id, float x, float y)
+ {
+ Attrib* attrib = immVertexFormat.attribs + attrib_id;
+
+#if TRUST_NO_ONE
+ assert(attrib_id < immVertexFormat.attrib_ct);
+ assert(attrib->comp_type == GL_FLOAT);
+ assert(attrib->comp_ct == 2);
+ assert(imm.vertex_idx < imm.vertex_ct);
+ assert(imm.primitive != GL_NONE); // make sure we're between a Begin/End pair
+#endif
+
+ setAttribValueBit(attrib_id);
+
+ float* data = imm.vertex_data + attrib->offset;
+// printf("%s %ld %p\n", __FUNCTION__, (void*)data - imm.buffer_data, data);
+
+ data[0] = x;
+ data[1] = y;
+ }
+
void immAttrib3f(unsigned attrib_id, float x, float y, float z)
{
Attrib* attrib = immVertexFormat.attribs + attrib_id;
@@ -399,6 +420,51 @@ void immAttrib3f(unsigned attrib_id, float x, float y, float z)
data[2] = z;
}
+void immAttrib3ub(unsigned attrib_id, unsigned char r, unsigned char g, unsigned char b)
+ {
+ Attrib* attrib = immVertexFormat.attribs + attrib_id;
+
+#if TRUST_NO_ONE
+ assert(attrib_id < immVertexFormat.attrib_ct);
+ assert(attrib->comp_type == GL_UNSIGNED_BYTE);
+ assert(attrib->comp_ct == 3);
+ assert(imm.vertex_idx < imm.vertex_ct);
+ assert(imm.primitive != GL_NONE); // make sure we're between a Begin/End pair
+#endif
+
+ setAttribValueBit(attrib_id);
+
+ unsigned char* data = imm.vertex_data + attrib->offset;
+// printf("%s %ld %p\n", __FUNCTION__, (void*)data - imm.buffer_data, data);
+
+ data[0] = r;
+ data[1] = g;
+ data[2] = b;
+ }
+
+void immAttrib4ub(unsigned attrib_id, unsigned char r, unsigned char g, unsigned char b, unsigned char a)
+ {
+ Attrib* attrib = immVertexFormat.attribs + attrib_id;
+
+#if TRUST_NO_ONE
+ assert(attrib_id < immVertexFormat.attrib_ct);
+ assert(attrib->comp_type == GL_UNSIGNED_BYTE);
+ assert(attrib->comp_ct == 4);
+ assert(imm.vertex_idx < imm.vertex_ct);
+ assert(imm.primitive != GL_NONE); // make sure we're between a Begin/End pair
+#endif
+
+ setAttribValueBit(attrib_id);
+
+ unsigned char* data = imm.vertex_data + attrib->offset;
+// printf("%s %ld %p\n", __FUNCTION__, (void*)data - imm.buffer_data, data);
+
+ data[0] = r;
+ data[1] = g;
+ data[2] = b;
+ data[3] = a;
+ }
+
void immEndVertex()
{
#if TRUST_NO_ONE
@@ -415,3 +481,15 @@ void immEndVertex()
imm.vertex_data += immVertexFormat.stride;
imm.attrib_value_bits = 0;
}
+
+void immVertex2f(unsigned attrib_id, float x, float y)
+ {
+ immAttrib2f(attrib_id, x, y);
+ immEndVertex();
+ }
+
+void immVertex3f(unsigned attrib_id, float x, float y, float z)
+ {
+ immAttrib3f(attrib_id, x, y, z);
+ immEndVertex();
+ }
More information about the Bf-blender-cvs
mailing list