From 2a2547f216581766b392de5c3b43b93b6fc5487e Mon Sep 17 00:00:00 2001 From: NaifBanana <30419422+NaifBanana@users.noreply.github.com> Date: Wed, 10 Jun 2026 19:43:35 -0500 Subject: [PATCH] Make VertexAttributePointer store index instead of buffer pointer --- engine/NBGraphics/VertexArray.hpp | 12 +++++------- engine/NBGraphics/src/VertexArray.cpp | 14 +++++++------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/engine/NBGraphics/VertexArray.hpp b/engine/NBGraphics/VertexArray.hpp index b092e6c..be13f52 100644 --- a/engine/NBGraphics/VertexArray.hpp +++ b/engine/NBGraphics/VertexArray.hpp @@ -25,7 +25,11 @@ struct VertexAttribute { VertexAttributeLayout layout; }; -struct VertexAttributePointer; +struct VertexAttributePointer { + VertexAttribute attribute; + GLuint buffer; + GLuint index; +}; static bool isIndexInVertexAttribute(int i, const VertexAttribute& va) { if ((i -= va.layout.offset) < 0) { return false; } @@ -85,12 +89,6 @@ class VertexBuffer }; -struct VertexAttributePointer { - VertexAttribute attribute; - VertexBuffer* buffer; - GLuint index; -}; - class VAO : public OpenGLObject { using Base = OpenGLObject; using Codes = VAOError::Codes; diff --git a/engine/NBGraphics/src/VertexArray.cpp b/engine/NBGraphics/src/VertexArray.cpp index 1914cf2..b84eebf 100644 --- a/engine/NBGraphics/src/VertexArray.cpp +++ b/engine/NBGraphics/src/VertexArray.cpp @@ -38,7 +38,7 @@ VertexAttributePointerList VAO::attributes(const VertexAttributePointerList& att _attrs = attrs_; bind(); for (auto attr_ptr : attrs_) { - attr_ptr.buffer->bind(); + glBindBuffer(GL_ARRAY_BUFFER, attr_ptr.buffer); GLuint idx = attr_ptr.index; glVertexAttribPointer( idx, @@ -124,7 +124,7 @@ size_t VertexGroup::buffer(VertexBuffer&& buf_) { GLuint idx = attrs.size(); for (auto attr : buf_ptr->attributes) { attrs.emplace_back( - VertexAttributePointer{attr, buf_ptr,idx} + VertexAttributePointer{attr, buf_ptr->id(),idx} ); idx++; } @@ -152,7 +152,7 @@ size_t VertexGroup::buffers(std::vector>&& bufs_) { for (auto buf : _vertex_data) { for (auto attr : buf->attributes) { attr_ptrs.emplace_back( - VertexAttributePointer{attr, buf.get(), idx} + VertexAttributePointer{attr, buf->id(), idx} ); idx++; } @@ -197,10 +197,10 @@ void VertexGroup::disableAttr(GLuint idx) { } void VertexGroup::disableBuffer(size_t idx) { - auto buf_ptr = _vertex_data[idx].get(); + auto buf_idx = _vertex_data[idx]->id(); bind(); for (auto attr : _vao.attributes()) { - if (attr.buffer == buf_ptr) { + if (attr.buffer == buf_idx) { _vao.disable(attr.index); } } @@ -208,10 +208,10 @@ void VertexGroup::disableBuffer(size_t idx) { } void VertexGroup::enableBuffer(size_t idx) { - auto buf_ptr = _vertex_data[idx].get(); + auto buf_idx = _vertex_data[idx]->id(); bind(); for (auto attr : _vao.attributes()) { - if (attr.buffer == buf_ptr) { + if (attr.buffer == buf_idx) { _vao.enable(attr.index); } }