Showing the changes to libraries/render-utils/src/GeometryCache.cpp (1 of 9 files). Show all
Unified · Split
| @@ -661,6 +661,73 @@ void GeometryCache::renderWireCube(float size) { · 660 unmodified lines | |||
| 661 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | 661 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 662 | } | 662 | } |
| 663 | 663 | ||
| 664 | void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight) { | ||
| 665 | Vec2Pair key(topLeft, bottomRight); | ||
| 666 | VerticesIndices& vbo = _quad2DVBOs[key]; | ||
| 667 | const int FLOATS_PER_VERTEX = 2; | ||
| 668 | const int vertices = 4; | ||
| 669 | const int indices = 4; | ||
| 670 | if (vbo.first == 0) { | ||
| 671 | int vertexPoints = vertices * FLOATS_PER_VERTEX; | ||
| 672 | GLfloat* vertexData = new GLfloat[vertexPoints]; // only vertices, no normals because we're a 2D quad | ||
| 673 | GLfloat* vertex = vertexData; | ||
| 674 | // index array of vertex array for glDrawRangeElement() as a GL_LINES for each edge | ||
| 675 | static GLubyte cannonicalIndices[indices] = { 0, 1, 2, 3 }; | ||
| 676 | |||
| 677 | //glBegin(GL_QUADS); | ||
| 678 | // glVertex2f(left, top); | ||
| 679 | // glVertex2f(right, top); | ||
| 680 | // glVertex2f(right, bottom); | ||
| 681 | // glVertex2f(left, bottom); | ||
| 682 | //glEnd(); | ||
| 683 | |||
| 684 | vertex[0] = topLeft.x; | ||
| 685 | vertex[1] = topLeft.y; | ||
| 686 | vertex[2] = bottomRight.x; | ||
| 687 | vertex[3] = topLeft.y; | ||
| 688 | vertex[4] = bottomRight.x; | ||
| 689 | vertex[5] = bottomRight.y; | ||
| 690 | vertex[6] = topLeft.x; | ||
| 691 | vertex[7] = bottomRight.y; | ||
| 692 | |||
| 693 | glGenBuffers(1, &vbo.first); | ||
| 694 | glBindBuffer(GL_ARRAY_BUFFER, vbo.first); | ||
| 695 | glBufferData(GL_ARRAY_BUFFER, vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); | ||
| 696 | delete[] vertexData; | ||
| 697 | |||
| 698 | GLushort* indexData = new GLushort[indices]; | ||
| 699 | GLushort* index = indexData; | ||
| 700 | for (int i = 0; i < indices; i++) { | ||
| 701 | index[i] = cannonicalIndices[i]; | ||
| 702 | } | ||
| 703 | |||
| 704 | glGenBuffers(1, &vbo.second); | ||
| 705 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); | ||
| 706 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); | ||
| 707 | delete[] indexData; | ||
| 708 | |||
| 709 | qDebug() << "new quad VBO made -- _quad2DVBOs.size():" << _quad2DVBOs.size(); | ||
| 710 | |||
| 711 | } else { | ||
| 712 | glBindBuffer(GL_ARRAY_BUFFER, vbo.first); | ||
| 713 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); | ||
| 714 | } | ||
| 715 | glEnableClientState(GL_VERTEX_ARRAY); | ||
| 716 | glVertexPointer(FLOATS_PER_VERTEX, GL_FLOAT, FLOATS_PER_VERTEX * sizeof(float), 0); | ||
| 717 | glDrawRangeElementsEXT(GL_QUADS, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); | ||
| 718 | glDisableClientState(GL_VERTEX_ARRAY); | ||
| 719 | |||
| 720 | glBindBuffer(GL_ARRAY_BUFFER, 0); | ||
| 721 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | ||
| 722 | } | ||
| 723 | |||
| 724 | |||
| 725 | /* | ||
| 726 | void GeometryCache::renderQuad(cont glm::vec2& topLeft, cont glm::vec2& bottomRight, | ||
| 727 | cont glm::vec2& texCoordTopLeft, cont glm::vec2& texCoordBottomRight) { | ||
| 728 | } | ||
| 729 | */ | ||
| 730 | |||
| 664 | 731 | ||
| 665 | QSharedPointer<NetworkGeometry> GeometryCache::getGeometry(const QUrl& url, const QUrl& fallback, bool delayLoad) { | 732 | QSharedPointer<NetworkGeometry> GeometryCache::getGeometry(const QUrl& url, const QUrl& fallback, bool delayLoad) { |
| 666 | return getResource(url, fallback, delayLoad).staticCast<NetworkGeometry>(); | 733 | return getResource(url, fallback, delayLoad).staticCast<NetworkGeometry>(); |