1 #include <mbgl/programs/line_program.hpp>
2 #include <mbgl/style/layers/line_layer_properties.hpp>
3 #include <mbgl/renderer/render_tile.hpp>
4 #include <mbgl/renderer/image_atlas.hpp>
5 #include <mbgl/map/transform_state.hpp>
6 #include <mbgl/util/mat2.hpp>
7 #include <mbgl/geometry/line_atlas.hpp>
8
9 namespace mbgl {
10
11 using namespace style;
12
13 static_assert(sizeof(LineLayoutVertex) == 12, "expected LineLayoutVertex size");
14
15 template <class Values, class...Args>
makeValues(const RenderLinePaintProperties::PossiblyEvaluated & properties,const RenderTile & tile,const TransformState & state,const std::array<float,2> & pixelsToGLUnits,Args &&...args)16 Values makeValues(const RenderLinePaintProperties::PossiblyEvaluated& properties,
17 const RenderTile& tile,
18 const TransformState& state,
19 const std::array<float, 2>& pixelsToGLUnits,
20 Args&&... args) {
21
22 return Values {
23 uniforms::u_matrix::Value{
24 tile.translatedMatrix(properties.get<LineTranslate>(),
25 properties.get<LineTranslateAnchor>(),
26 state)
27 },
28 uniforms::u_ratio::Value{ 1.0f / tile.id.pixelsToTileUnits(1.0, state.getZoom()) },
29 uniforms::u_gl_units_to_pixels::Value{{{ 1.0f / pixelsToGLUnits[0], 1.0f / pixelsToGLUnits[1] }}},
30 std::forward<Args>(args)...
31 };
32 }
33
34 LineProgram::UniformValues
uniformValues(const RenderLinePaintProperties::PossiblyEvaluated & properties,const RenderTile & tile,const TransformState & state,const std::array<float,2> & pixelsToGLUnits)35 LineProgram::uniformValues(const RenderLinePaintProperties::PossiblyEvaluated& properties,
36 const RenderTile& tile,
37 const TransformState& state,
38 const std::array<float, 2>& pixelsToGLUnits) {
39 return makeValues<LineProgram::UniformValues>(
40 properties,
41 tile,
42 state,
43 pixelsToGLUnits
44 );
45 }
46
47 LineSDFProgram::UniformValues
uniformValues(const RenderLinePaintProperties::PossiblyEvaluated & properties,float pixelRatio,const RenderTile & tile,const TransformState & state,const std::array<float,2> & pixelsToGLUnits,const LinePatternPos & posA,const LinePatternPos & posB,float atlasWidth)48 LineSDFProgram::uniformValues(const RenderLinePaintProperties::PossiblyEvaluated& properties,
49 float pixelRatio,
50 const RenderTile& tile,
51 const TransformState& state,
52 const std::array<float, 2>& pixelsToGLUnits,
53 const LinePatternPos& posA,
54 const LinePatternPos& posB,
55 float atlasWidth) {
56 const float widthA = posA.width * properties.get<LineDasharray>().fromScale;
57 const float widthB = posB.width * properties.get<LineDasharray>().toScale;
58
59 std::array<float, 2> scaleA {{
60 1.0f / tile.id.pixelsToTileUnits(widthA, state.getIntegerZoom()),
61 -posA.height / 2.0f
62 }};
63
64 std::array<float, 2> scaleB {{
65 1.0f / tile.id.pixelsToTileUnits(widthB, state.getIntegerZoom()),
66 -posB.height / 2.0f
67 }};
68
69 return makeValues<LineSDFProgram::UniformValues>(
70 properties,
71 tile,
72 state,
73 pixelsToGLUnits,
74 uniforms::u_patternscale_a::Value{ scaleA },
75 uniforms::u_patternscale_b::Value{ scaleB },
76 uniforms::u_tex_y_a::Value{ posA.y },
77 uniforms::u_tex_y_b::Value{ posB.y },
78 uniforms::u_mix::Value{ properties.get<LineDasharray>().t },
79 uniforms::u_sdfgamma::Value{ atlasWidth / (std::min(widthA, widthB) * 256.0f * pixelRatio) / 2.0f },
80 uniforms::u_image::Value{ 0 }
81 );
82 }
83
84 LinePatternProgram::UniformValues
uniformValues(const RenderLinePaintProperties::PossiblyEvaluated & properties,const RenderTile & tile,const TransformState & state,const std::array<float,2> & pixelsToGLUnits,const Size atlasSize,const ImagePosition & posA,const ImagePosition & posB)85 LinePatternProgram::uniformValues(const RenderLinePaintProperties::PossiblyEvaluated& properties,
86 const RenderTile& tile,
87 const TransformState& state,
88 const std::array<float, 2>& pixelsToGLUnits,
89 const Size atlasSize,
90 const ImagePosition& posA,
91 const ImagePosition& posB) {
92 std::array<float, 2> sizeA {{
93 tile.id.pixelsToTileUnits(posA.displaySize()[0] * properties.get<LinePattern>().fromScale, state.getIntegerZoom()),
94 posA.displaySize()[1]
95 }};
96
97 std::array<float, 2> sizeB {{
98 tile.id.pixelsToTileUnits(posB.displaySize()[0] * properties.get<LinePattern>().toScale, state.getIntegerZoom()),
99 posB.displaySize()[1]
100 }};
101
102 return makeValues<LinePatternProgram::UniformValues>(
103 properties,
104 tile,
105 state,
106 pixelsToGLUnits,
107 uniforms::u_pattern_tl_a::Value{ posA.tl() },
108 uniforms::u_pattern_br_a::Value{ posA.br() },
109 uniforms::u_pattern_tl_b::Value{ posB.tl() },
110 uniforms::u_pattern_br_b::Value{ posB.br() },
111 uniforms::u_pattern_size_a::Value{ sizeA },
112 uniforms::u_pattern_size_b::Value{ sizeB },
113 uniforms::u_texsize::Value{ atlasSize },
114 uniforms::u_fade::Value{ properties.get<LinePattern>().t },
115 uniforms::u_image::Value{ 0 }
116 );
117 }
118
119 } // namespace mbgl
120