Hi,
Selenic wrote:
Brendan wrote:
In the past I've also used an additional "modified/unmodified" flag for each horizontal line, so the entire line is skipped if the drawing code didn't touch it (and got very good results with this technique, especially for menus and things where only a small part of the screen changes between frames).
Couldn't you optimise this even more? You could include a 'update this rectangle' function, which would allow the comparison to only scan relevant areas of video memory, potentially improving performance hugely (especially when using VBE-based high resolutions, where you have lots of memory to scan but no acceleration)
Using "dirty rectangles" can work (and can be faster) but it's complex (and can be slower).
For example, imagine you've got 12 dirty rectangles that all overlap in some way or another. If you use naive code to update all pixels in each dirty rectangle, then pixels in areas that overlap would be updated multiple times for no reason, which is bad.
A better (but more complex method) would be: for each horizontal line of pixels, find the intersections with all dirty rectangles and only update pieces of the horizontal line once. For example, if the horizontal line intersects with the left edge of the first dirty rectangle, the left edge of the second dirty rectangle, the right edge of the first dirty rectangle and then the right edge of the second dirty rectangle; then you know the dirty rectangles overlap and you can update pixels from the left edge of the first dirty rectangle to the right edge of the second dirty rectangle. In this case you'd minimise drawing, but checking for intersections and overlaps could be more work than it saves (if you're using a "change buffer" too).
The other thing to consider is whether or not the extra complexity is justified. With "reasonable" blitting code, the majority of the overhead ends up being in the drawing code. For an example, for my current code, drawing the screen costs about 4 times as much as dithering, and blitting to screen (using a "change buffer" but without any "modified/unmodified" flag for each horizontal line) is much faster than the dithering. In this case improving the blitting would make an insignificant difference to performance (but would also make a massive different to code maintainability, and make the drawing slower).
Cheers,
Brendan