QOpenGLWindow: make it possible to use a shared context

Change-Id: I7e9f115a9b75d38c1d6a214958d18d6fd9eac891
Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
This commit is contained in:
Jørgen Lind 2014-12-03 16:10:23 +01:00
parent 8758f532ae
commit 0dd38014b3
2 changed files with 28 additions and 3 deletions

View File

@ -166,10 +166,13 @@ class QOpenGLWindowPrivate : public QPaintDeviceWindowPrivate
{ {
Q_DECLARE_PUBLIC(QOpenGLWindow) Q_DECLARE_PUBLIC(QOpenGLWindow)
public: public:
QOpenGLWindowPrivate(QOpenGLWindow::UpdateBehavior updateBehavior) QOpenGLWindowPrivate(QOpenGLContext *shareContext, QOpenGLWindow::UpdateBehavior updateBehavior)
: updateBehavior(updateBehavior) : updateBehavior(updateBehavior)
, hasFboBlit(false) , hasFboBlit(false)
, shareContext(shareContext)
{ {
if (!shareContext)
this->shareContext = qt_gl_global_share_context();
} }
~QOpenGLWindowPrivate() ~QOpenGLWindowPrivate()
@ -201,7 +204,7 @@ public:
if (!context) { if (!context) {
context.reset(new QOpenGLContext); context.reset(new QOpenGLContext);
context->setShareContext(qt_gl_global_share_context()); context->setShareContext(shareContext);
context->setFormat(q->requestedFormat()); context->setFormat(q->requestedFormat());
if (!context->create()) if (!context->create())
qWarning("QOpenGLWindow::beginPaint: Failed to create context"); qWarning("QOpenGLWindow::beginPaint: Failed to create context");
@ -299,6 +302,7 @@ public:
QOpenGLWindow::UpdateBehavior updateBehavior; QOpenGLWindow::UpdateBehavior updateBehavior;
bool hasFboBlit; bool hasFboBlit;
QScopedPointer<QOpenGLContext> context; QScopedPointer<QOpenGLContext> context;
QOpenGLContext *shareContext;
QScopedPointer<QOpenGLFramebufferObject> fbo; QScopedPointer<QOpenGLFramebufferObject> fbo;
QScopedPointer<QOpenGLWindowPaintDevice> paintDevice; QScopedPointer<QOpenGLWindowPaintDevice> paintDevice;
QOpenGLTextureBlitter blitter; QOpenGLTextureBlitter blitter;
@ -317,11 +321,21 @@ void QOpenGLWindowPaintDevice::ensureActiveTarget()
\sa QOpenGLWindow::UpdateBehavior \sa QOpenGLWindow::UpdateBehavior
*/ */
QOpenGLWindow::QOpenGLWindow(QOpenGLWindow::UpdateBehavior updateBehavior, QWindow *parent) QOpenGLWindow::QOpenGLWindow(QOpenGLWindow::UpdateBehavior updateBehavior, QWindow *parent)
: QPaintDeviceWindow(*(new QOpenGLWindowPrivate(updateBehavior)), parent) : QPaintDeviceWindow(*(new QOpenGLWindowPrivate(Q_NULLPTR, updateBehavior)), parent)
{ {
setSurfaceType(QSurface::OpenGLSurface); 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. \return the update behavior for this QOpenGLWindow.
*/ */
@ -413,6 +427,15 @@ QOpenGLContext *QOpenGLWindow::context() const
return d->context.data(); 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. The framebuffer object handle used by this window.

View File

@ -59,6 +59,7 @@ public:
}; };
explicit QOpenGLWindow(UpdateBehavior updateBehavior = NoPartialUpdate, QWindow *parent = 0); explicit QOpenGLWindow(UpdateBehavior updateBehavior = NoPartialUpdate, QWindow *parent = 0);
explicit QOpenGLWindow(QOpenGLContext *shareContext, UpdateBehavior updateBehavior = NoPartialUpdate, QWindow *parent = 0);
UpdateBehavior updateBehavior() const; UpdateBehavior updateBehavior() const;
bool isValid() const; bool isValid() const;
@ -67,6 +68,7 @@ public:
void doneCurrent(); void doneCurrent();
QOpenGLContext *context() const; QOpenGLContext *context() const;
QOpenGLContext *shareContext() const;
GLuint defaultFramebufferObject() const; GLuint defaultFramebufferObject() const;