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 "qlayer.h"
5#include "qlayer_p.h"
6
7QT_BEGIN_NAMESPACE
8
9namespace Qt3DRender {
10
11QLayerPrivate::QLayerPrivate()
12 : QComponentPrivate()
13 , m_recursive(false)
14{
15}
16
17/*!
18 \class Qt3DRender::QLayer
19 \inmodule Qt3DRender
20 \since 5.5
21 \brief The QLayer class provides a way of filtering which entities will be rendered.
22
23 Qt3DRender::QLayer works in conjunction with the Qt3DRender::QLayerFilter in the FrameGraph.
24 \sa Qt3DRender::QLayerFilter
25
26 A QLayer can be applied to a subtree of entities by setting the recursive property to true.
27
28 \code
29 #include <Qt3DCore/QEntity>
30 #include <Qt3DRender/QGeometryRenderer>
31 #include <Qt3DRender/QLayer>
32 #include <Qt3DRender/QLayerFilter>
33 #include <Qt3DRender/QViewport>
34
35 // Scene
36 Qt3DCore::QEntity *rootEntity = new Qt3DCore::Qt3DCore::QEntity;
37
38 Qt3DCore::QEntity *renderableEntity = new Qt3DCore::Qt3DCore::QEntity(rootEntity);
39 Qt3DRender::QGeometryRenderer *geometryRenderer = new Qt3DCore::QGeometryRenderer(renderableEntity);
40 Qt3DRender::QLayer *layer1 = new Qt3DCore::QLayer(renderableEntity);
41 layer1->setRecursive(true);
42 renderableEntity->addComponent(geometryRenderer);
43 renderableEntity->addComponent(layer1);
44
45 ...
46
47 // FrameGraph
48 Qt3DRender::QViewport *viewport = new Qt3DRender::QViewport;
49 Qt3DRender::QLayerFilter *layerFilter = new Qt3DRender::QLayerFilter(viewport);
50 layerFilter->addLayer(layer1);
51
52 ...
53 \endcode
54*/
55/*!
56 \property QLayer::recursive
57 Specifies if the layer is also applied to the entity subtree.
58*/
59
60/*!
61 \qmltype Layer
62 \instantiates Qt3DRender::QLayer
63 \inherits Component3D
64 \inqmlmodule Qt3D.Render
65 \since 5.5
66 \sa LayerFilter
67 \brief Layer provides a way of filtering which entities will be rendered.
68
69 Layer works in conjunction with the LayerFilter in the FrameGraph.
70
71 A Layer can be applied to a subtree of entities by setting the recursive property to true.
72
73 \code
74 import Qt3D.Core 2.0
75 import Qt3D.Render 2.0
76
77 Entity {
78 id: root
79
80 components: RenderSettings {
81 // FrameGraph
82 Viewport {
83 ClearBuffers {
84 buffers: ClearBuffers.ColorDepthBuffer
85 CameraSelector {
86 camera: mainCamera
87 LayerFilter {
88 layers: [layer1]
89 }
90 }
91 }
92 }
93 }
94
95 // Scene
96 Camera { id: mainCamera }
97
98 Layer {
99 id: layer1
100 recursive: true
101 }
102
103 GeometryRenderer { id: mesh }
104
105 Entity {
106 id: renderableEntity
107 components: [ mesh, layer1 ]
108 }
109 }
110 \endcode
111*/
112
113/*!
114 \qmlproperty bool Layer::recursive
115
116 Specifies if the layer is also applied to the entity subtree.
117*/
118
119/*! \fn Qt3DRender::QLayer::QLayer(Qt3DCore::QNode *parent)
120 Constructs a new QLayer with the specified \a parent.
121 */
122
123QLayer::QLayer(QNode *parent)
124 : QComponent(*new QLayerPrivate, parent)
125{
126}
127
128/*! \internal */
129QLayer::~QLayer()
130{
131}
132
133bool QLayer::recursive() const
134{
135 Q_D(const QLayer);
136 return d->m_recursive;
137}
138
139void QLayer::setRecursive(bool recursive)
140{
141 Q_D(QLayer);
142 if (d->m_recursive != recursive) {
143 d->m_recursive = recursive;
144 emit recursiveChanged();
145 }
146}
147
148/*! \internal */
149QLayer::QLayer(QLayerPrivate &dd, QNode *parent)
150 : QComponent(dd, parent)
151{
152}
153
154} // namespace Qt3DRender
155
156QT_END_NAMESPACE
157
158#include "moc_qlayer.cpp"
159

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