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
|
#pragma once
#include <mbgl/gl/context.hpp>
#include <mbgl/gl/vertex_buffer.hpp>
#include <mbgl/util/optional.hpp>
#include <cstddef>
#include <vector>
namespace mbgl {
namespace gl {
template <class Attributes>
class Segment {
public:
Segment(std::size_t vertexOffset_,
std::size_t indexOffset_,
std::size_t vertexLength_ = 0,
std::size_t indexLength_ = 0)
: vertexOffset(vertexOffset_),
indexOffset(indexOffset_),
vertexLength(vertexLength_),
indexLength(indexLength_) {}
const std::size_t vertexOffset;
const std::size_t indexOffset;
std::size_t vertexLength;
std::size_t indexLength;
void bind(Context& context,
BufferID indexBuffer_,
const typename Attributes::Locations& attributeLocations,
const typename Attributes::Bindings& attributeBindings_) const {
if (!vao) {
vao = context.createVertexArray();
context.vertexBuffer.setDirty();
}
context.vertexArrayObject = *vao;
if (indexBuffer != indexBuffer_) {
indexBuffer = indexBuffer_;
context.elementBuffer.setDirty();
context.elementBuffer = indexBuffer_;
}
Attributes::bind(context,
attributeLocations,
variableBindings,
attributeBindings_,
vertexOffset);
}
private:
mutable optional<UniqueVertexArray> vao;
mutable optional<BufferID> indexBuffer;
mutable typename Attributes::VariableBindings variableBindings;
};
template <class Attributes>
class SegmentVector : public std::vector<Segment<Attributes>> {
public:
SegmentVector() = default;
};
} // namespace gl
} // namespace mbgl
|