Skip to content

Instantly share code, notes, and snippets.

Created October 14, 2013 09:43
What would you like to do?
#include <stdio.h>
#include "GLK2GetError.h"
#include <GLKit/GLKit.h>
void _gl2CheckAndClearAllErrorsImpl(char *source_function, char *source_file, int source_line)
GLenum glErrorLast;
while( (glErrorLast = glGetError()) != GL_NO_ERROR ) // GL spec says you must do this in a WHILE loop
/** OpenGL spec defines only 6 legal errors, that HAVE to be re-used by all gl method calls. OH THE PAIN! */
NSLog(@"GL Error: %@ in %s @ %s:%d", [glErrorNames objectForKey:@(glErrorLast)], source_function, source_file, source_line );
NSCAssert( FALSE, @"OpenGL Error; you need to investigate this!" ); // can't use NSAssert, because we're inside a C function
#define gl2CheckAndClearAllErrors() _gl2CheckAndClearAllErrorsImpl(__PRETTY_FUNCTION__,__FILE__,__LINE__)
Copy link

The idea is that you use the macro gl2CheckAndClearAllErrors() rather than the direct method call.

Allows you to pass through the function, file and line from the call site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment