Skip to content

Commit

Permalink
[Libretro] Fix VMU scaling for dynamic res games
Browse files Browse the repository at this point in the history
  • Loading branch information
bslenul authored and flyinghead committed Dec 21, 2023
1 parent 790f5b1 commit 57c2dcd
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 24 deletions.
28 changes: 17 additions & 11 deletions core/rend/dx11/dx11_overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions core/rend/gles/gldraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
28 changes: 20 additions & 8 deletions core/rend/vulkan/overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 57c2dcd

Please sign in to comment.