dpi-aware resolution list

This commit is contained in:
Freddie Wang 2021-05-06 18:59:30 +08:00
parent 97ab2c6c01
commit 2f008d04d3
5 changed files with 66 additions and 39 deletions

View file

@ -201,7 +201,7 @@ void CCommandProcessorFragment_SDL::Cmd_VideoModes(const CCommandBuffer::SComman
bool AlreadyFound = false;
for(int j = 0; j < numModes; j++)
{
if(pCommand->m_pModes[j].m_Width == mode.w && pCommand->m_pModes[j].m_Height == mode.h)
if(pCommand->m_pModes[j].m_CanvasWidth == mode.w && pCommand->m_pModes[j].m_CanvasHeight == mode.h)
{
AlreadyFound = true;
break;
@ -210,8 +210,15 @@ void CCommandProcessorFragment_SDL::Cmd_VideoModes(const CCommandBuffer::SComman
if(AlreadyFound)
continue;
pCommand->m_pModes[numModes].m_Width = mode.w;
pCommand->m_pModes[numModes].m_Height = mode.h;
int WindowWidth = mode.w / pCommand->m_HiDPIScale;
int WindowHeight = mode.h / pCommand->m_HiDPIScale;
if(WindowWidth > pCommand->m_MaxWindowWidth || WindowHeight > pCommand->m_MaxWindowHeight)
continue;
pCommand->m_pModes[numModes].m_CanvasWidth = mode.w;
pCommand->m_pModes[numModes].m_CanvasHeight = mode.h;
pCommand->m_pModes[numModes].m_WindowWidth = mode.w / pCommand->m_HiDPIScale;
pCommand->m_pModes[numModes].m_WindowHeight = mode.h / pCommand->m_HiDPIScale;
pCommand->m_pModes[numModes].m_Red = 8;
pCommand->m_pModes[numModes].m_Green = 8;
pCommand->m_pModes[numModes].m_Blue = 8;
@ -845,7 +852,12 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Screen, int *pWidt
InitError = IsVersionSupportedGlew(m_BackendType, g_Config.m_GfxOpenGLMajor, g_Config.m_GfxOpenGLMinor, g_Config.m_GfxOpenGLPatch, GlewMajor, GlewMinor, GlewPatch);
SDL_GL_GetDrawableSize(m_pWindow, pCurrentWidth, pCurrentHeight);
// SDL_GL_GetDrawableSize reports HiDPI resolution even with SDL_WINDOW_ALLOW_HIGHDPI not set, which is wrong
if(SdlFlags & SDL_WINDOW_ALLOW_HIGHDPI)
SDL_GL_GetDrawableSize(m_pWindow, pCurrentWidth, pCurrentHeight);
else
SDL_GetWindowSize(m_pWindow, pCurrentWidth, pCurrentHeight);
SDL_GL_SetSwapInterval(Flags & IGraphicsBackend::INITFLAG_VSYNC ? 1 : 0);
SDL_GL_MakeCurrent(NULL, NULL);

View file

@ -33,31 +33,31 @@
#include "graphics_threaded.h"
static CVideoMode g_aFakeModes[] = {
{8192, 4320, 8, 8, 8}, {7680, 4320, 8, 8, 8}, {5120, 2880, 8, 8, 8},
{4096, 2160, 8, 8, 8}, {3840, 2160, 8, 8, 8}, {2560, 1440, 8, 8, 8},
{2048, 1536, 8, 8, 8}, {1920, 2400, 8, 8, 8}, {1920, 1440, 8, 8, 8},
{1920, 1200, 8, 8, 8}, {1920, 1080, 8, 8, 8}, {1856, 1392, 8, 8, 8},
{1800, 1440, 8, 8, 8}, {1792, 1344, 8, 8, 8}, {1680, 1050, 8, 8, 8},
{1600, 1200, 8, 8, 8}, {1600, 1000, 8, 8, 8}, {1440, 1050, 8, 8, 8},
{1440, 900, 8, 8, 8}, {1400, 1050, 8, 8, 8}, {1368, 768, 8, 8, 8},
{1280, 1024, 8, 8, 8}, {1280, 960, 8, 8, 8}, {1280, 800, 8, 8, 8},
{1280, 768, 8, 8, 8}, {1152, 864, 8, 8, 8}, {1024, 768, 8, 8, 8},
{1024, 600, 8, 8, 8}, {800, 600, 8, 8, 8}, {768, 576, 8, 8, 8},
{720, 400, 8, 8, 8}, {640, 480, 8, 8, 8}, {400, 300, 8, 8, 8},
{320, 240, 8, 8, 8},
{8192, 4320, 8192, 4320, 8, 8, 8}, {7680, 4320, 7680, 4320, 8, 8, 8}, {5120, 2880, 5120, 2880, 8, 8, 8},
{4096, 2160, 4096, 2160, 8, 8, 8}, {3840, 2160, 3840, 2160, 8, 8, 8}, {2560, 1440, 2560, 1440, 8, 8, 8},
{2048, 1536, 2048, 1536, 8, 8, 8}, {1920, 2400, 1920, 2400, 8, 8, 8}, {1920, 1440, 1920, 1440, 8, 8, 8},
{1920, 1200, 1920, 1200, 8, 8, 8}, {1920, 1080, 1920, 1080, 8, 8, 8}, {1856, 1392, 1856, 1392, 8, 8, 8},
{1800, 1440, 1800, 1440, 8, 8, 8}, {1792, 1344, 1792, 1344, 8, 8, 8}, {1680, 1050, 1680, 1050, 8, 8, 8},
{1600, 1200, 1600, 1200, 8, 8, 8}, {1600, 1000, 1600, 1000, 8, 8, 8}, {1440, 1050, 1440, 1050, 8, 8, 8},
{1440, 900, 1440, 900, 8, 8, 8}, {1400, 1050, 1400, 1050, 8, 8, 8}, {1368, 768, 1368, 768, 8, 8, 8},
{1280, 1024, 1280, 1024, 8, 8, 8}, {1280, 960, 1280, 960, 8, 8, 8}, {1280, 800, 1280, 800, 8, 8, 8},
{1280, 768, 1280, 768, 8, 8, 8}, {1152, 864, 1152, 864, 8, 8, 8}, {1024, 768, 1024, 768, 8, 8, 8},
{1024, 600, 1024, 600, 8, 8, 8}, {800, 600, 800, 600, 8, 8, 8}, {768, 576, 768, 576, 8, 8, 8},
{720, 400, 720, 400, 8, 8, 8}, {640, 480, 640, 480, 8, 8, 8}, {400, 300, 400, 300, 8, 8, 8},
{320, 240, 320, 240, 8, 8, 8},
{8192, 4320, 5, 6, 5}, {7680, 4320, 5, 6, 5}, {5120, 2880, 5, 6, 5},
{4096, 2160, 5, 6, 5}, {3840, 2160, 5, 6, 5}, {2560, 1440, 5, 6, 5},
{2048, 1536, 5, 6, 5}, {1920, 2400, 5, 6, 5}, {1920, 1440, 5, 6, 5},
{1920, 1200, 5, 6, 5}, {1920, 1080, 5, 6, 5}, {1856, 1392, 5, 6, 5},
{1800, 1440, 5, 6, 5}, {1792, 1344, 5, 6, 5}, {1680, 1050, 5, 6, 5},
{1600, 1200, 5, 6, 5}, {1600, 1000, 5, 6, 5}, {1440, 1050, 5, 6, 5},
{1440, 900, 5, 6, 5}, {1400, 1050, 5, 6, 5}, {1368, 768, 5, 6, 5},
{1280, 1024, 5, 6, 5}, {1280, 960, 5, 6, 5}, {1280, 800, 5, 6, 5},
{1280, 768, 5, 6, 5}, {1152, 864, 5, 6, 5}, {1024, 768, 5, 6, 5},
{1024, 600, 5, 6, 5}, {800, 600, 5, 6, 5}, {768, 576, 5, 6, 5},
{720, 400, 5, 6, 5}, {640, 480, 5, 6, 5}, {400, 300, 5, 6, 5},
{320, 240, 5, 6, 5}};
{8192, 4320, 8192, 4320, 5, 6, 5}, {7680, 4320, 7680, 4320, 5, 6, 5}, {5120, 2880, 5120, 2880, 5, 6, 5},
{4096, 2160, 4096, 2160, 5, 6, 5}, {3840, 2160, 3840, 2160, 5, 6, 5}, {2560, 1440, 2560, 1440, 5, 6, 5},
{2048, 1536, 2048, 1536, 5, 6, 5}, {1920, 2400, 1920, 2400, 5, 6, 5}, {1920, 1440, 1920, 1440, 5, 6, 5},
{1920, 1200, 1920, 1200, 5, 6, 5}, {1920, 1080, 1920, 1080, 5, 6, 5}, {1856, 1392, 1856, 1392, 5, 6, 5},
{1800, 1440, 1800, 1440, 5, 6, 5}, {1792, 1344, 1792, 1344, 5, 6, 5}, {1680, 1050, 1680, 1050, 5, 6, 5},
{1600, 1200, 1600, 1200, 5, 6, 5}, {1600, 1000, 1600, 1000, 5, 6, 5}, {1440, 1050, 1440, 1050, 5, 6, 5},
{1440, 900, 1440, 900, 5, 6, 5}, {1400, 1050, 1400, 1050, 5, 6, 5}, {1368, 768, 1368, 768, 5, 6, 5},
{1280, 1024, 1280, 1024, 5, 6, 5}, {1280, 960, 1280, 960, 5, 6, 5}, {1280, 800, 1280, 800, 5, 6, 5},
{1280, 768, 1280, 768, 5, 6, 5}, {1152, 864, 1152, 864, 5, 6, 5}, {1024, 768, 1024, 768, 5, 6, 5},
{1024, 600, 1024, 600, 5, 6, 5}, {800, 600, 800, 600, 5, 6, 5}, {768, 576, 768, 576, 5, 6, 5},
{720, 400, 720, 400, 5, 6, 5}, {640, 480, 640, 480, 5, 6, 5}, {400, 300, 400, 300, 5, 6, 5},
{320, 240, 320, 240, 5, 6, 5}};
void CGraphics_Threaded::FlushVertices(bool KeepVertices)
{
@ -2093,6 +2093,7 @@ int CGraphics_Threaded::IssueInit()
m_OpenGLQuadContainerBufferingEnabled = m_IsNewOpenGL || m_pBackend->HasQuadContainerBuffering();
m_OpenGLTextBufferingEnabled = m_IsNewOpenGL || (m_OpenGLQuadContainerBufferingEnabled && m_pBackend->HasTextBuffering());
m_OpenGLHasTextureArrays = m_IsNewOpenGL || m_pBackend->Has2DTextureArrays();
m_ScreenHiDPIScale = m_ScreenWidth / (float)g_Config.m_GfxScreenWidth;
return r;
}
@ -2241,6 +2242,12 @@ int CGraphics_Threaded::Init()
if(InitWindow() != 0)
return -1;
for(auto &FakeMode : g_aFakeModes)
{
FakeMode.m_WindowWidth = FakeMode.m_CanvasWidth / m_ScreenHiDPIScale;
FakeMode.m_WindowHeight = FakeMode.m_CanvasHeight / m_ScreenHiDPIScale;
}
// create command buffers
for(auto &pCommandBuffer : m_apCommandBuffers)
pCommandBuffer = new CCommandBuffer(CMD_BUFFER_CMD_BUFFER_SIZE, CMD_BUFFER_DATA_BUFFER_SIZE);
@ -2315,15 +2322,12 @@ void CGraphics_Threaded::Resize(int w, int h, bool SetWindowSize)
return;
#endif
if(m_DesktopScreenWidth == w && m_DesktopScreenHeight == h)
if(WindowWidth() == w && WindowHeight() == h)
return;
if(SetWindowSize)
m_pBackend->ResizeWindow(w, h);
m_DesktopScreenWidth = w;
m_DesktopScreenHeight = h;
m_pBackend->GetViewportSize(m_ScreenWidth, m_ScreenHeight);
// adjust the viewport to only allow certain aspect ratios
@ -2532,6 +2536,9 @@ int CGraphics_Threaded::GetVideoModes(CVideoMode *pModes, int MaxModes, int Scre
Cmd.m_pModes = pModes;
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_Screen = Screen;
if(!AddCmd(

View file

@ -498,6 +498,9 @@ public:
CVideoMode *m_pModes; // processor will fill this in
int m_MaxModes; // maximum of modes the processor can write to the m_pModes
int *m_pNumModes; // processor will write to this pointer
int m_HiDPIScale;
int m_MaxWindowWidth;
int m_MaxWindowHeight;
int m_Screen;
};

View file

@ -93,7 +93,8 @@ public:
class CVideoMode
{
public:
int m_Width, m_Height;
int m_CanvasWidth, m_CanvasHeight;
int m_WindowWidth, m_WindowHeight;
int m_Red, m_Green, m_Blue;
};
@ -168,6 +169,7 @@ protected:
int m_ScreenHeight;
int m_DesktopScreenWidth;
int m_DesktopScreenHeight;
float m_ScreenHiDPIScale;
public:
/* Constants: Texture Loading Flags
@ -202,6 +204,9 @@ public:
int ScreenWidth() const { return m_ScreenWidth; }
int ScreenHeight() const { return m_ScreenHeight; }
float ScreenAspect() const { return (float)ScreenWidth() / (float)ScreenHeight(); }
float ScreenHiDPIScale() const { return m_ScreenHiDPIScale; }
int WindowWidth() const { return m_ScreenWidth / m_ScreenHiDPIScale; }
int WindowHeight() const { return m_ScreenHeight / m_ScreenHiDPIScale; }
virtual void SetWindowParams(int FullscreenMode, bool IsBorderless) = 0;
virtual bool SetWindowScreen(int Index) = 0;

View file

@ -1108,8 +1108,8 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView)
{
const int Depth = s_aModes[i].m_Red + s_aModes[i].m_Green + s_aModes[i].m_Blue > 16 ? 24 : 16;
if(g_Config.m_GfxColorDepth == Depth &&
g_Config.m_GfxScreenWidth == s_aModes[i].m_Width &&
g_Config.m_GfxScreenHeight == s_aModes[i].m_Height)
g_Config.m_GfxScreenWidth == s_aModes[i].m_WindowWidth &&
g_Config.m_GfxScreenHeight == s_aModes[i].m_WindowHeight)
{
OldSelected = i;
}
@ -1117,8 +1117,8 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView)
CListboxItem Item = UiDoListboxNextItem(&s_aModes[i], OldSelected == i);
if(Item.m_Visible)
{
int G = gcd(s_aModes[i].m_Width, s_aModes[i].m_Height);
str_format(aBuf, sizeof(aBuf), " %dx%d %d bit (%d:%d)", s_aModes[i].m_Width, s_aModes[i].m_Height, Depth, s_aModes[i].m_Width / G, s_aModes[i].m_Height / G);
int G = gcd(s_aModes[i].m_CanvasWidth, s_aModes[i].m_CanvasHeight);
str_format(aBuf, sizeof(aBuf), " %dx%d %d bit (%d:%d)", s_aModes[i].m_CanvasWidth, s_aModes[i].m_CanvasHeight, Depth, s_aModes[i].m_CanvasWidth / G, s_aModes[i].m_CanvasHeight / G);
UI()->DoLabelScaled(&Item.m_Rect, aBuf, 16.0f, -1);
}
}
@ -1128,8 +1128,8 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView)
{
const int Depth = s_aModes[NewSelected].m_Red + s_aModes[NewSelected].m_Green + s_aModes[NewSelected].m_Blue > 16 ? 24 : 16;
g_Config.m_GfxColorDepth = Depth;
g_Config.m_GfxScreenWidth = s_aModes[NewSelected].m_Width;
g_Config.m_GfxScreenHeight = s_aModes[NewSelected].m_Height;
g_Config.m_GfxScreenWidth = s_aModes[NewSelected].m_WindowWidth;
g_Config.m_GfxScreenHeight = s_aModes[NewSelected].m_WindowHeight;
Graphics()->Resize(g_Config.m_GfxScreenWidth, g_Config.m_GfxScreenHeight, true);
}