#include "vbo.h"

/* Initializes/generates a Vertex Buffer Object (VBO). */
void
vbo_init(VBO* self, GLint type, bool isDynamic)
{
	self->isDynamic = isDynamic;
	self->type = type;

	glGenBuffers(1, &self->handle);
}

/* Bind a VBO, specifying a type. */
void
vbo_bind(VBO* self)
{
	glBindBuffer(self->type, self->handle);
}

/* Frees a given VBO. */
void
vbo_free(VBO* self)
{
	glDeleteBuffers(1, &self->handle);
	memset(self, '\0', sizeof(VBO));
}

/* Binds and sends data to a VBO. */
void
vbo_buffer(VBO* self, size_t size, void* data)
{
	glBufferData(self->type, size, data, self->isDynamic ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW);
}
