Skip to main content

UniformValueMap Class

Maps uniform semantics to their values for shader parameter binding. More...

Declaration

class UniformValueMap { ... }

Public Constructors Index

UniformValueMap ()=default

Default constructor. More...

Public Destructor Index

~UniformValueMap ()=default

Default destructor. More...

Public Member Functions Index

voidset (UniformSemantics uniformSemantics, const helios::math::mat4f &mat4f) noexcept

Sets or updates a `helios::math::mat4f` uniform value for a given semantic. More...

voidset (UniformSemantics uniformSemantics, const helios::math::vec4f &vec4f) noexcept

Sets or updates a `helios::math::vec4f` uniform value for a given semantic. More...

voidset (UniformSemantics uniformSemantics, int value) noexcept

Sets or updates an integer uniform value for a given semantic. More...

voidset (UniformSemantics uniformSemantics, float value) noexcept

Sets or updates a float uniform value for a given semantic. More...

const float *mat4f_ptr (UniformSemantics uniformSemantics) const noexcept

Returns a raw const pointer to the `mat4f` for the specified uniform semantics. More...

const helios::math::mat4f *mat4f (UniformSemantics uniformSemantics) const noexcept

Returns a const pointer to the `mat4f` value for the specified uniform semantics. More...

const float *vec4f_ptr (UniformSemantics uniformSemantics) const noexcept

Returns a raw const pointer to the `vec4f` for the specified uniform semantics. More...

const float *float_ptr (UniformSemantics uniformSemantics) const noexcept

Returns a raw const pointer to the float value for the specified uniform semantics. More...

const int *int_ptr (UniformSemantics uniformSemantics) const noexcept

Returns a raw const pointer to the integer value for the specified uniform semantics. More...

Private Member Attributes Index

std::array< std::optional< UniformValue >, std::to_underlying(UniformSemantics::size_)>map_

Internal data structure storing the association between a uniform semantic and a concrete value. More...

Description

Maps uniform semantics to their values for shader parameter binding.

`UniformValueMap` stores uniform values (matrices, vectors, scalars) indexed by their `UniformSemantics` identifier. This allows the rendering pipeline to efficiently pass data to shaders without string-based lookups.

## Supported Types

  • `mat4f` – 4x4 transformation matrices
  • `vec4f` – 4-component vectors (colors, positions)
  • `float` – Scalar values (roughness, time)
  • `int` – Integer values (texture units)

## Usage

```cpp UniformValueMap uniforms;

// Set transform matrices uniforms.set(UniformSemantics::ModelMatrix, modelMat); uniforms.set(UniformSemantics::ViewMatrix, viewMat);

// Set material properties uniforms.set(UniformSemantics::MaterialBaseColor, vec4f{1.0f, 0.0f, 0.0f, 1.0f});

// Retrieve raw pointer for OpenGL const float* modelPtr = uniforms.mat4f_ptr(UniformSemantics::ModelMatrix); ```

Todo

UniformMap must allow only one index for all data structures, i.e. if map_[semantics] contains a mat4f, other types should not be allowed for the same semantics.

Todo

UniformValueMaps should be scoped, e.g. per frame (world matrix, projection, view...), per material (colors, emissive...), per object (world matrix...), which allows for better handling of assigning uniforms: per-frame values change once per frame, while per-object values change per object.

Definition at line 71 of file UniformValueMap.ixx.

Public Constructors

UniformValueMap()

helios::rendering::shader::UniformValueMap::UniformValueMap ()
default

Default constructor.

Initializes an empty uniform value map with no values set.

Definition at line 92 of file UniformValueMap.ixx.

Public Destructor

~UniformValueMap()

helios::rendering::shader::UniformValueMap::~UniformValueMap ()
default

Default destructor.

Definition at line 85 of file UniformValueMap.ixx.

Public Member Functions

float_ptr()

