GraphicsContext.hpp
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//
24
25#ifndef SFML_GRAPHICSCONTEXT_HPP
26#define SFML_GRAPHICSCONTEXT_HPP
27
29// Headers
31#include <SFML/Config.hpp>
32#include <SFML/System/NonCopyable.hpp>
33#include <GL/glew.h>
34#include <iostream>
35#include <string>
36
37
38namespace sf
39{
40class Context;
41
42namespace priv
43{
52class GraphicsContext : NonCopyable
53{
54public :
55
61 GraphicsContext();
62
68 ~GraphicsContext();
69
70private :
71
73 // Member data
75 bool myActivated;
76};
77
78} // namespace priv
79
80
85#ifdef SFML_DEBUG
86
87 // In debug mode, perform a test on every OpenGL call
88 #define GLCheck(Func) ((Func), GLCheckError(__FILE__, __LINE__))
89
90#else
91
92 // Else, we don't add any overhead
93 #define GLCheck(Func) (Func)
94
95#endif
96
97
102inline void GLCheckError(const std::string& File, unsigned int Line)
103{
104 // Get the last error
105 GLenum ErrorCode = glGetError();
106
107 if (ErrorCode != GL_NO_ERROR)
108 {
109 std::string Error = "unknown error";
110 std::string Desc = "no description";
111
112 // Decode the error code
113 switch (ErrorCode)
114 {
115 case GL_INVALID_ENUM :
116 {
117 Error = "GL_INVALID_ENUM";
118 Desc = "an unacceptable value has been specified for an enumerated argument";
119 break;
120 }
121
122 case GL_INVALID_VALUE :
123 {
124 Error = "GL_INVALID_VALUE";
125 Desc = "a numeric argument is out of range";
126 break;
127 }
128
129 case GL_INVALID_OPERATION :
130 {
131 Error = "GL_INVALID_OPERATION";
132 Desc = "the specified operation is not allowed in the current state";
133 break;
134 }
135
136 case GL_STACK_OVERFLOW :
137 {
138 Error = "GL_STACK_OVERFLOW";
139 Desc = "this command would cause a stack overflow";
140 break;
141 }
142
143 case GL_STACK_UNDERFLOW :
144 {
145 Error = "GL_STACK_UNDERFLOW";
146 Desc = "this command would cause a stack underflow";
147 break;
148 }
149
150 case GL_OUT_OF_MEMORY :
151 {
152 Error = "GL_OUT_OF_MEMORY";
153 Desc = "there is not enough memory left to execute the command";
154 break;
155 }
156
157 case GL_INVALID_FRAMEBUFFER_OPERATION_EXT :
158 {
159 Error = "GL_INVALID_FRAMEBUFFER_OPERATION_EXT";
160 Desc = "the object bound to FRAMEBUFFER_BINDING_EXT is not \"framebuffer complete\"";
161 break;
162 }
163 }
164
165 // Log the error
166 std::cerr << "An internal OpenGL call failed in "
167 << File.substr(File.find_last_of("\\/") + 1) << " (" << Line << ") : "
168 << Error << ", " << Desc
169 << std::endl;
170 }
171}
172
173} // namespace sf
174
175
176#endif // SFML_GRAPHICSCONTEXT_HPP
Class wrapping an OpenGL context.
Definition Context.hpp:50