summaryrefslogtreecommitdiff
path: root/include/mbgl/renderer/symbol_bucket.hpp
blob: 42682401ef511c081526a9f9b929b6488f82e1d3 (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
103
104
105
106
107
108
109
110
111
112
113
114
#ifndef MBGL_RENDERER_SYMBOLBUCKET
#define MBGL_RENDERER_SYMBOLBUCKET

#include "bucket.hpp"
#include <mbgl/geometry/vao.hpp>
#include <mbgl/geometry/elements_buffer.hpp>
#include <mbgl/geometry/text_buffer.hpp>
#include <mbgl/geometry/icon_buffer.hpp>
#include <mbgl/map/vector_tile.hpp>
#include <mbgl/text/types.hpp>
#include <mbgl/text/glyph.hpp>
#include <mbgl/style/style_bucket.hpp>

#include <memory>
#include <map>
#include <vector>

namespace mbgl {

class Style;
class SDFShader;
class IconShader;
class DotShader;
class Collision;
class SpriteAtlas;
class Sprite;
class GlyphAtlas;
class GlyphStore;
class FontStack;

class SymbolFeature {
public:
    pbf geometry;
    std::u32string label;
    std::string sprite;
};


class Symbol {
public:
    vec2<float> tl, tr, bl, br;
    Rect<uint16_t> tex;
    float angle;
    float minScale = 0.0f;
    float maxScale = std::numeric_limits<float>::infinity();
    CollisionAnchor anchor;
};

typedef std::vector<Symbol> Symbols;


class SymbolBucket : public Bucket {
    typedef ElementGroup<1> TextElementGroup;
    typedef ElementGroup<2> IconElementGroup;

public:
    SymbolBucket(const StyleBucketSymbol &properties, Collision &collision);

    virtual void render(Painter &painter, util::ptr<StyleLayer> layer_desc, const Tile::ID &id, const mat4 &matrix);
    virtual bool hasData() const;
    virtual bool hasTextData() const;
    virtual bool hasIconData() const;

    void addFeatures(const VectorTileLayer &layer, const FilterExpression &filter,
                     const Tile::ID &id, SpriteAtlas &spriteAtlas, Sprite &sprite,
                     GlyphAtlas &glyphAtlas, GlyphStore &glyphStore);

    void addGlyphs(const PlacedGlyphs &glyphs, float placementZoom, PlacementRange placementRange,
                   float zoom);

    void drawGlyphs(SDFShader& shader);
    void drawIcons(SDFShader& shader);
    void drawIcons(IconShader& shader);

private:

    std::vector<SymbolFeature> processFeatures(const VectorTileLayer &layer, const FilterExpression &filter, GlyphStore &glyphStore, const Sprite &sprite);


    void addFeature(const pbf &geom_pbf, const Shaping &shaping, const GlyphPositions &face, const Rect<uint16_t> &image);
    void addFeature(const std::vector<Coordinate> &line, const Shaping &shaping, const GlyphPositions &face, const Rect<uint16_t> &image);


    // Adds placed items to the buffer.
    template <typename Buffer>
    void addSymbols(Buffer &buffer, const PlacedGlyphs &symbols, float scale, PlacementRange placementRange);

    // Adds glyphs to the glyph atlas so that they have a left/top/width/height coordinates associated to them that we can use for writing to a buffer.
    void addGlyphsToAtlas(uint64_t tileid, const std::string stackname, const std::u32string &string,
                  const FontStack &fontStack, GlyphAtlas &glyphAtlas, GlyphPositions &face);

public:
    const StyleBucketSymbol &properties;
    bool sdfIcons = false;

private:
    Collision &collision;

    struct {
        TextVertexBuffer vertices;
        TriangleElementsBuffer triangles;
        std::vector<TextElementGroup> groups;
    } text;

    struct {
        IconVertexBuffer vertices;
        TriangleElementsBuffer triangles;
        std::vector<IconElementGroup> groups;
    } icon;

};
}

#endif