LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: CuppoJava on February 18, 2008, 15:41:45

Title: Multi-Threaded Loading and Drawing?
Post by: CuppoJava on February 18, 2008, 15:41:45
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
Title: Re: Multi-Threaded Loading and Drawing?
Post by: oNyx on February 18, 2008, 15:56:54
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.
Title: Re: Multi-Threaded Loading and Drawing?
Post by: VeAr on February 19, 2008, 07:26:28
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?
Title: Re: Multi-Threaded Loading and Drawing?
Post by: the2bears on February 22, 2008, 07:18:41
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
Title: Re: Multi-Threaded Loading and Drawing?
Post by: princec on February 22, 2008, 13:26:48
You need to explicity share textures between contexts. See this FAQ (http://www.opengl.org/resources/faq/technical/texture.htm):
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 (http://www.opengl.org/resources/faq/technical/displaylist.htm#0020) can. If you're using Microsoft Windows, see the wglShareLists() function. For a GLX platform, see the share parameter to glXCreateContext().

Cas :)
Title: Re: Multi-Threaded Loading and Drawing?
Post by: vladl on April 10, 2008, 19:27:47
Quote from: princec on February 22, 2008, 13:26:48
You need to explicity share textures between contexts. See this FAQ (http://www.opengl.org/resources/faq/technical/texture.htm):
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 (http://www.opengl.org/resources/faq/technical/displaylist.htm#0020) 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