GraphicsContext.hpp
00001 00002 // 00003 // SFML - Simple and Fast Multimedia Library 00004 // Copyright (C) 2007-2009 Laurent Gomila ([email protected]) 00005 // 00006 // This software is provided 'as-is', without any express or implied warranty. 00007 // In no event will the authors be held liable for any damages arising from the use of this software. 00008 // 00009 // Permission is granted to anyone to use this software for any purpose, 00010 // including commercial applications, and to alter it and redistribute it freely, 00011 // subject to the following restrictions: 00012 // 00013 // 1. The origin of this software must not be misrepresented; 00014 // you must not claim that you wrote the original software. 00015 // If you use this software in a product, an acknowledgment 00016 // in the product documentation would be appreciated but is not required. 00017 // 00018 // 2. Altered source versions must be plainly marked as such, 00019 // and must not be misrepresented as being the original software. 00020 // 00021 // 3. This notice may not be removed or altered from any source distribution. 00022 // 00024 00025 #ifndef SFML_GRAPHICSCONTEXT_HPP 00026 #define SFML_GRAPHICSCONTEXT_HPP 00027 00029 // Headers 00031 #include <SFML/Config.hpp> 00032 #include <SFML/System/NonCopyable.hpp> 00033 #include <SFML/Graphics/GLEW/glew.h> 00034 #include <iostream> 00035 #include <string> 00036 00037 00038 namespace sf 00039 { 00040 class Context; 00041 00042 namespace priv 00043 { 00052 class GraphicsContext : NonCopyable 00053 { 00054 public : 00055 00061 GraphicsContext(); 00062 00068 ~GraphicsContext(); 00069 00070 private : 00071 00073 // Member data 00075 bool myActivated; 00076 }; 00077 00078 } // namespace priv 00079 00080 00085 #ifdef SFML_DEBUG 00086 00087 // In debug mode, perform a test on every OpenGL call 00088 #define GLCheck(Func) ((Func), GLCheckError(__FILE__, __LINE__)) 00089 00090 #else 00091 00092 // Else, we don't add any overhead 00093 #define GLCheck(Func) (Func) 00094 00095 #endif 00096 00097 00102 inline void GLCheckError(const std::string& File, unsigned int Line) 00103 { 00104 // Get the last error 00105 GLenum ErrorCode = glGetError(); 00106 00107 if (ErrorCode != GL_NO_ERROR) 00108 { 00109 std::string Error = "unknown error"; 00110 std::string Desc = "no description"; 00111 00112 // Decode the error code 00113 switch (ErrorCode) 00114 { 00115 case GL_INVALID_ENUM : 00116 { 00117 Error = "GL_INVALID_ENUM"; 00118 Desc = "an unacceptable value has been specified for an enumerated argument"; 00119 break; 00120 } 00121 00122 case GL_INVALID_VALUE : 00123 { 00124 Error = "GL_INVALID_VALUE"; 00125 Desc = "a numeric argument is out of range"; 00126 break; 00127 } 00128 00129 case GL_INVALID_OPERATION : 00130 { 00131 Error = "GL_INVALID_OPERATION"; 00132 Desc = "the specified operation is not allowed in the current state"; 00133 break; 00134 } 00135 00136 case GL_STACK_OVERFLOW : 00137 { 00138 Error = "GL_STACK_OVERFLOW"; 00139 Desc = "this command would cause a stack overflow"; 00140 break; 00141 } 00142 00143 case GL_STACK_UNDERFLOW : 00144 { 00145 Error = "GL_STACK_UNDERFLOW"; 00146 Desc = "this command would cause a stack underflow"; 00147 break; 00148 } 00149 00150 case GL_OUT_OF_MEMORY : 00151 { 00152 Error = "GL_OUT_OF_MEMORY"; 00153 Desc = "there is not enough memory left to execute the command"; 00154 break; 00155 } 00156 00157 case GL_INVALID_FRAMEBUFFER_OPERATION_EXT : 00158 { 00159 Error = "GL_INVALID_FRAMEBUFFER_OPERATION_EXT"; 00160 Desc = "the object bound to FRAMEBUFFER_BINDING_EXT is not \"framebuffer complete\""; 00161 break; 00162 } 00163 } 00164 00165 // Log the error 00166 std::cerr << "An internal OpenGL call failed in " 00167 << File.substr(File.find_last_of("\\/") + 1) << " (" << Line << ") : " 00168 << Error << ", " << Desc 00169 << std::endl; 00170 } 00171 } 00172 00173 } // namespace sf 00174 00175 00176 #endif // SFML_GRAPHICSCONTEXT_HPP
:: Copyright © 2007-2008 Laurent Gomila, all rights reserved :: Documentation generated by doxygen 1.5.2 ::