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

batcher_helpers.hpp « drape - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1d8ee5ae3b81d167cec6d9838602976fb8013a20 (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#pragma once

#include "drape/pointers.hpp"

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

namespace dp
{

class AttributeProvider;
class BindingInfo;

class BatchCallbacks
{
public:
  virtual void FlushData(BindingInfo const & binding, void const * data, uint32_t count) = 0;
  virtual void * GetIndexStorage(uint32_t indexCount, uint32_t & startIndex) = 0;
  virtual void SubmitIndices() = 0;
  virtual uint32_t GetAvailableVertexCount() const = 0;
  virtual uint32_t GetAvailableIndexCount() const = 0;
  virtual void ChangeBuffer() = 0;
};

class UniversalBatch
{
public:
  UniversalBatch(BatchCallbacks & callbacks, uint8_t minVerticesCount, uint8_t minIndicesCount);
  virtual ~UniversalBatch(){}

  virtual void BatchData(ref_ptr<AttributeProvider> streams) = 0;
  void SetCanDevideStreams(bool canDevide);
  bool CanDevideStreams() const;
  void SetVertexStride(uint8_t vertexStride);

protected:
  void FlushData(ref_ptr<AttributeProvider> streams, uint32_t vertexCount) const;
  void FlushData(BindingInfo const & info, void const * data, uint32_t elementCount) const;
  void * GetIndexStorage(uint32_t indexCount, uint32_t & startIndex);
  void SubmitIndex();
  uint32_t GetAvailableVertexCount() const;
  uint32_t GetAvailableIndexCount() const;
  void ChangeBuffer() const;
  uint8_t GetVertexStride() const;

  virtual bool IsBufferFilled(uint32_t availableVerticesCount, uint32_t availableIndicesCount) const;

private:
  BatchCallbacks & m_callbacks;
  bool m_canDevideStreams;
  uint8_t m_vertexStride;
  uint8_t const m_minVerticesCount;
  uint8_t const m_minIndicesCount;
};

class TriangleListBatch : public UniversalBatch
{
  using TBase = UniversalBatch;

public:
  TriangleListBatch(BatchCallbacks & callbacks);

  void BatchData(ref_ptr<AttributeProvider> streams) override;
};

class LineStripBatch : public UniversalBatch
{
  using TBase = UniversalBatch;

public:
  LineStripBatch(BatchCallbacks & callbacks);

  void BatchData(ref_ptr<AttributeProvider> streams) override;
};

class LineRawBatch : public UniversalBatch
{
  using TBase = UniversalBatch;

public:
  LineRawBatch(BatchCallbacks & callbacks, vector<int> const & indices);

  void BatchData(ref_ptr<AttributeProvider> streams) override;

private:
  vector<int> const & m_indices;
};

class FanStripHelper : public UniversalBatch
{
  using TBase = UniversalBatch;

public:
  FanStripHelper(BatchCallbacks & callbacks);

protected:
  uint32_t BatchIndexes(uint32_t vertexCount);
  void CalcBatchPortion(uint32_t vertexCount, uint32_t avVertex, uint32_t avIndex,
                        uint32_t & batchVertexCount, uint32_t & batchIndexCount);
  bool IsFullUploaded() const;

  virtual uint32_t VtoICount(uint32_t vCount) const;
  virtual uint32_t ItoVCount(uint32_t iCount) const;
  virtual uint32_t AlignVCount(uint32_t vCount) const;
  virtual uint32_t AlignICount(uint32_t vCount) const;
  virtual void GenerateIndexes(void * indexStorage, uint32_t count, uint32_t startIndex) const = 0;

private:
  bool m_isFullUploaded;
};

class TriangleStripBatch : public FanStripHelper
{
  using TBase = FanStripHelper;

public:
  TriangleStripBatch(BatchCallbacks & callbacks);

  virtual void BatchData(ref_ptr<AttributeProvider> streams);
protected:
  virtual void GenerateIndexes(void * indexStorage, uint32_t count, uint32_t startIndex) const;
};

class TriangleFanBatch : public FanStripHelper
{
  using TBase = FanStripHelper;

public:
  TriangleFanBatch(BatchCallbacks & callbacks);

  virtual void BatchData(ref_ptr<AttributeProvider> streams);
protected:
  virtual void GenerateIndexes(void * indexStorage, uint32_t count, uint32_t startIndex) const;
};

class TriangleListOfStripBatch : public FanStripHelper
{
  using TBase = FanStripHelper;

public:
  TriangleListOfStripBatch(BatchCallbacks & callbacks);

  virtual void BatchData(ref_ptr<AttributeProvider> streams);

protected:
  virtual bool IsBufferFilled(uint32_t availableVerticesCount, uint32_t availableIndicesCount) const;
  virtual uint32_t VtoICount(uint32_t vCount) const;
  virtual uint32_t ItoVCount(uint32_t iCount) const;
  virtual uint32_t AlignVCount(uint32_t vCount) const;
  virtual uint32_t AlignICount(uint32_t iCount) const;
  virtual void GenerateIndexes(void * indexStorage, uint32_t count, uint32_t startIndex) const;
};

} // namespace dp