Fix windows macro and split the resize events

This commit is contained in:
Jupeyy 2022-01-15 16:20:01 +01:00
parent ca07c0a92f
commit 69202fdc22
8 changed files with 87 additions and 57 deletions

View file

@ -309,7 +309,7 @@ static bool BackendInitGlew(EBackendType BackendType, int &GlewMajor, int &GlewM
return true; return true;
} }
// Don't allow GL 3.3, if the driver doesn't support atleast OpenGL 4.5 // Don't allow GL 3.3, if the driver doesn't support atleast OpenGL 4.5
#ifndef CONF_PLATFORM_WINDOWS #ifndef CONF_FAMILY_WINDOWS
if(GLEW_VERSION_4_4) if(GLEW_VERSION_4_4)
{ {
GlewMajor = 4; GlewMajor = 4;
@ -726,6 +726,16 @@ void CGraphicsBackend_SDL_OpenGL::GetVideoModes(CVideoMode *pModes, int MaxModes
void CGraphicsBackend_SDL_OpenGL::GetCurrentVideoMode(CVideoMode &CurMode, int HiDPIScale, int MaxWindowWidth, int MaxWindowHeight, int Screen) void CGraphicsBackend_SDL_OpenGL::GetCurrentVideoMode(CVideoMode &CurMode, int HiDPIScale, int MaxWindowWidth, int MaxWindowHeight, int Screen)
{ {
SDL_DisplayMode DPMode; SDL_DisplayMode DPMode;
// if "real" fullscreen, obtain the video mode for that
if((SDL_GetWindowFlags(m_pWindow) & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN)
{
if(SDL_GetCurrentDisplayMode(Screen, &DPMode))
{
dbg_msg("gfx", "unable to get display mode: %s", SDL_GetError());
}
}
else
{
if(SDL_GetDesktopDisplayMode(Screen, &DPMode) < 0) if(SDL_GetDesktopDisplayMode(Screen, &DPMode) < 0)
{ {
dbg_msg("gfx", "unable to get display mode: %s", SDL_GetError()); dbg_msg("gfx", "unable to get display mode: %s", SDL_GetError());
@ -738,6 +748,7 @@ void CGraphicsBackend_SDL_OpenGL::GetCurrentVideoMode(CVideoMode &CurMode, int H
DPMode.w = Width; DPMode.w = Width;
DPMode.h = Height; DPMode.h = Height;
} }
}
DisplayToVideoMode(&CurMode, &DPMode, HiDPIScale, DPMode.refresh_rate); DisplayToVideoMode(&CurMode, &DPMode, HiDPIScale, DPMode.refresh_rate);
} }
@ -1173,16 +1184,16 @@ void CGraphicsBackend_SDL_OpenGL::SetWindowGrab(bool Grab)
SDL_SetWindowGrab(m_pWindow, Grab ? SDL_TRUE : SDL_FALSE); SDL_SetWindowGrab(m_pWindow, Grab ? SDL_TRUE : SDL_FALSE);
} }
void CGraphicsBackend_SDL_OpenGL::ResizeWindow(int w, int h, int RefreshRate) bool CGraphicsBackend_SDL_OpenGL::ResizeWindow(int w, int h, int RefreshRate)
{ {
// don't call resize events when the window is at fullscreen desktop // don't call resize events when the window is at fullscreen desktop
if(!m_pWindow || (SDL_GetWindowFlags(m_pWindow) & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) if(!m_pWindow || (SDL_GetWindowFlags(m_pWindow) & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP)
return; return false;
// if the window is at fullscreen use SDL_SetWindowDisplayMode instead, suggested by SDL // if the window is at fullscreen use SDL_SetWindowDisplayMode instead, suggested by SDL
if(SDL_GetWindowFlags(m_pWindow) & SDL_WINDOW_FULLSCREEN) if(SDL_GetWindowFlags(m_pWindow) & SDL_WINDOW_FULLSCREEN)
{ {
#ifdef CONF_PLATFORM_WINDOWS #ifdef CONF_FAMILY_WINDOWS
// in windows make the window windowed mode first, this prevents strange window glitches (other games probably do something similar) // in windows make the window windowed mode first, this prevents strange window glitches (other games probably do something similar)
SetWindowParams(0, 1); SetWindowParams(0, 1);
#endif #endif
@ -1193,11 +1204,12 @@ void CGraphicsBackend_SDL_OpenGL::ResizeWindow(int w, int h, int RefreshRate)
SetMode.h = h; SetMode.h = h;
SetMode.refresh_rate = RefreshRate; SetMode.refresh_rate = RefreshRate;
SDL_SetWindowDisplayMode(m_pWindow, SDL_GetClosestDisplayMode(g_Config.m_GfxScreen, &SetMode, &ClosestMode)); SDL_SetWindowDisplayMode(m_pWindow, SDL_GetClosestDisplayMode(g_Config.m_GfxScreen, &SetMode, &ClosestMode));
#ifdef CONF_PLATFORM_WINDOWS #ifdef CONF_FAMILY_WINDOWS
// now change it back to fullscreen, this will restore the above set state, bcs SDL saves fullscreen modes appart from other video modes (as of SDL 2.0.16) // now change it back to fullscreen, this will restore the above set state, bcs SDL saves fullscreen modes appart from other video modes (as of SDL 2.0.16)
// see implementation of SDL_SetWindowDisplayMode // see implementation of SDL_SetWindowDisplayMode
SetWindowParams(1, 0); SetWindowParams(1, 0);
#endif #endif
return true;
} }
else else
{ {
@ -1206,6 +1218,8 @@ void CGraphicsBackend_SDL_OpenGL::ResizeWindow(int w, int h, int RefreshRate)
// remove maximize flag // remove maximize flag
SDL_RestoreWindow(m_pWindow); SDL_RestoreWindow(m_pWindow);
} }
return false;
} }
void CGraphicsBackend_SDL_OpenGL::GetViewportSize(int &w, int &h) void CGraphicsBackend_SDL_OpenGL::GetViewportSize(int &w, int &h)

View file

@ -260,7 +260,7 @@ public:
virtual int WindowActive(); virtual int WindowActive();
virtual int WindowOpen(); virtual int WindowOpen();
virtual void SetWindowGrab(bool Grab); virtual void SetWindowGrab(bool Grab);
virtual void ResizeWindow(int w, int h, int RefreshRate); virtual bool ResizeWindow(int w, int h, int RefreshRate);
virtual void GetViewportSize(int &w, int &h); virtual void GetViewportSize(int &w, int &h);
virtual void NotifyWindow(); virtual void NotifyWindow();

View file

@ -2315,7 +2315,7 @@ void CGraphics_Threaded::SetWindowParams(int FullscreenMode, bool IsBorderless)
m_pBackend->SetWindowParams(FullscreenMode, IsBorderless); m_pBackend->SetWindowParams(FullscreenMode, IsBorderless);
CVideoMode CurMode; CVideoMode CurMode;
m_pBackend->GetCurrentVideoMode(CurMode, m_ScreenHiDPIScale, g_Config.m_GfxDesktopWidth, g_Config.m_GfxDesktopHeight, g_Config.m_GfxScreen); m_pBackend->GetCurrentVideoMode(CurMode, m_ScreenHiDPIScale, g_Config.m_GfxDesktopWidth, g_Config.m_GfxDesktopHeight, g_Config.m_GfxScreen);
Resize(CurMode.m_WindowWidth, CurMode.m_WindowHeight, CurMode.m_RefreshRate, false, true); GotResized(CurMode.m_WindowWidth, CurMode.m_WindowHeight, CurMode.m_RefreshRate);
} }
bool CGraphics_Threaded::SetWindowScreen(int Index) bool CGraphics_Threaded::SetWindowScreen(int Index)
@ -2344,23 +2344,36 @@ void CGraphics_Threaded::Move(int x, int y)
m_ScreenHiDPIScale = m_ScreenWidth / (float)g_Config.m_GfxScreenWidth; m_ScreenHiDPIScale = m_ScreenWidth / (float)g_Config.m_GfxScreenWidth;
} }
void CGraphics_Threaded::Resize(int w, int h, int RefreshRate, bool SetWindowSize, bool ForceResizeEvent) void CGraphics_Threaded::Resize(int w, int h, int RefreshRate)
{ {
#if defined(CONF_VIDEORECORDER) #if defined(CONF_VIDEORECORDER)
if(IVideo::Current() && IVideo::Current()->IsRecording()) if(IVideo::Current() && IVideo::Current()->IsRecording())
return; return;
#endif #endif
if(!ForceResizeEvent && WindowWidth() == w && WindowHeight() == h && (RefreshRate != -1 && RefreshRate == m_ScreenRefreshRate)) if(WindowWidth() == w && WindowHeight() == h && RefreshRate == m_ScreenRefreshRate)
return; return;
// if the size is changed manually, only set the window resize, a window size changed event is triggered anyway // if the size is changed manually, only set the window resize, a window size changed event is triggered anyway
if(SetWindowSize) if(m_pBackend->ResizeWindow(w, h, RefreshRate))
{ {
m_pBackend->ResizeWindow(w, h, RefreshRate); CVideoMode CurMode;
m_pBackend->GetCurrentVideoMode(CurMode, m_ScreenHiDPIScale, g_Config.m_GfxDesktopWidth, g_Config.m_GfxDesktopHeight, g_Config.m_GfxScreen);
GotResized(w, h, RefreshRate);
} }
else }
void CGraphics_Threaded::GotResized(int w, int h, int RefreshRate)
{ {
#if defined(CONF_VIDEORECORDER)
if(IVideo::Current() && IVideo::Current()->IsRecording())
return;
#endif
// if RefreshRate is -1 use the current config refresh rate
if(RefreshRate == -1)
RefreshRate = g_Config.m_GfxScreenRefreshRate;
// if the size change event is triggered, set all parameters and change the viewport // if the size change event is triggered, set all parameters and change the viewport
m_pBackend->GetViewportSize(m_ScreenWidth, m_ScreenHeight); m_pBackend->GetViewportSize(m_ScreenWidth, m_ScreenHeight);
@ -2368,7 +2381,7 @@ void CGraphics_Threaded::Resize(int w, int h, int RefreshRate, bool SetWindowSiz
if(m_ScreenHeight > 4 * m_ScreenWidth / 5) if(m_ScreenHeight > 4 * m_ScreenWidth / 5)
m_ScreenHeight = 4 * m_ScreenWidth / 5; m_ScreenHeight = 4 * m_ScreenWidth / 5;
m_ScreenRefreshRate = RefreshRate == -1 ? m_ScreenRefreshRate : RefreshRate; m_ScreenRefreshRate = RefreshRate;
g_Config.m_GfxScreenWidth = w; g_Config.m_GfxScreenWidth = w;
g_Config.m_GfxScreenHeight = h; g_Config.m_GfxScreenHeight = h;
@ -2394,7 +2407,6 @@ void CGraphics_Threaded::Resize(int w, int h, int RefreshRate, bool SetWindowSiz
for(auto &ResizeListener : m_ResizeListeners) for(auto &ResizeListener : m_ResizeListeners)
ResizeListener.m_pFunc(ResizeListener.m_pUser); ResizeListener.m_pFunc(ResizeListener.m_pUser);
} }
}
void CGraphics_Threaded::AddWindowResizeListener(WINDOW_RESIZE_FUNC pFunc, void *pUser) void CGraphics_Threaded::AddWindowResizeListener(WINDOW_RESIZE_FUNC pFunc, void *pUser)
{ {

View file

@ -676,7 +676,8 @@ public:
virtual int WindowActive() = 0; virtual int WindowActive() = 0;
virtual int WindowOpen() = 0; virtual int WindowOpen() = 0;
virtual void SetWindowGrab(bool Grab) = 0; virtual void SetWindowGrab(bool Grab) = 0;
virtual void ResizeWindow(int w, int h, int RefreshRate) = 0; // returns true, if the video mode changed
virtual bool ResizeWindow(int w, int h, int RefreshRate) = 0;
virtual void GetViewportSize(int &w, int &h) = 0; virtual void GetViewportSize(int &w, int &h) = 0;
virtual void NotifyWindow() = 0; virtual void NotifyWindow() = 0;
@ -1168,7 +1169,8 @@ public:
void SetWindowParams(int FullscreenMode, bool IsBorderless) override; void SetWindowParams(int FullscreenMode, bool IsBorderless) override;
bool SetWindowScreen(int Index) override; bool SetWindowScreen(int Index) override;
void Move(int x, int y) override; void Move(int x, int y) override;
void Resize(int w, int h, int RefreshRate, bool SetWindowSize = false, bool ForceResizeEvent = false) override; void Resize(int w, int h, int RefreshRate) override;
void GotResized(int w, int h, int RefreshRate) override;
void AddWindowResizeListener(WINDOW_RESIZE_FUNC pFunc, void *pUser) override; void AddWindowResizeListener(WINDOW_RESIZE_FUNC pFunc, void *pUser) override;
int GetWindowScreen() override; int GetWindowScreen() override;

View file

@ -150,7 +150,8 @@ public:
void SetWindowParams(int FullscreenMode, bool IsBorderless) override{}; void SetWindowParams(int FullscreenMode, bool IsBorderless) override{};
bool SetWindowScreen(int Index) override { return false; }; bool SetWindowScreen(int Index) override { return false; };
void Move(int x, int y) override{}; void Move(int x, int y) override{};
void Resize(int w, int h, int RefreshRate, bool SetWindowSize = false, bool ForceResizeEvent = false) override{}; void Resize(int w, int h, int RefreshRate) override{};
void GotResized(int w, int h, int RefreshRate) override{};
void AddWindowResizeListener(WINDOW_RESIZE_FUNC pFunc, void *pUser) override{}; void AddWindowResizeListener(WINDOW_RESIZE_FUNC pFunc, void *pUser) override{};
int GetWindowScreen() override { return 0; }; int GetWindowScreen() override { return 0; };

View file

@ -364,7 +364,7 @@ int CInput::Update()
break; break;
// listen to size changes, this includes our manual changes and the ones by the window manager // listen to size changes, this includes our manual changes and the ones by the window manager
case SDL_WINDOWEVENT_SIZE_CHANGED: case SDL_WINDOWEVENT_SIZE_CHANGED:
Graphics()->Resize(Event.window.data1, Event.window.data2, -1); Graphics()->GotResized(Event.window.data1, Event.window.data2, -1);
break; break;
case SDL_WINDOWEVENT_FOCUS_GAINED: case SDL_WINDOWEVENT_FOCUS_GAINED:
if(m_InputGrabbed) if(m_InputGrabbed)

View file

@ -214,7 +214,8 @@ public:
virtual bool SetVSync(bool State) = 0; virtual bool SetVSync(bool State) = 0;
virtual int GetWindowScreen() = 0; virtual int GetWindowScreen() = 0;
virtual void Move(int x, int y) = 0; virtual void Move(int x, int y) = 0;
virtual void Resize(int w, int h, int RefreshRate, bool SetWindowSize = false, bool ForceResizeEvent = false) = 0; virtual void Resize(int w, int h, int RefreshRate) = 0;
virtual void GotResized(int w, int h, int RefreshRate) = 0;
virtual void AddWindowResizeListener(WINDOW_RESIZE_FUNC pFunc, void *pUser) = 0; virtual void AddWindowResizeListener(WINDOW_RESIZE_FUNC pFunc, void *pUser) = 0;
virtual void WindowDestroyNtf(uint32_t WindowID) = 0; virtual void WindowDestroyNtf(uint32_t WindowID) = 0;

View file

@ -1167,7 +1167,7 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView)
g_Config.m_GfxScreenWidth = s_aModes[NewSelected].m_WindowWidth; g_Config.m_GfxScreenWidth = s_aModes[NewSelected].m_WindowWidth;
g_Config.m_GfxScreenHeight = s_aModes[NewSelected].m_WindowHeight; g_Config.m_GfxScreenHeight = s_aModes[NewSelected].m_WindowHeight;
g_Config.m_GfxScreenRefreshRate = s_aModes[NewSelected].m_RefreshRate; g_Config.m_GfxScreenRefreshRate = s_aModes[NewSelected].m_RefreshRate;
Graphics()->Resize(g_Config.m_GfxScreenWidth, g_Config.m_GfxScreenHeight, g_Config.m_GfxScreenRefreshRate, true); Graphics()->Resize(g_Config.m_GfxScreenWidth, g_Config.m_GfxScreenHeight, g_Config.m_GfxScreenRefreshRate);
} }
// switches // switches