summaryrefslogtreecommitdiff
path: root/src/mbgl/geometry/line_atlas.hpp
blob: 66a2343a428837a2c00aac902e936468fa72a3bd (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
#pragma once

#include <mbgl/gl/object.hpp>
#include <mbgl/util/optional.hpp>

#include <vector>
#include <unordered_map>
#include <memory>

namespace mbgl {

namespace gl {
class Context;
} // namespace gl

class LinePatternPos {
public:
    float width;
    float height;
    float y;
};

enum class LinePatternCap : bool {
    Square = false,
    Round = true,
};

class LineAtlas {
public:
    LineAtlas(uint16_t width, uint16_t height);
    ~LineAtlas();

    // Binds the atlas texture to the GPU, and uploads data if it is out of date.
    void bind(gl::Context&, gl::TextureUnit unit);

    // Uploads the texture to the GPU to be available when we need it. This is a lazy operation;
    // the texture is only bound when the data is out of date (=dirty).
    void upload(gl::Context&, gl::TextureUnit unit);

    LinePatternPos getDashPosition(const std::vector<float>&, LinePatternCap);
    LinePatternPos addDash(const std::vector<float>& dasharray, LinePatternCap);

    const uint16_t width;
    const uint16_t height;

private:
    const std::unique_ptr<char[]> data;
    bool dirty;
    mbgl::optional<gl::UniqueTexture> texture;
    int nextRow = 0;
    std::unordered_map<size_t, LinePatternPos> positions;
};

} // namespace mbgl