Move VBO buffer allocation out of allocate() and into BindVBO()

fixes #256
This commit is contained in:
manuelk 2014-01-30 17:29:14 -08:00
parent 0ba68c00bd
commit ec98c7fe03

View File

@ -39,7 +39,10 @@ OsdCpuGLVertexBuffer::OsdCpuGLVertexBuffer(int numElements, int numVertices)
OsdCpuGLVertexBuffer::~OsdCpuGLVertexBuffer() {
delete[] _cpuBuffer;
glDeleteBuffers(1, &_vbo);
if (_vbo) {
glDeleteBuffers(1, &_vbo);
}
}
OsdCpuGLVertexBuffer *
@ -72,17 +75,23 @@ OsdCpuGLVertexBuffer::GetNumVertices() const {
float*
OsdCpuGLVertexBuffer::BindCpuBuffer() {
_dataDirty = true; // caller might modify data
return _cpuBuffer;
}
GLuint
OsdCpuGLVertexBuffer::BindVBO() {
if (not _dataDirty)
return _vbo;
int size = GetNumElements() * GetNumVertices() * sizeof(float);
if (not _vbo) {
glGenBuffers(1, &_vbo);
}
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, size, _cpuBuffer, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
@ -93,15 +102,9 @@ OsdCpuGLVertexBuffer::BindVBO() {
bool
OsdCpuGLVertexBuffer::allocate() {
_cpuBuffer = new float[GetNumElements() * GetNumVertices()];
_dataDirty = true;
int size = GetNumElements() * GetNumVertices() * sizeof(float);
glGenBuffers(1, &_vbo);
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, size, 0, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
return true;
}