QQuickFramebufferObject: where is the custom FBO u

2019-07-20 13:26发布

问题:

I am currently integrating a custom OpenGL viewport within QML via QQuickFramebufferObject. I observe some flickering of the whole app window (not only of the QQuickFramebufferObject window) and I am wondering why.

My custom QQuickFramebufferObject::Renderer does create a separate FPO:

QOpenGLFramebufferObject* OsgRenderer::createFramebufferObject(const QSize &size)
{
    QOpenGLFramebufferObjectFormat format;
    format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
    return new QOpenGLFramebufferObject(size, format);
}

So I understand that Qt defines its own FBO type (QOpenGLFramebufferObject) so it can later use the FBO to mix it with its own GL rendering, is that right?

I then do all my rendering

void OsgRenderer::render()
{
    assert(m_osgItem);

    if ( !m_osgItem->getViewer() )
        return;

    // Without this line the model is not displayed in the second
    // and subsequent frames.
    QOpenGLContext::currentContext()->functions()->glUseProgram(0);

    // Ask OSG to render.
    m_osgItem->getViewer()->frame(); // WARNING: non-blocking (executed in a thread of its own - in a thread-safe way).

    // Reset OpenGl state for QtQuick.
    m_osgItem->window()->resetOpenGLState();
}

I expect QtQuick to actually gather my custom rendered FBO with its own rendering of the window after the call to render(), is that right?

My rendering is actually achieved in a separate context. In this context, how can it cause flickering? Any idea?