OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

QtQuickFrameBufferObject and GraphicsContexts


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
arennuit
User


Joined: 06 Dec 2013
Posts: 45

PostPosted: Tue Aug 22, 2017 4:51 pm    Post subject:
QtQuickFrameBufferObject and GraphicsContexts
Reply with quote

Hi all

I have integrated OSG within QQuick 2 via QtQuickFramebufferObject, it is working great with complex scenes and within a complex application behind the hood, except for 1 point: I sometimes observe flickering of the whole window (it is not only the 3d view that flickers but the whole application window - check the video here). It is not periodic, only every now and then, it can get crazy for a few seconds and then calms down.

In QtQuick the windowing system is actually rendered in OpenGL (hence the complexity). QtQuickFramebufferObject provides you with the tools to design a custom 3d item, and is thus the preferred way to implement a 3d view.

QtQuickFramebufferObject has you define a renderer and create a Qt compatible GL framebuffer in a function called by the QtQuick framework

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


it then has you write a render function also called by the QtQuick 2 framework, this is where I call my OSG rendering
Code:

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();
}


The QtQuick framework then merges the framebuffer in which I rendered with its own rendering to display the final image.

Now I suspect my flickering issue comes from a problem of GL context mix-up between QtQuick and OSG.

So I have inherited osgViewer::GraphicsWindowEmbedded to use as custom GraphicsContext which binds and releases the framebuffer created above:
Code:

bool OsgWindow::makeCurrentImplementation()
{
    if (!m_renderer)
        return false;

    if (!m_renderer->framebufferObject())
        return false;

    return m_renderer->framebufferObject()->bind();
}

bool OsgWindow::releaseContextImplementation()
{
    if (!m_renderer)
        return false;

    if (!m_renderer->framebufferObject())
        return false;

    return m_renderer->framebufferObject()->release();
}


Does that ensure me that the OSG rendering in frame() is written to this FBO?

Also as far as I know, the GL context is kept in OsgWindow (it inherits osgViewer::GraphicsWindowEmbedded as stated above), but is it reapplied at each frame? i.e. the GL context is modified by QtQuick's own GL rendering but am I sure that it is put back in place for OSG's correct rendering when I call frame()? If not, is there a way for me to enforce OSG's GL context is not modified by QtQuick?

QtQuick's GL context is put back at the end of each render() thanks to m_osgItem->window()->resetOpenGLState(); but is there such a feature for OSG?

Thanks a lot,

Antoine
Back to top
View user's profile Send private message
Konstantin Podsvirov
Guest





PostPosted: Tue Aug 22, 2017 7:21 pm    Post subject:
QtQuickFrameBufferObject and GraphicsContexts
Reply with quote

Hello Antoine!

22.08.2017, 19:51, "Antoine Rennuit" <>:
Quote:
Hi all

I have integrated OSG within QQuick 2 via QtQuickFramebufferObject, it is working great with complex scenes and within a complex application behind the hood, except for 1 point: I sometimes observe flickering of the whole window (it is not only the 3d view that flickers but the whole application window - check the video here (https://youtu.be/NlAxvTAVpl0)). It is not periodic, only every now and then, it can get crazy for a few seconds and then calms down.

In QtQuick the windowing system is actually rendered in OpenGL (hence the complexity). QtQuickFramebufferObject provides you with the tools to design a custom 3d item, and is thus the preferred way to implement a 3d view.

QtQuickFramebufferObject has you define a renderer and create a Qt compatible GL framebuffer in a function called by the QtQuick framework

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

it then has you write a render function also called by the QtQuick 2 framework, this is where I call my OSG rendering

Code:

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();
}

The QtQuick framework then merges the framebuffer in which I rendered with its own rendering to display the final image.

Now I suspect my flickering issue comes from a problem of GL context mix-up between QtQuick and OSG.

So I have inherited osgViewer::GraphicsWindowEmbedded to use as custom GraphicsContext which binds and releases the framebuffer created above:

Code:

bool OsgWindow::makeCurrentImplementation()
{
    if (!m_renderer)
        return false;

    if (!m_renderer->framebufferObject())
        return false;

    return m_renderer->framebufferObject()->bind();
}

bool OsgWindow::releaseContextImplementation()
{
    if (!m_renderer)
        return false;

    if (!m_renderer->framebufferObject())
        return false;

    return m_renderer->framebufferObject()->release();
}

Does that ensure me that the OSG rendering in frame() is written to this FBO?

Also as far as I know, the GL context is kept in OsgWindow (it inherits osgViewer::GraphicsWindowEmbedded as stated above), but is it reapplied at each frame? i.e. the GL context is modified by QtQuick's own GL rendering but am I sure that it is put back in place for OSG's correct rendering when I call frame()? If not, is there a way for me to enforce OSG's GL context is not modified by QtQuick?

Thanks a lot,

Antoine

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=71500#71500



Please review source code of the other similar projects:

a) osgQtQuick

https://github.com/podsvirov/osgqtquick

b) qmlosg

https://github.com/rickyviking/qmlosg

c) QtQuick2OSGItem

https://bitbucket.org/leon_manukyan/qtquick2osgitem

Perhaps you will find answers to your questions or help develop another project.

--
Regards,
Konstantin Podsvirov - osgQtQuick author


------------------
Post generated by Mail2Forum
Back to top
arennuit
User


Joined: 06 Dec 2013
Posts: 45

PostPosted: Wed Aug 23, 2017 7:33 am    Post subject:
Reply with quote

Hello Konstantin,

I am afraid my current framework already comes from the understanding of the examples you mention, especially https://bitbucket.org/leon_manukyan/qtquick2osgitem which is most up-to-date and uses the now recommended QQuickFramebufferObject.

Any more idea?

Thanks a lot anyways,

Antoine
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum



Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP