From 98ebc312616953905602f5ae5654c246cd3e37f6 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Stefan=20D=C3=B6singer?= <stefan@codeweavers.com>
Date: Sat, 1 Aug 2009 12:01:54 +0200
Subject: [PATCH 2/7] WineD3D: SetRenderTarget sets the scissor rect

---
 dlls/d3d9/tests/stateblock.c |    9 ++++++++-
 dlls/wined3d/device.c        |   11 +++++++++--
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/dlls/d3d9/tests/stateblock.c b/dlls/d3d9/tests/stateblock.c
index 057b6fe..e9d8150 100644
--- a/dlls/d3d9/tests/stateblock.c
+++ b/dlls/d3d9/tests/stateblock.c
@@ -1570,6 +1570,7 @@ static void test_set_rendertarget(IDirect3DDevice9 *device)
     IDirect3DSurface9 *offscreen, *backbuffer;
     IDirect3DTexture9 *offscreenTexture = NULL;
     HRESULT hr;
+    RECT scissor;
     D3DVIEWPORT9 vp;
 
     hr = IDirect3DDevice9_GetRenderTarget(device, 0, &backbuffer);
@@ -1593,10 +1594,16 @@ static void test_set_rendertarget(IDirect3DDevice9 *device)
     ok(hr == D3D_OK, "SetRenderTarget failed, hr = %08x\n", hr);
 
     hr = IDirect3DDevice9_EndStateBlock(device, &stateblock);
-    ok(hr == D3D_OK, "IDirect3DDevice9_BeginStateBlock failed, hr = %08x\n", hr);
+    ok(hr == D3D_OK, "IDirect3DDevice9_EndStateBlock failed, hr = %08x\n", hr);
     IDirect3DStateBlock9_Release(stateblock);
 
     /* Test how the SetRenderTarget affects viewport and scissor rectangle */
+    hr = IDirect3DDevice9_GetScissorRect(device, &scissor);
+    ok(hr == D3D_OK, "IDirect3DDevice9_GetScissorRect failed, hr = %08x\n", hr);
+    ok(scissor.top == 0, "Scissor rect top is %d, expected 0\n", scissor.top);
+    ok(scissor.left == 0, "Scissor rect left is %d, expected 0\n", scissor.left);
+    ok(scissor.right == 128, "Scissor rect right is %d, expected 128\n", scissor.right);
+    ok(scissor.bottom == 128, "Scissor rect bottom is %d, expected 128\n", scissor.bottom);
     hr = IDirect3DDevice9_GetViewport(device, &vp);
     ok(hr == D3D_OK, "IDirect3DDevice9_GetViewport failed, hr = %08x\n", hr);
     ok(vp.X == 0, "Expected viewport X = 0, got %d\n", vp.X);
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 48a9210..0a1639f 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -6554,8 +6554,9 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetRenderTarget(IWineD3DDevice *iface,
 
     /* Render target 0 is special */
     if(RenderTargetIndex == 0) {
-        /* Finally, reset the viewport as the MSDN states. Tests show that stateblock recording is ignored.
-         * the change goes directly into the primary stateblock.
+        /* Finally, reset the viewport and scissor rect as the MSDN states.
+         * Tests show that stateblock recording is ignored, the change goes
+         * directly into the primary stateblock.
          */
         This->stateBlock->viewport.Height = ((IWineD3DSurfaceImpl *)This->render_targets[0])->currentDesc.Height;
         This->stateBlock->viewport.Width  = ((IWineD3DSurfaceImpl *)This->render_targets[0])->currentDesc.Width;
@@ -6564,6 +6565,12 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetRenderTarget(IWineD3DDevice *iface,
         This->stateBlock->viewport.MaxZ   = 1.0f;
         This->stateBlock->viewport.MinZ   = 0.0f;
         IWineD3DDeviceImpl_MarkStateDirty(This, STATE_VIEWPORT);
+
+        This->stateBlock->scissorRect.top = 0;
+        This->stateBlock->scissorRect.left = 0;
+        This->stateBlock->scissorRect.right = This->stateBlock->viewport.Width;
+        This->stateBlock->scissorRect.bottom = This->stateBlock->viewport.Height;
+        IWineD3DDeviceImpl_MarkStateDirty(This, STATE_SCISSORRECT);
     }
     return WINED3D_OK;
 }
-- 
1.6.3.3


