6#include <brenta/shader.hpp>
10using namespace brenta;
29 if ((err = glGetError()) != GL_NO_ERROR)
31 ERROR(
"shader::use: error using shader {}: {}", shader_name, err);
42 GLint location = glGetUniformLocation(program, name);
46 ERROR(
"shader::set_bool: uniform '{}' not found in shader '{}'",
51 glUniform1i(location, (
int) value);
54 if ((err = glGetError()) != GL_NO_ERROR)
56 ERROR(
"shader::set_bool: error setting bool value for shader {} with name {}: {}",
57 shader_name, name, err);
68 GLint location = glGetUniformLocation(program, name);
72 ERROR(
"shader::set_int: uniform '{}' not found in shader '{}'",
77 glUniform1i(location, value);
80 if ((err = glGetError()) != GL_NO_ERROR)
82 ERROR(
"shader::set_int: error setting int value for shader '{}' with name '{}'",
83 shader_name, name, err);
90 const GLchar *name,
float value)
93 GLint location = glGetUniformLocation(program, name);
97 ERROR(
"shader::set_float: uniform '{}' not found in shader '{}'",
102 glUniform1f(location, value);
105 if ((err = glGetError()) != GL_NO_ERROR)
107 ERROR(
"shader::set_float: error setting float value for shader '{}' with name '{}': {}",
108 shader_name, name, err);
119 GLint location = glGetUniformLocation(program, name);
123 ERROR(
"shader::set_mat4: uniform '{}' not found in shader '{}'",
128 glUniformMatrix4fv(location, 1, GL_FALSE, glm::value_ptr(value));
131 if ((err = glGetError()) != GL_NO_ERROR)
133 ERROR(
"shader::set_mat4: error setting mat4 value for shader '{}' with name '{}': {}",
134 shader_name, name, err);
142 float x,
float y,
float z)
145 GLint location = glGetUniformLocation(program, name);
149 ERROR(
"shader::set_vec3: uniform '{}' not found in shader '{}'",
154 glUniform3f(location, x, y, z);
157 if ((err = glGetError()) != GL_NO_ERROR)
159 ERROR(
"shader::set_vec3: error setting vec3 value for shader '{}' with name '{}': {}",
160 shader_name, name, err);
171 GLint location = glGetUniformLocation(program, name);
175 ERROR(
"shader::set_vec3: uniform '{}' not found in shader '{}'",
180 glUniform3f(location, value.x, value.y, value.z);
183 if ((err = glGetError()) != GL_NO_ERROR)
185 ERROR(
"shader::set_vec3: error setting vec3 value for shader '{}' with name '{}': {}",
186 shader_name, name, err);
192bool shader::check_compile_errors(
unsigned int shader, std::string type)
196 if (type !=
"PROGRAM")
198 glGetShaderiv(
shader, GL_COMPILE_STATUS, &success);
201 std::stringstream out;
202 glGetShaderInfoLog(
shader, 1024, NULL, infoLog);
203 out <<
"shader: compilation error of type: " << type <<
"\n"
205 ERROR(
"{}", out.str());
211 glGetProgramiv(
shader, GL_LINK_STATUS, &success);
214 std::stringstream out;
215 glGetProgramInfoLog(
shader, 1024, NULL, infoLog);
216 out <<
"shader: program linking error of type: " << type <<
"\n"
218 ERROR(
"{}", out.str());
static bool set_mat4(types::shader_name_t shader_name, const GLchar *name, glm::mat4 value)
Set a 4x4 matrix in the shader.
static std::unordered_map< types::shader_name_t, unsigned int > shaders
Map of shaders.
static bool set_bool(types::shader_name_t shader_name, const GLchar *name, bool value)
Set a boolean 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 unsigned int get_id(types::shader_name_t shader_name)
Get the ID of a shader.
static bool set_int(types::shader_name_t shader_name, const GLchar *name, int value)
Set an integer in the shader.
static bool use(types::shader_name_t shader_name)
Use the shader.
static bool set_float(types::shader_name_t shader_name, const GLchar *name, float value)
Set a float in the shader.