lmgl 1.0.0
A lightweight OpenGL graphics engine library written in C++
Loading...
Searching...
No Matches
lmgl::renderer::Shader Class Reference

Represents a shader program used in rendering. More...

#include <shader.hpp>

Public Member Functions

 Shader (const std::string &vert, const std::string &frag)
 Creates a shader program from vertex and fragment shader source code.
 
 Shader (const std::string &vert, const std::string &geom, const std::string &frag)
 Creates a shader program with vertex, geometry, and fragment shaders.
 
 ~Shader ()
 Destructor for the Shader class.
 
void bind () const
 Binds the shader program for use in rendering.
 
void unbind () const
 Unbinds the shader program.
 
unsigned int get_id () const
 Retrieves the unique identifier of the shader program.
 
void set_int (const std::string &name, int val)
 Sets an integer uniform variable in the shader program.
 
void set_int_array (const std::string &name, int *vals, unsigned int count)
 Sets an array of integer uniform variables in the shader program.
 
void set_float (const std::string &name, float val)
 Sets a float uniform variable in the shader program.
 
void set_vec2 (const std::string &name, const glm::vec2 &val)
 Sets a vec2 uniform variable in the shader program.
 
void set_vec3 (const std::string &name, const glm::vec3 &val)
 Sets a vec3 uniform variable in the shader program.
 
void set_vec4 (const std::string &name, const glm::vec4 &val)
 Sets a vec4 uniform variable in the shader program.
 
void set_mat3 (const std::string &name, const glm::mat3 &val)
 Sets a mat3 uniform variable in the shader program.
 
void set_mat4 (const std::string &name, const glm::mat4 &val)
 Sets a mat4 uniform variable in the shader program.
 

Static Public Member Functions

static std::shared_ptr< Shaderfrom_vf_files (const std::string &vert, const std::string &frag)
 Creates a Shader instance from vertex and fragment shader files.
 
static std::shared_ptr< Shaderfrom_vgf_files (const std::string &vert, const std::string &geom, const std::string &frag)
 Creates a Shader instance from vertex, geometry, and fragment shader files.
 
static std::shared_ptr< Shaderfrom_glsl_file (const std::string &glsl)
 Creates a Shader instance from a single GLSL file.
 

Detailed Description

Represents a shader program used in rendering.

The Shader class encapsulates the functionality to create, compile, and manage shader programs consisting of vertex and fragment shaders. It provides an interface for loading shader source code, compiling it, and linking it into a usable program for rendering graphics.

Constructor & Destructor Documentation

◆ Shader() [1/2]

lmgl::renderer::Shader::Shader ( const std::string & vert,
const std::string & frag )

Creates a shader program from vertex and fragment shader source code.

Compiles the provided vertex and fragment shader source code, links them into a shader program, and prepares it for use in rendering.

Parameters
vertex_srcThe source code for the vertex shader.
fragment_srcThe source code for the fragment shader.

◆ Shader() [2/2]

lmgl::renderer::Shader::Shader ( const std::string & vert,
const std::string & geom,
const std::string & frag )

Creates a shader program with vertex, geometry, and fragment shaders.

Parameters
vertex_srcThe source code for the vertex shader.
geometry_srcThe source code for the geometry shader.
fragment_srcThe source code for the fragment shader.

◆ ~Shader()

lmgl::renderer::Shader::~Shader ( )

Destructor for the Shader class.

Cleans up the shader program and releases any associated resources.

Member Function Documentation

◆ bind()

void lmgl::renderer::Shader::bind ( ) const

Binds the shader program for use in rendering.

Activates the shader program so that it is used for subsequent rendering operations.

◆ from_glsl_file()

std::shared_ptr< Shader > lmgl::renderer::Shader::from_glsl_file ( const std::string & glsl)
static

Creates a Shader instance from a single GLSL file.

Reads the shader source code from the specified GLSL file, which contains both vertex and fragment shader code, compiles them, and links them into a shader program. Also supports optional geometry shader with #shader geometry directive.

Parameters
glslThe file path to the GLSL shader source code.
Returns
A shared pointer to the created Shader instance.

◆ from_vf_files()

std::shared_ptr< Shader > lmgl::renderer::Shader::from_vf_files ( const std::string & vert,
const std::string & frag )
static

Creates a Shader instance from vertex and fragment shader files.

Reads the shader source code from the specified files, compiles them, and links them into a shader program.

Parameters
vertThe file path to the vertex shader source code.
fragThe file path to the fragment shader source code.
Returns
A shared pointer to the created Shader instance.

◆ from_vgf_files()

std::shared_ptr< Shader > lmgl::renderer::Shader::from_vgf_files ( const std::string & vert,
const std::string & geom,
const std::string & frag )
static

Creates a Shader instance from vertex, geometry, and fragment shader files.

Parameters
vertThe file path to the vertex shader source code.
geomThe file path to the geometry shader source code.
fragThe file path to the fragment shader source code.
Returns
A shared pointer to the created Shader instance.

◆ get_id()

unsigned int lmgl::renderer::Shader::get_id ( ) const

Retrieves the unique identifier of the shader program.

Returns
The OpenGL-assigned ID of the shader program.

◆ set_float()

void lmgl::renderer::Shader::set_float ( const std::string & name,
float val )

Sets a float uniform variable in the shader program.

Parameters
nameThe name of the uniform variable.
valThe float value to set.

◆ set_int()

void lmgl::renderer::Shader::set_int ( const std::string & name,
int val )

Sets an integer uniform variable in the shader program.

Parameters
nameThe name of the uniform variable.
valThe integer value to set.

◆ set_int_array()

void lmgl::renderer::Shader::set_int_array ( const std::string & name,
int * vals,
unsigned int count )

Sets an array of integer uniform variables in the shader program.

Parameters
nameThe name of the uniform variable.
valsPointer to the array of integer values to set.
countThe number of integers in the array.

◆ set_mat3()

void lmgl::renderer::Shader::set_mat3 ( const std::string & name,
const glm::mat3 & val )

Sets a mat3 uniform variable in the shader program.

Parameters
nameThe name of the uniform variable.
valThe glm::mat3 value to set.

◆ set_mat4()

void lmgl::renderer::Shader::set_mat4 ( const std::string & name,
const glm::mat4 & val )

Sets a mat4 uniform variable in the shader program.

Parameters
nameThe name of the uniform variable.
valThe glm::mat4 value to set.

◆ set_vec2()

void lmgl::renderer::Shader::set_vec2 ( const std::string & name,
const glm::vec2 & val )

Sets a vec2 uniform variable in the shader program.

Parameters
nameThe name of the uniform variable.
valThe glm::vec2 value to set.

◆ set_vec3()

void lmgl::renderer::Shader::set_vec3 ( const std::string & name,
const glm::vec3 & val )

Sets a vec3 uniform variable in the shader program.

Parameters
nameThe name of the uniform variable.
valThe glm::vec3 value to set.

◆ set_vec4()

void lmgl::renderer::Shader::set_vec4 ( const std::string & name,
const glm::vec4 & val )

Sets a vec4 uniform variable in the shader program.

Parameters
nameThe name of the uniform variable.
valThe glm::vec4 value to set.

◆ unbind()

void lmgl::renderer::Shader::unbind ( ) const

Unbinds the shader program.

Deactivates the shader program, preventing it from being used in subsequent rendering operations.


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