]> git.sesse.net Git - casparcg/blob - common/gl/gl_check.cpp
#467 [framerate_producer] Fixed nb_frames() and frame_number() calculation
[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 std::string& 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                                 CASPAR_THROW_EXCEPTION(ogl_invalid_enum()
53                                         << msg_info("an unacceptable value has been specified for an enumerated argument")
54                                         << error_info("GL_INVALID_ENUM")
55                                         << line_info(line)
56                                         << source_info(file));
57
58                         case GL_INVALID_VALUE :
59                                 CASPAR_THROW_EXCEPTION(ogl_invalid_value()
60                                         << msg_info("a numeric argument is out of range")
61                                         << error_info("GL_INVALID_VALUE")
62                                         << line_info(line)
63                                         << source_info(file));
64
65                         case GL_INVALID_OPERATION :
66                                 CASPAR_THROW_EXCEPTION(ogl_invalid_operation()
67                                         << msg_info("the specified operation is not allowed in the current state")
68                                         << error_info("GL_INVALID_OPERATION")
69                                         << line_info(line)
70                                         << source_info(file));
71
72                         case GL_STACK_OVERFLOW :
73                                 CASPAR_THROW_EXCEPTION(ogl_stack_overflow()
74                                         << msg_info("this command would cause a stack overflow")
75                                         << error_info("GL_STACK_OVERFLOW")
76                                         << line_info(line)
77                                         << source_info(file));
78
79                         case GL_STACK_UNDERFLOW :
80                                 CASPAR_THROW_EXCEPTION(ogl_stack_underflow()
81                                         << msg_info("this command would cause a stack underflow")
82                                         << error_info("GL_STACK_UNDERFLOW")
83                                         << line_info(line)
84                                         << source_info(file));
85
86                         case GL_OUT_OF_MEMORY :
87                                 CASPAR_THROW_EXCEPTION(ogl_out_of_memory()
88                                         << msg_info("there is not enough memory left to execute the command")
89                                         << error_info("GL_OUT_OF_MEMORY")
90                                         << line_info(line)
91                                         << source_info(file));
92
93                         case GL_INVALID_FRAMEBUFFER_OPERATION_EXT :
94                                 CASPAR_THROW_EXCEPTION(ogl_stack_underflow()
95                                         << msg_info("the object bound to FRAMEBUFFER_BINDING_EXT is not \"framebuffer complete\"")
96                                         << error_info("GL_INVALID_FRAMEBUFFER_OPERATION_EXT")
97                                         << line_info(line)
98                                         << source_info(file));
99                 }
100         }
101 }
102
103 }}