Vsync, double buffering, and smooth animation

Started by
23 comments, last by Extrarius 15 years, 10 months ago
Quote:Original post by Hodgman
I tried your test program - I can't see any tearing at all (although I did notice that the animation seems to "jump" ahead/behind occasionally). I think your problem simply lies with an imperfect timer implementation running the animation.

Screen tearing should look like this if it were happening (courtesy of mspaint).


I'm using SDL_GetTicks(), does that not have a high enough resolution?
Advertisement
Quote:Original post by hikikomori-san
With all respect, your post is full of wrong statements. You can't write directly to the front buffer

Yes you can (not in current version DX of course, it would be better if I said "you could". I see you're also seeing from a 3D prespective. I'm also taking 2D rendering in mind). See you didn't program 8-bit & 16-bit console games.

Quote:Original post by hikikomori-san
It has to either copy the contents of your back buffer to the front buffer (D3DSWAPEFFECT_COPY), or flip (swap) the buffers (D3DSWAPEFFECT_FLIP).

Thanks for finishing my explanation. ;-) I did say it wasn't complete.

Quote:Original post by hikikomori-san
This change happens regardless of how much of the old front buffer has been sent to the card, and for the rest of the screen update, the pixels that the card will send will be from the new front buffer contents, causing the upper half of the screen to display pixels from the old frame and the lower half to display pixels from the new frame


Yep. The screen is filled with mixed old & new content. This is what happened in the front-buffer-only attempt. Plus, tearing was more evident because if we rendered multiple layers, the screen was being updated when not all of the layers have finished drawing, while being mixed with old stuff from the previous frame.
This resulted in very evident tearing. But I have to admit I wrongly stated that using Double buffering solves tearing. (by double-buffer = front+back) But it reduces the effect

In 3D applications, there's no point in calling triple buffering to what you call double buffering, because like you say, you can't render to the front buffer directly. However this make sense for 2D-only applications. This term became popular around 1998 if I recall correctly. Plus the word "triple" sounded cooler (I'm not kidding, this is a marketing issue). And it was a performance optimization to include this option, because it seemed to boost it, but the lack of VRAM prevented many cards from benefit from it (common cards had around 4-8 MB, high-end ones could reach 16MB, or the CPU/GPU wasn't just fast enough).

Like MS says "A tear occurs when a page flip or blt happens at the wrong time". You explained what happens when a flip occurs at the wrong time. I explained what happens when a blit is performed at the wrong time.

Here's more info (I've just googled it):
Wikipedia about triple-buffering
Wikipedia about double-buffering
http://msdn.microsoft.com/en-us/library/ms796537.aspx

Cheers
Dark Sylinc
Quote:Original post by darknebula42
Yes, that's quite true. But when even moving at about 10 pixels per second it looks bad. And there is no way I shouldn't be able to not move 150 frames per second without tearing if double buffering is enabled.
Double buffering really has nothing to do with this. It doesn't matter if you have 180 buffers. If you are rendering fast enough that your machine can render more frames than the machine can actually show on screen, and those frames are not similar enough in appearance to each other, you will see tearing.

When VSync is off, the buffer can be swapped at any time, including when another frame is being drawn on the monitor. So if you render out another scene and then dump it onto the front buffer while the screen is in the middle of drawing the previous frame, the second half of the screen will show the next frame.

If those 2 frames have different content, your eye will see a tear at the point where the new frame was inserted.

You can do some things to prevent it, or minimize it's effect, but you can't stop it completely.

Don't tie the movement and logic of your game to the frame rate, and make sure that you are moving nice and smooth, and it will look good at 60hrtz, regardless of what frame rate you run it at. You're a slave to the refresh rate of your minitor.
Quote:Original post by Daaark
Quote:Original post by darknebula42
Yes, that's quite true. But when even moving at about 10 pixels per second it looks bad. And there is no way I shouldn't be able to not move 150 frames per second without tearing if double buffering is enabled.
Double buffering really has nothing to do with this. It doesn't matter if you have 180 buffers. If you are rendering fast enough that your machine can render more frames than the machine can actually show on screen, and those frames are not similar enough in appearance to each other, you will see tearing.

When VSync is off, the buffer can be swapped at any time, including when another frame is being drawn on the monitor. So if you render out another scene and then dump it onto the front buffer while the screen is in the middle of drawing the previous frame, the second half of the screen will show the next frame.

If those 2 frames have different content, your eye will see a tear at the point where the new frame was inserted.

You can do some things to prevent it, or minimize it's effect, but you can't stop it completely.

Don't tie the movement and logic of your game to the frame rate, and make sure that you are moving nice and smooth, and it will look good at 60hrtz, regardless of what frame rate you run it at. You're a slave to the refresh rate of your minitor.


So am I correct that using Linear Interpolation is the correct way to do smooth movement?
x += time it took to get here from last movement * velocity

So... sync with the hertz of the monitor or tearing will happen no matter what is the answer?
Quote:Original post by darknebula42
[...]So... sync with the hertz of the monitor or tearing will happen no matter what is the answer?
V-sync is the only way to ensure tearing is eliminated.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk

This topic is closed to new replies.

Advertisement