OpenGLShader Class
An OpenGL-specific implementation of a Shader program, consisting of a vertex and a fragment shader. More...
Declaration
Base class
| class | Shader |
|
Abstract representation of a Shader program (e.g. composed of vertex/fragment shader). More... | |
Public Constructors Index
| OpenGLShader (const OpenGLShader &)=delete | |
|
Rule of three. More... | |
| 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 () override | |
|
Deletes the program object upon destruction of this instance. More... | |
Public Operators Index
| OpenGLShader & | operator= (const OpenGLShader &)=delete |
Public Member Functions Index
| void | use () const noexcept override |
|
Activates this OpenGLShader for subsequent draw calls. This implementation calls `glUseProgram` with the `progId_` received after compilation. More... | |
| void | setUniformLocationMap (std::unique_ptr< 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 override |
|
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::unique_ptr< const OpenGLUniformLocationMap > | uniformLocationMap_ = nullptr |
|
A unique pointer to 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 34 of file OpenGLShader.ixx.
Public Constructors
OpenGLShader()
| delete |
Rule of three.
Prevent copying.
Definition at line 158 of file OpenGLShader.ixx.
Reference OpenGLShader.
Referenced by OpenGLShader and operator=.
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 173 of file OpenGLShader.ixx.
Reference helios::rendering::shader::Shader::logger_.
Public Destructor
~OpenGLShader()
| inline |
Deletes the program object upon destruction of this instance.
Definition at line 207 of file OpenGLShader.ixx.
Reference progId_.
Public Operators
operator=()
| delete |
Definition at line 159 of file OpenGLShader.ixx.
Reference OpenGLShader.
Public Member Functions
applyUniformValues()
| inline noexcept virtual |
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 247 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 220 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 235 of file OpenGLShader.ixx.
Reference uniformLocationMap_.
Referenced by applyUniformValues.
use()
| inline noexcept virtual |
Activates this OpenGLShader for subsequent draw calls. This implementation calls `glUseProgram` with the `progId_` received after compilation.
Definition at line 195 of file OpenGLShader.ixx.
References helios::rendering::shader::Shader::logger_ and 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 57 of file OpenGLShader.ixx.
Protected Member Attributes
progId_
| protected |
The program id as assigned by the underlying rendering backend.
Definition at line 143 of file OpenGLShader.ixx.
Referenced by use and ~OpenGLShader.
uniformLocationMap_
| protected |
A unique pointer to the OpenGLUniformLocationMap this shader uses.
Definition at line 148 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 48 of file OpenGLShader.ixx.
vertexShaderSource_
|
Source of the shader. Not guaranteed to be persisted once compilation was successful.
Definition at line 41 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.