-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathvertex_attributes.cpp
More file actions
90 lines (74 loc) · 2.28 KB
/
Copy pathvertex_attributes.cpp
File metadata and controls
90 lines (74 loc) · 2.28 KB
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
////////////////////////////////////////////////////////////////////////////////
// Distributed under the Boost Software License, Version 1.0. //
// (See accompanying file LICENSE or copy at //
// https://www.boost.org/LICENSE_1_0.txt) //
////////////////////////////////////////////////////////////////////////////////
#include "graphics/vertex_attributes.h"
#include <cstddef>
#include <iterator>
#include <tuple>
#include <vector>
#include "core/exception.h"
#include "core/vector3.h"
namespace
{
/**
* Helper function to convert a VertexAttributeType to a tuple of:
* <number of components, size of singe component>
*
* @param type
* Type to convert.
*
* @returns
* Tuple of <number of components, size of single component>.
*/
std::tuple<std::size_t, std::size_t> type_information(iris::VertexAttributeType type)
{
std::tuple<std::size_t, std::size_t> info(0u, 0u);
switch (type)
{
case iris::VertexAttributeType::FLOAT_3: info = {3u, sizeof(float)}; break;
case iris::VertexAttributeType::FLOAT_4: info = {4u, sizeof(float)}; break;
case iris::VertexAttributeType::UINT32_1: info = {1u, sizeof(std::uint32_t)}; break;
case iris::VertexAttributeType::UINT32_4: info = {4u, sizeof(std::uint32_t)}; break;
default: throw iris::Exception("unknown vertex attribute type");
}
return info;
}
}
namespace iris
{
VertexAttributes::VertexAttributes(const std::vector<VertexAttributeType> &types)
: attributes_()
, size_(0u)
{
std::size_t offset = 0u;
for (const auto type : types)
{
const auto [components, size] = type_information(type);
attributes_.emplace_back(VertexAttribute{type, components, size, offset});
offset += components * size;
}
size_ = offset;
}
std::size_t VertexAttributes::size() const
{
return size_;
}
VertexAttributes::const_iterator VertexAttributes::begin() const
{
return cbegin();
}
VertexAttributes::const_iterator VertexAttributes::end() const
{
return cend();
}
VertexAttributes::const_iterator VertexAttributes::cbegin() const
{
return std::cbegin(attributes_);
}
VertexAttributes::const_iterator VertexAttributes::cend() const
{
return std::cend(attributes_);
}
}