History

better working version of hideOutOfView voxel support

ZappoMan committed 13 years ago

Commit 2979a8e1 parent 303f4a84 files · +359 −76Browse files

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

Unified · Split

interface/src/VoxelSystem.cpp+342−75
@@ -107,6 +107,8 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) · 106 unmodified lines
107107
108108 _inSetupNewVoxelsForDrawing = false;
109109 _useFastVoxelPipeline = false;
110+
111+ _culledOnce = false;
110112 }
111113
112114 void VoxelSystem::voxelDeleted(VoxelNode* node) {
@@ -229,16 +231,21 @@ void VoxelSystem::freeBufferIndex(glBufferIndex index) { · 116 unmodified lines
229231
230232 // This will run through the list of _freeIndexes and reset their VBO array values to be "invisible".
231233 void VoxelSystem::clearFreeBufferIndexes() {
232− PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "###### clearFreeBufferIndexes()");
234+ bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
235+ PerformanceWarning warn(showWarnings, "clearFreeBufferIndexes()");
233236 _voxelsInWriteArrays = 0; // reset our VBO
234237 _abandonedVBOSlots = 0;
235238
236239 // clear out freeIndexes
237− pthread_mutex_lock(&_freeIndexLock);
238− _freeIndexes.clear();
240+ {
241+ PerformanceWarning warn(showWarnings,"clearFreeBufferIndexes() : pthread_mutex_lock(&_freeIndexLock)");
242+ pthread_mutex_lock(&_freeIndexLock);
243+ }
244+ {
245+ PerformanceWarning warn(showWarnings,"clearFreeBufferIndexes() : _freeIndexes.clear()");
246+ _freeIndexes.clear();
247+ }
239248 pthread_mutex_unlock(&_freeIndexLock);
240−
241− clearAllNodesBufferIndex();
242249 }
243250
244251 VoxelSystem::~VoxelSystem() {
@@ -745,7 +752,6 @@ void VoxelSystem::checkForCulling() { · 500 unmodified lines
745752 && !isViewChanging()
746753 )
747754 ) {
748−
749755 _lastViewCulling = start;
750756
751757 // When we call removeOutOfView() voxels, we don't actually remove the voxels from the VBOs, but we do remove
@@ -950,6 +956,12 @@ int VoxelSystem::forceRemoveNodeFromArrays(VoxelNode* node) { · 198 unmodified lines
950956 int VoxelSystem::updateNodeInArrays(VoxelNode* node, bool reuseIndex, bool forceDraw) {
951957 // If we've run out of room, then just bail...
952958 if (_voxelsInWriteArrays >= _maxVoxels) {
959+ // We need to think about what else we can do in this case. This basically means that all of our available
960+ // VBO slots are used up, but we're trying to render more voxels. At this point, if this happens we'll just
961+ // not render these Voxels. We need to think about ways to keep the entire scene intact but maybe lower quality
962+ // possibly shifting down to lower LOD or something. This debug message is to help identify, if/when/how this
963+ // state actually occurs.
964+ qDebug("OHHHH NOOOOOO!!!! updateNodeInArrays() BAILING (_voxelsInWriteArrays >= _maxVoxels)\n");
953965 return 0;
954966 }
955967
@@ -1062,10 +1074,24 @@ void VoxelSystem::changeTree(VoxelTree* newTree) { · 106 unmodified lines
10621074 }
10631075
10641076 void VoxelSystem::updateFullVBOs() {
1065− updateVBOSegment(0, _voxelsInReadArrays);
1077+ bool outputWarning = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
1078+ PerformanceWarning warn(outputWarning, "updateFullVBOs()");
1079+
1080+ {
1081+ static char buffer[128] = { 0 };
1082+ if (outputWarning) {
1083+ sprintf(buffer, "updateFullVBOs() : updateVBOSegment(0, _voxelsInReadArrays=%lu);", _voxelsInReadArrays);
1084+ };
1085+
1086+ PerformanceWarning warn(outputWarning,buffer);
1087+ updateVBOSegment(0, _voxelsInReadArrays);
1088+ }
10661089
1067− // consider the _readVoxelDirtyArray[] clean!
1068− memset(_readVoxelDirtyArray, false, _voxelsInReadArrays * sizeof(bool));
1090+ {
1091+ PerformanceWarning warn(outputWarning,"updateFullVBOs() : memset(_readVoxelDirtyArray...)");
1092+ // consider the _readVoxelDirtyArray[] clean!
1093+ memset(_readVoxelDirtyArray, false, _voxelsInReadArrays * sizeof(bool));
1094+ }
10691095 }
10701096
10711097 void VoxelSystem::updatePartialVBOs() {
@@ -1117,6 +1143,9 @@ void VoxelSystem::updateVBOs() { · 45 unmodified lines
11171143 }
11181144
11191145 void VoxelSystem::updateVBOSegment(glBufferIndex segmentStart, glBufferIndex segmentEnd) {
1146+ bool showWarning = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
1147+ PerformanceWarning warn(showWarning, "updateVBOSegment()");
1148+
11201149 if (_useVoxelShader) {
11211150 int segmentLength = (segmentEnd - segmentStart) + 1;
11221151 GLintptr segmentStartAt = segmentStart * sizeof(VoxelShaderVBOData);
@@ -1131,18 +1160,36 @@ void VoxelSystem::updateVBOSegment(glBufferIndex segmentStart, glBufferIndex seg · 8 unmodified lines
11311160 GLintptr segmentStartAt = segmentStart * vertexPointsPerVoxel * sizeof(GLfloat);
11321161 GLsizeiptr segmentSizeBytes = segmentLength * vertexPointsPerVoxel * sizeof(GLfloat);
11331162 GLfloat* readVerticesFrom = _readVerticesArray + (segmentStart * vertexPointsPerVoxel);
1134− glBindBuffer(GL_ARRAY_BUFFER, _vboVerticesID);
1135− glBufferSubData(GL_ARRAY_BUFFER, segmentStartAt, segmentSizeBytes, readVerticesFrom);
1163+
1164+ {
1165+ PerformanceWarning warn(showWarning, "updateVBOSegment() : glBindBuffer(GL_ARRAY_BUFFER, _vboVerticesID);");
1166+ glBindBuffer(GL_ARRAY_BUFFER, _vboVerticesID);
1167+ }
1168+
1169+ {
1170+ PerformanceWarning warn(showWarning, "updateVBOSegment() : glBufferSubData() _vboVerticesID);");
1171+ glBufferSubData(GL_ARRAY_BUFFER, segmentStartAt, segmentSizeBytes, readVerticesFrom);
1172+ }
1173+
11361174 segmentStartAt = segmentStart * vertexPointsPerVoxel * sizeof(GLubyte);
11371175 segmentSizeBytes = segmentLength * vertexPointsPerVoxel * sizeof(GLubyte);
11381176 GLubyte* readColorsFrom = _readColorsArray + (segmentStart * vertexPointsPerVoxel);
1139− glBindBuffer(GL_ARRAY_BUFFER, _vboColorsID);
1140− glBufferSubData(GL_ARRAY_BUFFER, segmentStartAt, segmentSizeBytes, readColorsFrom);
1177+
1178+ {
1179+ PerformanceWarning warn(showWarning, "updateVBOSegment() : glBindBuffer(GL_ARRAY_BUFFER, _vboColorsID);");
1180+ glBindBuffer(GL_ARRAY_BUFFER, _vboColorsID);
1181+ }
1182+
1183+ {
1184+ PerformanceWarning warn(showWarning, "updateVBOSegment() : glBufferSubData() _vboColorsID);");
1185+ glBufferSubData(GL_ARRAY_BUFFER, segmentStartAt, segmentSizeBytes, readColorsFrom);
1186+ }
11411187 }
11421188 }
11431189
11441190 void VoxelSystem::render(bool texture) {
1145− PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "render()");
1191+ bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
1192+ PerformanceWarning warn(showWarnings, "render()");
11461193
11471194 // If we got here and we're not initialized then bail!
11481195 if (!_initialized) {
@@ -1154,8 +1201,7 @@ void VoxelSystem::render(bool texture) { · 5 unmodified lines
11541201 bool dontCallOpenGLDraw = Menu::getInstance()->isOptionChecked(MenuOption::DontCallOpenGLForVoxels);
11551202 // if not don't... then do...
11561203 if (_useVoxelShader) {
1157− PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
1158− "render().. _useVoxelShader openGL..");
1204+ PerformanceWarning warn(showWarnings,"render().. _useVoxelShader openGL..");
11591205
11601206
11611207 //Define this somewhere in your header file
@@ -1201,68 +1247,78 @@ void VoxelSystem::render(bool texture) { · 39 unmodified lines
12011247 glDisableVertexAttribArray(attributeLocation);
12021248 }
12031249 } else {
1204− PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "render().. openGL...");
1250+ PerformanceWarning warn(showWarnings, "render().. TRIANGLES...");
12051251
1206− // tell OpenGL where to find vertex and color information
1207− glEnableClientState(GL_VERTEX_ARRAY);
1208− glEnableClientState(GL_COLOR_ARRAY);
1252+ {
1253+ PerformanceWarning warn(showWarnings,"render().. setup before glDrawRangeElementsEXT()...");
1254+
1255+ // tell OpenGL where to find vertex and color information
1256+ glEnableClientState(GL_VERTEX_ARRAY);
1257+ glEnableClientState(GL_COLOR_ARRAY);
12091258
1210− glBindBuffer(GL_ARRAY_BUFFER, _vboVerticesID);
1211− glVertexPointer(3, GL_FLOAT, 0, 0);
1259+ glBindBuffer(GL_ARRAY_BUFFER, _vboVerticesID);
1260+ glVertexPointer(3, GL_FLOAT, 0, 0);
12121261
1213− glBindBuffer(GL_ARRAY_BUFFER, _vboColorsID);
1214− glColorPointer(3, GL_UNSIGNED_BYTE, 0, 0);
1262+ glBindBuffer(GL_ARRAY_BUFFER, _vboColorsID);
1263+ glColorPointer(3, GL_UNSIGNED_BYTE, 0, 0);
12151264
1216− applyScaleAndBindProgram(texture);
1265+ applyScaleAndBindProgram(texture);
12171266
1218− // for performance, enable backface culling
1219− glEnable(GL_CULL_FACE);
1267+ // for performance, enable backface culling
1268+ glEnable(GL_CULL_FACE);
1269+ }
12201270
12211271 // draw voxels in 6 passes
12221272
12231273 if (!dontCallOpenGLDraw) {
1274+ PerformanceWarning warn(showWarnings, "render().. glDrawRangeElementsEXT()...");
1275+
12241276 glNormal3f(0,1.0f,0);
12251277 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesTop);
1226− glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1,
1278+ glDrawRangeElementsEXT(GL_TRIANGLES, 0, GLOBAL_NORMALS_VERTICES_PER_VOXEL * _voxelsInReadArrays - 1,
12271279 INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
12281280
12291281 glNormal3f(0,-1.0f,0);
12301282 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesBottom);
1231− glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1,
1283+ glDrawRangeElementsEXT(GL_TRIANGLES, 0, GLOBAL_NORMALS_VERTICES_PER_VOXEL * _voxelsInReadArrays - 1,
12321284 INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
12331285
12341286 glNormal3f(-1.0f,0,0);
12351287 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesLeft);
1236− glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1,
1288+ glDrawRangeElementsEXT(GL_TRIANGLES, 0, GLOBAL_NORMALS_VERTICES_PER_VOXEL * _voxelsInReadArrays - 1,
12371289 INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
12381290
12391291 glNormal3f(1.0f,0,0);
12401292 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesRight);
1241− glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1,
1293+ glDrawRangeElementsEXT(GL_TRIANGLES, 0, GLOBAL_NORMALS_VERTICES_PER_VOXEL * _voxelsInReadArrays - 1,
12421294 INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
12431295
12441296 glNormal3f(0,0,-1.0f);
12451297 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesFront);
1246− glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1,
1298+ glDrawRangeElementsEXT(GL_TRIANGLES, 0, GLOBAL_NORMALS_VERTICES_PER_VOXEL * _voxelsInReadArrays - 1,
12471299 INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
12481300
12491301 glNormal3f(0,0,1.0f);
12501302 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesBack);
1251− glDrawRangeElementsEXT(GL_TRIANGLES, 0, INDICES_PER_FACE * _voxelsInReadArrays - 1,
1303+ glDrawRangeElementsEXT(GL_TRIANGLES, 0, GLOBAL_NORMALS_VERTICES_PER_VOXEL * _voxelsInReadArrays - 1,
12521304 INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
12531305 }
12541306
1255− glDisable(GL_CULL_FACE);
1307+ {
1308+ PerformanceWarning warn(showWarnings, "render().. cleanup after glDrawRangeElementsEXT()...");
1309+
1310+ glDisable(GL_CULL_FACE);
12561311
1257− removeScaleAndReleaseProgram(texture);
1312+ removeScaleAndReleaseProgram(texture);
12581313
1259− // deactivate vertex and color arrays after drawing
1260− glDisableClientState(GL_VERTEX_ARRAY);
1261− glDisableClientState(GL_COLOR_ARRAY);
1314+ // deactivate vertex and color arrays after drawing
1315+ glDisableClientState(GL_VERTEX_ARRAY);
1316+ glDisableClientState(GL_COLOR_ARRAY);
12621317
1263− // bind with 0 to switch back to normal operation
1264− glBindBuffer(GL_ARRAY_BUFFER, 0);
1265− glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
1318+ // bind with 0 to switch back to normal operation
1319+ glBindBuffer(GL_ARRAY_BUFFER, 0);
1320+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
1321+ }
12661322 }
12671323 }
12681324
@@ -1527,11 +1583,11 @@ public: · 258 unmodified lines
15271583 VoxelSystem* thisVoxelSystem;
15281584 ViewFrustum thisViewFrustum;
15291585 VoxelNodeBag dontRecurseBag;
1530− unsigned long nodesScanned;
1531− unsigned long nodesRemoved;
1532− unsigned long nodesInside;
1533− unsigned long nodesIntersect;
1534− unsigned long nodesOutside;
1586+ unsigned long nodesScanned;
1587+ unsigned long nodesRemoved;
1588+ unsigned long nodesInside;
1589+ unsigned long nodesIntersect;
1590+ unsigned long nodesOutside;
15351591 VoxelNode* insideRoot;
15361592 VoxelNode* outsideRoot;
15371593
@@ -1612,10 +1668,10 @@ bool VoxelSystem::removeOutOfViewOperation(VoxelNode* node, void* extraData) { · 74 unmodified lines
16121668 bool VoxelSystem::isViewChanging() {
16131669 bool result = false; // assume the best
16141670
1615− // If our viewFrustum has changed since our _lastKnowViewFrustum
1616− if (!_lastKnowViewFrustum.matches(_viewFrustum)) {
1671+ // If our viewFrustum has changed since our _lastKnownViewFrustum
1672+ if (!_lastKnownViewFrustum.matches(_viewFrustum)) {
16171673 result = true;
1618− _lastKnowViewFrustum = *_viewFrustum; // save last known
1674+ _lastKnownViewFrustum = *_viewFrustum; // save last known
16191675 }
16201676 return result;
16211677 }
@@ -1628,7 +1684,7 @@ bool VoxelSystem::hasViewChanged() { · 6 unmodified lines
16281684 return false;
16291685 }
16301686
1631− // If our viewFrustum has changed since our _lastKnowViewFrustum
1687+ // If our viewFrustum has changed since our _lastKnownViewFrustum
16321688 if (!_lastStableViewFrustum.matches(_viewFrustum)) {
16331689 result = true;
16341690 _lastStableViewFrustum = *_viewFrustum; // save last stable
@@ -1653,27 +1709,92 @@ void VoxelSystem::removeOutOfView() { · 18 unmodified lines
16531709 }
16541710 }
16551711
1712+// combines the removeOutOfView args into a single class
1713+class showAllLocalVoxelsArgs {
1714+public:
1715+ VoxelSystem* thisVoxelSystem;
1716+ ViewFrustum thisViewFrustum;
1717+ unsigned long nodesScanned;
1718+
1719+ showAllLocalVoxelsArgs(VoxelSystem* voxelSystem) :
1720+ thisVoxelSystem(voxelSystem),
1721+ thisViewFrustum(*voxelSystem->getViewFrustum()),
1722+ nodesScanned(0)
1723+ {
1724+ }
1725+};
1726+
1727+void VoxelSystem::showAllLocalVoxels() {
1728+ PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "showAllLocalVoxels()");
1729+ showAllLocalVoxelsArgs args(this);
1730+ _tree->recurseTreeWithOperation(showAllLocalVoxelsOperation,(void*)&args);
1731+
1732+ bool showRemoveDebugDetails = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
1733+ if (showRemoveDebugDetails) {
1734+ qDebug("showAllLocalVoxels() scanned=%ld \n",args.nodesScanned );
1735+ }
1736+}
1737+
1738+bool VoxelSystem::showAllLocalVoxelsOperation(VoxelNode* node, void* extraData) {
1739+ showAllLocalVoxelsArgs* args = (showAllLocalVoxelsArgs*)extraData;
1740+
1741+ args->nodesScanned++;
1742+
1743+ bool shouldRender = true; // node->calculateShouldRender(&args->thisViewFrustum);
1744+ node->setShouldRender(shouldRender);
1745+
1746+ if (shouldRender) {
1747+ bool falseColorize = false;
1748+ if (falseColorize) {
1749+ node->setFalseColor(0,0,255); // fake
1750+ }
1751+ // how does randomize color work?
1752+ node->setDirtyBit(); // will this make it draw!
1753+ node->markWithChangedTime(); // fake
1754+ }
1755+
1756+ return true; // keep recursing!
1757+}
1758+
1759+
16561760 // combines the removeOutOfView args into a single class
16571761 class hideOutOfViewArgs {
16581762 public:
1659− VoxelSystem* thisVoxelSystem;
1660− VoxelTree* tree;
1661− ViewFrustum thisViewFrustum;
1662− unsigned long nodesScanned;
1663− unsigned long nodesRemoved;
1664− unsigned long nodesInside;
1665− unsigned long nodesIntersect;
1666− unsigned long nodesOutside;
1763+ VoxelSystem* thisVoxelSystem;
1764+ VoxelTree* tree;
1765+ ViewFrustum thisViewFrustum;
1766+ ViewFrustum lastViewFrustum;
1767+ bool culledOnce;
1768+ bool wantDeltaFrustums;
1769+ unsigned long nodesScanned;
1770+ unsigned long nodesRemoved;
1771+ unsigned long nodesInside;
1772+ unsigned long nodesIntersect;
1773+ unsigned long nodesOutside;
1774+ unsigned long nodesInsideInside;
1775+ unsigned long nodesIntersectInside;
1776+ unsigned long nodesOutsideInside;
1777+ unsigned long nodesInsideOutside;
1778+ unsigned long nodesOutsideOutside;
16671779
1668− hideOutOfViewArgs(VoxelSystem* voxelSystem, VoxelTree* tree, bool widenViewFrustum = true) :
1780+ hideOutOfViewArgs(VoxelSystem* voxelSystem, VoxelTree* tree,
1781+ bool culledOnce, bool widenViewFrustum, bool wantDeltaFrustums) :
16691782 thisVoxelSystem(voxelSystem),
16701783 tree(tree),
16711784 thisViewFrustum(*voxelSystem->getViewFrustum()),
1785+ lastViewFrustum(*voxelSystem->getLastCulledViewFrustum()),
1786+ culledOnce(culledOnce),
1787+ wantDeltaFrustums(wantDeltaFrustums),
16721788 nodesScanned(0),
16731789 nodesRemoved(0),
16741790 nodesInside(0),
16751791 nodesIntersect(0),
1676− nodesOutside(0)
1792+ nodesOutside(0),
1793+ nodesInsideInside(0),
1794+ nodesIntersectInside(0),
1795+ nodesOutsideInside(0),
1796+ nodesInsideOutside(0),
1797+ nodesOutsideOutside(0)
16771798 {
16781799 // Widen the FOV for trimming
16791800 if (widenViewFrustum) {
@@ -1686,9 +1807,67 @@ public: · 6 unmodified lines
16861807 };
16871808
16881809 void VoxelSystem::hideOutOfView() {
1689− PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "hideOutOfView()");
1690− hideOutOfViewArgs args(this, this->_tree, true); // widen to match server!
1810+ bool showDebugDetails = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
1811+ PerformanceWarning warn(showDebugDetails, "hideOutOfView()", showDebugDetails);
1812+ bool widenFrustum = true;
1813+ bool wantDeltaFrustums = false; // Menu::getInstance()->isOptionChecked(MenuOption::UseDeltaFrustumInHide);
1814+ hideOutOfViewArgs args(this, this->_tree, _culledOnce, widenFrustum, wantDeltaFrustums);
1815+
1816+ const bool wantViewFrustumDebugging = false; // change to true for additional debugging
1817+ if (wantViewFrustumDebugging) {
1818+ printf("\n\n----------thisViewFrustum----------\n");
1819+ args.thisViewFrustum.printDebugDetails();
1820+
1821+ if (!_culledOnce) {
1822+ printf("\n\n----------NOT YET CULLED !!!!----------\n");
1823+ } else {
1824+ printf("\n\n----------lastViewFrustum----------\n");
1825+ args.lastViewFrustum.printDebugDetails();
1826+ }
1827+ }
1828+
1829+ if (_culledOnce && args.lastViewFrustum.matches(args.thisViewFrustum)) {
1830+ //printf("view frustum hasn't changed BAIL!!!\n");
1831+ return;
1832+ }
1833+
1834+ // Changed hideOutOfView() to support "delta" view frustums and only hide/show items that are in the difference
1835+ // between the two view frustums. There are some potential problems with this idea...
1836+ //
1837+ // 1) This might work well for rotating, but what about moving forward?
1838+ // in the move forward case, you'll get new voxel details, but those
1839+ // new voxels will be in the last view... does that work?
1840+ //
1841+ // 2) what about voxels coming in from the network that are OUTSIDE of the view
1842+ // frustum... they don't get hidden... and so we can't assume they are correctly
1843+ // hidden... we could solve this with checking in view on voxelUpdated...
1844+ //
1845+ // 3) this seems to mostly work for a few minutes, then it starts to break after some period of time??
1846+ // and is it related to what appears to be the view changing even when stationary...???
1847+ //
1848+ // 4) if something goes wrong it stays wrong? unless new packets come from network... why aren't those redrawing...
1849+ //
1850+ // consider doing false colorization...
1851+ //
1852+ // What if we kept track of which voxels were visible, and iterated them in an array instead of in the tree?
1853+ // would that be faster? seems like it wouldn't be.
1854+
1855+ //
1856+ // What's working well now....
1857+ // Fast Voxel Pipeline + normal Remove Out Of View...
1858+ // this fails when you spin around, it will just have a big blank spot...
1859+ // you also see flashes of white/no voxels in areas you've already been
1860+ //
1861+ // When you add Don't Remove Out of View voxels...
1862+ // works OK... but... it loads up too many voxels...
1863+ // and frame rate drops...
1864+ //
1865+ // We'd like to add in hide/show... but things break... See above.
1866+ // this is the problem... SOLVE this problem...
1867+
16911868 _tree->recurseTreeWithOperation(hideOutOfViewOperation,(void*)&args);
1869+ _lastCulledViewFrustum = args.thisViewFrustum; // save last stable
1870+ _culledOnce = true;
16921871
16931872 if (args.nodesRemoved) {
16941873 _tree->setDirtyBit();
@@ -1696,24 +1875,47 @@ void VoxelSystem::hideOutOfView() { · 1 unmodified line
16961875 }
16971876
16981877
1699− bool showRemoveDebugDetails = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
1700− if (showRemoveDebugDetails) {
1878+ if (showDebugDetails) {
17011879 qDebug("hideOutOfView() scanned=%ld removed=%ld inside=%ld intersect=%ld outside=%ld\n",
17021880 args.nodesScanned, args.nodesRemoved, args.nodesInside,
17031881 args.nodesIntersect, args.nodesOutside
17041882 );
1883+ qDebug(" inside/inside=%ld intersect/inside=%ld outside/outside=%ld\n",
1884+ args.nodesInsideInside, args.nodesIntersectInside, args.nodesOutsideOutside
1885+ );
17051886 }
17061887 }
17071888
17081889 bool VoxelSystem::hideAllSubTreeOperation(VoxelNode* node, void* extraData) {
17091890 hideOutOfViewArgs* args = (hideOutOfViewArgs*)extraData;
17101891
1892+ // If we've culled at least once, then we will use the status of this voxel in the last culled frustum to determine
1893+ // how to proceed. If we've never culled, then we just consider all these voxels to be UNKNOWN so that we will not
1894+ // consider that case.
1895+ ViewFrustum::location inLastCulledFrustum;
1896+
1897+ if (args->culledOnce && args->wantDeltaFrustums) {
1898+ inLastCulledFrustum = node->inFrustum(args->lastViewFrustum);
1899+
1900+ // if this node is fully OUTSIDE our last culled view frustum, then we don't need to recurse further
1901+ if (inLastCulledFrustum == ViewFrustum::OUTSIDE) {
1902+ args->nodesOutsideOutside++;
1903+ return false;
1904+ }
1905+ }
1906+
17111907 args->nodesOutside++;
17121908 if (node->isKnownBufferIndex()) {
17131909 args->nodesRemoved++;
1714− VoxelSystem* thisVoxelSystem = args->thisVoxelSystem;
1715− thisVoxelSystem->_voxelsUpdated += thisVoxelSystem->forceRemoveNodeFromArrays(node);
1716− thisVoxelSystem->setupNewVoxelsForDrawingSingleNode();
1910+ bool falseColorize = false;
1911+ if (falseColorize) {
1912+ node->setFalseColor(255,0,0); // fake
1913+ } else {
1914+ VoxelSystem* thisVoxelSystem = args->thisVoxelSystem;
1915+ thisVoxelSystem->_voxelsUpdated += thisVoxelSystem->forceRemoveNodeFromArrays(node);
1916+ thisVoxelSystem->setupNewVoxelsForDrawingSingleNode();
1917+ }
1918+
17171919 }
17181920
17191921 return true;
@@ -1722,17 +1924,40 @@ bool VoxelSystem::hideAllSubTreeOperation(VoxelNode* node, void* extraData) { · 2 unmodified lines
17221924 bool VoxelSystem::showAllSubTreeOperation(VoxelNode* node, void* extraData) {
17231925 hideOutOfViewArgs* args = (hideOutOfViewArgs*)extraData;
17241926
1927+ // If we've culled at least once, then we will use the status of this voxel in the last culled frustum to determine
1928+ // how to proceed. If we've never culled, then we just consider all these voxels to be UNKNOWN so that we will not
1929+ // consider that case.
1930+ ViewFrustum::location inLastCulledFrustum;
1931+
1932+ if (args->culledOnce && args->wantDeltaFrustums) {
1933+ inLastCulledFrustum = node->inFrustum(args->lastViewFrustum);
1934+
1935+ // if this node is fully inside our last culled view frustum, then we don't need to recurse further
1936+ if (inLastCulledFrustum == ViewFrustum::INSIDE) {
1937+ args->nodesInsideInside++;
1938+ return false;
1939+ }
1940+ }
1941+
17251942 args->nodesInside++;
17261943
1727− if (node->getShouldRender() && !node->isKnownBufferIndex()) {
1944+ //printf("<<<<<<<<<<< showAllSubTreeOperation() >>>>>>>>>>>>>>>\n");
1945+
1946+ bool shouldRender = node->calculateShouldRender(&args->thisViewFrustum);
1947+ node->setShouldRender(shouldRender);
1948+
1949+ if (shouldRender /*&& !node->isKnownBufferIndex()*/) {
1950+ bool falseColorize = false;
1951+ if (falseColorize) {
1952+ node->setFalseColor(0,0,255); // fake
1953+ }
17281954 node->setDirtyBit(); // will this make it draw!
1955+ node->markWithChangedTime(); // fake
17291956 }
17301957
17311958 return true; // keep recursing!
17321959 }
17331960
1734−
1735−
17361961 // "hide" voxels in the VBOs that are still in the tree that but not in view.
17371962 // We don't remove them from the tree, we don't delete them, we do remove them
17381963 // from the VBOs and mark them as such in the tree.
@@ -1742,26 +1967,67 @@ bool VoxelSystem::hideOutOfViewOperation(VoxelNode* node, void* extraData) { · 3 unmodified lines
17421967 // If we're still recursing the tree using this operator, then we don't know if we're inside or outside...
17431968 // so before we move forward we need to determine our frustum location
17441969 ViewFrustum::location inFrustum = node->inFrustum(args->thisViewFrustum);
1970+
1971+ // If we've culled at least once, then we will use the status of this voxel in the last culled frustum to determine
1972+ // how to proceed. If we've never culled, then we just consider all these voxels to be UNKNOWN so that we will not
1973+ // consider that case.
1974+ ViewFrustum::location inLastCulledFrustum;
1975+
1976+ if (args->culledOnce && args->wantDeltaFrustums) {
1977+ inLastCulledFrustum = node->inFrustum(args->lastViewFrustum);
1978+ }
17451979
17461980 // ok, now do some processing for this node...
17471981 switch (inFrustum) {
17481982 case ViewFrustum::OUTSIDE: {
1749− // if this node is fully OUTSIDE the view, then we know that ALL of it's children are also fully OUTSIDE
1750− // so we can recurse the children and simply mark them as hidden
1983+
1984+ // If this node is outside the current view, then we might want to hide it... unless it was previously OUTSIDE,
1985+ // if it was previously outside, then we can safely assume it's already hidden, and we can also safely assume
1986+ // that all of it's children are outside both of our views, in which case we can just stop recursing...
1987+ if (args->culledOnce && args->wantDeltaFrustums && inLastCulledFrustum == ViewFrustum::OUTSIDE) {
1988+ args->nodesScanned++;
1989+ args->nodesOutsideOutside++;
1990+ return false; // stop recursing this branch!
1991+ }
1992+
1993+ // if this node is fully OUTSIDE the view, but previously intersected and/or was inside the last view, then
1994+ // we need to hide it. Additionally we know that ALL of it's children are also fully OUTSIDE so we can recurse
1995+ // the children and simply mark them as hidden
17511996 args->tree->recurseNodeWithOperation(node, hideAllSubTreeOperation, args );
17521997
17531998 return false;
17541999
17552000 } break;
17562001 case ViewFrustum::INSIDE: {
1757− // if this node is fully INSIDE the view, then we know that ALL of it's children are also fully INSIDE
1758− // so we can recurse the children and simply mark them as visible (as appropriate based on LOD)
1759− args->tree->recurseNodeWithOperation(node, showAllSubTreeOperation, args );
2002+
2003+ // If this node is INSIDE the current view, then we might want to show it... unless it was previously INSIDE,
2004+ // if it was previously INSIDE, then we can safely assume it's already shown, and we can also safely assume
2005+ // that all of it's children are INSIDE both of our views, in which case we can just stop recursing...
2006+ if (args->culledOnce && args->wantDeltaFrustums && inLastCulledFrustum == ViewFrustum::INSIDE) {
2007+ args->nodesScanned++;
2008+ args->nodesInsideInside++;
2009+ return false; // stop recursing this branch!
2010+ }
2011+
2012+ // if this node is fully INSIDE the view, but previously INTERSECTED and/or was OUTSIDE the last view, then
2013+ // we need to show it. Additionally we know that ALL of it's children are also fully INSIDE so we can recurse
2014+ // the children and simply mark them as visible (as appropriate based on LOD)
2015+ //printf("<<<<<<<<<<< HERE!!!!! >>>>>>>>>>>>>>>\n");
2016+ args->tree->recurseNodeWithOperation(node, showAllSubTreeOperation, args);
17602017
17612018 return false;
17622019 } break;
17632020 case ViewFrustum::INTERSECT: {
17642021 args->nodesScanned++;
2022+
2023+ // If this node INTERSECTS the current view, then we might want to show it... unless it was previously INSIDE
2024+ // the last known view, in which case it will already be visible, and we know that all it's children are also
2025+ // previously INSIDE and visible. So in this case stop recursing
2026+ if (args->culledOnce && args->wantDeltaFrustums && inLastCulledFrustum == ViewFrustum::INSIDE) {
2027+ args->nodesIntersectInside++;
2028+ return false; // stop recursing this branch!
2029+ }
2030+
17652031 args->nodesIntersect++;
17662032
17672033 // if the child node INTERSECTs the view, then we want to check to see if it thinks it should render
@@ -1887,6 +2153,7 @@ public: · 119 unmodified lines
18872153 };
18882154
18892155 bool VoxelSystem::collectStatsForTreesAndVBOsOperation(VoxelNode* node, void* extraData) {
2156+
18902157 collectStatsForTreesAndVBOsArgs* args = (collectStatsForTreesAndVBOsArgs*)extraData;
18912158 args->totalNodes++;
18922159

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t