From 4586afc6c5dabe8f192f2b5ca9312330a0d08e9c Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Mon, 29 Dec 2014 17:23:54 -0800 Subject: [PATCH 1/7] Fix for new version of cmake --- cmake/macros/IncludeDependencyIncludes.cmake | 11 +++++++---- cmake/macros/LinkHifiLibraries.cmake | 8 +++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/cmake/macros/IncludeDependencyIncludes.cmake b/cmake/macros/IncludeDependencyIncludes.cmake index a375404164..cc2e5ca121 100644 --- a/cmake/macros/IncludeDependencyIncludes.cmake +++ b/cmake/macros/IncludeDependencyIncludes.cmake @@ -15,8 +15,11 @@ macro(INCLUDE_DEPENDENCY_INCLUDES) # include those in our own target include_directories(SYSTEM ${${TARGET_NAME}_DEPENDENCY_INCLUDES}) - endif () - - # set the property on this target so it can be retreived by targets linking to us - set_target_properties(${TARGET_NAME} PROPERTIES DEPENDENCY_INCLUDES "${${TARGET_NAME}_DEPENDENCY_INCLUDES}") + + list(LENGTH ${TARGET_NAME}_DEPENDENCY_INCLUDES NUM_DEPENDENCY_INCLUDES) + if(NUM_DEPENDENCY_INCLUDES STRGREATER 0) + # set the property on this target so it can be retreived by targets linking to us + set_target_properties(${TARGET_NAME} PROPERTIES DEPENDENCY_INCLUDES "${${TARGET_NAME}_DEPENDENCY_INCLUDES}") + endif () + endif() endmacro(INCLUDE_DEPENDENCY_INCLUDES) \ No newline at end of file diff --git a/cmake/macros/LinkHifiLibraries.cmake b/cmake/macros/LinkHifiLibraries.cmake index 646b680f27..7d3aff0e78 100644 --- a/cmake/macros/LinkHifiLibraries.cmake +++ b/cmake/macros/LinkHifiLibraries.cmake @@ -27,7 +27,13 @@ macro(LINK_HIFI_LIBRARIES) # ask the library what its include dependencies are and link them get_target_property(LINKED_TARGET_DEPENDENCY_INCLUDES ${HIFI_LIBRARY} DEPENDENCY_INCLUDES) - list(APPEND ${TARGET_NAME}_DEPENDENCY_INCLUDES ${LINKED_TARGET_DEPENDENCY_INCLUDES}) + + if(LINKED_TARGET_DEPENDENCY_INCLUDES) + list(LENGTH LINKED_TARGET_DEPENDENCY_INCLUDES NUM_DEPENDENCY_INCLUDES) + if(NUM_DEPENDENCY_INCLUDES STRGREATER 0) + list(APPEND ${TARGET_NAME}_DEPENDENCY_INCLUDES ${LINKED_TARGET_DEPENDENCY_INCLUDES}) + endif() + endif() endforeach() endmacro(LINK_HIFI_LIBRARIES) \ No newline at end of file From 729034dd947fd5c4337f80f2030a5aaee54eabd3 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 30 Dec 2014 11:13:00 -0800 Subject: [PATCH 2/7] Removed unnecessary list(LENGTH ...) --- cmake/macros/IncludeDependencyIncludes.cmake | 7 ++----- cmake/macros/LinkHifiLibraries.cmake | 5 +---- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/cmake/macros/IncludeDependencyIncludes.cmake b/cmake/macros/IncludeDependencyIncludes.cmake index cc2e5ca121..4474bdc53a 100644 --- a/cmake/macros/IncludeDependencyIncludes.cmake +++ b/cmake/macros/IncludeDependencyIncludes.cmake @@ -16,10 +16,7 @@ macro(INCLUDE_DEPENDENCY_INCLUDES) # include those in our own target include_directories(SYSTEM ${${TARGET_NAME}_DEPENDENCY_INCLUDES}) - list(LENGTH ${TARGET_NAME}_DEPENDENCY_INCLUDES NUM_DEPENDENCY_INCLUDES) - if(NUM_DEPENDENCY_INCLUDES STRGREATER 0) - # set the property on this target so it can be retreived by targets linking to us - set_target_properties(${TARGET_NAME} PROPERTIES DEPENDENCY_INCLUDES "${${TARGET_NAME}_DEPENDENCY_INCLUDES}") - endif () + # set the property on this target so it can be retreived by targets linking to us + set_target_properties(${TARGET_NAME} PROPERTIES DEPENDENCY_INCLUDES "${${TARGET_NAME}_DEPENDENCY_INCLUDES}") endif() endmacro(INCLUDE_DEPENDENCY_INCLUDES) \ No newline at end of file diff --git a/cmake/macros/LinkHifiLibraries.cmake b/cmake/macros/LinkHifiLibraries.cmake index 7d3aff0e78..ef0c8321c6 100644 --- a/cmake/macros/LinkHifiLibraries.cmake +++ b/cmake/macros/LinkHifiLibraries.cmake @@ -29,10 +29,7 @@ macro(LINK_HIFI_LIBRARIES) get_target_property(LINKED_TARGET_DEPENDENCY_INCLUDES ${HIFI_LIBRARY} DEPENDENCY_INCLUDES) if(LINKED_TARGET_DEPENDENCY_INCLUDES) - list(LENGTH LINKED_TARGET_DEPENDENCY_INCLUDES NUM_DEPENDENCY_INCLUDES) - if(NUM_DEPENDENCY_INCLUDES STRGREATER 0) - list(APPEND ${TARGET_NAME}_DEPENDENCY_INCLUDES ${LINKED_TARGET_DEPENDENCY_INCLUDES}) - endif() + list(APPEND ${TARGET_NAME}_DEPENDENCY_INCLUDES ${LINKED_TARGET_DEPENDENCY_INCLUDES}) endif() endforeach() From be137534b5a76a816684d6e7943dda71febec2dc Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 30 Dec 2014 12:38:16 -0800 Subject: [PATCH 3/7] first cut at registered quads to reduce copies of constantly changing quads --- interface/src/ui/ApplicationOverlay.cpp | 50 +++++++-- interface/src/ui/ApplicationOverlay.h | 9 +- libraries/render-utils/src/GeometryCache.cpp | 105 ++++++++++++++++--- libraries/render-utils/src/GeometryCache.h | 20 ++-- 4 files changed, 149 insertions(+), 35 deletions(-) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 6c68e0add1..120c5b3043 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -105,7 +105,7 @@ bool raySphereIntersect(const glm::vec3 &dir, const glm::vec3 &origin, float r, } } -void renderReticle(glm::quat orientation, float alpha) { +void ApplicationOverlay::renderReticle(glm::quat orientation, float alpha) { glPushMatrix(); { glm::vec3 axis = glm::axis(orientation); glRotatef(glm::degrees(glm::angle(orientation)), axis.x, axis.y, axis.z); @@ -114,9 +114,12 @@ void renderReticle(glm::quat orientation, float alpha) { glm::vec3 bottomLeft = getPoint(reticleSize / 2.0f, reticleSize / 2.0f); glm::vec3 bottomRight = getPoint(-reticleSize / 2.0f, reticleSize / 2.0f); glColor4f(RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2], alpha); + if (_reticleQuad == GeometryCache::UNKNOWN_QUAD_ID) { + _reticleQuad = DependencyManager::get()->allocateQuad(); + } DependencyManager::get()->renderQuad(topLeft, bottomLeft, bottomRight, topRight, glm::vec2(0.0f, 0.0f), glm::vec2(1.0f, 0.0f), - glm::vec2(1.0f, 1.0f), glm::vec2(0.0f, 1.0f)); + glm::vec2(1.0f, 1.0f), glm::vec2(0.0f, 1.0f), _reticleQuad); } glPopMatrix(); } @@ -126,8 +129,13 @@ ApplicationOverlay::ApplicationOverlay() : _lastMouseMove(0), _alpha(1.0f), _oculusUIRadius(1.0f), - _crosshairTexture(0) { - + _crosshairTexture(0), + _reticleQuad(GeometryCache::UNKNOWN_QUAD_ID), + _magnifierQuad(GeometryCache::UNKNOWN_QUAD_ID), + _audioRedQuad(GeometryCache::UNKNOWN_QUAD_ID), + _audioGreenQuad(GeometryCache::UNKNOWN_QUAD_ID), + _audioBlueQuad(GeometryCache::UNKNOWN_QUAD_ID) +{ memset(_reticleActive, 0, sizeof(_reticleActive)); memset(_magActive, 0, sizeof(_reticleActive)); memset(_magSizeMult, 0, sizeof(_magSizeMult)); @@ -389,12 +397,17 @@ void ApplicationOverlay::displayOverlayTexture3DTV(Camera& whichCamera, float as glColor3f(RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2]); + if (_reticleQuad == GeometryCache::UNKNOWN_QUAD_ID) { + _reticleQuad = DependencyManager::get()->allocateQuad(); + } + DependencyManager::get()->renderQuad(glm::vec3(x + mouseX, y + mouseY, -distance), glm::vec3(x + mouseX + reticleSize, y + mouseY, -distance), glm::vec3(x + mouseX + reticleSize, y + mouseY - reticleSize, -distance), glm::vec3(x + mouseX, y + mouseY - reticleSize, -distance), glm::vec2(0.0f, 0.0f), glm::vec2(1.0f, 0.0f), - glm::vec2(1.0f, 1.0f), glm::vec2(0.0f, 1.0f)); + glm::vec2(1.0f, 1.0f), glm::vec2(0.0f, 1.0f), + _reticleQuad); glEnable(GL_DEPTH_TEST); @@ -696,7 +709,7 @@ void ApplicationOverlay::renderPointersOculus(const glm::vec3& eyePos) { } //Renders a small magnification of the currently bound texture at the coordinates -void ApplicationOverlay::renderMagnifier(glm::vec2 magPos, float sizeMult, bool showBorder) const { +void ApplicationOverlay::renderMagnifier(glm::vec2 magPos, float sizeMult, bool showBorder) { GLCanvas::SharedPointer glCanvas = DependencyManager::get(); const int widgetWidth = glCanvas->width(); @@ -742,11 +755,16 @@ void ApplicationOverlay::renderMagnifier(glm::vec2 magPos, float sizeMult, bool } glColor4f(1.0f, 1.0f, 1.0f, _alpha); + if (_magnifierQuad == GeometryCache::UNKNOWN_QUAD_ID) { + _magnifierQuad = DependencyManager::get()->allocateQuad(); + } + DependencyManager::get()->renderQuad(bottomLeft, bottomRight, topRight, topLeft, glm::vec2(magnifyULeft, magnifyVBottom), glm::vec2(magnifyURight, magnifyVBottom), glm::vec2(magnifyURight, magnifyVTop), - glm::vec2(magnifyULeft, magnifyVTop)); + glm::vec2(magnifyULeft, magnifyVTop), + _magnifierQuad); } glPopMatrix(); } @@ -845,10 +863,14 @@ void ApplicationOverlay::renderAudioMeter() { glColor3f(1, 1, 1); } // Draw Red Quad + if (_audioRedQuad == GeometryCache::UNKNOWN_QUAD_ID) { + _audioRedQuad = DependencyManager::get()->allocateQuad(); + } DependencyManager::get()->renderQuad(AUDIO_METER_X + AUDIO_METER_INSET + AUDIO_RED_START, audioMeterY + AUDIO_METER_INSET, audioLevel - AUDIO_RED_START, - AUDIO_METER_HEIGHT - AUDIO_METER_INSET); + AUDIO_METER_HEIGHT - AUDIO_METER_INSET, + _audioRedQuad); audioLevel = AUDIO_RED_START; } @@ -860,10 +882,14 @@ void ApplicationOverlay::renderAudioMeter() { glColor3f(1, 1, 1); } // Draw Green Quad + if (_audioGreenQuad == GeometryCache::UNKNOWN_QUAD_ID) { + _audioGreenQuad = DependencyManager::get()->allocateQuad(); + } DependencyManager::get()->renderQuad(AUDIO_METER_X + AUDIO_METER_INSET + AUDIO_GREEN_START, audioMeterY + AUDIO_METER_INSET, audioLevel - AUDIO_GREEN_START, - AUDIO_METER_HEIGHT - AUDIO_METER_INSET); + AUDIO_METER_HEIGHT - AUDIO_METER_INSET, + _audioGreenQuad); audioLevel = AUDIO_GREEN_START; } @@ -874,9 +900,13 @@ void ApplicationOverlay::renderAudioMeter() { glColor3f(1, 1, 1); } // Draw Blue (low level) quad + if (_audioBlueQuad == GeometryCache::UNKNOWN_QUAD_ID) { + _audioBlueQuad = DependencyManager::get()->allocateQuad(); + } DependencyManager::get()->renderQuad(AUDIO_METER_X + AUDIO_METER_INSET, audioMeterY + AUDIO_METER_INSET, - audioLevel, AUDIO_METER_HEIGHT - AUDIO_METER_INSET); + audioLevel, AUDIO_METER_HEIGHT - AUDIO_METER_INSET, + _audioBlueQuad); } void ApplicationOverlay::renderStatsAndLogs() { diff --git a/interface/src/ui/ApplicationOverlay.h b/interface/src/ui/ApplicationOverlay.h index 269adef4f3..20d38c879c 100644 --- a/interface/src/ui/ApplicationOverlay.h +++ b/interface/src/ui/ApplicationOverlay.h @@ -79,8 +79,9 @@ private: VerticesIndices _vbo; }; + void renderReticle(glm::quat orientation, float alpha); void renderPointers();; - void renderMagnifier(glm::vec2 magPos, float sizeMult, bool showBorder) const; + void renderMagnifier(glm::vec2 magPos, float sizeMult, bool showBorder); void renderControllerPointers(); void renderPointersOculus(const glm::vec3& eyePos); @@ -106,6 +107,12 @@ private: float _trailingAudioLoudness; GLuint _crosshairTexture; + + int _reticleQuad; + int _magnifierQuad; + int _audioRedQuad; + int _audioGreenQuad; + int _audioBlueQuad; }; #endif // hifi_ApplicationOverlay_h diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index a1cadf2c20..2eb54331c8 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -23,7 +23,13 @@ #include "TextureCache.h" #include "GeometryCache.h" -GeometryCache::GeometryCache() { +//#define WANT_DEBUG + +const int GeometryCache::UNKNOWN_QUAD_ID = -1; + +GeometryCache::GeometryCache() : + _nextQuadID(0) +{ } GeometryCache::~GeometryCache() { @@ -661,9 +667,23 @@ void GeometryCache::renderWireCube(float size) { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } -void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight) { +void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight, int quadID) { + + bool registeredQuad = (quadID != UNKNOWN_QUAD_ID); Vec2Pair key(topLeft, bottomRight); - VerticesIndices& vbo = _quad2DVBOs[key]; + VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad2DVBOs[key]; + + // if this is a registered quad, and we have buffers, then clear them and rebuild + // TODO: would be nice to only rebuild if the geometry changed from last time. + if (registeredQuad && vbo.first != 0) { + glDeleteBuffers(1, &vbo.first); + glDeleteBuffers(1, &vbo.second); + vbo.first = vbo.second = 0; + #ifdef WANT_DEBUG + qDebug() << "renderQuad() vec2... RELEASING REGISTERED QUAD"; + #endif // def WANT_DEBUG + } + const int FLOATS_PER_VERTEX = 2; const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); const int vertices = 4; @@ -700,7 +720,11 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom delete[] indexData; #ifdef WANT_DEBUG - qDebug() << "new quad VBO made -- _quad2DVBOs.size():" << _quad2DVBOs.size(); + if (quadID == UNKNOWN_QUAD_ID) { + qDebug() << "new quad VBO made -- _quad2DVBOs.size():" << _quad2DVBOs.size(); + } else { + qDebug() << "new registered quad VBO made -- _registeredQuadVBOs.size():" << _registeredQuadVBOs.size(); + } #endif } else { @@ -718,10 +742,23 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight, - const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomRight) { + const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomRight, int quadID) { + + bool registeredQuad = (quadID != UNKNOWN_QUAD_ID); Vec2PairPair key(Vec2Pair(topLeft, bottomRight), Vec2Pair(texCoordTopLeft, texCoordBottomRight)); + VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad2DTextureVBOs[key]; - VerticesIndices& vbo = _quad2DTextureVBOs[key]; + // if this is a registered quad, and we have buffers, then clear them and rebuild + // TODO: would be nice to only rebuild if the geometry changed from last time. + if (registeredQuad && vbo.first != 0) { + glDeleteBuffers(1, &vbo.first); + glDeleteBuffers(1, &vbo.second); + vbo.first = vbo.second = 0; + #ifdef WANT_DEBUG + qDebug() << "renderQuad() vec2 + texture... RELEASING REGISTERED QUAD"; + #endif // def WANT_DEBUG + } + const int FLOATS_PER_VERTEX = 2 * 2; // text coords & vertices const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); const int vertices = 4; @@ -770,7 +807,11 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom delete[] indexData; #ifdef WANT_DEBUG - qDebug() << "new quad + texture VBO made -- _quad2DTextureVBOs.size():" << _quad2DTextureVBOs.size(); + if (quadID == UNKNOWN_QUAD_ID) { + qDebug() << "new quad + texture VBO made -- _quad2DTextureVBOs.size():" << _quad2DTextureVBOs.size(); + } else { + qDebug() << "new registered quad VBO made -- _registeredQuadVBOs.size():" << _registeredQuadVBOs.size(); + } #endif } else { glBindBuffer(GL_ARRAY_BUFFER, vbo.first); @@ -791,9 +832,23 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } -void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomRight) { +void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomRight, int quadID) { + + bool registeredQuad = (quadID != UNKNOWN_QUAD_ID); Vec3Pair key(topLeft, bottomRight); - VerticesIndices& vbo = _quad3DVBOs[key]; + VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad3DVBOs[key]; + + // if this is a registered quad, and we have buffers, then clear them and rebuild + // TODO: would be nice to only rebuild if the geometry changed from last time. + if (registeredQuad && vbo.first != 0) { + glDeleteBuffers(1, &vbo.first); + glDeleteBuffers(1, &vbo.second); + vbo.first = vbo.second = 0; + #ifdef WANT_DEBUG + qDebug() << "renderQuad() vec3... RELEASING REGISTERED QUAD"; + #endif // def WANT_DEBUG + } + const int FLOATS_PER_VERTEX = 3; const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); const int vertices = 4; @@ -838,7 +893,11 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom delete[] indexData; #ifdef WANT_DEBUG - qDebug() << "new quad VBO made -- _quad3DVBOs.size():" << _quad3DVBOs.size(); + if (quadID == UNKNOWN_QUAD_ID) { + qDebug() << "new quad VBO made -- _quad3DVBOs.size():" << _quad3DVBOs.size(); + } else { + qDebug() << "new registered quad VBO made -- _registeredQuadVBOs.size():" << _registeredQuadVBOs.size(); + } #endif } else { @@ -858,7 +917,7 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomLeft, const glm::vec3& bottomRight, const glm::vec3& topRight, const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomLeft, - const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight) { + const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight, int quadID) { #ifdef WANT_DEBUG qDebug() << "renderQuad() vec3 + texture VBO..."; @@ -869,10 +928,22 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom qDebug() << " texCoordTopLeft:" << texCoordTopLeft; qDebug() << " texCoordBottomRight:" << texCoordBottomRight; #endif //def WANT_DEBUG - - Vec3PairVec2Pair key(Vec3Pair(topLeft, bottomRight), Vec2Pair(texCoordTopLeft, texCoordBottomRight)); - VerticesIndices& vbo = _quad3DTextureVBOs[key]; + bool registeredQuad = (quadID != UNKNOWN_QUAD_ID); + Vec3PairVec2Pair key(Vec3Pair(topLeft, bottomRight), Vec2Pair(texCoordTopLeft, texCoordBottomRight)); + VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad3DTextureVBOs[key]; + + // if this is a registered quad, and we have buffers, then clear them and rebuild + // TODO: would be nice to only rebuild if the geometry changed from last time. + if (registeredQuad && vbo.first != 0) { + glDeleteBuffers(1, &vbo.first); + glDeleteBuffers(1, &vbo.second); + vbo.first = vbo.second = 0; + #ifdef WANT_DEBUG + qDebug() << "renderQuad() vec3 + texture VBO... RELEASING REGISTERED QUAD"; + #endif // def WANT_DEBUG + } + const int FLOATS_PER_VERTEX = 5; // text coords & vertices const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); const int vertices = 4; @@ -925,7 +996,11 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom delete[] indexData; #ifdef WANT_DEBUG - qDebug() << " _quad3DTextureVBOs.size():" << _quad3DTextureVBOs.size(); + if (quadID == UNKNOWN_QUAD_ID) { + qDebug() << " _quad3DTextureVBOs.size():" << _quad3DTextureVBOs.size(); + } else { + qDebug() << "new registered quad VBO made -- _registeredQuadVBOs.size():" << _registeredQuadVBOs.size(); + } #endif } else { glBindBuffer(GL_ARRAY_BUFFER, vbo.first); diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 9a76973f77..5736cea116 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -90,23 +90,23 @@ public: void renderSolidCube(float size); void renderWireCube(float size); + int allocateQuad() { return _nextQuadID++; } + static const int UNKNOWN_QUAD_ID; - void renderQuad(int x, int y, int width, int height) { renderQuad(glm::vec2(x,y), glm::vec2(x + width, y + height)); } - void renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight); + void renderQuad(int x, int y, int width, int height, int quadID = UNKNOWN_QUAD_ID) + { renderQuad(glm::vec2(x,y), glm::vec2(x + width, y + height), quadID); } + + void renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight, int quadID = UNKNOWN_QUAD_ID); void renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight, - const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomRight); + const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomRight, int quadID = UNKNOWN_QUAD_ID); - - void renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomRight); - - //void renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomRight, - // const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomRight); + void renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomRight, int quadID = UNKNOWN_QUAD_ID); void renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomLeft, const glm::vec3& bottomRight, const glm::vec3& topRight, const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomLeft, - const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight); + const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight, int quadID = UNKNOWN_QUAD_ID); /// Loads geometry from the specified URL. /// \param fallback a fallback URL to load if the desired one is unavailable @@ -136,6 +136,8 @@ private: QHash _quad2DTextureVBOs; QHash _quad3DVBOs; QHash _quad3DTextureVBOs; + QHash _registeredQuadVBOs; + int _nextQuadID; QHash _gridBuffers; From 28569836bb1b0ae9aa1b13d0564ebeebb8dba9c9 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 30 Dec 2014 13:24:31 -0800 Subject: [PATCH 4/7] rename parameters and reuse previously registered quad if geometry didn't change --- libraries/render-utils/src/GeometryCache.cpp | 161 +++++++++++-------- libraries/render-utils/src/GeometryCache.h | 13 +- 2 files changed, 107 insertions(+), 67 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 2eb54331c8..a7ff3827f0 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -667,20 +667,28 @@ void GeometryCache::renderWireCube(float size) { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } -void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight, int quadID) { +void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, int quadID) { bool registeredQuad = (quadID != UNKNOWN_QUAD_ID); - Vec2Pair key(topLeft, bottomRight); + Vec2Pair key(minCorner, maxCorner); VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad2DVBOs[key]; // if this is a registered quad, and we have buffers, then clear them and rebuild // TODO: would be nice to only rebuild if the geometry changed from last time. if (registeredQuad && vbo.first != 0) { - glDeleteBuffers(1, &vbo.first); - glDeleteBuffers(1, &vbo.second); - vbo.first = vbo.second = 0; + Vec2Pair& lastKey = _lastRegisteredQuad2D[quadID]; + if (lastKey != key) { + glDeleteBuffers(1, &vbo.first); + glDeleteBuffers(1, &vbo.second); + vbo.first = vbo.second = 0; + #ifdef WANT_DEBUG + qDebug() << "renderQuad() vec2... RELEASING REGISTERED QUAD"; + #endif // def WANT_DEBUG + } #ifdef WANT_DEBUG - qDebug() << "renderQuad() vec2... RELEASING REGISTERED QUAD"; + else { + qDebug() << "renderQuad() vec2... REUSING PREVIOUSLY REGISTERED QUAD"; + } #endif // def WANT_DEBUG } @@ -688,20 +696,21 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); const int vertices = 4; const int indices = 4; - if (vbo.first == 0) { + if (vbo.first == 0) { + _lastRegisteredQuad2D[quadID] = key; int vertexPoints = vertices * FLOATS_PER_VERTEX; GLfloat* vertexData = new GLfloat[vertexPoints]; // only vertices, no normals because we're a 2D quad GLfloat* vertex = vertexData; static GLubyte cannonicalIndices[indices] = {0, 1, 2, 3}; - vertex[0] = topLeft.x; - vertex[1] = topLeft.y; - vertex[2] = bottomRight.x; - vertex[3] = topLeft.y; - vertex[4] = bottomRight.x; - vertex[5] = bottomRight.y; - vertex[6] = topLeft.x; - vertex[7] = bottomRight.y; + vertex[0] = minCorner.x; + vertex[1] = minCorner.y; + vertex[2] = maxCorner.x; + vertex[3] = minCorner.y; + vertex[4] = maxCorner.x; + vertex[5] = maxCorner.y; + vertex[6] = minCorner.x; + vertex[7] = maxCorner.y; glGenBuffers(1, &vbo.first); glBindBuffer(GL_ARRAY_BUFFER, vbo.first); @@ -741,21 +750,28 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom } -void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight, - const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomRight, int quadID) { +void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, + const glm::vec2& texCoordMinCorner, const glm::vec2& texCoordMaxCorner, int quadID) { bool registeredQuad = (quadID != UNKNOWN_QUAD_ID); - Vec2PairPair key(Vec2Pair(topLeft, bottomRight), Vec2Pair(texCoordTopLeft, texCoordBottomRight)); + Vec2PairPair key(Vec2Pair(minCorner, maxCorner), Vec2Pair(texCoordMinCorner, texCoordMaxCorner)); VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad2DTextureVBOs[key]; // if this is a registered quad, and we have buffers, then clear them and rebuild - // TODO: would be nice to only rebuild if the geometry changed from last time. if (registeredQuad && vbo.first != 0) { - glDeleteBuffers(1, &vbo.first); - glDeleteBuffers(1, &vbo.second); - vbo.first = vbo.second = 0; + Vec2PairPair& lastKey = _lastRegisteredQuad2DTexture[quadID]; + if (lastKey != key) { + glDeleteBuffers(1, &vbo.first); + glDeleteBuffers(1, &vbo.second); + vbo.first = vbo.second = 0; + #ifdef WANT_DEBUG + qDebug() << "renderQuad() vec2 + texture... RELEASING REGISTERED QUAD"; + #endif // def WANT_DEBUG + } #ifdef WANT_DEBUG - qDebug() << "renderQuad() vec2 + texture... RELEASING REGISTERED QUAD"; + else { + qDebug() << "renderQuad() vec2 + texture... REUSING PREVIOUSLY REGISTERED QUAD"; + } #endif // def WANT_DEBUG } @@ -763,32 +779,33 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); const int vertices = 4; const int indices = 4; - if (vbo.first == 0) { + if (vbo.first == 0) { + _lastRegisteredQuad2DTexture[quadID] = key; int vertexPoints = vertices * FLOATS_PER_VERTEX; GLfloat* vertexData = new GLfloat[vertexPoints]; // text coords & vertices GLfloat* vertex = vertexData; static GLubyte cannonicalIndices[indices] = {0, 1, 2, 3}; int v = 0; - vertex[v++] = topLeft.x; - vertex[v++] = topLeft.y; - vertex[v++] = texCoordTopLeft.x; - vertex[v++] = texCoordTopLeft.y; + vertex[v++] = minCorner.x; + vertex[v++] = minCorner.y; + vertex[v++] = texCoordMinCorner.x; + vertex[v++] = texCoordMinCorner.y; - vertex[v++] = bottomRight.x; - vertex[v++] = topLeft.y; - vertex[v++] = texCoordBottomRight.x; - vertex[v++] = texCoordTopLeft.y; + vertex[v++] = maxCorner.x; + vertex[v++] = minCorner.y; + vertex[v++] = texCoordMaxCorner.x; + vertex[v++] = texCoordMinCorner.y; - vertex[v++] = bottomRight.x; - vertex[v++] = bottomRight.y; - vertex[v++] = texCoordBottomRight.x; - vertex[v++] = texCoordBottomRight.y; + vertex[v++] = maxCorner.x; + vertex[v++] = maxCorner.y; + vertex[v++] = texCoordMaxCorner.x; + vertex[v++] = texCoordMaxCorner.y; - vertex[v++] = topLeft.x; - vertex[v++] = bottomRight.y; - vertex[v++] = texCoordTopLeft.x; - vertex[v++] = texCoordBottomRight.y; + vertex[v++] = minCorner.x; + vertex[v++] = maxCorner.y; + vertex[v++] = texCoordMinCorner.x; + vertex[v++] = texCoordMaxCorner.y; glGenBuffers(1, &vbo.first); glBindBuffer(GL_ARRAY_BUFFER, vbo.first); @@ -832,20 +849,28 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } -void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomRight, int quadID) { +void GeometryCache::renderQuad(const glm::vec3& minCorner, const glm::vec3& maxCorner, int quadID) { bool registeredQuad = (quadID != UNKNOWN_QUAD_ID); - Vec3Pair key(topLeft, bottomRight); + Vec3Pair key(minCorner, maxCorner); VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad3DVBOs[key]; // if this is a registered quad, and we have buffers, then clear them and rebuild // TODO: would be nice to only rebuild if the geometry changed from last time. if (registeredQuad && vbo.first != 0) { - glDeleteBuffers(1, &vbo.first); - glDeleteBuffers(1, &vbo.second); - vbo.first = vbo.second = 0; + Vec3Pair& lastKey = _lastRegisteredQuad3D[quadID]; + if (lastKey != key) { + glDeleteBuffers(1, &vbo.first); + glDeleteBuffers(1, &vbo.second); + vbo.first = vbo.second = 0; + #ifdef WANT_DEBUG + qDebug() << "renderQuad() vec3... RELEASING REGISTERED QUAD"; + #endif // def WANT_DEBUG + } #ifdef WANT_DEBUG - qDebug() << "renderQuad() vec3... RELEASING REGISTERED QUAD"; + else { + qDebug() << "renderQuad() vec3... REUSING PREVIOUSLY REGISTERED QUAD"; + } #endif // def WANT_DEBUG } @@ -854,27 +879,28 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom const int vertices = 4; const int indices = 4; if (vbo.first == 0) { + _lastRegisteredQuad3D[quadID] = key; int vertexPoints = vertices * FLOATS_PER_VERTEX; GLfloat* vertexData = new GLfloat[vertexPoints]; // only vertices GLfloat* vertex = vertexData; static GLubyte cannonicalIndices[indices] = {0, 1, 2, 3}; int v = 0; - vertex[v++] = topLeft.x; - vertex[v++] = topLeft.y; - vertex[v++] = topLeft.z; + vertex[v++] = minCorner.x; + vertex[v++] = minCorner.y; + vertex[v++] = minCorner.z; - vertex[v++] = bottomRight.x; - vertex[v++] = topLeft.y; - vertex[v++] = topLeft.z; + vertex[v++] = maxCorner.x; + vertex[v++] = minCorner.y; + vertex[v++] = minCorner.z; - vertex[v++] = bottomRight.x; - vertex[v++] = bottomRight.y; - vertex[v++] = bottomRight.z; + vertex[v++] = maxCorner.x; + vertex[v++] = maxCorner.y; + vertex[v++] = maxCorner.z; - vertex[v++] = topLeft.x; - vertex[v++] = bottomRight.y; - vertex[v++] = bottomRight.z; + vertex[v++] = minCorner.x; + vertex[v++] = maxCorner.y; + vertex[v++] = maxCorner.z; glGenBuffers(1, &vbo.first); glBindBuffer(GL_ARRAY_BUFFER, vbo.first); @@ -936,11 +962,19 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom // if this is a registered quad, and we have buffers, then clear them and rebuild // TODO: would be nice to only rebuild if the geometry changed from last time. if (registeredQuad && vbo.first != 0) { - glDeleteBuffers(1, &vbo.first); - glDeleteBuffers(1, &vbo.second); - vbo.first = vbo.second = 0; + Vec3PairVec2Pair& lastKey = _lastRegisteredQuad3DTexture[quadID]; + if (lastKey != key) { + glDeleteBuffers(1, &vbo.first); + glDeleteBuffers(1, &vbo.second); + vbo.first = vbo.second = 0; + #ifdef WANT_DEBUG + qDebug() << "renderQuad() vec3 + texture VBO... RELEASING REGISTERED QUAD"; + #endif // def WANT_DEBUG + } #ifdef WANT_DEBUG - qDebug() << "renderQuad() vec3 + texture VBO... RELEASING REGISTERED QUAD"; + else { + qDebug() << "renderQuad() vec3 + texture... REUSING PREVIOUSLY REGISTERED QUAD"; + } #endif // def WANT_DEBUG } @@ -948,7 +982,8 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); const int vertices = 4; const int indices = 4; - if (vbo.first == 0) { + if (vbo.first == 0) { + _lastRegisteredQuad3DTexture[quadID] = key; int vertexPoints = vertices * FLOATS_PER_VERTEX; GLfloat* vertexData = new GLfloat[vertexPoints]; // text coords & vertices GLfloat* vertex = vertexData; diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 5736cea116..f7b4489cc8 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -96,12 +96,12 @@ public: void renderQuad(int x, int y, int width, int height, int quadID = UNKNOWN_QUAD_ID) { renderQuad(glm::vec2(x,y), glm::vec2(x + width, y + height), quadID); } - void renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight, int quadID = UNKNOWN_QUAD_ID); + void renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, int quadID = UNKNOWN_QUAD_ID); - void renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight, - const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomRight, int quadID = UNKNOWN_QUAD_ID); + void renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, + const glm::vec2& texCoordMinCorner, const glm::vec2& texCoordMaxCorner, int quadID = UNKNOWN_QUAD_ID); - void renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomRight, int quadID = UNKNOWN_QUAD_ID); + void renderQuad(const glm::vec3& minCorner, const glm::vec3& maxCorner, int quadID = UNKNOWN_QUAD_ID); void renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomLeft, const glm::vec3& bottomRight, const glm::vec3& topRight, @@ -139,6 +139,11 @@ private: QHash _registeredQuadVBOs; int _nextQuadID; + QHash _lastRegisteredQuad2D; + QHash _lastRegisteredQuad2DTexture; + QHash _lastRegisteredQuad3D; + QHash _lastRegisteredQuad3DTexture; + QHash _gridBuffers; QHash > _networkGeometry; From 4e6ed4a449419392e2c4de800f196b219e46bf3c Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 30 Dec 2014 13:26:13 -0800 Subject: [PATCH 5/7] fix comments --- libraries/render-utils/src/GeometryCache.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index a7ff3827f0..7e415a5d0d 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -673,8 +673,7 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC Vec2Pair key(minCorner, maxCorner); VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad2DVBOs[key]; - // if this is a registered quad, and we have buffers, then clear them and rebuild - // TODO: would be nice to only rebuild if the geometry changed from last time. + // if this is a registered quad, and we have buffers, then check to see if the geometry changed and rebuild if needed if (registeredQuad && vbo.first != 0) { Vec2Pair& lastKey = _lastRegisteredQuad2D[quadID]; if (lastKey != key) { @@ -757,7 +756,7 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC Vec2PairPair key(Vec2Pair(minCorner, maxCorner), Vec2Pair(texCoordMinCorner, texCoordMaxCorner)); VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad2DTextureVBOs[key]; - // if this is a registered quad, and we have buffers, then clear them and rebuild + // if this is a registered quad, and we have buffers, then check to see if the geometry changed and rebuild if needed if (registeredQuad && vbo.first != 0) { Vec2PairPair& lastKey = _lastRegisteredQuad2DTexture[quadID]; if (lastKey != key) { @@ -855,8 +854,7 @@ void GeometryCache::renderQuad(const glm::vec3& minCorner, const glm::vec3& maxC Vec3Pair key(minCorner, maxCorner); VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad3DVBOs[key]; - // if this is a registered quad, and we have buffers, then clear them and rebuild - // TODO: would be nice to only rebuild if the geometry changed from last time. + // if this is a registered quad, and we have buffers, then check to see if the geometry changed and rebuild if needed if (registeredQuad && vbo.first != 0) { Vec3Pair& lastKey = _lastRegisteredQuad3D[quadID]; if (lastKey != key) { @@ -959,8 +957,7 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom Vec3PairVec2Pair key(Vec3Pair(topLeft, bottomRight), Vec2Pair(texCoordTopLeft, texCoordBottomRight)); VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[quadID] : _quad3DTextureVBOs[key]; - // if this is a registered quad, and we have buffers, then clear them and rebuild - // TODO: would be nice to only rebuild if the geometry changed from last time. + // if this is a registered quad, and we have buffers, then check to see if the geometry changed and rebuild if needed if (registeredQuad && vbo.first != 0) { Vec3PairVec2Pair& lastKey = _lastRegisteredQuad3DTexture[quadID]; if (lastKey != key) { From fbfa40e3c96b085b7665900636c2ee1b32d1e1ab Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 30 Dec 2014 13:44:25 -0800 Subject: [PATCH 6/7] remove hair --- interface/src/Hair.cpp | 256 ------------------------------ interface/src/Hair.h | 70 -------- interface/src/Menu.cpp | 3 - interface/src/Menu.h | 1 - interface/src/avatar/Avatar.cpp | 20 --- interface/src/avatar/Avatar.h | 6 - interface/src/avatar/MyAvatar.cpp | 23 --- 7 files changed, 379 deletions(-) delete mode 100644 interface/src/Hair.cpp delete mode 100644 interface/src/Hair.h diff --git a/interface/src/Hair.cpp b/interface/src/Hair.cpp deleted file mode 100644 index c2d3f78b98..0000000000 --- a/interface/src/Hair.cpp +++ /dev/null @@ -1,256 +0,0 @@ -// -// Hair.cpp -// interface/src -// -// Created by Philip on June 26, 2014 -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// -// Creates single flexible verlet-integrated strands that can be used for hair/fur/grass - -#include - -#include "Util.h" -#include "world.h" - -#include "Hair.h" - - -const float HAIR_DAMPING = 0.99f; -const float CONSTRAINT_RELAXATION = 10.0f; -const float HAIR_ACCELERATION_COUPLING = 0.045f; -const float HAIR_ANGULAR_VELOCITY_COUPLING = 0.001f; -const float HAIR_ANGULAR_ACCELERATION_COUPLING = 0.001f; -const float HAIR_MAX_LINEAR_ACCELERATION = 4.0f; -const float HAIR_STIFFNESS = 0.00f; -const glm::vec3 HAIR_COLOR1(0.98f, 0.76f, 0.075f); -const glm::vec3 HAIR_COLOR2(0.912f, 0.184f, 0.101f); - -Hair::Hair(int strands, - int links, - float radius, - float linkLength, - float hairThickness) : - _strands(strands), - _links(links), - _linkLength(linkLength), - _hairThickness(hairThickness), - _radius(radius), - _acceleration(0.0f), - _angularVelocity(0.0f), - _angularAcceleration(0.0f), - _gravity(DEFAULT_GRAVITY), - _loudness(0.0f) -{ - _hairPosition = new glm::vec3[_strands * _links]; - _hairOriginalPosition = new glm::vec3[_strands * _links]; - _hairLastPosition = new glm::vec3[_strands * _links]; - _hairQuadDelta = new glm::vec3[_strands * _links]; - _hairNormals = new glm::vec3[_strands * _links]; - _hairColors = new glm::vec3[_strands * _links]; - _hairIsMoveable = new int[_strands * _links]; - _hairConstraints = new int[_strands * _links * HAIR_CONSTRAINTS]; // Hair can link to two others - glm::vec3 thisVertex; - for (int strand = 0; strand < _strands; strand++) { - float strandAngle = randFloat() * PI; - - float azimuth = (float)strand / (float)_strands * PI * 2.0f; - float elevation = 0.0f; - - glm::vec3 thisStrand(sinf(azimuth) * cosf(elevation), sinf(elevation), -cosf(azimuth) * cosf(elevation)); - thisStrand *= _radius; - - for (int link = 0; link < _links; link++) { - int vertexIndex = strand * _links + link; - // Clear constraints - for (int link2 = 0; link2 < HAIR_CONSTRAINTS; link2++) { - _hairConstraints[vertexIndex * HAIR_CONSTRAINTS + link2] = -1; - } - if (vertexIndex % _links == 0) { - // start of strand - thisVertex = thisStrand; - } else { - thisVertex+= glm::normalize(thisStrand) * _linkLength; - // Set constraints to vertex before and maybe vertex after in strand - _hairConstraints[vertexIndex * HAIR_CONSTRAINTS] = vertexIndex - 1; - if (link < (_links - 1)) { - _hairConstraints[vertexIndex * HAIR_CONSTRAINTS + 1] = vertexIndex + 1; - } - } - _hairOriginalPosition[vertexIndex] = _hairLastPosition[vertexIndex] = _hairPosition[vertexIndex] = thisVertex; - - _hairQuadDelta[vertexIndex] = glm::vec3(cos(strandAngle) * _hairThickness, 0.0f, sin(strandAngle) * _hairThickness); - _hairQuadDelta[vertexIndex] *= ((float)link / _links); - _hairNormals[vertexIndex] = glm::normalize(randVector()); - if (randFloat() < elevation / PI_OVER_TWO) { - _hairColors[vertexIndex] = HAIR_COLOR1 * ((float)(link + 1) / (float)_links); - } else { - _hairColors[vertexIndex] = HAIR_COLOR2 * ((float)(link + 1) / (float)_links); - } - } - } -} - -Hair::~Hair() { - delete[] _hairPosition; - delete[] _hairOriginalPosition; - delete[] _hairLastPosition; - delete[] _hairQuadDelta; - delete[] _hairNormals; - delete[] _hairColors; - delete[] _hairIsMoveable; - delete[] _hairConstraints; -} - -const float SOUND_THRESHOLD = 40.0f; - -void Hair::simulate(float deltaTime) { - deltaTime = glm::clamp(deltaTime, 0.0f, 1.0f / 30.0f); - glm::vec3 acceleration = _acceleration; - if (glm::length(acceleration) > HAIR_MAX_LINEAR_ACCELERATION) { - acceleration = glm::normalize(acceleration) * HAIR_MAX_LINEAR_ACCELERATION; - } - - for (int strand = 0; strand < _strands; strand++) { - for (int link = 0; link < _links; link++) { - int vertexIndex = strand * _links + link; - if (vertexIndex % _links == 0) { - // Base Joint - no integration - } else { - // - // Vertlet Integration - // - // Add velocity from last position, with damping - glm::vec3 thisPosition = _hairPosition[vertexIndex]; - glm::vec3 diff = thisPosition - _hairLastPosition[vertexIndex]; - _hairPosition[vertexIndex] += diff * HAIR_DAMPING; - - /* - // Resolve collisions with sphere - if (glm::length(_hairPosition[vertexIndex]) < _radius) { - _hairPosition[vertexIndex] += glm::normalize(_hairPosition[vertexIndex]) * - (_radius - glm::length(_hairPosition[vertexIndex])); - } */ - - // Collide with a conical body descending from the root of the hair - glm::vec3 thisVertex = _hairPosition[vertexIndex]; - float depth = -thisVertex.y; - thisVertex.y = 0.0f; - const float BODY_CONE_ANGLE = 0.30; - if (glm::length(thisVertex) < depth * BODY_CONE_ANGLE) { - _hairPosition[vertexIndex] += glm::normalize(thisVertex) * (depth * BODY_CONE_ANGLE - glm::length(thisVertex)); - } - - // Add random thing driven by loudness - float loudnessFactor = (_loudness > SOUND_THRESHOLD) ? logf(_loudness - SOUND_THRESHOLD) / 2000.0f : 0.0f; - - const float QUIESCENT_LOUDNESS = 0.0f; - _hairPosition[vertexIndex] += randVector() * (QUIESCENT_LOUDNESS + loudnessFactor) * ((float)link / (float)_links); - - // Add gravity - const float SCALE_GRAVITY = 0.001f; - _hairPosition[vertexIndex] += _gravity * deltaTime * SCALE_GRAVITY; - - // Add linear acceleration - _hairPosition[vertexIndex] -= acceleration * HAIR_ACCELERATION_COUPLING * deltaTime; - - // Add stiffness to return to original position - _hairPosition[vertexIndex] += (_hairOriginalPosition[vertexIndex] - _hairPosition[vertexIndex]) - * powf(1.0f - (float)link / _links, 2.0f) * HAIR_STIFFNESS; - - // Add angular acceleration - const float ANGULAR_VELOCITY_MIN = 0.001f; - if (glm::length(_angularVelocity) > ANGULAR_VELOCITY_MIN) { - glm::vec3 yawVector = _hairPosition[vertexIndex]; - glm::vec3 angularVelocity = _angularVelocity * HAIR_ANGULAR_VELOCITY_COUPLING; - glm::vec3 angularAcceleration = _angularAcceleration * HAIR_ANGULAR_ACCELERATION_COUPLING; - yawVector.y = 0.0f; - if (glm::length(yawVector) > EPSILON) { - float radius = glm::length(yawVector); - yawVector = glm::normalize(yawVector); - float angle = atan2f(yawVector.x, -yawVector.z) + PI; - glm::vec3 delta = glm::vec3(-1.0f, 0.0f, 0.0f) * glm::angleAxis(angle, glm::vec3(0, 1, 0)); - _hairPosition[vertexIndex] -= delta * radius * (angularVelocity.y - angularAcceleration.y) * deltaTime; - } - glm::vec3 pitchVector = _hairPosition[vertexIndex]; - pitchVector.x = 0.0f; - if (glm::length(pitchVector) > EPSILON) { - float radius = glm::length(pitchVector); - pitchVector = glm::normalize(pitchVector); - float angle = atan2f(pitchVector.y, -pitchVector.z) + PI; - glm::vec3 delta = glm::vec3(0.0f, 1.0f, 0.0f) * glm::angleAxis(angle, glm::vec3(1, 0, 0)); - _hairPosition[vertexIndex] -= delta * radius * (angularVelocity.x - angularAcceleration.x) * deltaTime; - } - glm::vec3 rollVector = _hairPosition[vertexIndex]; - rollVector.z = 0.0f; - if (glm::length(rollVector) > EPSILON) { - float radius = glm::length(rollVector); - pitchVector = glm::normalize(rollVector); - float angle = atan2f(rollVector.x, rollVector.y) + PI; - glm::vec3 delta = glm::vec3(-1.0f, 0.0f, 0.0f) * glm::angleAxis(angle, glm::vec3(0, 0, 1)); - _hairPosition[vertexIndex] -= delta * radius * (angularVelocity.z - angularAcceleration.z) * deltaTime; - } - } - - // Impose link constraints - for (int link = 0; link < HAIR_CONSTRAINTS; link++) { - if (_hairConstraints[vertexIndex * HAIR_CONSTRAINTS + link] > -1) { - // If there is a constraint, try to enforce it - glm::vec3 vectorBetween = _hairPosition[_hairConstraints[vertexIndex * HAIR_CONSTRAINTS + link]] - _hairPosition[vertexIndex]; - _hairPosition[vertexIndex] += glm::normalize(vectorBetween) * (glm::length(vectorBetween) - _linkLength) * CONSTRAINT_RELAXATION * deltaTime; - } - } - - // Store start position for next verlet pass - _hairLastPosition[vertexIndex] = thisPosition; - } - } - } -} - -void Hair::render() { - // - // Before calling this function, translate/rotate to the origin of the owning object - // - float loudnessFactor = (_loudness > SOUND_THRESHOLD) ? logf(_loudness - SOUND_THRESHOLD) / 16.0f : 0.0f; - const int SPARKLE_EVERY = 5; - const float HAIR_SETBACK = 0.0f; - int sparkleIndex = (int) (randFloat() * SPARKLE_EVERY); - glPushMatrix(); - glTranslatef(0.0f, 0.0f, HAIR_SETBACK); - glBegin(GL_QUADS); - for (int strand = 0; strand < _strands; strand++) { - for (int link = 0; link < _links - 1; link++) { - int vertexIndex = strand * _links + link; - glm::vec3 thisColor = _hairColors[vertexIndex]; - if (sparkleIndex % SPARKLE_EVERY == 0) { - thisColor.x += (1.0f - thisColor.x) * loudnessFactor; - thisColor.y += (1.0f - thisColor.y) * loudnessFactor; - thisColor.z += (1.0f - thisColor.z) * loudnessFactor; - } - glColor3fv(&thisColor.x); - glNormal3fv(&_hairNormals[vertexIndex].x); - glVertex3f(_hairPosition[vertexIndex].x - _hairQuadDelta[vertexIndex].x, - _hairPosition[vertexIndex].y - _hairQuadDelta[vertexIndex].y, - _hairPosition[vertexIndex].z - _hairQuadDelta[vertexIndex].z); - glVertex3f(_hairPosition[vertexIndex].x + _hairQuadDelta[vertexIndex].x, - _hairPosition[vertexIndex].y + _hairQuadDelta[vertexIndex].y, - _hairPosition[vertexIndex].z + _hairQuadDelta[vertexIndex].z); - - glVertex3f(_hairPosition[vertexIndex + 1].x + _hairQuadDelta[vertexIndex].x, - _hairPosition[vertexIndex + 1].y + _hairQuadDelta[vertexIndex].y, - _hairPosition[vertexIndex + 1].z + _hairQuadDelta[vertexIndex].z); - glVertex3f(_hairPosition[vertexIndex + 1].x - _hairQuadDelta[vertexIndex].x, - _hairPosition[vertexIndex + 1].y - _hairQuadDelta[vertexIndex].y, - _hairPosition[vertexIndex + 1].z - _hairQuadDelta[vertexIndex].z); - sparkleIndex++; - } - } - glEnd(); - glPopMatrix(); -} - - - diff --git a/interface/src/Hair.h b/interface/src/Hair.h deleted file mode 100644 index 436c6b836a..0000000000 --- a/interface/src/Hair.h +++ /dev/null @@ -1,70 +0,0 @@ -// -// Hair.h -// interface/src -// -// Created by Philip on June 26, 2014 -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#ifndef hifi_Hair_h -#define hifi_Hair_h - -#include - -#include -#include - -#include "GeometryUtil.h" -#include "InterfaceConfig.h" -#include "Util.h" - -const int HAIR_CONSTRAINTS = 2; - -const int DEFAULT_HAIR_STRANDS = 20; -const int DEFAULT_HAIR_LINKS = 11; -const float DEFAULT_HAIR_RADIUS = 0.075f; -const float DEFAULT_HAIR_LINK_LENGTH = 0.1f; -const float DEFAULT_HAIR_THICKNESS = 0.07f; -const glm::vec3 DEFAULT_GRAVITY(0.0f, -9.8f, 0.0f); - -class Hair { -public: - Hair(int strands = DEFAULT_HAIR_STRANDS, - int links = DEFAULT_HAIR_LINKS, - float radius = DEFAULT_HAIR_RADIUS, - float linkLength = DEFAULT_HAIR_LINK_LENGTH, - float hairThickness = DEFAULT_HAIR_THICKNESS); - ~Hair(); - void simulate(float deltaTime); - void render(); - void setAcceleration(const glm::vec3& acceleration) { _acceleration = acceleration; } - void setAngularVelocity(const glm::vec3& angularVelocity) { _angularVelocity = angularVelocity; } - void setAngularAcceleration(const glm::vec3& angularAcceleration) { _angularAcceleration = angularAcceleration; } - void setLoudness(const float loudness) { _loudness = loudness; } - -private: - int _strands; - int _links; - float _linkLength; - float _hairThickness; - float _radius; - glm::vec3* _hairPosition; - glm::vec3* _hairOriginalPosition; - glm::vec3* _hairLastPosition; - glm::vec3* _hairQuadDelta; - glm::vec3* _hairNormals; - glm::vec3* _hairColors; - int* _hairIsMoveable; - int* _hairConstraints; - glm::vec3 _acceleration; - glm::vec3 _angularVelocity; - glm::vec3 _angularAcceleration; - glm::vec3 _gravity; - float _loudness; - - }; - -#endif // hifi_Hair_h diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 2147dd9220..3e9bdde1ff 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -635,9 +635,6 @@ Menu::Menu() : connect(appInstance->getAudio(), SIGNAL(muteToggled()), this, SLOT(audioMuteToggled())); - QMenu* experimentalOptionsMenu = developerMenu->addMenu("Experimental"); - addCheckableActionToQMenuAndActionHash(experimentalOptionsMenu, MenuOption::StringHair, 0, false); - addActionToQMenuAndActionHash(developerMenu, MenuOption::PasteToVoxel, Qt::CTRL | Qt::SHIFT | Qt::Key_V, this, diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 27e57983af..a3e32b3682 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -475,7 +475,6 @@ namespace MenuOption { const QString Stats = "Stats"; const QString StereoAudio = "Stereo Audio"; const QString StopAllScripts = "Stop All Scripts"; - const QString StringHair = "String Hair"; const QString SuppressShortTimings = "Suppress Timings Less than 10ms"; const QString TestPing = "Test Ping"; const QString ToolWindow = "Tool Window"; diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 6b6316f578..3e57fc7dba 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -191,14 +191,6 @@ void Avatar::simulate(float deltaTime) { head->setScale(_scale); head->simulate(deltaTime, false, _shouldRenderBillboard); } - if (Menu::getInstance()->isOptionChecked(MenuOption::StringHair)) { - PerformanceTimer perfTimer("hair"); - _hair.setAcceleration(getAcceleration() * getHead()->getFinalOrientationInWorldFrame()); - _hair.setAngularVelocity((getAngularVelocity() + getHead()->getAngularVelocity()) * getHead()->getFinalOrientationInWorldFrame()); - _hair.setAngularAcceleration(getAngularAcceleration() * getHead()->getFinalOrientationInWorldFrame()); - _hair.setLoudness((float) getHeadData()->getAudioLoudness()); - _hair.simulate(deltaTime); - } } // update animation for display name fade in/out @@ -543,18 +535,6 @@ void Avatar::renderBody(RenderMode renderMode, bool postLighting, float glowLeve } } getHead()->render(1.0f, modelRenderMode, postLighting); - - if (!postLighting && Menu::getInstance()->isOptionChecked(MenuOption::StringHair)) { - // Render Hair - glPushMatrix(); - glm::vec3 headPosition = getHead()->getPosition(); - glTranslatef(headPosition.x, headPosition.y, headPosition.z); - const glm::quat& rotation = getHead()->getFinalOrientationInWorldFrame(); - glm::vec3 axis = glm::axis(rotation); - glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); - _hair.render(); - glPopMatrix(); - } } bool Avatar::shouldRenderHead(const glm::vec3& cameraPosition, RenderMode renderMode) const { diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index d862e042c2..f4727de94c 100644 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -19,7 +19,6 @@ #include -#include "Hair.h" #include "Hand.h" #include "Head.h" #include "InterfaceConfig.h" @@ -34,10 +33,6 @@ static const float RESCALING_TOLERANCE = .02f; extern const float CHAT_MESSAGE_SCALE; extern const float CHAT_MESSAGE_HEIGHT; -const int HAIR_STRANDS = 150; // Number of strands of hair -const int HAIR_LINKS = 10; // Number of links in a hair strand -const int HAIR_MAX_CONSTRAINTS = 2; // Hair verlet is connected to at most how many others - enum DriveKeys { FWD = 0, BACK, @@ -187,7 +182,6 @@ signals: void collisionWithAvatar(const QUuid& myUUID, const QUuid& theirUUID, const CollisionInfo& collision); protected: - Hair _hair; SkeletonModel _skeletonModel; glm::vec3 _skeletonOffset; QVector _attachmentModels; diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 4e3a9c4ff4..81d00bae74 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -225,17 +225,6 @@ void MyAvatar::simulate(float deltaTime) { head->simulate(deltaTime, true); } - { - PerformanceTimer perfTimer("hair"); - if (Menu::getInstance()->isOptionChecked(MenuOption::StringHair)) { - _hair.setAcceleration(getAcceleration() * getHead()->getFinalOrientationInWorldFrame()); - _hair.setAngularVelocity((getAngularVelocity() + getHead()->getAngularVelocity()) * getHead()->getFinalOrientationInWorldFrame()); - _hair.setAngularAcceleration(getAngularAcceleration() * getHead()->getFinalOrientationInWorldFrame()); - _hair.setLoudness((float)getHeadData()->getAudioLoudness()); - _hair.simulate(deltaTime); - } - } - { PerformanceTimer perfTimer("physics"); const float minError = 0.00001f; @@ -1139,18 +1128,6 @@ void MyAvatar::renderBody(RenderMode renderMode, bool postLighting, float glowLe const glm::vec3 cameraPos = camera->getPosition(); if (shouldRenderHead(cameraPos, renderMode)) { getHead()->render(1.0f, modelRenderMode, postLighting); - - if (!postLighting && Menu::getInstance()->isOptionChecked(MenuOption::StringHair)) { - // Render Hair - glPushMatrix(); - glm::vec3 headPosition = getHead()->getPosition(); - glTranslatef(headPosition.x, headPosition.y, headPosition.z); - const glm::quat& rotation = getHead()->getFinalOrientationInWorldFrame(); - glm::vec3 axis = glm::axis(rotation); - glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); - _hair.render(); - glPopMatrix(); - } } if (postLighting) { getHand()->render(true, modelRenderMode); From 86a9d5719b0f48ba71f8c1c0b63918d1a570954e Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 30 Dec 2014 15:12:23 -0800 Subject: [PATCH 7/7] fix one more case of animaiton stutter --- libraries/entities/src/ModelEntityItem.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index 0989068f2a..4cdec0f29a 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -18,7 +18,6 @@ #include "EntityTreeElement.h" #include "ModelEntityItem.h" - const QString ModelEntityItem::DEFAULT_MODEL_URL = QString(""); const QString ModelEntityItem::DEFAULT_ANIMATION_URL = QString(""); const float ModelEntityItem::DEFAULT_ANIMATION_FRAME_INDEX = 0.0f; @@ -33,7 +32,7 @@ EntityItem* ModelEntityItem::factory(const EntityItemID& entityID, const EntityI ModelEntityItem::ModelEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID, properties) { - _type = EntityTypes::Model; + _type = EntityTypes::Model; setProperties(properties); _lastAnimated = usecTimestampNow(); _jointMappingCompleted = false; @@ -343,9 +342,6 @@ QVector ModelEntityItem::getAnimationFrame() { Animation* myAnimation = getAnimation(_animationURL); QVector frames = myAnimation->getFrames(); int frameCount = frames.size(); - if (_animationLoop.getMaxFrameIndexHint() != frameCount) { - _animationLoop.setMaxFrameIndexHint(frameCount); - } if (frameCount > 0) { int animationFrameIndex = (int)(glm::floor(getAnimationFrameIndex())) % frameCount; if (animationFrameIndex < 0 || animationFrameIndex > frameCount) {