Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-64757

QRenderTargetOutput cannot change its target texture when the new texture has the same size

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.9, 5.10, 5.11
    • Qt3D
    • None

    Description

      Have a QRenderTargetOutput, set a texture. Then later on, e.g. in a frame action, change it to another texture. The second texture should have the same size as the first (which is a pretty common case in techniques where one plays ping pong with two textures)

      This has no effect: in practice the output gets unchanged.

      Looking at GraphicsContext::activateRenderTarget the code looks suspicious (at first glance): there is nothing saying we hit the needsResize branch at the end when the texture (i.e. attachment.m_textureUuid) but not the size changes.

             } else {
                  fboId = m_renderTargets.value(renderTargetNodeId);
      
                  // We need to check if  one of the attachment was resized
                  bool needsResize = !m_renderTargetsSize.contains(fboId);    // not even initialized yet?
                  if (!needsResize) {
                      // render target exists, has attachment been resized?
                      GLTextureManager *glTextureManager = m_renderer->nodeManagers()->glTextureManager();
                      const QSize s = m_renderTargetsSize[fboId];
                      const auto attachments_ = attachments.attachments();
                      for (const Attachment &attachment : attachments_) {
                          GLTexture *rTex = glTextureManager->lookupResource(attachment.m_textureUuid);
                          needsResize |= (rTex != nullptr && rTex->size() != s);
                          if (attachment.m_point == QRenderTargetOutput::Color0)
                              m_renderTargetFormat = rTex->properties().format;
                      }
                  }
      
                  if (needsResize) {
                      m_glHelper->bindFrameBufferObject(fboId, GraphicsHelperInterface::FBODraw);
                      bindFrameBufferAttachmentHelper(fboId, attachments);
                  }
              }
      

      Could probably be worked on application side around by changing the entire QRenderTarget in the QRenderTargetSelector. (and that would likely be more efficient since we then just switch FBOs then instead of altering the framebuffer attachments all the time) Still, would be good to handle this somehow on QRenderTargetOutput level too.

      Update: Actually, there are very valid use cases when a texture changes and it is more appropriate to update that one attachment only, not create a whole new FBO (i.e. QRenderTarget). Think a technique that (infrequently) needs to steal the texture belonging to a QRenderTargetOutput, replacing it with a new one.

      Attachments

        Issue Links

          Activity

            People

              seanharmer Sean Harmer
              lagocs Laszlo Agocs
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: