summaryrefslogtreecommitdiffstats
path: root/src/gui/opengl/qopenglfunctions.cpp
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2023-07-21 13:48:35 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2023-07-25 23:05:50 +0200
commit8cc8bbb466fb871585bfa1d5c56fc8bc6d6c8a96 (patch)
tree53bcdf2fc7b1e125fb87f1abdcce0fbc3766725f /src/gui/opengl/qopenglfunctions.cpp
parentabe7c77d6d095c684f2e725f02638f062aea029c (diff)
QOpenGLWidget: use (and prefer) InvalidateFramebuffer
Desktop GL does not have the GL_EXT_discard_framebuffer extension at all. Instead, it may have GL_ARB_invalidate_subdata. Furthermore, GLES >= 3.0 and GL >= 4.3 both support FBO invalidation through glInvalidateFramebuffer. Extend the semantics of OpenGLExtension::DiscardFramebuffer to mean that *any* possibility above is supported, and wrap it in a helper function that calls whatever support is present. (This is all private API anyhow.) Technically speaking glInvalidateFramebuffer supports a superset of what glDiscardFramebufferEXT supports, but we never use such superset, and the two APIs are otherwise identical. Then, make QOpenGLWidget call that wrapper. Change-Id: I64e042daf51493d3834c3ba1b53ae6e224bbc4ed Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'src/gui/opengl/qopenglfunctions.cpp')
-rw-r--r--src/gui/opengl/qopenglfunctions.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/gui/opengl/qopenglfunctions.cpp b/src/gui/opengl/qopenglfunctions.cpp
index 0b760eb2dd..c9352fbc31 100644
--- a/src/gui/opengl/qopenglfunctions.cpp
+++ b/src/gui/opengl/qopenglfunctions.cpp
@@ -365,6 +365,7 @@ static int qt_gl_resolve_extensions()
| QOpenGLExtensions::FramebufferBlit
| QOpenGLExtensions::FramebufferMultisample
| QOpenGLExtensions::Sized8Formats
+ | QOpenGLExtensions::DiscardFramebuffer
| QOpenGLExtensions::StandardDerivatives
| QOpenGLExtensions::ETC2TextureCompression
| QOpenGLExtensions::HalfFloatVertex;
@@ -450,6 +451,9 @@ static int qt_gl_resolve_extensions()
if (format.version() >= qMakePair(3, 3))
extensions |= QOpenGLExtensions::TextureSwizzle;
+ if (format.version() >= qMakePair(4, 3) || extensionMatcher.match("GL_ARB_invalidate_subdata"))
+ extensions |= QOpenGLExtensions::DiscardFramebuffer;
+
if (extensionMatcher.match("GL_ARB_map_buffer_range"))
extensions |= QOpenGLExtensions::MapBufferRange;
@@ -5051,7 +5055,23 @@ QOpenGLExtensionsPrivate::QOpenGLExtensionsPrivate(QOpenGLContext *ctx)
MapBuffer = RESOLVE(MapBuffer);
GetBufferSubData = RESOLVE(GetBufferSubData);
DiscardFramebuffer = RESOLVE(DiscardFramebuffer);
- }
+}
+
+void QOpenGLExtensions::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
+{
+ Q_D(QOpenGLExtensions);
+ Q_ASSERT(QOpenGLExtensions::isInitialized(d));
+ Q_ASSERT(d->f.InvalidateFramebuffer || d->DiscardFramebuffer);
+
+ // On GLES >= 3 we prefer glInvalidateFramebuffer, even if the
+ // discard extension is present
+ if (d->f.InvalidateFramebuffer)
+ d->f.InvalidateFramebuffer(target, numAttachments, attachments);
+ else
+ d->DiscardFramebuffer(target, numAttachments, attachments);
+
+ Q_OPENGL_FUNCTIONS_DEBUG
+}
void QOpenGLExtensions::flushShared()
{