Antkeeper  0.0.1
vertex-buffer.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Antkeeper source code is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef ANTKEEPER_GL_VERTEX_BUFFER_HPP
21 #define ANTKEEPER_GL_VERTEX_BUFFER_HPP
22 
24 #include <cstddef>
25 #include <span>
26 
27 namespace gl {
28 
33 {
34 public:
45  vertex_buffer(buffer_usage usage, std::size_t size, std::span<const std::byte> data = {});
46 
47  inline explicit vertex_buffer(buffer_usage usage, std::span<const std::byte> data = {}):
48  vertex_buffer(usage, data.size(), data)
49  {}
50 
51  inline vertex_buffer():
53  {}
55 
61  vertex_buffer(const vertex_buffer& buffer);
62 
68  vertex_buffer(vertex_buffer&& buffer);
69 
72 
80  vertex_buffer& operator=(const vertex_buffer& buffer);
81 
90 
101  void repurpose(buffer_usage usage, std::size_t size, std::span<const std::byte> data = {});
102 
103  inline void repurpose(buffer_usage usage, std::span<const std::byte> data)
104  {
105  repurpose(usage, data.size(), data);
106  }
107 
109  {
110  repurpose(usage, m_size, {});
111  }
113 
123  inline void resize(std::size_t size, std::span<const std::byte> data = {})
124  {
125  repurpose(m_usage, size, data);
126  }
127 
128  inline void resize(std::span<const std::byte> data)
129  {
130  repurpose(m_usage, data.size(), data);
131  }
133 
143  void write(std::size_t offset, std::span<const std::byte> data);
144 
145  inline void write(std::span<const std::byte> data)
146  {
147  write(0, data);
148  }
150 
160  void read(std::size_t offset, std::span<std::byte> data) const;
161 
162  inline void read(std::span<std::byte> data) const
163  {
164  read(0, data);
165  }
167 
179  void copy(const vertex_buffer& read_buffer, std::size_t copy_size, std::size_t read_offset = 0, std::size_t write_offset = 0);
180 
182  [[nodiscard]] inline constexpr std::size_t size() const noexcept
183  {
184  return m_size;
185  }
186 
188  [[nodiscard]] inline constexpr buffer_usage usage() const noexcept
189  {
190  return m_usage;
191  }
192 
193 private:
194  friend class pipeline;
195 
196  unsigned int m_gl_named_buffer{0};
198  std::size_t m_size{0};
199 };
200 
201 } // namespace gl
202 
203 #endif // ANTKEEPER_GL_VERTEX_BUFFER_HPP
Graphics pipeline interface.
Definition: pipeline.hpp:48
Vertex buffer object (VBO).
void repurpose(buffer_usage usage, std::size_t size, std::span< const std::byte > data={})
Repurposes the vertex buffer, changing its usage hint, size, and updating its data.
void write(std::span< const std::byte > data)
Writes data into the vertex buffer.
vertex_buffer()
Constructs a vertex buffer.
void copy(const vertex_buffer &read_buffer, std::size_t copy_size, std::size_t read_offset=0, std::size_t write_offset=0)
Copies a subset of another vertex buffer's data into this vertex buffer.
vertex_buffer & operator=(const vertex_buffer &buffer)
Copies another vertex buffer.
vertex_buffer(buffer_usage usage, std::span< const std::byte > data={})
Constructs a vertex buffer.
void write(std::size_t offset, std::span< const std::byte > data)
Writes data into the vertex buffer.
constexpr std::size_t size() const noexcept
Returns the size of the buffer's data, in bytes.
void read(std::size_t offset, std::span< std::byte > data) const
Reads a subset of the buffer's data from the GL and returns it to the application.
void repurpose(buffer_usage usage, std::span< const std::byte > data)
Repurposes the vertex buffer, changing its usage hint, size, and updating its data.
void resize(std::span< const std::byte > data)
Resizes the vertex buffer.
~vertex_buffer()
Destroys a vertex buffer.
void resize(std::size_t size, std::span< const std::byte > data={})
Resizes the vertex buffer.
void repurpose(buffer_usage usage)
Repurposes the vertex buffer, changing its usage hint, size, and updating its data.
constexpr buffer_usage usage() const noexcept
Return's the buffer's usage hint.
void read(std::span< std::byte > data) const
Reads a subset of the buffer's data from the GL and returns it to the application.
Graphics library interface.
Definition: window.hpp:28
buffer_usage
Usage hints for vertex buffers.
@ static_draw
Data will be modified once, by the application, and used many times, for drawing commands.
T offset(T longitude)
Calculates the UTC offset at a given longitude.
Definition: utc.hpp:38