1

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.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • 1
    "*I can't seem to find GL_MAP_PERSISTENT_BIT anwhere, e.g. in GLES31 or GLES31Ext*" What are you looking in where you cannot find them? Also, they would have the `_EXT` suffix. – Nicol Bolas May 09 '21 at 17:07
  • @NicolBolas In Android Studio, e.g., if I type `GLES30.` or `GLES31.` or `GLES31Ext.` the intelli sense does not show up `GL_MAP_PERSISTENT_BIT` (with or without `EXT` on the end) –  May 09 '21 at 17:26
  • I found this (https://developer.android.com/reference/android/opengl/GLES31Ext) and the tokens I would expect to find just aren't there, so as a previous comment mentioned (which has since been deleted) the functionality I require might not actually be available. It was a bit confusing because `glGetString` returns that the extension is supported, but I guess it's just not supported yet by Google's extension API's. So I will stick to my current use of `glMapBufferRange` as described above and hope that Vulkan provides better support when I make the switch later on. –  May 09 '21 at 19:00
  • @Pixel The value of `MAP_PERSISTENT_BIT_EXT` is _0x0040_. If [EXT_buffer_storage](https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_buffer_storage.txt) is supported by your hardware, you can define the value yourself. – Rabbid76 May 09 '21 at 19:07
  • 1
    @Rabbid76 I think this goes back to my original problem. I can make my own flag for `0x0040` but according to the docs I need to use `glBufferStorage` to allocate my buffer to use that flag instead of `glBufferData`. But I can't seem to find a way to access `glBufferStorage` via the `EXT_buffer_storage` extension. I don't know how to find/use `glBufferStorage` - it doesn't seem accessible in any way from Android. –  May 09 '21 at 20:14
  • As pointed out in a comment [here](https://stackoverflow.com/questions/51245319/minimal-working-example-of-compute-shader-for-open-gl-es-3-1/51249789?noredirect=1#comment119240771_51249789) (since deleted) it turns out `glBufferStorage` isn't available in OpenGL ES so unfortunately it doesn't seem possible to use `MAP_PERSISTENT_BIT` anyway, at least officially. That's really confusing because Android reports `EXT_storage_buffer` as an available extension. –  May 10 '21 at 07:21

1 Answers1

3

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().

solidpixel
  • 10,688
  • 1
  • 20
  • 33