1999-01-03 18:00:19 +01:00
|
|
|
/* Direct3D Light
|
|
|
|
(c) 1998 Lionel ULMER
|
|
|
|
|
|
|
|
This files contains the implementation of Direct3DLight. */
|
|
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
1999-03-14 17:35:05 +01:00
|
|
|
#include "windef.h"
|
1999-01-03 18:00:19 +01:00
|
|
|
#include "winerror.h"
|
1999-02-02 17:14:23 +01:00
|
|
|
#include "wine/obj_base.h"
|
1999-01-03 18:00:19 +01:00
|
|
|
#include "heap.h"
|
|
|
|
#include "ddraw.h"
|
|
|
|
#include "d3d.h"
|
1999-06-26 21:09:08 +02:00
|
|
|
#include "debugtools.h"
|
1999-01-03 18:00:19 +01:00
|
|
|
|
|
|
|
#include "d3d_private.h"
|
|
|
|
|
1999-04-19 16:56:29 +02:00
|
|
|
DEFAULT_DEBUG_CHANNEL(ddraw)
|
|
|
|
|
1999-01-03 18:00:19 +01:00
|
|
|
#ifdef HAVE_MESAGL
|
|
|
|
|
1999-03-27 17:56:13 +01:00
|
|
|
static ICOM_VTABLE(IDirect3DLight) light_vtable;
|
1999-01-03 18:00:19 +01:00
|
|
|
|
|
|
|
enum {
|
|
|
|
D3D_1,
|
|
|
|
D3D_2
|
|
|
|
};
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* Light static functions
|
|
|
|
*/
|
|
|
|
static const float zero_value[] = {
|
|
|
|
0.0, 0.0, 0.0, 0.0
|
|
|
|
};
|
|
|
|
|
1999-03-27 17:56:13 +01:00
|
|
|
static void update(IDirect3DLightImpl* This) {
|
|
|
|
switch (This->light.dltType) {
|
1999-01-03 18:00:19 +01:00
|
|
|
case D3DLIGHT_POINT: /* 1 */
|
1999-06-26 21:09:08 +02:00
|
|
|
TRACE("Activating POINT\n");
|
1999-01-03 18:00:19 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DLIGHT_SPOT: /* 2 */
|
1999-06-26 21:09:08 +02:00
|
|
|
TRACE("Activating SPOT\n");
|
1999-01-03 18:00:19 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case D3DLIGHT_DIRECTIONAL: { /* 3 */
|
|
|
|
float direction[4];
|
|
|
|
|
1999-06-26 21:09:08 +02:00
|
|
|
TRACE("Activating DIRECTIONAL\n");
|
|
|
|
TRACE(" direction : %f %f %f\n",
|
1999-03-27 17:56:13 +01:00
|
|
|
This->light.dvDirection.x.x,
|
|
|
|
This->light.dvDirection.y.y,
|
|
|
|
This->light.dvDirection.z.z);
|
|
|
|
_dump_colorvalue(" color ", This->light.dcvColor);
|
1999-01-03 18:00:19 +01:00
|
|
|
|
1999-03-27 17:56:13 +01:00
|
|
|
glLightfv(This->light_num,
|
1999-01-03 18:00:19 +01:00
|
|
|
GL_AMBIENT,
|
|
|
|
(float *) zero_value);
|
|
|
|
|
1999-03-27 17:56:13 +01:00
|
|
|
glLightfv(This->light_num,
|
1999-01-03 18:00:19 +01:00
|
|
|
GL_DIFFUSE,
|
1999-03-27 17:56:13 +01:00
|
|
|
(float *) &(This->light.dcvColor));
|
1999-01-03 18:00:19 +01:00
|
|
|
|
1999-03-27 17:56:13 +01:00
|
|
|
direction[0] = -This->light.dvDirection.x.x;
|
|
|
|
direction[1] = -This->light.dvDirection.y.y;
|
|
|
|
direction[2] = -This->light.dvDirection.z.z;
|
1999-01-03 18:00:19 +01:00
|
|
|
direction[3] = 0.0; /* This is a directional light */
|
1999-03-27 17:56:13 +01:00
|
|
|
glLightfv(This->light_num,
|
1999-01-03 18:00:19 +01:00
|
|
|
GL_POSITION,
|
|
|
|
(float *) direction);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case D3DLIGHT_PARALLELPOINT: /* 4 */
|
1999-06-26 21:09:08 +02:00
|
|
|
TRACE("Activating PARRALLEL-POINT\n");
|
1999-01-03 18:00:19 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1999-06-26 21:09:08 +02:00
|
|
|
TRACE("Not a know Light Type\n");
|
1999-01-03 18:00:19 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-03-27 17:56:13 +01:00
|
|
|
static void activate(IDirect3DLightImpl* This) {
|
1999-05-13 20:53:05 +02:00
|
|
|
ENTER_GL();
|
1999-03-27 17:56:13 +01:00
|
|
|
update(This);
|
1999-01-03 18:00:19 +01:00
|
|
|
|
|
|
|
/* If was not active, activate it */
|
1999-03-27 17:56:13 +01:00
|
|
|
if (This->is_active == 0) {
|
|
|
|
glEnable(This->light_num);
|
1999-01-03 18:00:19 +01:00
|
|
|
|
1999-03-27 17:56:13 +01:00
|
|
|
This->is_active = 1;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
1999-05-13 20:53:05 +02:00
|
|
|
LEAVE_GL();
|
1999-01-03 18:00:19 +01:00
|
|
|
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* Light Creation functions
|
|
|
|
*/
|
1999-03-27 17:56:13 +01:00
|
|
|
LPDIRECT3DLIGHT d3dlight_create(IDirect3D2Impl* d3d2)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
1999-03-27 17:56:13 +01:00
|
|
|
IDirect3DLightImpl* light;
|
1999-01-03 18:00:19 +01:00
|
|
|
|
1999-03-27 17:56:13 +01:00
|
|
|
light = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DLightImpl));
|
|
|
|
light->ref = 1;
|
1999-10-31 02:59:23 +01:00
|
|
|
ICOM_VTBL(light) = &light_vtable;
|
1999-03-27 17:56:13 +01:00
|
|
|
light->d3d.d3d2 = d3d2;
|
|
|
|
light->type = D3D_2;
|
|
|
|
|
|
|
|
light->next = NULL;
|
|
|
|
light->prev = NULL;
|
|
|
|
light->activate = activate;
|
|
|
|
light->is_active = 0;
|
1999-01-03 18:00:19 +01:00
|
|
|
|
1999-03-27 17:56:13 +01:00
|
|
|
return (LPDIRECT3DLIGHT)light;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
1999-03-27 17:56:13 +01:00
|
|
|
LPDIRECT3DLIGHT d3dlight_create_dx3(IDirect3DImpl* d3d1)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
1999-03-27 17:56:13 +01:00
|
|
|
IDirect3DLightImpl* light;
|
1999-01-03 18:00:19 +01:00
|
|
|
|
1999-03-27 17:56:13 +01:00
|
|
|
light = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DLightImpl));
|
|
|
|
light->ref = 1;
|
1999-10-31 02:59:23 +01:00
|
|
|
ICOM_VTBL(light) = &light_vtable;
|
1999-01-03 18:00:19 +01:00
|
|
|
|
1999-03-27 17:56:13 +01:00
|
|
|
light->d3d.d3d1 = d3d1;
|
|
|
|
light->type = D3D_1;
|
1999-01-03 18:00:19 +01:00
|
|
|
|
1999-03-27 17:56:13 +01:00
|
|
|
light->next = NULL;
|
|
|
|
light->prev = NULL;
|
|
|
|
light->activate = activate;
|
|
|
|
light->is_active = 0;
|
1999-01-03 18:00:19 +01:00
|
|
|
|
1999-03-27 17:56:13 +01:00
|
|
|
return (LPDIRECT3DLIGHT)light;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* IDirect3DLight methods
|
|
|
|
*/
|
|
|
|
|
1999-03-27 17:56:13 +01:00
|
|
|
static HRESULT WINAPI IDirect3DLightImpl_QueryInterface(LPDIRECT3DLIGHT iface,
|
1999-01-03 18:00:19 +01:00
|
|
|
REFIID riid,
|
|
|
|
LPVOID* ppvObj)
|
|
|
|
{
|
1999-03-27 17:56:13 +01:00
|
|
|
ICOM_THIS(IDirect3DLightImpl,iface);
|
1999-01-03 18:00:19 +01:00
|
|
|
|
2000-01-18 06:09:49 +01:00
|
|
|
FIXME("(%p)->(%s,%p): stub\n", This, debugstr_guid(riid),ppvObj);
|
1999-01-03 18:00:19 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-03-27 17:56:13 +01:00
|
|
|
static ULONG WINAPI IDirect3DLightImpl_AddRef(LPDIRECT3DLIGHT iface)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
1999-03-27 17:56:13 +01:00
|
|
|
ICOM_THIS(IDirect3DLightImpl,iface);
|
1999-06-26 21:09:08 +02:00
|
|
|
TRACE("(%p)->()incrementing from %lu.\n", This, This->ref );
|
1999-01-03 18:00:19 +01:00
|
|
|
|
1999-03-27 17:56:13 +01:00
|
|
|
return ++(This->ref);
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-03-27 17:56:13 +01:00
|
|
|
static ULONG WINAPI IDirect3DLightImpl_Release(LPDIRECT3DLIGHT iface)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
1999-03-27 17:56:13 +01:00
|
|
|
ICOM_THIS(IDirect3DLightImpl,iface);
|
1999-06-26 21:09:08 +02:00
|
|
|
FIXME("(%p)->() decrementing from %lu.\n", This, This->ref );
|
1999-01-03 18:00:19 +01:00
|
|
|
|
1999-03-27 17:56:13 +01:00
|
|
|
if (!--(This->ref)) {
|
|
|
|
HeapFree(GetProcessHeap(),0,This);
|
1999-01-03 18:00:19 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-03-27 17:56:13 +01:00
|
|
|
return This->ref;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*** IDirect3DLight methods ***/
|
|
|
|
static void dump_light(LPD3DLIGHT light)
|
|
|
|
{
|
|
|
|
fprintf(stderr, " dwSize : %ld\n", light->dwSize);
|
|
|
|
}
|
|
|
|
|
1999-03-27 17:56:13 +01:00
|
|
|
static HRESULT WINAPI IDirect3DLightImpl_GetLight(LPDIRECT3DLIGHT iface,
|
1999-01-03 18:00:19 +01:00
|
|
|
LPD3DLIGHT lpLight)
|
|
|
|
{
|
1999-03-27 17:56:13 +01:00
|
|
|
ICOM_THIS(IDirect3DLightImpl,iface);
|
1999-06-26 21:09:08 +02:00
|
|
|
TRACE("(%p)->(%p)\n", This, lpLight);
|
1999-01-03 18:00:19 +01:00
|
|
|
if (TRACE_ON(ddraw))
|
|
|
|
dump_light(lpLight);
|
|
|
|
|
|
|
|
/* Copies the light structure */
|
1999-03-27 17:56:13 +01:00
|
|
|
switch (This->type) {
|
1999-01-03 18:00:19 +01:00
|
|
|
case D3D_1:
|
1999-03-27 17:56:13 +01:00
|
|
|
*((LPD3DLIGHT)lpLight) = *((LPD3DLIGHT) &(This->light));
|
1999-01-03 18:00:19 +01:00
|
|
|
break;
|
|
|
|
case D3D_2:
|
1999-03-27 17:56:13 +01:00
|
|
|
*((LPD3DLIGHT2)lpLight) = *((LPD3DLIGHT2) &(This->light));
|
1999-01-03 18:00:19 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DD_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-27 17:56:13 +01:00
|
|
|
static HRESULT WINAPI IDirect3DLightImpl_SetLight(LPDIRECT3DLIGHT iface,
|
1999-01-03 18:00:19 +01:00
|
|
|
LPD3DLIGHT lpLight)
|
|
|
|
{
|
1999-03-27 17:56:13 +01:00
|
|
|
ICOM_THIS(IDirect3DLightImpl,iface);
|
1999-06-26 21:09:08 +02:00
|
|
|
TRACE("(%p)->(%p)\n", This, lpLight);
|
1999-01-03 18:00:19 +01:00
|
|
|
if (TRACE_ON(ddraw))
|
|
|
|
dump_light(lpLight);
|
|
|
|
|
|
|
|
/* Stores the light */
|
1999-03-27 17:56:13 +01:00
|
|
|
switch (This->type) {
|
1999-01-03 18:00:19 +01:00
|
|
|
case D3D_1:
|
1999-03-27 17:56:13 +01:00
|
|
|
*((LPD3DLIGHT) &(This->light)) = *((LPD3DLIGHT)lpLight);
|
1999-01-03 18:00:19 +01:00
|
|
|
break;
|
|
|
|
case D3D_2:
|
1999-03-27 17:56:13 +01:00
|
|
|
*((LPD3DLIGHT2) &(This->light)) = *((LPD3DLIGHT2)lpLight);
|
1999-01-03 18:00:19 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-05-13 20:53:05 +02:00
|
|
|
ENTER_GL();
|
1999-03-27 17:56:13 +01:00
|
|
|
if (This->is_active)
|
|
|
|
update(This);
|
1999-05-13 20:53:05 +02:00
|
|
|
LEAVE_GL();
|
1999-01-03 18:00:19 +01:00
|
|
|
|
|
|
|
return DD_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-27 17:56:13 +01:00
|
|
|
static HRESULT WINAPI IDirect3DLightImpl_Initialize(LPDIRECT3DLIGHT iface,
|
1999-01-03 18:00:19 +01:00
|
|
|
LPDIRECT3D lpDirect3D)
|
|
|
|
|
|
|
|
{
|
1999-03-27 17:56:13 +01:00
|
|
|
ICOM_THIS(IDirect3DLightImpl,iface);
|
1999-06-26 21:09:08 +02:00
|
|
|
TRACE("(%p)->(%p)\n", This, lpDirect3D);
|
1999-01-03 18:00:19 +01:00
|
|
|
|
|
|
|
return DDERR_ALREADYINITIALIZED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* IDirect3DLight VTable
|
|
|
|
*/
|
1999-05-22 13:41:38 +02:00
|
|
|
static ICOM_VTABLE(IDirect3DLight) light_vtable =
|
|
|
|
{
|
|
|
|
ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
1999-01-03 18:00:19 +01:00
|
|
|
/*** IUnknown methods ***/
|
1999-03-27 17:56:13 +01:00
|
|
|
IDirect3DLightImpl_QueryInterface,
|
|
|
|
IDirect3DLightImpl_AddRef,
|
|
|
|
IDirect3DLightImpl_Release,
|
1999-01-03 18:00:19 +01:00
|
|
|
/*** IDirect3DLight methods ***/
|
1999-03-27 17:56:13 +01:00
|
|
|
IDirect3DLightImpl_Initialize,
|
|
|
|
IDirect3DLightImpl_SetLight,
|
|
|
|
IDirect3DLightImpl_GetLight
|
1999-01-03 18:00:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#else /* HAVE_MESAGL */
|
|
|
|
|
|
|
|
/* These function should never be called if MesaGL is not present */
|
1999-03-27 17:56:13 +01:00
|
|
|
LPDIRECT3DLIGHT d3dlight_create_dx3(IDirect3DImpl* d3d1) {
|
1999-06-26 21:09:08 +02:00
|
|
|
ERR("Should not be called...\n");
|
1999-01-03 18:00:19 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1999-03-27 17:56:13 +01:00
|
|
|
LPDIRECT3DLIGHT d3dlight_create(IDirect3D2Impl* d3d2) {
|
1999-06-26 21:09:08 +02:00
|
|
|
ERR("Should not be called...\n");
|
1999-01-03 18:00:19 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_MESAGL */
|