#include <memory>
#include "Shader.hpp"
gl::Shader::Shader (Wrangler &gl, GLenum type, const char *source)
: gl (gl)
{
this->id = gl.CreateShader (type);
if (this->id == 0)
throw "Shader creation failed";
GLint status;
gl.ShaderSource (this->id, 1, &source, NULL);
gl.CompileShader (this->id);
gl.GetShaderiv (this->id, GL_COMPILE_STATUS, &status);
if (status == GL_FALSE)
{
GLint log_length;
gl.GetShaderiv (this->id, GL_INFO_LOG_LENGTH, &log_length);
try
{
std::unique_ptr<GLchar[]> log (new GLchar[log_length]);
gl.GetShaderInfoLog (this->id, log_length, NULL, log.get ());
throw log;
}
catch (...)
{
gl.DeleteShader (this->id);
throw;
}
}
}
gl::Shader::~Shader ()
{
gl.DeleteShader (this->id);
}