1 | // Copyright (C) 2015 Paul Lemire paul.lemire350@gmail.com |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QT3DCORE_BUFFERUTILS_P_H |
5 | #define QT3DCORE_BUFFERUTILS_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists for the convenience |
12 | // of other Qt classes. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <Qt3DCore/QAttribute> |
19 | #include <QByteArray> |
20 | #include <private/qglobal_p.h> |
21 | |
22 | QT_BEGIN_NAMESPACE |
23 | |
24 | |
25 | namespace Qt3DCore { |
26 | |
27 | class QGeometryView; |
28 | class QBuffer; |
29 | |
30 | struct BufferInfo |
31 | { |
32 | BufferInfo() |
33 | : type(Qt3DCore::QAttribute::VertexBaseType::Float) |
34 | , dataSize(0) |
35 | , count(0) |
36 | , byteStride(0) |
37 | , byteOffset(0) |
38 | , restartEnabled(false) |
39 | , restartIndexValue(-1) |
40 | {} |
41 | |
42 | QByteArray data; |
43 | Qt3DCore::QAttribute::VertexBaseType type; |
44 | uint dataSize; |
45 | uint count; |
46 | uint byteStride; |
47 | uint byteOffset; |
48 | bool restartEnabled; |
49 | int restartIndexValue; |
50 | }; |
51 | |
52 | |
53 | namespace BufferTypeInfo { |
54 | |
55 | template <Qt3DCore::QAttribute::VertexBaseType> struct EnumToType; |
56 | template <> struct EnumToType<Qt3DCore::QAttribute::Byte> { typedef const char type; }; |
57 | template <> struct EnumToType<Qt3DCore::QAttribute::UnsignedByte> { typedef const uchar type; }; |
58 | template <> struct EnumToType<Qt3DCore::QAttribute::Short> { typedef const short type; }; |
59 | template <> struct EnumToType<Qt3DCore::QAttribute::UnsignedShort> { typedef const ushort type; }; |
60 | template <> struct EnumToType<Qt3DCore::QAttribute::Int> { typedef const int type; }; |
61 | template <> struct EnumToType<Qt3DCore::QAttribute::UnsignedInt> { typedef const uint type; }; |
62 | template <> struct EnumToType<Qt3DCore::QAttribute::Float> { typedef const float type; }; |
63 | template <> struct EnumToType<Qt3DCore::QAttribute::Double> { typedef const double type; }; |
64 | |
65 | template<Qt3DCore::QAttribute::VertexBaseType v> |
66 | typename EnumToType<v>::type *castToType(const QByteArray &u, uint byteOffset) |
67 | { |
68 | return reinterpret_cast< typename EnumToType<v>::type *>(u.constData() + byteOffset); |
69 | } |
70 | |
71 | } // namespace BufferTypeInfo |
72 | |
73 | } // namespace Qt3DCore |
74 | |
75 | QT_END_NAMESPACE |
76 | |
77 | |
78 | #endif // QT3DCORE_BUFFERUTILS_P_H |
79 |