- Implement URL_ESCAPE_SEGEMENT_ONLY, URL_ESCAPE_PERCENT,
[wine] / dlls / ddraw / d3dlight.c
1 /* Direct3D Light
2    (c) 1998 Lionel ULMER
3    
4    This files contains the implementation of Direct3DLight. */
5
6
7 #include "config.h"
8 #include "windef.h"
9 #include "winerror.h"
10 #include "wine/obj_base.h"
11 #include "ddraw.h"
12 #include "d3d.h"
13 #include "debugtools.h"
14
15 #include "mesa_private.h"
16
17 DEFAULT_DEBUG_CHANNEL(ddraw);
18     
19 #define D3DLPRIVATE(x) mesa_d3dl_private*dlpriv=((mesa_d3dl_private*)x->private)
20
21 static ICOM_VTABLE(IDirect3DLight) light_vtable;
22
23 enum {
24   D3D_1,
25   D3D_2
26 };
27
28 /*******************************************************************************
29  *                              Light static functions
30  */
31 static const float zero_value[] = {
32   0.0, 0.0, 0.0, 0.0
33 };
34
35 static void update(IDirect3DLightImpl* This) {
36   D3DLPRIVATE(This);
37   switch (This->light.dltType) {
38   case D3DLIGHT_POINT:         /* 1 */
39     TRACE("Activating POINT\n");
40     break;
41     
42   case D3DLIGHT_SPOT:          /* 2 */
43     TRACE("Activating SPOT\n");
44     break;
45     
46   case D3DLIGHT_DIRECTIONAL: {  /* 3 */
47     float direction[4];
48     
49     TRACE("Activating DIRECTIONAL\n");
50     TRACE("  direction : %f %f %f\n",
51           This->light.dvDirection.u1.x,
52           This->light.dvDirection.u2.y,
53           This->light.dvDirection.u3.z);
54     _dump_colorvalue(" color    ", This->light.dcvColor);
55
56     glLightfv(dlpriv->light_num, GL_AMBIENT, (float *) zero_value);
57     glLightfv(dlpriv->light_num, GL_DIFFUSE, (float *) &(This->light.dcvColor));
58
59     direction[0] = -This->light.dvDirection.u1.x;
60     direction[1] = -This->light.dvDirection.u2.y;
61     direction[2] = -This->light.dvDirection.u3.z;
62     direction[3] = 0.0; /* This is a directional light */
63
64     glLightfv(dlpriv->light_num, GL_POSITION, (float *) direction);
65   } break;
66     
67   case D3DLIGHT_PARALLELPOINT:  /* 4 */
68     TRACE("Activating PARRALLEL-POINT\n");
69     break;
70
71   default:
72     TRACE("Not a known Light Type: %d\n",This->light.dltType);
73     break;
74   }
75 }
76
77 static void activate(IDirect3DLightImpl* This) {
78   D3DLPRIVATE(This);
79
80   ENTER_GL();
81   update(This);
82   /* If was not active, activate it */
83   if (This->is_active == 0) {
84     glEnable(dlpriv->light_num);
85     This->is_active = 1;
86   }
87   LEAVE_GL();
88
89   return ;
90 }
91
92 /*******************************************************************************
93  *                              Light Creation functions
94  */
95 LPDIRECT3DLIGHT d3dlight_create(IDirect3D2Impl* d3d2)
96 {
97   IDirect3DLightImpl* light;
98   
99   light = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DLightImpl));
100   light->ref = 1;
101   ICOM_VTBL(light) = &light_vtable;
102   light->d3d.d3d2 = d3d2;
103   light->type = D3D_2;
104
105   light->next = NULL;
106   light->prev = NULL;
107   light->activate = activate;
108   light->is_active = 0;
109   
110   return (LPDIRECT3DLIGHT)light;
111 }
112
113 LPDIRECT3DLIGHT d3dlight_create_dx3(IDirect3DImpl* d3d1)
114 {
115   IDirect3DLightImpl* light;
116   
117   light = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DLightImpl));
118   light->ref = 1;
119   ICOM_VTBL(light) = &light_vtable;
120   
121   light->d3d.d3d1 = d3d1;
122   light->type = D3D_1;
123   
124   light->next = NULL;
125   light->prev = NULL;
126   light->activate = activate;
127   light->is_active = 0;
128   
129   return (LPDIRECT3DLIGHT)light;
130 }
131
132 /*******************************************************************************
133  *                              IDirect3DLight methods
134  */
135
136 static HRESULT WINAPI IDirect3DLightImpl_QueryInterface(LPDIRECT3DLIGHT iface,
137                                                     REFIID riid,
138                                                     LPVOID* ppvObj)
139 {
140   ICOM_THIS(IDirect3DLightImpl,iface);
141   
142   FIXME("(%p)->(%s,%p): stub\n", This, debugstr_guid(riid),ppvObj);
143   
144   return S_OK;
145 }
146
147
148
149 static ULONG WINAPI IDirect3DLightImpl_AddRef(LPDIRECT3DLIGHT iface)
150 {
151   ICOM_THIS(IDirect3DLightImpl,iface);
152   TRACE("(%p)->()incrementing from %lu.\n", This, This->ref );
153   
154   return ++(This->ref);
155 }
156
157
158
159 static ULONG WINAPI IDirect3DLightImpl_Release(LPDIRECT3DLIGHT iface)
160 {
161   ICOM_THIS(IDirect3DLightImpl,iface);
162   FIXME("(%p)->() decrementing from %lu.\n", This, This->ref );
163   
164   if (!--(This->ref)) {
165     HeapFree(GetProcessHeap(),0,This);
166     return 0;
167   }
168   
169   return This->ref;
170 }
171
172 /*** IDirect3DLight methods ***/
173 static void dump_light(LPD3DLIGHT light)
174 {
175   DPRINTF("  dwSize : %ld\n", light->dwSize);
176 }
177
178 static HRESULT WINAPI IDirect3DLightImpl_GetLight(LPDIRECT3DLIGHT iface,
179                                               LPD3DLIGHT lpLight)
180 {
181   ICOM_THIS(IDirect3DLightImpl,iface);
182   TRACE("(%p)->(%p)\n", This, lpLight);
183   if (TRACE_ON(ddraw))
184     dump_light(lpLight);
185   
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;
194   }
195   
196   return DD_OK;
197 }
198
199 static HRESULT WINAPI IDirect3DLightImpl_SetLight(LPDIRECT3DLIGHT iface,
200                                               LPD3DLIGHT lpLight)
201 {
202   ICOM_THIS(IDirect3DLightImpl,iface);
203   TRACE("(%p)->(%p)\n", This, lpLight);
204   if (TRACE_ON(ddraw))
205     dump_light(lpLight);
206   
207   /* Stores the light */
208   switch (This->type) {
209   case D3D_1:
210     *((LPD3DLIGHT) &(This->light)) = *((LPD3DLIGHT)lpLight);
211     break;
212   case D3D_2:
213     *((LPD3DLIGHT2) &(This->light)) = *((LPD3DLIGHT2)lpLight);
214     break;
215   }
216   
217   ENTER_GL();
218   if (This->is_active)
219     update(This);
220   LEAVE_GL();
221   
222   return DD_OK;
223 }
224
225 static HRESULT WINAPI IDirect3DLightImpl_Initialize(LPDIRECT3DLIGHT iface,
226                                                 LPDIRECT3D lpDirect3D)
227
228 {
229   ICOM_THIS(IDirect3DLightImpl,iface);
230   TRACE("(%p)->(%p)\n", This, lpDirect3D);
231
232   return DDERR_ALREADYINITIALIZED;
233 }
234
235
236 /*******************************************************************************
237  *                              IDirect3DLight VTable
238  */
239 static ICOM_VTABLE(IDirect3DLight) light_vtable = 
240 {
241   ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
242   /*** IUnknown methods ***/
243   IDirect3DLightImpl_QueryInterface,
244   IDirect3DLightImpl_AddRef,
245   IDirect3DLightImpl_Release,
246   /*** IDirect3DLight methods ***/
247   IDirect3DLightImpl_Initialize,
248   IDirect3DLightImpl_SetLight,
249   IDirect3DLightImpl_GetLight
250 };