Skip to content

Commit

Permalink
Update order enum display modes for compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Dec 10, 2024
1 parent 5646eb5 commit c088a67
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 53 deletions.
2 changes: 1 addition & 1 deletion Dllmain/BuildNo.rc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILD_NUMBER 7370
#define BUILD_NUMBER 7371
113 changes: 61 additions & 52 deletions ddraw/IDirectDrawX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,6 @@ HRESULT m_IDirectDrawX::EnumDisplayModes2(DWORD dwFlags, LPDDSURFACEDESC2 lpDDSu
DWORD Width = 0;
DWORD Height = 0;
DWORD RefreshRate = 0;
DWORD BitCount = 0;
};
std::vector<RESLIST> ResolutionList;

Expand Down Expand Up @@ -988,60 +987,70 @@ HRESULT m_IDirectDrawX::EnumDisplayModes2(DWORD dwFlags, LPDDSURFACEDESC2 lpDDSu
// Add resolution to global list
AddDisplayResolution(d3ddispmode.Width, d3ddispmode.Height);

// Loop through each bit count
for (DWORD bpMode : {8, 16, 32})
// Set display refresh rate
DWORD RefreshRate = (dwFlags & DDEDM_REFRESHRATES) ? d3ddispmode.RefreshRate : 0;

// Check if the resolution is on the LimitedResolutionList
bool ResolutionOkToUse = (!Config.DdrawLimitDisplayModeCount ||
std::any_of(std::begin(LimitedResolutionList), std::end(LimitedResolutionList),
[&](const SIZE& entry) {
return ((DWORD)entry.cx == d3ddispmode.Width && (DWORD)entry.cy == d3ddispmode.Height);
}));

// Check if resolution has already been sent
bool ResolutionAlreadySent = std::any_of(ResolutionList.begin(), ResolutionList.end(),
[&](const RESLIST& Entry) {
return (Entry.Width == d3ddispmode.Width && Entry.Height == d3ddispmode.Height && Entry.RefreshRate == RefreshRate);
});

// Check mode
if (ResolutionOkToUse && !ResolutionAlreadySent &&
(!EnumWidth || d3ddispmode.Width == EnumWidth) &&
(!EnumHeight || d3ddispmode.Height == EnumHeight))
{
// Set display bit count
if (DisplayAllModes)
{
DisplayBitCount = bpMode;
}

// Set display refresh rate
DWORD RefreshRate = (dwFlags & DDEDM_REFRESHRATES) ? d3ddispmode.RefreshRate : 0;

// Check if the resolution is on the LimitedResolutionList
bool ResolutionOkToUse = (!Config.DdrawLimitDisplayModeCount ||
std::any_of(std::begin(LimitedResolutionList), std::end(LimitedResolutionList),
[&](const SIZE& entry) {
return ((DWORD)entry.cx == d3ddispmode.Width && (DWORD)entry.cy == d3ddispmode.Height);
}));

// Check if resolution has already been sent
bool ResolutionAlreadySent = std::any_of(ResolutionList.begin(), ResolutionList.end(),
[&](const RESLIST& Entry) {
return (Entry.Width == d3ddispmode.Width && Entry.Height == d3ddispmode.Height && Entry.RefreshRate == RefreshRate && Entry.BitCount == DisplayBitCount);
});

// Check mode
if (ResolutionOkToUse && !ResolutionAlreadySent &&
(!EnumWidth || d3ddispmode.Width == EnumWidth) &&
(!EnumHeight || d3ddispmode.Height == EnumHeight))
{
// Store resolution
ResolutionList.push_back({ d3ddispmode.Width, d3ddispmode.Height, RefreshRate, DisplayBitCount });

// Set surface desc options
DDSURFACEDESC2 Desc2 = {};
Desc2.dwSize = sizeof(DDSURFACEDESC2);
Desc2.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_REFRESHRATE;
Desc2.dwWidth = d3ddispmode.Width;
Desc2.dwHeight = d3ddispmode.Height;
Desc2.dwRefreshRate = RefreshRate;

// Set adapter pixel format
Desc2.dwFlags |= DDSD_PIXELFORMAT;
Desc2.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
D3DFORMAT Format = SetDisplayFormat(Desc2.ddpfPixelFormat, DisplayBitCount);
// Store resolution
ResolutionList.push_back({ d3ddispmode.Width, d3ddispmode.Height, RefreshRate });
}
}

// Set pitch
Desc2.dwFlags |= DDSD_PITCH;
Desc2.lPitch = ComputePitch(Format, GetByteAlignedWidth(d3ddispmode.Width, DisplayBitCount), DisplayBitCount);
// Set display bit count modes
std::vector<DWORD> BitCountList;
if (DisplayAllModes)
{
BitCountList.push_back(32);
BitCountList.push_back(16);
BitCountList.push_back(8);
}
else
{
BitCountList.push_back(DisplayBitCount);
}

if (lpEnumModesCallback2(&Desc2, lpContext) == DDENUMRET_CANCEL)
{
return DD_OK;
}
// Loop through each bit count
for (DWORD bpMode : BitCountList)
{
for (auto& entry : ResolutionList)
{
// Set surface desc options
DDSURFACEDESC2 Desc2 = {};
Desc2.dwSize = sizeof(DDSURFACEDESC2);
Desc2.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_REFRESHRATE;
Desc2.dwWidth = entry.Width;
Desc2.dwHeight = entry.Height;
Desc2.dwRefreshRate = entry.RefreshRate;

// Set adapter pixel format
Desc2.dwFlags |= DDSD_PIXELFORMAT;
Desc2.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
D3DFORMAT Format = SetDisplayFormat(Desc2.ddpfPixelFormat, bpMode);

// Set pitch
Desc2.dwFlags |= DDSD_PITCH;
Desc2.lPitch = ComputePitch(Format, GetByteAlignedWidth(Desc2.dwWidth, bpMode), bpMode);

if (lpEnumModesCallback2(&Desc2, lpContext) == DDENUMRET_CANCEL)
{
return DD_OK;
}
}
}
Expand Down

0 comments on commit c088a67

Please sign in to comment.