4 This files contains the implementation of Direct3DLight. */
11 #include "wine/obj_base.h"
17 #include "d3d_private.h"
21 static IDirect3DLight_VTable light_vtable;
28 /*******************************************************************************
29 * Light static functions
31 static const float zero_value[] = {
35 static void update(LPDIRECT3DLIGHT this) {
36 switch (this->light.dltType) {
37 case D3DLIGHT_POINT: /* 1 */
38 TRACE(ddraw, "Activating POINT\n");
41 case D3DLIGHT_SPOT: /* 2 */
42 TRACE(ddraw, "Activating SPOT\n");
45 case D3DLIGHT_DIRECTIONAL: { /* 3 */
48 TRACE(ddraw, "Activating DIRECTIONAL\n");
49 TRACE(ddraw, " direction : %f %f %f\n",
50 this->light.dvDirection.x.x,
51 this->light.dvDirection.y.y,
52 this->light.dvDirection.z.z);
53 _dump_colorvalue(" color ", this->light.dcvColor);
55 glLightfv(this->light_num,
57 (float *) zero_value);
59 glLightfv(this->light_num,
61 (float *) &(this->light.dcvColor));
63 direction[0] = -this->light.dvDirection.x.x;
64 direction[1] = -this->light.dvDirection.y.y;
65 direction[2] = -this->light.dvDirection.z.z;
66 direction[3] = 0.0; /* This is a directional light */
67 glLightfv(this->light_num,
72 case D3DLIGHT_PARALLELPOINT: /* 4 */
73 TRACE(ddraw, "Activating PARRALLEL-POINT\n");
77 TRACE(ddraw, "Not a know Light Type\n");
82 static void activate(LPDIRECT3DLIGHT this) {
85 /* If was not active, activate it */
86 if (this->is_active == 0) {
87 glEnable(this->light_num);
95 /*******************************************************************************
96 * Light Creation functions
98 LPDIRECT3DLIGHT d3dlight_create(LPDIRECT3D2 d3d)
102 mat = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DLight));
104 mat->lpvtbl = &light_vtable;
110 mat->activate = activate;
116 LPDIRECT3DLIGHT d3dlight_create_dx3(LPDIRECT3D d3d)
120 mat = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DLight));
122 mat->lpvtbl = &light_vtable;
129 mat->activate = activate;
135 /*******************************************************************************
136 * IDirect3DLight methods
139 static HRESULT WINAPI IDirect3DLight_QueryInterface(LPDIRECT3DLIGHT this,
145 WINE_StringFromCLSID((LPCLSID)riid,xrefiid);
146 FIXME(ddraw, "(%p)->(%s,%p): stub\n", this, xrefiid,ppvObj);
153 static ULONG WINAPI IDirect3DLight_AddRef(LPDIRECT3DLIGHT this)
155 TRACE(ddraw, "(%p)->()incrementing from %lu.\n", this, this->ref );
157 return ++(this->ref);
162 static ULONG WINAPI IDirect3DLight_Release(LPDIRECT3DLIGHT this)
164 FIXME( ddraw, "(%p)->() decrementing from %lu.\n", this, this->ref );
166 if (!--(this->ref)) {
167 HeapFree(GetProcessHeap(),0,this);
174 /*** IDirect3DLight methods ***/
175 static void dump_light(LPD3DLIGHT light)
177 fprintf(stderr, " dwSize : %ld\n", light->dwSize);
180 static HRESULT WINAPI IDirect3DLight_GetLight(LPDIRECT3DLIGHT this,
183 TRACE(ddraw, "(%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 IDirect3DLight_SetLight(LPDIRECT3DLIGHT this,
203 TRACE(ddraw, "(%p)->(%p)\n", this, lpLight);
207 /* Stores the light */
208 switch (this->type) {
210 *((LPD3DLIGHT) &(this->light)) = *((LPD3DLIGHT)lpLight);
213 *((LPD3DLIGHT2) &(this->light)) = *((LPD3DLIGHT2)lpLight);
223 static HRESULT WINAPI IDirect3DLight_Initialize(LPDIRECT3DLIGHT this,
224 LPDIRECT3D lpDirect3D)
227 TRACE(ddraw, "(%p)->(%p)\n", this, lpDirect3D);
229 return DDERR_ALREADYINITIALIZED;
233 /*******************************************************************************
234 * IDirect3DLight VTable
236 static IDirect3DLight_VTable light_vtable = {
237 /*** IUnknown methods ***/
238 IDirect3DLight_QueryInterface,
239 IDirect3DLight_AddRef,
240 IDirect3DLight_Release,
241 /*** IDirect3DLight methods ***/
242 IDirect3DLight_Initialize,
243 IDirect3DLight_SetLight,
244 IDirect3DLight_GetLight
247 #else /* HAVE_MESAGL */
249 /* These function should never be called if MesaGL is not present */
250 LPDIRECT3DLIGHT d3dlight_create_dx3(LPDIRECT3D d3d) {
251 ERR(ddraw, "Should not be called...\n");
255 LPDIRECT3DLIGHT d3dlight_create(LPDIRECT3D2 d3d) {
256 ERR(ddraw, "Should not be called...\n");
260 #endif /* HAVE_MESAGL */