Showing the changes to libraries/render-utils/src/GeometryCache.cpp (1 of 2 files). Show all
Unified · Split
| @@ -55,8 +55,6 @@ const int NUM_VERTICES_PER_TRIANGLE = 3; · 54 unmodified lines | ||
| 55 | 55 | const int NUM_TRIANGLES_PER_QUAD = 2; |
| 56 | 56 | const int NUM_VERTICES_PER_TRIANGULATED_QUAD = NUM_VERTICES_PER_TRIANGLE * NUM_TRIANGLES_PER_QUAD; |
| 57 | 57 | const int NUM_COORDS_PER_VERTEX = 3; |
| 58 | −const int NUM_BYTES_PER_VERTEX = NUM_COORDS_PER_VERTEX * sizeof(GLfloat); | |
| 59 | −const int NUM_BYTES_PER_INDEX = sizeof(GLushort); | |
| 60 | 58 | |
| 61 | 59 | void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm::vec4& color, bool solid, int id) { |
| 62 | 60 | gpu::Batch batch; |
| @@ -308,106 +306,6 @@ void GeometryCache::renderSphere(gpu::Batch& batch, float radius, int slices, in · 245 unmodified lines | ||
| 308 | 306 | } |
| 309 | 307 | } |
| 310 | 308 | |
| 311 | −void GeometryCache::renderCone(float base, float height, int slices, int stacks) { | |
| 312 | − VerticesIndices& vbo = _coneVBOs[IntPair(slices, stacks)]; | |
| 313 | − int vertices = (stacks + 2) * slices; | |
| 314 | − int baseTriangles = slices - 2; | |
| 315 | − int indices = NUM_VERTICES_PER_TRIANGULATED_QUAD * slices * stacks + NUM_VERTICES_PER_TRIANGLE * baseTriangles; | |
| 316 | − if (vbo.first == 0) { | |
| 317 | − GLfloat* vertexData = new GLfloat[vertices * NUM_COORDS_PER_VERTEX * 2]; | |
| 318 | − GLfloat* vertex = vertexData; | |
| 319 | − // cap | |
| 320 | − for (int i = 0; i < slices; i++) { | |
| 321 | − float theta = TWO_PI * i / slices; | |
| 322 | − | |
| 323 | − //normals | |
| 324 | − *(vertex++) = 0.0f; | |
| 325 | − *(vertex++) = 0.0f; | |
| 326 | − *(vertex++) = -1.0f; | |
| 327 | − | |
| 328 | − // vertices | |
| 329 | − *(vertex++) = cosf(theta); | |
| 330 | − *(vertex++) = sinf(theta); | |
| 331 | − *(vertex++) = 0.0f; | |
| 332 | − } | |
| 333 | − // body | |
| 334 | − for (int i = 0; i <= stacks; i++) { | |
| 335 | − float z = (float)i / stacks; | |
| 336 | − float radius = 1.0f - z; | |
| 337 | − | |
| 338 | − for (int j = 0; j < slices; j++) { | |
| 339 | − float theta = TWO_PI * j / slices; | |
| 340 | − | |
| 341 | − //normals | |
| 342 | − *(vertex++) = cosf(theta) / SQUARE_ROOT_OF_2; | |
| 343 | − *(vertex++) = sinf(theta) / SQUARE_ROOT_OF_2; | |
| 344 | − *(vertex++) = 1.0f / SQUARE_ROOT_OF_2; | |
| 345 | − | |
| 346 | − // vertices | |
| 347 | − *(vertex++) = radius * cosf(theta); | |
| 348 | − *(vertex++) = radius * sinf(theta); | |
| 349 | − *(vertex++) = z; | |
| 350 | − } | |
| 351 | − } | |
| 352 | − | |
| 353 | − glGenBuffers(1, &vbo.first); | |
| 354 | − glBindBuffer(GL_ARRAY_BUFFER, vbo.first); | |
| 355 | − glBufferData(GL_ARRAY_BUFFER, 2 * vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); | |
| 356 | − delete[] vertexData; | |
| 357 | − | |
| 358 | − GLushort* indexData = new GLushort[indices]; | |
| 359 | − GLushort* index = indexData; | |
| 360 | − for (int i = 0; i < baseTriangles; i++) { | |
| 361 | − *(index++) = 0; | |
| 362 | − *(index++) = i + 2; | |
| 363 | − *(index++) = i + 1; | |
| 364 | − } | |
| 365 | − for (int i = 1; i <= stacks; i++) { | |
| 366 | − GLushort bottom = i * slices; | |
| 367 | − GLushort top = bottom + slices; | |
| 368 | − for (int j = 0; j < slices; j++) { | |
| 369 | − int next = (j + 1) % slices; | |
| 370 | − | |
| 371 | − *(index++) = bottom + j; | |
| 372 | − *(index++) = top + next; | |
| 373 | − *(index++) = top + j; | |
| 374 | − | |
| 375 | − *(index++) = bottom + j; | |
| 376 | − *(index++) = bottom + next; | |
| 377 | − *(index++) = top + next; | |
| 378 | − } | |
| 379 | − } | |
| 380 | − | |
| 381 | − glGenBuffers(1, &vbo.second); | |
| 382 | − glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); | |
| 383 | − glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); | |
| 384 | − delete[] indexData; | |
| 385 | − | |
| 386 | − } else { | |
| 387 | − glBindBuffer(GL_ARRAY_BUFFER, vbo.first); | |
| 388 | − glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); | |
| 389 | − } | |
| 390 | − glEnableClientState(GL_VERTEX_ARRAY); | |
| 391 | − glEnableClientState(GL_NORMAL_ARRAY); | |
| 392 | − | |
| 393 | − int stride = NUM_VERTICES_PER_TRIANGULATED_QUAD * sizeof(float); | |
| 394 | − glNormalPointer(GL_FLOAT, stride, 0); | |
| 395 | − glVertexPointer(NUM_COORDS_PER_VERTEX, GL_FLOAT, stride, (const void *)(NUM_COORDS_PER_VERTEX * sizeof(float))); | |
| 396 | − | |
| 397 | − glPushMatrix(); | |
| 398 | − glScalef(base, base, height); | |
| 399 | − | |
| 400 | − glDrawRangeElementsEXT(GL_TRIANGLES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); | |
| 401 | − | |
| 402 | − glPopMatrix(); | |
| 403 | − | |
| 404 | − glDisableClientState(GL_VERTEX_ARRAY); | |
| 405 | − glDisableClientState(GL_NORMAL_ARRAY); | |
| 406 | − | |
| 407 | − glBindBuffer(GL_ARRAY_BUFFER, 0); | |
| 408 | − glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | |
| 409 | −} | |
| 410 | − | |
| 411 | 309 | void GeometryCache::renderGrid(int xDivisions, int yDivisions, const glm::vec4& color) { |
| 412 | 310 | gpu::Batch batch; |
| 413 | 311 | renderGrid(batch, xDivisions, yDivisions, color); |