Game Development Reference
What Is a Swap Chain?
An application utilizing Direct3D to render real-time 3D graphics organizes an
animated sequence into a series of frames that are stored in a collection of buffers,
and renders them in the correct sequence. These buffers are grouped into swap
chains that flip to the screen one after the other. A swap chain can render an
upcoming frame in the background and present the frame to the screen when
ready. This mechanism solves a common problem known as “tearing” and offers
Every Direct3D device that is created automatically instantiates a single implicit
swap chain. When a surface flip is requested through the execution of
Device.Present , the pointers for the front and back buffer(s) are swapped, and a
new frame is presented to the viewer. If there is more than one back buffer in a
swap chain, the pointers are swapped in a circular order.
Additional swap chains can be created within a given device, though a device can
only contain a single full-screen swap chain. Each swap chain renders into a col-
lection of buffers and can be presented to a different window from the main device.
The back buffer for a swap chain can be accessed with SwapChain.GetBackBuffer .
Before continuing, it is important to note that, by the term window, I am referring to any control.
This association goes back to the unmanaged Win32 API.
A great benefit of using swap chains with a single device is the notion that resources,
such as meshes and textures, are shared across all swap chains using a single loca-
tion in memory.
Creating a swap chain is very easy to do, and the only prerequisite is that a valid
Direct3D is already available. The first thing to do is to create a PresentParameters
object and specify some rendering properties about the swap chain. Most of the
properties are familiar from regular device settings, but the important ones to note
are DeviceWindow , BackBufferWidth , and BackBufferHeight . All three refer to the han-
dle, width, and height of the window (control) that the swap chain will be bound
to for rendering. The variable of this control is called renderTarget and is of type
The following code shows how to build present parameters for a swap chain.
PresentParameters presentParams = new PresentParameters();
presentParams.AutoDepthStencilFormat = DepthFormat.D16;