caching GL objects

Hi!

In TUER, I store a reference to the first GL I get from the canvas and I use it everywhere instead of doing GL gl=glCanvas.getGL(). But I read that in the documentation:

[quote]Users should not rely on the identity of the returned GL object; for example, users should not maintain a hash table with the GL object as the key. Additionally, the GL object should not be cached in client code, but should be re-fetched from the GLAutoDrawable at the beginning of each call to init, display, etc.
[/quote]
Can my bad practice have any impact on the performance?

Hi!

how about to use not GL gl=glCanvas.getGL() in everywhere
and use next construction:


public void yourDefinedMethod(){
   GL gl = GLU.getCurrentGL();
   ...
}

you can take GL from thread, where was created canvas…

Good idea. But I’m going to check if GL is really changing during the execution of the game to be sure such a modification is required.

If the underlying context is destroyed, then the GL will be invalidated (and cause a crash if you try to use it). On reliable systems this happens with a GLCanvas when it is removed and re-added to a JFrame. On a GLJPanel, I’ve heard rumors this happens when it is resized (but I’m not sure).

A better approach, is to pass the GL around in the methods that need it, or to keep the GLContext object (which will never change) and call getGL() on it inside each method.

Now I fetch the GL instance where I need it and it works fine. Thank you for your precisions.