History

Fixed issue with freeing up abandoned VBO slots when not moving with animation

ZappoMan committed 13 years ago

Commit 4cca7e21 parent 0c95dc42 files · +15 −3Browse files

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

Unified · Split

interface/src/VoxelSystem.cpp+14−2
@@ -60,6 +60,7 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) : · 59 unmodified lines
6060 pthread_mutex_init(&_treeLock, NULL);
6161
6262 _hookID = VoxelNode::addDeleteHook(voxelNodeDeleteHook, (void*)this);
63+ _abandonedVBOSlots = 0;
6364 }
6465
6566 void VoxelSystem::voxelNodeDeleteHook(VoxelNode* node, void* extraData) {
@@ -82,6 +83,7 @@ void VoxelSystem::clearFreeBufferIndexes() { · 16 unmodified lines
8283 _writeVoxelDirtyArray[nodeIndex] = true;
8384 nodeColor color = { 0, 0, 0, 0};
8485 updateNodeInArrays(nodeIndex, startVertex, voxelScale, color);
86+ _abandonedVBOSlots++;
8587 }
8688 _freeIdexes.clear();
8789 }
@@ -243,6 +245,10 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 155 unmodified lines
243245 }
244246 _voxelsUpdated = newTreeToArrays(_tree->rootNode);
245247 _tree->clearDirtyBit(); // after we pull the trees into the array, we can consider the tree clean
248+
249+ if (_writeRenderFullVBO) {
250+ _abandonedVBOSlots = 0; // reset the count of our abandoned slots
251+ }
246252
247253 // since we called treeToArrays, we can assume that our VBO is in sync, and so partial updates to the VBOs are
248254 // ok again, until/unless we call removeOutOfView()
@@ -270,14 +276,20 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 21 unmodified lines
270276 }
271277
272278 void VoxelSystem::cleanupRemovedVoxels() {
273− //printf("cleanupRemovedVoxels...\n");
274279 PerformanceWarning warn(_renderWarningsOn, "cleanupRemovedVoxels()");
280+ // This handles cleanup of voxels that were culled as part of our regular out of view culling operation
275281 if (!_removedVoxels.isEmpty()) {
276282 while (!_removedVoxels.isEmpty()) {
277283 delete _removedVoxels.extract();
278284 }
279285 _writeRenderFullVBO = true; // if we remove voxels, we must update our full VBOs
280286 }
287+ // we also might have VBO slots that have been abandoned, if too many of our VBO slots
288+ // are abandonded we want to rerender our full VBOs
289+ const float TOO_MANY_ABANDONED_RATIO = 0.25f;
290+ if (!_writeRenderFullVBO && (_abandonedVBOSlots > (_voxelsInWriteArrays * TOO_MANY_ABANDONED_RATIO))) {
291+ _writeRenderFullVBO = true;
292+ }
281293 }
282294
283295 void VoxelSystem::copyWrittenDataToReadArraysFullVBOs() {
@@ -418,6 +430,7 @@ int VoxelSystem::updateNodeInArraysAsPartialVBO(VoxelNode* node) { · 134 unmodified lines
418430 // and our scale as infinitely small
419431 startVertex[0] = startVertex[1] = startVertex[2] = FLT_MAX;
420432 voxelScale = 0;
433+ _abandonedVBOSlots++;
421434 }
422435
423436 // If this node has not yet been written to the array, then add it to the end of the array.
@@ -470,7 +483,6 @@ void VoxelSystem::init() { · 46 unmodified lines
470483 _voxelsDirty = false;
471484 _voxelsInWriteArrays = 0;
472485 _voxelsInReadArrays = 0;
473− _unusedArraySpace = 0;
474486
475487 // we will track individual dirty sections with these arrays of bools
476488 _writeVoxelDirtyArray = new bool[_maxVoxels];

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