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
|
#include <mbgl/renderer/painter.hpp>
#include <mbgl/renderer/paint_parameters.hpp>
#include <mbgl/renderer/line_bucket.hpp>
#include <mbgl/renderer/render_tile.hpp>
#include <mbgl/style/layers/line_layer.hpp>
#include <mbgl/style/layers/line_layer_impl.hpp>
#include <mbgl/programs/programs.hpp>
#include <mbgl/programs/line_program.hpp>
#include <mbgl/sprite/sprite_atlas.hpp>
#include <mbgl/geometry/line_atlas.hpp>
namespace mbgl {
using namespace style;
void Painter::renderLine(PaintParameters& parameters,
LineBucket& bucket,
const LineLayer& layer,
const RenderTile& tile) {
if (pass == RenderPass::Opaque) {
return;
}
const LinePaintProperties::Evaluated& properties = layer.impl->paint.evaluated;
auto draw = [&] (auto& program, auto&& uniformValues) {
program.draw(
context,
gl::Triangles(),
depthModeForSublayer(0, gl::DepthMode::ReadOnly),
stencilModeForClipping(tile.clip),
colorModeForRenderPass(),
std::move(uniformValues),
*bucket.vertexBuffer,
*bucket.indexBuffer,
bucket.segments,
bucket.paintPropertyBinders.at(layer.getID()),
properties,
state.getZoom()
);
};
if (!properties.get<LineDasharray>().from.empty()) {
const LinePatternCap cap = bucket.layout.get<LineCap>() == LineCapType::Round
? LinePatternCap::Round : LinePatternCap::Square;
LinePatternPos posA = lineAtlas->getDashPosition(properties.get<LineDasharray>().from, cap);
LinePatternPos posB = lineAtlas->getDashPosition(properties.get<LineDasharray>().to, cap);
lineAtlas->bind(context, 0);
draw(parameters.programs.lineSDF,
LineSDFProgram::uniformValues(
properties,
frame.pixelRatio,
tile,
state,
pixelsToGLUnits,
posA,
posB,
layer.impl->dashLineWidth,
lineAtlas->getSize().width));
} else if (!properties.get<LinePattern>().from.empty()) {
optional<SpriteAtlasElement> posA = spriteAtlas->getImage(
properties.get<LinePattern>().from, SpritePatternMode::Repeating);
optional<SpriteAtlasElement> posB = spriteAtlas->getImage(
properties.get<LinePattern>().to, SpritePatternMode::Repeating);
if (!posA || !posB)
return;
spriteAtlas->bind(true, context, 0);
draw(parameters.programs.linePattern,
LinePatternProgram::uniformValues(
properties,
tile,
state,
pixelsToGLUnits,
*posA,
*posB));
} else {
draw(parameters.programs.line,
LineProgram::uniformValues(
properties,
tile,
state,
pixelsToGLUnits));
}
}
} // namespace mbgl
|