Here we go again…
No, you can’t get SDL to explicitly sync with the retrace (seems
that most targets cannot support that anyway), but SDL_FlipSurface()
does it when possible. (Someone will have to fill in the details here
- I’m not sure when SDL is supposed to sync; I’m just aware that it
never does on any Linux targets but svgalib, because these targets
don’t support it…)
On Windows you can get retrace sync when using DirectX. (Possibly
even in windowed mode - not sure.) On Linux, you have to use the
svgalib target, OpenGL on X, using a driver with retrace sync, or you
own retrace sync code.
I have some retrace sync code lying around, with TSC timing to deal
with the fact that you miss lots of retraces (due to the stupid way
the VGA retrace bit works), but 1) you need to be root to get access
to the VGA port, 2) you need to take additional measures to produce a
tearing free display (“flipping” is done by blitting the back buffer
to screen on X), and 3) my timing code could use some more tweaking.
(I’m working some on the game I wrote it for, so there’s hope!
Anyway, the proper way to do smooth animation on modern computers (ie
with multitasking and other crap is not to have the entire engine
sync with the retrace, but to have the driver sync the flip! This,
in combination with triplebuffering (or more), makes it possible to
produce rock solid animation even at near 100% CPU load, as long as
the driver (or the video hardware) does it’s job properly. No need
for hard real time scheduling for the rendering engine.
Of course, this increases latency a bit, but fortunately, the eye is
a lot slower than the ear, so video programming is rather forgiving
compared to audio in this respect. (Meanwhile, it’s possible to do
rock solid audio processing with <3 ms latency on slightly modified
Linux kernels these days, so there’s no theoretical excuse for video
lagging behind like this. We’re dealing with driver and architecture
limitations.)
//David
.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------> http://www.linuxaudiodev.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |
--------------------------------------> david at linuxdj.com -'On Saturday 14 July 2001 00:43, Mik Mifflin wrote:
Is there a function incuded with SDL that will wait for the
verticle retrace to start so I can draw my screen and things won’t
look so jumpy? There was a similar function in Allegro called
vsync(). And if there is not one, where might I find out how to
make one?