Any way to create glGenList on a background thread?

I have been developing some Swing/jogl application. The Swing part uses SwingApplicationFramework.
Main function of the app is drawing fractals. It is done by some recurent function that draw lines:
gl.glNewList(genlist, gl.GL_COMPILE);
gl.glBegin(GL.GL_LINES);
draw fancy lines
gl.glEnd();
gl.glEndList();

Is there any possible way to do it on background thread? This would really help. If someone cranks up
resolution too much and it it runs on background there would be a nice and clean way to cancel it. At this
time my application hangs. :smiley:
To help You better understand the problem, here is the recent snapshot: http://maciek.t4.ds.pwr.wroc.pl/dist/launch.jnlp
And here’s whole project: ftp://maciek.t4.ds.pwr.wroc.pl/pub/NetBeansProjects/Fractals/src

Thanks in advance.

Try running your app with “-Dopengl.1thread=worker” in the VM args. This should decouple the rendering completely from the GUI thread, but might lead to other problems with some platforms/drivers.

Thanks for a very quick response. I did as You told. The result was quite surprising. The glCanvas’ background went black
(grey before) and stopped responding for mouse pan&zoom action. It’ll take me some time to investigate it.
The whole jogl project is really supreme. I’m a beginner and would really like to master it.
Meanwhile another question arose. Is there any other way I can access glContext at any time, outside GLEventListener
methods?

Sorry to hear that the worker thread is not working for you. There were some stability problems before and maybe it is not tested anymore when the implementation changes. Did you use a GLCanvas or a GLJPanel? The GLJPanel might not work because it need back copying of the gl framebuffer to the swing surface. You could try again with a GLCanvas.

Calling gl commands outside of the GLEventListener is not encouraged. You will probably shoot yourself in the foot spend more time debugging and researching odd behaviour on some platforms/drivers than creating your application. There is however a “makeCurrent()” method in GLContext [http://download.java.net/media/jogl/builds/nightly/javadoc_public/javax/media/opengl/GLContext.html#makeCurrent()], but I can’t help you with that, since I never used it…

Oh, I’m quite sure the worker thread doesn’t work because of my code since I made few experiments and lost track of some. Fortunately it runs pretty well on decent subdivisions.
From the beginning I was using GLCanvas. I heard about some issues with the GLPanel so I started with Canvas instead.
My first attempts on makeCurrent: GLContext.makeCurrent() keeps returning GLContext.CONTEXT_NOT_CURRENT. Looking into it now.

As a workaround I implemented simple flag. Outside code sets the flag and calls repaint(). The draw method gets the context from argument and uses it to update the genlist. Right after that beautiful fractal pops out. Works good, but long generation frozes gui. At this time I’ve no idea how to solve it. I think this issue shows interesting direction to which JOGL api could be expanded.

I really apreciate Your attention Cylab. Thanks!

Ok, I owe You one.

I rebuilt the gui - old one was calling panel containing GLCanvas and that was the frozing part. The switch -Dopengl.1thread=worker finally worked for me. Just to be sure I remove any Canvas listeners (correct me if it’s not necessary) and right after that draw lines in while(!isCanceled) loop. Cancel button sets isCancel to true. After comilation I reset the listeners. So finally user can cancel genlist creation.

Cheers.