Java Buffers and OpenGL ES 2.0 (Android)

| | August 5, 2015

I’ve been trying to come up with a good solution for preloading textures asynchronously, but in Android with OpenGL ES you cannot create a texture out of context.

Would the proper solution be to load up a ByteBuffer with data from my png image, then when I’m back on the render thread call glTexImage2D? What I don’t understand is whether or not OpenGL will actually copy the buffer into it’s own location, or directly access mine. The latter approach would be ideal.

Could anyone give me clarification?

One Response to “Java Buffers and OpenGL ES 2.0 (Android)”

  1. Would the proper solution be to load up a ByteBuffer with data from my
    png image, then when I’m back on the render thread call glTexImage2D?
    What I don’t understand is whether or not OpenGL will actually copy
    the buffer into it’s own location, or directly access mine. The latter
    approach would be ideal.

    This is basically what you want to do. Load the texture data from a worker thread, and once the load is complete construct the OpenGL texture resource (from that data) on the main/render thread.

    Once you call glTexImage2D, you don’t need to keep your copy of the texture data in-memory any longer (you can delete it) unless you need it for some other purpose. OpenGL will copy the data it needs elsewhere.

Leave a Reply