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

Shader class. More...

#include <shader.hpp>

Static Public Member Functions

template<typename... Args>
static void create (std::string shader_name, GLenum type, std::string path, Args... args)
 Create a new shader.
 
template<typename... Args>
static void 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 void compile_shaders (std::vector< unsigned int > &compiled)
 
template<typename... Args>
static void 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 void use (types::shader_name_t shader_name)
 Use the shader.
 
static void set_bool (types::shader_name_t shader_name, const std::string &name, bool value)
 Set a boolean in the shader.
 
static void set_int (types::shader_name_t shader_name, const std::string &name, int value)
 Set an integer in the shader.
 
static void set_float (types::shader_name_t shader_name, const std::string &name, float value)
 Set a float in the shader.
 
static void set_mat4 (types::shader_name_t shader_name, const GLchar *name, glm::mat4 value)
 Set a 4x4 matrix in the shader.
 
static void 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 void 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. The shader can be used with the Use method, and the uniforms can be set using the SetBool, SetInt, SetFloat, SetMat4, SetVec3 methods.

Definition at line 65 of file shader.hpp.

Member Function Documentation

◆ compile_shaders() [1/2]

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

Definition at line 154 of file shader.hpp.

◆ compile_shaders() [2/2]

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

Definition at line 160 of file shader.hpp.

◆ create() [1/2]

template<typename... Args>
static void 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

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 128 of file shader.hpp.

◆ create() [2/2]

template<typename... Args>
static void 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

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

Definition at line 93 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 33 of file shader.cpp.

◆ set_bool()

void shader::set_bool ( types::shader_name_t shader_name,
const std::string & 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

Definition at line 55 of file shader.cpp.

◆ set_float()

void shader::set_float ( types::shader_name_t shader_name,
const std::string & 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

Definition at line 77 of file shader.cpp.

◆ set_int()

void shader::set_int ( types::shader_name_t shader_name,
const std::string & 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

Definition at line 66 of file shader.cpp.

◆ set_mat4()

void 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

Definition at line 88 of file shader.cpp.

◆ set_vec3() [1/2]

void 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

Definition at line 100 of file shader.cpp.

◆ set_vec3() [2/2]

void 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

Definition at line 112 of file shader.cpp.

◆ use()

void 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.

Definition at line 43 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 75 of file shader.hpp.


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