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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
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
|
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"
|
2000-04-09 16:30:50 +02:00
|
|
|
#include "mesa_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);
|
|
|
|
TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, This->ref);
|
|
|
|
return ++(This->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);
|
|
|
|
TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, This->ref);
|
|
|
|
if (!--(This->ref)) {
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return This->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)) {
|
|
|
|
TRACE(" Light definition : \n");
|
|
|
|
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
|
|
|
|
light7->dcvSpecular = *(D3DCOLORVALUE*)zero_value;
|
|
|
|
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)) {
|
|
|
|
TRACE(" Returning light definition : \n");
|
|
|
|
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
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
static void update(IDirect3DLightImpl* This) {
|
2003-05-20 19:49:40 +02:00
|
|
|
IDirect3DDeviceImpl* device;
|
|
|
|
if (!This->active_viewport||!This->active_viewport->active_device)
|
|
|
|
return;
|
|
|
|
device = This->active_viewport->active_device;
|
2003-01-21 00:24:05 +01:00
|
|
|
IDirect3DDevice7_SetLight(ICOM_INTERFACE(device,IDirect3DDevice7),This->dwLightIndex,&(This->light7));
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
static void activate(IDirect3DLightImpl* This) {
|
|
|
|
IDirect3DLightGLImpl *glThis = (IDirect3DLightGLImpl *) This;
|
2003-06-05 01:36:48 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
ENTER_GL();
|
|
|
|
update(This);
|
|
|
|
/* If was not active, activate it */
|
|
|
|
if ((glThis->parent.light.dwFlags & D3DLIGHT_ACTIVE) == 0) {
|
|
|
|
glEnable(glThis->light_num);
|
|
|
|
glThis->parent.light.dwFlags |= D3DLIGHT_ACTIVE;
|
|
|
|
}
|
|
|
|
LEAVE_GL();
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
static void desactivate(IDirect3DLightImpl* This) {
|
|
|
|
IDirect3DLightGLImpl *glThis = (IDirect3DLightGLImpl *) This;
|
2003-06-05 01:36:48 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
ENTER_GL();
|
|
|
|
/* If was not active, activate it */
|
|
|
|
if ((glThis->parent.light.dwFlags & D3DLIGHT_ACTIVE) != 0) {
|
|
|
|
glDisable(glThis->light_num);
|
|
|
|
glThis->parent.light.dwFlags &= ~D3DLIGHT_ACTIVE;
|
|
|
|
}
|
|
|
|
LEAVE_GL();
|
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);
|
|
|
|
IDirect3DLightGLImpl *glThis = (IDirect3DLightGLImpl *) This;
|
|
|
|
|
|
|
|
TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, This->ref);
|
|
|
|
if (!--(This->ref)) {
|
|
|
|
((IDirect3DGLImpl *) This->d3d)->light_released(This->d3d, glThis->light_num);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return This->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
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
ICOM_VTABLE(IDirect3DLight) VTABLE_IDirect3DLight =
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2002-11-21 22:04:16 +01:00
|
|
|
ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
|
|
|
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
|
|
|
|
|
|
|
|
2003-06-05 01:31:39 +02:00
|
|
|
HRESULT d3dlight_create(IDirect3DLightImpl **obj, IDirectDrawImpl *d3d, GLenum light_num)
|
1999-05-22 13:41:38 +02:00
|
|
|
{
|
2002-11-21 22:04:16 +01:00
|
|
|
IDirect3DLightImpl *object;
|
|
|
|
IDirect3DLightGLImpl *gl_object;
|
|
|
|
|
|
|
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DLightGLImpl));
|
|
|
|
if (object == NULL) return DDERR_OUTOFMEMORY;
|
|
|
|
gl_object = (IDirect3DLightGLImpl *) object;
|
|
|
|
|
|
|
|
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
|
|
|
gl_object->light_num = light_num;
|
|
|
|
|
|
|
|
ICOM_INIT_INTERFACE(object, IDirect3DLight, VTABLE_IDirect3DLight);
|
|
|
|
|
|
|
|
*obj = object;
|
|
|
|
|
|
|
|
TRACE(" creating implementation at %p.\n", *obj);
|
|
|
|
|
|
|
|
return D3D_OK;
|
|
|
|
}
|