Skip to main content

UniformValueBag.ixx File

Scope-local, typed storage for shader uniform values. More...

Included Headers

#include <array> #include <bitset> #include <cassert> #include <utility> #include <variant> #include <helios.engine.rendering.shader.types.uniforms> #include <helios.engine.rendering.shader.types.UniformSemantics> #include <helios.math.types>

Namespaces Index

namespacehelios
namespaceengine
namespacerendering
namespaceshader

Classes Index

classUniformValueBag<TUniformScope>

Typed uniform container keyed by compile-time uniform tags. More...

Description

Scope-local, typed storage for shader uniform values.

File Listing

The file content with the documentation metadata removed is:

1
5module;
6
7#include <array>
8#include <bitset>
9#include <cassert>
10#include <utility>
11#include <variant>
12
13export module helios.engine.rendering.shader.UniformValueBag;
14
15import helios.math.types;
16
17import helios.engine.rendering.shader.types.UniformSemantics;
18import helios.engine.rendering.shader.types.uniforms;
19
20
23
28 template<typename TUniformScope>
30 helios::math::mat4f modelMatrix;
31 helios::math::mat4f projectionMatrix;
32 helios::math::mat4f viewMatrix;
33 helios::math::vec4f materialBaseColor;
34
35 helios::math::vec4f textColor;
36
37 int textTexture;
38
39 float materialRoughness;
40 float deltaTime;
41 float totalTime;
42
43 std::bitset<std::to_underlying(UniformSemantics::size_)> active_;
44
45 public :
46
52 }
53
54
58 void clearValues() {
59 modelMatrix = helios::math::mat4f();
60 projectionMatrix = helios::math::mat4f();
61 viewMatrix = helios::math::mat4f();
62 materialBaseColor = helios::math::vec4f();
63 textColor = helios::math::vec4f();
64
65 textTexture = 0;
66
67 materialRoughness = 0.0f;
68 deltaTime = 0.0f;
69 totalTime = 0.0f;
70 }
71
77 template<typename TUniform>
79 return active_.test(std::to_underlying(TUniform::semantics));
80 }
81
87 [[nodiscard]] bool has(const UniformSemantics semantics) const noexcept {
88 return active_.test(std::to_underlying(semantics));
89 }
90
96 template<typename TUniform>
97 [[nodiscard]] const typename TUniform::value_type& get() {
98 if constexpr (std::same_as<TUniform, ModelMatrixUniform>) {
99 return modelMatrix;
100 } else if constexpr (std::same_as<TUniform, ViewMatrixUniform>) {
101 return viewMatrix;
102 } else if constexpr (std::same_as<TUniform, ProjectionMatrixUniform>) {
103 return projectionMatrix;
104 } else if constexpr (std::same_as<TUniform, MaterialBaseColorUniform>) {
105 return materialBaseColor;
106 } else {
107 assert(false && "Unsupported uniform type in UniformValueBag::value");
108 }
109
110
111 }
112
118 template<typename TUniform>
119 void set (const typename TUniform::value_type& value) {
120 if constexpr (std::same_as<TUniform, ModelMatrixUniform>) {
121 modelMatrix = value;
122 } else if constexpr (std::same_as<TUniform, ViewMatrixUniform>) {
123 viewMatrix = value;
124 } else if constexpr (std::same_as<TUniform, ProjectionMatrixUniform>) {
125 projectionMatrix = value;
126 } else if constexpr (std::same_as<TUniform, MaterialBaseColorUniform>) {
127 materialBaseColor = value;
128 } else {
129 assert(false && "Unsupported uniform type in UniformValueBag::value");
130 }
131
132 active_.set(std::to_underlying(TUniform::semantics));
133 }
134
140 [[nodiscard]] const helios::math::mat4f* mat4f(const UniformSemantics semantics) const noexcept {
141 if (!has(semantics)) {
142 return nullptr;
143 }
144
145 switch (semantics) {
146 case UniformSemantics::ModelMatrix:
147 return &modelMatrix;
148 case UniformSemantics::ViewMatrix:
149 return &viewMatrix;
150 case UniformSemantics::ProjectionMatrix:
151 return &projectionMatrix;
152 default:
153 assert(false && "Unsupported uniform type in UniformValueBag::value");
154 }
155 }
156
162 [[nodiscard]] const helios::math::vec4f* vec4f(const UniformSemantics semantics) const noexcept {
163 if (!has(semantics)) {
164 return nullptr;
165 }
166
167 switch (semantics) {
168 case UniformSemantics::MaterialBaseColor:
169 return &materialBaseColor;
170 case UniformSemantics::TextColor:
171 return &textColor;
172 default:
173 assert(false && "Unsupported uniform type in UniformValueBag::value");
174 }
175 }
176 };
177
178}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.