src/video/glutil.hpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #ifndef HEADER_SUPERTUX_VIDEO_GLUTIL_HPP
00018 #define HEADER_SUPERTUX_VIDEO_GLUTIL_HPP
00019 
00020 #include <config.h>
00021 
00022 #ifdef HAVE_OPENGL
00023 
00024 #include <sstream>
00025 #include <stdexcept>
00026 
00027 #ifndef GL_VERSION_ES_CM_1_0
00028 #  include <GL/glew.h>
00029 #endif
00030 
00031 #if defined(MACOSX)
00032 #  include <OpenGL/gl.h>
00033 #  include <OpenGL/glext.h>
00034 #elif defined(GL_VERSION_ES_CM_1_0)
00035 #  include <GLES/gl.h>
00036 #  include <GLES/glext.h>
00037 #else
00038 #  include <GL/gl.h>
00039 #  include <GL/glext.h>
00040 #endif
00041 
00042 static inline void check_gl_error(const char* message)
00043 {
00044   GLenum error = glGetError();
00045   if(error != GL_NO_ERROR) {
00046     std::ostringstream msg;
00047     msg << "OpenGLError while '" << message << "': ";
00048     switch(error) {
00049       case GL_INVALID_ENUM:
00050         msg << "INVALID_ENUM: An unacceptable value is specified for an "
00051           "enumerated argument.";
00052         break;
00053       case GL_INVALID_VALUE:
00054         msg << "INVALID_VALUE: A numeric argument is out of range.";
00055         break;
00056       case GL_INVALID_OPERATION:
00057         msg << "INVALID_OPERATION: The specified operation is not allowed "
00058           "in the current state.";
00059         break;
00060       case GL_STACK_OVERFLOW:
00061         msg << "STACK_OVERFLOW: This command would cause a stack overflow.";
00062         break;
00063       case GL_STACK_UNDERFLOW:
00064         msg << "STACK_UNDERFLOW: This command would cause a stack underflow.";
00065         break;
00066       case GL_OUT_OF_MEMORY:
00067         msg << "OUT_OF_MEMORY: There is not enough memory left to execute the "
00068           "command.";
00069         break;
00070 #ifdef GL_TABLE_TOO_LARGE
00071       case GL_TABLE_TOO_LARGE:
00072         msg << "TABLE_TOO_LARGE: table is too large";
00073         break;
00074 #endif
00075       default:
00076         msg << "Unknown error (code " << error << ")";
00077     }
00078 
00079     throw std::runtime_error(msg.str());
00080   }
00081 }
00082 
00083 static inline void assert_gl(const char* message)
00084 {
00085   check_gl_error(message);
00086 }
00087 
00088 #else
00089 
00090 #define GLenum int
00091 #define GLint int
00092 #define GL_SRC_ALPHA 0
00093 #define GL_ONE_MINUS_SRC_ALPHA 1
00094 #define GL_RGBA 2
00095 #define GL_ONE 3
00096 
00097 #endif
00098 
00099 #endif
00100 
00101 /* EOF */

Generated on Mon Jun 9 03:38:24 2014 for SuperTux by  doxygen 1.5.1