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

tile_renderer.hpp « map - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 96e6d97b3f383864fd08b8e18893eae07e305605 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#pragma once

#include "render_policy.hpp"
#include "tiler.hpp"
#include "tile_cache.hpp"
#include "tile_set.hpp"
#include "drawer.hpp"

#include "../geometry/screenbase.hpp"

#include "../base/thread.hpp"
#include "../base/threaded_list.hpp"
#include "../base/commands_queue.hpp"

#include "../std/shared_ptr.hpp"
#include "../std/vector.hpp"

namespace graphics
{
  class ResourceManager;
  class PacketsQueue;

  namespace gl
  {
    class RenderContext;
  }
}

class WindowHandle;
class Drawer;

class TileRenderer
{
protected:

  core::CommandsQueue m_queue;

  shared_ptr<graphics::ResourceManager> m_resourceManager;

  struct ThreadData
  {
    Drawer * m_drawer;
    Drawer::Params m_drawerParams;
    shared_ptr<graphics::gl::BaseTexture> m_dummyRT;
    shared_ptr<graphics::gl::RenderContext> m_renderContext;
    shared_ptr<graphics::gl::RenderBuffer> m_depthBuffer;
  };

  buffer_vector<ThreadData, 4> m_threadData;

  shared_ptr<graphics::gl::RenderContext> m_primaryContext;

  TileCache m_tileCache;

  /// set of already rendered tiles, which are waiting
  /// for the CoverageGenerator to process them
  TileSet m_tileSet;

  size_t m_tileSize;

  RenderPolicy::TRenderFn m_renderFn;
  string m_skinName;
  graphics::Color m_bgColor;
  int m_sequenceID;
  bool m_isExiting;

  bool m_isPaused;

  threads::Mutex m_tilesInProgressMutex;
  set<Tiler::RectInfo> m_tilesInProgress;

  void InitializeThreadGL(core::CommandsQueue::Environment const & env);
  void FinalizeThreadGL(core::CommandsQueue::Environment const & env);

protected:

  virtual void DrawTile(core::CommandsQueue::Environment const & env,
                        Tiler::RectInfo const & rectInfo,
                        int sequenceID);

  void ReadPixels(graphics::PacketsQueue * glQueue, core::CommandsQueue::Environment const & env);

public:

  /// constructor.
  TileRenderer(size_t tileSize,
               string const & skinName,
               unsigned tasksCount,
               graphics::Color const & bgColor,
               RenderPolicy::TRenderFn const & renderFn,
               shared_ptr<graphics::gl::RenderContext> const & primaryRC,
               shared_ptr<graphics::ResourceManager> const & rm,
               double visualScale,
               graphics::PacketsQueue ** packetsQueue);
  /// destructor.
  virtual ~TileRenderer();
  /// add command to the commands queue.
  void AddCommand(Tiler::RectInfo const & rectInfo,
                  int sequenceID,
                  core::CommandsQueue::Chain const & afterTileFns = core::CommandsQueue::Chain());
  /// get tile cache.
  TileCache & GetTileCache();
  /// get tile set
  TileSet & GetTileSet();
  /// wait on a condition variable for an empty queue.
  void WaitForEmptyAndFinished();

  void SetSequenceID(int sequenceID);

  void CancelCommands();

  void ClearCommands();

  bool HasTile(Tiler::RectInfo const & rectInfo);

  /// add tile to the temporary set of rendered tiles, cache it and lock it in the cache.
  /// temporary set is necessary to carry the state between corresponding Tile rendering
  /// commands and MergeTile commands.
  void AddActiveTile(Tile const & tile);
  /// remove tile from the TileSet.
  /// @param doUpdateCache shows, whether we should
  void RemoveActiveTile(Tiler::RectInfo const & rectInfo);

  void SetIsPaused(bool flag);

  size_t TileSize() const;
};