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.
Asked
Active
Viewed 436 times
1

Denis Sologub
- 7,277
- 11
- 56
- 123
-
1Similar to http://stackoverflow.com/questions/24953805/about-opengles-and-texture-on-android. – Reto Koradi Sep 27 '15 at 06:37
-
I use OpenGL ES 2.0. Is it compatible with EGL1.4? – Denis Sologub Sep 28 '15 at 01:55
-
I was not able to create secondary OpenGL context in java. It seems that this is only available in native library interfaces. – Denis Sologub Sep 28 '15 at 03:51
-
1It works from Java as well as native code. My answer here has complete code for creating contexts from Java: http://stackoverflow.com/questions/26985858/gles10-glgetintegerv-returns-0-in-lollipop-only. – Reto Koradi Sep 28 '15 at 04:02
-
EGL14 was added in API v17 only – Denis Sologub Sep 28 '15 at 04:08
-
1Yes. But that's pretty far back. It covers about 80% of devices currently in use. If you need something that works with older devices, the answer I linked also has code using EGL10. – Reto Koradi Sep 28 '15 at 04:55
-
But I cannot write: EGL10 egl = (EGL10)EGLContext.getEGL(); It was marked like error. – Denis Sologub Sep 28 '15 at 05:00
-
Oh, I try to use android package... It works! Thank you! – Denis Sologub Sep 28 '15 at 05:18
1 Answers
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
-
1The 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
-