Showing the changes to interface/src/VoxelSystem.cpp (1 of 2 files). Show all
Unified · Split
| @@ -73,10 +73,29 @@ void VoxelSystem::nodeDeleted(VoxelNode* node) { · 72 unmodified lines | ||
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | +// returns an available index, starts by reusing a previously freed index, but if there isn't one available | |
| 77 | +// it will use the end of the VBO array and grow our accounting of that array. | |
| 78 | +// and makes the index available for some other node to use | |
| 79 | +glBufferIndex VoxelSystem::getNextBufferIndex() { | |
| 80 | + glBufferIndex output = GLBUFFER_INDEX_UNKNOWN; | |
| 81 | + // if there's a free index, use it... | |
| 82 | + if (_freeIndexes.size() > 0) { | |
| 83 | + output = _freeIndexes.back(); | |
| 84 | + _freeIndexes.pop_back(); | |
| 85 | + } else { | |
| 86 | + output = _voxelsInWriteArrays; | |
| 87 | + _voxelsInWriteArrays++; | |
| 88 | + } | |
| 89 | + return output; | |
| 90 | +} | |
| 91 | + | |
| 92 | +// Doesn't actually clean up the VBOs for the index, but does release responsibility of the index from the VoxelNode, | |
| 93 | +// and makes the index available for some other node to use | |
| 76 | 94 | void VoxelSystem::freeBufferIndex(glBufferIndex index) { |
| 77 | 95 | _freeIndexes.push_back(index); |
| 78 | 96 | } |
| 79 | 97 | |
| 98 | +// This will run through the list of _freeIndexes and reset their VBO array values to be "invisible". | |
| 80 | 99 | void VoxelSystem::clearFreeBufferIndexes() { |
| 81 | 100 | for (int i = 0; i < _freeIndexes.size(); i++) { |
| 82 | 101 | glBufferIndex nodeIndex = _freeIndexes[i]; |
| @@ -246,12 +265,13 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 163 unmodified lines | ||
| 246 | 265 | _callsToTreesToArrays++; |
| 247 | 266 | if (_writeRenderFullVBO) { |
| 248 | 267 | _voxelsInWriteArrays = 0; // reset our VBO |
| 268 | + _freeIndexes.clear(); // reset our free indexes | |
| 249 | 269 | } |
| 250 | 270 | _voxelsUpdated = newTreeToArrays(_tree->rootNode); |
| 251 | 271 | _tree->clearDirtyBit(); // after we pull the trees into the array, we can consider the tree clean |
| 252 | 272 | |
| 253 | 273 | if (_writeRenderFullVBO) { |
| 254 | − _abandonedVBOSlots = 0; // reset the count of our abandoned slots | |
| 274 | + _abandonedVBOSlots = 0; // reset the count of our abandoned slots, why is this here and not earlier???? | |
| 255 | 275 | } |
| 256 | 276 | |
| 257 | 277 | // since we called treeToArrays, we can assume that our VBO is in sync, and so partial updates to the VBOs are |
| @@ -399,15 +419,13 @@ int VoxelSystem::updateNodeInArraysAsFullVBO(VoxelNode* node) { · 141 unmodified lines | ||
| 399 | 419 | if (node->getShouldRender()) { |
| 400 | 420 | glm::vec3 startVertex = node->getCorner(); |
| 401 | 421 | float voxelScale = node->getScale(); |
| 402 | − glBufferIndex nodeIndex = _voxelsInWriteArrays; | |
| 422 | + glBufferIndex nodeIndex = getNextBufferIndex(); | |
| 403 | 423 | |
| 404 | 424 | // populate the array with points for the 8 vertices |
| 405 | 425 | // and RGB color for each added vertex |
| 406 | 426 | updateNodeInArrays(nodeIndex, startVertex, voxelScale, node->getColor()); |
| 407 | 427 | node->setBufferIndex(nodeIndex); |
| 408 | 428 | node->setVoxelSystem(this); |
| 409 | − _writeVoxelDirtyArray[nodeIndex] = true; // just in case we switch to Partial mode | |
| 410 | − _voxelsInWriteArrays++; // our know vertices in the arrays | |
| 411 | 429 | return 1; // rendered |
| 412 | 430 | } else { |
| 413 | 431 | node->setBufferIndex(GLBUFFER_INDEX_UNKNOWN); |
| @@ -444,10 +462,9 @@ int VoxelSystem::updateNodeInArraysAsPartialVBO(VoxelNode* node) { · 30 unmodified lines | ||
| 444 | 462 | if (node->isKnownBufferIndex()) { |
| 445 | 463 | nodeIndex = node->getBufferIndex(); |
| 446 | 464 | } else { |
| 447 | − nodeIndex = _voxelsInWriteArrays; | |
| 465 | + nodeIndex = getNextBufferIndex(); | |
| 448 | 466 | node->setBufferIndex(nodeIndex); |
| 449 | 467 | node->setVoxelSystem(this); |
| 450 | − _voxelsInWriteArrays++; | |
| 451 | 468 | } |
| 452 | 469 | _writeVoxelDirtyArray[nodeIndex] = true; |
| 453 | 470 | |