iDevGames Forums
Fullscreen/resolution switch causes texture loss - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Fullscreen/resolution switch causes texture loss (/thread-2766.html)



Fullscreen/resolution switch causes texture loss - IBethune - Feb 20, 2008 01:48 PM

I have found several references to this type of problem but can't quite get my head around the solution, so please go right back to basics in your explanations.

I'm using SDL to set up my OpenGL context, then I load some textures from disk with
Code:
glGenTextures()
glTexImage2D()
and all is working fine.

When I do a resolution switch, i.e. calling

Code:
SDL_SetVideoMode(width, height, 32, SDL_OPENGL | fs

then none of my textures draw any more, but all non-textured geometry is OK. My understandng of this is that some data (including textures) is bound to a particular OpenGL context, and SDL is destroying the context when I switch resolution. Also, if I switch back to a previous setting (e.g. toggle fullscreen and back again), then the texture data is gone completely.

So I guess I have several questions:

1) What is context-stored data i.e. what do I have to recreate when I switch contexts?
2) I have heard a bit about context sharing - is this possible with SDL and if so how would this work?

Cheers

- Iain


Fullscreen/resolution switch causes texture loss - OneSadCookie - Feb 20, 2008 03:24 PM

*everything* in OpenGL belongs to a context. All your objects (textures, VBOs, display lists, framebuffers, etc) and all your state (bound textures, enables, etc).

Since SDL destroys the context when changing video mode, you need to start completely from scratch each time.

OpenGL contexts can share objects if set up correctly, but not state, so if you can set up sharing between your windowed and full screen contexts your textures will be preserved, but you'll still need to carefully manage your enables and the like.

If you search these boards you can probably turn up a patch to SDL (by fcovett if memory serves?) that allows full-screen toggling without context destruction. I don't remember how it works, whether it's by sharing or by using the same context for both full-screen and windowed modes. If the latter, both objects and state will be preserved.


Fullscreen/resolution switch causes texture loss - Cochrane - Feb 21, 2008 02:01 AM

The version I have found here (ages ago) uses sharing. There may be other versions around somewhere.


Fullscreen/resolution switch causes texture loss - IBethune - Feb 21, 2008 03:06 AM

So I think I'll just go with reloading all my textures and resetting state when the context is destroyed and recreated...

If I have objects (textures, VBOs) etc. am I still responsible for releasing these resources e.g.

Code:
glDeleteTextures()

or does destroying the context clear it all up for me, and I just need to recreate them all again?

Cheers

- Iain


Fullscreen/resolution switch causes texture loss - OneSadCookie - Feb 21, 2008 01:37 PM

Destroying the context clears it all up.