diff options
author | chai <chaifix@163.com> | 2019-08-14 22:50:43 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-08-14 22:50:43 +0800 |
commit | 15740faf9fe9fe4be08965098bbf2947e096aeeb (patch) | |
tree | a730ec236656cc8cab5b13f088adfaed6bb218fb /Runtime/Shaders/ShaderKeywords.h |
Diffstat (limited to 'Runtime/Shaders/ShaderKeywords.h')
-rw-r--r-- | Runtime/Shaders/ShaderKeywords.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Runtime/Shaders/ShaderKeywords.h b/Runtime/Shaders/ShaderKeywords.h new file mode 100644 index 0000000..7a273bb --- /dev/null +++ b/Runtime/Shaders/ShaderKeywords.h @@ -0,0 +1,43 @@ +#pragma once + +#include <string> + +typedef int ShaderKeyword; + +// We use about 14 builtin keywords now, 18 more for the user should be fine now +// (shader size explosion will happen before that limit is reached anyways...) +const int kMaxShaderKeywords = 64; +struct ShaderKeywordSet { +public: + explicit ShaderKeywordSet () : mask(0) {} + + void Enable (ShaderKeyword key) { mask |= (0x1ULL<<key); } + void Disable (ShaderKeyword key) { mask &= ~(0x1ULL<<key); } + bool IsEnabled (ShaderKeyword key) const { return (mask & (0x1ULL<<key)) != 0; } + void Reset () { mask = 0; } + + UInt64 GetMask() const { return mask; } + void SetMask (UInt64 m) { mask = m; } + + bool operator== (const ShaderKeywordSet& o) const { return mask==o.mask; } + bool operator!= (const ShaderKeywordSet& o) const { return mask!=o.mask; } + +private: + UInt64 mask; +}; + +extern ShaderKeywordSet g_ShaderKeywords; + + +namespace keywords { + + void Initialize(); + void Cleanup(); + + ShaderKeyword Create( const std::string& name ); + + #if UNITY_EDITOR + std::string GetKeywordName (ShaderKeyword k); + #endif + +} // namespace keywords |