1
1
#include " GLCheck.h"
2
2
#include " glad/gl.h"
3
3
4
- #include < cstdio>
5
- #include < cstdlib>
4
+ #include < string>
5
+ #include < sstream>
6
+ #include " ConsoleMan.h"
6
7
7
8
void CheckOpenGLError (const char * stmt, const char * fname, int line) {
8
- GLenum err = glGetError ();
9
- if (err != GL_NO_ERROR) {
10
- printf (" OpenGL error %08x, at %s:%i - for %s\n " , err, fname, line, stmt);
11
- abort ();
9
+ GLenum errorCode = glGetError ();
10
+
11
+ if (errorCode != GL_NO_ERROR) {
12
+ std::string fileString = fname;
13
+ std::string error = " Unknown error" ;
14
+ std::string description = " No description" ;
15
+
16
+ // Decode the error code
17
+ switch (errorCode) {
18
+ case GL_INVALID_ENUM: {
19
+ error = " GL_INVALID_ENUM" ;
20
+ description = " An unacceptable value has been specified for an enumerated argument." ;
21
+ break ;
22
+ }
23
+
24
+ case GL_INVALID_VALUE: {
25
+ error = " GL_INVALID_VALUE" ;
26
+ description = " A numeric argument is out of range." ;
27
+ break ;
28
+ }
29
+
30
+ case GL_INVALID_OPERATION: {
31
+ error = " GL_INVALID_OPERATION" ;
32
+ description = " The specified operation is not allowed in the current state." ;
33
+ break ;
34
+ }
35
+
36
+ case GL_STACK_OVERFLOW: {
37
+ error = " GL_STACK_OVERFLOW" ;
38
+ description = " This command would cause a stack overflow." ;
39
+ break ;
40
+ }
41
+
42
+ case GL_STACK_UNDERFLOW: {
43
+ error = " GL_STACK_UNDERFLOW" ;
44
+ description = " This command would cause a stack underflow." ;
45
+ break ;
46
+ }
47
+
48
+ case GL_OUT_OF_MEMORY: {
49
+ error = " GL_OUT_OF_MEMORY" ;
50
+ description = " There is not enough memory left to execute the command." ;
51
+ break ;
52
+ }
53
+
54
+ case GL_INVALID_FRAMEBUFFER_OPERATION: {
55
+ error = " GL_INVALID_FRAMEBUFFER_OPERATION" ;
56
+ description = " The object bound to FRAMEBUFFER_BINDING is not \" framebuffer complete\" ." ;
57
+ break ;
58
+ }
59
+
60
+ default : {
61
+ error = " Unknown Error: " + std::to_string (errorCode);
62
+ description = " " ;
63
+ }
64
+ }
65
+
66
+ // Log the error
67
+ std::stringstream errorMessage;
68
+ errorMessage << " ERROR: An internal OpenGL call failed in "
69
+ << fileString.substr (fileString.find_last_of (" \\ /" ) + 1 ) << " (" << line << " )."
70
+ << " \n Expression:\n " << stmt
71
+ << " \n Error description:\n " << error << " \n " << description << " \n " ;
72
+ g_ConsoleMan.PrintString (errorMessage.str ());
12
73
}
13
- }
74
+ }
0 commit comments