From 0f525fddaf338156f14bf12b55c3019d3e565b74 Mon Sep 17 00:00:00 2001 From: Bobby Smith <33353403+bslenul@users.noreply.github.com> Date: Sun, 17 Dec 2023 14:10:48 +0100 Subject: [PATCH] [Libretro] Fix VMU scaling for dynamic res games --- core/rend/dx11/dx11_overlay.cpp | 28 +++++++++++++++++----------- core/rend/gles/gldraw.cpp | 9 ++++----- core/rend/vulkan/overlay.cpp | 28 ++++++++++++++++++++-------- 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/core/rend/dx11/dx11_overlay.cpp b/core/rend/dx11/dx11_overlay.cpp index 741cc560fd..dfbd88d066 100644 --- a/core/rend/dx11/dx11_overlay.cpp +++ b/core/rend/dx11/dx11_overlay.cpp @@ -36,9 +36,15 @@ void DX11Overlay::draw(u32 width, u32 height, bool vmu, bool crosshair) const float blend_factor[4] = { 0.75f, 0.75f, 0.75f, 0.75f }; deviceContext->OMSetBlendState(blendStates.getState(true, 8, 8), blend_factor, 0xffffffff); #else - float vmu_padding = 8.f * config::RenderResolution / 480.f; - float vmu_height = 32.f * config::RenderResolution / 480.f; - float vmu_width = 48.f * config::RenderResolution / 480.f; + float vmu_padding_x = 8.f * width / 640.f; + float vmu_padding_y = 8.f * height / 480.f; + float vmu_width = 48.f * width / 640.f; + float vmu_height = 32.f * height / 480.f; + if (config::Widescreen) + { + vmu_padding_x = vmu_padding_x / 4.f * 3.f; + vmu_width = vmu_width / 4.f * 3.f; + } deviceContext->OMSetBlendState(blendStates.getState(true, 4, 5), nullptr, 0xffffffff); #endif @@ -91,20 +97,20 @@ void DX11Overlay::draw(u32 width, u32 height, bool vmu, bool crosshair) { case UPPER_LEFT: default: - x = vmu_padding; - y = vmu_padding; + x = vmu_padding_x; + y = vmu_padding_y; break; case UPPER_RIGHT: - x = width - vmu_padding - w; - y = vmu_padding; + x = width - vmu_padding_x - w; + y = vmu_padding_y; break; case LOWER_LEFT: - x = vmu_padding; - y = height - vmu_padding - h; + x = vmu_padding_x; + y = height - vmu_padding_y - h; break; case LOWER_RIGHT: - x = width - vmu_padding - w; - y = height - vmu_padding - h; + x = width - vmu_padding_x - w; + y = height - vmu_padding_y - h; break; } #else diff --git a/core/rend/gles/gldraw.cpp b/core/rend/gles/gldraw.cpp index 529bcc9b43..4ba2eca0fd 100644 --- a/core/rend/gles/gldraw.cpp +++ b/core/rend/gles/gldraw.cpp @@ -828,11 +828,10 @@ static void updateVmuTexture(int vmu_screen_number) void DrawVmuTexture(u8 vmu_screen_number, int width, int height) { - float vmu_padding = 8.f * config::RenderResolution / 480.f; - float x = vmu_padding; - float y = vmu_padding; - float w = (float)VMU_SCREEN_WIDTH * vmu_screen_params[vmu_screen_number].vmu_screen_size_mult * 4.f / 3.f / gl.ofbo.aspectRatio * config::RenderResolution / 480.f; - float h = (float)VMU_SCREEN_HEIGHT * vmu_screen_params[vmu_screen_number].vmu_screen_size_mult * config::RenderResolution / 480.f; + float x = 8.f * width / 640.f; + float y = 8.f * height / 480.f; + float w = (float)VMU_SCREEN_WIDTH * vmu_screen_params[vmu_screen_number].vmu_screen_size_mult * 4.f / 3.f / gl.ofbo.aspectRatio * width / 640.f; + float h = (float)VMU_SCREEN_HEIGHT * vmu_screen_params[vmu_screen_number].vmu_screen_size_mult * height / 480.f; if (vmu_lcd_changed[vmu_screen_number * 2] || vmuTextureId[vmu_screen_number] == 0) updateVmuTexture(vmu_screen_number); diff --git a/core/rend/vulkan/overlay.cpp b/core/rend/vulkan/overlay.cpp index bd966f91d7..0cbbdc74bf 100644 --- a/core/rend/vulkan/overlay.cpp +++ b/core/rend/vulkan/overlay.cpp @@ -126,9 +126,21 @@ void VulkanOverlay::Draw(vk::CommandBuffer commandBuffer, vk::Extent2D viewport, if (vmu) { +#ifndef LIBRETRO f32 vmu_padding = 8.f * scaling; f32 vmu_height = 32.f * scaling; f32 vmu_width = 48.f * scaling; +#else + f32 vmu_padding_x = 8.f * viewport.width / 640.f; + f32 vmu_padding_y = 8.f * viewport.height / 480.f; + f32 vmu_width = 48.f * viewport.width / 640.f; + f32 vmu_height = 32.f * viewport.height / 480.f; + if (config::Widescreen) + { + vmu_padding_x = vmu_padding_x / 4.f * 3.f; + vmu_width = vmu_width / 4.f * 3.f; + } +#endif pipeline->BindPipeline(commandBuffer); const float *color = nullptr; @@ -158,20 +170,20 @@ void VulkanOverlay::Draw(vk::CommandBuffer commandBuffer, vk::Extent2D viewport, { case UPPER_LEFT: default: - x = vmu_padding; - y = vmu_padding; + x = vmu_padding_x; + y = vmu_padding_y; break; case UPPER_RIGHT: - x = viewport.width - vmu_padding - w; - y = vmu_padding; + x = viewport.width - vmu_padding_x - w; + y = vmu_padding_y; break; case LOWER_LEFT: - x = vmu_padding; - y = viewport.height - vmu_padding - h; + x = vmu_padding_x; + y = viewport.height - vmu_padding_y - h; break; case LOWER_RIGHT: - x = viewport.width - vmu_padding - w; - y = viewport.height - vmu_padding - h; + x = viewport.width - vmu_padding_x - w; + y = viewport.height - vmu_padding_y - h; break; } #else