Thread: [Plib-users] Threads and textures
Brought to you by:
sjbaker
From: Tinoshi K. <ti...@li...> - 2006-01-11 20:14:52
|
Hi, I think I have got a problem related with OpenGL context and threads... = I'm loading my database in a secondary thread, and textures are not = loaded!!! if i print(stdout," ",3) the Leaf i load, textures handles are = always set to 0, while geometry (vertex) are correctly drawn. If I load = the database in the main thread, textures are loaded!=20 I tryed to pass to the thread the ssgGetCurrentContext() and to = makeCurrent() just inside the thread function, but I doesn't work... = What can I do??? Thanks!!! P.S. OS is WindowsXP, I use Visual Studio 6.0 |
From: Curtis L. O. <cur...@fl...> - 2006-01-11 20:27:51
|
Tinoshi Kitazawa wrote: > I think I have got a problem related with OpenGL context and > threads... I'm loading my database in a secondary thread, and textures > are not loaded!!! if i print(stdout," ",3) the Leaf i load, textures > handles are always set to 0, while geometry (vertex) are correctly > drawn. If I load the database in the main thread, textures are loaded! > I tryed to pass to the thread the ssgGetCurrentContext() and to > makeCurrent() just inside the thread function, but I doesn't work... > What can I do??? > > Thanks!!! > > P.S. OS is WindowsXP, I use Visual Studio 6.0 I'm not an opengl guru, but we have the same issue with FlightGear. Basically opengl is not multithreaded. In other words, if you generate opengl calls from multiple threads, you can expect that the calls will be interleaved in unpredictable ways and cause all kinds of strange behavior and problems. The fact that your program actually survived this without crashing is actually a bit surprising! :-) For flightgear, we only load geometry from a thread. Most of our textures we preload. If we have to load some new model on the fly, we queue that up and load it in the main thread (taking the corresponding performance hit) because loading an arbitrary model can trigger loading of textures. And the thought of rewriting all the plib model loaders to separate geometry vs. texture loading was a bit more than I wanted to consider. Also, you need to be careful with your scene graph. You don't want to be changing it in one thread while another thread is trying to cull and draw it. That can also cause unpredictable problems and crashes. What we do with FlightGear is load new geometry into an orphan tree in our 2nd thread, then throw the pointer to the tree on a queue some place. The main thread checks this queue every frame and if there is any thing in there, it connects it into the main scene graph before the cullanddraw phase. We do something similar when removing things from our scene graph. The main thread disconnects it from the scene graph and throws a pointer onto a queue. Our tile paging thread looks for anything in the queue and deletes it. For what it's worth, you could generate opengl calls from multiple threads if you were extremely careful to use some sort of locking to ensure that the calls happened in a safe order. However, as soon as you do that, you then lose most/all the benefits of threading, so you might as well keep it simple (as possible) and do the model loading and texture loading in the main thread. Fun stuff ... :-) Curt. -- Curtis Olson http://www.flightgear.org/~curt HumanFIRST Program http://www.humanfirst.umn.edu/ FlightGear Project http://www.flightgear.org Unique text: 2f585eeea02e2c79d7b1d8c4963bae2d |
From: Paolo L. <p.l...@ci...> - 2006-01-12 12:23:23
|
> -----Messaggio originale----- > Da: pli...@li...=20 > [mailto:pli...@li...] Per conto di=20 > Curtis L. Olson > Inviato: mercoled=EC 11 gennaio 2006 21.28 > A: pli...@li... > Oggetto: Re: [Plib-users] Threads and textures >=20 >=20 > Tinoshi Kitazawa wrote: >=20 > > I think I have got a problem related with OpenGL context and > > threads... I'm loading my database in a secondary thread,=20 > and textures=20 > > are not loaded!!! if i print(stdout," ",3) the Leaf i load,=20 > textures=20 > > handles are always set to 0, while geometry (vertex) are correctly=20 > > drawn. If I load the database in the main thread, textures=20 > are loaded! > > I tryed to pass to the thread the ssgGetCurrentContext() and to=20 > > makeCurrent() just inside the thread function, but I=20 > doesn't work...=20 > > What can I do??? > > =20 > > Thanks!!! > > =20 > > P.S. OS is WindowsXP, I use Visual Studio 6.0 >=20 >=20 > I'm not an opengl guru, but we have the same issue with FlightGear. =20 > Basically opengl is not multithreaded. In other words, if=20 > you generate=20 > opengl calls from multiple threads, you can expect that the=20 > calls will=20 > be interleaved in unpredictable ways and cause all kinds of strange=20 > behavior and problems. The fact that your program actually survived=20 > this without crashing is actually a bit surprising! :-) Loading/filling a SSG scene graph shouldn't involve OpenGL as far as = don't create display lists for leaf nodes - excepting textures, which, infact, seems to arise the problem. Greetings - Paolo Leoncini |
From: Paolo L. <p.l...@ci...> - 2006-01-12 11:10:00
|
I'm not sure this can help, but the wglShareLists function allows to = share texture and display lists between two OpenGL contexes. =20 So as last resource you could create a second, windowless context in the thread and sharing texture with the main one. =20 Greetings - =20 Paolo Leoncini =20 -----Messaggio originale----- Da: pli...@li... [mailto:pli...@li...] Per conto di Tinoshi Kitazawa Inviato: mercoled=EC 11 gennaio 2006 21.14 A: PLIB USERS Oggetto: [Plib-users] Threads and textures Hi, =20 I think I have got a problem related with OpenGL context and threads... = I'm loading my database in a secondary thread, and textures are not = loaded!!! if i print(stdout," ",3) the Leaf i load, textures handles are always set = to 0, while geometry (vertex) are correctly drawn. If I load the database in = the main thread, textures are loaded!=20 I tryed to pass to the thread the ssgGetCurrentContext() and to makeCurrent() just inside the thread function, but I doesn't work... = What can I do??? =20 Thanks!!! =20 P.S. OS is WindowsXP, I use Visual Studio 6.0=20 |
From: Tinoshi K. <ti...@li...> - 2006-01-16 07:47:04
|
Messaggio Thanks for the answers!!! Now I preload textures and everything seems to work... |