Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qssgrendergeometry.cpp
Go to the documentation of this file.
1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5
8#include "resourcemanager/qssgrenderbuffermanager_p.h"
9
10QSSGRenderGeometry::QSSGRenderGeometry()
11 : QSSGRenderGraphObject(QSSGRenderGraphObject::Type::Geometry, FlagT(Flags::HasGraphicsResources))
12{
13}
14
15QSSGRenderGeometry::~QSSGRenderGeometry()
16{
17}
18
19const QByteArray &QSSGRenderGeometry::vertexBuffer() const
20{
21 return m_meshData.m_vertexBuffer;
22}
23
24QByteArray &QSSGRenderGeometry::vertexBuffer()
25{
26 return m_meshData.m_vertexBuffer;
27}
28
29const QByteArray &QSSGRenderGeometry::indexBuffer() const
30{
31 return m_meshData.m_indexBuffer;
32}
33
34QByteArray &QSSGRenderGeometry::indexBuffer()
35{
36 return m_meshData.m_indexBuffer;
37}
38
39int QSSGRenderGeometry::attributeCount() const
40{
41 return m_meshData.m_attributeCount;
42}
43
44QVector3D QSSGRenderGeometry::boundsMin() const
45{
46 return m_bounds.minimum;
47}
48
49QVector3D QSSGRenderGeometry::boundsMax() const
50{
51 return m_bounds.maximum;
52}
53
54int QSSGRenderGeometry::stride() const
55{
56 return m_meshData.m_stride;
57}
58
59QSSGMesh::Mesh::DrawMode QSSGRenderGeometry::primitiveType() const
60{
61 return m_meshData.m_primitiveType;
62}
63
64QSSGRenderGeometry::Attribute QSSGRenderGeometry::attribute(int idx) const
65{
66 Attribute attr;
67 const auto &mattr = m_meshData.m_attributes[idx];
68 attr.offset = mattr.offset;
69 attr.semantic = mattr.semantic;
70 attr.componentType = mattr.componentType;
71 return attr;
72}
73
74void QSSGRenderGeometry::addAttribute(QSSGMesh::RuntimeMeshData::Attribute::Semantic semantic,
75 int offset,
76 QSSGMesh::Mesh::ComponentType componentType)
77{
78 Attribute attr;
79 attr.semantic = semantic;
80 attr.offset = offset;
81 attr.componentType = componentType;
82 addAttribute(attr);
83}
84
85void QSSGRenderGeometry::addAttribute(const Attribute &att)
86{
87 const int index = m_meshData.m_attributeCount;
88 if (index == QSSGMesh::RuntimeMeshData::MAX_ATTRIBUTES) {
89 qWarning("Maximum number (%d) of vertex attributes in custom geometry has been reached; ignoring extra attributes",
90 QSSGMesh::RuntimeMeshData::MAX_ATTRIBUTES);
91 return;
92 }
93 m_meshData.m_attributes[index].semantic
94 = static_cast<QSSGMesh::RuntimeMeshData::Attribute::Semantic>(att.semantic);
95 m_meshData.m_attributes[index].offset = att.offset;
96 m_meshData.m_attributes[index].componentType = att.componentType;
97 ++m_meshData.m_attributeCount;
98 markDirty();
99}
100
101void QSSGRenderGeometry::addTargetAttribute(quint32 targetId,
102 QSSGMesh::RuntimeMeshData::Attribute::Semantic semantic,
103 int offset,
104 int stride)
105{
106 TargetAttribute tAttr;
107 tAttr.targetId = targetId;
108 tAttr.attr.semantic = semantic;
109 tAttr.attr.offset = offset;
110 tAttr.stride = stride;
111 addTargetAttribute(tAttr);
112}
113
114void QSSGRenderGeometry::addTargetAttribute(const TargetAttribute &att)
115{
116 const int index = m_meshData.m_targetAttributeCount;
117 if (index == QSSGMesh::RuntimeMeshData::MAX_TARGET_ATTRIBUTES) {
118 qWarning("Maximum number (%d) of morph target attributes in custom geometry has been reached; ignoring extra attributes",
119 QSSGMesh::RuntimeMeshData::MAX_TARGET_ATTRIBUTES);
120 return;
121 }
122 m_meshData.m_targetAttributes[index].attr.semantic
123 = static_cast<QSSGMesh::RuntimeMeshData::Attribute::Semantic>(att.attr.semantic);
124 m_meshData.m_targetAttributes[index].attr.offset = att.attr.offset;
125 m_meshData.m_targetAttributes[index].targetId = att.targetId;
126 m_meshData.m_targetAttributes[index].stride = att.stride;
127 ++m_meshData.m_targetAttributeCount;
128 markDirty();
129}
130
131void QSSGRenderGeometry::addSubset(quint32 offset, quint32 count, const QVector3D &boundsMin, const QVector3D &boundsMax, const QString &name)
132{
133 m_meshData.m_subsets.append({name, {boundsMin, boundsMax}, count, offset, {}, {}});
134 markDirty();
135}
136
137void QSSGRenderGeometry::setStride(int stride)
138{
139 m_meshData.m_stride = stride;
140 markDirty();
141}
142
143void QSSGRenderGeometry::setPrimitiveType(QSSGMesh::Mesh::DrawMode type)
144{
145 m_meshData.m_primitiveType = type;
146 markDirty();
147}
148
149void QSSGRenderGeometry::setBounds(const QVector3D &min, const QVector3D &max)
150{
151 m_bounds = QSSGBounds3(min, max);
152 markDirty();
153}
154
155void QSSGRenderGeometry::clear()
156{
157 m_meshData.clearVertexAndIndex();
158 m_meshData.clearTarget();
159 m_bounds.setEmpty();
160 markDirty();
161}
162
163void QSSGRenderGeometry::clearVertexAndIndex()
164{
165 m_meshData.clearVertexAndIndex();
166 m_bounds.setEmpty();
167 markDirty();
168}
169
170
171void QSSGRenderGeometry::clearTarget()
172{
173 m_meshData.clearTarget();
174 markDirty();
175}
176
177void QSSGRenderGeometry::clearAttributes()
178{
179 m_meshData.m_attributeCount = 0;
180}
181
182uint32_t QSSGRenderGeometry::generationId() const
183{
184 return m_generationId;
185}
186
187const QSSGMesh::RuntimeMeshData &QSSGRenderGeometry::meshData() const
188{
189 return m_meshData;
190}
191
192void QSSGRenderGeometry::setVertexData(const QByteArray &data)
193{
194 m_meshData.m_vertexBuffer = data;
195 markDirty();
196}
197
198void QSSGRenderGeometry::setIndexData(const QByteArray &data)
199{
200 m_meshData.m_indexBuffer = data;
201 markDirty();
202}
203
204void QSSGRenderGeometry::setTargetData(const QByteArray &data)
205{
206 m_meshData.m_targetBuffer = data;
207 markDirty();
208}
209
210void QSSGRenderGeometry::markDirty()
211{
212 m_generationId++;
213}