我使用QQuickControls 2 (SwipeView)和OpenSceneGraph进行3d渲染。使用QQuickFramebufferObject进行集成。
自从我介绍了一个SwipeView之后,我观察到我的图形用户界面有些闪烁。
我已经找了很长时间的医生(它可能是字面上的数周),完全不知道为什么我会有这种闪烁。
这是一段关于错误行为的视频 (闪烁开始于20岁左右)。
这是我的渲染代码:
class OsgRenderer : public QQuickFramebufferObject::Renderer
{
public:
explicit OsgRenderer();
QOpenGLFramebufferObject *createFramebufferObject(const QSize &size) LC_OVERRIDE;
void synchronize(QQuickFramebufferObject* item) LC_OVERRIDE;
void render() LC_OVERRIDE;
protected:
friend class OsgWindow;
OsgItem* m_osgItem;
};
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();
}知道那是从哪里来的吗?
发布于 2017-08-21 22:32:32
通常,让QtQuick和OSG都呈现到相同的OpenGL上下文并不是一个好主意。
OSG在帧之间保持GL状态,但Qt可能在“外部”修改它,而不通知osg,这可能会导致呈现问题。
更可靠的方法是让它们使用单独(和共享) GL上下文,并将的上下文复制到Qt使用的纹理中。
我已经在这里成功地实现了这个方法:https://github.com/rickyviking/qmlosg,但是还没有用QtQuick的最新版本对它进行测试。
在这里可以找到更最新的集成:https://github.com/podsvirov/osgqtquick。
https://stackoverflow.com/questions/45802323
复制相似问题