forked from christopher-besch/opengl_reference
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndexBuffer.cpp
36 lines (29 loc) · 816 Bytes
/
IndexBuffer.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
#include "IndexBuffer.h"
#include "Renderer.h"
IndexBuffer::IndexBuffer(const unsigned int* data, unsigned int count)
: m_count(count)
{
#ifdef DEBUG
ASSERT(sizeof(unsigned int) == sizeof(GLuint));
#endif
glGenBuffers(1, &m_renderer_id);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_renderer_id);
// <- should be a four byte type <- GLuint
glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(unsigned int), data, GL_STATIC_DRAW);
}
IndexBuffer::~IndexBuffer()
{
glDeleteBuffers(1, &m_renderer_id);
}
void IndexBuffer::bind() const
{
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_renderer_id);
}
void IndexBuffer::unbind() const
{
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
unsigned int IndexBuffer::get_count() const
{
return m_count;
}