AWT thread question

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

AWT thread question

Kain16
Hello,

i want to load resources with an “offscreen drawable”, meanwhile on EDT i use a “ProgressPanel” to display a “progessbar”.(Later iwant to use the Contex of this “offscreen drawable” as a shared context for other “onscreen drawables” )
My  problem is that the GLEventListener is processed on AWT thread, what blocks “progressbar” animation itself.
Is it possible to put GLEventListener to another Thread?
If yes then could You provide me a simple example, how to do it.

Balazs
Reply | Threaded
Open this post in threaded view
|

Re: AWT thread question

gouessej
Administrator
Hi

Actually, you should separate the operations that absolutely must be done on the EDT with a current OpenGL context from the others. Moreover, you don't need to make the OpenGL context current on the EDT when you use your offscreen drawable, you can choose another thread. You can use a Swing Worker and call setProgress or something similar from another thread (not the EDT).

Finally, you can split your whole job into smaller tasks and execute each task one by one. This is what I do in my game and in my editor. It allows me to block my (non AWT) progress bar only during the execution of each task and I can update it before starting the execution of another task.

Good luck.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: AWT thread question

Kain16
Hi,

Thanks for the reply.
I made a small example.

At a JButton's action:

SwingWorker<Void, Void> sw = new SwingWorker<Void, Void>() {
        @Override
        protected Void doInBackground() throws Exception {
                rManager.changeEnvMap(); //  call display of my "offscreen drawable"(rManage)
                return null;
        }
};
sw.execute();

For my test i have two GLJPanel with shared context which are displaying a box and a sphere with environment mapping and a button for call code above. If  i use the button and check which thread is processing my display for "offscreen drawable" than i got "SwingWorker-pool...".

And it works :).

Is this so simple ? Does "Jogl" manage all the current thread / context switching?

Balazs
 
Reply | Threaded
Open this post in threaded view
|

Re: AWT thread question

gouessej
Administrator
When you call offscreenDrawable.display(), JOGL manages the context switching for you. Now you know better why you have chosen JOGL, it eases numerous operations but it's flexible, it's not in your way when you need to do everything by yourself :)
Julien Gouesse | Personal blog | Website