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

View File

@ -21,15 +21,20 @@ namespace MM::OpenGL {
private: private:
GLuint _handle = 0; GLuint _handle = 0;
std::size_t _size = 0; std::size_t _size = 0;
GLenum _target;
public: 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); ~Buffer(void);
void bind(void) const;
void bind(GLenum target) const; void bind(GLenum target) const;
void unbind(void) const;
void unbind(GLenum target) const; void unbind(GLenum target) const;
std::size_t getSize(void) const; std::size_t getSize(void) const;
GLuint getHandle(void) const;
}; };
} // MM::OpenGL } // MM::OpenGL