aboutsummaryrefslogtreecommitdiff
path: root/src/Platform/OpenGL/OpenGLVertexArray.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Platform/OpenGL/OpenGLVertexArray.cpp')
-rw-r--r--src/Platform/OpenGL/OpenGLVertexArray.cpp55
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;
+ }
+};