mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-02-18 22:54:15 +01:00
[dxgi] FindClosestMatchingMode: Handle Width/Height = 0 case
When an applicationn calls this method with the width or height set to 0, we are allowed to pick any resolution, so we'll try to find one close to the *current* display mode which usually returns the current display mode itself.
This commit is contained in:
parent
c93f2b980e
commit
7a22fa22a7
@ -121,19 +121,32 @@ namespace dxvk {
|
||||
if (modes.size() == 0)
|
||||
return DXGI_ERROR_NOT_FOUND;
|
||||
|
||||
// If no valid resolution is specified, find the
|
||||
// closest match for the current display resolution
|
||||
UINT targetWidth = pModeToMatch->Width;
|
||||
UINT targetHeight = pModeToMatch->Height;
|
||||
|
||||
if (targetWidth == 0 || targetHeight == 0) {
|
||||
DXGI_MODE_DESC activeMode;
|
||||
GetDisplayMode(&activeMode, ENUM_CURRENT_SETTINGS);
|
||||
|
||||
targetWidth = activeMode.Width;
|
||||
targetHeight = activeMode.Height;
|
||||
}
|
||||
|
||||
// Select mode with minimal height+width difference
|
||||
UINT minDifference = std::numeric_limits<unsigned int>::max();
|
||||
|
||||
for (auto& mode : modes) {
|
||||
UINT currDifference = std::abs(int(pModeToMatch->Width - mode.Width))
|
||||
+ std::abs(int(pModeToMatch->Height - mode.Height));
|
||||
UINT currDifference = std::abs(int(targetWidth - mode.Width))
|
||||
+ std::abs(int(targetHeight - mode.Height));
|
||||
|
||||
if (currDifference <= minDifference) {
|
||||
minDifference = currDifference;
|
||||
*pClosestMatch = mode;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user