1 #include <cstdlib>
2 
3 #include "Common/GPU/OpenGL/GLCommon.h"
4 #include "Common/GPU/OpenGL/GLDebugLog.h"
5 
6 #include "Common/Log.h"
7 
8 // This we can expand as needed.
GLEnumToString(uint16_t value)9 std::string GLEnumToString(uint16_t value) {
10 	char str[64];
11 	switch (value) {
12 	case GL_UNSIGNED_SHORT_4_4_4_4: return "GL_UNSIGNED_SHORT_4_4_4_4";
13 	case GL_UNSIGNED_SHORT_5_5_5_1: return "GL_UNSIGNED_SHORT_5_5_5_1";
14 	case GL_UNSIGNED_SHORT_5_6_5: return "GL_UNSIGNED_SHORT_5_6_5";
15 	case GL_UNSIGNED_BYTE: return "GL_UNSIGNED_BYTE";
16 	case GL_RGBA: return "GL_RGBA";
17 	case GL_RGB: return "GL_RGB";
18 #if !defined(USING_GLES2)
19 	case GL_BGRA: return "GL_BGRA";
20 	case GL_UNSIGNED_SHORT_4_4_4_4_REV: return "GL_UNSIGNED_SHORT_4_4_4_4_REV";
21 	case GL_UNSIGNED_SHORT_5_6_5_REV: return "GL_UNSIGNED_SHORT_5_6_5_REV";
22 	case GL_UNSIGNED_SHORT_1_5_5_5_REV: return "GL_UNSIGNED_SHORT_1_5_5_5_REV";
23 	case GL_UNSIGNED_INT_8_8_8_8_REV: return "GL_UNSIGNED_INT_8_8_8_8_REV";
24 #endif
25 	case GL_OUT_OF_MEMORY: return "GL_OUT_OF_MEMORY";
26 	case GL_PACK_ALIGNMENT: return "GL_PACK_ALIGNMENT";
27 	case GL_INVALID_ENUM: return "GL_INVALID_ENUM";
28 	case GL_INVALID_VALUE: return "GL_INVALID_VALUE";
29 	case GL_INVALID_OPERATION: return "GL_INVALID_OPERATION";
30 	default: {
31 		snprintf(str, sizeof(str), "(unk:%04x)", value);
32 		return str;
33 	}
34 	}
35 }
36 
CheckGLError(const char * file,int line)37 bool CheckGLError(const char *file, int line) {
38 	GLenum err = glGetError();
39 	if (err != GL_NO_ERROR) {
40 		ERROR_LOG(G3D, "GL error %s on %s:%d", GLEnumToString(err).c_str(), file, line);
41 		return false;
42 	}
43 	return true;
44 }
45