blob: e96884add77ef2a2f9afc45788ce1ce881ac824e (
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
|
#pragma once
#include "drape/texture.hpp"
#include "drape/color.hpp"
#include "drape/dynamic_texture.hpp"
#include "base/buffer_vector.hpp"
namespace dp
{
class ColorKey : public Texture::Key
{
public:
ColorKey(Color color) : Texture::Key(), m_color(color) {}
virtual Texture::ResourceType GetType() const { return Texture::Color; }
Color m_color;
};
class ColorResourceInfo : public Texture::ResourceInfo
{
public:
ColorResourceInfo(m2::RectF const & texRect) : Texture::ResourceInfo(texRect) { }
virtual Texture::ResourceType GetType() const { return Texture::Color; }
};
class ColorPalette
{
public:
ColorPalette(m2::PointU const & canvasSize);
RefPointer<Texture::ResourceInfo> MapResource(ColorKey const & key);
void UploadResources(RefPointer<Texture> texture);
glConst GetMinFilter() const;
glConst GetMagFilter() const;
void SetIsDebug(bool isDebug) { m_isDebug = isDebug; }
private:
void MoveCursor();
private:
typedef map<Color, ColorResourceInfo> TPalette;
struct PendingColor
{
m2::RectU m_rect;
Color m_color;
};
TPalette m_palette;
buffer_vector<PendingColor, 16> m_pendingNodes;
m2::PointU m_textureSize;
m2::PointU m_cursor;
bool m_isDebug = false;
};
class ColorTexture : public DynamicTexture<ColorPalette, ColorKey, Texture::Color>
{
typedef DynamicTexture<ColorPalette, ColorKey, Texture::Color> TBase;
public:
ColorTexture(m2::PointU const & size)
: m_pallete(size)
{
TBase::TextureParams params;
params.m_size = size;
params.m_format = TextureFormat::RGBA8;
params.m_minFilter = gl_const::GLNearest;
params.m_magFilter = gl_const::GLNearest;
TBase::Init(MakeStackRefPointer(&m_pallete), params);
}
~ColorTexture() { TBase::Reset(); }
private:
ColorPalette m_pallete;
};
}
|