From 2ca04fbe7985ee944f3fa6302886a252a51add0c Mon Sep 17 00:00:00 2001 From: Wolfgang Draxinger Date: Sun, 24 Apr 2016 23:52:45 +0200 Subject: initial commit --- debuggl/debuggl.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ debuggl/debuggl.h | 29 ++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 debuggl/debuggl.c create mode 100644 debuggl/debuggl.h (limited to 'debuggl') 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 +#include + +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*/ -- cgit v1.2.3