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
60 pthread_mutex_init(&_treeLock, NULL);60 pthread_mutex_init(&_treeLock, NULL);
61 61
62 _hookID = VoxelNode::addDeleteHook(voxelNodeDeleteHook, (void*)this);62 _hookID = VoxelNode::addDeleteHook(voxelNodeDeleteHook, (void*)this);
63 _abandonedVBOSlots = 0;
63}64}
64 65
65void VoxelSystem::voxelNodeDeleteHook(VoxelNode* node, void* extraData) {66void VoxelSystem::voxelNodeDeleteHook(VoxelNode* node, void* extraData) {
@@ -82,6 +83,7 @@ void VoxelSystem::clearFreeBufferIndexes() { · 16 unmodified lines
82 _writeVoxelDirtyArray[nodeIndex] = true;83 _writeVoxelDirtyArray[nodeIndex] = true;
83 nodeColor color = { 0, 0, 0, 0};84 nodeColor color = { 0, 0, 0, 0};
84 updateNodeInArrays(nodeIndex, startVertex, voxelScale, color);85 updateNodeInArrays(nodeIndex, startVertex, voxelScale, color);
86 _abandonedVBOSlots++;
85 }87 }
86 _freeIdexes.clear();88 _freeIdexes.clear();
87}89}
@@ -243,6 +245,10 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 155 unmodified lines
243 }245 }
244 _voxelsUpdated = newTreeToArrays(_tree->rootNode);246 _voxelsUpdated = newTreeToArrays(_tree->rootNode);
245 _tree->clearDirtyBit(); // after we pull the trees into the array, we can consider the tree clean247 _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 }
246 252
247 // since we called treeToArrays, we can assume that our VBO is in sync, and so partial updates to the VBOs are253 // since we called treeToArrays, we can assume that our VBO is in sync, and so partial updates to the VBOs are
248 // ok again, until/unless we call removeOutOfView() 254 // ok again, until/unless we call removeOutOfView()
@@ -270,14 +276,20 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 21 unmodified lines
270}276}
271 277
272void VoxelSystem::cleanupRemovedVoxels() {278void VoxelSystem::cleanupRemovedVoxels() {
273 //printf("cleanupRemovedVoxels...\n");
274 PerformanceWarning warn(_renderWarningsOn, "cleanupRemovedVoxels()");279 PerformanceWarning warn(_renderWarningsOn, "cleanupRemovedVoxels()");
280 // This handles cleanup of voxels that were culled as part of our regular out of view culling operation
275 if (!_removedVoxels.isEmpty()) {281 if (!_removedVoxels.isEmpty()) {
276 while (!_removedVoxels.isEmpty()) {282 while (!_removedVoxels.isEmpty()) {
277 delete _removedVoxels.extract();283 delete _removedVoxels.extract();
278 }284 }
279 _writeRenderFullVBO = true; // if we remove voxels, we must update our full VBOs285 _writeRenderFullVBO = true; // if we remove voxels, we must update our full VBOs
280 }286 }
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 }
281}293}
282 294
283void VoxelSystem::copyWrittenDataToReadArraysFullVBOs() {295void VoxelSystem::copyWrittenDataToReadArraysFullVBOs() {
@@ -418,6 +430,7 @@ int VoxelSystem::updateNodeInArraysAsPartialVBO(VoxelNode* node) { · 134 unmodified lines
418 // and our scale as infinitely small430 // and our scale as infinitely small
419 startVertex[0] = startVertex[1] = startVertex[2] = FLT_MAX;431 startVertex[0] = startVertex[1] = startVertex[2] = FLT_MAX;
420 voxelScale = 0;432 voxelScale = 0;
433 _abandonedVBOSlots++;
421 }434 }
422 435
423 // If this node has not yet been written to the array, then add it to the end of the array.436 // 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
470 _voxelsDirty = false;483 _voxelsDirty = false;
471 _voxelsInWriteArrays = 0;484 _voxelsInWriteArrays = 0;
472 _voxelsInReadArrays = 0;485 _voxelsInReadArrays = 0;
473 _unusedArraySpace = 0;
474 486
475 // we will track individual dirty sections with these arrays of bools487 // we will track individual dirty sections with these arrays of bools
476 _writeVoxelDirtyArray = new bool[_maxVoxels];488 _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