1 #include <mbgl/renderer/buckets/debug_bucket.hpp>
2 #include <mbgl/programs/fill_program.hpp>
3 #include <mbgl/geometry/debug_font_data.hpp>
4 #include <mbgl/tile/tile_id.hpp>
5 #include <mbgl/util/string.hpp>
6
7 #include <cmath>
8 #include <string>
9 #include <vector>
10
11 namespace mbgl {
12
DebugBucket(const OverscaledTileID & id,const bool renderable_,const bool complete_,optional<Timestamp> modified_,optional<Timestamp> expires_,MapDebugOptions debugMode_,gl::Context & context)13 DebugBucket::DebugBucket(const OverscaledTileID& id,
14 const bool renderable_,
15 const bool complete_,
16 optional<Timestamp> modified_,
17 optional<Timestamp> expires_,
18 MapDebugOptions debugMode_,
19 gl::Context& context)
20 : renderable(renderable_),
21 complete(complete_),
22 modified(std::move(modified_)),
23 expires(std::move(expires_)),
24 debugMode(debugMode_) {
25
26 gl::VertexVector<FillLayoutVertex> vertices;
27 gl::IndexVector<gl::Lines> indices;
28
29 auto addText = [&] (const std::string& text, double left, double baseline, double scale) {
30 for (uint8_t c : text) {
31 if (c < 32 || c >= 127)
32 continue;
33
34 optional<Point<int16_t>> prev;
35
36 const glyph& glyph = simplex[c - 32];
37 for (int32_t j = 0; j < glyph.length; j += 2) {
38 if (glyph.data[j] == -1 && glyph.data[j + 1] == -1) {
39 prev = {};
40 } else {
41 Point<int16_t> p {
42 int16_t(::round(left + glyph.data[j] * scale)),
43 int16_t(::round(baseline - glyph.data[j + 1] * scale))
44 };
45
46 vertices.emplace_back(FillProgram::layoutVertex(p));
47
48 if (prev) {
49 indices.emplace_back(vertices.vertexSize() - 2,
50 vertices.vertexSize() - 1);
51 }
52
53 prev = p;
54 }
55 }
56
57 left += glyph.width * scale;
58 }
59 };
60
61 double baseline = 200;
62 if (debugMode & MapDebugOptions::ParseStatus) {
63 const std::string text = util::toString(id) + " - " +
64 (complete ? "complete" : renderable ? "renderable" : "pending");
65 addText(text, 50, baseline, 5);
66 baseline += 200;
67 }
68
69 if (debugMode & MapDebugOptions::Timestamps && modified && expires) {
70 const std::string modifiedText = "modified: " + util::iso8601(*modified);
71 addText(modifiedText, 50, baseline, 5);
72
73 const std::string expiresText = "expires: " + util::iso8601(*expires);
74 addText(expiresText, 50, baseline + 200, 5);
75 }
76
77 segments.emplace_back(0, 0, vertices.vertexSize(), indices.indexSize());
78
79 vertexBuffer = context.createVertexBuffer(std::move(vertices));
80 indexBuffer = context.createIndexBuffer(std::move(indices));
81 }
82
83 } // namespace mbgl
84