Search code examples
directxfullscreendxgi

Fullscreen Exclusive: How to change the native resolution?


I can successfully control the native refresh-rate by specifying the refresh rate in DXGI_SWAP_CHAIN_FULLSCREEN_DESC which is passed to CreateSwapChainForHwnd.

I was expecting native resolution to change to that specified by the hight and width of the swapchain. However, I was not this lucky.

Moreover, the CreateSwapChainForHwnd suggests that you cant control the native resolution of the monitor since you can specify DXGI_SWAP_CHAIN_FULLSCREEN_DESC has a scaling parameter

typedef enum DXGI_MODE_SCALING { 
  DXGI_MODE_SCALING_UNSPECIFIED  = 0,
  DXGI_MODE_SCALING_CENTERED     = 1,
  DXGI_MODE_SCALING_STRETCHED    = 2
} DXGI_MODE_SCALING;

But, video games are clearly trigging a mode change (temporary black screen) when they change resolution in fullscreen exclusive. So they must be able to change the native resolution. How are they doing this?

Also, I was wondering why DXGI_MODE_SCALING_STRETCHED only fills a sub-rectangle of screen (DXGI_MODE_SCALING_CENTERED centres on this sub-rectangle, and DXGI_MODE_SCALING_UNSPECIFIED aligns the swapchain's top right corner with the top-right of this sub-rectangle). This sub-rectangle also changes as the hight and width passed to CreateSwapChainForHwnd changes. Maybe it's that I'm really in Fullscreen Optimizations rather than Fullscreen Exclusive and this sub-rectangle is the same size of my window(changing the window size didn't affect the observed behaviour).


Solution

  • DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH Set this flag to enable an application to switch modes by calling IDXGISwapChain::ResizeTarget. When switching from windowed to full-screen mode, the display mode (or monitor resolution) will be changed to match the dimensions of the application window.

    https://learn.microsoft.com/en-us/windows/win32/api/dxgi/ne-dxgi-dxgi_swap_chain_flag

    Interestingly, the mode switch works correctly without the flag when changing refresh-rates but will not when changing resolutions