Showing the changes to interface/src/VoxelSystem.cpp (1 of 2 files). Show all
Unified · Split
| @@ -60,6 +60,7 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) : · 59 unmodified lines | ||
| 60 | 60 | pthread_mutex_init(&_treeLock, NULL); |
| 61 | 61 | |
| 62 | 62 | _hookID = VoxelNode::addDeleteHook(voxelNodeDeleteHook, (void*)this); |
| 63 | + _abandonedVBOSlots = 0; | |
| 63 | 64 | } |
| 64 | 65 | |
| 65 | 66 | void VoxelSystem::voxelNodeDeleteHook(VoxelNode* node, void* extraData) { |
| @@ -82,6 +83,7 @@ void VoxelSystem::clearFreeBufferIndexes() { · 16 unmodified lines | ||
| 82 | 83 | _writeVoxelDirtyArray[nodeIndex] = true; |
| 83 | 84 | nodeColor color = { 0, 0, 0, 0}; |
| 84 | 85 | updateNodeInArrays(nodeIndex, startVertex, voxelScale, color); |
| 86 | + _abandonedVBOSlots++; | |
| 85 | 87 | } |
| 86 | 88 | _freeIdexes.clear(); |
| 87 | 89 | } |
| @@ -243,6 +245,10 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 155 unmodified lines | ||
| 243 | 245 | } |
| 244 | 246 | _voxelsUpdated = newTreeToArrays(_tree->rootNode); |
| 245 | 247 | _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 | 253 | // since we called treeToArrays, we can assume that our VBO is in sync, and so partial updates to the VBOs are |
| 248 | 254 | // ok again, until/unless we call removeOutOfView() |
| @@ -270,14 +276,20 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 21 unmodified lines | ||
| 270 | 276 | } |
| 271 | 277 | |
| 272 | 278 | void VoxelSystem::cleanupRemovedVoxels() { |
| 273 | − //printf("cleanupRemovedVoxels...\n"); | |
| 274 | 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 | 281 | if (!_removedVoxels.isEmpty()) { |
| 276 | 282 | while (!_removedVoxels.isEmpty()) { |
| 277 | 283 | delete _removedVoxels.extract(); |
| 278 | 284 | } |
| 279 | 285 | _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 | |
| 283 | 295 | void VoxelSystem::copyWrittenDataToReadArraysFullVBOs() { |
| @@ -418,6 +430,7 @@ int VoxelSystem::updateNodeInArraysAsPartialVBO(VoxelNode* node) { · 134 unmodified lines | ||
| 418 | 430 | // and our scale as infinitely small |
| 419 | 431 | startVertex[0] = startVertex[1] = startVertex[2] = FLT_MAX; |
| 420 | 432 | voxelScale = 0; |
| 433 | + _abandonedVBOSlots++; | |
| 421 | 434 | } |
| 422 | 435 | |
| 423 | 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 | 483 | _voxelsDirty = false; |
| 471 | 484 | _voxelsInWriteArrays = 0; |
| 472 | 485 | _voxelsInReadArrays = 0; |
| 473 | − _unusedArraySpace = 0; | |
| 474 | 486 | |
| 475 | 487 | // we will track individual dirty sections with these arrays of bools |
| 476 | 488 | _writeVoxelDirtyArray = new bool[_maxVoxels]; |