History

Fixed voxel trails from animations - removed stageForDeletion behavior of VoxelNode - replaced with VoxelNodeDeletionHook strategy - VoxelSystem now cleans up previously used VBO index slots via hook

ZappoMan committed 13 years ago

Commit 0c95dc41 parent 79648ce7 files · +59 −72Browse files

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

Unified · Split

interface/src/VoxelSystem.cpp+37−29
@@ -58,6 +58,32 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) : · 57 unmodified lines
58 _tree = new VoxelTree();58 _tree = new VoxelTree();
59 pthread_mutex_init(&_bufferWriteLock, NULL);59 pthread_mutex_init(&_bufferWriteLock, NULL);
60 pthread_mutex_init(&_treeLock, NULL);60 pthread_mutex_init(&_treeLock, NULL);
61
62 _hookID = VoxelNode::addDeleteHook(voxelNodeDeleteHook, (void*)this);
63}
64
65void VoxelSystem::voxelNodeDeleteHook(VoxelNode* node, void* extraData) {
66 VoxelSystem* theSystem = (VoxelSystem*)extraData;
67
68 if (node->isKnownBufferIndex()) {
69 theSystem->freeBufferIndex(node->getBufferIndex());
70 }
71}
72
73void VoxelSystem::freeBufferIndex(glBufferIndex index) {
74 _freeIdexes.push_back(index);
75}
76
77void VoxelSystem::clearFreeBufferIndexes() {
78 for (int i = 0; i < _freeIdexes.size(); i++) {
79 glBufferIndex nodeIndex = _freeIdexes[i];
80 glm::vec3 startVertex(FLT_MAX, FLT_MAX, FLT_MAX);
81 float voxelScale = 0;
82 _writeVoxelDirtyArray[nodeIndex] = true;
83 nodeColor color = { 0, 0, 0, 0};
84 updateNodeInArrays(nodeIndex, startVertex, voxelScale, color);
85 }
86 _freeIdexes.clear();
61}87}
62 88
63VoxelSystem::~VoxelSystem() {89VoxelSystem::~VoxelSystem() {
@@ -70,6 +96,8 @@ VoxelSystem::~VoxelSystem() { · 6 unmodified lines
70 delete _tree;96 delete _tree;
71 pthread_mutex_destroy(&_bufferWriteLock);97 pthread_mutex_destroy(&_bufferWriteLock);
72 pthread_mutex_destroy(&_treeLock);98 pthread_mutex_destroy(&_treeLock);
99
100 VoxelNode::removeDeleteHook(_hookID);
73}101}
74 102
75void VoxelSystem::loadVoxelsFile(const char* fileName, bool wantColorRandomizer) {103void VoxelSystem::loadVoxelsFile(const char* fileName, bool wantColorRandomizer) {
@@ -173,6 +201,9 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 97 unmodified lines
173 PerformanceWarning warn(_renderWarningsOn, "setupNewVoxelsForDrawing()"); // would like to include _voxelsInArrays, _voxelsUpdated201 PerformanceWarning warn(_renderWarningsOn, "setupNewVoxelsForDrawing()"); // would like to include _voxelsInArrays, _voxelsUpdated
174 uint64_t start = usecTimestampNow();202 uint64_t start = usecTimestampNow();
175 uint64_t sinceLastTime = (start - _setupNewVoxelsForDrawingLastFinished) / 1000;203 uint64_t sinceLastTime = (start - _setupNewVoxelsForDrawingLastFinished) / 1000;
204
205 // clear up the VBOs for any nodes that have been recently deleted.
206 clearFreeBufferIndexes();
176 207
177 bool iAmDebugging = false; // if you're debugging set this to true, so you won't get skipped for slow debugging208 bool iAmDebugging = false; // if you're debugging set this to true, so you won't get skipped for slow debugging
178 if (!iAmDebugging && sinceLastTime <= std::max((float) _setupNewVoxelsForDrawingLastElapsed, SIXTY_FPS_IN_MILLISECONDS)) {209 if (!iAmDebugging && sinceLastTime <= std::max((float) _setupNewVoxelsForDrawingLastElapsed, SIXTY_FPS_IN_MILLISECONDS)) {
@@ -182,7 +213,7 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 3 unmodified lines
182 uint64_t sinceLastViewCulling = (start - _lastViewCulling) / 1000;213 uint64_t sinceLastViewCulling = (start - _lastViewCulling) / 1000;
183 // If the view frustum is no longer changing, but has changed, since last time, then remove nodes that are out of view214 // If the view frustum is no longer changing, but has changed, since last time, then remove nodes that are out of view
184 if ((sinceLastViewCulling >= std::max((float) _lastViewCullingElapsed, VIEW_CULLING_RATE_IN_MILLISECONDS))215 if ((sinceLastViewCulling >= std::max((float) _lastViewCullingElapsed, VIEW_CULLING_RATE_IN_MILLISECONDS))
185 && !isViewChanging() && hasViewChanged()) {216 && !isViewChanging()) {
186 _lastViewCulling = start;217 _lastViewCulling = start;
187 218
188 // When we call removeOutOfView() voxels, we don't actually remove the voxels from the VBOs, but we do remove219 // When we call removeOutOfView() voxels, we don't actually remove the voxels from the VBOs, but we do remove
@@ -239,6 +270,7 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 50 unmodified lines
239}270}
240 271
241void VoxelSystem::cleanupRemovedVoxels() {272void VoxelSystem::cleanupRemovedVoxels() {
273 //printf("cleanupRemovedVoxels...\n");
242 PerformanceWarning warn(_renderWarningsOn, "cleanupRemovedVoxels()");274 PerformanceWarning warn(_renderWarningsOn, "cleanupRemovedVoxels()");
243 if (!_removedVoxels.isEmpty()) {275 if (!_removedVoxels.isEmpty()) {
244 while (!_removedVoxels.isEmpty()) {276 while (!_removedVoxels.isEmpty()) {
@@ -323,7 +355,7 @@ int VoxelSystem::newTreeToArrays(VoxelNode* node) { · 78 unmodified lines
323 bool shouldRender = false; // assume we don't need to render it355 bool shouldRender = false; // assume we don't need to render it
324 // if it's colored, we might need to render it!356 // if it's colored, we might need to render it!
325 shouldRender = node->calculateShouldRender(Application::getInstance()->getViewFrustum());357 shouldRender = node->calculateShouldRender(Application::getInstance()->getViewFrustum());
326 node->setShouldRender(shouldRender && !node->isStagedForDeletion());358 node->setShouldRender(shouldRender);
327 // let children figure out their renderness359 // let children figure out their renderness
328 if (!node->isLeaf()) {360 if (!node->isLeaf()) {
329 for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {361 for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
@@ -339,13 +371,6 @@ int VoxelSystem::newTreeToArrays(VoxelNode* node) { · 9 unmodified lines
339 }371 }
340 node->clearDirtyBit(); // clear the dirty bit, do this before we potentially delete things.372 node->clearDirtyBit(); // clear the dirty bit, do this before we potentially delete things.
341 373
342 // If the node has been asked to be deleted, but we've gotten to here, after updateNodeInArraysXXX()
343 // then it means our VBOs are "clean" and our vertices have been removed or not added. So we can now
344 // safely remove the node from the tree and actually delete it.
345 if (node->isStagedForDeletion()) {
346 _tree->deleteVoxelCodeFromTree(node->getOctalCode());
347 }
348
349 return voxelsUpdated;374 return voxelsUpdated;
350}375}
351 376
@@ -1111,7 +1136,7 @@ void VoxelSystem::collectStatsForTreesAndVBOs() { · 759 unmodified lines
1111void VoxelSystem::deleteVoxelAt(float x, float y, float z, float s) {1136void VoxelSystem::deleteVoxelAt(float x, float y, float z, float s) {
1112 pthread_mutex_lock(&_treeLock);1137 pthread_mutex_lock(&_treeLock);
1113 1138
1114 _tree->deleteVoxelAt(x, y, z, s, true);1139 _tree->deleteVoxelAt(x, y, z, s);
1115 1140
1116 // redraw!1141 // redraw!
1117 setupNewVoxelsForDrawing(); // do we even need to do this? Or will the next network receive kick in?1142 setupNewVoxelsForDrawing(); // do we even need to do this? Or will the next network receive kick in?
@@ -1167,7 +1192,6 @@ struct FalseColorizeOccludedArgs { · 49 unmodified lines
1167 long nonLeaves;1192 long nonLeaves;
1168 long nonLeavesOutOfView;1193 long nonLeavesOutOfView;
1169 long nonLeavesOccluded;1194 long nonLeavesOccluded;
1170 long stagedForDeletion;
1171};1195};
1172 1196
1173struct FalseColorizeSubTreeOperationArgs {1197struct FalseColorizeSubTreeOperationArgs {
@@ -1189,12 +1213,6 @@ bool VoxelSystem::falseColorizeOccludedOperation(VoxelNode* node, void* extraDat · 15 unmodified lines
1189 FalseColorizeOccludedArgs* args = (FalseColorizeOccludedArgs*) extraData;1213 FalseColorizeOccludedArgs* args = (FalseColorizeOccludedArgs*) extraData;
1190 args->totalVoxels++;1214 args->totalVoxels++;
1191 1215
1192 // if this node is staged for deletion, then just return
1193 if (node->isStagedForDeletion()) {
1194 args->stagedForDeletion++;
1195 return true;
1196 }
1197
1198 // If we are a parent, let's see if we're completely occluded.1216 // If we are a parent, let's see if we're completely occluded.
1199 if (!node->isLeaf()) {1217 if (!node->isLeaf()) {
1200 args->nonLeaves++;1218 args->nonLeaves++;
@@ -1275,7 +1293,6 @@ void VoxelSystem::falseColorizeOccluded() { · 74 unmodified lines
1275 args.outOfView = 0;1293 args.outOfView = 0;
1276 args.subtreeVoxelsSkipped = 0;1294 args.subtreeVoxelsSkipped = 0;
1277 args.nonLeaves = 0;1295 args.nonLeaves = 0;
1278 args.stagedForDeletion = 0;
1279 args.nonLeavesOutOfView = 0;1296 args.nonLeavesOutOfView = 0;
1280 args.nonLeavesOccluded = 0;1297 args.nonLeavesOccluded = 0;
1281 args.tree = _tree;1298 args.tree = _tree;
@@ -1288,11 +1305,10 @@ void VoxelSystem::falseColorizeOccluded() { · 6 unmodified lines
1288 1305
1289 _tree->recurseTreeWithOperationDistanceSorted(falseColorizeOccludedOperation, position, (void*)&args);1306 _tree->recurseTreeWithOperationDistanceSorted(falseColorizeOccludedOperation, position, (void*)&args);
1290 1307
1291 qDebug("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", 1308 qDebug("falseColorizeOccluded()\n position=(%f,%f)\n total=%ld\n colored=%ld\n occluded=%ld\n notOccluded=%ld\n outOfView=%ld\n subtreeVoxelsSkipped=%ld\n nonLeaves=%ld\n nonLeavesOutOfView=%ld\n nonLeavesOccluded=%ld\n pointInside_calls=%ld\n occludes_calls=%ld\n intersects_calls=%ld\n",
1292 position.x, position.y,1309 position.x, position.y,
1293 args.totalVoxels, args.coloredVoxels, args.occludedVoxels, 1310 args.totalVoxels, args.coloredVoxels, args.occludedVoxels,
1294 args.notOccludedVoxels, args.outOfView, args.subtreeVoxelsSkipped, 1311 args.notOccludedVoxels, args.outOfView, args.subtreeVoxelsSkipped,
1295 args.stagedForDeletion,
1296 args.nonLeaves, args.nonLeavesOutOfView, args.nonLeavesOccluded,1312 args.nonLeaves, args.nonLeavesOutOfView, args.nonLeavesOccluded,
1297 VoxelProjectedPolygon::pointInside_calls,1313 VoxelProjectedPolygon::pointInside_calls,
1298 VoxelProjectedPolygon::occludes_calls,1314 VoxelProjectedPolygon::occludes_calls,
@@ -1310,12 +1326,6 @@ bool VoxelSystem::falseColorizeOccludedV2Operation(VoxelNode* node, void* extraD · 11 unmodified lines
1310 FalseColorizeOccludedArgs* args = (FalseColorizeOccludedArgs*) extraData;1326 FalseColorizeOccludedArgs* args = (FalseColorizeOccludedArgs*) extraData;
1311 args->totalVoxels++;1327 args->totalVoxels++;
1312 1328
1313 // if this node is staged for deletion, then just return
1314 if (node->isStagedForDeletion()) {
1315 args->stagedForDeletion++;
1316 return true;
1317 }
1318
1319 // If we are a parent, let's see if we're completely occluded.1329 // If we are a parent, let's see if we're completely occluded.
1320 if (!node->isLeaf()) {1330 if (!node->isLeaf()) {
1321 args->nonLeaves++;1331 args->nonLeaves++;
@@ -1404,7 +1414,6 @@ void VoxelSystem::falseColorizeOccludedV2() { · 82 unmodified lines
1404 args.outOfView = 0;1414 args.outOfView = 0;
1405 args.subtreeVoxelsSkipped = 0;1415 args.subtreeVoxelsSkipped = 0;
1406 args.nonLeaves = 0;1416 args.nonLeaves = 0;
1407 args.stagedForDeletion = 0;
1408 args.nonLeavesOutOfView = 0;1417 args.nonLeavesOutOfView = 0;
1409 args.nonLeavesOccluded = 0;1418 args.nonLeavesOccluded = 0;
1410 args.tree = _tree;1419 args.tree = _tree;
@@ -1413,11 +1422,10 @@ void VoxelSystem::falseColorizeOccludedV2() { · 2 unmodified lines
1413 1422
1414 _tree->recurseTreeWithOperationDistanceSorted(falseColorizeOccludedV2Operation, position, (void*)&args);1423 _tree->recurseTreeWithOperationDistanceSorted(falseColorizeOccludedV2Operation, position, (void*)&args);
1415 1424
1416 qDebug("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", 1425 qDebug("falseColorizeOccludedV2()\n position=(%f,%f)\n total=%ld\n colored=%ld\n occluded=%ld\n notOccluded=%ld\n outOfView=%ld\n subtreeVoxelsSkipped=%ld\n nonLeaves=%ld\n nonLeavesOutOfView=%ld\n nonLeavesOccluded=%ld\n pointInside_calls=%ld\n occludes_calls=%ld\n intersects_calls=%ld\n",
1417 position.x, position.y,1426 position.x, position.y,
1418 args.totalVoxels, args.coloredVoxels, args.occludedVoxels, 1427 args.totalVoxels, args.coloredVoxels, args.occludedVoxels,
1419 args.notOccludedVoxels, args.outOfView, args.subtreeVoxelsSkipped, 1428 args.notOccludedVoxels, args.outOfView, args.subtreeVoxelsSkipped,
1420 args.stagedForDeletion,
1421 args.nonLeaves, args.nonLeavesOutOfView, args.nonLeavesOccluded,1429 args.nonLeaves, args.nonLeavesOutOfView, args.nonLeavesOccluded,
1422 VoxelProjectedPolygon::pointInside_calls,1430 VoxelProjectedPolygon::pointInside_calls,
1423 VoxelProjectedPolygon::occludes_calls,1431 VoxelProjectedPolygon::occludes_calls,

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