forked from michal1000w/GPUSmoke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVertexArray.cpp
35 lines (29 loc) · 889 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
#include "VertexArray.h"
#include "Common.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::Bind() const {
GLCall(glBindVertexArray(m_RendererID))
}
void VertexArray::UnBind() const {
GLCall(glBindVertexArray(0))
}