1

I write Android game that using OpenGL ES 2.0.
For example, a some game scene is drawing. How I can load another scene in background and when it loaded switch them. In background scene needs to load texture, generate their IDs and compile GL programs (shaders). But if I just create new Thread game crushes because game entities haven't access to GL context. And if I try to make it in GLSurfaceView.queueEvent get same error.
How I can do it? I found nothing by this theme.
P.S. Sorry for my English.

Denis Sologub
  • 7,277
  • 11
  • 56
  • 123

1 Answers1

2

My advice is to keep the texture generation on the main thread.

Just do the image loading on a different thread. Once the images are all loaded, notify the main thread, so that the main thread can do the actual creation of GL resources.

The file IO is probably slower than the actual gl texture creation anyway.

Also, for loading scenes, it pays to do the collision mesh generation on a helper thread, as that can be quite costly as well for large triangle meshes.

Bram
  • 7,440
  • 3
  • 52
  • 94
  • I just think that if I try to load bitmap into OpenGL in another thread it should not influence on base thread because it doesn't have conflicts with OpenGL drawing. Isn't it? – Denis Sologub Oct 12 '15 at 08:38
  • 1
    The glTexImage2d() call will require an OpenGL context. So do that on the main thread. Only do the file read and image decoding on another. – Bram Oct 12 '15 at 15:02
  • OK, I understood! Thank you! – Denis Sologub Oct 13 '15 at 20:15