Welcome to mirror list, hosted at ThFree Co, Russian Federation.

texture_of_colors.hpp « drape - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 98c6ee38f1aa2b35df7b75bf4b9f56f1c91d74dc (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
82
83
84
85
#pragma once

#include "drape/texture.hpp"
#include "drape/color.hpp"
#include "drape/dynamic_texture.hpp"

#include "base/buffer_vector.hpp"

#include "std/mutex.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);

  ref_ptr<Texture::ResourceInfo> ReserveResource(bool predefined, ColorKey const & key, bool & newResource);
  ref_ptr<Texture::ResourceInfo> MapResource(ColorKey const & key, bool & newResource);
  void UploadResources(ref_ptr<Texture> texture);

  void SetIsDebug(bool isDebug) { m_isDebug = isDebug; }

private:
  typedef map<Color, ColorResourceInfo> TPalette;

  struct PendingColor
  {
    m2::RectU m_rect;
    Color m_color;
  };

  TPalette m_palette;
  TPalette m_predefinedPalette;
  buffer_vector<PendingColor, 16> m_pendingNodes;
  m2::PointU m_textureSize;
  m2::PointU m_cursor;
  bool m_isDebug = false;
  mutex m_lock;
  mutex m_mappingLock;
};

class ColorTexture : public DynamicTexture<ColorPalette, ColorKey, Texture::Color>
{
  typedef DynamicTexture<ColorPalette, ColorKey, Texture::Color> TBase;
public:
  ColorTexture(m2::PointU const & size, ref_ptr<HWTextureAllocator> allocator)
    : m_pallete(size)
  {
    TBase::TextureParams params;
    params.m_size = size;
    params.m_format = TextureFormat::RGBA8;
    params.m_filter = gl_const::GLNearest;

    TBase::Init(allocator, make_ref(&m_pallete), params);
  }

  void ReserveColor(dp::Color const & color);

  ~ColorTexture() { TBase::Reset(); }

  static int GetColorSizeInPixels();

private:
  ColorPalette m_pallete;
};

}