main.cpp 3.16 KB
Newer Older
1
2
3
4
// ================================================================================================
// 
// This file is part of the CAMPVis Software Framework.
// 
5
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
6
7
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
//      Chair for Computer Aided Medical Procedures
8
9
//      Technische Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// 
// 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
#include "gtest/gtest.h"
#include <stdio.h>
33
34
35
#include <QApplication>

#include "sigslot/sigslot.h"
36

37
38
39
40
41
42
43
#include "cgt/glcontextmanager.h"
#include "cgt/gpucapabilities.h"
#include "cgt/init.h"
#include "cgt/logmanager.h"
#include "cgt/opengljobprocessor.h"
#include "cgt/shadermanager.h"
#include "cgt/qt/qtthreadedcanvas.h"
44

45
#include "core/init.h"
46
#include "core/tools/simplejobprocessor.h"
47
48
49
50
51
52
#include "core/tools/quadrenderer.h"

QApplication *app;
/// Flag, whether CampVisApplication was correctly initialized
bool _initialized;
/// A local OpenGL context used for initialization
53
cgt::GLCanvas* _localContext = nullptr;
54
55
static const std::string loggerCat_;

56
57

void init() {
58
59
60
61
    std::vector<std::string> searchPaths;
#ifdef CAMPVIS_SOURCE_DIR
        searchPaths.push_back(CAMPVIS_SOURCE_DIR);
#endif
62

63
    cgt::QtThreadedCanvas* backgroundCanvas = new cgt::QtThreadedCanvas("", cgt::ivec2(16, 16));
64
    campvis::init(backgroundCanvas, searchPaths);
65
    
66
67
    _localContext = new cgt::QtThreadedCanvas("", cgt::ivec2(16, 16));
    cgt::GlContextManager::getRef().registerContextAndInitGlew(_localContext, "Local Context");
68
69
    GLCtxtMgr.releaseContext(_localContext, false);

70
    _initialized = true;
71
72
73
}

void deinit() {
74
    cgtAssert(_initialized, "Tried to deinitialize uninitialized CampVisApplication.");
75
    campvis::deinit();
76

77
    _initialized = false;
78
79
80
81
}

GTEST_API_ int main(int argc, char **argv) {
    printf("Running main() from main.cpp\n");
82

83
    // Make Xlib and GLX thread safe under X11
84
85
    QCoreApplication::setAttribute(Qt::AA_X11InitThreads);
    app = new QApplication(argc, argv);
86

87
    testing::InitGoogleTest(&argc, argv);
88
    init();
89
    int ret;
90
    
91
    std::thread testThread([&] () {
92
        cgt::GLContextScopedLock lock(_localContext);
93
        ret= RUN_ALL_TESTS();
94

95
96
97
    });

    app->exec();
98
99
    testThread.join();
    app->exit();
100
101
    deinit();

102
103
    delete app;
    printf("main() returned with %d\n", ret);
104
105
    return 0;
}