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

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

namespace graphics
{
  DisplayList::DisplayList(DisplayListRenderer * parent)
    : m_parent(parent),
      m_isDebugging(false)
  {}

  DisplayList::~DisplayList()
  {
    set<TextureRef>::const_iterator tit;
    for (tit = m_textures.begin();
         tit != m_textures.end();
         ++tit)
      m_parent->removeTextureRef(*tit);

    set<StorageRef>::const_iterator sit;
    for (sit = m_storages.begin();
         sit != m_storages.end();
         ++sit)
      m_parent->removeStorageRef(*sit);

    m_commands.clear();
  }

  void DisplayList::applySharpStates(shared_ptr<ApplySharpStatesCmd> const & cmd)
  {
    cmd->setIsDebugging(m_isDebugging);
    m_commands.push_back(cmd);
  }

  void DisplayList::applyBlitStates(shared_ptr<ApplyBlitStatesCmd> const & cmd)
  {
    cmd->setIsDebugging(m_isDebugging);
    m_commands.push_back(cmd);
  }

  void DisplayList::applyStates(shared_ptr<ApplyStatesCmd> const & cmd)
  {
    cmd->setIsDebugging(m_isDebugging);
    m_commands.push_back(cmd);
  }

  void DisplayList::makeTextureRef(shared_ptr<gl::BaseTexture> const & texture)
  {
    TextureRef tref(texture.get());

    if (texture && m_textures.insert(tref).second)
      m_parent->addTextureRef(tref);
  }

  void DisplayList::makeStorageRef(gl::Storage const & storage)
  {
    StorageRef sref(storage.m_vertices.get(), storage.m_indices.get());

    if (storage.isValid() && m_storages.insert(sref).second)
      m_parent->addStorageRef(sref);
  }

  void DisplayList::drawGeometry(shared_ptr<DrawGeometryCmd> const & cmd)
  {
    cmd->setIsDebugging(m_isDebugging);
    makeTextureRef(cmd->m_texture);
    makeStorageRef(cmd->m_storage);
    m_commands.push_back(cmd);
  }

  void DisplayList::drawRouteGeometry(shared_ptr<DrawRouteGeometryCmd> const & cmd)
  {
    cmd->setIsDebugging(m_isDebugging);
    makeTextureRef(cmd->m_texture);
    m_commands.push_back(cmd);
  }

  void DisplayList::unlockStorage(shared_ptr<UnlockStorageCmd> const & cmd)
  {
    cmd->setIsDebugging(m_isDebugging);
    m_parent->processCommand(cmd);
  }

  void DisplayList::freeStorage(shared_ptr<FreeStorageCmd> const & cmd)
  {
  }

  void DisplayList::freeTexture(shared_ptr<FreeTextureCmd> const & cmd)
  {
  }

  void DisplayList::discardStorage(shared_ptr<DiscardStorageCmd> const & cmd)
  {
  }

  void DisplayList::uploadResources(shared_ptr<UploadDataCmd> const & cmd)
  {
    cmd->setIsDebugging(m_isDebugging);
    m_parent->processCommand(cmd);
  }

  void DisplayList::clear(shared_ptr<ClearCommandCmd> const & cmd)
  {
    cmd->setIsDebugging(m_isDebugging);
    m_commands.push_back(cmd);
  }

  void DisplayList::addCheckPoint()
  {
    static_cast<gl::Renderer*>(m_parent)->addCheckPoint();
  }

  void DisplayList::draw(DisplayListRenderer * r, math::Matrix<double, 3, 3> const & m,
                         UniformsHolder * holder, size_t indicesCount)
  {
    math::Matrix<float, 4, 4> mv;

    /// preparing ModelView matrix

    mv(0, 0) = m(0, 0); mv(0, 1) = m(1, 0); mv(0, 2) = 0; mv(0, 3) = m(2, 0);
    mv(1, 0) = m(0, 1); mv(1, 1) = m(1, 1); mv(1, 2) = 0; mv(1, 3) = m(2, 1);
    mv(2, 0) = 0;       mv(2, 1) = 0;       mv(2, 2) = 1; mv(2, 3) = 0;
    mv(3, 0) = m(0, 2); mv(3, 1) = m(1, 2); mv(3, 2) = 0; mv(3, 3) = m(2, 2);

    r->renderContext()->setMatrix(EModelView, mv);

    /// drawing collected geometry

    for (list<shared_ptr<Command> >::const_iterator it = m_commands.begin();
         it != m_commands.end();
         ++it)
    {
      (*it)->setRenderContext(r->renderContext());
      if (holder != NULL && (*it)->isNeedAdditionalUniforms())
        (*it)->setAdditionalUniforms(*holder);
      else
        (*it)->resetAdditionalUniforms();

      if ((*it)->isNeedIndicesCount())
        (*it)->setIndicesCount(indicesCount);

      (*it)->perform();
    }

    r->renderContext()->setMatrix(EModelView, math::Identity<double, 4>());
  }
}