Showing the changes to interface/src/VoxelSystem.cpp (1 of 2 files). Show all
Unified · Split
| @@ -104,7 +104,12 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) · 103 unmodified lines | |||
| 104 | 104 | ||
| 105 | void VoxelSystem::voxelDeleted(VoxelNode* node) { | 105 | void VoxelSystem::voxelDeleted(VoxelNode* node) { |
| 106 | if (node->isKnownBufferIndex() && (node->getVoxelSystem() == this)) { | 106 | 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 | } | ||
| 108 | } | 113 | } |
| 109 | } | 114 | } |
| 110 | 115 | ||
| @@ -115,22 +120,19 @@ void VoxelSystem::setUseFastVoxelPipeline(bool useFastVoxelPipeline) { · 4 unmodified lines | |||
| 115 | } | 120 | } |
| 116 | 121 | ||
| 117 | void VoxelSystem::voxelUpdated(VoxelNode* node) { | 122 | void VoxelSystem::voxelUpdated(VoxelNode* node) { |
| 118 | |||
| 119 | //printf("VoxelSystem::voxelUpdated() _useFastVoxelPipeline=%s\n", debug::valueOf(_useFastVoxelPipeline)); | ||
| 120 | |||
| 121 | // If we're in SetupNewVoxelsForDrawing() or _writeRenderFullVBO then bail.. | 123 | // If we're in SetupNewVoxelsForDrawing() or _writeRenderFullVBO then bail.. |
| 122 | if (!_useFastVoxelPipeline || _inSetupNewVoxelsForDrawing || _writeRenderFullVBO) { | 124 | if (!_useFastVoxelPipeline || _inSetupNewVoxelsForDrawing || _writeRenderFullVBO) { |
| 123 | return; | 125 | return; |
| 124 | } | 126 | } |
| 125 | 127 | ||
| 126 | if (node->getVoxelSystem() == this) { | 128 | if (node->getVoxelSystem() == this) { |
| 127 | //printf("VoxelSystem::voxelUpdated()... node->getVoxelSystem() == this\n"); | ||
| 128 | |||
| 129 | bool shouldRender = false; // assume we don't need to render it | 129 | bool shouldRender = false; // assume we don't need to render it |
| 130 | // if it's colored, we might need to render it! | 130 | // if it's colored, we might need to render it! |
| 131 | shouldRender = node->calculateShouldRender(_viewFrustum); | 131 | shouldRender = node->calculateShouldRender(_viewFrustum); |
| 132 | 132 | ||
| 133 | node->setShouldRender(shouldRender); | 133 | if (node->getShouldRender() != shouldRender) { |
| 134 | node->setShouldRender(shouldRender); | ||
| 135 | } | ||
| 134 | 136 | ||
| 135 | if (!node->isLeaf()) { | 137 | if (!node->isLeaf()) { |
| 136 | 138 | ||
| @@ -158,7 +160,7 @@ void VoxelSystem::voxelUpdated(VoxelNode* node) { · 21 unmodified lines | |||
| 158 | 160 | ||
| 159 | node->clearDirtyBit(); // clear the dirty bit, do this before we potentially delete things. | 161 | node->clearDirtyBit(); // clear the dirty bit, do this before we potentially delete things. |
| 160 | 162 | ||
| 161 | setupNewVoxelsForDrawingSingleNode(); | 163 | setupNewVoxelsForDrawingSingleNode(); |
| 162 | } | 164 | } |
| 163 | } | 165 | } |
| 164 | 166 | ||
| @@ -524,6 +526,8 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 359 unmodified lines | |||
| 524 | 526 | ||
| 525 | if (!_useFastVoxelPipeline || _writeRenderFullVBO) { | 527 | if (!_useFastVoxelPipeline || _writeRenderFullVBO) { |
| 526 | setupNewVoxelsForDrawing(); | 528 | setupNewVoxelsForDrawing(); |
| 529 | } else { | ||
| 530 | setupNewVoxelsForDrawingSingleNode(DONT_BAIL_EARLY); | ||
| 527 | } | 531 | } |
| 528 | 532 | ||
| 529 | pthread_mutex_unlock(&_treeLock); | 533 | pthread_mutex_unlock(&_treeLock); |
| @@ -596,7 +600,7 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 66 unmodified lines | |||
| 596 | _inSetupNewVoxelsForDrawing = false; | 600 | _inSetupNewVoxelsForDrawing = false; |
| 597 | } | 601 | } |
| 598 | 602 | ||
| 599 | void VoxelSystem::setupNewVoxelsForDrawingSingleNode() { | 603 | void VoxelSystem::setupNewVoxelsForDrawingSingleNode(bool allowBailEarly) { |
| 600 | 604 | ||
| 601 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), | 605 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), |
| 602 | "setupNewVoxelsForDrawingSingleNode()"); // would like to include _voxelsInArrays, _voxelsUpdated | 606 | "setupNewVoxelsForDrawingSingleNode()"); // would like to include _voxelsInArrays, _voxelsUpdated |
| @@ -608,11 +612,11 @@ void VoxelSystem::setupNewVoxelsForDrawingSingleNode() { · 5 unmodified lines | |||
| 608 | clearFreeBufferIndexes(); | 612 | clearFreeBufferIndexes(); |
| 609 | 613 | ||
| 610 | bool iAmDebugging = false; // if you're debugging set this to true, so you won't get skipped for slow debugging | 614 | 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)) { | ||
| 612 | return; // bail early, it hasn't been long enough since the last time we ran | 617 | return; // bail early, it hasn't been long enough since the last time we ran |
| 613 | } | 618 | } |
| 614 | 619 | ||
| 615 | |||
| 616 | checkForCulling(); // check for out of view and deleted voxels... | 620 | checkForCulling(); // check for out of view and deleted voxels... |
| 617 | 621 | ||
| 618 | // lock on the buffer write lock so we can't modify the data when the GPU is reading it | 622 | // 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 | |||
| 827 | return 0; // not-rendered | 831 | return 0; // not-rendered |
| 828 | } | 832 | } |
| 829 | 833 | ||
| 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 | |||
| 830 | int VoxelSystem::updateNodeInArraysAsPartialVBO(VoxelNode* node) { | 864 | int VoxelSystem::updateNodeInArraysAsPartialVBO(VoxelNode* node) { |
| 831 | // If we've run out of room, then just bail... | 865 | // If we've run out of room, then just bail... |
| 832 | if (_voxelsInWriteArrays >= _maxVoxels) { | 866 | if (_voxelsInWriteArrays >= _maxVoxels) { |
| @@ -1273,10 +1307,6 @@ bool VoxelSystem::falseColorizeBySourceOperation(VoxelNode* node, void* extraDat · 440 unmodified lines | |||
| 1273 | if (node->isColored()) { | 1307 | if (node->isColored()) { |
| 1274 | // pick a color based on the source - we want each source to be obviously different | 1308 | // pick a color based on the source - we want each source to be obviously different |
| 1275 | uint16_t nodeID = node->getSourceID(); | 1309 | 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 | |||
| 1280 | node->setFalseColor(args->colors[nodeID].red, args->colors[nodeID].green, args->colors[nodeID].blue); | 1310 | node->setFalseColor(args->colors[nodeID].red, args->colors[nodeID].green, args->colors[nodeID].blue); |
| 1281 | } | 1311 | } |
| 1282 | return true; // keep going! | 1312 | return true; // keep going! |
| @@ -1305,9 +1335,6 @@ void VoxelSystem::falseColorizeBySource() { · 22 unmodified lines | |||
| 1305 | int groupColor = voxelServerCount % NUMBER_OF_COLOR_GROUPS; | 1335 | int groupColor = voxelServerCount % NUMBER_OF_COLOR_GROUPS; |
| 1306 | args.colors[nodeID] = groupColors[groupColor]; | 1336 | args.colors[nodeID] = groupColors[groupColor]; |
| 1307 | 1337 | ||
| 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 | |||
| 1311 | if (groupColors[groupColor].red > 0) { | 1338 | if (groupColors[groupColor].red > 0) { |
| 1312 | groupColors[groupColor].red = ((groupColors[groupColor].red - MIN_COLOR)/2) + MIN_COLOR; | 1339 | groupColors[groupColor].red = ((groupColors[groupColor].red - MIN_COLOR)/2) + MIN_COLOR; |
| 1313 | } | 1340 | } |