From f4e8dd2e191f062fa527dd5e6bdd7611f1e68d02 Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Fri, 24 Feb 2023 09:07:57 +0100 Subject: OpenGL SubmissionContext: reset m_renderTargetFormat for default FBO We rely on m_renderTargetFormat when doing render capture to know in whick internal format the currently bound FBO is. m_renderTargetFormat is reset once per surface change based on the QSurfaceFormat. However, when using custom RenderTargets, it gets overwritten in the call to SubmissionContext::activateRenderTarget which happens for each RenderView. If we switch back to the default FBO in a RenderView that follows one using a custom RenderTarget, both using the same surface, we failed to reset the m_renderTargetFormat and it would mistakenly remain to the value set for the custom RenderTarget. If a RenderCapture were to happen at that stage, this would lead to crashes as we would compute the capture buffer assuming a format that doesn't match that of the current FBO. Change-Id: I5c722f20857b23b5696617065c8f50406e10aea9 Reviewed-by: Mike Krus (cherry picked from commit 77823b3b678a586f90d1211fa27dddfbf1fe4e71) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp b/src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp index 2b4da1ec7..06557debc 100644 --- a/src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp +++ b/src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp @@ -471,6 +471,8 @@ void SubmissionContext::endDrawing(bool swapBuffers) void SubmissionContext::activateRenderTarget(Qt3DCore::QNodeId renderTargetNodeId, const AttachmentPack &attachments, GLuint defaultFboId) { GLuint fboId = defaultFboId; // Default FBO + resolveRenderTargetFormat(); // Reset m_renderTargetFormat based on the default FBO + if (renderTargetNodeId) { // New RenderTarget if (!m_renderTargets.contains(renderTargetNodeId)) { @@ -481,9 +483,10 @@ void SubmissionContext::activateRenderTarget(Qt3DCore::QNodeId renderTargetNodeI fboId = createRenderTarget(renderTargetNodeId, attachments); } } else { - fboId = updateRenderTarget(renderTargetNodeId, attachments, true); + fboId = updateRenderTarget(renderTargetNodeId, attachments, true); // Overwrites m_renderTargetFormat based on custom FBO } } + m_activeFBO = fboId; m_activeFBONodeId = renderTargetNodeId; m_glHelper->bindFrameBufferObject(m_activeFBO, GraphicsHelperInterface::FBODraw); @@ -613,6 +616,7 @@ QImage SubmissionContext::readFramebuffer(const QRect &rect) QImage::Format imageFormat; uint stride; + // m_renderTargetFormat is set when the current RV FBO is set in activateRenderTarget /* format value should match GL internalFormat */ GLenum internalFormat = m_renderTargetFormat; -- cgit v1.2.3