Showing the changes to interface/src/VoxelSystem.cpp (1 of 4 files). Show all
Unified · Split
| @@ -753,25 +753,54 @@ void VoxelSystem::checkForCulling() { · 752 unmodified lines | ||
| 753 | 753 | && !isViewChanging() |
| 754 | 754 | ) |
| 755 | 755 | ) { |
| 756 | − _lastViewCulling = start; | |
| 757 | − | |
| 758 | 756 | // When we call removeOutOfView() voxels, we don't actually remove the voxels from the VBOs, but we do remove |
| 759 | 757 | // them from tree, this makes our tree caclulations faster, but doesn't require us to fully rebuild the VBOs (which |
| 760 | 758 | // can be expensive). |
| 761 | 759 | if (!Menu::getInstance()->isOptionChecked(MenuOption::DisableHideOutOfView)) { |
| 762 | − hideOutOfView(); | |
| 763 | − } | |
| 764 | − if (Menu::getInstance()->isOptionChecked(MenuOption::RemoveOutOfView)) { | |
| 760 | + | |
| 761 | + // track how long its been since we were last moving. If we have recently moved then only use delta frustums, if | |
| 762 | + // it's been a long time since we last moved, then go ahead and do a full frustum cull. | |
| 763 | + if (isViewChanging()) { | |
| 764 | + _lastViewIsChanging = start; | |
| 765 | + } | |
| 766 | + uint64_t sinceLastMoving = (start - _lastViewIsChanging) / 1000; | |
| 767 | + | |
| 768 | + bool enoughTime = (sinceLastMoving >= std::max((float) _lastViewCullingElapsed, VIEW_CULLING_RATE_IN_MILLISECONDS)); | |
| 769 | + | |
| 770 | + // These has changed events will occur before we stop. So we need to remember this for when we finally have stopped | |
| 771 | + // moving long enough to be enoughTime | |
| 772 | + if (hasViewChanged()) { | |
| 773 | + _hasRecentlyChanged = true; | |
| 774 | + } | |
| 775 | + | |
| 776 | + // If we have recently changed, but it's been enough time since we last moved, then we will do a full frustum | |
| 777 | + // hide/show culling pass | |
| 778 | + bool forceFullFrustum = enoughTime && _hasRecentlyChanged; | |
| 779 | + | |
| 780 | + // in hide mode, we only track the full frustum culls, because we don't care about the partials. | |
| 781 | + if (forceFullFrustum) { | |
| 782 | + _lastViewCulling = start; | |
| 783 | + _hasRecentlyChanged = false; | |
| 784 | + } | |
| 785 | + | |
| 786 | + hideOutOfView(forceFullFrustum); | |
| 787 | + | |
| 788 | + if (forceFullFrustum) { | |
| 789 | + uint64_t endViewCulling = usecTimestampNow(); | |
| 790 | + _lastViewCullingElapsed = (endViewCulling - start) / 1000; | |
| 791 | + } | |
| 792 | + | |
| 793 | + } else if (Menu::getInstance()->isOptionChecked(MenuOption::RemoveOutOfView)) { | |
| 794 | + _lastViewCulling = start; | |
| 765 | 795 | removeOutOfView(); |
| 796 | + uint64_t endViewCulling = usecTimestampNow(); | |
| 797 | + _lastViewCullingElapsed = (endViewCulling - start) / 1000; | |
| 766 | 798 | } |
| 767 | 799 | |
| 768 | 800 | // Once we call cleanupRemovedVoxels() we do need to rebuild our VBOs (if anything was actually removed). So, |
| 769 | 801 | // we should consider putting this someplace else... as this might be able to occur less frequently, and save us on |
| 770 | 802 | // VBO reubuilding. Possibly we should do this only if our actual VBO usage crosses some lower boundary. |
| 771 | 803 | cleanupRemovedVoxels(); |
| 772 | − | |
| 773 | − uint64_t endViewCulling = usecTimestampNow(); | |
| 774 | − _lastViewCullingElapsed = (endViewCulling - start) / 1000; | |
| 775 | 804 | } |
| 776 | 805 | |
| 777 | 806 | uint64_t sinceLastAudit = (start - _lastAudit) / 1000; |
| @@ -1047,7 +1076,8 @@ void VoxelSystem::init() { · 269 unmodified lines | ||
| 1047 | 1076 | _callsToTreesToArrays = 0; |
| 1048 | 1077 | _setupNewVoxelsForDrawingLastFinished = 0; |
| 1049 | 1078 | _setupNewVoxelsForDrawingLastElapsed = 0; |
| 1050 | − _lastViewCullingElapsed = _lastViewCulling = _lastAudit = 0; | |
| 1079 | + _lastViewCullingElapsed = _lastViewCulling = _lastAudit = _lastViewIsChanging = 0; | |
| 1080 | + _hasRecentlyChanged = false; | |
| 1051 | 1081 | |
| 1052 | 1082 | _voxelsDirty = false; |
| 1053 | 1083 | _voxelsInWriteArrays = 0; |
| @@ -1807,11 +1837,27 @@ public: · 753 unmodified lines | ||
| 1807 | 1837 | } |
| 1808 | 1838 | }; |
| 1809 | 1839 | |
| 1810 | −void VoxelSystem::hideOutOfView() { | |
| 1840 | +void VoxelSystem::hideOutOfView(bool forceFullFrustum) { | |
| 1841 | + printf("VoxelSystem::hideOutOfView(bool forceFullFrustum=%s)\n",debug::valueOf(forceFullFrustum)); | |
| 1811 | 1842 | bool showDebugDetails = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); |
| 1812 | 1843 | PerformanceWarning warn(showDebugDetails, "hideOutOfView()", showDebugDetails); |
| 1813 | 1844 | bool widenFrustum = true; |
| 1814 | − bool wantDeltaFrustums = !Menu::getInstance()->isOptionChecked(MenuOption::UseFullFrustumInHide); | |
| 1845 | + | |
| 1846 | + // When using "delta" view frustums and only hide/show items that are in the difference | |
| 1847 | + // between the two view frustums. There are some potential problems with this mode. | |
| 1848 | + // | |
| 1849 | + // 1) This work well for rotating, but what about moving forward? | |
| 1850 | + // In the move forward case, you'll get new voxel details, but those | |
| 1851 | + // new voxels will be in the last view. | |
| 1852 | + // | |
| 1853 | + // 2) Also, voxels will arrive from the network that are OUTSIDE of the view | |
| 1854 | + // frustum... these won't get hidden... and so we can't assume they are correctly | |
| 1855 | + // hidden... | |
| 1856 | + // | |
| 1857 | + // Both these problems are solved by intermittently calling this with forceFullFrustum set | |
| 1858 | + // to true. This will essentially clean up the improperly hidden or shown voxels. | |
| 1859 | + // | |
| 1860 | + bool wantDeltaFrustums = !forceFullFrustum && !Menu::getInstance()->isOptionChecked(MenuOption::UseFullFrustumInHide); | |
| 1815 | 1861 | hideOutOfViewArgs args(this, this->_tree, _culledOnce, widenFrustum, wantDeltaFrustums); |
| 1816 | 1862 | |
| 1817 | 1863 | const bool wantViewFrustumDebugging = false; // change to true for additional debugging |
| @@ -1822,24 +1868,11 @@ void VoxelSystem::hideOutOfView() { · 4 unmodified lines | ||
| 1822 | 1868 | } |
| 1823 | 1869 | } |
| 1824 | 1870 | |
| 1825 | − if (_culledOnce && args.lastViewFrustum.matches(args.thisViewFrustum)) { | |
| 1826 | − //printf("view frustum hasn't changed BAIL!!!\n"); | |
| 1871 | + if (!forceFullFrustum && _culledOnce && args.lastViewFrustum.matches(args.thisViewFrustum)) { | |
| 1872 | + printf("view frustum hasn't changed BAIL!!!\n"); | |
| 1827 | 1873 | return; |
| 1828 | 1874 | } |
| 1829 | 1875 | |
| 1830 | − // Changed hideOutOfView() to support "delta" view frustums and only hide/show items that are in the difference | |
| 1831 | − // between the two view frustums. There are some potential problems with this idea... | |
| 1832 | − // | |
| 1833 | − // 1) This might work well for rotating, but what about moving forward? | |
| 1834 | − // in the move forward case, you'll get new voxel details, but those | |
| 1835 | − // new voxels will be in the last view... does that work? This works | |
| 1836 | − // ok for now because voxel server resends them and so they get redisplayed, | |
| 1837 | − // but this will not work if we update the voxel server to send less data. | |
| 1838 | − // | |
| 1839 | − // 2) what about voxels coming in from the network that are OUTSIDE of the view | |
| 1840 | − // frustum... they don't get hidden... and so we can't assume they are correctly | |
| 1841 | − // hidden... we could solve this with checking in view on voxelUpdated... | |
| 1842 | − // | |
| 1843 | 1876 | _tree->recurseTreeWithOperation(hideOutOfViewOperation,(void*)&args); |
| 1844 | 1877 | _lastCulledViewFrustum = args.thisViewFrustum; // save last stable |
| 1845 | 1878 | _culledOnce = true; |