1// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qtechniquefilter.h"
5#include "qtechniquefilter_p.h"
6#include <Qt3DRender/qfilterkey.h>
7#include <Qt3DRender/qparameter.h>
8
9QT_BEGIN_NAMESPACE
10
11using namespace Qt3DCore;
12
13namespace Qt3DRender {
14
15QTechniqueFilterPrivate::QTechniqueFilterPrivate()
16 : QFrameGraphNodePrivate()
17{
18}
19
20/*!
21 \class Qt3DRender::QTechniqueFilter
22 \inmodule Qt3DRender
23 \since 5.7
24 \brief A QFrameGraphNode used to select QTechniques to use.
25
26 A Qt3DRender::QTechniqueFilter specifies which techniques are used
27 by the FrameGraph when rendering the entities. QTechniqueFilter specifies
28 a list of Qt3DRender::QFilterKey objects and Qt3DRender::QParameter objects.
29 When QTechniqueFilter is present in the FrameGraph, only the techiques matching
30 the keys in the list are used for rendering. The parameters in the list can be used
31 to set values for shader parameters. The parameters in QTechniqueFilter
32 override parameters in QMaterial, QEffect, QTechnique and QRenderPass, but are overridden
33 by parameters in QRenderPassFilter.
34*/
35
36/*!
37 \qmltype TechniqueFilter
38 \inqmlmodule Qt3D.Render
39 \instantiates Qt3DRender::QTechniqueFilter
40 \inherits FrameGraphNode
41 \since 5.7
42 \brief A FrameGraphNode used to select used Techniques.
43
44 A TechniqueFilter specifies which techniques are used by the FrameGraph
45 when rendering the entities. TechniqueFilter specifies
46 a list of FilterKey objects and Parameter objects.
47 When TechniqueFilter is present in the FrameGraph, only the techiques matching
48 the keys in list are used for rendering. The parameters in the list can be used
49 to set values for shader parameters. The parameters in TechniqueFilter
50 override parameters in Material, Effect, Technique and RenderPass, but are overridden
51 by parameters in RenderPassFilter.
52*/
53
54/*!
55 \qmlproperty list<FilterKey> TechniqueFilter::matchAll
56 Holds the list of filterkeys used by the TechiqueFilter
57*/
58
59/*!
60 \qmlproperty list<Parameter> TechniqueFilter::parameters
61 Holds the list of parameters used by the TechiqueFilter
62*/
63
64/*!
65 The constructor creates an instance with the specified \a parent.
66 */
67QTechniqueFilter::QTechniqueFilter(QNode *parent)
68 : QFrameGraphNode(*new QTechniqueFilterPrivate, parent)
69{
70}
71
72/*! \internal */
73QTechniqueFilter::~QTechniqueFilter()
74{
75}
76
77/*! \internal */
78QTechniqueFilter::QTechniqueFilter(QTechniqueFilterPrivate &dd, QNode *parent)
79 : QFrameGraphNode(dd, parent)
80{
81}
82
83/*!
84 Returns a vector of the current keys for the filter.
85 */
86QList<QFilterKey *> QTechniqueFilter::matchAll() const
87{
88 Q_D(const QTechniqueFilter);
89 return d->m_matchList;
90}
91
92/*!
93 Add the \a filterKey to the match vector.
94 */
95void QTechniqueFilter::addMatch(QFilterKey *filterKey)
96{
97 Q_ASSERT(filterKey);
98 Q_D(QTechniqueFilter);
99 if (!d->m_matchList.contains(t: filterKey)) {
100 d->m_matchList.append(t: filterKey);
101
102 // Ensures proper bookkeeping
103 d->registerDestructionHelper(node: filterKey, func: &QTechniqueFilter::removeMatch, d->m_matchList);
104
105 // We need to add it as a child of the current node if it has been declared inline
106 // Or not previously added as a child of the current node so that
107 // 1) The backend gets notified about it's creation
108 // 2) When the current node is destroyed, it gets destroyed as well
109 if (!filterKey->parent())
110 filterKey->setParent(this);
111
112 d->update();
113 }
114}
115
116/*!
117 Remove the \a filterKey from the match vector.
118 */
119void QTechniqueFilter::removeMatch(QFilterKey *filterKey)
120{
121 Q_ASSERT(filterKey);
122 Q_D(QTechniqueFilter);
123 if (!d->m_matchList.removeOne(t: filterKey))
124 return;
125 d->update();
126 // Remove bookkeeping connection
127 d->unregisterDestructionHelper(node: filterKey);
128}
129
130/*!
131 Add \a parameter to the vector of parameters that will be passed to the graphics pipeline.
132 */
133void QTechniqueFilter::addParameter(QParameter *parameter)
134{
135 Q_ASSERT(parameter);
136 Q_D(QTechniqueFilter);
137 if (!d->m_parameters.contains(t: parameter)) {
138 d->m_parameters.append(t: parameter);
139
140 // Ensures proper bookkeeping
141 d->registerDestructionHelper(node: parameter, func: &QTechniqueFilter::removeParameter, d->m_parameters);
142
143 // We need to add it as a child of the current node if it has been declared inline
144 // Or not previously added as a child of the current node so that
145 // 1) The backend gets notified about it's creation
146 // 2) When the current node is destroyed, the child parameters get destroyed as well
147 if (!parameter->parent())
148 parameter->setParent(this);
149
150 d->update();
151 }
152}
153
154/*!
155 Remove \a parameter from the vector of parameters passed to the graphics pipeline.
156 */
157void QTechniqueFilter::removeParameter(QParameter *parameter)
158{
159 Q_ASSERT(parameter);
160 Q_D(QTechniqueFilter);
161 if (!d->m_parameters.removeOne(t: parameter))
162 return;
163 d->update();
164 // Remove bookkeeping connection
165 d->unregisterDestructionHelper(node: parameter);
166}
167
168/*!
169 Returns the current vector of parameters.
170 */
171QList<QParameter *> QTechniqueFilter::parameters() const
172{
173 Q_D(const QTechniqueFilter);
174 return d->m_parameters;
175}
176
177} // namespace Qt3DRender
178
179QT_END_NAMESPACE
180
181#include "moc_qtechniquefilter.cpp"
182

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