summaryrefslogtreecommitdiff
path: root/Runtime/GfxDevice/opengl/GLAssert.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Runtime/GfxDevice/opengl/GLAssert.cpp')
-rw-r--r--Runtime/GfxDevice/opengl/GLAssert.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/Runtime/GfxDevice/opengl/GLAssert.cpp b/Runtime/GfxDevice/opengl/GLAssert.cpp
new file mode 100644
index 0000000..4f3501d
--- /dev/null
+++ b/Runtime/GfxDevice/opengl/GLAssert.cpp
@@ -0,0 +1,42 @@
+#include "UnityPrefix.h"
+#include "GLAssert.h"
+#include "UnityGL.h"
+
+#if UNITY_WIN || UNITY_LINUX
+#include <GL/glu.h>
+#else
+#include <OpenGL/glu.h>
+#endif
+
+using namespace std;
+
+void CheckOpenGLError (const char *prefix, const char* file, long line)
+{
+ const int kMaxErrors = 10;
+ int counter = 0;
+
+ GLenum glerr;
+ while( (glerr = glGetError ()) != GL_NO_ERROR )
+ {
+ if (prefix)
+ {
+ string errorString = prefix;
+ errorString += ": ";
+ const char* gluMsg = reinterpret_cast<const char*>(gluErrorString (glerr));
+ errorString += gluMsg ? gluMsg : Format("unknown error 0x%x", glerr);
+ DebugStringToFile (errorString.c_str(), 0, file, line, kAssert);
+ }
+ else
+ {
+ const char* gluMsg = reinterpret_cast<const char*>(gluErrorString (glerr));
+ string errorString = gluMsg ? gluMsg : Format("unknown error 0x%x", glerr);
+ DebugStringToFile (errorString.c_str(), 0, file, line, kAssert);
+ }
+ ++counter;
+ if( counter > kMaxErrors )
+ {
+ printf_console( "GL: error count exceeds %i, stop reporting errors\n", kMaxErrors );
+ return;
+ }
+ }
+}