本文介绍了在 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 中的两种方法的比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-29 01:49
查看更多