summaryrefslogtreecommitdiff
path: root/src/mbgl/gl/vertex_buffer.hpp
blob: 9f8b156b25559a154edfb49e331f091f26ac05d9 (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
#pragma once

#include <mbgl/gl/object.hpp>
#include <mbgl/gl/primitives.hpp>
#include <mbgl/gl/draw_mode.hpp>
#include <mbgl/util/ignore.hpp>

#include <vector>

namespace mbgl {
namespace gl {

template <class V, class DrawMode = Indexed>
class VertexVector {
public:
    using Vertex = V;
    static constexpr std::size_t groupSize = DrawMode::bufferGroupSize;

    template <class... Args>
    void emplace_back(Args&&... args) {
        static_assert(sizeof...(args) == groupSize, "wrong buffer element count");
        util::ignore({(v.emplace_back(std::forward<Args>(args)), 0)...});
    }

    std::size_t vertexSize() const { return v.size(); }
    std::size_t byteSize() const { return v.size() * sizeof(Vertex); }

    bool empty() const { return v.empty(); }
    void clear() { v.clear(); }
    const Vertex* data() const { return v.data(); }
    const std::vector<Vertex>& vector() const { return v; }

private:
    std::vector<Vertex> v;
};

template <class V, class DrawMode = Indexed>
class VertexBuffer {
public:
    using Vertex = V;
    static constexpr std::size_t vertexSize = sizeof(Vertex);

    std::size_t vertexCount;
    UniqueBuffer buffer;
};

} // namespace gl
} // namespace mbgl