+static const char *glErrorToString(GLenum e)
+{
+#define CASE(name) case name: return #name
+ switch (e) {
+ CASE(GL_NO_ERROR);
+ CASE(GL_INVALID_ENUM);
+ CASE(GL_INVALID_VALUE);
+ CASE(GL_INVALID_OPERATION);
+#ifndef CON_GLES2
+ CASE(GL_STACK_OVERFLOW);
+ CASE(GL_STACK_UNDERFLOW);
+#endif
+ CASE(GL_OUT_OF_MEMORY);
+ default: return "<unknown>";
+ }
+#undef CASE
+}
+
+static void checkGlError(const char *what)
+{
+ GLenum e = glGetError();
+ if (e == GL_NO_ERROR) return;
+ fprintf(stderr, "GL error %d (%s): %s\n", e, glErrorToString(e), what);
+ exit(1);
+}
+