diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-09-26 12:53:32 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-10-05 10:52:19 -0700 |
commit | 7a3bef091e7390fa57bf33f1a704c893768b5625 (patch) | |
tree | af798d879923fd45e763f5dc5449b7e8419aa192 /src/mbgl/renderer/debug_bucket.cpp | |
parent | ac8a74ebccb85f83c40b9fccfeb11dc2cb3c79e4 (diff) | |
download | qtlocation-mapboxgl-7a3bef091e7390fa57bf33f1a704c893768b5625.tar.gz |
[core] Refactor Buffer
Diffstat (limited to 'src/mbgl/renderer/debug_bucket.cpp')
-rw-r--r-- | src/mbgl/renderer/debug_bucket.cpp | 89 |
1 files changed, 68 insertions, 21 deletions
diff --git a/src/mbgl/renderer/debug_bucket.cpp b/src/mbgl/renderer/debug_bucket.cpp index 249924abb7..e37ccbff2f 100644 --- a/src/mbgl/renderer/debug_bucket.cpp +++ b/src/mbgl/renderer/debug_bucket.cpp @@ -1,54 +1,101 @@ #include <mbgl/renderer/debug_bucket.hpp> #include <mbgl/renderer/painter.hpp> #include <mbgl/shader/plain_shader.hpp> +#include <mbgl/shader/plain_vertex.hpp> +#include <mbgl/geometry/debug_font_data.hpp> #include <mbgl/util/string.hpp> #include <mbgl/gl/gl.hpp> -#include <cassert> +#include <cmath> #include <string> +#include <vector> namespace mbgl { -DebugBucket::DebugBucket(const OverscaledTileID& id, - const bool renderable_, - const bool complete_, - optional<Timestamp> modified_, - optional<Timestamp> expires_, - MapDebugOptions debugMode_) - : renderable(renderable_), - complete(complete_), - modified(std::move(modified_)), - expires(std::move(expires_)), - debugMode(debugMode_) { +std::vector<PlainVertex> buildTextVertexes(const OverscaledTileID& id, + const bool renderable, + const bool complete, + optional<Timestamp> modified, + optional<Timestamp> expires, + MapDebugOptions debugMode) { + std::vector<PlainVertex> textPoints; + + auto addText = [&] (const std::string& text, double left, double baseline, double scale) { + for (uint8_t c : text) { + if (c < 32 || c >= 127) + continue; + + optional<Point<int16_t>> prev; + + const glyph& glyph = simplex[c - 32]; + for (int32_t j = 0; j < glyph.length; j += 2) { + if (glyph.data[j] == -1 && glyph.data[j + 1] == -1) { + prev = {}; + } else { + Point<int16_t> p { + int16_t(::round(left + glyph.data[j] * scale)), + int16_t(::round(baseline - glyph.data[j + 1] * scale)) + }; + + if (prev) { + textPoints.emplace_back(prev->x, prev->y); + textPoints.emplace_back(p.x, p.y); + } + + prev = p; + } + } + + left += glyph.width * scale; + } + }; + double baseline = 200; if (debugMode & MapDebugOptions::ParseStatus) { const std::string text = util::toString(id) + " - " + (complete ? "complete" : renderable ? "renderable" : "pending"); - fontBuffer.addText(text.c_str(), 50, baseline, 5); + addText(text, 50, baseline, 5); baseline += 200; } if (debugMode & MapDebugOptions::Timestamps && modified && expires) { const std::string modifiedText = "modified: " + util::iso8601(*modified); - fontBuffer.addText(modifiedText.c_str(), 50, baseline, 5); + addText(modifiedText, 50, baseline, 5); const std::string expiresText = "expires: " + util::iso8601(*expires); - fontBuffer.addText(expiresText.c_str(), 50, baseline + 200, 5); + addText(expiresText, 50, baseline + 200, 5); } + + return textPoints; +} + +DebugBucket::DebugBucket(const OverscaledTileID& id, + const bool renderable_, + const bool complete_, + optional<Timestamp> modified_, + optional<Timestamp> expires_, + MapDebugOptions debugMode_, + gl::Context& context) + : renderable(renderable_), + complete(complete_), + modified(std::move(modified_)), + expires(std::move(expires_)), + debugMode(debugMode_), + textVertexes(context.createVertexBuffer(buildTextVertexes(id, renderable_, complete_, modified_, expires_, debugMode_))) { } void DebugBucket::drawLines(PlainShader& shader, gl::Context& context) { - if (!fontBuffer.empty()) { - array.bind(shader, fontBuffer, BUFFER_OFFSET_0, context); - MBGL_CHECK_ERROR(glDrawArrays(GL_LINES, 0, (GLsizei)(fontBuffer.index()))); + if (textVertexes.vertexCount != 0) { + array.bind(shader, textVertexes, BUFFER_OFFSET_0, context); + MBGL_CHECK_ERROR(glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(textVertexes.vertexCount))); } } void DebugBucket::drawPoints(PlainShader& shader, gl::Context& context) { - if (!fontBuffer.empty()) { - array.bind(shader, fontBuffer, BUFFER_OFFSET_0, context); - MBGL_CHECK_ERROR(glDrawArrays(GL_POINTS, 0, (GLsizei)(fontBuffer.index()))); + if (textVertexes.vertexCount != 0) { + array.bind(shader, textVertexes, BUFFER_OFFSET_0, context); + MBGL_CHECK_ERROR(glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(textVertexes.vertexCount))); } } |