initial commit
This commit is contained in:
74
include/opengl/error.hpp
Normal file
74
include/opengl/error.hpp
Normal file
@@ -0,0 +1,74 @@
|
||||
#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() };
|
||||
}
|
||||
|
||||
} // namespace zgl
|
||||
|
||||
template<>
|
||||
struct std::is_error_code_enum<zgl::error::codes> : std::true_type {};
|
||||
Reference in New Issue
Block a user