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

route_shape.hpp « drape_frontend - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4647341c20a96a71775a8eae4f747fd4ac39699a (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
#pragma once

#include "drape_frontend/color_constants.hpp"
#include "drape_frontend/map_shape.hpp"
#include "drape_frontend/shape_view_params.hpp"

#include "drape/glstate.hpp"
#include "drape/render_bucket.hpp"
#include "drape/utils/vertex_decl.hpp"
#include "drape/pointers.hpp"

#include "traffic/speed_groups.hpp"

#include "geometry/polyline2d.hpp"

#include <vector>

namespace df
{
double const kArrowSize = 0.0008;

// Constants below depend on arrow texture.
double const kArrowTextureWidth = 74.0;
double const kArrowTextureHeight = 44.0;
double const kArrowBodyHeight = 24.0;
double const kArrowHeadTextureWidth = 32.0;
double const kArrowTailTextureWidth = 4.0;

double const kArrowHeadSize = kArrowHeadTextureWidth / kArrowTextureWidth;
float const kArrowHeadFactor = static_cast<float>(2.0 * kArrowHeadTextureWidth / kArrowTextureHeight);
double const kArrowTailSize = kArrowTailTextureWidth / kArrowTextureWidth;
float const kArrowTailFactor = static_cast<float>(2.0 * kArrowTailTextureWidth / kArrowTextureHeight);
double const kArrowHeightFactor = kArrowTextureHeight / kArrowBodyHeight;
double const kArrowAspect = kArrowTextureWidth / kArrowTextureHeight;

enum class RouteType : uint8_t
{
  Car,
  Pedestrian,
  Bicycle,
  Taxi
};

struct RoutePattern
{
  bool m_isDashed = false;
  double m_dashLength = 0.0;
  double m_gapLength = 0.0;

  RoutePattern() = default;

  RoutePattern(double dashLength, double gapLength)
    : m_isDashed(true)
    , m_dashLength(dashLength)
    , m_gapLength(gapLength)
  {}
};

struct Subroute
{
  df::RouteType m_routeType;
  m2::PolylineD m_polyline;
  df::ColorConstant m_color;
  std::vector<double> m_turns;
  std::vector<traffic::SpeedGroup> m_traffic;
  double m_baseDistance = 0.0;
  df::RoutePattern m_pattern;

  Subroute() = default;
  Subroute(m2::PolylineD const & polyline, df::ColorConstant color,
           std::vector<double> const & turns,
           std::vector<traffic::SpeedGroup> const & traffic,
           double baseDistance, df::RoutePattern pattern = df::RoutePattern())
    : m_polyline(polyline), m_color(color), m_turns(turns), m_traffic(traffic)
    , m_baseDistance(baseDistance), m_pattern(pattern)
  {}
};

struct RouteRenderProperty
{
  dp::GLState m_state;
  std::vector<drape_ptr<dp::RenderBucket>> m_buckets;
  RouteRenderProperty() : m_state(0, dp::GLState::GeometryLayer) {}
};

struct BaseRouteData
{
  dp::DrapeID m_subrouteId = 0;
  m2::PointD m_pivot = m2::PointD(0.0, 0.0);
  int m_recacheId = -1;
  RouteRenderProperty m_renderProperty;
};

struct RouteData : public BaseRouteData
{
  drape_ptr<Subroute> m_subroute;
  double m_length = 0.0;
};

struct RouteArrowsData : public BaseRouteData {};

struct ArrowBorders
{
  double m_startDistance = 0.0;
  double m_endDistance = 0.0;
  int m_groupIndex = 0;
};

class RouteShape
{
public:
  using RV = gpu::RouteVertex;
  using TGeometryBuffer = buffer_vector<RV, 128>;
  using AV = gpu::SolidTexturingVertex;
  using TArrowGeometryBuffer = buffer_vector<AV, 128>;

  static void CacheRoute(ref_ptr<dp::TextureManager> textures, RouteData & routeData);

  static void CacheRouteArrows(ref_ptr<dp::TextureManager> mng, m2::PolylineD const & polyline,
                               std::vector<ArrowBorders> const & borders,
                               RouteArrowsData & routeArrowsData);

private:
  static void PrepareGeometry(std::vector<m2::PointD> const & path, m2::PointD const & pivot,
                              std::vector<glsl::vec4> const & segmentsColors,
                              TGeometryBuffer & geometry, TGeometryBuffer & joinsGeometry,
                              double & outputLength);
  static void PrepareArrowGeometry(std::vector<m2::PointD> const & path, m2::PointD const & pivot,
                                   m2::RectF const & texRect, float depthStep, float depth,
                                   TArrowGeometryBuffer & geometry,
                                   TArrowGeometryBuffer & joinsGeometry);
  static void BatchGeometry(dp::GLState const & state, ref_ptr<void> geometry, uint32_t geomSize,
                            ref_ptr<void> joinsGeometry, uint32_t joinsGeomSize,
                            dp::BindingInfo const & bindingInfo, RouteRenderProperty & property);
};
}  // namespace df