summaryrefslogtreecommitdiff
path: root/src/mbgl/renderer/painter_debug.cpp
blob: 7f9c990776f8a3bf6b92e7fa241545b44565634d (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
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
#include <mbgl/renderer/painter.hpp>
#include <mbgl/renderer/debug_bucket.hpp>
#include <mbgl/map/map.hpp>
#include <mbgl/util/string.hpp>

using namespace mbgl;

void Painter::renderTileDebug(const Tile& tile) {
    gl::group group(std::string { "debug " } + std::string(tile.id));
    assert(tile.data);
    if (debug) {
        prepareTile(tile);
        renderDebugText(tile.data->debugBucket, tile.matrix);
        renderDebugFrame(tile.matrix);
    }
}

void Painter::renderDebugText(DebugBucket& bucket, const mat4 &matrix) {
    gl::group group("debug text");

    MBGL_CHECK_ERROR(glDisable(GL_DEPTH_TEST));

    useProgram(plainShader->program);
    plainShader->u_matrix = matrix;

    // Draw white outline
    plainShader->u_color = {{ 1.0f, 1.0f, 1.0f, 1.0f }};
    lineWidth(4.0f * state.getPixelRatio());
    bucket.drawLines(*plainShader);

#ifndef GL_ES_VERSION_2_0
    // Draw line "end caps"
    MBGL_CHECK_ERROR(glPointSize(2));
    bucket.drawPoints(*plainShader);
#endif

    // Draw black text.
    plainShader->u_color = {{ 0.0f, 0.0f, 0.0f, 1.0f }};
    lineWidth(2.0f * state.getPixelRatio());
    bucket.drawLines(*plainShader);

    MBGL_CHECK_ERROR(glEnable(GL_DEPTH_TEST));
}

void Painter::renderDebugFrame(const mat4 &matrix) {
    gl::group group("debug frame");

    // Disable depth test and don't count this towards the depth buffer,
    // but *don't* disable stencil test, as we want to clip the red tile border
    // to the tile viewport.
    MBGL_CHECK_ERROR(glDisable(GL_DEPTH_TEST));

    useProgram(plainShader->program);
    plainShader->u_matrix = matrix;

    // draw tile outline
    tileBorderArray.bind(*plainShader, tileBorderBuffer, BUFFER_OFFSET(0));
    plainShader->u_color = {{ 1.0f, 0.0f, 0.0f, 1.0f }};
    lineWidth(4.0f * state.getPixelRatio());
    MBGL_CHECK_ERROR(glDrawArrays(GL_LINE_STRIP, 0, (GLsizei)tileBorderBuffer.index()));

    MBGL_CHECK_ERROR(glEnable(GL_DEPTH_TEST));
}

void Painter::renderDebugText(const std::vector<std::string> &strings) {
    if (strings.empty()) {
        return;
    }

    gl::group group("debug text");

    MBGL_CHECK_ERROR(glDisable(GL_DEPTH_TEST));
    MBGL_CHECK_ERROR(glStencilFunc(GL_ALWAYS, 0xFF, 0xFF));

    useProgram(plainShader->program);
    plainShader->u_matrix = nativeMatrix;

    DebugFontBuffer debugFontBuffer;
    int line = 25;
    for (const auto& str : strings) {
        debugFontBuffer.addText(str.c_str(), 10, line, 0.75);
        line += 20;
    }

    if (!debugFontBuffer.empty()) {
        // draw debug info
        VertexArrayObject debugFontArray;
        debugFontArray.bind(*plainShader, debugFontBuffer, BUFFER_OFFSET(0));
        plainShader->u_color = {{ 1.0f, 1.0f, 1.0f, 1.0f }};
        lineWidth(4.0f * state.getPixelRatio());
        MBGL_CHECK_ERROR(glDrawArrays(GL_LINES, 0, (GLsizei)debugFontBuffer.index()));
    #ifndef GL_ES_VERSION_2_0
        MBGL_CHECK_ERROR(glPointSize(2));
        MBGL_CHECK_ERROR(glDrawArrays(GL_POINTS, 0, (GLsizei)debugFontBuffer.index()));
    #endif
        plainShader->u_color = {{ 0.0f, 0.0f, 0.0f, 1.0f }};
        lineWidth(2.0f * state.getPixelRatio());
        MBGL_CHECK_ERROR(glDrawArrays(GL_LINES, 0, (GLsizei)debugFontBuffer.index()));
    }

    MBGL_CHECK_ERROR(glEnable(GL_DEPTH_TEST));
}