| 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 | |
| 11 | QT_BEGIN_NAMESPACE |
| 12 | |
| 13 | namespace Qt3DRender { |
| 14 | namespace Render { |
| 15 | |
| 16 | using namespace Qt3DCore; |
| 17 | |
| 18 | Geometry::Geometry() |
| 19 | : BackendNode(ReadWrite) |
| 20 | , m_geometryDirty(false) |
| 21 | { |
| 22 | } |
| 23 | |
| 24 | Geometry::~Geometry() |
| 25 | { |
| 26 | } |
| 27 | |
| 28 | void 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 | |
| 38 | void 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 | |
| 63 | void 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)) |
| 70 | void 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 | |
| 85 | QT_END_NAMESPACE |
| 86 |
