main.cpp 4.92 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// ================================================================================================
// 
// This file is part of the CAMPVis Software Framework.
// 
// If not explicitly stated otherwise: Copyright (C) 2012-2013, all rights reserved,
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
//      Chair for Computer Aided Medical Procedures
//      Technische Universitt Mnchen
//      Boltzmannstr. 3, 85748 Garching b. Mnchen, Germany
// 
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
// 
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 
// except in compliance with the License. You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software distributed under the 
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
// either express or implied. See the License for the specific language governing permissions 
// and limitations under the License.
// 
// ================================================================================================

/**
 * Author: Hossain Mahmud <mahmud@in.tum.de>
 * Date: March 2014
 */


31
32
33
#include "gtest/gtest.h"
#include <stdio.h>

34
35
36
37
38
39
40
41
42
43
44
//#include "tgt/assert.h"
//#include "tgt/exception.h"
//#include "tgt/glcanvas.h"
#include "tgt/gpucapabilities.h"
#include "tgt/shadermanager.h"
#include "tgt/qt/qtapplication.h"
//#include "tgt/qt/qtthreadedcanvas.h"
#include "tgt/qt/qtcontextmanager.h"
#include "tgt/logmanager.h"
//#include "tbb/compat/thread"

45
#include "core/tools/simplejobprocessor.h"
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "core/tools/opengljobprocessor.h"
#include "core/tools/quadrenderer.h"

//using namespace campvis;

/// Not sure, whether or not we need it!!
QApplication *app;

/// Flag, whether CampVisApplication was correctly initialized
bool _initialized;

/// A local OpenGL context used for initialization
/**?
 * how this variable is related with tgt macros!! 
 */
tgt::GLCanvas* _localContext = nullptr;

static const std::string loggerCat_;

65
66

void init() {
67
68
69
70
71
72
    // Make Xlib and GLX thread safe under X11
    QApplication::setAttribute(Qt::AA_X11InitThreads);

    tgt::QtContextManager::init();

    campvis::OpenGLJobProcessor::init();
73
    campvis::SimpleJobProcessor::init();
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

    // Init TGT
    tgt::InitFeature::Features featureset = tgt::InitFeature::ALL;
    tgt::init(featureset);
    LogMgr.getConsoleLog()->addCat("", true);

    // create a local OpenGL context and init GL
    _localContext = tgt::GlContextManager::getRef().createContext("AppContext", "", tgt::ivec2(16, 16));
    tgtAssert(nullptr != _localContext, "Could not create local OpenGL context");

    tgt::GLContextScopedLock lock(_localContext);

    tgt::initGL(featureset);
    ShdrMgr.setDefaultGlslVersion("330");


    campvis::QuadRenderer::init();

Hossain Mahmud's avatar
Hossain Mahmud committed
92
93
94
95
96
97
98
99
#ifdef CAMPVIS_SOURCE_DIR
    {
        std::string sourcePath = CAMPVIS_SOURCE_DIR;
        ShdrMgr.addPath(sourcePath);
        ShdrMgr.addPath(sourcePath + "/core/glsl");
    }
#endif

100
101
102
103
104
105
106
107
108
    // ensure matching OpenGL specs
    LINFO("Using Graphics Hardware " << GpuCaps.getVendorAsString() << " " << GpuCaps.getGlRendererString() << " on " << GpuCaps.getOSVersionString());
    LINFO("Supported OpenGL " << GpuCaps.getGlVersion() << ", GLSL " << GpuCaps.getShaderVersion());
    if (GpuCaps.getGlVersion() < tgt::GpuCapabilities::GlVersion::TGT_GL_VERSION_3_3) {
        LERROR("Your system does not support OpenGL 3.3, which is mandatory. CAMPVis will probably not work as intended.");
    }
    if (GpuCaps.getShaderVersion() < tgt::GpuCapabilities::GlVersion::SHADER_VERSION_330) {
        LERROR("Your system does not support GLSL Shader Version 3.30, which is mandatory. CAMPVis will probably not work as intended.");
    }
109
    
110
    _initialized = true;
111
112
113
}

void deinit() {
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
    tgtAssert(_initialized, "Tried to deinitialize uninitialized CampVisApplication.");


    /**?
     * Grrrrrrrrrrrrrrrr :#
     * What with this BLOCK :-/ without it the program doesn't exit.
     * OpenGLJobProcessor::deinit() halts in Singleton::deinit()
     * WHY IS STACK SCOPE IMPORTANT HERE!!!
     */
    {
        // Deinit everything OpenGL related using the local context.
        tgt::GLContextScopedLock lock(_localContext);

        campvis::QuadRenderer::deinit();

        // deinit OpenGL and tgt
        tgt::deinitGL();

    }

134
    campvis::SimpleJobProcessor::deinit();
135
136
137
138
139
140
141
    campvis::OpenGLJobProcessor::deinit();


    tgt::QtContextManager::deinit();
    tgt::deinit();

    _initialized = false;
142
143
144
145
}

GTEST_API_ int main(int argc, char **argv) {
    printf("Running main() from main.cpp\n");
146
    app = new QApplication(argc, argv);
147
148
    testing::InitGoogleTest(&argc, argv);

149
    int ret;
150

151
152
153
154
    init();
    {
        tgt::GLContextScopedLock lock(_localContext);
        ret= RUN_ALL_TESTS();
155

156
    }
157
158
159
    deinit();

    //getchar();
160
161
    delete app;
    printf("main() returned with %d\n", ret);
162
163
    return 0;
}