2016-06-17 14:40:40 +00:00
|
|
|
#include <Dengine/Shader.h>
|
2016-06-03 05:07:40 +00:00
|
|
|
|
2016-06-09 05:49:03 +00:00
|
|
|
#include <glm/gtc/type_ptr.hpp>
|
|
|
|
|
2016-06-03 05:07:40 +00:00
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
|
|
|
|
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
|
|
|
|
2016-06-04 12:42:22 +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);
|
2016-06-04 12:42:22 +00:00
|
|
|
return -1;
|
2016-06-03 05:07:40 +00:00
|
|
|
}
|
|
|
|
|
2016-06-04 12:42:22 +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,
|
|
|
|
const glm::mat4 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
|
|
|
glUniformMatrix4fv(uniformLoc, 1, GL_FALSE, glm::value_ptr(data));
|
|
|
|
}
|
|
|
|
|
2016-06-17 14:40:40 +00:00
|
|
|
void shader_use(const Shader *const shader) { glUseProgram(shader->id); }
|