1999-01-03 18:00:19 +01:00
|
|
|
/* Direct3D Light
|
2002-11-21 22:04:16 +01:00
|
|
|
* Copyright (c) 1998 / 2002 Lionel ULMER
|
2002-03-10 00:29:33 +01: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 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"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2003-01-07 21:36:20 +01:00
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
2005-05-27 22:17:35 +02:00
|
|
|
|
1999-03-14 17:35:05 +01:00
|
|
|
#include "windef.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "winbase.h"
|
1999-01-03 18:00:19 +01:00
|
|
|
#include "winerror.h"
|
2002-12-05 21:33:07 +01:00
|
|
|
#include "objbase.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "wingdi.h"
|
1999-01-03 18:00:19 +01:00
|
|
|
#include "ddraw.h"
|
|
|
|
#include "d3d.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
1999-01-03 18:00:19 +01:00
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
#include "d3d_private.h"
|
2005-06-06 17:51:50 +02:00
|
|
|
#include "opengl_private.h"
|
1999-01-03 18:00:19 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
/* First, the 'main' interface... */
|
|
|
|
HRESULT WINAPI
|
|
|
|
Main_IDirect3DLightImpl_1_QueryInterface(LPDIRECT3DLIGHT iface,
|
|
|
|
REFIID riid,
|
|
|
|
LPVOID* obp)
|
|
|
|
{
|
|
|
|
ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
|
|
|
|
FIXME("(%p/%p)->(%s,%p): stub!\n", This, iface, debugstr_guid(riid), obp);
|
|
|
|
return DD_OK;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
ULONG WINAPI
|
|
|
|
Main_IDirect3DLightImpl_1_AddRef(LPDIRECT3DLIGHT iface)
|
|
|
|
{
|
|
|
|
ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
|
2005-01-09 18:29:21 +01:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, ref - 1);
|
|
|
|
|
|
|
|
return ref;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
ULONG WINAPI
|
|
|
|
Main_IDirect3DLightImpl_1_Release(LPDIRECT3DLIGHT iface)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2002-11-21 22:04:16 +01:00
|
|
|
ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
|
2005-01-09 18:29:21 +01:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, ref + 1);
|
|
|
|
|
|
|
|
if (!ref) {
|
2002-11-21 22:04:16 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
return 0;
|
|
|
|
}
|
2005-01-09 18:29:21 +01:00
|
|
|
return ref;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
HRESULT WINAPI
|
|
|
|
Main_IDirect3DLightImpl_1_Initialize(LPDIRECT3DLIGHT iface,
|
|
|
|
LPDIRECT3D lpDirect3D)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2002-11-21 22:04:16 +01:00
|
|
|
ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
|
|
|
|
TRACE("(%p/%p)->(%p) no-op...\n", This, iface, lpDirect3D);
|
|
|
|
return DD_OK;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
/*** IDirect3DLight methods ***/
|
|
|
|
static void dump_light(LPD3DLIGHT2 light)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2002-11-21 22:04:16 +01:00
|
|
|
DPRINTF(" - dwSize : %ld\n", light->dwSize);
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2003-01-21 00:24:05 +01:00
|
|
|
static const float zero_value[] = {
|
|
|
|
0.0, 0.0, 0.0, 0.0
|
|
|
|
};
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
HRESULT WINAPI
|
|
|
|
Main_IDirect3DLightImpl_1_SetLight(LPDIRECT3DLIGHT iface,
|
|
|
|
LPD3DLIGHT lpLight)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2002-11-21 22:04:16 +01:00
|
|
|
ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
|
2003-01-21 00:24:05 +01:00
|
|
|
LPD3DLIGHT7 light7 = &(This->light7);
|
2002-11-21 22:04:16 +01:00
|
|
|
TRACE("(%p/%p)->(%p)\n", This, iface, lpLight);
|
|
|
|
if (TRACE_ON(ddraw)) {
|
2005-11-10 13:14:56 +01:00
|
|
|
TRACE(" Light definition :\n");
|
2002-11-21 22:04:16 +01:00
|
|
|
dump_light((LPD3DLIGHT2) lpLight);
|
|
|
|
}
|
2003-01-21 00:24:05 +01: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 22:38:57 +01:00
|
|
|
light7->dcvSpecular = *(const D3DCOLORVALUE*)zero_value;
|
2003-01-21 00:24:05 +01: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;
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
memcpy(&This->light, lpLight, lpLight->dwSize);
|
|
|
|
if ((This->light.dwFlags & D3DLIGHT_ACTIVE) != 0) {
|
|
|
|
This->update(This);
|
|
|
|
}
|
|
|
|
return DD_OK;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
HRESULT WINAPI
|
|
|
|
Main_IDirect3DLightImpl_1_GetLight(LPDIRECT3DLIGHT iface,
|
|
|
|
LPD3DLIGHT lpLight)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2002-11-21 22:04:16 +01:00
|
|
|
ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
|
|
|
|
TRACE("(%p/%p)->(%p)\n", This, iface, lpLight);
|
|
|
|
if (TRACE_ON(ddraw)) {
|
2005-11-10 13:14:56 +01:00
|
|
|
TRACE(" Returning light definition :\n");
|
2002-11-21 22:04:16 +01:00
|
|
|
dump_light(&This->light);
|
|
|
|
}
|
|
|
|
memcpy(lpLight, &This->light, lpLight->dwSize);
|
|
|
|
return DD_OK;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
/*******************************************************************************
|
|
|
|
* Light static functions
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-10-31 11:05:15 +01:00
|
|
|
static void update(IDirect3DLightImpl* This)
|
|
|
|
{
|
2003-05-20 19:49:40 +02:00
|
|
|
IDirect3DDeviceImpl* device;
|
2005-10-31 11:05:15 +01:00
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
if (!This->active_viewport || !This->active_viewport->active_device)
|
2003-05-20 19:49:40 +02:00
|
|
|
return;
|
|
|
|
device = This->active_viewport->active_device;
|
2005-10-31 11:05:15 +01:00
|
|
|
|
|
|
|
IDirect3DDevice7_SetLight(ICOM_INTERFACE(device,IDirect3DDevice7), This->dwLightIndex, &(This->light7));
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2005-10-31 11:05:15 +01:00
|
|
|
static void activate(IDirect3DLightImpl* This)
|
|
|
|
{
|
|
|
|
IDirect3DDeviceImpl* device;
|
2003-06-05 01:36:48 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
2005-10-31 11:05:15 +01:00
|
|
|
|
|
|
|
if (!This->active_viewport || !This->active_viewport->active_device)
|
|
|
|
return;
|
|
|
|
device = This->active_viewport->active_device;
|
2003-06-05 01:36:48 +02:00
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
update(This);
|
|
|
|
/* If was not active, activate it */
|
2005-10-31 11:05:15 +01: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 22:04:16 +01:00
|
|
|
}
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2005-10-31 11:05:15 +01:00
|
|
|
static void desactivate(IDirect3DLightImpl* This)
|
|
|
|
{
|
|
|
|
IDirect3DDeviceImpl* device;
|
|
|
|
|
2003-06-05 01:36:48 +02:00
|
|
|
TRACE("(%p)\n", This);
|
2005-10-31 11:05:15 +01:00
|
|
|
|
|
|
|
if (!This->active_viewport || !This->active_viewport->active_device)
|
|
|
|
return;
|
|
|
|
device = This->active_viewport->active_device;
|
2003-06-05 01:36:48 +02:00
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
/* If was not active, activate it */
|
2005-10-31 11:05:15 +01: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 22:04:16 +01:00
|
|
|
}
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
ULONG WINAPI
|
|
|
|
GL_IDirect3DLightImpl_1_Release(LPDIRECT3DLIGHT iface)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2002-11-21 22:04:16 +01:00
|
|
|
ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
|
2005-01-09 18:29:21 +01:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
2002-11-21 22:04:16 +01:00
|
|
|
|
2005-01-09 18:29:21 +01:00
|
|
|
TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, ref + 1);
|
|
|
|
|
|
|
|
if (!ref) {
|
2002-11-21 22:04:16 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
return 0;
|
|
|
|
}
|
2005-01-09 18:29:21 +01:00
|
|
|
return ref;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
#if !defined(__STRICT_ANSI__) && defined(__GNUC__)
|
|
|
|
# define XCAST(fun) (typeof(VTABLE_IDirect3DLight.fun))
|
|
|
|
#else
|
|
|
|
# define XCAST(fun) (void*)
|
|
|
|
#endif
|
1999-01-03 18:00:19 +01:00
|
|
|
|
2005-05-27 22:17:35 +02:00
|
|
|
static const IDirect3DLightVtbl VTABLE_IDirect3DLight =
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2002-11-21 22:04:16 +01:00
|
|
|
XCAST(QueryInterface) Main_IDirect3DLightImpl_1_QueryInterface,
|
|
|
|
XCAST(AddRef) Main_IDirect3DLightImpl_1_AddRef,
|
|
|
|
XCAST(Release) GL_IDirect3DLightImpl_1_Release,
|
|
|
|
XCAST(Initialize) Main_IDirect3DLightImpl_1_Initialize,
|
|
|
|
XCAST(SetLight) Main_IDirect3DLightImpl_1_SetLight,
|
|
|
|
XCAST(GetLight) Main_IDirect3DLightImpl_1_GetLight,
|
|
|
|
};
|
1999-01-03 18:00:19 +01:00
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
#if !defined(__STRICT_ANSI__) && defined(__GNUC__)
|
|
|
|
#undef XCAST
|
|
|
|
#endif
|
1999-01-03 18:00:19 +01:00
|
|
|
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
|
|
|
|
|
2005-10-31 11:05:15 +01:00
|
|
|
HRESULT d3dlight_create(IDirect3DLightImpl **obj, IDirectDrawImpl *d3d)
|
1999-05-22 13:41:38 +02:00
|
|
|
{
|
2002-11-21 22:04:16 +01:00
|
|
|
IDirect3DLightImpl *object;
|
|
|
|
|
2005-10-31 11:05:15 +01:00
|
|
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DLightImpl));
|
2002-11-21 22:04:16 +01:00
|
|
|
if (object == NULL) return DDERR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
object->ref = 1;
|
|
|
|
object->d3d = d3d;
|
|
|
|
object->next = NULL;
|
|
|
|
object->activate = activate;
|
|
|
|
object->desactivate = desactivate;
|
|
|
|
object->update = update;
|
2003-01-21 00:24:05 +01:00
|
|
|
object->active_viewport = NULL;
|
2002-11-21 22:04:16 +01:00
|
|
|
|
|
|
|
ICOM_INIT_INTERFACE(object, IDirect3DLight, VTABLE_IDirect3DLight);
|
|
|
|
|
|
|
|
*obj = object;
|
|
|
|
|
|
|
|
TRACE(" creating implementation at %p.\n", *obj);
|
|
|
|
|
|
|
|
return D3D_OK;
|
|
|
|
}
|