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

source code of qtquick3d/src/runtimerender/graphobjects/qssgrendergeometry.cpp