summaryrefslogtreecommitdiffstats
path: root/src/render/framegraph/qlayerfilter.cpp
blob: 3b2c8f2ba490c5389c85875bfa243a4683d1d77e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/****************************************************************************
**
** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt3D module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:COMM$
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** $QT_END_LICENSE$
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
****************************************************************************/

#include "qlayerfilter.h"
#include "qlayerfilter_p.h"
#include "qlayer.h"
#include <Qt3DRender/qframegraphnodecreatedchange.h>

QT_BEGIN_NAMESPACE

namespace Qt3DRender {

QLayerFilterPrivate::QLayerFilterPrivate()
    : QFrameGraphNodePrivate()
    , m_filterMode(QLayerFilter::AcceptAnyMatchingLayers)
{
}

/*!
    \class Qt3DRender::QLayerFilter
    \inmodule Qt3DRender
    \since 5.5
    \brief Controls layers drawn in a frame graph branch.

    A Qt3DRender::QLayerFilter can be used to instruct the renderer as to
    which layer(s) to draw in that branch of the frame graph. QLayerFilter
    selects which entities to draw based on the QLayer instance(s) added to
    the QLayerFilter and as components to Qt3DCore::QEntity.

    QLayerFilter can be configured to select or discard entities with a
    specific \l QLayer depending on the filterMode property. By default,
    entities referencing one of the \l QLayer objects that are also being
    referenced by the \l QLayerFilter are selected (AcceptAnyMatchingLayers).

    Within the FrameGraph tree, multiple \l QLayerFilter nodes can be nested
    within a branch going from root to a leaf. In that case the filtering will
    first operate on all entities of the scene using the filtering method
    specified by the first declared \l QLayerFilter. Then the filtered subset
    of entities will be filtered again based on the filtering method set on the
    second \l QLayerFilter declared. This is then repeated until all \l
    QLayerFilter nodes of the branch have been consumed.
*/

/*!
    \enum QLayerFilter::FilterMode

    Specifies the rules for selecting entities to draw.

    \value AcceptAnyMatchingLayers
    Accept entities that reference one or more \l QLayer objects added to this
    QLayerFilter. This is the default

    \value AcceptAllMatchingLayers
    Accept entities that reference all the \l QLayer objects added to this
    QLayerFilter

    \value DiscardAnyMatchingLayers
    Discard entities that reference one or more \l QLayer objects added to this
    QLayerFilter

    \value DiscardAllMatchingLayers
    Discard entities that reference all \l QLayer objects added to this
    QLayerFilter
*/

/*!
    \property Qt3DRender::QLayerFilter::filterMode

    Holds the filter mode specifying the entities to select for drawing.

    The default value is AcceptMatchingLayers.
*/

/*!
    \qmltype LayerFilter
    \instantiates Qt3DRender::QLayerFilter
    \inherits FrameGraphNode
    \inqmlmodule Qt3D.Render
    \since 5.5
    \brief Controls layers drawn in a frame graph branch.

    A LayerFilter can be used to instruct the renderer as to which layer(s)
    to draw in that branch of the frame graph. The LayerFilter selects which
    entities to draw based on the \l Layer instances added to the LayerFilter
    and as components to the \l Entity.

    The LayerFilter can be configured to select or discard entities with a
    specific \l Layer depending on the filterMode property. By default,
    entities referencing one of the \l Layer objects that are also being
    referenced by the \l LayerFilter are selected (AcceptAnyMatchingLayers).

    Within the FrameGraph tree, multiple \l LayerFilter nodes can be nested
    within a branch going from root to a leaf. In that case the filtering will
    first operate on all entities of the scene using the filtering method
    specified by the first declared \l LayerFilter. Then the filtered subset of
    entities will be filtered again based on the filtering method set on the
    second \l LayerFilter declared. This is then repeated until all \l
    LayerFilter nodes of the branch have been consumed.
*/

/*!
    \qmlproperty list<Layer> Qt3D.Render::LayerFilter::layers
    Holds a list of layers specifying the layers to select for drawing.
    \readonly
 */

/*!
    \qmlproperty enumeration Qt3DRender::LayerFilter::filterMode

    Holds the filter mode specifying the entities to select for drawing.

    The default value is \c {LayerFilter.AcceptMatchingLayers}.

    \value LayerFilter.AcceptAnyMatchingLayers
    Accept entities that reference one or more \l Layer objects added to this
    LayerFilter. This is the default

    \value LayerFilter.AcceptAllMatchingLayers
    Accept entities that reference all the \l Layer objects added to this
    LayerFilter

    \value LayerFilter.DiscardAnyMatchingLayers
    Discard entities that reference one or more \l Layer objects added to this
    LayerFilter

    \value LayerFilter.DiscardAllMatchingLayers
    Discard entities that reference all \l Layer objects added to this
    LayerFilter
*/

/*!
    The constructor creates an instance with the specified \a parent.
 */
QLayerFilter::QLayerFilter(QNode *parent)
    : QFrameGraphNode(*new QLayerFilterPrivate, parent)
{
}

/*! \internal */
QLayerFilter::QLayerFilter(QLayerFilterPrivate &dd, QNode *parent)
    : QFrameGraphNode(dd, parent)
{
}

/*! \internal */
QLayerFilter::~QLayerFilter()
{
}

/*!
    Add \a layer to the current list of layers
 */
void QLayerFilter::addLayer(QLayer *layer)
{
    Q_ASSERT(layer);
    Q_D(QLayerFilter);
    if (!d->m_layers.contains(layer)) {
        d->m_layers.append(layer);

        // Ensures proper bookkeeping
        d->registerDestructionHelper(layer, &QLayerFilter::removeLayer, d->m_layers);

        // We need to add it as a child of the current node if it has been declared inline
        // Or not previously added as a child of the current node so that
        // 1) The backend gets notified about it's creation
        // 2) When the current node is destroyed, it gets destroyed as well
        if (!layer->parent())
            layer->setParent(this);

        d->updateNode(layer, "layer", Qt3DCore::PropertyValueAdded);
    }
}

/*!
    Remove \a layer from the current list of layers
 */
void QLayerFilter::removeLayer(QLayer *layer)
{
    Q_ASSERT(layer);
    Q_D(QLayerFilter);
    if (!d->m_layers.removeOne(layer))
        return;
    d->updateNode(layer, "layer", Qt3DCore::PropertyValueRemoved);
    // Remove bookkeeping connection
    d->unregisterDestructionHelper(layer);
}

/*!
    \return the current list of layers
 */
QVector<QLayer *> QLayerFilter::layers() const
{
    Q_D(const QLayerFilter);
    return d->m_layers;
}

QLayerFilter::FilterMode QLayerFilter::filterMode() const
{
    Q_D(const QLayerFilter);
    return d->m_filterMode;
}

void QLayerFilter::setFilterMode(QLayerFilter::FilterMode filterMode)
{
    Q_D(QLayerFilter);
    if (d->m_filterMode != filterMode) {
        d->m_filterMode = filterMode;
        emit filterModeChanged(filterMode);
    }
}

Qt3DCore::QNodeCreatedChangeBasePtr QLayerFilter::createNodeCreationChange() const
{
    auto creationChange = QFrameGraphNodeCreatedChangePtr<QLayerFilterData>::create(this);
    auto &data = creationChange->data;
    Q_D(const QLayerFilter);
    data.layerIds = qIdsForNodes(d->m_layers);
    data.filterMode = d->m_filterMode;
    return creationChange;
}

} // namespace Qt3DRender

QT_END_NAMESPACE