From 0ac489ade17f4ea6394b4715e1362f63539c5419 Mon Sep 17 00:00:00 2001 From: rogerman Date: Sun, 15 Mar 2015 06:46:49 +0000 Subject: [PATCH] Cocoa Port: - Fall back to using a legacy OpenGL context if the GPU driver rejects initializing a 3.2 Core Profile context. --- desmume/src/cocoa/OGLDisplayOutput.h | 2 ++ .../userinterface/DisplayWindowController.mm | 25 ++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/desmume/src/cocoa/OGLDisplayOutput.h b/desmume/src/cocoa/OGLDisplayOutput.h index 20109b259..9c726063f 100644 --- a/desmume/src/cocoa/OGLDisplayOutput.h +++ b/desmume/src/cocoa/OGLDisplayOutput.h @@ -405,6 +405,8 @@ public: virtual void SetViewportSizeOGL(GLsizei w, GLsizei h); }; +OGLInfo* OGLInfoCreate_Legacy(); + extern OGLInfo* (*OGLInfoCreate_Func)(); extern void (*glBindVertexArrayDESMUME)(GLuint id); extern void (*glDeleteVertexArraysDESMUME)(GLsizei n, const GLuint *ids); diff --git a/desmume/src/cocoa/userinterface/DisplayWindowController.mm b/desmume/src/cocoa/userinterface/DisplayWindowController.mm index ac6fe2b56..2b49e0aa0 100644 --- a/desmume/src/cocoa/userinterface/DisplayWindowController.mm +++ b/desmume/src/cocoa/userinterface/DisplayWindowController.mm @@ -1316,19 +1316,36 @@ static std::unordered_map _screenMap; // (NSOpenGLPixelFormatAttribute)0, (NSOpenGLPixelFormatAttribute)0, (NSOpenGLPixelFormatAttribute)0 }; + NSOpenGLPixelFormat *format = nil; + #ifdef _OGLDISPLAYOUTPUT_3_2_H_ // If we can support a 3.2 Core Profile context, then request that in our // pixel format attributes. if (IsOSXVersionSupported(10, 7, 0)) { - attributes[9] = kCGLPFAOpenGLProfile; - attributes[10] = (CGLPixelFormatAttribute)kCGLOGLPVersion_3_2_Core; - + attributes[9] = NSOpenGLPFAOpenGLProfile; + attributes[10] = NSOpenGLProfileVersion3_2Core; OGLInfoCreate_Func = &OGLInfoCreate_3_2; + format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]; + + if (format == nil) + { + attributes[9] = NSOpenGLPFAOpenGLProfile; + attributes[10] = NSOpenGLProfileVersionLegacy; + OGLInfoCreate_Func = &OGLInfoCreate_Legacy; + format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]; + } } #endif - NSOpenGLPixelFormat *format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]; + if (format == nil) + { + attributes[9] = (NSOpenGLPixelFormatAttribute)0; + attributes[10] = (NSOpenGLPixelFormatAttribute)0; + OGLInfoCreate_Func = &OGLInfoCreate_Legacy; + format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]; + } + context = [[NSOpenGLContext alloc] initWithFormat:format shareContext:nil]; [format release]; cglDisplayContext = (CGLContextObj)[context CGLContextObj];