blob: 9ccf48d9bd9f5009efbd170cab8d9eb1b22fc306 (
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
|
#pragma once
#include <mbgl/gl/object.hpp>
#include <mbgl/gl/attribute.hpp>
#include <mbgl/gl/state.hpp>
#include <mbgl/gl/value.hpp>
#include <array>
#include <memory>
namespace mbgl {
namespace gl {
class Context;
class VertexArrayState {
public:
VertexArrayState(UniqueVertexArray vertexArray_, Context& context)
: vertexArray(std::move(vertexArray_)),
bindings(makeBindings(context, std::make_index_sequence<MAX_ATTRIBUTES>())) {
}
void setDirty() {
indexBuffer.setDirty();
for (auto& binding : bindings) {
binding.setDirty();
}
}
UniqueVertexArray vertexArray;
State<value::BindElementBuffer> indexBuffer;
using AttributeState = State<value::VertexAttribute, Context&, AttributeLocation>;
std::array<AttributeState, MAX_ATTRIBUTES> bindings;
private:
template <std::size_t... I>
std::array<AttributeState, MAX_ATTRIBUTES> makeBindings(Context& context, std::index_sequence<I...>) {
return {{ AttributeState { context, I }... }};
}
};
using UniqueVertexArrayState = std::unique_ptr<VertexArrayState, std::function<void (VertexArrayState*)>>;
class VertexArray {
public:
VertexArray(UniqueVertexArrayState state_)
: state(std::move(state_)) {
}
void bind(Context&, BufferID indexBuffer, const AttributeBindingArray&);
private:
UniqueVertexArrayState state;
};
} // namespace gl
} // namespace mbgl
|