From 1aa1e3dac36707f28865ad887ec076579ea6c7a2 Mon Sep 17 00:00:00 2001
From: Stefan Doesinger <stefan@codeweavers.com>
Date: Thu, 10 May 2007 21:10:49 +0200
Subject: [PATCH] WineD3D: Implement DDBLT_DEPTHFILL on the active depth stencil target

---
 dlls/wined3d/surface.c |   33 ++++++++++++++++++++++++++++-----
 1 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index f5272bb..b03e4d8 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -3086,6 +3086,26 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(IWineD3DSurfaceImpl *This, RECT *
     return WINED3DERR_INVALIDCALL;
 }
 
+static HRESULT WINAPI IWineD3DSurfaceImpl_BltZ(IWineD3DSurfaceImpl *This, RECT *DestRect, IWineD3DSurface *SrcSurface, RECT *SrcRect, DWORD Flags, WINEDDBLTFX *DDBltFx)
+{
+    IWineD3DDeviceImpl *myDevice = This->resource.wineD3DDevice;
+
+    if (Flags & WINEDDBLT_DEPTHFILL) {
+        return IWineD3DDevice_Clear((IWineD3DDevice *) myDevice,
+                                    DestRect == NULL ? 0 : 1,
+                                    (WINED3DRECT *) DestRect,
+                                    WINED3DCLEAR_ZBUFFER,
+                                    0x00000000,
+                                    (float) DDBltFx->u5.dwFillDepth / (float) MAXDWORD,
+                                    0x00000000);
+
+        return WINED3D_OK;
+    }
+
+    FIXME("(%p): Unsupp depthstencil blit\n", This);
+    return WINED3DERR_INVALIDCALL;
+}
+
 static HRESULT WINAPI IWineD3DSurfaceImpl_Blt(IWineD3DSurface *iface, RECT *DestRect, IWineD3DSurface *SrcSurface, RECT *SrcRect, DWORD Flags, WINEDDBLTFX *DDBltFx, WINED3DTEXTUREFILTERTYPE Filter) {
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
     IWineD3DSurfaceImpl *Src = (IWineD3DSurfaceImpl *) SrcSurface;
@@ -3094,11 +3114,14 @@ static HRESULT WINAPI IWineD3DSurfaceImpl_Blt(IWineD3DSurface *iface, RECT *Dest
     TRACE("(%p): Usage is %s\n", This, debug_d3dusage(This->resource.usage));
 
     /* Accessing the depth stencil is supposed to fail between a BeginScene and EndScene pair */
-    if(myDevice->inScene &&
-       (iface == myDevice->stencilBufferTarget ||
-       (SrcSurface && SrcSurface == myDevice->stencilBufferTarget))) {
-        TRACE("Attempt to access the depth stencil surface in a BeginScene / EndScene pair, returning WINED3DERR_INVALIDCALL\n");
-        return WINED3DERR_INVALIDCALL;
+    if(iface == myDevice->stencilBufferTarget || (SrcSurface && SrcSurface == myDevice->stencilBufferTarget)) {
+        if(myDevice->inScene) {
+            TRACE("Attempt to access the depth stencil surface in a BeginScene / EndScene pair, returning WINED3DERR_INVALIDCALL\n");
+            return WINED3DERR_INVALIDCALL;
+        } else if(IWineD3DSurfaceImpl_BltZ(This, DestRect, SrcSurface, SrcRect, Flags, DDBltFx) == WINED3D_OK) {
+            TRACE("Z Blit override handled the blit\n");
+            return WINED3D_OK;
+        }
     }
 
     /* Special cases for RenderTargets */
-- 
1.5.0.7

