1// Copyright (C) 2019 Ford Motor Company
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 "qsubtreeenabler_p.h"
5
6QT_BEGIN_NAMESPACE
7
8namespace Qt3DRender
9{
10
11/*!
12 \class Qt3DRender::QSubtreeEnabler
13 \inmodule Qt3DRender
14 \brief Enables or disables entire subtrees of framegraph nodes.
15 \since 5.14
16
17 While QFrameGraphNodes can be individually enabled and disabled via the
18 \c enabled property, this can become tedious when an entire path
19 needs to be turned on or off. QSubtreeEnabler is a convenience node
20 that makes this use case trivial, allowing all of its children to be
21 controlled by a single switch.
22
23 QSubtreeEnabler is enabled by default.
24*/
25
26/*!
27 \qmltype SubtreeEnabler
28 \inqmlmodule Qt3D.Render
29 \since 5.14
30 \instantiates Qt3DRender::QSubtreeEnabler
31 \inherits FrameGraphNode
32 \brief Enables or disables entire subtrees of frame graph nodes.
33
34 While FrameGraphNodes can be individually enabled and disabled via the
35 \c enabled property, this can become tedious when an entire path
36 needs to be turned on or off. SubtreeEnabler is a convenience node
37 that makes this use case trivial, allowing all of its children to be
38 controlled by a single switch.
39
40 For example, the following simplified frame graph includes a subtree for
41 debug rendering that can easily be enabled only when debugging.
42
43 \qml
44 RenderSurfaceSelector {
45 ClearBuffers {
46 Viewport {
47 CameraSelector {}
48 }
49 }
50
51 SubtreeEnabler {
52 enabled: showDebugView
53 Viewport {
54 CameraSelector {
55 RenderPassFilter {}
56 }
57 }
58 }
59 }
60 \endqml
61
62 SubtreeEnabler is enabled by default.
63 */
64
65QSubtreeEnabler::QSubtreeEnabler(Qt3DCore::QNode *parent)
66 : QFrameGraphNode(*new QSubtreeEnablerPrivate, parent)
67{
68}
69
70QSubtreeEnabler::~QSubtreeEnabler()
71{
72}
73
74/*!
75 \enum QSubtreeEnabler::Enablement
76
77 Specifies whether subtree enablement is persistent or transient.
78
79 \value Persistent
80 The value of enabled is persistent. This is the default.
81
82 \value SingleShot
83 The value of enabled will last for a single frame and then be reset to false.
84 This might be used for a subtree drawing to an FBO, for example, to only update
85 the FBO when the relevant portions of the scene changed.
86*/
87
88/*!
89 \qmlproperty enumeration Qt3D.Render::SubtreeEnabler::enablement
90 Controls whether subtree enablement is persistent or transient.
91
92 \value Persistent
93 The value of enabled is persistent. This is the default.
94
95 \value SingleShot
96 The value of enabled will last for a single frame and then be reset to false.
97 This might be used for a subtree drawing to an FBO, for example, to only update
98 the FBO when the relevant portions of the scene changed.
99*/
100
101/*!
102 \property Qt3DRender::QSubtreeEnabler::enablement
103 Controls whether subtree enablement is persistent or transient.
104*/
105QSubtreeEnabler::Enablement QSubtreeEnabler::enablement() const
106{
107 Q_D(const QSubtreeEnabler);
108 return d->m_enablement;
109}
110
111void QSubtreeEnabler::setEnablement(QSubtreeEnabler::Enablement enablement)
112{
113 Q_D(QSubtreeEnabler);
114 if (d->m_enablement == enablement)
115 return;
116 d->m_enablement = enablement;
117 emit enablementChanged(enablement: d->m_enablement);
118}
119
120/*!
121 \qmlmethod void Qt3D.Render::SubtreeEnabler::requestUpdate()
122 Requests that the subtree be enabled.
123
124 A conveninence method intended to be used with \c SingleShot enablement.
125 */
126
127/*!
128 Requests that the subtree be enabled.
129
130 A convenience method intended to be used with \c SingleShot enablement.
131 */
132void QSubtreeEnabler::requestUpdate()
133{
134 setEnabled(true);
135}
136
137} //Qt3DRender
138
139QT_END_NAMESPACE
140
141#include "moc_qsubtreeenabler.cpp"
142

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