| 1 |
|
| 2 |
|
| 3 |
#include <GUI/QtLauncher.hxx> |
| 4 |
|
| 5 |
#include <QOpenGLContext> |
| 6 |
#include <QtPlatformHeaders/QCocoaNativeContext> |
| 7 |
#include <QWindow> |
| 8 |
|
| 9 |
#include <osgViewer/api/Cocoa/GraphicsWindowCocoa> |
| 10 |
|
| 11 |
|
| 12 |
namespace flightgear |
| 13 |
{ |
| 14 |
|
| 15 |
QOpenGLContext* qtContextFromOSG(osg::GraphicsContext* context) |
| 16 |
{ |
| 17 |
osgViewer::GraphicsWindowCocoa* win = dynamic_cast<osgViewer::GraphicsWindowCocoa*>(context); |
| 18 |
if (!win) { |
| 19 |
return nullptr; |
| 20 |
} |
| 21 |
|
| 22 |
auto cnc = QCocoaNativeContext{win->getContext()}; |
| 23 |
QVariant nativeHandle = QVariant::fromValue(cnc); |
| 24 |
|
| 25 |
if (nativeHandle.isNull()) |
| 26 |
return nullptr; |
| 27 |
|
| 28 |
std::unique_ptr<QOpenGLContext> qtOpenGLContext(new QOpenGLContext); |
| 29 |
qtOpenGLContext->setNativeHandle(nativeHandle); |
| 30 |
if (!qtOpenGLContext->create()) { |
| 31 |
return nullptr; |
| 32 |
} |
| 33 |
|
| 34 |
return qtOpenGLContext.release(); |
| 35 |
} |
| 36 |
|
| 37 |
QWindow* qtWindowFromOSG(osgViewer::GraphicsWindow* graphicsWindow) |
| 38 |
{ |
| 39 |
osgViewer::GraphicsWindowCocoa* win = dynamic_cast<osgViewer::GraphicsWindowCocoa*>(graphicsWindow); |
| 40 |
if (!win) { |
| 41 |
return nullptr; |
| 42 |
} |
| 43 |
|
| 44 |
NSView* osgView = [win->getContext() view]; |
| 45 |
return QWindow::fromWinId(reinterpret_cast<qlonglong>(osgView)); |
| 46 |
} |
| 47 |
|
| 48 |
} // of namespace flightgear |