Skip to main content

OpenGLUniformWriter.ixx File

Applies prepared uniform write operations to the currently bound OpenGL program. More...

Included Headers

#include <glad/gl.h> #include <span> #include <cassert> #include <helios.math.types> #include <helios.opengl.types> #include <helios.engine.rendering.shader> #include <helios.opengl.types.OpenGLUniformWriteOperation>

Namespaces Index

namespacehelios
namespaceopengl

Classes Index

classOpenGLUniformWriter

Executes typed uniform uploads based on pre-resolved OpenGL locations. More...

Description

Applies prepared uniform write operations to the currently bound OpenGL program.

File Listing

The file content with the documentation metadata removed is:

1
5module;
6
7#include <glad/gl.h>
8#include <span>
9#include <cassert>
10
11export module helios.opengl.OpenGLUniformWriter;
12
13import helios.opengl.types.OpenGLUniformWriteOperation;
14import helios.engine.rendering.shader;
15import helios.math.types;
16
17import helios.opengl.types;
18
19using namespace helios::opengl::types;
20using namespace helios::engine::rendering::shader;
21using namespace helios::engine::rendering::shader::types;
22export namespace helios::opengl {
23
28
29
30 public:
31
43 template<typename TUniformScope>
44 static void write(
45 std::span<OpenGLUniformWriteOperation> operations,
46 UniformValueBag<TUniformScope>& uniformValueBag
47 ) noexcept {
48
49 for (std::size_t i = 0; i < operations.size(); ++i) {
50 auto& op = operations[i];
51 GLint location = op.location;
52 if (location == -1) {
53 continue;
54 }
55
56 auto semantics = static_cast<UniformSemantics>(op.semantics);
57 switch (semantics) {
58 case UniformSemantics::ViewMatrix:
59 if (uniformValueBag.template has<ViewMatrixUniform>()) {
60 glUniformMatrix4fv(location, 1, false,
61 helios::math::value_ptr(uniformValueBag.template get<ViewMatrixUniform>()));
62 }
63 break;
64 case UniformSemantics::ProjectionMatrix:
65 if (uniformValueBag.template has<ProjectionMatrixUniform>()) {
66 glUniformMatrix4fv(location, 1, false,
67 helios::math::value_ptr(uniformValueBag.template get<ProjectionMatrixUniform>()));
68 }
69 break;
70 case UniformSemantics::ModelMatrix:
71 if (uniformValueBag.template has<ModelMatrixUniform>()) {
72 glUniformMatrix4fv(location, 1, false,
73 helios::math::value_ptr(uniformValueBag.template get<ModelMatrixUniform>()));
74 }
75 break;
76 case UniformSemantics::MaterialBaseColor:
77 if (uniformValueBag.template has<MaterialBaseColorUniform>()) {
78 glUniform4fv(location, 1,
79 helios::math::value_ptr(uniformValueBag.template get<MaterialBaseColorUniform>()));
80 }
81 break;
82 default:
83 assert(false && "Missing support for Uniform");
84 break;
85 }
86
87 }
88
89 }
90
91
92 };
93}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.