-
-
Notifications
You must be signed in to change notification settings - Fork 333
/
line_program.cpp
127 lines (112 loc) · 4.62 KB
/
line_program.cpp
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
#include <mbgl/programs/line_program.hpp>
#include <mbgl/style/layers/line_layer_properties.hpp>
#include <mbgl/renderer/render_tile.hpp>
#include <mbgl/renderer/image_atlas.hpp>
#include <mbgl/map/transform_state.hpp>
#include <mbgl/util/mat2.hpp>
#include <mbgl/geometry/line_atlas.hpp>
namespace mbgl {
using namespace style;
static_assert(sizeof(LineLayoutVertex) == 8, "expected LineLayoutVertex size");
template <class Values, class...Args>
Values makeValues(const style::LinePaintProperties::PossiblyEvaluated& properties,
const RenderTile& tile,
const TransformState& state,
const std::array<float, 2>& pixelsToGLUnits,
const float pixelRatio,
Args&&... args) {
return Values {
uniforms::matrix::Value(
tile.translatedMatrix(properties.get<LineTranslate>(),
properties.get<LineTranslateAnchor>(),
state)
),
uniforms::ratio::Value( 1.0f / tile.id.pixelsToTileUnits(1.0f, static_cast<float>(state.getZoom())) ),
uniforms::units_to_pixels::Value({ {1.0f / pixelsToGLUnits[0], 1.0f / pixelsToGLUnits[1]} }),
uniforms::device_pixel_ratio::Value( pixelRatio ),
std::forward<Args>(args)...
};
}
LineProgram::LayoutUniformValues
LineProgram::layoutUniformValues(const style::LinePaintProperties::PossiblyEvaluated& properties,
const RenderTile& tile,
const TransformState& state,
const std::array<float, 2>& pixelsToGLUnits,
const float pixelRatio) {
return makeValues<LineProgram::LayoutUniformValues>(
properties,
tile,
state,
pixelsToGLUnits,
pixelRatio
);
}
LineSDFProgram::LayoutUniformValues
LineSDFProgram::layoutUniformValues(const style::LinePaintProperties::PossiblyEvaluated& properties,
float pixelRatio,
const RenderTile& tile,
const TransformState& state,
const std::array<float, 2>& pixelsToGLUnits,
const LinePatternPos& posA,
const LinePatternPos& posB,
const CrossfadeParameters& crossfade,
float atlasWidth) {
const float widthA = posA.width * crossfade.fromScale;
const float widthB = posB.width * crossfade.toScale;
std::array<float, 2> scaleA {{
1.0f / tile.id.pixelsToTileUnits(widthA, state.getIntegerZoom()),
-posA.height / 2.0f
}};
std::array<float, 2> scaleB {{
1.0f / tile.id.pixelsToTileUnits(widthB, state.getIntegerZoom()),
-posB.height / 2.0f
}};
return makeValues<LineSDFProgram::LayoutUniformValues>(
properties,
tile,
state,
pixelsToGLUnits,
pixelRatio,
uniforms::patternscale_a::Value( scaleA ),
uniforms::patternscale_b::Value( scaleB ),
uniforms::tex_y_a::Value( posA.y ),
uniforms::tex_y_b::Value( posB.y ),
uniforms::mix::Value( crossfade.t ),
uniforms::sdfgamma::Value( atlasWidth / (std::min(widthA, widthB) * 256.0f * pixelRatio) / 2.0f )
);
}
LinePatternProgram::LayoutUniformValues LinePatternProgram::layoutUniformValues(
const style::LinePaintProperties::PossiblyEvaluated& properties,
const RenderTile& tile,
const TransformState& state,
const std::array<float, 2>& pixelsToGLUnits,
const float pixelRatio,
const Size atlasSize,
const CrossfadeParameters& crossfade) {
const auto tileRatio = 1 / tile.id.pixelsToTileUnits(1, state.getIntegerZoom());
return makeValues<LinePatternProgram::LayoutUniformValues>(
properties,
tile,
state,
pixelsToGLUnits,
pixelRatio,
uniforms::scale::Value ({ {pixelRatio, tileRatio, crossfade.fromScale, crossfade.toScale} }),
uniforms::texsize::Value( atlasSize ),
uniforms::fade::Value( crossfade.t )
);
}
LineGradientProgram::LayoutUniformValues LineGradientProgram::layoutUniformValues(
const style::LinePaintProperties::PossiblyEvaluated& properties,
const RenderTile& tile,
const TransformState& state,
const std::array<float, 2>& pixelsToGLUnits,
const float pixelRatio) {
return makeValues<LineGradientProgram::LayoutUniformValues>(
properties,
tile,
state,
pixelsToGLUnits,
pixelRatio
);
}
} // namespace mbgl