OpenGLShader Class
An OpenGL-specific implementation of a Shader program, consisting of a vertex and a fragment shader. More...
Declaration
Public Constructors Index
| OpenGLShader (const std::string &vertexShaderPath, const std::string &fragmentShaderPath, const helios::util::io::StringFileReader &stringFileReader) | |
|
Creates and initializes this OpenGLShader. An instance of this class is guaranteed to have a progId_ != 0, hence shader-files where successfully loaded and compiled, ready to be used. More... | |
Public Destructor Index
| ~OpenGLShader () | |
|
Deletes the program object upon destruction of this instance. More... | |
Public Member Functions Index
| void | use () const noexcept |
|
Activates this OpenGLShader for subsequent draw calls. This implementation calls `glUseProgram` with the `progId_` received after compilation. More... | |
| void | setUniformLocationMap (const OpenGLUniformLocationMap &uniformLocationMap) noexcept |
|
Sets the OpenGLUniformLocationMap for this OpenGLShader. Ownership is transferred to this instance. More... | |
| int | uniformLocation (helios::rendering::shader::UniformSemantics uniformSemantics) const noexcept |
|
Returns the uniform location for the uniform represented by the specified UniformSemantics. More... | |
| void | applyUniformValues (const helios::rendering::shader::UniformValueMap &uniformValueMap) const noexcept |
|
Applies the specified UniformValueMap to the uniforms defined by the shader. This method does not change the binding state of the shader, but it passes the uniform values to the underlying rendering backend. Implementations should ensure that the shader is properly bound before this method is called. More... | |
Private Member Functions Index
| void | load (const std::string &vertexShaderPath, const std::string &fragmentShaderPath, const helios::util::io::StringFileReader &stringFileReader) |
|
Loads the specified vertex and fragment shader. More... | |
| void | compile () |
|
Compiles the vertex and fragment shader represented by this instance. More... | |
Protected Member Attributes Index
| unsigned int | progId_ = 0 |
|
The program id as assigned by the underlying rendering backend. More... | |
| std::optional< OpenGLUniformLocationMap > | uniformLocationMap_ |
|
The OpenGLUniformLocationMap this shader uses. More... | |
Private Member Attributes Index
| std::string | vertexShaderSource_ |
|
Source of the shader. Not guaranteed to be persisted once compilation was successful. More... | |
| std::string | fragmentShaderSource_ |
|
Source of the shader. Not guaranteed to be persisted once compilation was successful. More... | |
Description
An OpenGL-specific implementation of a Shader program, consisting of a vertex and a fragment shader.
This class manages the lifecycle of the Shaders. Source files are getting loaded via a StringFileReader and immediately compiled after loading. Any occupied memory for source-files and file-paths to the shader is being cleared once compilation succeeded and are not guaranteed to persist the compilation process.
Definition at line 36 of file OpenGLShader.ixx.
Public Constructors
OpenGLShader()
| inline |
Creates and initializes this OpenGLShader. An instance of this class is guaranteed to have a progId_ != 0, hence shader-files where successfully loaded and compiled, ready to be used.
- Parameters
-
vertexShaderPath The path to the vertex shader.
fragmentShaderPath The path to the fragment shader.
stringFileReader The StringFileReader used for loading the shader source files.
- Exceptions
-
if creating this shader failed.
Definition at line 160 of file OpenGLShader.ixx.
Public Destructor
~OpenGLShader()
| inline |
Deletes the program object upon destruction of this instance.
Definition at line 191 of file OpenGLShader.ixx.
Reference progId_.
Public Member Functions
applyUniformValues()
| inline noexcept |
Applies the specified UniformValueMap to the uniforms defined by the shader. This method does not change the binding state of the shader, but it passes the uniform values to the underlying rendering backend. Implementations should ensure that the shader is properly bound before this method is called.
- Parameters
-
uniformValueMap A const ref to the `UniformValueMap` containing the values for the uniforms in this shader.
Definition at line 229 of file OpenGLShader.ixx.
References helios::rendering::shader::MaterialBaseColor, helios::rendering::shader::ModelMatrix, helios::rendering::shader::ProjectionMatrix, helios::rendering::shader::TextColor, helios::rendering::shader::TextTexture, uniformLocation and helios::rendering::shader::ViewMatrix.
setUniformLocationMap()
| inline noexcept |
Sets the OpenGLUniformLocationMap for this OpenGLShader. Ownership is transferred to this instance.
- Parameters
-
uniformLocationMap The OpenGLUniformMap providing the mappings for the uniforms of the underlying GLSL shader.
Definition at line 204 of file OpenGLShader.ixx.
Reference uniformLocationMap_.
uniformLocation()
| inline nodiscard noexcept |
Returns the uniform location for the uniform represented by the specified UniformSemantics.
- Parameters
-
uniformSemantics The `UniformSemantics` identifier.
- Returns
The integer representing the uniform variable location in the shader, or -1 if no location map was registered with this shader or if the uniform with the specified semantics was not found.
Definition at line 218 of file OpenGLShader.ixx.
Reference uniformLocationMap_.
Referenced by applyUniformValues.
use()
| inline noexcept |
Activates this OpenGLShader for subsequent draw calls. This implementation calls `glUseProgram` with the `progId_` received after compilation.
Definition at line 181 of file OpenGLShader.ixx.
Reference progId_.
Private Member Functions
compile()
| inline |
Compiles the vertex and fragment shader represented by this instance.
- Returns
true if compilation succeeded, otherwise false.
- Exceptions
-
if compilation failed.
Definition at line 78 of file OpenGLShader.ixx.
load()
| inline |
Loads the specified vertex and fragment shader.
- Returns
true if loading succeeded, otherwise false.
- Exceptions
-
if loading the specified files failed.
Definition at line 59 of file OpenGLShader.ixx.
Protected Member Attributes
progId_
| protected |
The program id as assigned by the underlying rendering backend.
Definition at line 140 of file OpenGLShader.ixx.
Referenced by use and ~OpenGLShader.
uniformLocationMap_
| protected |
The OpenGLUniformLocationMap this shader uses.
Definition at line 145 of file OpenGLShader.ixx.
Referenced by setUniformLocationMap and uniformLocation.
Private Member Attributes
fragmentShaderSource_
|
Source of the shader. Not guaranteed to be persisted once compilation was successful.
Definition at line 50 of file OpenGLShader.ixx.
vertexShaderSource_
|
Source of the shader. Not guaranteed to be persisted once compilation was successful.
Definition at line 43 of file OpenGLShader.ixx.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.