DDraw: Forward the depth stencil buffer to wined3d

Stefan Dösinger stefandoesinger at gmx.at
Wed Oct 25 05:54:15 CDT 2006


This is the patch sent in August, this time without the dependency on the crit 
section patches.
-------------- next part --------------
From 60b1ffe2b582f59aeba4f5270d702f27c5054e16 Mon Sep 17 00:00:00 2001
From: Stefan Doesinger <stefan at codeweavers.com>
Date: Wed, 25 Oct 2006 12:52:09 +0200
Subject: [PATCH] DDraw: Forward the depth stencil buffer to wined3d
---
 dlls/ddraw/direct3d.c |   15 +++++++++++++++
 dlls/ddraw/surface.c  |   17 +++++++++++++++++
 2 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/dlls/ddraw/direct3d.c b/dlls/ddraw/direct3d.c
index 4a35938..8de0c1c 100644
--- a/dlls/ddraw/direct3d.c
+++ b/dlls/ddraw/direct3d.c
@@ -737,6 +737,8 @@ IDirect3DImpl_7_CreateDevice(IDirect3D7 
     IParentImpl *IndexBufferParent;
     HRESULT hr;
     IDirectDrawSurfaceImpl *target = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Surface);
+    IDirectDrawSurface7 *depthbuffer = NULL;
+    static DDSCAPS2 depthcaps = { DDSCAPS_ZBUFFER, 0, 0, 0 };
     TRACE("(%p)->(%s,%p,%p)\n", iface, debugstr_guid(refiid), Surface, Device);
 
     *Device = NULL;
@@ -872,6 +874,19 @@ IDirect3DImpl_7_CreateDevice(IDirect3D7 
 
     This->d3ddevice = object;
 
+    /* Look for a depth buffer and enable the Z test if one is found */
+    hr = IDirectDrawSurface7_GetAttachedSurface(Surface,
+                                                &depthcaps,
+                                                &depthbuffer);
+    if(depthbuffer)
+    {
+        TRACE("(%p) Depth buffer found, enabling Z test\n", object);
+        IWineD3DDevice_SetRenderState(This->wineD3DDevice,
+                                      WINED3DRS_ZENABLE,
+                                      TRUE);
+        IDirectDrawSurface7_Release(depthbuffer);
+    }
+
     return D3D_OK;
 }
 
diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c
index d7940bd..ab7eda6 100644
--- a/dlls/ddraw/surface.c
+++ b/dlls/ddraw/surface.c
@@ -309,6 +309,7 @@ IDirectDrawSurfaceImpl_Release(IDirectDr
 
             /* Unset any index buffer, just to be sure */
             IWineD3DDevice_SetIndices(ddraw->wineD3DDevice, NULL, 0);
+            IWineD3DDevice_SetDepthStencilSurface(ddraw->wineD3DDevice, NULL);
 
             if(IWineD3DDevice_Uninit3D(ddraw->wineD3DDevice) != D3D_OK)
             {
@@ -779,6 +780,14 @@ IDirectDrawSurfaceImpl_AddAttachedSurfac
     Surf->first_attached = This->first_attached;
     This->next_attached = Surf;
 
+    /* Check if we attach a back buffer to the primary */
+    if(Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER &&
+       This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
+    {
+        IWineD3DDevice_SetDepthStencilSurface(This->ddraw->wineD3DDevice,
+                                              Surf->WineD3DSurface);
+    }
+
     /* MSDN: 
      * "This method increments the reference count of the surface being attached."
      */
@@ -838,6 +847,14 @@ IDirectDrawSurfaceImpl_DeleteAttachedSur
     Surf->next_attached = NULL;
     Surf->first_attached = Surf;
 
+    /* Check if we attach a back buffer to the primary */
+    if(Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER &&
+       This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
+    {
+        IWineD3DDevice_SetDepthStencilSurface(This->ddraw->wineD3DDevice,
+                                              NULL);
+    }
+
     IDirectDrawSurface7_Release(Attach);
     return DD_OK;
 }
-- 
1.4.1.1



More information about the wine-patches mailing list