Showing the changes to interface/src/VoxelSystem.cpp (1 of 2 files). Show all
Unified · Split
| @@ -681,6 +681,7 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 680 unmodified lines | |||
| 681 | if (_writeRenderFullVBO) { | 681 | if (_writeRenderFullVBO) { |
| 682 | if (_usePrimitiveRenderer) { | 682 | if (_usePrimitiveRenderer) { |
| 683 | _renderer->release(); | 683 | _renderer->release(); |
| 684 | clearAllNodesPrimitiveIndex(); | ||
| 684 | } | 685 | } |
| 685 | clearFreeBufferIndexes(); | 686 | clearFreeBufferIndexes(); |
| 686 | } | 687 | } |
| @@ -1081,8 +1082,7 @@ int VoxelSystem::forceRemoveNodeFromArrays(VoxelTreeElement* node) { · 394 unmodified lines | |||
| 1081 | node->setPrimitiveIndex(0); | 1082 | node->setPrimitiveIndex(0); |
| 1082 | return 1; | 1083 | return 1; |
| 1083 | } | 1084 | } |
| 1084 | } | 1085 | } else { |
| 1085 | else { | ||
| 1086 | // if the node is not in the VBOs then we have nothing to do! | 1086 | // if the node is not in the VBOs then we have nothing to do! |
| 1087 | if (node->isKnownBufferIndex()) { | 1087 | if (node->isKnownBufferIndex()) { |
| 1088 | // If this node has not yet been written to the array, then add it to the end of the array. | 1088 | // 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 | |||
| 1585 | _tree->eraseAllOctreeElements(); | 1585 | _tree->eraseAllOctreeElements(); |
| 1586 | _tree->unlock(); | 1586 | _tree->unlock(); |
| 1587 | clearFreeBufferIndexes(); | 1587 | clearFreeBufferIndexes(); |
| 1588 | if (_renderer) { | 1588 | if (_usePrimitiveRenderer) { |
| 1589 | _renderer->release(); | 1589 | if (_renderer) { |
| 1590 | _renderer->release(); | ||
| 1591 | } | ||
| 1592 | clearAllNodesPrimitiveIndex(); | ||
| 1590 | } | 1593 | } |
| 1591 | _voxelsInReadArrays = 0; // do we need to do this? | 1594 | _voxelsInReadArrays = 0; // do we need to do this? |
| 1592 | setupNewVoxelsForDrawing(); | 1595 | setupNewVoxelsForDrawing(); |
| @@ -1597,7 +1600,6 @@ bool VoxelSystem::clearAllNodesBufferIndexOperation(OctreeElement* element, void · 4 unmodified lines | |||
| 1597 | _nodeCount++; | 1600 | _nodeCount++; |
| 1598 | VoxelTreeElement* voxel = (VoxelTreeElement*)element; | 1601 | VoxelTreeElement* voxel = (VoxelTreeElement*)element; |
| 1599 | voxel->setBufferIndex(GLBUFFER_INDEX_UNKNOWN); | 1602 | voxel->setBufferIndex(GLBUFFER_INDEX_UNKNOWN); |
| 1600 | voxel->setPrimitiveIndex(0); | ||
| 1601 | return true; | 1603 | return true; |
| 1602 | } | 1604 | } |
| 1603 | 1605 | ||
| @@ -1616,6 +1618,28 @@ void VoxelSystem::clearAllNodesBufferIndex() { · 12 unmodified lines | |||
| 1616 | } | 1618 | } |
| 1617 | } | 1619 | } |
| 1618 | 1620 | ||
| 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 | |||
| 1619 | bool VoxelSystem::inspectForInteriorOcclusionsOperation(OctreeElement* element, void* extraData) { | 1643 | bool VoxelSystem::inspectForInteriorOcclusionsOperation(OctreeElement* element, void* extraData) { |
| 1620 | _nodeCount++; | 1644 | _nodeCount++; |
| 1621 | VoxelTreeElement* voxel = (VoxelTreeElement*)element; | 1645 | VoxelTreeElement* voxel = (VoxelTreeElement*)element; |
| @@ -1689,7 +1713,15 @@ bool VoxelSystem::inspectForExteriorOcclusionsOperation(OctreeElement* element, · 67 unmodified lines | |||
| 1689 | 1713 | ||
| 1690 | // Nothing to do at the leaf level | 1714 | // Nothing to do at the leaf level |
| 1691 | if (voxel->isLeaf()) { | 1715 | 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); | ||
| 1692 | return false; | 1721 | return false; |
| 1722 | } else { | ||
| 1723 | voxel->setExteriorOcclusions(OctreeElement::HalfSpace::None); | ||
| 1724 | voxel->setInteriorOcclusions(OctreeElement::HalfSpace::None); | ||
| 1693 | } | 1725 | } |
| 1694 | 1726 | ||
| 1695 | // Count of exterior occluding faces of this voxel element indexed | 1727 | // Count of exterior occluding faces of this voxel element indexed |
| @@ -1756,40 +1788,20 @@ bool VoxelSystem::inspectForExteriorOcclusionsOperation(OctreeElement* element, · 60 unmodified lines | |||
| 1756 | return true; | 1788 | return true; |
| 1757 | } | 1789 | } |
| 1758 | 1790 | ||
| 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 | } | ||
| 1778 | 1791 | ||
| 1779 | return rc; | ||
| 1780 | } | ||
| 1781 | void VoxelSystem::cullSharedFaces() { | 1792 | void VoxelSystem::cullSharedFaces() { |
| 1782 | 1793 | ||
| 1783 | if (Menu::getInstance()->isOptionChecked(MenuOption::CullSharedFaces)) { | 1794 | if (Menu::getInstance()->isOptionChecked(MenuOption::CullSharedFaces)) { |
| 1784 | _useVoxelShader = false; | 1795 | _useVoxelShader = false; |
| 1785 | _usePrimitiveRenderer = true; | 1796 | _usePrimitiveRenderer = true; |
| 1786 | clearAllNodesBufferIndex(); | ||
| 1787 | inspectForOcclusions(); | 1797 | inspectForOcclusions(); |
| 1788 | } else { | 1798 | } else { |
| 1789 | _usePrimitiveRenderer = false; | 1799 | _usePrimitiveRenderer = false; |
| 1790 | clearAllNodesBufferIndex(); | 1800 | clearAllNodesBufferIndex(); |
| 1791 | clearAllOcclusions(); | ||
| 1792 | } | 1801 | } |
| 1802 | _writeRenderFullVBO = true; | ||
| 1803 | _tree->setDirtyBit(); | ||
| 1804 | setupNewVoxelsForDrawing(); | ||
| 1793 | } | 1805 | } |
| 1794 | 1806 | ||
| 1795 | void VoxelSystem::showCulledSharedFaces() { | 1807 | void VoxelSystem::showCulledSharedFaces() { |
| @@ -1802,44 +1814,12 @@ void VoxelSystem::showCulledSharedFaces() { · 6 unmodified lines | |||
| 1802 | } | 1814 | } |
| 1803 | _tree->unlock(); | 1815 | _tree->unlock(); |
| 1804 | if (Menu::getInstance()->isOptionChecked(MenuOption::CullSharedFaces)) { | 1816 | if (Menu::getInstance()->isOptionChecked(MenuOption::CullSharedFaces)) { |
| 1805 | if (_renderer) { | ||
| 1806 | _renderer->release(); | ||
| 1807 | } | ||
| 1808 | _writeRenderFullVBO = true; | 1817 | _writeRenderFullVBO = true; |
| 1809 | _tree->setDirtyBit(); | 1818 | _tree->setDirtyBit(); |
| 1810 | setupNewVoxelsForDrawing(); | 1819 | setupNewVoxelsForDrawing(); |
| 1811 | } | 1820 | } |
| 1812 | } | 1821 | } |
| 1813 | 1822 | ||
| 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 | |||
| 1843 | void VoxelSystem::inspectForOcclusions() { | 1823 | void VoxelSystem::inspectForOcclusions() { |
| 1844 | 1824 | ||
| 1845 | if (_inOcclusions) { | 1825 | if (_inOcclusions) { |
| @@ -1852,10 +1832,6 @@ void VoxelSystem::inspectForOcclusions() { · 6 unmodified lines | |||
| 1852 | PerformanceWarning warn(showDebugDetails, "inspectForOcclusions()"); | 1832 | PerformanceWarning warn(showDebugDetails, "inspectForOcclusions()"); |
| 1853 | 1833 | ||
| 1854 | _tree->lockForRead(); | 1834 | _tree->lockForRead(); |
| 1855 | if (_renderer) { | ||
| 1856 | _renderer->release(); | ||
| 1857 | } | ||
| 1858 | |||
| 1859 | _tree->recurseTreeWithPostOperation(inspectForExteriorOcclusionsOperation); | 1835 | _tree->recurseTreeWithPostOperation(inspectForExteriorOcclusionsOperation); |
| 1860 | _nodeCount = 0; | 1836 | _nodeCount = 0; |
| 1861 | _tree->recurseTreeWithOperation(inspectForInteriorOcclusionsOperation); | 1837 | _tree->recurseTreeWithOperation(inspectForInteriorOcclusionsOperation); |
| @@ -1864,9 +1840,6 @@ void VoxelSystem::inspectForOcclusions() { · 2 unmodified lines | |||
| 1864 | if (showDebugDetails) { | 1840 | if (showDebugDetails) { |
| 1865 | qDebug("inspecting all occlusions of %d nodes", _nodeCount); | 1841 | qDebug("inspecting all occlusions of %d nodes", _nodeCount); |
| 1866 | } | 1842 | } |
| 1867 | _writeRenderFullVBO = true; | ||
| 1868 | _tree->setDirtyBit(); | ||
| 1869 | setupNewVoxelsForDrawing(); | ||
| 1870 | _inOcclusions = false; | 1843 | _inOcclusions = false; |
| 1871 | } | 1844 | } |
| 1872 | 1845 | ||