]> git.sesse.net Git - casparcg/blob - common/gl/gl_check.cpp
47e111c4842326bf87bba6ec44e59ad3401b9ca8
[casparcg] / common / gl / gl_check.cpp
1 ///////////////////////////\r
2 //\r
3 // SFML - Simple and Fast Multimedia Library\r
4 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
5 //\r
6 // This software is provided 'as-is', without any express or implied warranty.\r
7 // In no event will the authors be held liable for any damages arising from the use of this software.\r
8 //\r
9 // Permission is granted to anyone to use this software for any purpose,\r
10 // including commercial applications, and to alter it and redistribute it freely,\r
11 // subject to the following restrictions:\r
12 //\r
13 // 1. The origin of this software must not be misrepresented;\r
14 //    you must not claim that you wrote the original software.\r
15 //    If you use this software in a product, an acknowledgment\r
16 //    in the product documentation would be appreciated but is not required.\r
17 //\r
18 // 2. Altered source versions must be plainly marked as such,\r
19 //    and must not be misrepresented as being the original software.\r
20 //\r
21 // 3. This notice may not be removed or altered from any source distribution.\r
22 //\r
23 ///////////////////////////\r
24 \r
25 #pragma once\r
26 \r
27 #include "../stdafx.h"\r
28 \r
29 #include "gl_check.h"\r
30 \r
31 #include "../log.h"\r
32 \r
33 #include <GL/glew.h>\r
34 \r
35 namespace caspar { namespace gl {       \r
36 \r
37 void SMFL_GLCheckError(const std::string&, const std::string& file, unsigned int line)\r
38 {\r
39         // Get the last error\r
40         GLenum LastErrorCode = GL_NO_ERROR;\r
41 \r
42         for(GLenum ErrorCode = glGetError(); ErrorCode != GL_NO_ERROR; ErrorCode = glGetError())\r
43         {\r
44                 CASPAR_LOG(error) << "OpenGL Error: " << ErrorCode << L" " << glewGetErrorString(ErrorCode);\r
45                 LastErrorCode = ErrorCode;\r
46         }\r
47 \r
48         if (LastErrorCode != GL_NO_ERROR)\r
49         {\r
50                 // Decode the error code\r
51                 switch (LastErrorCode)\r
52                 {\r
53                         case GL_INVALID_ENUM :\r
54                                 CASPAR_THROW_EXCEPTION(ogl_invalid_enum()\r
55                                         << msg_info("an unacceptable value has been specified for an enumerated argument")\r
56                                         << error_info("GL_INVALID_ENUM")\r
57                                         << line_info(line)\r
58                                         << source_info(file));\r
59 \r
60                         case GL_INVALID_VALUE :\r
61                                 CASPAR_THROW_EXCEPTION(ogl_invalid_value()\r
62                                         << msg_info("a numeric argument is out of range")\r
63                                         << error_info("GL_INVALID_VALUE")\r
64                                         << line_info(line)\r
65                                         << source_info(file));\r
66 \r
67                         case GL_INVALID_OPERATION :\r
68                                 CASPAR_THROW_EXCEPTION(ogl_invalid_operation()\r
69                                         << msg_info("the specified operation is not allowed in the current state")\r
70                                         << error_info("GL_INVALID_OPERATION")\r
71                                         << line_info(line)\r
72                                         << source_info(file));\r
73 \r
74                         case GL_STACK_OVERFLOW :\r
75                                 CASPAR_THROW_EXCEPTION(ogl_stack_overflow()\r
76                                         << msg_info("this command would cause a stack overflow")\r
77                                         << error_info("GL_STACK_OVERFLOW")\r
78                                         << line_info(line)\r
79                                         << source_info(file));\r
80 \r
81                         case GL_STACK_UNDERFLOW :\r
82                                 CASPAR_THROW_EXCEPTION(ogl_stack_underflow()\r
83                                         << msg_info("this command would cause a stack underflow")\r
84                                         << error_info("GL_STACK_UNDERFLOW")\r
85                                         << line_info(line)\r
86                                         << source_info(file));\r
87 \r
88                         case GL_OUT_OF_MEMORY :\r
89                                 CASPAR_THROW_EXCEPTION(ogl_out_of_memory()\r
90                                         << msg_info("there is not enough memory left to execute the command")\r
91                                         << error_info("GL_OUT_OF_MEMORY")\r
92                                         << line_info(line)\r
93                                         << source_info(file));\r
94 \r
95                         case GL_INVALID_FRAMEBUFFER_OPERATION_EXT :\r
96                                 CASPAR_THROW_EXCEPTION(ogl_stack_underflow()\r
97                                         << msg_info("the object bound to FRAMEBUFFER_BINDING_EXT is not \"framebuffer complete\"")\r
98                                         << error_info("GL_INVALID_FRAMEBUFFER_OPERATION_EXT")\r
99                                         << line_info(line)\r
100                                         << source_info(file));\r
101                 }\r
102         }\r
103 }\r
104 \r
105 }}