GL Context Handling

Hi *,

i am currently redesigning my renderengine and wondering about the OpenGL context handling. If i have several displaylists and VBOs, do they get invalid, if i, e.g. change into fullscreen mode (does that work with java 1.6 ?). Or, more generic, can the GL object or the GLContext object get invalid? and when yes, in which situations does that event occur?

Can the javadoc made more specific regarding this topic?

thx in advance,
funsheep

Assuming there is no sharing of display lists between multiple contexts in your application, when your GLEventListener.init() method is called, you need to re-create them. That is the callback sent when a new OpenGL context is created. Depending on how the JDK implements full-screen support you may or may not have to reinitialize these objects. Fundamentally you should just structure your application to watch for calls to init() and perform your display list initialization there.

Note that if you have sharing of display lists in place then the rules change. OpenGL specifies a reference counting mechanism for these server-side objects. If you have a second persistent context sharing with the first, then the when the first is destroyed and re-created the lists will still be alive since the second one kept them alive.

As it happens the GL object is also supposed to be discarded when init() is called. Internally to the library a new one is created for the GLContext each time it is re-initialized. You can either pass the GL object down your call chain or call GLU.getCurrentGL() each time you need access to it. The GLContext object is persistent and is a container for the real OpenGL context which may or may not be created at the current time, depending on whether the window is visible.