- replaced IUniformBuffer with IDataBuffer, which reuses the code for the other buffer types and is more flexible.

This commit is contained in:
Christoph Oelckers 2018-10-28 11:54:26 +01:00
commit a1fb1f60f4
13 changed files with 74 additions and 147 deletions

View file

@ -122,6 +122,32 @@ void GLBuffer::Unlock()
gl_RenderState.ResetVertexBuffer();
}
void GLBuffer::Resize(size_t newsize)
{
assert(!nomap); // only mappable buffers can be resized.
if (newsize > buffersize && !nomap)
{
// reallocate the buffer with twice the size
unsigned int oldbuffer = mBufferId;
// first unmap the old buffer
Bind();
glUnmapBuffer(mUseType);
glGenBuffers(1, &mBufferId);
SetData(newsize, nullptr, false);
glBindBuffer(GL_COPY_READ_BUFFER, oldbuffer);
// copy contents and delete the old buffer.
glCopyBufferSubData(GL_COPY_READ_BUFFER, mUseType, 0, 0, buffersize);
glBindBuffer(GL_COPY_READ_BUFFER, 0);
glDeleteBuffers(1, &oldbuffer);
buffersize = newsize;
gl_RenderState.ResetVertexBuffer();
}
}
//===========================================================================
//
// Vertex buffer implementation
@ -171,3 +197,13 @@ void GLVertexBuffer::Bind(int *offsets)
}
}
void GLDataBuffer::BindRange(size_t start, size_t length)
{
if (mUseType == GL_UNIFORM_BUFFER) // SSBO's cannot be rebound.
glBindBufferRange(mUseType, mBindingPoint, mBufferId, start, length);
}
void GLDataBuffer::BindBase()
{
glBindBufferBase(mUseType, mBindingPoint, mBufferId);
}