4 This files contains the implementation of Direct3DLight. */
10 #include "wine/obj_base.h"
14 #include "debugtools.h"
16 #include "d3d_private.h"
18 DEFAULT_DEBUG_CHANNEL(ddraw
)
22 static ICOM_VTABLE(IDirect3DLight
) light_vtable
;
29 /*******************************************************************************
30 * Light static functions
32 static const float zero_value
[] = {
36 static void update(IDirect3DLightImpl
* This
) {
37 switch (This
->light
.dltType
) {
38 case D3DLIGHT_POINT
: /* 1 */
39 TRACE("Activating POINT\n");
42 case D3DLIGHT_SPOT
: /* 2 */
43 TRACE("Activating SPOT\n");
46 case D3DLIGHT_DIRECTIONAL
: { /* 3 */
49 TRACE("Activating DIRECTIONAL\n");
50 TRACE(" direction : %f %f %f\n",
51 This
->light
.dvDirection
.x
.x
,
52 This
->light
.dvDirection
.y
.y
,
53 This
->light
.dvDirection
.z
.z
);
54 _dump_colorvalue(" color ", This
->light
.dcvColor
);
56 glLightfv(This
->light_num
,
58 (float *) zero_value
);
60 glLightfv(This
->light_num
,
62 (float *) &(This
->light
.dcvColor
));
64 direction
[0] = -This
->light
.dvDirection
.x
.x
;
65 direction
[1] = -This
->light
.dvDirection
.y
.y
;
66 direction
[2] = -This
->light
.dvDirection
.z
.z
;
67 direction
[3] = 0.0; /* This is a directional light */
68 glLightfv(This
->light_num
,
73 case D3DLIGHT_PARALLELPOINT
: /* 4 */
74 TRACE("Activating PARRALLEL-POINT\n");
78 TRACE("Not a know Light Type\n");
83 static void activate(IDirect3DLightImpl
* This
) {
87 /* If was not active, activate it */
88 if (This
->is_active
== 0) {
89 glEnable(This
->light_num
);
98 /*******************************************************************************
99 * Light Creation functions
101 LPDIRECT3DLIGHT
d3dlight_create(IDirect3D2Impl
* d3d2
)
103 IDirect3DLightImpl
* light
;
105 light
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirect3DLightImpl
));
107 ICOM_VTBL(light
) = &light_vtable
;
108 light
->d3d
.d3d2
= d3d2
;
113 light
->activate
= activate
;
114 light
->is_active
= 0;
116 return (LPDIRECT3DLIGHT
)light
;
119 LPDIRECT3DLIGHT
d3dlight_create_dx3(IDirect3DImpl
* d3d1
)
121 IDirect3DLightImpl
* light
;
123 light
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirect3DLightImpl
));
125 ICOM_VTBL(light
) = &light_vtable
;
127 light
->d3d
.d3d1
= d3d1
;
132 light
->activate
= activate
;
133 light
->is_active
= 0;
135 return (LPDIRECT3DLIGHT
)light
;
138 /*******************************************************************************
139 * IDirect3DLight methods
142 static HRESULT WINAPI
IDirect3DLightImpl_QueryInterface(LPDIRECT3DLIGHT iface
,
146 ICOM_THIS(IDirect3DLightImpl
,iface
);
148 FIXME("(%p)->(%s,%p): stub\n", This
, debugstr_guid(riid
),ppvObj
);
155 static ULONG WINAPI
IDirect3DLightImpl_AddRef(LPDIRECT3DLIGHT iface
)
157 ICOM_THIS(IDirect3DLightImpl
,iface
);
158 TRACE("(%p)->()incrementing from %lu.\n", This
, This
->ref
);
160 return ++(This
->ref
);
165 static ULONG WINAPI
IDirect3DLightImpl_Release(LPDIRECT3DLIGHT iface
)
167 ICOM_THIS(IDirect3DLightImpl
,iface
);
168 FIXME("(%p)->() decrementing from %lu.\n", This
, This
->ref
);
170 if (!--(This
->ref
)) {
171 HeapFree(GetProcessHeap(),0,This
);
178 /*** IDirect3DLight methods ***/
179 static void dump_light(LPD3DLIGHT light
)
181 DPRINTF(" dwSize : %ld\n", light
->dwSize
);
184 static HRESULT WINAPI
IDirect3DLightImpl_GetLight(LPDIRECT3DLIGHT iface
,
187 ICOM_THIS(IDirect3DLightImpl
,iface
);
188 TRACE("(%p)->(%p)\n", This
, lpLight
);
192 /* Copies the light structure */
193 switch (This
->type
) {
195 *((LPD3DLIGHT
)lpLight
) = *((LPD3DLIGHT
) &(This
->light
));
198 *((LPD3DLIGHT2
)lpLight
) = *((LPD3DLIGHT2
) &(This
->light
));
205 static HRESULT WINAPI
IDirect3DLightImpl_SetLight(LPDIRECT3DLIGHT iface
,
208 ICOM_THIS(IDirect3DLightImpl
,iface
);
209 TRACE("(%p)->(%p)\n", This
, lpLight
);
213 /* Stores the light */
214 switch (This
->type
) {
216 *((LPD3DLIGHT
) &(This
->light
)) = *((LPD3DLIGHT
)lpLight
);
219 *((LPD3DLIGHT2
) &(This
->light
)) = *((LPD3DLIGHT2
)lpLight
);
231 static HRESULT WINAPI
IDirect3DLightImpl_Initialize(LPDIRECT3DLIGHT iface
,
232 LPDIRECT3D lpDirect3D
)
235 ICOM_THIS(IDirect3DLightImpl
,iface
);
236 TRACE("(%p)->(%p)\n", This
, lpDirect3D
);
238 return DDERR_ALREADYINITIALIZED
;
242 /*******************************************************************************
243 * IDirect3DLight VTable
245 static ICOM_VTABLE(IDirect3DLight
) light_vtable
=
247 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
248 /*** IUnknown methods ***/
249 IDirect3DLightImpl_QueryInterface
,
250 IDirect3DLightImpl_AddRef
,
251 IDirect3DLightImpl_Release
,
252 /*** IDirect3DLight methods ***/
253 IDirect3DLightImpl_Initialize
,
254 IDirect3DLightImpl_SetLight
,
255 IDirect3DLightImpl_GetLight
258 #else /* HAVE_MESAGL */
260 /* These function should never be called if MesaGL is not present */
261 LPDIRECT3DLIGHT
d3dlight_create_dx3(IDirect3DImpl
* d3d1
) {
262 ERR("Should not be called...\n");
266 LPDIRECT3DLIGHT
d3dlight_create(IDirect3D2Impl
* d3d2
) {
267 ERR("Should not be called...\n");
271 #endif /* HAVE_MESAGL */