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

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