Updated support for legacy renderer in Cocoa backend

Added fallback to legacy profile when creation of pixel format for core context failed
Added handling of -glversion command line switch
This commit is contained in:
alexey.lysiuk 2016-09-04 15:23:29 +03:00
parent d2ead39bcc
commit 108dcf122a
1 changed files with 52 additions and 19 deletions

View File

@ -459,23 +459,14 @@ CocoaWindow* CreateCocoaWindow(const NSUInteger styleMask)
return window;
}
} // unnamed namespace
// ---------------------------------------------------------------------------
CocoaVideo::CocoaVideo()
: m_window(CreateCocoaWindow(STYLE_MASK_WINDOWED))
, m_width(-1)
, m_height(-1)
, m_fullscreen(false)
, m_hiDPI(false)
enum OpenGLProfile
{
memset(&m_modeIterator, 0, sizeof m_modeIterator);
// Set attributes for OpenGL context
Core,
Legacy
};
NSOpenGLPixelFormat* CreatePixelFormat(const OpenGLProfile profile)
{
NSOpenGLPixelFormatAttribute attributes[16];
size_t i = 0;
@ -492,17 +483,59 @@ CocoaVideo::CocoaVideo()
attributes[i++] = NSOpenGLPFAAllowOfflineRenderers;
}
if (NSAppKitVersionNumber >= AppKit10_7)
if (NSAppKitVersionNumber >= AppKit10_7 && OpenGLProfile::Core == profile)
{
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.2)
{
profile = NSOpenGLProfileVersionLegacy;
}
}
attributes[i++] = NSOpenGLPFAOpenGLProfile;
attributes[i++] = NSOpenGLProfileVersion3_2Core;
attributes[i++] = profile;
}
attributes[i] = NSOpenGLPixelFormatAttribute(0);
// Create OpenGL context and view
return [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
}
NSOpenGLPixelFormat *pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
} // unnamed namespace
// ---------------------------------------------------------------------------
CocoaVideo::CocoaVideo()
: m_window(CreateCocoaWindow(STYLE_MASK_WINDOWED))
, m_width(-1)
, m_height(-1)
, m_fullscreen(false)
, m_hiDPI(false)
{
memset(&m_modeIterator, 0, sizeof m_modeIterator);
// Create OpenGL pixel format
NSOpenGLPixelFormat* pixelFormat = CreatePixelFormat(OpenGLProfile::Core);
if (nil == pixelFormat)
{
pixelFormat = CreatePixelFormat(OpenGLProfile::Legacy);
if (nil == pixelFormat)
{
I_FatalError("Cannot OpenGL create pixel format, graphics hardware is not supported");
}
}
// Create OpenGL context and view
const NSRect contentRect = [m_window contentRectForFrameRect:[m_window frame]];
NSOpenGLView* glView = [[CocoaView alloc] initWithFrame:contentRect