[SDL] tearring graphics
david at olofson.net
Wed Jan 29 08:16:01 PST 2003
On Wednesday 29 January 2003 05.44, Chris Thielen wrote:
> Just a simple question: how do you (anybody who cares to respond)
> avoid tearring graphics? Is it as simple as passing SDL_DOUBLEBUF
> to SDL_SetVideoMode() or is there more to it? The game I'm working
> on doesn't have any protection against tearring so generally on
> quick loops you can get screenshots of half the screen drawn with a
> new frame and the old frame still taking up 300 rows down. Any
*Screenshots*...? I assume you're using som external tool for that,
since SDL isn't thread safe.
Anyway, there's only one way to prevent this: Retrace sync'ed page
flipping. If the rendering target doesn't support it, there isn't
much SDL can do about it.
Note that there are two commonly used methods of "flipping"; actual
h/w pageflipping (multiple buffers; a flip is just changing one or
two h/w registers), and fake flipping through blitting (a "flip"
means you blit the off-screen back buffer into the display buffer.)
If you use SDL_DOUBLEBUF, the underlying rendering backend has a
*chance* of doing the right thing (real page flipping), but there's
no guarantee. Either SDL or the driver might still use back->front
blits, and may not even be able to sync them with the retrace. (Which
wouldn't help much anyway, unless you're on a real time OS. To do
blit based flipping without tearing, you have to hit the retrace
right on, or you'll get tearing anyway.)
Also note that virtually no desktop environments are double buffered,
so forget about SDL_DOUBLEBUF in windowed mode. Use SDL_FULLSCREEN,
or you'll almost certainly enforce fake blit based flipping, and you
may also lose the retrace sync.
Finally, note that it's on some platforms (Linux; maybe some others),
only a few drivers can retrace sync at all. You're basically out of
luck on these. Best bet is to use OpenGL in fullscreen mode, as
that's much more likely to support both h/w pageflipping and retrace
sync, at least in my experience.
//David Olofson - Programmer, Composer, Open Source Advocate
.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`---------------------------> http://olofson.net/audiality -'
--- http://olofson.net --- http://www.reologica.se ---
More information about the SDL