qt性能ߝ OpenGL
我不想在我的小部件(QPainter)的绘画功能中使用本机OpenGL来提高性能。 我看到有函数 QPainter::begin/endNativePainting(),可以帮助我。 但我找不到这方面的例子...... 我想知道这些功能是否成本低廉,或者每次使用它们都会降低性能? 2.我可以为我使用的所有小部件定义 beginNativePainting() 和 endNativePainting() ,而不是在我拥有的每个绘制函数中使用它们。
tnx 寻求任何帮助......
i wan't to use Native OpenGL in the paint function of my widgets(QPainter), to improve performance.
i saw that there is function QPainter::begin/endNativePainting(), that can help me.
but i can't find examples for that...
i wanted to know if those functions are low cost, or evry use of them reduce performance?
2.can i define beginNativePainting() and endNativePainting(), in general for all the widgets i use, instead of using that in every paint function i have.
tnx for any help....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
文档中有一些基本的示例代码:http://doc.qt。 io/qt-4.8/qpainter.html#beginNativePainting
函数本身的成本应该相当低,但调用它们可能仍然会导致明显的开销,因为 Qt 必须在 beginNativePainting 上刷新其内部绘画队列() 调用,并且可能必须假设一旦调用
endNativePainting()
一切都会改变。对于第二部分,我不确定我是否理解您的目标。基本上,如果你有一个 QPainter 对象,你可以调用一次
beginNativePainting()
。但您必须将其与endNativePainting()
调用相匹配。所以通常的地方是paint()方法。There is some basic example code right in the documentation: http://doc.qt.io/qt-4.8/qpainter.html#beginNativePainting
The functions themselves should be fairly low-cost, but calling them might still cause a noticeably overhead, because Qt has to flush its internal painting queue on the
beginNativePainting()
call and probably has to assume that everything is changed as soon asendNativePainting()
is called.For the second part I am not sure if I understand what you are aiming at. Basically if you have a QPainter object, you can call
beginNativePainting()
once. But you have to match it with anendNativePainting()
call. So the usual place would be the paint() method.Qt 使用一系列 OpenGL 功能来实现其 2D 绘画,包括自定义着色器和各种帧缓冲区。它使 OpenGL 陷入相当混乱的状态。
beginNativePainting
/endNativePainting
允许 Qt 的绘图引擎保存此上下文并在用户完成绘图后检索它。如果
xxxNativePainting
方法能做相反的事情(即自动保存和恢复 OpenGL 的用户配置),那就太好了,但是由于 Qt 允许直接调用 OpenGL 基元,因此如果不保存全局状态几乎是不可能的。大量的代码和潜在的严重性能影响。相反,这些方法只是保存 Qt 的内部 OpenGL 状态,而不是让用户代码在毫无意义的配置中启动(并且可能会随着每个新的 Qt 版本而改变),而是将 OpenGL 重置为“中性”状态。
这意味着,在开始/结束部分中,您将从一个干净的状态开始:没有着色器链接,没有顶点数组,大多数全局参数重置等。
与简单的
QGLWidget
/PaintGL 场景中,您可以一劳永逸地设置全局 OpenGL 状态,并且只需在每帧调用渲染基元,您将必须在调用
beginNativePainting
之后恢复几乎所有内容> (链接/绑定着色器、设置全局参数、选择并启用各种缓冲区等)。这也意味着你应该谨慎使用本土绘画。让每个小部件进行自定义绘制可能很快就会使您的渲染陷入困境。
Qt is using a range of OpenGL functionalities to implement its 2D painting, including custom shaders and various frame buffers. It puts OpenGL into a pretty messy state.
beginNativePainting
/endNativePainting
are there to allow Qt's drawing engine to save this context and retrieve it once the user is done drawing.It would have been nice to have the
xxxNativePainting
methods do the contrary (i.e. automatically save and restore user configuration of OpenGL), but since Qt allows to call OpenGL primitives directly, saving the global state is nigh impossible without tons of code and potential serious performance hit.Instead, these methods simply save Qt's internal OpenGL state and, rather than having user code start in a configuration that would be meaningless anyway (and likely to change with each new Qt release), reset OpenGL to a "neutral" state.
It means that, inside a begin/end section, you will start with a clean slate: no shader linked, no vertex array, most of global parameters reset, etc.
Contrary to a simple
QGLWidget
/PaintGL
scenario where you can afford to setup the global OpenGL state once and for all and simply call the rendering primitives each frame, you will have to restore pretty much everything just after the call tobeginNativePainting
(link/bind your shaders, set global parameters, select and enable various buffers, etc).It also means that you should use native painting sparringly. Having each single widget do custom painting might soon bring your rendering to its knees.