OpenGL ES 2.0 Multithreading

Hi,

I have been trying to use OpenGL ES 2.0 to make a photo

viewing application. To optimize the code I’m changing the textures

loaded with the objects as the user scroll down. But image loading into

the texture takes some time and thus the effect is not good. To solve

the above problem I tried using multithreading with the following ways:
1.Create a separate context for the new thread and then share the resources(texture object) with the other context
2.Use multiple threads and a single context. Make the context current while executing gl commands in the threads.

But

wasn’t successful in either of them. So if anyone has tried similar

things with opengl earlier, could you please tell which of the above

ones would work and the things I need to pay attention to while doing

the same? Also would FBO’s and pbuffers be of any use in this case?

Thanks for any help.


In terms of getting your textures to load faster, threading won’t do you any good on a device without actual multi-core CPU.





Where it can help is keeping your user interface responsive even when your app is busy in some custom texture loading code, but that can be done without threading using basic idle processing and incremental approach to loading textures into memory.





FBOs and pbuffers won’t help either since they can be only used to generate texture content using OpenGL ES own rendering pipeline.


I’d suggest you try this:





Only interact with OGLES in your main thread, not from a worker thread. When you want to load a texture from disk/memory card, either a) use asynchronous IO, or b) have a second thread load the texture into memory (not directly into GL).





When the asynchronous IO or worker thread has finished (which may well be several frames later), use your main thread to load the texture into GL. Keeping all GL interaction in a single thread removes the need to call eglMakeCurrent().





Aaron.Aaron2009-11-25 16:38:56