17 #include <glm/glm.hpp> 33 void init(
const std::string& vertexCode,
const std::string& fragmentCode)
36 const char* vShaderCode = vertexCode.c_str();
37 const char* fShaderCode = fragmentCode.c_str();
39 unsigned int vertex, fragment;
41 vertex = glCreateShader(GL_VERTEX_SHADER);
42 glShaderSource(vertex, 1, &vShaderCode, NULL);
43 glCompileShader(vertex);
44 checkCompileErrors(vertex,
"VERTEX");
46 fragment = glCreateShader(GL_FRAGMENT_SHADER);
47 glShaderSource(fragment, 1, &fShaderCode, NULL);
48 glCompileShader(fragment);
49 checkCompileErrors(fragment,
"FRAGMENT");
52 ID = glCreateProgram();
53 glAttachShader(
ID, vertex);
54 glAttachShader(
ID, fragment);
57 checkCompileErrors(
ID,
"PROGRAM");
59 glDeleteShader(vertex);
60 glDeleteShader(fragment);
71 void setBool(
const std::string& name,
bool value)
const 73 glUniform1i(glGetUniformLocation(
ID, name.c_str()), (
int)value);
76 void setInt(
const std::string& name,
int value)
const 78 glUniform1i(glGetUniformLocation(
ID, name.c_str()), value);
81 void setFloat(
const std::string& name,
float value)
const 83 glUniform1f(glGetUniformLocation(
ID, name.c_str()), value);
86 void setVec2(
const std::string& name,
const glm::vec2& value)
const 88 glUniform2fv(glGetUniformLocation(
ID, name.c_str()), 1, &value[0]);
90 void setVec2(
const std::string& name,
float x,
float y)
const 92 glUniform2f(glGetUniformLocation(
ID, name.c_str()), x, y);
95 void setVec3(
const std::string& name,
const glm::vec3& value)
const 97 glUniform3fv(glGetUniformLocation(
ID, name.c_str()), 1, &value[0]);
99 void setVec3(
const std::string& name,
float x,
float y,
float z)
const 101 glUniform3f(glGetUniformLocation(
ID, name.c_str()), x, y, z);
104 void setVec4(
const std::string& name,
const glm::vec4& value)
const 106 glUniform4fv(glGetUniformLocation(
ID, name.c_str()), 1, &value[0]);
108 void setVec4(
const std::string& name,
float x,
float y,
float z,
float w)
110 glUniform4f(glGetUniformLocation(
ID, name.c_str()), x, y, z, w);
113 void setMat2(
const std::string& name,
const glm::mat2& mat)
const 115 glUniformMatrix2fv(glGetUniformLocation(
ID, name.c_str()), 1, GL_FALSE, &mat[0][0]);
118 void setMat3(
const std::string& name,
const glm::mat3& mat)
const 120 glUniformMatrix3fv(glGetUniformLocation(
ID, name.c_str()), 1, GL_FALSE, &mat[0][0]);
123 void setMat4(
const std::string& name,
const glm::mat4& mat)
const 125 glUniformMatrix4fv(glGetUniformLocation(
ID, name.c_str()), 1, GL_FALSE, &mat[0][0]);
131 void checkCompileErrors(GLuint shader, std::string type)
134 GLchar infoLog[1024];
135 if (type !=
"PROGRAM")
137 glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
140 glGetShaderInfoLog(shader, 1024, NULL, infoLog);
141 std::cerr <<
"ERROR::SHADER_COMPILATION_ERROR of type: " << type <<
"\n" << infoLog <<
"\n -- --------------------------------------------------- -- " << std::endl;
146 glGetProgramiv(shader, GL_LINK_STATUS, &success);
149 glGetProgramInfoLog(shader, 1024, NULL, infoLog);
150 std::cerr <<
"ERROR::PROGRAM_LINKING_ERROR of type: " << type <<
"\n" << infoLog <<
"\n -- --------------------------------------------------- -- " << std::endl;
158 #endif // ECVL_SHADER_H
void setVec3(const std::string &name, const glm::vec3 &value) const
void setInt(const std::string &name, int value) const
void setMat2(const std::string &name, const glm::mat2 &mat) const
void init(const std::string &vertexCode, const std::string &fragmentCode)
void setFloat(const std::string &name, float value) const
void setVec4(const std::string &name, float x, float y, float z, float w)
void setVec2(const std::string &name, float x, float y) const
void setVec2(const std::string &name, const glm::vec2 &value) const
void setVec3(const std::string &name, float x, float y, float z) const
void setVec4(const std::string &name, const glm::vec4 &value) const
void setMat4(const std::string &name, const glm::mat4 &mat) const
void setMat3(const std::string &name, const glm::mat3 &mat) const
void setBool(const std::string &name, bool value) const