Files
Z3D/include/opengl/error.hpp
2025-03-23 21:11:22 +01:00

80 lines
2.0 KiB
C++

#pragma once
#include <system_error>
#include "GL/glew.h"
namespace zgl
{
namespace error
{
enum class codes : GLenum {
ok = GL_NO_ERROR,
invalid_enum = GL_INVALID_ENUM,
invalid_value = GL_INVALID_VALUE,
invalid_operation = GL_INVALID_OPERATION,
invalid_framebuffer_operation = GL_INVALID_FRAMEBUFFER_OPERATION,
out_of_memory = GL_OUT_OF_MEMORY,
stack_overflow = GL_STACK_OVERFLOW,
stack_underflow = GL_STACK_UNDERFLOW,
context_lost = GL_CONTEXT_LOST
};
struct category : std::error_category
{
[[nodiscard]] const char* name() const noexcept override
{
return "opengl";
}
[[nodiscard]] std::string message(int ev) const override
{
switch (static_cast<codes>(ev)) {
using enum codes;
case ok:
return "No error has been recorded.";
case invalid_enum:
return "An unacceptable value is specified for an enumerated argument.";
case invalid_value:
return "A numeric argument is out of range.";
case invalid_operation:
return "The specified operation is not allowed in the current state.";
case invalid_framebuffer_operation:
return "The framebuffer object is not complete.";
case out_of_memory:
return "There is not enough memory left to execute the command.";
case stack_overflow:
return "An attempt has been made to perform an operation that would cause an internal stack to underflow.";
case stack_underflow:
return "An attempt has been made to perform an operation that would cause an internal stack to overflow.";
case context_lost:
return "The OpenGL context has been lost.";
default:
return "<unknown>";
}
}
};
} // namespace error
[[nodiscard]] inline std::error_category& error_category() noexcept
{
static error::category category;
return category;
}
[[nodiscard]] inline std::error_code make_error_code(const GLenum e) noexcept
{
return { static_cast<int>(e), error_category() };
}
[[nodiscard]] inline std::error_code get_error()
{
return make_error_code(glGetError());
}
} // namespace zgl
template<>
struct std::is_error_code_enum<zgl::error::codes> : std::true_type {};