Skip to content

Commit

Permalink
Fix gamma shader and reset textures
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Mar 4, 2025
1 parent abb327e commit 05c5e81
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 24 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 7537
#define BUILD_NUMBER 7538
1 change: 1 addition & 0 deletions Settings/AllSettings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ OverrideRefreshRate = 0
LimitPerFrameFPS = 0
EnableWindowMode = 0
WindowModeBorder = 0
WindowModeGammaShader = 0
SetInitialWindowPosition = 0
InitialWindowPositionLeft = 0
InitialWindowPositionTop = 0
Expand Down
2 changes: 2 additions & 0 deletions Settings/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ void Settings::SetDefaultConfigSettings()
Config.EnvironmentMapCubeFix = NOT_EXIST;
Config.LimitStateBlocks = NOT_EXIST;
Config.ForceSingleBeginEndScene = NOT_EXIST;
Config.WindowModeGammaShader = NOT_EXIST;

// Other values that may not exist in ini file
Config.DisableMaxWindowedModeNotSet = true;
Expand Down Expand Up @@ -777,4 +778,5 @@ void CONFIG::SetConfig()
EnvironmentMapCubeFix = (EnvironmentMapCubeFix != 0);
LimitStateBlocks = (LimitStateBlocks != 0);
ForceSingleBeginEndScene = (ForceSingleBeginEndScene != 0);
WindowModeGammaShader = (WindowModeGammaShader != 0);
}
2 changes: 2 additions & 0 deletions Settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
visit(WindowModeBorder) \
visit(WinVersionLie) \
visit(WinVersionLieSP) \
visit(WindowModeGammaShader) \
visit(WrapperMode)

