From 0a5f38157f5180cad286c5bb11a841dadf10ce26 Mon Sep 17 00:00:00 2001 From: Marco Antognini Date: Sun, 13 Apr 2014 16:41:03 +0200 Subject: [PATCH] Added support for OpenGL 3.2 context on OS X (close #84) The Graphics module is not compatible with a core profile on Mac. If you plan to use it, use OpenGL 2.1 (default). --- src/SFML/Window/OSX/SFContext.mm | 34 ++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/SFML/Window/OSX/SFContext.mm b/src/SFML/Window/OSX/SFContext.mm index 0feaf645..a7364950 100644 --- a/src/SFML/Window/OSX/SFContext.mm +++ b/src/SFML/Window/OSX/SFContext.mm @@ -90,7 +90,8 @@ m_window(0) //////////////////////////////////////////////////////////// SFContext::~SFContext() { -@autoreleasepool { +@autoreleasepool +{ [m_context clearDrawable]; m_context = nil; @@ -180,6 +181,26 @@ void SFContext::createContext(SFContext* shared, attrs.push_back(NSOpenGLPFAAccelerated); } + // Support for OpenGL 3.2 on Mac OS X Lion and later: + // SFML 2 Graphics module uses some OpenGL features that are deprecated + // in OpenGL 3.2 and that are no more available with core context. + // Therefore the Graphics module won't work as expected. + + // 2.x are mapped to 2.1 since Apple only support that legacy version. + // >=3.0 are mapped to a 3.2 core profile. + bool legacy = settings.majorVersion < 3; + + if (legacy) + { + attrs.push_back(NSOpenGLPFAOpenGLProfile); + attrs.push_back(NSOpenGLProfileVersionLegacy); + } + else + { + attrs.push_back(NSOpenGLPFAOpenGLProfile); + attrs.push_back(NSOpenGLProfileVersion3_2Core); + } + attrs.push_back((NSOpenGLPixelFormatAttribute)0); // end of array // Create the pixel format. @@ -199,7 +220,16 @@ void SFContext::createContext(SFContext* shared, shareContext:sharedContext]; if (m_context == nil) - sf::err() << "Error. Unable to create the context." << std::endl; + { + sf::err() << "Error. Unable to create the context. Retrying without shared context." << std::endl; + m_context = [[NSOpenGLContext alloc] initWithFormat:pixFmt + shareContext:nil]; + + if (m_context == nil) + sf::err() << "Error. Unable to create the context." << std::endl; + else + sf::err() << "Warning. New context created without shared context." << std::endl; + } // Save the settings. (OpenGL version is updated elsewhere.) m_settings = settings;