From b8a0cdfa3ee6bb8ea601b9aacab3080f539e4402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20GUEZO?= Date: Mon, 8 Dec 2025 15:53:48 +0100 Subject: [PATCH] feat: rework ebo, vao and vbo --- inc/ebo.hpp | 5 +++-- inc/vbo.hpp | 4 +++- src/ebo.cpp | 12 +++++++----- src/vao.cpp | 3 --- src/vbo.cpp | 12 +++++++----- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/inc/ebo.hpp b/inc/ebo.hpp index 43aa831..26b30c7 100755 --- a/inc/ebo.hpp +++ b/inc/ebo.hpp @@ -5,16 +5,17 @@ #include "glad/glad.h" - class EBO { private: GLuint id; public: - EBO(unsigned int* indices, size_t size); + EBO(); ~EBO(); + void setData(unsigned int* indices, size_t size); + void bind(); void unbind(); }; diff --git a/inc/vbo.hpp b/inc/vbo.hpp index 3d4a856..a28d6fe 100755 --- a/inc/vbo.hpp +++ b/inc/vbo.hpp @@ -11,9 +11,11 @@ class VBO unsigned int id; public: - VBO(GLfloat* vertices, size_t size); + VBO(); ~VBO(); + void setData(GLfloat* vertices, size_t size); + void bind(); void unbind(); }; diff --git a/src/ebo.cpp b/src/ebo.cpp index a325529..bfc917c 100755 --- a/src/ebo.cpp +++ b/src/ebo.cpp @@ -1,14 +1,16 @@ #include "ebo.hpp" -EBO::EBO(unsigned int* indices, size_t size) +EBO::EBO() : id(0) {} + +void EBO::setData(unsigned int* indices, size_t size) { - glGenBuffers(1, &id); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id); + if (this->id == 0) glGenBuffers(1, &this->id); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->id); glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, indices, GL_STATIC_DRAW); } -EBO::~EBO() { glDeleteBuffers(1, &id); } +EBO::~EBO() { glDeleteBuffers(1, &this->id); } -void EBO::bind() { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id); } +void EBO::bind() { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->id); } void EBO::unbind() { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } \ No newline at end of file diff --git a/src/vao.cpp b/src/vao.cpp index b666f3d..9944d21 100755 --- a/src/vao.cpp +++ b/src/vao.cpp @@ -11,7 +11,6 @@ void VAO::unbind() { glBindVertexArray(0); } void VAO::setAttributePointer(GLuint index, GLuint size, GLenum type, GLsizei stride, const void* offset) { - bind(); glEnableVertexAttribArray(index); glVertexAttribPointer(index, size, type, GL_FALSE, stride, offset); } @@ -19,12 +18,10 @@ void VAO::setAttributePointer(GLuint index, GLuint size, GLenum type, void VAO::drawElement(GLenum mode, GLsizei count, GLenum type, const void* indices) { - bind(); glDrawElements(mode, count, type, indices); } void VAO::drawArray(GLenum mode, GLint first, GLsizei count) { - bind(); glDrawArrays(mode, first, count); } \ No newline at end of file diff --git a/src/vbo.cpp b/src/vbo.cpp index cec3b3a..e056745 100755 --- a/src/vbo.cpp +++ b/src/vbo.cpp @@ -1,14 +1,16 @@ #include "vbo.hpp" -VBO::VBO(GLfloat* vertices, size_t size) +VBO::VBO() : id(0) {} + +void VBO::setData(GLfloat* vertices, size_t size) { - glGenBuffers(1, &id); - glBindBuffer(GL_ARRAY_BUFFER, id); + if (this->id == 0) glGenBuffers(1, &this->id); + glBindBuffer(GL_ARRAY_BUFFER, this->id); glBufferData(GL_ARRAY_BUFFER, size, vertices, GL_STATIC_DRAW); } -VBO::~VBO() { glDeleteBuffers(1, &id); } +VBO::~VBO() { glDeleteBuffers(1, &this->id); } -void VBO::bind() { glBindBuffer(GL_ARRAY_BUFFER, id); } +void VBO::bind() { glBindBuffer(GL_ARRAY_BUFFER, this->id); } void VBO::unbind() { glBindBuffer(GL_ARRAY_BUFFER, 0); } \ No newline at end of file