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