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

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

#include "../drape/utils/vertex_decl.hpp"
#include "../drape/glsl_types.hpp"
#include "../drape/glsl_func.hpp"
#include "../drape/overlay_handle.hpp"
#include "../drape/shader_def.hpp"
#include "../drape/attribute_provider.hpp"
#include "../drape/texture_manager.hpp"
#include "../drape/glstate.hpp"
#include "../drape/batcher.hpp"

namespace df
{

PathSymbolShape::PathSymbolShape(m2::SharedSpline const & spline,
                                 PathSymbolViewParams const & params)
  : m_params(params)
  , m_spline(spline)
{
}

void PathSymbolShape::Draw(dp::RefPointer<dp::Batcher> batcher, dp::RefPointer<dp::TextureManager> textures) const
{
  dp::TextureManager::SymbolRegion region;
  textures->GetSymbolRegion(m_params.m_symbolName, region);
  m2::RectF const & rect = region.GetTexRect();

  m2::PointU pixelSize;
  region.GetPixelSize(pixelSize);
  float halfW = pixelSize.x / 2.0f;
  float halfH = pixelSize.y / 2.0f;

  gpu::TSolidTexVertexBuffer buffer;

  m2::Spline::iterator splineIter = m_spline.CreateIterator();
  double pToGScale = 1.0 / m_params.m_baseGtoPScale;
  splineIter.Step(m_params.m_offset * pToGScale);
  float step = m_params.m_step * pToGScale;
  glsl::vec2 dummy(0.0, 0.0);
  while (!splineIter.BeginAgain())
  {
    glsl::vec2 pivot = glsl::ToVec2(splineIter.m_pos);
    glsl::vec2 n = halfH * glsl::normalize(glsl::vec2(-splineIter.m_dir.y, splineIter.m_dir.x));
    glsl::vec2 d = halfW * glsl::normalize(glsl::vec2(splineIter.m_dir.x, splineIter.m_dir.y));
    float nLength = glsl::length(n) * pToGScale;
    float dLength = glsl::length(d) * pToGScale;
    n = nLength * glsl::normalize(n);
    d = dLength * glsl::normalize(d);

    buffer.push_back(gpu::SolidTexturingVertex(glsl::vec3(pivot - d + n, m_params.m_depth), dummy, glsl::ToVec2(rect.LeftTop())));
    buffer.push_back(gpu::SolidTexturingVertex(glsl::vec3(pivot - d - n, m_params.m_depth), dummy, glsl::ToVec2(rect.LeftBottom())));
    buffer.push_back(gpu::SolidTexturingVertex(glsl::vec3(pivot + d + n, m_params.m_depth), dummy, glsl::ToVec2(rect.RightTop())));
    buffer.push_back(gpu::SolidTexturingVertex(glsl::vec3(pivot + d - n, m_params.m_depth), dummy, glsl::ToVec2(rect.RightBottom())));
    splineIter.Step(step);
  }

  if (buffer.empty())
    return;

  dp::GLState state(gpu::TEXTURING_PROGRAM, dp::GLState::GeometryLayer);
  state.SetColorTexture(region.GetTexture());
  state.SetBlending(dp::Blending(true));

  dp::AttributeProvider provider(1, 4 * buffer.size());
  provider.InitStream(0, gpu::SolidTexturingVertex::GetBindingInfo(), dp::MakeStackRefPointer<void>(buffer.data()));
  batcher->InsertListOfStrip(state, dp::MakeStackRefPointer(&provider), 4);
}

}