cgt_gl.cpp 3.92 KB
Newer Older
schultezub's avatar
schultezub committed
1
2
/**********************************************************************
 *                                                                    *
3
 * cgt - CAMP Graphics Toolbox, Copyright (C) 2012-2015               *
4
5
6
 *     Chair for Computer Aided Medical Procedures                    *
 *     Technische Universitaet Muenchen, Germany.                     *
 *     <http://campar.in.tum.de/>                                     *
schultezub's avatar
schultezub committed
7
 *                                                                    *
8
9
10
11
 * forked from tgt - Tiny Graphics Toolbox, Copyright (C) 2006-2011   *
 *     Visualization and Computer Graphics Group, Department of       *
 *     Computer Science, University of Muenster, Germany.             *
 *     <http://viscg.uni-muenster.de>                                 *
schultezub's avatar
schultezub committed
12
 *                                                                    *
13
 * This file is part of the cgt library. This library is free         *
schultezub's avatar
schultezub committed
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 * 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 <http://www.gnu.org/licenses/>.                        *
 *                                                                    *
 **********************************************************************/

29
#include "cgt/cgt_gl.h"
schultezub's avatar
schultezub committed
30

31
#include "cgt/logmanager.h"
schultezub's avatar
schultezub committed
32

33
namespace cgt {
schultezub's avatar
schultezub committed
34
35

GLenum _lGLError(int line, const char* file) {
36
37
38
    GLenum err;
    while ((err = glGetError()) != GL_NO_ERROR) {
        std::string exp = getErrorString(err);
schultezub's avatar
schultezub committed
39
40
41

        std::ostringstream tmp1, tmp2, loggerCat;
        tmp2 << " File: " << file << "@" << line;
42
        tmp1 << exp;
schultezub's avatar
schultezub committed
43
44
        loggerCat << "gl-error:" << file << ':' << line;

45
        LogMgr.log(loggerCat.str(), cgt::Error, tmp1.str(), tmp2.str());
schultezub's avatar
schultezub committed
46
47
48
49
50
    }

    return err;
}

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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;
}

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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.";
    }
}

93
} // namespace cgt