Welcome to mirror list, hosted at ThFree Co, Russian Federation.

binding_info.hpp « drape - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: eee6513df267db6a7a607b7723b62b2b98ee0a14 (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
79
80
81
#pragma once

#include "drape/glfunctions.hpp"
#include "drape/glsl_types.hpp"

#include "std/string.hpp"
#include "std/shared_array.hpp"

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();
  BindingInfo(uint8_t count, uint8_t id = 0);
  ~BindingInfo();

  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:
  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(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:
  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