Skip to content

Instantly share code, notes, and snippets.

Embed
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! */
NSDictionary* glErrorNames = @{ @(GL_INVALID_ENUM) : @"GL_INVALID_ENUM", @(GL_INVALID_VALUE) : @"GL_INVALID_VALUE", @(GL_INVALID_OPERATION) : @"GL_INVALID_OPERATION", @(GL_STACK_OVERFLOW) : @"GL_STACK_OVERFLOW", @(GL_STACK_UNDERFLOW) : @"GL_STACK_UNDERFLOW", @(GL_OUT_OF_MEMORY) : @"GL_OUT_OF_MEMORY" };
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__)
@hiddenmemory
Copy link
Author

hiddenmemory commented Oct 14, 2013

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