VertexArray.hpp
1// Copyright 2019 Arthur Sonzogni. All rights reserved.
2// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
4
5#ifndef SMK_VERTEX_ARRAY_HPP
6#define SMK_VERTEX_ARRAY_HPP
7
8#include <initializer_list>
9#include <smk/OpenGL.hpp>
10#include <smk/Vertex.hpp>
11#include <vector>
12
13namespace smk {
14
15/// @brief An array of smk::Vertex moved to the GPU memory. This represent a set
16/// of triangles to be drawn by the GPU.
17///
18/// This class is movable and copyable. It is refcounted. The GPU data is
19/// automatically released when the last smk::VertextArray is deleted.
21 public:
22 VertexArray(); // The null VertexArray.
23 VertexArray(const std::vector<Vertex2D>& array);
24 VertexArray(const std::vector<Vertex3D>& array);
25
27
28 void Bind() const;
29 void UnBind() const;
30
31 // --- Movable-Copyable resource ---------------------------------------------
32 VertexArray(VertexArray&&) noexcept;
34 VertexArray& operator=(VertexArray&&) noexcept;
35 VertexArray& operator=(const VertexArray&);
36 // ---------------------------------------------------------------------------
37 bool operator==(const smk::VertexArray&) const;
38 bool operator!=(const smk::VertexArray&) const;
39
40 size_t size() const;
41
42 private:
43 void Allocate(int element_size, void* data);
44 void Release();
45
46 GLuint vbo_ = 0;
47 GLuint vao_ = 0;
48 size_t size_ = 0u;
49
50 // Used to support copy. Nullptr as long as this class is not copied.
51 // Otherwise an integer counting how many instances shares this resource.
52 mutable int* ref_count_ = nullptr;
53};
54
55} // namespace smk.
56
57#endif /* end of include guard: SMK_VERTEX_ARRAY_HPP */
An array of smk::Vertex moved to the GPU memory. This represent a set of triangles to be drawn by the...
Definition: VertexArray.hpp:20
size_t size() const
The size of the GPU array.
Definition: VertexArray.cpp:92