]> git.sesse.net Git - casparcg/blob - common/gl/gl_check.cpp
512e5aefd5a03854d6f3cf741343f071cbd39e84
[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 <Glee.h>\r
32 \r
33 #include "../exception/exceptions.h"\r
34 #include "../log/log.h"\r
35 \r
36 #include <boost/lexical_cast.hpp>\r
37 \r
38 namespace caspar { namespace gl {       \r
39 \r
40 void SMFL_GLCheckError(const std::string& expr, const std::string& File, unsigned int Line)\r
41 {\r
42         // Get the last error\r
43         GLenum ErrorCode = glGetError();\r
44 \r
45         if (ErrorCode != GL_NO_ERROR)\r
46         {\r
47                 std::string Error = "unknown error";\r
48                 std::string Desc  = "no description";\r
49 \r
50                 // Decode the error code\r
51                 switch (ErrorCode)\r
52                 {\r
53                         case GL_INVALID_ENUM :\r
54                         {\r
55                                 Error = "GL_INVALID_ENUM";\r
56                                 Desc  = "an unacceptable value has been specified for an enumerated argument";\r
57                                 break;\r
58                         }\r
59 \r
60                         case GL_INVALID_VALUE :\r
61                         {\r
62                                 Error = "GL_INVALID_VALUE";\r
63                                 Desc  = "a numeric argument is out of range";\r
64                                 break;\r
65                         }\r
66 \r
67                         case GL_INVALID_OPERATION :\r
68                         {\r
69                                 Error = "GL_INVALID_OPERATION";\r
70                                 Desc  = "the specified operation is not allowed in the current state";\r
71                                 break;\r
72                         }\r
73 \r
74                         case GL_STACK_OVERFLOW :\r
75                         {\r
76                                 Error = "GL_STACK_OVERFLOW";\r
77                                 Desc  = "this command would cause a stack overflow";\r
78                                 break;\r
79                         }\r
80 \r
81                         case GL_STACK_UNDERFLOW :\r
82                         {\r
83                                 Error = "GL_STACK_UNDERFLOW";\r
84                                 Desc  = "this command would cause a stack underflow";\r
85                                 break;\r
86                         }\r
87 \r
88                         case GL_OUT_OF_MEMORY :\r
89                         {\r
90                                 Error = "GL_OUT_OF_MEMORY";\r
91                                 Desc  = "there is not enough memory left to execute the command";\r
92                                 break;\r
93                         }\r
94 \r
95                         case GL_INVALID_FRAMEBUFFER_OPERATION_EXT :\r
96                         {\r
97                                 Error = "GL_INVALID_FRAMEBUFFER_OPERATION_EXT";\r
98                                 Desc  = "the object bound to FRAMEBUFFER_BINDING_EXT is not \"framebuffer complete\"";\r
99                                 break;\r
100                         }\r
101                 }\r
102 \r
103                 // Log the error\r
104                 CASPAR_LOG(error) << "An internal OpenGL call failed in "\r
105                                   << File.substr(File.find_last_of("\\/") + 1).c_str() << " (" << Line << ") : "\r
106                                   << Error.c_str() << ", " << Desc.c_str()\r
107                                   << ", " << expr.c_str()\r
108                                   << std::endl;\r
109         }\r
110 }\r
111 \r
112 #ifdef _DEBUG\r
113         \r
114 #define CASPAR_GL_EXPR_STR(expr) #expr\r
115 \r
116 #define GL(expr) \\r
117         do \\r
118         { \\r
119                 (expr);  \\r
120                 caspar::gl::SMFL_GLCheckError(CASPAR_GL_EXPR_STR(expr), __FILE__, __LINE__);\\r
121         }while(0);\r
122 #else\r
123 #define GL(expr) expr\r
124 #endif\r
125 \r
126 }}