forked from mapsme/omim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamic_texture.hpp
71 lines (57 loc) · 1.46 KB
/
dynamic_texture.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
#pragma once
#include "drape/texture.hpp"
#include "drape/glconstants.hpp"
namespace dp
{
template<typename TIndexer, typename TResourceKey, Texture::ResourceType TResourceType>
class DynamicTexture : public Texture
{
public:
virtual ~DynamicTexture()
{
ASSERT(m_indexer == nullptr, ());
}
virtual ref_ptr<ResourceInfo> FindResource(Key const & key, bool & newResource)
{
ASSERT(m_indexer != nullptr, ());
if (key.GetType() != TResourceType)
return nullptr;
return m_indexer->MapResource(static_cast<TResourceKey const &>(key), newResource);
}
virtual void UpdateState()
{
ASSERT(m_indexer != nullptr, ());
Bind();
m_indexer->UploadResources(make_ref(this));
}
protected:
DynamicTexture() {}
struct TextureParams
{
m2::PointU m_size;
dp::TextureFormat m_format;
glConst m_filter;
};
void Init(ref_ptr<HWTextureAllocator> allocator, ref_ptr<TIndexer> indexer, TextureParams const & params)
{
Init(allocator, indexer, params, nullptr);
}
void Init(ref_ptr<HWTextureAllocator> allocator, ref_ptr<TIndexer> indexer, TextureParams const & params,
ref_ptr<void> data)
{
m_indexer = indexer;
Texture::Params p;
p.m_allocator = allocator;
p.m_width = params.m_size.x;
p.m_height = params.m_size.y;
p.m_format = params.m_format;
p.m_filter = params.m_filter;
Create(p, data);
}
void Reset()
{
m_indexer = nullptr;
}
ref_ptr<TIndexer> m_indexer;
};
}