| 1 |
/**************************************************************************** |
| 2 |
** |
| 3 |
** Copyright (C) 2019 The Qt Company Ltd. |
| 4 |
** Contact: https://www.qt.io/licensing/ |
| 5 |
** |
| 6 |
** This file is part of the documentation of the Qt Toolkit. |
| 7 |
** |
| 8 |
** $QT_BEGIN_LICENSE:FDL$ |
| 9 |
** Commercial License Usage |
| 10 |
** Licensees holding valid commercial Qt licenses may use this file in |
| 11 |
** accordance with the commercial license agreement provided with the |
| 12 |
** Software or, alternatively, in accordance with the terms contained in |
| 13 |
** a written agreement between you and The Qt Company. For licensing terms |
| 14 |
** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 |
** information use the contact form at https://www.qt.io/contact-us. |
| 16 |
** |
| 17 |
** GNU Free Documentation License Usage |
| 18 |
** Alternatively, this file may be used under the terms of the GNU Free |
| 19 |
** Documentation License version 1.3 as published by the Free Software |
| 20 |
** Foundation and appearing in the file included in the packaging of |
| 21 |
** this file. Please review the following information to ensure |
| 22 |
** the GNU Free Documentation License version 1.3 requirements |
| 23 |
** will be met: https://www.gnu.org/licenses/fdl-1.3.html. |
| 24 |
** $QT_END_LICENSE$ |
| 25 |
** |
| 26 |
****************************************************************************/ |
| 27 |
|
| 28 |
/*! |
| 29 |
\example scenegraph/metalunderqml |
| 30 |
\title Scene Graph - Metal Under QML |
| 31 |
\ingroup qtquickexamples |
| 32 |
\brief Shows how to render directly with Metal under a Qt Quick scene. |
| 33 |
|
| 34 |
\image metalunderqml-example.jpg |
| 35 |
|
| 36 |
The Metal Under QML example shows how an application can make use |
| 37 |
of the \l QQuickWindow::beforeRendering() and \l |
| 38 |
QQuickWindow::beforeRenderPassRecording() signals to draw custom |
| 39 |
Metal content under a Qt Quick scene. This signal is emitted at |
| 40 |
the start of every frame, before the scene graph starts its |
| 41 |
rendering, thus any Metal draw calls that are made as a response |
| 42 |
to this signal, will stack under the Qt Quick items. There are two |
| 43 |
signals, because the custom Metal commands are recorded onto the |
| 44 |
same command buffer with the same render command encoder that the |
| 45 |
scene graph uses. beforeRendering() on its own is not sufficient |
| 46 |
for this because it gets emitted at the start of the frame, before |
| 47 |
having an |
| 48 |
\l{https://developer.apple.com/documentation/metal/mtlrendercommandencoder}{MTLRenderCommandEncoder} |
| 49 |
available. By also connecting to beforeRenderPassRecording(), the |
| 50 |
application can gain access to the necessary native objects. |
| 51 |
|
| 52 |
As an alternative, applications that wish to render Metal content |
| 53 |
on top of the Qt Quick scene, can do so by connecting to the \l |
| 54 |
QQuickWindow::afterRendering() and \l |
| 55 |
QQuickWindow::afterRenderPassRecording() signals. |
| 56 |
|
| 57 |
In this example, we will also see how it is possible to have |
| 58 |
values that are exposed to QML which affect the Metal |
| 59 |
rendering. We animate the threshold value using a NumberAnimation |
| 60 |
in the QML file and this value is used by the Metal shader |
| 61 |
program that draws the squircles. |
| 62 |
|
| 63 |
The example is equivalent in most ways to the \l{Scene Graph - OpenGL Under |
| 64 |
QML}{OpenGL Under QML}, \l{Scene Graph - Direct3D 11 Under QML}{Direct3D 11 |
| 65 |
Under QML}, and \l{Scene Graph - Vulkan Under QML}{Vulkan Under QML} |
| 66 |
examples, they all render the same custom content, just via different |
| 67 |
native APIs. |
| 68 |
|
| 69 |
*/ |