Improved glsafe macro to print out file name, line number and function

name on OpenGL assert.
This commit is contained in:
bubnikv 2019-03-27 10:26:55 +01:00
parent f65eb9afdb
commit 3987296b62
2 changed files with 5 additions and 5 deletions

View File

@ -32,7 +32,7 @@
#include "GUI.hpp" #include "GUI.hpp"
#ifdef HAS_GLSAFE #ifdef HAS_GLSAFE
void glAssertRecentCallImpl() void glAssertRecentCallImpl(const char *file_name, unsigned int line, const char *function_name)
{ {
GLenum err = glGetError(); GLenum err = glGetError();
if (err == GL_NO_ERROR) if (err == GL_NO_ERROR)
@ -47,7 +47,7 @@ void glAssertRecentCallImpl()
case GL_OUT_OF_MEMORY: sErr = "Out Of Memory"; break; case GL_OUT_OF_MEMORY: sErr = "Out Of Memory"; break;
default: sErr = "Unknown"; break; default: sErr = "Unknown"; break;
} }
BOOST_LOG_TRIVIAL(error) << "OpenGL error " << (int)err << ": " << sErr; BOOST_LOG_TRIVIAL(error) << "OpenGL error in " << file_name << ":" << line << ", function " << function_name << "() : " << (int)err << " - " << sErr;
assert(false); assert(false);
} }
#endif #endif

View File

@ -16,9 +16,9 @@
#endif #endif
#ifdef HAS_GLSAFE #ifdef HAS_GLSAFE
extern void glAssertRecentCallImpl(); extern void glAssertRecentCallImpl(const char *file_name, unsigned int line, const char *function_name);
inline void glAssertRecentCall() { glAssertRecentCallImpl(); } inline void glAssertRecentCall() { glAssertRecentCallImpl(__FILE__, __LINE__, __FUNCTION__); }
#define glsafe(cmd) do { cmd; glAssertRecentCallImpl(); } while (false) #define glsafe(cmd) do { cmd; glAssertRecentCallImpl(__FILE__, __LINE__, __FUNCTION__); } while (false)
#else #else
inline void glAssertRecentCall() { } inline void glAssertRecentCall() { }
#define glsafe(cmd) cmd #define glsafe(cmd) cmd