BuffersGL 3.0
glFlushMappedBufferRange
Tells OpenGL which bytes of a mapped buffer you wrote, when the mapping is not coherent.
Signature
void glFlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length);
How it works
Writing through a mapped pointer may sit in CPU caches where the GPU cannot see it. Two ways to make it visible: map with GL_MAP_COHERENT_BIT (automatic, sometimes a little slower), or map with GL_MAP_FLUSH_EXPLICIT_BIT and call this for exactly the bytes you changed. Flushing only the region you touched can be cheaper than keeping the whole buffer coherent.
Parameters
targetGLenum
Where the mapped buffer is bound.
offsetGLintptr
Start of the written bytes, relative to the start of the MAPPED range (not of the buffer).
lengthGLsizeiptr
How many bytes.
Tips & pitfalls
The DSA form is glFlushMappedNamedBufferRange(buffer, offset, length).
Errors
When the call is invalid it does nothing and sets an error, which glGetError returns:
- GL_INVALID_OPERATION
- The buffer is not mapped, or was not mapped with GL_MAP_FLUSH_EXPLICIT_BIT.
- GL_INVALID_VALUE
- The range goes outside the mapped range.
Example
example.cpp
1void *p = glMapBufferRange(GL_ARRAY_BUFFER, 0, size,
2 GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT);
3memcpy((char *)p + off, data, n);
4glFlushMappedBufferRange(GL_ARRAY_BUFFER, off, n);
5glUnmapBuffer(GL_ARRAY_BUFFER);