History

Merged clearAllOcclusions into inspectOcclusions

matsukaze committed 12 years ago

Commit 75ecdbd1 parent 8aa645b2 files · +42 −69Browse files

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

Unified · Split

interface/src/VoxelSystem.cpp+40−67
@@ -681,6 +681,7 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 680 unmodified lines
681681 if (_writeRenderFullVBO) {
682682 if (_usePrimitiveRenderer) {
683683 _renderer->release();
684+ clearAllNodesPrimitiveIndex();
684685 }
685686 clearFreeBufferIndexes();
686687 }
@@ -1081,8 +1082,7 @@ int VoxelSystem::forceRemoveNodeFromArrays(VoxelTreeElement* node) { · 394 unmodified lines
10811082 node->setPrimitiveIndex(0);
10821083 return 1;
10831084 }
1084− }
1085− else {
1085+ } else {
10861086 // if the node is not in the VBOs then we have nothing to do!
10871087 if (node->isKnownBufferIndex()) {
10881088 // If this node has not yet been written to the array, then add it to the end of the array.
@@ -1585,8 +1585,11 @@ void VoxelSystem::killLocalVoxels() { · 496 unmodified lines
15851585 _tree->eraseAllOctreeElements();
15861586 _tree->unlock();
15871587 clearFreeBufferIndexes();
1588− if (_renderer) {
1589− _renderer->release();
1588+ if (_usePrimitiveRenderer) {
1589+ if (_renderer) {
1590+ _renderer->release();
1591+ }
1592+ clearAllNodesPrimitiveIndex();
15901593 }
15911594 _voxelsInReadArrays = 0; // do we need to do this?
15921595 setupNewVoxelsForDrawing();
@@ -1597,7 +1600,6 @@ bool VoxelSystem::clearAllNodesBufferIndexOperation(OctreeElement* element, void · 4 unmodified lines
15971600 _nodeCount++;
15981601 VoxelTreeElement* voxel = (VoxelTreeElement*)element;
15991602 voxel->setBufferIndex(GLBUFFER_INDEX_UNKNOWN);
1600− voxel->setPrimitiveIndex(0);
16011603 return true;
16021604 }
16031605
@@ -1616,6 +1618,28 @@ void VoxelSystem::clearAllNodesBufferIndex() { · 12 unmodified lines
16161618 }
16171619 }
16181620
1621+// only called on main thread
1622+bool VoxelSystem::clearAllNodesPrimitiveIndexOperation(OctreeElement* element, void* extraData) {
1623+ _nodeCount++;
1624+ VoxelTreeElement* voxel = (VoxelTreeElement*)element;
1625+ voxel->setPrimitiveIndex(0);
1626+ return true;
1627+}
1628+
1629+// only called on main thread, and also always followed by a call to cleanupVoxelMemory()
1630+// you shouldn't be calling this on any other thread or without also cleaning up voxel memory
1631+void VoxelSystem::clearAllNodesPrimitiveIndex() {
1632+ PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
1633+ "VoxelSystem::clearAllNodesPrimitiveIndex()");
1634+ _nodeCount = 0;
1635+ _tree->lockForRead(); // we won't change the tree so it's ok to treat this as a read
1636+ _tree->recurseTreeWithOperation(clearAllNodesPrimitiveIndexOperation);
1637+ _tree->unlock();
1638+ if (Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings)) {
1639+ qDebug("clearing primitive index of %d nodes", _nodeCount);
1640+ }
1641+}
1642+
16191643 bool VoxelSystem::inspectForInteriorOcclusionsOperation(OctreeElement* element, void* extraData) {
16201644 _nodeCount++;
16211645 VoxelTreeElement* voxel = (VoxelTreeElement*)element;
@@ -1689,7 +1713,15 @@ bool VoxelSystem::inspectForExteriorOcclusionsOperation(OctreeElement* element, · 67 unmodified lines
16891713
16901714 // Nothing to do at the leaf level
16911715 if (voxel->isLeaf()) {
1716+ // By definition the the exterior faces of a leaf voxel are
1717+ // always occluders.
1718+ voxel->setExteriorOcclusions(OctreeElement::HalfSpace::All);
1719+ // And the sibling occluders
1720+ voxel->setInteriorOcclusions(OctreeElement::HalfSpace::None);
16921721 return false;
1722+ } else {
1723+ voxel->setExteriorOcclusions(OctreeElement::HalfSpace::None);
1724+ voxel->setInteriorOcclusions(OctreeElement::HalfSpace::None);
16931725 }
16941726
16951727 // Count of exterior occluding faces of this voxel element indexed
@@ -1756,40 +1788,20 @@ bool VoxelSystem::inspectForExteriorOcclusionsOperation(OctreeElement* element, · 60 unmodified lines
17561788 return true;
17571789 }
17581790
1759−bool VoxelSystem::clearAllOcclusionsOperation(OctreeElement* element, void* extraData) {
1760− _nodeCount++;
1761− VoxelTreeElement* voxel = (VoxelTreeElement*)element;
1762−
1763− bool rc;
1764− if (voxel->isLeaf()) {
1765−
1766− // By definition the the exterior faces of a leaf voxel are
1767− // always occluders.
1768− voxel->setExteriorOcclusions(OctreeElement::HalfSpace::All);
1769−
1770− // And the sibling occluders
1771− voxel->setInteriorOcclusions(OctreeElement::HalfSpace::None);
1772− rc = false;
1773− } else {
1774− voxel->setExteriorOcclusions(OctreeElement::HalfSpace::None);
1775− voxel->setInteriorOcclusions(OctreeElement::HalfSpace::None);
1776− rc = true;
1777− }
17781791
1779− return rc;
1780−}
17811792 void VoxelSystem::cullSharedFaces() {
17821793
17831794 if (Menu::getInstance()->isOptionChecked(MenuOption::CullSharedFaces)) {
17841795 _useVoxelShader = false;
17851796 _usePrimitiveRenderer = true;
1786− clearAllNodesBufferIndex();
17871797 inspectForOcclusions();
17881798 } else {
17891799 _usePrimitiveRenderer = false;
17901800 clearAllNodesBufferIndex();
1791− clearAllOcclusions();
17921801 }
1802+ _writeRenderFullVBO = true;
1803+ _tree->setDirtyBit();
1804+ setupNewVoxelsForDrawing();
17931805 }
17941806
17951807 void VoxelSystem::showCulledSharedFaces() {
@@ -1802,44 +1814,12 @@ void VoxelSystem::showCulledSharedFaces() { · 6 unmodified lines
18021814 }
18031815 _tree->unlock();
18041816 if (Menu::getInstance()->isOptionChecked(MenuOption::CullSharedFaces)) {
1805− if (_renderer) {
1806− _renderer->release();
1807− }
18081817 _writeRenderFullVBO = true;
18091818 _tree->setDirtyBit();
18101819 setupNewVoxelsForDrawing();
18111820 }
18121821 }
18131822
1814−void VoxelSystem::clearAllOcclusions() {
1815−
1816− if (_inOcclusions) {
1817− return;
1818− }
1819− _inOcclusions = true;
1820− _nodeCount = 0;
1821−
1822− bool showDebugDetails = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
1823− PerformanceWarning warn(showDebugDetails, "clearAllOcclusions()");
1824−
1825− _tree->lockForRead();
1826− if (_renderer) {
1827− _renderer->release();
1828− }
1829−
1830− _tree->recurseTreeWithOperation(clearAllOcclusionsOperation);
1831− _tree->unlock();
1832−
1833− if (showDebugDetails) {
1834− qDebug("clearing all occlusions of %d nodes", _nodeCount);
1835− }
1836− _writeRenderFullVBO = true;
1837− _tree->setDirtyBit();
1838− setupNewVoxelsForDrawing();
1839−
1840− _inOcclusions = false;
1841−}
1842−
18431823 void VoxelSystem::inspectForOcclusions() {
18441824
18451825 if (_inOcclusions) {
@@ -1852,10 +1832,6 @@ void VoxelSystem::inspectForOcclusions() { · 6 unmodified lines
18521832 PerformanceWarning warn(showDebugDetails, "inspectForOcclusions()");
18531833
18541834 _tree->lockForRead();
1855− if (_renderer) {
1856− _renderer->release();
1857− }
1858−
18591835 _tree->recurseTreeWithPostOperation(inspectForExteriorOcclusionsOperation);
18601836 _nodeCount = 0;
18611837 _tree->recurseTreeWithOperation(inspectForInteriorOcclusionsOperation);
@@ -1864,9 +1840,6 @@ void VoxelSystem::inspectForOcclusions() { · 2 unmodified lines
18641840 if (showDebugDetails) {
18651841 qDebug("inspecting all occlusions of %d nodes", _nodeCount);
18661842 }
1867− _writeRenderFullVBO = true;
1868− _tree->setDirtyBit();
1869− setupNewVoxelsForDrawing();
18701843 _inOcclusions = false;
18711844 }
18721845

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