PDA

View Full Version : Sharing textures in SDL's OpenGL surfaces


PowerMacX
2004.10.09, 01:53 PM
I'd like to be able to switch from windowed mode to fullscreen and back using SDL+OpenGL, but the context switch means I have to reload all my textures. It works, but it's a mess to maintain. I read here (http://www.idevgames.com/forum/showthread.php?t=7283) that it is posible to share a context in AGL.

The question:
Has anybody been able to implement this using a standard SDL framework?
If not, has anybody been able to hack SDL's source code to make this possible?

Joseph Duchesne
2004.10.10, 01:22 AM
For the record I asked the same question for the same reason a few months ago and nobody could help me :( . I hope things have changed.

isgoed
2004.10.10, 07:10 AM
I'd like to be able to switch from windowed mode to fullscreen and back using SDL+OpenGL, but the context switch means I have to reload all my textures. It works, but it's a mess to maintain. I read here (http://www.idevgames.com/forum/showthread.php?t=7283) that it is posible to share a context in AGL.

I am the one in the thread you pointed out. I don't know what SDL is though. It is possible to share textures between fullscreen and window (as I am able to do). The trick is that you must treat your window and fullscreen state both as grafports. The pseudo code i have does this:

AGLContext FullscreenContext;
AGLContext WindowContext;

FullscreenContext = aglCreateContext (PixelFormat, 0);
WindowContext = aglCreateContext (PixelFormat, FullscreenContext); // HERE YOU SHARE TEXTURES

aglSetDrawable(FullscreenContext, FullScreenGrafPort);
aglSetDrawable(WindowContext, WindowGrafPort);

if(windowed_mode){
aglSetCurrentContext(WindowContext);}
else{
aglSetCurrentContext(FullscreenContext);}

you can also look into the function

Succes = aglCopyContext (FullscreenContext,WindowContext,GL_ALL_ATTRIB_BIT S);

A disadvantage of this method is that your fullscreencontext is not as fast as:

aglSetFullScreen (FullscreenContext, 0, 0, 0, 0);

PowerMacX
2004.10.11, 03:56 PM
Upon closer inspection of SDL (http://www.libsdl.org) source code, I found out that althrough there is an AGL version of the video code, there is also a "Quartz" version, wich is probably what it is using on OS X...?

For now, I'll just make the player exit the game to apply changes :( , especially if sharing a context makes it a bit slower (my goal is to make my 3D game playable on a Rage128Pro)

Still, if I have time I'll experiment with SDL source a bit :wacko:

OneSadCookie
2004.10.11, 05:34 PM
Yes, it uses Cocoa on Mac OS X, so you'd have to do NSGL things.

Sharing the context shouldn't be a performance penalty.