From c6351825b84f25e5535d70a50cf13d7a0081ca47 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Thu, 13 Jul 2017 15:15:57 +0300 Subject: [PATCH] Enable Core Profile on macOS only when OpenGL 3.3 is available --- src/posix/cocoa/i_common.h | 2 ++ src/posix/cocoa/i_video.mm | 50 +++++++++++++++++++------------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/posix/cocoa/i_common.h b/src/posix/cocoa/i_common.h index 0fc46e377..5b2d6f6cb 100644 --- a/src/posix/cocoa/i_common.h +++ b/src/posix/cocoa/i_common.h @@ -60,6 +60,8 @@ extern RenderBufferOptions rbOpts; #define AppKit10_5 949 #define AppKit10_6 1038 #define AppKit10_7 1138 +#define AppKit10_8 1187 +#define AppKit10_9 1265 @interface NSWindow(ExitAppOnClose) diff --git a/src/posix/cocoa/i_video.mm b/src/posix/cocoa/i_video.mm index b51be142e..d15a20737 100644 --- a/src/posix/cocoa/i_video.mm +++ b/src/posix/cocoa/i_video.mm @@ -498,13 +498,7 @@ CocoaWindow* CreateCocoaWindow(const NSUInteger styleMask) return window; } -enum OpenGLProfile -{ - Core, - Legacy -}; - -NSOpenGLPixelFormat* CreatePixelFormat(const OpenGLProfile profile) +NSOpenGLPixelFormat* CreatePixelFormat(const NSOpenGLPixelFormatAttribute profile) { NSOpenGLPixelFormatAttribute attributes[16]; size_t i = 0; @@ -522,20 +516,8 @@ NSOpenGLPixelFormat* CreatePixelFormat(const OpenGLProfile profile) attributes[i++] = NSOpenGLPFAAllowOfflineRenderers; } - if (NSAppKitVersionNumber >= AppKit10_7 && OpenGLProfile::Core == profile) + if (NSAppKitVersionNumber >= AppKit10_7) { - NSOpenGLPixelFormatAttribute profile = NSOpenGLProfileVersion3_2Core; - const char* const glversion = Args->CheckValue("-glversion"); - - if (nullptr != glversion) - { - const double version = strtod(glversion, nullptr) + 0.01; - if (version < 3.0) - { - profile = NSOpenGLProfileVersionLegacy; - } - } - attributes[i++] = NSOpenGLPFAOpenGLProfile; attributes[i++] = profile; } @@ -564,15 +546,33 @@ CocoaVideo::CocoaVideo() gl_CalculateCPUSpeed(); // Create OpenGL pixel format + NSOpenGLPixelFormatAttribute defaultProfile = NSOpenGLProfileVersion3_2Core; + + if (1 == vid_renderer && NSAppKitVersionNumber < AppKit10_9) + { + // There is no support for OpenGL 3.3 before Mavericks + defaultProfile = NSOpenGLProfileVersionLegacy; + } + else if (0 == vid_renderer && vid_glswfb && NSAppKitVersionNumber < AppKit10_7) + { + // There is no support for OpenGL 3.x before Lion + defaultProfile = NSOpenGLProfileVersionLegacy; + } + else if (const char* const glversion = Args->CheckValue("-glversion")) + { + // Check for explicit version specified in command line + const double version = strtod(glversion, nullptr) + 0.01; + if (version < 3.3) + { + defaultProfile = NSOpenGLProfileVersionLegacy; + } + } - const OpenGLProfile defaultProfile = (1 == vid_renderer || vid_glswfb) - ? OpenGLProfile::Core - : OpenGLProfile::Legacy; NSOpenGLPixelFormat* pixelFormat = CreatePixelFormat(defaultProfile); - if (nil == pixelFormat && OpenGLProfile::Core == defaultProfile) + if (nil == pixelFormat && NSOpenGLProfileVersion3_2Core == defaultProfile) { - pixelFormat = CreatePixelFormat(OpenGLProfile::Legacy); + pixelFormat = CreatePixelFormat(NSOpenGLProfileVersionLegacy); if (nil == pixelFormat) {