Supermodel/Src/Graphics/New3D/VBO.cpp

81 lines
1.3 KiB
C++
Raw Permalink Normal View History

#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;
}
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;
m_capacity = (int)size;
2016-03-24 13:17:17 +00:00
m_size = 0;
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)
{
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);
m_size += (int)size;
2016-03-24 13:17:17 +00:00
return true;
}
void VBO::Reset()
{
m_size = 0;
}
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;
}
}
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;
}