From c89192990b1f9fb1adbb0c3a67cbf835c0060c21 Mon Sep 17 00:00:00 2001 From: Sasha Szpakowski Date: Tue, 6 Dec 2022 20:36:36 -0400 Subject: [PATCH] vulkan: potentially improved highdpi support. Mostly untested. --- src/modules/graphics/vulkan/Graphics.cpp | 20 ++++++++------------ src/modules/window/sdl/Window.cpp | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/modules/graphics/vulkan/Graphics.cpp b/src/modules/graphics/vulkan/Graphics.cpp index 90827a67f..8c8e39ee0 100644 --- a/src/modules/graphics/vulkan/Graphics.cpp +++ b/src/modules/graphics/vulkan/Graphics.cpp @@ -28,7 +28,7 @@ #include "Shader.h" #include "Vulkan.h" -#include "SDL_vulkan.h" +#include #include #include @@ -470,7 +470,8 @@ void Graphics::setViewportSize(int width, int height, int pixelwidth, int pixelh this->pixelWidth = pixelwidth; this->pixelHeight = pixelheight; - resetProjection(); + if (!isRenderTargetActive()) + resetProjection(); } bool Graphics::setMode(void *context, int width, int height, int pixelwidth, int pixelheight, bool windowhasstencil, int msaa) @@ -478,6 +479,9 @@ bool Graphics::setMode(void *context, int width, int height, int pixelwidth, int requestedMsaa = msaa; windowHasStencil = windowhasstencil; + // Must be called before the swapchain is created. + setViewportSize(width, height, pixelwidth, pixelheight); + cleanUpFunctions.clear(); cleanUpFunctions.resize(MAX_FRAMES_IN_FLIGHT); @@ -531,8 +535,6 @@ bool Graphics::setMode(void *context, int width, int height, int pixelwidth, int restoreState(states.back()); - setViewportSize(width, height, pixelwidth, pixelheight); - Vulkan::resetShaderSwitches(); frameCounter = 0; @@ -1851,15 +1853,9 @@ VkExtent2D Graphics::chooseSwapExtent(const VkSurfaceCapabilitiesKHR &capabiliti return capabilities.currentExtent; else { - auto window = Module::getInstance(M_WINDOW); - const void *handle = window->getHandle(); - - int width, height; - SDL_Vulkan_GetDrawableSize((SDL_Window*)handle, &width, &height); - VkExtent2D actualExtent = { - static_cast(width), - static_cast(height) + static_cast(pixelWidth), + static_cast(pixelHeight) }; actualExtent.width = clampuint32_t(actualExtent.width, capabilities.minImageExtent.width, capabilities.maxImageExtent.width); diff --git a/src/modules/window/sdl/Window.cpp b/src/modules/window/sdl/Window.cpp index ebf08e5cd..1de1f42c4 100644 --- a/src/modules/window/sdl/Window.cpp +++ b/src/modules/window/sdl/Window.cpp @@ -46,6 +46,10 @@ // SDL #include +#ifdef LOVE_GRAPHICS_VULKAN +#include +#endif + #if defined(LOVE_WINDOWS) #include #include @@ -684,11 +688,16 @@ bool Window::onSizeChanged(int width, int height) windowWidth = width; windowHeight = height; + // TODO: Use SDL_GetWindowSizeInPixels here when supported. if (glcontext != nullptr) SDL_GL_GetDrawableSize(window, &pixelWidth, &pixelHeight); #ifdef LOVE_GRAPHICS_METAL else if (metalView != nullptr) SDL_Metal_GetDrawableSize(window, &pixelWidth, &pixelHeight); +#endif +#ifdef LOVE_GRAPHICS_VULKAN + else if (windowRenderer == graphics::RENDERER_VULKAN) + SDL_Vulkan_GetDrawableSize(window, &pixelWidth, &pixelHeight); #endif else { @@ -716,12 +725,17 @@ void Window::updateSettings(const WindowSettings &newsettings, bool updateGraphi pixelWidth = windowWidth; pixelHeight = windowHeight; + // TODO: Use SDL_GetWindowSizeInPixels here when supported. if ((wflags & SDL_WINDOW_OPENGL) != 0) SDL_GL_GetDrawableSize(window, &pixelWidth, &pixelHeight); #ifdef LOVE_GRAPHICS_METAL else if ((wflags & SDL_WINDOW_METAL) != 0) SDL_Metal_GetDrawableSize(window, &pixelWidth, &pixelHeight); #endif +#ifdef LOVE_GRAPHICS_VULKAN + else if ((wflags & SDL_WINDOW_VULKAN) != 0) + SDL_Vulkan_GetDrawableSize(window, &pixelWidth, &pixelHeight); +#endif if ((wflags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {