-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVertexArray.cpp
More file actions
43 lines (37 loc) · 882 Bytes
/
VertexArray.cpp
File metadata and controls
43 lines (37 loc) · 882 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
39
40
41
42
43
#include "VertexArray.h"
VertexArray::VertexArray()
{
glGenVertexArrays(1, &m_RendererID);
}
VertexArray::~VertexArray()
{
glDeleteVertexArrays(1, &m_RendererID);
}
void VertexArray::AddBuffer(VertexBuffer& vb, const VertexBufferLayout& layout)
{
Bind();
vb.Bind();
this->vb = &vb;
const auto& elements = layout.GetElements();
unsigned int offset = 0;
for (int i = 0; i < elements.size(); i++)
{
const auto& element = elements[i];
glEnableVertexAttribArray(i);
glVertexAttribPointer(i, element.count, element.type, element.normalized, layout.GetStride(), (const void*)offset);
offset += element.count * element.GetSizeOfType(element.type);
}
UnBind();
}
void VertexArray::Bind() const
{
glBindVertexArray(m_RendererID);
}
void VertexArray::UnBind() const
{
glBindVertexArray(0);
}
void VertexArray::changeData(const void* data)
{
vb->changeData(data);
}