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.
 
void compile ()
 Compiles shader into GPU mem.
 
void destroy ()
 Destroys shader program.
 
void bind () const
 Make active shader.
 
void unbind () const
 Unbind.
 
template<typename... Uniforms>
void set_uniform (const std::string &name, const Uniforms &... args)
 Specialized variadic template for setting shader uniforms.
 
unsigned int id () const noexcept
 Get program id.
 
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 int &a, const int &b)
 
template<>
void set_uniform (const std::string &name, const int &a, const int &b, const int &c)
 
template<>
void set_uniform (const std::string &name, const int &a, const int &b, const int &c, const int &d)
 
template<>
void set_uniform (const std::string &name, const unsigned int &a)
 
template<>
void set_uniform (const std::string &name, const unsigned int &a, const unsigned int &b)
 
template<>
void set_uniform (const std::string &name, const unsigned int &a, const unsigned int &b, const unsigned int &c)
 
template<>
void set_uniform (const std::string &name, const unsigned int &a, const unsigned int &b, const unsigned int &c, const unsigned int &d)
 
template<>
void set_uniform (const std::string &name, const float &a)
 
template<>
void set_uniform (const std::string &name, const float &a, const float &b)
 
template<>
void set_uniform (const std::string &name, const float &a, const float &b, const float &c)
 
template<>
void set_uniform (const std::string &name, const float &a, const float &b, const float &c, const float &d)
 
template<>
void set_uniform (const std::string &name, const double &a)
 
template<>
void set_uniform (const std::string &name, const double &a, const double &b)
 
template<>
void set_uniform (const std::string &name, const double &a, const double &b, const double &c)
 
template<>
void set_uniform (const std::string &name, const double &a, const double &b, const double &c, const double &d)
 
template<>
void set_uniform (const std::string &name, const Colour &a)
 

Private Member Functions

 Shader (const Shader &)=delete
 Copy constructor.
 
Shaderoperator= (const Shader &)=delete
 Copy assignment operator.
 
bool preprocess (const std::string &src) noexcept
 Extract source code from a combined shader.
 
int get_uniform_location (const std::string &name)
 Retrieves the location of a shader uniform.
 

Private Attributes

unsigned int m_id
 OpenGL handle.
 
ankerl::unordered_dense::map< std::string, int > m_cache
 Cache of uniforms for better performance.
 
entt::compressed_pair< std::string, std::string > m_src
 Shader source code.
 

Detailed Description

OpenGL Shader Program.

Currently only supports vertex and fragment shaders.

Definition at line 27 of file Shader.hpp.

Constructor & Destructor Documentation

◆ Shader() [1/3]

galaxy::Shader::Shader ( )
noexcept

Constructor.

Definition at line 22 of file Shader.cpp.

◆ Shader() [2/3]

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

Move constructor.

Definition at line 27 of file Shader.cpp.

◆ ~Shader()

galaxy::Shader::~Shader ( )
noexcept

Destructor.

Definition at line 60 of file Shader.cpp.

+ Here is the call graph for this function:

◆ Shader() [3/3]

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

Copy constructor.

Member Function Documentation

◆ operator=() [1/2]

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

Move assignment operator.

Definition at line 41 of file Shader.cpp.

◆ 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 65 of file Shader.cpp.

+ Here is the caller 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 73 of file Shader.cpp.

◆ 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 83 of file Shader.cpp.

+ 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 88 of file Shader.cpp.

◆ compile()

void galaxy::Shader::compile ( )

Compiles shader into GPU mem.

Definition at line 113 of file Shader.cpp.

+ Here is the caller graph for this function:

◆ destroy()

void galaxy::Shader::destroy ( )

Destroys shader program.

Definition at line 202 of file Shader.cpp.

+ Here is the caller graph for this function:

◆ bind()

void galaxy::Shader::bind ( ) const

Make active shader.

Definition at line 211 of file Shader.cpp.

+ Here is the caller graph for this function:

◆ unbind()

void galaxy::Shader::unbind ( ) const

Unbind.

Definition at line 216 of file Shader.cpp.

+ Here is the caller graph for this function:

◆ set_uniform() [1/20]

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:

◆ id()

unsigned int galaxy::Shader::id ( ) const
nodiscardnoexcept

Get program id.

Returns
unsigned int.

Definition at line 221 of file Shader.cpp.

+ Here is the caller graph for this function:

◆ operator=() [2/2]

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

Copy assignment operator.

◆ preprocess()

bool galaxy::Shader::preprocess ( const std::string & src)
nodiscardprivatenoexcept

Extract source code from a combined shader.

Parameters
srcRaw source code.
Returns
True if parse was successful.

Definition at line 226 of file Shader.cpp.

◆ 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 273 of file Shader.cpp.

+ Here is the caller graph for this function:

◆ set_uniform() [2/20]

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

Definition at line 181 of file Shader.hpp.

◆ set_uniform() [3/20]

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

Definition at line 187 of file Shader.hpp.

+ Here is the call graph for this function:

◆ set_uniform() [4/20]

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

Definition at line 193 of file Shader.hpp.

+ Here is the call graph for this function:

◆ set_uniform() [5/20]

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

Definition at line 199 of file Shader.hpp.

+ Here is the call graph for this function:

◆ set_uniform() [6/20]

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

Definition at line 205 of file Shader.hpp.

+ Here is the call graph for this function:

◆ set_uniform() [7/20]

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

Definition at line 211 of file Shader.hpp.

+ Here is the call graph for this function:

◆ set_uniform() [8/20]

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

Definition at line 217 of file Shader.hpp.

+ Here is the call graph for this function:

◆ set_uniform() [9/20]

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

Definition at line 223 of file Shader.hpp.

+ Here is the call graph for this function:

◆ set_uniform() [10/20]

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

Definition at line 229 of file Shader.hpp.

+ Here is the call graph for this function:

◆ set_uniform() [11/20]

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

Definition at line 235 of file Shader.hpp.

+ Here is the call graph for this function:

◆ set_uniform() [12/20]

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

Definition at line 247 of file Shader.hpp.

+ Here is the call graph for this function:

◆ set_uniform() [13/20]

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

Definition at line 253 of file Shader.hpp.

+ Here is the call graph for this function:

◆ set_uniform() [14/20]

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

Definition at line 259 of file Shader.hpp.

+ Here is the call graph for this function:

◆ set_uniform() [15/20]

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

Definition at line 265 of file Shader.hpp.

+ Here is the call graph for this function:

◆ set_uniform() [16/20]

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

Definition at line 271 of file Shader.hpp.

+ Here is the call graph for this function:

◆ set_uniform() [17/20]

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

Definition at line 277 of file Shader.hpp.

+ Here is the call graph for this function:

◆ set_uniform() [18/20]

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

Definition at line 283 of file Shader.hpp.

+ Here is the call graph for this function:

◆ set_uniform() [19/20]

template<>
void galaxy::Shader::set_uniform ( const std::string & name,
const double & a,
const double & b,
const double & c,
const double & d )
inline

Definition at line 289 of file Shader.hpp.

+ Here is the call graph for this function:

◆ set_uniform() [20/20]

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

Definition at line 337 of file Shader.hpp.

+ Here is the call graph for this function:

Member Data Documentation

◆ m_id

unsigned int galaxy::Shader::m_id
private

OpenGL handle.

Definition at line 167 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 172 of file Shader.hpp.

◆ m_src

entt::compressed_pair<std::string, std::string> galaxy::Shader::m_src
private

Shader source code.

Definition at line 177 of file Shader.hpp.


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