Skip to main content

OpenGLUniformLocationMap.ixx File

Maps shader uniform semantics to OpenGL uniform locations. More...

Included Headers

#include <array> #include <optional> #include <cassert> #include <format> #include <utility> #include <helios.util.log.Logger> #include <helios.util.log.LogManager> #include <helios.rendering.shader.UniformSemantics>

Namespaces Index

namespacehelios
namespaceext

Platform-specific extensions and backend implementations. More...

namespaceopengl

OpenGL-specific implementations. More...

namespacerendering

OpenGL rendering implementations. More...

namespaceshader

OpenGL shader implementations. More...

Classes Index

classOpenGLUniformLocationMap

Manages the mapping between OpenGL uniform semantics and their locations in an underlying OpenGL shader. More...

Macro Definitions Index

#defineHELIOS_LOG_SCOPE   "helios::ext::opengl::rendering::shader::OpenGLUniformLocationMap"

Description

Maps shader uniform semantics to OpenGL uniform locations.

Macro Definitions

HELIOS_LOG_SCOPE

#define HELIOS_LOG_SCOPE   "helios::ext::opengl::rendering::shader::OpenGLUniformLocationMap"

Definition at line 20 of file OpenGLUniformLocationMap.ixx.

20#define HELIOS_LOG_SCOPE "helios::ext::opengl::rendering::shader::OpenGLUniformLocationMap"

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file OpenGLUniformLocationMap.ixx
3 * @brief Maps shader uniform semantics to OpenGL uniform locations.
4 */
5module;
6
7
8#include <array>
9#include <optional>
10#include <cassert>
11#include <format>
12#include <utility>
13
14export module helios.ext.opengl.rendering.shader.OpenGLUniformLocationMap;
15
16import helios.rendering.shader.UniformSemantics;
17import helios.util.log.LogManager;
18import helios.util.log.Logger;
19
20#define HELIOS_LOG_SCOPE "helios::ext::opengl::rendering::shader::OpenGLUniformLocationMap"
22
23
24 /**
25 * @brief Manages the mapping between OpenGL uniform semantics and their locations
26 * in an underlying OpenGL shader.
27 *
28 * This class should be used to store and retrieve the uniform locations, e.g.
29 * for a OpenGL render backend for easy access.
30 */
32
33 private:
34 /**
35 * @brief Bit mask serving as sentinel to keep track of set indices.
36 * Since position 0 is allowed for uniform locations, this bitmask keeps
37 * track of set indices in `map_`.
38 */
39 unsigned int sentinel_ = 0;
40
41 /**
42 * @brief The internal map used for mapping uniform semantics to positions.
43 */
44 std::array<int, std::to_underlying(helios::rendering::shader::UniformSemantics::size_)> map_ = {};
45
46 /**
47 * @brief Shared logger instance for all OpenGLUniformLocationMap objects.
48 */
51 );
52
53 public:
55
56 /**
57 * Make sure the sentinel has enough bits to keep track of the entries
58 * of the UniformSemantics enum.
59 */
60 static_assert(
62 <= (sizeof(sentinel_) * 8) && "sentinel type is too narrow");
63
64 /**
65 * @brief Default constructor for a OpenGLUniformLocationMap.
66 */
68
69 /**
70 * @brief Sets or updates the OpenGLUniform.
71 * If the semantics already exists in the map, it is updated with `position`.
72 *
73 * @param uniformSemantics The uniformSemantics to register with `position`
74 * @param position A positive integer value as the location of the uniform represented by
75 * uniformSemantics.
76 *
77 * @return true if the position for the specified uniformSemantics was registered with this
78 * map, otherwise false (e.g. if position was < 0)
79 */
80 bool set(
82 int position
83 ) noexcept {
84 assert(position >= 0 && "position must not be less than 0");
85
86 const decltype(sentinel_) index = std::to_underlying(uniformSemantics);
87
88 sentinel_ = (sentinel_ | (decltype(sentinel_){1} << index));
89 map_[std::to_underlying(uniformSemantics)] = position;
90 return true;
91 }
92
93 /**
94 * @brief Returns the index of the uniform variable for the specified UniformSemantics
95 * as configured with this location map.
96 * This method returns -1 if the specified semantics is not configured with this map.
97 *
98 * @param uniformSemantics The UniformSemantics for which the location index
99 * should be returned.
100 *
101 * @return The index as previously set for the specified uniformSemantics, or -1
102 * if not found.
103 *
104 * @see glGetUniformLocation
105 * @see [KSS17, 47]
106 */
107 [[nodiscard]] int get(helios::rendering::shader::UniformSemantics uniformSemantics) const noexcept {
108 const decltype(sentinel_) index = std::to_underlying(uniformSemantics);
109
110 if (!(sentinel_ & (decltype(sentinel_){1} << index))) {
111 return -1;
112 }
113
114 return map_[index];
115 }
116 };
117
118
119}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.