Showing the changes to interface/src/VoxelSystem.cpp (1 of 7 files). Show all
Unified · Split
| @@ -76,6 +76,7 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) · 75 unmodified lines | |||
| 76 | _tree->rootNode->setVoxelSystem(this); | 76 | _tree->rootNode->setVoxelSystem(this); |
| 77 | pthread_mutex_init(&_bufferWriteLock, NULL); | 77 | pthread_mutex_init(&_bufferWriteLock, NULL); |
| 78 | pthread_mutex_init(&_treeLock, NULL); | 78 | pthread_mutex_init(&_treeLock, NULL); |
| 79 | pthread_mutex_init(&_freeIndexLock, NULL); | ||
| 79 | 80 | ||
| 80 | VoxelNode::addDeleteHook(this); | 81 | VoxelNode::addDeleteHook(this); |
| 81 | VoxelNode::addUpdateHook(this); | 82 | VoxelNode::addUpdateHook(this); |
| @@ -109,15 +110,7 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) · 27 unmodified lines | |||
| 109 | 110 | ||
| 110 | void VoxelSystem::voxelDeleted(VoxelNode* node) { | 111 | void VoxelSystem::voxelDeleted(VoxelNode* node) { |
| 111 | if (node->isKnownBufferIndex() && (node->getVoxelSystem() == this)) { | 112 | if (node->isKnownBufferIndex() && (node->getVoxelSystem() == this)) { |
| 112 | forceRemoveNodeFromArraysAsPartialVBO(node); | 113 | forceRemoveNodeFromArrays(node); |
| 113 | |||
| 114 | /*** | ||
| 115 | if (!_useFastVoxelPipeline || _inSetupNewVoxelsForDrawing || _writeRenderFullVBO) { | ||
| 116 | freeBufferIndex(node->getBufferIndex()); | ||
| 117 | } else { | ||
| 118 | forceRemoveNodeFromArraysAsPartialVBO(node); | ||
| 119 | } | ||
| 120 | ***/ | ||
| 121 | } | 114 | } |
| 122 | } | 115 | } |
| 123 | 116 | ||
| @@ -181,8 +174,10 @@ glBufferIndex VoxelSystem::getNextBufferIndex() { · 57 unmodified lines | |||
| 181 | glBufferIndex output = GLBUFFER_INDEX_UNKNOWN; | 174 | glBufferIndex output = GLBUFFER_INDEX_UNKNOWN; |
| 182 | // if there's a free index, use it... | 175 | // if there's a free index, use it... |
| 183 | if (_freeIndexes.size() > 0) { | 176 | if (_freeIndexes.size() > 0) { |
| 177 | pthread_mutex_lock(&_freeIndexLock); | ||
| 184 | output = _freeIndexes.back(); | 178 | output = _freeIndexes.back(); |
| 185 | _freeIndexes.pop_back(); | 179 | _freeIndexes.pop_back(); |
| 180 | pthread_mutex_unlock(&_freeIndexLock); | ||
| 186 | } else { | 181 | } else { |
| 187 | output = _voxelsInWriteArrays; | 182 | output = _voxelsInWriteArrays; |
| 188 | _voxelsInWriteArrays++; | 183 | _voxelsInWriteArrays++; |
| @@ -194,14 +189,15 @@ glBufferIndex VoxelSystem::getNextBufferIndex() { · 5 unmodified lines | |||
| 194 | // will also "clean up" the index data for the buffer/vbo slot, so that if it's in the middle of the draw range, the triangles | 189 | // will also "clean up" the index data for the buffer/vbo slot, so that if it's in the middle of the draw range, the triangles |
| 195 | // will be "invisible" | 190 | // will be "invisible" |
| 196 | void VoxelSystem::freeBufferIndex(glBufferIndex index) { | 191 | void VoxelSystem::freeBufferIndex(glBufferIndex index) { |
| 197 | assert(_voxelsInWriteArrays > 0); | 192 | if (_voxelsInWriteArrays == 0) { |
| 193 | qDebug() << "freeBufferIndex() called when _voxelsInWriteArrays == 0!!!!\n"; | ||
| 194 | } | ||
| 198 | 195 | ||
| 199 | // if the "freed" index was our max index, then just drop the _voxelsInWriteArrays down one... | 196 | // if the "freed" index was our max index, then just drop the _voxelsInWriteArrays down one... |
| 200 | if (index == (_voxelsInWriteArrays - 1)) { | 197 | bool inList = false; |
| 201 | _voxelsInWriteArrays--; | 198 | |
| 202 | } else { | 199 | // make sure the index isn't already in the free list..., this is a debugging measure only done if you've enabled audits |
| 203 | bool inList = false; | 200 | if (Menu::getInstance()->isOptionChecked(MenuOption::AutomaticallyAuditTree)) { |
| 204 | // make sure the index isn't already in the free list... | ||
| 205 | for (long i = 0; i < _freeIndexes.size(); i++) { | 201 | for (long i = 0; i < _freeIndexes.size(); i++) { |
| 206 | if (_freeIndexes[i] == index) { | 202 | if (_freeIndexes[i] == index) { |
| 207 | printf("freeBufferIndex(glBufferIndex index)... index=%ld already in free list!\n", index); | 203 | printf("freeBufferIndex(glBufferIndex index)... index=%ld already in free list!\n", index); |
| @@ -209,25 +205,28 @@ void VoxelSystem::freeBufferIndex(glBufferIndex index) { · 1 unmodified line | |||
| 209 | break; | 205 | break; |
| 210 | } | 206 | } |
| 211 | } | 207 | } |
| 212 | 208 | } | |
| 213 | if (!inList) { | 209 | if (!inList) { |
| 214 | // make the index available for next node that needs to be drawn | 210 | // make the index available for next node that needs to be drawn |
| 215 | _freeIndexes.push_back(index); | 211 | pthread_mutex_lock(&_freeIndexLock); |
| 216 | 212 | _freeIndexes.push_back(index); | |
| 217 | // make the VBO slot "invisible" in case this slot is not used | 213 | pthread_mutex_unlock(&_freeIndexLock); |
| 218 | const glm::vec3 startVertex(FLT_MAX, FLT_MAX, FLT_MAX); | 214 | |
| 219 | const float voxelScale = 0; | 215 | // make the VBO slot "invisible" in case this slot is not used |
| 220 | const nodeColor BLACK = {0, 0, 0, 0}; | 216 | const glm::vec3 startVertex(FLT_MAX, FLT_MAX, FLT_MAX); |
| 221 | updateArraysDetails(index, startVertex, voxelScale, BLACK); | 217 | const float voxelScale = 0; |
| 222 | } | 218 | const nodeColor BLACK = {0, 0, 0, 0}; |
| 219 | updateArraysDetails(index, startVertex, voxelScale, BLACK); | ||
| 223 | } | 220 | } |
| 224 | } | 221 | } |
| 225 | 222 | ||
| 226 | // This will run through the list of _freeIndexes and reset their VBO array values to be "invisible". | 223 | // This will run through the list of _freeIndexes and reset their VBO array values to be "invisible". |
| 227 | void VoxelSystem::clearFreeBufferIndexes() { | 224 | void VoxelSystem::clearFreeBufferIndexes() { |
| 228 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "###### clearFreeBufferIndexes()"); | 225 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "###### clearFreeBufferIndexes()"); |
| 226 | pthread_mutex_lock(&_freeIndexLock); | ||
| 229 | _freeIndexes.clear(); | 227 | _freeIndexes.clear(); |
| 230 | _abandonedVBOSlots = 0; | 228 | _abandonedVBOSlots = 0; |
| 229 | pthread_mutex_unlock(&_freeIndexLock); | ||
| 231 | } | 230 | } |
| 232 | 231 | ||
| 233 | VoxelSystem::~VoxelSystem() { | 232 | VoxelSystem::~VoxelSystem() { |
| @@ -235,6 +234,7 @@ VoxelSystem::~VoxelSystem() { · 1 unmodified line | |||
| 235 | delete _tree; | 234 | delete _tree; |
| 236 | pthread_mutex_destroy(&_bufferWriteLock); | 235 | pthread_mutex_destroy(&_bufferWriteLock); |
| 237 | pthread_mutex_destroy(&_treeLock); | 236 | pthread_mutex_destroy(&_treeLock); |
| 237 | pthread_mutex_destroy(&_freeIndexLock); | ||
| 238 | 238 | ||
| 239 | VoxelNode::removeDeleteHook(this); | 239 | VoxelNode::removeDeleteHook(this); |
| 240 | VoxelNode::removeUpdateHook(this); | 240 | VoxelNode::removeUpdateHook(this); |
| @@ -612,10 +612,8 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 371 unmodified lines | |||
| 612 | 612 | ||
| 613 | 613 | ||
| 614 | if (!_useFastVoxelPipeline || _writeRenderFullVBO) { | 614 | if (!_useFastVoxelPipeline || _writeRenderFullVBO) { |
| 615 | //printf("parseData about to call setupNewVoxelsForDrawing();\n"); | ||
| 616 | setupNewVoxelsForDrawing(); | 615 | setupNewVoxelsForDrawing(); |
| 617 | } else { | 616 | } else { |
| 618 | printf("parseData about to call checkForCulling() and setupNewVoxelsForDrawingSingleNode(DONT_BAIL_EARLY)\n"); | ||
| 619 | checkForCulling(); | 617 | checkForCulling(); |
| 620 | setupNewVoxelsForDrawingSingleNode(DONT_BAIL_EARLY); | 618 | setupNewVoxelsForDrawingSingleNode(DONT_BAIL_EARLY); |
| 621 | } | 619 | } |
| @@ -659,7 +657,9 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 37 unmodified lines | |||
| 659 | if (_writeRenderFullVBO) { | 657 | if (_writeRenderFullVBO) { |
| 660 | printf("resetting _freeIndexes and _voxelsInWriteArrays\n"); | 658 | printf("resetting _freeIndexes and _voxelsInWriteArrays\n"); |
| 661 | _voxelsInWriteArrays = 0; // reset our VBO | 659 | _voxelsInWriteArrays = 0; // reset our VBO |
| 660 | pthread_mutex_lock(&_freeIndexLock); | ||
| 662 | _freeIndexes.clear(); // reset our free indexes | 661 | _freeIndexes.clear(); // reset our free indexes |
| 662 | pthread_mutex_unlock(&_freeIndexLock); | ||
| 663 | } | 663 | } |
| 664 | _voxelsUpdated = newTreeToArrays(_tree->rootNode); | 664 | _voxelsUpdated = newTreeToArrays(_tree->rootNode); |
| 665 | _tree->clearDirtyBit(); // after we pull the trees into the array, we can consider the tree clean | 665 | _tree->clearDirtyBit(); // after we pull the trees into the array, we can consider the tree clean |
| @@ -741,9 +741,15 @@ void VoxelSystem::checkForCulling() { · 75 unmodified lines | |||
| 741 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "checkForCulling()"); | 741 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "checkForCulling()"); |
| 742 | uint64_t start = usecTimestampNow(); | 742 | uint64_t start = usecTimestampNow(); |
| 743 | uint64_t sinceLastViewCulling = (start - _lastViewCulling) / 1000; | 743 | uint64_t sinceLastViewCulling = (start - _lastViewCulling) / 1000; |
| 744 | |||
| 745 | bool constantCulling = Menu::getInstance()->isOptionChecked(MenuOption::ConstantCulling); | ||
| 746 | |||
| 744 | // If the view frustum is no longer changing, but has changed, since last time, then remove nodes that are out of view | 747 | // If the view frustum is no longer changing, but has changed, since last time, then remove nodes that are out of view |
| 745 | if ((sinceLastViewCulling >= std::max((float) _lastViewCullingElapsed, VIEW_CULLING_RATE_IN_MILLISECONDS)) | 748 | if (constantCulling || ( |
| 746 | && !isViewChanging()) { | 749 | (sinceLastViewCulling >= std::max((float) _lastViewCullingElapsed, VIEW_CULLING_RATE_IN_MILLISECONDS)) |
| 750 | && !isViewChanging() | ||
| 751 | ) | ||
| 752 | ) { | ||
| 747 | 753 | ||
| 748 | _lastViewCulling = start; | 754 | _lastViewCulling = start; |
| 749 | 755 | ||
| @@ -764,7 +770,16 @@ void VoxelSystem::checkForCulling() { · 14 unmodified lines | |||
| 764 | 770 | ||
| 765 | uint64_t endViewCulling = usecTimestampNow(); | 771 | uint64_t endViewCulling = usecTimestampNow(); |
| 766 | _lastViewCullingElapsed = (endViewCulling - start) / 1000; | 772 | _lastViewCullingElapsed = (endViewCulling - start) / 1000; |
| 767 | } | 773 | } |
| 774 | |||
| 775 | uint64_t sinceLastAudit = (start - _lastAudit) / 1000; | ||
| 776 | |||
| 777 | if (Menu::getInstance()->isOptionChecked(MenuOption::AutomaticallyAuditTree)) { | ||
| 778 | if (sinceLastAudit >= std::max((float) _lastViewCullingElapsed, VIEW_CULLING_RATE_IN_MILLISECONDS)) { | ||
| 779 | _lastAudit = start; | ||
| 780 | collectStatsForTreesAndVBOs(); | ||
| 781 | } | ||
| 782 | } | ||
| 768 | } | 783 | } |
| 769 | 784 | ||
| 770 | void VoxelSystem::cleanupRemovedVoxels() { | 785 | void VoxelSystem::cleanupRemovedVoxels() { |
| @@ -905,12 +920,10 @@ int VoxelSystem::newTreeToArrays(VoxelNode* node) { · 134 unmodified lines | |||
| 905 | if (_writeRenderFullVBO) { | 920 | if (_writeRenderFullVBO) { |
| 906 | const bool DONT_REUSE_INDEX = false; | 921 | const bool DONT_REUSE_INDEX = false; |
| 907 | const bool FORCE_REDRAW = true; | 922 | const bool FORCE_REDRAW = true; |
| 908 | //printf("newTreeToArrays() about to call updateNodeInArrays(node, DONT_REUSE_INDEX, FORCE_REDRAW);\n"); | ||
| 909 | voxelsUpdated += updateNodeInArrays(node, DONT_REUSE_INDEX, FORCE_REDRAW); | 923 | voxelsUpdated += updateNodeInArrays(node, DONT_REUSE_INDEX, FORCE_REDRAW); |
| 910 | } else { | 924 | } else { |
| 911 | const bool REUSE_INDEX = true; | 925 | const bool REUSE_INDEX = true; |
| 912 | const bool DONT_FORCE_REDRAW = false; | 926 | const bool DONT_FORCE_REDRAW = false; |
| 913 | //printf("newTreeToArrays() about to call updateNodeInArrays(node, REUSE_INDEX, DONT_FORCE_REDRAW);\n"); | ||
| 914 | voxelsUpdated += updateNodeInArrays(node, REUSE_INDEX, DONT_FORCE_REDRAW); | 927 | voxelsUpdated += updateNodeInArrays(node, REUSE_INDEX, DONT_FORCE_REDRAW); |
| 915 | } | 928 | } |
| 916 | node->clearDirtyBit(); // clear the dirty bit, do this before we potentially delete things. | 929 | node->clearDirtyBit(); // clear the dirty bit, do this before we potentially delete things. |
| @@ -922,7 +935,7 @@ int VoxelSystem::newTreeToArrays(VoxelNode* node) { · 5 unmodified lines | |||
| 922 | // is being deleted, but it's state is such that it thinks it should render | 935 | // is being deleted, but it's state is such that it thinks it should render |
| 923 | // and therefore we can't use the normal render calculations. This method | 936 | // and therefore we can't use the normal render calculations. This method |
| 924 | // will forcibly remove it from the VBOs because we know better!!! | 937 | // will forcibly remove it from the VBOs because we know better!!! |
| 925 | int VoxelSystem::forceRemoveNodeFromArraysAsPartialVBO(VoxelNode* node) { | 938 | int VoxelSystem::forceRemoveNodeFromArrays(VoxelNode* node) { |
| 926 | 939 | ||
| 927 | if (!_initialized) { | 940 | if (!_initialized) { |
| 928 | return 0; | 941 | return 0; |
| @@ -932,8 +945,8 @@ int VoxelSystem::forceRemoveNodeFromArraysAsPartialVBO(VoxelNode* node) { · 3 unmodified lines | |||
| 932 | if (node->isKnownBufferIndex()) { | 945 | if (node->isKnownBufferIndex()) { |
| 933 | // If this node has not yet been written to the array, then add it to the end of the array. | 946 | // If this node has not yet been written to the array, then add it to the end of the array. |
| 934 | glBufferIndex nodeIndex = node->getBufferIndex(); | 947 | glBufferIndex nodeIndex = node->getBufferIndex(); |
| 935 | freeBufferIndex(nodeIndex); // NOTE: This is make the node invisible! | ||
| 936 | node->setBufferIndex(GLBUFFER_INDEX_UNKNOWN); | 948 | node->setBufferIndex(GLBUFFER_INDEX_UNKNOWN); |
| 949 | freeBufferIndex(nodeIndex); // NOTE: This is make the node invisible! | ||
| 937 | return 1; // updated! | 950 | return 1; // updated! |
| 938 | } | 951 | } |
| 939 | return 0; // not-updated | 952 | return 0; // not-updated |
| @@ -958,25 +971,15 @@ printf("updateNodeInArrays(VoxelNode* node=[%f, %f, %f] %f, bool reuseIndex=%s, · 18 unmodified lines | |||
| 958 | // If we've changed any attributes (our renderness, our color, etc), or we've been told to force a redraw | 971 | // If we've changed any attributes (our renderness, our color, etc), or we've been told to force a redraw |
| 959 | // then update the Arrays... | 972 | // then update the Arrays... |
| 960 | if (forceDraw || node->isDirty()) { | 973 | if (forceDraw || node->isDirty()) { |
| 961 | /* | ||
| 962 | printf("updateNodeInArrays(VoxelNode* node=[%f, %f, %f] %f, bool reuseIndex=%s, bool forceDraw=%s)\n", | ||
| 963 | node->getCorner().x,node->getCorner().y,node->getCorner().z, node->getScale(), | ||
| 964 | debug::valueOf(reuseIndex),debug::valueOf(forceDraw)); | ||
| 965 | */ | ||
| 966 | //printf("....(isDirty() [isDirty()=%s] or forceRedraw=%s_...\n",debug::valueOf(node->isDirty()),debug::valueOf(forceDraw)); | ||
| 967 | |||
| 968 | // If we're should render, use our legit location and scale, | 974 | // If we're should render, use our legit location and scale, |
| 969 | if (node->getShouldRender()) { | 975 | if (node->getShouldRender()) { |
| 970 | //printf("....shouldRender()...\n"); | ||
| 971 | glm::vec3 startVertex = node->getCorner(); | 976 | glm::vec3 startVertex = node->getCorner(); |
| 972 | float voxelScale = node->getScale(); | 977 | float voxelScale = node->getScale(); |
| 973 | 978 | ||
| 974 | glBufferIndex nodeIndex = GLBUFFER_INDEX_UNKNOWN; | 979 | glBufferIndex nodeIndex = GLBUFFER_INDEX_UNKNOWN; |
| 975 | if (reuseIndex && node->isKnownBufferIndex()) { | 980 | if (reuseIndex && node->isKnownBufferIndex()) { |
| 976 | //printf("....shouldRender() and reuseIndex && node->isKnownBufferIndex() reusing...\n"); | ||
| 977 | nodeIndex = node->getBufferIndex(); | 981 | nodeIndex = node->getBufferIndex(); |
| 978 | } else { | 982 | } else { |
| 979 | //printf("....shouldRender() and NOT(reuseIndex && node->isKnownBufferIndex()) getting new index...\n"); | ||
| 980 | nodeIndex = getNextBufferIndex(); | 983 | nodeIndex = getNextBufferIndex(); |
| 981 | node->setBufferIndex(nodeIndex); | 984 | node->setBufferIndex(nodeIndex); |
| 982 | node->setVoxelSystem(this); | 985 | node->setVoxelSystem(this); |
| @@ -985,16 +988,12 @@ printf("updateNodeInArrays(VoxelNode* node=[%f, %f, %f] %f, bool reuseIndex=%s, · 2 unmodified lines | |||
| 985 | updateArraysDetails(nodeIndex, startVertex, voxelScale, node->getColor()); | 988 | updateArraysDetails(nodeIndex, startVertex, voxelScale, node->getColor()); |
| 986 | return 1; // updated! | 989 | return 1; // updated! |
| 987 | } else { | 990 | } else { |
| 988 | //printf("....NOT shouldRender()...\n"); | ||
| 989 | // If we shouldn't render, but we did have a known index, then we will need to release our index | 991 | // If we shouldn't render, but we did have a known index, then we will need to release our index |
| 990 | if (reuseIndex && node->isKnownBufferIndex()) { | 992 | if (reuseIndex && node->isKnownBufferIndex()) { |
| 991 | //printf("....NOT shouldRender() and reuseIndex && node->isKnownBufferIndex() freeBufferIndex!...\n"); | 993 | forceRemoveNodeFromArrays(node); |
| 992 | freeBufferIndex(node->getBufferIndex()); // this will make the node invisible | ||
| 993 | return 1; // updated! | 994 | return 1; // updated! |
| 994 | } | 995 | } |
| 995 | } | 996 | } |
| 996 | } else { | ||
| 997 | //printf("....NOT (dirty [isDirty()=%s] or forceRedraw=%s_...\n",debug::valueOf(node->isDirty()),debug::valueOf(forceDraw)); | ||
| 998 | } | 997 | } |
| 999 | return 0; // not-updated | 998 | return 0; // not-updated |
| 1000 | } | 999 | } |
| @@ -1046,7 +1045,7 @@ void VoxelSystem::init() { · 45 unmodified lines | |||
| 1046 | _callsToTreesToArrays = 0; | 1045 | _callsToTreesToArrays = 0; |
| 1047 | _setupNewVoxelsForDrawingLastFinished = 0; | 1046 | _setupNewVoxelsForDrawingLastFinished = 0; |
| 1048 | _setupNewVoxelsForDrawingLastElapsed = 0; | 1047 | _setupNewVoxelsForDrawingLastElapsed = 0; |
| 1049 | _lastViewCullingElapsed = _lastViewCulling = 0; | 1048 | _lastViewCullingElapsed = _lastViewCulling = _lastAudit = 0; |
| 1050 | 1049 | ||
| 1051 | _voxelsDirty = false; | 1050 | _voxelsDirty = false; |
| 1052 | _voxelsInWriteArrays = 0; | 1051 | _voxelsInWriteArrays = 0; |
| @@ -1537,6 +1536,8 @@ public: · 484 unmodified lines | |||
| 1537 | unsigned long nodesInside; | 1536 | unsigned long nodesInside; |
| 1538 | unsigned long nodesIntersect; | 1537 | unsigned long nodesIntersect; |
| 1539 | unsigned long nodesOutside; | 1538 | unsigned long nodesOutside; |
| 1539 | VoxelNode* insideRoot; | ||
| 1540 | VoxelNode* outsideRoot; | ||
| 1540 | 1541 | ||
| 1541 | removeOutOfViewArgs(VoxelSystem* voxelSystem, bool widenViewFrustum = true) : | 1542 | removeOutOfViewArgs(VoxelSystem* voxelSystem, bool widenViewFrustum = true) : |
| 1542 | thisVoxelSystem(voxelSystem), | 1543 | thisVoxelSystem(voxelSystem), |
| @@ -1546,7 +1547,9 @@ public: · 3 unmodified lines | |||
| 1546 | nodesRemoved(0), | 1547 | nodesRemoved(0), |
| 1547 | nodesInside(0), | 1548 | nodesInside(0), |
| 1548 | nodesIntersect(0), | 1549 | nodesIntersect(0), |
| 1549 | nodesOutside(0) | 1550 | nodesOutside(0), |
| 1551 | insideRoot(NULL), | ||
| 1552 | outsideRoot(NULL) | ||
| 1550 | { | 1553 | { |
| 1551 | // Widen the FOV for trimming | 1554 | // Widen the FOV for trimming |
| 1552 | if (widenViewFrustum) { | 1555 | if (widenViewFrustum) { |
| @@ -1610,81 +1613,6 @@ bool VoxelSystem::removeOutOfViewOperation(VoxelNode* node, void* extraData) { · 57 unmodified lines | |||
| 1610 | return true; // keep going! | 1613 | return true; // keep going! |
| 1611 | } | 1614 | } |
| 1612 | 1615 | ||
| 1613 | // "hide" voxels in the VBOs that are still in the tree that but not in view. | ||
| 1614 | // We don't remove them from the tree, we don't delete them, we do remove them | ||
| 1615 | // from the VBOs and mark them as such in the tree. | ||
| 1616 | bool VoxelSystem::hideOutOfViewOperation(VoxelNode* node, void* extraData) { | ||
| 1617 | removeOutOfViewArgs* args = (removeOutOfViewArgs*)extraData; | ||
| 1618 | |||
| 1619 | // If our node was previously added to the don't recurse bag, then return false to | ||
| 1620 | // stop the further recursion. This means that the whole node and it's children are | ||
| 1621 | // known to be in view, so don't recurse them | ||
| 1622 | if (args->dontRecurseBag.contains(node)) { | ||
| 1623 | args->dontRecurseBag.remove(node); | ||
| 1624 | return false; // stop recursion | ||
| 1625 | } | ||
| 1626 | |||
| 1627 | VoxelSystem* thisVoxelSystem = args->thisVoxelSystem; | ||
| 1628 | args->nodesScanned++; | ||
| 1629 | // Need to operate on our child nodes, so we can remove them | ||
| 1630 | for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { | ||
| 1631 | VoxelNode* childNode = node->getChildAtIndex(i); | ||
| 1632 | if (childNode) { | ||
| 1633 | ViewFrustum::location inFrustum = childNode->inFrustum(args->thisViewFrustum); | ||
| 1634 | switch (inFrustum) { | ||
| 1635 | case ViewFrustum::OUTSIDE: { | ||
| 1636 | args->nodesOutside++; | ||
| 1637 | if (childNode->isKnownBufferIndex()) { | ||
| 1638 | args->nodesRemoved++; | ||
| 1639 | thisVoxelSystem->forceRemoveNodeFromArraysAsPartialVBO(childNode); | ||
| 1640 | thisVoxelSystem->_voxelsUpdated++; | ||
| 1641 | thisVoxelSystem->setupNewVoxelsForDrawingSingleNode(); | ||
| 1642 | } | ||
| 1643 | // how to handle recursion???? we probably want to continue | ||
| 1644 | } break; | ||
| 1645 | case ViewFrustum::INSIDE: { | ||
| 1646 | |||
| 1647 | // if the child node is fully INSIDE the view, then there's no need to recurse it | ||
| 1648 | // because we know all it's children will also be in the view, so we want to | ||
| 1649 | // tell the caller to NOT recurse this child | ||
| 1650 | args->nodesInside++; | ||
| 1651 | |||
| 1652 | if (childNode->getShouldRender() && !childNode->isKnownBufferIndex()) { | ||
| 1653 | /* | ||
| 1654 | printf("in view, isKnownIndex()=%s isDirty()=%s shouldRender()=%s\n", | ||
| 1655 | debug::valueOf(childNode->isKnownBufferIndex()), | ||
| 1656 | debug::valueOf(childNode->isDirty()), | ||
| 1657 | debug::valueOf(childNode->getShouldRender())); | ||
| 1658 | */ | ||
| 1659 | childNode->setDirtyBit(); // will this make it draw? | ||
| 1660 | } | ||
| 1661 | //args->dontRecurseBag.insert(childNode); | ||
| 1662 | } break; | ||
| 1663 | case ViewFrustum::INTERSECT: { | ||
| 1664 | // if the child node INTERSECTs the view, then we don't want to remove it because | ||
| 1665 | // it is at least partially in view. But we DO want to recurse the children because | ||
| 1666 | // some of them may not be in view... nothing specifically to do, just keep iterating | ||
| 1667 | // the children | ||
| 1668 | args->nodesIntersect++; | ||
| 1669 | |||
| 1670 | if (childNode->getShouldRender() && !childNode->isKnownBufferIndex()) { | ||
| 1671 | /* | ||
| 1672 | printf("intersect view, isKnownIndex()=%s isDirty()=%s shouldRender()=%s\n", | ||
| 1673 | debug::valueOf(childNode->isKnownBufferIndex()), | ||
| 1674 | debug::valueOf(childNode->isDirty()), | ||
| 1675 | debug::valueOf(childNode->getShouldRender())); | ||
| 1676 | */ | ||
| 1677 | childNode->setDirtyBit(); // will this make it draw? | ||
| 1678 | } | ||
| 1679 | |||
| 1680 | } break; | ||
| 1681 | } | ||
| 1682 | } | ||
| 1683 | } | ||
| 1684 | return true; // keep going! | ||
| 1685 | } | ||
| 1686 | |||
| 1687 | |||
| 1688 | bool VoxelSystem::isViewChanging() { | 1616 | bool VoxelSystem::isViewChanging() { |
| 1689 | bool result = false; // assume the best | 1617 | bool result = false; // assume the best |
| 1690 | 1618 | ||
| @@ -1729,9 +1657,41 @@ void VoxelSystem::removeOutOfView() { · 38 unmodified lines | |||
| 1729 | } | 1657 | } |
| 1730 | } | 1658 | } |
| 1731 | 1659 | ||
| 1660 | // combines the removeOutOfView args into a single class | ||
| 1661 | class hideOutOfViewArgs { | ||
| 1662 | public: | ||
| 1663 | VoxelSystem* thisVoxelSystem; | ||
| 1664 | VoxelTree* tree; | ||
| 1665 | ViewFrustum thisViewFrustum; | ||
| 1666 | unsigned long nodesScanned; | ||
| 1667 | unsigned long nodesRemoved; | ||
| 1668 | unsigned long nodesInside; | ||
| 1669 | unsigned long nodesIntersect; | ||
| 1670 | unsigned long nodesOutside; | ||
| 1671 | |||
| 1672 | hideOutOfViewArgs(VoxelSystem* voxelSystem, VoxelTree* tree, bool widenViewFrustum = true) : | ||
| 1673 | thisVoxelSystem(voxelSystem), | ||
| 1674 | tree(tree), | ||
| 1675 | thisViewFrustum(*voxelSystem->getViewFrustum()), | ||
| 1676 | nodesScanned(0), | ||
| 1677 | nodesRemoved(0), | ||
| 1678 | nodesInside(0), | ||
| 1679 | nodesIntersect(0), | ||
| 1680 | nodesOutside(0) | ||
| 1681 | { | ||
| 1682 | // Widen the FOV for trimming | ||
| 1683 | if (widenViewFrustum) { | ||
| 1684 | float originalFOV = thisViewFrustum.getFieldOfView(); | ||
| 1685 | float wideFOV = originalFOV + VIEW_FRUSTUM_FOV_OVERSEND; | ||
| 1686 | thisViewFrustum.setFieldOfView(wideFOV); | ||
| 1687 | thisViewFrustum.calculate(); | ||
| 1688 | } | ||
| 1689 | } | ||
| 1690 | }; | ||
| 1691 | |||
| 1732 | void VoxelSystem::hideOutOfView() { | 1692 | void VoxelSystem::hideOutOfView() { |
| 1733 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "hideOutOfView()",true); | 1693 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "hideOutOfView()"); |
| 1734 | removeOutOfViewArgs args(this, true); // widen to match server! | 1694 | hideOutOfViewArgs args(this, this->_tree, true); // widen to match server! |
| 1735 | _tree->recurseTreeWithOperation(hideOutOfViewOperation,(void*)&args); | 1695 | _tree->recurseTreeWithOperation(hideOutOfViewOperation,(void*)&args); |
| 1736 | 1696 | ||
| 1737 | if (args.nodesRemoved) { | 1697 | if (args.nodesRemoved) { |
| @@ -1747,8 +1707,86 @@ void VoxelSystem::hideOutOfView() { · 9 unmodified lines | |||
| 1747 | args.nodesIntersect, args.nodesOutside | 1707 | args.nodesIntersect, args.nodesOutside |
| 1748 | ); | 1708 | ); |
| 1749 | } | 1709 | } |
| 1710 | } | ||
| 1711 | |||
| 1712 | bool VoxelSystem::hideAllSubTreeOperation(VoxelNode* node, void* extraData) { | ||
| 1713 | hideOutOfViewArgs* args = (hideOutOfViewArgs*)extraData; | ||
| 1714 | |||
| 1715 | args->nodesOutside++; | ||
| 1716 | if (node->isKnownBufferIndex()) { | ||
| 1717 | args->nodesRemoved++; | ||
| 1718 | VoxelSystem* thisVoxelSystem = args->thisVoxelSystem; | ||
| 1719 | thisVoxelSystem->forceRemoveNodeFromArrays(node); | ||
| 1720 | thisVoxelSystem->_voxelsUpdated++; | ||
| 1721 | thisVoxelSystem->setupNewVoxelsForDrawingSingleNode(); | ||
| 1722 | } | ||
| 1750 | 1723 | ||
| 1751 | collectStatsForTreesAndVBOs(); | 1724 | return true; |
| 1725 | } | ||
| 1726 | |||
| 1727 | bool VoxelSystem::showAllSubTreeOperation(VoxelNode* node, void* extraData) { | ||
| 1728 | hideOutOfViewArgs* args = (hideOutOfViewArgs*)extraData; | ||
| 1729 | |||
| 1730 | args->nodesInside++; | ||
| 1731 | |||
| 1732 | if (node->getShouldRender() && !node->isKnownBufferIndex()) { | ||
| 1733 | node->setDirtyBit(); // will this make it draw? | ||
| 1734 | } | ||
| 1735 | |||
| 1736 | return true; | ||
| 1737 | } | ||
| 1738 | |||
| 1739 | |||
| 1740 | |||
| 1741 | // "hide" voxels in the VBOs that are still in the tree that but not in view. | ||
| 1742 | // We don't remove them from the tree, we don't delete them, we do remove them | ||
| 1743 | // from the VBOs and mark them as such in the tree. | ||
| 1744 | bool VoxelSystem::hideOutOfViewOperation(VoxelNode* node, void* extraData) { | ||
| 1745 | hideOutOfViewArgs* args = (hideOutOfViewArgs*)extraData; | ||
| 1746 | |||
| 1747 | // If we're still recursing the tree using this operator, then we don't know if we're inside or outside... | ||
| 1748 | // so before we move forward we need to determine our frustum location | ||
| 1749 | ViewFrustum::location inFrustum = node->inFrustum(args->thisViewFrustum); | ||
| 1750 | |||
| 1751 | // ok, now do some processing for this node... | ||
| 1752 | switch (inFrustum) { | ||
| 1753 | case ViewFrustum::OUTSIDE: { | ||
| 1754 | // if this node is fully OUTSIDE the view, then we know that ALL of it's children are also fully OUTSIDE | ||
| 1755 | // so we can recurse the children and simply mark them as hidden | ||
| 1756 | args->tree->recurseNodeWithOperation(node, hideAllSubTreeOperation, args ); | ||
| 1757 | |||
| 1758 | return false; | ||
| 1759 | |||
| 1760 | } break; | ||
| 1761 | case ViewFrustum::INSIDE: { | ||
| 1762 | // if this node is fully INSIDE the view, then we know that ALL of it's children are also fully INSIDE | ||
| 1763 | // so we can recurse the children and simply mark them as visible (as appropriate based on LOD) | ||
| 1764 | args->tree->recurseNodeWithOperation(node, showAllSubTreeOperation, args ); | ||
| 1765 | |||
| 1766 | return false; | ||
| 1767 | } break; | ||
| 1768 | case ViewFrustum::INTERSECT: { | ||
| 1769 | args->nodesScanned++; | ||
| 1770 | args->nodesIntersect++; | ||
| 1771 | |||
| 1772 | // if the child node INTERSECTs the view, then we want to check to see if it thinks it should render | ||
| 1773 | // if it should render but is missing it's VBO index, then we want to flip it on, and we can stop recursing from | ||
| 1774 | // here because we know will block any children anyway | ||
| 1775 | if (node->getShouldRender() && !node->isKnownBufferIndex()) { | ||
| 1776 | node->setDirtyBit(); // will this make it draw? | ||
| 1777 | return false; | ||
| 1778 | } | ||
| 1779 | |||
| 1780 | // If it INTERSECTS but shouldn't be displayed, then it's probably a parent and it is at least partially in view. | ||
| 1781 | // So we DO want to recurse the children because some of them may not be in view... nothing specifically to do, | ||
| 1782 | // just keep iterating the children | ||
| 1783 | return true; | ||
| 1784 | |||
| 1785 | } break; | ||
| 1786 | } // switch | ||
| 1787 | |||
| 1788 | |||
| 1789 | return true; // keep going! | ||
| 1752 | } | 1790 | } |
| 1753 | 1791 | ||
| 1754 | 1792 | ||