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

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

#include "drape/texture.hpp"
#include "drape/glconstants.hpp"

namespace dp
{

template<typename TIndexer, typename TResourceKey, Texture::ResourceType TResourceType>
class DynamicTexture : public Texture
{
public:
  virtual ~DynamicTexture()
  {
    ASSERT(m_indexer == nullptr, ());
  }

  virtual ref_ptr<ResourceInfo> FindResource(Key const & key, bool & newResource)
  {
    ASSERT(m_indexer != nullptr, ());
    if (key.GetType() != TResourceType)
      return nullptr;

    return m_indexer->MapResource(static_cast<TResourceKey const &>(key), newResource);
  }

  virtual void UpdateState()
  {
    ASSERT(m_indexer != nullptr, ());
    Bind();
    m_indexer->UploadResources(make_ref(this));
  }

protected:
  DynamicTexture() {}

  struct TextureParams
  {
    m2::PointU m_size;
    dp::TextureFormat m_format;
    glConst m_filter;
  };

  void Init(ref_ptr<HWTextureAllocator> allocator, ref_ptr<TIndexer> indexer, TextureParams const & params)
  {
    Init(allocator, indexer, params, nullptr);
  }

  void Init(ref_ptr<HWTextureAllocator> allocator, ref_ptr<TIndexer> indexer, TextureParams const & params,
            ref_ptr<void> data)
  {
    m_indexer = indexer;
    Texture::Params p;
    p.m_allocator = allocator;
    p.m_width = params.m_size.x;
    p.m_height = params.m_size.y;
    p.m_format = params.m_format;
    p.m_filter = params.m_filter;

    Create(p, data);
  }

  void Reset()
  {
    m_indexer = nullptr;
  }

  ref_ptr<TIndexer> m_indexer;
};

}