History

Swizzle bit pairs in the occlusion bit mask

matsukaze committed 12 years ago

Commit b8388331 parent 32f0a812 files · +88 −12Browse files

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

Unified · Split

interface/src/VoxelSystem.cpp+87−12
@@ -1542,15 +1542,17 @@ bool VoxelSystem::inspectForInteriorOcclusionsOperation(OctreeElement* element, · 1541 unmodified lines
15421542 exteriorOcclusionsB;
15431543
15441544 // Determine which face of each sibling is occluded.
1545− // Note the intentionally crossed indicies. It is necessary because
1546− // the _sOctantIndexToBitMask is a partition occupancy mask. For
1545+
1546+ // The _sOctantIndexToBitMask is a partition occupancy mask. For
15471547 // example, if the near-left-top (NLT) and near-left-bottom (NLB) child voxels
15481548 // exist, the shared partition is top-bottom (TB), and thus the occluded
15491549 // shared face of the NLT voxel is its bottom face.
1550− occludedSharedFace[i] |= (partitionB & _sOctantIndexToBitMask[j]);
1551− occludedSharedFace[j] |= (partitionA & _sOctantIndexToBitMask[i]);
1550+ occludedSharedFace[i] |= (partitionB & _sOctantIndexToBitMask[i]);
1551+ occludedSharedFace[j] |= (partitionA & _sOctantIndexToBitMask[j]);
15521552 }
15531553 }
1554+ // Exchange bit pairs, left to right, vice versa, etc.
1555+ occludedSharedFace[i] = _sSwizzledOcclusionBits[occludedSharedFace[i]];
15541556 // Combine this voxel's interior excluded shared face only to those children which are coincident
15551557 // with the excluded face.
15561558 occludedSharedFace[i] |= (voxel->getInteriorOcclusions() & _sOctantIndexToBitMask[i]);
@@ -1669,16 +1671,10 @@ void VoxelSystem::cullSharedFaces() { · 112 unmodified lines
16691671 _useVoxelShader = false;
16701672 _usePrimitiveRenderer = true;
16711673 clearAllNodesBufferIndex();
1672− if (_renderer) {
1673− _renderer->release();
1674− }
16751674 inspectForOcclusions();
16761675 } else {
16771676 _usePrimitiveRenderer = false;
16781677 clearAllNodesBufferIndex();
1679− if (_renderer) {
1680− _renderer->release();
1681− }
16821678 clearAllOcclusions();
16831679 }
16841680 }
@@ -1693,6 +1689,9 @@ void VoxelSystem::showCulledSharedFaces() { · 8 unmodified lines
16931689 }
16941690 _tree->unlock();
16951691 if (Menu::getInstance()->isOptionChecked(MenuOption::CullSharedFaces)) {
1692+ if (_renderer) {
1693+ _renderer->release();
1694+ }
16961695 _writeRenderFullVBO = true;
16971696 _tree->setDirtyBit();
16981697 setupNewVoxelsForDrawing();
@@ -1711,6 +1710,10 @@ void VoxelSystem::clearAllOcclusions() { · 12 unmodified lines
17111710 PerformanceWarning warn(showDebugDetails, "clearAllOcclusions()");
17121711
17131712 _tree->lockForRead();
1713+ if (_renderer) {
1714+ _renderer->release();
1715+ }
1716+
17141717 _tree->recurseTreeWithOperation(clearAllOcclusionsOperation);
17151718 _tree->unlock();
17161719
@@ -1736,15 +1739,19 @@ void VoxelSystem::inspectForOcclusions() { · 19 unmodified lines
17361739 PerformanceWarning warn(showDebugDetails, "inspectForOcclusions()");
17371740
17381741 _tree->lockForRead();
1742+ if (_renderer) {
1743+ _renderer->release();
1744+ }
1745+
17391746 _tree->recurseTreeWithPostOperation(inspectForExteriorOcclusionsOperation);
17401747 _nodeCount = 0;
17411748 _tree->recurseTreeWithOperation(inspectForInteriorOcclusionsOperation);
17421749 _tree->unlock();
17431750
1744− if (showDebugDetails) {
1751+ if (showDebugDetails) {
17451752 qDebug("inspecting all occlusions of %d nodes", _nodeCount);
17461753 }
1747− _writeRenderFullVBO = true;
1754+ _writeRenderFullVBO = true;
17481755 _tree->setDirtyBit();
17491756 setupNewVoxelsForDrawing();
17501757 _inOcclusions = false;
@@ -3127,6 +3134,74 @@ unsigned long VoxelSystem::getVoxelMemoryUsageGPU() { · 1376 unmodified lines
31273134 return (_initialMemoryUsageGPU - currentFreeMemory);
31283135 }
31293136
3137+// Swizzle value of bit pairs of the value of index
3138+unsigned short VoxelSystem::_sSwizzledOcclusionBits[64] = {
3139+ 0x0000, // 00000000
3140+ 0x0002, // 00000001
3141+ 0x0001, // 00000010
3142+ 0x0003, // 00000011
3143+ 0x0008, // 00000100
3144+ 0x000a, // 00000101
3145+ 0x0009, // 00000110
3146+ 0x000b, // 00000111
3147+ 0x0004, // 00001000
3148+ 0x0006, // 00001001
3149+ 0x0005, // 00001010
3150+ 0x0007, // 00001011
3151+ 0x000c, // 00001100
3152+ 0x000e, // 00001101
3153+ 0x000d, // 00001110
3154+ 0x000f, // 00001111
3155+ 0x0020, // 00010000
3156+ 0x0022, // 00010001
3157+ 0x0021, // 00010010
3158+ 0x0023, // 00010011
3159+ 0x0028, // 00010100
3160+ 0x002a, // 00010101
3161+ 0x0029, // 00010110
3162+ 0x002b, // 00010111
3163+ 0x0024, // 00011000
3164+ 0x0026, // 00011001
3165+ 0x0025, // 00011010
3166+ 0x0027, // 00011011
3167+ 0x002c, // 00011100
3168+ 0x002e, // 00011101
3169+ 0x002d, // 00011110
3170+ 0x002f, // 00011111
3171+ 0x0010, // 00100000
3172+ 0x0012, // 00100001
3173+ 0x0011, // 00100010
3174+ 0x0013, // 00100011
3175+ 0x0018, // 00100100
3176+ 0x001a, // 00100101
3177+ 0x0019, // 00100110
3178+ 0x001b, // 00100111
3179+ 0x0014, // 00101000
3180+ 0x0016, // 00101001
3181+ 0x0015, // 00101010
3182+ 0x0017, // 00101011
3183+ 0x001c, // 00101100
3184+ 0x001e, // 00101101
3185+ 0x001d, // 00101110
3186+ 0x001f, // 00101111
3187+ 0x0030, // 00110000
3188+ 0x0032, // 00110001
3189+ 0x0031, // 00110010
3190+ 0x0033, // 00110011
3191+ 0x0038, // 00110100
3192+ 0x003a, // 00110101
3193+ 0x0039, // 00110110
3194+ 0x003b, // 00110111
3195+ 0x0034, // 00111000
3196+ 0x0036, // 00111001
3197+ 0x0035, // 00111010
3198+ 0x0037, // 00111011
3199+ 0x003c, // 00111100
3200+ 0x003e, // 00111101
3201+ 0x003d, // 00111110
3202+ 0x003f, // 00111111
3203+};
3204+
31303205 // Octant bitmask array indexed by octant. The mask value indicates the octant's halfspace partitioning. The index
31313206 // value corresponds to the voxel's octal code derived in "pointToVoxel" in SharedUtil.cpp, which, BTW, does *not*
31323207 // correspond to the "ChildIndex" enum value in OctreeElement.h