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

Can't create depth buffer with my own pixel format using QOpenGLTexture

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P3: Somewhat important
    • None
    • 6.4.1
    • GUI: OpenGL
    • None
    • Kubunt 22.04 + NVidia v520 drivers
      Qt from binary packages.
    • Linux/X11

    Description

      I want to create a float32 depth buffer for OpenGl ES 3 (and later WebGL via webassembly). I got it working with opengl commands, but not with the QOpenGLTexture class.

      These are the relevant opengl calls:

      f->glGenTextures(1, &m_frame_buffer_depth);
      f->glBindTexture(GL_TEXTURE_2D, m_frame_buffer_depth);
      {
          const auto level = 0;
          const auto internalFormat = GL_DEPTH_COMPONENT32F;
          const auto border = 0;
          const auto format = GL_DEPTH_COMPONENT;
          const auto type = GL_FLOAT;
          const auto data = nullptr;
          f->glTexImage2D(GL_TEXTURE_2D, level, internalFormat, 4, 4, border, format, type, data);
      }
      

      I tried to switch to QOpenGLTexture for a nicer API:

      m_depth_texture = std::make_unique<QOpenGLTexture>(QOpenGLTexture::Target::Target2D);
      m_depth_texture->setFormat(QOpenGLTexture::TextureFormat::D32F);
      m_depth_texture->setSize(800, 600);
      m_depth_texture->allocateStorage(QOpenGLTexture::Depth, QOpenGLTexture::PixelType::Float32);
      

      unfortunately, QOpenGLTexture::Depth and QOpenGLTexture::PixelType::Float32 get ignored and creating the texture fails. The reason is, that Qt tries to allocate immutable storage, and ignores the parameters when doing so:

      void QOpenGLTexturePrivate::allocateStorage(QOpenGLTexture::PixelFormat pixelFormat, QOpenGLTexture::PixelType pixelType)
      {
          // Resolve the actual number of mipmap levels we can use
          mipLevels = evaluateMipLevels();
      
          if (isUsingImmutableStorage())
              allocateImmutableStorage(); // -> debugger stepped in this one.
          else
              allocateMutableStorage(pixelFormat, pixelType);
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            lagocs Laszlo Agocs
            adamce Adam
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes