D:/Programmation/Cpp/SFML/src/SFML/Graphics/OpenGL.hpp

00001 
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com)
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_OPENGL_HPP
00026 #define SFML_OPENGL_HPP
00027 
00029 // Headers
00031 #include <SFML/Graphics/glew/glew.h>
00032 #include <GL/gl.h>
00033 #include <iostream>
00034 #include <string>
00035 
00036 
00037 namespace sf_private
00038 {
00044 #ifdef SFML_DEBUG
00045 
00046     // If in debug mode, perform a test on every call
00047     #define sfGLCheck(Func) ((Func), sf_private::sfGLCheckError())
00048 
00049 #else
00050 
00051     // Else, we don't add any overhead
00052     #define sfGLCheck(Func) (Func)
00053 
00054 #endif
00055 
00056 
00061 inline void sfGLCheckError()
00062 {
00063     // Get the last error
00064     GLenum ErrorCode = glGetError();
00065 
00066     if (ErrorCode != GL_NO_ERROR)
00067     {
00068         std::string Error, Desc;
00069 
00070         // Decode the error code
00071         switch (ErrorCode)
00072         {
00073             case GL_INVALID_ENUM :
00074             {
00075                 Error = "GL_INVALID_ENUM";
00076                 Desc  = "an unacceptable value has been specified for an enumerated argument";
00077                 break;
00078             }
00079 
00080             case GL_INVALID_VALUE :
00081             {
00082                 Error = "GL_INVALID_VALUE";
00083                 Desc  = "a numeric argument is out of range";
00084                 break;
00085             }
00086 
00087             case GL_INVALID_OPERATION :
00088             {
00089                 Error = "GL_INVALID_OPERATION";
00090                 Desc  = "the specified operation is not allowed in the current state";
00091                 break;
00092             }
00093 
00094             case GL_STACK_OVERFLOW :
00095             {
00096                 Error = "GL_STACK_OVERFLOW";
00097                 Desc  = "this command would cause a stack overflow";
00098                 break;
00099             }
00100 
00101             case GL_STACK_UNDERFLOW :
00102             {
00103                 Error = "GL_STACK_UNDERFLOW";
00104                 Desc  = "this command would cause a stack underflow";
00105                 break;
00106             }
00107 
00108             case GL_OUT_OF_MEMORY :
00109             {
00110                 Error = "GL_OUT_OF_MEMORY";
00111                 Desc  = "there is not enough memory left to execute the command";
00112                 break;
00113             }
00114         }
00115 
00116         // Log the error
00117         std::cerr << "An internal OpenGL call failed "
00118                   << "("  << Error << " : " << Desc << ")"
00119                   << std::endl;
00120     }
00121 }
00122 
00123 } // namespace sf_private
00124 
00125 #endif // SFML_OPENGL_HPP

Generated for SFML by  doxygen 1.5.2