forked from organicmaps/organicmaps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_buffer_impl.hpp
126 lines (106 loc) · 3.47 KB
/
data_buffer_impl.hpp
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#pragma once
#include "drape/cpu_buffer.hpp"
#include "drape/data_buffer.hpp"
#include "drape/gpu_buffer.hpp"
#include "base/macros.hpp"
#include <cstdint>
#include <utility>
namespace dp
{
// Generic implementation of data buffer.
template <typename TBuffer>
class DataBufferImpl : public DataBufferBase
{
public:
template <typename... Args>
DataBufferImpl(Args &&... params)
: m_buffer(make_unique_dp<TBuffer>(std::forward<Args>(params)...))
{}
uint32_t GetCapacity() const override { return m_buffer->GetCapacity(); }
uint32_t GetCurrentSize() const override { return m_buffer->GetCurrentSize(); }
uint32_t GetAvailableSize() const override { return m_buffer->GetAvailableSize(); }
uint8_t GetElementSize() const override { return m_buffer->GetElementSize(); }
void Seek(uint32_t elementNumber) override { m_buffer->Seek(elementNumber); }
protected:
drape_ptr<TBuffer> m_buffer;
};
// CPU implementation of data buffer.
class CpuBufferImpl : public DataBufferImpl<CPUBuffer>
{
public:
template <typename... Args>
CpuBufferImpl(Args &&... params)
: DataBufferImpl(std::forward<Args>(params)...)
{}
void const * Data() const override { return m_buffer->Data(); }
void UploadData(ref_ptr<GraphicsContext> context, void const * data,
uint32_t elementCount) override
{
UNUSED_VALUE(context);
m_buffer->UploadData(data, elementCount);
uint32_t const newOffset = m_buffer->GetCurrentSize();
m_buffer->Seek(newOffset);
}
void * Map(ref_ptr<GraphicsContext> context, uint32_t elementOffset,
uint32_t elementCount) override
{
UNUSED_VALUE(context);
UNUSED_VALUE(elementOffset);
UNUSED_VALUE(elementCount);
ASSERT(false, ("Mapping is unavailable for CPU buffer"));
return nullptr;
}
void UpdateData(void * destPtr, void const * srcPtr, uint32_t elementOffset,
uint32_t elementCount) override
{
UNUSED_VALUE(destPtr);
UNUSED_VALUE(srcPtr);
UNUSED_VALUE(elementOffset);
UNUSED_VALUE(elementCount);
ASSERT(false, ("Data updating is unavailable for CPU buffer"));
}
void Unmap(ref_ptr<GraphicsContext> context) override
{
UNUSED_VALUE(context);
ASSERT(false, ("Unmapping is unavailable for CPU buffer"));
}
void Bind() override { ASSERT(false, ("Binding is unavailable for CPU buffer")); }
};
// GPU implementation of data buffer for OpenGL.
class GpuBufferImpl : public DataBufferImpl<GPUBuffer>
{
public:
template <typename... Args>
GpuBufferImpl(Args &&... params)
: DataBufferImpl(std::forward<Args>(params)...)
{}
void const * Data() const override
{
ASSERT(false, ("Retrieving of raw data is unavailable for GPU buffer"));
return nullptr;
}
void UploadData(ref_ptr<GraphicsContext> context, void const * data,
uint32_t elementCount) override
{
UNUSED_VALUE(context);
m_buffer->UploadData(data, elementCount);
}
void * Map(ref_ptr<GraphicsContext> context, uint32_t elementOffset,
uint32_t elementCount) override
{
UNUSED_VALUE(context);
return m_buffer->Map(elementOffset, elementCount);
}
void UpdateData(void * destPtr, void const * srcPtr, uint32_t elementOffset,
uint32_t elementCount) override
{
m_buffer->UpdateData(destPtr, srcPtr, elementOffset, elementCount);
}
void Unmap(ref_ptr<GraphicsContext> context) override
{
UNUSED_VALUE(context);
m_buffer->Unmap();
}
void Bind() override { m_buffer->Bind(); }
};
} // namespace dp