|
cangine
|
Wraps a compiled and linked OpenGL shader program. More...
#include <shader.hpp>
Classes | |
| struct | SourceTag |
Public Member Functions | |
| void | use () |
| Activates this shader program for subsequent draw calls. | |
| void | unbind () |
| Deactivates the current shader program. | |
| void | setBool (const std::string &name, bool value) |
| Sets a boolean uniform. | |
| void | setInt (const std::string &name, int value) |
| Sets an integer uniform. | |
| void | setFloat (const std::string &name, float value) |
| Sets a float uniform. | |
| void | setVec2 (const std::string &name, float x, float y) |
| Sets a vec2 uniform. | |
| void | setVec3 (const std::string &name, float x, float y, float z) |
| Sets a vec3 uniform. | |
| void | setVec4 (const std::string &name, float x, float y, float z, float w) |
| Sets a vec4 uniform. | |
| Shader (std::string name, std::string shaderPath="./shaders") | |
| Loads, compiles and links a shader program. | |
| ~Shader () | |
| Deletes the OpenGL shader program. | |
Static Public Member Functions | |
| static Shader * | fromSource (const std::string &vsSrc, const std::string &fsSrc) |
| Creates a shader program compiled from source strings. | |
Public Attributes | |
| std::string | shaderPath |
| Directory the shader sources are loaded from. | |
| bool | valid = true |
| Whether compilation and linking succeeded. | |
| unsigned int | ID |
| OpenGL shader program handle. | |
| std::string | name |
| Base name of the shader source files. | |
Private Member Functions | |
| void | attach () |
| Attaches and links the compiled shader stages into the program. | |
| void | cleanUp () |
| Deletes the intermediate shader stage objects after linking. | |
| void | compileShaders () |
| Reads and compiles the vertex and fragment shader sources. | |
| void | compileFromSource (const std::string &vsSrc, const std::string &fsSrc) |
| Compiles vertex and fragment shaders directly from source strings. | |
| Shader (const std::string &vsSrc, const std::string &fsSrc, SourceTag) | |
Private Attributes | |
| unsigned int | vs |
| Compiled vertex shader handle. | |
| unsigned int | fs |
| Compiled fragment shader handle. | |
Wraps a compiled and linked OpenGL shader program.
Loads a vertex/fragment shader pair from disk, compiles and links them into a program, and exposes helpers for setting uniform values.
|
private |
| cangine::Shader::Shader | ( | std::string | name, |
| std::string | shaderPath = "./shaders" |
||
| ) |
Loads, compiles and links a shader program.
| name | Base name of the shader source files. |
| shaderPath | Directory containing the shader sources. |
| cangine::Shader::~Shader | ( | ) |
Deletes the OpenGL shader program.
|
private |
Attaches and links the compiled shader stages into the program.
|
private |
Deletes the intermediate shader stage objects after linking.
|
private |
Compiles vertex and fragment shaders directly from source strings.
|
private |
Reads and compiles the vertex and fragment shader sources.
|
static |
Creates a shader program compiled from source strings.
| vsSrc | Vertex shader GLSL source. |
| fsSrc | Fragment shader GLSL source. |
| void cangine::Shader::setBool | ( | const std::string & | name, |
| bool | value | ||
| ) |
Sets a boolean uniform.
| name | Uniform variable name. |
| value | Value to assign. |
| void cangine::Shader::setFloat | ( | const std::string & | name, |
| float | value | ||
| ) |
Sets a float uniform.
| name | Uniform variable name. |
| value | Value to assign. |
| void cangine::Shader::setInt | ( | const std::string & | name, |
| int | value | ||
| ) |
Sets an integer uniform.
| name | Uniform variable name. |
| value | Value to assign. |
| void cangine::Shader::setVec2 | ( | const std::string & | name, |
| float | x, | ||
| float | y | ||
| ) |
Sets a vec2 uniform.
| name | Uniform variable name. |
| x | First component. |
| y | Second component. |
| void cangine::Shader::setVec3 | ( | const std::string & | name, |
| float | x, | ||
| float | y, | ||
| float | z | ||
| ) |
Sets a vec3 uniform.
| name | Uniform variable name. |
| x | First component. |
| y | Second component. |
| z | Third component. |
| void cangine::Shader::setVec4 | ( | const std::string & | name, |
| float | x, | ||
| float | y, | ||
| float | z, | ||
| float | w | ||
| ) |
Sets a vec4 uniform.
| name | Uniform variable name. |
| x | First component. |
| y | Second component. |
| z | Third component. |
| w | Fourth component. |
| void cangine::Shader::unbind | ( | ) |
Deactivates the current shader program.
| void cangine::Shader::use | ( | ) |
Activates this shader program for subsequent draw calls.
|
private |
Compiled fragment shader handle.
| unsigned int cangine::Shader::ID |
OpenGL shader program handle.
| std::string cangine::Shader::name |
Base name of the shader source files.
| std::string cangine::Shader::shaderPath |
Directory the shader sources are loaded from.
| bool cangine::Shader::valid = true |
Whether compilation and linking succeeded.
|
private |
Compiled vertex shader handle.