1 #ifndef TACOS_GRAPHICS_BUFFER_HPP_
2 #define TACOS_GRAPHICS_BUFFER_HPP_
4 #include "../app/error.hpp"
16 MappedBuffer(GLenum target, GLenum access)
17 : buf(reinterpret_cast<T *>(glMapBuffer(target, access)))
20 throw GLError("failed to map buffer");
27 ~MappedBuffer() noexcept {
29 glUnmapBuffer(target);
33 MappedBuffer(MappedBuffer<T> &&other) noexcept
35 , target(other.target) {
38 MappedBuffer<T> &operator =(MappedBuffer<T> &&other) noexcept {
39 std::swap(buf, other.buf);
40 std::swap(target, other.target);
43 MappedBuffer(const MappedBuffer<T> &) = delete;
44 MappedBuffer<T> &operator =(const MappedBuffer<T> &) = delete;
46 explicit operator bool() const noexcept { return buf; }
49 T &operator [](std::size_t i) noexcept { return buf[i]; }
50 const T &operator [](std::size_t i) const noexcept { return buf[i]; }