ACGL.cc 2.65 KB
Newer Older
1 2 3 4 5
/***********************************************************************
 * Copyright 2011-2012 Computer Graphics Group RWTH Aachen University. *
 * All rights reserved.                                                *
 * Distributed under the terms of the MIT License (see LICENSE.TXT).   *
 **********************************************************************/
Robert Menzel's avatar
Robert Menzel committed
6 7

#include <ACGL/ACGL.hh>
Robert Menzel's avatar
Robert Menzel committed
8
#include <ACGL/OpenGL/GL.hh>
9
#include <ACGL/OpenGL/Tools.hh>
10
#include <ACGL/OpenGL/Objects/VertexArrayObject.hh>
Robert Menzel's avatar
Robert Menzel committed
11 12 13 14

namespace ACGL
{

15
bool init()
Robert Menzel's avatar
Robert Menzel committed
16
{
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
    Utils::debug() << "ACGL was compiled for "
    #ifdef ACGL_DEBUG
        << "debug" << std::endl;
    #else
        << "release" << std::endl;
    #endif

    Utils::debug() << "OpenGL error checking is set to "
    #if defined( ACGL_CHECK_NO_GL_ERRORS )
        << "NO checks" << std::endl;
    #elif defined( ACGL_CHECK_RARE_GL_ERRORS )
        << "check a lot (for debugging)" << std::endl;
    #elif defined( ACGL_CHECK_COMMON_GL_ERRORS )
        << "normal" << std::endl;
    #elif defined( ACGL_CHECK_CRITICAL_GL_ERRORS )
        << "only most critical checks" << std::endl;
    #endif


36
    //
37
    // init GLEW or own extension loader, do nothing on ES
38
    //
39
#ifdef ACGL_USE_GLEW
40
#   ifdef ACGL_OPENGL_PROFILE_CORE
41
        glewExperimental = GL_TRUE;
42
#   endif
43 44 45
        GLenum errorCode = glewInit();
        if ((errorCode != GLEW_OK) || (openGLCriticalErrorOccured())) {
            Utils::error() << "could not init GLEW!" << std::endl;
46
            #ifdef ACGL_OPENGL_PROFILE_CORE
47
            Utils::error() << "Make sure your version of GLEW is compatible with core contexts" << std::endl;
48
            #endif
49 50
            return false;
        }
51
#elif defined( ACGL_EXTENSION_LOADER_GLLOADGEN )
52 53 54 55 56 57
    int loaded = ogl_LoadFunctions();
    if (loaded == ogl_LOAD_FAILED)
    {
        Utils::error() << "could not load OpenGL functions!" << std::endl;
        return false;
    }
58
#endif // GLEW
59 60 61 62

    //
    // check OpenGL version
    //
63
    Utils::debug() << "OpenGL Version: " << OpenGL::getOpenGLMajorVersionNumber() << "." << OpenGL::getOpenGLMinorVersionNumber() << std::endl;
64

65
#ifdef ACGL_OPENGL_ES
66
    unsigned int versionToTest = ACGL_OPENGLES_VERSION ;
67
#else
68
    unsigned int versionToTest = ACGL_OPENGL_VERSION ;
69 70 71 72
#endif
    
    if (OpenGL::getOpenGLVersionNumber() < versionToTest) {
       Utils::error() << "At compile time an OpenGL context of version " << versionToTest
73 74
                      << " was requested, but the current context only supports " << OpenGL::getOpenGLVersionNumber() << std::endl;
       return false;
75
    }
76

77 78 79
    // gets runtime limits to be used internally:
    OpenGL::initRuntimeDependentLimits();

80
    return true;
Robert Menzel's avatar
Robert Menzel committed
81 82
}
    
83
}
Robert Menzel's avatar
Robert Menzel committed
84