From 6b2e1fe62b7ce8cfc2c35fd3f11def8011cdda3e Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 18 Feb 2019 11:13:54 -0500 Subject: [PATCH] Makes error reporting more communicative. --- Outputs/OpenGL/OpenGL.hpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/Outputs/OpenGL/OpenGL.hpp b/Outputs/OpenGL/OpenGL.hpp index cc17cc4f5..c4a48379e 100644 --- a/Outputs/OpenGL/OpenGL.hpp +++ b/Outputs/OpenGL/OpenGL.hpp @@ -9,6 +9,8 @@ #ifndef OpenGL_h #define OpenGL_h +#include + // TODO: figure out correct include paths for other platforms. #ifdef __APPLE__ #if TARGET_OS_IPHONE @@ -22,14 +24,25 @@ #include #endif -// To consider: might it be smarter to switch and log on error, -// rather than raising an exception? They're conventionally -// something you're permitted to ignore. -// -// (and, from that indecision, hence the pointless decision -// on whether to use an assert based on NDEBUG) #ifndef NDEBUG -#define test_gl_error() assert(!glGetError()); + +#define test_gl_error() { \ + const auto error = glGetError(); \ + if(error) { \ + switch(error) { \ + default: std::cerr << "Error " << error;\ + case GL_INVALID_ENUM: std::cerr << "GL_INVALID_ENUM"; break; \ + case GL_INVALID_VALUE: std::cerr << "GL_INVALID_VALUE"; break; \ + case GL_INVALID_OPERATION: std::cerr << "GL_INVALID_OPERATION"; break; \ + case GL_INVALID_FRAMEBUFFER_OPERATION: std::cerr << "GL_INVALID_FRAMEBUFFER_OPERATION"; break; \ + case GL_OUT_OF_MEMORY: std::cerr << "GL_OUT_OF_MEMORY"; break; \ + }; \ + std::cerr << " at line " << __LINE__ << " in " << __FILE__ << std::endl; \ + assert(false); \ + } \ + \ +} + #else #define test_gl_error() while(false) {} #endif