1 #ifndef BLOBS_GRAPHICS_BUFFER_HPP_
2 #define BLOBS_GRAPHICS_BUFFER_HPP_
4 #include "../app/error.hpp"
17 MappedBuffer(GLenum target, GLenum access)
18 : buf(reinterpret_cast<T *>(glMapBuffer(target, access)))
21 throw app::GLError("failed to map buffer");
28 ~MappedBuffer() noexcept {
30 glUnmapBuffer(target);
34 MappedBuffer(MappedBuffer<T> &&other) noexcept
36 , target(other.target) {
39 MappedBuffer<T> &operator =(MappedBuffer<T> &&other) noexcept {
40 std::swap(buf, other.buf);
41 std::swap(target, other.target);
44 MappedBuffer(const MappedBuffer<T> &) = delete;
45 MappedBuffer<T> &operator =(const MappedBuffer<T> &) = delete;
47 explicit operator bool() const noexcept { return buf; }
50 T &operator [](std::size_t i) noexcept { return buf[i]; }
51 const T &operator [](std::size_t i) const noexcept { return buf[i]; }