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

geometry_pipeline.cpp « graphics - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1dacdb93ca474e917c2864b9f3de9857cdbd3acc (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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#include "geometry_pipeline.hpp"
#include "resource_manager.hpp"
#include "resource_cache.hpp"
#include "opengl/buffer_object.hpp"

namespace graphics
{
  GeometryPipeline::GeometryPipeline(shared_ptr<ResourceCache> const & cache,
                                     EStorageType storageType,
                                     shared_ptr<ResourceManager> const & rm,
                                     VertexDecl const * decl)
    : m_decl(decl),
      m_cache(cache),
      m_currentVx(0),
      m_currentIdx(0),
      m_maxVx(0),
      m_maxIdx(0),
      m_rm(rm),
      m_storageType(storageType)
  {
  }

  GeometryPipeline::GeometryPipeline(ETextureType textureType,
                                     EStorageType storageType,
                                     shared_ptr<ResourceManager> const & rm,
                                     VertexDecl const * decl,
                                     uint8_t pipelineID)
    : m_decl(decl),
      m_cache(new ResourceCache(rm, textureType, pipelineID)),
      m_currentVx(0),
      m_currentIdx(0),
      m_maxVx(0),
      m_maxIdx(0),
      m_rm(rm),
      m_storageType(storageType)
  {}

  bool GeometryPipeline::hasStorage() const
  {
    return m_storage.isValid();
  }

  bool GeometryPipeline::hasTexture() const
  {
    return m_cache->texture() != 0;
  }

  void GeometryPipeline::checkStorage() const
  {
    if (!m_storage.isValid())
    {
      resetStorage();
      m_storage = m_rm->storagePool(m_storageType)->Reserve();

      if (m_storage.isValid())
      {
        if (!m_storage.m_vertices->isLocked())
          m_storage.m_vertices->lock();
        if (!m_storage.m_indices->isLocked())
          m_storage.m_indices->lock();

        m_decl->initStream(&m_vertexStream,
                           (unsigned char*)m_storage.m_vertices->data());

        m_maxVx = m_storage.m_vertices->size() / m_decl->elemSize();
        m_maxIdx = m_storage.m_indices->size() / sizeof(unsigned short);
      }
    }
  }

  void GeometryPipeline::checkTexture() const
  {
    m_cache->checkTexture();
  }

  void GeometryPipeline::resetTexture()
  {
    m_cache->resetTexture();
  }

  void GeometryPipeline::clearStorage() const
  {
    m_currentVx = 0;
    m_currentIdx = 0;
  }

  void GeometryPipeline::resetStorage() const
  {
    m_storage = gl::Storage();
    m_maxIdx = 0;
    m_maxVx = 0;
    clearStorage();
  }

  bool GeometryPipeline::hasRoom(unsigned verticesCount, unsigned indicesCount) const
  {
    checkStorage();
    if (!hasStorage())
      return false;

    return ((m_currentVx + verticesCount <= m_maxVx)
         && (m_currentIdx + indicesCount <= m_maxIdx));
  }

  void GeometryPipeline::setVertexDecl(VertexDecl * decl)
  {
    m_decl = decl;
  }

  VertexDecl const * GeometryPipeline::vertexDecl() const
  {
    return m_decl;
  }

  VertexStream * GeometryPipeline::vertexStream()
  {
    return &m_vertexStream;
  }

  shared_ptr<gl::Program> const & GeometryPipeline::program() const
  {
    return m_program;
  }

  void GeometryPipeline::setProgram(shared_ptr<gl::Program> const & prg)
  {
    m_program = prg;
  }

  uint8_t GeometryPipeline::pipelineID() const
  {
    return m_cache->pipelineID();
  }

  shared_ptr<gl::BaseTexture> const & GeometryPipeline::texture() const
  {
    return m_cache->texture();
  }

  gl::Storage const & GeometryPipeline::storage() const
  {
    return m_storage;
  }

  TTexturePool * GeometryPipeline::texturePool() const
  {
    return m_cache->texturePool();
  }

  TStoragePool * GeometryPipeline::storagePool() const
  {
    if (m_storageType != EInvalidStorage)
      return m_rm->storagePool(m_storageType);
    else
    {
      LOG(LERROR, ("no storagePool for such storageType", m_storageType));
      return 0;
    }
  }

  bool GeometryPipeline::hasGeometry() const
  {
    return m_storage.isValid() && (m_currentIdx != 0);
  }

  ResourceCache::TUploadQueue const & GeometryPipeline::uploadQueue() const
  {
    return m_cache->uploadQueue();
  }

  void GeometryPipeline::clearUploadQueue()
  {
    return m_cache->clearUploadQueue();
  }

  bool GeometryPipeline::hasUploadData() const
  {
    return m_cache->hasData();
  }

  unsigned GeometryPipeline::vxLeft() const
  {
    checkStorage();

    if (!m_storage.isValid())
      return (unsigned)-1;

    return m_maxVx - m_currentVx;
  }

  unsigned GeometryPipeline::currentVx() const
  {
    return m_currentVx;
  }

  void GeometryPipeline::advanceVx(unsigned elemCnt)
  {
    m_currentVx += elemCnt;
    m_vertexStream.advanceVertex(elemCnt);
  }

  void * GeometryPipeline::vxData()
  {
    return m_storage.m_vertices->data();
  }

  unsigned GeometryPipeline::idxLeft() const
  {
    checkStorage();

    if (!m_storage.isValid())
      return (unsigned)-1;

    return m_maxIdx - m_currentIdx;
  }

  unsigned GeometryPipeline::currentIdx() const
  {
    return m_currentIdx;
  }

  void GeometryPipeline::advanceIdx(unsigned elemCnt)
  {
    m_currentIdx += elemCnt;
  }

  void * GeometryPipeline::idxData()
  {
    return m_storage.m_indices->data();
  }

  void GeometryPipeline::addHandlesOverflowFn(ResourceCache::handlesOverflowFn const & fn,
                                              int priority)
  {
    m_cache->addHandlesOverflowFn(fn, priority);
  }

  shared_ptr<ResourceCache> const & GeometryPipeline::cache() const
  {
    return m_cache;
  }
}