History

fixed behavior of voxel delete and some cases of voxel add in fast pipeline mode

ZappoMan committed 13 years ago

Commit 1c664b31 parent a36ea502 files · +48 −19Browse files

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

Unified · Split

interface/src/VoxelSystem.cpp+45−18
@@ -104,7 +104,12 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) · 103 unmodified lines
104104
105105 void VoxelSystem::voxelDeleted(VoxelNode* node) {
106106 if (node->isKnownBufferIndex() && (node->getVoxelSystem() == this)) {
107− freeBufferIndex(node->getBufferIndex());
107+ if (!_useFastVoxelPipeline || _inSetupNewVoxelsForDrawing || _writeRenderFullVBO) {
108+ freeBufferIndex(node->getBufferIndex());
109+ } else {
110+ forceRemoveNodeFromArraysAsPartialVBO(node);
111+ freeBufferIndex(node->getBufferIndex());
112+ }
108113 }
109114 }
110115
@@ -115,22 +120,19 @@ void VoxelSystem::setUseFastVoxelPipeline(bool useFastVoxelPipeline) { · 4 unmodified lines
115120 }
116121
117122 void VoxelSystem::voxelUpdated(VoxelNode* node) {
118−
119− //printf("VoxelSystem::voxelUpdated() _useFastVoxelPipeline=%s\n", debug::valueOf(_useFastVoxelPipeline));
120−
121123 // If we're in SetupNewVoxelsForDrawing() or _writeRenderFullVBO then bail..
122124 if (!_useFastVoxelPipeline || _inSetupNewVoxelsForDrawing || _writeRenderFullVBO) {
123125 return;
124126 }
125127
126128 if (node->getVoxelSystem() == this) {
127− //printf("VoxelSystem::voxelUpdated()... node->getVoxelSystem() == this\n");
128−
129129 bool shouldRender = false; // assume we don't need to render it
130130 // if it's colored, we might need to render it!
131131 shouldRender = node->calculateShouldRender(_viewFrustum);
132132
133− node->setShouldRender(shouldRender);
133+ if (node->getShouldRender() != shouldRender) {
134+ node->setShouldRender(shouldRender);
135+ }
134136
135137 if (!node->isLeaf()) {
136138
@@ -158,7 +160,7 @@ void VoxelSystem::voxelUpdated(VoxelNode* node) { · 21 unmodified lines
158160
159161 node->clearDirtyBit(); // clear the dirty bit, do this before we potentially delete things.
160162
161− setupNewVoxelsForDrawingSingleNode();
163+ setupNewVoxelsForDrawingSingleNode();
162164 }
163165 }
164166
@@ -524,6 +526,8 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 359 unmodified lines
524526
525527 if (!_useFastVoxelPipeline || _writeRenderFullVBO) {
526528 setupNewVoxelsForDrawing();
529+ } else {
530+ setupNewVoxelsForDrawingSingleNode(DONT_BAIL_EARLY);
527531 }
528532
529533 pthread_mutex_unlock(&_treeLock);
@@ -596,7 +600,7 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 66 unmodified lines
596600 _inSetupNewVoxelsForDrawing = false;
597601 }
598602
599−void VoxelSystem::setupNewVoxelsForDrawingSingleNode() {
603+void VoxelSystem::setupNewVoxelsForDrawingSingleNode(bool allowBailEarly) {
600604
601605 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
602606 "setupNewVoxelsForDrawingSingleNode()"); // would like to include _voxelsInArrays, _voxelsUpdated
@@ -608,11 +612,11 @@ void VoxelSystem::setupNewVoxelsForDrawingSingleNode() { · 5 unmodified lines
608612 clearFreeBufferIndexes();
609613
610614 bool iAmDebugging = false; // if you're debugging set this to true, so you won't get skipped for slow debugging
611− if (!iAmDebugging && sinceLastTime <= std::max((float) _setupNewVoxelsForDrawingLastElapsed, SIXTY_FPS_IN_MILLISECONDS)) {
615+ if (allowBailEarly && !iAmDebugging &&
616+ sinceLastTime <= std::max((float) _setupNewVoxelsForDrawingLastElapsed, SIXTY_FPS_IN_MILLISECONDS)) {
612617 return; // bail early, it hasn't been long enough since the last time we ran
613618 }
614619
615−
616620 checkForCulling(); // check for out of view and deleted voxels...
617621
618622 // lock on the buffer write lock so we can't modify the data when the GPU is reading it
@@ -827,6 +831,36 @@ int VoxelSystem::updateNodeInArraysAsFullVBO(VoxelNode* node) { · 208 unmodified lines
827831 return 0; // not-rendered
828832 }
829833
834+// called as response to voxelDeleted() in fast pipeline case. The node
835+// is being deleted, but it's state is such that it thinks it should render
836+// and therefore we can't use the normal render calculations. This method
837+// will forcibly remove it from the VBOs because we know better!!!
838+int VoxelSystem::forceRemoveNodeFromArraysAsPartialVBO(VoxelNode* node) {
839+
840+ // if the node is not in the VBOs then we have nothing to do!
841+ if (node->isKnownBufferIndex()) {
842+
843+ // if we shouldn't render then set out location to some infinitely distant location,
844+ // and our scale as infinitely small
845+ glm::vec3 startVertex(FLT_MAX, FLT_MAX, FLT_MAX);
846+ float voxelScale = 0;
847+ _abandonedVBOSlots++;
848+
849+ // If this node has not yet been written to the array, then add it to the end of the array.
850+ glBufferIndex nodeIndex = node->getBufferIndex();
851+
852+ _writeVoxelDirtyArray[nodeIndex] = true;
853+
854+ // populate the array with points for the 8 vertices
855+ // and RGB color for each added vertex
856+ const nodeColor BLACK = { 0,0,0};
857+ updateNodeInArrays(nodeIndex, startVertex, voxelScale, BLACK);
858+
859+ return 1; // updated!
860+ }
861+ return 0; // not-updated
862+}
863+
830864 int VoxelSystem::updateNodeInArraysAsPartialVBO(VoxelNode* node) {
831865 // If we've run out of room, then just bail...
832866 if (_voxelsInWriteArrays >= _maxVoxels) {
@@ -1273,10 +1307,6 @@ bool VoxelSystem::falseColorizeBySourceOperation(VoxelNode* node, void* extraDat · 440 unmodified lines
12731307 if (node->isColored()) {
12741308 // pick a color based on the source - we want each source to be obviously different
12751309 uint16_t nodeID = node->getSourceID();
1276−
1277− //printf("false colorizing from source %d, color: %d, %d, %d\n", nodeID,
1278− // args->colors[nodeID].red, args->colors[nodeID].green, args->colors[nodeID].blue);
1279−
12801310 node->setFalseColor(args->colors[nodeID].red, args->colors[nodeID].green, args->colors[nodeID].blue);
12811311 }
12821312 return true; // keep going!
@@ -1305,9 +1335,6 @@ void VoxelSystem::falseColorizeBySource() { · 22 unmodified lines
13051335 int groupColor = voxelServerCount % NUMBER_OF_COLOR_GROUPS;
13061336 args.colors[nodeID] = groupColors[groupColor];
13071337
1308− //printf("assigning color for source %d, color: %d, %d, %d\n", nodeID,
1309− // args.colors[nodeID].red, args.colors[nodeID].green, args.colors[nodeID].blue);
1310−
13111338 if (groupColors[groupColor].red > 0) {
13121339 groupColors[groupColor].red = ((groupColors[groupColor].red - MIN_COLOR)/2) + MIN_COLOR;
13131340 }

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