2016-06-03 05:07:40 +00:00
|
|
|
#include <Dengine\Shader.h>
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
namespace Dengine
|
|
|
|
{
|
2016-06-04 12:42:22 +00:00
|
|
|
Shader::Shader()
|
2016-06-07 15:35:00 +00:00
|
|
|
: program(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-04 12:42:22 +00:00
|
|
|
i32 Shader::loadProgram(GLuint vertexShader, GLuint fragmentShader)
|
2016-06-03 05:07:40 +00:00
|
|
|
{
|
2016-06-07 15:35:00 +00:00
|
|
|
this->program = glCreateProgram();
|
|
|
|
glAttachShader(this->program, vertexShader);
|
|
|
|
glAttachShader(this->program, fragmentShader);
|
|
|
|
glLinkProgram(this->program);
|
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-07 15:35:00 +00:00
|
|
|
glGetProgramiv(this->program, GL_LINK_STATUS, &success);
|
2016-06-03 05:07:40 +00:00
|
|
|
if (!success)
|
|
|
|
{
|
2016-06-07 15:35:00 +00:00
|
|
|
glGetProgramInfoLog(this->program, 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-04 12:42:22 +00:00
|
|
|
}
|
2016-06-03 05:07:40 +00:00
|
|
|
|
2016-06-07 15:35:00 +00:00
|
|
|
void Shader::use() { glUseProgram(this->program); }
|
2016-06-03 05:07:40 +00:00
|
|
|
}
|