Class ChainedShader
Multi-stage shader supporting vertex, fragment, and optional geometry stages. More...
#include <RenderShader.h>
Inherits the following classes: Shaders
Public Types inherited from Shaders
See Shaders
| Type | Name |
|---|---|
| typedef std::tuple< std::string, std::string, GLuint > | ShaderConstInfo Shader metadata tuple: (name, filename, GL_enum). |
Public Attributes inherited from Shaders
See Shaders
| Type | Name |
|---|---|
| std::function< void(void)> | InitShader = {}Optional callback for custom shader initialization. |
| bool | is_shader_changed = { true }Flag indicating shader code has changed and needs recompilation. |
| GLuint | program_id = { 0 }OpenGL shader program ID (owned by this class) |
Public Static Attributes inherited from Shaders
See Shaders
| Type | Name |
|---|---|
| std::vector< std::string > | file_type = { ".vert", ".frag", ".comp", ".geom" }File extensions for shader types. |
| std::string | folder_root = "res/shaders/"Root directory for shader files. |
| std::string const | shader_type = { "Vertex Shader", "Fragment Shader", "Compute Shader", "Geometry Shader" }Shader type name strings. |
Public Functions
| Type | Name |
|---|---|
| ChainedShader (const std::vector< std::string > & chain) Constructs a chained shader from a list of shader file names. |
|
| ChainedShader () Default constructor. |
|
| virtual GLuint | CompileShader (ShaderType type=NONE_SHADER) override Compiles a shader stage. |
| void | CreatShader () Creates shader program from loaded shader chain. |
| virtual void | GenerateShader (ShaderType type=NONE_SHADER) override Generates shader code (unused for ChainedShader ). |
| virtual std::vector< ShaderType > | GetAllShaderTypes () override const Returns list of all shader stages in this chain. |
| virtual GLuint | GetShaderID (ShaderType type) override const Returns OpenGL shader ID for a specific stage. |
| virtual ShaderUnit * | GetShaderUnit (ShaderType type=NONE_SHADER) override Returns pointer to shader unit for a specific stage. |
| virtual void | LocalDebug () override const Prints debug information about all shaders in chain. |
| virtual void | ParseShaderCode (const std::string & _code, ShaderType type) override Parses raw GLSL code for a specific stage. |
| virtual void | RelinkShader (ShaderType type=NONE_SHADER) override Relinks the shader program. |
| virtual void | ResetID (ShaderType type, GLuint id) override Resets shader ID for a specific stage. |
| ChainedShader & | operator= (ChainedShader &&) = default Move assignment operator. |
| ChainedShader & | operator= (const ChainedShader &) = default Copy assignment operator. |
| ~ChainedShader () Destructor (releases all shader objects in chain). |
Public Functions inherited from Shaders
See Shaders
| Type | Name |
|---|---|
| virtual GLuint | CompileShader (ShaderType tar) = 0 Compiles a shader stage. |
| virtual void | GenerateShader (ShaderType tar=NONE_SHADER) = 0 Generates shader code (for procedural shaders). |
| virtual std::vector< ShaderType > | GetAllShaderTypes () const = 0 Returns list of all shader stages in this program. |
| GLuint | GetProgramID () const Returns the OpenGL program ID. |
| virtual GLuint | GetShaderID (ShaderType type) const = 0 Returns the OpenGL shader object ID for a specific stage. |
| virtual ShaderUnit * | GetShaderUnit (ShaderType tar=NONE_SHADER) = 0 Returns pointer to shader unit for a specific stage. |
| virtual void | LocalDebug () const = 0 Prints debug information about the shader program. |
| virtual void | ParseShaderCode (const std::string & _code, ShaderType _type) = 0 Parses GLSL source code for a shader stage. |
| virtual void | RelinkShader (ShaderType tar=NONE_SHADER) = 0 Relinks the shader program after shader unit changes. |
| void | ResetCache () Clears the uniform location cache. |
| virtual void | ResetID (ShaderType type, GLuint id) = 0 Resets the shader ID for a specific stage. |
| void | SetValue (const std::string & name, const glm::mat4 & projection) |
| void | SetValue (const std::string & name, int v0) |
| void | SetValue (const std::string & name, int v0, int v1, int v2) |
| void | SetValue (const std::string & name, int v0, int v1, int v2, int v3) |
| void | SetValue (const std::string & name, float v0) |
| void | SetValue (const std::string & name, float v0, float v1) |
| void | SetValue (const std::string & name, float v0, float v1, float v2) |
| void | SetValue (const std::string & name, float v0, float v1, float v2, float v3) |
| void | SetValue (const std::string & name, const glm::vec2 & vec2) |
| void | SetValue (const std::string & name, const glm::vec3 & vec3) |
| void | SetValue (const std::string & name, const glm::vec4 & vec4) |
| void | SetValue (const std::string & name, bool v0) |
| void | SetValue (const std::string & name, const GLuint & v0) |
| void | SetValue (const std::string & name, GLsizei count, const float * va0, ArrayType TYPE) |
| void | SetValue (const std::string & name, Shaders::ArrayUni arr) |
| void | SetValue (const std::string & name, GLsizei count, const int * va0, ArrayType TYPE) |
| void | SetValue (const std::string & name, GLsizei count, const GLuint * va0, ArrayType TYPE) |
| void | SetValue (const std::string & name, GLsizei count, const glm::mat4 * va0) |
| Shaders () Default constructor. |
|
| Shaders (const Shaders & shader) Copy constructor. |
|
| Shaders (Shaders && shader) noexcept Move constructor (transfers ownership of GPU resources). |
|
| void | UnuseShader () const Unbinds this shader program. |
| void | UseShader () const Binds this shader program for rendering. |
| GLuint | getVarID (const char * name) const Gets uniform location ID for a uniform variable. |
| Shaders & | operator= (const Shaders & shader) Copy assignment operator. |
| Shaders & | operator= (Shaders && shader) noexcept Move assignment operator (transfers ownership). |
| ~Shaders () Destructor (releases OpenGL program object). |
Public Static Functions
| Type | Name |
|---|---|
| ChainedShader & | ImportShader (const std::vector< std::string > & chain) Imports or retrieves a cached chained shader. |
| ChainedShader & | ImportShader (_Name ... name) Imports or retrieves a cached chained shader (variadic version). |
Public Static Functions inherited from Shaders
See Shaders
| Type | Name |
|---|---|
| GLuint | CompileShaderCode (ShaderType _type, const std::string & source) Compiles GLSL source code into an OpenGL shader object. |
| ShaderType | ParseFileEXT (std::string path) Infers shader type from file extension. |
| ShaderConstInfo | ParseShaderType (ShaderType _type) Parses shader type to metadata tuple. |
| std::string | ReadShaderFile (ShaderType _type, const std::string & name) Reads shader source from file. |
Protected Attributes inherited from Shaders
See Shaders
| Type | Name |
|---|---|
| std::unordered_map< std::string, int > | _LINK_LOC Map of linked uniform locations. |
| std::unordered_map< std::string, GLuint > | _uniforms_cache Cache of uniform locations (avoids redundant glGetUniformLocation) |
Protected Functions inherited from Shaders
See Shaders
| Type | Name |
|---|---|
| void | _del () Deletes the OpenGL program object. |
| bool | _is_link_repeat (const std::string _name) Checks if a uniform name has already been linked. |
| void | _resetProgramID (GLuint _ID) Resets program ID, deleting old program if needed. |
Detailed Description
ChainedShader allows flexible shader pipelines with arbitrary combinations of vertex, fragment, and geometry shaders. Supports runtime recompilation and shader hot-reloading. Shaders are cached globally by name.
Usage:
// Create shader with vertex, geometry, and fragment stages
auto& shader = ChainedShader::ImportShader({"vert_name", "geom_name", "frag_name"});
// Or using variadic template
auto& shader2 = ChainedShader::ImportShader("vert_name", "frag_name");
Note:
Shaders are cached in chain_sh_list and shared across instances.
Public Functions Documentation
function ChainedShader [1/2]
Constructs a chained shader from a list of shader file names.
ChainedShader::ChainedShader (
const std::vector< std::string > & chain
)
Parameters:
chainVector of shader file names (order determines pipeline stages)
Note:
File extensions determine shader stages (.vert, .frag, .geom)
function ChainedShader [2/2]
Default constructor.
ChainedShader::ChainedShader ()
function CompileShader
Compiles a shader stage.
virtual GLuint ChainedShader::CompileShader (
ShaderType type=NONE_SHADER
) override
Parameters:
typeShader stage to compile
Returns:
OpenGL shader object ID, or 0 on failure
Implements Shaders::CompileShader
function CreatShader
Creates shader program from loaded shader chain.
void ChainedShader::CreatShader ()
Note:
Compiles all shader units and links them into a program
function GenerateShader
Generates shader code (unused for ChainedShader ).
inline virtual void ChainedShader::GenerateShader (
ShaderType type=NONE_SHADER
) override
Implements Shaders::GenerateShader
function GetAllShaderTypes
Returns list of all shader stages in this chain.
inline virtual std::vector< ShaderType > ChainedShader::GetAllShaderTypes () override const
Returns:
Vector of ShaderType enums
Implements Shaders::GetAllShaderTypes
function GetShaderID
Returns OpenGL shader ID for a specific stage.
inline virtual GLuint ChainedShader::GetShaderID (
ShaderType type
) override const
Parameters:
typeShader stage type
Returns:
Shader object ID, or 0 if stage not in chain
Implements Shaders::GetShaderID
function GetShaderUnit
Returns pointer to shader unit for a specific stage.
virtual ShaderUnit * ChainedShader::GetShaderUnit (
ShaderType type=NONE_SHADER
) override
Parameters:
typeShader stage type
Returns:
Pointer to ShaderUnit, or nullptr if stage not in chain
Implements Shaders::GetShaderUnit
function LocalDebug
Prints debug information about all shaders in chain.
virtual void ChainedShader::LocalDebug () override const
Implements Shaders::LocalDebug
function ParseShaderCode
Parses raw GLSL code for a specific stage.
virtual void ChainedShader::ParseShaderCode (
const std::string & _code,
ShaderType type
) override
Parameters:
_codeGLSL source codetypeShader stage type
Implements Shaders::ParseShaderCode
function RelinkShader
Relinks the shader program.
virtual void ChainedShader::RelinkShader (
ShaderType type=NONE_SHADER
) override
Parameters:
typeShader stage to recompile before linking, or NONE_SHADER to link all
Implements Shaders::RelinkShader
function ResetID
Resets shader ID for a specific stage.
virtual void ChainedShader::ResetID (
ShaderType type,
GLuint id
) override
Parameters:
typeShader stage typeidNew OpenGL shader object ID
Implements Shaders::ResetID
function operator=
Move assignment operator.
ChainedShader & ChainedShader::operator= (
ChainedShader &&
) = default
function operator=
Copy assignment operator.
ChainedShader & ChainedShader::operator= (
const ChainedShader &
) = default
function ~ChainedShader
Destructor (releases all shader objects in chain).
ChainedShader::~ChainedShader ()
Public Static Functions Documentation
function ImportShader [1/2]
Imports or retrieves a cached chained shader.
static ChainedShader & ChainedShader::ImportShader (
const std::vector< std::string > & chain
)
Parameters:
chainVector of shader file names
Returns:
Reference to cached ChainedShader instance
Note:
If shader already exists in cache, returns existing instance
function ImportShader [2/2]
Imports or retrieves a cached chained shader (variadic version).
template<class... _Name>
static ChainedShader & ChainedShader::ImportShader (
_Name ... name
)
Template parameters:
_NameVariadic template for shader names
Parameters:
nameShader file names
Returns:
Reference to cached ChainedShader instance
The documentation for this class was generated from the following file src/render/shaders/RenderShader.h