Back to index

nux  3.0.0
GLError.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 #include "GLResource.h"
00023 #include "FontTexture.h"
00024 #include "GLError.h"
00025 
00026 namespace nux
00027 {
00028 #ifdef NUX_DEBUG
00029   static bool bBreakOnGLErrors = FALSE;
00030 #endif
00031 
00032 // WARNING: never call glGetError between glBegin and glEnd.
00033   int CheckGLError(const char *GLcall, const char *file, int line)
00034   {
00035     GLenum glErr;
00036     int    retCode = 0;
00037 
00038     while ((glErr = glGetError()) != GL_NO_ERROR)
00039     {
00040 
00041       switch(glErr)
00042       {
00043         case GL_INVALID_ENUM:
00044           nuxWarningMsg("[CheckGLError] GL_INVALID_ENUM error in File %s at line: %d", file, line);
00045           break;
00046         case GL_INVALID_VALUE:
00047           nuxWarningMsg("[CheckGLError] GL_INVALID_VALUE error in File %s at line: %d", file, line);
00048           break;
00049         case GL_INVALID_OPERATION:
00050           nuxWarningMsg("[CheckGLError] GL_INVALID_OPERATION error in File %s at line: %d", file, line);
00051           break;
00052 #ifndef NUX_OPENGLES_20
00053         case GL_STACK_OVERFLOW:
00054           nuxWarningMsg("[CheckGLError] GL_STACK_OVERFLOW error in File %s at line: %d", file, line);
00055           break;
00056         case GL_STACK_UNDERFLOW:
00057           nuxWarningMsg("[CheckGLError] GL_STACK_UNDERFLOW error in File %s at line: %d", file, line);
00058           break;
00059 #endif
00060         case GL_OUT_OF_MEMORY:
00061           nuxWarningMsg("[CheckGLError] GL_OUT_OF_MEMORY error in File %s at line: %d", file, line);
00062           break;
00063         default:
00064           nuxWarningMsg("[CheckGLError] UNKNOWN ERROR in File %s at line: %d", file, line);
00065       }
00066 
00067 #ifndef NUX_OPENGLES_20
00068       nuxWarningMsg("[CheckGLError] OpenGL Error %d( %s )  in File %s at line: %d \n", glErr, ANSI_TO_TCHAR(gluErrorString(glErr)), ANSI_TO_TCHAR(file), line);
00069 #endif
00070       retCode = 1;
00071 
00072 #ifdef NUX_DEBUG
00073 
00074       // break on errors if asked to
00075       if (bBreakOnGLErrors)
00076 #endif
00077         inlDebugBreak();
00078     }
00079 
00080     return retCode;
00081   }
00082 
00083 }