ddraw: Fix ddraw[1-4] light activation / deactivation.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=42572
Signed-off-by: Paul Gofman <gofmanp@gmail.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
(cherry picked from commit addc611b2a)
Signed-off-by: Michael Stefaniuc <mstefani@winehq.org>
oldstable
Paul Gofman 2019-03-28 21:50:12 +03:00 committed by Michael Stefaniuc
parent 5c50407f7f
commit 7bbec8bf22
5 changed files with 51 additions and 45 deletions

View File

@ -517,6 +517,7 @@ struct d3d_viewport *unsafe_impl_from_IDirect3DViewport(IDirect3DViewport *iface
/* Helper functions */ /* Helper functions */
void viewport_activate(struct d3d_viewport *viewport, BOOL ignore_lights) DECLSPEC_HIDDEN; void viewport_activate(struct d3d_viewport *viewport, BOOL ignore_lights) DECLSPEC_HIDDEN;
void viewport_deactivate(struct d3d_viewport *viewport) DECLSPEC_HIDDEN;
void d3d_viewport_init(struct d3d_viewport *viewport, struct ddraw *ddraw) DECLSPEC_HIDDEN; void d3d_viewport_init(struct d3d_viewport *viewport, struct ddraw *ddraw) DECLSPEC_HIDDEN;
/***************************************************************************** /*****************************************************************************

View File

@ -819,7 +819,9 @@ static HRESULT WINAPI d3d_device3_DeleteViewport(IDirect3DDevice3 *iface, IDirec
if (device->current_viewport == vp) if (device->current_viewport == vp)
{ {
TRACE("Deleting current viewport, unsetting and releasing\n"); TRACE("Deleting current viewport, unsetting and releasing.\n");
viewport_deactivate(vp);
IDirect3DViewport3_Release(viewport); IDirect3DViewport3_Release(viewport);
device->current_viewport = NULL; device->current_viewport = NULL;
} }
@ -1689,48 +1691,42 @@ static HRESULT WINAPI d3d_device1_GetDirect3D(IDirect3DDevice *iface, IDirect3D
* (Is a NULL viewport valid?) * (Is a NULL viewport valid?)
* *
*****************************************************************************/ *****************************************************************************/
static HRESULT WINAPI d3d_device3_SetCurrentViewport(IDirect3DDevice3 *iface, IDirect3DViewport3 *Direct3DViewport3) static HRESULT WINAPI d3d_device3_SetCurrentViewport(IDirect3DDevice3 *iface, IDirect3DViewport3 *viewport)
{ {
struct d3d_device *This = impl_from_IDirect3DDevice3(iface); struct d3d_viewport *vp = unsafe_impl_from_IDirect3DViewport3(viewport);
struct d3d_viewport *vp = unsafe_impl_from_IDirect3DViewport3(Direct3DViewport3); struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
TRACE("iface %p, viewport %p.\n", iface, Direct3DViewport3); TRACE("iface %p, viewport %p, current_viewport %p.\n", iface, viewport, device->current_viewport);
if (!vp) if (!vp)
{ {
WARN("Direct3DViewport3 is NULL, returning DDERR_INVALIDPARAMS\n"); WARN("Direct3DViewport3 is NULL.\n");
return DDERR_INVALIDPARAMS; return DDERR_INVALIDPARAMS;
} }
wined3d_mutex_lock(); wined3d_mutex_lock();
/* Do nothing if the specified viewport is the same as the current one */ /* Do nothing if the specified viewport is the same as the current one */
if (This->current_viewport == vp) if (device->current_viewport == vp)
{ {
wined3d_mutex_unlock(); wined3d_mutex_unlock();
return D3D_OK; return D3D_OK;
} }
if (vp->active_device != This) if (vp->active_device != device)
{ {
WARN("Viewport %p active device is %p.\n", vp, vp->active_device); WARN("Viewport %p, active device %p.\n", vp, vp->active_device);
wined3d_mutex_unlock(); wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS; return DDERR_INVALIDPARAMS;
} }
/* Release previous viewport and AddRef the new one */ IDirect3DViewport3_AddRef(viewport);
if (This->current_viewport) if (device->current_viewport)
{ {
TRACE("ViewportImpl is at %p, interface is at %p\n", This->current_viewport, viewport_deactivate(device->current_viewport);
&This->current_viewport->IDirect3DViewport3_iface); IDirect3DViewport3_Release(&device->current_viewport->IDirect3DViewport3_iface);
IDirect3DViewport3_Release(&This->current_viewport->IDirect3DViewport3_iface);
} }
IDirect3DViewport3_AddRef(Direct3DViewport3); device->current_viewport = vp;
viewport_activate(device->current_viewport, FALSE);
/* Set this viewport as the current viewport */
This->current_viewport = vp;
/* Activate this viewport */
viewport_activate(This->current_viewport, FALSE);
wined3d_mutex_unlock(); wined3d_mutex_unlock();

View File

@ -54,15 +54,14 @@ void light_activate(struct d3d_light *light)
TRACE("light %p.\n", light); TRACE("light %p.\n", light);
if (!light->active_viewport || !light->active_viewport->active_device) return; if (!light->active_viewport || !light->active_viewport->active_device
|| light->active_viewport->active_device->current_viewport != light->active_viewport)
return;
device = light->active_viewport->active_device; device = light->active_viewport->active_device;
light_update(light); light_update(light);
if (!(light->light.dwFlags & D3DLIGHT_ACTIVE)) if (light->light.dwFlags & D3DLIGHT_ACTIVE)
{
IDirect3DDevice7_LightEnable(&device->IDirect3DDevice7_iface, light->dwLightIndex, TRUE); IDirect3DDevice7_LightEnable(&device->IDirect3DDevice7_iface, light->dwLightIndex, TRUE);
light->light.dwFlags |= D3DLIGHT_ACTIVE;
}
} }
/***************************************************************************** /*****************************************************************************
@ -78,14 +77,13 @@ void light_deactivate(struct d3d_light *light)
TRACE("light %p.\n", light); TRACE("light %p.\n", light);
if (!light->active_viewport || !light->active_viewport->active_device) return; if (!light->active_viewport || !light->active_viewport->active_device
device = light->active_viewport->active_device; || light->active_viewport->active_device->current_viewport != light->active_viewport)
return;
device = light->active_viewport->active_device;
if (light->light.dwFlags & D3DLIGHT_ACTIVE) if (light->light.dwFlags & D3DLIGHT_ACTIVE)
{
IDirect3DDevice7_LightEnable(&device->IDirect3DDevice7_iface, light->dwLightIndex, FALSE); IDirect3DDevice7_LightEnable(&device->IDirect3DDevice7_iface, light->dwLightIndex, FALSE);
light->light.dwFlags &= ~D3DLIGHT_ACTIVE;
}
} }
static inline struct d3d_light *impl_from_IDirect3DLight(IDirect3DLight *iface) static inline struct d3d_light *impl_from_IDirect3DLight(IDirect3DLight *iface)
@ -195,13 +193,12 @@ static HRESULT WINAPI d3d_light_SetLight(IDirect3DLight *iface, D3DLIGHT *data)
wined3d_mutex_lock(); wined3d_mutex_lock();
memcpy(&light->light, data, sizeof(*data)); memcpy(&light->light, data, sizeof(*data));
if (!(light->light.dwFlags & D3DLIGHT_ACTIVE) && flags & D3DLIGHT_ACTIVE)
light_activate(light); if (!(flags & D3DLIGHT_ACTIVE))
else if (light->light.dwFlags & D3DLIGHT_ACTIVE && !(flags & D3DLIGHT_ACTIVE))
light_deactivate(light); light_deactivate(light);
else if (flags & D3DLIGHT_ACTIVE)
light_update(light);
light->light.dwFlags = flags; light->light.dwFlags = flags;
light_activate(light);
wined3d_mutex_unlock(); wined3d_mutex_unlock();
return D3D_OK; return D3D_OK;

View File

@ -4189,7 +4189,16 @@ static void test_lighting(void)
light_desc.dwFlags = D3DLIGHT_ACTIVE; light_desc.dwFlags = D3DLIGHT_ACTIVE;
hr = IDirect3DLight_SetLight(light, (D3DLIGHT *)&light_desc); hr = IDirect3DLight_SetLight(light, (D3DLIGHT *)&light_desc);
ok(SUCCEEDED(hr), "Failed to set light, hr %#x.\n", hr); ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DViewport3_DeleteLight(viewport, light);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
light_desc.dwFlags = 0;
hr = IDirect3DLight_GetLight(light, (D3DLIGHT *)&light_desc);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
ok(light_desc.dwFlags == D3DLIGHT_ACTIVE, "Got unexpected flags %#x.\n", light_desc.dwFlags);
hr = IDirect3DViewport3_AddLight(viewport, light);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
for (i = 0; i < ARRAY_SIZE(tests); ++i) for (i = 0; i < ARRAY_SIZE(tests); ++i)
{ {

View File

@ -112,6 +112,16 @@ void viewport_activate(struct d3d_viewport *This, BOOL ignore_lights)
IDirect3DDevice7_SetViewport(&This->active_device->IDirect3DDevice7_iface, &vp); IDirect3DDevice7_SetViewport(&This->active_device->IDirect3DDevice7_iface, &vp);
} }
void viewport_deactivate(struct d3d_viewport *viewport)
{
struct d3d_light *light;
LIST_FOR_EACH_ENTRY(light, &viewport->light_list, struct d3d_light, entry)
{
light_deactivate(light);
}
}
/***************************************************************************** /*****************************************************************************
* _dump_D3DVIEWPORT, _dump_D3DVIEWPORT2 * _dump_D3DVIEWPORT, _dump_D3DVIEWPORT2
* *
@ -783,14 +793,7 @@ static HRESULT WINAPI d3d_viewport_AddLight(IDirect3DViewport3 *iface, IDirect3D
/* Attach the light to the viewport */ /* Attach the light to the viewport */
light_impl->active_viewport = This; light_impl->active_viewport = This;
light_activate(light_impl);
/* If active, activate the light */
if (This->active_device && light_impl->light.dwFlags & D3DLIGHT_ACTIVE)
{
/* Disable the flag so that light_activate actually does its job. */
light_impl->light.dwFlags &= ~D3DLIGHT_ACTIVE;
light_activate(light_impl);
}
wined3d_mutex_unlock(); wined3d_mutex_unlock();