yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie Hermaszewskaformatf65d756bf

master
1.3 KiB56 linesraw
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
10    SLANG_ASSERT(flags);
11    SLANG_ASSERT((flags & m_usedFlags) == 0);
12    // Mark the flags used
13    m_usedFlags |= flags;
14
15    if (type == ChangeType::On || type == ChangeType::OnOff)
16    {
17        m_invertBits |= flags;
18    }
19    if (type == ChangeType::OnOff || type == ChangeType::OffOn)
20    {
21        m_changingBits[m_numChangingBits++] = flags;
22    }
23}
24
25void FlagCombiner::calcCombinations(List<uint32_t>& outCombinations) const
26{
27    const int numCombinations = getNumCombinations();
28    outCombinations.setCount(numCombinations);
29    uint32_t* dstCombinations = outCombinations.getBuffer();
30    for (int i = 0; i < numCombinations; ++i)
31    {
32        dstCombinations[i] = getCombination(i);
33    }
34}
35
36uint32_t FlagCombiner::getCombination(int index) const
37{
38    SLANG_ASSERT(index >= 0 && index < getNumCombinations());
39
40    uint32_t combination = 0;
41    uint32_t bit = 1;
42    for (int i = m_numChangingBits - 1; i >= 0; --i, bit += bit)
43    {
44        combination |= ((bit & index) ? m_changingBits[i] : 0);
45    }
46    return combination ^ m_invertBits;
47}
48
49void FlagCombiner::reset()
50{
51    m_numChangingBits = 0;
52    m_usedFlags = 0;
53    m_invertBits = 0;
54}
55
56} // namespace gfx