-
-
Save jsimmons/477777 to your computer and use it in GitHub Desktop.
opengl error checking
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 "gl.h" | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdbool.h> | |
void sgl_check_gl_error(const char *func, const char *file, int line) | |
{ | |
GLenum error = glGetError(); | |
bool had_error = false; | |
while(error != GL_NO_ERROR) | |
{ | |
had_error = true; | |
char *err_msg = 0; | |
switch(error) | |
{ | |
case GL_INVALID_ENUM: | |
err_msg = "GL_INVALID_ENUM error in function %s of %s:%i\n"; | |
break; | |
case GL_INVALID_VALUE: | |
err_msg = "GL_INVALID_VALUE error in function %s of %s:%i\n"; | |
break; | |
case GL_INVALID_OPERATION: | |
err_msg = "GL_INVALID_OPERATION error in function %s of %s:%i\n"; | |
break; | |
case GL_OUT_OF_MEMORY: | |
err_msg = "GL_OUT_OF_MEMORY error in function %s of %s:%i\n"; | |
break; | |
case GL_STACK_OVERFLOW: | |
err_msg = "GL_STACK_OVERFLOW error in function %s of %s:%i\n"; | |
break; | |
case GL_STACK_UNDERFLOW: | |
err_msg = "GL_STACK_UNDERFLOW error in function %s of %s:%i\n"; | |
break; | |
case GL_TABLE_TOO_LARGE: | |
err_msg = "GL_TABLE_TOO_LARGE error in function %s of %s:%i\n"; | |
break; | |
default: | |
err_msg = "Unknown error in function %s of %s:%i\n"; | |
break; | |
} | |
fprintf(stderr, err_msg, func, file, line); | |
error = glGetError(); | |
} | |
if(had_error) | |
exit(1); | |
} |
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
#ifndef SGL_GL_H | |
#define SGL_GL_H | |
#include <GL/glew.h> | |
void sgl_check_gl_error(); | |
#ifdef SGL_DEBUG | |
#define SGL_CHECK_GL(Func) \ | |
Func; \ | |
sgl_check_gl_error(#Func, __FILE__, __LINE__); \ | |
#else | |
#define SGL_CHECK_GL | |
#endif | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment