-Fixed MESSAGE functions that were thunking down to 16 bits implementation.
[wine] / graphics / 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 "windows.h"
9 #include "wintypes.h"
10 #include "winerror.h"
11 #include "wine/obj_base.h"
12 #include "heap.h"
13 #include "ddraw.h"
14 #include "d3d.h"
15 #include "debug.h"
16
17 #include "d3d_private.h"
18
19 #ifdef HAVE_MESAGL
20
21 static IDirect3DLight_VTable 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(LPDIRECT3DLIGHT this) {
36   switch (this->light.dltType) {
37   case D3DLIGHT_POINT:         /* 1 */
38     TRACE(ddraw, "Activating POINT\n");
39     break;
40     
41   case D3DLIGHT_SPOT:          /* 2 */
42     TRACE(ddraw, "Activating SPOT\n");
43     break;
44     
45   case D3DLIGHT_DIRECTIONAL: {  /* 3 */
46     float direction[4];
47     
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);
54
55     glLightfv(this->light_num,
56               GL_AMBIENT,
57               (float *) zero_value);
58
59     glLightfv(this->light_num,
60               GL_DIFFUSE,
61               (float *) &(this->light.dcvColor));
62
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,
68               GL_POSITION,
69               (float *) direction);
70   } break;
71     
72   case D3DLIGHT_PARALLELPOINT:  /* 4 */
73     TRACE(ddraw, "Activating PARRALLEL-POINT\n");
74     break;
75
76   default:
77     TRACE(ddraw, "Not a know Light Type\n");
78     break;
79   }
80 }
81
82 static void activate(LPDIRECT3DLIGHT this) {
83   update(this);
84
85   /* If was not active, activate it */
86   if (this->is_active == 0) {
87     glEnable(this->light_num);
88
89     this->is_active = 1;
90   }
91
92   return ;
93 }
94
95 /*******************************************************************************
96  *                              Light Creation functions
97  */
98 LPDIRECT3DLIGHT d3dlight_create(LPDIRECT3D2 d3d)
99 {
100   LPDIRECT3DLIGHT mat;
101   
102   mat = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DLight));
103   mat->ref = 1;
104   mat->lpvtbl = &light_vtable;
105   mat->d3d.d3d2 = d3d;
106   mat->type = D3D_2;
107
108   mat->next = NULL;
109   mat->prev = NULL;
110   mat->activate = activate;
111   mat->is_active = 0;
112   
113   return mat;
114 }
115
116 LPDIRECT3DLIGHT d3dlight_create_dx3(LPDIRECT3D d3d)
117 {
118   LPDIRECT3DLIGHT mat;
119   
120   mat = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DLight));
121   mat->ref = 1;
122   mat->lpvtbl = &light_vtable;
123   
124   mat->d3d.d3d = d3d;
125   mat->type = D3D_1;
126   
127   mat->next = NULL;
128   mat->prev = NULL;
129   mat->activate = activate;
130   mat->is_active = 0;
131   
132   return mat;
133 }
134
135 /*******************************************************************************
136  *                              IDirect3DLight methods
137  */
138
139 static HRESULT WINAPI IDirect3DLight_QueryInterface(LPDIRECT3DLIGHT this,
140                                                     REFIID riid,
141                                                     LPVOID* ppvObj)
142 {
143   char xrefiid[50];
144   
145   WINE_StringFromCLSID((LPCLSID)riid,xrefiid);
146   FIXME(ddraw, "(%p)->(%s,%p): stub\n", this, xrefiid,ppvObj);
147   
148   return S_OK;
149 }
150
151
152
153 static ULONG WINAPI IDirect3DLight_AddRef(LPDIRECT3DLIGHT this)
154 {
155   TRACE(ddraw, "(%p)->()incrementing from %lu.\n", this, this->ref );
156   
157   return ++(this->ref);
158 }
159
160
161
162 static ULONG WINAPI IDirect3DLight_Release(LPDIRECT3DLIGHT this)
163 {
164   FIXME( ddraw, "(%p)->() decrementing from %lu.\n", this, this->ref );
165   
166   if (!--(this->ref)) {
167     HeapFree(GetProcessHeap(),0,this);
168     return 0;
169   }
170   
171   return this->ref;
172 }
173
174 /*** IDirect3DLight methods ***/
175 static void dump_light(LPD3DLIGHT light)
176 {
177   fprintf(stderr, "  dwSize : %ld\n", light->dwSize);
178 }
179
180 static HRESULT WINAPI IDirect3DLight_GetLight(LPDIRECT3DLIGHT this,
181                                               LPD3DLIGHT lpLight)
182 {
183   TRACE(ddraw, "(%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 IDirect3DLight_SetLight(LPDIRECT3DLIGHT this,
201                                               LPD3DLIGHT lpLight)
202 {
203   TRACE(ddraw, "(%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   if (this->is_active)
218     update(this);
219   
220   return DD_OK;
221 }
222
223 static HRESULT WINAPI IDirect3DLight_Initialize(LPDIRECT3DLIGHT this,
224                                                 LPDIRECT3D lpDirect3D)
225
226 {
227   TRACE(ddraw, "(%p)->(%p)\n", this, lpDirect3D);
228
229   return DDERR_ALREADYINITIALIZED;
230 }
231
232
233 /*******************************************************************************
234  *                              IDirect3DLight VTable
235  */
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
245 };
246
247 #else /* HAVE_MESAGL */
248
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");
252   return NULL;
253 }
254
255 LPDIRECT3DLIGHT d3dlight_create(LPDIRECT3D2 d3d) {
256   ERR(ddraw, "Should not be called...\n");
257   return NULL;
258 }
259
260 #endif /* HAVE_MESAGL */