Vivid
Loading...
Searching...
No Matches
IndexBuffer.cpp
1#include "IndexBuffer.h"
2#include "Renderer.h"
3
4namespace Vivid
5{
6 IndexBuffer::IndexBuffer(Vector<unsigned int>& indices)
7 : m_Count(indices.size())
8 {
9 GLCall(glGenBuffers(1, &m_RendererID)); // creating a buffer
10 GLCall(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_RendererID)); // binding the buffer
11 GLCall(glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(unsigned int), indices.data(),
12 GL_STATIC_DRAW));
13 }
14
15 IndexBuffer::~IndexBuffer()
16 {
17 GLCall(glDeleteBuffers(1, &m_RendererID));
18 }
19
20 void IndexBuffer::Bind() const
21 {
22 GLCall(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_RendererID));
23 }
24
25 void IndexBuffer::Unbind() const
26 {
27 GLCall(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
28 }
29
30 Ref<IndexBuffer> IndexBuffer::Create(Vector<unsigned int>& indices)
31 {
32 return MakeRef<IndexBuffer>(indices);
33 }
34}