Login  Register

Re: moving GLPanel from one to other AWT container

Posted by Sven Gothel on Mar 24, 2011; 12:11am
URL: https://forum.jogamp.org/moving-GLPanel-from-one-to-other-AWT-container-tp2722179p2723111.html

On Wednesday, March 23, 2011 21:48:23 Ondrej [via jogamp] wrote:
>
> Is it good idea to remove GLPanel from one AWT container and add it other
> container? It would be useful in our application design but we could find
> alternative if you guys don't recommend it. I tried to add existing instance
> of GLPanel to other AWT container (JPanel) . First dispose and then init
> method (GLEventListener) were called. The GLAutoDrawable instance stays the
> same but getContext() method returns different instance. This must be the
> reason why all textures and probably all other resources allocated under the
> first context (before moving GLPanel) are lost.

correct analysis ..

you may utilize a 'parent' shared context
holding your resources (textures ..).

then you can create your GLCanvas one passing he shared one.

we have to call dispose on removeNotify(), since this is the only chance
to release the GL stuff before passing the 'signal' to super,
which frees the native peer.

You could also use NewtCanvasAWT (see junit tests),
where a removeNotify() only reparents the NEWT window (child -> top window).
This is demonstrated in the many unit tests.

~Sven