1// Copyright (C) 2017 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 "levelofdetail_p.h"
5#include <Qt3DRender/QLevelOfDetail>
6#include <Qt3DRender/private/qlevelofdetail_p.h>
7#include <Qt3DRender/private/stringtoint_p.h>
8#include <Qt3DRender/QCamera>
9#include <QVariant>
10
11QT_BEGIN_NAMESPACE
12
13using namespace Qt3DCore;
14
15namespace Qt3DRender {
16namespace Render {
17
18LevelOfDetail::LevelOfDetail()
19 : BackendNode(BackendNode::ReadWrite)
20 , m_currentIndex(0)
21 , m_thresholdType(QLevelOfDetail::DistanceToCameraThreshold)
22 , m_volumeOverride()
23{
24}
25
26LevelOfDetail::~LevelOfDetail()
27{
28 cleanup();
29}
30
31void LevelOfDetail::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
32{
33 const QLevelOfDetail *node = qobject_cast<const QLevelOfDetail *>(object: frontEnd);
34 if (!node)
35 return;
36
37 const bool oldEnabled = isEnabled();
38 BackendNode::syncFromFrontEnd(frontEnd, firstTime);
39
40 const Qt3DCore::QNodeId cameraId = Qt3DCore::qIdForNode(node: node->camera());
41 if (cameraId != m_camera) {
42 m_camera = cameraId;
43 markDirty(changes: AbstractRenderer::GeometryDirty);
44 }
45
46 if (node->currentIndex() != m_currentIndex) {
47 m_currentIndex = node->currentIndex();
48 markDirty(changes: AbstractRenderer::GeometryDirty);
49 }
50
51 if (node->thresholdType() != m_thresholdType) {
52 m_thresholdType = node->thresholdType();
53 markDirty(changes: AbstractRenderer::GeometryDirty);
54 }
55
56 if (node->thresholds() != m_thresholds) {
57 m_thresholds = node->thresholds();
58 markDirty(changes: AbstractRenderer::GeometryDirty);
59 }
60
61 if (node->volumeOverride() != m_volumeOverride) {
62 m_volumeOverride = node->volumeOverride();
63 markDirty(changes: AbstractRenderer::GeometryDirty);
64 }
65
66 if (isEnabled() != oldEnabled || firstTime)
67 markDirty(changes: AbstractRenderer::LayersDirty);
68}
69
70void LevelOfDetail::cleanup()
71{
72 QBackendNode::setEnabled(false);
73}
74
75void LevelOfDetail::setCurrentIndex(int currentIndex)
76{
77 if (m_currentIndex != currentIndex)
78 m_currentIndex = currentIndex;
79}
80
81} // namespace Render
82} // namespace Qt3DRender
83
84QT_END_NAMESPACE
85

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