Skip to main content

OpenGLUniformLocationMap Class

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

Declaration

class helios::ext::opengl::rendering::shader::OpenGLUniformLocationMap { ... }

Public Constructors Index

OpenGLUniformLocationMap ()=default

Default constructor for a OpenGLUniformLocationMap. More...

Public Destructor Index

~OpenGLUniformLocationMap ()=default

Public Member Functions Index

boolset (const helios::rendering::shader::UniformSemantics uniformSemantics, const int position) noexcept

Sets or updates the OpenGLUniform. If the semantics already exists in the map, it is updated with `position`. More...

intget (helios::rendering::shader::UniformSemantics uniformSemantics) const noexcept

Returns the index of the uniform variable for the specified UniformSemantics as configured with this location map. This method returns -1 if the specified semantics is not configured with this map. More...

Private Member Attributes Index

unsigned intsentinel_ = 0

Bit mask serving as sentinel to keep track of set indices. Since position 0 is allowed for uniform locations, this bitmask keeps track of set indices in `map_`. More...

std::array< int, std::to_underlying(helios::rendering::shader::UniformSemantics::size_)>map_ = {}

The internal map used for mapping uniform semantics to positions. More...

Private Static Attributes Index

static const helios::util::log::Logger &logger_ = ...

Shared logger instance for all OpenGLUniformLocationMap objects. More...

Description

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

This class should be used to store and retrieve the uniform locations, e.g. for a OpenGL render backend for easy access.

Definition at line 31 of file OpenGLUniformLocationMap.ixx.

Public Constructors

OpenGLUniformLocationMap()

helios::ext::opengl::rendering::shader::OpenGLUniformLocationMap::OpenGLUniformLocationMap ()
default

Default constructor for a OpenGLUniformLocationMap.

Make sure the sentinel has enough bits to keep track of the entries of the UniformSemantics enum.

Definition at line 67 of file OpenGLUniformLocationMap.ixx.

Public Destructor

~OpenGLUniformLocationMap()

helios::ext::opengl::rendering::shader::OpenGLUniformLocationMap::~OpenGLUniformLocationMap ()
default

Definition at line 54 of file OpenGLUniformLocationMap.ixx.

Reference helios::rendering::shader::size_.

Public Member Functions

get()

int helios::ext::opengl::rendering::shader::OpenGLUniformLocationMap::get (helios::rendering::shader::UniformSemantics uniformSemantics)
inline nodiscard noexcept

Returns the index of the uniform variable for the specified UniformSemantics as configured with this location map. This method returns -1 if the specified semantics is not configured with this map.

Parameters
uniformSemantics

The UniformSemantics for which the location index should be returned.

Returns

The index as previously set for the specified uniformSemantics, or -1 if not found.

See Also

glGetUniformLocation

See Also

[KSS17, 47]

Definition at line 107 of file OpenGLUniformLocationMap.ixx.

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 }

set()

bool helios::ext::opengl::rendering::shader::OpenGLUniformLocationMap::set (const helios::rendering::shader::UniformSemantics uniformSemantics, const int position)
inline noexcept

Sets or updates the OpenGLUniform. If the semantics already exists in the map, it is updated with `position`.

Parameters
uniformSemantics

The uniformSemantics to register with `position`

position

A positive integer value as the location of the uniform represented by uniformSemantics.

Returns

true if the position for the specified uniformSemantics was registered with this map, otherwise false (e.g. if position was < 0)

Definition at line 80 of file OpenGLUniformLocationMap.ixx.

80 bool set(
82 const 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 }

Private Member Attributes

map_

std::array<int, std::to_underlying(helios::rendering::shader::UniformSemantics::size_)> helios::ext::opengl::rendering::shader::OpenGLUniformLocationMap::map_ = {}

The internal map used for mapping uniform semantics to positions.

Definition at line 44 of file OpenGLUniformLocationMap.ixx.

44 std::array<int, std::to_underlying(helios::rendering::shader::UniformSemantics::size_)> map_ = {};

sentinel_

unsigned int helios::ext::opengl::rendering::shader::OpenGLUniformLocationMap::sentinel_ = 0

Bit mask serving as sentinel to keep track of set indices. Since position 0 is allowed for uniform locations, this bitmask keeps track of set indices in `map_`.

Definition at line 39 of file OpenGLUniformLocationMap.ixx.

39 unsigned int sentinel_ = 0;

Private Static Attributes

logger_

const helios::util::log::Logger& helios::ext::opengl::rendering::shader::OpenGLUniformLocationMap::logger_
static

Shared logger instance for all OpenGLUniformLocationMap objects.

Initialiser

Definition at line 49 of file OpenGLUniformLocationMap.ixx.


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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.