Slight tweak to the the error function from http://t-machine.org/index.php/2013/10/12/opengl-es-2-for-ios-gldebugging-and-cleaning-up-our-vbos-vaos-and-draw-calls/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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__) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.