diff options
| author | hachem <im@hachem.wtf> | 2025-08-12 18:12:37 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2025-08-12 18:12:37 +0200 |
| commit | a2ec7dabd48a70ea69623406ddd0f8f97af403c8 (patch) | |
| tree | 52d71b51753b88473607f5e97f8bc15bdb5ad7d3 /src/Platform/OpenGL/OpenGLVertexArray.cpp | |
| parent | 16dff443789c7f1461b46ce52966972ae14c042b (diff) | |
[add]: Start of a basic rendering backend
Diffstat (limited to 'src/Platform/OpenGL/OpenGLVertexArray.cpp')
| -rw-r--r-- | src/Platform/OpenGL/OpenGLVertexArray.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/Platform/OpenGL/OpenGLVertexArray.cpp b/src/Platform/OpenGL/OpenGLVertexArray.cpp new file mode 100644 index 0000000..f172b9f --- /dev/null +++ b/src/Platform/OpenGL/OpenGLVertexArray.cpp @@ -0,0 +1,55 @@ +#include <glad/glad.h> +#include "OpenGLVertexArray.h" +#include "Rendering/VertexBuffer.h" +#include "Rendering/IndexBuffer.h" + +namespace Donut +{ + OpenGLVertexArray::OpenGLVertexArray() + { + glCreateVertexArrays(1, &m_RendererID); + } + + OpenGLVertexArray::~OpenGLVertexArray() + { + glDeleteVertexArrays(1, &m_RendererID); + } + + void OpenGLVertexArray::Bind() const + { + glBindVertexArray(m_RendererID); + } + + void OpenGLVertexArray::Unbind() const + { + glBindVertexArray(0); + } + + void OpenGLVertexArray::AddVertexBuffer(const std::shared_ptr<VertexBuffer>& vertexBuffer) + { + glBindVertexArray(m_RendererID); + vertexBuffer->Bind(); + + const auto& layout = vertexBuffer->GetLayout(); + for (const auto& element : layout.GetElements()) + { + glEnableVertexAttribArray(m_VertexBufferIndex); + glVertexAttribPointer(m_VertexBufferIndex, + element.count, + element.type, + element.normalized ? GL_TRUE : GL_FALSE, + layout.GetStride(), + (const void*)element.offset); + m_VertexBufferIndex++; + } + + m_VertexBuffers.push_back(vertexBuffer); + } + + void OpenGLVertexArray::SetIndexBuffer(const std::shared_ptr<IndexBuffer>& indexBuffer) + { + glBindVertexArray(m_RendererID); + indexBuffer->Bind(); + m_IndexBuffer = indexBuffer; + } +}; |
