问题
According to this article, there are two main methods for rendering raw OpenGL into an application whose UI is otherwise managed by QtQuick's scene graph. In short, they are (according to my understanding):
- Calling raw OpenGL methods in hand-written code that is hooked into the scene graph's render loop through some APIs exposed by QtQuick.
- Rendering the raw OpenGL portion of your scene to a QQuickFramebufferObject, which is treated like a component in the scene graph and itself rendered as if it were a texture.
What are the advantages/disadvantages of the two approaches?
回答1:
The issue with QQuickWindow::beforeRendering()
or QQuickWindow::afterRendering()
signals is that all OpenGL drawing done from their slots will be appropriately under or over the rendered Qt Quick scene. If this is good enough for you — ie. you only want to draw a custom OpenGL background or some kind of overlay — then go for it.
If you need more, ie. use OpenGL to render some QtQuick Item that placed within the scene graph, then you have to go with the second option: rendering OpenGL to a framebufferobject that is used as a texture on some QtQuick Item. As the documentation article you have linked to states, it gives you more possibilities (using multiple rendering contexts or even multiple rendering threads) but also comes with performance cost. It is also more troublesome to implement.
Generally, as the option 1) is usually inadequate, you are forced to go with 2). It is the only way to use raw OpenGL within a QtQuick scene that I know of.
来源:https://stackoverflow.com/questions/27948211/comparison-of-two-approaches-to-rendering-raw-opengl-into-a-qml-ui-in-qt