Add OpenGL error reporting
This commit is contained in:
parent
040497887c
commit
616b7cfce5
2 changed files with 47 additions and 0 deletions
12
libs/gfx/include/psemek/gfx/error.hpp
Normal file
12
libs/gfx/include/psemek/gfx/error.hpp
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <string_view>
|
||||
|
||||
namespace psemek::gfx
|
||||
{
|
||||
|
||||
std::string_view gl_error_str(unsigned int e);
|
||||
|
||||
void check_error();
|
||||
|
||||
}
|
||||
35
libs/gfx/source/error.cpp
Normal file
35
libs/gfx/source/error.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#include <psemek/gfx/error.hpp>
|
||||
#include <psemek/gfx/gl.hpp>
|
||||
#include <psemek/util/to_string.hpp>
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
namespace psemek::gfx
|
||||
{
|
||||
|
||||
static_assert(std::is_same_v<unsigned int, GLenum>);
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue