yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
1#include "flag-combiner.h" 2 3namespace gfx 4{ 5using namespace Slang ; 6 7void FlagCombiner ::add (uint32_t flags ,ChangeType type ) 8{ 9// The flag/s must be set 10SLANG_ASSERT (flags ); 11SLANG_ASSERT ((flags & m_usedFlags )== 0 ); 12// Mark the flags used 13m_usedFlags |=flags ; 14 15if (type == ChangeType ::On || type == ChangeType ::OnOff ) 16 { 17m_invertBits |=flags ; 18 } 19if (type == ChangeType ::OnOff || type == ChangeType ::OffOn ) 20 { 21m_changingBits [m_numChangingBits ++ ]= flags ; 22 } 23} 24 25void FlagCombiner ::calcCombinations (List < uint32_t >& outCombinations )const 26{ 27const int numCombinations = getNumCombinations (); 28outCombinations .setCount (numCombinations ); 29uint32_t * dstCombinations = outCombinations .getBuffer (); 30for (int i = 0 ;i < numCombinations ;++ i ) 31 { 32dstCombinations [i ]= getCombination (i ); 33 } 34} 35 36uint32_t FlagCombiner ::getCombination (int index )const 37{ 38SLANG_ASSERT (index >=0 && index < getNumCombinations ()); 39 40uint32_t combination = 0 ; 41uint32_t bit = 1 ; 42for (int i = m_numChangingBits - 1 ;i >=0 ;-- i ,bit += bit ) 43 { 44combination |= ((bit & index ) ?m_changingBits [i ] :0 ); 45 } 46return combination ^m_invertBits ; 47} 48 49void FlagCombiner ::reset () 50{ 51m_numChangingBits = 0 ; 52m_usedFlags = 0 ; 53m_invertBits = 0 ; 54} 55 56}// namespace gfx