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 "attribute_p.h" |
41 | #include <Qt3DRender/qbuffer.h> |
42 | #include <Qt3DRender/private/qattribute_p.h> |
43 | #include <Qt3DRender/private/stringtoint_p.h> |
44 | |
45 | QT_BEGIN_NAMESPACE |
46 | |
47 | using namespace Qt3DCore; |
48 | |
49 | namespace Qt3DRender { |
50 | namespace Render { |
51 | |
52 | Attribute::Attribute() |
53 | : BackendNode(ReadOnly) |
54 | , m_nameId(0) |
55 | , m_vertexBaseType(QAttribute::Float) |
56 | , m_vertexSize(1) |
57 | , m_count(0) |
58 | , m_byteStride(0) |
59 | , m_byteOffset(0) |
60 | , m_divisor(0) |
61 | , m_attributeType(QAttribute::VertexAttribute) |
62 | , m_attributeDirty(false) |
63 | { |
64 | } |
65 | |
66 | Attribute::~Attribute() |
67 | { |
68 | } |
69 | |
70 | void Attribute::cleanup() |
71 | { |
72 | m_vertexBaseType = QAttribute::Float; |
73 | m_vertexSize = 1; |
74 | m_count = 0; |
75 | m_byteStride = 0; |
76 | m_byteOffset = 0; |
77 | m_divisor = 0; |
78 | m_attributeType = QAttribute::VertexAttribute; |
79 | m_bufferId = Qt3DCore::QNodeId(); |
80 | m_name.clear(); |
81 | m_attributeDirty = false; |
82 | m_nameId = 0; |
83 | } |
84 | |
85 | void Attribute::syncFromFrontEnd(const QNode *frontEnd, bool firstTime) |
86 | { |
87 | BackendNode::syncFromFrontEnd(frontEnd, firstTime); |
88 | const QAttribute *node = qobject_cast<const QAttribute *>(object: frontEnd); |
89 | if (!node) |
90 | return; |
91 | |
92 | m_attributeDirty = firstTime; |
93 | if (m_name != node->name()) { |
94 | m_name = node->name(); |
95 | m_nameId = StringToInt::lookupId(str: m_name); |
96 | m_attributeDirty = true; |
97 | } |
98 | if (m_vertexBaseType != node->vertexBaseType()) { |
99 | m_vertexBaseType = node->vertexBaseType(); |
100 | m_attributeDirty = true; |
101 | } |
102 | if (m_vertexSize != node->vertexSize()) { |
103 | m_vertexSize = node->vertexSize(); |
104 | m_attributeDirty = true; |
105 | } |
106 | if (m_count != node->count()) { |
107 | m_count = node->count(); |
108 | m_attributeDirty = true; |
109 | } |
110 | if (m_byteStride != node->byteStride()) { |
111 | m_byteStride = node->byteStride(); |
112 | m_attributeDirty = true; |
113 | } |
114 | if (m_byteOffset != node->byteOffset()) { |
115 | m_byteOffset = node->byteOffset(); |
116 | m_attributeDirty = true; |
117 | } |
118 | if (m_divisor != node->divisor()) { |
119 | m_divisor = node->divisor(); |
120 | m_attributeDirty = true; |
121 | } |
122 | if (m_attributeType != node->attributeType()) { |
123 | m_attributeType = node->attributeType(); |
124 | m_attributeDirty = true; |
125 | } |
126 | const auto bufferId = node->buffer() ? node->buffer()->id() : QNodeId{}; |
127 | if (bufferId != m_bufferId) { |
128 | m_bufferId = bufferId; |
129 | m_attributeDirty = true; |
130 | } |
131 | |
132 | markDirty(changes: AbstractRenderer::AllDirty); |
133 | } |
134 | |
135 | void Attribute::unsetDirty() |
136 | { |
137 | m_attributeDirty = false; |
138 | } |
139 | |
140 | } // namespace Render |
141 | } // namespace Qt3DRender |
142 | |
143 | QT_END_NAMESPACE |
144 | |