]> git.tdb.fi Git - libs/gl.git/blob - source/core/buffer.h
Add correct copy and move semantics to most classes
[libs/gl.git] / source / core / buffer.h
1 #ifndef MSP_GL_BUFFER_H_
2 #define MSP_GL_BUFFER_H_
3
4 #include <stdexcept>
5 #include <string>
6 #include "buffer_backend.h"
7
8 namespace Msp {
9 namespace GL {
10
11 class buffer_too_small: public std::logic_error
12 {
13 public:
14         buffer_too_small(const std::string &w): std::logic_error(w) { }
15         virtual ~buffer_too_small() throw() { }
16 };
17
18 /**
19 Stores data in GPU memory.
20
21 Memory must be allocated for the buffer by calling storage().  Contents can
22 then be modified either synchronously with the data() and sub_data() functions,
23 or asynchronously by memory-mapping the buffer.
24
25 Applications normally don't need to deal with Buffers directly.  They're
26 managed by other classes such as Mesh and ProgramData.
27 */
28 class Buffer: public BufferBackend
29 {
30         friend BufferBackend;
31
32 private:
33         std::size_t size = 0;
34
35 public:
36         /** Sets the storage size and allocates memory for the buffer.  Size cannot
37         be changed once set. */
38         void storage(std::size_t);
39
40         /** Replaces contents of the entire buffer.  Allocated storage must exist.
41         The data must have size matching the defined storage. */
42         void data(const void *);
43
44         /** Replaces a range of bytes in the buffer.  Allocated storage must exist.
45         The range must be fully inside the buffer. */
46         void sub_data(std::size_t, std::size_t, const void *);
47
48         std::size_t get_size() const { return size; }
49
50         void require_size(std::size_t) const;
51
52         using BufferBackend::map;
53         using BufferBackend::unmap;
54
55         using BufferBackend::set_debug_name;
56 };
57
58 } // namespace GL
59 } // namespace Msp
60
61 #endif