galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
galaxy::Shader Class Referencefinal

OpenGL Shader Program. More...

#include <Shader.hpp>

Collaboration diagram for galaxy::Shader:

Public Member Functions

 Shader () noexcept
 Constructor.
 Shader (Shader &&) noexcept
 Move constructor.
Shaderoperator= (Shader &&) noexcept
 Move assignment operator.
 ~Shader () noexcept
 Destructor.
bool load (const std::string &file) noexcept
 Loads a combined shader.
bool load (const std::string &vertex, const std::string &frag) noexcept
 Loads an OpenGL shader.
bool parse (const std::string &src) noexcept
 Loads a combined raw shader.
bool parse (const std::string &vertex, const std::string &frag) noexcept
 Loads a raw shader.
template<typename... Uniforms>
void set_uniform (const std::string &name, const Uniforms &... args)
 Specialized variadic template for setting shader uniforms.
template<>
void set_uniform (const std::string &name)
template<>
void set_uniform (const std::string &name, const bool &a)
template<>
void set_uniform (const std::string &name, const int &a)
template<>
void set_uniform (const std::string &name, const unsigned int &a)
template<>
void set_uniform (const std::string &name, const float &a)

Private Member Functions

 Shader (const Shader &)=delete
 Copy constructor.
Shaderoperator= (const Shader &)=delete
 Copy assignment operator.
int get_uniform_location (const std::string &name)
 Retrieves the location of a shader uniform.

Private Attributes

ray::Shader m_shader
 Handle.
ankerl::unordered_dense::map< std::string, int > m_cache
 Cache of uniforms for better performance.

Detailed Description

OpenGL Shader Program.

Currently only supports vertex and fragment shaders.

Definition at line 23 of file Shader.hpp.

Constructor & Destructor Documentation

◆ Shader() [1/3]

galaxy::Shader::Shader ( )
noexcept

Constructor.

Definition at line 16 of file Shader.cpp.

Here is the caller graph for this function:

◆ Shader() [2/3]

galaxy::Shader::Shader ( Shader && s)
noexcept

Move constructor.

Definition at line 20 of file Shader.cpp.

Here is the call graph for this function:

◆ ~Shader()

galaxy::Shader::~Shader ( )
noexcept

Destructor.

Definition at line 55 of file Shader.cpp.

◆ Shader() [3/3]

galaxy::Shader::Shader ( const Shader & )
privatedelete

Copy constructor.

Here is the call graph for this function:

Member Function Documentation

◆ operator=() [1/2]

Shader & galaxy::Shader::operator= ( Shader && s)
noexcept

Move assignment operator.

Definition at line 35 of file Shader.cpp.

Here is the call graph for this function:

◆ load() [1/2]

bool galaxy::Shader::load ( const std::string & file)
nodiscardnoexcept

Loads a combined shader.

Parameters
filePath to a combined shader source.
Returns
True if successful.

Definition at line 63 of file Shader.cpp.

Here is the call graph for this function:

◆ load() [2/2]

bool galaxy::Shader::load ( const std::string & vertex,
const std::string & frag )
nodiscardnoexcept

Loads an OpenGL shader.

Parameters
vertexVertex shader.
fragFragment shader.
Returns
True if successful.

Definition at line 71 of file Shader.cpp.

Here is the call graph for this function:

◆ parse() [1/2]

bool galaxy::Shader::parse ( const std::string & src)
nodiscardnoexcept

Loads a combined raw shader.

Parameters
srcRaw shader code.
Returns
True if successful.

Definition at line 81 of file Shader.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse() [2/2]

bool galaxy::Shader::parse ( const std::string & vertex,
const std::string & frag )
nodiscardnoexcept

Loads a raw shader.

Parameters
vertexRaw vertex shader code.
fragRaw fragment shader code.
Returns
True if successful.

Definition at line 135 of file Shader.cpp.

◆ set_uniform() [1/6]

template<typename... Uniforms>
void galaxy::Shader::set_uniform ( const std::string & name,
const Uniforms &... args )

Specialized variadic template for setting shader uniforms.

Useful for i.e. 2f would be ("name", 1.0f, 2.0f) and 3i would be ("name", 1, 2, 3)

Parameters
nameThe name of the uniform to set.
argsVariable amount of arguments for the uniform.
Here is the caller graph for this function:

◆ operator=() [2/2]

Shader & galaxy::Shader::operator= ( const Shader & )
privatedelete

Copy assignment operator.

Here is the call graph for this function:

◆ get_uniform_location()

int galaxy::Shader::get_uniform_location ( const std::string & name)
nodiscardprivate

Retrieves the location of a shader uniform.

Parameters
nameShader uniform name.
Returns
Uniform location. -1 on error.

Definition at line 160 of file Shader.cpp.

Here is the caller graph for this function:

◆ set_uniform() [2/6]

template<>
void galaxy::Shader::set_uniform ( const std::string & name)
inline

Definition at line 134 of file Shader.hpp.

◆ set_uniform() [3/6]

template<>
void galaxy::Shader::set_uniform ( const std::string & name,
const bool & a )
inline

Definition at line 140 of file Shader.hpp.

Here is the call graph for this function:

◆ set_uniform() [4/6]

template<>
void galaxy::Shader::set_uniform ( const std::string & name,
const int & a )
inline

Definition at line 146 of file Shader.hpp.

Here is the call graph for this function:

◆ set_uniform() [5/6]

template<>
void galaxy::Shader::set_uniform ( const std::string & name,
const unsigned int & a )
inline

Definition at line 152 of file Shader.hpp.

Here is the call graph for this function:

◆ set_uniform() [6/6]

template<>
void galaxy::Shader::set_uniform ( const std::string & name,
const float & a )
inline

Definition at line 158 of file Shader.hpp.

Here is the call graph for this function:

Member Data Documentation

◆ m_shader

ray::Shader galaxy::Shader::m_shader
private

Handle.

Definition at line 125 of file Shader.hpp.

◆ m_cache

ankerl::unordered_dense::map<std::string, int> galaxy::Shader::m_cache
private

Cache of uniforms for better performance.

Definition at line 130 of file Shader.hpp.


The documentation for this class was generated from the following files: