1 #pragma once
2 
3 #include <mbgl/gl/texture.hpp>
4 #include <mbgl/gl/object.hpp>
5 #include <mbgl/util/image.hpp>
6 #include <mbgl/util/optional.hpp>
7 
8 #include <vector>
9 #include <unordered_map>
10 #include <memory>
11 
12 namespace mbgl {
13 
14 namespace gl {
15 class Context;
16 } // namespace gl
17 
18 class LinePatternPos {
19 public:
20     float width;
21     float height;
22     float y;
23 };
24 
25 enum class LinePatternCap : bool {
26     Square = false,
27     Round = true,
28 };
29 
30 class LineAtlas {
31 public:
32     LineAtlas(Size);
33     ~LineAtlas();
34 
35     // Binds the atlas texture to the GPU, and uploads data if it is out of date.
36     void bind(gl::Context&, gl::TextureUnit unit);
37 
38     // Uploads the texture to the GPU to be available when we need it. This is a lazy operation;
39     // the texture is only bound when the data is out of date (=dirty).
40     void upload(gl::Context&, gl::TextureUnit unit);
41 
42     LinePatternPos getDashPosition(const std::vector<float>&, LinePatternCap);
43     LinePatternPos addDash(const std::vector<float>& dasharray, LinePatternCap);
44 
45     Size getSize() const;
46 
47 private:
48     const AlphaImage image;
49     bool dirty;
50     mbgl::optional<gl::Texture> texture;
51     uint32_t nextRow = 0;
52     std::unordered_map<size_t, LinePatternPos> positions;
53 };
54 
55 } // namespace mbgl
56