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

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

#include "drape/attribute_provider.hpp"
#include "drape/graphics_context.hpp"
#include "drape/overlay_handle.hpp"
#include "drape/pointers.hpp"
#include "drape/render_bucket.hpp"
#include "drape/render_state.hpp"
#include "drape/vertex_array_buffer.hpp"

#include "base/macros.hpp"

#include <functional>
#include <map>

namespace dp
{
class RenderBucket;
class AttributeProvider;
class OverlayHandle;

class Batcher
{
public:
  static uint32_t const IndexPerTriangle = 3;
  static uint32_t const IndexPerQuad = 6;
  static uint32_t const VertexPerQuad = 4;

  Batcher(uint32_t indexBufferSize, uint32_t vertexBufferSize);
  ~Batcher();

  void InsertTriangleList(ref_ptr<GraphicsContext> context, RenderState const & state,
                          ref_ptr<AttributeProvider> params);
  IndicesRange InsertTriangleList(ref_ptr<GraphicsContext> context, RenderState const & state,
                                  ref_ptr<AttributeProvider> params,
                                  drape_ptr<OverlayHandle> && handle);

  void InsertTriangleStrip(ref_ptr<GraphicsContext> context, RenderState const & state,
                           ref_ptr<AttributeProvider> params);
  IndicesRange InsertTriangleStrip(ref_ptr<GraphicsContext> context, RenderState const & state,
                                   ref_ptr<AttributeProvider> params,
                                   drape_ptr<OverlayHandle> && handle);

  void InsertTriangleFan(ref_ptr<GraphicsContext> context, RenderState const & state,
                         ref_ptr<AttributeProvider> params);
  IndicesRange InsertTriangleFan(ref_ptr<GraphicsContext> context, RenderState const & state,
                                 ref_ptr<AttributeProvider> params,
                                 drape_ptr<OverlayHandle> && handle);

  void InsertListOfStrip(ref_ptr<GraphicsContext> context, RenderState const & state,
                         ref_ptr<AttributeProvider> params, uint8_t vertexStride);
  IndicesRange InsertListOfStrip(ref_ptr<GraphicsContext> context, RenderState const & state,
                                 ref_ptr<AttributeProvider> params,
                                 drape_ptr<OverlayHandle> && handle, uint8_t vertexStride);

  void InsertLineStrip(ref_ptr<GraphicsContext> context, RenderState const & state,
                       ref_ptr<AttributeProvider> params);
  IndicesRange InsertLineStrip(ref_ptr<GraphicsContext> context, RenderState const & state,
                               ref_ptr<AttributeProvider> params,
                               drape_ptr<OverlayHandle> && handle);

  void InsertLineRaw(ref_ptr<GraphicsContext> context, RenderState const & state,
                     ref_ptr<AttributeProvider> params, vector<int> const & indices);
  IndicesRange InsertLineRaw(ref_ptr<GraphicsContext> context, RenderState const & state,
                             ref_ptr<AttributeProvider> params, vector<int> const & indices,
                             drape_ptr<OverlayHandle> && handle);

  using TFlushFn = std::function<void (RenderState const &, drape_ptr<RenderBucket> &&)>;
  void StartSession(TFlushFn const & flusher);
  void EndSession(ref_ptr<GraphicsContext> context);
  void ResetSession();

  void SetBatcherHash(uint64_t batcherHash);

  void SetFeatureMinZoom(int minZoom);

private:
  template <typename TBatcher, typename... TArgs>
  IndicesRange InsertPrimitives(ref_ptr<GraphicsContext> context, RenderState const & state,
                                ref_ptr<AttributeProvider> params,
                                drape_ptr<OverlayHandle> && transferHandle, uint8_t vertexStride,
                                TArgs... batcherArgs);

  class CallbacksWrapper;
  void ChangeBuffer(ref_ptr<GraphicsContext> context, ref_ptr<CallbacksWrapper> wrapper);
  ref_ptr<RenderBucket> GetBucket(RenderState const & state);

  void FinalizeBucket(ref_ptr<GraphicsContext> context, RenderState const & state);
  void Flush(ref_ptr<GraphicsContext> context);

  uint32_t const m_indexBufferSize;
  uint32_t const m_vertexBufferSize;

  uint64_t m_batcherHash = 0;

  TFlushFn m_flushInterface;

  using TBuckets = std::map<RenderState, drape_ptr<RenderBucket>>;
  TBuckets m_buckets;

  int m_featureMinZoom = 0;
};

class BatcherFactory
{
public:
  BatcherFactory(uint32_t indexBufferSize, uint32_t vertexBufferSize)
    : m_indexBufferSize(indexBufferSize)
    , m_vertexBufferSize(vertexBufferSize)
  {}

  Batcher * GetNew() const;

private:
  uint32_t const m_indexBufferSize;
  uint32_t const m_vertexBufferSize;
};

class SessionGuard
{
public:
  SessionGuard(ref_ptr<GraphicsContext> context, Batcher & batcher,
               Batcher::TFlushFn const & flusher);
  ~SessionGuard();

private:
  ref_ptr<GraphicsContext> m_context;
  Batcher & m_batcher;
  DISALLOW_COPY_AND_MOVE(SessionGuard);
};
}  // namespace dp