blob: 5f6bb8fc91ab9af4bcea8a1ae31ae4ad42f6ba3f (
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
|
#include "drape/index_storage.hpp"
#include "drape/gl_functions.hpp"
#include <utility>
namespace dp
{
IndexStorage::IndexStorage()
: m_size(0)
{}
IndexStorage::IndexStorage(std::vector<uint32_t> && initial)
{
m_size = (uint32_t)initial.size();
if (IsSupported32bit())
{
m_storage = std::move(initial);
}
else
{
// We pack 2 uint16_t indices into single m_storage element.
// Every element of "initial" vector is a 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;//GLFunctions::ExtensionsList.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);
}
} // namespace dp
|