OpenGLShader.ixx File
OpenGL implementation of shader program management. More...
Included Headers
#include <cassert>
#include <format>
#include <glad/gl.h>
#include <helios/helios_config.h>
#include <optional>
#include <stdexcept>
#include <string>
#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:
25export namespace helios::ext::opengl::rendering::shader {
36 class OpenGLShader {
62 const helios::util::io::StringFileReader& stringFileReader
64 if (!stringFileReader.readInto(fragmentShaderPath, fragmentShaderSource_) ||
65 !stringFileReader.readInto(vertexShaderPath, vertexShaderSource_)) {
79 if (progId_ != 0) {
112 progId_ = glCreateProgram();
114 glAttachShader(progId_, vertexShader);
115 glAttachShader(progId_, fragmentShader);
116 glLinkProgram(progId_);
118 glGetProgramiv(progId_, GL_LINK_STATUS, &success);
120 glGetProgramInfoLog(progId_, 512, nullptr, infoLog);
145 std::optional<OpenGLUniformLocationMap> uniformLocationMap_;
163 const helios::util::io::StringFileReader& stringFileReader
182 assert(progId_ != 0 && "Shader program ID must be valid before use.");
183 glUseProgram(progId_);
191 ~OpenGLShader() {
192 if (progId_ != 0) {
193 glDeleteProgram(progId_);
204 void setUniformLocationMap(const OpenGLUniformLocationMap& uniformLocationMap) noexcept {
205 uniformLocationMap_ = uniformLocationMap;
218 [[nodiscard]] int uniformLocation(helios::rendering::shader::UniformSemantics uniformSemantics) const noexcept {
219 if (uniformLocationMap_) {
220 return uniformLocationMap_->get(uniformSemantics);
229 void applyUniformValues(
230 const helios::rendering::shader::UniformValueMap& uniformValueMap) const noexcept {
232 if (const auto viewMatrixUniform = uniformLocation(helios::rendering::shader::UniformSemantics::ViewMatrix); viewMatrixUniform != -1) {
233 if (const auto* mat4f_ptr = uniformValueMap.mat4f_ptr(helios::rendering::shader::UniformSemantics::ViewMatrix)) {
238 if (const auto projectionMatrixUniform = uniformLocation(helios::rendering::shader::UniformSemantics::ProjectionMatrix); projectionMatrixUniform != -1) {
239 if (const auto* mat4f_ptr = uniformValueMap.mat4f_ptr(helios::rendering::shader::UniformSemantics::ProjectionMatrix)) {
244 if (const auto modelMatrixUniform = uniformLocation(helios::rendering::shader::UniformSemantics::ModelMatrix); modelMatrixUniform != -1) {
245 if (const auto* mat4f_ptr = uniformValueMap.mat4f_ptr(helios::rendering::shader::UniformSemantics::ModelMatrix)) {
249 if (const auto materialBaseColorUniform = uniformLocation(helios::rendering::shader::UniformSemantics::MaterialBaseColor); materialBaseColorUniform != -1) {
250 if (const auto* vec4f_ptr = uniformValueMap.vec4f_ptr(helios::rendering::shader::UniformSemantics::MaterialBaseColor)) {
256 if (const auto textColorUniform = uniformLocation(helios::rendering::shader::UniformSemantics::TextColor); textColorUniform != -1) {
257 if (const auto* vec4f_ptr = uniformValueMap.vec4f_ptr(helios::rendering::shader::UniformSemantics::TextColor)) {
261 if (const auto textTextureUniform = uniformLocation(helios::rendering::shader::UniformSemantics::TextTexture); textTextureUniform != -1) {
262 if (const auto* int_ptr = uniformValueMap.int_ptr(helios::rendering::shader::UniformSemantics::TextTexture)) {
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.