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