diff --git a/libs/gfx/include/psemek/gfx/error.hpp b/libs/gfx/include/psemek/gfx/error.hpp new file mode 100644 index 00000000..85e753f4 --- /dev/null +++ b/libs/gfx/include/psemek/gfx/error.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include + +namespace psemek::gfx +{ + + std::string_view gl_error_str(unsigned int e); + + void check_error(); + +} diff --git a/libs/gfx/source/error.cpp b/libs/gfx/source/error.cpp new file mode 100644 index 00000000..8da6856a --- /dev/null +++ b/libs/gfx/source/error.cpp @@ -0,0 +1,35 @@ +#include +#include +#include + +#include + +namespace psemek::gfx +{ + + static_assert(std::is_same_v); + + std::string_view gl_error_str(GLenum e) + { + switch (e) + { + case gl::NO_ERROR_: return "GL_NO_ERROR"; + case gl::INVALID_ENUM: return "GL_INVALID_ENUM"; + case gl::INVALID_VALUE: return "GL_INVALID_VALUE"; + case gl::INVALID_OPERATION: return "GL_INVALID_OPERATION"; + case gl::INVALID_FRAMEBUFFER_OPERATION: return "GL_INVALID_FRAMEBUFFER_OPERATION"; + case gl::OUT_OF_MEMORY: return "GL_OUT_OF_MEMORY"; + } + + return "(unknown)"; + } + + void check_error() + { + auto e = gl::GetError(); + + if (e != gl::GetError()) + throw std::runtime_error(util::to_string("OpenGL error: ", gl_error_str(e))); + } + +}