From 0170e61bfcc31f7f5921ff1ca368cbdb921e9c9e Mon Sep 17 00:00:00 2001 From: Rodolfo Osvaldo Bogado Date: Fri, 2 Oct 2009 21:23:56 +0000 Subject: [PATCH] more work on peek_Z this fix sms and zww sun flare git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4355 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../Plugin_VideoDX9/Src/BPFunctions.cpp | 28 ++++------- Source/Plugins/Plugin_VideoDX9/Src/Render.cpp | 46 +++++++++++++++++-- 2 files changed, 51 insertions(+), 23 deletions(-) diff --git a/Source/Plugins/Plugin_VideoDX9/Src/BPFunctions.cpp b/Source/Plugins/Plugin_VideoDX9/Src/BPFunctions.cpp index d1efcf6de8..de230ebb10 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/BPFunctions.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/BPFunctions.cpp @@ -222,31 +222,19 @@ void ClearScreen(const BPCmd &bp, const EFBRectangle &rc) // it seems that the GC is able to alpha blend on color-fill // we cant do that so if alpha is != 255 we skip it - VertexShaderManager::SetViewportChanged(); - // Since clear operations use the source rectangle, we have to do - // regular renders - DWORD clearflags = 0; - D3DCOLOR col = 0; - float clearZ = 0; + bool colorEnable = bpmem.blendmode.colorupdate; + bool alphaEnable = (bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24 && bpmem.blendmode.alphaupdate); + bool zEnable = bpmem.zmode.updateenable; - if (bpmem.blendmode.colorupdate || bpmem.blendmode.alphaupdate) - { - col = (bpmem.clearcolorAR << 16) | bpmem.clearcolorGB; - clearflags |= D3DCLEAR_TARGET; // set to break animal crossing :p ?? - } - - // clear z-buffer - if (bpmem.zmode.updateenable) + if (colorEnable || alphaEnable || zEnable) { - clearZ = (float)(bpmem.clearZValue & 0xFFFFFF) / float(0xFFFFFF); - if (clearZ > 1.0f) clearZ = 1.0f; - if (clearZ < 0.0f) clearZ = 0.0f; - clearflags |= D3DCLEAR_ZBUFFER;//removed stencil - } + u32 color = (bpmem.clearcolorAR << 16) | bpmem.clearcolorGB; + u32 z = bpmem.clearZValue; - D3D::dev->Clear(0, NULL, clearflags, col, clearZ, 0); + Renderer::ClearScreen(rc, colorEnable, alphaEnable, zEnable, color, z); + } } void RestoreRenderState(const BPCmd &bp) diff --git a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp index 8b2e3ab5d2..fc10376bc8 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp @@ -148,7 +148,7 @@ bool Renderer::Init() D3D::dev->SetRenderTarget(0, FBManager::GetEFBColorRTSurface()); D3D::dev->SetDepthStencilSurface(FBManager::GetEFBDepthRTSurface()); - D3D::dev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER , 0x0, 1.0f, 0);//| D3DCLEAR_STENCIL + D3D::dev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x0, 1.0f, 0); D3D::BeginFrame(); return true; @@ -493,12 +493,12 @@ u32 Renderer::AccessEFB(EFBAccessType type, int x, int y) pZBuffer->UnlockRect(); // [0.0, 1.0] ==> [0, 0xFFFFFFFF] - z = val * 0xFFFFFFFF; + z =((u32)(val * 0xffffff));// 0xFFFFFFFF; // Scale the 32-bit value returned by glReadPixels to a 24-bit // value (GC uses a 24-bit Z-buffer). // TODO: in RE0 this value is often off by one, which causes lighting to disappear - return z >> 8; + return z;//z >> 8; } case POKE_Z: @@ -575,6 +575,46 @@ void UpdateViewport() D3D::dev->SetViewport(&vp); } +void Renderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable, bool zEnable, u32 color, u32 z) +{ + // Update the view port for clearing the picture + D3DVIEWPORT9 vp; + vp.X = 0; + vp.Y = 0; + vp.Width = Renderer::GetTargetWidth(); + vp.Height = Renderer::GetTargetHeight(); + vp.MinZ = 0.0; + vp.MaxZ = 1.0; + D3D::dev->SetViewport(&vp); + + TargetRectangle targetRc = Renderer::ConvertEFBRectangle(rc); + + // Always set the scissor in case it was set by the game and has not been reset + RECT sirc; + sirc.left = targetRc.left; + sirc.top = targetRc.top; + sirc.right = targetRc.right; + sirc.bottom = targetRc.bottom; + D3D::dev->SetScissorRect(&sirc); + + VertexShaderManager::SetViewportChanged(); + + DWORD clearflags = 0; + if(colorEnable) + { + clearflags |= D3DCLEAR_TARGET; + } + if (zEnable) + { + clearflags |= D3DCLEAR_ZBUFFER; + } + + D3D::dev->Clear(0, NULL, clearflags, color,(z & 0xFFFFFF) / float(0xFFFFFF), 0); +} + + + + void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight) { // this function is called after the XFB field is changed, not after