const float * helios::rendering::shader::UniformValueMap::float_ptr (UniformSemantics uniformSemantics)
inline nodiscard noexcept

Returns a raw const pointer to the float value for the specified uniform semantics.

This method retrieves the float value associated with a given `UniformSemantics` identifier. If no float value is associated with the specified semantics, the method returns `nullptr`.

Parameters
uniformSemantics

The `UniformSemantics` identifier for the uniform.

Returns

A raw const pointer to the associated float value, or `nullptr` if no float value is associated with this semantics.

Definition at line 224 of file UniformValueMap.ixx.

224 [[nodiscard]] const float* float_ptr(UniformSemantics uniformSemantics) const noexcept {
225
226 const auto index = std::to_underlying(uniformSemantics);
227
228 if (index >= map_.size()) {
229 return nullptr;
230 }
231
232 if (const auto& el = map_[index]; el.has_value()) {
233 if (const auto* floatPtr = std::get_if<float>(&el.value())) {
234 return floatPtr;
235 }
236 }
237
238 return nullptr;
239 }

int_ptr()

const int * helios::rendering::shader::UniformValueMap::int_ptr (UniformSemantics uniformSemantics)
inline nodiscard noexcept

Returns a raw const pointer to the integer value for the specified uniform semantics.

Parameters
uniformSemantics

The `UniformSemantics` identifier for the uniform.

Returns

A raw const pointer to the associated integer value, or `nullptr` if no integer value is associated with this semantics.

Definition at line 249 of file UniformValueMap.ixx.

249 [[nodiscard]] const int* int_ptr(UniformSemantics uniformSemantics) const noexcept {
250
251 const auto index = std::to_underlying(uniformSemantics);
252
253 if (index >= map_.size()) {
254 return nullptr;
255 }
256
257 if (const auto& el = map_[index]; el.has_value()) {
258 if (const auto* intPtr = std::get_if<int>(&el.value())) {
259 return intPtr;
260 }
261 }
262
263 return nullptr;
264 }

mat4f()

const helios::math::mat4f * helios::rendering::shader::UniformValueMap::mat4f (UniformSemantics uniformSemantics)
inline nodiscard noexcept

Returns a const pointer to the `mat4f` value for the specified uniform semantics.

Unlike `mat4f_ptr()`, this returns a pointer to the `mat4f` object itself rather than its underlying float array.

Parameters
uniformSemantics

The `UniformSemantics` identifier for the uniform.

Returns

A const pointer to the associated `mat4f`, or `nullptr` if no mat4f is associated with this semantics.

Definition at line 140 of file UniformValueMap.ixx.

140 [[nodiscard]] const helios::math::mat4f* mat4f(UniformSemantics uniformSemantics) const noexcept {
141
142 const auto index = std::to_underlying(uniformSemantics);
143
144 if (index >= map_.size()) {
145 return nullptr;
146 }
147
148 if (const auto& el = map_[index]; el.has_value()) {
149 if (const auto* it = std::get_if<helios::math::mat4f>(&el.value())) {
150 return it;
151 }
152 }
153
154 return nullptr;
155 }

mat4f_ptr()

const float * helios::rendering::shader::UniformValueMap::mat4f_ptr (UniformSemantics uniformSemantics)
inline nodiscard noexcept

Returns a raw const pointer to the `mat4f` for the specified uniform semantics.

Parameters
uniformSemantics

The `UniformSemantics` identifier for the uniform.

Returns

A raw const pointer to the associated mat4f, or `nullptr` if no mat4f is associated with this semantics.

Definition at line 112 of file UniformValueMap.ixx.

112 [[nodiscard]] const float* mat4f_ptr(UniformSemantics uniformSemantics) const noexcept {
113
114 const auto index = std::to_underlying(uniformSemantics);
115
116 if (index >= map_.size()) {
117 return nullptr;
118 }
119
120 if (const auto& el = map_[index]; el.has_value()) {
121 if (const auto* it = std::get_if<helios::math::mat4f>(&el.value())) {
122 return helios::math::value_ptr(*it);
123 }
124 }
125
126 return nullptr;
127 }

