diff options
Diffstat (limited to 'src/gui/kernel/qopenglwindow.cpp')
| -rw-r--r-- | src/gui/kernel/qopenglwindow.cpp | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/src/gui/kernel/qopenglwindow.cpp b/src/gui/kernel/qopenglwindow.cpp index c37974c429b..f12032b1715 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<QOpenGLContext> context; + QOpenGLContext *shareContext; QScopedPointer<QOpenGLFramebufferObject> fbo; QScopedPointer<QOpenGLWindowPaintDevice> paintDevice; QOpenGLTextureBlitter blitter; @@ -317,12 +321,47 @@ 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); +} + +/*! + Destroys the QOpenGLWindow instance, freeing its resources. + + The OpenGLWindow's context is made current in the destructor, allowing for + safe destruction of any child object that may need to release OpenGL + resources belonging to the context provided by this window. + + \warning if you have objects wrapping OpenGL resources (such as + QOpenGLBuffer, QOpenGLShaderProgram, etc.) as members of a QOpenGLWindow + subclass, you may need to add a call to makeCurrent() in that subclass' + destructor as well. Due to the rules of C++ object destruction, those objects + will be destroyed \e{before} calling this function (but after that the + destructor of the subclass has run), therefore making the OpenGL context + current in this function happens too late for their safe disposal. + + \sa makeCurrent + + \since 5.5 +*/ +QOpenGLWindow::~QOpenGLWindow() +{ + makeCurrent(); +} + +/*! \return the update behavior for this QOpenGLWindow. */ QOpenGLWindow::UpdateBehavior QOpenGLWindow::updateBehavior() const @@ -414,6 +453,15 @@ QOpenGLContext *QOpenGLWindow::context() const } /*! + \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. When the update behavior is set to \c NoPartialUpdate, there is no separate |
