Skip to content

Instantly share code, notes, and snippets.

@hiddenmemory
Created October 14, 2013 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiddenmemory/6973311 to your computer and use it in GitHub Desktop.
Save hiddenmemory/6973311 to your computer and use it in GitHub Desktop.
#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

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