-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVertexArray.cpp
38 lines (27 loc) · 902 Bytes
/
VertexArray.cpp
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"Renderer.h"
VertexArray::VertexArray() {
GLCall(glGenVertexArrays(1, &m_RendererID));
}
VertexArray::~VertexArray() {
GLCall(glDeleteVertexArrays(1, 0));
}
void VertexArray::Bind() const {
GLCall(glBindVertexArray(m_RendererID));
}
void VertexArray::Unbind() const {
GLCall(glBindVertexArray(0));
}
void VertexArray::AddBuffer(const VertexBuffer& vb, 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);
}
}