Commit ffae39c3 authored by Stefan Dösinger's avatar Stefan Dösinger Committed by Alexandre Julliard

ddraw: Update the wined3d depth stencil on device creation, render.

parent 37800544
...@@ -360,6 +360,7 @@ const GUID IID_D3DDEVICE_WineD3D; ...@@ -360,6 +360,7 @@ const GUID IID_D3DDEVICE_WineD3D;
/* Helper functions */ /* Helper functions */
HRESULT IDirect3DImpl_GetCaps(IWineD3D *WineD3D, D3DDEVICEDESC *Desc123, D3DDEVICEDESC7 *Desc7); HRESULT IDirect3DImpl_GetCaps(IWineD3D *WineD3D, D3DDEVICEDESC *Desc123, D3DDEVICEDESC7 *Desc7);
DWORD IDirect3DDeviceImpl_CreateHandle(IDirect3DDeviceImpl *This); DWORD IDirect3DDeviceImpl_CreateHandle(IDirect3DDeviceImpl *This);
WINED3DZBUFFERTYPE IDirect3DDeviceImpl_UpdateDepthStencil(IDirect3DDeviceImpl *This);
/* Structures */ /* Structures */
struct EnumTextureFormatsCBS struct EnumTextureFormatsCBS
......
...@@ -1742,13 +1742,23 @@ IDirect3DDeviceImpl_7_SetRenderTarget(IDirect3DDevice7 *iface, ...@@ -1742,13 +1742,23 @@ IDirect3DDeviceImpl_7_SetRenderTarget(IDirect3DDevice7 *iface,
{ {
ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface); ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
IDirectDrawSurfaceImpl *Target = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, NewTarget); IDirectDrawSurfaceImpl *Target = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, NewTarget);
HRESULT hr;
TRACE("(%p)->(%p,%08x): Relay\n", This, NewTarget, Flags); TRACE("(%p)->(%p,%08x): Relay\n", This, NewTarget, Flags);
/* Flags: Not used */ /* Flags: Not used */
return IWineD3DDevice_SetRenderTarget(This->wineD3DDevice, hr = IWineD3DDevice_SetRenderTarget(This->wineD3DDevice,
0, 0,
Target ? Target->WineD3DSurface : NULL); 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 static HRESULT WINAPI
...@@ -5135,3 +5145,40 @@ IDirect3DDeviceImpl_CreateHandle(IDirect3DDeviceImpl *This) ...@@ -5135,3 +5145,40 @@ IDirect3DDeviceImpl_CreateHandle(IDirect3DDeviceImpl *This)
TRACE("Returning %d\n", This->numHandles); TRACE("Returning %d\n", This->numHandles);
return 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;
}
...@@ -735,8 +735,6 @@ IDirect3DImpl_7_CreateDevice(IDirect3D7 *iface, ...@@ -735,8 +735,6 @@ IDirect3DImpl_7_CreateDevice(IDirect3D7 *iface,
IParentImpl *IndexBufferParent; IParentImpl *IndexBufferParent;
HRESULT hr; HRESULT hr;
IDirectDrawSurfaceImpl *target = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Surface); 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); TRACE("(%p)->(%s,%p,%p)\n", iface, debugstr_guid(refiid), Surface, Device);
*Device = NULL; *Device = NULL;
...@@ -876,19 +874,9 @@ IDirect3DImpl_7_CreateDevice(IDirect3D7 *iface, ...@@ -876,19 +874,9 @@ IDirect3DImpl_7_CreateDevice(IDirect3D7 *iface,
This->d3ddevice = object; This->d3ddevice = object;
/* Look for a depth buffer and enable the Z test if one is found */ IWineD3DDevice_SetRenderState(This->wineD3DDevice,
hr = IDirectDrawSurface7_GetAttachedSurface(Surface, WINED3DRS_ZENABLE,
&depthcaps, IDirect3DDeviceImpl_UpdateDepthStencil(object));
&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; return D3D_OK;
} }
......
...@@ -825,12 +825,10 @@ IDirectDrawSurfaceImpl_AddAttachedSurface(IDirectDrawSurface7 *iface, ...@@ -825,12 +825,10 @@ IDirectDrawSurfaceImpl_AddAttachedSurface(IDirectDrawSurface7 *iface,
Surf->first_attached = This->first_attached; Surf->first_attached = This->first_attached;
This->next_attached = Surf; This->next_attached = Surf;
/* Check if we attach a back buffer to the primary */ /* Check if the WineD3D depth stencil needs updating */
if(Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER && if(This->ddraw->d3ddevice)
This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
{ {
IWineD3DDevice_SetDepthStencilSurface(This->ddraw->wineD3DDevice, IDirect3DDeviceImpl_UpdateDepthStencil(This->ddraw->d3ddevice);
Surf->WineD3DSurface);
} }
/* MSDN: /* MSDN:
...@@ -892,12 +890,10 @@ IDirectDrawSurfaceImpl_DeleteAttachedSurface(IDirectDrawSurface7 *iface, ...@@ -892,12 +890,10 @@ IDirectDrawSurfaceImpl_DeleteAttachedSurface(IDirectDrawSurface7 *iface,
Surf->next_attached = NULL; Surf->next_attached = NULL;
Surf->first_attached = Surf; Surf->first_attached = Surf;
/* Check if we attach a back buffer to the primary */ /* Check if the WineD3D depth stencil needs updating */
if(Surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER && if(This->ddraw->d3ddevice)
This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
{ {
IWineD3DDevice_SetDepthStencilSurface(This->ddraw->wineD3DDevice, IDirect3DDeviceImpl_UpdateDepthStencil(This->ddraw->d3ddevice);
NULL);
} }
IDirectDrawSurface7_Release(Attach); IDirectDrawSurface7_Release(Attach);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment