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 | #include "TextureCache.h" | 23 | #include "TextureCache.h" |
| 24 | #include "GeometryCache.h" | 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 | GeometryCache::~GeometryCache() { | 35 | GeometryCache::~GeometryCache() { |
| @@ -661,9 +667,23 @@ void GeometryCache::renderWireCube(float size) { · 631 unmodified lines | |||
| 661 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | 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 | Vec2Pair key(topLeft, bottomRight); | 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 | const int FLOATS_PER_VERTEX = 2; | 687 | const int FLOATS_PER_VERTEX = 2; |
| 668 | const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); | 688 | const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); |
| 669 | const int vertices = 4; | 689 | const int vertices = 4; |
| @@ -700,7 +720,11 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom · 30 unmodified lines | |||
| 700 | delete[] indexData; | 720 | delete[] indexData; |
| 701 | 721 | ||
| 702 | #ifdef WANT_DEBUG | 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 | #endif | 728 | #endif |
| 705 | 729 | ||
| 706 | } else { | 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 | void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight, | 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 | Vec2PairPair key(Vec2Pair(topLeft, bottomRight), Vec2Pair(texCoordTopLeft, texCoordBottomRight)); | 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 | const int FLOATS_PER_VERTEX = 2 * 2; // text coords & vertices | 762 | const int FLOATS_PER_VERTEX = 2 * 2; // text coords & vertices |
| 726 | const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); | 763 | const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); |
| 727 | const int vertices = 4; | 764 | const int vertices = 4; |
| @@ -770,7 +807,11 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom · 42 unmodified lines | |||
| 770 | delete[] indexData; | 807 | delete[] indexData; |
| 771 | 808 | ||
| 772 | #ifdef WANT_DEBUG | 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 | #endif | 815 | #endif |
| 775 | } else { | 816 | } else { |
| 776 | glBindBuffer(GL_ARRAY_BUFFER, vbo.first); | 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 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | 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 | Vec3Pair key(topLeft, bottomRight); | 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 | const int FLOATS_PER_VERTEX = 3; | 852 | const int FLOATS_PER_VERTEX = 3; |
| 798 | const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); | 853 | const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); |
| 799 | const int vertices = 4; | 854 | const int vertices = 4; |
| @@ -838,7 +893,11 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom · 38 unmodified lines | |||
| 838 | delete[] indexData; | 893 | delete[] indexData; |
| 839 | 894 | ||
| 840 | #ifdef WANT_DEBUG | 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 | #endif | 901 | #endif |
| 843 | 902 | ||
| 844 | } else { | 903 | } else { |
| @@ -858,7 +917,7 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom · 13 unmodified lines | |||
| 858 | void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomLeft, | 917 | void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomLeft, |
| 859 | const glm::vec3& bottomRight, const glm::vec3& topRight, | 918 | const glm::vec3& bottomRight, const glm::vec3& topRight, |
| 860 | const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomLeft, | 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 | #ifdef WANT_DEBUG | 922 | #ifdef WANT_DEBUG |
| 864 | qDebug() << "renderQuad() vec3 + texture VBO..."; | 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 | qDebug() << " texCoordTopLeft:" << texCoordTopLeft; | 928 | qDebug() << " texCoordTopLeft:" << texCoordTopLeft; |
| 870 | qDebug() << " texCoordBottomRight:" << texCoordBottomRight; | 929 | qDebug() << " texCoordBottomRight:" << texCoordBottomRight; |
| 871 | #endif //def WANT_DEBUG | 930 | #endif //def WANT_DEBUG |
| 872 | 931 | ||
| 932 | bool registeredQuad = (quadID != UNKNOWN_QUAD_ID); | ||
| 873 | Vec3PairVec2Pair key(Vec3Pair(topLeft, bottomRight), Vec2Pair(texCoordTopLeft, texCoordBottomRight)); | 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 | const int FLOATS_PER_VERTEX = 5; // text coords & vertices | 947 | const int FLOATS_PER_VERTEX = 5; // text coords & vertices |
| 877 | const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); | 948 | const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); |
| 878 | const int vertices = 4; | 949 | const int vertices = 4; |
| @@ -925,7 +996,11 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom · 46 unmodified lines | |||
| 925 | delete[] indexData; | 996 | delete[] indexData; |
| 926 | 997 | ||
| 927 | #ifdef WANT_DEBUG | 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 | #endif | 1004 | #endif |
| 930 | } else { | 1005 | } else { |
| 931 | glBindBuffer(GL_ARRAY_BUFFER, vbo.first); | 1006 | glBindBuffer(GL_ARRAY_BUFFER, vbo.first); |