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