I just started playing with SDL yesterday, and pretty quickly ran into
a problem with screen updates. Calls to UpdateRect() do not always
result in an image being drawn on the screen. Rather, after a number
of calls to UpdateRect a vaguely rectangular portion of the
window/screen may be updated, but not necessarily the entire portion
that ought to have been updated. I am reasonably confident that my
update rectangles are correct, as some of the time UpdateRect()
behaves as I would expect. Also, in windowed mode, moving my window
off the screen and back on will update regions that went off the
screen.
NB: I am using SDL 1.2 Mac OS X.
I have seen a number of questions like these in a cursory search of
the mailing list archives, but I have not yet seen an explanation or
solution. Any suggestions?
You shouldn’t be using SDL_UpdateRect() to do multiple dirty rects per
frame, as the cost of SDL_UpdateRect() is very - dare I say extremely
- high. The reason is that each time you call UpdateRect() or
UpdateRects() or Flip(), the window server copies the region you
specified to the display, in sync with the retrace of the monitor
(VBL), and possibly involving compositing if the window is occluded.
Even if there is no compositing required, just the sync with the VBL
causes a huge hit while the CPU is idle waiting for the CRT beam to go
by.
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.
Note that SDL_UpdateRects() is the low-level function. SDL_UpdateRect()
and SDL_Flip() call SDL_UpdateRects().
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.
Benchmarking has shown that the best performance on Mac OS X is using a
software fullscreen surface (SDL_SWSURFACE | SDL_FULLSCREEN) of the bit
depth you desire (lower bit depths are faster).
If you are using 10.2 (Jaguar), I am aware of the flickering issue in
windowed mode (which is actually different from your problem it seems)
and I have a fix which should make it into SDL soon.
Cheers,
DarrellOn Saturday, September 14, 2002, at 12:17 PM, pchans at wm.edu wrote: