History

first cut at auto-LOD adjustment

ZappoMan committed 12 years ago

Commit 20a6f4e1 parent d6b71f18 files · +108 −28Browse files

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

Unified · Split

interface/src/VoxelSystem.cpp+43−18
@@ -99,6 +99,9 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) · 98 unmodified lines
9999
100100 _culledOnce = false;
101101 _inhideOutOfView = false;
102+
103+ _lastKnownVoxelSizeScale = DEFAULT_OCTREE_SIZE_SCALE;
104+ _lastKnownBoundaryLevelAdjust = 0;
102105 }
103106
104107 void VoxelSystem::elementDeleted(OctreeElement* element) {
@@ -249,6 +252,9 @@ VoxelSystem::~VoxelSystem() { · 144 unmodified lines
249252 delete _tree;
250253 }
251254
255+
256+// This is called by the main application thread on both the initialization of the application and when
257+// the preferences dialog box is called/saved
252258 void VoxelSystem::setMaxVoxels(int maxVoxels) {
253259 if (maxVoxels == _maxVoxels) {
254260 return;
@@ -267,6 +273,8 @@ void VoxelSystem::setMaxVoxels(int maxVoxels) { · 12 unmodified lines
267273 }
268274 }
269275
276+// This is called by the main application thread on both the initialization of the application and when
277+// the use voxel shader menu item is chosen
270278 void VoxelSystem::setUseVoxelShader(bool useVoxelShader) {
271279 if (_useVoxelShader == useVoxelShader) {
272280 return;
@@ -330,7 +338,7 @@ void VoxelSystem::setVoxelsAsPoints(bool voxelsAsPoints) { · 57 unmodified lines
330338
331339 void VoxelSystem::cleanupVoxelMemory() {
332340 if (_initialized) {
333− _bufferWriteLock.lock();
341+ _readArraysLock.lockForWrite();
334342 _initialized = false; // no longer initialized
335343 if (_useVoxelShader) {
336344 // these are used when in VoxelShader mode.
@@ -368,7 +376,7 @@ void VoxelSystem::cleanupVoxelMemory() { · 31 unmodified lines
368376 delete[] _writeVoxelDirtyArray;
369377 delete[] _readVoxelDirtyArray;
370378 _writeVoxelDirtyArray = _readVoxelDirtyArray = NULL;
371− _bufferWriteLock.unlock();
379+ _readArraysLock.unlock();
372380 }
373381 }
374382
@@ -401,7 +409,7 @@ void VoxelSystem::setupFaceIndices(GLuint& faceVBOID, GLubyte faceIdentityIndice · 26 unmodified lines
401409 }
402410
403411 void VoxelSystem::initVoxelMemory() {
404− _bufferWriteLock.lock();
412+ _readArraysLock.lockForWrite();
405413
406414 _memoryUsageRAM = 0;
407415 _memoryUsageVBO = 0; // our VBO allocations as we know them
@@ -516,7 +524,7 @@ void VoxelSystem::initVoxelMemory() { · 108 unmodified lines
516524
517525 _initialized = true;
518526
519− _bufferWriteLock.unlock();
527+ _readArraysLock.unlock();
520528 }
521529
522530 void VoxelSystem::writeToSVOFile(const char* filename, VoxelTreeElement* element) const {
@@ -646,7 +654,7 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 123 unmodified lines
646654 }
647655
648656 _inSetupNewVoxelsForDrawing = true;
649−
657+
650658 bool didWriteFullVBO = _writeRenderFullVBO;
651659 if (_tree->isDirty()) {
652660 static char buffer[64] = { 0 };
@@ -673,7 +681,7 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 20 unmodified lines
673681 }
674682
675683 // lock on the buffer write lock so we can't modify the data when the GPU is reading it
676− _bufferWriteLock.lock();
684+ _readArraysLock.lockForWrite();
677685
678686 if (_voxelsUpdated) {
679687 _voxelsDirty=true;
@@ -682,7 +690,7 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 2 unmodified lines
682690 // copy the newly written data to the arrays designated for reading, only does something if _voxelsDirty && _voxelsUpdated
683691 copyWrittenDataToReadArrays(didWriteFullVBO);
684692
685− _bufferWriteLock.unlock();
693+ _readArraysLock.unlock();
686694
687695 quint64 end = usecTimestampNow();
688696 int elapsedmsec = (end - start) / 1000;
@@ -713,8 +721,8 @@ void VoxelSystem::setupNewVoxelsForDrawingSingleNode(bool allowBailEarly) { · 24 unmodified lines
713721 // lock on the buffer write lock so we can't modify the data when the GPU is reading it
714722 {
715723 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
716− "setupNewVoxelsForDrawingSingleNode()... _bufferWriteLock.lock();" );
717− _bufferWriteLock.lock();
724+ "setupNewVoxelsForDrawingSingleNode()... _readArraysLock.lockForWrite();" );
725+ _readArraysLock.lockForWrite();
718726 }
719727
720728 _voxelsDirty = true; // if we got this far, then we can assume some voxels are dirty
@@ -725,7 +733,7 @@ void VoxelSystem::setupNewVoxelsForDrawingSingleNode(bool allowBailEarly) { · 4 unmodified lines
725733 // after...
726734 _voxelsUpdated = 0;
727735
728− _bufferWriteLock.unlock();
736+ _readArraysLock.unlock();
729737
730738 quint64 end = usecTimestampNow();
731739 int elapsedmsec = (end - start) / 1000;
@@ -733,8 +741,12 @@ void VoxelSystem::setupNewVoxelsForDrawingSingleNode(bool allowBailEarly) { · 1 unmodified line
733741 _setupNewVoxelsForDrawingLastElapsed = elapsedmsec;
734742 }
735743
736−void VoxelSystem::checkForCulling() {
744+void VoxelSystem::recreateVoxelGeometryInView() {
745+ // this is a temporary solution... we need a full implementation that actually does a full redraw into clean VBOs
746+ hideOutOfView(true);
747+}
737748
749+void VoxelSystem::checkForCulling() {
738750 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "checkForCulling()");
739751 quint64 start = usecTimestampNow();
740752
@@ -762,7 +774,20 @@ void VoxelSystem::checkForCulling() { · 21 unmodified lines
762774 _hasRecentlyChanged = false;
763775 }
764776
765− hideOutOfView(forceFullFrustum);
777+ // This would be a good place to do a special processing pass, for example, switching the LOD of the scene
778+ bool fullRedraw = (_lastKnownVoxelSizeScale != Menu::getInstance()->getVoxelSizeScale() ||
779+ _lastKnownBoundaryLevelAdjust != Menu::getInstance()->getBoundaryLevelAdjust());
780+
781+ // track that these values
782+ _lastKnownVoxelSizeScale = Menu::getInstance()->getVoxelSizeScale();
783+ _lastKnownBoundaryLevelAdjust = Menu::getInstance()->getBoundaryLevelAdjust();
784+
785+ if (fullRedraw) {
786+ // this will remove all old geometry and recreate the correct geometry for all in view voxels
787+ recreateVoxelGeometryInView();
788+ } else {
789+ hideOutOfView(forceFullFrustum);
790+ }
766791
767792 if (forceFullFrustum) {
768793 quint64 endViewCulling = usecTimestampNow();
@@ -1197,7 +1222,8 @@ void VoxelSystem::updateVBOSegment(glBufferIndex segmentStart, glBufferIndex seg · 428 unmodified lines
11971222 }
11981223 }
11991224
1200−void VoxelSystem::render(bool texture) {
1225+void VoxelSystem::render() {
1226+ bool texture = Menu::getInstance()->isOptionChecked(MenuOption::VoxelTextures);
12011227 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
12021228 PerformanceWarning warn(showWarnings, "render()");
12031229
@@ -1404,11 +1430,7 @@ void VoxelSystem::killLocalVoxels() { · 200 unmodified lines
14041430 setupNewVoxelsForDrawing();
14051431 }
14061432
1407−void VoxelSystem::redrawInViewVoxels() {
1408− hideOutOfView(true);
1409−}
1410−
1411−
1433+// only called on main thread
14121434 bool VoxelSystem::clearAllNodesBufferIndexOperation(OctreeElement* element, void* extraData) {
14131435 _nodeCount++;
14141436 VoxelTreeElement* voxel = (VoxelTreeElement*)element;
@@ -1416,12 +1438,15 @@ bool VoxelSystem::clearAllNodesBufferIndexOperation(OctreeElement* element, void · 1 unmodified line
14161438 return true;
14171439 }
14181440
1441+// only called on main thread, and also always followed by a call to cleanupVoxelMemory()
1442+// you shouldn't be calling this on any other thread or without also cleaning up voxel memory
14191443 void VoxelSystem::clearAllNodesBufferIndex() {
14201444 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
14211445 "VoxelSystem::clearAllNodesBufferIndex()");
14221446 _nodeCount = 0;
14231447 _tree->lockForRead(); // we won't change the tree so it's ok to treat this as a read
14241448 _tree->recurseTreeWithOperation(clearAllNodesBufferIndexOperation);
1449+ clearFreeBufferIndexes(); // this should be called too
14251450 _tree->unlock();
14261451 if (Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings)) {
14271452 qDebug("clearing buffer index of %d nodes", _nodeCount);