Brenta Engine 1.2
Loading...
Searching...
No Matches
brenta::shader Class Reference

Shader class. More...

#include <shader.hpp>

Static Public Member Functions

template<typename... Args>
static bool create (std::string shader_name, GLenum type, std::string path, Args... args)
 Create a new shader.
 
template<typename... Args>
static bool create (const GLchar **feedback_varyings, int num_varyings, std::string shader_name, GLenum type, std::string path, Args... args)
 Create a new shader with feedback varyings.
 
static bool compile_shaders (std::vector< unsigned int > &compiled)
 
template<typename... Args>
static bool compile_shaders (std::vector< unsigned int > &compiled, GLenum type, std::string path, Args... args)
 
static unsigned int get_id (types::shader_name_t shader_name)
 Get the ID of a shader.
 
static bool use (types::shader_name_t shader_name)
 Use the shader.
 
static bool set_bool (types::shader_name_t shader_name, const GLchar *name, bool value)
 Set a boolean in the shader.
 
static bool set_int (types::shader_name_t shader_name, const GLchar *name, int value)
 Set an integer in the shader.
 
static bool set_float (types::shader_name_t shader_name, const GLchar *name, float value)
 Set a float in the shader.
 
static bool set_mat4 (types::shader_name_t shader_name, const GLchar *name, glm::mat4 value)
 Set a 4x4 matrix in the shader.
 
static bool set_vec3 (types::shader_name_t shader_name, const GLchar *name, float x, float y, float z)
 Set a 3D vector in the shader.
 
static bool set_vec3 (types::shader_name_t shader_name, const GLchar *name, glm::vec3 value)
 Set a 3D vector in the shader.
 

Static Public Attributes

static std::unordered_map< types::shader_name_t, unsigned int > shaders
 Map of shaders.
 

Detailed Description

Shader class.

This class is used to create and manage shaders. The shaders are created using the new method, which takes the name of the shader, the type of the shader, and the path to the file that contains the shader code. Multile shaders can be compiled and linked together by providing any number of types and paths paired. The shader can be used with the Use method, and the uniforms can be set using the set_bool, set_int, set_float, set_mat4, set_vec3 methods.

Definition at line 42 of file shader.hpp.

Member Function Documentation

◆ compile_shaders() [1/2]

static bool brenta::shader::compile_shaders ( std::vector< unsigned int > & compiled)
inlinestatic

Definition at line 151 of file shader.hpp.

◆ compile_shaders() [2/2]

template<typename... Args>
static bool brenta::shader::compile_shaders ( std::vector< unsigned int > & compiled,
GLenum type,
std::string path,
Args... args )
inlinestatic

Definition at line 157 of file shader.hpp.

◆ create() [1/2]

template<typename... Args>
static bool brenta::shader::create ( const GLchar ** feedback_varyings,
int num_varyings,
std::string shader_name,
GLenum type,
std::string path,
Args... args )
inlinestatic

Create a new shader with feedback varyings.

Parameters
feedback_varyingsArray of feedback varyings
num_varyingsNumber of feedback varyings
shader_nameName of the shader
typeType of the shader
pathPath to the file that contains the shader code
Returns
true on success, or false on error

Same as the New method, but adds feedback varyings to the shader, so that the output of the shader can be saved in a buffer object.

Example feedback_varyings: const GLchar* feedback_varyings[] = {"outValue"};

Definition at line 115 of file shader.hpp.

◆ create() [2/2]

template<typename... Args>
static bool brenta::shader::create ( std::string shader_name,
GLenum type,
std::string path,
Args... args )
inlinestatic

Create a new shader.

This method is used to create a new shader with the given name, type, and path. The path is the path to the file that contains the shader code. The type is the type of the shader (GL_VERTEX_SHADER, GL_FRAGMENT_SHADER, GL_GEOMETRY_SHADER).

Parameters
shader_nameName of the shader
typeType of the shader
pathPath to the file that contains the shader code
Returns
true on success, or false on error

You can provide any number of types and paths, those will be all compiled and linked in the same program.

Definition at line 71 of file shader.hpp.

◆ get_id()

unsigned int shader::get_id ( types::shader_name_t shader_name)
static

Get the ID of a shader.

Parameters
shader_nameName of the shader
Returns
ID of the shader

Definition at line 14 of file shader.cpp.

◆ set_bool()

bool shader::set_bool ( types::shader_name_t shader_name,
const GLchar * name,
bool value )
static

Set a boolean in the shader.

Parameters
shader_nameName of the shader
nameName of the uniform boolean
valueValue of the boolean
Returns
true on success, or false on error

Definition at line 37 of file shader.cpp.

◆ set_float()

bool shader::set_float ( types::shader_name_t shader_name,
const GLchar * name,
float value )
static

Set a float in the shader.

Parameters
shader_nameName of the shader
nameName of the uniform float
valueValue of the float
Returns
true on success, or false on error

Definition at line 89 of file shader.cpp.

◆ set_int()

bool shader::set_int ( types::shader_name_t shader_name,
const GLchar * name,
int value )
static

Set an integer in the shader.

Parameters
shader_nameName of the shader
nameName of the uniform integer
valueValue of the integer
Returns
true on success, or false on error

Definition at line 63 of file shader.cpp.

◆ set_mat4()

bool shader::set_mat4 ( types::shader_name_t shader_name,
const GLchar * name,
glm::mat4 value )
static

Set a 4x4 matrix in the shader.

Parameters
shader_nameName of the shader
nameName of the uniform matrix
valueValue of the matrix
Returns
true on success, or false on error

Definition at line 114 of file shader.cpp.

◆ set_vec3() [1/2]

bool shader::set_vec3 ( types::shader_name_t shader_name,
const GLchar * name,
float x,
float y,
float z )
static

Set a 3D vector in the shader.

Parameters
shader_nameName of uniform the shader
nameName of the vector
xX value of the vector
yY value of the vector
zZ value of the vector
Returns
true on success, or false on error

Definition at line 140 of file shader.cpp.

◆ set_vec3() [2/2]

bool shader::set_vec3 ( types::shader_name_t shader_name,
const GLchar * name,
glm::vec3 value )
static

Set a 3D vector in the shader.

Parameters
shader_nameName of the shader
nameName of the uniform vector
valueValue of the vector
Returns
true on success, or false on error

Definition at line 166 of file shader.cpp.

◆ use()

bool shader::use ( types::shader_name_t shader_name)
static

Use the shader.

Parameters
shader_nameName of the shader

You need to call this method before rendering anything with the shader.

Returns
true on success, or false on error

Definition at line 24 of file shader.cpp.

Field Documentation

◆ shaders

std::unordered_map< types::shader_name_t, unsigned int > shader::shaders
static

Map of shaders.

This map is used to store the shaders that are created during the execution of the program. The key is the name of the shader and the value is the ID of the shader.

Definition at line 52 of file shader.hpp.


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