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: c35e84f035e4f840042370ec2e56df5a402274b6 (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
#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.IsNull(), ());
  }

  virtual RefPointer<ResourceInfo> FindResource(Key const & key) const
  {
    ASSERT(!m_indexer.IsNull(), ());
    if (key.GetType() != TResourceType)
      return RefPointer<ResourceInfo>();

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

  virtual void UpdateState()
  {
    ASSERT(!m_indexer.IsNull(), ());

    Bind();
    m_indexer->UploadResources(MakeStackRefPointer<Texture>(this));
  }

protected:
  DynamicTexture() {}

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

  void Init(RefPointer<TIndexer> indexer, TextureParams const & params)
  {
    Init(indexer, params, MakeStackRefPointer<void>(nullptr));
  }

  void Init(RefPointer<TIndexer> indexer, TextureParams const & params, RefPointer<void> data)
  {
    m_indexer = indexer;
    Create(params.m_size.x, params.m_size.y, params.m_format, data);
    SetFilterParams(params.m_minFilter, params.m_magFilter);
  }

  void Reset()
  {
    m_indexer = RefPointer<TIndexer>();
  }

private:
  mutable RefPointer<TIndexer> m_indexer;
};

}