Added new CLIENT_DebuggerRequest routine, implemented support for
[wine/wine-kai.git] / graphics / d3dlight.c
blobae9b3a07fccb001f7a19a777e4f4a10021aa0597
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 ICOM_VTABLE(IDirect3DLight) 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(IDirect3DLightImpl* 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(IDirect3DLightImpl* 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(IDirect3D2Impl* d3d2)
99 IDirect3DLightImpl* light;
101 light = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DLightImpl));
102 light->ref = 1;
103 light->lpvtbl = &light_vtable;
104 light->d3d.d3d2 = d3d2;
105 light->type = D3D_2;
107 light->next = NULL;
108 light->prev = NULL;
109 light->activate = activate;
110 light->is_active = 0;
112 return (LPDIRECT3DLIGHT)light;
115 LPDIRECT3DLIGHT d3dlight_create_dx3(IDirect3DImpl* d3d1)
117 IDirect3DLightImpl* light;
119 light = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DLightImpl));
120 light->ref = 1;
121 light->lpvtbl = &light_vtable;
123 light->d3d.d3d1 = d3d1;
124 light->type = D3D_1;
126 light->next = NULL;
127 light->prev = NULL;
128 light->activate = activate;
129 light->is_active = 0;
131 return (LPDIRECT3DLIGHT)light;
134 /*******************************************************************************
135 * IDirect3DLight methods
138 static HRESULT WINAPI IDirect3DLightImpl_QueryInterface(LPDIRECT3DLIGHT iface,
139 REFIID riid,
140 LPVOID* ppvObj)
142 ICOM_THIS(IDirect3DLightImpl,iface);
143 char xrefiid[50];
145 WINE_StringFromCLSID((LPCLSID)riid,xrefiid);
146 FIXME(ddraw, "(%p)->(%s,%p): stub\n", This, xrefiid,ppvObj);
148 return S_OK;
153 static ULONG WINAPI IDirect3DLightImpl_AddRef(LPDIRECT3DLIGHT iface)
155 ICOM_THIS(IDirect3DLightImpl,iface);
156 TRACE(ddraw, "(%p)->()incrementing from %lu.\n", This, This->ref );
158 return ++(This->ref);
163 static ULONG WINAPI IDirect3DLightImpl_Release(LPDIRECT3DLIGHT iface)
165 ICOM_THIS(IDirect3DLightImpl,iface);
166 FIXME( ddraw, "(%p)->() decrementing from %lu.\n", This, This->ref );
168 if (!--(This->ref)) {
169 HeapFree(GetProcessHeap(),0,This);
170 return 0;
173 return This->ref;
176 /*** IDirect3DLight methods ***/
177 static void dump_light(LPD3DLIGHT light)
179 fprintf(stderr, " dwSize : %ld\n", light->dwSize);
182 static HRESULT WINAPI IDirect3DLightImpl_GetLight(LPDIRECT3DLIGHT iface,
183 LPD3DLIGHT lpLight)
185 ICOM_THIS(IDirect3DLightImpl,iface);
186 TRACE(ddraw, "(%p)->(%p)\n", This, lpLight);
187 if (TRACE_ON(ddraw))
188 dump_light(lpLight);
190 /* Copies the light structure */
191 switch (This->type) {
192 case D3D_1:
193 *((LPD3DLIGHT)lpLight) = *((LPD3DLIGHT) &(This->light));
194 break;
195 case D3D_2:
196 *((LPD3DLIGHT2)lpLight) = *((LPD3DLIGHT2) &(This->light));
197 break;
200 return DD_OK;
203 static HRESULT WINAPI IDirect3DLightImpl_SetLight(LPDIRECT3DLIGHT iface,
204 LPD3DLIGHT lpLight)
206 ICOM_THIS(IDirect3DLightImpl,iface);
207 TRACE(ddraw, "(%p)->(%p)\n", This, lpLight);
208 if (TRACE_ON(ddraw))
209 dump_light(lpLight);
211 /* Stores the light */
212 switch (This->type) {
213 case D3D_1:
214 *((LPD3DLIGHT) &(This->light)) = *((LPD3DLIGHT)lpLight);
215 break;
216 case D3D_2:
217 *((LPD3DLIGHT2) &(This->light)) = *((LPD3DLIGHT2)lpLight);
218 break;
221 if (This->is_active)
222 update(This);
224 return DD_OK;
227 static HRESULT WINAPI IDirect3DLightImpl_Initialize(LPDIRECT3DLIGHT iface,
228 LPDIRECT3D lpDirect3D)
231 ICOM_THIS(IDirect3DLightImpl,iface);
232 TRACE(ddraw, "(%p)->(%p)\n", This, lpDirect3D);
234 return DDERR_ALREADYINITIALIZED;
238 /*******************************************************************************
239 * IDirect3DLight VTable
241 static ICOM_VTABLE(IDirect3DLight) light_vtable = {
242 /*** IUnknown methods ***/
243 IDirect3DLightImpl_QueryInterface,
244 IDirect3DLightImpl_AddRef,
245 IDirect3DLightImpl_Release,
246 /*** IDirect3DLight methods ***/
247 IDirect3DLightImpl_Initialize,
248 IDirect3DLightImpl_SetLight,
249 IDirect3DLightImpl_GetLight
252 #else /* HAVE_MESAGL */
254 /* These function should never be called if MesaGL is not present */
255 LPDIRECT3DLIGHT d3dlight_create_dx3(IDirect3DImpl* d3d1) {
256 ERR(ddraw, "Should not be called...\n");
257 return NULL;
260 LPDIRECT3DLIGHT d3dlight_create(IDirect3D2Impl* d3d2) {
261 ERR(ddraw, "Should not be called...\n");
262 return NULL;
265 #endif /* HAVE_MESAGL */