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.
This commit is contained in:
Mike Erwin 2016-08-06 17:32:19 -04:00
parent 3eae585791
commit a55c5dbcc4
2 changed files with 86 additions and 0 deletions

View File

@ -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);

View File

@ -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();
}