如何优化组合图形操作?
这是一个场景,我将调用一系列用于绘画的操作,
QPainter p(this);
1)。 p.fillRect(0,0,320,240, RED_COLOR)
2) p.drawLine(0,0,100,100, BLUE_COLOR)
3) p.fillRect(0,0,320,240, YELLOW_COLOR)
现在我希望画家不应该先绘制 FillRect 函数。 它不应该画线。 它应该只执行最后一个操作。
有什么办法可以在 Qt 中实现这种优化吗?
任何库都支持这种类型的绘图/绘画优化吗?
Here is a Scenario, A series of operations that I will call for painting,
QPainter p(this);
1). p.fillRect(0,0,320,240, RED_COLOR)
2) p.drawLine(0,0,100,100, BLUE_COLOR)
3) p.fillRect(0,0,320,240, YELLOW_COLOR)
Now I want that painter should not draw first FillRect Function.
It should not draw line.
It should only perform last operation.
Is there any way to achive this optimization in Qt.
Is this type of drawing/painting optimizations are supported by any library?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
简而言之,不。然而,离屏渲染通常很快,并且 Qt 双缓冲区小部件适合您。 绘制到 QImage 或 QPixmap 也可以在非 GUI 线程中完成,这样你就可以多线程绘画。 QPixmaps 还具有 QPixmapCache 的优点。
您可以根据绘制命令的创建方式自行进行优化。如果您在开始时知道所有命令,则可以使用一堆形状,并且如果堆栈的顶部包含在最后创建的形状内,则不要绘制它。
但是,您应该分析这部分代码,看看它是否真的有所收获。过早的微观优化通常会导致浪费精力。
我将从离屏渲染开始(如果可能的话,多线程),如果这确实太慢,请尝试其他步骤。然而,在大多数情况下,标准绘制方法足够快。
In short, no. However, off-screen rendering is generally fast and Qt double-buffers widgets for you. Painting to QImage or QPixmap can also be done in non-GUI threads, so you can multi thread the painting. QPixmaps also have the advantage of QPixmapCache.
You could do the optimization yourself depending on how the paint commands are created. If you know all the commands at the time you start, you could use a stack of shapes and if the top of the stack is contained within the last created shape, don't draw it.
However, you should profile this section of code to see if it really is gaining anything. Premature micro-optimization often leads to wasted effort.
I would start with offscreen rendering (multi threaded if possible), if that really is too slow, try other steps. However, in most cases the standard paint methods will be fast enough.
您始终可以将复杂的场景绘制到 QPixmap 中,然后仅在绘制时对该像素图进行 blit。当然,当场景发生变化时(例如,调整大小、其中的状态发生变化等),它需要更新。
You can always paint your complex scene into a QPixmap and then only blit that pixmap when painting happens. Of course, it needs to be updated when the scene changes (e.g. it is resized, a state something in it changed, etc.)
如果您正在寻找显示列表渲染优化,特别是示例中的遮挡测试,那么我认为 Qt 本身不提供这样的功能。
您可能想看看 OpenGL 是否具有此功能。如果是这样,那么也许绘制 QGLWidget 会得到你想要的东西?
If you are looking for display list rendering optimization, specifically occlusion test in your example, then I don't think Qt itself provides such function.
You may want to see if OpenGL has this capability. If so, then maybe drawing to a QGLWidget will get what you want?