1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-22 12:33:29 +00:00

Makes error reporting more communicative.

This commit is contained in:
Thomas Harte 2019-02-18 11:13:54 -05:00
parent 8ecf885629
commit 6b2e1fe62b

View File

@ -9,6 +9,8 @@
#ifndef OpenGL_h
#define OpenGL_h
#include <iostream>
// TODO: figure out correct include paths for other platforms.
#ifdef __APPLE__
#if TARGET_OS_IPHONE
@ -22,14 +24,25 @@
#include <GL/gl.h>
#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