-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathShaderOptions.h
131 lines (117 loc) · 4.23 KB
/
ShaderOptions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// ------------------------------------------------------------
// Copyright(c) 2018-2022 Jesse Yurkovich
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
// See the LICENSE file in the repo root for full license information.
// ------------------------------------------------------------
#pragma once
#include <cstdint>
#include <stdexcept>
#include <string>
#include <vector>
enum class ShaderOptions : uint64_t
{
// clang-format off
None = 0,
USE_AUTO_COLOR = (1u << 0u),
USE_FACTORS_ONLY = (1u << 1u),
USE_MANUAL_SRGB = (1u << 2u),
USE_IBL = (1u << 3u),
HAS_BASECOLORMAP = (1u << 4u),
HAS_TANGENTS = (1u << 5u),
HAS_NORMALMAP = (1u << 6u),
HAS_METALROUGHNESSMAP = (1u << 7u),
HAS_OCCLUSIONMAP = (1u << 8u),
HAS_OCCLUSIONMAP_COMBINED = (1u << 9u),
HAS_EMISSIVEMAP = (1u << 10u),
IS_GROUND = (1u << 12u),
// clang-format on
};
inline constexpr ShaderOptions operator|(ShaderOptions a, ShaderOptions b) noexcept
{
return static_cast<ShaderOptions>(static_cast<uint64_t>(a) | static_cast<uint64_t>(b));
}
inline ShaderOptions & operator|=(ShaderOptions & a, ShaderOptions b) noexcept
{
return reinterpret_cast<ShaderOptions &>(reinterpret_cast<uint64_t &>(a) |= static_cast<uint64_t>(b));
}
inline constexpr ShaderOptions operator&(ShaderOptions a, ShaderOptions b) noexcept
{
return static_cast<ShaderOptions>(static_cast<uint64_t>(a) & static_cast<uint64_t>(b));
}
inline ShaderOptions & operator&=(ShaderOptions & a, ShaderOptions b) noexcept
{
return reinterpret_cast<ShaderOptions &>(reinterpret_cast<uint64_t &>(a) &= static_cast<uint64_t>(b));
}
inline constexpr ShaderOptions operator~(ShaderOptions a) noexcept
{
return static_cast<ShaderOptions>(~static_cast<uint64_t>(a));
}
inline constexpr ShaderOptions operator^(ShaderOptions a, ShaderOptions b) noexcept
{
return static_cast<ShaderOptions>(static_cast<uint64_t>(a) ^ static_cast<uint64_t>(b));
}
inline ShaderOptions & operator^=(ShaderOptions & a, ShaderOptions b) noexcept
{
return reinterpret_cast<ShaderOptions &>(reinterpret_cast<uint64_t &>(a) ^= static_cast<uint64_t>(b));
}
inline constexpr bool IsSet(ShaderOptions options, ShaderOptions flag) noexcept
{
return (options & flag) == flag;
}
inline std::vector<std::string> GetShaderDefines(ShaderOptions options)
{
std::vector<std::string> defines;
if (IsSet(options, ShaderOptions::USE_AUTO_COLOR))
{
defines.emplace_back("USE_AUTO_COLOR");
}
if (IsSet(options, ShaderOptions::USE_FACTORS_ONLY))
{
defines.emplace_back("USE_FACTORS_ONLY");
}
if (IsSet(options, ShaderOptions::USE_MANUAL_SRGB))
{
defines.emplace_back("USE_MANUAL_SRGB");
}
if (IsSet(options, ShaderOptions::USE_IBL))
{
defines.emplace_back("USE_IBL");
}
if (IsSet(options, ShaderOptions::HAS_BASECOLORMAP))
{
defines.emplace_back("HAS_BASECOLORMAP");
}
if (IsSet(options, ShaderOptions::HAS_TANGENTS))
{
defines.emplace_back("HAS_TANGENTS");
}
if (IsSet(options, ShaderOptions::HAS_NORMALMAP))
{
defines.emplace_back("HAS_NORMALMAP");
}
if (IsSet(options, ShaderOptions::HAS_METALROUGHNESSMAP))
{
defines.emplace_back("HAS_METALROUGHNESSMAP");
}
if (IsSet(options, ShaderOptions::HAS_OCCLUSIONMAP))
{
defines.emplace_back("HAS_OCCLUSIONMAP");
}
if (IsSet(options, ShaderOptions::HAS_OCCLUSIONMAP_COMBINED))
{
if (!IsSet(options, ShaderOptions::HAS_METALROUGHNESSMAP))
{
throw std::runtime_error("Invalid ShaderOptions. HAS_OCCLUSIONMAP_COMBINED requires HAS_METALROUGHNESSMAP");
}
defines.emplace_back("HAS_OCCLUSIONMAP_COMBINED");
}
if (IsSet(options, ShaderOptions::HAS_EMISSIVEMAP))
{
defines.emplace_back("HAS_EMISSIVEMAP");
}
if (IsSet(options, ShaderOptions::IS_GROUND))
{
defines.emplace_back("IS_GROUND");
}
return defines;
}