diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index 65f9718e80..001c7432df 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -292,6 +292,7 @@ int VoxelSystem::newTreeToArrays(VoxelNode* node) { assert(_viewFrustum); // you must set up _viewFrustum before calling this int voxelsUpdated = 0; bool shouldRender = false; // assume we don't need to render it + bool isLeaf = node->isLeaf(); // if it's colored, we might need to render it! if (node->isColored()) { float distanceToNode = node->distanceToCamera(*_viewFrustum); @@ -299,13 +300,15 @@ int VoxelSystem::newTreeToArrays(VoxelNode* node) { float childBoundary = boundaryDistanceForRenderLevel(node->getLevel() + 1); bool inBoundary = (distanceToNode <= boundary); bool inChildBoundary = (distanceToNode <= childBoundary); - shouldRender = (node->isLeaf() && inChildBoundary) || (inBoundary && !inChildBoundary); + shouldRender = (isLeaf && inChildBoundary) || (inBoundary && !inChildBoundary); } node->setShouldRender(shouldRender && !node->isStagedForDeletion()); // let children figure out their renderness - for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { - if (node->getChildAtIndex(i)) { - voxelsUpdated += newTreeToArrays(node->getChildAtIndex(i)); + if (!isLeaf) { + for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { + if (node->getChildAtIndex(i)) { + voxelsUpdated += newTreeToArrays(node->getChildAtIndex(i)); + } } } if (_renderFullVBO) { @@ -886,7 +889,8 @@ public: coloredNodes(0), nodesInVBO(0), nodesInVBOOverExpectedMax(0), - duplicateVBOIndex(0) + duplicateVBOIndex(0), + leafNodes(0) { memset(hasIndexFound, false, MAX_VOXELS_PER_SYSTEM * sizeof(bool)); }; @@ -898,9 +902,10 @@ public: unsigned long nodesInVBO; unsigned long nodesInVBOOverExpectedMax; unsigned long duplicateVBOIndex; + unsigned long leafNodes; + unsigned long expectedMax; - bool colorThis; bool hasIndexFound[MAX_VOXELS_PER_SYSTEM]; }; @@ -908,6 +913,10 @@ bool VoxelSystem::collectStatsForTreesAndVBOsOperation(VoxelNode* node, void* ex collectStatsForTreesAndVBOsArgs* args = (collectStatsForTreesAndVBOsArgs*)extraData; args->totalNodes++; + if (node->isLeaf()) { + args->leafNodes++; + } + if (node->isColored()) { args->coloredNodes++; } @@ -939,6 +948,7 @@ bool VoxelSystem::collectStatsForTreesAndVBOsOperation(VoxelNode* node, void* ex } void VoxelSystem::collectStatsForTreesAndVBOs() { + PerformanceWarning warn(true, "collectStatsForTreesAndVBOs()", true); glBufferIndex minDirty = GLBUFFER_INDEX_UNKNOWN; glBufferIndex maxDirty = 0; @@ -957,8 +967,10 @@ void VoxelSystem::collectStatsForTreesAndVBOs() { printLog("_voxelsDirty=%s _voxelsInWriteArrays=%ld minDirty=%ld maxDirty=%ld \n", (_voxelsDirty ? "yes" : "no"), _voxelsInWriteArrays, minDirty, maxDirty); - printLog("stats: total %ld, dirty %ld, colored %ld, shouldRender %ld, inVBO %ld, nodesInVBOOverExpectedMax %ld, duplicateVBOIndex %ld\n", - args.totalNodes, args.dirtyNodes, args.coloredNodes, args.shouldRenderNodes, + printLog("stats: total %ld, leaves %ld, dirty %ld, colored %ld, shouldRender %ld, inVBO %ld\n", + args.totalNodes, args.leafNodes, args.dirtyNodes, args.coloredNodes, args.shouldRenderNodes); + + printLog("inVBO %ld, nodesInVBOOverExpectedMax %ld, duplicateVBOIndex %ld\n", args.nodesInVBO, args.nodesInVBOOverExpectedMax, args.duplicateVBOIndex); glBufferIndex minInVBO = GLBUFFER_INDEX_UNKNOWN; diff --git a/libraries/voxels/src/VoxelNode.cpp b/libraries/voxels/src/VoxelNode.cpp index 19e6a12aa5..2e3194f5cb 100644 --- a/libraries/voxels/src/VoxelNode.cpp +++ b/libraries/voxels/src/VoxelNode.cpp @@ -40,6 +40,7 @@ void VoxelNode::init(unsigned char * octalCode) { for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { _children[i] = NULL; } + _childCount = 0; _glBufferIndex = GLBUFFER_INDEX_UNKNOWN; _isDirty = true; @@ -87,6 +88,8 @@ void VoxelNode::deleteChildAtIndex(int childIndex) { if (_children[childIndex]) { delete _children[childIndex]; _children[childIndex] = NULL; + _isDirty = true; + _childCount--; } } @@ -96,6 +99,7 @@ VoxelNode* VoxelNode::removeChildAtIndex(int childIndex) { if (_children[childIndex]) { _children[childIndex] = NULL; _isDirty = true; + _childCount--; } return returnedChild; } @@ -111,6 +115,7 @@ void VoxelNode::addChildAtIndex(int childIndex) { _children[childIndex]->setFalseColored(false); _isDirty = true; + _childCount++; } } @@ -215,6 +220,7 @@ bool VoxelNode::collapseIdenticalLeaves() { delete _children[i]; // delete all the child nodes _children[i]=NULL; // set it to NULL } + _childCount = 0; nodeColor collapsedColor; collapsedColor[0]=red; collapsedColor[1]=green; @@ -235,15 +241,6 @@ void VoxelNode::setRandomColor(int minimumBrightness) { setColor(newColor); } -bool VoxelNode::isLeaf() const { - for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { - if (_children[i]) { - return false; - } - } - return true; -} - void VoxelNode::printDebugDetails(const char* label) const { printLog("%s - Voxel at corner=(%f,%f,%f) size=%f octcode=", label, _box.getCorner().x, _box.getCorner().y, _box.getCorner().z, _box.getSize().x); diff --git a/libraries/voxels/src/VoxelNode.h b/libraries/voxels/src/VoxelNode.h index c07cb528e6..410f39e218 100644 --- a/libraries/voxels/src/VoxelNode.h +++ b/libraries/voxels/src/VoxelNode.h @@ -31,6 +31,7 @@ private: AABox _box; unsigned char* _octalCode; VoxelNode* _children[8]; + int _childCount; void calculateAABox(); @@ -60,7 +61,7 @@ public: bool isInView(const ViewFrustum& viewFrustum) const; ViewFrustum::location inFrustum(const ViewFrustum& viewFrustum) const; float distanceToCamera(const ViewFrustum& viewFrustum) const; - bool isLeaf() const; + bool isLeaf() const { return _childCount == 0; } void printDebugDetails(const char* label) const; bool isDirty() const { return _isDirty; }; void clearDirtyBit() { _isDirty = false; };