Smooth Scrolling Theory

Sorry to keep this subject alive, but I’m being criticized for whining
rather than providing a solution - and indeed, these discussions should
have been held on a video driver related list.

Anyway, here’s your solution. Works with or without retrace synced flips,
but for slightly different reasons.-------------------------------------------------------------------------

Some of you might have noticed that on targets that don’t do retrace
sync’ed pageflipping, higher frame rates - even many times higher than
the refresh rate! - seem to reduce tearing.

Note that you’ll need sub-pixel accurate scrolling or very fast scrolling
to see this effect! (Just rendering the same image for N frames at a time
won’t make a difference…)

As an example, the smoothscroll demo runs incredibly well even without
retrace sync on my machines at home (G400 and GeForce 2 GTS) - but it
produces rather terrible tearing on this machine (some cheap Rage Pro AGP
card).

Why is this?

Well, it’s rather obvious, if you consider what “tearing” is; the result
of the on-screen image being composed of partial frames rendered at
different points in “logic time”. The actual tearing is seen where the
rendering passes the raster, causing objects to be in a slightly
different position from that point and on. If you’re rendering at N times
the refresh rate, you’ll see approximately N “skips” on the screen at any
time.

Now, the interesting part is that a side effect of increasing the
rendering frame rate is that objects move a shorter distance between each
frame. Considering the above, this obviously makes the tearing less
visible the higher the frame rate is in relation to the refresh rate.

As an example, a rather fast scrolling game could be scrolling at 100
pixels/second. If the refresh rate is 100 Hz, this would be exactly 1
pixel per refresh. If there are no retrace sync’ed flips, and the
rendering frame rate is approximately 100 Hz, there will be “skips” of 1
pixel jumping around on the screen. If the rendering frame rate was 500
Hz, there would be around 5 skips on the screen at a time - BUT, each
skip would be only one 5th of a pixel! This is a very real difference,
which can be taken advantage of using sub-pixel accurate rendering and
fast accelerated video cards.

Conclusion:

So there’s the “solution” for now; if you can’t get retrace sync’ed
flips, use sub-pixel accurate rendering and keep the frame rate as high
as possible.

In fact, just try to make the rendering as fast as possible at all times.
(As usual!)

* If there is retrace sync, you'll have a better chance of
  locking at full frame rate, getting *perfect* results.

* If there's no retrace sync, the raw speed will reduce
  tearing, for reasons explained above.

That’s it. If you want smoother scrolling without OpenGL, you’ll need a
2D blitter that uses fractional coordinates, because you need sub-pixel
accurate rendering at full frame rate, or faster. (Note that this is
actually doable as long as you don’t need to redraw the entire screen
every frame!)

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -’