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 | 76 | _tree->rootNode->setVoxelSystem(this); |
| 77 | 77 | pthread_mutex_init(&_bufferWriteLock, NULL); |
| 78 | 78 | pthread_mutex_init(&_treeLock, NULL); |
| 79 | + pthread_mutex_init(&_freeIndexLock, NULL); | |
| 79 | 80 | |
| 80 | 81 | VoxelNode::addDeleteHook(this); |
| 81 | 82 | VoxelNode::addUpdateHook(this); |
| @@ -109,15 +110,7 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) · 27 unmodified lines | ||
| 109 | 110 | |
| 110 | 111 | void VoxelSystem::voxelDeleted(VoxelNode* node) { |
| 111 | 112 | if (node->isKnownBufferIndex() && (node->getVoxelSystem() == this)) { |
| 112 | − forceRemoveNodeFromArraysAsPartialVBO(node); | |
| 113 | − | |
| 114 | − /*** | |
| 115 | − if (!_useFastVoxelPipeline || _inSetupNewVoxelsForDrawing || _writeRenderFullVBO) { | |
| 116 | − freeBufferIndex(node->getBufferIndex()); | |
| 117 | − } else { | |
| 118 | − forceRemoveNodeFromArraysAsPartialVBO(node); | |
| 119 | − } | |
| 120 | − ***/ | |
| 113 | + forceRemoveNodeFromArrays(node); | |
| 121 | 114 | } |
| 122 | 115 | } |
| 123 | 116 | |
| @@ -181,8 +174,10 @@ glBufferIndex VoxelSystem::getNextBufferIndex() { · 57 unmodified lines | ||
| 181 | 174 | glBufferIndex output = GLBUFFER_INDEX_UNKNOWN; |
| 182 | 175 | // if there's a free index, use it... |
| 183 | 176 | if (_freeIndexes.size() > 0) { |
| 177 | + pthread_mutex_lock(&_freeIndexLock); | |
| 184 | 178 | output = _freeIndexes.back(); |
| 185 | 179 | _freeIndexes.pop_back(); |
| 180 | + pthread_mutex_unlock(&_freeIndexLock); | |
| 186 | 181 | } else { |
| 187 | 182 | output = _voxelsInWriteArrays; |
| 188 | 183 | _voxelsInWriteArrays++; |
| @@ -194,14 +189,15 @@ glBufferIndex VoxelSystem::getNextBufferIndex() { · 5 unmodified lines | ||
| 194 | 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 | 190 | // will be "invisible" |
| 196 | 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 | 196 | // if the "freed" index was our max index, then just drop the _voxelsInWriteArrays down one... |
| 200 | − if (index == (_voxelsInWriteArrays - 1)) { | |
| 201 | − _voxelsInWriteArrays--; | |
| 202 | − } else { | |
| 203 | − bool inList = false; | |
| 204 | − // make sure the index isn't already in the free list... | |
| 197 | + bool inList = false; | |
| 198 | + | |
| 199 | + // make sure the index isn't already in the free list..., this is a debugging measure only done if you've enabled audits | |
| 200 | + if (Menu::getInstance()->isOptionChecked(MenuOption::AutomaticallyAuditTree)) { | |
| 205 | 201 | for (long i = 0; i < _freeIndexes.size(); i++) { |
| 206 | 202 | if (_freeIndexes[i] == index) { |
| 207 | 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 | 205 | break; |
| 210 | 206 | } |
| 211 | 207 | } |
| 212 | − | |
| 213 | − if (!inList) { | |
| 214 | − // make the index available for next node that needs to be drawn | |
| 215 | − _freeIndexes.push_back(index); | |
| 216 | − | |
| 217 | − // make the VBO slot "invisible" in case this slot is not used | |
| 218 | − const glm::vec3 startVertex(FLT_MAX, FLT_MAX, FLT_MAX); | |
| 219 | − const float voxelScale = 0; | |
| 220 | − const nodeColor BLACK = {0, 0, 0, 0}; | |
| 221 | − updateArraysDetails(index, startVertex, voxelScale, BLACK); | |
| 222 | − } | |
| 208 | + } | |
| 209 | + if (!inList) { | |
| 210 | + // make the index available for next node that needs to be drawn | |
| 211 | + pthread_mutex_lock(&_freeIndexLock); | |
| 212 | + _freeIndexes.push_back(index); | |
| 213 | + pthread_mutex_unlock(&_freeIndexLock); | |
| 214 | + | |
| 215 | + // make the VBO slot "invisible" in case this slot is not used | |
| 216 | + const glm::vec3 startVertex(FLT_MAX, FLT_MAX, FLT_MAX); | |
| 217 | + const float voxelScale = 0; | |
| 218 | + const nodeColor BLACK = {0, 0, 0, 0}; | |
| 219 | + updateArraysDetails(index, startVertex, voxelScale, BLACK); | |
| 223 | 220 | } |
| 224 | 221 | } |
| 225 | 222 | |
| 226 | 223 | // This will run through the list of _freeIndexes and reset their VBO array values to be "invisible". |
| 227 | 224 | void VoxelSystem::clearFreeBufferIndexes() { |
| 228 | 225 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "###### clearFreeBufferIndexes()"); |
| 226 | + pthread_mutex_lock(&_freeIndexLock); | |
| 229 | 227 | _freeIndexes.clear(); |
| 230 | 228 | _abandonedVBOSlots = 0; |
| 229 | + pthread_mutex_unlock(&_freeIndexLock); | |
| 231 | 230 | } |
| 232 | 231 | |
| 233 | 232 | VoxelSystem::~VoxelSystem() { |
| @@ -235,6 +234,7 @@ VoxelSystem::~VoxelSystem() { · 1 unmodified line | ||
| 235 | 234 | delete _tree; |
| 236 | 235 | pthread_mutex_destroy(&_bufferWriteLock); |
| 237 | 236 | pthread_mutex_destroy(&_treeLock); |
| 237 | + pthread_mutex_destroy(&_freeIndexLock); | |
| 238 | 238 | |
| 239 | 239 | VoxelNode::removeDeleteHook(this); |
| 240 | 240 | VoxelNode::removeUpdateHook(this); |
| @@ -612,10 +612,8 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 371 unmodified lines | ||
| 612 | 612 | |
| 613 | 613 | |
| 614 | 614 | if (!_useFastVoxelPipeline || _writeRenderFullVBO) { |
| 615 | −//printf("parseData about to call setupNewVoxelsForDrawing();\n"); | |
| 616 | 615 | setupNewVoxelsForDrawing(); |
| 617 | 616 | } else { |
| 618 | −printf("parseData about to call checkForCulling() and setupNewVoxelsForDrawingSingleNode(DONT_BAIL_EARLY)\n"); | |
| 619 | 617 | checkForCulling(); |
| 620 | 618 | setupNewVoxelsForDrawingSingleNode(DONT_BAIL_EARLY); |
| 621 | 619 | } |
| @@ -659,7 +657,9 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 37 unmodified lines | ||
| 659 | 657 | if (_writeRenderFullVBO) { |
| 660 | 658 | printf("resetting _freeIndexes and _voxelsInWriteArrays\n"); |
| 661 | 659 | _voxelsInWriteArrays = 0; // reset our VBO |
| 660 | + pthread_mutex_lock(&_freeIndexLock); | |
| 662 | 661 | _freeIndexes.clear(); // reset our free indexes |
| 662 | + pthread_mutex_unlock(&_freeIndexLock); | |
| 663 | 663 | } |
| 664 | 664 | _voxelsUpdated = newTreeToArrays(_tree->rootNode); |
| 665 | 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 | 741 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "checkForCulling()"); |
| 742 | 742 | uint64_t start = usecTimestampNow(); |
| 743 | 743 | uint64_t sinceLastViewCulling = (start - _lastViewCulling) / 1000; |
| 744 | + | |
| 745 | + bool constantCulling = Menu::getInstance()->isOptionChecked(MenuOption::ConstantCulling); | |
| 746 | + | |
| 744 | 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)) | |
| 746 | − && !isViewChanging()) { | |
| 748 | + if (constantCulling || ( | |
| 749 | + (sinceLastViewCulling >= std::max((float) _lastViewCullingElapsed, VIEW_CULLING_RATE_IN_MILLISECONDS)) | |
| 750 | + && !isViewChanging() | |
| 751 | + ) | |
| 752 | + ) { | |
| 747 | 753 | |
| 748 | 754 | _lastViewCulling = start; |
| 749 | 755 | |
| @@ -764,7 +770,16 @@ void VoxelSystem::checkForCulling() { · 14 unmodified lines | ||
| 764 | 770 | |
| 765 | 771 | uint64_t endViewCulling = usecTimestampNow(); |
| 766 | 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 | 785 | void VoxelSystem::cleanupRemovedVoxels() { |
| @@ -905,12 +920,10 @@ int VoxelSystem::newTreeToArrays(VoxelNode* node) { · 134 unmodified lines | ||
| 905 | 920 | if (_writeRenderFullVBO) { |
| 906 | 921 | const bool DONT_REUSE_INDEX = false; |
| 907 | 922 | const bool FORCE_REDRAW = true; |
| 908 | −//printf("newTreeToArrays() about to call updateNodeInArrays(node, DONT_REUSE_INDEX, FORCE_REDRAW);\n"); | |
| 909 | 923 | voxelsUpdated += updateNodeInArrays(node, DONT_REUSE_INDEX, FORCE_REDRAW); |
| 910 | 924 | } else { |
| 911 | 925 | const bool REUSE_INDEX = true; |
| 912 | 926 | const bool DONT_FORCE_REDRAW = false; |
| 913 | −//printf("newTreeToArrays() about to call updateNodeInArrays(node, REUSE_INDEX, DONT_FORCE_REDRAW);\n"); | |
| 914 | 927 | voxelsUpdated += updateNodeInArrays(node, REUSE_INDEX, DONT_FORCE_REDRAW); |
| 915 | 928 | } |
| 916 | 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 | 935 | // is being deleted, but it's state is such that it thinks it should render |
| 923 | 936 | // and therefore we can't use the normal render calculations. This method |
| 924 | 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 | 940 | if (!_initialized) { |
| 928 | 941 | return 0; |
| @@ -932,8 +945,8 @@ int VoxelSystem::forceRemoveNodeFromArraysAsPartialVBO(VoxelNode* node) { · 3 unmodified lines | ||
| 932 | 945 | if (node->isKnownBufferIndex()) { |
| 933 | 946 | // If this node has not yet been written to the array, then add it to the end of the array. |
| 934 | 947 | glBufferIndex nodeIndex = node->getBufferIndex(); |
| 935 | − freeBufferIndex(nodeIndex); // NOTE: This is make the node invisible! | |
| 936 | 948 | node->setBufferIndex(GLBUFFER_INDEX_UNKNOWN); |
| 949 | + freeBufferIndex(nodeIndex); // NOTE: This is make the node invisible! | |
| 937 | 950 | return 1; // updated! |
| 938 | 951 | } |
| 939 | 952 | return 0; // not-updated |
| @@ -958,25 +971,15 @@ printf("updateNodeInArrays(VoxelNode* node=[%f, %f, %f] %f, bool reuseIndex=%s, · 18 unmodified lines | ||
| 958 | 971 | // If we've changed any attributes (our renderness, our color, etc), or we've been told to force a redraw |
| 959 | 972 | // then update the Arrays... |
| 960 | 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 | 974 | // If we're should render, use our legit location and scale, |
| 969 | 975 | if (node->getShouldRender()) { |
| 970 | − //printf("....shouldRender()...\n"); | |
| 971 | 976 | glm::vec3 startVertex = node->getCorner(); |
| 972 | 977 | float voxelScale = node->getScale(); |
| 973 | 978 | |
| 974 | 979 | glBufferIndex nodeIndex = GLBUFFER_INDEX_UNKNOWN; |
| 975 | 980 | if (reuseIndex && node->isKnownBufferIndex()) { |
| 976 | − //printf("....shouldRender() and reuseIndex && node->isKnownBufferIndex() reusing...\n"); | |
| 977 | 981 | nodeIndex = node->getBufferIndex(); |
| 978 | 982 | } else { |
| 979 | − //printf("....shouldRender() and NOT(reuseIndex && node->isKnownBufferIndex()) getting new index...\n"); | |
| 980 | 983 | nodeIndex = getNextBufferIndex(); |
| 981 | 984 | node->setBufferIndex(nodeIndex); |
| 982 | 985 | node->setVoxelSystem(this); |
| @@ -985,16 +988,12 @@ printf("updateNodeInArrays(VoxelNode* node=[%f, %f, %f] %f, bool reuseIndex=%s, · 2 unmodified lines | ||
| 985 | 988 | updateArraysDetails(nodeIndex, startVertex, voxelScale, node->getColor()); |
| 986 | 989 | return 1; // updated! |
| 987 | 990 | } else { |
| 988 | − //printf("....NOT shouldRender()...\n"); | |
| 989 | 991 | // If we shouldn't render, but we did have a known index, then we will need to release our index |
| 990 | 992 | if (reuseIndex && node->isKnownBufferIndex()) { |
| 991 | − //printf("....NOT shouldRender() and reuseIndex && node->isKnownBufferIndex() freeBufferIndex!...\n"); | |
| 992 | − freeBufferIndex(node->getBufferIndex()); // this will make the node invisible | |
| 993 | + forceRemoveNodeFromArrays(node); | |
| 993 | 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 | 998 | return 0; // not-updated |
| 1000 | 999 | } |
| @@ -1046,7 +1045,7 @@ void VoxelSystem::init() { · 45 unmodified lines | ||
| 1046 | 1045 | _callsToTreesToArrays = 0; |
| 1047 | 1046 | _setupNewVoxelsForDrawingLastFinished = 0; |
| 1048 | 1047 | _setupNewVoxelsForDrawingLastElapsed = 0; |
| 1049 | − _lastViewCullingElapsed = _lastViewCulling = 0; | |
| 1048 | + _lastViewCullingElapsed = _lastViewCulling = _lastAudit = 0; | |
| 1050 | 1049 | |
| 1051 | 1050 | _voxelsDirty = false; |
| 1052 | 1051 | _voxelsInWriteArrays = 0; |
| @@ -1537,6 +1536,8 @@ public: · 484 unmodified lines | ||
| 1537 | 1536 | unsigned long nodesInside; |
| 1538 | 1537 | unsigned long nodesIntersect; |
| 1539 | 1538 | unsigned long nodesOutside; |
| 1539 | + VoxelNode* insideRoot; | |
| 1540 | + VoxelNode* outsideRoot; | |
| 1540 | 1541 | |
| 1541 | 1542 | removeOutOfViewArgs(VoxelSystem* voxelSystem, bool widenViewFrustum = true) : |
| 1542 | 1543 | thisVoxelSystem(voxelSystem), |
| @@ -1546,7 +1547,9 @@ public: · 3 unmodified lines | ||
| 1546 | 1547 | nodesRemoved(0), |
| 1547 | 1548 | nodesInside(0), |
| 1548 | 1549 | nodesIntersect(0), |
| 1549 | − nodesOutside(0) | |
| 1550 | + nodesOutside(0), | |
| 1551 | + insideRoot(NULL), | |
| 1552 | + outsideRoot(NULL) | |
| 1550 | 1553 | { |
| 1551 | 1554 | // Widen the FOV for trimming |
| 1552 | 1555 | if (widenViewFrustum) { |
| @@ -1610,81 +1613,6 @@ bool VoxelSystem::removeOutOfViewOperation(VoxelNode* node, void* extraData) { · 57 unmodified lines | ||
| 1610 | 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 | 1616 | bool VoxelSystem::isViewChanging() { |
| 1689 | 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 | 1692 | void VoxelSystem::hideOutOfView() { |
| 1733 | − PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "hideOutOfView()",true); | |
| 1734 | − removeOutOfViewArgs args(this, true); // widen to match server! | |
| 1693 | + PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "hideOutOfView()"); | |
| 1694 | + hideOutOfViewArgs args(this, this->_tree, true); // widen to match server! | |
| 1735 | 1695 | _tree->recurseTreeWithOperation(hideOutOfViewOperation,(void*)&args); |
| 1736 | 1696 | |
| 1737 | 1697 | if (args.nodesRemoved) { |
| @@ -1747,8 +1707,86 @@ void VoxelSystem::hideOutOfView() { · 9 unmodified lines | ||
| 1747 | 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 | |