Make multisampling more robust in QOpenGLFramebufferObject

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 <paul.tvete@digia.com>
Reviewed-by: Kimmo Leppälä <kimmo.leppala@digia.com>
This commit is contained in:
Laszlo Agocs 2014-06-04 15:54:25 +02:00 committed by The Qt Project
parent fce9c2dd26
commit d1c0015546
2 changed files with 9 additions and 2 deletions

View File

@ -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) {

View File

@ -131,6 +131,7 @@ public:
GLenum target;
QSize size;
QOpenGLFramebufferObjectFormat format;
int requestedSamples;
uint valid : 1;
QOpenGLFramebufferObject::Attachment fbo_attachment;
QOpenGLExtensions funcs;