-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathVertexArray.cpp
More file actions
38 lines (32 loc) · 970 Bytes
/
VertexArray.cpp
File metadata and controls
38 lines (32 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "VertexArray.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(), reinterpret_cast<const void*>(offset)));
offset += element.count * VertexBufferLayoutElement::GetSizeOfType(element.type);
}
}
void VertexArray::Bind() const
{
GLCall(glBindVertexArray(m_RendererId));
}
void VertexArray::Unbind() const
{
GLCall(glBindVertexArray(0));
}