vulkan: potentially improved highdpi support.

Mostly untested.
This commit is contained in:
Sasha Szpakowski
2022-12-06 20:36:36 -04:00
parent 8119b87b89
commit c89192990b
2 changed files with 22 additions and 12 deletions
+8 -12
View File
@@ -28,7 +28,7 @@
#include "Shader.h" #include "Shader.h"
#include "Vulkan.h" #include "Vulkan.h"
#include "SDL_vulkan.h" #include <SDL_vulkan.h>
#include <algorithm> #include <algorithm>
#include <vector> #include <vector>
@@ -470,7 +470,8 @@ void Graphics::setViewportSize(int width, int height, int pixelwidth, int pixelh
this->pixelWidth = pixelwidth; this->pixelWidth = pixelwidth;
this->pixelHeight = pixelheight; this->pixelHeight = pixelheight;
resetProjection(); if (!isRenderTargetActive())
resetProjection();
} }
bool Graphics::setMode(void *context, int width, int height, int pixelwidth, int pixelheight, bool windowhasstencil, int msaa) 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; requestedMsaa = msaa;
windowHasStencil = windowhasstencil; windowHasStencil = windowhasstencil;
// Must be called before the swapchain is created.
setViewportSize(width, height, pixelwidth, pixelheight);
cleanUpFunctions.clear(); cleanUpFunctions.clear();
cleanUpFunctions.resize(MAX_FRAMES_IN_FLIGHT); 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()); restoreState(states.back());
setViewportSize(width, height, pixelwidth, pixelheight);
Vulkan::resetShaderSwitches(); Vulkan::resetShaderSwitches();
frameCounter = 0; frameCounter = 0;
@@ -1851,15 +1853,9 @@ VkExtent2D Graphics::chooseSwapExtent(const VkSurfaceCapabilitiesKHR &capabiliti
return capabilities.currentExtent; return capabilities.currentExtent;
else else
{ {
auto window = Module::getInstance<love::window::Window>(M_WINDOW);
const void *handle = window->getHandle();
int width, height;
SDL_Vulkan_GetDrawableSize((SDL_Window*)handle, &width, &height);
VkExtent2D actualExtent = { VkExtent2D actualExtent = {
static_cast<uint32_t>(width), static_cast<uint32_t>(pixelWidth),
static_cast<uint32_t>(height) static_cast<uint32_t>(pixelHeight)
}; };
actualExtent.width = clampuint32_t(actualExtent.width, capabilities.minImageExtent.width, capabilities.maxImageExtent.width); actualExtent.width = clampuint32_t(actualExtent.width, capabilities.minImageExtent.width, capabilities.maxImageExtent.width);
+14
View File
@@ -46,6 +46,10 @@
// SDL // SDL
#include <SDL_syswm.h> #include <SDL_syswm.h>
#ifdef LOVE_GRAPHICS_VULKAN
#include <SDL_vulkan.h>
#endif
#if defined(LOVE_WINDOWS) #if defined(LOVE_WINDOWS)
#include <windows.h> #include <windows.h>
#include <dwmapi.h> #include <dwmapi.h>
@@ -684,11 +688,16 @@ bool Window::onSizeChanged(int width, int height)
windowWidth = width; windowWidth = width;
windowHeight = height; windowHeight = height;
// TODO: Use SDL_GetWindowSizeInPixels here when supported.
if (glcontext != nullptr) if (glcontext != nullptr)
SDL_GL_GetDrawableSize(window, &pixelWidth, &pixelHeight); SDL_GL_GetDrawableSize(window, &pixelWidth, &pixelHeight);
#ifdef LOVE_GRAPHICS_METAL #ifdef LOVE_GRAPHICS_METAL
else if (metalView != nullptr) else if (metalView != nullptr)
SDL_Metal_GetDrawableSize(window, &pixelWidth, &pixelHeight); SDL_Metal_GetDrawableSize(window, &pixelWidth, &pixelHeight);
#endif
#ifdef LOVE_GRAPHICS_VULKAN
else if (windowRenderer == graphics::RENDERER_VULKAN)
SDL_Vulkan_GetDrawableSize(window, &pixelWidth, &pixelHeight);
#endif #endif
else else
{ {
@@ -716,12 +725,17 @@ void Window::updateSettings(const WindowSettings &newsettings, bool updateGraphi
pixelWidth = windowWidth; pixelWidth = windowWidth;
pixelHeight = windowHeight; pixelHeight = windowHeight;
// TODO: Use SDL_GetWindowSizeInPixels here when supported.
if ((wflags & SDL_WINDOW_OPENGL) != 0) if ((wflags & SDL_WINDOW_OPENGL) != 0)
SDL_GL_GetDrawableSize(window, &pixelWidth, &pixelHeight); SDL_GL_GetDrawableSize(window, &pixelWidth, &pixelHeight);
#ifdef LOVE_GRAPHICS_METAL #ifdef LOVE_GRAPHICS_METAL
else if ((wflags & SDL_WINDOW_METAL) != 0) else if ((wflags & SDL_WINDOW_METAL) != 0)
SDL_Metal_GetDrawableSize(window, &pixelWidth, &pixelHeight); SDL_Metal_GetDrawableSize(window, &pixelWidth, &pixelHeight);
#endif #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) if ((wflags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP)
{ {