Stefan Dösinger : ddraw: Update the wined3d depth stencil on device creation, render.
Alexandre Julliard
julliard at wine.codeweavers.com
Tue May 1 07:39:24 CDT 2007
Module: wine
Branch: master
Commit: ffae39c3f37c8c1f5d671c6fe37966ebd1878e55
URL: http://source.winehq.org/git/wine.git/?a=commit;h=ffae39c3f37c8c1f5d671c6fe37966ebd1878e55
Author: Stefan Dösinger <stefan at codeweavers.com>
Date: Tue Apr 24 22:30:03 2007 +0200
ddraw: Update the wined3d depth stencil on device creation, render.
---
dlls/ddraw/ddraw_private.h | 1 +
dlls/ddraw/device.c | 53 +++++++++++++++++++++++++++++++++++++++++--
dlls/ddraw/direct3d.c | 18 ++------------
dlls/ddraw/surface.c | 16 +++++--------
4 files changed, 60 insertions(+), 28 deletions(-)
diff --git a/dlls/ddraw/ddraw_private.h b/dlls/ddraw/ddraw_private.h
index b2fc8b3..8a04ad2 100644
--- a/dlls/ddraw/ddraw_private.h
+++ b/dlls/ddraw/ddraw_private.h
@@ -360,6 +360,7 @@ const GUID IID_D3DDEVICE_WineD3D;
/* Helper functions */
HRESULT IDirect3DImpl_GetCaps(IWineD3D *WineD3D, D3DDEVICEDESC *Desc123, D3DDEVICEDESC7 *Desc7);
DWORD IDirect3DDeviceImpl_CreateHandle(IDirect3DDeviceImpl *This);
+WINED3DZBUFFERTYPE IDirect3DDeviceImpl_UpdateDepthStencil(IDirect3DDeviceImpl *This);
/* Structures */
struct EnumTextureFormatsCBS
diff --git a/dlls/ddraw/device.c b/dlls/ddraw/device.c
index 61be064..5ef8748 100644
--- a/dlls/ddraw/device.c
+++ b/dlls/ddraw/device.c
@@ -1742,13 +1742,23 @@ IDirect3DDeviceImpl_7_SetRenderTarget(IDirect3DDevice7 *iface,
{
ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
IDirectDrawSurfaceImpl *Target = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, NewTarget);
+ HRESULT hr;
TRACE("(%p)->(%p,%08x): Relay\n", This, NewTarget, Flags);
/* Flags: Not used */
- return IWineD3DDevice_SetRenderTarget(This->wineD3DDevice,
- 0,
- Target ? Target->WineD3DSurface : NULL);
+ hr = IWineD3DDevice_SetRenderTarget(This->wineD3DDevice,
+ 0,
+ Target ? Target->WineD3DSurface : NULL);
+ if(hr != D3D_OK)
+ {
+ return hr;
+ }
+ IDirectDrawSurface7_AddRef(NewTarget);
+ IDirectDrawSurface7_Release(ICOM_INTERFACE(This->target, IDirectDrawSurface7));
+ This->target = Target;
+ IDirect3DDeviceImpl_UpdateDepthStencil(This);
+ return D3D_OK;
}
static HRESULT WINAPI
@@ -5135,3 +5145,40 @@ IDirect3DDeviceImpl_CreateHandle(IDirect3DDeviceImpl *This)
TRACE("Returning %d\n", This->numHandles);
return This->numHandles;
}
+
+/*****************************************************************************
+ * IDirect3DDeviceImpl_UpdateDepthStencil
+ *
+ * Checks the current render target for attached depth stencils and sets the
+ * WineD3D depth stencil accordingly.
+ *
+ * Returns:
+ * The depth stencil state to set if creating the device
+ *
+ *****************************************************************************/
+WINED3DZBUFFERTYPE
+IDirect3DDeviceImpl_UpdateDepthStencil(IDirect3DDeviceImpl *This)
+{
+ IDirectDrawSurface7 *depthStencil = NULL;
+ IDirectDrawSurfaceImpl *dsi;
+ static DDSCAPS2 depthcaps = { DDSCAPS_ZBUFFER, 0, 0, 0 };
+
+ IDirectDrawSurface7_GetAttachedSurface(ICOM_INTERFACE(This->target, IDirectDrawSurface7),
+ &depthcaps,
+ &depthStencil);
+ if(!depthStencil)
+ {
+ TRACE("Setting wined3d depth stencil to NULL\n");
+ IWineD3DDevice_SetDepthStencilSurface(This->wineD3DDevice,
+ NULL);
+ return WINED3DZB_FALSE;
+ }
+
+ dsi = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, depthStencil);
+ TRACE("Setting wined3d depth stencil to %p (wined3d %p)\n", dsi, dsi->WineD3DSurface);
+ IWineD3DDevice_SetDepthStencilSurface(This->wineD3DDevice,
+ dsi->WineD3DSurface);
+
+ IDirectDrawSurface7_Release(depthStencil);
+ return WINED3DZB_TRUE;
+}
diff --git a/dlls/ddraw/direct3d.c b/dlls/ddraw/direct3d.c
index ad18bf8..9f7e136 100644
--- a/dlls/ddraw/direct3d.c
+++ b/dlls/ddraw/direct3d.c
@@ -735,8 +735,6 @@ IDirect3DImpl_7_CreateDevice(IDirect3D7 *iface,
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;
@@ -876,19 +874,9 @@ IDirect3DImpl_7_CreateDevice(IDirect3D7 *iface,
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);
- }
-
+ IWineD3DDevice_SetRenderState(This->wineD3DDevice,
+ WINED3DRS_ZENABLE,
+ IDirect3DDeviceImpl_UpdateDepthStencil(object));
return D3D_OK;
}
diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c
index 96aec40..00b2820 100644
--- a/dlls/ddraw/surface.c
+++ b/dlls/ddraw/surface.c
@@ -825,12 +825,10 @@ IDirectDrawSurfaceImpl_AddAttachedSurface(IDirectDrawSurface7 *iface,
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)
+ /* Check if the WineD3D depth stencil needs updating */
+ if(This->ddraw->d3ddevice)
{
- IWineD3DDevice_SetDepthStencilSurface(This->ddraw->wineD3DDevice,
- Surf->WineD3DSurface);
+ IDirect3DDeviceImpl_UpdateDepthStencil(This->ddraw->d3ddevice);
}
/* MSDN:
@@ -892,12 +890,10 @@ IDirectDrawSurfaceImpl_DeleteAttachedSurface(IDirectDrawSurface7 *iface,
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)
+ /* Check if the WineD3D depth stencil needs updating */
+ if(This->ddraw->d3ddevice)
{
- IWineD3DDevice_SetDepthStencilSurface(This->ddraw->wineD3DDevice,
- NULL);
+ IDirect3DDeviceImpl_UpdateDepthStencil(This->ddraw->d3ddevice);
}
IDirectDrawSurface7_Release(Attach);
More information about the wine-cvs
mailing list