This change enables receiving the native CGLContextObj 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: Id00efc88a73d7df04a68c022f19d9d1c4f6d386b
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
public:
QCocoaNativeInterface();
+ void *nativeResourceForContext(const QByteArray &resourceString, QOpenGLContext *context);
void *nativeResourceForWindow(const QByteArray &resourceString, QWindow *window);
+ static void *cglContextForContext(QOpenGLContext *context);
+
public Q_SLOTS:
void onAppFocusWindowChanged(QWindow *window);
{
}
+void *QCocoaNativeInterface::nativeResourceForContext(const QByteArray &resourceString, QOpenGLContext *context)
+{
+ if (!context)
+ return 0;
+
+ if (resourceString.toLower() == "cglcontextobj")
+ return cglContextForContext(context);
+
+ return 0;
+}
+
void *QCocoaNativeInterface::nativeResourceForWindow(const QByteArray &resourceString, QWindow *window)
{
if (!window->handle()) {
QCocoaMenuBar::updateMenuBarImmediately();
}
+void *QCocoaNativeInterface::cglContextForContext(QOpenGLContext* context)
+{
+ if (context) {
+ QCocoaGLContext *cocoaGLContext = static_cast<QCocoaGLContext *>(context->handle());
+ if (cocoaGLContext) {
+ NSOpenGLContext *nsOpenGLContext = cocoaGLContext->nsOpenGLContext();
+ if (nsOpenGLContext)
+ return [nsOpenGLContext CGLContextObj];
+ }
+ }
+ return 0;
+}
+
QT_END_NAMESPACE