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 "qlayerfilter.h"
5#include "qlayerfilter_p.h"
6#include "qlayer.h"
7
8QT_BEGIN_NAMESPACE
9
10namespace Qt3DRender {
11
12QLayerFilterPrivate::QLayerFilterPrivate()
13 : QFrameGraphNodePrivate()
14 , m_filterMode(QLayerFilter::AcceptAnyMatchingLayers)
15{
16}
17
18/*!
19 \class Qt3DRender::QLayerFilter
20 \inmodule Qt3DRender
21 \since 5.5
22 \brief Controls layers drawn in a frame graph branch.
23
24 A Qt3DRender::QLayerFilter can be used to instruct the renderer as to
25 which layer(s) to draw in that branch of the frame graph. QLayerFilter
26 selects which entities to draw based on the QLayer instance(s) added to
27 the QLayerFilter and as components to Qt3DCore::QEntity.
28
29 QLayerFilter can be configured to select or discard entities with a
30 specific \l QLayer depending on the filterMode property. By default,
31 entities referencing one of the \l QLayer objects that are also being
32 referenced by the \l QLayerFilter are selected (AcceptAnyMatchingLayers).
33
34 Within the FrameGraph tree, multiple \l QLayerFilter nodes can be nested
35 within a branch going from root to a leaf. In that case the filtering will
36 first operate on all entities of the scene using the filtering method
37 specified by the first declared \l QLayerFilter. Then the filtered subset
38 of entities will be filtered again based on the filtering method set on the
39 second \l QLayerFilter declared. This is then repeated until all \l
40 QLayerFilter nodes of the branch have been consumed.
41*/
42
43/*!
44 \enum QLayerFilter::FilterMode
45
46 Specifies the rules for selecting entities to draw.
47
48 \value AcceptAnyMatchingLayers
49 Accept entities that reference one or more \l QLayer objects added to this
50 QLayerFilter. This is the default
51
52 \value AcceptAllMatchingLayers
53 Accept entities that reference all the \l QLayer objects added to this
54 QLayerFilter
55
56 \value DiscardAnyMatchingLayers
57 Discard entities that reference one or more \l QLayer objects added to this
58 QLayerFilter
59
60 \value DiscardAllMatchingLayers
61 Discard entities that reference all \l QLayer objects added to this
62 QLayerFilter
63*/
64
65/*!
66 \property Qt3DRender::QLayerFilter::filterMode
67
68 Holds the filter mode specifying the entities to select for drawing.
69
70 The default value is AcceptMatchingLayers.
71*/
72
73/*!
74 \qmltype LayerFilter
75 \instantiates Qt3DRender::QLayerFilter
76 \inherits FrameGraphNode
77 \inqmlmodule Qt3D.Render
78 \since 5.5
79 \brief Controls layers drawn in a frame graph branch.
80
81 A LayerFilter can be used to instruct the renderer as to which layer(s)
82 to draw in that branch of the frame graph. The LayerFilter selects which
83 entities to draw based on the \l Layer instances added to the LayerFilter
84 and as components to the \l Entity.
85
86 The LayerFilter can be configured to select or discard entities with a
87 specific \l Layer depending on the filterMode property. By default,
88 entities referencing one of the \l Layer objects that are also being
89 referenced by the \l LayerFilter are selected (AcceptAnyMatchingLayers).
90
91 Within the FrameGraph tree, multiple \l LayerFilter nodes can be nested
92 within a branch going from root to a leaf. In that case the filtering will
93 first operate on all entities of the scene using the filtering method
94 specified by the first declared \l LayerFilter. Then the filtered subset of
95 entities will be filtered again based on the filtering method set on the
96 second \l LayerFilter declared. This is then repeated until all \l
97 LayerFilter nodes of the branch have been consumed.
98*/
99
100/*!
101 \qmlproperty list<Layer> Qt3D.Render::LayerFilter::layers
102 Holds a list of layers specifying the layers to select for drawing.
103 \readonly
104 */
105
106/*!
107 \qmlproperty enumeration Qt3D.Render::LayerFilter::filterMode
108
109 Holds the filter mode specifying the entities to select for drawing.
110
111 The default value is \c {LayerFilter.AcceptMatchingLayers}.
112
113 \value LayerFilter.AcceptAnyMatchingLayers
114 Accept entities that reference one or more \l Layer objects added to this
115 LayerFilter. This is the default
116
117 \value LayerFilter.AcceptAllMatchingLayers
118 Accept entities that reference all the \l Layer objects added to this
119 LayerFilter
120
121 \value LayerFilter.DiscardAnyMatchingLayers
122 Discard entities that reference one or more \l Layer objects added to this
123 LayerFilter
124
125 \value LayerFilter.DiscardAllMatchingLayers
126 Discard entities that reference all \l Layer objects added to this
127 LayerFilter
128*/
129
130/*!
131 The constructor creates an instance with the specified \a parent.
132 */
133QLayerFilter::QLayerFilter(QNode *parent)
134 : QFrameGraphNode(*new QLayerFilterPrivate, parent)
135{
136}
137
138/*! \internal */
139QLayerFilter::QLayerFilter(QLayerFilterPrivate &dd, QNode *parent)
140 : QFrameGraphNode(dd, parent)
141{
142}
143
144/*! \internal */
145QLayerFilter::~QLayerFilter()
146{
147}
148
149/*!
150 Add \a layer to the current list of layers
151 */
152void QLayerFilter::addLayer(QLayer *layer)
153{
154 Q_ASSERT(layer);
155 Q_D(QLayerFilter);
156 if (!d->m_layers.contains(t: layer)) {
157 d->m_layers.append(t: layer);
158
159 // Ensures proper bookkeeping
160 d->registerDestructionHelper(node: layer, func: &QLayerFilter::removeLayer, d->m_layers);
161
162 // We need to add it as a child of the current node if it has been declared inline
163 // Or not previously added as a child of the current node so that
164 // 1) The backend gets notified about it's creation
165 // 2) When the current node is destroyed, it gets destroyed as well
166 if (!layer->parent())
167 layer->setParent(this);
168
169 d->update();
170 }
171}
172
173/*!
174 Remove \a layer from the current list of layers
175 */
176void QLayerFilter::removeLayer(QLayer *layer)
177{
178 Q_ASSERT(layer);
179 Q_D(QLayerFilter);
180 if (!d->m_layers.removeOne(t: layer))
181 return;
182 d->update();
183 // Remove bookkeeping connection
184 d->unregisterDestructionHelper(node: layer);
185}
186
187/*!
188 \return the current list of layers
189 */
190QList<QLayer *> QLayerFilter::layers() const
191{
192 Q_D(const QLayerFilter);
193 return d->m_layers;
194}
195
196QLayerFilter::FilterMode QLayerFilter::filterMode() const
197{
198 Q_D(const QLayerFilter);
199 return d->m_filterMode;
200}
201
202void QLayerFilter::setFilterMode(QLayerFilter::FilterMode filterMode)
203{
204 Q_D(QLayerFilter);
205 if (d->m_filterMode != filterMode) {
206 d->m_filterMode = filterMode;
207 emit filterModeChanged(filterMode);
208 }
209}
210
211} // namespace Qt3DRender
212
213QT_END_NAMESPACE
214
215#include "moc_qlayerfilter.cpp"
216

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