![]() |
galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
|
OpenGL Shader Program. More...
#include <Shader.hpp>
Public Member Functions | |
Shader () | |
Constructor. | |
Shader (const nlohmann::json &json) | |
JSON Constructor. | |
Shader (Shader &&) | |
Move constructor. | |
Shader & | operator= (Shader &&) |
Move assignment operator. | |
~Shader () | |
Destructor. | |
bool | load (const std::string &file) |
Loads a combined shader. | |
bool | load (const std::string &vertex, const std::string &frag) |
Loads an OpenGL shader. | |
bool | parse (const std::string &src) |
Loads a combined raw shader. | |
bool | parse (const std::string &vertex, const std::string &frag) |
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 |
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) |
Private Member Functions | |
Shader (const Shader &)=delete | |
Copy constructor. | |
Shader & | operator= (const Shader &)=delete |
Copy assignment operator. | |
bool | preprocess (const std::string &src) |
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. | |
OpenGL Shader Program.
Currently only supports vertex and fragment shaders.
Definition at line 28 of file Shader.hpp.
galaxy::graphics::Shader::Shader | ( | ) |
Constructor.
Definition at line 26 of file Shader.cpp.
galaxy::graphics::Shader::Shader | ( | const nlohmann::json & | json | ) |
JSON Constructor.
json | JSON defining object. |
Definition at line 31 of file Shader.cpp.
galaxy::graphics::Shader::Shader | ( | Shader && | s | ) |
Move constructor.
Definition at line 44 of file Shader.cpp.
galaxy::graphics::Shader::~Shader | ( | ) |
|
privatedelete |
Copy constructor.
Move assignment operator.
Definition at line 58 of file Shader.cpp.
|
nodiscard |
Loads a combined shader.
file | Path to a combined shader source. |
Definition at line 82 of file Shader.cpp.
|
nodiscard |
Loads an OpenGL shader.
vertex | Vertex shader. |
frag | Fragment shader. |
Definition at line 90 of file Shader.cpp.
|
nodiscard |
Loads a combined raw shader.
src | Raw shader code. |
Definition at line 100 of file Shader.cpp.
|
nodiscard |
Loads a raw shader.
vertex | Raw vertex shader code. |
frag | Raw fragment shader code. |
Definition at line 105 of file Shader.cpp.
void galaxy::graphics::Shader::compile | ( | ) |
Compiles shader into GPU mem.
Definition at line 130 of file Shader.cpp.
void galaxy::graphics::Shader::destroy | ( | ) |
Destroys shader program.
Definition at line 219 of file Shader.cpp.
void galaxy::graphics::Shader::bind | ( | ) | const |
Make active shader.
Definition at line 227 of file Shader.cpp.
void galaxy::graphics::Shader::unbind | ( | ) | const |
Unbind.
Definition at line 232 of file Shader.cpp.
void galaxy::graphics::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)
name | The name of the uniform to set. |
args | Variable amount of arguments for the uniform. |
|
nodiscard |
Copy assignment operator.
|
nodiscardprivate |
Extract source code from a combined shader.
src | Raw source code. |
Definition at line 242 of file Shader.cpp.
|
nodiscardprivate |
Retrieves the location of a shader uniform.
name | Shader uniform name. |
Definition at line 289 of file Shader.cpp.
|
inline |
Definition at line 189 of file Shader.hpp.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
private |
OpenGL handle.
Definition at line 175 of file Shader.hpp.
|
private |
Cache of uniforms for better performance.
Definition at line 180 of file Shader.hpp.
|
private |
Shader source code.
Definition at line 185 of file Shader.hpp.