[SDL] SDL_UpdateRect

Darrell Walisser walisser at mac.com
Thu Jul 25 15:19:01 PDT 2002


On Thursday, July 25, 2002, at 03:34 PM, Neil Bradley wrote:

> I've read the documentation repeatedly and can't figure out what this
> function does. The docs say "Makes sure the given area is updated on the
> given screen. The rectangle must be confined within the screen 
> boundaries
> (no clipping is done)."
>
> I'm able to blit from a memory surface to a display surface without
> calling this function. How does SDL_UpdateRect actually work, or how 
> would
> it operate or be used when I'm using an in-system memory backbuffer and
> blitting deltas to a hardware surface?

If the display surface is SDL_HWSURFACE, then you don't have to call 
SDL_UpdateRect(). You are drawing directly to (visible) video memory. If 
you also set SDL_DOUBLEBUF, you have to call SDL_Flip() since you are 
drawing to offscreen video memory. SDL_UpdateRect() does nothing if the 
surface is a hardware surface, since it has nothing to do.

Otherwise, you have to call SDL_UpdateRects(). In this case, you are not 
drawing directly to video memory, you are drawing to some offscreen 
(system) memory area; hence, you must tell the windowing system to 
display the new area on the display (visible video memory).

So, if you always call SDL_UpdateRects() you don't have to worry about 
the situation where you run a system that doesn't have hardware 
surfaces; your program will still work if the system you run on can't 
get a hardware surface. <soap box>This is what everyone should do, 
because it works on every supported platform, and gives the best chance 
for portability of your app. Realize that on most targets you can't even 
*get* a hardware surface to scribble on.</soap box>.

In all actuality, drawing in system memory and using SDL_UpdateRects() 
can be faster for most applications because SDL_UpdateRects() can update 
video memory more efficiently than you (or SDL's blitters) can. There 
are also serious performance penalties to blits that must read pixels 
from the screen (alpha blits, in particular) when the SDL surface is in 
video memory.

-D





More information about the SDL mailing list