diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/kernel/qopenglwindow.cpp | 25 | ||||
-rw-r--r-- | src/gui/kernel/qopenglwindow.h | 1 | ||||
-rw-r--r-- | src/widgets/kernel/qopenglwidget.cpp | 17 |
3 files changed, 41 insertions, 2 deletions
diff --git a/src/gui/kernel/qopenglwindow.cpp b/src/gui/kernel/qopenglwindow.cpp index c58e296b5a..741df78407 100644 --- a/src/gui/kernel/qopenglwindow.cpp +++ b/src/gui/kernel/qopenglwindow.cpp @@ -336,6 +336,31 @@ QOpenGLWindow::QOpenGLWindow(QOpenGLContext *shareContext, UpdateBehavior update { 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. */ diff --git a/src/gui/kernel/qopenglwindow.h b/src/gui/kernel/qopenglwindow.h index 6b64271b7b..86c51676f8 100644 --- a/src/gui/kernel/qopenglwindow.h +++ b/src/gui/kernel/qopenglwindow.h @@ -60,6 +60,7 @@ public: explicit QOpenGLWindow(UpdateBehavior updateBehavior = NoPartialUpdate, QWindow *parent = 0); explicit QOpenGLWindow(QOpenGLContext *shareContext, UpdateBehavior updateBehavior = NoPartialUpdate, QWindow *parent = 0); + ~QOpenGLWindow(); UpdateBehavior updateBehavior() const; bool isValid() const; diff --git a/src/widgets/kernel/qopenglwidget.cpp b/src/widgets/kernel/qopenglwidget.cpp index 63ef4d6cc6..ae1231b8c6 100644 --- a/src/widgets/kernel/qopenglwidget.cpp +++ b/src/widgets/kernel/qopenglwidget.cpp @@ -862,10 +862,23 @@ QOpenGLWidget::QOpenGLWidget(QWidget *parent, Qt::WindowFlags f) } /*! - Destroys the widget - */ + The QOpenGLWidget'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 widget. + + \warning if you have objects wrapping OpenGL resources (such as + QOpenGLBuffer, QOpenGLShaderProgram, etc.), as members of a OpenGLWidget + 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 +*/ QOpenGLWidget::~QOpenGLWidget() { + makeCurrent(); } /*! |