4 This files contains the implementation of Direct3DLight. */
10 #include "wine/obj_base.h"
16 #include "d3d_private.h"
20 static ICOM_VTABLE(IDirect3DLight
) light_vtable
;
27 /*******************************************************************************
28 * Light static functions
30 static const float zero_value
[] = {
34 static void update(IDirect3DLightImpl
* 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(IDirect3DLightImpl
* 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(IDirect3D2Impl
* d3d2
)
99 IDirect3DLightImpl
* light
;
101 light
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirect3DLightImpl
));
103 light
->lpvtbl
= &light_vtable
;
104 light
->d3d
.d3d2
= d3d2
;
109 light
->activate
= activate
;
110 light
->is_active
= 0;
112 return (LPDIRECT3DLIGHT
)light
;
115 LPDIRECT3DLIGHT
d3dlight_create_dx3(IDirect3DImpl
* d3d1
)
117 IDirect3DLightImpl
* light
;
119 light
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirect3DLightImpl
));
121 light
->lpvtbl
= &light_vtable
;
123 light
->d3d
.d3d1
= d3d1
;
128 light
->activate
= activate
;
129 light
->is_active
= 0;
131 return (LPDIRECT3DLIGHT
)light
;
134 /*******************************************************************************
135 * IDirect3DLight methods
138 static HRESULT WINAPI
IDirect3DLightImpl_QueryInterface(LPDIRECT3DLIGHT iface
,
142 ICOM_THIS(IDirect3DLightImpl
,iface
);
145 WINE_StringFromCLSID((LPCLSID
)riid
,xrefiid
);
146 FIXME(ddraw
, "(%p)->(%s,%p): stub\n", This
, xrefiid
,ppvObj
);
153 static ULONG WINAPI
IDirect3DLightImpl_AddRef(LPDIRECT3DLIGHT iface
)
155 ICOM_THIS(IDirect3DLightImpl
,iface
);
156 TRACE(ddraw
, "(%p)->()incrementing from %lu.\n", This
, This
->ref
);
158 return ++(This
->ref
);
163 static ULONG WINAPI
IDirect3DLightImpl_Release(LPDIRECT3DLIGHT iface
)
165 ICOM_THIS(IDirect3DLightImpl
,iface
);
166 FIXME( ddraw
, "(%p)->() decrementing from %lu.\n", This
, This
->ref
);
168 if (!--(This
->ref
)) {
169 HeapFree(GetProcessHeap(),0,This
);
176 /*** IDirect3DLight methods ***/
177 static void dump_light(LPD3DLIGHT light
)
179 fprintf(stderr
, " dwSize : %ld\n", light
->dwSize
);
182 static HRESULT WINAPI
IDirect3DLightImpl_GetLight(LPDIRECT3DLIGHT iface
,
185 ICOM_THIS(IDirect3DLightImpl
,iface
);
186 TRACE(ddraw
, "(%p)->(%p)\n", This
, lpLight
);
190 /* Copies the light structure */
191 switch (This
->type
) {
193 *((LPD3DLIGHT
)lpLight
) = *((LPD3DLIGHT
) &(This
->light
));
196 *((LPD3DLIGHT2
)lpLight
) = *((LPD3DLIGHT2
) &(This
->light
));
203 static HRESULT WINAPI
IDirect3DLightImpl_SetLight(LPDIRECT3DLIGHT iface
,
206 ICOM_THIS(IDirect3DLightImpl
,iface
);
207 TRACE(ddraw
, "(%p)->(%p)\n", This
, lpLight
);
211 /* Stores the light */
212 switch (This
->type
) {
214 *((LPD3DLIGHT
) &(This
->light
)) = *((LPD3DLIGHT
)lpLight
);
217 *((LPD3DLIGHT2
) &(This
->light
)) = *((LPD3DLIGHT2
)lpLight
);
227 static HRESULT WINAPI
IDirect3DLightImpl_Initialize(LPDIRECT3DLIGHT iface
,
228 LPDIRECT3D lpDirect3D
)
231 ICOM_THIS(IDirect3DLightImpl
,iface
);
232 TRACE(ddraw
, "(%p)->(%p)\n", This
, lpDirect3D
);
234 return DDERR_ALREADYINITIALIZED
;
238 /*******************************************************************************
239 * IDirect3DLight VTable
241 static ICOM_VTABLE(IDirect3DLight
) light_vtable
= {
242 /*** IUnknown methods ***/
243 IDirect3DLightImpl_QueryInterface
,
244 IDirect3DLightImpl_AddRef
,
245 IDirect3DLightImpl_Release
,
246 /*** IDirect3DLight methods ***/
247 IDirect3DLightImpl_Initialize
,
248 IDirect3DLightImpl_SetLight
,
249 IDirect3DLightImpl_GetLight
252 #else /* HAVE_MESAGL */
254 /* These function should never be called if MesaGL is not present */
255 LPDIRECT3DLIGHT
d3dlight_create_dx3(IDirect3DImpl
* d3d1
) {
256 ERR(ddraw
, "Should not be called...\n");
260 LPDIRECT3DLIGHT
d3dlight_create(IDirect3D2Impl
* d3d2
) {
261 ERR(ddraw
, "Should not be called...\n");
265 #endif /* HAVE_MESAGL */