blob: 6a217ff7b498c652a7f8b1074da4a35d37ae47c9 (
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
|
#include "drape/index_storage.hpp"
#include "drape/glextensions_list.hpp"
#include "std/utility.hpp"
namespace dp
{
IndexStorage::IndexStorage()
: m_size(0)
{}
IndexStorage::IndexStorage(vector<uint32_t> && initial)
{
m_size = (uint32_t)initial.size();
if (IsSupported32bit())
{
m_storage = move(initial);
}
else
{
/// we pack 2 uint16_t indices into single m_storage element
/// every element of "initial" vector is single index
m_storage.resize(GetStorageSize(m_size));
for (size_t i = 0; i < initial.size(); i++)
{
uint16_t * ptr = reinterpret_cast<uint16_t *>(m_storage.data()) + i;
*ptr = (uint16_t)initial[i];
}
}
}
void IndexStorage::Resize(uint32_t size)
{
m_size = size;
m_storage.resize(GetStorageSize(m_size));
}
uint32_t IndexStorage::Size() const
{
return m_size;
}
void * IndexStorage::GetRaw(uint32_t offsetInElements)
{
if (IsSupported32bit())
return &m_storage[offsetInElements];
return reinterpret_cast<uint16_t *>(m_storage.data()) + offsetInElements;
}
void const * IndexStorage::GetRawConst() const
{
return static_cast<void const *>(m_storage.data());
}
bool IndexStorage::IsSupported32bit()
{
// We do not use 32-bit indices now to reduce size of index buffers.
static bool const supports32Bit = false;//GLExtensionsList::Instance().IsSupported(GLExtensionsList::UintIndices);
return supports32Bit;
}
uint32_t IndexStorage::SizeOfIndex()
{
return IsSupported32bit() ? sizeof(uint32_t) : sizeof(uint16_t);
}
uint32_t IndexStorage::GetStorageSize(uint32_t elementsCount) const
{
return IsSupported32bit() ? elementsCount : (elementsCount / 2 + 1);
}
}
|