History

first cut at registered quads to reduce copies of constantly changing quads

ZappoMan committed 11 years ago

Commit be137531 parent 53a7d834 files · +148 −34Browse files

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

Unified · Split

libraries/render-utils/src/GeometryCache.cpp+89−14
@@ -23,7 +23,13 @@ · 22 unmodified lines
2323 #include "TextureCache.h"
2424 #include "GeometryCache.h"
2525
26−GeometryCache::GeometryCache() {
26+//#define WANT_DEBUG
27+
28+const int GeometryCache::UNKNOWN_QUAD_ID = -1;
29+
30+GeometryCache::GeometryCache() :
31+ _nextQuadID(0)
32+{
2733 }
2834
2935 GeometryCache::~GeometryCache() {
@@ -661,9 +667,23 @@ void GeometryCache::renderWireCube(float size) { · 631 unmodified lines
661667 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
662668 }
663669
664−void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight) {
670+void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight, int quadID) {
671+
672+ bool registeredQuad = (quadID != UNKNOWN_QUAD_ID);
665673 Vec2Pair key(topLeft, bottomRight);
666− VerticesIndices& vbo = _quad2DVBOs[key];
674+ VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad2DVBOs[key];
675+
676+ // if this is a registered quad, and we have buffers, then clear them and rebuild
677+ // TODO: would be nice to only rebuild if the geometry changed from last time.
678+ if (registeredQuad && vbo.first != 0) {
679+ glDeleteBuffers(1, &vbo.first);
680+ glDeleteBuffers(1, &vbo.second);
681+ vbo.first = vbo.second = 0;
682+ #ifdef WANT_DEBUG
683+ qDebug() << "renderQuad() vec2... RELEASING REGISTERED QUAD";
684+ #endif // def WANT_DEBUG
685+ }
686+
667687 const int FLOATS_PER_VERTEX = 2;
668688 const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat);
669689 const int vertices = 4;
@@ -700,7 +720,11 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom · 30 unmodified lines
700720 delete[] indexData;
701721
702722 #ifdef WANT_DEBUG
703− qDebug() << "new quad VBO made -- _quad2DVBOs.size():" << _quad2DVBOs.size();
723+ if (quadID == UNKNOWN_QUAD_ID) {
724+ qDebug() << "new quad VBO made -- _quad2DVBOs.size():" << _quad2DVBOs.size();
725+ } else {
726+ qDebug() << "new registered quad VBO made -- _registeredQuadVBOs.size():" << _registeredQuadVBOs.size();
727+ }
704728 #endif
705729
706730 } else {
@@ -718,10 +742,23 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom · 11 unmodified lines
718742
719743
720744 void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight,
721− const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomRight) {
745+ const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomRight, int quadID) {
746+
747+ bool registeredQuad = (quadID != UNKNOWN_QUAD_ID);
722748 Vec2PairPair key(Vec2Pair(topLeft, bottomRight), Vec2Pair(texCoordTopLeft, texCoordBottomRight));
749+ VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad2DTextureVBOs[key];
723750
724− VerticesIndices& vbo = _quad2DTextureVBOs[key];
751+ // if this is a registered quad, and we have buffers, then clear them and rebuild
752+ // TODO: would be nice to only rebuild if the geometry changed from last time.
753+ if (registeredQuad && vbo.first != 0) {
754+ glDeleteBuffers(1, &vbo.first);
755+ glDeleteBuffers(1, &vbo.second);
756+ vbo.first = vbo.second = 0;
757+ #ifdef WANT_DEBUG
758+ qDebug() << "renderQuad() vec2 + texture... RELEASING REGISTERED QUAD";
759+ #endif // def WANT_DEBUG
760+ }
761+
725762 const int FLOATS_PER_VERTEX = 2 * 2; // text coords & vertices
726763 const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat);
727764 const int vertices = 4;
@@ -770,7 +807,11 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom · 42 unmodified lines
770807 delete[] indexData;
771808
772809 #ifdef WANT_DEBUG
773− qDebug() << "new quad + texture VBO made -- _quad2DTextureVBOs.size():" << _quad2DTextureVBOs.size();
810+ if (quadID == UNKNOWN_QUAD_ID) {
811+ qDebug() << "new quad + texture VBO made -- _quad2DTextureVBOs.size():" << _quad2DTextureVBOs.size();
812+ } else {
813+ qDebug() << "new registered quad VBO made -- _registeredQuadVBOs.size():" << _registeredQuadVBOs.size();
814+ }
774815 #endif
775816 } else {
776817 glBindBuffer(GL_ARRAY_BUFFER, vbo.first);
@@ -791,9 +832,23 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom · 14 unmodified lines
791832 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
792833 }
793834
794−void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomRight) {
835+void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomRight, int quadID) {
836+
837+ bool registeredQuad = (quadID != UNKNOWN_QUAD_ID);
795838 Vec3Pair key(topLeft, bottomRight);
796− VerticesIndices& vbo = _quad3DVBOs[key];
839+ VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad3DVBOs[key];
840+
841+ // if this is a registered quad, and we have buffers, then clear them and rebuild
842+ // TODO: would be nice to only rebuild if the geometry changed from last time.
843+ if (registeredQuad && vbo.first != 0) {
844+ glDeleteBuffers(1, &vbo.first);
845+ glDeleteBuffers(1, &vbo.second);
846+ vbo.first = vbo.second = 0;
847+ #ifdef WANT_DEBUG
848+ qDebug() << "renderQuad() vec3... RELEASING REGISTERED QUAD";
849+ #endif // def WANT_DEBUG
850+ }
851+
797852 const int FLOATS_PER_VERTEX = 3;
798853 const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat);
799854 const int vertices = 4;
@@ -838,7 +893,11 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom · 38 unmodified lines
838893 delete[] indexData;
839894
840895 #ifdef WANT_DEBUG
841− qDebug() << "new quad VBO made -- _quad3DVBOs.size():" << _quad3DVBOs.size();
896+ if (quadID == UNKNOWN_QUAD_ID) {
897+ qDebug() << "new quad VBO made -- _quad3DVBOs.size():" << _quad3DVBOs.size();
898+ } else {
899+ qDebug() << "new registered quad VBO made -- _registeredQuadVBOs.size():" << _registeredQuadVBOs.size();
900+ }
842901 #endif
843902
844903 } else {
@@ -858,7 +917,7 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom · 13 unmodified lines
858917 void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomLeft,
859918 const glm::vec3& bottomRight, const glm::vec3& topRight,
860919 const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomLeft,
861− const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight) {
920+ const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight, int quadID) {
862921
863922 #ifdef WANT_DEBUG
864923 qDebug() << "renderQuad() vec3 + texture VBO...";
@@ -869,10 +928,22 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom · 4 unmodified lines
869928 qDebug() << " texCoordTopLeft:" << texCoordTopLeft;
870929 qDebug() << " texCoordBottomRight:" << texCoordBottomRight;
871930 #endif //def WANT_DEBUG
872−
931+
932+ bool registeredQuad = (quadID != UNKNOWN_QUAD_ID);
873933 Vec3PairVec2Pair key(Vec3Pair(topLeft, bottomRight), Vec2Pair(texCoordTopLeft, texCoordBottomRight));
934+ VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad3DTextureVBOs[key];
935+
936+ // if this is a registered quad, and we have buffers, then clear them and rebuild
937+ // TODO: would be nice to only rebuild if the geometry changed from last time.
938+ if (registeredQuad && vbo.first != 0) {
939+ glDeleteBuffers(1, &vbo.first);
940+ glDeleteBuffers(1, &vbo.second);
941+ vbo.first = vbo.second = 0;
942+ #ifdef WANT_DEBUG
943+ qDebug() << "renderQuad() vec3 + texture VBO... RELEASING REGISTERED QUAD";
944+ #endif // def WANT_DEBUG
945+ }
874946
875− VerticesIndices& vbo = _quad3DTextureVBOs[key];
876947 const int FLOATS_PER_VERTEX = 5; // text coords & vertices
877948 const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat);
878949 const int vertices = 4;
@@ -925,7 +996,11 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom · 46 unmodified lines
925996 delete[] indexData;
926997
927998 #ifdef WANT_DEBUG
928− qDebug() << " _quad3DTextureVBOs.size():" << _quad3DTextureVBOs.size();
999+ if (quadID == UNKNOWN_QUAD_ID) {
1000+ qDebug() << " _quad3DTextureVBOs.size():" << _quad3DTextureVBOs.size();
1001+ } else {
1002+ qDebug() << "new registered quad VBO made -- _registeredQuadVBOs.size():" << _registeredQuadVBOs.size();
1003+ }
9291004 #endif
9301005 } else {
9311006 glBindBuffer(GL_ARRAY_BUFFER, vbo.first);

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