Brenta Engine 1.0
Loading...
Searching...
No Matches
Brenta::Shader Class Reference

Shader class. More...

#include <shader.hpp>

Static Public Member Functions

template<typename... Args>
static void New (std::string shader_name, GLenum type, std::string path, Args... args)
 Create a new shader.
 
template<typename... Args>
static void New (const GLchar **feedbackVaryings, int numVaryings, 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 GetId (Types::ShaderName shader_name)
 Get the ID of a shader.
 
static void Use (Types::ShaderName shader_name)
 Use the shader.
 
static void SetBool (Types::ShaderName shader_name, const std::string &name, bool value)
 Set a boolean in the shader.
 
static void SetInt (Types::ShaderName shader_name, const std::string &name, int value)
 Set an integer in the shader.
 
static void SetFloat (Types::ShaderName shader_name, const std::string &name, float value)
 Set a float in the shader.
 
static void SetMat4 (Types::ShaderName shader_name, const GLchar *name, glm::mat4 value)
 Set a 4x4 matrix in the shader.
 
static void SetVec3 (Types::ShaderName shader_name, const GLchar *name, float x, float y, float z)
 Set a 3D vector in the shader.
 
static void SetVec3 (Types::ShaderName shader_name, const GLchar *name, glm::vec3 value)
 Set a 3D vector in the shader.
 

Static Public Attributes

static std::unordered_map< Types::ShaderName, 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.

◆ GetId()

unsigned int Shader::GetId ( Types::ShaderName 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.

◆ New() [1/2]

template<typename... Args>
static void Brenta::Shader::New ( const GLchar ** feedbackVaryings,
int numVaryings,
std::string shader_name,
GLenum type,
std::string path,
Args... args )
inlinestatic

Create a new shader with feedback varyings.

Parameters
feedbackVaryingsArray of feedback varyings
numVaryingsNumber 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 feedbackVaryings: const GLchar* feedbackVaryings[] = {"outValue"};

Definition at line 128 of file shader.hpp.

◆ New() [2/2]

template<typename... Args>
static void Brenta::Shader::New ( 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.

◆ SetBool()

void Shader::SetBool ( Types::ShaderName 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.

◆ SetFloat()

void Shader::SetFloat ( Types::ShaderName 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 79 of file shader.cpp.

◆ SetInt()

void Shader::SetInt ( Types::ShaderName 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 67 of file shader.cpp.

◆ SetMat4()

void Shader::SetMat4 ( Types::ShaderName 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 90 of file shader.cpp.

◆ SetVec3() [1/2]

void Shader::SetVec3 ( Types::ShaderName 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 103 of file shader.cpp.

◆ SetVec3() [2/2]

void Shader::SetVec3 ( Types::ShaderName 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 116 of file shader.cpp.

◆ Use()

void Shader::Use ( Types::ShaderName 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::ShaderName, 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: