summaryrefslogtreecommitdiff
path: root/include/llmr/renderer/fill_bucket.hpp
blob: db0e9c1042ea67d917df8e767efb50f910e2f855 (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
#ifndef LLMR_RENDERER_FILLBUCKET
#define LLMR_RENDERER_FILLBUCKET

#include <llmr/renderer/bucket.hpp>
#include <llmr/geometry/elements_buffer.hpp>
#include <llmr/geometry/fill_buffer.hpp>
#include <llmr/style/style_bucket.hpp>

#include <clipper/clipper.hpp>
#include <libtess2/tesselator.h>

#include <vector>
#include <memory>

#ifndef BUFFER_OFFSET
#define BUFFER_OFFSET(i) ((char *)nullptr + (i))
#endif

namespace llmr {

class Style;
class FillVertexBuffer;
class TriangleElementsBuffer;
class LineElementsBuffer;
class BucketDescription;
class OutlineShader;
class PlainShader;
class PatternShader;
struct pbf;

class FillBucket : public Bucket {

    static void *alloc(void *data, unsigned int size);
    static void *realloc(void *data, void *ptr, unsigned int size);
    static void free(void *userData, void *ptr);


    typedef ElementGroup triangle_group_type;
    typedef ElementGroup line_group_type;
public:
    FillBucket(FillVertexBuffer& vertexBuffer,
               TriangleElementsBuffer& triangleElementsBuffer,
               LineElementsBuffer& lineElementsBuffer,
               const StyleBucketFill& properties);
    ~FillBucket();

    virtual void render(Painter& painter, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id);
    virtual bool hasData() const;

    void addGeometry(pbf& data);
    void tessellate();

    void drawElements(PlainShader& shader);
    void drawElements(PatternShader& shader);
    void drawVertices(OutlineShader& shader);

public:
    const StyleBucketFill &properties;

private:
    TESSalloc *allocator;
    TESStesselator *tesselator;
    ClipperLib::Clipper clipper;

    FillVertexBuffer& vertexBuffer;
    TriangleElementsBuffer& triangleElementsBuffer;
    LineElementsBuffer& lineElementsBuffer;

    // hold information on where the vertices are located in the FillBuffer
    const size_t vertex_start;
    const size_t triangle_elements_start;
    const size_t line_elements_start;
    VertexArrayObject array;

    std::vector<triangle_group_type> triangleGroups;
    std::vector<line_group_type> lineGroups;

    std::vector<ClipperLib::IntPoint> line;
    bool hasVertices = false;

    static const int vertexSize = 2;
    static const int stride = sizeof(TESSreal) * vertexSize;
    static const int vertices_per_group = 3;
};

}

#endif