From 6e4a61a991a29f32367accc2aa8a6d1e575b2090 Mon Sep 17 00:00:00 2001 From: NeoBrainX Date: Fri, 28 Sep 2012 23:19:50 +0200 Subject: [PATCH 1/7] Minor cleanups. --- Source/Core/VideoCommon/Src/RenderBase.cpp | 2 +- Source/Core/VideoCommon/Src/VideoConfig.h | 6 ++++++ Source/Plugins/Plugin_VideoDX11/Src/Render.cpp | 2 +- Source/Plugins/Plugin_VideoDX9/Src/Render.cpp | 2 +- Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 4 ++-- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Source/Core/VideoCommon/Src/RenderBase.cpp b/Source/Core/VideoCommon/Src/RenderBase.cpp index 0bd1c89118..bf0eaa79f9 100644 --- a/Source/Core/VideoCommon/Src/RenderBase.cpp +++ b/Source/Core/VideoCommon/Src/RenderBase.cpp @@ -313,7 +313,7 @@ void Renderer::DrawDebugText() void Renderer::CalculateXYScale(const TargetRectangle& dst_rect) { - if (g_ActiveConfig.bUseXFB && g_ActiveConfig.bUseRealXFB) + if (g_ActiveConfig.RealXFBEnabled()) { xScale = 1.0f; yScale = 1.0f; diff --git a/Source/Core/VideoCommon/Src/VideoConfig.h b/Source/Core/VideoCommon/Src/VideoConfig.h index 7653972ec8..da760e48b9 100644 --- a/Source/Core/VideoCommon/Src/VideoConfig.h +++ b/Source/Core/VideoCommon/Src/VideoConfig.h @@ -162,6 +162,12 @@ struct VideoConfig bool bSupportsFormatReinterpretation; bool bSupportsPixelLighting; } backend_info; + + // Utility + bool RealXFBEnabled() const { return bUseXFB && bUseRealXFB; } + bool VirtualXFBEnabled() const { return bUseXFB && !bUseRealXFB; } + bool EFBCopiesToTextureEnabled() const { return bEFBCopyEnable && bCopyEFBToTexture; } + bool EFBCopiesToRamEnabled() const { return bEFBCopyEnable && !bCopyEFBToTexture; } }; extern VideoConfig g_Config; diff --git a/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp b/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp index 1b7cfb25bb..857688ceec 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp @@ -898,7 +898,7 @@ void formatBufferDump(const char *in, char *out, int w, int h, int p) // This function has the final picture. We adjust the aspect ratio here. void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,const EFBRectangle& rc,float Gamma) { - if (g_bSkipCurrentFrame || (!XFBWrited && (!g_ActiveConfig.bUseXFB || !g_ActiveConfig.bUseRealXFB)) || !fbWidth || !fbHeight) + if (g_bSkipCurrentFrame || (!XFBWrited && !g_ActiveConfig.RealXFBEnabled()) || !fbWidth || !fbHeight) { if (g_ActiveConfig.bDumpFrames && frame_data) AVIDump::AddFrame(frame_data); diff --git a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp index fda9a02d25..c2e1c46bfd 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp @@ -831,7 +831,7 @@ bool Renderer::SaveScreenshot(const std::string &filename, const TargetRectangle // This function has the final picture. We adjust the aspect ratio here. void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,const EFBRectangle& rc,float Gamma) { - if (g_bSkipCurrentFrame || (!XFBWrited && (!g_ActiveConfig.bUseXFB || !g_ActiveConfig.bUseRealXFB)) || !fbWidth || !fbHeight) + if (g_bSkipCurrentFrame || (!XFBWrited && !g_ActiveConfig.RealXFBEnabled()) || !fbWidth || !fbHeight) { if (g_ActiveConfig.bDumpFrames && frame_data) AVIDump::AddFrame(frame_data); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index 19e4002b7e..4bdee8e198 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -990,7 +990,7 @@ void Renderer::SetBlendMode(bool forceUpdate) void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,const EFBRectangle& rc,float Gamma) { static int w = 0, h = 0; - if (g_bSkipCurrentFrame || (!XFBWrited && (!g_ActiveConfig.bUseXFB || !g_ActiveConfig.bUseRealXFB)) || !fbWidth || !fbHeight) + if (g_bSkipCurrentFrame || (!XFBWrited && !g_ActiveConfig.RealXFBEnabled()) || !fbWidth || !fbHeight) { if (g_ActiveConfig.bDumpFrames && frame_data) { @@ -1010,7 +1010,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons if (field == FIELD_LOWER) xfbAddr -= fbWidth * 2; u32 xfbCount = 0; const XFBSourceBase* const* xfbSourceList = FramebufferManager::GetXFBSource(xfbAddr, fbWidth, fbHeight, xfbCount); - if ((!xfbSourceList || xfbCount == 0) && g_ActiveConfig.bUseXFB && !g_ActiveConfig.bUseRealXFB) + if (g_ActiveConfig.VirtualXFBEnabled() && (!xfbSourceList || xfbCount == 0)) { if (g_ActiveConfig.bDumpFrames && frame_data) { From 8f5223d0e66bf3fa3c1fe314b8e40c19555d3b09 Mon Sep 17 00:00:00 2001 From: NeoBrainX Date: Fri, 28 Sep 2012 23:21:09 +0200 Subject: [PATCH 2/7] More cleanups. --- Source/Plugins/Plugin_VideoDX11/Src/Render.cpp | 16 ++++++++-------- Source/Plugins/Plugin_VideoDX9/Src/Render.cpp | 16 ++++++++-------- Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 17 ++++++++--------- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp b/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp index 857688ceec..5b031a850f 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp @@ -974,7 +974,14 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons MathUtil::Rectangle drawRc; - if (g_ActiveConfig.bUseXFB && !g_ActiveConfig.bUseRealXFB) + if (g_ActiveConfig.bUseRealXFB) + { + drawRc.top = 1; + drawRc.bottom = -1; + drawRc.left = -1; + drawRc.right = 1; + } + else { // use virtual xfb with offset int xfbHeight = xfbSource->srcHeight; @@ -995,13 +1002,6 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons //drawRc.left *= hScale; //drawRc.right *= hScale; } - else - { - drawRc.top = 1; - drawRc.bottom = -1; - drawRc.left = -1; - drawRc.right = 1; - } xfbSource->Draw(sourceRc, drawRc, 0, 0); } diff --git a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp index c2e1c46bfd..ea2afab345 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp @@ -949,7 +949,14 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons MathUtil::Rectangle drawRc; - if (!g_ActiveConfig.bUseRealXFB) + if (g_ActiveConfig.bUseRealXFB) + { + drawRc.top = -1; + drawRc.bottom = 1; + drawRc.left = -1; + drawRc.right = 1; + } + else { // use virtual xfb with offset int xfbHeight = xfbSource->srcHeight; @@ -970,13 +977,6 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons //drawRc.left *= hScale; //drawRc.right *= hScale; } - else - { - drawRc.top = -1; - drawRc.bottom = 1; - drawRc.left = -1; - drawRc.right = 1; - } xfbSource->Draw(sourceRc, drawRc, Width, Height); } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index 4bdee8e198..cf81459245 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -1067,7 +1067,14 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons MathUtil::Rectangle drawRc; - if (!g_ActiveConfig.bUseRealXFB) + if (g_ActiveConfig.bUseRealXFB) + { + drawRc.top = 1; + drawRc.bottom = -1; + drawRc.left = -1; + drawRc.right = 1; + } + else { // use virtual xfb with offset int xfbHeight = xfbSource->srcHeight; @@ -1088,14 +1095,6 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons //drawRc.left *= hScale; //drawRc.right *= hScale; } - else - { - drawRc.top = 1; - drawRc.bottom = -1; - drawRc.left = -1; - drawRc.right = 1; - } - // Tell the OSD Menu about the current internal resolution OSDInternalW = xfbSource->sourceRc.GetWidth(); OSDInternalH = xfbSource->sourceRc.GetHeight(); From 035840e7b57d8056c1b8546aa5d2ae3a8b65d6e4 Mon Sep 17 00:00:00 2001 From: NeoBrainX Date: Fri, 28 Sep 2012 23:48:18 +0200 Subject: [PATCH 3/7] Move last XFB size from Render to FramebufferManager. --- .../VideoCommon/Src/FramebufferManagerBase.cpp | 3 +++ .../VideoCommon/Src/FramebufferManagerBase.h | 8 ++++++++ Source/Core/VideoCommon/Src/RenderBase.cpp | 15 ++++++--------- Source/Core/VideoCommon/Src/RenderBase.h | 3 --- Source/Plugins/Plugin_VideoDX11/Src/Render.cpp | 16 +++++++--------- Source/Plugins/Plugin_VideoDX9/Src/Render.cpp | 16 +++++++--------- Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 17 ++++++++--------- 7 files changed, 39 insertions(+), 39 deletions(-) diff --git a/Source/Core/VideoCommon/Src/FramebufferManagerBase.cpp b/Source/Core/VideoCommon/Src/FramebufferManagerBase.cpp index b234a7c865..fbb042c227 100644 --- a/Source/Core/VideoCommon/Src/FramebufferManagerBase.cpp +++ b/Source/Core/VideoCommon/Src/FramebufferManagerBase.cpp @@ -10,6 +10,9 @@ XFBSourceBase *FramebufferManagerBase::m_realXFBSource; // Only used in Real XFB FramebufferManagerBase::VirtualXFBListType FramebufferManagerBase::m_virtualXFBList; // Only used in Virtual XFB mode const XFBSourceBase* FramebufferManagerBase::m_overlappingXFBArray[MAX_VIRTUAL_XFB]; +unsigned int FramebufferManagerBase::s_last_xfb_width; +unsigned int FramebufferManagerBase::s_last_xfb_height; + FramebufferManagerBase::FramebufferManagerBase() { m_realXFBSource = NULL; diff --git a/Source/Core/VideoCommon/Src/FramebufferManagerBase.h b/Source/Core/VideoCommon/Src/FramebufferManagerBase.h index 26d360647d..a28a941e5b 100644 --- a/Source/Core/VideoCommon/Src/FramebufferManagerBase.h +++ b/Source/Core/VideoCommon/Src/FramebufferManagerBase.h @@ -50,6 +50,11 @@ public: static void CopyToXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& sourceRc,float Gamma); static const XFBSourceBase* const* GetXFBSource(u32 xfbAddr, u32 fbWidth, u32 fbHeight, u32 &xfbCount); + static void SetLastXfbWidth(unsigned int width) { s_last_xfb_width = width; } + static void SetLastXfbHeight(unsigned int height) { s_last_xfb_height = height; } + static unsigned int LastXfbWidth() { return s_last_xfb_width; } + static unsigned int LastXfbHeight() { return s_last_xfb_height; } + protected: struct VirtualXFB { @@ -85,6 +90,9 @@ private: static VirtualXFBListType m_virtualXFBList; // Only used in Virtual XFB mode static const XFBSourceBase* m_overlappingXFBArray[MAX_VIRTUAL_XFB]; + + static unsigned int s_last_xfb_width; + static unsigned int s_last_xfb_height; }; extern FramebufferManagerBase *g_framebuffer_manager; diff --git a/Source/Core/VideoCommon/Src/RenderBase.cpp b/Source/Core/VideoCommon/Src/RenderBase.cpp index bf0eaa79f9..d968ab5fbb 100644 --- a/Source/Core/VideoCommon/Src/RenderBase.cpp +++ b/Source/Core/VideoCommon/Src/RenderBase.cpp @@ -71,9 +71,6 @@ int Renderer::s_backbuffer_height; float Renderer::xScale; float Renderer::yScale; -unsigned int Renderer::s_XFB_width; -unsigned int Renderer::s_XFB_height; - int Renderer::s_LastEFBScale; bool Renderer::s_skipSwap; @@ -121,14 +118,14 @@ void Renderer::RenderToXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRect VideoFifo_CheckSwapRequestAt(xfbAddr, fbWidth, fbHeight); XFBWrited = true; - // XXX: Without the VI, how would we know what kind of field this is? So - // just use progressive. if (g_ActiveConfig.bUseXFB) { FramebufferManagerBase::CopyToXFB(xfbAddr, fbWidth, fbHeight, sourceRc,Gamma); } else { + // XXX: Without the VI, how would we know what kind of field this is? So + // just use progressive. g_renderer->Swap(xfbAddr, FIELD_PROGRESSIVE, fbWidth, fbHeight,sourceRc,Gamma); Common::AtomicStoreRelease(s_swapRequested, false); } @@ -323,13 +320,13 @@ void Renderer::CalculateXYScale(const TargetRectangle& dst_rect) if (g_ActiveConfig.b3DVision) { // This works, yet the version in the else doesn't. No idea why. - xScale = (float)(s_backbuffer_width-1) / (float)(s_XFB_width-1); - yScale = (float)(s_backbuffer_height-1) / (float)(s_XFB_height-1); + xScale = (float)(s_backbuffer_width-1) / (float)(FramebufferManagerBase::LastXfbWidth()-1); + yScale = (float)(s_backbuffer_height-1) / (float)(FramebufferManagerBase::LastXfbHeight()-1); } else { - xScale = (float)(dst_rect.right - dst_rect.left - 1) / (float)(s_XFB_width-1); - yScale = (float)(dst_rect.bottom - dst_rect.top - 1) / (float)(s_XFB_height-1); + xScale = (float)(dst_rect.right - dst_rect.left - 1) / (float)(FramebufferManagerBase::LastXfbWidth()-1); + yScale = (float)(dst_rect.bottom - dst_rect.top - 1) / (float)(FramebufferManagerBase::LastXfbHeight()-1); } } } diff --git a/Source/Core/VideoCommon/Src/RenderBase.h b/Source/Core/VideoCommon/Src/RenderBase.h index e8d4c55a20..7f5e4743e6 100644 --- a/Source/Core/VideoCommon/Src/RenderBase.h +++ b/Source/Core/VideoCommon/Src/RenderBase.h @@ -163,9 +163,6 @@ protected: static float xScale; static float yScale; - static unsigned int s_XFB_width; - static unsigned int s_XFB_height; - // can probably eliminate this static var static int s_LastEFBScale; diff --git a/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp b/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp index 5b031a850f..b89226b410 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp @@ -345,8 +345,8 @@ Renderer::Renderer() s_backbuffer_width = D3D::GetBackBufferWidth(); s_backbuffer_height = D3D::GetBackBufferHeight(); - s_XFB_width = MAX_XFB_WIDTH; - s_XFB_height = MAX_XFB_HEIGHT; + FramebufferManagerBase::SetLastXfbWidth(MAX_XFB_WIDTH); + FramebufferManagerBase::SetLastXfbHeight(MAX_XFB_HEIGHT); TargetRectangle dst_rect; ComputeDrawRectangle(s_backbuffer_width, s_backbuffer_height, false, &dst_rect); @@ -1131,15 +1131,13 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons bool xfbchanged = false; - if (s_XFB_width != fbWidth || s_XFB_height != fbHeight) + if (FramebufferManagerBase::LastXfbWidth() != fbWidth || FramebufferManagerBase::LastXfbHeight() != fbHeight) { xfbchanged = true; - s_XFB_width = fbWidth; - s_XFB_height = fbHeight; - if (s_XFB_width < 1) s_XFB_width = MAX_XFB_WIDTH; - if (s_XFB_width > MAX_XFB_WIDTH) s_XFB_width = MAX_XFB_WIDTH; - if (s_XFB_height < 1) s_XFB_height = MAX_XFB_HEIGHT; - if (s_XFB_height > MAX_XFB_HEIGHT) s_XFB_height = MAX_XFB_HEIGHT; + unsigned int w = (fbWidth < 1 || fbWidth > MAX_XFB_WIDTH) ? MAX_XFB_WIDTH : fbWidth; + unsigned int h = (fbHeight < 1 || fbHeight > MAX_XFB_HEIGHT) ? MAX_XFB_HEIGHT : fbHeight; + FramebufferManagerBase::SetLastXfbWidth(w); + FramebufferManagerBase::SetLastXfbHeight(h); } // update FPS counter diff --git a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp index ea2afab345..66656d5022 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp @@ -274,8 +274,8 @@ Renderer::Renderer() s_backbuffer_width = D3D::GetBackBufferWidth(); s_backbuffer_height = D3D::GetBackBufferHeight(); - s_XFB_width = MAX_XFB_WIDTH; - s_XFB_height = MAX_XFB_HEIGHT; + FramebufferManagerBase::SetLastXfbWidth(MAX_XFB_WIDTH); + FramebufferManagerBase::SetLastXfbHeight(MAX_XFB_HEIGHT); TargetRectangle dst_rect; ComputeDrawRectangle(s_backbuffer_width, s_backbuffer_height, false, &dst_rect); @@ -1124,15 +1124,13 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons bool xfbchanged = false; - if (s_XFB_width != fbWidth || s_XFB_height != fbHeight) + if (FramebufferManagerBase::LastXfbWidth() != fbWidth || FramebufferManagerBase::LastXfbHeight() != fbHeight) { xfbchanged = true; - s_XFB_width = fbWidth; - s_XFB_height = fbHeight; - if (s_XFB_width < 1) s_XFB_width = MAX_XFB_WIDTH; - if (s_XFB_width > MAX_XFB_WIDTH) s_XFB_width = MAX_XFB_WIDTH; - if (s_XFB_height < 1) s_XFB_height = MAX_XFB_HEIGHT; - if (s_XFB_height > MAX_XFB_HEIGHT) s_XFB_height = MAX_XFB_HEIGHT; + unsigned int w = (fbWidth < 1 || fbWidth > MAX_XFB_WIDTH) ? MAX_XFB_WIDTH : fbWidth; + unsigned int h = (fbHeight < 1 || fbHeight > MAX_XFB_HEIGHT) ? MAX_XFB_HEIGHT : fbHeight; + FramebufferManagerBase::SetLastXfbWidth(w); + FramebufferManagerBase::SetLastXfbHeight(h); } u32 newAA = g_ActiveConfig.iMultisampleMode; diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index cf81459245..16d3af59cc 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -359,8 +359,9 @@ Renderer::Renderer() if (!GLEW_ARB_texture_non_power_of_two) WARN_LOG(VIDEO, "ARB_texture_non_power_of_two not supported."); - s_XFB_width = MAX_XFB_WIDTH; - s_XFB_height = MAX_XFB_HEIGHT; + // TODO: Move these somewhere else? + FramebufferManagerBase::SetLastXfbWidth(MAX_XFB_WIDTH); + FramebufferManagerBase::SetLastXfbHeight(MAX_XFB_HEIGHT); TargetRectangle dst_rect; ComputeDrawRectangle(s_backbuffer_width, s_backbuffer_height, false, &dst_rect); @@ -1288,15 +1289,13 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons bool xfbchanged = false; - if (s_XFB_width != fbWidth || s_XFB_height != fbHeight) + if (FramebufferManagerBase::LastXfbWidth() != fbWidth || FramebufferManagerBase::LastXfbHeight() != fbHeight) { xfbchanged = true; - s_XFB_width = fbWidth; - s_XFB_height = fbHeight; - if (s_XFB_width < 1) s_XFB_width = MAX_XFB_WIDTH; - if (s_XFB_width > MAX_XFB_WIDTH) s_XFB_width = MAX_XFB_WIDTH; - if (s_XFB_height < 1) s_XFB_height = MAX_XFB_HEIGHT; - if (s_XFB_height > MAX_XFB_HEIGHT) s_XFB_height = MAX_XFB_HEIGHT; + unsigned int w = (fbWidth < 1 || fbWidth > MAX_XFB_WIDTH) ? MAX_XFB_WIDTH : fbWidth; + unsigned int h = (fbHeight < 1 || fbHeight > MAX_XFB_HEIGHT) ? MAX_XFB_HEIGHT : fbHeight; + FramebufferManagerBase::SetLastXfbWidth(w); + FramebufferManagerBase::SetLastXfbHeight(h); } bool WindowResized = false; From 78031c2d54b4acbca14747c57572b34e2530e474 Mon Sep 17 00:00:00 2001 From: NeoBrainX Date: Sat, 29 Sep 2012 00:04:55 +0200 Subject: [PATCH 4/7] Move ComputeDrawRectangle() to Renderer::UpdateDrawRectangle(). --- Source/Core/VideoCommon/Src/RenderBase.cpp | 123 ++++++++++++++++++ Source/Core/VideoCommon/Src/RenderBase.h | 6 + Source/Core/VideoCommon/Src/VideoConfig.cpp | 122 ----------------- Source/Core/VideoCommon/Src/VideoConfig.h | 2 - .../Plugins/Plugin_VideoDX11/Src/Render.cpp | 30 ++--- Source/Plugins/Plugin_VideoDX9/Src/Render.cpp | 34 +++-- Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 43 +++--- 7 files changed, 180 insertions(+), 180 deletions(-) diff --git a/Source/Core/VideoCommon/Src/RenderBase.cpp b/Source/Core/VideoCommon/Src/RenderBase.cpp index d968ab5fbb..84eac4ec7f 100644 --- a/Source/Core/VideoCommon/Src/RenderBase.cpp +++ b/Source/Core/VideoCommon/Src/RenderBase.cpp @@ -71,6 +71,8 @@ int Renderer::s_backbuffer_height; float Renderer::xScale; float Renderer::yScale; +TargetRectangle Renderer::target_rc; + int Renderer::s_LastEFBScale; bool Renderer::s_skipSwap; @@ -331,6 +333,127 @@ void Renderer::CalculateXYScale(const TargetRectangle& dst_rect) } } +// TODO: remove +extern bool g_aspect_wide; + +void Renderer::UpdateDrawRectangle(int backbuffer_width, int backbuffer_height) +{ + float FloatGLWidth = (float)backbuffer_width; + float FloatGLHeight = (float)backbuffer_height; + float FloatXOffset = 0; + float FloatYOffset = 0; + + // The rendering window size + const float WinWidth = FloatGLWidth; + const float WinHeight = FloatGLHeight; + + // Handle aspect ratio. + // Default to auto. + bool use16_9 = g_aspect_wide; + + // 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) + use16_9 = true; + else if (g_ActiveConfig.iAspectRatio == ASPECT_FORCE_4_3) + use16_9 = false; + + if (g_ActiveConfig.iAspectRatio != ASPECT_STRETCH) + { + // The rendering window aspect ratio as a proportion of the 4:3 or 16:9 ratio + float Ratio = (WinWidth / WinHeight) / (!use16_9 ? (4.0f / 3.0f) : (16.0f / 9.0f)); + // Check if height or width is the limiting factor. If ratio > 1 the picture is too wide and have to limit the width. + if (Ratio > 1.0f) + { + // Scale down and center in the X direction. + FloatGLWidth /= Ratio; + FloatXOffset = (WinWidth - FloatGLWidth) / 2.0f; + } + // The window is too high, we have to limit the height + else + { + // Scale down and center in the Y direction. + FloatGLHeight *= Ratio; + FloatYOffset = FloatYOffset + (WinHeight - FloatGLHeight) / 2.0f; + } + } + + // ----------------------------------------------------------------------- + // Crop the picture from 4:3 to 5:4 or from 16:9 to 16:10. + // Output: FloatGLWidth, FloatGLHeight, FloatXOffset, FloatYOffset + // ------------------ + if (g_ActiveConfig.iAspectRatio != ASPECT_STRETCH && g_ActiveConfig.bCrop) + { + float Ratio = !use16_9 ? ((4.0f / 3.0f) / (5.0f / 4.0f)) : (((16.0f / 9.0f) / (16.0f / 10.0f))); + // The width and height we will add (calculate this before FloatGLWidth and FloatGLHeight is adjusted) + float IncreasedWidth = (Ratio - 1.0f) * FloatGLWidth; + float IncreasedHeight = (Ratio - 1.0f) * FloatGLHeight; + // The new width and height + FloatGLWidth = FloatGLWidth * Ratio; + FloatGLHeight = FloatGLHeight * Ratio; + // Adjust the X and Y offset + FloatXOffset = FloatXOffset - (IncreasedWidth * 0.5f); + FloatYOffset = FloatYOffset - (IncreasedHeight * 0.5f); + } + + int XOffset = (int)(FloatXOffset + 0.5f); + int YOffset = (int)(FloatYOffset + 0.5f); + int iWhidth = (int)ceil(FloatGLWidth); + int iHeight = (int)ceil(FloatGLHeight); + iWhidth -= iWhidth % 4; // ensure divisibility by 4 to make it compatible with all the video encoders + iHeight -= iHeight % 4; + + target_rc.left = XOffset; + target_rc.top = YOffset; + target_rc.right = XOffset + iWhidth; + target_rc.bottom = YOffset + iHeight; +} + void Renderer::SetWindowSize(int width, int height) { if (width < 1) diff --git a/Source/Core/VideoCommon/Src/RenderBase.h b/Source/Core/VideoCommon/Src/RenderBase.h index 7f5e4743e6..3a3231ed5e 100644 --- a/Source/Core/VideoCommon/Src/RenderBase.h +++ b/Source/Core/VideoCommon/Src/RenderBase.h @@ -85,6 +85,10 @@ public: // Use this to convert a whole native EFB rect to backbuffer coordinates virtual TargetRectangle ConvertEFBRectangle(const EFBRectangle& rc) = 0; + static const TargetRectangle& GetTargetRectangle() { return target_rc; } + static void UpdateDrawRectangle(int backbuffer_width, int backbuffer_height); + + // Use this to upscale native EFB coordinates to IDEAL internal resolution static unsigned int EFBToScaledX(int x) { return x * GetTargetWidth() / EFB_WIDTH; } static unsigned int EFBToScaledY(int y) { return y * GetTargetHeight() / EFB_HEIGHT; } @@ -163,6 +167,8 @@ protected: static float xScale; static float yScale; + static TargetRectangle target_rc; + // can probably eliminate this static var static int s_LastEFBScale; diff --git a/Source/Core/VideoCommon/Src/VideoConfig.cpp b/Source/Core/VideoCommon/Src/VideoConfig.cpp index c5628c19a1..cd63871365 100644 --- a/Source/Core/VideoCommon/Src/VideoConfig.cpp +++ b/Source/Core/VideoCommon/Src/VideoConfig.cpp @@ -290,125 +290,3 @@ void VideoConfig::GameIniSave(const char* default_ini, const char* game_ini) iniFile.Save(game_ini); } - - -// TODO: remove -extern bool g_aspect_wide; - -// TODO: Figure out a better place for this function. -void ComputeDrawRectangle(int backbuffer_width, int backbuffer_height, bool flip, TargetRectangle *rc) -{ - float FloatGLWidth = (float)backbuffer_width; - float FloatGLHeight = (float)backbuffer_height; - float FloatXOffset = 0; - float FloatYOffset = 0; - - // The rendering window size - const float WinWidth = FloatGLWidth; - const float WinHeight = FloatGLHeight; - - // Handle aspect ratio. - // Default to auto. - bool use16_9 = g_aspect_wide; - - // 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) - use16_9 = true; - else if (g_ActiveConfig.iAspectRatio == ASPECT_FORCE_4_3) - use16_9 = false; - - if (g_ActiveConfig.iAspectRatio != ASPECT_STRETCH) - { - // The rendering window aspect ratio as a proportion of the 4:3 or 16:9 ratio - float Ratio = (WinWidth / WinHeight) / (!use16_9 ? (4.0f / 3.0f) : (16.0f / 9.0f)); - // Check if height or width is the limiting factor. If ratio > 1 the picture is too wide and have to limit the width. - if (Ratio > 1.0f) - { - // Scale down and center in the X direction. - FloatGLWidth /= Ratio; - FloatXOffset = (WinWidth - FloatGLWidth) / 2.0f; - } - // The window is too high, we have to limit the height - else - { - // Scale down and center in the Y direction. - FloatGLHeight *= Ratio; - FloatYOffset = FloatYOffset + (WinHeight - FloatGLHeight) / 2.0f; - } - } - - // ----------------------------------------------------------------------- - // Crop the picture from 4:3 to 5:4 or from 16:9 to 16:10. - // Output: FloatGLWidth, FloatGLHeight, FloatXOffset, FloatYOffset - // ------------------ - if (g_ActiveConfig.iAspectRatio != ASPECT_STRETCH && g_ActiveConfig.bCrop) - { - float Ratio = !use16_9 ? ((4.0f / 3.0f) / (5.0f / 4.0f)) : (((16.0f / 9.0f) / (16.0f / 10.0f))); - // The width and height we will add (calculate this before FloatGLWidth and FloatGLHeight is adjusted) - float IncreasedWidth = (Ratio - 1.0f) * FloatGLWidth; - float IncreasedHeight = (Ratio - 1.0f) * FloatGLHeight; - // The new width and height - FloatGLWidth = FloatGLWidth * Ratio; - FloatGLHeight = FloatGLHeight * Ratio; - // Adjust the X and Y offset - FloatXOffset = FloatXOffset - (IncreasedWidth * 0.5f); - FloatYOffset = FloatYOffset - (IncreasedHeight * 0.5f); - } - - int XOffset = (int)(FloatXOffset + 0.5f); - int YOffset = (int)(FloatYOffset + 0.5f); - int iWhidth = (int)ceil(FloatGLWidth); - int iHeight = (int)ceil(FloatGLHeight); - iWhidth -= iWhidth % 4; // ensure divisibility by 4 to make it compatible with all the video encoders - iHeight -= iHeight % 4; - rc->left = XOffset; - rc->top = flip ? (int)(YOffset + iHeight) : YOffset; - rc->right = XOffset + iWhidth; - rc->bottom = flip ? YOffset : (int)(YOffset + iHeight); -} diff --git a/Source/Core/VideoCommon/Src/VideoConfig.h b/Source/Core/VideoCommon/Src/VideoConfig.h index da760e48b9..47cdd445d4 100644 --- a/Source/Core/VideoCommon/Src/VideoConfig.h +++ b/Source/Core/VideoCommon/Src/VideoConfig.h @@ -176,6 +176,4 @@ extern VideoConfig g_ActiveConfig; // Called every frame. void UpdateActiveConfig(); -void ComputeDrawRectangle(int backbuffer_width, int backbuffer_height, bool flip, TargetRectangle *rc); - #endif // _VIDEO_CONFIG_H_ diff --git a/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp b/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp index b89226b410..38ccff0a9c 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp @@ -348,10 +348,8 @@ Renderer::Renderer() FramebufferManagerBase::SetLastXfbWidth(MAX_XFB_WIDTH); FramebufferManagerBase::SetLastXfbHeight(MAX_XFB_HEIGHT); - TargetRectangle dst_rect; - ComputeDrawRectangle(s_backbuffer_width, s_backbuffer_height, false, &dst_rect); - - CalculateXYScale(dst_rect); + UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height); + CalculateXYScale(GetTargetRectangle()); s_LastAA = g_ActiveConfig.iMultisampleMode; s_LastEFBScale = g_ActiveConfig.iEFBScale; @@ -924,13 +922,12 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons ResetAPIState(); // Prepare to copy the XFBs to our backbuffer - TargetRectangle dst_rect; - ComputeDrawRectangle(s_backbuffer_width, s_backbuffer_height, false, &dst_rect); + UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height); - int X = dst_rect.left; - int Y = dst_rect.top; - int Width = dst_rect.right - dst_rect.left; - int Height = dst_rect.bottom - dst_rect.top; + int X = GetTargetRectangle().left; + int Y = GetTargetRectangle().top; + int Width = GetTargetRectangle().right - GetTargetRectangle().left; + int Height = GetTargetRectangle().bottom - GetTargetRectangle().top; // TODO: Redundant checks... if (X < 0) X = 0; @@ -1018,7 +1015,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons // done with drawing the game stuff, good moment to save a screenshot if (s_bScreenshot) { - SaveScreenshot(s_sScreenshotName, dst_rect); + SaveScreenshot(s_sScreenshotName, GetTargetRectangle()); s_bScreenshot = false; } @@ -1035,8 +1032,8 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons D3D::context->CopyResource(s_screenshot_texture, (ID3D11Resource*)D3D::GetBackBuffer()->GetTex()); if (!bLastFrameDumped) { - s_recordWidth = dst_rect.GetWidth(); - s_recordHeight = dst_rect.GetHeight(); + s_recordWidth = GetTargetRectangle().GetWidth(); + s_recordHeight = GetTargetRectangle().GetHeight(); bAVIDumping = AVIDump::Start(EmuWindow::GetParentWnd(), s_recordWidth, s_recordHeight); if (!bAVIDumping) { @@ -1062,7 +1059,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons w = s_recordWidth; h = s_recordHeight; } - char* source_ptr = (char*)map.pData + dst_rect.left*4 + dst_rect.top*map.RowPitch; + char* source_ptr = (char*)map.pData + GetTargetRectangle().left*4 + GetTargetRectangle().top*map.RowPitch; formatBufferDump(source_ptr, frame_data, s_recordWidth, s_recordHeight, map.RowPitch); AVIDump::AddFrame(frame_data); D3D::context->Unmap(s_screenshot_texture, 0); @@ -1178,9 +1175,8 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons s_backbuffer_height = D3D::GetBackBufferHeight(); } - ComputeDrawRectangle(s_backbuffer_width, s_backbuffer_height, false, &dst_rect); - - CalculateXYScale(dst_rect); + UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height); + CalculateXYScale(GetTargetRectangle()); s_LastEFBScale = g_ActiveConfig.iEFBScale; CalculateTargetSize(); diff --git a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp index 66656d5022..95302bd620 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp @@ -277,10 +277,8 @@ Renderer::Renderer() FramebufferManagerBase::SetLastXfbWidth(MAX_XFB_WIDTH); FramebufferManagerBase::SetLastXfbHeight(MAX_XFB_HEIGHT); - TargetRectangle dst_rect; - ComputeDrawRectangle(s_backbuffer_width, s_backbuffer_height, false, &dst_rect); - - CalculateXYScale(dst_rect); + UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height); + CalculateXYScale(GetTargetRectangle()); s_LastAA = g_ActiveConfig.iMultisampleMode; int SupersampleCoeficient = (s_LastAA % 3) + 1; @@ -882,8 +880,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons D3D::dev->SetDepthStencilSurface(NULL); D3D::dev->SetRenderTarget(0, D3D::GetBackBufferSurface()); - TargetRectangle dst_rect; - ComputeDrawRectangle(s_backbuffer_width, s_backbuffer_height, false, &dst_rect); + UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height); D3DVIEWPORT9 vp; // Clear full target screen (edges, borders etc) @@ -903,10 +900,10 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons D3D::dev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); } - int X = dst_rect.left; - int Y = dst_rect.top; - int Width = dst_rect.right - dst_rect.left; - int Height = dst_rect.bottom - dst_rect.top; + int X = GetTargetRectangle().left; + int Y = GetTargetRectangle().top; + int Width = GetTargetRectangle().right - GetTargetRectangle().left; + int Height = GetTargetRectangle().bottom - GetTargetRectangle().top; // Sanity check if (X < 0) X = 0; @@ -970,8 +967,8 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons // The following code disables auto stretch. Kept for reference. // scale draw area for a 1 to 1 pixel mapping with the draw target - //float vScale = (float)fbHeight / (float)dst_rect.GetHeight(); - //float hScale = (float)fbWidth / (float)dst_rect.GetWidth(); + //float vScale = (float)fbHeight / (float)GetTargetRectangle().GetHeight(); + //float hScale = (float)fbWidth / (float)GetTargetRectangle().GetWidth(); //drawRc.top *= vScale; //drawRc.bottom *= vScale; //drawRc.left *= hScale; @@ -1013,7 +1010,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons if (s_bScreenshot) { std::lock_guard lk(s_criticalScreenshot); - SaveScreenshot(s_sScreenshotName, dst_rect); + SaveScreenshot(s_sScreenshotName, GetTargetRectangle()); s_bScreenshot = false; } @@ -1027,8 +1024,8 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons HRESULT hr = D3D::dev->GetRenderTargetData(D3D::GetBackBufferSurface(),ScreenShootMEMSurface); if (!bLastFrameDumped) { - s_recordWidth = dst_rect.GetWidth(); - s_recordHeight = dst_rect.GetHeight(); + s_recordWidth = GetTargetRectangle().GetWidth(); + s_recordHeight = GetTargetRectangle().GetHeight(); bAVIDumping = AVIDump::Start(EmuWindow::GetParentWnd(), s_recordWidth, s_recordHeight); if (!bAVIDumping) { @@ -1045,7 +1042,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons if (bAVIDumping) { D3DLOCKED_RECT rect; - if (SUCCEEDED(ScreenShootMEMSurface->LockRect(&rect, dst_rect.AsRECT(), D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_NOSYSLOCK | D3DLOCK_READONLY))) + if (SUCCEEDED(ScreenShootMEMSurface->LockRect(&rect, GetTargetRectangle().AsRECT(), D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_NOSYSLOCK | D3DLOCK_READONLY))) { if (!frame_data || w != s_recordWidth || h != s_recordHeight) { @@ -1139,9 +1136,8 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons { s_LastAA = newAA; - ComputeDrawRectangle(s_backbuffer_width, s_backbuffer_height, false, &dst_rect); - - CalculateXYScale(dst_rect); + UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height); + CalculateXYScale(GetTargetRectangle()); int SupersampleCoeficient = (s_LastAA % 3) + 1; diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index 16d3af59cc..838eda49ec 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -363,10 +363,8 @@ Renderer::Renderer() FramebufferManagerBase::SetLastXfbWidth(MAX_XFB_WIDTH); FramebufferManagerBase::SetLastXfbHeight(MAX_XFB_HEIGHT); - TargetRectangle dst_rect; - ComputeDrawRectangle(s_backbuffer_width, s_backbuffer_height, false, &dst_rect); - - CalculateXYScale(dst_rect); + UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height); + CalculateXYScale(GetTargetRectangle()); s_LastEFBScale = g_ActiveConfig.iEFBScale; CalculateTargetSize(); @@ -1027,8 +1025,13 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons ResetAPIState(); - TargetRectangle dst_rect; - ComputeDrawRectangle(s_backbuffer_width, s_backbuffer_height, true, &dst_rect); + UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height); + TargetRectangle flipped_trc = GetTargetRectangle(); + + // Flip top and bottom for some reason; TODO: Fix the code to suck less? + int tmp = flipped_trc.top; + flipped_trc.top = flipped_trc.bottom; + flipped_trc.bottom = tmp; // Textured triangles are necessary because of post-processing shaders @@ -1037,7 +1040,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons OGL::TextureCache::DisableStage(i); // Update GLViewPort - glViewport(dst_rect.left, dst_rect.bottom, dst_rect.GetWidth(), dst_rect.GetHeight()); + glViewport(flipped_trc.left, flipped_trc.bottom, flipped_trc.GetWidth(), flipped_trc.GetHeight()); GL_REPORT_ERRORD(); @@ -1089,8 +1092,8 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons // The following code disables auto stretch. Kept for reference. // scale draw area for a 1 to 1 pixel mapping with the draw target - //float vScale = (float)fbHeight / (float)dst_rect.GetHeight(); - //float hScale = (float)fbWidth / (float)dst_rect.GetWidth(); + //float vScale = (float)fbHeight / (float)flipped_trc.GetHeight(); + //float hScale = (float)fbWidth / (float)flipped_trc.GetWidth(); //drawRc.top *= vScale; //drawRc.bottom *= vScale; //drawRc.left *= hScale; @@ -1167,7 +1170,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons if (s_bScreenshot) { std::lock_guard lk(s_criticalScreenshot); - SaveScreenshot(s_sScreenshotName, dst_rect); + SaveScreenshot(s_sScreenshotName, flipped_trc); // Reset settings s_sScreenshotName.clear(); s_bScreenshot = false; @@ -1178,16 +1181,16 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons if (g_ActiveConfig.bDumpFrames) { std::lock_guard lk(s_criticalScreenshot); - if (!frame_data || w != dst_rect.GetWidth() || - h != dst_rect.GetHeight()) + if (!frame_data || w != flipped_trc.GetWidth() || + h != flipped_trc.GetHeight()) { if (frame_data) delete[] frame_data; - w = dst_rect.GetWidth(); - h = dst_rect.GetHeight(); + w = flipped_trc.GetWidth(); + h = flipped_trc.GetHeight(); frame_data = new char[3 * w * h]; } glPixelStorei(GL_PACK_ALIGNMENT, 1); - glReadPixels(dst_rect.left, dst_rect.bottom, w, h, GL_BGR, GL_UNSIGNED_BYTE, frame_data); + glReadPixels(flipped_trc.left, flipped_trc.bottom, w, h, GL_BGR, GL_UNSIGNED_BYTE, frame_data); if (GL_REPORT_ERROR() == GL_NO_ERROR && w > 0 && h > 0) { if (!bLastFrameDumped) @@ -1242,11 +1245,11 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons { std::lock_guard lk(s_criticalScreenshot); std::string movie_file_name; - w = dst_rect.GetWidth(); - h = dst_rect.GetHeight(); + w = GetTargetRectangle().GetWidth(); + h = GetTargetRectangle().GetHeight(); frame_data = new char[3 * w * h]; glPixelStorei(GL_PACK_ALIGNMENT, 1); - glReadPixels(dst_rect.left, dst_rect.bottom, w, h, GL_BGR, GL_UNSIGNED_BYTE, frame_data); + glReadPixels(GetTargetRectangle().left, GetTargetRectangle().bottom, w, h, GL_BGR, GL_UNSIGNED_BYTE, frame_data); if (GL_REPORT_ERROR() == GL_NO_ERROR) { if (!bLastFrameDumped) @@ -1311,9 +1314,9 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons if (xfbchanged || WindowResized || (s_LastMultisampleMode != g_ActiveConfig.iMultisampleMode)) { - ComputeDrawRectangle(s_backbuffer_width, s_backbuffer_height, false, &dst_rect); + UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height); - CalculateXYScale(dst_rect); + CalculateXYScale(GetTargetRectangle()); if (CalculateTargetSize() || (s_LastMultisampleMode != g_ActiveConfig.iMultisampleMode)) { From a38bb488d205752dd3c3e59bae55924ae286c4ec Mon Sep 17 00:00:00 2001 From: NeoBrainX Date: Sat, 29 Sep 2012 00:19:28 +0200 Subject: [PATCH 5/7] Remove Renderer::xScale and Renderer::yScale. --- .../Src/FramebufferManagerBase.cpp | 28 ++++++++++++ .../VideoCommon/Src/FramebufferManagerBase.h | 3 ++ Source/Core/VideoCommon/Src/RenderBase.cpp | 43 +++++-------------- Source/Core/VideoCommon/Src/RenderBase.h | 11 +---- .../Src/FramebufferManager.cpp | 11 ++--- .../Plugins/Plugin_VideoDX11/Src/Render.cpp | 6 +-- .../Src/FramebufferManager.cpp | 11 ++--- Source/Plugins/Plugin_VideoDX9/Src/Render.cpp | 6 +-- Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 7 +-- 9 files changed, 56 insertions(+), 70 deletions(-) diff --git a/Source/Core/VideoCommon/Src/FramebufferManagerBase.cpp b/Source/Core/VideoCommon/Src/FramebufferManagerBase.cpp index fbb042c227..be6109decf 100644 --- a/Source/Core/VideoCommon/Src/FramebufferManagerBase.cpp +++ b/Source/Core/VideoCommon/Src/FramebufferManagerBase.cpp @@ -229,3 +229,31 @@ void FramebufferManagerBase::ReplaceVirtualXFB() } } } + +unsigned int FramebufferManagerBase::ScaleToVirtualXfbWidth(unsigned int width, unsigned int backbuffer_width) +{ + if (g_ActiveConfig.RealXFBEnabled()) + return width; + + if (g_ActiveConfig.b3DVision) + { + // This works, yet the version in the else doesn't. No idea why. + return width * (backbuffer_width-1) / (FramebufferManagerBase::LastXfbWidth()-1); + } + else + return width * (Renderer::GetTargetRectangle().GetWidth() - 1) / (float)(FramebufferManagerBase::LastXfbWidth()-1); +} + +unsigned int FramebufferManagerBase::ScaleToVirtualXfbHeight(unsigned int height, unsigned int backbuffer_height) +{ + if (g_ActiveConfig.RealXFBEnabled()) + return height; + + if (g_ActiveConfig.b3DVision) + { + // This works, yet the version in the else doesn't. No idea why. + return height * (backbuffer_height-1) / (FramebufferManagerBase::LastXfbHeight()-1); + } + else + return height * (Renderer::GetTargetRectangle().GetHeight() - 1) / (float)(FramebufferManagerBase::LastXfbHeight()-1); +} diff --git a/Source/Core/VideoCommon/Src/FramebufferManagerBase.h b/Source/Core/VideoCommon/Src/FramebufferManagerBase.h index a28a941e5b..d915130ac4 100644 --- a/Source/Core/VideoCommon/Src/FramebufferManagerBase.h +++ b/Source/Core/VideoCommon/Src/FramebufferManagerBase.h @@ -55,6 +55,9 @@ public: static unsigned int LastXfbWidth() { return s_last_xfb_width; } static unsigned int LastXfbHeight() { return s_last_xfb_height; } + static unsigned int ScaleToVirtualXfbWidth(unsigned int width, unsigned int backbuffer_width); + static unsigned int ScaleToVirtualXfbHeight(unsigned int height, unsigned int backbuffer_height); + protected: struct VirtualXFB { diff --git a/Source/Core/VideoCommon/Src/RenderBase.cpp b/Source/Core/VideoCommon/Src/RenderBase.cpp index 84eac4ec7f..8bb6ab6750 100644 --- a/Source/Core/VideoCommon/Src/RenderBase.cpp +++ b/Source/Core/VideoCommon/Src/RenderBase.cpp @@ -67,10 +67,6 @@ int Renderer::s_target_height; int Renderer::s_backbuffer_width; int Renderer::s_backbuffer_height; -// ratio of backbuffer size and render area size -float Renderer::xScale; -float Renderer::yScale; - TargetRectangle Renderer::target_rc; int Renderer::s_LastEFBScale; @@ -165,19 +161,23 @@ void Renderer::CalculateTargetScale(int x, int y, int &scaledX, int &scaledY) } // return true if target size changed -bool Renderer::CalculateTargetSize(int multiplier) +bool Renderer::CalculateTargetSize(unsigned int framebuffer_width, unsigned int framebuffer_height, int multiplier) { int newEFBWidth, newEFBHeight; switch (s_LastEFBScale) { case 0: // fractional - newEFBWidth = (int)(EFB_WIDTH * xScale); - newEFBHeight = (int)(EFB_HEIGHT * yScale); - break; case 1: // integral - newEFBWidth = EFB_WIDTH * (int)ceilf(xScale); - newEFBHeight = EFB_HEIGHT * (int)ceilf(yScale); + newEFBWidth = FramebufferManagerBase::ScaleToVirtualXfbWidth(EFB_WIDTH, framebuffer_width); + newEFBHeight = FramebufferManagerBase::ScaleToVirtualXfbHeight(EFB_HEIGHT, framebuffer_height); + + if (s_LastEFBScale) + { + newEFBWidth = ((newEFBWidth-1) / EFB_WIDTH + 1) * EFB_WIDTH; + newEFBHeight = ((newEFBHeight-1) / EFB_HEIGHT + 1) * EFB_HEIGHT; + } break; + default: CalculateTargetScale(EFB_WIDTH, EFB_HEIGHT, newEFBWidth, newEFBHeight); break; @@ -310,29 +310,6 @@ void Renderer::DrawDebugText() } } -void Renderer::CalculateXYScale(const TargetRectangle& dst_rect) -{ - if (g_ActiveConfig.RealXFBEnabled()) - { - xScale = 1.0f; - yScale = 1.0f; - } - else - { - if (g_ActiveConfig.b3DVision) - { - // This works, yet the version in the else doesn't. No idea why. - xScale = (float)(s_backbuffer_width-1) / (float)(FramebufferManagerBase::LastXfbWidth()-1); - yScale = (float)(s_backbuffer_height-1) / (float)(FramebufferManagerBase::LastXfbHeight()-1); - } - else - { - xScale = (float)(dst_rect.right - dst_rect.left - 1) / (float)(FramebufferManagerBase::LastXfbWidth()-1); - yScale = (float)(dst_rect.bottom - dst_rect.top - 1) / (float)(FramebufferManagerBase::LastXfbHeight()-1); - } - } -} - // TODO: remove extern bool g_aspect_wide; diff --git a/Source/Core/VideoCommon/Src/RenderBase.h b/Source/Core/VideoCommon/Src/RenderBase.h index 3a3231ed5e..534aa732fe 100644 --- a/Source/Core/VideoCommon/Src/RenderBase.h +++ b/Source/Core/VideoCommon/Src/RenderBase.h @@ -74,10 +74,6 @@ public: static int GetBackbufferWidth() { return s_backbuffer_width; } static int GetBackbufferHeight() { return s_backbuffer_height; } - // XFB scale - TODO: Remove this and add two XFBToScaled functions instead - static float GetXFBScaleX() { return xScale; } - static float GetXFBScaleY() { return yScale; } - static void SetWindowSize(int width, int height); // EFB coordinate conversion functions @@ -137,8 +133,7 @@ public: protected: static void CalculateTargetScale(int x, int y, int &scaledX, int &scaledY); - static bool CalculateTargetSize(int multiplier = 1); - static void CalculateXYScale(const TargetRectangle& dst_rect); + static bool CalculateTargetSize(unsigned int framebuffer_width, unsigned int framebuffer_height, int multiplier = 1); static void CheckFifoRecording(); static void RecordVideoMemory(); @@ -163,10 +158,6 @@ protected: static int s_backbuffer_width; static int s_backbuffer_height; - // ratio of backbuffer size and render area size - TODO: Remove these! - static float xScale; - static float yScale; - static TargetRectangle target_rc; // can probably eliminate this static var diff --git a/Source/Plugins/Plugin_VideoDX11/Src/FramebufferManager.cpp b/Source/Plugins/Plugin_VideoDX11/Src/FramebufferManager.cpp index 0389085fae..cb94884eb7 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/FramebufferManager.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/FramebufferManager.cpp @@ -181,15 +181,12 @@ XFBSourceBase* FramebufferManager::CreateXFBSource(unsigned int target_width, un void FramebufferManager::GetTargetSize(unsigned int *width, unsigned int *height, const EFBRectangle& sourceRc) { - const float scaleX = Renderer::GetXFBScaleX(); - const float scaleY = Renderer::GetXFBScaleY(); - TargetRectangle targetSource; - targetSource.top = (int)(sourceRc.top *scaleY); - targetSource.bottom = (int)(sourceRc.bottom *scaleY); - targetSource.left = (int)(sourceRc.left *scaleX); - targetSource.right = (int)(sourceRc.right * scaleX); + targetSource.top = ScaleToVirtualXfbHeight(sourceRc.top, Renderer::GetBackbufferHeight()); + targetSource.bottom = ScaleToVirtualXfbHeight(sourceRc.bottom, Renderer::GetBackbufferHeight()); + targetSource.left = ScaleToVirtualXfbWidth(sourceRc.left, Renderer::GetBackbufferWidth()); + targetSource.right = ScaleToVirtualXfbWidth(sourceRc.right, Renderer::GetBackbufferWidth()); *width = targetSource.right - targetSource.left; *height = targetSource.bottom - targetSource.top; diff --git a/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp b/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp index 38ccff0a9c..32456dec08 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp @@ -349,11 +349,10 @@ Renderer::Renderer() FramebufferManagerBase::SetLastXfbHeight(MAX_XFB_HEIGHT); UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height); - CalculateXYScale(GetTargetRectangle()); s_LastAA = g_ActiveConfig.iMultisampleMode; s_LastEFBScale = g_ActiveConfig.iEFBScale; - CalculateTargetSize(); + CalculateTargetSize(s_backbuffer_width, s_backbuffer_height); SetupDeviceObjects(); @@ -1176,10 +1175,9 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons } UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height); - CalculateXYScale(GetTargetRectangle()); s_LastEFBScale = g_ActiveConfig.iEFBScale; - CalculateTargetSize(); + CalculateTargetSize(s_backbuffer_width, s_backbuffer_height); D3D::context->OMSetRenderTargets(1, &D3D::GetBackBuffer()->GetRTV(), NULL); diff --git a/Source/Plugins/Plugin_VideoDX9/Src/FramebufferManager.cpp b/Source/Plugins/Plugin_VideoDX9/Src/FramebufferManager.cpp index 0a87a1baf5..1903bce989 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/FramebufferManager.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/FramebufferManager.cpp @@ -149,15 +149,12 @@ XFBSourceBase* FramebufferManager::CreateXFBSource(unsigned int target_width, un void FramebufferManager::GetTargetSize(unsigned int *width, unsigned int *height, const EFBRectangle& sourceRc) { - const float scaleX = Renderer::GetXFBScaleX(); - const float scaleY = Renderer::GetXFBScaleY(); - TargetRectangle targetSource; - targetSource.top = (int)(sourceRc.top *scaleY); - targetSource.bottom = (int)(sourceRc.bottom *scaleY); - targetSource.left = (int)(sourceRc.left *scaleX); - targetSource.right = (int)(sourceRc.right * scaleX); + targetSource.top = ScaleToVirtualXfbHeight(sourceRc.top, Renderer::GetBackbufferHeight()); + targetSource.bottom = ScaleToVirtualXfbHeight(sourceRc.bottom, Renderer::GetBackbufferHeight()); + targetSource.left = ScaleToVirtualXfbWidth(sourceRc.left, Renderer::GetBackbufferWidth()); + targetSource.right = ScaleToVirtualXfbWidth(sourceRc.right, Renderer::GetBackbufferWidth()); *width = targetSource.right - targetSource.left; *height = targetSource.bottom - targetSource.top; diff --git a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp index 95302bd620..e80407e7ac 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp @@ -278,13 +278,12 @@ Renderer::Renderer() FramebufferManagerBase::SetLastXfbHeight(MAX_XFB_HEIGHT); UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height); - CalculateXYScale(GetTargetRectangle()); s_LastAA = g_ActiveConfig.iMultisampleMode; int SupersampleCoeficient = (s_LastAA % 3) + 1; s_LastEFBScale = g_ActiveConfig.iEFBScale; - CalculateTargetSize(SupersampleCoeficient); + CalculateTargetSize(s_backbuffer_width, s_backbuffer_height, SupersampleCoeficient); // Make sure to use valid texture sizes D3D::FixTextureSize(s_target_width, s_target_height); @@ -1137,12 +1136,11 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons s_LastAA = newAA; UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height); - CalculateXYScale(GetTargetRectangle()); int SupersampleCoeficient = (s_LastAA % 3) + 1; s_LastEFBScale = g_ActiveConfig.iEFBScale; - CalculateTargetSize(SupersampleCoeficient); + CalculateTargetSize(s_backbuffer_width, s_backbuffer_height, SupersampleCoeficient); D3D::dev->SetRenderTarget(0, D3D::GetBackBufferSurface()); D3D::dev->SetDepthStencilSurface(D3D::GetBackBufferDepthSurface()); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index 838eda49ec..9f55ad47e4 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -364,10 +364,9 @@ Renderer::Renderer() FramebufferManagerBase::SetLastXfbHeight(MAX_XFB_HEIGHT); UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height); - CalculateXYScale(GetTargetRectangle()); s_LastEFBScale = g_ActiveConfig.iEFBScale; - CalculateTargetSize(); + CalculateTargetSize(s_backbuffer_width, s_backbuffer_height); // Because of the fixed framebuffer size we need to disable the resolution // options while running @@ -1316,9 +1315,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons { UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height); - CalculateXYScale(GetTargetRectangle()); - - if (CalculateTargetSize() || (s_LastMultisampleMode != g_ActiveConfig.iMultisampleMode)) + if (CalculateTargetSize(s_backbuffer_width, s_backbuffer_height) || s_LastMultisampleMode != g_ActiveConfig.iMultisampleMode) { s_LastMultisampleMode = g_ActiveConfig.iMultisampleMode; s_MSAASamples = GetNumMSAASamples(s_LastMultisampleMode); From f88e7d3b73e99908e29b243c22210c4b8d47353b Mon Sep 17 00:00:00 2001 From: NeoBrainX Date: Sat, 29 Sep 2012 23:08:17 +0200 Subject: [PATCH 6/7] Fix an off-by-one error. --- Source/Core/VideoCommon/Src/FramebufferManagerBase.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Core/VideoCommon/Src/FramebufferManagerBase.cpp b/Source/Core/VideoCommon/Src/FramebufferManagerBase.cpp index be6109decf..090c1c7872 100644 --- a/Source/Core/VideoCommon/Src/FramebufferManagerBase.cpp +++ b/Source/Core/VideoCommon/Src/FramebufferManagerBase.cpp @@ -238,10 +238,10 @@ unsigned int FramebufferManagerBase::ScaleToVirtualXfbWidth(unsigned int width, if (g_ActiveConfig.b3DVision) { // This works, yet the version in the else doesn't. No idea why. - return width * (backbuffer_width-1) / (FramebufferManagerBase::LastXfbWidth()-1); + return width * backbuffer_width / FramebufferManagerBase::LastXfbWidth(); } else - return width * (Renderer::GetTargetRectangle().GetWidth() - 1) / (float)(FramebufferManagerBase::LastXfbWidth()-1); + return width * Renderer::GetTargetRectangle().GetWidth() / FramebufferManagerBase::LastXfbWidth(); } unsigned int FramebufferManagerBase::ScaleToVirtualXfbHeight(unsigned int height, unsigned int backbuffer_height) @@ -252,8 +252,8 @@ unsigned int FramebufferManagerBase::ScaleToVirtualXfbHeight(unsigned int height if (g_ActiveConfig.b3DVision) { // This works, yet the version in the else doesn't. No idea why. - return height * (backbuffer_height-1) / (FramebufferManagerBase::LastXfbHeight()-1); + return height * backbuffer_height / FramebufferManagerBase::LastXfbHeight(); } else - return height * (Renderer::GetTargetRectangle().GetHeight() - 1) / (float)(FramebufferManagerBase::LastXfbHeight()-1); + return height * Renderer::GetTargetRectangle().GetHeight() / FramebufferManagerBase::LastXfbHeight(); } From b02bb7617fe5bdcda524d065b5601834e0a3ed4a Mon Sep 17 00:00:00 2001 From: NeoBrainX Date: Tue, 2 Oct 2012 22:11:15 +0200 Subject: [PATCH 7/7] Fix some fractional EFB scaling issues. --- .../Src/FramebufferManagerBase.cpp | 20 ++-- .../VideoCommon/Src/FramebufferManagerBase.h | 4 +- Source/Core/VideoCommon/Src/RenderBase.cpp | 108 ++++++++++++++---- Source/Core/VideoCommon/Src/RenderBase.h | 9 +- 4 files changed, 102 insertions(+), 39 deletions(-) diff --git a/Source/Core/VideoCommon/Src/FramebufferManagerBase.cpp b/Source/Core/VideoCommon/Src/FramebufferManagerBase.cpp index 090c1c7872..c883714daf 100644 --- a/Source/Core/VideoCommon/Src/FramebufferManagerBase.cpp +++ b/Source/Core/VideoCommon/Src/FramebufferManagerBase.cpp @@ -10,8 +10,8 @@ XFBSourceBase *FramebufferManagerBase::m_realXFBSource; // Only used in Real XFB FramebufferManagerBase::VirtualXFBListType FramebufferManagerBase::m_virtualXFBList; // Only used in Virtual XFB mode const XFBSourceBase* FramebufferManagerBase::m_overlappingXFBArray[MAX_VIRTUAL_XFB]; -unsigned int FramebufferManagerBase::s_last_xfb_width; -unsigned int FramebufferManagerBase::s_last_xfb_height; +unsigned int FramebufferManagerBase::s_last_xfb_width = 1; +unsigned int FramebufferManagerBase::s_last_xfb_height = 1; FramebufferManagerBase::FramebufferManagerBase() { @@ -230,30 +230,30 @@ void FramebufferManagerBase::ReplaceVirtualXFB() } } -unsigned int FramebufferManagerBase::ScaleToVirtualXfbWidth(unsigned int width, unsigned int backbuffer_width) +int FramebufferManagerBase::ScaleToVirtualXfbWidth(int x, unsigned int backbuffer_width) { if (g_ActiveConfig.RealXFBEnabled()) - return width; + return x; if (g_ActiveConfig.b3DVision) { // This works, yet the version in the else doesn't. No idea why. - return width * backbuffer_width / FramebufferManagerBase::LastXfbWidth(); + return x * (int)backbuffer_width / (int)FramebufferManagerBase::LastXfbWidth(); } else - return width * Renderer::GetTargetRectangle().GetWidth() / FramebufferManagerBase::LastXfbWidth(); + return x * (int)Renderer::GetTargetRectangle().GetWidth() / (int)FramebufferManagerBase::LastXfbWidth(); } -unsigned int FramebufferManagerBase::ScaleToVirtualXfbHeight(unsigned int height, unsigned int backbuffer_height) +int FramebufferManagerBase::ScaleToVirtualXfbHeight(int y, unsigned int backbuffer_height) { if (g_ActiveConfig.RealXFBEnabled()) - return height; + return y; if (g_ActiveConfig.b3DVision) { // This works, yet the version in the else doesn't. No idea why. - return height * backbuffer_height / FramebufferManagerBase::LastXfbHeight(); + return y * (int)backbuffer_height / (int)FramebufferManagerBase::LastXfbHeight(); } else - return height * Renderer::GetTargetRectangle().GetHeight() / FramebufferManagerBase::LastXfbHeight(); + return y * (int)Renderer::GetTargetRectangle().GetHeight() / (int)FramebufferManagerBase::LastXfbHeight(); } diff --git a/Source/Core/VideoCommon/Src/FramebufferManagerBase.h b/Source/Core/VideoCommon/Src/FramebufferManagerBase.h index d915130ac4..e529bb1a39 100644 --- a/Source/Core/VideoCommon/Src/FramebufferManagerBase.h +++ b/Source/Core/VideoCommon/Src/FramebufferManagerBase.h @@ -55,8 +55,8 @@ public: static unsigned int LastXfbWidth() { return s_last_xfb_width; } static unsigned int LastXfbHeight() { return s_last_xfb_height; } - static unsigned int ScaleToVirtualXfbWidth(unsigned int width, unsigned int backbuffer_width); - static unsigned int ScaleToVirtualXfbHeight(unsigned int height, unsigned int backbuffer_height); + static int ScaleToVirtualXfbWidth(int x, unsigned int backbuffer_width); + static int ScaleToVirtualXfbHeight(int y, unsigned int backbuffer_height); protected: struct VirtualXFB diff --git a/Source/Core/VideoCommon/Src/RenderBase.cpp b/Source/Core/VideoCommon/Src/RenderBase.cpp index 8bb6ab6750..f83ce29e49 100644 --- a/Source/Core/VideoCommon/Src/RenderBase.cpp +++ b/Source/Core/VideoCommon/Src/RenderBase.cpp @@ -76,6 +76,11 @@ bool Renderer::XFBWrited; bool Renderer::s_EnableDLCachingAfterRecording; unsigned int Renderer::prev_efb_format = (unsigned int)-1; +unsigned int Renderer::efb_scale_numeratorX = 1; +unsigned int Renderer::efb_scale_numeratorY = 1; +unsigned int Renderer::efb_scale_denominatorX = 1; +unsigned int Renderer::efb_scale_denominatorY = 1; +unsigned int Renderer::ssaa_multiplier = 1; Renderer::Renderer() : frame_data(NULL), bLastFrameDumped(false) @@ -93,6 +98,8 @@ Renderer::~Renderer() // invalidate previous efb format prev_efb_format = (unsigned int)-1; + efb_scale_numeratorX = efb_scale_numeratorY = efb_scale_denominatorX = efb_scale_denominatorY = ssaa_multiplier = 1; + #if defined _WIN32 || defined HAVE_LIBAV if (g_ActiveConfig.bDumpFrames && bLastFrameDumped && bAVIDumping) AVIDump::Stop(); @@ -129,41 +136,86 @@ void Renderer::RenderToXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRect } } -void Renderer::CalculateTargetScale(int x, int y, int &scaledX, int &scaledY) +int Renderer::EFBToScaledX(int x) { switch (g_ActiveConfig.iEFBScale) { - case 3: // 1.5x - scaledX = (x / 2) * 3; - scaledY = (y / 2) * 3; - break; - case 4: // 2x - scaledX = x * 2; - scaledY = y * 2; - break; - case 5: // 2.5x - scaledX = (x / 2) * 5; - scaledY = (y / 2) * 5; - break; - case 6: // 3x - scaledX = x * 3; - scaledY = y * 3; - break; - case 7: // 4x - scaledX = x * 4; - scaledY = y * 4; - break; + case 0: // fractional + return (int)ssaa_multiplier * FramebufferManagerBase::ScaleToVirtualXfbWidth(x, s_backbuffer_width); + default: - scaledX = x; - scaledY = y; - break; + return x * (int)ssaa_multiplier * (int)efb_scale_numeratorX / (int)efb_scale_denominatorX; }; } +int Renderer::EFBToScaledY(int y) +{ + switch (g_ActiveConfig.iEFBScale) + { + case 0: // fractional + return (int)ssaa_multiplier * FramebufferManagerBase::ScaleToVirtualXfbHeight(y, s_backbuffer_height); + + default: + return y * (int)ssaa_multiplier * (int)efb_scale_numeratorY / (int)efb_scale_denominatorY; + }; +} + +void Renderer::CalculateTargetScale(int x, int y, int &scaledX, int &scaledY) +{ + if (g_ActiveConfig.iEFBScale == 0 || g_ActiveConfig.iEFBScale == 1) + { + scaledX = x; + scaledY = y; + } + else + { + scaledX = x * (int)efb_scale_numeratorX / (int)efb_scale_denominatorX; + scaledY = y * (int)efb_scale_numeratorY / (int)efb_scale_denominatorY; + } +} + // return true if target size changed bool Renderer::CalculateTargetSize(unsigned int framebuffer_width, unsigned int framebuffer_height, int multiplier) { int newEFBWidth, newEFBHeight; + + // TODO: Ugly. Clean up + switch (s_LastEFBScale) + { + case 2: // 1x + efb_scale_numeratorX = efb_scale_numeratorY = 1; + efb_scale_denominatorX = efb_scale_denominatorY = 1; + break; + + case 3: // 1.5x + efb_scale_numeratorX = efb_scale_numeratorY = 3; + efb_scale_denominatorX = efb_scale_denominatorY = 2; + break; + + case 4: // 2x + efb_scale_numeratorX = efb_scale_numeratorY = 2; + efb_scale_denominatorX = efb_scale_denominatorY = 1; + break; + + case 5: // 2.5x + efb_scale_numeratorX = efb_scale_numeratorY = 5; + efb_scale_denominatorX = efb_scale_denominatorY = 2; + break; + + case 6: // 3x + efb_scale_numeratorX = efb_scale_numeratorY = 3; + efb_scale_denominatorX = efb_scale_denominatorY = 1; + break; + + case 7: // 4x + efb_scale_numeratorX = efb_scale_numeratorY = 4; + efb_scale_denominatorX = efb_scale_denominatorY = 1; + break; + + default: // fractional & integral handled later + break; + } + switch (s_LastEFBScale) { case 0: // fractional @@ -171,13 +223,18 @@ bool Renderer::CalculateTargetSize(unsigned int framebuffer_width, unsigned int newEFBWidth = FramebufferManagerBase::ScaleToVirtualXfbWidth(EFB_WIDTH, framebuffer_width); newEFBHeight = FramebufferManagerBase::ScaleToVirtualXfbHeight(EFB_HEIGHT, framebuffer_height); - if (s_LastEFBScale) + if (s_LastEFBScale == 1) { newEFBWidth = ((newEFBWidth-1) / EFB_WIDTH + 1) * EFB_WIDTH; newEFBHeight = ((newEFBHeight-1) / EFB_HEIGHT + 1) * EFB_HEIGHT; } + efb_scale_numeratorX = newEFBWidth; + efb_scale_denominatorX = EFB_WIDTH; + efb_scale_numeratorY = newEFBHeight; + efb_scale_denominatorY = EFB_HEIGHT; break; + default: CalculateTargetScale(EFB_WIDTH, EFB_HEIGHT, newEFBWidth, newEFBHeight); break; @@ -185,6 +242,7 @@ bool Renderer::CalculateTargetSize(unsigned int framebuffer_width, unsigned int newEFBWidth *= multiplier; newEFBHeight *= multiplier; + ssaa_multiplier = multiplier; if (newEFBWidth != s_target_width || newEFBHeight != s_target_height) { diff --git a/Source/Core/VideoCommon/Src/RenderBase.h b/Source/Core/VideoCommon/Src/RenderBase.h index 534aa732fe..4da80c9752 100644 --- a/Source/Core/VideoCommon/Src/RenderBase.h +++ b/Source/Core/VideoCommon/Src/RenderBase.h @@ -86,8 +86,8 @@ public: // Use this to upscale native EFB coordinates to IDEAL internal resolution - static unsigned int EFBToScaledX(int x) { return x * GetTargetWidth() / EFB_WIDTH; } - static unsigned int EFBToScaledY(int y) { return y * GetTargetHeight() / EFB_HEIGHT; } + static int EFBToScaledX(int x); + static int EFBToScaledY(int y); // Floating point versions of the above - only use them if really necessary static float EFBToScaledXf(float x) { return x * ((float)GetTargetWidth() / (float)EFB_WIDTH); } @@ -170,6 +170,11 @@ protected: private: static unsigned int prev_efb_format; + static unsigned int efb_scale_numeratorX; + static unsigned int efb_scale_numeratorY; + static unsigned int efb_scale_denominatorX; + static unsigned int efb_scale_denominatorY; + static unsigned int ssaa_multiplier; }; extern Renderer *g_renderer;