#include #include #ifndef GLENUMSTRPAIR #define GLENUMSTRPAIR(x) {x, #x} #endif // GLENUMSTRPAIR namespace nb { const std::string OpenGLObjectError::type = "nb::OpenGLObjectError"; const ErrorCodeMap OpenGLObjectError::ErrorMessages = { { OpenGLObjectError::Codes::UNDEFINED, "Error" }, {OpenGLObjectError::Codes::HANGING_OBJECT, "Attempting to leave a hanging OpenGL object"}, {OpenGLObjectError::Codes::INVALID_OBJECT, "Attempting operation with invalid object"}, {OpenGLObjectError::Codes::INVALID_CONTEXT, "Object not valid with current OpengGL context"} }; const std::string OpenGLError::type = "nb::OpenGLError"; const ErrorCodeMap OpenGLError::ErrorMessages = { GLENUMSTRPAIR(GL_NO_ERROR), GLENUMSTRPAIR(GL_INVALID_ENUM), GLENUMSTRPAIR(GL_INVALID_ENUM), GLENUMSTRPAIR(GL_INVALID_VALUE), GLENUMSTRPAIR(GL_INVALID_OPERATION), GLENUMSTRPAIR(GL_INVALID_FRAMEBUFFER_OPERATION), GLENUMSTRPAIR(GL_OUT_OF_MEMORY), GLENUMSTRPAIR(GL_STACK_UNDERFLOW), GLENUMSTRPAIR(GL_STACK_OVERFLOW) }; OpenGLError OpenGLError::status() { return OpenGLError(glGetError()); } OpenGLError OpenGLError::status(const std::string& note) { return OpenGLError(glGetError(), note); } const ConstantMap TypeToGLSL = { {TypeCodes::FLOAT16, GL_HALF_FLOAT}, {TypeCodes::FLOAT32, GL_FLOAT}, {TypeCodes::DOUBLE64, GL_DOUBLE}, {TypeCodes::INT8, GL_BYTE}, {TypeCodes::INT16, GL_SHORT}, {TypeCodes::INT32, GL_INT}, {TypeCodes::UINT8, GL_UNSIGNED_BYTE}, {TypeCodes::UINT16, GL_UNSIGNED_SHORT}, {TypeCodes::UINT32, GL_UNSIGNED_INT}, }; // class OpenGLObject void OpenGLObject::checkObjectContextValidity() { if (_arena != OGLWindow::GetCurrentObjectArena()) { THROW(OpenGLObjectError(OpenGLObjectError::INVALID_CONTEXT)); } } OpenGLObject::OpenGLObject(OpenGLObject&& rval) : _arena(rval._arena) { checkObjectContextValidity(); *this = std::move(rval); } OpenGLObject::OpenGLObject() : _arena(OGLWindow::GetCurrentObjectArena()) {} OpenGLObject& OpenGLObject::operator=(OpenGLObject&& rhs) { rhs.checkObjectContextValidity(); if (_id) { THROW(OpenGLObjectError(Codes::HANGING_OBJECT)); } _id = rhs._id; rhs._id = 0; return *this; } const GLEnumTableType GLenumTable = { GLENUMSTRPAIR(GL_DRAW_FRAMEBUFFER), GLENUMSTRPAIR(GL_FRAMEBUFFER), GLENUMSTRPAIR(GL_FRAMEBUFFER_COMPLETE), GLENUMSTRPAIR(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT), GLENUMSTRPAIR(GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER), GLENUMSTRPAIR(GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS), GLENUMSTRPAIR(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT), GLENUMSTRPAIR(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE), GLENUMSTRPAIR(GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER), GLENUMSTRPAIR(GL_FRAMEBUFFER_UNDEFINED), GLENUMSTRPAIR(GL_FRAMEBUFFER_UNSUPPORTED), GLENUMSTRPAIR(GL_READ_FRAMEBUFFER), GLENUMSTRPAIR(GL_RG), GLENUMSTRPAIR(GL_RG32F), GLENUMSTRPAIR(GL_RGB), GLENUMSTRPAIR(GL_RGB8UI), GLENUMSTRPAIR(GL_RGBA8UI), GLENUMSTRPAIR(GL_RGBA), GLENUMSTRPAIR(GL_ELEMENT_ARRAY_BUFFER), GLENUMSTRPAIR(GL_UNSIGNED_INT), GLENUMSTRPAIR(GL_UNSIGNED_SHORT), GLENUMSTRPAIR(GL_UNSIGNED_BYTE), }; } // namespace nb