Jump to content
  • Advertisement
Sign in to follow this  
pcmattman

Dirty Rectangles

This topic is 4070 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Can anyone give me any hints on dirty rectangles? I'm working on a GUI that currently goes extremely slow because every time I want to blit it back to the screen I'm copying the entire buffer. My problem is, how are dirty rectangles implemented? My current understanding: If I have an 800x600 screen I can divide this into virtual rectangles in which portions of the screen are drawn, and when one changes a bit is set to 1 in some index list, which is used by the blitter to find which rectangles to draw, and which to leave.

Share this post


Link to post
Share on other sites
Advertisement
Sorry thats not what dirty rects are.

Traditional dirty rect system involves building an array of rects that indicate the portions of the screen that needs to be blitted to the main buffer. The idea being to blit larger rects encompassing several smaller changes in one go.

This array is built each frame, it starts off empty and you push 'changed area' rects into it (that is any change like a button will have aminimum rect encompassing it, that is the changed area). The first rect will just be added to the array, the next rect is then compared against the first and if they overalp then the two are merged to create one big rect that replaces the orignal one in the array. If they don't overlap the new rect is added to the end of the array.

This process is repeated for all your 'changed area' rects. However at some stage you need to limit the max number of dirty rects you can have (e.g. 5 or maybe upto 10, you have to experiment to find the best number). Otherwise you'd end up with a rect per changed area more or less, gaining no benifit.

So what to do if you have a max of 5 dirty rects and a sixth rect that doesn't overlap? You determine which rect in the array when merged with the new rect takes up the least amount of area. However you can't simply replace the rect in the array with the new merged rect. First you delete the rect to be replaced from the array, then you test the new merged rect against all the remaining rects in the array to see if any overlap now (since the rect has changed from the original 'changed rect' fed in). If there is an overlap then the two rects are merged together, otherwise the new merged rect is added to the end of the array.

At the end of the process you'll have an arrya of rects to blit to the buffer

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!