Skip to content

Commit

Permalink
GPU: Fix non-internal resolution screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Sep 2, 2023
1 parent a63ae48 commit cb68cc2
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/core/gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2069,10 +2069,13 @@ bool GPU::RenderScreenshotToFile(std::string filename, bool internal_resolution
{
u32 width = g_gpu_device->GetWindowWidth();
u32 height = g_gpu_device->GetWindowHeight();
auto [draw_left, draw_top, draw_width, draw_height] = CalculateDrawRect(width, height);
Common::Rectangle<s32> draw_rect = CalculateDrawRect(width, height);

if (internal_resolution && m_display_texture_view_width != 0 && m_display_texture_view_height != 0)
{
const u32 draw_width = static_cast<u32>(draw_rect.GetWidth());
const u32 draw_height = static_cast<u32>(draw_rect.GetHeight());

// If internal res, scale the computed draw rectangle to the internal res.
// We re-use the draw rect because it's already been AR corrected.
const float sar =
Expand Down Expand Up @@ -2109,20 +2112,16 @@ bool GPU::RenderScreenshotToFile(std::string filename, bool internal_resolution
}

// Remove padding, it's not part of the framebuffer.
draw_left = 0;
draw_top = 0;
draw_width = static_cast<s32>(width);
draw_height = static_cast<s32>(height);
draw_rect.Set(0, 0, static_cast<s32>(width), static_cast<s32>(height));
}
if (width == 0 || height == 0)
return false;

std::vector<u32> pixels;
u32 pixels_stride;
GPUTexture::Format pixels_format;
if (!RenderScreenshotToBuffer(width, height,
Common::Rectangle<s32>::FromExtents(draw_left, draw_top, draw_width, draw_height),
!internal_resolution, &pixels, &pixels_stride, &pixels_format))
if (!RenderScreenshotToBuffer(width, height, draw_rect, !internal_resolution, &pixels, &pixels_stride,
&pixels_format))
{
Log_ErrorPrintf("Failed to render %ux%u screenshot", width, height);
return false;
Expand Down

0 comments on commit cb68cc2

Please sign in to comment.