23 #ifndef __OPENGL_UTILITY_H 24 #define __OPENGL_UTILITY_H 37 #define LOG_GL "[OpenGL] " 43 #define GL(x) { x; glCheckError( #x, __FILE__, __LINE__ ); } 49 #define GL_VERIFY(x) { x; if(glCheckError( #x, __FILE__, __LINE__ )) return false; } 55 #define GL_VERIFYN(x) { x; if(glCheckError( #x, __FILE__, __LINE__ )) return NULL; } 61 #define GL_CHECK(msg) { glCheckError(msg, __FILE__, __LINE__); } 67 inline bool glCheckError(
const char* msg,
const char* file,
int line)
69 GLenum err = glGetError();
71 if( err == GL_NO_ERROR )
78 case GL_INVALID_ENUM: e =
"invalid enum";
break;
79 case GL_INVALID_VALUE: e =
"invalid value";
break;
80 case GL_INVALID_OPERATION: e =
"invalid operation";
break;
81 case GL_STACK_OVERFLOW: e =
"stack overflow";
break;
82 case GL_STACK_UNDERFLOW: e =
"stack underflow";
break;
83 case GL_OUT_OF_MEMORY: e =
"out of memory";
break;
84 #ifdef GL_TABLE_TOO_LARGE_EXT 85 case GL_TABLE_TOO_LARGE_EXT: e =
"table too large";
break;
87 #ifdef GL_TEXTURE_TOO_LARGE_EXT 88 case GL_TEXTURE_TOO_LARGE_EXT: e =
"texture too large";
break;
90 default: e =
"unknown error";
93 printf(
LOG_GL "Error %i - '%s'\n", (uint)err, e);
94 printf(
LOG_GL " %s::%i\n", file, line );
95 printf(
LOG_GL " %s\n", msg );
107 GLenum err = glGetError();
109 if( err == GL_NO_ERROR )
112 const char* e = NULL;
116 case GL_INVALID_ENUM: e =
"invalid enum";
break;
117 case GL_INVALID_VALUE: e =
"invalid value";
break;
118 case GL_INVALID_OPERATION: e =
"invalid operation";
break;
119 case GL_STACK_OVERFLOW: e =
"stack overflow";
break;
120 case GL_STACK_UNDERFLOW: e =
"stack underflow";
break;
121 case GL_OUT_OF_MEMORY: e =
"out of memory";
break;
122 #ifdef GL_TABLE_TOO_LARGE_EXT 123 case GL_TABLE_TOO_LARGE_EXT: e =
"table too large";
break;
125 #ifdef GL_TEXTURE_TOO_LARGE_EXT 126 case GL_TEXTURE_TOO_LARGE_EXT: e =
"texture too large";
break;
128 default: e =
"unknown error";
131 printf(
LOG_GL "%s (error %i - %s)\n", msg, (uint)err, e);
137 #define GL_GPU_MEM_INFO_TOTAL_AVAILABLE_MEM_NVX 0x9048 138 #define GL_GPU_MEM_INFO_CURRENT_AVAILABLE_MEM_NVX 0x9049 147 GLint total_mem_kb = 0;
148 GLint cur_avail_mem_kb = 0;
153 printf(
LOG_GL "GPU memory free %i / %i kb\n", cur_avail_mem_kb, total_mem_kb);
#define GL_GPU_MEM_INFO_TOTAL_AVAILABLE_MEM_NVX
Definition: glUtility.h:137
#define LOG_GL
OpenGL logging prefix.
Definition: glUtility.h:37
bool glCheckError(const char *msg, const char *file, int line)
OpenGL error-checking messsage function.
Definition: glUtility.h:67
void glPrintFreeMem()
Print the amount of free GPU memory.
Definition: glUtility.h:145
#define GL_GPU_MEM_INFO_CURRENT_AVAILABLE_MEM_NVX
Definition: glUtility.h:138