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 | |
11 | QT_BEGIN_NAMESPACE |
12 | |
13 | using namespace Qt3DCore; |
14 | |
15 | namespace Qt3DRender { |
16 | namespace Render { |
17 | |
18 | RenderSettings::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 | |
29 | void 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 | |
71 | RenderSettingsFunctor::RenderSettingsFunctor(AbstractRenderer *renderer) |
72 | : m_renderer(renderer) |
73 | { |
74 | } |
75 | |
76 | Qt3DCore::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 | |
89 | Qt3DCore::QBackendNode *RenderSettingsFunctor::get(Qt3DCore::QNodeId id) const |
90 | { |
91 | Q_UNUSED(id); |
92 | return m_renderer->settings(); |
93 | } |
94 | |
95 | void 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 | |
109 | QT_END_NAMESPACE |
110 |