/**********************************************************************
* *
* cgt - CAMP Graphics Toolbox, Copyright (C) 2012-2015 *
* Chair for Computer Aided Medical Procedures *
* Technische Universitaet Muenchen, Germany. *
* *
* *
* forked from tgt - Tiny Graphics Toolbox, Copyright (C) 2006-2011 *
* Visualization and Computer Graphics Group, Department of *
* Computer Science, University of Muenster, Germany. *
* *
* *
* This file is part of the cgt library. This library is free *
* software; you can redistribute it and/or modify it under the terms *
* of the GNU Lesser General Public License version 2.1 as published *
* by the Free Software Foundation. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License in the file "LICENSE.txt" along with this library. *
* If not, see . *
* *
**********************************************************************/
#include "cgt/cgt_gl.h"
#include "cgt/logmanager.h"
namespace cgt {
GLenum _lGLError(int line, const char* file) {
GLenum err;
while ((err = glGetError()) != GL_NO_ERROR) {
std::string exp = getErrorString(err);
std::ostringstream tmp1, tmp2, loggerCat;
tmp2 << " File: " << file << "@" << line;
tmp1 << exp;
loggerCat << "gl-error:" << file << ':' << line;
LogMgr.log(loggerCat.str(), cgt::Error, tmp1.str(), tmp2.str());
}
return err;
}
GLboolean getGlBool(GLenum param) {
GLboolean toReturn;
glGetBooleanv(param, &toReturn);
return toReturn;
}
GLint getGlInt(GLenum param) {
GLint toReturn;
glGetIntegerv(param, &toReturn);
return toReturn;
}
GLfloat getGlFloat(GLenum param) {
GLfloat toReturn;
glGetFloatv(param, &toReturn);
return toReturn;
}
CGT_API const char* getErrorString(GLenum err)
{
switch (err) {
case GL_NO_ERROR:
return "GL_NO_ERROR: No error has been recorded.";
case GL_INVALID_ENUM:
return "GL_INVALID_ENUM: An unacceptable value is specified for an enumerated argument.";
case GL_INVALID_VALUE:
return "GL_INVALID_VALUE: A numeric argument is out of range.";
case GL_INVALID_OPERATION:
return "GL_INVALID_OPERATION: The specified operation is not allowed in the current state.";
case GL_INVALID_FRAMEBUFFER_OPERATION:
return "GL_INVALID_FRAMEBUFFER_OPERATION: The framebuffer object is not complete.";
case GL_OUT_OF_MEMORY:
return "GL_OUT_OF_MEMORY: There is not enough memory left to execute the command.";
case GL_STACK_UNDERFLOW:
return "GL_STACK_UNDERFLOW: An attempt has been made to perform an operation that would cause an internal stack to underflow.";
case GL_STACK_OVERFLOW:
return "GL_STACK_OVERFLOW: An attempt has been made to perform an operation that would cause an internal stack to overflow.";
default:
return "UNKNOWN: An unknown error occurred or the enum is not an error code.";
}
}
} // namespace cgt