Vivid
Loading...
Searching...
No Matches
VertexArray.cpp
1#include "VertexArray.h"
2
3namespace Vivid
4{
5 VertexArray::VertexArray()
6 {
7 GLCall(glGenVertexArrays(1, &m_RendererID));
8 GLCall(glBindVertexArray(m_RendererID));
9 }
10
11 VertexArray::~VertexArray()
12 {
13 }
14
15 void VertexArray::AddVertexBuffer(const VertexBuffer& vb, const VertexBufferLayout& layout,
16 const Vector<Vertex>& vertices)
17 {
18 Bind();
19 vb.Bind(vertices);
20 const Vector<VertexBufferElement> elements = layout.GetElements();
21 unsigned int offset = 0;
22 for (unsigned int i = 0; i < elements.size(); i++)
23 {
24 const VertexBufferElement element = elements[i];
25 GLCall(glEnableVertexAttribArray(i));
26 GLCall(glVertexAttribPointer(i, element.count, element.type, element.normalised, layout.GetStride(),
27 (const void*)offset));
28 offset += element.count * VertexBufferElement::GetSizeOfType(element.type);
29 }
30 }
31
32 void VertexArray::AddIndexBuffer(const IndexBuffer& ib)
33 {
34 Bind();
35 ib.Bind();
36 }
37
38 void VertexArray::Bind() const
39 {
40 GLCall(glBindVertexArray(m_RendererID));
41 }
42
43 void VertexArray::Unbind() const
44 {
45 GLCall(glBindVertexArray(0));
46 }
47
48 Ref<VertexArray> VertexArray::Create()
49 {
50 return MakeRef<VertexArray>();
51 };
52}