From 92724e533d13f56d359122d7d83ddc2316a75ef8 Mon Sep 17 00:00:00 2001 From: Zeno Albisser Date: Fri, 23 Nov 2012 10:52:22 +0100 Subject: Add nsOpenGLContextForContext to QCocoaNativeInterface. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change enables receiving the native NSOpenGLContext that is used by a QOpenGLContext. This clearly is non-public api that is only meant to be used as a last resort for cases where it is really necessary to get hold of a native context object. Change-Id: Iea7c6abb458acc7aa15926052673270d25d1d9d1 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoanativeinterface.h | 1 + src/plugins/platforms/cocoa/qcocoanativeinterface.mm | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.h b/src/plugins/platforms/cocoa/qcocoanativeinterface.h index e4b52b9454..70ec497309 100644 --- a/src/plugins/platforms/cocoa/qcocoanativeinterface.h +++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.h @@ -60,6 +60,7 @@ public: void *nativeResourceForWindow(const QByteArray &resourceString, QWindow *window); static void *cglContextForContext(QOpenGLContext *context); + static void *nsOpenGLContextForContext(QOpenGLContext* context); public Q_SLOTS: void onAppFocusWindowChanged(QWindow *window); diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm index 7f37b971d7..f0b1bd330a 100644 --- a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm +++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm @@ -69,7 +69,8 @@ void *QCocoaNativeInterface::nativeResourceForContext(const QByteArray &resource { if (!context) return 0; - + if (resourceString.toLower() == "nsopenglcontext") + return nsOpenGLContextForContext(context); if (resourceString.toLower() == "cglcontextobj") return cglContextForContext(context); @@ -121,13 +122,19 @@ void QCocoaNativeInterface::onAppFocusWindowChanged(QWindow *window) } void *QCocoaNativeInterface::cglContextForContext(QOpenGLContext* context) +{ + NSOpenGLContext *nsOpenGLContext = static_cast(nsOpenGLContextForContext(context)); + if (nsOpenGLContext) + return [nsOpenGLContext CGLContextObj]; + return 0; +} + +void *QCocoaNativeInterface::nsOpenGLContextForContext(QOpenGLContext* context) { if (context) { QCocoaGLContext *cocoaGLContext = static_cast(context->handle()); if (cocoaGLContext) { - NSOpenGLContext *nsOpenGLContext = cocoaGLContext->nsOpenGLContext(); - if (nsOpenGLContext) - return [nsOpenGLContext CGLContextObj]; + return cocoaGLContext->nsOpenGLContext(); } } return 0; -- cgit v1.2.3