refactor ogl buffer

This commit is contained in:
Green Sky 2022-04-13 01:23:39 +02:00
parent ab169927fe
commit 69a04cbd7e
2 changed files with 22 additions and 5 deletions

View File

@ -6,20 +6,28 @@
namespace MM::OpenGL {
Buffer::Buffer(const void* data, std::size_t size, GLenum usage) : _size(size) {
Buffer::Buffer(const void* data, std::size_t size, GLenum usage, GLenum target) : _size(size), _target(target) {
glGenBuffers(1, &_handle);
glBindBuffer(GL_ARRAY_BUFFER, _handle);
glBufferData(GL_ARRAY_BUFFER, size, data, usage);
glBindBuffer(_target, _handle);
glBufferData(_target, size, data, usage);
}
Buffer::~Buffer(void) {
glDeleteBuffers(1,&_handle);
glDeleteBuffers(1, &_handle);
}
void Buffer::bind(void) const {
glBindBuffer(_target, _handle);
}
void Buffer::bind(GLenum target) const {
glBindBuffer(target, _handle);
}
void Buffer::unbind(void) const {
glBindBuffer(_target, 0);
}
void Buffer::unbind(GLenum target) const {
glBindBuffer(target, 0);
}
@ -28,5 +36,9 @@ std::size_t Buffer::getSize(void) const {
return _size;
}
GLuint Buffer::getHandle(void) const {
return _handle;
}
} // MM::OpenGL

View File

@ -21,15 +21,20 @@ namespace MM::OpenGL {
private:
GLuint _handle = 0;
std::size_t _size = 0;
GLenum _target;
public:
Buffer(const void* data, std::size_t size, GLenum usage);
Buffer(const void* data, std::size_t size, GLenum usage, GLenum target = GL_ARRAY_BUFFER);
~Buffer(void);
void bind(void) const;
void bind(GLenum target) const;
void unbind(void) const;
void unbind(GLenum target) const;
std::size_t getSize(void) const;
GLuint getHandle(void) const;
};
} // MM::OpenGL