diff options
author | Mike Erwin <significant.bit@gmail.com> | 2016-08-20 22:09:32 +0300 |
---|---|---|
committer | Mike Erwin <significant.bit@gmail.com> | 2016-08-20 22:09:32 +0300 |
commit | eb717ee9794a0e3c217f7e6f32904a115fc6e9e1 (patch) | |
tree | 83ac32c64bdafd3fb8e722e52989742b4366fdb9 | |
parent | 1e6b3ef1a1e257741fb4c982a1cb4854d49a1713 (diff) |
Gawain: more immediate mode functions
Scanned Blender code for commonly used glVertex, glColor functions.
Implemented immVertex, immAttrib versions of these to ease transition
away from legacy OpenGL.
-rw-r--r-- | source/blender/gpu/GPU_immediate.h | 8 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_immediate.c | 44 |
2 files changed, 52 insertions, 0 deletions
diff --git a/source/blender/gpu/GPU_immediate.h b/source/blender/gpu/GPU_immediate.h index 7c2b35c29f1..08362c35845 100644 --- a/source/blender/gpu/GPU_immediate.h +++ b/source/blender/gpu/GPU_immediate.h @@ -69,9 +69,15 @@ 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 immAttrib4f(unsigned attrib_id, float x, float y, float z, float w); + +void immAttrib3fv(unsigned attrib_id, const float data[3]); +void immAttrib4fv(unsigned attrib_id, const float data[4]); 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 immAttrib3ubv(unsigned attrib_id, const unsigned char data[4]); void immAttrib4ubv(unsigned attrib_id, const unsigned char data[4]); void immEndVertex(void); // and move on to the next vertex @@ -79,6 +85,8 @@ 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); + +void immVertex2fv(unsigned attrib_id, const float data[2]); void immVertex3fv(unsigned attrib_id, const float data[3]); // provide values that don't change for the entire draw call diff --git a/source/blender/gpu/intern/gpu_immediate.c b/source/blender/gpu/intern/gpu_immediate.c index 3065a3eb63f..d250bcc78f9 100644 --- a/source/blender/gpu/intern/gpu_immediate.c +++ b/source/blender/gpu/intern/gpu_immediate.c @@ -571,6 +571,39 @@ void immAttrib3f(unsigned attrib_id, float x, float y, float z) data[2] = z; } +void immAttrib4f(unsigned attrib_id, float x, float y, float z, float w) + { + Attrib* attrib = imm.vertex_format.attribs + attrib_id; + +#if TRUST_NO_ONE + assert(attrib_id < imm.vertex_format.attrib_ct); + assert(attrib->comp_type == GL_FLOAT); + 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); + + float* data = (float*)(imm.vertex_data + attrib->offset); +// printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm.buffer_data, data); + + data[0] = x; + data[1] = y; + data[2] = z; + data[3] = w; + } + +void immAttrib3fv(unsigned attrib_id, const float data[3]) + { + immAttrib3f(attrib_id, data[0], data[1], data[2]); + } + +void immAttrib4fv(unsigned attrib_id, const float data[4]) + { + immAttrib4f(attrib_id, data[0], data[1], data[2], data[3]); + } + void immAttrib3ub(unsigned attrib_id, unsigned char r, unsigned char g, unsigned char b) { Attrib* attrib = imm.vertex_format.attribs + attrib_id; @@ -616,6 +649,11 @@ void immAttrib4ub(unsigned attrib_id, unsigned char r, unsigned char g, unsigned data[3] = a; } +void immAttrib3ubv(unsigned attrib_id, const unsigned char data[3]) + { + immAttrib3ub(attrib_id, data[0], data[1], data[2]); + } + void immAttrib4ubv(unsigned attrib_id, const unsigned char data[4]) { immAttrib4ub(attrib_id, data[0], data[1], data[2], data[3]); @@ -669,6 +707,12 @@ void immVertex3f(unsigned attrib_id, float x, float y, float z) immEndVertex(); } +void immVertex2fv(unsigned attrib_id, const float data[2]) + { + immAttrib2f(attrib_id, data[0], data[1]); + immEndVertex(); + } + void immVertex3fv(unsigned attrib_id, const float data[3]) { immAttrib3f(attrib_id, data[0], data[1], data[2]); |