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

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

#include "drape/index_buffer_mutator.hpp"
#include "drape/attribute_buffer_mutator.hpp"
#include "drape/pointers.hpp"
#include "drape/index_buffer.hpp"
#include "drape/data_buffer.hpp"
#include "drape/binding_info.hpp"
#include "drape/gpu_program.hpp"

#include "std/map.hpp"

namespace df
{
class BatchMergeHelper;
}

namespace dp
{

struct IndicesRange
{
  uint32_t m_idxStart;
  uint32_t m_idxCount;

  IndicesRange()
    : m_idxStart(0), m_idxCount(0)
  {}

  IndicesRange(uint32_t idxStart, uint32_t idxCount)
    : m_idxStart(idxStart), m_idxCount(idxCount)
  {}

  bool IsValid() const { return m_idxCount != 0; }
};

class VertexArrayBuffer
{
  typedef map<BindingInfo, drape_ptr<DataBuffer> > TBuffersMap;
  friend class df::BatchMergeHelper;
public:
  VertexArrayBuffer(uint32_t indexBufferSize, uint32_t dataBufferSize);
  ~VertexArrayBuffer();

  /// This method must be call on reading thread, before VAO will be transfer on render thread
  void Preflush();

  ///{@
  /// On devices where implemented OES_vertex_array_object extensions we use it for build VertexArrayBuffer
  /// OES_vertex_array_object create OpenGL resource that belong only one GL context (which was created by)
  /// by this reason Build/Bind and Render must be called only on Frontendrendere thread
  void Render(bool drawAsLine);
  void RenderRange(bool drawAsLine, IndicesRange const & range);
  void Build(ref_ptr<GpuProgram> program);
  ///@}

  uint32_t GetAvailableVertexCount() const;
  uint32_t GetAvailableIndexCount() const;
  uint32_t GetStartIndexValue() const;
  uint32_t GetDynamicBufferOffset(BindingInfo const & bindingInfo);
  uint32_t GetIndexCount() const;

  void UploadData(BindingInfo const & bindingInfo, void const * data, uint32_t count);
  void UploadIndexes(void const * data, uint32_t count);

  void ApplyMutation(ref_ptr<IndexBufferMutator> indexMutator,
                     ref_ptr<AttributeBufferMutator> attrMutator);

  void ResetChangingTracking() { m_isChanged = false; }
  bool IsChanged() const { return m_isChanged; }

private:
  ref_ptr<DataBuffer> GetOrCreateStaticBuffer(BindingInfo const & bindingInfo);
  ref_ptr<DataBuffer> GetOrCreateDynamicBuffer(BindingInfo const & bindingInfo);
  ref_ptr<DataBuffer> GetDynamicBuffer(BindingInfo const & bindingInfo) const;

  ref_ptr<DataBuffer> GetOrCreateBuffer(BindingInfo const & bindingInfo, bool isDynamic);
  ref_ptr<DataBuffer> GetBuffer(BindingInfo const & bindingInfo, bool isDynamic) const;
  bool Bind() const;
  void Unbind() const;
  void BindStaticBuffers() const;
  void BindDynamicBuffers() const;
  void BindBuffers(TBuffersMap const & buffers) const;

  ref_ptr<DataBufferBase> GetIndexBuffer() const;

  void PreflushImpl();

private:
  /// m_VAO - VertexArrayObject name/identificator
  int m_VAO;
  TBuffersMap m_staticBuffers;
  TBuffersMap m_dynamicBuffers;

  drape_ptr<IndexBuffer> m_indexBuffer;
  uint32_t m_dataBufferSize;

  ref_ptr<GpuProgram> m_program;

  bool m_isPreflushed;
  bool m_moveToGpuOnBuild;
  bool m_isChanged;
};

} // namespace dp