1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2019 Ford Motor Company |
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 "qsubtreeenabler_p.h" |
41 | #include <Qt3DRender/qframegraphnodecreatedchange.h> |
42 | |
43 | QT_BEGIN_NAMESPACE |
44 | |
45 | namespace Qt3DRender |
46 | { |
47 | |
48 | /*! |
49 | \class Qt3DRender::QSubtreeEnabler |
50 | \inmodule Qt3DRender |
51 | \brief Enables or disables entire subtrees of framegraph nodes. |
52 | \since 5.14 |
53 | |
54 | While QFrameGraphNodes can be individually enabled and disabled via the |
55 | \c enabled property, this can become tedious when an entire path |
56 | needs to be turned on or off. QSubtreeEnabler is a convenience node |
57 | that makes this use case trivial, allowing all of its children to be |
58 | controlled by a single switch. |
59 | |
60 | QSubtreeEnabler is enabled by default. |
61 | */ |
62 | |
63 | /*! |
64 | \qmltype SubtreeEnabler |
65 | \inqmlmodule Qt3D.Render |
66 | \since 5.14 |
67 | \instantiates Qt3DRender::QSubtreeEnabler |
68 | \inherits FrameGraphNode |
69 | \brief Enables or disables entire subtrees of frame graph nodes. |
70 | |
71 | While FrameGraphNodes can be individually enabled and disabled via the |
72 | \c enabled property, this can become tedious when an entire path |
73 | needs to be turned on or off. SubtreeEnabler is a convenience node |
74 | that makes this use case trivial, allowing all of its children to be |
75 | controlled by a single switch. |
76 | |
77 | For example, the following simplified frame graph includes a subtree for |
78 | debug rendering that can easily be enabled only when debugging. |
79 | |
80 | \qml |
81 | RenderSurfaceSelector { |
82 | ClearBuffers { |
83 | Viewport { |
84 | CameraSelector {} |
85 | } |
86 | } |
87 | |
88 | SubtreeEnabler { |
89 | enabled: showDebugView |
90 | Viewport { |
91 | CameraSelector { |
92 | RenderPassFilter {} |
93 | } |
94 | } |
95 | } |
96 | } |
97 | \endqml |
98 | |
99 | SubtreeEnabler is enabled by default. |
100 | */ |
101 | |
102 | QSubtreeEnabler::QSubtreeEnabler(Qt3DCore::QNode *parent) |
103 | : QFrameGraphNode(*new QSubtreeEnablerPrivate, parent) |
104 | { |
105 | } |
106 | |
107 | QSubtreeEnabler::~QSubtreeEnabler() |
108 | { |
109 | } |
110 | |
111 | /*! |
112 | \enum QSubtreeEnabler::Enablement |
113 | |
114 | Specifies whether subtree enablement is persistent or transient. |
115 | |
116 | \value Persistent |
117 | The value of enabled is persistent. This is the default. |
118 | |
119 | \value SingleShot |
120 | The value of enabled will last for a single frame and then be reset to false. |
121 | This might be used for a subtree drawing to an FBO, for example, to only update |
122 | the FBO when the relevant portions of the scene changed. |
123 | */ |
124 | |
125 | /*! |
126 | \qmlproperty enumeration Qt3D.Render::SubtreeEnabler::enablement |
127 | Controls whether subtree enablement is persistent or transient. |
128 | |
129 | \value Persistent |
130 | The value of enabled is persistent. This is the default. |
131 | |
132 | \value SingleShot |
133 | The value of enabled will last for a single frame and then be reset to false. |
134 | This might be used for a subtree drawing to an FBO, for example, to only update |
135 | the FBO when the relevant portions of the scene changed. |
136 | */ |
137 | |
138 | /*! |
139 | \property Qt3DRender::QSubtreeEnabler::enablement |
140 | Controls whether subtree enablement is persistent or transient. |
141 | */ |
142 | QSubtreeEnabler::Enablement QSubtreeEnabler::enablement() const |
143 | { |
144 | Q_D(const QSubtreeEnabler); |
145 | return d->m_enablement; |
146 | } |
147 | |
148 | void QSubtreeEnabler::setEnablement(QSubtreeEnabler::Enablement enablement) |
149 | { |
150 | Q_D(QSubtreeEnabler); |
151 | if (d->m_enablement == enablement) |
152 | return; |
153 | d->m_enablement = enablement; |
154 | emit enablementChanged(enablement: d->m_enablement); |
155 | } |
156 | |
157 | /*! |
158 | \qmlmethod void Qt3D.Render::SubtreeEnabler::requestUpdate() |
159 | Requests that the subtree be enabled. |
160 | |
161 | A conveninence method intended to be used with \c SingleShot enablement. |
162 | */ |
163 | |
164 | /*! |
165 | Requests that the subtree be enabled. |
166 | |
167 | A convenience method intended to be used with \c SingleShot enablement. |
168 | */ |
169 | void QSubtreeEnabler::requestUpdate() |
170 | { |
171 | setEnabled(true); |
172 | } |
173 | |
174 | Qt3DCore::QNodeCreatedChangeBasePtr QSubtreeEnabler::createNodeCreationChange() const |
175 | { |
176 | auto creationChange = QFrameGraphNodeCreatedChangePtr<QSubtreeEnablerData>::create(arguments: this); |
177 | auto &data = creationChange->data; |
178 | Q_D(const QSubtreeEnabler); |
179 | data.enablement = d->m_enablement; |
180 | return creationChange; |
181 | } |
182 | |
183 | } //Qt3DRender |
184 | |
185 | QT_END_NAMESPACE |
186 | |