| Summary: | OpenGL and NSOpenPanel conflict | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Anthony Catel <paraboul> |
| Component: | video | Assignee: | Alex Szpakowski <amaranth72> |
| Status: | RESOLVED WONTFIX | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | gabomdq |
| Version: | 2.0.1 | ||
| Hardware: | x86_64 | ||
| OS: | Mac OS X 10.8 | ||
I think I understand the problem. I tried to call SDL_GL_MakeCurrent() before entering my GL calls. The problem is that the system has changed the current thread openGL context though SDL think it still the same (making SDL_GL_MakeCurrent a no op because of the cached value in current_glctx_tls). invalid cached value proven by this : NSLog(@"[Render] Current open GL : %@ vs %@", [NSOpenGLContext currentContext], SDL_GL_GetCurrentContext()); out : [Render] Current open GL : <NSOpenGLContext: 0x7fd3d6376a60> vs <SDLOpenGLContext: 0x7fd3d3c4bb80> As a workaround, you can probably call SDL_GL_MakeCurrent with a null context, and then again with the actual context you want to use. That's an option. There is however no work around for SDL_GL_GetCurrentContext() though. Even though we try to remove the cache thing for the GL context, we would have to downcast a possible NSOpenGLContext to a SDLOpenGLContext (which is not possible without a wrapper because of extra ivar in SDLOpenGLContext). Any idea? Alex, any ideas? At the very least you can save and restore the previously active (SDL or otherwise) opengl context by calling [NSOpenGLContext currentContext] before the NSOpenPanel call, and [context makeCurrentContext] after. We could probably also modify SDL_GL_GetCurrentContext to return NULL if the current platform opengl context is not SDL-owned (at the cost of a bit more overhead in SDL_GL_GetCurrentContext and SDL_GL_MakeCurrent). That would fix SDL_GL_MakeCurrent being a no-op in this situation. If you're using OpenGL outside of SDL, you should probably save and restore your state. Alex showed how to do that above. I'm going to mark this WONTFIX to keep SDL context functions fast. Thanks! |
When creating an NSOpenPanel object, OSX create a new OpenGL context on the same thread than the caller and make it current. This can be verified by calling : NSLog(@"[Before] Current open GL : %@", [NSOpenGLContext currentContext]); NSOpenPanel* openDlg = [NSOpenPanel openPanel]; NSLog(@"[After] Current open GL : %@", [NSOpenGLContext currentContext]); I tried the same code on a simple cocoa OpenGL without SDL, the behaviour is the same. The problem is that, using SDL, the current context never go back to the one before the NSOpenPanel initialisation while it seems to restore using a simple cocoa application. In the following log, I initialised a NSOpenPanel at the frame #200 and continuously printed to stdout the current opengl context : GLWithoutSDL[13290:6703] [198] Render for <NSOpenGLContext: 0x60800003f2e0> GLWithoutSDL[13290:6703] [199] Render for <NSOpenGLContext: 0x60800003f2e0> GLWithoutSDL[13290:6703] [200] Render for <NSOpenGLContext: 0x618000229d00> GLWithoutSDL[13290:6703] [201] Render for <NSOpenGLContext: 0x60800003f2e0> GLWithoutSDL[13290:6703] [202] Render for <NSOpenGLContext: 0x60800003f2e0> As you can see, the current context is not the same for the frame #200 but go back to normal right after. Doing the same with SDL : GLWITHSDK[13383:507] [Render] Current open GL : <SDLOpenGLContext: 0x7f8243d36f50> GLWITHSDK[13383:507] [Render] Current open GL : <SDLOpenGLContext: 0x7f8243d36f50> GLWITHSDK[13383:507] [Render] Current open GL : <NSOpenGLContext: 0x7f8243c7f710> GLWITHSDK[13383:507] [Render] Current open GL : <NSOpenGLContext: 0x7f8243c7f710> GLWITHSDK[13383:507] [Render] Current open GL : <NSOpenGLContext: 0x7f8243c7f710>