Safe usage of glMapBufferRange() on Android/Java

后端 未结 1 432
甜味超标
甜味超标 2021-01-17 08:28

I have working code using glMapBufferRange() from OpenGL-ES 3.0 on Android that looks like this:

  glBindBuffer(GL_ARRAY_BUFFER, myVertexBufferN         


        
1条回答
  •  时光取名叫无心
    2021-01-17 09:05

    As you already found, the documentation is lacking. But there is still a fairly conclusive reference: The implementation of the OpenGL Java bindings is part of the public Android source code.

    If you look at the implementation of the JNI wrapper for glMapBufferRange(), which is in the file glMapBufferRange.cpp, you can see that the buffer is allocated by calling a function named NewDirectByteBuffer(). Based on this, it seems safe to assume that the buffer is indeed a ByteBuffer.

    While vendors can change the Android code, it seems very unlikely that anybody would change the behavior of the Java bindings (except maybe to fix bugs). If you are concerned that the implementation could change in later Android versions, you can certainly use a standard Java type check:

    Buffer buf = glMapBufferRange(...);
    ByteBuffer byteBuf = null;
    if (buf instanceof ByteBuffer) {
        byteBuf = (ByteBuffer)buf;
    }
    

    Or you could use more elaborate reflection, starting with calling getClass() on the returned buffer. The next question is of course what you do if the returned buffer is not a ByteBuffer. It's really the only type that makes sense to me.

    0 讨论(0)
提交回复
热议问题