比较两种在Qt中将原始OpenGL渲染到QML

比较两种在Qt中将原始OpenGL渲染到QML

本文介绍了比较两种在Qt中将原始OpenGL渲染到QML UI中的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据文章,有两种主要方法可将原始OpenGL渲染到其UI由QtQuick的场景图管理的应用程序中.简而言之,它们是(根据我的理解):

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):

  • 通过QtQuick公开的一些API以手写代码调用原始OpenGL方法,而这些代码已挂接到场景图的渲染循环中.
  • 将场景的原始OpenGL部分渲染到QQuickFramebufferObject,该对象被视为场景图中的组件,并且本身被渲染为纹理.

这两种方法的优点/缺点是什么?

What are the advantages/disadvantages of the two approaches?

推荐答案

QQuickWindow::beforeRendering()QQuickWindow::afterRendering()信号的问题在于,从其插槽完成的所有OpenGL绘制都将适当地位于渲染的Qt Quick场景之下或之上.如果这对您足够好-即您只想绘制自定义OpenGL背景或某种叠加层,然后继续即可.

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.

如果您需要更多,即.使用OpenGL渲染放置在场景图中的某些QtQuick项,然后必须使用第二个选项:将OpenGL渲染到用作某些QtQuick项上的纹理的帧缓冲对象.正如您链接到状态的文档文章一样,它为您提供了更多的可能性(使用多个渲染上下文或什至多个渲染线程),但同时也会带来性能成本.实施起来也比较麻烦.

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.

通常,由于选项1)通常不足,因此您不得不选择2).据我所知,这是在QtQuick场景中使用原始OpenGL的唯一方法.

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.

这篇关于比较两种在Qt中将原始OpenGL渲染到QML UI中的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 01:46