summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Romanick <idr@freedesktop.org>2010-09-27 07:31:20 -0700
committerIan Romanick <idr@freedesktop.org>2010-10-02 14:58:26 -0700
commit73a53f2912a5312ce6d51dc2324167f79501ef62 (patch)
tree6a9ea644633558a7a3d46184fd59fb3ed5ee956c
parent197b409f054b01e9b3c2595dd508f8b181fea19a (diff)
GLUshape: Initial work towards making GLUshapeConsumer interface batch oriented
-rw-r--r--include/glu3.h12
-rw-r--r--src/cube.cpp99
-rw-r--r--src/revolve.c33
-rw-r--r--src/revolve.h2
-rw-r--r--src/sphere.cpp4
5 files changed, 77 insertions, 73 deletions
diff --git a/include/glu3.h b/include/glu3.h
index 995132f..4b18c13 100644
--- a/include/glu3.h
+++ b/include/glu3.h
@@ -301,7 +301,7 @@ struct GLUarcball {
class GLUshapeConsumer {
public:
/**
- * Emit an individual vertex
+ * Emit a batch of vertices
*
* \param position Object-space position of the vertex.
* \param normal Object-space normal of the vertex.
@@ -309,11 +309,13 @@ public:
* \param uv Parameter-space position of the vertex. The
* per-vertex values will range from (0,0,0,0) to
* (1, 1, 0, 0).
+ * \param count Number of vertices being emitted.
*/
- virtual void vertex(const GLUvec4 &position,
- const GLUvec4 &normal,
- const GLUvec4 &tangent,
- const GLUvec4 &uv) = 0;
+ virtual void vertex_batch(const GLUvec4 *position,
+ const GLUvec4 *normal,
+ const GLUvec4 *tangent,
+ const GLUvec4 *uv,
+ unsigned count) = 0;
/**
* Start a new indexed primitive.
diff --git a/src/cube.cpp b/src/cube.cpp
index 88d4fe3..c1a3b96 100644
--- a/src/cube.cpp
+++ b/src/cube.cpp
@@ -60,15 +60,15 @@ GLUcubeProducer::primitive_count(void) const
void
GLUcubeProducer::generate(GLUshapeConsumer *consumer) const
{
- static const float p[] = {
- +1.0, 1.0, 1.0, 1.0,
- -1.0, 1.0, 1.0, 1.0,
- +1.0, -1.0, 1.0, 1.0,
- -1.0, -1.0, 1.0, 1.0,
- +1.0, 1.0, -1.0, 1.0,
- -1.0, 1.0, -1.0, 1.0,
- +1.0, -1.0, -1.0, 1.0,
- -1.0, -1.0, -1.0, 1.0,
+ static const GLUvec4 p[] = {
+ GLUvec4(+1.0, 1.0, 1.0, 1.0),
+ GLUvec4(-1.0, 1.0, 1.0, 1.0),
+ GLUvec4(+1.0, -1.0, 1.0, 1.0),
+ GLUvec4(-1.0, -1.0, 1.0, 1.0),
+ GLUvec4(+1.0, 1.0, -1.0, 1.0),
+ GLUvec4(-1.0, 1.0, -1.0, 1.0),
+ GLUvec4(+1.0, -1.0, -1.0, 1.0),
+ GLUvec4(-1.0, -1.0, -1.0, 1.0),
};
#define X 0
@@ -112,54 +112,47 @@ GLUcubeProducer::generate(GLUshapeConsumer *consumer) const
#undef P
#undef V
- unsigned i;
-
-
- for (i = 0; i < Elements(p); i += 4) {
- GLUvec4 n;
- GLUvec4 t;
- GLUvec4 uv;
-
- n = GLUvec4(p[i + 0], 0.0, 0.0, 0.0);
- t = GLUvec4(0.0, 0.0, p[i + 0], 0.0);
- uv = GLUvec4((p[i + 2] + 1.0) * 0.5,
- (p[i + 1] + 1.0) * 0.5,
- 0.0,
- 0.0);
- consumer->vertex(GLUvec4(p[i + 0], p[i + 1],
- p[i + 2], p[i + 3]),
- n,
- t,
- uv);
-
- n = GLUvec4(0.0, p[i + 1], 0.0, 0.0);
- t = GLUvec4(p[i + 1], 0.0, 0.0, 0.0);
- uv = GLUvec4((p[i + 0] + 1.0) * 0.5,
- (p[i + 2] + 1.0) * 0.5,
- 0.0,
- 0.0);
- consumer->vertex(GLUvec4(p[i + 0], p[i + 1],
- p[i + 2], p[i + 3]),
- n,
- t,
- uv);
-
- n = GLUvec4(0.0, 0.0, p[i + 2], 0.0);
- t = GLUvec4(p[i + 2], 0.0, 0.0, 0.0);
- uv = GLUvec4((p[i + 0] + 1.0) * 0.5,
- (p[i + 1] + 1.0) * 0.5,
- 0.0,
- 0.0);
- consumer->vertex(GLUvec4(p[i + 0], p[i + 1],
- p[i + 2], p[i + 3]),
- n,
- t,
- uv);
+
+ GLUvec4 pos[3 * Elements(p)];
+ GLUvec4 nrm[3 * Elements(p)];
+ GLUvec4 tng[3 * Elements(p)];
+ GLUvec4 uv[3 * Elements(p)];
+ unsigned j = 0;
+
+ for (unsigned i = 0; i < Elements(p); i++) {
+ pos[j] = p[i];
+ nrm[j] = GLUvec4(p[i].values[0], 0.0, 0.0, 0.0);
+ tng[j] = GLUvec4(0.0, 0.0, p[i].values[0], 0.0);
+ uv[j] = GLUvec4((p[i].values[2] + 1.0) * 0.5,
+ (p[i].values[1] + 1.0) * 0.5,
+ 0.0,
+ 0.0);
+ j++;
+
+ pos[j] = p[i];
+ nrm[j] = GLUvec4(0.0, p[i].values[1], 0.0, 0.0);
+ tng[j] = GLUvec4(p[i].values[1], 0.0, 0.0, 0.0);
+ uv[j] = GLUvec4((p[i].values[0] + 1.0) * 0.5,
+ (p[i].values[2] + 1.0) * 0.5,
+ 0.0,
+ 0.0);
+ j++;
+
+ pos[j] = p[i];
+ nrm[j] = GLUvec4(0.0, 0.0, p[i].values[2], 0.0);
+ tng[j] = GLUvec4(p[i].values[2], 0.0, 0.0, 0.0);
+ uv[j] = GLUvec4((p[i].values[0] + 1.0) * 0.5,
+ (p[i].values[1] + 1.0) * 0.5,
+ 0.0,
+ 0.0);
+ j++;
}
+ consumer->vertex_batch(pos, nrm, tng, uv, j);
+
consumer->begin_primitive(GL_TRIANGLES);
- for (i = 0; i < Elements(elts); i++)
+ for (unsigned i = 0; i < Elements(elts); i++)
consumer->index(elts[i]);
consumer->end_primitive();
diff --git a/src/revolve.c b/src/revolve.c
index b345b0b..f6a170a 100644
--- a/src/revolve.c
+++ b/src/revolve.c
@@ -38,10 +38,16 @@ revolve(const GLUvec4 *points, const GLUvec4 *normals, const float *u,
{
const float angle_step = (end_angle - start_angle) / (float) (steps - 1);
const GLUvec4 tangent = {{ 0.0, 0.0, 1.0, 0.0 }};
+ GLUvec4 p[64];
+ GLUvec4 n[64];
+ GLUvec4 t[64];
+ GLUvec4 uv[64];
+ unsigned idx;
unsigned i;
unsigned j;
+ idx = 0;
for (i = 0; i < steps; i++) {
const float a = start_angle + (angle_step * i);
const float v = (float) i / (float) (steps - 1);
@@ -54,23 +60,26 @@ revolve(const GLUvec4 *points, const GLUvec4 *normals, const float *u,
gluRotate4v(& r, axis, a);
for (j = 0; j < num_points; j++) {
- GLUvec4 p;
- GLUvec4 n;
- GLUvec4 t;
- GLUvec4 uv;
+ gluMult4m_4v(& p[idx], & r, & points[j]);
+ gluMult4m_4v(& n[idx], & r, & normals[j]);
+ gluMult4m_4v(& t[idx], & r, & tangent);
- gluMult4m_4v(& p, & r, & points[j]);
- gluMult4m_4v(& n, & r, & normals[j]);
- gluMult4m_4v(& t, & r, & tangent);
+ uv[idx].values[0] = u[j];
+ uv[idx].values[1] = v;
+ uv[idx].values[2] = 0.0;
+ uv[idx].values[3] = 0.0;
- uv.values[0] = u[j];
- uv.values[1] = v;
- uv.values[2] = 0.0;
- uv.values[3] = 0.0;
+ idx++;
- (*cb)(data, & p, & n, & t, & uv);
+ if (idx >= 64) {
+ (*cb)(data, p, n, t, uv, idx);
+ idx = 0;
+ }
}
}
+
+ if (idx > 0)
+ (*cb)(data, p, n, t, uv, idx);
}
diff --git a/src/revolve.h b/src/revolve.h
index 960a50d..dafbc9e 100644
--- a/src/revolve.h
+++ b/src/revolve.h
@@ -30,7 +30,7 @@ extern "C" {
typedef void (revolve_cb)(void *data, const GLUvec4 *position,
const GLUvec4 *normal, const GLUvec4 *tangent,
- const GLUvec4 *uv);
+ const GLUvec4 *uv, unsigned count);
/**
* Generate a surface of revolution
diff --git a/src/sphere.cpp b/src/sphere.cpp
index c580323..79a733a 100644
--- a/src/sphere.cpp
+++ b/src/sphere.cpp
@@ -114,11 +114,11 @@ GLUsphereProducer::element_count(void) const
static void
sphere_revolve_cb(void *data, const GLUvec4 *position, const GLUvec4 *normal,
- const GLUvec4 *tangent, const GLUvec4 *uv)
+ const GLUvec4 *tangent, const GLUvec4 *uv, unsigned count)
{
GLUconsumerFriend *c = (GLUconsumerFriend *) data;
- c->vertex(*position, *normal, *tangent, *uv);
+ c->vertex_batch(position, normal, tangent, uv, count);
}