fix switch screen and blackscreen on opengl + window borderless

This commit is contained in:
Peakies 2024-02-05 20:58:22 +03:30
parent 68ee8a758b
commit 6b7c8f1a28
6 changed files with 44 additions and 14 deletions

View file

@ -173,7 +173,7 @@ public:
virtual void ServerBrowserUpdate() = 0;
// gfx
virtual void SwitchWindowScreen(int Index) = 0;
virtual void SwitchWindowScreen(int Index, int WindowMode = -1) = 0;
virtual void SetWindowParams(int FullscreenMode, bool IsBorderless) = 0;
virtual void ToggleWindowVSync() = 0;
virtual void Notify(const char *pTitle, const char *pMessage) = 0;

View file

@ -3880,21 +3880,41 @@ int CClient::HandleChecksum(int Conn, CUuid Uuid, CUnpacker *pUnpacker)
return 0;
}
void CClient::SwitchWindowScreen(int Index)
void CClient::SwitchWindowScreen(int Index, int WindowMode)
{
// Todo SDL: remove this when fixed (changing screen when in fullscreen is bugged)
if(g_Config.m_GfxFullscreen)
SetWindowParams(0, false);
if(Graphics()->SetWindowScreen(Index))
{
SetWindowParams(0, g_Config.m_GfxBorderless);
if(Graphics()->SetWindowScreen(Index))
g_Config.m_GfxScreen = Index;
SetWindowParams(g_Config.m_GfxFullscreen, g_Config.m_GfxBorderless);
g_Config.m_GfxScreen = Index;
}
else
static const int MAX_RESOLUTIONS = 256;
static CVideoMode s_aModes[MAX_RESOLUTIONS];
static int s_NumNodes = Graphics()->GetVideoModes(s_aModes, MAX_RESOLUTIONS, g_Config.m_GfxScreen);
for(int i = 0; i < s_NumNodes; ++i)
{
if(Graphics()->SetWindowScreen(Index))
g_Config.m_GfxScreen = Index;
SetWindowParams(3, false);
if(s_aModes[i].m_WindowWidth == g_Config.m_GfxDesktopWidth && s_aModes[i].m_WindowHeight == g_Config.m_GfxDesktopHeight)
{
const int Depth = s_aModes[i].m_Red + s_aModes[i].m_Green + s_aModes[i].m_Blue > 16 ? 24 : 16;
g_Config.m_GfxColorDepth = Depth;
g_Config.m_GfxScreenWidth = s_aModes[i].m_WindowWidth;
g_Config.m_GfxScreenHeight = s_aModes[i].m_WindowHeight;
g_Config.m_GfxScreenRefreshRate = s_aModes[i].m_RefreshRate;
Graphics()->Resize(g_Config.m_GfxScreenWidth, g_Config.m_GfxScreenHeight, g_Config.m_GfxScreenRefreshRate);
break;
}
}
if(WindowMode == 0)
SetWindowParams(0, false);
else if(WindowMode == 1)
SetWindowParams(0, true);
else if(WindowMode == 2)
SetWindowParams(3, false);
else if(WindowMode == 3)
SetWindowParams(2, false);
else if(WindowMode == 4)
SetWindowParams(1, false);
}
void CClient::ConchainWindowScreen(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
@ -3903,7 +3923,7 @@ void CClient::ConchainWindowScreen(IConsole::IResult *pResult, void *pUserData,
if(pSelf->Graphics() && pResult->NumArguments())
{
if(g_Config.m_GfxScreen != pResult->GetInteger(0))
pSelf->SwitchWindowScreen(pResult->GetInteger(0));
pSelf->SwitchWindowScreen(pResult->GetInteger(0), g_Config.m_GfxWindowMode);
}
else
pfnCallback(pResult, pCallbackUserData);

View file

@ -457,7 +457,7 @@ public:
virtual int HandleChecksum(int Conn, CUuid Uuid, CUnpacker *pUnpacker);
// gfx
void SwitchWindowScreen(int Index) override;
void SwitchWindowScreen(int Index, int WindowMode = -1) override;
void SetWindowParams(int FullscreenMode, bool IsBorderless) override;
void ToggleWindowVSync() override;
void Notify(const char *pTitle, const char *pMessage) override;

View file

@ -318,6 +318,7 @@ MACRO_CONFIG_INT(SndServerMessage, snd_servermessage, 1, 0, 1, CFGFLAG_SAVE | CF
MACRO_CONFIG_INT(SndHighlight, snd_highlight, 1, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Enable highlighted chat sound")
MACRO_CONFIG_INT(GfxScreen, gfx_screen, 0, 0, 15, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Screen index")
MACRO_CONFIG_INT(GfxWindowMode, gfx_window_mode, 0, 0, 5, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Screen window mode")
MACRO_CONFIG_INT(GfxScreenWidth, gfx_screen_width, 0, 0, 0, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Screen resolution width")
MACRO_CONFIG_INT(GfxScreenHeight, gfx_screen_height, 0, 0, 0, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Screen resolution height")
MACRO_CONFIG_INT(GfxScreenRefreshRate, gfx_screen_refresh_rate, 0, 0, 0, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Screen refresh rate")

View file

@ -1551,6 +1551,8 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView)
Client()->SetWindowParams(2, false);
else if(NewWindowMode == 4)
Client()->SetWindowParams(1, false);
g_Config.m_GfxWindowMode = NewWindowMode;
}
if(Graphics()->GetNumScreens() > 1)
@ -1578,7 +1580,7 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView)
const int NewScreen = UI()->DoDropDown(&ScreenDropDown, g_Config.m_GfxScreen, s_vpScreenNames.data(), s_vpScreenNames.size(), s_ScreenDropDownState);
if(NewScreen != g_Config.m_GfxScreen)
{
Client()->SwitchWindowScreen(NewScreen);
Client()->SwitchWindowScreen(NewScreen, g_Config.m_GfxWindowMode);
s_NumNodes = Graphics()->GetVideoModes(s_aModes, MAX_RESOLUTIONS, g_Config.m_GfxScreen);
}
}

View file

@ -14,3 +14,10 @@ void RustVersionPrint(const ::IConsole &console) noexcept {
void RustVersionRegister(::IConsole &console) noexcept {
cxxbridge1$RustVersionRegister(console);
}
void cxxbridge1$RustVersionPrint(const ::IConsole &console) noexcept
{
}
void cxxbridge1$RustVersionRegister(::IConsole &console) noexcept
{
}