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

attribute_provider.cpp « drape - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6c677ba7b61f024c7a2406d3b8d85f4aa69e7085 (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
87
88
89
90
91
#include "attribute_provider.hpp"
#include "../base/assert.hpp"

#ifdef DEBUG
  #define INIT_CHECK_INFO(x) m_checkInfo = vector<bool>((vector<bool>::size_type)(x), false);
  #define CHECK_STREAMS CheckStreams()
  #define INIT_STREAM(x) InitCheckStream((x))
#else
  #include "../../base/macros.hpp"
  #define INIT_CHECK_INFO(x) UNUSED_VALUE((x))
  #define CHECK_STREAMS
  #define INIT_STREAM(x) UNUSED_VALUE((x))
#endif

AttributeProvider::AttributeProvider(uint8_t streamCount, uint16_t vertexCount)
  : m_vertexCount(vertexCount)
{
  m_streams.resize(streamCount);
  INIT_CHECK_INFO(streamCount);
}

/// interface for batcher
bool AttributeProvider::IsDataExists() const
{
  CHECK_STREAMS;
  return m_vertexCount > 0;
}

uint16_t AttributeProvider::GetVertexCount() const
{
  return m_vertexCount;
}

uint8_t AttributeProvider::GetStreamCount() const
{
  return m_streams.size();
}

const void * AttributeProvider::GetRawPointer(uint8_t streamIndex)
{
  ASSERT_LESS(streamIndex, GetStreamCount(), ());
  CHECK_STREAMS;
  return m_streams[streamIndex].m_data.GetRaw();
}

const BindingInfo & AttributeProvider::GetBindingInfo(uint8_t streamIndex) const
{
  ASSERT_LESS(streamIndex, GetStreamCount(), ());
  CHECK_STREAMS;
  return m_streams[streamIndex].m_binding;
}

void AttributeProvider::Advance(uint16_t vertexCount)
{
  ASSERT_LESS_OR_EQUAL(vertexCount, m_vertexCount, ());
  CHECK_STREAMS;
  for (size_t i = 0; i < GetStreamCount(); ++i)
  {
    const BindingInfo & info = m_streams[i].m_binding;
    uint32_t offset = vertexCount * info.GetElementSize();
    void * rawPointer = m_streams[i].m_data.GetRaw();
    m_streams[i].m_data = ReferencePoiner<void>((void *)(((uint8_t *)rawPointer) + offset));
  }

  m_vertexCount -= vertexCount;
}

void AttributeProvider::InitStream(uint8_t streamIndex,
                                   const BindingInfo &bindingInfo,
                                   ReferencePoiner<void> data)
{
  ASSERT_LESS(streamIndex, GetStreamCount(), ());
  AttributeStream s;
  s.m_binding = bindingInfo;
  s.m_data = data;
  m_streams[streamIndex] = s;
  INIT_STREAM(streamIndex);
}

#ifdef DEBUG
void AttributeProvider::CheckStreams() const
{
  ASSERT(std::find(m_checkInfo.begin(), m_checkInfo.end(), false) == m_checkInfo.end(),
         ("Not all streams initialized"));
}

void AttributeProvider::InitCheckStream(uint8_t streamIndex)
{
  m_checkInfo[streamIndex] = true;
}
#endif