IDXGISwapChain Interface

The IDXGISwapChain interface represents a swap chain, which is a collection of buffers that are used to display rendered frames on the screen. The swap chain manages the presentation of rendered images by allowing applications to specify how and when to present them.

This interface is part of the DirectX Graphics Infrastructure (DXGI) and is used by applications to manage the presentation of rendered content.

Interface Properties

The IDXGISwapChain interface inherits from IDXGISurface1.

Methods

The IDXGISwapChain interface includes the following methods:

Method Description
GetBuffer Retrieves a back buffer.
GetDesc Gets a description of the swap chain.
GetFrameStatistics Gets frame statistics.
GetLastPresentCount Gets the count of present operations.
Present Presents the next frame of the swap chain to the user.
ResizeBuffers Resizes the back buffers.
ScrollPresent Updates a portion of the client area and presents it.

GetBuffer

Retrieves a back buffer.

HRESULT GetBuffer(
  [in]  UINT  Buffer,
  [in]  REFIID riid,
  [out] void  **ppSurface
);
Buffer
[in] The index of the buffer to retrieve.
riid
[in] The globally unique identifier (GUID) for the interface to the buffer.
ppSurface
[out] A pointer to a buffer interface (e.g., ID3D11Texture2D or IDXGISurface). For a back buffer, this is typically an ID3D11Texture2D interface.

GetDesc

Gets a description of the swap chain.

HRESULT GetDesc(
  [out] DXGI_SWAP_CHAIN_DESC *pDesc
);
pDesc
[out] A pointer to a DXGI_SWAP_CHAIN_DESC structure that describes the swap chain.

GetFrameStatistics

Gets frame statistics.

HRESULT GetFrameStatistics(
  [out] DXGI_FRAME_STATISTICS *pStats
);
pStats
[out] A pointer to a DXGI_FRAME_STATISTICS structure that receives frame statistics.

GetLastPresentCount

Gets the count of present operations.

HRESULT GetLastPresentCount(
  [out] UINT *pLastPresentCount
);
pLastPresentCount
[out] A pointer to a UINT variable that receives the count of present operations.

Present

Presents the next frame of the swap chain to the user.

HRESULT Present(
  [in] UINT SyncInterval,
  [in] UINT Flags
);
SyncInterval
[in] The time interval for VSync. 0 means skip v-sync, 1 means wait for v-sync, 2 means wait for two v-blanks, etc.
Flags
[in] Options for presenting the frame. Can be 0 or DXGI_PRESENT_DO_NOT_SEQUENCE.

ResizeBuffers

Resizes the back buffers.

HRESULT ResizeBuffers(
  [in] UINT        BufferCount,
  [in] UINT        Width,
  [in] UINT        Height,
  [in] DXGI_FORMAT NewFormat,
  [in] UINT        SwapChainFlags
);
BufferCount
[in] The number of buffers in the swap chain.
Width
[in] The new width of the buffers.
Height
[in] The new height of the buffers.
NewFormat
[in] The new pixel format of the buffers.
SwapChainFlags
[in] Flags that specify properties of the new swap chain.

ScrollPresent

Updates a portion of the client area and presents it.

HRESULT ScrollPresent(
  [in] UINT        ScrollX,
  [in] UINT        ScrollY,
  [in] const RECT  *pDirtyRect,
  [in] UINT        Flags
);
ScrollX
[in] The amount to scroll horizontally.
ScrollY
[in] The amount to scroll vertically.
pDirtyRect
[in] A pointer to a RECT structure that specifies the updated region.
Flags
[in] Options for presenting the frame.

Remarks

The IDXGISwapChain interface is central to how graphics are displayed in Windows applications. It provides control over buffer presentation, resolution changes, and frame synchronization, making it a fundamental component for any application that renders graphics using DirectX.

When an application renders a frame, it typically draws to a back buffer. The Present method then makes this back buffer visible to the user, often synchronizing with the monitor's refresh rate to avoid tearing.

The ResizeBuffers method is crucial for handling window resizing or changes in display resolution. Applications must be able to adapt their rendering targets and swap chain configuration to these changes.