1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2015 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 "geometry_p.h" |
41 | #include <Qt3DRender/qattribute.h> |
42 | #include <Qt3DRender/qgeometry.h> |
43 | #include <Qt3DRender/private/qgeometry_p.h> |
44 | #include <Qt3DCore/qpropertyupdatedchange.h> |
45 | |
46 | #include <algorithm> |
47 | |
48 | QT_BEGIN_NAMESPACE |
49 | |
50 | using namespace Qt3DCore; |
51 | |
52 | namespace Qt3DRender { |
53 | namespace Render { |
54 | |
55 | Geometry::Geometry() |
56 | : BackendNode(ReadWrite) |
57 | , m_geometryDirty(false) |
58 | , m_shouldNotifyMinExtentChanged(false) |
59 | , m_shouldNotifyMaxExtentChanged(false) |
60 | { |
61 | } |
62 | |
63 | Geometry::~Geometry() |
64 | { |
65 | } |
66 | |
67 | void Geometry::cleanup() |
68 | { |
69 | QBackendNode::setEnabled(false); |
70 | m_attributes.clear(); |
71 | m_geometryDirty = false; |
72 | m_boundingPositionAttribute = Qt3DCore::QNodeId(); |
73 | m_min = QVector3D(); |
74 | m_max = QVector3D(); |
75 | m_shouldNotifyMinExtentChanged = false; |
76 | m_shouldNotifyMaxExtentChanged = false; |
77 | } |
78 | |
79 | void Geometry::syncFromFrontEnd(const QNode *frontEnd, bool firstTime) |
80 | { |
81 | BackendNode::syncFromFrontEnd(frontEnd, firstTime); |
82 | const QGeometry *node = qobject_cast<const QGeometry *>(object: frontEnd); |
83 | if (!node) |
84 | return; |
85 | |
86 | m_geometryDirty |= firstTime; |
87 | |
88 | QNodeIdVector attribs = qIdsForNodes(nodes: node->attributes()); |
89 | std::sort(first: std::begin(cont&: attribs), last: std::end(cont&: attribs)); |
90 | if (m_attributes != attribs) { |
91 | m_attributes = attribs; |
92 | m_geometryDirty = true; |
93 | } |
94 | |
95 | if ((node->boundingVolumePositionAttribute() && node->boundingVolumePositionAttribute()->id() != m_boundingPositionAttribute) || |
96 | // Note: doesn't set dirtyness as this parameter changing doesn't need a new VAO update. |
97 | (!node->boundingVolumePositionAttribute() && !m_boundingPositionAttribute.isNull())) { |
98 | m_boundingPositionAttribute = node->boundingVolumePositionAttribute() ? node->boundingVolumePositionAttribute()->id() : QNodeId{}; |
99 | } |
100 | |
101 | markDirty(changes: AbstractRenderer::GeometryDirty); |
102 | } |
103 | |
104 | void Geometry::unsetDirty() |
105 | { |
106 | m_geometryDirty = false; |
107 | } |
108 | |
109 | // Called from calcboundingvolumejob (in a QtConcurrent thead (can't send |
110 | // update changes from such a thread)) |
111 | void Geometry::updateExtent(const QVector3D &min, const QVector3D &max) |
112 | { |
113 | // Send notification to frontend |
114 | if (m_min != min) { |
115 | m_min = min; |
116 | m_shouldNotifyMinExtentChanged = true; |
117 | } |
118 | |
119 | if (m_max != max) { |
120 | m_max = max; |
121 | m_shouldNotifyMaxExtentChanged = true; |
122 | } |
123 | } |
124 | |
125 | // Called from calcboundingvolumejob after all bounding volumes have been |
126 | // updated (in an aspect thread) |
127 | void Geometry::notifyExtentChanged() |
128 | { |
129 | if (m_shouldNotifyMinExtentChanged || m_shouldNotifyMaxExtentChanged) { |
130 | auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(arguments: peerId()); |
131 | change->setDeliveryFlags(Qt3DCore::QSceneChange::Nodes); |
132 | change->setPropertyName("extent" ); |
133 | change->setValue(QVariant::fromValue(value: QPair<QVector3D, QVector3D>(m_min, m_max))); |
134 | notifyObservers(e: change); |
135 | m_shouldNotifyMinExtentChanged = false; |
136 | m_shouldNotifyMaxExtentChanged = false; |
137 | } |
138 | } |
139 | |
140 | } // namespace Render |
141 | } // namespace Qt3DRender |
142 | |
143 | QT_END_NAMESPACE |
144 | |