summaryrefslogtreecommitdiffstats
path: root/examples/vulkan/doc/src/hellovulkanwindow.qdoc
blob: 06cc9c1c288c92f42927672c793baba48b745e68 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
    \example hellovulkanwindow
    \title Hello Vulkan Window Example
    \ingroup examples-vulkan
    \brief Shows the basics of using QVulkanWindow

    The \e{Hello Vulkan Window Example} shows the basics of using QVulkanWindow
    in order to display rendering with the Vulkan graphics API on systems that
    support this.

    \image hellovulkanwindow.png

    In this example there will be no actual rendering: it simply begins and
    ends a render pass, which results in clearing the buffers to a fixed value.
    The color buffer clear value changes on every frame.

    \section1 Startup

    Each Qt application using Vulkan will have to have a \c{Vulkan instance}
    which encapsulates application-level state and initializes a Vulkan library.

    A QVulkanWindow must always be associated with a QVulkanInstance and hence
    the example performs instance creation before the window. The
    QVulkanInstance object must also outlive the window.

    \snippet hellovulkanwindow/main.cpp 0

    The example enables validation layers, when supported. When the requested
    layers are not present, the request will be ignored. Additional layers and
    extensions can be enabled in a similar manner.

    \snippet hellovulkanwindow/main.cpp 1

    Once the instance is ready, it is time to create a window. Note that \c w
    lives on the stack and is declared after \c inst.

    \section1 The QVulkanWindow Subclass

    To add custom functionality to a QVulkanWindow, subclassing is used. This
    follows the existing patterns from QOpenGLWindow and QOpenGLWidget.
    However, QVulkanWindow utilizes a separate QVulkanWindowRenderer object.
    This resembles QQuickFramebufferObject, and allows better separation of the
    functions that are supposed to be reimplemented.

    \snippet hellovulkanwindow/hellovulkanwindow.h 0

    The QVulkanWindow subclass reimplements the factory function
    QVulkanWindow::createRenderer(). This simply returns a new instance of the
    QVulkanWindowRenderer subclass. In order to be able to access various
    Vulkan resources via the window object, a pointer to the window is passed
    and stored via the constructor.

    \snippet hellovulkanwindow/hellovulkanwindow.cpp 0

    Graphics resource creation and destruction is typically done in one of the
    init - resource functions.

    \snippet hellovulkanwindow/hellovulkanwindow.cpp 1

    \section1 The Actual Rendering

    QVulkanWindow subclasses queue their draw calls in their reimplementation
    of QVulkanWindowRenderer::startNextFrame(). Once done, they are required to
    call back QVulkanWindow::frameReady(). The example has no asynchronous
    command generation, so the frameReady() call is made directly from
    startNextFrame().

    \snippet hellovulkanwindow/hellovulkanwindow.cpp 2

    To get continuous updates, the example simply invokes
    QWindow::requestUpdate() in order to schedule a repaint.

    \include examples-run.qdocinc
*/