diff options
author | Ian Romanick <idr@freedesktop.org> | 2010-10-03 10:15:28 -0700 |
---|---|---|
committer | Ian Romanick <idr@freedesktop.org> | 2010-10-03 10:19:37 -0700 |
commit | 1539a63122d9dc2b66681775ac6d9c7434679c89 (patch) | |
tree | 091398cd0f9ea2c94a205ee50d57ef7554125eb5 | |
parent | 7dd9d08b1e9eec07a050b12144ea74ad02aa6a6d (diff) |
GLUshape: Make consumer index interface batch oriented as well
-rw-r--r-- | include/glu3.h | 7 | ||||
-rw-r--r-- | src/cube.cpp | 7 | ||||
-rw-r--r-- | src/mesh.c | 34 | ||||
-rw-r--r-- | src/mesh.h | 2 | ||||
-rw-r--r-- | src/sphere.cpp | 6 |
5 files changed, 37 insertions, 19 deletions
diff --git a/include/glu3.h b/include/glu3.h index 70b2eb7..e97e477 100644 --- a/include/glu3.h +++ b/include/glu3.h @@ -327,9 +327,12 @@ public: virtual void begin_primitive(GLenum mode, unsigned count) = 0; /** - * Emit an element index for drawing + * Emit a batch of element indices for drawing + * + * \param idx Vertex indices. + * \param count Number of indices being emitted. */ - virtual void index(unsigned idx) = 0; + virtual void index_batch(const unsigned *idx, unsigned count) = 0; /** * End an index primitive previously started with begin_primitive diff --git a/src/cube.cpp b/src/cube.cpp index 6b8d601..55f924d 100644 --- a/src/cube.cpp +++ b/src/cube.cpp @@ -80,7 +80,7 @@ GLUcubeProducer::generate(GLUshapeConsumer *consumer) const #define V(x, y, z, n) (((((z) * 4) + (y * 2) + x) * 3) + (n)) - static const unsigned char elts[] = { + static const unsigned elts[] = { /* +X face */ V(P, P, P, X), V(P, N, N, X), V(P, P, N, X), V(P, P, P, X), V(P, N, P, X), V(P, N, N, X), @@ -184,9 +184,6 @@ GLUcubeProducer::generate(GLUshapeConsumer *consumer) const } consumer->begin_primitive(GL_TRIANGLES, Elements(elts)); - - for (unsigned i = 0; i < Elements(elts); i++) - consumer->index(elts[i]); - + consumer->index_batch(elts, Elements(elts)); consumer->end_primitive(); } @@ -23,6 +23,18 @@ #include "mesh.h" +#define Elements(a) (sizeof(a) / sizeof(a[0])) + +#define EMIT_ELT(e) \ + do { \ + elts[count] = (e); \ + count++; \ + if (count >= Elements(elts)) { \ + (*index_cb)(data, elts, count); \ + count = 0; \ + } \ + } while (0) + void generate_triangle_mesh(unsigned rows, unsigned cols, unsigned width, mesh_begin_cb *begin_cb, @@ -30,32 +42,38 @@ generate_triangle_mesh(unsigned rows, unsigned cols, unsigned width, mesh_end_cb *end_cb, void *data) { - int i; + unsigned elts[64]; + unsigned count = 0; + unsigned i; int j; (*begin_cb)(data, GL_TRIANGLE_STRIP, rows * ((2 * cols) + 1)); for (i = 0; i < rows; i++) { if ((i & 1) == 0) { - for (j = 0; j < cols; j++) { + for (j = 0; j < (int)cols; j++) { const unsigned e0 = ((i + 0) * width) + j; const unsigned e1 = ((i + 1) * width) + j; - (*index_cb)(data, e0); - (*index_cb)(data, e1); + EMIT_ELT(e0); + EMIT_ELT(e1); } - (*index_cb)(data, (width - 1) + ((i + 0) * width)); + EMIT_ELT((width - 1) + ((i + 0) * width)); } else { for (j = cols - 1; j >= 0; j--) { const unsigned e0 = ((i + 0) * width) + j; const unsigned e1 = ((i + 1) * width) + j; - (*index_cb)(data, e0); - (*index_cb)(data, e1); + EMIT_ELT(e0); + EMIT_ELT(e1); } - (*index_cb)(data, (i + 0) * width); + EMIT_ELT((i + 0) * width); } } + + if (count != 0) + (*index_cb)(data, elts, count); + (*end_cb)(data); } @@ -28,7 +28,7 @@ extern "C" { #endif typedef void (mesh_begin_cb)(void *data, GLenum mode, unsigned count); -typedef void (mesh_index_cb)(void *data, unsigned index); +typedef void (mesh_index_cb)(void *data, const unsigned *index, unsigned count); typedef void (mesh_end_cb)(void *data); /** diff --git a/src/sphere.cpp b/src/sphere.cpp index 896f8d8..fafcb86 100644 --- a/src/sphere.cpp +++ b/src/sphere.cpp @@ -36,7 +36,7 @@ static void sphere_revolve_cb(void *data, static void sphere_begin_cb(void *data, GLenum mode, unsigned count); -static void sphere_index_cb(void *data, unsigned index); +static void sphere_index_cb(void *data, const unsigned *index, unsigned count); static void sphere_end_cb(void *data); /*@}*/ @@ -132,11 +132,11 @@ sphere_begin_cb(void *data, GLenum mode, unsigned count) static void -sphere_index_cb(void *data, unsigned index) +sphere_index_cb(void *data, const unsigned *index, unsigned count) { GLUconsumerFriend *c = (GLUconsumerFriend *) data; - c->index(index); + c->index_batch(index, count); } |