Debian Codegraph @

tests/auto/extras/common/geometrytesthelper.h

raw symbols SCIP
1 // Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 #ifndef GEOMETRYTESTHELPER_H
5 #define GEOMETRYTESTHELPER_H
6
7 #include <Qt3DCore/qattribute.h>
8 #include <Qt3DCore/qbuffer.h>
9 #include <Qt3DCore/qgeometry.h>
10
11 template<typename IndexType>
12 IndexType extractIndexData(Qt3DCore::QAttribute *attribute, int index)
13 {
14 // Get the raw data
15 const IndexType *typedData = reinterpret_cast<const IndexType *>(attribute->buffer()->data().constData());
16
17 // Offset into the data taking stride and offset into account
18 const IndexType indexValue = *(typedData + index);
19 return indexValue;
20 }
21
22 template<typename VertexType, typename IndexType>
23 VertexType extractVertexData(Qt3DCore::QAttribute *attribute, IndexType index)
24 {
25 // Get the raw data
26 const char *rawData = attribute->buffer()->data().constData();
27
28 // Offset into the data taking stride and offset into account
29 const char *vertexData = rawData + (index * attribute->byteStride() + attribute->byteOffset());
30
31 // Construct vertex from the typed data
32 VertexType vertex;
33 const Qt3DCore::QAttribute::VertexBaseType type = attribute->vertexBaseType();
34 switch (type)
35 {
36 case Qt3DCore::QAttribute::Float: {
37 const float *typedVertexData = reinterpret_cast<const float *>(vertexData);
38 const int components = attribute->vertexSize();
39 for (int i = 0; i < components; ++i)
40 vertex[i] = typedVertexData[i];
41 break;
42
43 // TODO: Handle other types as needed
44 }
45
46 default:
47 qWarning() << "Unhandled type";
48 Q_UNREACHABLE();
49 break;
50 }
51
52 return vertex;
53 }
54
55 #endif // GEOMETRYTESTHELPER_H