DDraw: Set the depth buffer in wined3d, enable the Z test
Stefan Dösinger
stefandoesinger at gmx.at
Sun Aug 20 03:05:59 CDT 2006
Direct3D <= 7 games set the depth buffer with AddAttachedSurface, and
apparently the depth test is enabled in the newly created device
automatically if a depth buffer is attached to the render target.
The depth stencil buffer is unset before d3d is uninitialized. This is needed
to avoid confusing the d3d9-style depth buffer management in wined3d.
This patch fixes the depth test regression in Tomb Raider 3 caused by the
EnableAutoDepthStencil patch in wined3d.
-------------- next part --------------
From nobody Mon Sep 17 00:00:00 2001
From: Stefan Dösinger <stefan at codeweavers.com>
Date: Sun Aug 20 10:03:04 2006 +0200
Subject: [PATCH] Coalescing 59f5495cf81fd590336a846ab4a82b7d69ba845a and 889a78a425837ea6e736990d88489646a76259fb
First commit:
DDraw: Set the depth stencil surface in wined3d, enable z test
Second commit:
unset the stencil buffer
---
dlls/ddraw/direct3d.c | 15 +++++++++++++++
dlls/ddraw/surface.c | 17 +++++++++++++++++
2 files changed, 32 insertions(+), 0 deletions(-)
16775d88d0befe817bac323b7eb7612eceedad00
diff --git a/dlls/ddraw/direct3d.c b/dlls/ddraw/direct3d.c
index ce255e0..636422d 100644
--- a/dlls/ddraw/direct3d.c
+++ b/dlls/ddraw/direct3d.c
@@ -753,6 +753,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;
@@ -906,6 +908,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);
+ }
+
DDOBJ_UNLOCK(This);
return D3D_OK;
}
diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c
index 806bd5b..7a1430d 100644
--- a/dlls/ddraw/surface.c
+++ b/dlls/ddraw/surface.c
@@ -330,6 +330,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)
{
@@ -815,6 +816,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."
*/
@@ -879,6 +888,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);
+ }
+
DDOBJ_UNLOCK(Surf);
DDOBJ_UNLOCK(This);
IDirectDrawSurface7_Release(Attach);
--
1.2.4
More information about the wine-patches
mailing list