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

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