Tools.cc 2.07 KB
Newer Older
Robert Menzel's avatar
Robert Menzel committed
1 2 3 4 5
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University         //
// All rights reserved.                                                       //
////////////////////////////////////////////////////////////////////////////////

Robert Menzel's avatar
Robert Menzel committed
6
#include <ACGL/ACGL.hh>
Robert Menzel's avatar
Robert Menzel committed
7
#include <ACGL/OpenGL/Tools.hh>
Robert Menzel's avatar
Robert Menzel committed
8 9

namespace ACGL{
Robert Menzel's avatar
Robert Menzel committed
10
namespace OpenGL{
Robert Menzel's avatar
Robert Menzel committed
11

12
const GLubyte* acglErrorString( GLenum _errorCode )
Robert Menzel's avatar
Robert Menzel committed
13 14 15 16 17
{
#ifdef PLATFORM_IOS
    // no gluErrorString on iOS
    // this should only get used on OpenGL ES plattforms, so error strings from the compatibility profile
    // are ignored. Only 3.2+ Core and ES 2.0+ errors belong here:
18 19 20 21 22 23
    if      (_errorCode == GL_INVALID_ENUM)                  { return (GLubyte*) "GL_INVALID_ENUM"; }
    else if (_errorCode == GL_INVALID_VALUE)                 { return (GLubyte*) "GL_INVALID_VALUE"; }
    else if (_errorCode == GL_INVALID_OPERATION)             { return (GLubyte*) "GL_INVALID_OPERATION"l; }
    else if (_errorCode == GL_INVALID_FRAMEBUFFER_OPERATION) { return (GLubyte*) "GL_INVALID_FRAMEBUFFER_OPERATION"; }
    else if (_errorCode == GL_OUT_OF_MEMORY)                 { return (GLubyte*) "GL_OUT_OF_MEMORY" };
    else if (_errorCode == GL_NO_ERROR)                      { return (GLubyte*) "GL_NO_ERROR"; }
Robert Menzel's avatar
Robert Menzel committed
24
    else {
25
        return (GLubyte*) "unknown error";
Robert Menzel's avatar
Robert Menzel committed
26 27
    }
#else
28
    return gluErrorString( _errorCode );
Robert Menzel's avatar
Robert Menzel committed
29 30 31 32 33 34 35
#endif
}



GLenum openGLError_( const char *_fileName, const unsigned long _lineNumber )
{
36 37 38 39 40 41 42 43 44
    GLenum currentError = glGetError();
    GLenum lastError    = currentError;

    // OpenGL does not forbit the implementation to stack up more than one error code
    // so we have to check those in a loop:
    while ( currentError != GL_NO_ERROR ) {
        ACGL::Utils::error() << "GL error in file " << _fileName << ":" << _lineNumber << " - " << acglErrorString( currentError ) << std::endl;
        lastError    = currentError;
        currentError = glGetError();
Robert Menzel's avatar
Robert Menzel committed
45 46
    }

47
    return lastError; // returns the last real error (in case there was at least one!)
Robert Menzel's avatar
Robert Menzel committed
48 49 50
}


Robert Menzel's avatar
Robert Menzel committed
51
} // OpenGL
Robert Menzel's avatar
Robert Menzel committed
52 53
} // ACGL