diff options
Diffstat (limited to 'Project/VertexArray.cpp')
-rw-r--r-- | Project/VertexArray.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/Project/VertexArray.cpp b/Project/VertexArray.cpp new file mode 100644 index 0000000..2ae8725 --- /dev/null +++ b/Project/VertexArray.cpp @@ -0,0 +1,44 @@ +#include "VertexArray.h" +#include "Renderer.h" +#include "VertexBufferLayout.h" + +VertexArray::VertexArray() +{ + GLCall(glGenVertexArrays(1, &m_rendererID)); +} + +VertexArray::~VertexArray() +{ + GLCall(glDeleteVertexArrays(1, &m_rendererID)); +} + +void VertexArray::AddBuffer(const VertexBuffer& vb, const VertexBufferLayout& layout) +{ + Bind(); + vb.Bind(); + const auto& elements = layout.GetElements(); + unsigned int offset = 0; + for (unsigned int i = 0; i < elements.size(); ++i) { + const auto& element = elements[i]; + GLCall(glEnableVertexAttribArray(i)); + GLCall(glVertexAttribPointer(i, element.count, element.type, element.normalized, layout.GetStride(), (const void*)offset)); + offset += element.count * VertexBufferElement::GetSizeOfType(element.type); + } +} + +void VertexArray::UpdateBuffer(const VertexBuffer& vb, const void* newVBData, const unsigned int& newVBSize) +{ + Bind(); + vb.Bind(); + vb.SetSubData(newVBData, newVBSize); +} + +void VertexArray::Bind() const +{ + GLCall(glBindVertexArray(m_rendererID)); +} + +void VertexArray::Unbind() const +{ + GLCall(glBindVertexArray(0)); +} |