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

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

#include "drape/graphics_context.hpp"
#include "drape/hw_texture.hpp"
#include "drape/pointers.hpp"
#include "drape/texture_types.hpp"

#include "geometry/rect2d.hpp"

#include "base/macros.hpp"

#include <cstdint>

namespace dp
{
class Texture
{
public:
  enum class ResourceType : uint8_t
  {
    Symbol,
    Glyph,
    StipplePen,
    Color,
    Static
  };

  class Key
  {
  public:
    virtual ~Key() = default;
    virtual ResourceType GetType() const = 0;
  };

  class ResourceInfo
  {
  public:
    explicit ResourceInfo(m2::RectF const & texRect);
    virtual ~ResourceInfo() = default;
    virtual ResourceType GetType() const = 0;
    m2::RectF const & GetTexRect() const;

  private:
    m2::RectF m_texRect;
  };

  Texture() = default;
  virtual ~Texture();

  virtual ref_ptr<ResourceInfo> FindResource(Key const & key, bool & newResource) = 0;
  virtual void UpdateState(ref_ptr<dp::GraphicsContext> context) {}
  virtual bool HasEnoughSpace(uint32_t /* newKeysCount */) const { return true; }
  using Params = HWTexture::Params;

  virtual TextureFormat GetFormat() const;
  virtual uint32_t GetWidth() const;
  virtual uint32_t GetHeight() const;
  virtual float GetS(uint32_t x) const;
  virtual float GetT(uint32_t y) const;
  virtual uint32_t GetID() const;

  virtual void Bind(ref_ptr<dp::GraphicsContext> context) const;

  // Texture must be bound before calling this method.
  virtual void SetFilter(TextureFilter filter);

  virtual void Create(ref_ptr<dp::GraphicsContext> context, Params const & params);
  virtual void Create(ref_ptr<dp::GraphicsContext> context, Params const & params,
                      ref_ptr<void> data);
  void UploadData(ref_ptr<dp::GraphicsContext> context, uint32_t x, uint32_t y,
                  uint32_t width, uint32_t height, ref_ptr<void> data);
  
  ref_ptr<HWTexture> GetHardwareTexture() const;

  static bool IsPowerOfTwo(uint32_t width, uint32_t height);

protected:
  void Destroy();
  bool AllocateTexture(ref_ptr<dp::GraphicsContext> context,
                       ref_ptr<HWTextureAllocator> allocator);

  drape_ptr<HWTexture> m_hwTexture;

  DISALLOW_COPY_AND_MOVE(Texture);
};
}  // namespace dp