/
gl.h
47 lines (38 loc) · 1.04 KB
/
gl.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
#pragma once
#ifdef _DEBUG
#include "igl.h"
#include "string/convert.h"
#endif
namespace debug
{
/// \brief Asserts that there no OpenGL errors have occurred since the last call to glGetError.
inline void assertNoGlErrors()
{
#ifdef _DEBUG
// Return if no error
GLenum error = glGetError();
if (error == GL_NO_ERROR)
{
return;
}
// Build list of all GL errors
std::string allErrString = "GL errors encountered: ";
int maxErrors = 100;
for (; error != GL_NO_ERROR; error = glGetError())
{
const char* strErr = reinterpret_cast<const char*>(
gluErrorString(error)
);
allErrString += string::to_string(error);
allErrString += " (" + std::string(strErr) + ") ";
if (--maxErrors <= 0)
{
allErrString += "---> Maximum number of GL errors reached, maybe there is a problem with the GL context?";
break;
}
}
// Show the error message and terminate
GlobalErrorHandler()("OpenGL Error", allErrString);
#endif
}
}