2016-03-21 04:10:14 +00:00
|
|
|
#include "VBO.h"
|
|
|
|
|
|
|
|
VBO::VBO()
|
|
|
|
{
|
2016-03-24 13:17:17 +00:00
|
|
|
m_id = 0;
|
|
|
|
m_target = 0;
|
|
|
|
m_capacity = 0;
|
|
|
|
m_size = 0;
|
2016-03-21 04:10:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VBO::Create(GLenum target, GLenum usage, GLsizeiptr size, const void* data)
|
|
|
|
{
|
|
|
|
glGenBuffers(1, &m_id); // create a vbo
|
|
|
|
glBindBuffer(target, m_id); // activate vbo id to use
|
|
|
|
glBufferData(target, size, data, usage); // upload data to video card
|
|
|
|
|
2016-03-24 13:17:17 +00:00
|
|
|
m_target = target;
|
2022-11-07 21:33:01 +00:00
|
|
|
m_capacity = (int)size;
|
2016-03-24 13:17:17 +00:00
|
|
|
m_size = 0;
|
2016-03-21 04:10:14 +00:00
|
|
|
|
|
|
|
Bind(false); // unbind
|
|
|
|
}
|
|
|
|
|
|
|
|
void VBO::BufferSubData(GLintptr offset, GLsizeiptr size, const GLvoid* data)
|
|
|
|
{
|
|
|
|
glBufferSubData(m_target, offset, size, data);
|
|
|
|
}
|
|
|
|
|
2016-03-24 13:17:17 +00:00
|
|
|
bool VBO::AppendData(GLsizeiptr size, const GLvoid* data)
|
|
|
|
{
|
2016-03-26 22:44:26 +00:00
|
|
|
if (size == 0 || !data) {
|
|
|
|
return true; // nothing to do
|
|
|
|
}
|
|
|
|
|
2016-03-24 13:17:17 +00:00
|
|
|
if (m_size + size >= m_capacity) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
BufferSubData(m_size, size, data);
|
|
|
|
|
2022-11-07 21:33:01 +00:00
|
|
|
m_size += (int)size;
|
2016-03-24 13:17:17 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VBO::Reset()
|
|
|
|
{
|
|
|
|
m_size = 0;
|
|
|
|
}
|
|
|
|
|
2016-03-21 04:10:14 +00:00
|
|
|
void VBO::Destroy()
|
|
|
|
{
|
|
|
|
if (m_id) {
|
|
|
|
glDeleteBuffers(1, &m_id);
|
2016-03-24 13:17:17 +00:00
|
|
|
m_id = 0;
|
|
|
|
m_target = 0;
|
|
|
|
m_capacity = 0;
|
|
|
|
m_size = 0;
|
2016-03-21 04:10:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VBO::Bind(bool enable)
|
|
|
|
{
|
|
|
|
if (enable) {
|
|
|
|
glBindBuffer(m_target, m_id);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
glBindBuffer(m_target, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-24 13:17:17 +00:00
|
|
|
int VBO::GetSize()
|
|
|
|
{
|
|
|
|
return m_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
int VBO::GetCapacity()
|
|
|
|
{
|
|
|
|
return m_capacity;
|
|
|
|
}
|