Game Development Reference
In-Depth Information
its the amount of time the game loop has to render to the color buffer to only that
VBLANK period, which isn't going to be enough time for a modern game.
It is instead possible to solve screen tearing with a rendering technique called
double buffering . In double buffering, there are two color buffers. The game al-
ternates between drawing to these two buffers. On one frame, the game loop might
write to buffer A while the CRT displays buffer B. Then on the next frame, the
CRT will display buffer A while the game loop writes to buffer B. As long as both
the CRT and game loop aren't accessing the same buffer at the same time, there is
no risk of the CRT drawing an incomplete frame.
In order to fully prevent screen tearing, the buffer swap must happen during
VBLANK. This is often listed as VSYNC in the graphics settings for games,
thoughtechnicallyit'samisnomerbecauseVSYNCisthesignalthemonitorsends
the system to let it know VBLANK has commenced. In any event, because the
buffer swap is a relatively fast operation, the game has a much longer period of
time to render the entire frame (though ideally this should be less than the amount
oftime ittakes theCRTtodrawaframe).Solongasthebufferswapoccursduring
VBLANK, screen tearing will be entirely avoided.
Here's what a game world render function might look like with double buffering:
Click here to view code image
function RenderWorld()
// Draw all objects in the game world
...
wait for VBLANK
swap color buffers
end
Some games do allow buffer swaps to occur as soon as rendering finishes, which
means there may be some screen tearing. This is typically allowed when a user
wants to run the game at a frame rate much higher than the screen refresh rate. If
a particular monitor has a 60 Hz refresh rate, synchronizing the buffer swaps to
VBLANK would cap the frame rate at 60 FPS. But players who are very conscien-
tious of reducing their input lag (and have fast enough computers) may be able to
achieve much higher frame rates if that cap is removed.
Even though CRT monitors are rarely used today, double buffering still will pre-
vent screen tearing if buffer swaps are timed correctly on an LCD. Some games
Search WWH ::




Custom Search