A class to represent an OpenGL shader program, combining vertex and fragment shaders. More...
#include <shader.hpp>
Public Member Functions | |
| ShaderProgram ()=default | |
| Default constructor for ShaderProgram. | |
| ShaderProgram (const std::string &vertexPath, const std::string &fragmentPath) | |
| Constructor for ShaderProgram, loading and linking shaders from files. | |
| ~ShaderProgram () | |
| Destructor for ShaderProgram. | |
| MOVABLE_BUT_NOT_COPYABLE (ShaderProgram) | |
| Move constructor for ShaderProgram. | |
| bool | load (const std::string &vertexPath, const std::string &fragmentPath) |
| Loads and links shaders from files. | |
| void | use () |
| Activates the shader program for use. | |
| void | unUse () |
| Deactivates the shader program. | |
| void | setUniform (const std::string &name, int value) |
| Sets an integer uniform in the shader program. | |
| void | setUniform (const std::string &name, float value) |
| Sets a float uniform in the shader program. | |
| void | setUniform (const std::string &name, glm::vec3 value) |
| Sets a glm::vec3 uniform in the shader program. | |
| void | setUniform (const std::string &name, glm::vec4 value) |
| Sets a glm::vec4 uniform in the shader program. | |
| void | setUniform (const std::string &name, const glm::mat4 &matrix) |
| Sets a glm::mat4 uniform in the shader program. | |
| GLuint | GetProgramID () const |
| Gets the OpenGL program ID. | |
| const std::string & | getLastError () const |
| Gets the last error message. | |
| void | attachShader (const Shader &shader) |
| Attaches a shader to the shader program. | |
| void | printActiveUniforms () |
| Prints active uniforms in the shader program. | |
| bool | loadFromMemory (const char *vertexSource, const char *fragmentSource) |
| Loads and compiles vertex and fragment shaders from memory. | |
A class to represent an OpenGL shader program, combining vertex and fragment shaders.
This class provides functionality to link multiple shaders into a program, use the program, and set uniforms in the program. It supports handling of both vertex and fragment shaders, and provides methods to set uniform values of various types.
Definition at line 119 of file shader.hpp.
| Raftel::ShaderProgram::ShaderProgram | ( | const std::string & | vertexPath, |
| const std::string & | fragmentPath ) |
Constructor for ShaderProgram, loading and linking shaders from files.
| vertexPath | Path to the vertex shader file. |
| fragmentPath | Path to the fragment shader file. |
| Raftel::ShaderProgram::~ShaderProgram | ( | ) |
Destructor for ShaderProgram.
Deletes the shader program if it was created successfully.
| void Raftel::ShaderProgram::attachShader | ( | const Shader & | shader | ) |
Attaches a shader to the shader program.
| shader | The shader to attach. |
|
inline |
|
inline |
| bool Raftel::ShaderProgram::load | ( | const std::string & | vertexPath, |
| const std::string & | fragmentPath ) |
Loads and links shaders from files.
| vertexPath | Path to the vertex shader file. |
| fragmentPath | Path to the fragment shader file. |
| bool Raftel::ShaderProgram::loadFromMemory | ( | const char * | vertexSource, |
| const char * | fragmentSource ) |
Loads and compiles vertex and fragment shaders from memory.
This function allows loading shaders directly from memory instead of files. It compiles the given vertex and fragment shader source codes and links them into a shader program.
| vertexSource | The source code of the vertex shader as a null-terminated string. |
| fragmentSource | The source code of the fragment shader as a null-terminated string. |
getLastError(). | Raftel::ShaderProgram::MOVABLE_BUT_NOT_COPYABLE | ( | ShaderProgram | ) |
Move constructor for ShaderProgram.
Moves the resources of another ShaderProgram to this one.
| other | The ShaderProgram to move from. |
| void Raftel::ShaderProgram::setUniform | ( | const std::string & | name, |
| const glm::mat4 & | matrix ) |
Sets a glm::mat4 uniform in the shader program.
| name | The name of the uniform variable. |
| matrix | The glm::mat4 value to set. |
| void Raftel::ShaderProgram::setUniform | ( | const std::string & | name, |
| float | value ) |
Sets a float uniform in the shader program.
| name | The name of the uniform variable. |
| value | The float value to set. |
| void Raftel::ShaderProgram::setUniform | ( | const std::string & | name, |
| glm::vec3 | value ) |
Sets a glm::vec3 uniform in the shader program.
| name | The name of the uniform variable. |
| value | The glm::vec3 value to set. |
| void Raftel::ShaderProgram::setUniform | ( | const std::string & | name, |
| glm::vec4 | value ) |
Sets a glm::vec4 uniform in the shader program.
| name | The name of the uniform variable. |
| value | The glm::vec4 value to set. |
| void Raftel::ShaderProgram::setUniform | ( | const std::string & | name, |
| int | value ) |
Sets an integer uniform in the shader program.
| name | The name of the uniform variable. |
| value | The integer value to set. |