Skip to content

Commit 503cb0b

Browse files
committed
update GLCheck to be more informative and enable in release
Also disable GLCheck unconditionally aborting, now it just prints the error to console.
1 parent de790fe commit 503cb0b

File tree

2 files changed

+68
-11
lines changed

2 files changed

+68
-11
lines changed

Source/System/GLCheck.cpp

Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,74 @@
11
#include "GLCheck.h"
22
#include "glad/gl.h"
33

4-
#include <cstdio>
5-
#include <cstdlib>
4+
#include <string>
5+
#include <sstream>
6+
#include "ConsoleMan.h"
67

78
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+
<< "\nExpression:\n " << stmt
71+
<< "\nError description:\n " << error << "\n " << description << "\n";
72+
g_ConsoleMan.PrintString(errorMessage.str());
1273
}
13-
}
74+
}

Source/System/GLCheck.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@
55
void CheckOpenGLError(const char* stmt, const char* fname, int line);
66

77
/// Debug macro to be used for all GL calls.
8-
#ifdef DEBUG
98
#define GL_CHECK(stmt) \
109
do { \
1110
stmt; \
1211
CheckOpenGLError(#stmt, __FILE__, __LINE__); \
1312
} while (0)
14-
#else
15-
#define GL_CHECK(stmt) stmt
16-
#endif

0 commit comments

Comments
 (0)