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
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
79glBufferIndex 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
76void VoxelSystem::freeBufferIndex(glBufferIndex index) {94void VoxelSystem::freeBufferIndex(glBufferIndex index) {
77 _freeIndexes.push_back(index);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".
80void VoxelSystem::clearFreeBufferIndexes() {99void VoxelSystem::clearFreeBufferIndexes() {
81 for (int i = 0; i < _freeIndexes.size(); i++) {100 for (int i = 0; i < _freeIndexes.size(); i++) {
82 glBufferIndex nodeIndex = _freeIndexes[i];101 glBufferIndex nodeIndex = _freeIndexes[i];
@@ -246,12 +265,13 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 163 unmodified lines
246 _callsToTreesToArrays++;265 _callsToTreesToArrays++;
247 if (_writeRenderFullVBO) {266 if (_writeRenderFullVBO) {
248 _voxelsInWriteArrays = 0; // reset our VBO267 _voxelsInWriteArrays = 0; // reset our VBO
268 _freeIndexes.clear(); // reset our free indexes
249 }269 }
250 _voxelsUpdated = newTreeToArrays(_tree->rootNode);270 _voxelsUpdated = newTreeToArrays(_tree->rootNode);
251 _tree->clearDirtyBit(); // after we pull the trees into the array, we can consider the tree clean271 _tree->clearDirtyBit(); // after we pull the trees into the array, we can consider the tree clean
252 272
253 if (_writeRenderFullVBO) {273 if (_writeRenderFullVBO) {
254 _abandonedVBOSlots = 0; // reset the count of our abandoned slots274 _abandonedVBOSlots = 0; // reset the count of our abandoned slots, why is this here and not earlier????
255 }275 }
256 276
257 // since we called treeToArrays, we can assume that our VBO is in sync, and so partial updates to the VBOs are277 // 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 if (node->getShouldRender()) {419 if (node->getShouldRender()) {
400 glm::vec3 startVertex = node->getCorner();420 glm::vec3 startVertex = node->getCorner();
401 float voxelScale = node->getScale();421 float voxelScale = node->getScale();
402 glBufferIndex nodeIndex = _voxelsInWriteArrays;422 glBufferIndex nodeIndex = getNextBufferIndex();
403 423
404 // populate the array with points for the 8 vertices424 // populate the array with points for the 8 vertices
405 // and RGB color for each added vertex425 // and RGB color for each added vertex
406 updateNodeInArrays(nodeIndex, startVertex, voxelScale, node->getColor());426 updateNodeInArrays(nodeIndex, startVertex, voxelScale, node->getColor());
407 node->setBufferIndex(nodeIndex);427 node->setBufferIndex(nodeIndex);
408 node->setVoxelSystem(this);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 return 1; // rendered429 return 1; // rendered
412 } else {430 } else {
413 node->setBufferIndex(GLBUFFER_INDEX_UNKNOWN);431 node->setBufferIndex(GLBUFFER_INDEX_UNKNOWN);
@@ -444,10 +462,9 @@ int VoxelSystem::updateNodeInArraysAsPartialVBO(VoxelNode* node) { · 30 unmodified lines
444 if (node->isKnownBufferIndex()) {462 if (node->isKnownBufferIndex()) {
445 nodeIndex = node->getBufferIndex();463 nodeIndex = node->getBufferIndex();
446 } else {464 } else {
447 nodeIndex = _voxelsInWriteArrays;465 nodeIndex = getNextBufferIndex();
448 node->setBufferIndex(nodeIndex);466 node->setBufferIndex(nodeIndex);
449 node->setVoxelSystem(this);467 node->setVoxelSystem(this);
450 _voxelsInWriteArrays++;
451 }468 }
452 _writeVoxelDirtyArray[nodeIndex] = true;469 _writeVoxelDirtyArray[nodeIndex] = true;
453 470