mirror of https://github.com/axmolengine/axmol.git
58 lines
1.2 KiB
C++
58 lines
1.2 KiB
C++
|
#include "BufferGL.h"
|
||
|
#include <cassert>
|
||
|
|
||
|
CC_BACKEND_BEGIN
|
||
|
|
||
|
BufferGL::BufferGL(unsigned int size, BufferType type, BufferUsage usage)
|
||
|
: Buffer(size, type, usage)
|
||
|
{
|
||
|
glGenBuffers(1, &_buffer);
|
||
|
}
|
||
|
|
||
|
BufferGL::~BufferGL()
|
||
|
{
|
||
|
if (_buffer)
|
||
|
glDeleteBuffers(1, &_buffer);
|
||
|
}
|
||
|
|
||
|
void BufferGL::updateData(void* data, unsigned int size)
|
||
|
{
|
||
|
assert(size);
|
||
|
|
||
|
if (_buffer)
|
||
|
{
|
||
|
if (BufferType::VERTEX == _type)
|
||
|
{
|
||
|
glBindBuffer(GL_ARRAY_BUFFER, _buffer);
|
||
|
glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffer);
|
||
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, data, GL_STATIC_DRAW);
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void BufferGL::updateSubData(void* data, unsigned int offset, unsigned int size)
|
||
|
{
|
||
|
assert(offset + size <= _size);
|
||
|
|
||
|
if (_buffer)
|
||
|
{
|
||
|
if (BufferType::VERTEX == _type)
|
||
|
{
|
||
|
glBindBuffer(GL_ARRAY_BUFFER, _buffer);
|
||
|
glBufferSubData(GL_ARRAY_BUFFER, offset, size, data);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffer);
|
||
|
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, offset, size, data);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
CC_BACKEND_END
|