4 This files contains the implementation of Direct3DLight. */
10 #include "wine/obj_base.h"
16 #include "d3d_private.h"
20 static IDirect3DLight_VTable light_vtable
;
27 /*******************************************************************************
28 * Light static functions
30 static const float zero_value
[] = {
34 static void update(LPDIRECT3DLIGHT
this) {
35 switch (this->light
.dltType
) {
36 case D3DLIGHT_POINT
: /* 1 */
37 TRACE(ddraw
, "Activating POINT\n");
40 case D3DLIGHT_SPOT
: /* 2 */
41 TRACE(ddraw
, "Activating SPOT\n");
44 case D3DLIGHT_DIRECTIONAL
: { /* 3 */
47 TRACE(ddraw
, "Activating DIRECTIONAL\n");
48 TRACE(ddraw
, " direction : %f %f %f\n",
49 this->light
.dvDirection
.x
.x
,
50 this->light
.dvDirection
.y
.y
,
51 this->light
.dvDirection
.z
.z
);
52 _dump_colorvalue(" color ", this->light
.dcvColor
);
54 glLightfv(this->light_num
,
56 (float *) zero_value
);
58 glLightfv(this->light_num
,
60 (float *) &(this->light
.dcvColor
));
62 direction
[0] = -this->light
.dvDirection
.x
.x
;
63 direction
[1] = -this->light
.dvDirection
.y
.y
;
64 direction
[2] = -this->light
.dvDirection
.z
.z
;
65 direction
[3] = 0.0; /* This is a directional light */
66 glLightfv(this->light_num
,
71 case D3DLIGHT_PARALLELPOINT
: /* 4 */
72 TRACE(ddraw
, "Activating PARRALLEL-POINT\n");
76 TRACE(ddraw
, "Not a know Light Type\n");
81 static void activate(LPDIRECT3DLIGHT
this) {
84 /* If was not active, activate it */
85 if (this->is_active
== 0) {
86 glEnable(this->light_num
);
94 /*******************************************************************************
95 * Light Creation functions
97 LPDIRECT3DLIGHT
d3dlight_create(LPDIRECT3D2 d3d
)
101 mat
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirect3DLight
));
103 mat
->lpvtbl
= &light_vtable
;
109 mat
->activate
= activate
;
115 LPDIRECT3DLIGHT
d3dlight_create_dx3(LPDIRECT3D d3d
)
119 mat
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirect3DLight
));
121 mat
->lpvtbl
= &light_vtable
;
128 mat
->activate
= activate
;
134 /*******************************************************************************
135 * IDirect3DLight methods
138 static HRESULT WINAPI
IDirect3DLight_QueryInterface(LPDIRECT3DLIGHT
this,
144 WINE_StringFromCLSID((LPCLSID
)riid
,xrefiid
);
145 FIXME(ddraw
, "(%p)->(%s,%p): stub\n", this, xrefiid
,ppvObj
);
152 static ULONG WINAPI
IDirect3DLight_AddRef(LPDIRECT3DLIGHT
this)
154 TRACE(ddraw
, "(%p)->()incrementing from %lu.\n", this, this->ref
);
156 return ++(this->ref
);
161 static ULONG WINAPI
IDirect3DLight_Release(LPDIRECT3DLIGHT
this)
163 FIXME( ddraw
, "(%p)->() decrementing from %lu.\n", this, this->ref
);
165 if (!--(this->ref
)) {
166 HeapFree(GetProcessHeap(),0,this);
173 /*** IDirect3DLight methods ***/
174 static void dump_light(LPD3DLIGHT light
)
176 fprintf(stderr
, " dwSize : %ld\n", light
->dwSize
);
179 static HRESULT WINAPI
IDirect3DLight_GetLight(LPDIRECT3DLIGHT
this,
182 TRACE(ddraw
, "(%p)->(%p)\n", this, lpLight
);
186 /* Copies the light structure */
187 switch (this->type
) {
189 *((LPD3DLIGHT
)lpLight
) = *((LPD3DLIGHT
) &(this->light
));
192 *((LPD3DLIGHT2
)lpLight
) = *((LPD3DLIGHT2
) &(this->light
));
199 static HRESULT WINAPI
IDirect3DLight_SetLight(LPDIRECT3DLIGHT
this,
202 TRACE(ddraw
, "(%p)->(%p)\n", this, lpLight
);
206 /* Stores the light */
207 switch (this->type
) {
209 *((LPD3DLIGHT
) &(this->light
)) = *((LPD3DLIGHT
)lpLight
);
212 *((LPD3DLIGHT2
) &(this->light
)) = *((LPD3DLIGHT2
)lpLight
);
222 static HRESULT WINAPI
IDirect3DLight_Initialize(LPDIRECT3DLIGHT
this,
223 LPDIRECT3D lpDirect3D
)
226 TRACE(ddraw
, "(%p)->(%p)\n", this, lpDirect3D
);
228 return DDERR_ALREADYINITIALIZED
;
232 /*******************************************************************************
233 * IDirect3DLight VTable
235 static IDirect3DLight_VTable light_vtable
= {
236 /*** IUnknown methods ***/
237 IDirect3DLight_QueryInterface
,
238 IDirect3DLight_AddRef
,
239 IDirect3DLight_Release
,
240 /*** IDirect3DLight methods ***/
241 IDirect3DLight_Initialize
,
242 IDirect3DLight_SetLight
,
243 IDirect3DLight_GetLight
246 #else /* HAVE_MESAGL */
248 /* These function should never be called if MesaGL is not present */
249 LPDIRECT3DLIGHT
d3dlight_create_dx3(LPDIRECT3D d3d
) {
250 ERR(ddraw
, "Should not be called...\n");
254 LPDIRECT3DLIGHT
d3dlight_create(LPDIRECT3D2 d3d
) {
255 ERR(ddraw
, "Should not be called...\n");
259 #endif /* HAVE_MESAGL */