tags:

views:

70

answers:

3

Hi,

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?

+1  A: 

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

Daniel Albuschat
Does not answer the question asked.
ypnos
+2  A: 

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.

Adam W
+1  A: 

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?

Stephen Chu