diff --git a/src/imports/qtcanvas3d/canvas3d.cpp b/src/imports/qtcanvas3d/canvas3d.cpp index 159e24db4a197010d13f6ffe1385fffff6aa9977..f1f62138e59d1e8645108cc80abb37de4cdc8d32 100644 --- a/src/imports/qtcanvas3d/canvas3d.cpp +++ b/src/imports/qtcanvas3d/canvas3d.cpp @@ -582,6 +582,23 @@ void Canvas::updateWindowParameters() } } +/*! + * \internal + * + * Blits the antialias fbo into the final render fbo. + * Returns the final render fbo handle. + */ +GLuint Canvas::resolveMSAAFbo() +{ + qCDebug(canvas3drendering).nospace() << "Canvas3D::" << __FUNCTION__ + << " Resolving MSAA from FBO:" + << m_antialiasFbo->handle() + << " to FBO:" << m_renderFbo->handle(); + QOpenGLFramebufferObject::blitFramebuffer(m_renderFbo, m_antialiasFbo); + + return m_renderFbo->handle(); +} + /*! * \internal */ @@ -791,14 +808,8 @@ void Canvas::renderNext() << " Emit paintGL() signal"; emit paintGL(); - // Resolve MSAA - if (m_contextAttribs.antialias()) { - qCDebug(canvas3drendering).nospace() << "Canvas3D::" << __FUNCTION__ - << " Resolving MSAA from FBO:" - << m_antialiasFbo->handle() - << " to FBO:" << m_renderFbo->handle(); - QOpenGLFramebufferObject::blitFramebuffer(m_renderFbo, m_antialiasFbo); - } + if (m_contextAttribs.antialias()) + resolveMSAAFbo(); // We need to flush the contents to the FBO before posting // the texture to the other thread, otherwise, we might diff --git a/src/imports/qtcanvas3d/canvas3d_p.h b/src/imports/qtcanvas3d/canvas3d_p.h index fe7f0d59d32470afefcb8739de7280fafdeda4f8..08be21a8aa2ecc99f06cf1fee8b8a0509d113a3a 100644 --- a/src/imports/qtcanvas3d/canvas3d_p.h +++ b/src/imports/qtcanvas3d/canvas3d_p.h @@ -93,6 +93,7 @@ public: void createFBOs(); void bindCurrentRenderTarget(); + GLuint resolveMSAAFbo(); uint fps(); diff --git a/src/imports/qtcanvas3d/context3d.cpp b/src/imports/qtcanvas3d/context3d.cpp index 234765abf2e81b94e8c63968850be93a01306aba..38e0487bc8a8818f344a2066fddc182a91caa182 100644 --- a/src/imports/qtcanvas3d/context3d.cpp +++ b/src/imports/qtcanvas3d/context3d.cpp @@ -5214,7 +5214,18 @@ void CanvasContext::readPixels(int x, int y, long width, long height, glEnums fo return; } + // Check if the buffer is antialiased. If it is, we need to blit to the final buffer before + // reading the value. + if (m_contextAttributes.antialias()) { + GLuint readFbo = m_canvas->resolveMSAAFbo(); + glBindFramebuffer(GL_FRAMEBUFFER, readFbo); + } + glReadPixels(x, y, width, height, format, type, bufferPtr); + + if (m_contextAttributes.antialias()) + m_canvas->bindCurrentRenderTarget(); + logAllGLErrors(__FUNCTION__); }