From 66f1ac2abc2a201b8cbc41a3a85fb95b2c60d26a Mon Sep 17 00:00:00 2001 From: OV2 Date: Mon, 20 May 2019 21:13:32 +0200 Subject: [PATCH] win32: reset d3d viewport before clearing (#531) --- win32/CDirect3D.cpp | 28 +++++++++++++++++++++++++--- win32/CDirect3D.h | 1 + 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/win32/CDirect3D.cpp b/win32/CDirect3D.cpp index 7d2fbc64..40b7f5a5 100644 --- a/win32/CDirect3D.cpp +++ b/win32/CDirect3D.cpp @@ -134,7 +134,7 @@ bool CDirect3D::Initialize(HWND hWnd) pDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); pDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); - pDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); + Clear(); init_done = true; @@ -298,8 +298,9 @@ void CDirect3D::Render(SSurface Src) drawSurface->UnlockRect(0); } - if(!GUI.Stretch||GUI.AspectRatio) - pDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); + if (!GUI.Stretch || GUI.AspectRatio) { + Clear(); + } //if the output size of the render method changes we need to update the viewport if(afterRenderHeight != dstRect.bottom || afterRenderWidth != dstRect.right) { @@ -687,3 +688,24 @@ void CDirect3D::SetFiltering() pDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT); } } + +// reset viewport to whole window, clear, set back to current viewport +void CDirect3D::Clear() +{ + if (!init_done) + return; + + D3DVIEWPORT9 vp_current, vp_all; + pDevice->GetViewport(&vp_current); + + vp_all.X = 0; + vp_all.Y = 0; + vp_all.Width = dPresentParams.BackBufferWidth; + vp_all.Height = dPresentParams.BackBufferHeight; + vp_all.MinZ = 0.0; + vp_all.MaxZ = 1.0; + + pDevice->SetViewport(&vp_all); + pDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); + pDevice->SetViewport(&vp_current); +} diff --git a/win32/CDirect3D.h b/win32/CDirect3D.h index 7d9e939b..c8f65c31 100644 --- a/win32/CDirect3D.h +++ b/win32/CDirect3D.h @@ -76,6 +76,7 @@ private: bool SetShader(const TCHAR *file); void checkForCgError(const char *situation); bool SetShaderCG(const TCHAR *file); + void Clear(); public: CDirect3D();