SFML logo
  • Main Page
  • Namespaces
  • Classes
  • Files
  • File List

GLCheck.cpp

00001 
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 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 
00026 // Headers
00028 #include <SFML/Graphics/GLCheck.hpp>
00029 #include <SFML/System/Err.hpp>
00030 
00031 
00032 namespace sf
00033 {
00034 namespace priv
00035 {
00039 void GLCheckError(const std::string& file, unsigned int line)
00040 {
00041     // Get the last error
00042     GLenum errorCode = glGetError();
00043 
00044     if (errorCode != GL_NO_ERROR)
00045     {
00046         std::string error = "unknown error";
00047         std::string description  = "no description";
00048 
00049         // Decode the error code
00050         switch (errorCode)
00051         {
00052             case GL_INVALID_ENUM :
00053             {
00054                 error = "GL_INVALID_ENUM";
00055                 description = "an unacceptable value has been specified for an enumerated argument";
00056                 break;
00057             }
00058 
00059             case GL_INVALID_VALUE :
00060             {
00061                 error = "GL_INVALID_VALUE";
00062                 description = "a numeric argument is out of range";
00063                 break;
00064             }
00065 
00066             case GL_INVALID_OPERATION :
00067             {
00068                 error = "GL_INVALID_OPERATION";
00069                 description = "the specified operation is not allowed in the current state";
00070                 break;
00071             }
00072 
00073             case GL_STACK_OVERFLOW :
00074             {
00075                 error = "GL_STACK_OVERFLOW";
00076                 description = "this command would cause a stack overflow";
00077                 break;
00078             }
00079 
00080             case GL_STACK_UNDERFLOW :
00081             {
00082                 error = "GL_STACK_UNDERFLOW";
00083                 description = "this command would cause a stack underflow";
00084                 break;
00085             }
00086 
00087             case GL_OUT_OF_MEMORY :
00088             {
00089                 error = "GL_OUT_OF_MEMORY";
00090                 description = "there is not enough memory left to execute the command";
00091                 break;
00092             }
00093 
00094             case GL_INVALID_FRAMEBUFFER_OPERATION_EXT :
00095             {
00096                 error = "GL_INVALID_FRAMEBUFFER_OPERATION_EXT";
00097                 description = "the object bound to FRAMEBUFFER_BINDING_EXT is not \"framebuffer complete\"";
00098                 break;
00099             }
00100         }
00101 
00102         // Log the error
00103         Err() << "An internal OpenGL call failed in "
00104               << file.substr(file.find_last_of("\\/") + 1) << " (" << line << ") : "
00105               << error << ", " << description
00106               << std::endl;
00107     }
00108 }
00109 
00110 
00114 void EnsureGlewInit()
00115 {
00116     static bool initialized = false;
00117     if (!initialized)
00118     {
00119         glewInit();
00120         initialized = true;
00121     }
00122 }
00123 
00124 } // namespace priv
00125 
00126 } // namespace sf

 ::  Copyright © 2007-2008 Laurent Gomila, all rights reserved  ::  Documentation generated by doxygen 1.5.2  ::