1// Copyright (C) 2015 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 "geometry_p.h"
5#include <Qt3DCore/private/qgeometry_p.h>
6#include <Qt3DCore/qattribute.h>
7#include <Qt3DCore/qgeometry.h>
8
9#include <algorithm>
10
11QT_BEGIN_NAMESPACE
12
13using namespace Qt3DCore;
14
15namespace Qt3DRender {
16namespace Render {
17
18Geometry::Geometry()
19 : BackendNode(ReadWrite)
20 , m_geometryDirty(false)
21{
22}
23
24Geometry::~Geometry()
25{
26}
27
28void Geometry::cleanup()
29{
30 QBackendNode::setEnabled(false);
31 m_attributes.clear();
32 m_geometryDirty = false;
33 m_boundingPositionAttribute = Qt3DCore::QNodeId();
34 m_min = QVector3D();
35 m_max = QVector3D();
36}
37
38void Geometry::syncFromFrontEnd(const QNode *frontEnd, bool firstTime)
39{
40 BackendNode::syncFromFrontEnd(frontEnd, firstTime);
41 const QGeometry *node = qobject_cast<const QGeometry *>(object: frontEnd);
42 if (!node)
43 return;
44
45 m_geometryDirty |= firstTime;
46
47 QNodeIdVector attribs = qIdsForNodes(nodes: node->attributes());
48 std::sort(first: std::begin(cont&: attribs), last: std::end(cont&: attribs));
49 if (m_attributes != attribs) {
50 m_attributes = attribs;
51 m_geometryDirty = true;
52 }
53
54 if ((node->boundingVolumePositionAttribute() && node->boundingVolumePositionAttribute()->id() != m_boundingPositionAttribute) ||
55 // Note: doesn't set dirtyness as this parameter changing doesn't need a new VAO update.
56 (!node->boundingVolumePositionAttribute() && !m_boundingPositionAttribute.isNull())) {
57 m_boundingPositionAttribute = node->boundingVolumePositionAttribute() ? node->boundingVolumePositionAttribute()->id() : QNodeId{};
58 }
59
60 markDirty(changes: AbstractRenderer::GeometryDirty);
61}
62
63void Geometry::unsetDirty()
64{
65 m_geometryDirty = false;
66}
67
68// Called from calcboundingvolumejob (in a QtConcurrent thead (can't send
69// update changes from such a thread))
70void Geometry::updateExtent(const QVector3D &min, const QVector3D &max)
71{
72 // Send notification to frontend
73 if (m_min != min) {
74 m_min = min;
75 }
76
77 if (m_max != max) {
78 m_max = max;
79 }
80}
81
82} // namespace Render
83} // namespace Qt3DRender
84
85QT_END_NAMESPACE
86

source code of qt3d/src/render/geometry/geometry.cpp