History

more work on removing immediate mode GL_QUADS

ZappoMan committed 11 years ago

Commit 3d42d531 parent 14458ac9 files · +148 −133Browse files

Showing the changes to libraries/render-utils/src/GeometryCache.cpp (1 of 9 files). Show all

Unified · Split

libraries/render-utils/src/GeometryCache.cpp+71−13
@@ -665,22 +665,15 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom · 664 unmodified lines
665665 Vec2Pair key(topLeft, bottomRight);
666666 VerticesIndices& vbo = _quad2DVBOs[key];
667667 const int FLOATS_PER_VERTEX = 2;
668+ const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat);
668669 const int vertices = 4;
669670 const int indices = 4;
670671 if (vbo.first == 0) {
671672 int vertexPoints = vertices * FLOATS_PER_VERTEX;
672673 GLfloat* vertexData = new GLfloat[vertexPoints]; // only vertices, no normals because we're a 2D quad
673674 GLfloat* vertex = vertexData;
674− // index array of vertex array for glDrawRangeElement() as a GL_LINES for each edge
675675 static GLubyte cannonicalIndices[indices] = { 0, 1, 2, 3 };
676676
677− //glBegin(GL_QUADS);
678− // glVertex2f(left, top);
679− // glVertex2f(right, top);
680− // glVertex2f(right, bottom);
681− // glVertex2f(left, bottom);
682− //glEnd();
683−
684677 vertex[0] = topLeft.x;
685678 vertex[1] = topLeft.y;
686679 vertex[2] = bottomRight.x;
@@ -722,12 +715,77 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom · 35 unmodified lines
722715 }
723716
724717
725−/*
726−void GeometryCache::renderQuad(cont glm::vec2& topLeft, cont glm::vec2& bottomRight,
727− cont glm::vec2& texCoordTopLeft, cont glm::vec2& texCoordBottomRight) {
728−}
729−*/
718+void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight,
719+ const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomRight) {
720+ Vec2PairPair key(Vec2Pair(topLeft, bottomRight), Vec2Pair(texCoordTopLeft, texCoordBottomRight));
721+
722+ VerticesIndices& vbo = _quad2DTextureVBOs[key];
723+ const int FLOATS_PER_VERTEX = 2 * 2; // text coords & vertices
724+ const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat);
725+ const int vertices = 4;
726+ const int indices = 4;
727+ if (vbo.first == 0) {
728+ int vertexPoints = vertices * FLOATS_PER_VERTEX;
729+ GLfloat* vertexData = new GLfloat[vertexPoints]; // text coords & vertices
730+ GLfloat* vertex = vertexData;
731+ static GLubyte cannonicalIndices[indices] = { 0, 1, 2, 3 };
732+ int v = 0;
730733
734+ vertex[v++] = topLeft.x;
735+ vertex[v++] = topLeft.y;
736+ vertex[v++] = texCoordTopLeft.x;
737+ vertex[v++] = texCoordTopLeft.y;
738+
739+ vertex[v++] = bottomRight.x;
740+ vertex[v++] = topLeft.y;
741+ vertex[v++] = texCoordBottomRight.x;
742+ vertex[v++] = texCoordTopLeft.y;
743+
744+ vertex[v++] = bottomRight.x;
745+ vertex[v++] = bottomRight.y;
746+ vertex[v++] = texCoordBottomRight.x;
747+ vertex[v++] = texCoordBottomRight.y;
748+
749+ vertex[v++] = topLeft.x;
750+ vertex[v++] = bottomRight.y;
751+ vertex[v++] = texCoordTopLeft.x;
752+ vertex[v++] = texCoordBottomRight.y;
753+
754+ glGenBuffers(1, &vbo.first);
755+ glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
756+ glBufferData(GL_ARRAY_BUFFER, vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW);
757+ delete[] vertexData;
758+
759+ GLushort* indexData = new GLushort[indices];
760+ GLushort* index = indexData;
761+ for (int i = 0; i < indices; i++) {
762+ index[i] = cannonicalIndices[i];
763+ }
764+
765+ glGenBuffers(1, &vbo.second);
766+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second);
767+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW);
768+ delete[] indexData;
769+
770+ qDebug() << "new quad + texture VBO made -- _quad2DTextureVBOs.size():" << _quad2DTextureVBOs.size();
771+ } else {
772+ glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
773+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second);
774+ }
775+
776+ glEnableClientState(GL_VERTEX_ARRAY);
777+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
778+ glVertexPointer(2, GL_FLOAT, NUM_BYTES_PER_VERTEX, 0);
779+ glTexCoordPointer(2, GL_FLOAT, NUM_BYTES_PER_VERTEX, (const void *)(2 * sizeof(float)));
780+
781+ glDrawRangeElementsEXT(GL_QUADS, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0);
782+
783+ glDisableClientState(GL_VERTEX_ARRAY);
784+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
785+
786+ glBindBuffer(GL_ARRAY_BUFFER, 0);
787+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
788+}
731789
732790 QSharedPointer<NetworkGeometry> GeometryCache::getGeometry(const QUrl& url, const QUrl& fallback, bool delayLoad) {
733791 return getResource(url, fallback, delayLoad).staticCast<NetworkGeometry>();

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t