Fix switching to fullscreen mode in D3D11/D3D12 flip presentation modes
This commit is contained in:
@@ -265,18 +265,15 @@ bool GPUDeviceDX11::Init()
|
||||
return true;
|
||||
}
|
||||
UpdateOutputs(adapter);
|
||||
|
||||
ComPtr<IDXGIFactory5> factory5;
|
||||
_factoryDXGI->QueryInterface(IID_PPV_ARGS(&factory5));
|
||||
if (factory5)
|
||||
{
|
||||
ComPtr<IDXGIFactory5> factory5;
|
||||
_factoryDXGI->QueryInterface(IID_PPV_ARGS(&factory5));
|
||||
if (factory5)
|
||||
{
|
||||
BOOL allowTearing;
|
||||
if (SUCCEEDED(factory5->CheckFeatureSupport(DXGI_FEATURE_PRESENT_ALLOW_TEARING, &allowTearing, sizeof(allowTearing))) && allowTearing)
|
||||
{
|
||||
AllowTearing = true;
|
||||
}
|
||||
factory5->Release();
|
||||
}
|
||||
BOOL allowTearing;
|
||||
if (SUCCEEDED(factory5->CheckFeatureSupport(DXGI_FEATURE_PRESENT_ALLOW_TEARING, &allowTearing, sizeof(allowTearing))) && allowTearing)
|
||||
AllowTearing = true;
|
||||
factory5->Release();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -112,6 +112,16 @@ void GPUSwapChainDX11::SetFullscreen(bool isFullscreen)
|
||||
}
|
||||
|
||||
_isFullscreen = isFullscreen;
|
||||
|
||||
// Buffers must be resized in flip presentation model
|
||||
if (swapChainDesc.SwapEffect == DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL ||
|
||||
swapChainDesc.SwapEffect == DXGI_SWAP_EFFECT_FLIP_DISCARD)
|
||||
{
|
||||
const int32 width = _width;
|
||||
const int32 height = _height;
|
||||
_width = _height = 0;
|
||||
Resize(width, height);
|
||||
}
|
||||
}
|
||||
#else
|
||||
LOG(Info, "Cannot change fullscreen mode on this platform");
|
||||
@@ -218,7 +228,7 @@ bool GPUSwapChainDX11::Resize(int32 width, int32 height)
|
||||
ASSERT(_swapChain);
|
||||
|
||||
// Disable DXGI changes to the window
|
||||
VALIDATE_DIRECTX_RESULT(dxgi->MakeWindowAssociation(_windowHandle, 0));
|
||||
VALIDATE_DIRECTX_RESULT(dxgi->MakeWindowAssociation(_windowHandle, DXGI_MWA_NO_ALT_ENTER));
|
||||
#else
|
||||
auto dxgiFactory = (IDXGIFactory2*)_device->GetDXGIFactory();
|
||||
VALIDATE_DIRECTX_RESULT(dxgiFactory->CreateSwapChainForCoreWindow(_device->GetDevice(), static_cast<IUnknown*>(_windowHandle), &swapChainDesc, nullptr, &_swapChain));
|
||||
|
||||
@@ -137,6 +137,16 @@ void GPUSwapChainDX12::SetFullscreen(bool isFullscreen)
|
||||
}
|
||||
|
||||
_isFullscreen = isFullscreen;
|
||||
|
||||
// Buffers must be resized in flip presentation model
|
||||
if (swapChainDesc.SwapEffect == DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL ||
|
||||
swapChainDesc.SwapEffect == DXGI_SWAP_EFFECT_FLIP_DISCARD)
|
||||
{
|
||||
const int32 width = _width;
|
||||
const int32 height = _height;
|
||||
_width = _height = 0;
|
||||
Resize(width, height);
|
||||
}
|
||||
}
|
||||
#else
|
||||
LOG(Info, "Cannot change fullscreen mode on this platform");
|
||||
@@ -219,7 +229,7 @@ bool GPUSwapChainDX12::Resize(int32 width, int32 height)
|
||||
_backBuffers.Resize(swapChainDesc.BufferCount);
|
||||
|
||||
// Disable DXGI changes to the window
|
||||
dxgiFactory->MakeWindowAssociation(_windowHandle, 0);
|
||||
VALIDATE_DIRECTX_RESULT(dxgiFactory->MakeWindowAssociation(_windowHandle, DXGI_MWA_NO_ALT_ENTER));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -1031,6 +1031,10 @@ LRESULT WindowsWindow::WndProc(UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
// In this case, we don't resize yet -- we wait until the user stops dragging, and a WM_EXITSIZEMOVE message comes.
|
||||
UpdateRegion();
|
||||
}
|
||||
else if (_isSwitchingFullScreen)
|
||||
{
|
||||
// Ignored
|
||||
}
|
||||
else
|
||||
{
|
||||
// This WM_SIZE come from resizing the window via an API like SetWindowPos() so resize
|
||||
@@ -1090,6 +1094,12 @@ LRESULT WindowsWindow::WndProc(UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
Close(ClosingReason::User);
|
||||
return 0;
|
||||
}
|
||||
if (wParam == VK_RETURN)
|
||||
{
|
||||
LOG(Info, "Alt+Enter pressed");
|
||||
SetIsFullscreen(!IsFullscreen());
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_POWERBROADCAST:
|
||||
switch (wParam)
|
||||
|
||||
Reference in New Issue
Block a user