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
5858 _tree = new VoxelTree();
5959 pthread_mutex_init(&_bufferWriteLock, NULL);
6060 pthread_mutex_init(&_treeLock, NULL);
61+
62+ _hookID = VoxelNode::addDeleteHook(voxelNodeDeleteHook, (void*)this);
63+}
64+
65+void VoxelSystem::voxelNodeDeleteHook(VoxelNode* node, void* extraData) {
66+ VoxelSystem* theSystem = (VoxelSystem*)extraData;
67+
68+ if (node->isKnownBufferIndex()) {
69+ theSystem->freeBufferIndex(node->getBufferIndex());
70+ }
71+}
72+
73+void VoxelSystem::freeBufferIndex(glBufferIndex index) {
74+ _freeIdexes.push_back(index);
75+}
76+
77+void 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();
6187 }
6288
6389 VoxelSystem::~VoxelSystem() {
@@ -70,6 +96,8 @@ VoxelSystem::~VoxelSystem() { · 6 unmodified lines
7096 delete _tree;
7197 pthread_mutex_destroy(&_bufferWriteLock);
7298 pthread_mutex_destroy(&_treeLock);
99+
100+ VoxelNode::removeDeleteHook(_hookID);
73101 }
74102
75103 void VoxelSystem::loadVoxelsFile(const char* fileName, bool wantColorRandomizer) {
@@ -173,6 +201,9 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 97 unmodified lines
173201 PerformanceWarning warn(_renderWarningsOn, "setupNewVoxelsForDrawing()"); // would like to include _voxelsInArrays, _voxelsUpdated
174202 uint64_t start = usecTimestampNow();
175203 uint64_t sinceLastTime = (start - _setupNewVoxelsForDrawingLastFinished) / 1000;
204+
205+ // clear up the VBOs for any nodes that have been recently deleted.
206+ clearFreeBufferIndexes();
176207
177208 bool iAmDebugging = false; // if you're debugging set this to true, so you won't get skipped for slow debugging
178209 if (!iAmDebugging && sinceLastTime <= std::max((float) _setupNewVoxelsForDrawingLastElapsed, SIXTY_FPS_IN_MILLISECONDS)) {
@@ -182,7 +213,7 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 3 unmodified lines
182213 uint64_t sinceLastViewCulling = (start - _lastViewCulling) / 1000;
183214 // If the view frustum is no longer changing, but has changed, since last time, then remove nodes that are out of view
184215 if ((sinceLastViewCulling >= std::max((float) _lastViewCullingElapsed, VIEW_CULLING_RATE_IN_MILLISECONDS))
185− && !isViewChanging() && hasViewChanged()) {
216+ && !isViewChanging()) {
186217 _lastViewCulling = start;
187218
188219 // 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
239270 }
240271
241272 void VoxelSystem::cleanupRemovedVoxels() {
273+ //printf("cleanupRemovedVoxels...\n");
242274 PerformanceWarning warn(_renderWarningsOn, "cleanupRemovedVoxels()");
243275 if (!_removedVoxels.isEmpty()) {
244276 while (!_removedVoxels.isEmpty()) {
@@ -323,7 +355,7 @@ int VoxelSystem::newTreeToArrays(VoxelNode* node) { · 78 unmodified lines
323355 bool shouldRender = false; // assume we don't need to render it
324356 // if it's colored, we might need to render it!
325357 shouldRender = node->calculateShouldRender(Application::getInstance()->getViewFrustum());
326− node->setShouldRender(shouldRender && !node->isStagedForDeletion());
358+ node->setShouldRender(shouldRender);
327359 // let children figure out their renderness
328360 if (!node->isLeaf()) {
329361 for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
@@ -339,13 +371,6 @@ int VoxelSystem::newTreeToArrays(VoxelNode* node) { · 9 unmodified lines
339371 }
340372 node->clearDirtyBit(); // clear the dirty bit, do this before we potentially delete things.
341373
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−
349374 return voxelsUpdated;
350375 }
351376
@@ -1111,7 +1136,7 @@ void VoxelSystem::collectStatsForTreesAndVBOs() { · 759 unmodified lines
11111136 void VoxelSystem::deleteVoxelAt(float x, float y, float z, float s) {
11121137 pthread_mutex_lock(&_treeLock);
11131138
1114− _tree->deleteVoxelAt(x, y, z, s, true);
1139+ _tree->deleteVoxelAt(x, y, z, s);
11151140
11161141 // redraw!
11171142 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
11671192 long nonLeaves;
11681193 long nonLeavesOutOfView;
11691194 long nonLeavesOccluded;
1170− long stagedForDeletion;
11711195 };
11721196
11731197 struct FalseColorizeSubTreeOperationArgs {
@@ -1189,12 +1213,6 @@ bool VoxelSystem::falseColorizeOccludedOperation(VoxelNode* node, void* extraDat · 15 unmodified lines
11891213 FalseColorizeOccludedArgs* args = (FalseColorizeOccludedArgs*) extraData;
11901214 args->totalVoxels++;
11911215
1192− // if this node is staged for deletion, then just return
1193− if (node->isStagedForDeletion()) {
1194− args->stagedForDeletion++;
1195− return true;
1196− }
1197−
11981216 // If we are a parent, let's see if we're completely occluded.
11991217 if (!node->isLeaf()) {
12001218 args->nonLeaves++;
@@ -1275,7 +1293,6 @@ void VoxelSystem::falseColorizeOccluded() { · 74 unmodified lines
12751293 args.outOfView = 0;
12761294 args.subtreeVoxelsSkipped = 0;
12771295 args.nonLeaves = 0;
1278− args.stagedForDeletion = 0;
12791296 args.nonLeavesOutOfView = 0;
12801297 args.nonLeavesOccluded = 0;
12811298 args.tree = _tree;
@@ -1288,11 +1305,10 @@ void VoxelSystem::falseColorizeOccluded() { · 6 unmodified lines
12881305
12891306 _tree->recurseTreeWithOperationDistanceSorted(falseColorizeOccludedOperation, position, (void*)&args);
12901307
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",
12921309 position.x, position.y,
12931310 args.totalVoxels, args.coloredVoxels, args.occludedVoxels,
12941311 args.notOccludedVoxels, args.outOfView, args.subtreeVoxelsSkipped,
1295− args.stagedForDeletion,
12961312 args.nonLeaves, args.nonLeavesOutOfView, args.nonLeavesOccluded,
12971313 VoxelProjectedPolygon::pointInside_calls,
12981314 VoxelProjectedPolygon::occludes_calls,
@@ -1310,12 +1326,6 @@ bool VoxelSystem::falseColorizeOccludedV2Operation(VoxelNode* node, void* extraD · 11 unmodified lines
13101326 FalseColorizeOccludedArgs* args = (FalseColorizeOccludedArgs*) extraData;
13111327 args->totalVoxels++;
13121328
1313− // if this node is staged for deletion, then just return
1314− if (node->isStagedForDeletion()) {
1315− args->stagedForDeletion++;
1316− return true;
1317− }
1318−
13191329 // If we are a parent, let's see if we're completely occluded.
13201330 if (!node->isLeaf()) {
13211331 args->nonLeaves++;
@@ -1404,7 +1414,6 @@ void VoxelSystem::falseColorizeOccludedV2() { · 82 unmodified lines
14041414 args.outOfView = 0;
14051415 args.subtreeVoxelsSkipped = 0;
14061416 args.nonLeaves = 0;
1407− args.stagedForDeletion = 0;
14081417 args.nonLeavesOutOfView = 0;
14091418 args.nonLeavesOccluded = 0;
14101419 args.tree = _tree;
@@ -1413,11 +1422,10 @@ void VoxelSystem::falseColorizeOccludedV2() { · 2 unmodified lines
14131422
14141423 _tree->recurseTreeWithOperationDistanceSorted(falseColorizeOccludedV2Operation, position, (void*)&args);
14151424
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",
14171426 position.x, position.y,
14181427 args.totalVoxels, args.coloredVoxels, args.occludedVoxels,
14191428 args.notOccludedVoxels, args.outOfView, args.subtreeVoxelsSkipped,
1420− args.stagedForDeletion,
14211429 args.nonLeaves, args.nonLeavesOutOfView, args.nonLeavesOccluded,
14221430 VoxelProjectedPolygon::pointInside_calls,
14231431 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