summaryrefslogtreecommitdiff
path: root/Runtime/GfxDevice/opengl/GLAssert.cpp
blob: 4f3501d92a81d8525eb3b2c6179b7a6f67530b75 (plain)
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
#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;
		}
	}
}