Showing the changes to interface/src/renderer/GeometryCache.cpp (1 of 2 files). Show all
Unified · Split
| @@ -163,3 +163,71 @@ void GeometryCache::renderSquare(int xDivisions, int yDivisions) { · 162 unmodified lines | |||
| 163 | glBindBuffer(GL_ARRAY_BUFFER, 0); | 163 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 164 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | 164 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 165 | } | 165 | } |
| 166 | |||
| 167 | void GeometryCache::renderHalfCylinder(int slices, int stacks, float radius, float height) { | ||
| 168 | VerticesIndices& vbo = _halfCylinderVBOs[IntPair(slices, stacks)]; | ||
| 169 | int vertices = slices * (stacks - 1) + 1; | ||
| 170 | int indices = slices * 2 * 3 * (stacks - 2) + slices * 3; | ||
| 171 | if (vbo.first == 0) { | ||
| 172 | GLfloat* vertexData = new GLfloat[vertices * 3]; | ||
| 173 | GLfloat* vertex = vertexData; | ||
| 174 | for (int i = 0; i < stacks; i++) { | ||
| 175 | float z = i * height / stacks; | ||
| 176 | |||
| 177 | for (int j = 0; j < slices; j++) { | ||
| 178 | float theta = PIf * j / slices; | ||
| 179 | |||
| 180 | *(vertex++) = sinf(theta) * radius; | ||
| 181 | *(vertex++) = cosf(theta) * radius; | ||
| 182 | *(vertex++) = z; | ||
| 183 | } | ||
| 184 | } | ||
| 185 | |||
| 186 | glGenBuffers(1, &vbo.first); | ||
| 187 | glBindBuffer(GL_ARRAY_BUFFER, vbo.first); | ||
| 188 | const int BYTES_PER_VERTEX = 3 * sizeof(GLfloat); | ||
| 189 | glBufferData(GL_ARRAY_BUFFER, vertices * BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); | ||
| 190 | delete[] vertexData; | ||
| 191 | |||
| 192 | GLushort* indexData = new GLushort[indices]; | ||
| 193 | GLushort* index = indexData; | ||
| 194 | for (int i = 0; i < stacks - 1; i++) { | ||
| 195 | GLushort bottom = i * slices; | ||
| 196 | GLushort top = bottom + slices; | ||
| 197 | for (int j = 0; j < slices; j++) { | ||
| 198 | int next = (j + 1) % slices; | ||
| 199 | |||
| 200 | *(index++) = bottom + j; | ||
| 201 | *(index++) = top + next; | ||
| 202 | *(index++) = top + j; | ||
| 203 | |||
| 204 | *(index++) = bottom + j; | ||
| 205 | *(index++) = bottom + next; | ||
| 206 | *(index++) = top + next; | ||
| 207 | } | ||
| 208 | } | ||
| 209 | |||
| 210 | glGenBuffers(1, &vbo.second); | ||
| 211 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); | ||
| 212 | const int BYTES_PER_INDEX = sizeof(GLushort); | ||
| 213 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); | ||
| 214 | delete[] indexData; | ||
| 215 | |||
| 216 | } else { | ||
| 217 | glBindBuffer(GL_ARRAY_BUFFER, vbo.first); | ||
| 218 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); | ||
| 219 | } | ||
| 220 | glEnableClientState(GL_VERTEX_ARRAY); | ||
| 221 | glEnableClientState(GL_NORMAL_ARRAY); | ||
| 222 | |||
| 223 | glVertexPointer(3, GL_FLOAT, 0, 0); | ||
| 224 | glNormalPointer(GL_FLOAT, 0, 0); | ||
| 225 | |||
| 226 | glDrawRangeElementsEXT(GL_TRIANGLES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); | ||
| 227 | |||
| 228 | glDisableClientState(GL_VERTEX_ARRAY); | ||
| 229 | glDisableClientState(GL_NORMAL_ARRAY); | ||
| 230 | |||
| 231 | glBindBuffer(GL_ARRAY_BUFFER, 0); | ||
| 232 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | ||
| 233 | } | ||