-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckError.h
63 lines (49 loc) · 1.64 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
54
55
56
57
58
59
60
61
62
63
//////////////////////////////////////////////////////////////////////////////
//
// --- CheckError.h ---
//
//////////////////////////////////////////////////////////////////////////////
#ifndef __CHECKERROR_H__
#define __CHECKERROR_H__
#include <stdio.h>
#ifdef __APPLE__
# include <OpenGL/gl3.h>
#else
# include <GL/gl.h>
#endif
//----------------------------------------------------------------------------
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 );
#ifndef __gl3_h_ // In OpenGL 3.2 core profile, GL_STACK_OVERFLOW and GL_STACK_UNDERFLOW are
// Not defined and thus the following 2 cases must be bypassed.
// So we check the two cases below only when it's NOT OpenGL 3.2 core profile,
// i.e., only when "__gl3_h_" is not defined.
Case( GL_STACK_OVERFLOW );
Case( GL_STACK_UNDERFLOW );
#endif
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__