engine::graphics::Shader class

Represents a compiled and linked GLSL shader program.

This class handles the lifecycle of a shader, from creation to binding and uniform setting.

Public static functions

static auto CreateFromSource(const std::string& vertex_source, const std::string& fragment_source) -> std::shared_ptr<Shader>
Loads vertex and fragment shader source code, compiles them, and links them into a single shader program.
static auto Load(const std::string& path) -> std::shared_ptr<Shader>
Placeholder Load method to satisfy the AssetManager requirement.

Constructors, destructors, conversion operators

~Shader()
Deletes the shader program from the GPU.

Public functions

auto id() const -> unsigned int
Gets the OpenGL ID of the shader program.
void Bind() const
Activates this shader program for subsequent rendering calls.
void Unbind() const
Deactivates the currently bound shader program.
void SetInt(const std::string& name, int value)
Sets an integer uniform variable in the shader.
void SetVec3(const std::string& name, glm::vec3 value)
Sets a 3-component float vector uniform variable in the shader.
void SetVec4(const std::string& name, glm::vec4 value)
Sets a 4-component float vector uniform variable in the shader.
void SetMat4(const std::string& name, glm::mat4 value)
Sets a 4x4 matrix uniform variable in the shader.

Function documentation

static std::shared_ptr<Shader> engine::graphics::Shader::CreateFromSource(const std::string& vertex_source, const std::string& fragment_source)

Loads vertex and fragment shader source code, compiles them, and links them into a single shader program.

Parameters
vertex_source A string containing the vertex shader source code.
fragment_source A string containing the fragment shader source code.
Returns A shared pointer to the newly created Shader object, or nullptr.

static std::shared_ptr<Shader> engine::graphics::Shader::Load(const std::string& path)

Placeholder Load method to satisfy the AssetManager requirement.

Parameters
path The path to the shader (not currently used for loading from disk).
Returns A shared pointer to the Shader, or nullptr.

Shaders are typically created from source in this engine.

unsigned int engine::graphics::Shader::id() const

Gets the OpenGL ID of the shader program.

Returns The shader ID.

void engine::graphics::Shader::SetInt(const std::string& name, int value)

Sets an integer uniform variable in the shader.

Parameters
name The name of the uniform variable in the GLSL code.
value The integer value to set.

void engine::graphics::Shader::SetVec3(const std::string& name, glm::vec3 value)

Sets a 3-component float vector uniform variable in the shader.

Parameters
name The name of the uniform variable in the GLSL code.
value The glm::vec3 value to set.

void engine::graphics::Shader::SetVec4(const std::string& name, glm::vec4 value)

Sets a 4-component float vector uniform variable in the shader.

Parameters
name The name of the uniform variable in the GLSL code.
value The glm::vec4 value to set.

void engine::graphics::Shader::SetMat4(const std::string& name, glm::mat4 value)

Sets a 4x4 matrix uniform variable in the shader.

Parameters
name The name of the uniform variable in the GLSL code.
value The glm::mat4 value to set.