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 "rendersettings_p.h"
5
6#include <Qt3DRender/QFrameGraphNode>
7#include <Qt3DRender/private/abstractrenderer_p.h>
8#include <Qt3DRender/private/qrendersettings_p.h>
9#include <Qt3DRender/private/qrendercapabilities_p.h>
10
11QT_BEGIN_NAMESPACE
12
13using namespace Qt3DCore;
14
15namespace Qt3DRender {
16namespace Render {
17
18RenderSettings::RenderSettings()
19 : BackendNode()
20 , m_renderPolicy(QRenderSettings::OnDemand)
21 , m_pickMethod(QPickingSettings::BoundingVolumePicking)
22 , m_pickResultMode(QPickingSettings::NearestPick)
23 , m_faceOrientationPickingMode(QPickingSettings::FrontFace)
24 , m_pickWorldSpaceTolerance(.1f)
25 , m_activeFrameGraph()
26{
27}
28
29void RenderSettings::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
30{
31 const QRenderSettings *node = qobject_cast<const QRenderSettings *>(object: frontEnd);
32 if (!node)
33 return;
34
35 BackendNode::syncFromFrontEnd(frontEnd, firstTime);
36
37 const Qt3DCore::QNodeId activeFGId = Qt3DCore::qIdForNode(node: node->activeFrameGraph());
38 if (activeFGId != m_activeFrameGraph) {
39 m_activeFrameGraph = activeFGId;
40 }
41
42 if (node->renderPolicy() != m_renderPolicy) {
43 m_renderPolicy = node->renderPolicy();
44 }
45
46 auto ncnode = const_cast<QRenderSettings *>(node);
47 if (ncnode->pickingSettings()->pickMethod() != m_pickMethod) {
48 m_pickMethod = ncnode->pickingSettings()->pickMethod();
49 }
50
51 if (ncnode->pickingSettings()->pickResultMode() != m_pickResultMode) {
52 m_pickResultMode = ncnode->pickingSettings()->pickResultMode();
53 }
54
55 if (!qFuzzyCompare(p1: ncnode->pickingSettings()->worldSpaceTolerance(), p2: m_pickWorldSpaceTolerance)) {
56 m_pickWorldSpaceTolerance = ncnode->pickingSettings()->worldSpaceTolerance();
57 }
58
59 if (ncnode->pickingSettings()->faceOrientationPickingMode() != m_faceOrientationPickingMode) {
60 m_faceOrientationPickingMode = ncnode->pickingSettings()->faceOrientationPickingMode();
61 }
62
63 if (firstTime)
64 m_capabilities = QRenderCapabilitiesPrivate::get(q: const_cast<QRenderSettings *>(node)->renderCapabilities())->toString();
65
66 // Either because something above as changed or if QRenderSettingsPrivate::invalidFrame()
67 // was called
68 markDirty(changes: AbstractRenderer::AllDirty);
69}
70
71RenderSettingsFunctor::RenderSettingsFunctor(AbstractRenderer *renderer)
72 : m_renderer(renderer)
73{
74}
75
76Qt3DCore::QBackendNode *RenderSettingsFunctor::create(Qt3DCore::QNodeId) const
77{
78 if (m_renderer->settings() != nullptr) {
79 qWarning() << "Renderer settings already exists";
80 return nullptr;
81 }
82
83 RenderSettings *settings = new RenderSettings;
84 settings->setRenderer(m_renderer);
85 m_renderer->setSettings(settings);
86 return settings;
87}
88
89Qt3DCore::QBackendNode *RenderSettingsFunctor::get(Qt3DCore::QNodeId id) const
90{
91 Q_UNUSED(id);
92 return m_renderer->settings();
93}
94
95void RenderSettingsFunctor::destroy(Qt3DCore::QNodeId id) const
96{
97 Q_UNUSED(id);
98 // Deletes the old settings object
99 auto settings = m_renderer->settings();
100 if (settings && settings->peerId() == id) {
101 m_renderer->setSettings(nullptr);
102 delete settings;
103 }
104}
105
106} // namespace Render
107} // namespace Qt3DRender
108
109QT_END_NAMESPACE
110

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