SleakEngine
0.1.0
C++23 multi-backend game engine
Toggle main menu visibility
Loading...
Searching...
No Matches
MeshData.hpp
Go to the documentation of this file.
1
#ifndef _MESHDATA_HPP_
2
#define _MESHDATA_HPP_
3
4
#include <array>
5
#include <cstddef>
6
#include <cstdint>
7
#include <
Utility/Container/List.hpp
>
8
9
namespace
Sleak
{
10
11
using
IndexType
= uint32_t;
12
using
IndexGroup
=
List<IndexType>
;
13
14
/// Standard 96-byte vertex format: position, normal, tangent, color, UV, and up to 4 skinning bone influences.
15
/// @ingroup rendering
16
struct
Vertex
{
17
float
px
,
py
,
pz
;
18
float
nx
,
ny
,
nz
;
19
float
tx
,
ty
,
tz
,
tw
;
20
float
r
,
g
,
b
,
a
;
21
float
u
,
v
;
22
int
boneIDs
[4] = {-1, -1, -1, -1};
23
float
boneWeights
[4] = {0, 0, 0, 0};
24
25
Vertex
() =
default
;
26
27
Vertex
(
float
px
,
float
py
,
float
pz
,
28
float
nx
,
float
ny
,
float
nz
,
29
float
tx
,
float
ty
,
float
tz
,
float
tw
,
30
float
u
= 0.0f,
float
v
= 0.0f)
31
:
px
(
px
),
py
(
py
),
pz
(
pz
),
32
nx
(
nx
),
ny
(
ny
),
nz
(
nz
),
33
tx
(
tx
),
ty
(
ty
),
tz
(
tz
),
tw
(
tw
),
34
r
(1.0f),
g
(1.0f),
b
(1.0f),
a
(1.0f),
35
u
(
u
),
v
(
v
) {
36
}
37
38
void
SetPosition
(
float
x,
float
y,
float
z) {
39
px
= x;
py
= y;
pz
= z;
40
}
41
42
void
SetNormal
(
float
x,
float
y,
float
z) {
43
nx
= x;
ny
= y;
nz
= z;
44
}
45
46
void
SetColor
(
float
r
,
float
g
,
float
b
,
float
a
) {
47
this->r =
r
; this->g =
g
; this->b =
b
; this->a =
a
;
48
}
49
50
void
SetTexCoord
(
float
u
,
float
v
) {
51
this->u =
u
; this->v =
v
;
52
}
53
54
static
constexpr
std::array<size_t, 6>
GetAttributeSizes
() {
55
return
{ 3, 3, 4, 2, 4, 4 };
56
}
57
58
static
constexpr
size_t
GetSize
() {
59
return
sizeof
(
Vertex
);
60
}
61
62
static
constexpr
std::array<size_t, 6>
GetAttributeOffsets
() {
63
return
{
64
offsetof(
Vertex
,
px
),
65
offsetof(
Vertex
,
nx
),
66
offsetof(
Vertex
,
r
),
67
offsetof(
Vertex
,
u
),
68
offsetof(
Vertex
,
boneIDs
),
69
offsetof(
Vertex
,
boneWeights
)
70
};
71
}
72
};
73
74
/// Growable CPU-side buffer of Vertex, ready to hand to MeshBatch::CreateMesh.
75
/// @ingroup rendering
76
class
VertexGroup
{
77
public
:
78
VertexGroup
() =
default
;
79
80
void
AddVertex
(
const
Vertex
& vertex) {
81
vertices.add(vertex);
82
}
83
84
void
AddVertex
(std::initializer_list<Vertex> vertexList) {
85
vertices.add(vertexList);
86
}
87
88
const
Vertex
*
GetData
()
const
{
return
vertices.GetData(); }
89
Vertex
*
GetMutableData
() {
return
const_cast<
Vertex
*
>
(vertices.GetData()); }
90
void
*
GetRawData
() {
return
vertices.GetRawData(); }
91
size_t
GetSize
()
const
{
return
vertices.GetSize(); }
92
size_t
GetSizeInBytes
()
const
{
return
vertices.GetSize() *
sizeof
(
Vertex
); }
93
94
void
clear
() { vertices.clear(); }
95
void
release
() { vertices.release(); }
96
97
private
:
98
Sleak::List<Vertex>
vertices;
99
};
100
101
/// CPU-side vertex and index buffers for one mesh, ready for upload.
102
/// @ingroup rendering
103
struct
MeshData
{
104
VertexGroup
vertices
;
105
IndexGroup
indices
;
106
};
107
108
}
109
110
#endif
List.hpp
Sleak::List
Implements a dynamic array-like list for storing and managing a collection of elements.
Definition
List.hpp:20
Sleak::VertexGroup
Definition
MeshData.hpp:76
Sleak::VertexGroup::VertexGroup
VertexGroup()=default
Sleak::VertexGroup::GetMutableData
Vertex * GetMutableData()
Definition
MeshData.hpp:89
Sleak::VertexGroup::AddVertex
void AddVertex(const Vertex &vertex)
Definition
MeshData.hpp:80
Sleak::VertexGroup::clear
void clear()
Definition
MeshData.hpp:94
Sleak::VertexGroup::GetRawData
void * GetRawData()
Definition
MeshData.hpp:90
Sleak::VertexGroup::AddVertex
void AddVertex(std::initializer_list< Vertex > vertexList)
Definition
MeshData.hpp:84
Sleak::VertexGroup::release
void release()
Definition
MeshData.hpp:95
Sleak::VertexGroup::GetSize
size_t GetSize() const
Definition
MeshData.hpp:91
Sleak::VertexGroup::GetSizeInBytes
size_t GetSizeInBytes() const
Definition
MeshData.hpp:92
Sleak::VertexGroup::GetData
const Vertex * GetData() const
Definition
MeshData.hpp:88
Sleak
Root namespace for everything the engine exposes.
Definition
Camera.hpp:10
Sleak::IndexType
uint32_t IndexType
Definition
MeshData.hpp:11
Sleak::IndexGroup
List< IndexType > IndexGroup
Definition
MeshData.hpp:12
Sleak::MeshData
Definition
MeshData.hpp:103
Sleak::MeshData::indices
IndexGroup indices
Definition
MeshData.hpp:105
Sleak::MeshData::vertices
VertexGroup vertices
Definition
MeshData.hpp:104
Sleak::Vertex
Definition
MeshData.hpp:16
Sleak::Vertex::GetAttributeOffsets
static constexpr std::array< size_t, 6 > GetAttributeOffsets()
Definition
MeshData.hpp:62
Sleak::Vertex::nz
float nz
Definition
MeshData.hpp:18
Sleak::Vertex::Vertex
Vertex(float px, float py, float pz, float nx, float ny, float nz, float tx, float ty, float tz, float tw, float u=0.0f, float v=0.0f)
Definition
MeshData.hpp:27
Sleak::Vertex::v
float v
Definition
MeshData.hpp:21
Sleak::Vertex::g
float g
Definition
MeshData.hpp:20
Sleak::Vertex::pz
float pz
Definition
MeshData.hpp:17
Sleak::Vertex::tz
float tz
Definition
MeshData.hpp:19
Sleak::Vertex::b
float b
Definition
MeshData.hpp:20
Sleak::Vertex::py
float py
Definition
MeshData.hpp:17
Sleak::Vertex::a
float a
Definition
MeshData.hpp:20
Sleak::Vertex::nx
float nx
Definition
MeshData.hpp:18
Sleak::Vertex::r
float r
Definition
MeshData.hpp:20
Sleak::Vertex::GetAttributeSizes
static constexpr std::array< size_t, 6 > GetAttributeSizes()
Definition
MeshData.hpp:54
Sleak::Vertex::px
float px
Definition
MeshData.hpp:17
Sleak::Vertex::ty
float ty
Definition
MeshData.hpp:19
Sleak::Vertex::GetSize
static constexpr size_t GetSize()
Definition
MeshData.hpp:58
Sleak::Vertex::ny
float ny
Definition
MeshData.hpp:18
Sleak::Vertex::SetColor
void SetColor(float r, float g, float b, float a)
Definition
MeshData.hpp:46
Sleak::Vertex::SetTexCoord
void SetTexCoord(float u, float v)
Definition
MeshData.hpp:50
Sleak::Vertex::Vertex
Vertex()=default
Sleak::Vertex::SetNormal
void SetNormal(float x, float y, float z)
Definition
MeshData.hpp:42
Sleak::Vertex::u
float u
Definition
MeshData.hpp:21
Sleak::Vertex::SetPosition
void SetPosition(float x, float y, float z)
Definition
MeshData.hpp:38
Sleak::Vertex::tw
float tw
Definition
MeshData.hpp:19
Sleak::Vertex::boneWeights
float boneWeights[4]
Definition
MeshData.hpp:23
Sleak::Vertex::boneIDs
int boneIDs[4]
Definition
MeshData.hpp:22
Sleak::Vertex::tx
float tx
Definition
MeshData.hpp:19
include
public
Runtime
MeshData.hpp
Generated on
for SleakEngine by
1.18.0