Dengine/src/Shader.c

42 lines
1.1 KiB
C
Raw Normal View History

2016-06-28 06:00:03 +00:00
#include "Dengine/Shader.h"
2016-06-03 05:07:40 +00:00
2016-06-17 14:40:40 +00:00
const i32 shader_loadProgram(Shader *const shader, const GLuint vertexShader,
const GLuint fragmentShader)
2016-06-03 05:07:40 +00:00
{
2016-06-17 14:40:40 +00:00
shader->id = glCreateProgram();
glAttachShader(shader->id, vertexShader);
glAttachShader(shader->id, fragmentShader);
glLinkProgram(shader->id);
2016-06-03 05:07:40 +00:00
glDeleteShader(fragmentShader);
glDeleteShader(vertexShader);
2016-06-03 05:07:40 +00:00
GLint success;
GLchar infoLog[512];
2016-06-17 14:40:40 +00:00
glGetProgramiv(shader->id, GL_LINK_STATUS, &success);
2016-06-03 05:07:40 +00:00
if (!success)
{
2016-06-17 14:40:40 +00:00
glGetProgramInfoLog(shader->id, 512, NULL, infoLog);
printf("glLinkProgram failed: %s\n", infoLog);
return -1;
2016-06-03 05:07:40 +00:00
}
return 0;
}
2016-06-03 05:07:40 +00:00
2016-06-17 14:40:40 +00:00
void shader_uniformSet1i(Shader *const shader, const GLchar *name,
const GLuint data)
2016-06-09 05:49:03 +00:00
{
2016-06-17 14:40:40 +00:00
GLint uniformLoc = glGetUniformLocation(shader->id, name);
2016-06-09 05:49:03 +00:00
glUniform1i(uniformLoc, data);
}
2016-06-17 14:40:40 +00:00
void shader_uniformSetMat4fv(Shader *const shader, const GLchar *name,
mat4 data)
2016-06-09 05:49:03 +00:00
{
2016-06-17 14:40:40 +00:00
GLint uniformLoc = glGetUniformLocation(shader->id, name);
glUniformMatrix4fv(uniformLoc, 1, GL_FALSE, data.e[0]);
2016-06-09 05:49:03 +00:00
}
2016-06-17 14:40:40 +00:00
void shader_use(const Shader *const shader) { glUseProgram(shader->id); }