-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvertexArray.cpp
More file actions
62 lines (51 loc) · 1.06 KB
/
vertexArray.cpp
File metadata and controls
62 lines (51 loc) · 1.06 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "vertexArray.h"
#include <bugl/bugl.h>
#include "vertexBuffer.h"
vertexArray::vertexArray()
{
glGenVertexArrays(1, &id);
if (!id) { throw std::exception(); }
dirty = true;
buffers.resize(20);
}
vertexArray::vertexArray(std::string _path)
{
id = buLoadModel(_path, &vertCount);
dirty = false;
}
size_t vertexArray::getVertCount()
{
return vertCount;
}
vertexArray::~vertexArray()
{
glDeleteVertexArrays(1, &id);
}
void vertexArray::setBuffer(GLuint _index, std::shared_ptr<vertexBuffer> _buffer)
{
buffers.at(_index) = _buffer;
dirty = true;
}
GLuint vertexArray::getId()
{
if (dirty)
{
glBindVertexArray(id);
for (size_t i = 0; i < buffers.size(); i++)
{
if (buffers.at(i) == NULL) { break; }
glBindBuffer(GL_ARRAY_BUFFER, buffers.at(i)->getId());
glVertexAttribPointer(i,buffers.at(i)->getComponents(),
GL_FLOAT,GL_FALSE,0,(void*)0);
glEnableVertexAttribArray(i);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
glBindVertexArray(0);
dirty = false;
}
return id;
}
void vertexArray::setVertCount(int _size)
{
vertCount = _size;
}