Multi-Threaded Loading and Drawing?

Started by CuppoJava, February 18, 2008, 15:41:45

Previous topic - Next topic

CuppoJava

Hi,
Is there any way to do texture loading on a separate thread as your game drawing thread? As I understand it so far, all openGL commands must be called from the same thread.

for example, how would you implement an animated loading screen? I originally thought to use one thread for drawing the animation, and one thread for loading all the textures, but openGL must be called from one thread so that doesn't work.

Thanks for your suggestions
  -Cuppo

oNyx

The loading can be done on another thread. The uploading, however, cannot. (So, you have to hand over the data to the main thread.)

Well, there is also a simple solution: update the progressbar whenever you finished loading one piece. Most people won't care if that status is only updated once a second.

VeAr

This is an interesting topic. I've tried loading textures in a backgroud thread, by creating another OpenGL context for that thread. It does work on my mashine (ATI/windows). Have someone information, is this feature (more GL contexts for a single app) supported on other hardware/OS?

the2bears

I've been unable to load textures in a different thread as well.  I'm creating an OSGi game engine, with the game loop as a service.  Each service gets loaded in its own thread and I inadvertently put a texture load in a constructor... that got called outside of the game loop.  No texture until I fixed that :)  ATI here as well.

Bill
the2bears - the indie shmup blog

princec

You need to explicity share textures between contexts. See this FAQ:
Quote
21.080 Can I share textures between different rendering contexts?

Yes, if you use texture objects. Texture objects can be shared the same way display lists can. If you're using Microsoft Windows, see the wglShareLists() function. For a GLX platform, see the share parameter to glXCreateContext().

Cas :)

vladl

Quote from: princec on February 22, 2008, 13:26:48
You need to explicity share textures between contexts. See this FAQ:
Quote
21.080 Can I share textures between different rendering contexts?

Yes, if you use texture objects. Texture objects can be shared the same way display lists can. If you're using Microsoft Windows, see the wglShareLists() function. For a GLX platform, see the share parameter to glXCreateContext().

Cas :)

Can you put some example code? I can't found any of this functions in the javadoc of lwjgl.
Thanks