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

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

#include "opengl/base_texture.hpp"

#include "../base/assert.hpp"
#include "../base/macros.hpp"

namespace graphics
{
  ImageRenderer::ImageRenderer(base_t::Params const & p)
    : base_t(p)
  {}

  void ImageRenderer::drawImage(math::Matrix<double, 3, 3> const & m,
                                uint32_t resID,
                                double depth)
  {
    Resource const * res(base_t::fromID(resID));

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

    ASSERT(res->m_cat == Resource::EImage, ());

    m2::RectI texRect(res->m_texRect);
    texRect.Inflate(-2, -2);

    m2::PointF pts[6] =
    {
      m2::PointF(m2::PointD(0, 0) * m),
      m2::PointF(m2::PointD(texRect.SizeX(), 0) * m),
      m2::PointF(m2::PointD(texRect.SizeX(), texRect.SizeY()) * m),
      m2::PointF(m2::PointD(texRect.SizeX(), texRect.SizeY()) * m),
      m2::PointF(m2::PointD(0, texRect.SizeY()) * m),
      m2::PointF(m2::PointD(0, 0) * m)
    };

    GeometryPipeline & p = pipeline(res->m_pipelineID);

    shared_ptr<gl::BaseTexture> const & texture = p.texture();

    m2::PointF texPts[6] =
    {
      m2::PointF(texRect.minX(), texRect.minY()),
      m2::PointF(texRect.maxX(), texRect.minY()),
      m2::PointF(texRect.maxX(), texRect.maxY()),
      m2::PointF(texRect.maxX(), texRect.maxY()),
      m2::PointF(texRect.minX(), texRect.maxY()),
      m2::PointF(texRect.minX(), texRect.minY())
    };

    for (unsigned i = 0; i < ARRAY_SIZE(texPts); ++i)
      texture->mapPixel(texPts[i].x, texPts[i].y);

    m2::PointF normal(0, 0);

    addTexturedListStrided(pts, sizeof(m2::PointF),
                           &normal, 0,
                           texPts, sizeof(m2::PointF),
                           6,
                           depth,
                           res->m_pipelineID);
  }
}