Skip to main content

OpenGLUniformLocationCacheStrategy Class Template

Builds OpenGL uniform write-operation plans for one shader entity. More...

Declaration

template <typename THandle> class helios::opengl::OpenGLUniformLocationCacheStrategy<THandle> { ... }

Public Member Functions Index

template <typename TUniformScope>
boolcacheUniforms (THandle entityHandle, RenderResourceWorld &renderResourceWorld, UpdateContext &updateContext)

Resolves configured uniform names and stores write operations. More...

Private Static Attributes Index

template <typename THandle>
static const Logger &logger_ = LogManager::loggerForScope(HELIOS_LOG_SCOPE)

Description

Builds OpenGL uniform write-operation plans for one shader entity.

Template Parameters
THandle

Shader handle type.

Definition at line 40 of file OpenGLUniformLocationCacheStrategy.ixx.

Public Member Functions

cacheUniforms()

template <typename TUniformScope>
bool helios::opengl::OpenGLUniformLocationCacheStrategy< THandle >::cacheUniforms (THandle entityHandle, RenderResourceWorld & renderResourceWorld, UpdateContext & updateContext)
inline

Resolves configured uniform names and stores write operations.

Template Parameters
TUniformScope

Uniform lifetime scope (for example pass or draw).

Parameters
entityHandle

Shader entity handle.

renderResourceWorld

Render-resource world containing shader entities.

updateContext

Frame-local update context.

Returns

true when mapping processing completed, otherwise false.

Reads UniformMappingsComponent, queries locations via glGetUniformLocation, appends resolved entries to OpenGLUniformWriteOperationsComponent, and removes the mapping component after processing.

Definition at line 60 of file OpenGLUniformLocationCacheStrategy.ixx.

60 [[nodiscard]] bool cacheUniforms(
61 THandle entityHandle,
62 RenderResourceWorld& renderResourceWorld,
63 UpdateContext& updateContext
64 ) {
65 auto shaderEntity = renderResourceWorld.findEntity(entityHandle);
66
67 if (!shaderEntity) {
68 logger_.error("ShaderEntity not found.");
69 assert(shaderEntity && "ShaderEntity not found.");
70 return false;
71 }
72
73 auto* umc = shaderEntity->template get<UniformMappingsComponent<THandle, TUniformScope>>();
74 if (!umc) {
75 logger_.info("No UniformMappingsComponent available.");
76 return false;
77 }
78
79 auto* osc = shaderEntity->template get<OpenGLShaderComponent<THandle>>();
80 if (!osc) {
81 logger_.info("No OpenGLShaderComponent available.");
82 return false;
83 }
84
85 GLuint programId = osc->programId;
86
87 auto& ulc = shaderEntity->template getOrAdd<OpenGLUniformWriteOperationsComponent<THandle, TUniformScope>>();
88
89 for (std::size_t i = 0; i < umc->mappings.size(); ++i ) {
90 if (!umc->mappings[i].empty()) {
91 GLint location = glGetUniformLocation(programId, umc->mappings[i].c_str());
92 if (location != -1) {
93 ulc.operations.emplace_back(static_cast<UniformSemantics>(i), location);
94 logger_.warn("Assigning uniform to plan: {0} to {1}", umc->mappings[i], location);
95 } else {
96 logger_.warn("Assigning uniform to plan failed. Expected uniform for {0}, but found nothing", umc->mappings[i]);
97 }
98
99 }
100 }
101
102 shaderEntity->template remove<UniformMappingsComponent<THandle, TUniformScope>>();
103
104 return true;
105 }

Private Static Attributes

logger_

template <typename THandle>
const Logger& helios::opengl::OpenGLUniformLocationCacheStrategy< THandle >::logger_ = LogManager::loggerForScope(HELIOS_LOG_SCOPE)
static

Definition at line 42 of file OpenGLUniformLocationCacheStrategy.ixx.

42 static inline const Logger& logger_ = LogManager::loggerForScope(HELIOS_LOG_SCOPE);

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.