4 This files contains the implementation of Direct3DLight. */
10 #include "wine/obj_base.h"
14 #include "debugtools.h"
16 #include "mesa_private.h"
18 DEFAULT_DEBUG_CHANNEL(ddraw)
20 #define D3DLPRIVATE(x) mesa_d3dl_private*dlpriv=((mesa_d3dl_private*)x->private)
22 static ICOM_VTABLE(IDirect3DLight) light_vtable;
29 /*******************************************************************************
30 * Light static functions
32 static const float zero_value[] = {
36 static void update(IDirect3DLightImpl* This) {
38 switch (This->light.dltType) {
39 case D3DLIGHT_POINT: /* 1 */
40 TRACE("Activating POINT\n");
43 case D3DLIGHT_SPOT: /* 2 */
44 TRACE("Activating SPOT\n");
47 case D3DLIGHT_DIRECTIONAL: { /* 3 */
50 TRACE("Activating DIRECTIONAL\n");
51 TRACE(" direction : %f %f %f\n",
52 This->light.dvDirection.u1.x,
53 This->light.dvDirection.u2.y,
54 This->light.dvDirection.u3.z);
55 _dump_colorvalue(" color ", This->light.dcvColor);
57 glLightfv(dlpriv->light_num, GL_AMBIENT, (float *) zero_value);
58 glLightfv(dlpriv->light_num, GL_DIFFUSE, (float *) &(This->light.dcvColor));
60 direction[0] = -This->light.dvDirection.u1.x;
61 direction[1] = -This->light.dvDirection.u2.y;
62 direction[2] = -This->light.dvDirection.u3.z;
63 direction[3] = 0.0; /* This is a directional light */
65 glLightfv(dlpriv->light_num, GL_POSITION, (float *) direction);
68 case D3DLIGHT_PARALLELPOINT: /* 4 */
69 TRACE("Activating PARRALLEL-POINT\n");
73 TRACE("Not a known Light Type: %d\n",This->light.dltType);
78 static void activate(IDirect3DLightImpl* This) {
83 /* If was not active, activate it */
84 if (This->is_active == 0) {
85 glEnable(dlpriv->light_num);
93 /*******************************************************************************
94 * Light Creation functions
96 LPDIRECT3DLIGHT d3dlight_create(IDirect3D2Impl* d3d2)
98 IDirect3DLightImpl* light;
100 light = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DLightImpl));
102 ICOM_VTBL(light) = &light_vtable;
103 light->d3d.d3d2 = d3d2;
108 light->activate = activate;
109 light->is_active = 0;
111 return (LPDIRECT3DLIGHT)light;
114 LPDIRECT3DLIGHT d3dlight_create_dx3(IDirect3DImpl* d3d1)
116 IDirect3DLightImpl* light;
118 light = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DLightImpl));
120 ICOM_VTBL(light) = &light_vtable;
122 light->d3d.d3d1 = d3d1;
127 light->activate = activate;
128 light->is_active = 0;
130 return (LPDIRECT3DLIGHT)light;
133 /*******************************************************************************
134 * IDirect3DLight methods
137 static HRESULT WINAPI IDirect3DLightImpl_QueryInterface(LPDIRECT3DLIGHT iface,
141 ICOM_THIS(IDirect3DLightImpl,iface);
143 FIXME("(%p)->(%s,%p): stub\n", This, debugstr_guid(riid),ppvObj);
150 static ULONG WINAPI IDirect3DLightImpl_AddRef(LPDIRECT3DLIGHT iface)
152 ICOM_THIS(IDirect3DLightImpl,iface);
153 TRACE("(%p)->()incrementing from %lu.\n", This, This->ref );
155 return ++(This->ref);
160 static ULONG WINAPI IDirect3DLightImpl_Release(LPDIRECT3DLIGHT iface)
162 ICOM_THIS(IDirect3DLightImpl,iface);
163 FIXME("(%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 DPRINTF(" dwSize : %ld\n", light->dwSize);
179 static HRESULT WINAPI IDirect3DLightImpl_GetLight(LPDIRECT3DLIGHT iface,
182 ICOM_THIS(IDirect3DLightImpl,iface);
183 TRACE("(%p)->(%p)\n", This, lpLight);
187 /* Copies the light structure */
188 switch (This->type) {
190 *((LPD3DLIGHT)lpLight) = *((LPD3DLIGHT) &(This->light));
193 *((LPD3DLIGHT2)lpLight) = *((LPD3DLIGHT2) &(This->light));
200 static HRESULT WINAPI IDirect3DLightImpl_SetLight(LPDIRECT3DLIGHT iface,
203 ICOM_THIS(IDirect3DLightImpl,iface);
204 TRACE("(%p)->(%p)\n", This, lpLight);
208 /* Stores the light */
209 switch (This->type) {
211 *((LPD3DLIGHT) &(This->light)) = *((LPD3DLIGHT)lpLight);
214 *((LPD3DLIGHT2) &(This->light)) = *((LPD3DLIGHT2)lpLight);
226 static HRESULT WINAPI IDirect3DLightImpl_Initialize(LPDIRECT3DLIGHT iface,
227 LPDIRECT3D lpDirect3D)
230 ICOM_THIS(IDirect3DLightImpl,iface);
231 TRACE("(%p)->(%p)\n", This, lpDirect3D);
233 return DDERR_ALREADYINITIALIZED;
237 /*******************************************************************************
238 * IDirect3DLight VTable
240 static ICOM_VTABLE(IDirect3DLight) light_vtable =
242 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
243 /*** IUnknown methods ***/
244 IDirect3DLightImpl_QueryInterface,
245 IDirect3DLightImpl_AddRef,
246 IDirect3DLightImpl_Release,
247 /*** IDirect3DLight methods ***/
248 IDirect3DLightImpl_Initialize,
249 IDirect3DLightImpl_SetLight,
250 IDirect3DLightImpl_GetLight