1/****************************************************************************
2**
3** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qlayer.h"
41#include "qlayer_p.h"
42
43QT_BEGIN_NAMESPACE
44
45namespace Qt3DRender {
46
47QLayerPrivate::QLayerPrivate()
48 : QComponentPrivate()
49 , m_recursive(false)
50{
51}
52
53/*!
54 \class Qt3DRender::QLayer
55 \inmodule Qt3DRender
56 \since 5.5
57 \brief The QLayer class provides a way of filtering which entities will be rendered.
58
59 Qt3DRender::QLayer works in conjunction with the Qt3DRender::QLayerFilter in the FrameGraph.
60 \sa Qt3DRender::QLayerFilter
61
62 A QLayer can be applied to a subtree of entities by setting the recursive property to true.
63
64 \code
65 #include <Qt3DCore/QEntity>
66 #include <Qt3DRender/QGeometryRenderer>
67 #include <Qt3DRender/QLayer>
68 #include <Qt3DRender/QLayerFilter>
69 #include <Qt3DRender/QViewport>
70
71 // Scene
72 Qt3DCore::QEntity *rootEntity = new Qt3DCore::Qt3DCore::QEntity;
73
74 Qt3DCore::QEntity *renderableEntity = new Qt3DCore::Qt3DCore::QEntity(rootEntity);
75 Qt3DRender::QGeometryRenderer *geometryRenderer = new Qt3DCore::QGeometryRenderer(renderableEntity);
76 Qt3DRender::QLayer *layer1 = new Qt3DCore::QLayer(renderableEntity);
77 layer1->setRecursive(true);
78 renderableEntity->addComponent(geometryRenderer);
79 renderableEntity->addComponent(layer1);
80
81 ...
82
83 // FrameGraph
84 Qt3DRender::QViewport *viewport = new Qt3DRender::QViewport;
85 Qt3DRender::QLayerFilter *layerFilter = new Qt3DRender::QLayerFilter(viewport);
86 layerFilter->addLayer(layer1);
87
88 ...
89 \endcode
90*/
91/*!
92 \property QLayer::recursive
93 Specifies if the layer is also applied to the entity subtree.
94*/
95
96/*!
97 \qmltype Layer
98 \instantiates Qt3DRender::QLayer
99 \inherits Component3D
100 \inqmlmodule Qt3D.Render
101 \since 5.5
102 \sa LayerFilter
103 \brief Layer provides a way of filtering which entities will be rendered.
104
105 Layer works in conjunction with the LayerFilter in the FrameGraph.
106
107 A Layer can be applied to a subtree of entities by setting the recursive property to true.
108
109 \code
110 import Qt3D.Core 2.0
111 import Qt3D.Render 2.0
112
113 Entity {
114 id: root
115
116 components: RenderSettings {
117 // FrameGraph
118 Viewport {
119 ClearBuffers {
120 buffers: ClearBuffers.ColorDepthBuffer
121 CameraSelector {
122 camera: mainCamera
123 LayerFilter {
124 layers: [layer1]
125 }
126 }
127 }
128 }
129 }
130
131 // Scene
132 Camera { id: mainCamera }
133
134 Layer {
135 id: layer1
136 recursive: true
137 }
138
139 GeometryRenderer { id: mesh }
140
141 Entity {
142 id: renderableEntity
143 components: [ mesh, layer1 ]
144 }
145 }
146 \endcode
147*/
148
149/*!
150 \qmlproperty bool Layer::recursive
151
152 Specifies if the layer is also applied to the entity subtree.
153*/
154
155/*! \fn Qt3DRender::QLayer::QLayer(Qt3DCore::QNode *parent)
156 Constructs a new QLayer with the specified \a parent.
157 */
158
159QLayer::QLayer(QNode *parent)
160 : QComponent(*new QLayerPrivate, parent)
161{
162}
163
164/*! \internal */
165QLayer::~QLayer()
166{
167}
168
169bool QLayer::recursive() const
170{
171 Q_D(const QLayer);
172 return d->m_recursive;
173}
174
175void QLayer::setRecursive(bool recursive)
176{
177 Q_D(QLayer);
178 if (d->m_recursive != recursive) {
179 d->m_recursive = recursive;
180 emit recursiveChanged();
181 }
182}
183
184/*! \internal */
185QLayer::QLayer(QLayerPrivate &dd, QNode *parent)
186 : QComponent(dd, parent)
187{
188}
189
190Qt3DCore::QNodeCreatedChangeBasePtr QLayer::createNodeCreationChange() const
191{
192 auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QLayerData>::create(arguments: this);
193 auto &data = creationChange->data;
194 Q_D(const QLayer);
195 data.m_recursive = d->m_recursive;
196 return creationChange;
197}
198
199} // namespace Qt3DRender
200
201QT_END_NAMESPACE
202

source code of qt3d/src/render/frontend/qlayer.cpp