summaryrefslogtreecommitdiff
path: root/src/core/geometry/bufferutils_p.h
blob: afba15c218c601e174e23e8de2f37dbfbce41f3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (C) 2015 Paul Lemire paul.lemire350@gmail.com
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#ifndef QT3DCORE_BUFFERUTILS_P_H
#define QT3DCORE_BUFFERUTILS_P_H

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API.  It exists for the convenience
// of other Qt classes.  This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//

#include <Qt3DCore/QAttribute>
#include <QByteArray>
#include <private/qglobal_p.h>

QT_BEGIN_NAMESPACE


namespace Qt3DCore {

class QGeometryView;
class QBuffer;

struct BufferInfo
{
    BufferInfo()
        : type(Qt3DCore::QAttribute::VertexBaseType::Float)
        , dataSize(0)
        , count(0)
        , byteStride(0)
        , byteOffset(0)
        , restartEnabled(false)
        , restartIndexValue(-1)
    {}

    QByteArray data;
    Qt3DCore::QAttribute::VertexBaseType type;
    uint dataSize;
    uint count;
    uint byteStride;
    uint byteOffset;
    bool restartEnabled;
    int restartIndexValue;
};


namespace BufferTypeInfo {

    template <Qt3DCore::QAttribute::VertexBaseType> struct EnumToType;
    template <> struct EnumToType<Qt3DCore::QAttribute::Byte> { typedef const char type; };
    template <> struct EnumToType<Qt3DCore::QAttribute::UnsignedByte> { typedef const uchar type; };
    template <> struct EnumToType<Qt3DCore::QAttribute::Short> { typedef const short type; };
    template <> struct EnumToType<Qt3DCore::QAttribute::UnsignedShort> { typedef const ushort type; };
    template <> struct EnumToType<Qt3DCore::QAttribute::Int> { typedef const int type; };
    template <> struct EnumToType<Qt3DCore::QAttribute::UnsignedInt> { typedef const uint type; };
    template <> struct EnumToType<Qt3DCore::QAttribute::Float> { typedef const float type; };
    template <> struct EnumToType<Qt3DCore::QAttribute::Double> { typedef const double type; };

    template<Qt3DCore::QAttribute::VertexBaseType v>
    typename EnumToType<v>::type *castToType(const QByteArray &u, uint byteOffset)
    {
        return reinterpret_cast< typename EnumToType<v>::type *>(u.constData() + byteOffset);
    }

} // namespace BufferTypeInfo

} // namespace Qt3DCore

QT_END_NAMESPACE


#endif // QT3DCORE_BUFFERUTILS_P_H