]> git.localhorst.tv Git - blank.git/blob - src/graphics/VertexArray.hpp
save a little bandwidth
[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         void Bind() const noexcept;
28
29         template <class T>
30         void PushAttribute(std::size_t which, const std::vector<T> &data, bool normalized = false) noexcept;
31
32         template<class T>
33         void PushIndices(std::size_t which, const std::vector<T> &indices) noexcept;
34
35         void DrawLineElements() const noexcept;
36         void DrawTriangleElements() const noexcept;
37
38 private:
39         void BindAttribute(std::size_t which) const noexcept;
40         void EnableAttribute(std::size_t which) noexcept;
41         template <class T>
42         void AttributeData(const std::vector<T> &) noexcept;
43         template <class T>
44         void AttributePointer(std::size_t which, bool normalized = false) noexcept;
45
46         void BindIndex(std::size_t which) const noexcept;
47         template <class T>
48         void IndexData(const std::vector<T> &) noexcept;
49
50 private:
51         GLuint array_id;
52         GLuint attr_id[NUM_ATTRS];
53
54         std::size_t idx_count;
55         GLenum idx_type;
56
57 };
58
59 }
60
61 #include "VertexArray.inl"
62
63 #endif