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
23#include "Log.h"23#include "Log.h"
24#include "VoxelConstants.h"24#include "VoxelConstants.h"
25#include "CoverageMap.h"25#include "CoverageMap.h"
26#include "CoverageMapV2.h"
26#include "InterfaceConfig.h"27#include "InterfaceConfig.h"
27#include "renderer/ProgramObject.h"28#include "renderer/ProgramObject.h"
28 29
@@ -167,17 +168,17 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 138 unmodified lines
167 168
168void VoxelSystem::setupNewVoxelsForDrawing() {169void VoxelSystem::setupNewVoxelsForDrawing() {
169 PerformanceWarning warn(_renderWarningsOn, "setupNewVoxelsForDrawing()"); // would like to include _voxelsInArrays, _voxelsUpdated170 PerformanceWarning warn(_renderWarningsOn, "setupNewVoxelsForDrawing()"); // would like to include _voxelsInArrays, _voxelsUpdated
170 long long start = usecTimestampNow();171 uint64_t start = usecTimestampNow();
171 long long sinceLastTime = (start - _setupNewVoxelsForDrawingLastFinished) / 1000;172 uint64_t sinceLastTime = (start - _setupNewVoxelsForDrawingLastFinished) / 1000;
172 173
173 bool iAmDebugging = false; // if you're debugging set this to true, so you won't get skipped for slow debugging174 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)) {
175 return; // bail early, it hasn't been long enough since the last time we ran176 return; // bail early, it hasn't been long enough since the last time we ran
176 }177 }
177 178
178 long long sinceLastViewCulling = (start - _lastViewCulling) / 1000;179 uint64_t sinceLastViewCulling = (start - _lastViewCulling) / 1000;
179 // If the view frustum is no longer changing, but has changed, since last time, then remove nodes that are out of view180 // 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))
181 && !isViewChanging() && hasViewChanged()) {182 && !isViewChanging() && hasViewChanged()) {
182 _lastViewCulling = start;183 _lastViewCulling = start;
183 184
@@ -191,7 +192,7 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 7 unmodified lines
191 // VBO reubuilding. Possibly we should do this only if our actual VBO usage crosses some lower boundary.192 // VBO reubuilding. Possibly we should do this only if our actual VBO usage crosses some lower boundary.
192 cleanupRemovedVoxels();193 cleanupRemovedVoxels();
193 194
194 long long endViewCulling = usecTimestampNow();195 uint64_t endViewCulling = usecTimestampNow();
195 _lastViewCullingElapsed = (endViewCulling - start) / 1000;196 _lastViewCullingElapsed = (endViewCulling - start) / 1000;
196 } 197 }
197 198
@@ -228,8 +229,8 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 30 unmodified lines
228 229
229 pthread_mutex_unlock(&_bufferWriteLock);230 pthread_mutex_unlock(&_bufferWriteLock);
230 231
231 long long end = usecTimestampNow();232 uint64_t end = usecTimestampNow();
232 long long elapsedmsec = (end - start) / 1000;233 int elapsedmsec = (end - start) / 1000;
233 _setupNewVoxelsForDrawingLastFinished = end;234 _setupNewVoxelsForDrawingLastFinished = end;
234 _setupNewVoxelsForDrawingLastElapsed = elapsedmsec;235 _setupNewVoxelsForDrawingLastElapsed = elapsedmsec;
235}236}
@@ -1088,13 +1089,13 @@ void VoxelSystem::collectStatsForTreesAndVBOs() { · 852 unmodified lines
1088 args.expectedMax = _voxelsInWriteArrays;1089 args.expectedMax = _voxelsInWriteArrays;
1089 _tree->recurseTreeWithOperation(collectStatsForTreesAndVBOsOperation,&args);1090 _tree->recurseTreeWithOperation(collectStatsForTreesAndVBOsOperation,&args);
1090 1091
1091 printLog("_voxelsDirty=%s _voxelsInWriteArrays=%ld minDirty=%ld maxDirty=%ld \n", debug::valueOf(_voxelsDirty),1092 printLog("Local Voxel Tree Statistics:\n total nodes %ld \n leaves %ld \n dirty %ld \n colored %ld \n shouldRender %ld \n",
1092 _voxelsInWriteArrays, minDirty, maxDirty);
1093
1094 printLog("stats: total %ld, leaves %ld, dirty %ld, colored %ld, shouldRender %ld, inVBO %ld\n",
1095 args.totalNodes, args.leafNodes, args.dirtyNodes, args.coloredNodes, args.shouldRenderNodes);1093 args.totalNodes, args.leafNodes, args.dirtyNodes, args.coloredNodes, args.shouldRenderNodes);
1096 1094
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",
1098 args.nodesInVBO, args.nodesInVBOOverExpectedMax, args.duplicateVBOIndex, args.nodesInVBONotShouldRender);1099 args.nodesInVBO, args.nodesInVBOOverExpectedMax, args.duplicateVBOIndex, args.nodesInVBONotShouldRender);
1099 1100
1100 glBufferIndex minInVBO = GLBUFFER_INDEX_UNKNOWN;1101 glBufferIndex minInVBO = GLBUFFER_INDEX_UNKNOWN;
@@ -1107,7 +1108,7 @@ void VoxelSystem::collectStatsForTreesAndVBOs() { · 6 unmodified lines
1107 }1108 }
1108 }1109 }
1109 1110
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",
1111 minInVBO, maxInVBO, _voxelsInWriteArrays, _voxelsInReadArrays);1112 minInVBO, maxInVBO, _voxelsInWriteArrays, _voxelsInReadArrays);
1112 1113
1113}1114}
@@ -1161,6 +1162,7 @@ void VoxelSystem::copyFromTreeIntoSubTree(VoxelTree* sourceTree, VoxelNode* dest · 47 unmodified lines
1161struct FalseColorizeOccludedArgs {1162struct FalseColorizeOccludedArgs {
1162 ViewFrustum* viewFrustum;1163 ViewFrustum* viewFrustum;
1163 CoverageMap* map;1164 CoverageMap* map;
1165 CoverageMapV2* mapV2;
1164 VoxelTree* tree;1166 VoxelTree* tree;
1165 long totalVoxels;1167 long totalVoxels;
1166 long coloredVoxels;1168 long coloredVoxels;
@@ -1180,9 +1182,11 @@ struct FalseColorizeSubTreeOperationArgs { · 13 unmodified lines
1180};1182};
1181 1183
1182bool VoxelSystem::falseColorizeSubTreeOperation(VoxelNode* node, void* extraData) {1184bool VoxelSystem::falseColorizeSubTreeOperation(VoxelNode* node, void* extraData) {
1183 FalseColorizeSubTreeOperationArgs* args = (FalseColorizeSubTreeOperationArgs*) extraData;1185 if (node->getShouldRender()) {
1184 node->setFalseColor(args->color[0], args->color[1], args->color[2]);1186 FalseColorizeSubTreeOperationArgs* args = (FalseColorizeSubTreeOperationArgs*) extraData;
1185 args->voxelsTouched++;1187 node->setFalseColor(args->color[0], args->color[1], args->color[2]);
1188 args->voxelsTouched++;
1189 }
1186 return true; 1190 return true;
1187}1191}
1188 1192
@@ -1262,12 +1266,14 @@ bool VoxelSystem::falseColorizeOccludedOperation(VoxelNode* node, void* extraDat · 73 unmodified lines
1262 }1266 }
1263 return true; // keep going!1267 return true; // keep going!
1264}1268}
1269
1265void VoxelSystem::falseColorizeOccluded() {1270void VoxelSystem::falseColorizeOccluded() {
1266 PerformanceWarning warn(true, "falseColorizeOccluded()",true);1271 PerformanceWarning warn(true, "falseColorizeOccluded()",true);
1267 CoverageMap map;1272 myCoverageMap.erase();
1273
1268 FalseColorizeOccludedArgs args;1274 FalseColorizeOccludedArgs args;
1269 args.viewFrustum = Application::getInstance()->getViewFrustum();1275 args.viewFrustum = Application::getInstance()->getViewFrustum();
1270 args.map = &map; 1276 args.map = &myCoverageMap;
1271 args.totalVoxels = 0;1277 args.totalVoxels = 0;
1272 args.coloredVoxels = 0;1278 args.coloredVoxels = 0;
1273 args.occludedVoxels = 0;1279 args.occludedVoxels = 0;
@@ -1279,18 +1285,154 @@ void VoxelSystem::falseColorizeOccluded() { · 5 unmodified lines
1279 args.nonLeavesOutOfView = 0;1285 args.nonLeavesOutOfView = 0;
1280 args.nonLeavesOccluded = 0;1286 args.nonLeavesOccluded = 0;
1281 args.tree = _tree;1287 args.tree = _tree;
1288
1289 VoxelProjectedPolygon::pointInside_calls = 0;
1290 VoxelProjectedPolygon::occludes_calls = 0;
1291 VoxelProjectedPolygon::intersects_calls = 0;
1282 1292
1283 glm::vec3 position = args.viewFrustum->getPosition() * (1.0f/TREE_SCALE);1293 glm::vec3 position = args.viewFrustum->getPosition() * (1.0f/TREE_SCALE);
1284 1294
1285 _tree->recurseTreeWithOperationDistanceSorted(falseColorizeOccludedOperation, position, (void*)&args);1295 _tree->recurseTreeWithOperationDistanceSorted(falseColorizeOccludedOperation, position, (void*)&args);
1286 1296
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
1314bool 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
1393void 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,
1288 args.totalVoxels, args.coloredVoxels, args.occludedVoxels, 1424 args.totalVoxels, args.coloredVoxels, args.occludedVoxels,
1289 args.notOccludedVoxels, args.outOfView, args.subtreeVoxelsSkipped, 1425 args.notOccludedVoxels, args.outOfView, args.subtreeVoxelsSkipped,
1290 args.stagedForDeletion, 1426 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();
1292 1433
1293 1434
1294 setupNewVoxelsForDrawing();1435 setupNewVoxelsForDrawing();
1295}1436}
1296 1437
1438