Add cglContextForContext to QCocoaNativeInterface.

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>
bb10
Zeno Albisser 2012-10-12 16:33:40 +02:00 committed by The Qt Project
parent 83ffc56a72
commit 00d78dac2f
2 changed files with 27 additions and 0 deletions

View File

@ -56,8 +56,11 @@ class QCocoaNativeInterface : public QPlatformNativeInterface
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);

View File

@ -65,6 +65,17 @@ QCocoaNativeInterface::QCocoaNativeInterface()
{
}
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()) {
@ -109,4 +120,17 @@ void QCocoaNativeInterface::onAppFocusWindowChanged(QWindow *window)
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