summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@qt.io>2017-09-14 15:09:22 +0200
committerMorten Johan Sørvig <morten.sorvig@qt.io>2017-11-16 08:21:13 +0000
commit12aa50175268064b3da36473ec0196cbdb1bdf7f (patch)
tree31c8b798df253083e0e3c4251b6b6f078e094083 /src/plugins
parenta066ad32b6ef87b8882642495dcabaa3ac1a0819 (diff)
macOS: Fix OpenGL context sharing
See code comments for problem and fix description. Task-number: QTBUG-63180 Change-Id: I6c6381f2c77c246bd975f66f9baa0165e32de777 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/platforms/cocoa/qcocoaglcontext.mm25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.mm b/src/plugins/platforms/cocoa/qcocoaglcontext.mm
index 5ed81a7f1b..be5029b7e0 100644
--- a/src/plugins/platforms/cocoa/qcocoaglcontext.mm
+++ b/src/plugins/platforms/cocoa/qcocoaglcontext.mm
@@ -152,9 +152,32 @@ QCocoaGLContext::QCocoaGLContext(const QSurfaceFormat &format, QPlatformOpenGLCo
QMacAutoReleasePool pool; // For the SG Canvas render thread
+ m_shareContext = share ? static_cast<QCocoaGLContext *>(share)->nsOpenGLContext() : nil;
+
+ if (m_shareContext) {
+ // Allow sharing between 3.2 Core and 4.1 Core profile versions in
+ // cases where NSOpenGLContext creates a 4.1 context where a 3.2
+ // context was requested. Due to the semantics of QSurfaceFormat
+ // this 4.1 version can find its way onto the format for the new
+ // context, even though it was at no point requested by the user.
+ GLint shareContextRequestedProfile;
+ [m_shareContext.pixelFormat getValues:&shareContextRequestedProfile
+ forAttribute:NSOpenGLPFAOpenGLProfile forVirtualScreen:0];
+ auto shareContextActualProfile = share->format().version();
+
+ if (shareContextRequestedProfile == NSOpenGLProfileVersion3_2Core &&
+ shareContextActualProfile >= qMakePair(4, 1)) {
+
+ // There is a mismatch, downgrade requested format to make the
+ // NSOpenGLPFAOpenGLProfile attributes match. (NSOpenGLContext will
+ // fail to create a new context if there is a mismatch).
+ if (m_format.version() >= qMakePair(4, 1))
+ m_format.setVersion(3, 2);
+ }
+ }
+
// create native context for the requested pixel format and share
NSOpenGLPixelFormat *pixelFormat = createNSOpenGLPixelFormat(m_format);
- m_shareContext = share ? static_cast<QCocoaGLContext *>(share)->nsOpenGLContext() : nil;
m_context = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:m_shareContext];
// retry without sharing on context creation failure.