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
|
#pragma once
#include <utility>
#include <vector>
#include "../Common/Sizes.hpp"
#include "../Math/Common.hpp"
namespace MC::GFX {
class Mesh {
public:
struct Attribute {
template<uint S = 3, typename T = float>
Attribute(
std::vector<Vector<S, T>> v
) : data_size(v.size()),
attribute_size(S),
type_size(sizeof(T)) {
data = copy(v.data(), v.size() * S * type_size);
}
Attribute(
const Attribute& other
) : data(copy(other.data, other.data_size * other.attribute_size * other.type_size)),
data_size(other.data_size),
attribute_size(other.attribute_size),
type_size(other.type_size) {}
static void* copy(void* ptr, U32 size) {
auto* buffer = new U8[size];
std::copy_n((U8*)ptr, size, buffer);
return buffer;
}
void* data;
USize data_size;
USize attribute_size;
USize type_size;
};
Mesh(
std::vector<Attribute> attributes,
std::vector<U32> indices
) : m_attributes(std::move(attributes)),
m_indices(std::move(indices)) {}
explicit Mesh(
std::vector<Attribute> attributes
) : m_attributes(std::move(attributes)) {}
const std::vector<U32>& indices() const;
const std::vector<Attribute>& attributes() const;
private:
std::vector<Attribute> m_attributes;
std::vector<U32> m_indices;
};
}
|