-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vertex.h
124 lines (102 loc) · 2.93 KB
/
Vertex.h
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#ifndef VERTEX_H
#define VERTEX_H
#include <QVector3D>
#include <QVector2D>
class Vertex
{
public:
// Constructors
Q_DECL_CONSTEXPR Vertex();
Q_DECL_CONSTEXPR explicit Vertex(const QVector3D &position);
Q_DECL_CONSTEXPR Vertex(const QVector3D &position, const QVector3D &color);
Q_DECL_CONSTEXPR Vertex(
const QVector3D &position,
const QVector3D &color,
const QVector2D &texCoords);
// Accessors / Mutators
Q_DECL_CONSTEXPR const QVector3D& position() const;
Q_DECL_CONSTEXPR const QVector3D& color() const;
Q_DECL_CONSTEXPR const QVector2D& texCoords() const;
void setPosition(const QVector3D& position);
void setColor(const QVector3D& color);
void setTexCoords(const QVector2D& texCoords);
// OpenGL Helpers
static const int PositionTupleSize = 3;
static const int ColorTupleSize = 3;
static const int TexCoordsTupleSize = 2;
static Q_DECL_CONSTEXPR int positionOffset();
static Q_DECL_CONSTEXPR int colorOffset();
static Q_DECL_CONSTEXPR int texCoordsOffset();
static Q_DECL_CONSTEXPR int stride();
private:
QVector3D m_position;
QVector3D m_color;
QVector2D m_texCoords;
};
/*******************************************************************************
* Inline Implementation
******************************************************************************/
// Note: Q_MOVABLE_TYPE means it can be memcpy'd.
Q_DECLARE_TYPEINFO(Vertex, Q_MOVABLE_TYPE);
// Constructors
Q_DECL_CONSTEXPR inline Vertex::Vertex() {}
Q_DECL_CONSTEXPR inline Vertex::Vertex(const QVector3D &position)
: m_position(position)
{
}
Q_DECL_CONSTEXPR inline Vertex::Vertex(
const QVector3D &position,
const QVector3D &color)
: m_position(position), m_color(color)
{
}
Q_DECL_CONSTEXPR inline Vertex::Vertex(
const QVector3D &position,
const QVector3D &color,
const QVector2D &texCoords)
: m_position(position), m_color(color), m_texCoords(texCoords)
{
}
// Accessors / Mutators
Q_DECL_CONSTEXPR inline const QVector3D& Vertex::position() const
{
return m_position;
}
Q_DECL_CONSTEXPR inline const QVector3D& Vertex::color() const
{
return m_color;
}
Q_DECL_CONSTEXPR inline const QVector2D &Vertex::texCoords() const
{
return m_texCoords;
}
void inline Vertex::setPosition(const QVector3D& position)
{
m_position = position;
}
void inline Vertex::setColor(const QVector3D& color)
{
m_color = color;
}
void inline Vertex::setTexCoords(const QVector2D &texCoords)
{
m_texCoords = texCoords;
}
// OpenGL Helpers
Q_DECL_CONSTEXPR inline int Vertex::positionOffset()
{
return offsetof(Vertex, m_position);
}
Q_DECL_CONSTEXPR inline int Vertex::colorOffset()
{
return offsetof(Vertex, m_color);
}
Q_DECL_CONSTEXPR inline int Vertex::texCoordsOffset()
{
return offsetof(Vertex, m_texCoords);
}
Q_DECL_CONSTEXPR inline int Vertex::stride()
{
return sizeof(Vertex);
}
#endif // VERTEX_H