From 0dd38014b307f12368888c089195b084158f94a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Wed, 3 Dec 2014 16:10:23 +0100 Subject: QOpenGLWindow: make it possible to use a shared context Change-Id: I7e9f115a9b75d38c1d6a214958d18d6fd9eac891 Reviewed-by: Laszlo Agocs --- src/gui/kernel/qopenglwindow.cpp | 29 ++++++++++++++++++++++++++--- src/gui/kernel/qopenglwindow.h | 2 ++ 2 files changed, 28 insertions(+), 3 deletions(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qopenglwindow.cpp b/src/gui/kernel/qopenglwindow.cpp index c37974c429..c58e296b5a 100644 --- a/src/gui/kernel/qopenglwindow.cpp +++ b/src/gui/kernel/qopenglwindow.cpp @@ -166,10 +166,13 @@ class QOpenGLWindowPrivate : public QPaintDeviceWindowPrivate { Q_DECLARE_PUBLIC(QOpenGLWindow) public: - QOpenGLWindowPrivate(QOpenGLWindow::UpdateBehavior updateBehavior) + QOpenGLWindowPrivate(QOpenGLContext *shareContext, QOpenGLWindow::UpdateBehavior updateBehavior) : updateBehavior(updateBehavior) , hasFboBlit(false) + , shareContext(shareContext) { + if (!shareContext) + this->shareContext = qt_gl_global_share_context(); } ~QOpenGLWindowPrivate() @@ -201,7 +204,7 @@ public: if (!context) { context.reset(new QOpenGLContext); - context->setShareContext(qt_gl_global_share_context()); + context->setShareContext(shareContext); context->setFormat(q->requestedFormat()); if (!context->create()) qWarning("QOpenGLWindow::beginPaint: Failed to create context"); @@ -299,6 +302,7 @@ public: QOpenGLWindow::UpdateBehavior updateBehavior; bool hasFboBlit; QScopedPointer context; + QOpenGLContext *shareContext; QScopedPointer fbo; QScopedPointer paintDevice; QOpenGLTextureBlitter blitter; @@ -317,11 +321,21 @@ void QOpenGLWindowPaintDevice::ensureActiveTarget() \sa QOpenGLWindow::UpdateBehavior */ QOpenGLWindow::QOpenGLWindow(QOpenGLWindow::UpdateBehavior updateBehavior, QWindow *parent) - : QPaintDeviceWindow(*(new QOpenGLWindowPrivate(updateBehavior)), parent) + : QPaintDeviceWindow(*(new QOpenGLWindowPrivate(Q_NULLPTR, updateBehavior)), parent) { setSurfaceType(QSurface::OpenGLSurface); } +/*! + Constructs a new QOpenGLWindow with the given \a parent and \a updateBehavior. The QOpenGLWindow's context will share with \a shareContext. + + \sa QOpenGLWindow::UpdateBehavior shareContext +*/ +QOpenGLWindow::QOpenGLWindow(QOpenGLContext *shareContext, UpdateBehavior updateBehavior, QWindow *parent) + : QPaintDeviceWindow(*(new QOpenGLWindowPrivate(shareContext, updateBehavior)), parent) +{ + setSurfaceType(QSurface::OpenGLSurface); +} /*! \return the update behavior for this QOpenGLWindow. */ @@ -413,6 +427,15 @@ QOpenGLContext *QOpenGLWindow::context() const return d->context.data(); } +/*! + \return The QOpenGLContext requested to be shared with this window's QOpenGLContext. +*/ +QOpenGLContext *QOpenGLWindow::shareContext() const +{ + Q_D(const QOpenGLWindow); + return d->shareContext; +} + /*! The framebuffer object handle used by this window. diff --git a/src/gui/kernel/qopenglwindow.h b/src/gui/kernel/qopenglwindow.h index 3b0b399b0a..6b64271b7b 100644 --- a/src/gui/kernel/qopenglwindow.h +++ b/src/gui/kernel/qopenglwindow.h @@ -59,6 +59,7 @@ public: }; explicit QOpenGLWindow(UpdateBehavior updateBehavior = NoPartialUpdate, QWindow *parent = 0); + explicit QOpenGLWindow(QOpenGLContext *shareContext, UpdateBehavior updateBehavior = NoPartialUpdate, QWindow *parent = 0); UpdateBehavior updateBehavior() const; bool isValid() const; @@ -67,6 +68,7 @@ public: void doneCurrent(); QOpenGLContext *context() const; + QOpenGLContext *shareContext() const; GLuint defaultFramebufferObject() const; -- cgit v1.2.3