Tatooine
indexeddata.h
Go to the documentation of this file.
1#ifndef TATOOINE_GL_INDEXED_DATA_H
2#define TATOOINE_GL_INDEXED_DATA_H
3//==============================================================================
7
8#include <mutex>
9//==============================================================================
10namespace tatooine::gl {
11//==============================================================================
12template <typename... Ts>
14 //============================================================================
15 // TYPEDEFS
16 //============================================================================
17 public:
18 using vbo_t = gl::vertexbuffer<Ts...>;
21 using ibo_value_type = unsigned int;
22 using vbo_data_vec = std::vector<vbo_value_type>;
23 using ibo_data_vec = std::vector<ibo_value_type>;
24 //============================================================================
25 // MEMBERS
26 //============================================================================
27 private:
30 mutable std::mutex m_mutex;
31 //============================================================================
32 // CONSTRUCTORS
33 //============================================================================
34 public:
35 indexeddata() = default;
36 //----------------------------------------------------------------------------
38 : m_vbo{other.m_vbo}, m_ibo{other.m_ibo} {}
39 indexeddata(indexeddata&& other) noexcept
40 : m_vbo{std::move(other.m_vbo)}, m_ibo{std::move(other.m_ibo)} {}
41 //----------------------------------------------------------------------------
42 auto operator=(indexeddata const& other) -> indexeddata& {
43 m_vbo = other.m_vbo;
44 m_ibo = other.m_ibo;
45 return *this;
46 }
47 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
48 auto operator=(indexeddata&& other) noexcept -> indexeddata& {
49 m_vbo = std::move(other.m_vbo);
50 m_ibo = std::move(other.m_ibo);
51 return *this;
52 }
53 //----------------------------------------------------------------------------
54 indexeddata(vbo_data_vec const& vbo_data, ibo_data_vec const& ibo_data)
55 : m_vbo(vbo_data), m_ibo(ibo_data) {}
56 //----------------------------------------------------------------------------
57 indexeddata(size_t const vbo_size, size_t const ibo_size)
58 : m_vbo(vbo_size), m_ibo(ibo_size) {}
59 //============================================================================
60 // METHODS
61 //============================================================================
62 auto create_vao() const {
63 vertexarray vao;
64 vao.bind();
65 m_vbo.bind();
67 m_ibo.bind();
68 return vao;
69 }
70 //----------------------------------------------------------------------------
71 void clear() {
72 //std::lock_guard lock{m_mutex};
73 m_vbo.clear();
74 m_ibo.clear();
75 }
76 //----------------------------------------------------------------------------
77 void draw_points() const {
78 std::lock_guard lock{m_mutex};
79 auto vao = create_vao();
80 vao.draw_points(m_ibo.size());
81 }
82 //----------------------------------------------------------------------------
83 void draw_line_strip() const {
84 std::lock_guard lock{m_mutex};
85 auto vao = create_vao();
86 vao.draw_line_strip(m_ibo.size());
87 }
88 //----------------------------------------------------------------------------
89 void draw_line_loop() const {
90 std::lock_guard lock{m_mutex};
91 auto vao = create_vao();
92 vao.draw_line_loop(m_ibo.size());
93 }
94 //----------------------------------------------------------------------------
95 void draw_lines() const {
96 auto vao = create_vao();
97 std::lock_guard lock{m_mutex};
98 vao.draw_lines(m_ibo.size());
99 }
100 //----------------------------------------------------------------------------
102 std::lock_guard lock{m_mutex};
103 auto vao = create_vao();
104 vao.draw_line_strip_adjacency(m_ibo.size());
105 }
106 //----------------------------------------------------------------------------
107 void draw_triangle_strip() const {
108 std::lock_guard lock{m_mutex};
109 auto vao = create_vao();
110 vao.draw_triangle_strip(m_ibo.size());
111 }
112 //----------------------------------------------------------------------------
113 void draw_triangle_fan() const {
114 std::lock_guard lock{m_mutex};
115 auto vao = create_vao();
116 vao.draw_triangle_fan(m_ibo.size());
117 }
118 //----------------------------------------------------------------------------
119 void draw_triangles() const {
120 std::lock_guard lock{m_mutex};
121 auto vao = create_vao();
122 vao.draw_triangles(m_ibo.size());
123 }
124 //----------------------------------------------------------------------------
126 std::lock_guard lock{m_mutex};
127 auto vao = create_vao();
128 vao.draw_triangle_strip_adjacency(m_ibo.size());
129 }
130 //----------------------------------------------------------------------------
132 std::lock_guard lock{m_mutex};
133 auto vao = create_vao();
134 vao.draw_triangles_adjacency(m_ibo.size());
135 }
136 //----------------------------------------------------------------------------
137 void draw_patches() const {
138 std::lock_guard lock{m_mutex};
139 auto vao = create_vao();
140 vao.draw_patches(m_ibo.size());
141 }
142 //============================================================================
143 // GETTER
144 //============================================================================
145 auto indexbuffer() -> auto& { return m_ibo; }
146 auto indexbuffer() const -> auto const& { return m_ibo; }
147 //----------------------------------------------------------------------------
148 auto vertexbuffer() -> auto& { return m_vbo; }
149 auto vertexbuffer() const -> auto const& { return m_vbo; }
150 //----------------------------------------------------------------------------
151 auto mutex() -> auto& { return m_mutex; }
152 auto mutex() const -> auto const& { return m_mutex; }
153};
154//==============================================================================
155} // namespace tatooine::gl
156//==============================================================================
157#endif
auto size() const
Definition: buffer.h:460
auto bind() const -> void
Definition: buffer.h:684
auto clear()
Definition: buffer.h:465
Definition: indexbuffer.h:13
Definition: indexeddata.h:13
auto mutex() -> auto &
Definition: indexeddata.h:151
typename vbo_t::value_type vbo_value_type
Definition: indexeddata.h:20
void draw_line_loop() const
Definition: indexeddata.h:89
auto create_vao() const
Definition: indexeddata.h:62
auto indexbuffer() -> auto &
Definition: indexeddata.h:145
auto operator=(indexeddata &&other) noexcept -> indexeddata &
Definition: indexeddata.h:48
void draw_triangle_fan() const
Definition: indexeddata.h:113
void clear()
Definition: indexeddata.h:71
void draw_lines() const
Definition: indexeddata.h:95
unsigned int ibo_value_type
Definition: indexeddata.h:21
std::vector< vbo_value_type > vbo_data_vec
Definition: indexeddata.h:22
void draw_triangles() const
Definition: indexeddata.h:119
void draw_triangles_adjacency() const
Definition: indexeddata.h:131
auto vertexbuffer() const -> auto const &
Definition: indexeddata.h:149
void draw_triangle_strip() const
Definition: indexeddata.h:107
indexeddata(indexeddata const &other)
Definition: indexeddata.h:37
indexeddata(size_t const vbo_size, size_t const ibo_size)
Definition: indexeddata.h:57
void draw_line_strip() const
Definition: indexeddata.h:83
void draw_patches() const
Definition: indexeddata.h:137
indexeddata(indexeddata &&other) noexcept
Definition: indexeddata.h:39
auto vertexbuffer() -> auto &
Definition: indexeddata.h:148
auto mutex() const -> auto const &
Definition: indexeddata.h:152
void draw_triangle_strip_adjacency() const
Definition: indexeddata.h:125
auto operator=(indexeddata const &other) -> indexeddata &
Definition: indexeddata.h:42
auto indexbuffer() const -> auto const &
Definition: indexeddata.h:146
void draw_line_strip_adjacency() const
Definition: indexeddata.h:101
std::mutex m_mutex
Definition: indexeddata.h:30
vbo_t m_vbo
Definition: indexeddata.h:28
void draw_points() const
Definition: indexeddata.h:77
indexeddata(vbo_data_vec const &vbo_data, ibo_data_vec const &ibo_data)
Definition: indexeddata.h:54
ibo_t m_ibo
Definition: indexeddata.h:29
std::vector< ibo_value_type > ibo_data_vec
Definition: indexeddata.h:23
Definition: vertexarray.h:15
DLL_API void bind() const
static constexpr void activate_attributes()
Definition: vertexbuffer.h:76
Definition: ansiformat.h:6
Definition: utility.h:13