Path Tracing
Loading...
Searching...
No Matches
buffer.hpp
Go to the documentation of this file.
1#pragma once
2#include <GL/glew.h>
3#include <utility>
4
9class GLBuffer {
10 GLuint id_ = 0;
11public:
12 GLBuffer() = default;
14
15 GLBuffer(const GLBuffer&) = delete;
16 GLBuffer& operator=(const GLBuffer&) = delete;
17
18 GLBuffer(GLBuffer&& other) noexcept : id_(std::exchange(other.id_, 0)) {}
19 GLBuffer& operator=(GLBuffer&& other) noexcept {
20 if(this != &other) { reset(); id_ = std::exchange(other.id_, 0); }
21 return *this;
22 }
23
25 void upload(GLsizeiptr size_bytes, const void* data, GLenum usage) {
26 reset();
27 glCreateBuffers(1, &id_);
28 glNamedBufferData(id_, size_bytes, data, usage);
29 }
30
31 void bindBase(GLenum target, GLuint binding) const {
32 glBindBufferBase(target, binding, id_);
33 }
34
35 void reset() {
36 if(id_) { glDeleteBuffers(1, &id_); id_ = 0; }
37 }
38
39 GLuint id() const { return id_; }
40 explicit operator bool() const { return id_ != 0; }
41};
void upload(GLsizeiptr size_bytes, const void *data, GLenum usage)
Uploads/Reuploads data, freeing any previous held buffer first.
Definition buffer.hpp:25
void bindBase(GLenum target, GLuint binding) const
Definition buffer.hpp:31
GLBuffer()=default
GLuint id() const
Definition buffer.hpp:39
GLBuffer & operator=(GLBuffer &&other) noexcept
Definition buffer.hpp:19
GLBuffer(GLBuffer &&other) noexcept
Definition buffer.hpp:18
GLBuffer(const GLBuffer &)=delete
~GLBuffer()
Definition buffer.hpp:13
GLBuffer & operator=(const GLBuffer &)=delete
void reset()
Definition buffer.hpp:35
khronos_ssize_t GLsizeiptr
Definition imgui_impl_opengl3_loader.h:267
#define glDeleteBuffers
Definition imgui_impl_opengl3_loader.h:580
unsigned int GLuint
Definition imgui_impl_opengl3_loader.h:147
unsigned int GLenum
Definition imgui_impl_opengl3_loader.h:140
GLint * data
Definition imgui_impl_opengl3_loader.h:202
GLsizeiptr const void GLenum usage
Definition imgui_impl_opengl3_loader.h:277