Skip to main content

OpenGLUniformLocationCacheStrategy.ixx File

Strategy that resolves shader uniform names into OpenGL write-operation plans. More...

Included Headers

#include <glad/gl.h> #include <vector> #include <cassert> #include <helios.opengl.components.OpenGLUniformWriteOperationsComponent> #include <helios.engine.util.log> #include <helios.engine.rendering.shader.types> #include <helios.engine.runtime.world.UpdateContext> #include <helios.opengl.components.OpenGLShaderComponent> #include <helios.engine.rendering.shader.concepts.IsShaderHandle> #include <helios.engine.runtime.world.EngineWorld> #include <helios.engine.rendering.shader.components.UniformMappingsComponent>

Namespaces Index

namespacehelios
namespaceopengl

Classes Index

classOpenGLUniformLocationCacheStrategy<THandle>

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

Macro Definitions Index

#defineHELIOS_LOG_SCOPE   "helios::opengl::OpenGLUniformLocationCacheStrategy"

Description

Strategy that resolves shader uniform names into OpenGL write-operation plans.

Macro Definitions

HELIOS_LOG_SCOPE

#define HELIOS_LOG_SCOPE   "helios::opengl::OpenGLUniformLocationCacheStrategy"

Definition at line 31 of file OpenGLUniformLocationCacheStrategy.ixx.

31#define HELIOS_LOG_SCOPE "helios::opengl::OpenGLUniformLocationCacheStrategy"

File Listing

The file content with the documentation metadata removed is:

1
5module;
6
7#include <glad/gl.h>
8#include <vector>
9#include <cassert>
10
11export module helios.opengl.OpenGLUniformLocationCacheStrategy;
12
13import helios.engine.rendering.shader.components.UniformMappingsComponent;
14import helios.engine.runtime.world.EngineWorld;
15import helios.engine.runtime.world.UpdateContext;
16import helios.engine.rendering.shader.concepts.IsShaderHandle;
17import helios.engine.rendering.shader.types;
18
19import helios.engine.util.log;
20
21import helios.opengl.components.OpenGLUniformWriteOperationsComponent;
22import helios.opengl.components.OpenGLShaderComponent;
23
24using namespace helios::engine::runtime::world;
25using namespace helios::engine::rendering::shader::concepts;
26using namespace helios::engine::rendering::shader::components;
27using namespace helios::engine::rendering::shader::types;
28using namespace helios::engine::util::log;
29using namespace helios::opengl::components;
30
31#define HELIOS_LOG_SCOPE "helios::opengl::OpenGLUniformLocationCacheStrategy"
32export namespace helios::opengl {
33
38 template<typename THandle>
39 requires IsShaderHandle<THandle>
41
42 static inline const Logger& logger_ = LogManager::loggerForScope(HELIOS_LOG_SCOPE);
43
44 public:
45
46
59 template<typename TUniformScope>
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 }
106
107 };
108}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.