diff options
| author | hachem <im@hachem.wtf> | 2026-08-20 02:27:02 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-08-20 02:40:07 +0200 |
| commit | 5b361d81dbd2af0d0e99b9eb1adebea76ff05db0 (patch) | |
| tree | 34db1df17e8c7248aeeb92156d635d31c2484e3f /src/platform/opengl/opengl_vertex_array.cpp | |
| parent | e3abaaf59777258ba06705135a0cafcb5918ad12 (diff) | |
[chore]: MASSIVE refactor + more vulkan bs
Diffstat (limited to 'src/platform/opengl/opengl_vertex_array.cpp')
| -rw-r--r-- | src/platform/opengl/opengl_vertex_array.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/platform/opengl/opengl_vertex_array.cpp b/src/platform/opengl/opengl_vertex_array.cpp new file mode 100644 index 0000000..01e6f56 --- /dev/null +++ b/src/platform/opengl/opengl_vertex_array.cpp @@ -0,0 +1,58 @@ +#include <glad/glad.h> + +#include "opengl_vertex_array.h" +#include "rendering/vertex_buffer.h" +#include "rendering/index_buffer.h" + +namespace Donut +{ + OpenGLVertexArray::OpenGLVertexArray() + { + // glCreateVertexArrays is 4.5 DSA; macOS caps at 4.1. glGenVertexArrays + // reserves the name and the VAO is created on first bind (done below). + glGenVertexArrays(1, &m_renderer_id); + } + + OpenGLVertexArray::~OpenGLVertexArray() + { + glDeleteVertexArrays(1, &m_renderer_id); + } + + auto OpenGLVertexArray::bind() const -> void + { + glBindVertexArray(m_renderer_id); + } + + auto OpenGLVertexArray::unbind() const -> void + { + glBindVertexArray(0); + } + + auto OpenGLVertexArray::add_vertex_buffer(const Ref<VertexBuffer>& vertex_buffer) -> void + { + glBindVertexArray(m_renderer_id); + vertex_buffer->bind(); + + const auto& layout = vertex_buffer->get_layout(); + for (const auto& element : layout.get_elements()) + { + glEnableVertexAttribArray(m_vertex_buffer_index); + glVertexAttribPointer(m_vertex_buffer_index, + element.count, + element.type, + element.normalized ? GL_TRUE : GL_FALSE, + layout.get_stride(), + reinterpret_cast<const void*>(static_cast<uintptr_t>(element.offset))); + m_vertex_buffer_index++; + } + + m_vertex_buffers.push_back(vertex_buffer); + } + + auto OpenGLVertexArray::set_index_buffer(const Ref<IndexBuffer>& index_buffer) -> void + { + glBindVertexArray(m_renderer_id); + index_buffer->bind(); + m_index_buffer = index_buffer; + } +}; |
