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

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

#include "glconstants.hpp"
#include "pointers.hpp"
#include "drape_global.hpp"

#include "std/cstdint.hpp"

namespace dp
{

class HWTextureAllocator;
class HWTexture
{
public:
  HWTexture();
  virtual ~HWTexture() {}

  struct Params
  {
    Params()
      : m_filter(gl_const::GLLinear)
      , m_wrapSMode(gl_const::GLClampToEdge)
      , m_wrapTMode(gl_const::GLClampToEdge)
      , m_format(UNSPECIFIED)
    {
    }

    uint32_t m_width;
    uint32_t m_height;
    glConst m_filter;
    glConst m_wrapSMode;
    glConst m_wrapTMode;
    TextureFormat m_format;

    ref_ptr<HWTextureAllocator> m_allocator;
  };

  void Create(Params const & params);
  virtual void Create(Params const & params, ref_ptr<void> data) = 0;
  virtual void UploadData(uint32_t x, uint32_t y, uint32_t width, uint32_t height, ref_ptr<void> data) = 0;

  void Bind() const;

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

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

protected:
  void UnpackFormat(TextureFormat format, glConst & layout, glConst & pixelType);
  int32_t GetID() const;

  uint32_t m_width;
  uint32_t m_height;
  TextureFormat m_format;
  int32_t m_textureID;
  glConst m_filter;
};

class HWTextureAllocator
{
public:
  virtual ~HWTextureAllocator() {}

  virtual drape_ptr<HWTexture> CreateTexture() = 0;
  virtual void Flush() = 0;
};

class OpenGLHWTexture : public HWTexture
{
  using TBase = HWTexture;

public:
  ~OpenGLHWTexture();
  void Create(Params const & params, ref_ptr<void> data) override;
  void UploadData(uint32_t x, uint32_t y, uint32_t width, uint32_t height, ref_ptr<void> data) override;
};

class OpenGLHWTextureAllocator : public HWTextureAllocator
{
public:
  drape_ptr<HWTexture> CreateTexture() override;
  void Flush() override {}
};

ref_ptr<HWTextureAllocator> GetDefaultAllocator();
drape_ptr<HWTextureAllocator> CreateAllocator();

}