Renamed wintypes.h to windef.h.
[wine/hacks.git] / graphics / d3dlight.c
blob7b19e252154d1ef406f546e768e7e3ee6dda960b
1 /* Direct3D Light
2 (c) 1998 Lionel ULMER
4 This files contains the implementation of Direct3DLight. */
7 #include "config.h"
8 #include "windef.h"
9 #include "winerror.h"
10 #include "wine/obj_base.h"
11 #include "heap.h"
12 #include "ddraw.h"
13 #include "d3d.h"
14 #include "debug.h"
16 #include "d3d_private.h"
18 #ifdef HAVE_MESAGL
20 static IDirect3DLight_VTable light_vtable;
22 enum {
23 D3D_1,
24 D3D_2
27 /*******************************************************************************
28 * Light static functions
30 static const float zero_value[] = {
31 0.0, 0.0, 0.0, 0.0
34 static void update(LPDIRECT3DLIGHT this) {
35 switch (this->light.dltType) {
36 case D3DLIGHT_POINT: /* 1 */
37 TRACE(ddraw, "Activating POINT\n");
38 break;
40 case D3DLIGHT_SPOT: /* 2 */
41 TRACE(ddraw, "Activating SPOT\n");
42 break;
44 case D3DLIGHT_DIRECTIONAL: { /* 3 */
45 float direction[4];
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,
55 GL_AMBIENT,
56 (float *) zero_value);
58 glLightfv(this->light_num,
59 GL_DIFFUSE,
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,
67 GL_POSITION,
68 (float *) direction);
69 } break;
71 case D3DLIGHT_PARALLELPOINT: /* 4 */
72 TRACE(ddraw, "Activating PARRALLEL-POINT\n");
73 break;
75 default:
76 TRACE(ddraw, "Not a know Light Type\n");
77 break;
81 static void activate(LPDIRECT3DLIGHT this) {
82 update(this);
84 /* If was not active, activate it */
85 if (this->is_active == 0) {
86 glEnable(this->light_num);
88 this->is_active = 1;
91 return ;
94 /*******************************************************************************
95 * Light Creation functions
97 LPDIRECT3DLIGHT d3dlight_create(LPDIRECT3D2 d3d)
99 LPDIRECT3DLIGHT mat;
101 mat = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DLight));
102 mat->ref = 1;
103 mat->lpvtbl = &light_vtable;
104 mat->d3d.d3d2 = d3d;
105 mat->type = D3D_2;
107 mat->next = NULL;
108 mat->prev = NULL;
109 mat->activate = activate;
110 mat->is_active = 0;
112 return mat;
115 LPDIRECT3DLIGHT d3dlight_create_dx3(LPDIRECT3D d3d)
117 LPDIRECT3DLIGHT mat;
119 mat = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DLight));
120 mat->ref = 1;
121 mat->lpvtbl = &light_vtable;
123 mat->d3d.d3d = d3d;
124 mat->type = D3D_1;
126 mat->next = NULL;
127 mat->prev = NULL;
128 mat->activate = activate;
129 mat->is_active = 0;
131 return mat;
134 /*******************************************************************************
135 * IDirect3DLight methods
138 static HRESULT WINAPI IDirect3DLight_QueryInterface(LPDIRECT3DLIGHT this,
139 REFIID riid,
140 LPVOID* ppvObj)
142 char xrefiid[50];
144 WINE_StringFromCLSID((LPCLSID)riid,xrefiid);
145 FIXME(ddraw, "(%p)->(%s,%p): stub\n", this, xrefiid,ppvObj);
147 return S_OK;
152 static ULONG WINAPI IDirect3DLight_AddRef(LPDIRECT3DLIGHT this)
154 TRACE(ddraw, "(%p)->()incrementing from %lu.\n", this, this->ref );
156 return ++(this->ref);
161 static ULONG WINAPI IDirect3DLight_Release(LPDIRECT3DLIGHT this)
163 FIXME( ddraw, "(%p)->() decrementing from %lu.\n", this, this->ref );
165 if (!--(this->ref)) {
166 HeapFree(GetProcessHeap(),0,this);
167 return 0;
170 return this->ref;
173 /*** IDirect3DLight methods ***/
174 static void dump_light(LPD3DLIGHT light)
176 fprintf(stderr, " dwSize : %ld\n", light->dwSize);
179 static HRESULT WINAPI IDirect3DLight_GetLight(LPDIRECT3DLIGHT this,
180 LPD3DLIGHT lpLight)
182 TRACE(ddraw, "(%p)->(%p)\n", this, lpLight);
183 if (TRACE_ON(ddraw))
184 dump_light(lpLight);
186 /* Copies the light structure */
187 switch (this->type) {
188 case D3D_1:
189 *((LPD3DLIGHT)lpLight) = *((LPD3DLIGHT) &(this->light));
190 break;
191 case D3D_2:
192 *((LPD3DLIGHT2)lpLight) = *((LPD3DLIGHT2) &(this->light));
193 break;
196 return DD_OK;
199 static HRESULT WINAPI IDirect3DLight_SetLight(LPDIRECT3DLIGHT this,
200 LPD3DLIGHT lpLight)
202 TRACE(ddraw, "(%p)->(%p)\n", this, lpLight);
203 if (TRACE_ON(ddraw))
204 dump_light(lpLight);
206 /* Stores the light */
207 switch (this->type) {
208 case D3D_1:
209 *((LPD3DLIGHT) &(this->light)) = *((LPD3DLIGHT)lpLight);
210 break;
211 case D3D_2:
212 *((LPD3DLIGHT2) &(this->light)) = *((LPD3DLIGHT2)lpLight);
213 break;
216 if (this->is_active)
217 update(this);
219 return DD_OK;
222 static HRESULT WINAPI IDirect3DLight_Initialize(LPDIRECT3DLIGHT this,
223 LPDIRECT3D lpDirect3D)
226 TRACE(ddraw, "(%p)->(%p)\n", this, lpDirect3D);
228 return DDERR_ALREADYINITIALIZED;
232 /*******************************************************************************
233 * IDirect3DLight VTable
235 static IDirect3DLight_VTable light_vtable = {
236 /*** IUnknown methods ***/
237 IDirect3DLight_QueryInterface,
238 IDirect3DLight_AddRef,
239 IDirect3DLight_Release,
240 /*** IDirect3DLight methods ***/
241 IDirect3DLight_Initialize,
242 IDirect3DLight_SetLight,
243 IDirect3DLight_GetLight
246 #else /* HAVE_MESAGL */
248 /* These function should never be called if MesaGL is not present */
249 LPDIRECT3DLIGHT d3dlight_create_dx3(LPDIRECT3D d3d) {
250 ERR(ddraw, "Should not be called...\n");
251 return NULL;
254 LPDIRECT3DLIGHT d3dlight_create(LPDIRECT3D2 d3d) {
255 ERR(ddraw, "Should not be called...\n");
256 return NULL;
259 #endif /* HAVE_MESAGL */