Flipping Surfaces |
A Microsoft Direct3D application typically displays an animated sequence by generating the frames of the animation in back buffers and presenting them in sequence. Back buffers are organized into swap chains. A swap chain is a series of buffers that flip to the screen one after another. A swap chain can be used to render one scene in memory and then flip the scene to the screen when rendering is complete. This prevents the phenomenon known as tearing, and allows for smoother animation.
Each device created in Direct3D has at least one swap chain. When you initialize the first Direct3D device, you set the BackBufferCount member of the PresentParameters structure, which tells Direct3D the number of back buffers that will be in the swap chain. The Device constructor then creates the Direct3D device and corresponding swap chain.
When you use the Device.Present method to request a surface flip operation, the pointers to surface memory for the front buffer and back buffers are swapped. Flipping is performed by switching pointers that the display device uses for referencing memory, not by copying surface memory. When a flipping chain contains a front buffer and more than one back buffer, the pointers are switched in a circular pattern, as shown in the following illustration.
Additional swap chains for a device can be created by calling the SwapChain constructor. An application can create one swap chain per view and associate each swap chain with a particular window. The application renders images in the back buffers of each swap chain, and then presents them individually. The two parameters that SwapChain takes are a reference to a PresentParameters object and a valid Device object. The SwapChain.Present method can then be used to display the contents of the next back buffer to the front buffer. Note that a device can have only one full-screen swap chain.
To gain access to a specific back buffer, call the Device.GetBackBuffer or SwapChain.GetBackBuffer method, which returns a Surface object that represents the returned back buffer surface.
Remember that Direct3D flips surfaces by swapping surface memory pointers within the swap chain, not by swapping the surfaces themselves. This means that you will always render to the back buffer that will be displayed next.
It is important to note the distinction between a "flipping operation" as performed by a display adapter driver, and a "present" operation applied to a swap chain that was created with SwapEffect.Flip.
The term flip conventionally denotes an operation that alters the range of video memory addresses that a display adapter uses to generate its output signal, thus causing the contents of a previously hidden back buffer to be displayed. In Microsoft DirectX 9.0, the term is often used more generally to describe the presentation of a back buffer in any swap chain created with the SwapEffect.Flip swap effect.
While such "present" operations are almost invariably implemented by flip operations when the swap chain is a full-screen one, they are necessarily implemented by copy operations when the swap chain is windowed. Furthermore, a display adapter driver can use flipping to implement "present" operations against full-screen swap chains based on SwapEffect.Discard and SwapEffect.Copy.
For a more general discussion of the different swap effects for both windowed and full-screen swap chains, see SwapEffect.
Send comments about this topic to Microsoft. © Microsoft Corporation. All rights reserved.
Feedback? Please provide us with your comments on this topic.
For more help, visit the DirectX Developer Center