Method to check if OpenGL is still active before using

Started by
41 comments, last by Halsafar 18 years, 2 months ago
I am under the assumption that OpenGL can loose it content at many of the same places a DirectX program would. So lets in this example assume the user done something (like alt+tab) which has caused OpenGL to be lost. All I am looking for here is a method within GL which can be called to ask if it's content has been lost. In DX it was practice to check each frame if D3D was still alive, if it wasn't hit a loop which would wait until it could acquire the cooperative level desired, when that loop was succesful you knew it was time to reload your textures, vertex buffers, etc. I want to accomplish a similar task in OpenGL so I can handle the situations where a user presses alt+tab or the SDL window looses focus and its time to re-init the game. Or have an alternative method. Since the above method mentioned has a big draw back, if the user alt+tabs in the middle of the rendering queue you may end up loosing GL in the middle of rendering. You cannot check if OpenGL is alive before every rendering related call to OpenGL...
Advertisement
This is a non-issue in OpenGL. You can never lose an OpenGL context unless you specifically destroy it (or its associated device context / window).

Some extension controlled resources can be invalidated by windows events such as display mode changes, but these are rare (pbuffers, VBO mapped memory lock). Appropriate query mechanisms are provided with the respective extensions to test for these possibilities. These resources are always very easy to reinit after the loss. You never have to reload textures, geometry or similar heavy resources in OpenGL, as they are non-volatile.
Really?
Period?

This is very interesting and good to hear.

However I have contridicting readings:
http://osdl.sourceforge.net/OSDL/OSDL-0.3/src/doc/web/main/documentation/rendering/SDL-openGL.html#resolution

From the page:
"
Under certain circumstances, the loaded textures, geometry or other OpenGL data are lost

On some platforms (ex : Windows), various events (going to fullscreen, switching to another application, etc.) lead to loosing the OpenGL context. For example, you may loose OpenGL textures and/or other OpenGL state data as a result of reopening the OpenGL context. Also, certain backends can loose hardware surfaces at any time, because the operating system steals the VRAM back whenever it wants to. It happens usually when the user switches to another application.

The only work-around is to reload the OpenGL context whenever it gets lost.
"


I do believe this is because as the page says, whenever SDL_SetVideoMode is called the GL Context is destroyed. In that case, I must re-init correct?
Quote:Original post by Halsafar
Under certain circumstances, the loaded textures, geometry or other OpenGL data are lost

On some platforms (ex : Windows), various events (going to fullscreen, switching to another application, etc.) lead to loosing the OpenGL context. For example, you may loose OpenGL textures and/or other OpenGL state data as a result of reopening the OpenGL context. Also, certain backends can loose hardware surfaces at any time, because the operating system steals the VRAM back whenever it wants to. It happens usually when the user switches to another application.

The only work-around is to reload the OpenGL context whenever it gets lost.


when you change resolution in SDL, it destroys and recreates the openGL context.

they are considering adding some type of SDL_Event to alert you to when this has occured, but at the minute its safer to recall your openGL setup and texture loading every resize/resolution change
Quote:Original post by Halsafar
Really?
Period?

Yes, period. Which is a very convenient thing.

Quote:Original post by Halsafar
However I have contridicting readings:
http://osdl.sourceforge.net/OSDL/OSDL-0.3/src/doc/web/main/documentation/rendering/SDL-openGL.html#resolution

This is not an OpenGL problem, but a major SDL design flaw. Use your own window management functions instead of SDLs to solve the problem.
Sorry got to stick with SDL.

So whats my solution here, how can I tell via SDL when its focus has been lost.
Obviously if I'm in fullscreen SDL/GL window and someone Alt+tabs then I'm going to have to reload everything. So is there an SDL event I can catch? Or should I post in the SDL forum...
Quote:Original post by Halsafar
So whats my solution here, how can I tell via SDL when its focus has been lost.
Obviously if I'm in fullscreen SDL/GL window and someone Alt+tabs then I'm going to have to reload everything. So is there an SDL event I can catch? Or should I post in the SDL forum...


No, you dont, aside from the possible loss of a pbuffers the gfx card drive manages everything which you send it, thus textures, VBOs and FBOs are still alive and will be uploaded again once they are needed.

To repeat : You will not lose the context nor any driver managed resources until you destroy the context.
I'm skeptical :)

But I'll go along with that idea.
Sure saves me some traps in my design.
Okay I do not believe it.

I took a sample app I found on the net which just shows a rotating cube in fullscreen. Nothing more, super simple, SDL/GL.

Alt+tabbed out of it, tried to go back in, sure worked okay but the cube was gone. I assume GL needs to be reinitialized, so does anything related to it.
Quote:Original post by Halsafar
Okay I do not believe it.

I took a sample app I found on the net which just shows a rotating cube in fullscreen. Nothing more, super simple, SDL/GL.

Alt+tabbed out of it, tried to go back in, sure worked okay but the cube was gone. I assume GL needs to be reinitialized, so does anything related to it.

.. as has been already pointed out, SDL does not handle it well. Just pure OpenGL does. Try any program/game that doesn't use SDL.


This topic is closed to new replies.

Advertisement