summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/RenderBase.cpp
diff options
context:
space:
mode:
authorStenzek <stenzek@users.noreply.github.com>2016-11-28 22:05:16 +1000
committerGitHub <noreply@github.com>2016-11-28 22:05:16 +1000
commit0212741574548fa95593e0e9d9451feca45ab83d (patch)
tree048acf7bcc5cb7b5eb3e7c92915ed4bf9f96af7c /Source/Core/VideoCommon/RenderBase.cpp
parent49e807b71f5f2af09359295ecd2f1645c86d7c2c (diff)
parentb81dee8b9afec63c9c7bf23a1e91afb7567bab49 (diff)
Merge pull request #4436 from stenzek/vulkan-full-ir-framedump
VideoBackends: Internal resolution frame dumping
Diffstat (limited to 'Source/Core/VideoCommon/RenderBase.cpp')
-rw-r--r--Source/Core/VideoCommon/RenderBase.cpp91
1 files changed, 76 insertions, 15 deletions
diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp
index 3120083e56..113358d35f 100644
--- a/Source/Core/VideoCommon/RenderBase.cpp
+++ b/Source/Core/VideoCommon/RenderBase.cpp
@@ -18,6 +18,7 @@
#include <mutex>
#include <string>
+#include "Common/Assert.h"
#include "Common/CommonTypes.h"
#include "Common/Event.h"
#include "Common/FileUtil.h"
@@ -188,7 +189,7 @@ void Renderer::CalculateTargetScale(int x, int y, int* scaledX, int* scaledY)
}
// return true if target size changed
-bool Renderer::CalculateTargetSize(unsigned int framebuffer_width, unsigned int framebuffer_height)
+bool Renderer::CalculateTargetSize()
{
int newEFBWidth, newEFBHeight;
newEFBWidth = newEFBHeight = 0;
@@ -449,10 +450,80 @@ void Renderer::DrawDebugText()
g_renderer->RenderText(final_yellow, 20, 20, 0xFFFFFF00);
}
-void Renderer::UpdateDrawRectangle(int backbuffer_width, int backbuffer_height)
+float Renderer::CalculateDrawAspectRatio(int target_width, int target_height)
{
- float FloatGLWidth = (float)backbuffer_width;
- float FloatGLHeight = (float)backbuffer_height;
+ // The dimensions are the sizes that are used to create the EFB/backbuffer textures, so
+ // they should always be greater than zero.
+ _assert_(target_width > 0 && target_height > 0);
+ if (g_ActiveConfig.iAspectRatio == ASPECT_STRETCH)
+ {
+ // If stretch is enabled, we prefer the aspect ratio of the window.
+ return (static_cast<float>(target_width) / static_cast<float>(target_height)) /
+ (static_cast<float>(s_backbuffer_width) / static_cast<float>(s_backbuffer_height));
+ }
+
+ // The rendering window aspect ratio as a proportion of the 4:3 or 16:9 ratio
+ if (g_ActiveConfig.iAspectRatio == ASPECT_ANALOG_WIDE ||
+ (g_ActiveConfig.iAspectRatio != ASPECT_ANALOG && Core::g_aspect_wide))
+ {
+ return (static_cast<float>(target_width) / static_cast<float>(target_height)) /
+ AspectToWidescreen(VideoInterface::GetAspectRatio());
+ }
+ else
+ {
+ return (static_cast<float>(target_width) / static_cast<float>(target_height)) /
+ VideoInterface::GetAspectRatio();
+ }
+}
+
+TargetRectangle Renderer::CalculateFrameDumpDrawRectangle()
+{
+ // No point including any borders in the frame dump image, since they'd have to be cropped anyway.
+ TargetRectangle rc;
+ rc.left = 0;
+ rc.top = 0;
+
+ // If full-resolution frame dumping is disabled, just use the window draw rectangle.
+ // Also do this if RealXFB is enabled, since the image has been downscaled for the XFB copy
+ // anyway, and there's no point writing an upscaled frame with no filtering.
+ if (!g_ActiveConfig.bInternalResolutionFrameDumps || g_ActiveConfig.RealXFBEnabled())
+ {
+ // But still remove the borders, since the caller expects this.
+ rc.right = target_rc.GetWidth();
+ rc.bottom = target_rc.GetHeight();
+ return rc;
+ }
+
+ // Grab the dimensions of the EFB textures, we scale either of these depending on the ratio.
+ unsigned int efb_width, efb_height;
+ g_framebuffer_manager->GetTargetSize(&efb_width, &efb_height);
+
+ // Scale either the width or height depending the content aspect ratio.
+ // This way we preserve as much resolution as possible when scaling.
+ float ratio = CalculateDrawAspectRatio(efb_width, efb_height);
+ float draw_width, draw_height;
+ if (ratio >= 1.0f)
+ {
+ // Preserve horizontal resolution, scale vertically.
+ draw_width = static_cast<float>(efb_width);
+ draw_height = static_cast<float>(efb_height) * ratio;
+ }
+ else
+ {
+ // Preserve vertical resolution, scale horizontally.
+ draw_width = static_cast<float>(efb_width) / ratio;
+ draw_height = static_cast<float>(efb_height);
+ }
+
+ rc.right = static_cast<int>(std::ceil(draw_width));
+ rc.bottom = static_cast<int>(std::ceil(draw_height));
+ return rc;
+}
+
+void Renderer::UpdateDrawRectangle()
+{
+ float FloatGLWidth = static_cast<float>(s_backbuffer_width);
+ float FloatGLHeight = static_cast<float>(s_backbuffer_height);
float FloatXOffset = 0;
float FloatYOffset = 0;
@@ -511,17 +582,7 @@ void Renderer::UpdateDrawRectangle(int backbuffer_width, int backbuffer_height)
// Check for force-settings and override.
// The rendering window aspect ratio as a proportion of the 4:3 or 16:9 ratio
- float Ratio;
- if (g_ActiveConfig.iAspectRatio == ASPECT_ANALOG_WIDE ||
- (g_ActiveConfig.iAspectRatio != ASPECT_ANALOG && Core::g_aspect_wide))
- {
- Ratio = (WinWidth / WinHeight) / AspectToWidescreen(VideoInterface::GetAspectRatio());
- }
- else
- {
- Ratio = (WinWidth / WinHeight) / VideoInterface::GetAspectRatio();
- }
-
+ float Ratio = CalculateDrawAspectRatio(s_backbuffer_width, s_backbuffer_height);
if (g_ActiveConfig.iAspectRatio != ASPECT_STRETCH)
{
if (Ratio > 1.0f)