Skip to content

Commit 00f7fe2

Browse files
committed
Clear up & fix high dpi handling.
1 parent e59a2c0 commit 00f7fe2

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/engine/client/backend_sdl.cpp

+20-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <SDL_stdinc.h>
2+
#include <SDL_vulkan.h>
13
#include <base/detect.h>
24

35
#ifndef CONF_BACKEND_OPENGL_ES
@@ -987,9 +989,13 @@ void CGraphicsBackend_SDL_GL::GetCurrentVideoMode(CVideoMode &CurMode, float HiD
987989
{
988990
int Width = 0;
989991
int Height = 0;
990-
SDL_GL_GetDrawableSize(m_pWindow, &Width, &Height);
991-
DpMode.w = Width;
992-
DpMode.h = Height;
992+
if(m_BackendType != EBackendType::BACKEND_TYPE_VULKAN)
993+
SDL_GL_GetDrawableSize(m_pWindow, &Width, &Height);
994+
else
995+
SDL_Vulkan_GetDrawableSize(m_pWindow, &Width, &Height);
996+
// SDL video modes are in screen space which are logical pixels
997+
DpMode.w = Width / HiDPIScale;
998+
DpMode.h = Height / HiDPIScale;
993999
}
9941000
}
9951001
DisplayToVideoMode(&CurMode, &DpMode, HiDPIScale, DpMode.refresh_rate);
@@ -1243,8 +1249,13 @@ int CGraphicsBackend_SDL_GL::Init(const char *pName, int *pScreen, int *pWidth,
12431249
InitError = IsVersionSupportedGlew(m_BackendType, g_Config.m_GfxGLMajor, g_Config.m_GfxGLMinor, g_Config.m_GfxGLPatch, GlewMajor, GlewMinor, GlewPatch);
12441250

12451251
// SDL_GL_GetDrawableSize reports HiDPI resolution even with SDL_WINDOW_ALLOW_HIGHDPI not set, which is wrong
1246-
if(SdlFlags & SDL_WINDOW_ALLOW_HIGHDPI && IsOpenGLFamilyBackend)
1247-
SDL_GL_GetDrawableSize(m_pWindow, pCurrentWidth, pCurrentHeight);
1252+
if(SdlFlags & SDL_WINDOW_ALLOW_HIGHDPI)
1253+
{
1254+
if(IsOpenGLFamilyBackend)
1255+
SDL_GL_GetDrawableSize(m_pWindow, pCurrentWidth, pCurrentHeight);
1256+
else
1257+
SDL_Vulkan_GetDrawableSize(m_pWindow, pCurrentWidth, pCurrentHeight);
1258+
}
12481259
else
12491260
SDL_GetWindowSize(m_pWindow, pCurrentWidth, pCurrentHeight);
12501261
SDL_GetWindowSize(m_pWindow, pWidth, pHeight);
@@ -1616,7 +1627,10 @@ bool CGraphicsBackend_SDL_GL::ResizeWindow(int w, int h, int RefreshRate)
16161627

16171628
void CGraphicsBackend_SDL_GL::GetViewportSize(int &w, int &h)
16181629
{
1619-
SDL_GL_GetDrawableSize(m_pWindow, &w, &h);
1630+
if(m_BackendType != EBackendType::BACKEND_TYPE_VULKAN)
1631+
SDL_GL_GetDrawableSize(m_pWindow, &w, &h);
1632+
else
1633+
SDL_Vulkan_GetDrawableSize(m_pWindow, &w, &h);
16201634
}
16211635

16221636
void CGraphicsBackend_SDL_GL::NotifyWindow()

src/engine/client/graphics_threaded.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -2596,8 +2596,18 @@ void CGraphics_Threaded::GotResized(int w, int h, int RefreshRate)
25962596
g_Config.m_GfxScreenWidth = w;
25972597
g_Config.m_GfxScreenHeight = h;
25982598
g_Config.m_GfxScreenRefreshRate = m_ScreenRefreshRate;
2599+
2600+
auto OldDpi = m_ScreenHiDPIScale;
25992601
m_ScreenHiDPIScale = m_ScreenWidth / (float)g_Config.m_GfxScreenWidth;
26002602

2603+
// A DPI change must notify the listeners, since e.g. video modes
2604+
// currently depend on it.
2605+
if(OldDpi != m_ScreenHiDPIScale)
2606+
{
2607+
for(auto &PropChangedListener : m_vPropChangeListeners)
2608+
PropChangedListener();
2609+
}
2610+
26012611
UpdateViewport(0, 0, m_ScreenWidth, m_ScreenHeight, true);
26022612

26032613
// kick the command buffer and wait

0 commit comments

Comments
 (0)