OpenGLShader.ixx File
OpenGL implementation of shader program management. More...
Included Headers
#include <glad/gl.h>
#include <format>
#include <stdexcept>
#include <string>
#include <helios/helios_config.h>
#include <helios.rendering.shader.UniformValueMap>
#include <helios.ext.opengl.rendering.shader.OpenGLUniformLocationMap>
#include <helios.rendering.shader.UniformSemantics>
#include <helios.util.io.StringFileReader>
#include <helios.rendering.shader.Shader>
Namespaces Index
| namespace | helios |
| namespace | ext |
|
Platform-specific extensions and backend implementations. More... | |
| namespace | opengl |
|
OpenGL-specific implementations. More... | |
| namespace | rendering |
|
OpenGL rendering implementations. More... | |
| namespace | shader |
|
OpenGL shader implementations. More... | |
Classes Index
| class | OpenGLShader |
|
An OpenGL-specific implementation of a Shader program, consisting of a vertex and a fragment shader. More... | |
Description
OpenGL implementation of shader program management.
File Listing
The file content with the documentation metadata removed is:
23export namespace helios::ext::opengl::rendering::shader {
34 class OpenGLShader : public helios::rendering::shader::Shader {
60 const helios::util::io::StringFileReader& stringFileReader
62 logger_.info(std::format("Loading shader from {0}, {1}", vertexShaderPath, fragmentShaderPath));
63 if (!stringFileReader.readInto(fragmentShaderPath, fragmentShaderSource_) ||
64 !stringFileReader.readInto(vertexShaderPath, vertexShaderSource_)) {
65 logger_.error("Could not load shader");
79 if (progId_ != 0) {
80 logger_.warn("Shader already compiled");
103 logger_.error("VERTEX::COMPILATION_FAILED " + static_cast<std::string>(infoLog));
110 logger_.error("SHADER::FRAGMENT::COMPILATION_FAILED " + static_cast<std::string>(infoLog));
114 progId_ = glCreateProgram();
116 glAttachShader(progId_, vertexShader);
117 glAttachShader(progId_, fragmentShader);
118 glLinkProgram(progId_);
120 glGetProgramiv(progId_, GL_LINK_STATUS, &success);
122 glGetProgramInfoLog(progId_, 512, nullptr, infoLog);
123 logger_.error("PROGRAM_LINKING_FAILED " + static_cast<std::string>(infoLog));
135 logger_.info("Shader loaded and linked");
148 std::unique_ptr<const OpenGLUniformLocationMap> uniformLocationMap_ = nullptr;
158 OpenGLShader(const OpenGLShader&)=delete;
159 OpenGLShader& operator =(const OpenGLShader&) = delete;
176 const helios::util::io::StringFileReader& stringFileReader
182 logger_.error("Could not initialize shader");
196 if (!progId_) {
197 logger_.error("Cannot use shader, progId_ is invalid");
199 glUseProgram(progId_);
207 ~OpenGLShader() override {
208 if (progId_ != 0) {
209 glDeleteProgram(progId_);
220 void setUniformLocationMap(
222 uniformLocationMap_ = std::move(uniformLocationMap);
235 [[nodiscard]] int uniformLocation(
236 helios::rendering::shader::UniformSemantics uniformSemantics) const noexcept {
237 if (uniformLocationMap_) {
238 return uniformLocationMap_->get(uniformSemantics);
247 void applyUniformValues(
248 const helios::rendering::shader::UniformValueMap& uniformValueMap) const noexcept override {
250 if (const auto viewMatrixUniform = uniformLocation(helios::rendering::shader::UniformSemantics::ViewMatrix); viewMatrixUniform != -1) {
251 if (const auto* mat4f_ptr = uniformValueMap.mat4f_ptr(helios::rendering::shader::UniformSemantics::ViewMatrix)) {
256 if (const auto projectionMatrixUniform = uniformLocation(helios::rendering::shader::UniformSemantics::ProjectionMatrix); projectionMatrixUniform != -1) {
257 if (const auto* mat4f_ptr = uniformValueMap.mat4f_ptr(helios::rendering::shader::UniformSemantics::ProjectionMatrix)) {
262 if (const auto modelMatrixUniform = uniformLocation(helios::rendering::shader::UniformSemantics::ModelMatrix); modelMatrixUniform != -1) {
263 if (const auto* mat4f_ptr = uniformValueMap.mat4f_ptr(helios::rendering::shader::UniformSemantics::ModelMatrix)) {
267 if (const auto materialBaseColorUniform = uniformLocation(helios::rendering::shader::UniformSemantics::MaterialBaseColor); materialBaseColorUniform != -1) {
268 if (const auto* vec4f_ptr = uniformValueMap.vec4f_ptr(helios::rendering::shader::UniformSemantics::MaterialBaseColor)) {
274 if (const auto textColorUniform = uniformLocation(helios::rendering::shader::UniformSemantics::TextColor); textColorUniform != -1) {
275 if (const auto* vec4f_ptr = uniformValueMap.vec4f_ptr(helios::rendering::shader::UniformSemantics::TextColor)) {
279 if (const auto textTextureUniform = uniformLocation(helios::rendering::shader::UniformSemantics::TextTexture); textTextureUniform != -1) {
280 if (const auto* int_ptr = uniformValueMap.int_ptr(helios::rendering::shader::UniformSemantics::TextTexture)) {
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.