History

optimized performance of VoxelNode::isLeaf()

ZappoMan committed 13 years ago

Commit ef20b3e1 parent b9a023a3 files · +28 −18Browse files

Showing the changes to interface/src/VoxelSystem.cpp (1 of 3 files). Show all

Unified · Split

interface/src/VoxelSystem.cpp+20−8
@@ -292,6 +292,7 @@ int VoxelSystem::newTreeToArrays(VoxelNode* node) { · 291 unmodified lines
292292 assert(_viewFrustum); // you must set up _viewFrustum before calling this
293293 int voxelsUpdated = 0;
294294 bool shouldRender = false; // assume we don't need to render it
295+ bool isLeaf = node->isLeaf();
295296 // if it's colored, we might need to render it!
296297 if (node->isColored()) {
297298 float distanceToNode = node->distanceToCamera(*_viewFrustum);
@@ -299,13 +300,15 @@ int VoxelSystem::newTreeToArrays(VoxelNode* node) { · 1 unmodified line
299300 float childBoundary = boundaryDistanceForRenderLevel(node->getLevel() + 1);
300301 bool inBoundary = (distanceToNode <= boundary);
301302 bool inChildBoundary = (distanceToNode <= childBoundary);
302− shouldRender = (node->isLeaf() && inChildBoundary) || (inBoundary && !inChildBoundary);
303+ shouldRender = (isLeaf && inChildBoundary) || (inBoundary && !inChildBoundary);
303304 }
304305 node->setShouldRender(shouldRender && !node->isStagedForDeletion());
305306 // let children figure out their renderness
306− for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
307− if (node->getChildAtIndex(i)) {
308− voxelsUpdated += newTreeToArrays(node->getChildAtIndex(i));
307+ if (!isLeaf) {
308+ for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
309+ if (node->getChildAtIndex(i)) {
310+ voxelsUpdated += newTreeToArrays(node->getChildAtIndex(i));
311+ }
309312 }
310313 }
311314 if (_renderFullVBO) {
@@ -886,7 +889,8 @@ public: · 574 unmodified lines
886889 coloredNodes(0),
887890 nodesInVBO(0),
888891 nodesInVBOOverExpectedMax(0),
889− duplicateVBOIndex(0)
892+ duplicateVBOIndex(0),
893+ leafNodes(0)
890894 {
891895 memset(hasIndexFound, false, MAX_VOXELS_PER_SYSTEM * sizeof(bool));
892896 };
@@ -898,9 +902,10 @@ public: · 5 unmodified lines
898902 unsigned long nodesInVBO;
899903 unsigned long nodesInVBOOverExpectedMax;
900904 unsigned long duplicateVBOIndex;
905+ unsigned long leafNodes;
906+
901907 unsigned long expectedMax;
902908
903− bool colorThis;
904909 bool hasIndexFound[MAX_VOXELS_PER_SYSTEM];
905910 };
906911
@@ -908,6 +913,10 @@ bool VoxelSystem::collectStatsForTreesAndVBOsOperation(VoxelNode* node, void* ex · 1 unmodified line
908913 collectStatsForTreesAndVBOsArgs* args = (collectStatsForTreesAndVBOsArgs*)extraData;
909914 args->totalNodes++;
910915
916+ if (node->isLeaf()) {
917+ args->leafNodes++;
918+ }
919+
911920 if (node->isColored()) {
912921 args->coloredNodes++;
913922 }
@@ -939,6 +948,7 @@ bool VoxelSystem::collectStatsForTreesAndVBOsOperation(VoxelNode* node, void* ex · 25 unmodified lines
939948 }
940949
941950 void VoxelSystem::collectStatsForTreesAndVBOs() {
951+ PerformanceWarning warn(true, "collectStatsForTreesAndVBOs()", true);
942952
943953 glBufferIndex minDirty = GLBUFFER_INDEX_UNKNOWN;
944954 glBufferIndex maxDirty = 0;
@@ -957,8 +967,10 @@ void VoxelSystem::collectStatsForTreesAndVBOs() { · 12 unmodified lines
957967 printLog("_voxelsDirty=%s _voxelsInWriteArrays=%ld minDirty=%ld maxDirty=%ld \n", (_voxelsDirty ? "yes" : "no"),
958968 _voxelsInWriteArrays, minDirty, maxDirty);
959969
960− printLog("stats: total %ld, dirty %ld, colored %ld, shouldRender %ld, inVBO %ld, nodesInVBOOverExpectedMax %ld, duplicateVBOIndex %ld\n",
961− args.totalNodes, args.dirtyNodes, args.coloredNodes, args.shouldRenderNodes,
970+ printLog("stats: total %ld, leaves %ld, dirty %ld, colored %ld, shouldRender %ld, inVBO %ld\n",
971+ args.totalNodes, args.leafNodes, args.dirtyNodes, args.coloredNodes, args.shouldRenderNodes);
972+
973+ printLog("inVBO %ld, nodesInVBOOverExpectedMax %ld, duplicateVBOIndex %ld\n",
962974 args.nodesInVBO, args.nodesInVBOOverExpectedMax, args.duplicateVBOIndex);
963975
964976 glBufferIndex minInVBO = GLBUFFER_INDEX_UNKNOWN;