summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Romanick <idr@freedesktop.org>2010-09-27 06:56:58 -0700
committerIan Romanick <idr@freedesktop.org>2010-10-02 14:58:20 -0700
commit8cc549346c62764428667cabac0544682843b0dd (patch)
tree57d4b73a5a30504623b4574a7da69d0493fcb629
parentcef3b96405348fc3e6b7ae8556873dbabc2f1ca0 (diff)
GLUshape: Implement single primitive NxM mesh generation
-rw-r--r--src/mesh.c32
-rw-r--r--src/sphere.cpp5
2 files changed, 23 insertions, 14 deletions
diff --git a/src/mesh.c b/src/mesh.c
index 603570b..9082834 100644
--- a/src/mesh.c
+++ b/src/mesh.c
@@ -30,20 +30,32 @@ generate_triangle_mesh(unsigned rows, unsigned cols, unsigned width,
mesh_end_cb *end_cb,
void *data)
{
- unsigned i;
- unsigned j;
+ int i;
+ int j;
+ (*begin_cb)(data, GL_TRIANGLE_STRIP);
for (i = 0; i < rows; i++) {
- (*begin_cb)(data, GL_TRIANGLE_STRIP);
+ if ((i & 1) == 0) {
+ for (j = 0; j < cols; j++) {
+ const unsigned e0 = ((i + 0) * width) + j;
+ const unsigned e1 = ((i + 1) * width) + j;
- for (j = 0; j < cols; j++) {
- const unsigned e0 = ((i + 0) * width) + j;
- const unsigned e1 = ((i + 1) * width) + j;
+ (*index_cb)(data, e0);
+ (*index_cb)(data, e1);
+ }
- (*index_cb)(data, e0);
- (*index_cb)(data, e1);
- }
+ (*index_cb)(data, (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);
+ }
- (*end_cb)(data);
+ (*index_cb)(data, (i + 0) * width);
+ }
}
+ (*end_cb)(data);
}
diff --git a/src/sphere.cpp b/src/sphere.cpp
index 4aa1a79..c580323 100644
--- a/src/sphere.cpp
+++ b/src/sphere.cpp
@@ -98,10 +98,7 @@ GLUsphereProducer::vertex_count(void) const
unsigned
GLUsphereProducer::primitive_count(void) const
{
- /* For each slice there is a triangle strip from the north pole to the
- * south pole.
- */
- return slices;
+ return 1;
}