Commit 8aae165f authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

ddraw: Verify that the surface is not a depth buffer in SetRenderTarget().

This check is even more inconsistent between versions. Notice how the v2 interface is particularly broken because it never AddRef()'s the new iface. This check also seems to be the original source for the questionable behaviour in d3d_device_set_render_target() of storing the new iface before checking the result of the wined3d_device_set_render_target(). (In particular, SetRenderTargetTest() in tests/d3d.c tests for this behavious.)
parent c70376af
...@@ -1821,12 +1821,13 @@ static HRESULT d3d_device_set_render_target(struct d3d_device *device, ...@@ -1821,12 +1821,13 @@ static HRESULT d3d_device_set_render_target(struct d3d_device *device,
return DDERR_INVALIDPARAMS; return DDERR_INVALIDPARAMS;
} }
IUnknown_AddRef(rt_iface);
IUnknown_Release(device->rt_iface);
device->rt_iface = rt_iface;
if (FAILED(hr = wined3d_device_set_render_target(device->wined3d_device, if (FAILED(hr = wined3d_device_set_render_target(device->wined3d_device,
0, target->wined3d_surface, FALSE))) 0, target->wined3d_surface, FALSE)))
return hr; return hr;
IUnknown_AddRef(rt_iface);
IUnknown_Release(device->rt_iface);
device->rt_iface = rt_iface;
d3d_device_update_depth_stencil(device); d3d_device_update_depth_stencil(device);
return D3D_OK; return D3D_OK;
...@@ -1864,6 +1865,16 @@ static HRESULT d3d_device7_SetRenderTarget(IDirect3DDevice7 *iface, ...@@ -1864,6 +1865,16 @@ static HRESULT d3d_device7_SetRenderTarget(IDirect3DDevice7 *iface,
return DDERR_INVALIDPARAMS; return DDERR_INVALIDPARAMS;
} }
if (target_impl->surface_desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER)
{
WARN("Surface %p is a depth buffer.\n", target_impl);
IDirectDrawSurface7_AddRef(target);
IUnknown_Release(device->rt_iface);
device->rt_iface = (IUnknown *)target;
wined3d_mutex_unlock();
return DDERR_INVALIDPIXELFORMAT;
}
hr = d3d_device_set_render_target(device, target_impl, (IUnknown *)target); hr = d3d_device_set_render_target(device, target_impl, (IUnknown *)target);
wined3d_mutex_unlock(); wined3d_mutex_unlock();
return hr; return hr;
...@@ -1913,6 +1924,16 @@ static HRESULT WINAPI d3d_device3_SetRenderTarget(IDirect3DDevice3 *iface, ...@@ -1913,6 +1924,16 @@ static HRESULT WINAPI d3d_device3_SetRenderTarget(IDirect3DDevice3 *iface,
return DDERR_INVALIDCAPS; return DDERR_INVALIDCAPS;
} }
if (target_impl->surface_desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER)
{
WARN("Surface %p is a depth buffer.\n", target_impl);
IDirectDrawSurface4_AddRef(target);
IUnknown_Release(device->rt_iface);
device->rt_iface = (IUnknown *)target;
wined3d_mutex_unlock();
return DDERR_INVALIDPIXELFORMAT;
}
if (!(target_impl->surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)) if (!(target_impl->surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY))
{ {
WARN("Surface %p is not in video memory.\n", target_impl); WARN("Surface %p is not in video memory.\n", target_impl);
...@@ -1953,6 +1974,15 @@ static HRESULT WINAPI d3d_device2_SetRenderTarget(IDirect3DDevice2 *iface, ...@@ -1953,6 +1974,15 @@ static HRESULT WINAPI d3d_device2_SetRenderTarget(IDirect3DDevice2 *iface,
return DDERR_INVALIDCAPS; return DDERR_INVALIDCAPS;
} }
if (target_impl->surface_desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER)
{
WARN("Surface %p is a depth buffer.\n", target_impl);
IUnknown_Release(device->rt_iface);
device->rt_iface = (IUnknown *)target;
wined3d_mutex_unlock();
return DDERR_INVALIDPIXELFORMAT;
}
if (!(target_impl->surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)) if (!(target_impl->surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY))
{ {
WARN("Surface %p is not in video memory.\n", target_impl); WARN("Surface %p is not in video memory.\n", target_impl);
......
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