1999-01-03 18:00:19 +01:00
|
|
|
/* Direct3D Light
|
2002-11-21 22:04:16 +01:00
|
|
|
* Copyright (c) 1998 / 2002 Lionel ULMER
|
2008-10-18 19:19:45 +02:00
|
|
|
* Copyright (c) 2006 Stefan DÖSINGER
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-10 00:29:33 +01:00
|
|
|
*/
|
1999-01-03 18:00:19 +01:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "config.h"
|
2006-06-09 19:36:12 +02:00
|
|
|
#include "wine/port.h"
|
1999-01-03 18:00:19 +01:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
#include "ddraw_private.h"
|
1999-01-03 18:00:19 +01:00
|
|
|
|
2010-08-19 18:57:50 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2010-08-17 19:03:23 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* light_update
|
|
|
|
*
|
|
|
|
* Updates the Direct3DDevice7 lighting parameters
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-13 20:31:37 +01:00
|
|
|
static void light_update(struct d3d_light *light)
|
2010-08-17 19:03:23 +02:00
|
|
|
{
|
2012-04-09 20:43:40 +02:00
|
|
|
struct d3d_device *device;
|
2010-08-17 19:03:23 +02:00
|
|
|
|
|
|
|
TRACE("light %p.\n", light);
|
|
|
|
|
|
|
|
if (!light->active_viewport || !light->active_viewport->active_device) return;
|
|
|
|
device = light->active_viewport->active_device;
|
|
|
|
|
2011-10-17 15:58:51 +02:00
|
|
|
IDirect3DDevice7_SetLight(&device->IDirect3DDevice7_iface, light->dwLightIndex, &light->light7);
|
2010-08-17 19:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* light_activate
|
|
|
|
*
|
|
|
|
* Uses the Direct3DDevice7::LightEnable method to active the light
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-13 20:31:37 +01:00
|
|
|
void light_activate(struct d3d_light *light)
|
2010-08-17 19:03:23 +02:00
|
|
|
{
|
2012-04-09 20:43:40 +02:00
|
|
|
struct d3d_device *device;
|
2010-08-17 19:03:23 +02:00
|
|
|
|
|
|
|
TRACE("light %p.\n", light);
|
|
|
|
|
2019-03-28 19:50:12 +01:00
|
|
|
if (!light->active_viewport || !light->active_viewport->active_device
|
|
|
|
|| light->active_viewport->active_device->current_viewport != light->active_viewport)
|
|
|
|
return;
|
2010-08-17 19:03:23 +02:00
|
|
|
device = light->active_viewport->active_device;
|
|
|
|
|
|
|
|
light_update(light);
|
2019-03-28 19:50:12 +01:00
|
|
|
if (light->light.dwFlags & D3DLIGHT_ACTIVE)
|
2011-10-17 15:58:51 +02:00
|
|
|
IDirect3DDevice7_LightEnable(&device->IDirect3DDevice7_iface, light->dwLightIndex, TRUE);
|
2010-08-17 19:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* light_deactivate
|
|
|
|
*
|
|
|
|
* Uses the Direct3DDevice7::LightEnable method to deactivate the light
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-13 20:31:37 +01:00
|
|
|
void light_deactivate(struct d3d_light *light)
|
2010-08-17 19:03:23 +02:00
|
|
|
{
|
2012-04-09 20:43:40 +02:00
|
|
|
struct d3d_device *device;
|
2010-08-17 19:03:23 +02:00
|
|
|
|
|
|
|
TRACE("light %p.\n", light);
|
|
|
|
|
2019-03-28 19:50:12 +01:00
|
|
|
if (!light->active_viewport || !light->active_viewport->active_device
|
|
|
|
|| light->active_viewport->active_device->current_viewport != light->active_viewport)
|
|
|
|
return;
|
2010-08-17 19:03:23 +02:00
|
|
|
|
2019-03-28 19:50:12 +01:00
|
|
|
device = light->active_viewport->active_device;
|
2010-08-17 19:03:23 +02:00
|
|
|
if (light->light.dwFlags & D3DLIGHT_ACTIVE)
|
2011-10-17 15:58:51 +02:00
|
|
|
IDirect3DDevice7_LightEnable(&device->IDirect3DDevice7_iface, light->dwLightIndex, FALSE);
|
2010-08-17 19:03:23 +02:00
|
|
|
}
|
|
|
|
|
2012-03-13 20:31:37 +01:00
|
|
|
static inline struct d3d_light *impl_from_IDirect3DLight(IDirect3DLight *iface)
|
2011-06-09 11:53:52 +02:00
|
|
|
{
|
2012-03-13 20:31:37 +01:00
|
|
|
return CONTAINING_RECORD(iface, struct d3d_light, IDirect3DLight_iface);
|
2011-06-09 11:53:52 +02:00
|
|
|
}
|
2006-06-09 19:36:12 +02:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DLight::QueryInterface
|
|
|
|
*
|
|
|
|
* Queries the object for different interfaces. Unimplemented for this
|
|
|
|
* object at the moment
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* riid: Interface id asked for
|
|
|
|
* obj: Address to return the resulting pointer at.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* E_NOINTERFACE, because it's a stub
|
|
|
|
*****************************************************************************/
|
2012-03-13 20:31:37 +01:00
|
|
|
static HRESULT WINAPI d3d_light_QueryInterface(IDirect3DLight *iface, REFIID riid, void **object)
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
2010-08-19 18:57:50 +02:00
|
|
|
FIXME("iface %p, riid %s, object %p stub!\n", iface, debugstr_guid(riid), object);
|
|
|
|
|
|
|
|
*object = NULL;
|
2006-06-09 19:36:12 +02:00
|
|
|
return E_NOINTERFACE;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2012-03-13 20:31:37 +01:00
|
|
|
static ULONG WINAPI d3d_light_AddRef(IDirect3DLight *iface)
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
2012-03-13 20:31:37 +01:00
|
|
|
struct d3d_light *light = impl_from_IDirect3DLight(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&light->ref);
|
2005-01-09 18:29:21 +01:00
|
|
|
|
2012-03-13 20:31:37 +01:00
|
|
|
TRACE("%p increasing refcount to %u.\n", light, ref);
|
2005-01-09 18:29:21 +01:00
|
|
|
|
|
|
|
return ref;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2012-03-13 20:31:37 +01:00
|
|
|
static ULONG WINAPI d3d_light_Release(IDirect3DLight *iface)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2012-03-13 20:31:37 +01:00
|
|
|
struct d3d_light *light = impl_from_IDirect3DLight(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&light->ref);
|
2005-01-09 18:29:21 +01:00
|
|
|
|
2012-03-13 20:31:37 +01:00
|
|
|
TRACE("%p decreasing refcount to %u.\n", light, ref);
|
2005-01-09 18:29:21 +01:00
|
|
|
|
2012-03-13 20:31:37 +01:00
|
|
|
if (!ref)
|
|
|
|
{
|
2018-02-13 10:32:47 +01:00
|
|
|
heap_free(light);
|
2010-09-08 11:24:49 +02:00
|
|
|
return 0;
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
2005-01-09 18:29:21 +01:00
|
|
|
return ref;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DLight Methods.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DLight::Initialize
|
|
|
|
*
|
|
|
|
* Initializes the interface. This implementation is a no-op, because
|
|
|
|
* initialization takes place at creation time
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* Direct3D: Pointer to an IDirect3D interface.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* D3D_OK
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-13 20:31:37 +01:00
|
|
|
static HRESULT WINAPI d3d_light_Initialize(IDirect3DLight *iface, IDirect3D *d3d)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2010-08-19 18:57:50 +02:00
|
|
|
TRACE("iface %p, d3d %p.\n", iface, d3d);
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
return D3D_OK;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2013-01-11 12:07:47 +01:00
|
|
|
static HRESULT WINAPI d3d_light_SetLight(IDirect3DLight *iface, D3DLIGHT *data)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2015-04-22 19:30:33 +02:00
|
|
|
static const D3DCOLORVALUE zero_value = {{0.0f}, {0.0f}, {0.0f}, {0.0f}};
|
2012-03-13 20:31:37 +01:00
|
|
|
struct d3d_light *light = impl_from_IDirect3DLight(iface);
|
2015-03-30 20:18:00 +02:00
|
|
|
DWORD flags = data->dwSize >= sizeof(D3DLIGHT2) ? ((D3DLIGHT2 *)data)->dwFlags : D3DLIGHT_ACTIVE;
|
2012-03-13 20:31:37 +01:00
|
|
|
D3DLIGHT7 *light7 = &light->light7;
|
2010-08-19 18:57:50 +02:00
|
|
|
|
2013-01-11 12:07:47 +01:00
|
|
|
TRACE("iface %p, data %p.\n", iface, data);
|
2010-08-19 18:57:50 +02:00
|
|
|
|
2013-01-11 12:07:47 +01:00
|
|
|
if ((!data->dltType) || (data->dltType > D3DLIGHT_PARALLELPOINT))
|
2003-01-21 00:24:05 +01:00
|
|
|
return DDERR_INVALIDPARAMS;
|
2009-09-01 09:09:37 +02:00
|
|
|
|
2013-01-11 12:07:47 +01:00
|
|
|
/* Translate D3DLIGHT2 structure to D3DLIGHT7. */
|
|
|
|
light7->dltType = data->dltType;
|
|
|
|
light7->dcvDiffuse = data->dcvColor;
|
2015-04-22 19:30:33 +02:00
|
|
|
if (flags & D3DLIGHT_NO_SPECULAR)
|
|
|
|
light7->dcvSpecular = zero_value;
|
2003-01-21 00:24:05 +01:00
|
|
|
else
|
2015-04-22 19:30:33 +02:00
|
|
|
light7->dcvSpecular = data->dcvColor;
|
2019-03-29 11:56:34 +01:00
|
|
|
light7->dcvAmbient = zero_value;
|
2013-01-11 12:07:47 +01:00
|
|
|
light7->dvPosition = data->dvPosition;
|
|
|
|
light7->dvDirection = data->dvDirection;
|
|
|
|
light7->dvRange = data->dvRange;
|
|
|
|
light7->dvFalloff = data->dvFalloff;
|
|
|
|
light7->dvAttenuation0 = data->dvAttenuation0;
|
|
|
|
light7->dvAttenuation1 = data->dvAttenuation1;
|
|
|
|
light7->dvAttenuation2 = data->dvAttenuation2;
|
|
|
|
light7->dvTheta = data->dvTheta;
|
|
|
|
light7->dvPhi = data->dvPhi;
|
2003-01-21 00:24:05 +01:00
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
2015-04-22 19:30:33 +02:00
|
|
|
memcpy(&light->light, data, sizeof(*data));
|
2019-03-28 19:50:12 +01:00
|
|
|
|
|
|
|
if (!(flags & D3DLIGHT_ACTIVE))
|
2015-03-30 20:18:02 +02:00
|
|
|
light_deactivate(light);
|
2019-03-28 19:50:12 +01:00
|
|
|
|
2015-03-30 20:18:00 +02:00
|
|
|
light->light.dwFlags = flags;
|
2019-03-28 19:50:12 +01:00
|
|
|
light_activate(light);
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
return D3D_OK;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DLight::GetLight
|
|
|
|
*
|
|
|
|
* Returns the parameters currently assigned to the IDirect3DLight object
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* Light: Pointer to an D3DLIGHT structure to store the parameters
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* D3D_OK on success
|
|
|
|
* DDERR_INVALIDPARAMS if Light is NULL
|
|
|
|
*****************************************************************************/
|
2012-03-13 20:31:37 +01:00
|
|
|
static HRESULT WINAPI d3d_light_GetLight(IDirect3DLight *iface, D3DLIGHT *lpLight)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2012-03-13 20:31:37 +01:00
|
|
|
struct d3d_light *light = impl_from_IDirect3DLight(iface);
|
2010-08-19 18:57:50 +02:00
|
|
|
|
|
|
|
TRACE("iface %p, light %p.\n", iface, lpLight);
|
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
2012-03-13 20:31:37 +01:00
|
|
|
memcpy(lpLight, &light->light, lpLight->dwSize);
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
2007-05-30 16:16:04 +02:00
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
return DD_OK;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2010-08-18 19:26:21 +02:00
|
|
|
static const struct IDirect3DLightVtbl d3d_light_vtbl =
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2006-06-09 19:36:12 +02:00
|
|
|
/*** IUnknown Methods ***/
|
2012-03-13 20:31:37 +01:00
|
|
|
d3d_light_QueryInterface,
|
|
|
|
d3d_light_AddRef,
|
|
|
|
d3d_light_Release,
|
2006-06-09 19:36:12 +02:00
|
|
|
/*** IDirect3DLight Methods ***/
|
2012-03-13 20:31:37 +01:00
|
|
|
d3d_light_Initialize,
|
|
|
|
d3d_light_SetLight,
|
|
|
|
d3d_light_GetLight
|
2002-11-21 22:04:16 +01:00
|
|
|
};
|
2010-08-18 19:26:21 +02:00
|
|
|
|
2012-03-13 20:31:37 +01:00
|
|
|
void d3d_light_init(struct d3d_light *light, struct ddraw *ddraw)
|
2010-08-18 19:26:21 +02:00
|
|
|
{
|
2011-06-09 11:53:52 +02:00
|
|
|
light->IDirect3DLight_iface.lpVtbl = &d3d_light_vtbl;
|
2010-08-18 19:26:21 +02:00
|
|
|
light->ref = 1;
|
|
|
|
light->ddraw = ddraw;
|
|
|
|
}
|
2011-06-09 11:57:45 +02:00
|
|
|
|
2012-03-13 20:31:37 +01:00
|
|
|
struct d3d_light *unsafe_impl_from_IDirect3DLight(IDirect3DLight *iface)
|
2011-06-09 11:57:45 +02:00
|
|
|
{
|
|
|
|
if (!iface)
|
|
|
|
return NULL;
|
|
|
|
assert(iface->lpVtbl == &d3d_light_vtbl);
|
|
|
|
|
|
|
|
return impl_from_IDirect3DLight(iface);
|
|
|
|
}
|