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 "rendersettings_p.h"
41
42#include <Qt3DRender/QFrameGraphNode>
43#include <Qt3DRender/private/abstractrenderer_p.h>
44#include <Qt3DRender/private/qrendersettings_p.h>
45#include <Qt3DRender/private/qrendercapabilities_p.h>
46
47QT_BEGIN_NAMESPACE
48
49using namespace Qt3DCore;
50
51namespace Qt3DRender {
52namespace Render {
53
54RenderSettings::RenderSettings()
55 : BackendNode()
56 , m_renderPolicy(QRenderSettings::OnDemand)
57 , m_pickMethod(QPickingSettings::BoundingVolumePicking)
58 , m_pickResultMode(QPickingSettings::NearestPick)
59 , m_faceOrientationPickingMode(QPickingSettings::FrontFace)
60 , m_pickWorldSpaceTolerance(.1f)
61 , m_activeFrameGraph()
62{
63}
64
65void RenderSettings::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
66{
67 const QRenderSettings *node = qobject_cast<const QRenderSettings *>(object: frontEnd);
68 if (!node)
69 return;
70
71 BackendNode::syncFromFrontEnd(frontEnd, firstTime);
72
73 const Qt3DCore::QNodeId activeFGId = Qt3DCore::qIdForNode(node: node->activeFrameGraph());
74 if (activeFGId != m_activeFrameGraph) {
75 m_activeFrameGraph = activeFGId;
76 }
77
78 if (node->renderPolicy() != m_renderPolicy) {
79 m_renderPolicy = node->renderPolicy();
80 }
81
82 auto ncnode = const_cast<QRenderSettings *>(node);
83 if (ncnode->pickingSettings()->pickMethod() != m_pickMethod) {
84 m_pickMethod = ncnode->pickingSettings()->pickMethod();
85 }
86
87 if (ncnode->pickingSettings()->pickResultMode() != m_pickResultMode) {
88 m_pickResultMode = ncnode->pickingSettings()->pickResultMode();
89 }
90
91 if (!qFuzzyCompare(p1: ncnode->pickingSettings()->worldSpaceTolerance(), p2: m_pickWorldSpaceTolerance)) {
92 m_pickWorldSpaceTolerance = ncnode->pickingSettings()->worldSpaceTolerance();
93 }
94
95 if (ncnode->pickingSettings()->faceOrientationPickingMode() != m_faceOrientationPickingMode) {
96 m_faceOrientationPickingMode = ncnode->pickingSettings()->faceOrientationPickingMode();
97 }
98
99 if (firstTime)
100 m_capabilities = QRenderCapabilitiesPrivate::get(q: const_cast<QRenderSettings *>(node)->renderCapabilities())->toString();
101
102 // Either because something above as changed or if QRenderSettingsPrivate::invalidFrame()
103 // was called
104 markDirty(changes: AbstractRenderer::AllDirty);
105}
106
107RenderSettingsFunctor::RenderSettingsFunctor(AbstractRenderer *renderer)
108 : m_renderer(renderer)
109{
110}
111
112Qt3DCore::QBackendNode *RenderSettingsFunctor::create(const Qt3DCore::QNodeCreatedChangeBasePtr &change) const
113{
114 Q_UNUSED(change)
115 if (m_renderer->settings() != nullptr) {
116 qWarning() << "Renderer settings already exists";
117 return nullptr;
118 }
119
120 RenderSettings *settings = new RenderSettings;
121 settings->setRenderer(m_renderer);
122 m_renderer->setSettings(settings);
123 return settings;
124}
125
126Qt3DCore::QBackendNode *RenderSettingsFunctor::get(Qt3DCore::QNodeId id) const
127{
128 Q_UNUSED(id)
129 return m_renderer->settings();
130}
131
132void RenderSettingsFunctor::destroy(Qt3DCore::QNodeId id) const
133{
134 Q_UNUSED(id)
135 // Deletes the old settings object
136 auto settings = m_renderer->settings();
137 if (settings && settings->peerId() == id) {
138 m_renderer->setSettings(nullptr);
139 delete settings;
140 }
141}
142
143} // namespace Render
144} // namespace Qt3DRender
145
146QT_END_NAMESPACE
147

source code of qt3d/src/render/backend/rendersettings.cpp