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

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

#include "opengl/base_texture.hpp"

#include "../base/logging.hpp"

namespace graphics
{
  AreaRenderer::Params::Params()
    : m_drawAreas(true)
  {
  }

  AreaRenderer::AreaRenderer(Params const & params)
    : base_t(params),
      m_drawAreas(params.m_drawAreas)
  {}

  void AreaRenderer::beginFrame()
  {
    base_t::beginFrame();
    m_areasCount = 0;
    m_trianglesCount = 0;
  }

  void AreaRenderer::endFrame()
  {
    if (isDebugging())
    {
      LOG(LINFO, ("drawing ", m_areasCount, " areas, ", m_trianglesCount, " triangles total"));
    }
    base_t::endFrame();
  }

  void AreaRenderer::drawTrianglesFan(m2::PointF const * points,
                                      size_t pointsCount,
                                      uint32_t resID,
                                      double depth)
  {
    ++m_areasCount;
    m_trianglesCount += (pointsCount - 2);

    if (!m_drawAreas)
      return;

    Resource const * res = base_t::fromID(resID);

    ASSERT(res->m_cat == Resource::EBrush, ("triangleFan should be rendered with Brush resource"));

    if (res == 0)
    {
      LOG(LINFO, ("drawTrianglesFan: resID=", resID, " wasn't found on current skin."));
      return;
    }

    ASSERT_GREATER_OR_EQUAL(pointsCount, 2, ());

    float texX = res->m_texRect.minX() + 1.0f;
    float texY = res->m_texRect.minY() + 1.0f;

    GeometryPipeline & p = pipeline(res->m_pipelineID);
    shared_ptr<gl::BaseTexture> texture = p.texture();

    if (!texture)
    {
      LOG(LDEBUG, ("returning as no texture is reserved"));
      return;
    }

    texture->mapPixel(texX, texY);

    m2::PointF texCoord(texX, texY);
    m2::PointF normal(0, 0);

    addTexturedFanStrided(points, sizeof(m2::PointF),
                          &normal, 0,
                          &texCoord, 0,
                          pointsCount,
                          depth,
                          res->m_pipelineID);
  }

  void AreaRenderer::drawTrianglesList(m2::PointD const * points, size_t pointsCount, uint32_t resID, double depth)
  {
    ++m_areasCount;
    m_trianglesCount += pointsCount / 3;

    if (!m_drawAreas)
      return;

    Resource const * res = base_t::fromID(resID);

    ASSERT(res->m_cat == Resource::EBrush, ("area should be rendered with Brush resource"));

    if (res == 0)
    {
      LOG(LINFO, ("drawArea: resID=", resID, " wasn't found on current skin."));
      return;
    }

    if (!hasRoom(pointsCount, pointsCount, res->m_pipelineID))
      flush(res->m_pipelineID);

    ASSERT_GREATER_OR_EQUAL(pointsCount, 2, ());

    float texX = res->m_texRect.minX() + 1.0f;
    float texY = res->m_texRect.minY() + 1.0f;

    GeometryPipeline & p = pipeline(res->m_pipelineID);
    shared_ptr<gl::BaseTexture> texture = p.texture();

    if (!texture)
    {
      LOG(LDEBUG, ("returning as no texture is reserved"));
      return;
    }

    texture->mapPixel(texX, texY);

    size_t pointsLeft = pointsCount;
    size_t batchOffset = 0;

    while (true)
    {
      size_t batchSize = pointsLeft;

      int vLeft = verticesLeft(res->m_pipelineID);
      int iLeft = indicesLeft(res->m_pipelineID);

      if ((vLeft == -1) || (iLeft == -1))
        return;

      if (batchSize > vLeft)
        /// Rounding to the boundary of 3 vertices
        batchSize = vLeft / 3 * 3;

      if (batchSize > iLeft)
        batchSize = iLeft / 3 * 3;

      bool needToFlush = (batchSize < pointsLeft);

      m2::PointF texCoord(texX, texY);
      m2::PointF normal(0, 0);

      addTexturedListStrided(&points[batchOffset], sizeof(m2::PointD),
                             &normal, 0,
                             &texCoord, 0,
                             batchSize,
                             depth,
                             res->m_pipelineID);

      batchOffset += batchSize;
      pointsLeft -= batchSize;

      if (needToFlush)
        flush(res->m_pipelineID);

      if (pointsLeft == 0)
        break;
    }
  }
}