]> git.localhorst.tv Git - blank.git/blob - src/graphics/VertexArray.hpp
avoid zero vertex draw calls
[blank.git] / src / graphics / VertexArray.hpp
1 #ifndef BLANK_GRAPHICS_VERTEXARRAY_HPP_
2 #define BLANK_GRAPHICS_VERTEXARRAY_HPP_
3
4 #include <vector>
5 #include <GL/glew.h>
6
7
8 namespace blank {
9
10 template<std::size_t N>
11 class VertexArray {
12
13 public:
14         static constexpr std::size_t NUM_ATTRS = N;
15
16 public:
17         VertexArray() noexcept;
18         ~VertexArray() noexcept;
19
20         VertexArray(const VertexArray<N> &) = delete;
21         VertexArray<N> &operator =(const VertexArray<N> &) = delete;
22
23         VertexArray(VertexArray<N> &&) noexcept;
24         VertexArray<N> &operator =(VertexArray<N> &&) noexcept;
25
26 public:
27         bool Empty() const noexcept { return idx_count == 0; }
28
29         void Bind() const noexcept;
30
31         template <class T>
32         void PushAttribute(std::size_t which, const std::vector<T> &data, bool normalized = false) noexcept;
33
34         template<class T>
35         void PushIndices(std::size_t which, const std::vector<T> &indices) noexcept;
36
37         void DrawLineElements() const noexcept;
38         void DrawTriangleElements() const noexcept;
39
40 private:
41         void BindAttribute(std::size_t which) const noexcept;
42         void EnableAttribute(std::size_t which) noexcept;
43         template <class T>
44         void AttributeData(const std::vector<T> &) noexcept;
45         template <class T>
46         void AttributePointer(std::size_t which, bool normalized = false) noexcept;
47
48         void BindIndex(std::size_t which) const noexcept;
49         template <class T>
50         void IndexData(const std::vector<T> &) noexcept;
51
52 private:
53         GLuint array_id;
54         GLuint attr_id[NUM_ATTRS];
55
56         std::size_t idx_count;
57         GLenum idx_type;
58
59 };
60
61 }
62
63 #include "VertexArray.inl"
64
65 #endif