[SDL] UpdateRects sketchy

Nick Whitelegg bssnrw at bath.ac.uk
Sun Sep 15 01:40:01 PDT 2002

> Each frame, pass all of your dirty rects together to SDL_UpdateRects() 
> - this minimizes the penalty associated with the VBL since all the 
> rects are processed at the same time. Also, that should solve the 
> problem with some areas not redrawing at the same time.

Is this always the best solution though? I haven't got round to
experimenting, but say you had a 2D game where there were a number of
moving sprites plus various (occasionally only updated) status info like
score and lives. What I tend to do (e.g. for my ZXLIB C++ game library) -
and, like I said,
I haven't tested this yet - is use UpdateRects() for the sprites (as they
move each time) but, for the scores, just blit them and update them as
needed as they are only occasionally updated. Otherwise (I'm using the STL
vector container to store my update rects) I'd have to add in the score
update rectangle to the list of update rectangles each time I want to
update it, do the updating with UpdateRects(), then remove the score
update rectangle from the list of "dirty" rects. At a guess, this seems
slower but I may be wrong?
> For even better performance, in the case you have a lot of rects to 
> pass per frame or most of the screen area is updated, try tossing out 
> dirty rects altogether and call SDL_UpdateRect (screen,0,0,0,0). 
> Updating the whole screen can be faster since the window server has 
> less work to do.

This (aka SDL_Flip() I presume) seems to be extraordinarily slow on my
system (X3.3.6, 16bpp display, SDL1.2.1, windowed, software surface) -
don't know why. 


More information about the SDL mailing list