summaryrefslogtreecommitdiffstats
path: root/src/render/frontend/qlayer.cpp
blob: 0859becfc9afff64d6d4a0fd997258db1eba2d28 (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
/****************************************************************************
**
** 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 "qlayer.h"
#include "qlayer_p.h"

QT_BEGIN_NAMESPACE

namespace Qt3DRender {

QLayerPrivate::QLayerPrivate()
    : QComponentPrivate()
    , m_recursive(false)
{
}

/*!
    \class Qt3DRender::QLayer
    \inmodule Qt3DRender
    \since 5.5
    \brief The QLayer class provides a way of filtering which entities will be rendered.

    Qt3DRender::QLayer works in conjunction with the Qt3DRender::QLayerFilter in the FrameGraph.
    \sa Qt3DRender::QLayerFilter

    A QLayer can be applied to a subtree of entities by setting the recursive property to true.

    \code
     #include <Qt3DCore/QEntity>
     #include <Qt3DRender/QGeometryRenderer>
     #include <Qt3DRender/QLayer>
     #include <Qt3DRender/QLayerFilter>
     #include <Qt3DRender/QViewport>

    // Scene
    Qt3DCore::QEntity *rootEntity = new Qt3DCore::Qt3DCore::QEntity;

    Qt3DCore::QEntity *renderableEntity = new Qt3DCore::Qt3DCore::QEntity(rootEntity);
    Qt3DRender::QGeometryRenderer *geometryRenderer = new Qt3DCore::QGeometryRenderer(renderableEntity);
    Qt3DRender::QLayer *layer1 = new Qt3DCore::QLayer(renderableEntity);
    layer1->setRecursive(true);
    renderableEntity->addComponent(geometryRenderer);
    renderableEntity->addComponent(layer1);

    ...

    // FrameGraph
    Qt3DRender::QViewport *viewport = new Qt3DRender::QViewport;
    Qt3DRender::QLayerFilter *layerFilter = new Qt3DRender::QLayerFilter(viewport);
    layerFilter->addLayer(layer1);

    ...
    \endcode
*/
/*!
    \property QLayer::recursive
    Specifies if the layer is also applied to the entity subtree.
*/

/*!
    \qmltype Layer
    \instantiates Qt3DRender::QLayer
    \inherits Component3D
    \inqmlmodule Qt3D.Render
    \since 5.5
    \sa LayerFilter
    \brief Layer provides a way of filtering which entities will be rendered.

    Layer works in conjunction with the LayerFilter in the FrameGraph.

    A Layer can be applied to a subtree of entities by setting the recursive property to true.

    \code
    import Qt3D.Core 2.0
    import Qt3D.Render 2.0

    Entity {
        id: root

        components: RenderSettings {
            // FrameGraph
            Viewport {
                ClearBuffers {
                    buffers: ClearBuffers.ColorDepthBuffer
                    CameraSelector {
                        camera: mainCamera
                        LayerFilter {
                            layers: [layer1]
                        }
                    }
                }
            }
        }

        // Scene
        Camera { id: mainCamera }

        Layer {
            id: layer1
            recursive: true
        }

        GeometryRenderer { id: mesh }

        Entity {
            id: renderableEntity
            components: [ mesh, layer1 ]
        }
    }
    \endcode
*/

/*!
    \qmlproperty bool Layer::recursive

    Specifies if the layer is also applied to the entity subtree.
*/

/*! \fn Qt3DRender::QLayer::QLayer(Qt3DCore::QNode *parent)
  Constructs a new QLayer with the specified \a parent.
 */

QLayer::QLayer(QNode *parent)
    : QComponent(*new QLayerPrivate, parent)
{
}

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

bool QLayer::recursive() const
{
    Q_D(const QLayer);
    return d->m_recursive;
}

void QLayer::setRecursive(bool recursive)
{
    Q_D(QLayer);
    if (d->m_recursive != recursive) {
        d->m_recursive = recursive;
        emit recursiveChanged();
    }
}

/*! \internal */
QLayer::QLayer(QLayerPrivate &dd, QNode *parent)
    : QComponent(dd, parent)
{
}

Qt3DCore::QNodeCreatedChangeBasePtr QLayer::createNodeCreationChange() const
{
    auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QLayerData>::create(this);
    auto &data = creationChange->data;
    Q_D(const QLayer);
    data.m_recursive = d->m_recursive;
    return creationChange;
}

} // namespace Qt3DRender

QT_END_NAMESPACE