1999-01-03 17:00:19 +00:00
|
|
|
|
/* Direct3D Light
|
2002-11-21 21:04:16 +00:00
|
|
|
|
* Copyright (c) 1998 / 2002 Lionel ULMER
|
2006-06-09 17:36:12 +00:00
|
|
|
|
* Copyright (c) 2006 Stefan D<EFBFBD>SINGER
|
2002-03-09 23:29:33 +00:00
|
|
|
|
*
|
|
|
|
|
* This file contains the implementation of Direct3DLight.
|
|
|
|
|
*
|
|
|
|
|
* 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 12:49:52 +00:00
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-09 23:29:33 +00:00
|
|
|
|
*/
|
1999-01-03 17:00:19 +00:00
|
|
|
|
|
2003-09-05 23:08:26 +00:00
|
|
|
|
#include "config.h"
|
2006-06-09 17:36:12 +00:00
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
#include "wine/debug.h"
|
2003-09-05 23:08:26 +00:00
|
|
|
|
|
2006-06-09 17:36:12 +00:00
|
|
|
|
#include <assert.h>
|
2003-09-05 23:08:26 +00:00
|
|
|
|
#include <stdarg.h>
|
2006-06-09 17:36:12 +00:00
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
2003-09-05 23:08:26 +00:00
|
|
|
|
|
2006-06-09 17:36:12 +00:00
|
|
|
|
#define COBJMACROS
|
2005-05-27 20:17:35 +00:00
|
|
|
|
|
1999-03-14 16:35:05 +00:00
|
|
|
|
#include "windef.h"
|
2003-09-05 23:08:26 +00:00
|
|
|
|
#include "winbase.h"
|
1999-01-03 17:00:19 +00:00
|
|
|
|
#include "winerror.h"
|
2003-09-05 23:08:26 +00:00
|
|
|
|
#include "wingdi.h"
|
2006-06-09 17:36:12 +00:00
|
|
|
|
#include "wine/exception.h"
|
|
|
|
|
|
1999-01-03 17:00:19 +00:00
|
|
|
|
#include "ddraw.h"
|
|
|
|
|
#include "d3d.h"
|
|
|
|
|
|
2006-06-09 17:36:12 +00:00
|
|
|
|
#include "ddraw_private.h"
|
1999-01-03 17:00:19 +00:00
|
|
|
|
|
2006-06-09 17:36:12 +00:00
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d7);
|
2002-05-31 23:06:46 +00:00
|
|
|
|
|
2006-06-09 17:36:12 +00:00
|
|
|
|
/*****************************************************************************
|
|
|
|
|
* IUnknown Methods.
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
|
* 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
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
static HRESULT WINAPI
|
|
|
|
|
IDirect3DLightImpl_QueryInterface(IDirect3DLight *iface,
|
|
|
|
|
REFIID riid,
|
|
|
|
|
void **obp)
|
2002-11-21 21:04:16 +00:00
|
|
|
|
{
|
|
|
|
|
ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
|
2006-06-09 17:36:12 +00:00
|
|
|
|
FIXME("(%p)->(%s,%p): stub!\n", This, debugstr_guid(riid), obp);
|
|
|
|
|
*obp = NULL;
|
|
|
|
|
return E_NOINTERFACE;
|
1999-01-03 17:00:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-09 17:36:12 +00:00
|
|
|
|
/*****************************************************************************
|
|
|
|
|
* IDirect3DLight::AddRef
|
|
|
|
|
*
|
|
|
|
|
* Increases the refcount by 1
|
|
|
|
|
*
|
|
|
|
|
* Returns:
|
|
|
|
|
* The new refcount
|
|
|
|
|
*
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
static ULONG WINAPI
|
|
|
|
|
IDirect3DLightImpl_AddRef(IDirect3DLight *iface)
|
2002-11-21 21:04:16 +00:00
|
|
|
|
{
|
|
|
|
|
ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
|
2005-01-09 17:29:21 +00:00
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
2006-10-10 17:23:27 +00:00
|
|
|
|
TRACE("(%p)->() incrementing from %u.\n", This, ref - 1);
|
2005-01-09 17:29:21 +00:00
|
|
|
|
|
|
|
|
|
return ref;
|
1999-01-03 17:00:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-09 17:36:12 +00:00
|
|
|
|
/*****************************************************************************
|
|
|
|
|
* IDirect3DLight::Release
|
|
|
|
|
*
|
|
|
|
|
* Reduces the refcount by one. If the refcount falls to 0, the object
|
|
|
|
|
* is destroyed
|
|
|
|
|
*
|
|
|
|
|
* Returns:
|
|
|
|
|
* The new refcount
|
|
|
|
|
*
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
static ULONG WINAPI
|
|
|
|
|
IDirect3DLightImpl_Release(IDirect3DLight *iface)
|
1999-01-03 17:00:19 +00:00
|
|
|
|
{
|
2002-11-21 21:04:16 +00:00
|
|
|
|
ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
|
2005-01-09 17:29:21 +00:00
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
2006-10-10 17:23:27 +00:00
|
|
|
|
TRACE("(%p)->() decrementing from %u.\n", This, ref + 1);
|
2005-01-09 17:29:21 +00:00
|
|
|
|
|
|
|
|
|
if (!ref) {
|
2002-11-21 21:04:16 +00:00
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2005-01-09 17:29:21 +00:00
|
|
|
|
return ref;
|
1999-01-03 17:00:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-09 17:36:12 +00: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
|
|
|
|
|
*
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
static HRESULT WINAPI
|
|
|
|
|
IDirect3DLightImpl_Initialize(IDirect3DLight *iface,
|
|
|
|
|
IDirect3D *lpDirect3D)
|
1999-01-03 17:00:19 +00:00
|
|
|
|
{
|
2002-11-21 21:04:16 +00:00
|
|
|
|
ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
|
2006-06-09 17:36:12 +00:00
|
|
|
|
IDirectDrawImpl *d3d = ICOM_OBJECT(IDirectDrawImpl, IDirect3D, lpDirect3D);
|
|
|
|
|
TRACE("(%p)->(%p) no-op...\n", This, d3d);
|
|
|
|
|
return D3D_OK;
|
1999-01-03 17:00:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-09 17:36:12 +00:00
|
|
|
|
/*****************************************************************************
|
|
|
|
|
* IDirect3DLight::SetLight
|
|
|
|
|
*
|
|
|
|
|
* Assigns a lighting value to this object
|
|
|
|
|
*
|
|
|
|
|
* Params:
|
2008-04-02 19:26:42 +00:00
|
|
|
|
* Light: Lighting parameter to set
|
2006-06-09 17:36:12 +00:00
|
|
|
|
*
|
|
|
|
|
* Returns:
|
|
|
|
|
* D3D_OK on success
|
|
|
|
|
* DDERR_INVALIDPARAMS if Light is NULL
|
|
|
|
|
*
|
|
|
|
|
*****************************************************************************/
|
2007-04-21 21:16:34 +00:00
|
|
|
|
static void dump_light(const D3DLIGHT2 *light)
|
1999-01-03 17:00:19 +00:00
|
|
|
|
{
|
2007-12-04 22:27:33 +00:00
|
|
|
|
TRACE(" - dwSize : %d\n", light->dwSize);
|
1999-01-03 17:00:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-01-20 23:24:05 +00:00
|
|
|
|
static const float zero_value[] = {
|
|
|
|
|
0.0, 0.0, 0.0, 0.0
|
|
|
|
|
};
|
|
|
|
|
|
2006-06-09 17:36:12 +00:00
|
|
|
|
static HRESULT WINAPI
|
|
|
|
|
IDirect3DLightImpl_SetLight(IDirect3DLight *iface,
|
|
|
|
|
D3DLIGHT *lpLight)
|
1999-01-03 17:00:19 +00:00
|
|
|
|
{
|
2002-11-21 21:04:16 +00:00
|
|
|
|
ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
|
2003-01-20 23:24:05 +00:00
|
|
|
|
LPD3DLIGHT7 light7 = &(This->light7);
|
2006-06-09 17:36:12 +00:00
|
|
|
|
TRACE("(%p)->(%p)\n", This, lpLight);
|
|
|
|
|
if (TRACE_ON(d3d7)) {
|
2005-11-10 12:14:56 +00:00
|
|
|
|
TRACE(" Light definition :\n");
|
2002-11-21 21:04:16 +00:00
|
|
|
|
dump_light((LPD3DLIGHT2) lpLight);
|
|
|
|
|
}
|
2003-01-20 23:24:05 +00:00
|
|
|
|
|
|
|
|
|
if ( (lpLight->dltType == 0) || (lpLight->dltType > D3DLIGHT_PARALLELPOINT) )
|
|
|
|
|
return DDERR_INVALIDPARAMS;
|
|
|
|
|
|
|
|
|
|
if ( lpLight->dltType == D3DLIGHT_PARALLELPOINT )
|
|
|
|
|
FIXME("D3DLIGHT_PARALLELPOINT no supported\n");
|
|
|
|
|
|
|
|
|
|
/* Translate D3DLIGH2 structure to D3DLIGHT7 */
|
|
|
|
|
light7->dltType = lpLight->dltType;
|
|
|
|
|
light7->dcvDiffuse = lpLight->dcvColor;
|
|
|
|
|
if ((((LPD3DLIGHT2)lpLight)->dwFlags & D3DLIGHT_NO_SPECULAR) != 0)
|
|
|
|
|
light7->dcvSpecular = lpLight->dcvColor;
|
|
|
|
|
else
|
2004-11-30 21:38:57 +00:00
|
|
|
|
light7->dcvSpecular = *(const D3DCOLORVALUE*)zero_value;
|
2003-01-20 23:24:05 +00:00
|
|
|
|
light7->dcvAmbient = lpLight->dcvColor;
|
|
|
|
|
light7->dvPosition = lpLight->dvPosition;
|
|
|
|
|
light7->dvDirection = lpLight->dvDirection;
|
|
|
|
|
light7->dvRange = lpLight->dvRange;
|
|
|
|
|
light7->dvFalloff = lpLight->dvFalloff;
|
|
|
|
|
light7->dvAttenuation0 = lpLight->dvAttenuation0;
|
|
|
|
|
light7->dvAttenuation1 = lpLight->dvAttenuation1;
|
|
|
|
|
light7->dvAttenuation2 = lpLight->dvAttenuation2;
|
|
|
|
|
light7->dvTheta = lpLight->dvTheta;
|
|
|
|
|
light7->dvPhi = lpLight->dvPhi;
|
|
|
|
|
|
2007-05-30 14:16:04 +00:00
|
|
|
|
EnterCriticalSection(&ddraw_cs);
|
2002-11-21 21:04:16 +00:00
|
|
|
|
memcpy(&This->light, lpLight, lpLight->dwSize);
|
|
|
|
|
if ((This->light.dwFlags & D3DLIGHT_ACTIVE) != 0) {
|
|
|
|
|
This->update(This);
|
|
|
|
|
}
|
2007-05-30 14:16:04 +00:00
|
|
|
|
LeaveCriticalSection(&ddraw_cs);
|
2006-06-09 17:36:12 +00:00
|
|
|
|
return D3D_OK;
|
1999-01-03 17:00:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-09 17:36:12 +00: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
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
static HRESULT WINAPI
|
|
|
|
|
IDirect3DLightImpl_GetLight(IDirect3DLight *iface,
|
|
|
|
|
D3DLIGHT *lpLight)
|
1999-01-03 17:00:19 +00:00
|
|
|
|
{
|
2002-11-21 21:04:16 +00:00
|
|
|
|
ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
|
|
|
|
|
TRACE("(%p/%p)->(%p)\n", This, iface, lpLight);
|
2006-06-09 17:36:12 +00:00
|
|
|
|
if (TRACE_ON(d3d7)) {
|
2005-11-10 12:14:56 +00:00
|
|
|
|
TRACE(" Returning light definition :\n");
|
2002-11-21 21:04:16 +00:00
|
|
|
|
dump_light(&This->light);
|
|
|
|
|
}
|
2007-05-30 14:16:04 +00:00
|
|
|
|
|
|
|
|
|
EnterCriticalSection(&ddraw_cs);
|
2002-11-21 21:04:16 +00:00
|
|
|
|
memcpy(lpLight, &This->light, lpLight->dwSize);
|
2007-05-30 14:16:04 +00:00
|
|
|
|
LeaveCriticalSection(&ddraw_cs);
|
|
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
|
return DD_OK;
|
|
|
|
|
}
|
2002-05-31 23:06:46 +00:00
|
|
|
|
|
2006-06-09 17:36:12 +00:00
|
|
|
|
/*****************************************************************************
|
|
|
|
|
* light_update
|
|
|
|
|
*
|
|
|
|
|
* Updates the Direct3DDevice7 lighting parameters
|
|
|
|
|
*
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
void light_update(IDirect3DLightImpl* This)
|
2005-10-31 10:05:15 +00:00
|
|
|
|
{
|
2003-05-20 17:49:40 +00:00
|
|
|
|
IDirect3DDeviceImpl* device;
|
2005-10-31 10:05:15 +00:00
|
|
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
|
|
if (!This->active_viewport || !This->active_viewport->active_device)
|
2003-05-20 17:49:40 +00:00
|
|
|
|
return;
|
|
|
|
|
device = This->active_viewport->active_device;
|
2005-10-31 10:05:15 +00:00
|
|
|
|
|
|
|
|
|
IDirect3DDevice7_SetLight(ICOM_INTERFACE(device,IDirect3DDevice7), This->dwLightIndex, &(This->light7));
|
1999-01-03 17:00:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-09 17:36:12 +00:00
|
|
|
|
/*****************************************************************************
|
|
|
|
|
* light_activate
|
|
|
|
|
*
|
|
|
|
|
* Uses the Direct3DDevice7::LightEnable method to active the light
|
|
|
|
|
*
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
void light_activate(IDirect3DLightImpl* This)
|
2005-10-31 10:05:15 +00:00
|
|
|
|
{
|
|
|
|
|
IDirect3DDeviceImpl* device;
|
2003-06-04 23:36:48 +00:00
|
|
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
2005-10-31 10:05:15 +00:00
|
|
|
|
|
|
|
|
|
if (!This->active_viewport || !This->active_viewport->active_device)
|
|
|
|
|
return;
|
|
|
|
|
device = This->active_viewport->active_device;
|
2003-06-04 23:36:48 +00:00
|
|
|
|
|
2006-06-09 17:36:12 +00:00
|
|
|
|
light_update(This);
|
2002-11-21 21:04:16 +00:00
|
|
|
|
/* If was not active, activate it */
|
2005-10-31 10:05:15 +00:00
|
|
|
|
if ((This->light.dwFlags & D3DLIGHT_ACTIVE) == 0) {
|
|
|
|
|
IDirect3DDevice7_LightEnable(ICOM_INTERFACE(device,IDirect3DDevice7), This->dwLightIndex, TRUE);
|
|
|
|
|
This->light.dwFlags |= D3DLIGHT_ACTIVE;
|
2002-11-21 21:04:16 +00:00
|
|
|
|
}
|
1999-01-03 17:00:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-09 17:36:12 +00:00
|
|
|
|
/*****************************************************************************
|
|
|
|
|
*
|
|
|
|
|
* light_desactivate
|
|
|
|
|
*
|
|
|
|
|
* Uses the Direct3DDevice7::LightEnable method to deactivate the light
|
|
|
|
|
*
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
void light_desactivate(IDirect3DLightImpl* This)
|
2005-10-31 10:05:15 +00:00
|
|
|
|
{
|
|
|
|
|
IDirect3DDeviceImpl* device;
|
|
|
|
|
|
2003-06-04 23:36:48 +00:00
|
|
|
|
TRACE("(%p)\n", This);
|
2005-10-31 10:05:15 +00:00
|
|
|
|
|
|
|
|
|
if (!This->active_viewport || !This->active_viewport->active_device)
|
|
|
|
|
return;
|
|
|
|
|
device = This->active_viewport->active_device;
|
2003-06-04 23:36:48 +00:00
|
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
|
/* If was not active, activate it */
|
2005-10-31 10:05:15 +00:00
|
|
|
|
if ((This->light.dwFlags & D3DLIGHT_ACTIVE) != 0) {
|
|
|
|
|
IDirect3DDevice7_LightEnable(ICOM_INTERFACE(device,IDirect3DDevice7), This->dwLightIndex, FALSE);
|
|
|
|
|
This->light.dwFlags &= ~D3DLIGHT_ACTIVE;
|
2002-11-21 21:04:16 +00:00
|
|
|
|
}
|
1999-01-03 17:00:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-09 17:36:12 +00:00
|
|
|
|
const IDirect3DLightVtbl IDirect3DLight_Vtbl =
|
1999-01-03 17:00:19 +00:00
|
|
|
|
{
|
2006-06-09 17:36:12 +00:00
|
|
|
|
/*** IUnknown Methods ***/
|
|
|
|
|
IDirect3DLightImpl_QueryInterface,
|
|
|
|
|
IDirect3DLightImpl_AddRef,
|
|
|
|
|
IDirect3DLightImpl_Release,
|
|
|
|
|
/*** IDirect3DLight Methods ***/
|
|
|
|
|
IDirect3DLightImpl_Initialize,
|
|
|
|
|
IDirect3DLightImpl_SetLight,
|
|
|
|
|
IDirect3DLightImpl_GetLight
|
2002-11-21 21:04:16 +00:00
|
|
|
|
};
|