Skip to content

Commit

Permalink
Use device gamma when formats mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Sep 29, 2024
1 parent 51a03e0 commit cd2234c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 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 7215
#define BUILD_NUMBER 7216
38 changes: 36 additions & 2 deletions d3d9/IDirect3DDevice9Ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,9 +684,43 @@ void m_IDirect3DDevice9Ex::SetGammaRamp(THIS_ UINT iSwapChain, DWORD Flags, CONS
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";

ProxyInterface->SetGammaRamp(iSwapChain, Flags, pRamp);
if (!pRamp)
{
return;
}

bool FormatsMatch = false;
do {
IDirect3DSurface9* pRenderTarget = nullptr;
if (FAILED(ProxyInterface->GetRenderTarget(0, &pRenderTarget)))
{
break;
}

IDirect3DSurface9* pBackBuffer = nullptr;
if (FAILED(ProxyInterface->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer)))
{
pRenderTarget->Release();
break;
}

D3DSURFACE_DESC renderTargetDesc, backBufferDesc;
pRenderTarget->GetDesc(&renderTargetDesc);
pBackBuffer->GetDesc(&backBufferDesc);

FormatsMatch = (renderTargetDesc.Format == backBufferDesc.Format);

pRenderTarget->Release();
pBackBuffer->Release();

} while (false);

if (FormatsMatch)
{
ProxyInterface->SetGammaRamp(iSwapChain, Flags, pRamp);
}

if (Config.EnableWindowMode && pRamp)
if (!FormatsMatch || (Config.EnableWindowMode && Flags == D3DSGR_NO_CALIBRATION))
{
// Get the device context for the screen
HDC hdc = ::GetDC(SHARED.DeviceWindow);
Expand Down
13 changes: 9 additions & 4 deletions ddraw/IDirectDrawX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4137,13 +4137,13 @@ HRESULT m_IDirectDrawX::GetD9Gamma(DWORD dwFlags, LPDDGAMMARAMP lpRampData)
return DDERR_GENERIC;
}

if (!presParams.Windowed)
if (!lpRampData)
{
d3d9Device->GetGammaRamp(dwFlags, (D3DGAMMARAMP*)lpRampData);
return DD_OK;
return DDERR_INVALIDPARAMS;
}

return D3DERR_INVALIDCALL;
d3d9Device->GetGammaRamp(dwFlags, (D3DGAMMARAMP*)lpRampData);
return DD_OK;
}

HRESULT m_IDirectDrawX::SetD9Gamma(DWORD dwFlags, LPDDGAMMARAMP lpRampData)
Expand All @@ -4154,6 +4154,11 @@ HRESULT m_IDirectDrawX::SetD9Gamma(DWORD dwFlags, LPDDGAMMARAMP lpRampData)
return DDERR_GENERIC;
}

if (!lpRampData)
{
return DDERR_INVALIDPARAMS;
}

d3d9Device->SetGammaRamp(0, dwFlags, (D3DGAMMARAMP*)lpRampData);
return DD_OK;
}
Expand Down

0 comments on commit cd2234c

Please sign in to comment.