summaryrefslogtreecommitdiffstats
path: root/src/openglwidgets/qopenglwidget.cpp
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2023-08-28 17:00:42 +0200
committerLaszlo Agocs <laszlo.agocs@qt.io>2023-09-04 11:46:29 +0200
commit7fbccd1900ff61d8bd980f73b22f472347ae9046 (patch)
treebcd0ad6b2a6f3a2680b314089062869eb5e7dd47 /src/openglwidgets/qopenglwidget.cpp
parent9505305c403423f58e70471aaf55994bb734a0bd (diff)
QOpenGLWidget: Call glClear in the default paintGL implementation
Amends 8cc8bbb466fb871585bfa1d5c56fc8bc6d6c8a96. With the referenced patch framebuffer invalidation is preferred over clearing with a wider range of OpenGL implementations. This is good and is in line with the documentation. If an existing application does not do glClear() in their reimplemented paintGL(), that we cannot fix, and the docs never actually promised that a glClear() is done automatically. However, there is a special case: when one does not reimplement paintGL(). A QOpenGLWidget is expected to be usable without reimplementing any of its virtuals (i.e., QOpenGLWidget is constructible as-is without subclassing). It is then ideal if this does not lead to showing rendering artifacts due to having potentially random content in the (invalidated, not cleared) color buffer. This problem was never encountered before due to hitting the invalidate-instead-of-clear code path on a limited set of platforms (like with OpenGL ES) only. Do a glClear() in paintGL(). This won't effect the vast majority of applications, that reimplement this function, but plays nice for when it is not. It is in fact also in line with Qt 4's QGLWidget: that also used to do a glClear() in the default paintGL() implementation. Change-Id: I117ce1d3340f6d4d82cde1f52769a3b13ce367fb Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'src/openglwidgets/qopenglwidget.cpp')
-rw-r--r--src/openglwidgets/qopenglwidget.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/openglwidgets/qopenglwidget.cpp b/src/openglwidgets/qopenglwidget.cpp
index b85e699fa4..e4438d226d 100644
--- a/src/openglwidgets/qopenglwidget.cpp
+++ b/src/openglwidgets/qopenglwidget.cpp
@@ -1457,6 +1457,10 @@ void QOpenGLWidget::resizeGL(int w, int h)
other state is set and no clearing or drawing is performed by the
framework.
+ The default implementation performs a glClear(). Subclasses are not expected
+ to invoke the base class implementation and should perform clearing on their
+ own.
+
\note To ensure portability, do not expect that state set in initializeGL()
persists. Rather, set all necessary state, for example, by calling
glEnable(), in paintGL(). This is because some platforms, such as WebAssembly
@@ -1476,6 +1480,9 @@ void QOpenGLWidget::resizeGL(int w, int h)
*/
void QOpenGLWidget::paintGL()
{
+ Q_D(QOpenGLWidget);
+ if (d->initialized)
+ d->context->functions()->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
}
/*!