75 lines
1.8 KiB
C++
75 lines
1.8 KiB
C++
#include "ProgramPipeline.hpp"
|
|
|
|
namespace nb{
|
|
|
|
using ShaderErrCodes = ShaderError::Codes;
|
|
const std::string ShaderError::type = "nb::ShaderError";
|
|
const ErrorCodeMap ShaderError::ErrorMessages = {
|
|
{ShaderErrCodes::UNDEFINED, "Error"}
|
|
};
|
|
|
|
using ProgramErrCodes = ProgramError::Codes;
|
|
const std::string ProgramError::type = "nb::ProgramError";
|
|
const ErrorCodeMap ProgramError::ErrorMessages = {
|
|
{ProgramErrCodes::UNDEFINED, "Error"},
|
|
{ProgramErrCodes::LINKING_ERROR, "Linker error"}
|
|
};
|
|
|
|
Shader::Shader(GLenum target_, const std::string& source_) : target(target_) {
|
|
declare();
|
|
_success = status(GL_COMPILE_STATUS);
|
|
}
|
|
|
|
Shader::Shader(Shader&& cpy) : target(cpy.target) {
|
|
_id = cpy._id;
|
|
}
|
|
|
|
Shader::operator bool() { return _success; }
|
|
|
|
GLint Shader::status(GLenum parameter) const {
|
|
GLint param = 0;
|
|
glGetShaderiv(_id, parameter, ¶m);
|
|
return param;
|
|
}
|
|
|
|
std::string Shader::log() const {
|
|
GLint logsize = status(GL_INFO_LOG_LENGTH);
|
|
char* log_ = new char[logsize];
|
|
glGetShaderInfoLog(_id, logsize, NULL, log_);
|
|
std::string ret(log_, logsize);
|
|
delete[] log_;
|
|
return ret;
|
|
}
|
|
|
|
Program::Program(SharedVector<Shader> shaders_) {
|
|
declare();
|
|
for (auto shad_ptr : shaders_) {
|
|
glAttachShader(_id, shad_ptr->id());
|
|
}
|
|
glLinkProgram(_id);
|
|
_success = status(GL_LINK_STATUS);
|
|
if (!_success) {
|
|
WARN(log(), 0x01);
|
|
}
|
|
}
|
|
|
|
Program::operator bool() { return _success; }
|
|
|
|
GLint Program::status(GLenum parameter) const {
|
|
GLint param = 0;
|
|
glGetProgramiv(_id, parameter, ¶m);
|
|
return param;
|
|
}
|
|
|
|
std::string Program::log() const {
|
|
GLint logsize = status(GL_INFO_LOG_LENGTH);
|
|
char* log_ = new char[logsize];
|
|
glGetProgramInfoLog(_id, logsize, NULL, log_);
|
|
std::string ret(log_, logsize);
|
|
delete[] log_;
|
|
return ret;
|
|
}
|
|
|
|
|
|
|
|
} |