summaryrefslogtreecommitdiffstats
path: root/examples/opengl/hellowindow/main.cpp
blob: b247807019c728819dd9d2f593a25da93633cb71 (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <QGuiApplication>
#include <QScreen>
#include <QThread>

#include "hellowindow.h"

int main(int argc, char **argv)
{
    QGuiApplication app(argc, argv);

    QScreen *screen = QGuiApplication::primaryScreen();

    QRect screenGeometry = screen->availableGeometry();

    QSurfaceFormat format;
    format.setDepthBufferSize(16);
    format.setSamples(4);

    QPoint center = QPoint(screenGeometry.center().x(), screenGeometry.top() + 80);
    QSize windowSize(400, 320);
    int delta = 40;

    Renderer rendererA(format);
    Renderer rendererB(format, &rendererA);

    QThread renderThread;
    rendererB.moveToThread(&renderThread);
    renderThread.start();

    QObject::connect(qGuiApp, SIGNAL(lastWindowClosed()), &renderThread, SLOT(quit()));

    HelloWindow windowA(&rendererA);
    windowA.setGeometry(QRect(center, windowSize).translated(-windowSize.width() - delta / 2, 0));
    windowA.setWindowTitle(QLatin1String("Thread A - Context A"));
    windowA.setVisible(true);

    HelloWindow windowB(&rendererA);
    windowB.setGeometry(QRect(center, windowSize).translated(delta / 2, 0));
    windowB.setWindowTitle(QLatin1String("Thread A - Context A"));
    windowB.setVisible(true);

    HelloWindow windowC(&rendererB);
    windowC.setGeometry(QRect(center, windowSize).translated(-windowSize.width() / 2, windowSize.height() + delta));
    windowC.setWindowTitle(QLatin1String("Thread B - Context B"));
    windowC.setVisible(true);

    app.exec();

    renderThread.wait();
}