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: 62603faed3f1ced51f9244c2c2c40cc1b5153203 (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
82
83
84
85
86
#pragma once

#include "drape/gl_constants.hpp"
#include "drape/glsl_func.hpp"
#include "drape/glsl_types.hpp"

#include <array>
#include <cstdint>
#include <string>

namespace dp
{
size_t constexpr kMaxBindingDecl = 8;
size_t constexpr kMaxBindingInfo = 2;

struct BindingDecl
{
  std::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;
  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;
  bool operator!=(BindingInfo const & other) const;
  bool operator<(BindingInfo const & other) const;

protected:
  std::array<BindingDecl, kMaxBindingDecl> m_bindings;
  uint16_t m_info;
};

template <typename TFieldType, typename TVertexType>
uint8_t FillDecl(size_t index, std::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);
}

using BindingInfoArray = std::array<dp::BindingInfo, kMaxBindingInfo>;

template <typename TVertex>
class BindingFiller
{
public:
  explicit BindingFiller(uint8_t count, uint8_t id = 0) : m_info(count, id) {}

  template <typename TFieldType>
  void FillDecl(std::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