Showing the changes to libraries/render-utils/src/GeometryCache.cpp (1 of 4 files). Show all
Unified · Split
| @@ -23,7 +23,13 @@ · 22 unmodified lines | ||
| 23 | 23 | #include "TextureCache.h" |
| 24 | 24 | #include "GeometryCache.h" |
| 25 | 25 | |
| 26 | −GeometryCache::GeometryCache() { | |
| 26 | +//#define WANT_DEBUG | |
| 27 | + | |
| 28 | +const int GeometryCache::UNKNOWN_QUAD_ID = -1; | |
| 29 | + | |
| 30 | +GeometryCache::GeometryCache() : | |
| 31 | + _nextQuadID(0) | |
| 32 | +{ | |
| 27 | 33 | } |
| 28 | 34 | |
| 29 | 35 | GeometryCache::~GeometryCache() { |
| @@ -661,9 +667,23 @@ void GeometryCache::renderWireCube(float size) { · 631 unmodified lines | ||
| 661 | 667 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 662 | 668 | } |
| 663 | 669 | |
| 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); | |
| 665 | 673 | 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 | + | |
| 667 | 687 | const int FLOATS_PER_VERTEX = 2; |
| 668 | 688 | const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); |
| 669 | 689 | const int vertices = 4; |
| @@ -700,7 +720,11 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom · 30 unmodified lines | ||
| 700 | 720 | delete[] indexData; |
| 701 | 721 | |
| 702 | 722 | #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 | + } | |
| 704 | 728 | #endif |
| 705 | 729 | |
| 706 | 730 | } else { |
| @@ -718,10 +742,23 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom · 11 unmodified lines | ||
| 718 | 742 | |
| 719 | 743 | |
| 720 | 744 | 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); | |
| 722 | 748 | Vec2PairPair key(Vec2Pair(topLeft, bottomRight), Vec2Pair(texCoordTopLeft, texCoordBottomRight)); |
| 749 | + VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad2DTextureVBOs[key]; | |
| 723 | 750 | |
| 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 | + | |
| 725 | 762 | const int FLOATS_PER_VERTEX = 2 * 2; // text coords & vertices |
| 726 | 763 | const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); |
| 727 | 764 | const int vertices = 4; |
| @@ -770,7 +807,11 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom · 42 unmodified lines | ||
| 770 | 807 | delete[] indexData; |
| 771 | 808 | |
| 772 | 809 | #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 | + } | |
| 774 | 815 | #endif |
| 775 | 816 | } else { |
| 776 | 817 | glBindBuffer(GL_ARRAY_BUFFER, vbo.first); |
| @@ -791,9 +832,23 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom · 14 unmodified lines | ||
| 791 | 832 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 792 | 833 | } |
| 793 | 834 | |
| 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); | |
| 795 | 838 | 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 | + | |
| 797 | 852 | const int FLOATS_PER_VERTEX = 3; |
| 798 | 853 | const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); |
| 799 | 854 | const int vertices = 4; |
| @@ -838,7 +893,11 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom · 38 unmodified lines | ||
| 838 | 893 | delete[] indexData; |
| 839 | 894 | |
| 840 | 895 | #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 | + } | |
| 842 | 901 | #endif |
| 843 | 902 | |
| 844 | 903 | } else { |
| @@ -858,7 +917,7 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom · 13 unmodified lines | ||
| 858 | 917 | void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomLeft, |
| 859 | 918 | const glm::vec3& bottomRight, const glm::vec3& topRight, |
| 860 | 919 | 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) { | |
| 862 | 921 | |
| 863 | 922 | #ifdef WANT_DEBUG |
| 864 | 923 | qDebug() << "renderQuad() vec3 + texture VBO..."; |
| @@ -869,10 +928,22 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom · 4 unmodified lines | ||
| 869 | 928 | qDebug() << " texCoordTopLeft:" << texCoordTopLeft; |
| 870 | 929 | qDebug() << " texCoordBottomRight:" << texCoordBottomRight; |
| 871 | 930 | #endif //def WANT_DEBUG |
| 872 | − | |
| 931 | + | |
| 932 | + bool registeredQuad = (quadID != UNKNOWN_QUAD_ID); | |
| 873 | 933 | 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 | + } | |
| 874 | 946 | |
| 875 | − VerticesIndices& vbo = _quad3DTextureVBOs[key]; | |
| 876 | 947 | const int FLOATS_PER_VERTEX = 5; // text coords & vertices |
| 877 | 948 | const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); |
| 878 | 949 | const int vertices = 4; |
| @@ -925,7 +996,11 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom · 46 unmodified lines | ||
| 925 | 996 | delete[] indexData; |
| 926 | 997 | |
| 927 | 998 | #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 | + } | |
| 929 | 1004 | #endif |
| 930 | 1005 | } else { |
| 931 | 1006 | glBindBuffer(GL_ARRAY_BUFFER, vbo.first); |