QML text rendering issue with custom OpenGL item a

2019-07-28 04:33发布

问题:

I've been working with the QmlOgre Qt example to make it work with Qt5 final. The original example itself looks fine now and behaves as intended. My code is here: https://github.com/advancingu/QmlOgre

However I found that there is an issue when a QML text item is modified either through changed signals emitted from C++ or from a simple timer in the sample QML scene. For example, I added a 10ms QML timer that simply increments a counter and assigns it to a text item. The corresponding code is here: https://github.com/advancingu/QmlOgre/tree/issue

What happens now is that on each frame, most characters (except one or two) of the text item randomly disappear. Which of them disappear changes with each frame, so there is a lot of flickering. The characters that do show are the correct ones and at the correct location.

My observation has been that this issue only appears on some application executions, so it very much looks like a threading issue (QmlEngine runs one thread dealing with QML object bindings, QML painting has its own thread in which Ogre lives / must live).

Anyone have ideas on why exactly this is happening or how this can be resolved?

  • Ogre version: 1.8.1
  • Qt version: 5.0.1 (5.1-dev from today has same issue)
  • OS/Distro: Ubuntu 12.04 64bit
  • Graphics driver: tried with Mesa 9.0 and FGLRX (both show it)

回答1:

Still not sure what caused the issue but I found a way to fix it by creating a separate OpenGL context in OgreNode to be used by Ogre. Of course this could cause performance to worsen, however this is still better than things not working reliably. Code in my repository is updated with the fix.



回答2:

In my case, I solved calling glPushAttrib(GL_ALL_ATTRIB_BITS) before the rendering and glPopAttrib() after. You should also ensure all drawing happens between beginNativePainting() and endNativePainting() (see http://doc.qt.io/qt-5.8/qpainter.html#beginNativePainting).



标签: qml qt5 ogre