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

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

#include "../drape/texture_set_holder.hpp"
#include "../drape/attribute_provider.hpp"
#include "../drape/glstate.hpp"
#include "../drape/batcher.hpp"

#include "../drape/shader_def.hpp"

namespace df
{

PoiSymbolShape::PoiSymbolShape(m2::PointF const & mercatorPt, PoiSymbolViewParams const & params)
  : m_pt(mercatorPt)
  , m_params(params)
{
}

void PoiSymbolShape::Draw(dp::RefPointer<dp::Batcher> batcher, dp::RefPointer<dp::TextureSetHolder> textures) const
{
  dp::TextureSetHolder::SymbolRegion region;
  textures->GetSymbolRegion(m_params.m_symbolName, region);

  dp::GLState state(gpu::TEXTURING_PROGRAM, dp::GLState::OverlayLayer);
  state.SetTextureSet(region.GetTextureNode().m_textureSet);

  state.SetBlending(dp::Blending(true));

  m2::PointU pixelSize;
  region.GetPixelSize(pixelSize);
  m2::PointF const halfSize(pixelSize.x / 2.0, pixelSize.y / 2.0);
  m2::RectF const & texRect = region.GetTexRect();
  float const depth = m_params.m_depth;
  float const texture = static_cast<float>(region.GetTextureNode().m_textureOffset);

  float positions[] = {
    m_pt.x, m_pt.y, depth,
    m_pt.x, m_pt.y, depth,
    m_pt.x, m_pt.y, depth,
    m_pt.x, m_pt.y, depth
  };

  float normals[] = {
    -halfSize.x,  halfSize.y,
    -halfSize.x, -halfSize.y,
     halfSize.x,  halfSize.y,
     halfSize.x, -halfSize.y
  };

  float uvs[] = {
    texRect.minX(), texRect.maxY(), texture,
    texRect.minX(), texRect.minY(), texture,
    texRect.maxX(), texRect.maxY(), texture,
    texRect.maxX(), texRect.minY(), texture
  };

  dp::AttributeProvider provider(3, 4);
  {
    dp::BindingInfo position(1, 1);
    dp::BindingDecl & decl = position.GetBindingDecl(0);
    decl.m_attributeName = "a_position";
    decl.m_componentCount = 3;
    decl.m_componentType = gl_const::GLFloatType;
    decl.m_offset = 0;
    decl.m_stride = 0;
    provider.InitStream(0, position, dp::MakeStackRefPointer<void>(positions));
  }
  {
    dp::BindingInfo normal(1);
    dp::BindingDecl & decl = normal.GetBindingDecl(0);
    decl.m_attributeName = "a_normal";
    decl.m_componentCount = 2;
    decl.m_componentType = gl_const::GLFloatType;
    decl.m_offset = 0;
    decl.m_stride = 0;
    provider.InitStream(1, normal, dp::MakeStackRefPointer<void>(normals));
  }
  {
    dp::BindingInfo texcoord(1);
    dp::BindingDecl & decl = texcoord.GetBindingDecl(0);
    decl.m_attributeName = "a_texCoords";
    decl.m_componentCount = 3;
    decl.m_componentType = gl_const::GLFloatType;
    decl.m_offset = 0;
    decl.m_stride = 0;
    provider.InitStream(2, texcoord, dp::MakeStackRefPointer<void>(uvs));
  }

  dp::OverlayHandle * handle = new dp::SquareHandle(m_params.m_id,
                                                    dp::Center,
                                                    m_pt,
                                                    pixelSize,
                                                    depth);

  batcher->InsertTriangleStrip(state, dp::MakeStackRefPointer(&provider), dp::MovePointer(handle));
}

} // namespace df