Search code examples
androidopengl-esopengl-extensions

How do I use GL_MAP_PERSISTENT_BIT in OpenGL ES 3.1 on Android?


I recently switched from using glBufferData to glMapBufferRange which gives me direct access to GPU memory rather than copying the data from CPU to GPU every frame.

This works just fine and in OpenGL ES 3.0 I do the following per frame:

  • Get a pointer to my GPU buffer memory via glMapBufferRange.
  • Directly update my buffer using this pointer.
  • Use glUnmapBuffer to unmap the buffer so that I can render.

But some Android devices may have at least OpenGL ES 3.1 and, as I understand it, may also have the EXT_buffer_storage extension (please correct me if that's the wrong extension ?). Using this extension it's possible to set up persistent buffer pointers which do not require mapping/unmapping every frame using the GL_MAP_PERSISTENT_BIT flag. But I can't figure out or find much online in the way of how to access these features.

How exactly do I invoke glMapBufferRange with GL_MAP_PERSISTENT_BIT set in OpenGL ES 3.1 on Android ?

Examining glGetString(GL_EXTENSIONS) does seem to show the extension is present on my device, but I can't seem to find GL_MAP_PERSISTENT_BIT anwhere, e.g. in GLES31 or GLES31Ext, and I'm just not sure how to proceed.


Solution

  • The standard Android Java bindings for OpenGL ES only expose extensions that are guaranteed to be supported by all implementations on Android. If you want to expose less universally available vendor extensions you'll need to roll your own JNI bindings, using eglGetProcAddress() from native code compiled with the NDK to fetch the entry points.

    For this one you want the extension entry point glBufferStorageEXT().