BuffersGL 3.1
glCopyBufferSubData
Copies bytes from one buffer to another on the GPU.
Signature
void glCopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
How it works
The data never passes through the CPU. The two buffers are named by the targets they are bound to; because two buffers cannot share one target, OpenGL provides GL_COPY_READ_BUFFER and GL_COPY_WRITE_BUFFER, which exist only for copies and never disturb the bindings your draws use.
Typical uses: growing a buffer while keeping its contents, duplicating a mesh, and moving data from a staging buffer into its final place.
Parameters
readTargetGLenum
Slot of the source buffer (usually GL_COPY_READ_BUFFER).
writeTargetGLenum
Slot of the destination buffer (usually GL_COPY_WRITE_BUFFER).
readOffsetGLintptr
First byte to read.
writeOffsetGLintptr
First byte to write.
sizeGLsizeiptr
Number of bytes to copy.
Errors
When the call is invalid it does nothing and sets an error, which glGetError returns:
- GL_INVALID_VALUE
- A range goes past the end of its buffer, or source and destination overlap within the same buffer.
- GL_INVALID_OPERATION
- No buffer is bound to one of the targets, or one of them is mapped.
Example
example.cpp
1glBindBuffer(GL_COPY_READ_BUFFER, oldVbo);
2glBindBuffer(GL_COPY_WRITE_BUFFER, biggerVbo);
3glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, 0, 0, oldSize);