开发者

How to Optimize Combined Graphical Operations?

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/pain开发者_如何学JAVAting optimizations are supported by any library?


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.


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


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