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
107 107
108 _inSetupNewVoxelsForDrawing = false;108 _inSetupNewVoxelsForDrawing = false;
109 _useFastVoxelPipeline = false;109 _useFastVoxelPipeline = false;
110
111 _culledOnce = false;
110}112}
111 113
112void VoxelSystem::voxelDeleted(VoxelNode* node) {114void VoxelSystem::voxelDeleted(VoxelNode* node) {
@@ -229,16 +231,21 @@ void VoxelSystem::freeBufferIndex(glBufferIndex index) { · 116 unmodified lines
229 231
230// This will run through the list of _freeIndexes and reset their VBO array values to be "invisible".232// This will run through the list of _freeIndexes and reset their VBO array values to be "invisible".
231void VoxelSystem::clearFreeBufferIndexes() {233void VoxelSystem::clearFreeBufferIndexes() {
232 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "###### clearFreeBufferIndexes()");234 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
235 PerformanceWarning warn(showWarnings, "clearFreeBufferIndexes()");
233 _voxelsInWriteArrays = 0; // reset our VBO236 _voxelsInWriteArrays = 0; // reset our VBO
234 _abandonedVBOSlots = 0;237 _abandonedVBOSlots = 0;
235 238
236 // clear out freeIndexes239 // clear out freeIndexes
237 pthread_mutex_lock(&_freeIndexLock);240 {
238 _freeIndexes.clear();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 }
239 pthread_mutex_unlock(&_freeIndexLock);248 pthread_mutex_unlock(&_freeIndexLock);
240
241 clearAllNodesBufferIndex();
242}249}
243 250
244VoxelSystem::~VoxelSystem() {251VoxelSystem::~VoxelSystem() {
@@ -745,7 +752,6 @@ void VoxelSystem::checkForCulling() { · 500 unmodified lines
745 && !isViewChanging()752 && !isViewChanging()
746 )753 )
747 ) {754 ) {
748
749 _lastViewCulling = start;755 _lastViewCulling = start;
750 756
751 // When we call removeOutOfView() voxels, we don't actually remove the voxels from the VBOs, but we do remove757 // 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
950int VoxelSystem::updateNodeInArrays(VoxelNode* node, bool reuseIndex, bool forceDraw) {956int VoxelSystem::updateNodeInArrays(VoxelNode* node, bool reuseIndex, bool forceDraw) {
951 // If we've run out of room, then just bail...957 // If we've run out of room, then just bail...
952 if (_voxelsInWriteArrays >= _maxVoxels) {958 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");
953 return 0;965 return 0;
954 }966 }
955 967
@@ -1062,10 +1074,24 @@ void VoxelSystem::changeTree(VoxelTree* newTree) { · 106 unmodified lines
1062}1074}
1063 1075
1064void VoxelSystem::updateFullVBOs() {1076void 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 }
1066 1089
1067 // consider the _readVoxelDirtyArray[] clean!1090 {
1068 memset(_readVoxelDirtyArray, false, _voxelsInReadArrays * sizeof(bool));1091 PerformanceWarning warn(outputWarning,"updateFullVBOs() : memset(_readVoxelDirtyArray...)");
1092 // consider the _readVoxelDirtyArray[] clean!
1093 memset(_readVoxelDirtyArray, false, _voxelsInReadArrays * sizeof(bool));
1094 }
1069}1095}
1070 1096
1071void VoxelSystem::updatePartialVBOs() {1097void VoxelSystem::updatePartialVBOs() {
@@ -1117,6 +1143,9 @@ void VoxelSystem::updateVBOs() { · 45 unmodified lines
1117}1143}
1118 1144
1119void VoxelSystem::updateVBOSegment(glBufferIndex segmentStart, glBufferIndex segmentEnd) {1145void VoxelSystem::updateVBOSegment(glBufferIndex segmentStart, glBufferIndex segmentEnd) {
1146 bool showWarning = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
1147 PerformanceWarning warn(showWarning, "updateVBOSegment()");
1148
1120 if (_useVoxelShader) {1149 if (_useVoxelShader) {
1121 int segmentLength = (segmentEnd - segmentStart) + 1;1150 int segmentLength = (segmentEnd - segmentStart) + 1;
1122 GLintptr segmentStartAt = segmentStart * sizeof(VoxelShaderVBOData);1151 GLintptr segmentStartAt = segmentStart * sizeof(VoxelShaderVBOData);
@@ -1131,18 +1160,36 @@ void VoxelSystem::updateVBOSegment(glBufferIndex segmentStart, glBufferIndex seg · 8 unmodified lines
1131 GLintptr segmentStartAt = segmentStart * vertexPointsPerVoxel * sizeof(GLfloat);1160 GLintptr segmentStartAt = segmentStart * vertexPointsPerVoxel * sizeof(GLfloat);
1132 GLsizeiptr segmentSizeBytes = segmentLength * vertexPointsPerVoxel * sizeof(GLfloat);1161 GLsizeiptr segmentSizeBytes = segmentLength * vertexPointsPerVoxel * sizeof(GLfloat);
1133 GLfloat* readVerticesFrom = _readVerticesArray + (segmentStart * vertexPointsPerVoxel);1162 GLfloat* readVerticesFrom = _readVerticesArray + (segmentStart * vertexPointsPerVoxel);
1134 glBindBuffer(GL_ARRAY_BUFFER, _vboVerticesID);1163
1135 glBufferSubData(GL_ARRAY_BUFFER, segmentStartAt, segmentSizeBytes, readVerticesFrom);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
1136 segmentStartAt = segmentStart * vertexPointsPerVoxel * sizeof(GLubyte);1174 segmentStartAt = segmentStart * vertexPointsPerVoxel * sizeof(GLubyte);
1137 segmentSizeBytes = segmentLength * vertexPointsPerVoxel * sizeof(GLubyte);1175 segmentSizeBytes = segmentLength * vertexPointsPerVoxel * sizeof(GLubyte);
1138 GLubyte* readColorsFrom = _readColorsArray + (segmentStart * vertexPointsPerVoxel);1176 GLubyte* readColorsFrom = _readColorsArray + (segmentStart * vertexPointsPerVoxel);
1139 glBindBuffer(GL_ARRAY_BUFFER, _vboColorsID);1177
1140 glBufferSubData(GL_ARRAY_BUFFER, segmentStartAt, segmentSizeBytes, readColorsFrom);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 }
1141 }1187 }
1142}1188}
1143 1189
1144void VoxelSystem::render(bool texture) {1190void 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()");
1146 1193
1147 // If we got here and we're not initialized then bail!1194 // If we got here and we're not initialized then bail!
1148 if (!_initialized) {1195 if (!_initialized) {
@@ -1154,8 +1201,7 @@ void VoxelSystem::render(bool texture) { · 5 unmodified lines
1154 bool dontCallOpenGLDraw = Menu::getInstance()->isOptionChecked(MenuOption::DontCallOpenGLForVoxels);1201 bool dontCallOpenGLDraw = Menu::getInstance()->isOptionChecked(MenuOption::DontCallOpenGLForVoxels);
1155 // if not don't... then do...1202 // if not don't... then do...
1156 if (_useVoxelShader) {1203 if (_useVoxelShader) {
1157 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), 1204 PerformanceWarning warn(showWarnings,"render().. _useVoxelShader openGL..");
1158 "render().. _useVoxelShader openGL..");
1159 1205
1160 1206
1161 //Define this somewhere in your header file1207 //Define this somewhere in your header file
@@ -1201,68 +1247,78 @@ void VoxelSystem::render(bool texture) { · 39 unmodified lines
1201 glDisableVertexAttribArray(attributeLocation);1247 glDisableVertexAttribArray(attributeLocation);
1202 }1248 }
1203 } else {1249 } else {
1204 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "render().. openGL...");1250 PerformanceWarning warn(showWarnings, "render().. TRIANGLES...");
1205 1251
1206 // tell OpenGL where to find vertex and color information1252 {
1207 glEnableClientState(GL_VERTEX_ARRAY);1253 PerformanceWarning warn(showWarnings,"render().. setup before glDrawRangeElementsEXT()...");
1208 glEnableClientState(GL_COLOR_ARRAY);1254
1255 // tell OpenGL where to find vertex and color information
1256 glEnableClientState(GL_VERTEX_ARRAY);
1257 glEnableClientState(GL_COLOR_ARRAY);
1209 1258
1210 glBindBuffer(GL_ARRAY_BUFFER, _vboVerticesID);1259 glBindBuffer(GL_ARRAY_BUFFER, _vboVerticesID);
1211 glVertexPointer(3, GL_FLOAT, 0, 0);1260 glVertexPointer(3, GL_FLOAT, 0, 0);
1212 1261
1213 glBindBuffer(GL_ARRAY_BUFFER, _vboColorsID);1262 glBindBuffer(GL_ARRAY_BUFFER, _vboColorsID);
1214 glColorPointer(3, GL_UNSIGNED_BYTE, 0, 0);1263 glColorPointer(3, GL_UNSIGNED_BYTE, 0, 0);
1215 1264
1216 applyScaleAndBindProgram(texture);1265 applyScaleAndBindProgram(texture);
1217 1266
1218 // for performance, enable backface culling1267 // for performance, enable backface culling
1219 glEnable(GL_CULL_FACE);1268 glEnable(GL_CULL_FACE);
1269 }
1220 1270
1221 // draw voxels in 6 passes1271 // draw voxels in 6 passes
1222 1272
1223 if (!dontCallOpenGLDraw) {1273 if (!dontCallOpenGLDraw) {
1274 PerformanceWarning warn(showWarnings, "render().. glDrawRangeElementsEXT()...");
1275
1224 glNormal3f(0,1.0f,0);1276 glNormal3f(0,1.0f,0);
1225 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesTop);1277 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,
1227 INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);1279 INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
1228 1280
1229 glNormal3f(0,-1.0f,0);1281 glNormal3f(0,-1.0f,0);
1230 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesBottom);1282 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,
1232 INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);1284 INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
1233 1285
1234 glNormal3f(-1.0f,0,0);1286 glNormal3f(-1.0f,0,0);
1235 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesLeft);1287 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,
1237 INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);1289 INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
1238 1290
1239 glNormal3f(1.0f,0,0);1291 glNormal3f(1.0f,0,0);
1240 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesRight);1292 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,
1242 INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);1294 INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
1243 1295
1244 glNormal3f(0,0,-1.0f);1296 glNormal3f(0,0,-1.0f);
1245 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesFront);1297 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,
1247 INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);1299 INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
1248 1300
1249 glNormal3f(0,0,1.0f);1301 glNormal3f(0,0,1.0f);
1250 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndicesBack);1302 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,
1252 INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);1304 INDICES_PER_FACE * _voxelsInReadArrays, GL_UNSIGNED_INT, 0);
1253 }1305 }
1254 1306
1255 glDisable(GL_CULL_FACE);1307 {
1308 PerformanceWarning warn(showWarnings, "render().. cleanup after glDrawRangeElementsEXT()...");
1309
1310 glDisable(GL_CULL_FACE);
1256 1311
1257 removeScaleAndReleaseProgram(texture);1312 removeScaleAndReleaseProgram(texture);
1258 1313
1259 // deactivate vertex and color arrays after drawing1314 // deactivate vertex and color arrays after drawing
1260 glDisableClientState(GL_VERTEX_ARRAY);1315 glDisableClientState(GL_VERTEX_ARRAY);
1261 glDisableClientState(GL_COLOR_ARRAY);1316 glDisableClientState(GL_COLOR_ARRAY);
1262 1317
1263 // bind with 0 to switch back to normal operation1318 // bind with 0 to switch back to normal operation
1264 glBindBuffer(GL_ARRAY_BUFFER, 0);1319 glBindBuffer(GL_ARRAY_BUFFER, 0);
1265 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);1320 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
1321 }
1266 }1322 }
1267}1323}
1268 1324
@@ -1527,11 +1583,11 @@ public: · 258 unmodified lines
1527 VoxelSystem* thisVoxelSystem;1583 VoxelSystem* thisVoxelSystem;
1528 ViewFrustum thisViewFrustum;1584 ViewFrustum thisViewFrustum;
1529 VoxelNodeBag dontRecurseBag;1585 VoxelNodeBag dontRecurseBag;
1530 unsigned long nodesScanned;1586 unsigned long nodesScanned;
1531 unsigned long nodesRemoved;1587 unsigned long nodesRemoved;
1532 unsigned long nodesInside;1588 unsigned long nodesInside;
1533 unsigned long nodesIntersect;1589 unsigned long nodesIntersect;
1534 unsigned long nodesOutside;1590 unsigned long nodesOutside;
1535 VoxelNode* insideRoot;1591 VoxelNode* insideRoot;
1536 VoxelNode* outsideRoot;1592 VoxelNode* outsideRoot;
1537 1593
@@ -1612,10 +1668,10 @@ bool VoxelSystem::removeOutOfViewOperation(VoxelNode* node, void* extraData) { · 74 unmodified lines
1612bool VoxelSystem::isViewChanging() {1668bool VoxelSystem::isViewChanging() {
1613 bool result = false; // assume the best1669 bool result = false; // assume the best
1614 1670
1615 // If our viewFrustum has changed since our _lastKnowViewFrustum1671 // If our viewFrustum has changed since our _lastKnownViewFrustum
1616 if (!_lastKnowViewFrustum.matches(_viewFrustum)) {1672 if (!_lastKnownViewFrustum.matches(_viewFrustum)) {
1617 result = true;1673 result = true;
1618 _lastKnowViewFrustum = *_viewFrustum; // save last known1674 _lastKnownViewFrustum = *_viewFrustum; // save last known
1619 }1675 }
1620 return result;1676 return result;
1621}1677}
@@ -1628,7 +1684,7 @@ bool VoxelSystem::hasViewChanged() { · 6 unmodified lines
1628 return false;1684 return false;
1629 }1685 }
1630 1686
1631 // If our viewFrustum has changed since our _lastKnowViewFrustum1687 // If our viewFrustum has changed since our _lastKnownViewFrustum
1632 if (!_lastStableViewFrustum.matches(_viewFrustum)) {1688 if (!_lastStableViewFrustum.matches(_viewFrustum)) {
1633 result = true;1689 result = true;
1634 _lastStableViewFrustum = *_viewFrustum; // save last stable1690 _lastStableViewFrustum = *_viewFrustum; // save last stable
@@ -1653,27 +1709,92 @@ void VoxelSystem::removeOutOfView() { · 18 unmodified lines
1653 }1709 }
1654}1710}
1655 1711
1712// combines the removeOutOfView args into a single class
1713class showAllLocalVoxelsArgs {
1714public:
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
1727void 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
1738bool 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
1656// combines the removeOutOfView args into a single class1760// combines the removeOutOfView args into a single class
1657class hideOutOfViewArgs {1761class hideOutOfViewArgs {
1658public:1762public:
1659 VoxelSystem* thisVoxelSystem;1763 VoxelSystem* thisVoxelSystem;
1660 VoxelTree* tree;1764 VoxelTree* tree;
1661 ViewFrustum thisViewFrustum;1765 ViewFrustum thisViewFrustum;
1662 unsigned long nodesScanned;1766 ViewFrustum lastViewFrustum;
1663 unsigned long nodesRemoved;1767 bool culledOnce;
1664 unsigned long nodesInside;1768 bool wantDeltaFrustums;
1665 unsigned long nodesIntersect;1769 unsigned long nodesScanned;
1666 unsigned long nodesOutside;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;
1667 1779
1668 hideOutOfViewArgs(VoxelSystem* voxelSystem, VoxelTree* tree, bool widenViewFrustum = true) :1780 hideOutOfViewArgs(VoxelSystem* voxelSystem, VoxelTree* tree,
1781 bool culledOnce, bool widenViewFrustum, bool wantDeltaFrustums) :
1669 thisVoxelSystem(voxelSystem),1782 thisVoxelSystem(voxelSystem),
1670 tree(tree),1783 tree(tree),
1671 thisViewFrustum(*voxelSystem->getViewFrustum()),1784 thisViewFrustum(*voxelSystem->getViewFrustum()),
1785 lastViewFrustum(*voxelSystem->getLastCulledViewFrustum()),
1786 culledOnce(culledOnce),
1787 wantDeltaFrustums(wantDeltaFrustums),
1672 nodesScanned(0),1788 nodesScanned(0),
1673 nodesRemoved(0),1789 nodesRemoved(0),
1674 nodesInside(0),1790 nodesInside(0),
1675 nodesIntersect(0),1791 nodesIntersect(0),
1676 nodesOutside(0)1792 nodesOutside(0),
1793 nodesInsideInside(0),
1794 nodesIntersectInside(0),
1795 nodesOutsideInside(0),
1796 nodesInsideOutside(0),
1797 nodesOutsideOutside(0)
1677 {1798 {
1678 // Widen the FOV for trimming1799 // Widen the FOV for trimming
1679 if (widenViewFrustum) {1800 if (widenViewFrustum) {
@@ -1686,9 +1807,67 @@ public: · 6 unmodified lines
1686};1807};
1687 1808
1688void VoxelSystem::hideOutOfView() {1809void VoxelSystem::hideOutOfView() {
1689 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "hideOutOfView()");1810 bool showDebugDetails = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
1690 hideOutOfViewArgs args(this, this->_tree, true); // widen to match server!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
1691 _tree->recurseTreeWithOperation(hideOutOfViewOperation,(void*)&args);1868 _tree->recurseTreeWithOperation(hideOutOfViewOperation,(void*)&args);
1869 _lastCulledViewFrustum = args.thisViewFrustum; // save last stable
1870 _culledOnce = true;
1692 1871
1693 if (args.nodesRemoved) {1872 if (args.nodesRemoved) {
1694 _tree->setDirtyBit();1873 _tree->setDirtyBit();
@@ -1696,24 +1875,47 @@ void VoxelSystem::hideOutOfView() { · 1 unmodified line
1696 }1875 }
1697 1876
1698 1877
1699 bool showRemoveDebugDetails = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);1878 if (showDebugDetails) {
1700 if (showRemoveDebugDetails) {
1701 qDebug("hideOutOfView() scanned=%ld removed=%ld inside=%ld intersect=%ld outside=%ld\n", 1879 qDebug("hideOutOfView() scanned=%ld removed=%ld inside=%ld intersect=%ld outside=%ld\n",
1702 args.nodesScanned, args.nodesRemoved, args.nodesInside, 1880 args.nodesScanned, args.nodesRemoved, args.nodesInside,
1703 args.nodesIntersect, args.nodesOutside1881 args.nodesIntersect, args.nodesOutside
1704 );1882 );
1883 qDebug(" inside/inside=%ld intersect/inside=%ld outside/outside=%ld\n",
1884 args.nodesInsideInside, args.nodesIntersectInside, args.nodesOutsideOutside
1885 );
1705 }1886 }
1706}1887}
1707 1888
1708bool VoxelSystem::hideAllSubTreeOperation(VoxelNode* node, void* extraData) {1889bool VoxelSystem::hideAllSubTreeOperation(VoxelNode* node, void* extraData) {
1709 hideOutOfViewArgs* args = (hideOutOfViewArgs*)extraData;1890 hideOutOfViewArgs* args = (hideOutOfViewArgs*)extraData;
1710 1891
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
1711 args->nodesOutside++;1907 args->nodesOutside++;
1712 if (node->isKnownBufferIndex()) {1908 if (node->isKnownBufferIndex()) {
1713 args->nodesRemoved++;1909 args->nodesRemoved++;
1714 VoxelSystem* thisVoxelSystem = args->thisVoxelSystem;1910 bool falseColorize = false;
1715 thisVoxelSystem->_voxelsUpdated += thisVoxelSystem->forceRemoveNodeFromArrays(node);1911 if (falseColorize) {
1716 thisVoxelSystem->setupNewVoxelsForDrawingSingleNode();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
1717 }1919 }
1718 1920
1719 return true;1921 return true;
@@ -1722,17 +1924,40 @@ bool VoxelSystem::hideAllSubTreeOperation(VoxelNode* node, void* extraData) { · 2 unmodified lines
1722bool VoxelSystem::showAllSubTreeOperation(VoxelNode* node, void* extraData) {1924bool VoxelSystem::showAllSubTreeOperation(VoxelNode* node, void* extraData) {
1723 hideOutOfViewArgs* args = (hideOutOfViewArgs*)extraData;1925 hideOutOfViewArgs* args = (hideOutOfViewArgs*)extraData;
1724 1926
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
1725 args->nodesInside++;1942 args->nodesInside++;
1726 1943
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 }
1728 node->setDirtyBit(); // will this make it draw!1954 node->setDirtyBit(); // will this make it draw!
1955 node->markWithChangedTime(); // fake
1729 }1956 }
1730 1957
1731 return true; // keep recursing!1958 return true; // keep recursing!
1732}1959}
1733 1960
1734
1735
1736// "hide" voxels in the VBOs that are still in the tree that but not in view. 1961// "hide" voxels in the VBOs that are still in the tree that but not in view.
1737// We don't remove them from the tree, we don't delete them, we do remove them1962// We don't remove them from the tree, we don't delete them, we do remove them
1738// from the VBOs and mark them as such in the tree.1963// 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
1742 // If we're still recursing the tree using this operator, then we don't know if we're inside or outside... 1967 // If we're still recursing the tree using this operator, then we don't know if we're inside or outside...
1743 // so before we move forward we need to determine our frustum location1968 // so before we move forward we need to determine our frustum location
1744 ViewFrustum::location inFrustum = node->inFrustum(args->thisViewFrustum);1969 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 }
1745 1979
1746 // ok, now do some processing for this node...1980 // ok, now do some processing for this node...
1747 switch (inFrustum) {1981 switch (inFrustum) {
1748 case ViewFrustum::OUTSIDE: {1982 case ViewFrustum::OUTSIDE: {
1749 // if this node is fully OUTSIDE the view, then we know that ALL of it's children are also fully OUTSIDE1983
1750 // so we can recurse the children and simply mark them as hidden1984 // 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
1751 args->tree->recurseNodeWithOperation(node, hideAllSubTreeOperation, args );1996 args->tree->recurseNodeWithOperation(node, hideAllSubTreeOperation, args );
1752 1997
1753 return false;1998 return false;
1754 1999
1755 } break;2000 } break;
1756 case ViewFrustum::INSIDE: {2001 case ViewFrustum::INSIDE: {
1757 // if this node is fully INSIDE the view, then we know that ALL of it's children are also fully INSIDE2002
1758 // so we can recurse the children and simply mark them as visible (as appropriate based on LOD)2003 // If this node is INSIDE the current view, then we might want to show it... unless it was previously INSIDE,
1759 args->tree->recurseNodeWithOperation(node, showAllSubTreeOperation, args );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);
1760 2017
1761 return false; 2018 return false;
1762 } break;2019 } break;
1763 case ViewFrustum::INTERSECT: {2020 case ViewFrustum::INTERSECT: {
1764 args->nodesScanned++;2021 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
1765 args->nodesIntersect++;2031 args->nodesIntersect++;
1766 2032
1767 // if the child node INTERSECTs the view, then we want to check to see if it thinks it should render2033 // 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
1887};2153};
1888 2154
1889bool VoxelSystem::collectStatsForTreesAndVBOsOperation(VoxelNode* node, void* extraData) {2155bool VoxelSystem::collectStatsForTreesAndVBOsOperation(VoxelNode* node, void* extraData) {
2156
1890 collectStatsForTreesAndVBOsArgs* args = (collectStatsForTreesAndVBOsArgs*)extraData;2157 collectStatsForTreesAndVBOsArgs* args = (collectStatsForTreesAndVBOsArgs*)extraData;
1891 args->totalNodes++;2158 args->totalNodes++;
1892 2159

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