1 #pragma once
2 
3 #include <mbgl/gl/object.hpp>
4 #include <mbgl/gl/primitives.hpp>
5 #include <mbgl/gl/draw_mode.hpp>
6 #include <mbgl/util/ignore.hpp>
7 
8 #include <vector>
9 
10 namespace mbgl {
11 namespace gl {
12 
13 template <class V, class DrawMode = Indexed>
14 class VertexVector {
15 public:
16     using Vertex = V;
17     static constexpr std::size_t groupSize = DrawMode::bufferGroupSize;
18 
19     template <class... Args>
emplace_back(Args &&...args)20     void emplace_back(Args&&... args) {
21         static_assert(sizeof...(args) == groupSize, "wrong buffer element count");
22         util::ignore({(v.emplace_back(std::forward<Args>(args)), 0)...});
23     }
24 
vertexSize() const25     std::size_t vertexSize() const { return v.size(); }
byteSize() const26     std::size_t byteSize() const { return v.size() * sizeof(Vertex); }
27 
empty() const28     bool empty() const { return v.empty(); }
clear()29     void clear() { v.clear(); }
data() const30     const Vertex* data() const { return v.data(); }
vector() const31     const std::vector<Vertex>& vector() const { return v; }
32 
33 private:
34     std::vector<Vertex> v;
35 };
36 
37 template <class V, class DrawMode = Indexed>
38 class VertexBuffer {
39 public:
40     using Vertex = V;
41     static constexpr std::size_t vertexSize = sizeof(Vertex);
42 
43     std::size_t vertexCount;
44     UniqueBuffer buffer;
45 };
46 
47 } // namespace gl
48 } // namespace mbgl
49