From 758bcf17cbde9e41e0ad68d74821a5a98587cf65 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sun, 4 Apr 2010 22:52:27 +0000 Subject: [PATCH] Tweaked the widescreen hack: It now "hacks" to and from any aspect ratio, not just from 4:3 to 16:9. When "Stretch to Window" is chosen, the aspect ratio will be adjusted to 5:4, 16:10, or anything (whatever the aspect ratio of the window is). Works for 4:3 and 16:9 games. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5280 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../VideoCommon/Src/VertexShaderManager.cpp | 4 +- Source/Core/VideoCommon/Src/VideoConfig.cpp | 50 +++++++++++++++++++ Source/Core/VideoCommon/Src/VideoConfig.h | 1 + 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/Source/Core/VideoCommon/Src/VertexShaderManager.cpp b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp index 7f6ca0b271..352434464b 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp @@ -289,13 +289,13 @@ void VertexShaderManager::SetConstants() { // Perspective - g_fProjectionMatrix[0] = xfregs.rawProjection[0] * (g_ActiveConfig.bWidescreenHack ? 0.75f : 1.0f); + g_fProjectionMatrix[0] = xfregs.rawProjection[0] * g_ActiveConfig.fAspectRatioHackW; g_fProjectionMatrix[1] = 0.0f; g_fProjectionMatrix[2] = xfregs.rawProjection[1]; g_fProjectionMatrix[3] = 0.0f; g_fProjectionMatrix[4] = 0.0f; - g_fProjectionMatrix[5] = xfregs.rawProjection[2]; + g_fProjectionMatrix[5] = xfregs.rawProjection[2] * g_ActiveConfig.fAspectRatioHackH; g_fProjectionMatrix[6] = xfregs.rawProjection[3]; g_fProjectionMatrix[7] = 0.0f; diff --git a/Source/Core/VideoCommon/Src/VideoConfig.cpp b/Source/Core/VideoCommon/Src/VideoConfig.cpp index f8abe8d762..307fb3ec35 100644 --- a/Source/Core/VideoCommon/Src/VideoConfig.cpp +++ b/Source/Core/VideoCommon/Src/VideoConfig.cpp @@ -35,6 +35,10 @@ VideoConfig::VideoConfig() { bRunning = false; bAllowSignedBytes = !IsD3D(); + + // Needed for the first frame, I think + fAspectRatioHackW = 1; + fAspectRatioHackH = 1; } void VideoConfig::Load(const char *ini_file) @@ -225,6 +229,52 @@ void ComputeDrawRectangle(int backbuffer_width, int backbuffer_height, bool flip // Handle aspect ratio. // Default to auto. bool use16_9 = g_VideoInitialize.bAutoAspectIs16_9; + + // Update aspect ratio hack values + // Won't take effect until next frame + // Don't know if there is a better place for this code so there isn't a 1 frame delay + if ( g_ActiveConfig.bWidescreenHack ) + { + float source_aspect = use16_9 ? (16.0f / 9.0f) : (4.0f / 3.0f); + float target_aspect; + + switch ( g_ActiveConfig.iAspectRatio ) + { + case ASPECT_FORCE_16_9 : + target_aspect = 16.0f / 9.0f; + break; + case ASPECT_FORCE_4_3 : + target_aspect = 4.0f / 3.0f; + break; + case ASPECT_STRETCH : + target_aspect = WinWidth / WinHeight; + break; + default : + // ASPECT_AUTO == no hacking + target_aspect = source_aspect; + break; + } + + float adjust = source_aspect / target_aspect; + if ( adjust > 1 ) + { + // Vert+ + g_Config.fAspectRatioHackW = 1; + g_Config.fAspectRatioHackH = 1/adjust; + } + else + { + // Hor+ + g_Config.fAspectRatioHackW = adjust; + g_Config.fAspectRatioHackH = 1; + } + } + else + { + // Hack is disabled + g_Config.fAspectRatioHackW = 1; + g_Config.fAspectRatioHackH = 1; + } // Check for force-settings and override. if (g_ActiveConfig.iAspectRatio == ASPECT_FORCE_16_9) diff --git a/Source/Core/VideoCommon/Src/VideoConfig.h b/Source/Core/VideoCommon/Src/VideoConfig.h index 5d77257b3e..9169134832 100644 --- a/Source/Core/VideoCommon/Src/VideoConfig.h +++ b/Source/Core/VideoCommon/Src/VideoConfig.h @@ -126,6 +126,7 @@ struct VideoConfig bool bPhackvalue1, bPhackvalue2; float fhackvalue1, fhackvalue2; bool bProjHack1; + float fAspectRatioHackW, fAspectRatioHackH; int iLog; // CONF_ bits int iSaveTargetId;