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

texture_manager.hpp « drape - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 68a41b39f71d41cb05b1a021a5d28c8a50baba42 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#pragma once

#include "base/string_utils.hpp"

#include "drape/color.hpp"
#include "drape/pointers.hpp"
#include "drape/texture.hpp"
#include "drape/glyph_manager.hpp"

namespace dp
{

class TextureManager
{
public:
  class BaseRegion
  {
  public:
    void SetResourceInfo(RefPointer<Texture::ResourceInfo> info);
    void SetTexture(RefPointer<Texture> texture);
    RefPointer<Texture> GetTexture() const { return m_texture; }
    bool IsValid() const;

    m2::PointU GetPixelSize() const;
    uint32_t GetPixelHeight() const;
    m2::RectF const & GetTexRect() const;

  protected:
    RefPointer<Texture::ResourceInfo> m_info;
    RefPointer<Texture> m_texture;
  };

  class SymbolRegion : public BaseRegion {};

  class GlyphRegion : public BaseRegion
  {
  public:
    GlyphRegion();

    float GetOffsetX() const;
    float GetOffsetY() const;
    float GetAdvanceX() const;
    float GetAdvanceY() const;
  };

  class StippleRegion : public BaseRegion
  {
  public:
    StippleRegion() : BaseRegion() {}

    uint32_t GetMaskPixelLength() const;
    uint32_t GetPatternPixelLength() const;
  };

  class ColorRegion : public BaseRegion
  {
  public:
    ColorRegion() : BaseRegion() {}
  };

  struct Params
  {
    string m_resPrefix;
    GlyphManager::Params m_glyphMngParams;
  };

  void Init(Params const & params);
  void Release();
  void GetSymbolRegion(string const & symbolName, SymbolRegion & region) const;
  typedef buffer_vector<uint8_t, 8> TStipplePattern;
  void GetStippleRegion(TStipplePattern const & pen, StippleRegion & region) const;
  void GetColorRegion(Color const & color, ColorRegion & region) const;

  typedef buffer_vector<GlyphRegion, 32> TGlyphsBuffer;
  void GetGlyphRegions(strings::UniString const & text, TGlyphsBuffer & regions) const;
  void UpdateDynamicTextures();

private:
  struct GlyphGroup
  {
    GlyphGroup() = default;
    GlyphGroup(strings::UniChar const & start, strings::UniChar const & end)
      : m_startChar(start), m_endChar(end) {}

    strings::UniChar m_startChar = 0;
    strings::UniChar m_endChar = 0;

    MasterPointer<Texture> m_texture;
  };

  uint32_t m_maxTextureSize;

  void AllocateGlyphTexture(TextureManager::GlyphGroup & group) const;

private:
  MasterPointer<Texture> m_symbolTexture;
  MasterPointer<Texture> m_stipplePenTexture;
  MasterPointer<Texture> m_colorTexture;

  MasterPointer<GlyphManager> m_glyphManager;

  mutable buffer_vector<GlyphGroup, 64> m_glyphGroups;
  mutable buffer_vector<MasterPointer<Texture>, 4> m_hybridGlyphGroups;
};

} // namespace dp