History

fixed disappearing voxel bug

ZappoMan committed 13 years ago

Commit edfd5cd1 parent b998d6b2 files · +24 −6Browse files

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

Unified · Split

interface/src/VoxelSystem.cpp+23−6
@@ -73,10 +73,29 @@ void VoxelSystem::nodeDeleted(VoxelNode* node) { · 72 unmodified lines
7373 }
7474 }
7575
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
7694 void VoxelSystem::freeBufferIndex(glBufferIndex index) {
7795 _freeIndexes.push_back(index);
7896 }
7997
98+// This will run through the list of _freeIndexes and reset their VBO array values to be "invisible".
8099 void VoxelSystem::clearFreeBufferIndexes() {
81100 for (int i = 0; i < _freeIndexes.size(); i++) {
82101 glBufferIndex nodeIndex = _freeIndexes[i];
@@ -246,12 +265,13 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 163 unmodified lines
246265 _callsToTreesToArrays++;
247266 if (_writeRenderFullVBO) {
248267 _voxelsInWriteArrays = 0; // reset our VBO
268+ _freeIndexes.clear(); // reset our free indexes
249269 }
250270 _voxelsUpdated = newTreeToArrays(_tree->rootNode);
251271 _tree->clearDirtyBit(); // after we pull the trees into the array, we can consider the tree clean
252272
253273 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????
255275 }
256276
257277 // 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
399419 if (node->getShouldRender()) {
400420 glm::vec3 startVertex = node->getCorner();
401421 float voxelScale = node->getScale();
402− glBufferIndex nodeIndex = _voxelsInWriteArrays;
422+ glBufferIndex nodeIndex = getNextBufferIndex();
403423
404424 // populate the array with points for the 8 vertices
405425 // and RGB color for each added vertex
406426 updateNodeInArrays(nodeIndex, startVertex, voxelScale, node->getColor());
407427 node->setBufferIndex(nodeIndex);
408428 node->setVoxelSystem(this);
409− _writeVoxelDirtyArray[nodeIndex] = true; // just in case we switch to Partial mode
410− _voxelsInWriteArrays++; // our know vertices in the arrays
411429 return 1; // rendered
412430 } else {
413431 node->setBufferIndex(GLBUFFER_INDEX_UNKNOWN);
@@ -444,10 +462,9 @@ int VoxelSystem::updateNodeInArraysAsPartialVBO(VoxelNode* node) { · 30 unmodified lines
444462 if (node->isKnownBufferIndex()) {
445463 nodeIndex = node->getBufferIndex();
446464 } else {
447− nodeIndex = _voxelsInWriteArrays;
465+ nodeIndex = getNextBufferIndex();
448466 node->setBufferIndex(nodeIndex);
449467 node->setVoxelSystem(this);
450− _voxelsInWriteArrays++;
451468 }
452469 _writeVoxelDirtyArray[nodeIndex] = true;
453470