blob: 3994bac2b55718cf5f2412413906af19a01c65cf (
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
|
#pragma once
#include "drape/gl_constants.hpp"
#include "drape/glsl_func.hpp"
#include "drape/glsl_types.hpp"
#include <boost/shared_array.hpp>
#include <string>
namespace dp
{
struct BindingDecl
{
string m_attributeName;
uint8_t m_componentCount;
glConst m_componentType;
uint8_t m_stride;
uint8_t m_offset;
bool operator!=(BindingDecl const & other) const;
bool operator<(BindingDecl const & other) const;
};
class BindingInfo
{
public:
BindingInfo();
explicit BindingInfo(uint8_t count, uint8_t id = 0);
~BindingInfo() = default;
uint8_t GetCount() const;
uint8_t GetID() const;
BindingDecl const & GetBindingDecl(uint16_t index) const;
BindingDecl & GetBindingDecl(uint16_t index);
uint16_t GetElementSize() const;
bool IsDynamic() const;
bool operator<(BindingInfo const & other) const;
protected:
boost::shared_array<BindingDecl> m_bindings;
uint16_t m_info;
};
template <typename TFieldType, typename TVertexType>
uint8_t FillDecl(size_t index, string const & attrName, dp::BindingInfo & info, uint8_t offset)
{
dp::BindingDecl & decl = info.GetBindingDecl(static_cast<uint16_t>(index));
decl.m_attributeName = attrName;
decl.m_componentCount = glsl::GetComponentCount<TFieldType>();
decl.m_componentType = gl_const::GLFloatType;
decl.m_offset = offset;
decl.m_stride = sizeof(TVertexType);
return sizeof(TFieldType);
}
template <typename TVertex>
class BindingFiller
{
public:
explicit BindingFiller(uint8_t count, uint8_t id = 0) : m_info(count, id) {}
template <typename TFieldType>
void FillDecl(string const & attrName)
{
m_offset += dp::FillDecl<TFieldType, TVertex>(m_index, attrName, m_info, m_offset);
++m_index;
}
dp::BindingInfo m_info;
private:
size_t m_index = 0;
uint8_t m_offset = 0;
};
} // namespace dp
|