NBEngine/engine/NBGraphics/ProgramPipeline.hpp

123 lines
2.4 KiB
C++

#pragma once
#ifndef _NB_SHADER
#define _NB_SHADER
#include "GLLoad.hpp"
#include <string>
#include <NBCore/Errors.hpp>
#include <NBCore/Utils.hpp>
#include "OGLObjects.hpp"
namespace nb {
class ShaderError : public Error<ShaderError> {
using Base = Error<ShaderError>;
public:
using Base::Base;
enum Codes : unsigned int {
UNDEFINED
};
static const std::string type;
static const ErrorCodeMap ErrorMessages;
};
class ProgramError : public Error<ProgramError> {
using Base = Error<ProgramError>;
public:
using Base::Base;
enum Codes : unsigned int {
UNDEFINED, LINKING_ERROR
};
static const std::string type;
static const ErrorCodeMap ErrorMessages;
};
enum OpenGLProfiles {
Core,
Compatibility,
ES
};
class Shader : public OpenGLObject {
using Base = OpenGLObject;
public:
using Base::Base;
using Base::id;
Shader(GLenum, const std::string&);
Shader(Shader&&);
Shader& operator=(Shader&&) = delete;
~Shader() { remove(); }
operator bool();
virtual void bind() const override { /* TODO: Some warning of some kind perhaps*/ }
virtual void unbind() const override { /* TODO: Some warning of some kind perhaps*/ }
GLint status(GLenum) const;
std::string log() const;
const GLenum target;
friend Base;
protected:
using Base::_id;
GLint _success;
virtual GLuint declare() override {
if (!_id) {
_id = _id = glCreateShader(target);
}
return _id;
}
virtual void remove() override {
if (_id) {
glDeleteShader(_id);
}
}
};
class Program : public OpenGLObject {
using Base = OpenGLObject;
public:
using Base::Base;
using Base::id;
Program(SharedVector<Shader>);
Program(Program&&);
Program& operator=(Program&&) = delete;
operator bool();
~Program() { remove(); }
virtual void bind() const override {
glUseProgram(_id);
}
virtual void unbind() const override { /* TODO: Some warning of some kind perhaps*/ }
GLint status(GLenum) const;
std::string log() const;
friend Base;
protected:
using Base::_id;
GLint _success;
virtual GLuint declare() override {
if (!_id) {
_id = glCreateProgram();
}
return _id;
}
virtual void remove() override {
if (_id) {
glDeleteProgram(_id);
}
}
};
}
#endif