4 This files contains the implementation of Direct3DLight. */
11 #include "wine/obj_base.h"
18 #include "d3d_private.h"
22 static IDirect3DLight_VTable light_vtable;
29 /*******************************************************************************
30 * Light static functions
32 static const float zero_value[] = {
36 static void update(LPDIRECT3DLIGHT this) {
37 switch (this->light.dltType) {
38 case D3DLIGHT_POINT: /* 1 */
39 TRACE(ddraw, "Activating POINT\n");
42 case D3DLIGHT_SPOT: /* 2 */
43 TRACE(ddraw, "Activating SPOT\n");
46 case D3DLIGHT_DIRECTIONAL: { /* 3 */
49 TRACE(ddraw, "Activating DIRECTIONAL\n");
50 TRACE(ddraw, " 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(ddraw, "Activating PARRALLEL-POINT\n");
78 TRACE(ddraw, "Not a know Light Type\n");
83 static void activate(LPDIRECT3DLIGHT this) {
86 /* If was not active, activate it */
87 if (this->is_active == 0) {
88 glEnable(this->light_num);
96 /*******************************************************************************
97 * Light Creation functions
99 LPDIRECT3DLIGHT d3dlight_create(LPDIRECT3D2 d3d)
103 mat = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DLight));
105 mat->lpvtbl = &light_vtable;
111 mat->activate = activate;
117 LPDIRECT3DLIGHT d3dlight_create_dx3(LPDIRECT3D d3d)
121 mat = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DLight));
123 mat->lpvtbl = &light_vtable;
130 mat->activate = activate;
136 /*******************************************************************************
137 * IDirect3DLight methods
140 static HRESULT WINAPI IDirect3DLight_QueryInterface(LPDIRECT3DLIGHT this,
146 WINE_StringFromCLSID((LPCLSID)riid,xrefiid);
147 FIXME(ddraw, "(%p)->(%s,%p): stub\n", this, xrefiid,ppvObj);
154 static ULONG WINAPI IDirect3DLight_AddRef(LPDIRECT3DLIGHT this)
156 TRACE(ddraw, "(%p)->()incrementing from %lu.\n", this, this->ref );
158 return ++(this->ref);
163 static ULONG WINAPI IDirect3DLight_Release(LPDIRECT3DLIGHT this)
165 FIXME( ddraw, "(%p)->() decrementing from %lu.\n", this, this->ref );
167 if (!--(this->ref)) {
168 HeapFree(GetProcessHeap(),0,this);
175 /*** IDirect3DLight methods ***/
176 static void dump_light(LPD3DLIGHT light)
178 fprintf(stderr, " dwSize : %ld\n", light->dwSize);
181 static HRESULT WINAPI IDirect3DLight_GetLight(LPDIRECT3DLIGHT this,
184 TRACE(ddraw, "(%p)->(%p)\n", this, lpLight);
188 /* Copies the light structure */
189 switch (this->type) {
191 *((LPD3DLIGHT)lpLight) = *((LPD3DLIGHT) &(this->light));
194 *((LPD3DLIGHT2)lpLight) = *((LPD3DLIGHT2) &(this->light));
201 static HRESULT WINAPI IDirect3DLight_SetLight(LPDIRECT3DLIGHT this,
204 TRACE(ddraw, "(%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);
224 static HRESULT WINAPI IDirect3DLight_Initialize(LPDIRECT3DLIGHT this,
225 LPDIRECT3D lpDirect3D)
228 TRACE(ddraw, "(%p)->(%p)\n", this, lpDirect3D);
230 return DDERR_ALREADYINITIALIZED;
234 /*******************************************************************************
235 * IDirect3DLight VTable
237 static IDirect3DLight_VTable light_vtable = {
238 /*** IUnknown methods ***/
239 IDirect3DLight_QueryInterface,
240 IDirect3DLight_AddRef,
241 IDirect3DLight_Release,
242 /*** IDirect3DLight methods ***/
243 IDirect3DLight_Initialize,
244 IDirect3DLight_SetLight,
245 IDirect3DLight_GetLight
248 #else /* HAVE_MESAGL */
250 /* These function should never be called if MesaGL is not present */
251 LPDIRECT3DLIGHT d3dlight_create_dx3(LPDIRECT3D d3d) {
252 ERR(ddraw, "Should not be called...\n");
256 LPDIRECT3DLIGHT d3dlight_create(LPDIRECT3D2 d3d) {
257 ERR(ddraw, "Should not be called...\n");
261 #endif /* HAVE_MESAGL */