1/****************************************************************************
2**
3** Copyright (C) 2014 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 "qrenderpassfilter.h"
41#include "qrenderpassfilter_p.h"
42
43#include <Qt3DRender/qfilterkey.h>
44#include <Qt3DRender/qparameter.h>
45#include <Qt3DRender/qframegraphnodecreatedchange.h>
46
47QT_BEGIN_NAMESPACE
48
49using namespace Qt3DCore;
50
51namespace Qt3DRender {
52
53/*!
54 \class Qt3DRender::QRenderPassFilter
55 \inmodule Qt3DRender
56 \since 5.7
57 \brief Provides storage for vectors of Filter Keys and Parameters.
58
59 A Qt3DRender::QRenderPassFilter FrameGraph node is used to select which
60 Qt3DRender::QRenderPass objects are selected for drawing. QRenderPassFilter
61 specifies a list of Qt3DRender::QFilterKey objects and Qt3DRender::QParameter objects.
62 When QRenderPassFilter is present in the FrameGraph, only the QRenderPass objects,
63 whose Qt3DRender::QFilterKey objects match the keys in QRenderPassFilter are
64 selected for rendering. If no QRenderPassFilter is present, then all QRenderPass
65 objects are selected for rendering. The parameters in the list can be used
66 to set values for shader parameters. The parameters in QRenderPassFilter
67 override parameters in QTechniqueFilter, QMaterial, QEffect, QTechnique and QRenderPass.
68*/
69
70/*!
71 \qmltype RenderPassFilter
72 \inqmlmodule Qt3D.Render
73 \since 5.7
74 \instantiates Qt3DRender::QRenderPassFilter
75 \inherits FrameGraphNode
76 \brief Provides storage for vectors of Filter Keys and Parameters.
77
78 A RenderPassFilter FrameGraph node is used to select which RenderPass
79 objects are selected for drawing. When RenderPassFilter is present in the FrameGraph,
80 only the RenderPass objects, whose FilterKey objects match the keys
81 in RenderPassFilter are selected for rendering. If no RenderPassFilter is present,
82 then all RenderPass objects are selected for rendering. RenderPassFilter
83 specifies a list of Parameter objects. The parameters in the list can be used
84 to set values for shader parameters. The parameters in RenderPassFilter
85 override parameters in TechniqueFilter, Material, Effect, Technique and RenderPass.
86*/
87
88/*!
89 \qmlproperty list<FilterKey> RenderPassFilter::matchAny
90 Holds the list of filterkeys used by the RenderPassFilter
91*/
92/*!
93 \qmlproperty list<Parameter> RenderPassFilter::parameters
94 Holds the list of parameters used by the RenderPassFilter
95*/
96
97
98/*!
99 The constructor creates an instance with the specified \a parent.
100 */
101QRenderPassFilter::QRenderPassFilter(QNode *parent)
102 : QFrameGraphNode(*new QRenderPassFilterPrivate, parent)
103{}
104
105/*! \internal */
106QRenderPassFilter::~QRenderPassFilter()
107{
108}
109
110/*! \internal */
111QRenderPassFilter::QRenderPassFilter(QRenderPassFilterPrivate &dd, QNode *parent)
112 : QFrameGraphNode(dd, parent)
113{
114}
115
116/*!
117 Returns a vector of the current keys for the filter.
118 */
119QVector<QFilterKey *> QRenderPassFilter::matchAny() const
120{
121 Q_D(const QRenderPassFilter);
122 return d->m_matchList;
123}
124
125/*!
126 Add the \a filterKey to the match vector.
127 */
128void QRenderPassFilter::addMatch(QFilterKey *filterKey)
129{
130 Q_ASSERT(filterKey);
131 Q_D(QRenderPassFilter);
132 if (!d->m_matchList.contains(t: filterKey)) {
133 d->m_matchList.append(t: filterKey);
134
135 // Ensures proper bookkeeping
136 d->registerDestructionHelper(node: filterKey, func: &QRenderPassFilter::removeMatch, d->m_matchList);
137
138 // We need to add it as a child of the current node if it has been declared inline
139 // Or not previously added as a child of the current node so that
140 // 1) The backend gets notified about it's creation
141 // 2) When the current node is destroyed, it gets destroyed as well
142 if (!filterKey->parent())
143 filterKey->setParent(this);
144
145 d->updateNode(node: filterKey, property: "match", change: Qt3DCore::PropertyValueAdded);
146 }
147}
148
149/*!
150 Remove the \a filterKey from the match vector.
151 */
152void QRenderPassFilter::removeMatch(QFilterKey *filterKey)
153{
154 Q_ASSERT(filterKey);
155 Q_D(QRenderPassFilter);
156
157 if (!d->m_matchList.removeOne(t: filterKey))
158 return;
159 d->updateNode(node: filterKey, property: "match", change: Qt3DCore::PropertyValueRemoved);
160 // Remove bookkeeping connection
161 d->unregisterDestructionHelper(node: filterKey);
162}
163
164/*!
165 Add the given \a parameter to the parameter vector.
166 */
167void QRenderPassFilter::addParameter(QParameter *parameter)
168{
169 Q_ASSERT(parameter);
170 Q_D(QRenderPassFilter);
171 if (!d->m_parameters.contains(t: parameter)) {
172 d->m_parameters.append(t: parameter);
173
174 // Ensures proper bookkeeping
175 d->registerDestructionHelper(node: parameter, func: &QRenderPassFilter::removeParameter, d->m_parameters);
176
177 // We need to add it as a child of the current node if it has been declared inline
178 // Or not previously added as a child of the current node so that
179 // 1) The backend gets notified about it's creation
180 // 2) When the current node is destroyed, the child parameters get destroyed as well
181 if (!parameter->parent())
182 parameter->setParent(this);
183
184 d->updateNode(node: parameter, property: "parameter", change: Qt3DCore::PropertyValueAdded);
185 }
186}
187
188/*!
189 Remove the given \a parameter from the parameter vector.
190 */
191void QRenderPassFilter::removeParameter(QParameter *parameter)
192{
193 Q_ASSERT(parameter);
194 Q_D(QRenderPassFilter);
195
196 if (!d->m_parameters.removeOne(t: parameter))
197 return;
198 d->updateNode(node: parameter, property: "parameter", change: Qt3DCore::PropertyValueRemoved);
199 // Remove bookkeeping connection
200 d->unregisterDestructionHelper(node: parameter);
201}
202
203/*!
204 Returns the current vector of parameters.
205 */
206QVector<QParameter *> QRenderPassFilter::parameters() const
207{
208 Q_D(const QRenderPassFilter);
209 return d->m_parameters;
210}
211
212Qt3DCore::QNodeCreatedChangeBasePtr QRenderPassFilter::createNodeCreationChange() const
213{
214 auto creationChange = QFrameGraphNodeCreatedChangePtr<QRenderPassFilterData>::create(arguments: this);
215 auto &data = creationChange->data;
216 Q_D(const QRenderPassFilter);
217 data.matchIds = qIdsForNodes(nodes: d->m_matchList);
218 data.parameterIds = qIdsForNodes(nodes: d->m_parameters);
219 return creationChange;
220}
221
222} // namespace Qt3DRender
223
224QT_END_NAMESPACE
225

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