Sharing textures between multiple OpenGL contexts

Hi,

I have two frames with their own GLCanvas and own animator thread. Is there any way to share a texture between both through clean jogl api usage? I want to avoid to uploading the same (large) texture two times…

Thanks,
Regards,
Ralf

Another multiple frames problem: when I sleep in one of the gleventlisteneres (running in his own animator thread) via Thread.sleep(), the other OpenGL window gets affected by this. Why does this happen - is drawing to different glcanvases synchronized somehow so that one glcanvas gets only rendered when the other is ready too? Is there some way to get rid of this behaviour (I have windows that are more important than others…)?

I am not an expert, but as far as I know, you should use one thread for all your OpenGL drawing. I wrote my own animator class that holds a vector of GLCanvasses that should be redrawn. The animator triggers all registered canvasses so that they all redraw. This work perfectly for me.

The problem with uploading the same texture more than once can be fixed by creating a invisible frame (just do not show it) and put a GLCanvas on it. This GLCanvas serves as the parent for all other canvasses. When creating textures and displaylists create them using the parent canvas, and all child canvasses can use the display lists and textures.

Maybe this is not the best way to fix it, but it works for me.

Sharing of textures and display lists between OpenGL contexts is supported in JOGL. See GLDrawableFactory.createGLCanvas(GLCapabilities capabilities, GLCapabilitiesChooser chooser, GLDrawable shareWith), and the demos.testContextSharing.TestContextSharing demo in the jogl-demos workspace.

Without seeing how your application is structured it’s hard to know why one canvas would be blocked while the other is sleeping, but if you put each canvas in its own animation thread there shouldn’t be any interference between them. The only synchronization built in to the JOGL library revolves around ensuring that a given context is current on only one thread at any given time.