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

display_list_renderer.cpp « graphics - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0f5f3b1bfb862b5b2d20454d4bf7bdf39ee82992 (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
#include "display_list_renderer.hpp"
#include "display_list.hpp"

namespace graphics
{
  DisplayListRenderer::DisplayListRenderer(Params const & p)
    : base_t(p),
      m_displayList(0)
  {
  }

  void DisplayListRenderer::addStorageRef(StorageRef const & storage)
  {
    m_discardStorageCmds[storage].first++;
    m_freeStorageCmds[storage].first++;
  }

  void DisplayListRenderer::removeStorageRef(StorageRef const & storage)
  {
    DelayedDiscardStorageMap::iterator dit = m_discardStorageCmds.find(storage);
    ASSERT(dit != m_discardStorageCmds.end(), ());

    pair<int, shared_ptr<DiscardStorageCmd> > & dval = dit->second;
    --dval.first;

    if ((dval.first == 0) && dval.second)
    {
      dval.second->perform();
      m_discardStorageCmds.erase(dit);
    }

    DelayedFreeStorageMap::iterator fit = m_freeStorageCmds.find(storage);
    ASSERT(fit != m_freeStorageCmds.end(), ());

    pair<int, shared_ptr<FreeStorageCmd> > & fval = fit->second;
    --fval.first;

    if ((fval.first == 0) && fval.second)
    {
      fval.second->perform();
      m_freeStorageCmds.erase(fit);
    }
  }

  void DisplayListRenderer::addTextureRef(TextureRef const & texture)
  {
    pair<int, shared_ptr<FreeTextureCmd> > & val = m_freeTextureCmds[texture];
    val.first++;
  }

  void DisplayListRenderer::removeTextureRef(TextureRef const & texture)
  {
    DelayedFreeTextureMap::iterator tit = m_freeTextureCmds.find(texture);
    ASSERT(tit != m_freeTextureCmds.end(), ());

    pair<int, shared_ptr<FreeTextureCmd> > & val = tit->second;
    --val.first;

    if ((val.first == 0) && val.second)
    {
      val.second->perform();
      m_freeTextureCmds.erase(tit);
    }
  }

  DisplayList * DisplayListRenderer::createDisplayList()
  {
    return new DisplayList(this);
  }

  void DisplayListRenderer::setDisplayList(DisplayList * dl)
  {
    m_displayList = dl;
  }

  DisplayList * DisplayListRenderer::displayList() const
  {
    return m_displayList;
  }

  void DisplayListRenderer::drawDisplayList(DisplayList * dl,
                                            math::Matrix<double, 3, 3> const & m)
  {
    dl->draw(this, m);
  }

  void DisplayListRenderer::drawGeometry(shared_ptr<gl::BaseTexture> const & texture,
                                         gl::Storage const & storage,
                                         size_t indicesCount,
                                         size_t indicesOffs,
                                         EPrimitives primType)
  {
    if (isCancelled())
      return;

    if (m_displayList)
    {
      shared_ptr<DrawGeometry> command(new DrawGeometry());

      command->m_texture = texture;
      command->m_storage = storage;
      command->m_indicesCount = indicesCount;
      command->m_indicesOffs = indicesOffs;
      command->m_primitiveType = primType;

      m_displayList->drawGeometry(command);
    }
    else
      base_t::drawGeometry(texture,
                           storage,
                           indicesCount,
                           indicesOffs,
                           primType);

  }

  void DisplayListRenderer::uploadResources(shared_ptr<Resource> const * resources,
                                            size_t count,
                                            shared_ptr<gl::BaseTexture> const & texture)
  {
    if (isCancelled())
      return;

    if (m_displayList)
      m_displayList->uploadResources(make_shared_ptr(new UploadData(resources, count, texture)));
    else
      base_t::uploadResources(resources, count, texture);
  }

  void DisplayListRenderer::freeTexture(shared_ptr<gl::BaseTexture> const & texture,
                                        TTexturePool * texturePool)
  {
    if (m_displayList)
    {
      shared_ptr<FreeTexture> command(new FreeTexture());

      command->m_texture = texture;
      command->m_texturePool = texturePool;

      m_freeTextureCmds[texture.get()].second = command;

//      m_displayList->freeTexture(command);
    }
    else
      base_t::freeTexture(texture, texturePool);
  }

  void DisplayListRenderer::freeStorage(gl::Storage const & storage,
                                        TStoragePool * storagePool)
  {
    if (m_displayList)
    {
      shared_ptr<FreeStorage> command(new FreeStorage());

      command->m_storage = storage;
      command->m_storagePool = storagePool;

      StorageRef sref(storage.m_vertices.get(), storage.m_indices.get());

      m_freeStorageCmds[sref].second = command;
//      m_displayList->freeStorage(command);
    }
    else
      base_t::freeStorage(storage, storagePool);
  }

  void DisplayListRenderer::unlockStorage(gl::Storage const & storage)
  {
    if (m_displayList)
    {
      shared_ptr<UnlockStorage> cmd(new UnlockStorage());

      cmd->m_storage = storage;

      m_displayList->unlockStorage(cmd);
    }
    else
      base_t::unlockStorage(storage);
  }

  void DisplayListRenderer::discardStorage(gl::Storage const & storage)
  {
    if (m_displayList)
    {
      shared_ptr<DiscardStorage> cmd(new DiscardStorage());

      cmd->m_storage = storage;

      StorageRef sref(storage.m_vertices.get(), storage.m_indices.get());

      m_discardStorageCmds[sref].second = cmd;
//      m_displayList->discardStorage(cmd);
    }
    else
      base_t::discardStorage(storage);
  }

  void DisplayListRenderer::applyBlitStates()
  {
    if (m_displayList)
      m_displayList->applyBlitStates(make_shared_ptr(new ApplyBlitStates()));
    else
      base_t::applyBlitStates();
  }

  void DisplayListRenderer::applyStates()
  {
    if (m_displayList)
      m_displayList->applyStates(make_shared_ptr(new ApplyStates()));
    else
      base_t::applyStates();
  }

  void DisplayListRenderer::applySharpStates()
  {
    if (m_displayList)
      m_displayList->applySharpStates(make_shared_ptr(new ApplySharpStates()));
    else
      base_t::applySharpStates();
  }

  void DisplayListRenderer::addCheckPoint()
  {
    if (m_displayList)
      m_displayList->addCheckPoint();
    else
      base_t::addCheckPoint();
  }

}