From d1c00155464fe9a8ce08216141ca978fe6415dcc Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 4 Jun 2014 15:54:25 +0200 Subject: Make multisampling more robust in QOpenGLFramebufferObject MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some drivers are reported to get confused when passing different sample counts (requested vs. actual) to the color and depth/stencil attachments. To overcome this, pass the requested sample count to all the attachments. Task-number: QTBUG-33406 Change-Id: I17b0e3dbbd78de2ab0f45e95164b4f326d47aeff Reviewed-by: Paul Olav Tvete Reviewed-by: Kimmo Leppälä --- src/gui/opengl/qopenglframebufferobject.cpp | 10 ++++++++-- src/gui/opengl/qopenglframebufferobject_p.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'src/gui/opengl') diff --git a/src/gui/opengl/qopenglframebufferobject.cpp b/src/gui/opengl/qopenglframebufferobject.cpp index 7d91d2c497..cd6468cccd 100644 --- a/src/gui/opengl/qopenglframebufferobject.cpp +++ b/src/gui/opengl/qopenglframebufferobject.cpp @@ -436,9 +436,9 @@ void QOpenGLFramebufferObjectPrivate::init(QOpenGLFramebufferObject *, const QSi samples = qBound(0, int(samples), int(maxSamples)); #endif + requestedSamples = samples; size = sz; target = texture_target; - // texture dimensions QT_RESET_GLERROR(); // reset error state GLuint fbo = 0; @@ -472,6 +472,9 @@ void QOpenGLFramebufferObjectPrivate::init(QOpenGLFramebufferObject *, const QSi valid = checkFramebufferStatus(ctx); if (valid) { + // Query the actual number of samples. This can be greater than the requested + // value since the typically supported values are 0, 4, 8, ..., and the + // requests are mapped to the next supported value. funcs.glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_SAMPLES, &samples); color_buffer_guard = new QOpenGLSharedResourceGuard(ctx, color_buffer, freeRenderbufferFunc); } @@ -542,7 +545,10 @@ void QOpenGLFramebufferObjectPrivate::initTexture(GLenum target, GLenum internal void QOpenGLFramebufferObjectPrivate::initAttachments(QOpenGLContext *ctx, QOpenGLFramebufferObject::Attachment attachment) { - int samples = format.samples(); + // Use the same sample count for all attachments. format.samples() already contains + // the actual number of samples for the color attachment and is not suitable. Use + // requestedSamples instead. + const int samples = requestedSamples; // free existing attachments if (depth_buffer_guard) { diff --git a/src/gui/opengl/qopenglframebufferobject_p.h b/src/gui/opengl/qopenglframebufferobject_p.h index 7a653bc16d..75348d1481 100644 --- a/src/gui/opengl/qopenglframebufferobject_p.h +++ b/src/gui/opengl/qopenglframebufferobject_p.h @@ -131,6 +131,7 @@ public: GLenum target; QSize size; QOpenGLFramebufferObjectFormat format; + int requestedSamples; uint valid : 1; QOpenGLFramebufferObject::Attachment fbo_attachment; QOpenGLExtensions funcs; -- cgit v1.2.3