4 #include <glm/gtc/type_ptr.hpp>
26 std::string vertexSource, fragmentSource;
80 for(std::string item : attributes) {
93 GLint linked = GL_FALSE;
94 glGetProgramiv(
m_programID, GL_LINK_STATUS, &linked);
97 if(linked == GL_FALSE) {
101 glGetProgramiv(
m_programID, GL_INFO_LOG_LENGTH, &maxLength);
104 std::vector<char> errorLog(maxLength);
105 glGetProgramInfoLog(
m_programID, maxLength, &maxLength, &errorLog[0]);
128 GLint location = glGetUniformLocation(
m_programID, uniform.c_str());
131 if(location == (GLint)GL_INVALID_INDEX) {
144 glBindFragDataLocation(
m_programID, location, outputVariableName.c_str());
154 glEnableVertexAttribArray(i);
168 glDisableVertexAttribArray(i);
186 glShaderSource(
id, 1, &source,
nullptr);
192 GLint compiled = GL_FALSE;
193 glGetShaderiv(
id, GL_COMPILE_STATUS, &compiled);
195 if(compiled == GL_FALSE) {
199 glGetShaderiv(
id, GL_INFO_LOG_LENGTH, &maxLength);
202 std::vector<char> errorLog(maxLength);
203 glGetShaderInfoLog(
id, maxLength, &maxLength, &errorLog[0]);
217 if(loc == -1)
return false;
224 void ShaderProgram::setUniform<int>(
const std::string uniform,
int* data,
unsigned int num)
230 if(loc == -1)
return;
233 glUniform1iv(loc, num, data);
236 void ShaderProgram::setUniform<unsigned int>(
const std::string uniform,
unsigned int* data,
unsigned int num)
242 if(loc == -1)
return;
245 glUniform1uiv(loc, num, data);
248 void ShaderProgram::setUniform<float>(
const std::string uniform,
float* data,
unsigned int num)
254 if(loc == -1)
return;
257 glUniform1fv(loc, num, data);
261 void ShaderProgram::setUniform<glm::vec2>(
const std::string uniform, glm::vec2* data,
unsigned int num)
264 GLint loc = getUniformLocation(uniform);
267 if(loc == -1)
return;
270 glUniform2fv(loc, num, glm::value_ptr(*data));
273 void ShaderProgram::setUniform<glm::vec3>(
const std::string uniform, glm::vec3* data,
unsigned int num)
276 GLint loc = getUniformLocation(uniform);
279 if(loc == -1)
return;
282 glUniform3fv(loc, num, glm::value_ptr(*data));
285 void ShaderProgram::setUniform<glm::vec4>(
const std::string uniform, glm::vec4* data,
unsigned int num)
288 GLint loc = getUniformLocation(uniform);
291 if(loc == -1)
return;
294 glUniform4fv(loc, num, glm::value_ptr(*data));
297 void ShaderProgram::setUniform<glm::ivec2>(
const std::string uniform, glm::ivec2* data,
unsigned int num)
300 GLint loc = getUniformLocation(uniform);
303 if(loc == -1)
return;
306 glUniform2iv(loc, num, glm::value_ptr(*data));
309 void ShaderProgram::setUniform<glm::ivec3>(
const std::string uniform, glm::ivec3* data,
unsigned int num)
312 GLint loc = getUniformLocation(uniform);
315 if(loc == -1)
return;
318 glUniform3iv(loc, num, glm::value_ptr(*data));
321 void ShaderProgram::setUniform<glm::ivec4>(
const std::string uniform, glm::ivec4* data,
unsigned int num)
324 GLint loc = getUniformLocation(uniform);
327 if(loc == -1)
return;
330 glUniform4iv(loc, num, glm::value_ptr(*data));
334 void ShaderProgram::setUniformMatrix<glm::mat4>(
const std::string uniform,
bool transpose, glm::mat4* data,
unsigned int num)
337 GLint loc = getUniformLocation(uniform);
340 if(loc == -1)
return;
343 glUniformMatrix4fv(loc, num, transpose, glm::value_ptr(*data));