1/****************************************************************************
2**
3** Copyright (C) 2016 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 "qrendersettings.h"
41#include "qrendersettings_p.h"
42#include "qrendercapabilities.h"
43#include "qframegraphnode.h"
44#include "qrendersurfaceselector.h"
45#include "qrendersurfaceselector_p.h"
46
47QT_BEGIN_NAMESPACE
48
49namespace Qt3DRender {
50
51/*!
52 \class Qt3DRender::QRenderSettings
53 \brief The QRenderSettings class holds settings related to rendering process and host the active
54 \l{Qt 3D Render Framegraph}{FrameGraph}.
55 \since 5.7
56 \inmodule Qt3DRender
57 \inherits Qt3DCore::QComponent
58
59 The QRenderSettings component must be set as a component of the scene root entity. It specifies
60 render policy and picking settings, as well as hosts the active
61 \l{Qt 3D Render Framegraph}{FrameGraph}.
62 */
63
64/*!
65 \qmltype RenderSettings
66 \brief The RenderSettings type holds settings related to rendering process and host the active
67 \l{Qt 3D Render Framegraph}{FrameGraph}.
68 \since 5.7
69 \inqmlmodule Qt3D.Render
70 \instantiates Qt3DRender::QRenderSettings
71
72 The RenderSettings component must be set as a component of the scene root entity. It specifies
73 render policy and picking settings, as well as hosts the active
74 \l{Qt 3D Render Framegraph}{FrameGraph}.
75 */
76
77
78/*! \internal */
79QRenderSettingsPrivate::QRenderSettingsPrivate()
80 : Qt3DCore::QComponentPrivate()
81 , m_activeFrameGraph(nullptr)
82 , m_renderPolicy(QRenderSettings::Always)
83{
84}
85
86/*! \internal */
87void QRenderSettingsPrivate::init()
88{
89 Q_Q(QRenderSettings);
90 QObject::connect(sender: &m_pickingSettings, SIGNAL(pickMethodChanged(QPickingSettings::PickMethod)),
91 receiver: q, SLOT(_q_onPickingMethodChanged(QPickingSettings::PickMethod)));
92 QObject::connect(sender: &m_pickingSettings, SIGNAL(pickResultModeChanged(QPickingSettings::PickResultMode)),
93 receiver: q, SLOT(_q_onPickResultModeChanged(QPickingSettings::PickResultMode)));
94 QObject::connect(sender: &m_pickingSettings, SIGNAL(faceOrientationPickingModeChanged(QPickingSettings::FaceOrientationPickingMode)),
95 receiver: q, SLOT(_q_onFaceOrientationPickingModeChanged(QPickingSettings::FaceOrientationPickingMode)));
96 QObject::connect(sender: &m_pickingSettings, SIGNAL(worldSpaceToleranceChanged(float)),
97 receiver: q, SLOT(_q_onWorldSpaceToleranceChanged(float)));
98}
99
100void QRenderSettingsPrivate::invalidateFrame()
101{
102 update();
103}
104
105/*! \internal */
106void QRenderSettingsPrivate::_q_onPickingMethodChanged(QPickingSettings::PickMethod pickMethod)
107{
108 notifyPropertyChange(name: "pickMethod", value: pickMethod);
109}
110
111/*! \internal */
112void QRenderSettingsPrivate::_q_onPickResultModeChanged(QPickingSettings::PickResultMode pickResultMode)
113{
114 notifyPropertyChange(name: "pickResultMode", value: pickResultMode);
115}
116
117/*! \internal */
118void QRenderSettingsPrivate::_q_onFaceOrientationPickingModeChanged(QPickingSettings::FaceOrientationPickingMode faceOrientationPickingMode)
119{
120 notifyPropertyChange(name: "faceOrientationPickingMode", value: faceOrientationPickingMode);
121}
122
123/*! \internal */
124void QRenderSettingsPrivate::_q_onWorldSpaceToleranceChanged(float worldSpaceTolerance)
125{
126 notifyPropertyChange(name: "pickWorldSpaceTolerance", value: worldSpaceTolerance);
127}
128
129QRenderSettings::QRenderSettings(Qt3DCore::QNode *parent)
130 : QRenderSettings(*new QRenderSettingsPrivate, parent) {}
131
132/*! \internal */
133QRenderSettings::QRenderSettings(QRenderSettingsPrivate &dd, Qt3DCore::QNode *parent)
134 : Qt3DCore::QComponent(dd, parent)
135{
136 Q_D(QRenderSettings);
137 d->init();
138}
139
140/*! \internal */
141QRenderSettings::~QRenderSettings()
142{
143}
144
145/*!
146 \qmlproperty RenderCapabilities RenderSettings::renderCapabilities
147
148 Holds the details of the supported rendering engine
149
150 \readonly
151 \since 5.15
152*/
153/*!
154 \property QRenderSettings::renderCapabilities
155
156 Holds the details of the supported rendering engine
157
158 \readonly
159 \since 5.15
160*/
161QRenderCapabilities *QRenderSettings::renderCapabilities()
162{
163 Q_D(QRenderSettings);
164 return &(d->m_renderCapabilities);
165}
166
167/*!
168 \qmlproperty PickingSettings RenderSettings::pickingSettings
169
170 Holds the current pick settings for the \l{Qt 3D Render Framegraph}{FrameGraph}.
171
172 \readonly
173*/
174/*!
175 \property QRenderSettings::pickingSettings
176
177 Holds the current pick settings for the \l{Qt 3D Render Framegraph}{FrameGraph}.
178
179 \readonly
180*/
181QPickingSettings *QRenderSettings::pickingSettings()
182{
183 Q_D(QRenderSettings);
184 return &(d->m_pickingSettings);
185}
186
187/*!
188 \qmlproperty FrameGraphNode RenderSettings::activeFrameGraph
189
190 Holds the currently active \l{Qt 3D Render Framegraph}{FrameGraph}.
191*/
192/*!
193 \property QRenderSettings::activeFrameGraph
194
195 Holds the currently active \l{Qt 3D Render Framegraph}{FrameGraph}.
196*/
197QFrameGraphNode *QRenderSettings::activeFrameGraph() const
198{
199 Q_D(const QRenderSettings);
200 return d->m_activeFrameGraph;
201}
202
203
204/*!
205 \enum QRenderSettings::RenderPolicy
206
207 The render policy.
208
209 \value OnDemand The \l{Qt 3D Render Framegraph}{FrameGraph} is rendered only when something
210 changes.
211 \value Always The \l{Qt 3D Render Framegraph}{FrameGraph} is rendered continuously, even if
212 nothing has changed.
213*/
214
215/*!
216 \qmlproperty enumeration RenderSettings::renderPolicy
217
218 Holds the current render policy.
219
220 \list
221 \li RenderSettings.OnDemand
222 \li RenderSettings.Always
223 \endlist
224
225 \sa Qt3DRender::QRenderSettings::RenderPolicy
226*/
227/*!
228 \property QRenderSettings::renderPolicy
229
230 Holds the current render policy.
231*/
232QRenderSettings::RenderPolicy QRenderSettings::renderPolicy() const
233{
234 Q_D(const QRenderSettings);
235 return d->m_renderPolicy;
236}
237
238void QRenderSettings::setActiveFrameGraph(QFrameGraphNode *activeFrameGraph)
239{
240 Q_D(QRenderSettings);
241 if (d->m_activeFrameGraph == activeFrameGraph)
242 return;
243
244 // if the old frame graph had a SurfaceSelector, use the given surface for the new framegraph, too.
245 if (d->m_activeFrameGraph && activeFrameGraph) {
246 Qt3DRender::QRenderSurfaceSelector *oldSurfaceSelector = Qt3DRender::QRenderSurfaceSelectorPrivate::find(rootObject: d->m_activeFrameGraph);
247 Qt3DRender::QRenderSurfaceSelector *newSurfaceSelector = Qt3DRender::QRenderSurfaceSelectorPrivate::find(rootObject: activeFrameGraph);
248 if (oldSurfaceSelector && newSurfaceSelector && oldSurfaceSelector->surface()) {
249 newSurfaceSelector->setExternalRenderTargetSize(oldSurfaceSelector->externalRenderTargetSize());
250 newSurfaceSelector->setSurfacePixelRatio(oldSurfaceSelector->surfacePixelRatio());
251 newSurfaceSelector->setSurface(oldSurfaceSelector->surface());
252 }
253 }
254
255 if (d->m_activeFrameGraph)
256 d->unregisterDestructionHelper(node: d->m_activeFrameGraph);
257
258 if (activeFrameGraph != nullptr && !activeFrameGraph->parent())
259 activeFrameGraph->setParent(this);
260
261 d->m_activeFrameGraph = activeFrameGraph;
262
263 // Ensures proper bookkeeping
264 if (d->m_activeFrameGraph)
265 d->registerDestructionHelper(node: d->m_activeFrameGraph, func: &QRenderSettings::setActiveFrameGraph, d->m_activeFrameGraph);
266
267 emit activeFrameGraphChanged(activeFrameGraph);
268}
269
270void QRenderSettings::setRenderPolicy(QRenderSettings::RenderPolicy renderPolicy)
271{
272 Q_D(QRenderSettings);
273 if (d->m_renderPolicy == renderPolicy)
274 return;
275
276 d->m_renderPolicy = renderPolicy;
277 emit renderPolicyChanged(renderPolicy);
278}
279
280Qt3DCore::QNodeCreatedChangeBasePtr QRenderSettings::createNodeCreationChange() const
281{
282 auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QRenderSettingsData>::create(arguments: this);
283 auto &data = creationChange->data;
284 Q_D(const QRenderSettings);
285 data.activeFrameGraphId = qIdForNode(node: d->m_activeFrameGraph);
286 data.renderPolicy = d->m_renderPolicy;
287 data.pickMethod = d->m_pickingSettings.pickMethod();
288 data.pickResultMode = d->m_pickingSettings.pickResultMode();
289 data.faceOrientationPickingMode = d->m_pickingSettings.faceOrientationPickingMode();
290 data.pickWorldSpaceTolerance = d->m_pickingSettings.worldSpaceTolerance();
291 return creationChange;
292}
293
294} // namespace Qt3Drender
295
296QT_END_NAMESPACE
297
298#include "moc_qrendersettings.cpp"
299

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