Stability of a GLContext object

Hello there,

in a small application I’m working on, there are a lot of objects that are tied to a certain OpenGL context (i.e. they rely on textures and OpenGL state previously established on this particular context). While the docs clearly state that it is unsafe to cache GL-objects, I just wanted to ask whether this also applies to GLContext-objects.

Is it safe to store a reference to a specific GLContext in order to make it current or to check whether the current context is the right one for a specific object? If an OpenGL context is re-created because of the removal of a GLCanvas from it’s containment hierarchy, will the GLContext-reference returned by GLCanvas.getContext() be the same (==) as it was before the removal?

Thanks in advance for your answers.
Best regards,
Ingomar

The GLContext object will remain the same across multiple low-level OpenGL context creations and destructions, so yes, you can use it as a key in caches, but you still need to be very careful and clear those caches each time you receive a call to GLEventListener.init() (if you aren’t sharing textures and display lists between contexts in your application in a way that makes the caches persistent across creations and destructions of that context).

Thank you for the short, yet comprehensive answer.