aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quick/scenegraph/customrendernode/main.cpp
blob: 0ad93ec1de753224ec00d4949c2741ab5b4b1bc1 (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
51
52
53
54
55
56
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#include <QGuiApplication>
#include <QQuickView>
#include <QSurfaceFormat>

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

    // On macOS, request a core profile context in the unlikely case of using OpenGL.
#ifdef Q_OS_MACOS
    QSurfaceFormat format = QSurfaceFormat::defaultFormat();
    format.setMajorVersion(4);
    format.setMinorVersion(1);
    format.setProfile(QSurfaceFormat::CoreProfile);
    QSurfaceFormat::setDefaultFormat(format);
#endif

    QQuickView view;

    view.setResizeMode(QQuickView::SizeRootObjectToView);
    view.setSource(QUrl("qrc:///scenegraph/customrendernode/main.qml"));
    view.setColor(Qt::black);
    view.show();

    QString api;
    switch (view.graphicsApi()) {
    case QSGRendererInterface::OpenGL:
        api = "RHI OpenGL";
        break;
    case QSGRendererInterface::Direct3D11:
        api = "RHI Direct 3D 11";
        break;
    case QSGRendererInterface::Direct3D12:
        api = "RHI Direct 3D 12";
        break;
    case QSGRendererInterface::Vulkan:
        api = "RHI Vulkan";
        break;
    case QSGRendererInterface::Metal:
        api = "RHI Metal";
        break;
    case QSGRendererInterface::Null:
        api = "RHI Null";
        break;
    default:
        api = "unknown";
        break;
    }

    view.setTitle(QStringLiteral("Custom QSGRenderNode - ") + api);

    return app.exec();
}