set()

void helios::rendering::shader::UniformValueMap::set (UniformSemantics uniformSemantics, const helios::math::mat4f & mat4f)
inline noexcept

Sets or updates a `helios::math::mat4f` uniform value for a given semantic.

Parameters
uniformSemantics

The `UniformSemantics` identifier for the uniform.

mat4f

A const ref to the mat4f value to set.

Definition at line 100 of file UniformValueMap.ixx.

100 void set(UniformSemantics uniformSemantics, const helios::math::mat4f& mat4f) noexcept {
101 map_[std::to_underlying(uniformSemantics)].emplace(mat4f);
102 }

set()

void helios::rendering::shader::UniformValueMap::set (UniformSemantics uniformSemantics, const helios::math::vec4f & vec4f)
inline noexcept

Sets or updates a `helios::math::vec4f` uniform value for a given semantic.

Parameters
uniformSemantics

The `UniformSemantics` identifier for the uniform.

vec4f

A const ref to the vec4f value to set.

Definition at line 163 of file UniformValueMap.ixx.

163 void set(UniformSemantics uniformSemantics, const helios::math::vec4f& vec4f) noexcept {
164 map_[std::to_underlying(uniformSemantics)].emplace(vec4f);
165 }

set()

void helios::rendering::shader::UniformValueMap::set (UniformSemantics uniformSemantics, int value)
inline noexcept

Sets or updates an integer uniform value for a given semantic.

Typically used for texture unit indices.

Parameters
uniformSemantics

The `UniformSemantics` identifier for the uniform.

value

The integer value to set.

Definition at line 199 of file UniformValueMap.ixx.

199 void set(UniformSemantics uniformSemantics, int value) noexcept {
200 map_[std::to_underlying(uniformSemantics)].emplace(value);
201 }

set()

void helios::rendering::shader::UniformValueMap::set (UniformSemantics uniformSemantics, float value)
inline noexcept

Sets or updates a float uniform value for a given semantic.

Parameters
uniformSemantics

The `UniformSemantics` identifier for the uniform.

value

The float value to set.

Definition at line 209 of file UniformValueMap.ixx.

209 void set(UniformSemantics uniformSemantics, float value) noexcept {
210 map_[std::to_underlying(uniformSemantics)].emplace(value);
211 }

vec4f_ptr()

const float * helios::rendering::shader::UniformValueMap::vec4f_ptr (UniformSemantics uniformSemantics)
inline nodiscard noexcept

Returns a raw const pointer to the `vec4f` for the specified uniform semantics.

Parameters
uniformSemantics

The `UniformSemantics` identifier for the uniform.

Returns

A raw const pointer to the associated vec4f, or `nullptr` if no vec4f is associated with this semantics.

Definition at line 174 of file UniformValueMap.ixx.

174 [[nodiscard]] const float* vec4f_ptr(UniformSemantics uniformSemantics) const noexcept {
175
176 const auto index = std::to_underlying(uniformSemantics);
177
178 if (index >= map_.size()) {
179 return nullptr;
180 }
181
182 if (const auto& el = map_[index]; el.has_value()) {
183 if (const auto* it = std::get_if<helios::math::vec4f>(&el.value())) {
184 return helios::math::value_ptr(*it);
185 }
186 }
187
188 return nullptr;
189 }

Private Member Attributes

map_

std::array<std::optional<UniformValue>, std::to_underlying(UniformSemantics::size_)> helios::rendering::shader::UniformValueMap::map_

Internal data structure storing the association between a uniform semantic and a concrete value.

Definition at line 78 of file UniformValueMap.ixx.

78 std::array<std::optional<UniformValue>, std::to_underlying(UniformSemantics::size_)> map_;

The documentation for this class was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.