Skip to content

Class FastLoadShader

ClassList > FastLoadShader

Fast-loading shader variant for pre-compiled shaders. 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
void CreatShader (const std::string & verShader, const std::string & fragShader)
Creates shader program from vertex and fragment shader names.
FastLoadShader (const std::string & vert, const std::string & frag="")
Constructs and loads a fast shader from files.
FastLoadShader ()
Default constructor.
virtual void GenerateShader (ShaderType tar=NONE_SHADER) override
Generates shader (not supported in FastLoadShader ).
virtual std::vector< ShaderType > GetAllShaderTypes () override const
Returns list of shader stages.
virtual GLuint GetShaderID (ShaderType type) override const
Returns OpenGL shader ID for a specific stage.
virtual void LocalDebug () override const
Prints debug information.
virtual void RelinkShader (ShaderType tar=NONE_SHADER) override
Relinks shader (not supported in FastLoadShader ).
virtual void ResetID (ShaderType type, GLuint id) override
Resets shader ID (not supported in FastLoadShader ).
FastLoadShader & operator= (FastLoadShader &&) = default
Move assignment operator.
~FastLoadShader ()
Destructor (releases shader objects).

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 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

FastLoadShader is optimized for quick shader loading by bypassing some features like runtime recompilation and structure parsing. Intended for production builds where shader editing is not needed.

Note:

Currently WIP: May not support all features of RenderShader.

Public Functions Documentation

function CreatShader

Creates shader program from vertex and fragment shader names.

void FastLoadShader::CreatShader (
    const std::string & verShader,
    const std::string & fragShader
) 

Parameters:

  • verShader Vertex shader file name
  • fragShader Fragment shader file name

function FastLoadShader [1/2]

Constructs and loads a fast shader from files.

FastLoadShader::FastLoadShader (
    const std::string & vert,
    const std::string & frag=""
) 

Parameters:

  • vert Vertex shader file name
  • frag Fragment shader file name (defaults to vert name)

function FastLoadShader [2/2]

Default constructor.

FastLoadShader::FastLoadShader () 


function GenerateShader

Generates shader (not supported in FastLoadShader ).

inline virtual void FastLoadShader::GenerateShader (
    ShaderType tar=NONE_SHADER
) override

Implements Shaders::GenerateShader


function GetAllShaderTypes

Returns list of shader stages.

inline virtual std::vector< ShaderType > FastLoadShader::GetAllShaderTypes () override const

Returns:

Vector containing VERTEX_SHADER and FRAGMENT_SHADER

Implements Shaders::GetAllShaderTypes


function GetShaderID

Returns OpenGL shader ID for a specific stage.

inline virtual GLuint FastLoadShader::GetShaderID (
    ShaderType type
) override const

Parameters:

  • type Shader stage type

Returns:

Shader object ID

Implements Shaders::GetShaderID


function LocalDebug

Prints debug information.

virtual void FastLoadShader::LocalDebug () override const

Implements Shaders::LocalDebug


function RelinkShader

Relinks shader (not supported in FastLoadShader ).

inline virtual void FastLoadShader::RelinkShader (
    ShaderType tar=NONE_SHADER
) override

Implements Shaders::RelinkShader


function ResetID

Resets shader ID (not supported in FastLoadShader ).

inline virtual void FastLoadShader::ResetID (
    ShaderType type,
    GLuint id
) override

Implements Shaders::ResetID


function operator=

Move assignment operator.

FastLoadShader & FastLoadShader::operator= (
    FastLoadShader &&
) = default


function ~FastLoadShader

Destructor (releases shader objects).

FastLoadShader::~FastLoadShader () 



The documentation for this class was generated from the following file src/render/shaders/RenderShader.h