#define VISIT_APPCOMPATDATA_SETTINGS(visit) \
Expand Down Expand Up @@ -298,6 +299,7 @@ struct CONFIG
bool WaitForProcess = false; // Waits for process to end before continuing, requires FullScreen
bool WaitForWindowChanges = false; // Waits for window handle to stabilize before setting fullsreen, requires FullScreen
bool WindowModeBorder = false; // Enables the window border when EnableWindowMode is set, requires EnableWindowMode
DWORD WindowModeGammaShader = 0; // Use shader for gamma when in window mode
bool SetInitialWindowPosition = false; // Enable Initial window position
DWORD InitialWindowPositionLeft; // Initial left window position for application
DWORD InitialWindowPositionTop; // Initial top window position for application
Expand Down
18 changes: 10 additions & 8 deletions d3d9/IDirect3D9Ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ HRESULT m_IDirect3D9Ex::CheckDeviceMultiSampleType(THIS_ UINT Adapter, D3DDEVTYP

if (Config.EnableWindowMode)
{
Windowed = true;
Windowed = TRUE;
}

return ProxyInterface->CheckDeviceMultiSampleType(Adapter, DeviceType, SurfaceFormat, Windowed, MultiSampleType, pQualityLevels);
Expand All @@ -294,7 +294,7 @@ HRESULT m_IDirect3D9Ex::CheckDeviceType(UINT Adapter, D3DDEVTYPE CheckType, D3DF

if (Config.EnableWindowMode)
{
Windowed = true;
Windowed = TRUE;
}

return ProxyInterface->CheckDeviceType(Adapter, CheckType, DisplayFormat, BackBufferFormat, Windowed);
Expand Down Expand Up @@ -339,6 +339,8 @@ HRESULT m_IDirect3D9Ex::CreateDeviceT(DEVICEDETAILS& DeviceDetails, UINT Adapter
CopyMemory(&d3dpp, pPresentationParameters, sizeof(D3DPRESENT_PARAMETERS));
UpdatePresentParameter(&d3dpp, hFocusWindow, DeviceDetails, ForceFullscreen, true);

bool IsWindowMode = d3dpp.Windowed != FALSE;

// Check for AntiAliasing
if (Config.AntiAliasing != 0)
{
Expand All @@ -358,7 +360,7 @@ HRESULT m_IDirect3D9Ex::CreateDeviceT(DEVICEDETAILS& DeviceDetails, UINT Adapter
UpdatePresentParameterForMultisample(&d3dpp, Samples, (QualityLevels > 0) ? QualityLevels - 1 : 0);

// Create Device
hr = CreateDeviceT(Adapter, DeviceType, hFocusWindow, BehaviorFlags, &d3dpp, (d3dpp.Windowed) ? nullptr : pFullscreenDisplayMode, ppReturnedDeviceInterface);
hr = CreateDeviceT(Adapter, DeviceType, hFocusWindow, BehaviorFlags, &d3dpp, (d3dpp.Windowed ? nullptr : pFullscreenDisplayMode), ppReturnedDeviceInterface);

// Check if device was created successfully
if (SUCCEEDED(hr))
Expand All @@ -384,7 +386,7 @@ HRESULT m_IDirect3D9Ex::CreateDeviceT(DEVICEDETAILS& DeviceDetails, UINT Adapter
UpdatePresentParameter(&d3dpp, hFocusWindow, DeviceDetails, ForceFullscreen, false);

// Create Device
hr = CreateDeviceT(Adapter, DeviceType, hFocusWindow, BehaviorFlags, &d3dpp, (d3dpp.Windowed) ? nullptr : pFullscreenDisplayMode, ppReturnedDeviceInterface);
hr = CreateDeviceT(Adapter, DeviceType, hFocusWindow, BehaviorFlags, &d3dpp, (d3dpp.Windowed ? nullptr : pFullscreenDisplayMode), ppReturnedDeviceInterface);
}

if (SUCCEEDED(hr))
Expand All @@ -393,7 +395,7 @@ HRESULT m_IDirect3D9Ex::CreateDeviceT(DEVICEDETAILS& DeviceDetails, UINT Adapter

if (WndDataStruct && WndDataStruct->IsExclusiveMode)
{
d3dpp.Windowed = false;
d3dpp.Windowed = FALSE;
}

if (MultiSampleFlag)
Expand All @@ -403,7 +405,7 @@ HRESULT m_IDirect3D9Ex::CreateDeviceT(DEVICEDETAILS& DeviceDetails, UINT Adapter
DeviceDetails.DeviceMultiSampleQuality = d3dpp.MultiSampleQuality;
}

DeviceDetails.IsWindowMode = pPresentationParameters->Windowed;
DeviceDetails.IsWindowMode = IsWindowMode;

CopyMemory(pPresentationParameters, &d3dpp, sizeof(D3DPRESENT_PARAMETERS));
}
Expand Down Expand Up @@ -629,7 +631,7 @@ void UpdatePresentParameter(D3DPRESENT_PARAMETERS* pPresentationParameters, HWND
// Set windowed mode if enabled
if (ForceExclusiveFullscreen)
{
pPresentationParameters->Windowed = false;
pPresentationParameters->Windowed = FALSE;
if (!pPresentationParameters->FullScreen_RefreshRateInHz)
{
pPresentationParameters->FullScreen_RefreshRateInHz = Utils::GetRefreshRate(DeviceDetails.DeviceWindow);
Expand All @@ -641,7 +643,7 @@ void UpdatePresentParameter(D3DPRESENT_PARAMETERS* pPresentationParameters, HWND
}
else if (Config.EnableWindowMode)
{
pPresentationParameters->Windowed = true;
pPresentationParameters->Windowed = TRUE;
pPresentationParameters->FullScreen_RefreshRateInHz = 0;
}

Expand Down
36 changes: 21 additions & 15 deletions d3d9/IDirect3DDevice9Ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ inline HRESULT m_IDirect3DDevice9Ex::ResetT(T func, D3DPRESENT_PARAMETERS* pPres
CopyMemory(&d3dpp, pPresentationParameters, sizeof(D3DPRESENT_PARAMETERS));
UpdatePresentParameter(&d3dpp, nullptr, SHARED, ForceFullscreen, true);

bool IsWindowMode = d3dpp.Windowed != FALSE;

// Test for Multisample
if (SHARED.DeviceMultiSampleFlag)
{
Expand Down Expand Up @@ -237,10 +239,10 @@ inline HRESULT m_IDirect3DDevice9Ex::ResetT(T func, D3DPRESENT_PARAMETERS* pPres

if (WndDataStruct && WndDataStruct->IsExclusiveMode)
{
d3dpp.Windowed = false;
d3dpp.Windowed = FALSE;
}

SHARED.IsWindowMode = d3dpp.Windowed;
SHARED.IsWindowMode = IsWindowMode;

CopyMemory(pPresentationParameters, &d3dpp, sizeof(D3DPRESENT_PARAMETERS));

Expand Down Expand Up @@ -911,6 +913,11 @@ inline void m_IDirect3DDevice9Ex::ApplyBrightnessLevel()
}

// Set texture
IDirect3DBaseTexture9* pTexture[8] = {};
for (int x = 0; x < 8; x++)
{
ProxyInterface->GetTexture(x, &pTexture[x]);
}
ProxyInterface->SetTexture(0, SHARED.ScreenCopyTexture);
ProxyInterface->SetTexture(1, SHARED.GammaLUTTexture);
for (int x = 2; x < 8; x++)
Expand Down Expand Up @@ -951,20 +958,19 @@ inline void m_IDirect3DDevice9Ex::ApplyBrightnessLevel()
// Reset textures
ProxyInterface->SetTexture(0, nullptr);
ProxyInterface->SetTexture(1, nullptr);

// Reset shaders
ProxyInterface->SetPixelShader(nullptr);
if (pPixelShader)
for (int x = 0; x < 8; x++)
{
ProxyInterface->SetPixelShader(pPixelShader);
pPixelShader->Release();
}
if (pVertexShader)
{
ProxyInterface->SetVertexShader(pVertexShader);
pVertexShader->Release();
if (pTexture[x])
{
ProxyInterface->SetTexture(x, pTexture[x]);
pTexture[x]->Release();
}
}

// Reset shaders
ProxyInterface->SetPixelShader(pPixelShader);
ProxyInterface->SetVertexShader(pVertexShader);

// Cleanup
pBackBuffer->Release();

Expand Down Expand Up @@ -1080,7 +1086,7 @@ void m_IDirect3DDevice9Ex::GetGammaRamp(THIS_ UINT iSwapChain, D3DGAMMARAMP* pRa
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";

if (pRamp && SHARED.IsWindowMode)
if (pRamp && Config.WindowModeGammaShader && SHARED.IsWindowMode)
{
if (iSwapChain)
{
Expand All @@ -1098,7 +1104,7 @@ void m_IDirect3DDevice9Ex::SetGammaRamp(THIS_ UINT iSwapChain, DWORD Flags, CONS
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";

if (pRamp && SHARED.IsWindowMode)
if (pRamp && Config.WindowModeGammaShader && SHARED.IsWindowMode)
{
if (iSwapChain)
{
Expand Down

0 comments on commit 05c5e81

Please sign in to comment.