1/****************************************************************************
2**
3** Copyright (C) 2018 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
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 Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qsetfence.h"
41#include "qsetfence_p.h"
42#include <Qt3DRender/private/qframegraphnodecreatedchange_p.h>
43#include <Qt3DCore/qpropertyupdatedchange.h>
44
45QT_BEGIN_NAMESPACE
46
47namespace Qt3DRender {
48
49QSetFencePrivate::QSetFencePrivate()
50 : QFrameGraphNodePrivate()
51 , m_handleType(QSetFence::NoHandle)
52 , m_handle(QVariant())
53{
54}
55
56/*!
57 \class Qt3DRender::QSetFence
58 \inmodule Qt3DRender
59 \brief FrameGraphNode used to insert a fence in the graphics command stream.
60
61 Fence allow to synchronosize GPU and CPU workloads. GPU commands usually
62 are non-blocking. When issued, commands are inserted in command buffers
63 which will be read at a later time by the GPU. In some cases, you want to
64 continue processing or issue specific command only when you are sure a
65 command has been executed by the hardware. Fences are a way to do so. This
66 is especially important when using 3rd party engines with Qt3D, Qt3D should
67 only access shared resources when we know the other engine command are done
68 modifying the resource.
69
70 QSetFence is a FrameGraph node that inserts a fence into the command
71 stream. It can then be used in conjunction with \l QWaitFence or by
72 extracting the underlying handle.
73
74 The handle property will be updated once the renderer has created the
75 underlying fence resource. The handle will remain valid as long as it
76 remains in the unsignaled state. Once it has reached the signaled state, it
77 will be destroyed and a new handle will be created. That means that
78 depending on how long it takes for the fence to be signaled, the same
79 handle could be used over several frames.
80
81 \since 5.13
82 */
83QSetFence::QSetFence(Qt3DCore::QNode *parent)
84 : QFrameGraphNode(*new QSetFencePrivate(), parent)
85{
86}
87
88QSetFence::~QSetFence()
89{
90}
91
92QSetFence::QSetFence(QSetFencePrivate &dd, Qt3DCore::QNode *parent)
93 : QFrameGraphNode(dd, parent)
94{
95}
96
97/*!
98 \qmlproperty HandleType SetFence::handleType
99
100 Specifies the type of handle being used. Currently only OpenGL Fence ids
101 are supported.
102*/
103/*!
104 \property Qt3DRender::QSetFence::handleType
105
106 Specifies the type of handle being used. Currently only OpenGL Fence ids
107 are supported.
108*/
109QSetFence::HandleType QSetFence::handleType() const
110{
111 Q_D(const QSetFence);
112 return d->m_handleType;
113}
114
115void QSetFencePrivate::setHandleType(QSetFence::HandleType type)
116{
117 Q_Q(QSetFence);
118 if (m_handleType != type) {
119 const bool blocked = q->blockNotifications(block: true);
120 m_handleType = type;
121 emit q->handleTypeChanged(handleType: type);
122 q->blockNotifications(block: blocked);
123 }
124}
125
126/*!
127 \qmlproperty variant SetFence::handle
128
129 Holds the underlying fence handle wrapped in a variant.
130*/
131/*!
132 \property Qt3DRender::QSetFence::handle
133
134 Holds the underlying fence handle wrapped in a QVariant.
135*/
136QVariant QSetFence::handle() const
137{
138 Q_D(const QSetFence);
139 return d->m_handle;
140}
141
142void QSetFencePrivate::setHandle(QVariant handle)
143{
144 Q_Q(QSetFence);
145 if (m_handle != handle) {
146 const bool blocked = q->blockNotifications(block: true);
147 m_handle = handle;
148 emit q->handleChanged(handle);
149 q->blockNotifications(block: blocked);
150 }
151}
152
153void QSetFence::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change)
154{
155 Qt3DCore::QPropertyUpdatedChangePtr e = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(src: change);
156 if (e->type() == Qt3DCore::PropertyUpdated) {
157 Q_D(QSetFence);
158 if (e->propertyName() == QByteArrayLiteral("handle"))
159 d->setHandle(e->value());
160 else if (e->propertyName() == QByteArrayLiteral("handleType"))
161 d->setHandleType(static_cast<Qt3DRender::QSetFence::HandleType>(e->value().toInt()));
162 }
163}
164
165Qt3DCore::QNodeCreatedChangeBasePtr QSetFence::createNodeCreationChange() const
166{
167 auto creationChange = QFrameGraphNodeCreatedChangePtr<QSetFenceData>::create(arguments: this);
168 QSetFenceData &data = creationChange->data;
169 Q_UNUSED(data); // Might be of use later
170 return creationChange;
171}
172
173} // Qt3DRender
174
175QT_END_NAMESPACE
176

source code of qt3d/src/render/framegraph/qsetfence.cpp