]> git.sesse.net Git - casparcg/blob - common/gl/gl_check.cpp
2.0. mixer: Propagate exception into video_channel to allow recovery.
[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 <GL/glew.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                 // Decode the error code\r
48                 switch (ErrorCode)\r
49                 {\r
50                         case GL_INVALID_ENUM :\r
51                                 BOOST_THROW_EXCEPTION(ogl_invalid_enum()\r
52                                         << msg_info("an unacceptable value has been specified for an enumerated argument")\r
53                                         << errorstr("GL_INVALID_ENUM")\r
54                                         << line_info(line)\r
55                                         << source_info(file));\r
56 \r
57                         case GL_INVALID_VALUE :\r
58                                 BOOST_THROW_EXCEPTION(ogl_invalid_value()\r
59                                         << msg_info("a numeric argument is out of range")\r
60                                         << errorstr("GL_INVALID_VALUE")\r
61                                         << line_info(line)\r
62                                         << source_info(file));\r
63 \r
64                         case GL_INVALID_OPERATION :\r
65                                 BOOST_THROW_EXCEPTION(ogl_invalid_operation()\r
66                                         << msg_info("the specified operation is not allowed in the current state")\r
67                                         << errorstr("GL_INVALID_OPERATION")\r
68                                         << line_info(line)\r
69                                         << source_info(file));\r
70 \r
71                         case GL_STACK_OVERFLOW :\r
72                                 BOOST_THROW_EXCEPTION(ogl_stack_overflow()\r
73                                         << msg_info("this command would cause a stack overflow")\r
74                                         << errorstr("GL_STACK_OVERFLOW")\r
75                                         << line_info(line)\r
76                                         << source_info(file));\r
77 \r
78                         case GL_STACK_UNDERFLOW :\r
79                                 BOOST_THROW_EXCEPTION(ogl_stack_underflow()\r
80                                         << msg_info("this command would cause a stack underflow")\r
81                                         << errorstr("GL_STACK_UNDERFLOW")\r
82                                         << line_info(line)\r
83                                         << source_info(file));\r
84 \r
85                         case GL_OUT_OF_MEMORY :\r
86                                 BOOST_THROW_EXCEPTION(ogl_out_of_memory()\r
87                                         << msg_info("there is not enough memory left to execute the command")\r
88                                         << errorstr("GL_OUT_OF_MEMORY")\r
89                                         << line_info(line)\r
90                                         << source_info(file));\r
91 \r
92                         case GL_INVALID_FRAMEBUFFER_OPERATION_EXT :\r
93                                 BOOST_THROW_EXCEPTION(ogl_stack_underflow()\r
94                                         << msg_info("the object bound to FRAMEBUFFER_BINDING_EXT is not \"framebuffer complete\"")\r
95                                         << errorstr("GL_INVALID_FRAMEBUFFER_OPERATION_EXT")\r
96                                         << line_info(line)\r
97                                         << source_info(file));\r
98                 }\r
99         }\r
100 }\r
101 \r
102 }}