mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
detect display changes and clamp the resolution
This commit is contained in:
parent
24ccffb005
commit
08ecb91622
|
@ -190,12 +190,23 @@ void CCommandProcessorFragment_SDL::Cmd_VideoModes(const CCommandBuffer::SComman
|
|||
int maxModes = SDL_GetNumDisplayModes(pCommand->m_Screen),
|
||||
numModes = 0;
|
||||
|
||||
for(int i = 0; i < maxModes; i++)
|
||||
for(int i = -1; i < maxModes; i++)
|
||||
{
|
||||
if(SDL_GetDisplayMode(pCommand->m_Screen, i, &mode) < 0)
|
||||
if(i == -1)
|
||||
{
|
||||
dbg_msg("gfx", "unable to get display mode: %s", SDL_GetError());
|
||||
continue;
|
||||
if(SDL_GetDesktopDisplayMode(pCommand->m_Screen, &mode) < 0)
|
||||
{
|
||||
dbg_msg("gfx", "unable to get display mode: %s", SDL_GetError());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(SDL_GetDisplayMode(pCommand->m_Screen, i, &mode) < 0)
|
||||
{
|
||||
dbg_msg("gfx", "unable to get display mode: %s", SDL_GetError());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
bool AlreadyFound = false;
|
||||
|
@ -745,11 +756,14 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Screen, int *pWidt
|
|||
dbg_msg("gfx", "unable to get desktop resolution: %s", SDL_GetError());
|
||||
return EGraphicsBackendErrorCodes::GRAPHICS_BACKEND_ERROR_CODE_SDL_SCREEN_RESOLUTION_REQUEST_FAILED;
|
||||
}
|
||||
|
||||
bool IsDesktopChanged = *pDesktopWidth == 0 || *pDesktopHeight == 0 || *pDesktopWidth != DisplayMode.w || *pDesktopHeight != DisplayMode.h;
|
||||
|
||||
*pDesktopWidth = DisplayMode.w;
|
||||
*pDesktopHeight = DisplayMode.h;
|
||||
|
||||
// use desktop resolution as default resolution
|
||||
if(*pWidth == 0 || *pHeight == 0)
|
||||
// use desktop resolution as default resolution, clamp resolution if users's display is smaller than we remembered
|
||||
if(*pWidth == 0 || *pHeight == 0 || (IsDesktopChanged && (*pWidth > *pDesktopWidth || *pHeight > *pDesktopHeight)))
|
||||
{
|
||||
*pWidth = *pDesktopWidth;
|
||||
*pHeight = *pDesktopHeight;
|
||||
|
|
|
@ -2085,7 +2085,7 @@ int CGraphics_Threaded::IssueInit()
|
|||
if(g_Config.m_GfxResizable)
|
||||
Flags |= IGraphicsBackend::INITFLAG_RESIZABLE;
|
||||
|
||||
int r = m_pBackend->Init("DDNet Client", &g_Config.m_GfxScreen, &g_Config.m_GfxScreenWidth, &g_Config.m_GfxScreenHeight, g_Config.m_GfxFsaaSamples, Flags, &m_DesktopScreenWidth, &m_DesktopScreenHeight, &m_ScreenWidth, &m_ScreenHeight, m_pStorage);
|
||||
int r = m_pBackend->Init("DDNet Client", &g_Config.m_GfxScreen, &g_Config.m_GfxScreenWidth, &g_Config.m_GfxScreenHeight, g_Config.m_GfxFsaaSamples, Flags, &g_Config.m_GfxDesktopWidth, &g_Config.m_GfxDesktopHeight, &m_ScreenWidth, &m_ScreenHeight, m_pStorage);
|
||||
AddBackEndWarningIfExists();
|
||||
m_IsNewOpenGL = m_pBackend->IsNewOpenGL();
|
||||
m_OpenGLTileBufferingEnabled = m_IsNewOpenGL || m_pBackend->HasTileBuffering();
|
||||
|
@ -2537,8 +2537,8 @@ int CGraphics_Threaded::GetVideoModes(CVideoMode *pModes, int MaxModes, int Scre
|
|||
Cmd.m_MaxModes = MaxModes;
|
||||
Cmd.m_pNumModes = &NumModes;
|
||||
Cmd.m_HiDPIScale = m_ScreenHiDPIScale;
|
||||
Cmd.m_MaxWindowWidth = m_DesktopScreenWidth;
|
||||
Cmd.m_MaxWindowHeight = m_DesktopScreenHeight;
|
||||
Cmd.m_MaxWindowWidth = g_Config.m_GfxDesktopWidth;
|
||||
Cmd.m_MaxWindowHeight = g_Config.m_GfxDesktopHeight;
|
||||
Cmd.m_Screen = Screen;
|
||||
|
||||
if(!AddCmd(
|
||||
|
|
|
@ -1166,8 +1166,8 @@ public:
|
|||
|
||||
int GetVideoModes(CVideoMode *pModes, int MaxModes, int Screen) override;
|
||||
|
||||
virtual int GetDesktopScreenWidth() const { return m_DesktopScreenWidth; }
|
||||
virtual int GetDesktopScreenHeight() const { return m_DesktopScreenHeight; }
|
||||
virtual int GetDesktopScreenWidth() const { return g_Config.m_GfxScreenWidth; }
|
||||
virtual int GetDesktopScreenHeight() const { return g_Config.m_GfxScreenHeight; }
|
||||
|
||||
// synchronization
|
||||
void InsertSignal(CSemaphore *pSemaphore) override;
|
||||
|
|
|
@ -167,8 +167,6 @@ class IGraphics : public IInterface
|
|||
protected:
|
||||
int m_ScreenWidth;
|
||||
int m_ScreenHeight;
|
||||
int m_DesktopScreenWidth;
|
||||
int m_DesktopScreenHeight;
|
||||
float m_ScreenHiDPIScale;
|
||||
|
||||
public:
|
||||
|
|
|
@ -98,6 +98,8 @@ MACRO_CONFIG_INT(SndHighlight, snd_highlight, 1, 0, 1, CFGFLAG_SAVE | CFGFLAG_CL
|
|||
MACRO_CONFIG_INT(GfxScreen, gfx_screen, 0, 0, 15, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Screen index")
|
||||
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(GfxDesktopWidth, gfx_desktop_height, 0, 0, 0, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Desktop resolution width for detecting display changes (not recommended to change manually)")
|
||||
MACRO_CONFIG_INT(GfxDesktopHeight, gfx_desktop_height, 0, 0, 0, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Desktop resolution height for detecting display changes (not recommended to change manually)")
|
||||
#if !defined(CONF_PLATFORM_MACOS)
|
||||
MACRO_CONFIG_INT(GfxBorderless, gfx_borderless, 0, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Borderless window (not to be used with fullscreen)")
|
||||
MACRO_CONFIG_INT(GfxFullscreen, gfx_fullscreen, 1, 0, 2, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Set fullscreen mode: 0=no fullscreen, 1=pure fullscreen, 2=desktop fullscreen")
|
||||
|
|
Loading…
Reference in a new issue