LegacyOpenGLShader.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.UniformSemantics>
#include <helios.rendering.shader.UniformValueMap>
#include <helios.ext.opengl.rendering.shader.OpenGLUniformLocationMap>
#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 | LegacyOpenGLShader |
|
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 {
36 class LegacyOpenGLShader : public helios::rendering::shader::Shader {
62 const helios::util::io::StringFileReader& stringFileReader
64 logger_.info(std::format("Loading shader from {0}, {1}", vertexShaderPath, fragmentShaderPath));
65 if (!stringFileReader.readInto(fragmentShaderPath, fragmentShaderSource_) ||
66 !stringFileReader.readInto(vertexShaderPath, vertexShaderSource_)) {
67 logger_.error("Could not load shader");
81 if (progId_ != 0) {
82 logger_.warn("Shader already compiled");
105 logger_.error("VERTEX::COMPILATION_FAILED " + static_cast<std::string>(infoLog));
112 logger_.error("SHADER::FRAGMENT::COMPILATION_FAILED " + static_cast<std::string>(infoLog));
116 progId_ = glCreateProgram();
118 glAttachShader(progId_, vertexShader);
119 glAttachShader(progId_, fragmentShader);
120 glLinkProgram(progId_);
122 glGetProgramiv(progId_, GL_LINK_STATUS, &success);
124 glGetProgramInfoLog(progId_, 512, nullptr, infoLog);
125 logger_.error("PROGRAM_LINKING_FAILED " + static_cast<std::string>(infoLog));
137 logger_.info("Shader loaded and linked");
150 std::unique_ptr<const OpenGLUniformLocationMap> uniformLocationMap_ = nullptr;
160 LegacyOpenGLShader(const LegacyOpenGLShader&)=delete;
161 LegacyOpenGLShader& operator =(const LegacyOpenGLShader&) = delete;
178 const helios::util::io::StringFileReader& stringFileReader
184 logger_.error("Could not initialize shader");
198 if (!progId_) {
199 logger_.error("Cannot use shader, progId_ is invalid");
201 glUseProgram(progId_);
209 ~LegacyOpenGLShader() override {
210 if (progId_ != 0) {
211 glDeleteProgram(progId_);
222 void setUniformLocationMap(
224 uniformLocationMap_ = std::move(uniformLocationMap);
237 [[nodiscard]] int uniformLocation(
238 helios::rendering::shader::UniformSemantics uniformSemantics) const noexcept {
239 if (uniformLocationMap_) {
240 return uniformLocationMap_->get(uniformSemantics);
249 void applyUniformValues(
250 const helios::rendering::shader::UniformValueMap& uniformValueMap) const noexcept override {
252 if (const auto viewMatrixUniform = uniformLocation(helios::rendering::shader::UniformSemantics::ViewMatrix); viewMatrixUniform != -1) {
253 if (const auto* mat4f_ptr = uniformValueMap.mat4f_ptr(helios::rendering::shader::UniformSemantics::ViewMatrix)) {
258 if (const auto projectionMatrixUniform = uniformLocation(helios::rendering::shader::UniformSemantics::ProjectionMatrix); projectionMatrixUniform != -1) {
259 if (const auto* mat4f_ptr = uniformValueMap.mat4f_ptr(helios::rendering::shader::UniformSemantics::ProjectionMatrix)) {
264 if (const auto modelMatrixUniform = uniformLocation(helios::rendering::shader::UniformSemantics::ModelMatrix); modelMatrixUniform != -1) {
265 if (const auto* mat4f_ptr = uniformValueMap.mat4f_ptr(helios::rendering::shader::UniformSemantics::ModelMatrix)) {
269 if (const auto materialBaseColorUniform = uniformLocation(helios::rendering::shader::UniformSemantics::MaterialBaseColor); materialBaseColorUniform != -1) {
270 if (const auto* vec4f_ptr = uniformValueMap.vec4f_ptr(helios::rendering::shader::UniformSemantics::MaterialBaseColor)) {
276 if (const auto textColorUniform = uniformLocation(helios::rendering::shader::UniformSemantics::TextColor); textColorUniform != -1) {
277 if (const auto* vec4f_ptr = uniformValueMap.vec4f_ptr(helios::rendering::shader::UniformSemantics::TextColor)) {
281 if (const auto textTextureUniform = uniformLocation(helios::rendering::shader::UniformSemantics::TextTexture); textTextureUniform != -1) {
282 if (const auto* int_ptr = uniformValueMap.int_ptr(helios::rendering::shader::UniformSemantics::TextTexture)) {
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.