I have working code using glMapBufferRange()
from OpenGL-ES 3.0 on Android that looks like this:
glBindBuffer(GL_ARRAY_BUFFER, myVertexBufferName);
glBufferData(GL_ARRAY_BUFFER, myVertexBufferSize, null, GL_STATIC_DRAW);
ByteBuffer mappedBuffer = (ByteBuffer)glMapBufferRange(
GL_ARRAY_BUFFER,
0, myVertexBufferSize,
GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);
// [fill buffer...]
glUnmapBuffer(GL_ARRAY_BUFFER);
My question is about downcasting the result of glMapBufferRange()
to ByteBuffer
on the third line. glMapBufferRange()
is declared to return a Buffer
:
public static Buffer glMapBufferRange (int target, int offset, int length, int access)
On my test platform the function returns a subclass of ByteBuffer
so the cast works, but making this assumption for all platforms or Android versions supporting OpenGL-ES 3+ doesn't seem very safe. Although it seems reasonable, I haven't found any documentation that guarantees it, and if it were guaranteed it seems like the function should be declared as returning ByteBuffer
.
What is the correct way (preferably supported by documentation) of using the Buffer
returned by glMapBufferRange()
?