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

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