mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 04:27:57 +02:00
Add untested renderHalfCylinder function to GeometryCache/
This commit is contained in:
parent
d7dc07502c
commit
57efea40ee
2 changed files with 70 additions and 0 deletions
|
@ -163,3 +163,71 @@ void GeometryCache::renderSquare(int xDivisions, int yDivisions) {
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GeometryCache::renderHalfCylinder(int slices, int stacks, float radius, float height) {
|
||||||
|
VerticesIndices& vbo = _halfCylinderVBOs[IntPair(slices, stacks)];
|
||||||
|
int vertices = slices * (stacks - 1) + 1;
|
||||||
|
int indices = slices * 2 * 3 * (stacks - 2) + slices * 3;
|
||||||
|
if (vbo.first == 0) {
|
||||||
|
GLfloat* vertexData = new GLfloat[vertices * 3];
|
||||||
|
GLfloat* vertex = vertexData;
|
||||||
|
for (int i = 0; i < stacks; i++) {
|
||||||
|
float z = i * height / stacks;
|
||||||
|
|
||||||
|
for (int j = 0; j < slices; j++) {
|
||||||
|
float theta = PIf * j / slices;
|
||||||
|
|
||||||
|
*(vertex++) = sinf(theta) * radius;
|
||||||
|
*(vertex++) = cosf(theta) * radius;
|
||||||
|
*(vertex++) = z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
glGenBuffers(1, &vbo.first);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
|
||||||
|
const int BYTES_PER_VERTEX = 3 * sizeof(GLfloat);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, vertices * BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW);
|
||||||
|
delete[] vertexData;
|
||||||
|
|
||||||
|
GLushort* indexData = new GLushort[indices];
|
||||||
|
GLushort* index = indexData;
|
||||||
|
for (int i = 0; i < stacks - 1; i++) {
|
||||||
|
GLushort bottom = i * slices;
|
||||||
|
GLushort top = bottom + slices;
|
||||||
|
for (int j = 0; j < slices; j++) {
|
||||||
|
int next = (j + 1) % slices;
|
||||||
|
|
||||||
|
*(index++) = bottom + j;
|
||||||
|
*(index++) = top + next;
|
||||||
|
*(index++) = top + j;
|
||||||
|
|
||||||
|
*(index++) = bottom + j;
|
||||||
|
*(index++) = bottom + next;
|
||||||
|
*(index++) = top + next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
glGenBuffers(1, &vbo.second);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second);
|
||||||
|
const int BYTES_PER_INDEX = sizeof(GLushort);
|
||||||
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * BYTES_PER_INDEX, indexData, GL_STATIC_DRAW);
|
||||||
|
delete[] indexData;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second);
|
||||||
|
}
|
||||||
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
|
glEnableClientState(GL_NORMAL_ARRAY);
|
||||||
|
|
||||||
|
glVertexPointer(3, GL_FLOAT, 0, 0);
|
||||||
|
glNormalPointer(GL_FLOAT, 0, 0);
|
||||||
|
|
||||||
|
glDrawRangeElementsEXT(GL_TRIANGLES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0);
|
||||||
|
|
||||||
|
glDisableClientState(GL_VERTEX_ARRAY);
|
||||||
|
glDisableClientState(GL_NORMAL_ARRAY);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
|
}
|
|
@ -20,6 +20,7 @@ public:
|
||||||
|
|
||||||
void renderHemisphere(int slices, int stacks);
|
void renderHemisphere(int slices, int stacks);
|
||||||
void renderSquare(int xDivisions, int yDivisions);
|
void renderSquare(int xDivisions, int yDivisions);
|
||||||
|
void renderHalfCylinder(int slices, int stacks, float radius, float height);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -28,6 +29,7 @@ private:
|
||||||
|
|
||||||
QHash<IntPair, VerticesIndices> _hemisphereVBOs;
|
QHash<IntPair, VerticesIndices> _hemisphereVBOs;
|
||||||
QHash<IntPair, VerticesIndices> _squareVBOs;
|
QHash<IntPair, VerticesIndices> _squareVBOs;
|
||||||
|
QHash<IntPair, VerticesIndices> _halfCylinderVBOs;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__interface__GeometryCache__) */
|
#endif /* defined(__interface__GeometryCache__) */
|
||||||
|
|
Loading…
Reference in a new issue