2016-06-03 05:07:40 +00:00
|
|
|
#include <Dengine\Shader.h>
|
|
|
|
|
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>
|
|
|
|
|
|
|
|
namespace Dengine
|
|
|
|
{
|
2016-06-04 12:42:22 +00:00
|
|
|
Shader::Shader()
|
2016-06-09 05:49:03 +00:00
|
|
|
: id(0)
|
2016-06-03 05:07:40 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-06-04 12:42:22 +00:00
|
|
|
Shader::~Shader() {}
|
2016-06-03 05:07:40 +00:00
|
|
|
|
2016-06-16 14:14:58 +00:00
|
|
|
const i32 Shader::loadProgram(const GLuint vertexShader, const GLuint fragmentShader)
|
2016-06-03 05:07:40 +00:00
|
|
|
{
|
2016-06-09 05:49:03 +00:00
|
|
|
this->id = glCreateProgram();
|
|
|
|
glAttachShader(this->id, vertexShader);
|
|
|
|
glAttachShader(this->id, fragmentShader);
|
|
|
|
glLinkProgram(this->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-09 05:49:03 +00:00
|
|
|
glGetProgramiv(this->id, GL_LINK_STATUS, &success);
|
2016-06-03 05:07:40 +00:00
|
|
|
if (!success)
|
|
|
|
{
|
2016-06-09 05:49:03 +00:00
|
|
|
glGetProgramInfoLog(this->id, 512, NULL, infoLog);
|
2016-06-03 05:07:40 +00:00
|
|
|
std::cout << "glLinkProgram failed: " << infoLog << std::endl;
|
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-09 05:49:03 +00:00
|
|
|
void Shader::uniformSet1i(const GLchar *name, const GLuint data)
|
|
|
|
{
|
|
|
|
GLint uniformLoc = glGetUniformLocation(this->id, name);
|
|
|
|
glUniform1i(uniformLoc, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Shader::uniformSetMat4fv(const GLchar *name, const glm::mat4 data)
|
|
|
|
{
|
|
|
|
GLint uniformLoc = glGetUniformLocation(this->id, name);
|
|
|
|
glCheckError();
|
|
|
|
glUniformMatrix4fv(uniformLoc, 1, GL_FALSE, glm::value_ptr(data));
|
|
|
|
glCheckError();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Shader::use() const { glUseProgram(this->id); }
|
2016-06-03 05:07:40 +00:00
|
|
|
}
|