diff options
author | Wolfgang Draxinger <Wolfgang.Draxinger@draxit.de> | 2016-04-24 23:52:45 +0200 |
---|---|---|
committer | Wolfgang Draxinger <Wolfgang.Draxinger@draxit.de> | 2016-04-24 23:52:45 +0200 |
commit | 2ca04fbe7985ee944f3fa6302886a252a51add0c (patch) | |
tree | b373879928a1060e564d29d44f6e20b620b272e9 /debuggl | |
download | pointoverdrawbench-2ca04fbe7985ee944f3fa6302886a252a51add0c.tar.gz pointoverdrawbench-2ca04fbe7985ee944f3fa6302886a252a51add0c.tar.bz2 |
initial commit
Diffstat (limited to 'debuggl')
-rw-r--r-- | debuggl/debuggl.c | 67 | ||||
-rw-r--r-- | debuggl/debuggl.h | 29 |
2 files changed, 96 insertions, 0 deletions
diff --git a/debuggl/debuggl.c b/debuggl/debuggl.c new file mode 100644 index 0000000..4775ade --- /dev/null +++ b/debuggl/debuggl.c @@ -0,0 +1,67 @@ +#include "debuggl.h" +#include <GL/gl.h> +#include <stdio.h> + +int debuggl_check_call( + char const * const file, + char const * const func, + unsigned int const line, + char const * const what) +{ + int errors = 0; + GLenum err; + while( (err = glGetError()) != GL_NO_ERROR) { + ++errors; + char const * errstr = NULL; + switch( err ) { + case GL_INVALID_ENUM: errstr = "invalid enum"; break; + case GL_INVALID_VALUE: errstr = "invalid value"; break; + case GL_INVALID_OPERATION: errstr = "invalid operation"; break; + case GL_STACK_OVERFLOW: errstr = "invalid overflow"; break; + case GL_STACK_UNDERFLOW: errstr = "invalid underflow"; break; + case GL_OUT_OF_MEMORY: errstr = "invalid memory"; break; + } + fprintf(stderr, + "%s(%d)/%s: %s => OpenGL Error: %s\n", + file, (int)line, func, what, + errstr ); + } + return errors; +} + +int debuggl_trace_call( + char const * const file, + char const * const func, + unsigned int const line, + char const * const what) +{ + int errors = 0; + GLenum err; + do { + err = glGetError(); + char const * errstr = NULL; + switch( err ) { + case GL_INVALID_ENUM: errstr = "invalid enum"; break; + case GL_INVALID_VALUE: errstr = "invalid value"; break; + case GL_INVALID_OPERATION: errstr = "invalid operation"; break; + case GL_STACK_OVERFLOW: errstr = "invalid overflow"; break; + case GL_STACK_UNDERFLOW: errstr = "invalid underflow"; break; + case GL_OUT_OF_MEMORY: errstr = "invalid memory"; break; + } + + if( errstr ) { + ++errors; + fprintf(stderr, + "%s(%d)/%s: %s => OpenGL Error: %s\n", + file, (int)line, func, what, + errstr ); + } + else { + fprintf(stderr, + "%s(%d): %s OK\n", + func, (int)line, what); + } + } while( GL_NO_ERROR != err ); + return errors; +} + diff --git a/debuggl/debuggl.h b/debuggl/debuggl.h new file mode 100644 index 0000000..4d8dff9 --- /dev/null +++ b/debuggl/debuggl.h @@ -0,0 +1,29 @@ +#pragma once +#ifndef DEBUGGL_H +#define DEBUGGL_H + +/* execute a OpenGL but check for errors only if compiled for debugging */ +#ifndef NDEBUG +#define debuggl_trace(glcmd) \ + ({ glcmd; debuggl_trace_call(__FILE__, __func__, __LINE__, #glcmd); }) +#else +#define debuggl_trace(glcmd) glcmd +#endif + +/* check for OpenGL errors */ +#define debuggl_check(glcmd) \ + ({ glcmd; debuggl_check_call(__FILE__, __func__, __LINE__, #glcmd); }) + +int debuggl_check_call( + char const * const file, + char const * const func, + unsigned int const line, + char const * const what); + +int debuggl_trace_call( + char const * const file, + char const * const func, + unsigned int const line, + char const * const what); + +#endif/*DEBUGGL_H*/ |