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: 0270e097ec217475d81aed85b2b36b23d4527c05 (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
#pragma once

#include "drape/pointers.hpp"

#include "std/function.hpp"

namespace dp
{

class AttributeProvider;
class BindingInfo;

class BatchCallbacks
{
public:
  typedef function<void (BindingInfo const &, void const *, uint16_t)> TFlushVertexFn;
  typedef function<uint16_t * (uint16_t, uint16_t &)> TGetIndexStorageFn;
  typedef function<void ()> TSubmitIndexFn;
  typedef function<uint16_t ()> TGetAvailableFn;
  typedef function<void (bool)> ChangeBufferFn;

  TFlushVertexFn      m_flushVertex;
  TGetIndexStorageFn m_getIndexStorage;
  TSubmitIndexFn      m_submitIndex;
  TGetAvailableFn     m_getAvailableVertex;
  TGetAvailableFn     m_getAvailableIndex;
  ChangeBufferFn     m_changeBuffer;
};

class TriangleBatch
{
public:
  TriangleBatch(BatchCallbacks const & callbacks);

  virtual void BatchData(RefPointer<AttributeProvider> streams) = 0;
  void SetIsCanDevideStreams(bool canDevide);
  bool IsCanDevideStreams() const;
  void SetVertexStride(uint8_t vertexStride);

protected:
  void FlushData(RefPointer<AttributeProvider> streams, uint16_t vertexVount) const;
  void FlushData(BindingInfo const & info, void const * data, uint16_t elementCount) const;
  uint16_t * GetIndexStorage(uint16_t indexCount, uint16_t & startIndex);
  void SubmitIndex();
  uint16_t GetAvailableVertexCount() const;
  uint16_t GetAvailableIndexCount() const;
  void ChangeBuffer(bool checkFilled) const;
  uint8_t GetVertexStride() const;


private:
  BatchCallbacks m_callbacks;
  bool m_canDevideStreams;
  uint8_t m_vertexStride;
};

class TriangleListBatch : public TriangleBatch
{
  typedef TriangleBatch TBase;

public:
  TriangleListBatch(BatchCallbacks const & callbacks);

  virtual void BatchData(RefPointer<AttributeProvider> streams);
};

class FanStripHelper : public TriangleBatch
{
  typedef TriangleBatch TBase;

public:
  FanStripHelper(BatchCallbacks const & callbacks);

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

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

private:
  bool m_isFullUploaded;
};

class TriangleStripBatch : public FanStripHelper
{
  typedef FanStripHelper TBase;

public:
  TriangleStripBatch(BatchCallbacks const & callbacks);

  virtual void BatchData(RefPointer<AttributeProvider> streams);
};

class TriangleFanBatch : public FanStripHelper
{
  typedef FanStripHelper TBase;

public:
  TriangleFanBatch(BatchCallbacks const & callbacks);

  virtual void BatchData(RefPointer<AttributeProvider> streams);
};

class TriangleListOfStripBatch : public FanStripHelper
{
  typedef FanStripHelper TBase;

public:
  TriangleListOfStripBatch(BatchCallbacks const & callbacks);

  virtual void BatchData(RefPointer<AttributeProvider> streams);

protected:
  virtual uint16_t VtoICount(uint16_t vCount) const;
  virtual uint16_t ItoVCount(uint16_t iCount) const;
  virtual uint16_t AlignVCount(uint16_t vCount) const;
  virtual void GenerateIndexes(uint16_t * indexStorage, uint16_t count, uint16_t startIndex) const;
};

} // namespace dp