summaryrefslogtreecommitdiff
path: root/src/mbgl/renderer/debug_bucket.cpp
blob: 947783ddb832c903188acb18b35911e51f8dd25d (plain)
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
#include <mbgl/renderer/debug_bucket.hpp>
#include <mbgl/renderer/painter.hpp>
#include <mbgl/shader/plain_shader.hpp>

#include <mbgl/gl/gl.hpp>

#include <cassert>
#include <string>

using namespace mbgl;

DebugBucket::DebugBucket(const TileID id, const TileData::State state_, optional<SystemTimePoint> modified_, optional<SystemTimePoint> expires_, MapDebugOptions debugMode_)
    : state(state_),
      modified(std::move(modified_)),
      expires(std::move(expires_)),
      debugMode(debugMode_) {
    double baseline = 200;
    if (debugMode & MapDebugOptions::ParseStatus) {
        const std::string text = std::string(id) + " - " + TileData::StateToString(state);
        fontBuffer.addText(text.c_str(), 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);

        const std::string expiresText = "expires: " + util::iso8601(*expires);
        fontBuffer.addText(expiresText.c_str(), 50, baseline + 200, 5);
    }
}

void DebugBucket::drawLines(PlainShader& shader, gl::GLObjectStore& glObjectStore) {
    array.bind(shader, fontBuffer, BUFFER_OFFSET_0, glObjectStore);
    MBGL_CHECK_ERROR(glDrawArrays(GL_LINES, 0, (GLsizei)(fontBuffer.index())));
}

void DebugBucket::drawPoints(PlainShader& shader, gl::GLObjectStore& glObjectStore) {
    array.bind(shader, fontBuffer, BUFFER_OFFSET_0, glObjectStore);
    MBGL_CHECK_ERROR(glDrawArrays(GL_POINTS, 0, (GLsizei)(fontBuffer.index())));
}