custom SDL that doesn't delete textures during resize

Moderator
Posts: 1,140
Joined: 2005.07
Post: #1
I have completed a version of SDL that doesn't delete textures, display lists, VBOs, etc. during a resize or switching in or out of fullscreen. (through the use of shared contexts) I have pre-built Windows and OS X binaries. (for OS X, it requires 10.3.9 or later, and is a universal binary) The source (with the changes) is also included. I haven't double checked every change possible, but as long as you keep the acceleration (aka: if it's hardware or software) consistent, it should be fine.

Download
Quote this message in a reply
Member
Posts: 320
Joined: 2003.06
Post: #2
Thanks! I gave this a shot once with a checkout of 2.3.0 but had too many problems and gave up. Since then I have implemented reloading of textures to deal with fullscreen and given up on resize so this will be fantastic!

Does the windows version handle resizing as well?

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #3
You'd better be careful in your context sharing. Be sure to test it out on a machine with two video cards installed (that is-- simply requiring hardware accleration is not sufficient to ensure that the virtual screen list is compatible between the window context and the fullscreen context.)
Quote this message in a reply
Member
Posts: 567
Joined: 2004.07
Post: #4
Is this cross platform, or simply mac?

It's not magic, it's Ruby.
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #5
Both the Mac and Windows version share contexts so whenever you call SDL_SetVideoMode it will keep your textures etc. intact. (the only exception is if you switch between software and hardware contexts) On the Windows version, I also changed it to be in line with the Mac version when setting an accelerated context: if it's > 1, it will set it to a full accelerated context. (if it's < 1, it uses a generic accelerated context)

arekkusu: I don't have access to a computer with multiple video cards. Can somebody with access to one test it and ensure it works?

Edit: I just checked resizing when you drag, and I noticed it jumps all around. I'll see if I can change it so it will keep the old window position. (it does set up the context stuff correctly; just make sure you also run your setup code for initializing the state) When I get to work on Friday, I can see if the Windows version suffers from the same problem.

Editx2: I just discovered that you can also use setenv("SDL_VIDEO_WINDOW_POS", "x, y", 1); to manually set the window position before you cal SetVideoMode.
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #6
I uploaded a new version that fixes a bug I just discovered where if you set a window position other than 0, 0 or centered, the view will be offset by that much. (it would be there in the official version, too; they forgot to set the rectangle's origin to 0, 0 before using it for the window)

I think it would alter their system too much to put in the window positioning stuff directly into SDL, but with a few #defines and a few lines of code for each platform, it shouldn't be too difficult to get the current window's position every time you resize and use setenv to set the new position (or just set it directly)
Quote this message in a reply
Member
Posts: 320
Joined: 2003.06
Post: #7
unfortunately I get an invalid share context error when trying to do the switch. It actually works fine from windowed to fullscreen, but fails on the way back. When I was playing around with modifying the SDL source (it was version 1.3.0, not 2.3.0... typo) I found that the no recovery pixel format attribute was the one that caused me headaches, I'll check that out first.

Perhaps someone can shed light on what no recovery is supposed to do, and why it seems to cause different shared context issues on a ATI 7500 to a NV 6800?

I'll try an SDL build from source with a couple of modifications and see if I can make it work here.

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #8
Thanks for the help. Strange, though, since it works going both ways on my computer. (Radeon X800) Definitely let me know if you can get it to work on your computer, and I'll add it to the build. Hopefully we'll be able to confirm it working on computers with multiple graphics cards, too.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #9
No Recovery disables software fallbacks.
Quote this message in a reply
Member
Posts: 320
Joined: 2003.06
Post: #10
OK I've spent enough time trying to get it to work, and all attempts have been worse than the original. Every time I recompile SDL I have to build my app from clean which is taking about 5 minutes each time, so I think it's time to give up.

I might give it another shot when my 24 inch iMac shows up Grin

I'm not sure why it's so hard to get SDL to share contexts properly but it has passed beyond my realm of interest yet again. Sad

Cheers

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #11
Bah! May I ask what OS you are using?

Can anybody else take a look at my context sharing code? I've tried other combinations, myself, but haven't had much luck. Perhaps this weekend I'll take another stab at different combinations.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #12
reubert Wrote:OK I've spent enough time trying to get it to work, and all attempts have been worse than the original. Every time I recompile SDL I have to build my app from clean which is taking about 5 minutes each time, so I think it's time to give up.

Just copy the SDL framework's executable, not the whole framework, and you can avoid the clean compile (which is caused because the header files look newer).
Quote this message in a reply
Member
Posts: 320
Joined: 2003.06
Post: #13
Ahh thanks I'll try that.

I'm using 10.4.7. I did manage to create a shared context that didn't give me any errors last night but it also didn't share... don't ask me how that works. Anyway I might keep trying.

I was trying to get the current context every switch to share with instead of only getting the first one as a shared context for all switches. That is how Chopper 1 does it.

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Quote this message in a reply
Member
Posts: 320
Joined: 2003.06
Post: #14
I managed to make it work Smile now I just have to figure out exactly how and I'll let you know.

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Quote this message in a reply
Member
Posts: 320
Joined: 2003.06
Post: #15
OK. Turns out it was the old No Recovery chestnut, and possibly some other fix generated by my changing of how the shared context was generated. Changed block as follows:

removed block up the top
Code:
/* if a GL library hasn't been loaded at this point, load the default. */
    if (!this->gl_config.driver_loaded) {
        if (QZ_GL_LoadLibrary(this, NULL) == -1)
            return 0;
    }
    
    //Add a shared context on the first creation to make sure that the textures
    //are preserved ADDED BY AARON BARANY
    // dave removed this block of code and placed a modified version below
    //END ADDED BY AARON BARANY

    if ( flags & SDL_FULLSCREEN ) {

        attr[i++] = NSOpenGLPFAFullScreen;
    }

Moved NoRecovery attribute, and inserted new version of shared context generation.
Code:
if ( this->gl_config.accelerated > 0 ) {
        attr[i++] = NSOpenGLPFAAccelerated; //dave removed NSOpenGLPFANoRecovery and placed it below
    }
    
    attr[i++] = NSOpenGLPFANoRecovery; //dave

    attr[i++] = NSOpenGLPFAScreenMask;
    attr[i++] = CGDisplayIDToOpenGLDisplayMask (display_id);
    attr[i] = 0;
    
    // dave put this here
    if (!SDL_SharedContext || (sharedAccelerated && this->gl_config.accelerated <= 0) ||
        (!sharedAccelerated && this->gl_config.accelerated > 0))
    {
        fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
        SDL_SharedContext = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:NULL];
        [fmt release];
    }
    // end dave

    fmt = [ [ NSOpenGLPixelFormat alloc ] initWithAttributes:attr ];
    if (fmt == nil) {
        SDL_SetError ("Failed creating OpenGL pixel format");
        return 0;
    }

Hopefully this still works elsewhere too!

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Showing resize control over NSOpenGLView AnotherJake 14 7,601 Oct 25, 2004 06:13 PM
Last Post: AnotherJake