From 69a04cbd7e96e844833ba92a92e50b0ec40192ff Mon Sep 17 00:00:00 2001 From: Green Sky Date: Wed, 13 Apr 2022 01:23:39 +0200 Subject: [PATCH] refactor ogl buffer --- .../src/mm/opengl/buffer.cpp | 20 +++++++++++++++---- .../src/mm/opengl/buffer.hpp | 7 ++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/framework/opengl_primitives/src/mm/opengl/buffer.cpp b/framework/opengl_primitives/src/mm/opengl/buffer.cpp index 3042fbe..562c8d1 100644 --- a/framework/opengl_primitives/src/mm/opengl/buffer.cpp +++ b/framework/opengl_primitives/src/mm/opengl/buffer.cpp @@ -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 diff --git a/framework/opengl_primitives/src/mm/opengl/buffer.hpp b/framework/opengl_primitives/src/mm/opengl/buffer.hpp index 6491d30..7e7cac2 100644 --- a/framework/opengl_primitives/src/mm/opengl/buffer.hpp +++ b/framework/opengl_primitives/src/mm/opengl/buffer.hpp @@ -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