From 847698dd32cf16357c8a7ba8b259f04ac766d3b2 Mon Sep 17 00:00:00 2001 From: Matt Tytel Date: Thu, 31 Oct 2024 13:09:05 -0400 Subject: [PATCH] Use DXGI_SWAP_CHAIN_DESC1 if available for additional scaling options. --- src/dxgi.cpp | 80 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 59 insertions(+), 21 deletions(-) diff --git a/src/dxgi.cpp b/src/dxgi.cpp index 4eae796d31..4cbf95036f 100644 --- a/src/dxgi.cpp +++ b/src/dxgi.cpp @@ -496,28 +496,66 @@ namespace bgfx DX_RELEASE_I(factory5); } - DXGI_SWAP_CHAIN_DESC scd; - scd.BufferDesc.Width = _scd.width; - scd.BufferDesc.Height = _scd.height; - scd.BufferDesc.RefreshRate.Numerator = 1; - scd.BufferDesc.RefreshRate.Denominator = 60; - scd.BufferDesc.Format = _scd.format; - scd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; - scd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; - scd.SampleDesc.Count = 1; - scd.SampleDesc.Quality = 0; - scd.BufferUsage = _scd.bufferUsage; - scd.BufferCount = _scd.bufferCount; - scd.OutputWindow = (HWND)_scd.nwh; - scd.Windowed = _scd.windowed; - scd.SwapEffect = _scd.swapEffect; - scd.Flags = scdFlags; - - hr = m_factory->CreateSwapChain( - _device - , &scd - , reinterpret_cast(_swapChain) + IDXGIFactory2* factory2; + hr = m_factory->QueryInterface(IID_IDXGIFactory2, (void**)&factory2); + + if (SUCCEEDED(hr) ) + { + DX_RELEASE_I(factory2); + DXGI_SWAP_CHAIN_DESC1 scd; + scd.Width = _scd.width; + scd.Height = _scd.height; + scd.Format = _scd.format; + scd.Stereo = _scd.stereo; + scd.SampleDesc.Count = 1; + scd.SampleDesc.Quality = 0; + scd.BufferUsage = _scd.bufferUsage; + scd.BufferCount = _scd.bufferCount; + scd.Scaling = _scd.scaling; + scd.SwapEffect = _scd.swapEffect; + scd.AlphaMode = _scd.alphaMode; + scd.Flags = scdFlags; + + DXGI_SWAP_CHAIN_FULLSCREEN_DESC scfd; + scfd.RefreshRate.Numerator = 1; + scfd.RefreshRate.Denominator = 60; + scfd.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; + scfd.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; + scfd.Windowed = _scd.windowed; + + hr = m_factory->CreateSwapChainForHwnd( + _device + , (HWND)_scd.nwh + , &scd + , &scfd, NULL + , reinterpret_cast(_swapChain) ); + } + else + { + DXGI_SWAP_CHAIN_DESC scd; + scd.BufferDesc.Width = _scd.width; + scd.BufferDesc.Height = _scd.height; + scd.BufferDesc.RefreshRate.Numerator = 1; + scd.BufferDesc.RefreshRate.Denominator = 60; + scd.BufferDesc.Format = _scd.format; + scd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; + scd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; + scd.SampleDesc.Count = 1; + scd.SampleDesc.Quality = 0; + scd.BufferUsage = _scd.bufferUsage; + scd.BufferCount = _scd.bufferCount; + scd.OutputWindow = (HWND)_scd.nwh; + scd.Windowed = _scd.windowed; + scd.SwapEffect = _scd.swapEffect; + scd.Flags = scdFlags; + + hr = m_factory->CreateSwapChain( + _device + , &scd + , reinterpret_cast(_swapChain) + ); + } #else DXGI_SWAP_CHAIN_DESC1 scd; scd.Width = _scd.width;