-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckError.h
53 lines (40 loc) · 1.26 KB
/
CheckError.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//////////////////////////////////////////////////////////////////////////////
//
// --- CheckError.h ---
//
//////////////////////////////////////////////////////////////////////////////
#ifndef __CHECKERROR_H__
#define __CHECKERROR_H__
#include <stdio.h>
#include <GL/gl.h>
//----------------------------------------------------------------------------
static const char*
ErrorString( GLenum error )
{
const char* msg;
switch( error ) {
#define Case( Token ) case Token: msg = #Token; break;
Case( GL_NO_ERROR );
Case( GL_INVALID_VALUE );
Case( GL_INVALID_ENUM );
Case( GL_INVALID_OPERATION );
Case( GL_STACK_OVERFLOW );
Case( GL_STACK_UNDERFLOW );
Case( GL_OUT_OF_MEMORY );
#undef Case
}
return msg;
}
//----------------------------------------------------------------------------
static void
_CheckError( const char* file, int line )
{
GLenum error = glGetError();
do {
fprintf( stderr, "[%s:%d] %s\n", file, line, ErrorString(error) );
} while ((error = glGetError()) != GL_NO_ERROR );
}
//----------------------------------------------------------------------------
#define CheckError() _CheckError( __FILE__, __LINE__ )
//----------------------------------------------------------------------------
#endif // !__CHECKERROR_H__