diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2023-07-22 00:47:28 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2023-07-26 06:46:51 +0200 |
commit | 21d3bb9e7407f906232d01744a368bbfd4dbfc0f (patch) | |
tree | 8b08cb7dd634d5374dcf23c811aca72c18a1ce4b /src/openglwidgets/qopenglwidget.cpp | |
parent | 76e650045e342c977042195059a6eedd7809a260 (diff) |
QOpenGLWidget: invalidate the depth/stencil after rendering
We don't need them any more, only the color is used for compositing.
In principle this enables a driver to not writeback their contents into
main memory.
Change-Id: Ibde17af6c14c98ebdca956aaf902dfd728f9219c
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'src/openglwidgets/qopenglwidget.cpp')
-rw-r--r-- | src/openglwidgets/qopenglwidget.cpp | 57 |
1 files changed, 39 insertions, 18 deletions
diff --git a/src/openglwidgets/qopenglwidget.cpp b/src/openglwidgets/qopenglwidget.cpp index 1733706437..1abd210e42 100644 --- a/src/openglwidgets/qopenglwidget.cpp +++ b/src/openglwidgets/qopenglwidget.cpp @@ -553,7 +553,13 @@ public: void initialize(); void render(); - void invalidateFbo(); + static constexpr GLenum gl_color_attachment0 = 0x8CE0; // GL_COLOR_ATTACHMENT0 + static constexpr GLenum gl_depth_attachment = 0x8D00; // GL_DEPTH_ATTACHMENT + static constexpr GLenum gl_stencil_attachment = 0x8D20; // GL_STENCIL_ATTACHMENT + static constexpr GLenum gl_depth_stencil_attachment = 0x821A; // GL_DEPTH_STENCIL_ATTACHMENT + + void invalidateFboBeforePainting(); + void invalidateFboAfterPainting(); void destroyFbos(); @@ -946,11 +952,11 @@ void QOpenGLWidgetPrivate::render() } if (updateBehavior == QOpenGLWidget::NoPartialUpdate && hasBeenComposed) { - invalidateFbo(); + invalidateFboBeforePainting(); if (stereo && fbos[QOpenGLWidget::RightBuffer]) { setCurrentTargetBuffer(QOpenGLWidget::RightBuffer); - invalidateFbo(); + invalidateFboBeforePainting(); setCurrentTargetBuffer(QOpenGLWidget::LeftBuffer); } @@ -967,11 +973,15 @@ void QOpenGLWidgetPrivate::render() QOpenGLContextPrivate::get(ctx)->defaultFboRedirect = fbos[currentTargetBuffer]->handle(); q->paintGL(); + if (updateBehavior == QOpenGLWidget::NoPartialUpdate) + invalidateFboAfterPainting(); if (stereo && fbos[QOpenGLWidget::RightBuffer]) { setCurrentTargetBuffer(QOpenGLWidget::RightBuffer); QOpenGLContextPrivate::get(ctx)->defaultFboRedirect = fbos[currentTargetBuffer]->handle(); q->paintGL(); + if (updateBehavior == QOpenGLWidget::NoPartialUpdate) + invalidateFboAfterPainting(); } QOpenGLContextPrivate::get(ctx)->defaultFboRedirect = 0; @@ -979,32 +989,43 @@ void QOpenGLWidgetPrivate::render() flushPending = true; } -void QOpenGLWidgetPrivate::invalidateFbo() +void QOpenGLWidgetPrivate::invalidateFboBeforePainting() { QOpenGLExtensions *f = static_cast<QOpenGLExtensions *>(QOpenGLContext::currentContext()->functions()); if (f->hasOpenGLExtension(QOpenGLExtensions::DiscardFramebuffer)) { - const int gl_color_attachment0 = 0x8CE0; // GL_COLOR_ATTACHMENT0 - const int gl_depth_attachment = 0x8D00; // GL_DEPTH_ATTACHMENT - const int gl_stencil_attachment = 0x8D20; // GL_STENCIL_ATTACHMENT -#ifdef Q_OS_WASM - // webgl does not allow separate depth and stencil attachments - // QTBUG-69913 - const int gl_depth_stencil_attachment = 0x821A; // GL_DEPTH_STENCIL_ATTACHMENT - - const GLenum attachments[] = { - gl_color_attachment0, gl_depth_attachment, gl_stencil_attachment, gl_depth_stencil_attachment - }; -#else const GLenum attachments[] = { - gl_color_attachment0, gl_depth_attachment, gl_stencil_attachment - }; + gl_color_attachment0, + gl_depth_attachment, + gl_stencil_attachment, +#ifdef Q_OS_WASM + // webgl does not allow separate depth and stencil attachments + // QTBUG-69913 + gl_depth_stencil_attachment #endif + }; f->discardFramebuffer(GL_FRAMEBUFFER, GLsizei(std::size(attachments)), attachments); } else { f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); } } +void QOpenGLWidgetPrivate::invalidateFboAfterPainting() +{ + QOpenGLExtensions *f = static_cast<QOpenGLExtensions *>(QOpenGLContext::currentContext()->functions()); + if (f->hasOpenGLExtension(QOpenGLExtensions::DiscardFramebuffer)) { + const GLenum attachments[] = { + gl_depth_attachment, + gl_stencil_attachment, +#ifdef Q_OS_WASM + // webgl does not allow separate depth and stencil attachments + // QTBUG-69913 + gl_depth_stencil_attachment +#endif + }; + f->discardFramebuffer(GL_FRAMEBUFFER, GLsizei(std::size(attachments)), attachments); + } +} + void QOpenGLWidgetPrivate::destroyFbos() { delete fbos[QOpenGLWidget::LeftBuffer]; |