diff options
| author | Tilka <tilkax@gmail.com> | 2019-02-26 04:21:05 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-26 04:21:05 +0000 |
| commit | 6ce7f44b8a0bb3b95d3f12ebffbef7a71a443fdd (patch) | |
| tree | 98380ce3a3284c52597a6fba86589c847219ecd5 /Source/Core/VideoCommon/BPFunctions.cpp | |
| parent | 19673ce79af814ca3b77d7f8ea60458e564bfa51 (diff) | |
| parent | f039149198657c1891e1c6462ed30c31ed4b8486 (diff) | |
Merge pull request #7753 from stenzek/videocommon-all-the-things
Move a significant amount of video backend logic to VideoCommon
Diffstat (limited to 'Source/Core/VideoCommon/BPFunctions.cpp')
| -rw-r--r-- | Source/Core/VideoCommon/BPFunctions.cpp | 93 |
1 files changed, 63 insertions, 30 deletions
diff --git a/Source/Core/VideoCommon/BPFunctions.cpp b/Source/Core/VideoCommon/BPFunctions.cpp index 61e4c54b27..7db9d58cad 100644 --- a/Source/Core/VideoCommon/BPFunctions.cpp +++ b/Source/Core/VideoCommon/BPFunctions.cpp @@ -5,8 +5,10 @@ #include "Common/CommonTypes.h" #include "Common/Logging/Log.h" +#include "VideoCommon/AbstractFramebuffer.h" #include "VideoCommon/BPFunctions.h" #include "VideoCommon/BPMemory.h" +#include "VideoCommon/FramebufferManager.h" #include "VideoCommon/RenderBase.h" #include "VideoCommon/RenderState.h" #include "VideoCommon/VertexManagerBase.h" @@ -51,8 +53,10 @@ void SetScissor() bpmem.scissorBR.x - xoff + 1, bpmem.scissorBR.y - yoff + 1); native_rc.ClampUL(0, 0, EFB_WIDTH, EFB_HEIGHT); - TargetRectangle target_rc = g_renderer->ConvertEFBRectangle(native_rc); - g_renderer->SetScissorRect(target_rc); + auto target_rc = g_renderer->ConvertEFBRectangle(native_rc); + auto converted_rc = + g_renderer->ConvertFramebufferRectangle(target_rc, g_renderer->GetCurrentFramebuffer()); + g_renderer->SetScissorRect(converted_rc); } void SetViewport() @@ -122,6 +126,21 @@ void SetViewport() far_depth = 1.0f - min_depth; } + // Clamp to size if oversized not supported. Required for D3D. + if (!g_ActiveConfig.backend_info.bSupportsOversizedViewports) + { + const float max_width = static_cast<float>(g_renderer->GetCurrentFramebuffer()->GetWidth()); + const float max_height = static_cast<float>(g_renderer->GetCurrentFramebuffer()->GetHeight()); + x = MathUtil::Clamp(x, 0.0f, max_width - 1.0f); + y = MathUtil::Clamp(y, 0.0f, max_height - 1.0f); + width = MathUtil::Clamp(width, 1.0f, max_width - x); + height = MathUtil::Clamp(height, 1.0f, max_height - y); + } + + // Lower-left flip. + if (g_ActiveConfig.backend_info.bUsesLowerLeftOrigin) + y = static_cast<float>(g_renderer->GetCurrentFramebuffer()->GetHeight()) - y - height; + g_renderer->SetViewport(x, y, width, height, near_depth, far_depth); } @@ -188,8 +207,6 @@ void ClearScreen(const EFBRectangle& rc) void OnPixelFormatChange() { - int convtype = -1; - // TODO : Check for Z compression format change // When using 16bit Z, the game may enable a special compression format which we need to handle // If we don't, Z values will be completely screwed up, currently only Star Wars:RS2 uses that. @@ -205,58 +222,74 @@ void OnPixelFormatChange() auto old_format = g_renderer->GetPrevPixelFormat(); auto new_format = bpmem.zcontrol.pixel_format; + g_renderer->StorePixelFormat(new_format); + + DEBUG_LOG(VIDEO, "pixelfmt: pixel=%d, zc=%d", static_cast<int>(new_format), + static_cast<int>(bpmem.zcontrol.zformat)); // no need to reinterpret pixel data in these cases if (new_format == old_format || old_format == PEControl::INVALID_FMT) - goto skip; + return; // Check for pixel format changes switch (old_format) { case PEControl::RGB8_Z24: case PEControl::Z24: + { // Z24 and RGB8_Z24 are treated equal, so just return in this case if (new_format == PEControl::RGB8_Z24 || new_format == PEControl::Z24) - goto skip; + return; if (new_format == PEControl::RGBA6_Z24) - convtype = 0; + { + g_renderer->ReinterpretPixelData(EFBReinterpretType::RGB8ToRGBA6); + return; + } else if (new_format == PEControl::RGB565_Z16) - convtype = 1; - break; + { + g_renderer->ReinterpretPixelData(EFBReinterpretType::RGB8ToRGB565); + return; + } + } + break; case PEControl::RGBA6_Z24: + { if (new_format == PEControl::RGB8_Z24 || new_format == PEControl::Z24) - convtype = 2; + { + g_renderer->ReinterpretPixelData(EFBReinterpretType::RGBA6ToRGB8); + return; + } else if (new_format == PEControl::RGB565_Z16) - convtype = 3; - break; + { + g_renderer->ReinterpretPixelData(EFBReinterpretType::RGBA6ToRGB565); + return; + } + } + break; case PEControl::RGB565_Z16: + { if (new_format == PEControl::RGB8_Z24 || new_format == PEControl::Z24) - convtype = 4; + { + g_renderer->ReinterpretPixelData(EFBReinterpretType::RGB565ToRGB8); + return; + } else if (new_format == PEControl::RGBA6_Z24) - convtype = 5; - break; + { + g_renderer->ReinterpretPixelData(EFBReinterpretType::RGB565ToRGBA6); + return; + } + } + break; default: break; } - if (convtype == -1) - { - ERROR_LOG(VIDEO, "Unhandled EFB format change: %d to %d", static_cast<int>(old_format), - static_cast<int>(new_format)); - goto skip; - } - - g_renderer->ReinterpretPixelData(convtype); - -skip: - DEBUG_LOG(VIDEO, "pixelfmt: pixel=%d, zc=%d", static_cast<int>(new_format), - static_cast<int>(bpmem.zcontrol.zformat)); - - g_renderer->StorePixelFormat(new_format); + ERROR_LOG(VIDEO, "Unhandled EFB format change: %d to %d", static_cast<int>(old_format), + static_cast<int>(new_format)); } void SetInterlacingMode(const BPCmd& bp) @@ -286,4 +319,4 @@ void SetInterlacingMode(const BPCmd& bp) break; } } -}; +}; // namespace BPFunctions |
