Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Interferences by using QQuickFramebufferObject and QQuickPaintedItem



  • Hi,
    I'm using Qml with e.g two items. The first consists a QQuickFramebufferObject and the second a QQuickPaintedItem. The QQuickFramebufferObject renders a terrain and by pressing on it the perspective angle is changing.

    ...
    Item {
         id: iFrameBuffer
          anchors.fill: parent
                  
          Render {
             anchors.fill: parent
             mirrorVertically: true
    
             MouseArea {
                 anchors.fill: parent
    
                 onClicked: parent.setAngle(0)
             }
         }
    }
    
    DCross {
       id: iCross
       width: parent.width * 0.28
       height: width
       anchors.centerIn: parent
    
    }
    ...
    

    If I set in DCross in C++

    setRenderTarget(QQuickPaintedItem::FramebufferObject);
    

    it comes to undesirable behavior.

    • win10: the app crashes

    • android:
      After pressing multiple times on it to recalculate the terrain with different perspective angles the QQuickFramebufferObject does not correctly display the terrain (looks like visually disorders/flickers).

    Using

    setRenderTarget(QQuickPaintedItem::Image);
    

    everything works fine.

    My question is now, is it possible that both items interfere because they maybe use the same framebuffer? Is there a special command for the QQuickFramebufferObject?

    Here a short version of the C++ part of the QQuickFramebufferObject

    Rend::Rend()
    {
        m_func = QOpenGLContext::currentContext()->functions();
        m_func->initializeOpenGLFunctions();
    
        m_func->glEnable(GL_DEPTH_TEST);
        m_func->glEnable(GL_CULL_FACE);
        m_func->glFrontFace(GL_CCW);
        m_func->glClearColor(0, 0, 0, 1);
    
        m_shaderProgram.addShaderFromSourceFile(QOpenGLShader::Vertex, ":/shd/vert.vsh");
        m_shaderProgram.addShaderFromSourceFile(QOpenGLShader::Fragment, ":/shd/frag.fsh");
        m_shaderProgram.link();
        m_shaderProgram.bind();
    
        ...
    }
    
    QOpenGLFramebufferObject* Rend::createFramebufferObject(const QSize &size) 
    {   
        QOpenGLFramebufferObjectFormat format;
        format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
        format.setSamples(0);
        
        return new QOpenGLFramebufferObject(size, format);
    }
    
    void Rend::render()
    {
        ...
    
        m_shaderProgram.bind();
    
        int mvpMatrixLoc = m_shaderProgram.uniformLocation("mvpMatrix");
        int colorLoc = m_shaderProgram.uniformLocation("color");
        m_shaderProgram.setUniformValue(mvpMatrixLoc, m_pMatrix * vMatrix * mMatrix);
        m_shaderProgram.setUniformValue(colorLoc, QColor(Qt::white));
    
        m_func->glClearColor(0, 0, 0, 1);
        m_func->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        m_geom->draw(&m_shaderProgram);
    
        m_shaderProgram.release();
    
        m_window->resetOpenGLState();
    }
    
    void Rend::synchronize(QQuickFramebufferObject *item)
    
    {
        m_fbo = static_cast<Fbo *>(item);
    
        m_window = m_fbo->window();
    
        m_alpha = m_fbo->angle();
    }
    

    Thxs in andvance...


Log in to reply