2018-09-05 06:49:02 +00:00
|
|
|
#include "ShaderProgram.h"
|
|
|
|
|
2018-09-12 21:03:46 +00:00
|
|
|
namespace charcoal
|
2018-09-05 06:49:02 +00:00
|
|
|
{
|
2018-09-12 21:03:46 +00:00
|
|
|
ShaderProgram::ShaderProgram()
|
|
|
|
: m_program(glCreateProgram())
|
|
|
|
{}
|
2018-09-05 06:49:02 +00:00
|
|
|
|
2018-09-12 21:03:46 +00:00
|
|
|
ShaderProgram::~ShaderProgram()
|
|
|
|
{
|
|
|
|
glDeleteProgram(m_program);
|
|
|
|
}
|
2018-09-05 06:49:02 +00:00
|
|
|
|
2018-09-12 21:03:46 +00:00
|
|
|
void ShaderProgram::attach_shader(const Shader& shader)
|
|
|
|
{
|
|
|
|
glAttachShader(m_program, shader.get_shader());
|
|
|
|
}
|
2018-09-05 06:49:02 +00:00
|
|
|
|
2018-09-12 21:03:46 +00:00
|
|
|
void ShaderProgram::link()
|
|
|
|
{
|
|
|
|
glLinkProgram(m_program);
|
2018-09-15 01:29:05 +00:00
|
|
|
|
|
|
|
GLint program_linked;
|
|
|
|
glGetProgramiv(m_program, GL_LINK_STATUS, &program_linked);
|
|
|
|
if (program_linked != GL_TRUE)
|
|
|
|
{
|
|
|
|
GLsizei log_length = 0;
|
|
|
|
GLchar message[1024];
|
|
|
|
glGetProgramInfoLog(m_program, 1023, &log_length, message);
|
|
|
|
message[log_length] = '\0'; // Add null terminator
|
|
|
|
OutputDebugString("Error Linking Shader Program:\n");
|
|
|
|
OutputDebugString(message);
|
|
|
|
OutputDebugString("\n");
|
|
|
|
throw EXCEPTION("Error linking Shader Program.");
|
|
|
|
}
|
|
|
|
|
2018-09-12 21:03:46 +00:00
|
|
|
}
|
2018-09-05 06:49:02 +00:00
|
|
|
|
2018-09-12 21:03:46 +00:00
|
|
|
void ShaderProgram::use() const
|
|
|
|
{
|
|
|
|
glUseProgram(m_program);
|
|
|
|
}
|
|
|
|
|
|
|
|
GLuint ShaderProgram::get_program() const
|
|
|
|
{
|
|
|
|
return m_program;
|
|
|
|
}
|
|
|
|
}
|