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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
|
#include "drape_frontend/user_mark_shapes.hpp"
#include "drape_frontend/colored_symbol_shape.hpp"
#include "drape_frontend/line_shape.hpp"
#include "drape_frontend/map_shape.hpp"
#include "drape_frontend/poi_symbol_shape.hpp"
#include "drape_frontend/shape_view_params.hpp"
#include "drape_frontend/text_layout.hpp"
#include "drape_frontend/text_shape.hpp"
#include "drape_frontend/tile_utils.hpp"
#include "drape_frontend/visual_params.hpp"
#include "shaders/programs.hpp"
#include "drape/utils/vertex_decl.hpp"
#include "drape/attribute_provider.hpp"
#include "drape/batcher.hpp"
#include "indexer/feature_decl.hpp"
#include "indexer/scales.hpp"
#include "geometry/clipping.hpp"
#include "geometry/mercator.hpp"
#include <cmath>
#include <vector>
namespace df
{
std::vector<double> const kLineWidthZoomFactor =
{
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
0.3, 0.3, 0.3, 0.4, 0.5, 0.6, 0.7, 0.7, 0.7, 0.7, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
};
int const kLineSimplifyLevelEnd = 15;
namespace
{
template <typename TCreateVector>
void AlignFormingNormals(TCreateVector const & fn, dp::Anchor anchor, dp::Anchor first,
dp::Anchor second, glsl::vec2 & firstNormal, glsl::vec2 & secondNormal)
{
firstNormal = fn();
secondNormal = -firstNormal;
if ((anchor & second) != 0)
{
firstNormal *= 2;
secondNormal = glsl::vec2(0.0, 0.0);
}
else if ((anchor & first) != 0)
{
firstNormal = glsl::vec2(0.0, 0.0);
secondNormal *= 2;
}
}
void AlignHorizontal(float halfWidth, dp::Anchor anchor, glsl::vec2 & left, glsl::vec2 & right)
{
AlignFormingNormals([&halfWidth] { return glsl::vec2(-halfWidth, 0.0f); }, anchor, dp::Left,
dp::Right, left, right);
}
void AlignVertical(float halfHeight, dp::Anchor anchor, glsl::vec2 & up, glsl::vec2 & down)
{
AlignFormingNormals([&halfHeight] { return glsl::vec2(0.0f, -halfHeight); }, anchor, dp::Top,
dp::Bottom, up, down);
}
struct UserPointVertex : public gpu::BaseVertex
{
using TTexCoord = glsl::vec4;
using TColorAndAnimate = glsl::vec4;
UserPointVertex() = default;
UserPointVertex(TPosition const & pos, TNormal const & normal, TTexCoord const & texCoord,
TColorAndAnimate const & colorAndAnimate)
: m_position(pos), m_normal(normal), m_texCoord(texCoord), m_colorAndAnimate(colorAndAnimate)
{}
static dp::BindingInfo GetBinding()
{
dp::BindingInfo info(4);
uint8_t offset = 0;
offset += dp::FillDecl<TPosition, UserPointVertex>(0, "a_position", info, offset);
offset += dp::FillDecl<TNormal, UserPointVertex>(1, "a_normal", info, offset);
offset += dp::FillDecl<TTexCoord, UserPointVertex>(2, "a_texCoords", info, offset);
offset += dp::FillDecl<TColorAndAnimate, UserPointVertex>(3, "a_colorAndAnimate", info, offset);
return info;
}
TPosition m_position;
TNormal m_normal;
TTexCoord m_texCoord;
TColorAndAnimate m_colorAndAnimate;
};
std::string GetSymbolNameForZoomLevel(ref_ptr<UserPointMark::SymbolNameZoomInfo> symbolNames, TileKey const & tileKey)
{
if (!symbolNames)
return {};
for (auto itName = symbolNames->crbegin(); itName != symbolNames->crend(); ++itName)
{
if (itName->first <= tileKey.m_zoomLevel)
return itName->second;
}
return {};
}
m2::PointF GetSymbolOffsetForZoomLevel(ref_ptr<UserPointMark::SymbolOffsets> symbolOffsets, TileKey const & tileKey)
{
if (!symbolOffsets)
return m2::PointF::Zero();
CHECK_GREATER(tileKey.m_zoomLevel, 0, ());
CHECK_LESS_OR_EQUAL(tileKey.m_zoomLevel, scales::UPPER_STYLE_SCALE, ());
auto const offsetIndex = static_cast<size_t>(tileKey.m_zoomLevel - 1);
return symbolOffsets->at(offsetIndex);
}
void GenerateColoredSymbolShapes(ref_ptr<dp::GraphicsContext> context, ref_ptr<dp::TextureManager> textures,
UserMarkRenderParams const & renderInfo, TileKey const & tileKey,
m2::PointD const & tileCenter, m2::PointF const & symbolOffset,
m2::PointF & symbolSize, dp::Batcher & batcher)
{
m2::PointF sizeInc(0.0f, 0.0f);
m2::PointF offset(0.0f, 0.0f);
UserPointMark::SymbolSizes symbolSizesInc;
auto const isTextBg = renderInfo.m_coloredSymbols->m_addTextSize;
if (isTextBg)
{
auto const & titleDecl = renderInfo.m_titleDecl->at(0);
dp::FontDecl const & fontDecl = titleDecl.m_primaryTextFont;
auto isSdf = df::VisualParams::Instance().IsSdfPrefered();
isSdf = fontDecl.m_outlineColor != dp::Color::Transparent() ? true : isSdf;
auto const vs = static_cast<float>(df::VisualParams::Instance().GetVisualScale());
TextLayout textLayout;
textLayout.Init(strings::MakeUniString(titleDecl.m_primaryText), fontDecl.m_size * vs, isSdf, textures);
sizeInc.x = textLayout.GetPixelLength();
sizeInc.y = textLayout.GetPixelHeight();
if (renderInfo.m_symbolSizes != nullptr)
{
symbolSizesInc.reserve(renderInfo.m_symbolSizes->size());
for (auto const & sz : *renderInfo.m_symbolSizes)
symbolSizesInc.push_back(sz + sizeInc);
}
offset = StraightTextLayout::GetSymbolBasedTextOffset(symbolSize, titleDecl.m_anchor, renderInfo.m_anchor);
}
ColoredSymbolViewParams params;
if (renderInfo.m_coloredSymbols->m_isSymbolStub)
{
params.m_anchor = renderInfo.m_anchor;
params.m_color = dp::Color::Transparent();
params.m_shape = ColoredSymbolViewParams::Shape::Rectangle;
params.m_sizeInPixels = symbolSize;
params.m_offset = symbolOffset;
}
else
{
for (auto itSym = renderInfo.m_coloredSymbols->m_zoomInfo.rbegin();
itSym != renderInfo.m_coloredSymbols->m_zoomInfo.rend(); ++itSym)
{
if (itSym->first <= tileKey.m_zoomLevel)
{
params = itSym->second;
break;
}
}
}
m2::PointF coloredSize(0.0f, 0.0f);
if (params.m_shape == ColoredSymbolViewParams::Shape::Circle)
{
params.m_radiusInPixels = params.m_radiusInPixels + std::max(sizeInc.x, sizeInc.y) / 2.0f;
coloredSize = m2::PointF(params.m_radiusInPixels * 2.0f, params.m_radiusInPixels * 2.0f);
}
else
{
params.m_sizeInPixels = params.m_sizeInPixels + sizeInc;
coloredSize = params.m_sizeInPixels;
}
if (!isTextBg)
symbolSize = m2::PointF(std::max(coloredSize.x, symbolSize.x), std::max(coloredSize.y, symbolSize.y));
params.m_featureID = renderInfo.m_featureId;
params.m_tileCenter = tileCenter;
params.m_depthTestEnabled = renderInfo.m_depthTestEnabled;
params.m_depth = renderInfo.m_depth;
params.m_depthLayer = renderInfo.m_depthLayer;
params.m_minVisibleScale = renderInfo.m_minZoom;
params.m_specialDisplacement = renderInfo.m_displacement;
params.m_specialPriority = renderInfo.m_priority;
params.m_offset += offset;
if (renderInfo.m_symbolSizes != nullptr)
{
ColoredSymbolShape(renderInfo.m_pivot, params, tileKey,
kStartUserMarkOverlayIndex + renderInfo.m_index,
isTextBg ? symbolSizesInc : *renderInfo.m_symbolSizes.get())
.Draw(context, &batcher, textures);
}
else
{
ColoredSymbolShape(renderInfo.m_pivot, params, tileKey,
kStartUserMarkOverlayIndex + renderInfo.m_index, renderInfo.m_coloredSymbols->m_needOverlay)
.Draw(context, &batcher, textures);
}
}
void GeneratePoiSymbolShape(ref_ptr<dp::GraphicsContext> context, ref_ptr<dp::TextureManager> textures,
UserMarkRenderParams const & renderInfo, TileKey const & tileKey,
m2::PointD const & tileCenter, std::string const & symbolName,
m2::PointF const & symbolOffset, dp::Batcher & batcher)
{
PoiSymbolViewParams params(renderInfo.m_featureId);
params.m_tileCenter = tileCenter;
params.m_depthTestEnabled = renderInfo.m_depthTestEnabled;
params.m_depth = renderInfo.m_depth;
params.m_depthLayer = renderInfo.m_depthLayer;
params.m_minVisibleScale = renderInfo.m_minZoom;
params.m_specialDisplacement = renderInfo.m_displacement;
params.m_specialPriority = renderInfo.m_priority;
params.m_symbolName = symbolName;
params.m_anchor = renderInfo.m_anchor;
params.m_offset = symbolOffset;
bool const hasColoredOverlay = renderInfo.m_coloredSymbols != nullptr && renderInfo.m_coloredSymbols->m_needOverlay;
params.m_startOverlayRank = hasColoredOverlay ? dp::OverlayRank1 : dp::OverlayRank0;
PoiSymbolShape(renderInfo.m_pivot, params, tileKey,
kStartUserMarkOverlayIndex + renderInfo.m_index)
.Draw(context, &batcher, textures);
}
void GenerateTextShapes(ref_ptr<dp::GraphicsContext> context, ref_ptr<dp::TextureManager> textures,
UserMarkRenderParams const & renderInfo, TileKey const & tileKey,
m2::PointD const & tileCenter, m2::PointF const & symbolOffset,
m2::PointF const & symbolSize, dp::Batcher & batcher)
{
if (renderInfo.m_minTitleZoom > tileKey.m_zoomLevel)
return;
auto const vs = static_cast<float>(df::VisualParams::Instance().GetVisualScale());
for (auto const & titleDecl : *renderInfo.m_titleDecl)
{
if (titleDecl.m_primaryText.empty())
continue;
TextViewParams params;
params.m_featureID = renderInfo.m_featureId;
params.m_tileCenter = tileCenter;
params.m_titleDecl = titleDecl;
// Here we use visual scale to adapt texts sizes and offsets
// to different screen resolutions and DPI.
params.m_titleDecl.m_primaryTextFont.m_size *= vs;
params.m_titleDecl.m_secondaryTextFont.m_size *= vs;
params.m_titleDecl.m_primaryOffset *= vs;
params.m_titleDecl.m_secondaryOffset *= vs;
bool const isSdf = df::VisualParams::Instance().IsSdfPrefered();
params.m_titleDecl.m_primaryTextFont.m_isSdf =
params.m_titleDecl.m_primaryTextFont.m_outlineColor != dp::Color::Transparent() ? true : isSdf;
params.m_titleDecl.m_secondaryTextFont.m_isSdf =
params.m_titleDecl.m_secondaryTextFont.m_outlineColor != dp::Color::Transparent() ? true : isSdf;
params.m_depthTestEnabled = renderInfo.m_depthTestEnabled;
params.m_depth = renderInfo.m_depth;
params.m_depthLayer = renderInfo.m_depthLayer;
params.m_minVisibleScale = renderInfo.m_minZoom;
uint32_t const overlayIndex = kStartUserMarkOverlayIndex + renderInfo.m_index;
if (renderInfo.m_hasTitlePriority)
{
params.m_specialDisplacement = renderInfo.m_displacement;
params.m_specialPriority = renderInfo.m_priority;
params.m_startOverlayRank = dp::OverlayRank0;
if (renderInfo.m_symbolNames != nullptr && renderInfo.m_symbolIsPOI)
params.m_startOverlayRank++;
if (renderInfo.m_coloredSymbols != nullptr && renderInfo.m_coloredSymbols->m_needOverlay)
params.m_startOverlayRank++;
ASSERT_LESS(params.m_startOverlayRank, dp::OverlayRanksCount, ());
}
if (renderInfo.m_symbolSizes != nullptr)
{
TextShape(renderInfo.m_pivot, params, tileKey, *renderInfo.m_symbolSizes,
m2::PointF(0.0f, 0.0f) /* symbolOffset */, renderInfo.m_anchor, overlayIndex)
.Draw(context, &batcher, textures);
}
else
{
TextShape(renderInfo.m_pivot, params, tileKey, symbolSize, symbolOffset, renderInfo.m_anchor,
overlayIndex)
.Draw(context, &batcher, textures);
}
}
}
m2::SharedSpline SimplifySpline(UserLineRenderParams const & renderInfo, double sqrScale)
{
auto const vs = static_cast<float>(df::VisualParams::Instance().GetVisualScale());
m2::SharedSpline spline;
spline.Reset(new m2::Spline(renderInfo.m_spline->GetSize()));
static double const kMinSegmentLength = std::pow(4.0 * vs, 2);
m2::PointD lastAddedPoint;
for (auto const & point : renderInfo.m_spline->GetPath())
{
if (spline->GetSize() > 1 && point.SquaredLength(lastAddedPoint) * sqrScale < kMinSegmentLength)
{
spline->ReplacePoint(point);
}
else
{
spline->AddPoint(point);
lastAddedPoint = point;
}
}
return spline;
}
std::string GetBackgroundForSymbol(std::string const & symbolName,
ref_ptr<dp::TextureManager> textures)
{
static std::string const kDelimiter = "-";
static std::string const kBackgroundName = "bg";
auto const tokens = strings::Tokenize(symbolName, kDelimiter.c_str());
if (tokens.size() < 2 || tokens.size() > 3)
return {};
std::string backgroundSymbol;
if (tokens.size() == 2)
backgroundSymbol = tokens[0] + kDelimiter + kBackgroundName;
else
backgroundSymbol = tokens[0] + kDelimiter + kBackgroundName + kDelimiter + tokens[2];
return textures->HasSymbolRegion(backgroundSymbol) ? backgroundSymbol : "";
}
} // namespace
void CacheUserMarks(ref_ptr<dp::GraphicsContext> context, TileKey const & tileKey,
ref_ptr<dp::TextureManager> textures, kml::MarkIdCollection const & marksId,
UserMarksRenderCollection & renderParams, dp::Batcher & batcher)
{
using UPV = UserPointVertex;
buffer_vector<UPV, dp::Batcher::VertexPerQuad> buffer;
for (auto const id : marksId)
{
auto const it = renderParams.find(id);
if (it == renderParams.end())
continue;
UserMarkRenderParams & renderInfo = *it->second;
if (!renderInfo.m_isVisible)
continue;
m2::PointD const tileCenter = tileKey.GetGlobalRect().Center();
m2::PointF symbolSize(0.0f, 0.0f);
auto const symbolName = GetSymbolNameForZoomLevel(make_ref(renderInfo.m_symbolNames), tileKey);
if (!symbolName.empty())
{
dp::TextureManager::SymbolRegion region;
textures->GetSymbolRegion(symbolName, region);
symbolSize = region.GetPixelSize();
}
m2::PointF symbolOffset = m2::PointF::Zero();
if (renderInfo.m_symbolIsPOI)
symbolOffset = GetSymbolOffsetForZoomLevel(make_ref(renderInfo.m_symbolOffsets), tileKey);
if (renderInfo.m_coloredSymbols != nullptr)
{
GenerateColoredSymbolShapes(context, textures, renderInfo, tileKey, tileCenter, symbolOffset, symbolSize,
batcher);
}
if (renderInfo.m_symbolNames != nullptr)
{
if (renderInfo.m_symbolIsPOI)
{
GeneratePoiSymbolShape(context, textures, renderInfo, tileKey, tileCenter, symbolName, symbolOffset, batcher);
}
else if (renderInfo.m_symbolNames != nullptr)
{
dp::TextureManager::SymbolRegion region;
dp::TextureManager::SymbolRegion backgroundRegion;
buffer.clear();
textures->GetSymbolRegion(symbolName, region);
auto const backgroundSymbol = GetBackgroundForSymbol(symbolName, textures);
if (!backgroundSymbol.empty())
textures->GetSymbolRegion(backgroundSymbol, backgroundRegion);
m2::RectF const & texRect = region.GetTexRect();
m2::RectF const & bgTexRect = backgroundRegion.GetTexRect();
m2::PointF const pxSize = region.GetPixelSize();
dp::Anchor const anchor = renderInfo.m_anchor;
m2::PointD const pt = MapShape::ConvertToLocal(renderInfo.m_pivot, tileCenter,
kShapeCoordScalar);
glsl::vec3 const pos = glsl::vec3(glsl::ToVec2(pt), renderInfo.m_depth);
bool const runAnim = renderInfo.m_hasCreationAnimation && renderInfo.m_justCreated;
glsl::vec2 left, right, up, down;
AlignHorizontal(pxSize.x * 0.5f, anchor, left, right);
AlignVertical(pxSize.y * 0.5f, anchor, up, down);
m2::PointD const pixelOffset = renderInfo.m_pixelOffset;
glsl::vec2 const offset(pixelOffset.x, pixelOffset.y);
up += offset;
down += offset;
dp::Color color = dp::Color::White();
if (!renderInfo.m_color.empty())
color = df::GetColorConstant(renderInfo.m_color);
glsl::vec4 colorAndAnimate(color.GetRedF(), color.GetGreenF(), color.GetBlueF(),
runAnim ? 1.0f : -1.0f);
buffer.emplace_back(pos, left + down,
glsl::ToVec4(m2::PointD(texRect.LeftTop()), m2::PointD(bgTexRect.LeftTop())),
colorAndAnimate);
buffer.emplace_back(pos, left + up,
glsl::ToVec4(m2::PointD(texRect.LeftBottom()), m2::PointD(bgTexRect.LeftBottom())),
colorAndAnimate);
buffer.emplace_back(pos, right + down,
glsl::ToVec4(m2::PointD(texRect.RightTop()), m2::PointD(bgTexRect.RightTop())),
colorAndAnimate);
buffer.emplace_back(pos, right + up,
glsl::ToVec4(m2::PointD(texRect.RightBottom()), m2::PointD(bgTexRect.RightBottom())),
colorAndAnimate);
gpu::Program program;
gpu::Program program3d;
if (renderInfo.m_isMarkAboveText)
{
program = runAnim ? gpu::Program::BookmarkAnimAboveText
: gpu::Program::BookmarkAboveText;
program3d = runAnim ? gpu::Program::BookmarkAnimAboveTextBillboard
: gpu::Program::BookmarkAboveTextBillboard;
}
else
{
program = runAnim ? gpu::Program::BookmarkAnim
: gpu::Program::Bookmark;
program3d = runAnim ? gpu::Program::BookmarkAnimBillboard
: gpu::Program::BookmarkBillboard;
}
auto state = CreateRenderState(program, renderInfo.m_depthLayer);
state.SetProgram3d(program3d);
state.SetColorTexture(region.GetTexture());
state.SetTextureFilter(dp::TextureFilter::Nearest);
state.SetDepthTestEnabled(renderInfo.m_depthTestEnabled);
dp::AttributeProvider attribProvider(1, static_cast<uint32_t>(buffer.size()));
attribProvider.InitStream(0, UPV::GetBinding(), make_ref(buffer.data()));
batcher.InsertListOfStrip(context, state, make_ref(&attribProvider), dp::Batcher::VertexPerQuad);
}
}
if (renderInfo.m_titleDecl != nullptr)
GenerateTextShapes(context, textures, renderInfo, tileKey, tileCenter, symbolOffset, symbolSize, batcher);
if (renderInfo.m_badgeNames != nullptr)
{
ASSERT(!renderInfo.m_symbolIsPOI || renderInfo.m_symbolNames == nullptr,
("Multiple POI shapes in an usermark are not supported yet"));
auto const badgeName = GetSymbolNameForZoomLevel(make_ref(renderInfo.m_badgeNames), tileKey);
if (!badgeName.empty())
{
// TODO: Badges use symbol offset. Refactor and create own "offset"-method for badges.
symbolOffset = GetSymbolOffsetForZoomLevel(make_ref(renderInfo.m_symbolOffsets), tileKey);
GeneratePoiSymbolShape(context, textures, renderInfo, tileKey, tileCenter, badgeName, symbolOffset, batcher);
}
}
renderInfo.m_justCreated = false;
}
}
void ProcessSplineSegmentRects(m2::SharedSpline const & spline, double maxSegmentLength,
const std::function<bool(const m2::RectD & segmentRect)> & func)
{
double const splineFullLength = spline->GetLength();
double length = 0;
while (length < splineFullLength)
{
m2::RectD splineRect;
auto const itBegin = spline->GetPoint(length);
auto itEnd = spline->GetPoint(length + maxSegmentLength);
if (itEnd.BeginAgain())
{
double const lastSegmentLength = spline->GetLengths().back();
itEnd = spline->GetPoint(splineFullLength - lastSegmentLength / 2.0);
splineRect.Add(spline->GetPath().back());
}
spline->ForEachNode(itBegin, itEnd, [&splineRect](m2::PointD const & pt)
{
splineRect.Add(pt);
});
length += maxSegmentLength;
if (!func(splineRect))
return;
}
}
void CacheUserLines(ref_ptr<dp::GraphicsContext> context, TileKey const & tileKey,
ref_ptr<dp::TextureManager> textures, kml::TrackIdCollection const & linesId,
UserLinesRenderCollection & renderParams, dp::Batcher & batcher)
{
CHECK_GREATER(tileKey.m_zoomLevel, 0, ());
CHECK_LESS_OR_EQUAL(tileKey.m_zoomLevel, scales::GetUpperStyleScale(), ());
auto const vs = static_cast<float>(df::VisualParams::Instance().GetVisualScale());
bool const simplify = tileKey.m_zoomLevel <= kLineSimplifyLevelEnd;
double sqrScale = 1.0;
if (simplify)
{
double const currentScaleGtoP = 1.0 / GetScreenScale(tileKey.m_zoomLevel);
sqrScale = currentScaleGtoP * currentScaleGtoP;
}
for (auto id : linesId)
{
auto const it = renderParams.find(id);
if (it == renderParams.end())
continue;
UserLineRenderParams const & renderInfo = *it->second;
m2::RectD const tileRect = tileKey.GetGlobalRect();
double const maxLength = MercatorBounds::kRangeX / (1 << (tileKey.m_zoomLevel - 1));
bool intersected = false;
ProcessSplineSegmentRects(renderInfo.m_spline, maxLength,
[&tileRect, &intersected](m2::RectD const & segmentRect)
{
if (segmentRect.IsIntersect(tileRect))
intersected = true;
return !intersected;
});
if (!intersected)
continue;
m2::SharedSpline spline = renderInfo.m_spline;
if (simplify)
spline = SimplifySpline(renderInfo, sqrScale);
auto const clippedSplines = m2::ClipSplineByRect(tileRect, spline);
for (auto const & clippedSpline : clippedSplines)
{
for (auto const & layer : renderInfo.m_layers)
{
LineViewParams params;
params.m_tileCenter = tileKey.GetGlobalRect().Center();
params.m_baseGtoPScale = 1.0f;
params.m_cap = dp::RoundCap;
params.m_join = dp::RoundJoin;
params.m_color = layer.m_color;
params.m_depthTestEnabled = true;
params.m_depth = layer.m_depth;
params.m_depthLayer = renderInfo.m_depthLayer;
params.m_width = static_cast<float>(layer.m_width * vs *
kLineWidthZoomFactor[tileKey.m_zoomLevel - 1]);
params.m_minVisibleScale = 1;
params.m_rank = 0;
LineShape(clippedSpline, params).Draw(context, make_ref(&batcher), textures);
}
}
}
}
} // namespace df
|