问题描述
问题主要在标题中确定.我尝试了Qt的示例( 2dpainting )并注意到,如果我尝试在QGLWidget上绘图,那么相同的代码会消耗更多的CPU能力,而如果我尝试简单地在QWidget上绘图,则消耗更少的CPU能力.我认为QGLWidget应该更快.还有一个有趣的现象:在QGLWidget中,抗锯齿提示似乎被忽略了.
The problem mainly is determined in the title. I tried out the Qt's example (2dpainting) and noticed, that the same code consumes more CPU power if I try to draw on QGLWidget and less if I try to draw simply on QWidget. I thought that the QGLWidget should be faster. And one more interesting phenomenon: In QGLWidget the antialiasing hint seems to be ignored.
OpenGL版本:3.3.0
OpenGL version: 3.3.0
那为什么呢?
推荐答案
首先,请注意您链接到的文档底部的文本:
Firstly, note this text at the bottom of the documentation that you link to:
此外,并非总是保证硬件渲染比软件渲染快.这完全取决于要求渲染器执行的操作.
Putting that aside, hardware rendering is not always guaranteed to be faster than software rendering; it all depends upon what the renderer is being asked to do.
如果要渲染的项目的目标不断变化,那么软件可以超越硬件的例子是.因此,如果您有一个绘制程序来绘制一条由不断移动的鼠标创建的线,并且该绘制程序是通过将点添加到每帧绘制的绘制路径上来实现的,则硬件渲染器将不断受到流水线停滞的影响,作为新的点被添加到画家路径.从停顿中建立图形管线需要花费时间,这不是软件渲染器必须处理的事情.
An example of where software can exceed hardware is if the goal of the item being rendered is constantly changing. So, if you have a drawing program that draws a line being created by the mouse being constantly moved and it is implemented by adding points to a painter path that is drawn every frame, a hardware renderer will be subject to constant pipeline stalls as new points are added to the painter path. Setting up the graphics pipeline from a stall takes time, which is not something a software renderer has to deal with.
在您询问的2dPainting示例中,执行绘画调用的helper类正在做很多不必要的工作;保存画家状态;设置笔/刷子;旋转画家;恢复画笔.所有这些在硬件上的开销要大于软件上的开销.要真正看到硬件渲染优于软件,先计算对象在渲染循环(绘画功能)之外的位置,然后不执行任何实际将绘画放置在绘画功能中的操作,这可能会显示出明显的区别.
In the 2dPainting example you ask about, the helper class, which performs the paint calls, is doing a lot of unnecessary work; saving the painter state; setting the pen / brush; rotating the painter; restoring the brush. All of this is a bigger overhead in hardware than software. To really see hardware rendering outperform software, pre-calculating the objects' positions outside of the render loop (paint function) and then doing nothing put actually rendering in the paint function is likely to display a noticeable difference here.
最后,关于抗锯齿,您链接到的文档指出:如果系统的OpenGL驱动程序支持所需的扩展名,则QGLWidget也将使用抗锯齿"
Finally, regarding anti-aliasing, the documentation that you linked to states: "the QGLWidget will also use anti-aliasing if the required extensions are supported by your system's OpenGL driver"
这篇关于QGLWidget比QWidget慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!