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

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

#include <vector>
#include <map>

namespace mbgl {

typedef struct {
    float width;
    float height;
    float y;
} LinePatternPos;

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

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

    // 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::ObjectStore&);

    LinePatternPos getDashPosition(const std::vector<float>&, bool, gl::ObjectStore&);
    LinePatternPos addDash(const std::vector<float> &dasharray, bool round, gl::ObjectStore&);

    const GLsizei width;
    const GLsizei height;

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

} // namespace mbgl