add checkGLError

This commit is contained in:
Josh Holtrop 2011-04-15 09:54:31 -04:00
parent 1fe30cc71f
commit db1b050d59
2 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,32 @@
#include <stdio.h>
#include "checkGLError.h"
#define checkGLErrorCase(e) \
case (e): sprintf(msg, #e); break
GLenum _checkGLError(const char *fname, int lineno)
{
char msg[40];
GLenum e;
sprintf(msg, "Unknown");
e = glGetError();
switch (e)
{
checkGLErrorCase(GL_NO_ERROR);
checkGLErrorCase(GL_INVALID_ENUM);
checkGLErrorCase(GL_INVALID_VALUE);
checkGLErrorCase(GL_INVALID_OPERATION);
checkGLErrorCase(GL_STACK_OVERFLOW);
checkGLErrorCase(GL_STACK_UNDERFLOW);
checkGLErrorCase(GL_OUT_OF_MEMORY);
checkGLErrorCase(GL_TABLE_TOO_LARGE);
}
if (e != GL_NO_ERROR)
fprintf(stderr, "GL error %s at %s:%d\n", msg, fname, lineno);
return e;
}

View File

@ -0,0 +1,12 @@
#ifndef CHECKGLERROR_H
#define CHECKGLERROR_H
#include <GL/gl.h>
#define checkGLError() _checkGLError(__FILE__, __LINE__)
#define GL_CHECK(x) ({x; checkGLError();})
GLenum _checkGLError(const char *fname, int lineno);
#endif