【GLES】How to choose parameters for glMapBufferRange

I want to use glMapBufferRange to modify the contents of a sub-buffer, which may currently be in use by the GPU。

Which flags should be used for marking? Would GL_MAP_INVALIDATE_RANGE_BIT | GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_WRITE_BIT be appropriate?

Additionally, could you provide a more detailed explanation of the purpose of GL_MAP_INVALIDATE_RANGE_BIT?

Ref: registry.khronos.org/.../glMapBufferRange.xhtml

  • to modify the contents of a sub-buffer, which may currently be in use by the GPU

    Note that you can have concurrent use of the buffer, but cannot have concurrent use of the subrange within in by CPU and GPU - this is not allowed and is impossible to synchronize safely. 

    Which flags should be used for marking? Would GL_MAP_INVALIDATE_RANGE_BIT | GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_WRITE_BIT be appropriate?

    Yes. 

    could you provide a more detailed explanation of the purpose of GL_MAP_INVALIDATE_RANGE_BIT

    It's a hint to the implementation that you don't need to keep the existing content of that range, so could e.g. use a cache invalidate rather than a cache clean+invalidate on the range to make it coherent with the CPU. What it actually does is implementation-defined, and it may well be a no-op on some.

    HTH, 
    Pete