1 #pragma once
2 
3 #include <mbgl/gl/object.hpp>
4 #include <mbgl/gl/attribute.hpp>
5 #include <mbgl/gl/state.hpp>
6 #include <mbgl/gl/value.hpp>
7 
8 #include <array>
9 #include <memory>
10 
11 namespace mbgl {
12 namespace gl {
13 
14 class Context;
15 
16 class VertexArrayState {
17 public:
VertexArrayState(UniqueVertexArray vertexArray_)18     VertexArrayState(UniqueVertexArray vertexArray_)
19         : vertexArray(std::move(vertexArray_)) {
20     }
21 
setDirty()22     void setDirty() {
23         indexBuffer.setDirty();
24         for (auto& binding : bindings) {
25             binding.setDirty();
26         }
27     }
28 
29     UniqueVertexArray vertexArray;
30     State<value::BindElementBuffer> indexBuffer;
31 
32     using AttributeState = State<value::VertexAttribute, Context&, AttributeLocation>;
33     std::vector<AttributeState> bindings;
34 };
35 
36 class VertexArrayStateDeleter {
37 public:
VertexArrayStateDeleter(bool destroy_)38     VertexArrayStateDeleter(bool destroy_)
39         : destroy(destroy_) {}
40 
operator ()(VertexArrayState * ptr) const41     void operator()(VertexArrayState* ptr) const {
42         if (destroy) {
43             delete ptr;
44         }
45     }
46 
47 private:
48     bool destroy;
49 };
50 
51 using UniqueVertexArrayState = std::unique_ptr<VertexArrayState, VertexArrayStateDeleter>;
52 
53 class VertexArray {
54 public:
VertexArray(UniqueVertexArrayState state_)55     VertexArray(UniqueVertexArrayState state_)
56         : state(std::move(state_)) {
57     }
58 
59     void bind(Context&, BufferID indexBuffer, const AttributeBindingArray&);
60 
61 private:
62     UniqueVertexArrayState state;
63 };
64 
65 } // namespace gl
66 } // namespace mbgl
67