| 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 "attribute_p.h" |
| 5 | #include <Qt3DCore/private/qattribute_p.h> |
| 6 | #include <Qt3DRender/private/stringtoint_p.h> |
| 7 | |
| 8 | QT_BEGIN_NAMESPACE |
| 9 | |
| 10 | namespace Qt3DRender { |
| 11 | namespace Render { |
| 12 | |
| 13 | using namespace Qt3DCore; |
| 14 | |
| 15 | Attribute::Attribute() |
| 16 | : BackendNode(ReadOnly) |
| 17 | , m_nameId(0) |
| 18 | , m_vertexBaseType(QAttribute::Float) |
| 19 | , m_vertexSize(1) |
| 20 | , m_count(0) |
| 21 | , m_byteStride(0) |
| 22 | , m_byteOffset(0) |
| 23 | , m_divisor(0) |
| 24 | , m_attributeType(QAttribute::VertexAttribute) |
| 25 | , m_attributeDirty(false) |
| 26 | { |
| 27 | } |
| 28 | |
| 29 | Attribute::~Attribute() |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | void Attribute::cleanup() |
| 34 | { |
| 35 | m_vertexBaseType = QAttribute::Float; |
| 36 | m_vertexSize = 1; |
| 37 | m_count = 0; |
| 38 | m_byteStride = 0; |
| 39 | m_byteOffset = 0; |
| 40 | m_divisor = 0; |
| 41 | m_attributeType = QAttribute::VertexAttribute; |
| 42 | m_bufferId = Qt3DCore::QNodeId(); |
| 43 | m_name.clear(); |
| 44 | m_attributeDirty = false; |
| 45 | m_nameId = 0; |
| 46 | } |
| 47 | |
| 48 | void Attribute::syncFromFrontEnd(const QNode *frontEnd, bool firstTime) |
| 49 | { |
| 50 | BackendNode::syncFromFrontEnd(frontEnd, firstTime); |
| 51 | const QAttribute *node = qobject_cast<const QAttribute *>(object: frontEnd); |
| 52 | if (!node) |
| 53 | return; |
| 54 | |
| 55 | m_attributeDirty = firstTime; |
| 56 | if (m_name != node->name()) { |
| 57 | m_name = node->name(); |
| 58 | m_nameId = StringToInt::lookupId(str: m_name); |
| 59 | m_attributeDirty = true; |
| 60 | } |
| 61 | if (m_vertexBaseType != node->vertexBaseType()) { |
| 62 | m_vertexBaseType = node->vertexBaseType(); |
| 63 | m_attributeDirty = true; |
| 64 | } |
| 65 | if (m_vertexSize != node->vertexSize()) { |
| 66 | m_vertexSize = node->vertexSize(); |
| 67 | m_attributeDirty = true; |
| 68 | } |
| 69 | if (m_count != node->count()) { |
| 70 | m_count = node->count(); |
| 71 | m_attributeDirty = true; |
| 72 | } |
| 73 | if (m_byteStride != node->byteStride()) { |
| 74 | m_byteStride = node->byteStride(); |
| 75 | m_attributeDirty = true; |
| 76 | } |
| 77 | if (m_byteOffset != node->byteOffset()) { |
| 78 | m_byteOffset = node->byteOffset(); |
| 79 | m_attributeDirty = true; |
| 80 | } |
| 81 | if (m_divisor != node->divisor()) { |
| 82 | m_divisor = node->divisor(); |
| 83 | m_attributeDirty = true; |
| 84 | } |
| 85 | if (m_attributeType != node->attributeType()) { |
| 86 | m_attributeType = node->attributeType(); |
| 87 | m_attributeDirty = true; |
| 88 | } |
| 89 | const auto bufferId = node->buffer() ? node->buffer()->id() : QNodeId{}; |
| 90 | if (bufferId != m_bufferId) { |
| 91 | m_bufferId = bufferId; |
| 92 | m_attributeDirty = true; |
| 93 | } |
| 94 | |
| 95 | markDirty(changes: AbstractRenderer::AllDirty); |
| 96 | } |
| 97 | |
| 98 | void Attribute::unsetDirty() |
| 99 | { |
| 100 | m_attributeDirty = false; |
| 101 | } |
| 102 | |
| 103 | } // namespace Render |
| 104 | } // namespace Qt3DRender |
| 105 | |
| 106 | QT_END_NAMESPACE |
| 107 | |