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: 3e61c1747a7cac438008e241d159b2b91db71c86 (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
#include "drape_frontend/poi_symbol_shape.hpp"

#include "drape/utils/vertex_decl.hpp"
#include "drape/attribute_provider.hpp"
#include "drape/texture_manager.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::TextureManager> textures) const
{
  dp::TextureManager::SymbolRegion region;
  textures->GetSymbolRegion(m_params.m_symbolName, region);

  m2::PointU pixelSize = region.GetPixelSize();
  m2::PointF const halfSize(pixelSize.x / 2.0, pixelSize.y / 2.0);
  m2::RectF const & texRect = region.GetTexRect();

  glsl::vec3 position = glsl::vec3(glsl::ToVec2(m_pt), m_params.m_depth);

  gpu::SolidTexturingVertex vertexes[] =
  {
    gpu::SolidTexturingVertex{ position,
                               glsl::vec2(-halfSize.x,  halfSize.y),
                               glsl::vec2(texRect.minX(), texRect.maxY())},
    gpu::SolidTexturingVertex{ position,
                               glsl::vec2(-halfSize.x,  -halfSize.y),
                               glsl::vec2(texRect.minX(), texRect.minY())},
    gpu::SolidTexturingVertex{ position,
                               glsl::vec2(halfSize.x,  halfSize.y),
                               glsl::vec2(texRect.maxX(), texRect.maxY())},
    gpu::SolidTexturingVertex{ position,
                               glsl::vec2(halfSize.x,  -halfSize.y),
                               glsl::vec2(texRect.maxX(), texRect.minY())},
  };

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

  dp::AttributeProvider provider(1, 4);
  provider.InitStream(0, gpu::SolidTexturingVertex::GetBindingInfo(), dp::MakeStackRefPointer<void>(vertexes));

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

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

} // namespace df