[SDL] Screen syncronizing
david at olofson.net
Fri May 14 04:23:37 PDT 2004
On Friday 14 May 2004 01.57, Bo Jangeborg wrote:
> David Olofson wrote:
> >If you use (SDL_DOUBLEBUF | SDL_FULLSCREEN), SDL_Flip() *may* sync
> >with the retrace. Depends on the backend, OS and drivers. There is
> >usually no reliable way of achieving explicit "direct" retrace
> > sync (as in "SDL_WaitRetrace()"), and you can't really use it for
> > anything in a normal OS anyway (need an RTOS), so there isn't
> > much point in trying to implement it.
> >As to combining the "smart update" approach (SDL_UpdateRects())
> > with a double buffered display surface, you can have a look at my
> > Pig example:
> > http://olofson.net/examples.html
> >It's not trivial, but I think it's about as simple as a useful
> > "smart updating" solution gets if it has to support both "fake"
> > double buffering and hardware page flipping.
> How does the "fake" dubble buffering work ? Im not very good at
> reading C code
By "fake" double buffering, I mean a setup where making a new frame
visible is done by copying a shadow buffer into the display buffer,
as opposed to just swapping two display buffers.
What Pig does when hardware page flipping is not available is stay
away from SDL_Flip() and use SDL_UpdateRects() instead. That way, it
can get away with copying only the areas that have actually changed,
which is how you get those insane frame rates (hundreds or thousands
of fps) even without h/w accelerated blits.
Note that SDL gives you *either* double buffering with h/w page
flipping, *or* a single display buffer + s/w shadow buffer! That is,
if you want a s/w back buffer for fast rendering, you'll have to
create that yourself, and implement your own alternative to
SDL_UpdateRects(). Pig does that to avoid doing alpha blending (which
there is a lot of) directly into VRAM.
> Btw, the Pig game looks very smooth.
Yeah, that's the idea. ;-)
//David Olofson - Programmer, Composer, Open Source Advocate
.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,... |
`-----------------------------------> http://audiality.org -'
--- http://olofson.net --- http://www.reologica.se ---
More information about the SDL