History

resolve conflicts on merge with upstream master

Stephen Birarda committed 13 years ago

Commit fcb88652 parents aaaba9c a1eed4e79 files · +10601 −971Browse files

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

Unified · Split

interface/src/VoxelSystem.cpp+163−21
@@ -23,6 +23,7 @@ · 22 unmodified lines
2323 #include "Log.h"
2424 #include "VoxelConstants.h"
2525 #include "CoverageMap.h"
26+#include "CoverageMapV2.h"
2627 #include "InterfaceConfig.h"
2728 #include "renderer/ProgramObject.h"
2829
@@ -167,17 +168,17 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 138 unmodified lines
167168
168169 void VoxelSystem::setupNewVoxelsForDrawing() {
169170 PerformanceWarning warn(_renderWarningsOn, "setupNewVoxelsForDrawing()"); // would like to include _voxelsInArrays, _voxelsUpdated
170− long long start = usecTimestampNow();
171− long long sinceLastTime = (start - _setupNewVoxelsForDrawingLastFinished) / 1000;
171+ uint64_t start = usecTimestampNow();
172+ uint64_t sinceLastTime = (start - _setupNewVoxelsForDrawingLastFinished) / 1000;
172173
173174 bool iAmDebugging = false; // if you're debugging set this to true, so you won't get skipped for slow debugging
174− if (!iAmDebugging && sinceLastTime <= std::max(_setupNewVoxelsForDrawingLastElapsed, SIXTY_FPS_IN_MILLISECONDS)) {
175+ if (!iAmDebugging && sinceLastTime <= std::max((float) _setupNewVoxelsForDrawingLastElapsed, SIXTY_FPS_IN_MILLISECONDS)) {
175176 return; // bail early, it hasn't been long enough since the last time we ran
176177 }
177178
178− long long sinceLastViewCulling = (start - _lastViewCulling) / 1000;
179+ uint64_t sinceLastViewCulling = (start - _lastViewCulling) / 1000;
179180 // If the view frustum is no longer changing, but has changed, since last time, then remove nodes that are out of view
180− if ((sinceLastViewCulling >= std::max(_lastViewCullingElapsed, VIEW_CULLING_RATE_IN_MILLISECONDS))
181+ if ((sinceLastViewCulling >= std::max((float) _lastViewCullingElapsed, VIEW_CULLING_RATE_IN_MILLISECONDS))
181182 && !isViewChanging() && hasViewChanged()) {
182183 _lastViewCulling = start;
183184
@@ -191,7 +192,7 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 7 unmodified lines
191192 // VBO reubuilding. Possibly we should do this only if our actual VBO usage crosses some lower boundary.
192193 cleanupRemovedVoxels();
193194
194− long long endViewCulling = usecTimestampNow();
195+ uint64_t endViewCulling = usecTimestampNow();
195196 _lastViewCullingElapsed = (endViewCulling - start) / 1000;
196197 }
197198
@@ -228,8 +229,8 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 30 unmodified lines
228229
229230 pthread_mutex_unlock(&_bufferWriteLock);
230231
231− long long end = usecTimestampNow();
232− long long elapsedmsec = (end - start) / 1000;
232+ uint64_t end = usecTimestampNow();
233+ int elapsedmsec = (end - start) / 1000;
233234 _setupNewVoxelsForDrawingLastFinished = end;
234235 _setupNewVoxelsForDrawingLastElapsed = elapsedmsec;
235236 }
@@ -1088,13 +1089,13 @@ void VoxelSystem::collectStatsForTreesAndVBOs() { · 852 unmodified lines
10881089 args.expectedMax = _voxelsInWriteArrays;
10891090 _tree->recurseTreeWithOperation(collectStatsForTreesAndVBOsOperation,&args);
10901091
1091− printLog("_voxelsDirty=%s _voxelsInWriteArrays=%ld minDirty=%ld maxDirty=%ld \n", debug::valueOf(_voxelsDirty),
1092− _voxelsInWriteArrays, minDirty, maxDirty);
1093−
1094− printLog("stats: total %ld, leaves %ld, dirty %ld, colored %ld, shouldRender %ld, inVBO %ld\n",
1092+ printLog("Local Voxel Tree Statistics:\n total nodes %ld \n leaves %ld \n dirty %ld \n colored %ld \n shouldRender %ld \n",
10951093 args.totalNodes, args.leafNodes, args.dirtyNodes, args.coloredNodes, args.shouldRenderNodes);
10961094
1097− printLog("inVBO %ld, nodesInVBOOverExpectedMax %ld, duplicateVBOIndex %ld, nodesInVBONotShouldRender %ld\n",
1095+ printLog(" _voxelsDirty=%s \n _voxelsInWriteArrays=%ld \n minDirty=%ld \n maxDirty=%ld \n", debug::valueOf(_voxelsDirty),
1096+ _voxelsInWriteArrays, minDirty, maxDirty);
1097+
1098+ printLog(" inVBO %ld \n nodesInVBOOverExpectedMax %ld \n duplicateVBOIndex %ld \n nodesInVBONotShouldRender %ld \n",
10981099 args.nodesInVBO, args.nodesInVBOOverExpectedMax, args.duplicateVBOIndex, args.nodesInVBONotShouldRender);
10991100
11001101 glBufferIndex minInVBO = GLBUFFER_INDEX_UNKNOWN;
@@ -1107,7 +1108,7 @@ void VoxelSystem::collectStatsForTreesAndVBOs() { · 6 unmodified lines
11071108 }
11081109 }
11091110
1110− printLog("minInVBO=%ld maxInVBO=%ld _voxelsInWriteArrays=%ld _voxelsInReadArrays=%ld\n",
1111+ printLog(" minInVBO=%ld \n maxInVBO=%ld \n _voxelsInWriteArrays=%ld \n _voxelsInReadArrays=%ld \n",
11111112 minInVBO, maxInVBO, _voxelsInWriteArrays, _voxelsInReadArrays);
11121113
11131114 }
@@ -1161,6 +1162,7 @@ void VoxelSystem::copyFromTreeIntoSubTree(VoxelTree* sourceTree, VoxelNode* dest · 47 unmodified lines
11611162 struct FalseColorizeOccludedArgs {
11621163 ViewFrustum* viewFrustum;
11631164 CoverageMap* map;
1165+ CoverageMapV2* mapV2;
11641166 VoxelTree* tree;
11651167 long totalVoxels;
11661168 long coloredVoxels;
@@ -1180,9 +1182,11 @@ struct FalseColorizeSubTreeOperationArgs { · 13 unmodified lines
11801182 };
11811183
11821184 bool VoxelSystem::falseColorizeSubTreeOperation(VoxelNode* node, void* extraData) {
1183− FalseColorizeSubTreeOperationArgs* args = (FalseColorizeSubTreeOperationArgs*) extraData;
1184− node->setFalseColor(args->color[0], args->color[1], args->color[2]);
1185− args->voxelsTouched++;
1185+ if (node->getShouldRender()) {
1186+ FalseColorizeSubTreeOperationArgs* args = (FalseColorizeSubTreeOperationArgs*) extraData;
1187+ node->setFalseColor(args->color[0], args->color[1], args->color[2]);
1188+ args->voxelsTouched++;
1189+ }
11861190 return true;
11871191 }
11881192
@@ -1262,12 +1266,14 @@ bool VoxelSystem::falseColorizeOccludedOperation(VoxelNode* node, void* extraDat · 73 unmodified lines
12621266 }
12631267 return true; // keep going!
12641268 }
1269+
12651270 void VoxelSystem::falseColorizeOccluded() {
12661271 PerformanceWarning warn(true, "falseColorizeOccluded()",true);
1267− CoverageMap map;
1272+ myCoverageMap.erase();
1273+
12681274 FalseColorizeOccludedArgs args;
12691275 args.viewFrustum = Application::getInstance()->getViewFrustum();
1270− args.map = &map;
1276+ args.map = &myCoverageMap;
12711277 args.totalVoxels = 0;
12721278 args.coloredVoxels = 0;
12731279 args.occludedVoxels = 0;
@@ -1279,18 +1285,154 @@ void VoxelSystem::falseColorizeOccluded() { · 5 unmodified lines
12791285 args.nonLeavesOutOfView = 0;
12801286 args.nonLeavesOccluded = 0;
12811287 args.tree = _tree;
1288+
1289+ VoxelProjectedPolygon::pointInside_calls = 0;
1290+ VoxelProjectedPolygon::occludes_calls = 0;
1291+ VoxelProjectedPolygon::intersects_calls = 0;
12821292
12831293 glm::vec3 position = args.viewFrustum->getPosition() * (1.0f/TREE_SCALE);
12841294
12851295 _tree->recurseTreeWithOperationDistanceSorted(falseColorizeOccludedOperation, position, (void*)&args);
12861296
1287− printLog("falseColorizeOccluded()\n total=%ld\n colored=%ld\n occluded=%ld\n notOccluded=%ld\n outOfView=%ld\n subtreeVoxelsSkipped=%ld\n stagedForDeletion=%ld\n nonLeaves=%ld\n nonLeavesOutOfView=%ld\n nonLeavesOccluded=%ld\n",
1297+ printLog("falseColorizeOccluded()\n position=(%f,%f)\n total=%ld\n colored=%ld\n occluded=%ld\n notOccluded=%ld\n outOfView=%ld\n subtreeVoxelsSkipped=%ld\n stagedForDeletion=%ld\n nonLeaves=%ld\n nonLeavesOutOfView=%ld\n nonLeavesOccluded=%ld\n pointInside_calls=%ld\n occludes_calls=%ld\n intersects_calls=%ld\n",
1298+ position.x, position.y,
1299+ args.totalVoxels, args.coloredVoxels, args.occludedVoxels,
1300+ args.notOccludedVoxels, args.outOfView, args.subtreeVoxelsSkipped,
1301+ args.stagedForDeletion,
1302+ args.nonLeaves, args.nonLeavesOutOfView, args.nonLeavesOccluded,
1303+ VoxelProjectedPolygon::pointInside_calls,
1304+ VoxelProjectedPolygon::occludes_calls,
1305+ VoxelProjectedPolygon::intersects_calls
1306+ );
1307+
1308+
1309+ //myCoverageMap.erase();
1310+
1311+ setupNewVoxelsForDrawing();
1312+}
1313+
1314+bool VoxelSystem::falseColorizeOccludedV2Operation(VoxelNode* node, void* extraData) {
1315+
1316+ FalseColorizeOccludedArgs* args = (FalseColorizeOccludedArgs*) extraData;
1317+ args->totalVoxels++;
1318+
1319+ // if this node is staged for deletion, then just return
1320+ if (node->isStagedForDeletion()) {
1321+ args->stagedForDeletion++;
1322+ return true;
1323+ }
1324+
1325+ // If we are a parent, let's see if we're completely occluded.
1326+ if (!node->isLeaf()) {
1327+ args->nonLeaves++;
1328+
1329+ AABox voxelBox = node->getAABox();
1330+ voxelBox.scale(TREE_SCALE);
1331+ VoxelProjectedPolygon* voxelPolygon = new VoxelProjectedPolygon(args->viewFrustum->getProjectedPolygon(voxelBox));
1332+
1333+ // If we're not all in view, then ignore it, and just return. But keep searching...
1334+ if (!voxelPolygon->getAllInView()) {
1335+ args->nonLeavesOutOfView++;
1336+ delete voxelPolygon;
1337+ return true;
1338+ }
1339+
1340+ CoverageMapV2StorageResult result = args->mapV2->checkMap(voxelPolygon, false);
1341+ if (result == V2_OCCLUDED) {
1342+ args->nonLeavesOccluded++;
1343+ delete voxelPolygon;
1344+
1345+ FalseColorizeSubTreeOperationArgs subArgs;
1346+ subArgs.color[0] = 0;
1347+ subArgs.color[1] = 255;
1348+ subArgs.color[2] = 0;
1349+ subArgs.voxelsTouched = 0;
1350+
1351+ args->tree->recurseNodeWithOperation(node, falseColorizeSubTreeOperation, &subArgs );
1352+
1353+ args->subtreeVoxelsSkipped += (subArgs.voxelsTouched - 1);
1354+ args->totalVoxels += (subArgs.voxelsTouched - 1);
1355+
1356+ return false;
1357+ }
1358+
1359+ delete voxelPolygon;
1360+ return true; // keep looking...
1361+ }
1362+
1363+ if (node->isLeaf() && node->isColored() && node->getShouldRender()) {
1364+ args->coloredVoxels++;
1365+
1366+ AABox voxelBox = node->getAABox();
1367+ voxelBox.scale(TREE_SCALE);
1368+ VoxelProjectedPolygon* voxelPolygon = new VoxelProjectedPolygon(args->viewFrustum->getProjectedPolygon(voxelBox));
1369+
1370+ // If we're not all in view, then ignore it, and just return. But keep searching...
1371+ if (!voxelPolygon->getAllInView()) {
1372+ args->outOfView++;
1373+ delete voxelPolygon;
1374+ return true;
1375+ }
1376+
1377+ CoverageMapV2StorageResult result = args->mapV2->checkMap(voxelPolygon, true);
1378+ if (result == V2_OCCLUDED) {
1379+ node->setFalseColor(255, 0, 0);
1380+ args->occludedVoxels++;
1381+ } else if (result == V2_STORED) {
1382+ args->notOccludedVoxels++;
1383+ //printLog("***** falseColorizeOccludedOperation() NODE is STORED *****\n");
1384+ } else if (result == V2_DOESNT_FIT) {
1385+ //printLog("***** falseColorizeOccludedOperation() NODE DOESNT_FIT???? *****\n");
1386+ }
1387+ delete voxelPolygon; // V2 maps don't store polygons, so we're always in charge of freeing
1388+ }
1389+ return true; // keep going!
1390+}
1391+
1392+
1393+void VoxelSystem::falseColorizeOccludedV2() {
1394+ PerformanceWarning warn(true, "falseColorizeOccludedV2()",true);
1395+ myCoverageMapV2.erase();
1396+
1397+ CoverageMapV2::wantDebugging = true;
1398+
1399+ VoxelProjectedPolygon::pointInside_calls = 0;
1400+ VoxelProjectedPolygon::occludes_calls = 0;
1401+ VoxelProjectedPolygon::intersects_calls = 0;
1402+
1403+ FalseColorizeOccludedArgs args;
1404+ args.viewFrustum = Application::getInstance()->getViewFrustum();
1405+ args.mapV2 = &myCoverageMapV2;
1406+ args.totalVoxels = 0;
1407+ args.coloredVoxels = 0;
1408+ args.occludedVoxels = 0;
1409+ args.notOccludedVoxels = 0;
1410+ args.outOfView = 0;
1411+ args.subtreeVoxelsSkipped = 0;
1412+ args.nonLeaves = 0;
1413+ args.stagedForDeletion = 0;
1414+ args.nonLeavesOutOfView = 0;
1415+ args.nonLeavesOccluded = 0;
1416+ args.tree = _tree;
1417+
1418+ glm::vec3 position = args.viewFrustum->getPosition() * (1.0f/TREE_SCALE);
1419+
1420+ _tree->recurseTreeWithOperationDistanceSorted(falseColorizeOccludedV2Operation, position, (void*)&args);
1421+
1422+ printLog("falseColorizeOccludedV2()\n position=(%f,%f)\n total=%ld\n colored=%ld\n occluded=%ld\n notOccluded=%ld\n outOfView=%ld\n subtreeVoxelsSkipped=%ld\n stagedForDeletion=%ld\n nonLeaves=%ld\n nonLeavesOutOfView=%ld\n nonLeavesOccluded=%ld\n pointInside_calls=%ld\n occludes_calls=%ld\n intersects_calls=%ld\n",
1423+ position.x, position.y,
12881424 args.totalVoxels, args.coloredVoxels, args.occludedVoxels,
12891425 args.notOccludedVoxels, args.outOfView, args.subtreeVoxelsSkipped,
12901426 args.stagedForDeletion,
1291− args.nonLeaves, args.nonLeavesOutOfView, args.nonLeavesOccluded);
1427+ args.nonLeaves, args.nonLeavesOutOfView, args.nonLeavesOccluded,
1428+ VoxelProjectedPolygon::pointInside_calls,
1429+ VoxelProjectedPolygon::occludes_calls,
1430+ VoxelProjectedPolygon::intersects_calls
1431+ );
1432+ //myCoverageMapV2.erase();
12921433
12931434
12941435 setupNewVoxelsForDrawing();
12951436 }
12961437
1438+