Fullscreen/resolution switch causes texture loss

Member
Posts: 156
Joined: 2002.10
Post: #1
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
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
*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.
Quote this message in a reply
Member
Posts: 114
Joined: 2005.03
Post: #3
The version I have found here (ages ago) uses sharing. There may be other versions around somewhere.
Quote this message in a reply
Member
Posts: 156
Joined: 2002.10
Post: #4
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
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
Destroying the context clears it all up.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  DPI and Resolution for Graphics mickyg 9 8,490 Apr 27, 2012 03:02 PM
Last Post: Andres Calil
  fullscreen-window mode switch NYGhost 10 5,325 Feb 10, 2005 09:52 AM
Last Post: NYGhost
  changing resolution in fullscreen ghettotek 22 8,247 Jan 18, 2005 09:39 PM
Last Post: arekkusu
  Switch Between Fullscreen and Windowed Modes - Again... thaeez 2 2,894 Jul 9, 2004 02:49 AM
Last Post: thaeez
  OpenGL CGL Switch Between Fullscreen and Windowed Mode thaeez 1 3,250 Jun 30, 2004 04:29 AM
Last Post: OneSadCookie