#include "VertexBuffer.hpp"

TSE::uint TSE::GLFW::VertexBuffer::boundBuffer = 0;

TSE::GLFW::VertexBuffer::VertexBuffer()
{
    glGenBuffers(1, &bufferID);
}

void TSE::GLFW::VertexBuffer::SetData(int size, void *buffer, GLenum usage)
{
    glBufferData(GL_ARRAY_BUFFER, size, buffer, usage);
}

void TSE::GLFW::VertexBuffer::Bind()
{
    glBindBuffer(GL_ARRAY_BUFFER, bufferID);
    boundBuffer = bufferID;
}

void TSE::GLFW::VertexBuffer::Unbind()
{
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    boundBuffer = 0;
}

bool TSE::GLFW::VertexBuffer::IsBound()
{
    return boundBuffer == bufferID;
}

TSE::GLFW::VertexBuffer::~VertexBuffer()
{
    if(bufferID != 0)
    {
        if(IsBound()) Unbind();
        glDeleteBuffers(1, &bufferID);
    }
}
