macOS: Move QCocoaGLContext initialization into dedicated method

Change-Id: I9dc2c400c3d26e9fcfaac04b61c1503229f59dba
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
bb10
Tor Arne Vestbø 2019-07-16 23:19:19 +02:00
parent e0a486c77d
commit 7a7fe9dbb3
3 changed files with 15 additions and 7 deletions

View File

@ -56,6 +56,8 @@ public:
QCocoaGLContext(QOpenGLContext *context);
~QCocoaGLContext();
void initialize() override;
bool makeCurrent(QPlatformSurface *surface) override;
void swapBuffers(QPlatformSurface *surface) override;
void doneCurrent() override;

View File

@ -76,9 +76,14 @@ QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(lcQpaOpenGLContext, "qt.qpa.openglcontext", QtWarningMsg);
QCocoaGLContext::QCocoaGLContext(QOpenGLContext *context)
: QPlatformOpenGLContext(), m_format(context->format())
: QPlatformOpenGLContext()
, m_format(context->format())
{
QVariant nativeHandle = context->nativeHandle();
}
void QCocoaGLContext::initialize()
{
QVariant nativeHandle = context()->nativeHandle();
if (!nativeHandle.isNull()) {
if (!nativeHandle.canConvert<QCocoaNativeContext>()) {
qCWarning(lcQpaOpenGLContext, "QOpenGLContext native handle must be a QCocoaNativeContext");
@ -95,7 +100,7 @@ QCocoaGLContext::QCocoaGLContext(QOpenGLContext *context)
// Note: We have no way of knowing whether the NSOpenGLContext was created with the
// share context as reported by the QOpenGLContext, but we just have to trust that
// it was. It's okey, as the only thing we're using it for is to report isShared().
if (QPlatformOpenGLContext *shareContext = context->shareHandle())
if (QPlatformOpenGLContext *shareContext = context()->shareHandle())
m_shareContext = static_cast<QCocoaGLContext *>(shareContext)->nativeContext();
updateSurfaceFormat();
@ -110,7 +115,7 @@ QCocoaGLContext::QCocoaGLContext(QOpenGLContext *context)
if (m_format.renderableType() != QSurfaceFormat::OpenGL)
return;
if (QPlatformOpenGLContext *shareContext = context->shareHandle()) {
if (QPlatformOpenGLContext *shareContext = context()->shareHandle()) {
m_shareContext = static_cast<QCocoaGLContext *>(shareContext)->nativeContext();
// Allow sharing between 3.2 Core and 4.1 Core profile versions in
@ -150,6 +155,9 @@ QCocoaGLContext::QCocoaGLContext(QOpenGLContext *context)
return;
}
// The native handle should reflect the underlying context, even if we created it
context()->setNativeHandle(QVariant::fromValue<QCocoaNativeContext>(m_context));
// --------------------- Set NSOpenGLContext properties ---------------------
const GLint interval = m_format.swapInterval() >= 0 ? m_format.swapInterval() : 1;

View File

@ -418,9 +418,7 @@ QPlatformOffscreenSurface *QCocoaIntegration::createPlatformOffscreenSurface(QOf
#ifndef QT_NO_OPENGL
QPlatformOpenGLContext *QCocoaIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
{
QCocoaGLContext *glContext = new QCocoaGLContext(context);
context->setNativeHandle(QVariant::fromValue<QCocoaNativeContext>(glContext->nativeContext()));
return glContext;
return new QCocoaGLContext(context);
}
#endif