-Fixed MESSAGE functions that were thunking down to 16 bits implementation.
[wine] / graphics / d3dviewport.c
1 /* Direct3D Viewport
2    (c) 1998 Lionel ULMER
3    
4    This files contains the implementation of Direct3DViewport2. */
5
6 #include "config.h"
7 #include "windows.h"
8 #include "wintypes.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"
15
16 #include "d3d_private.h"
17
18
19 #ifdef HAVE_MESAGL
20
21 static IDirect3DViewport2_VTable viewport2_vtable;
22
23 /*******************************************************************************
24  *                              Viewport1/2 static functions
25  */
26 static void activate(LPDIRECT3DVIEWPORT2 this) {
27   LPDIRECT3DLIGHT l;
28   
29   /* Activate all the lights associated with this context */
30   l = this->lights;
31
32   while (l != NULL) {
33     l->activate(l);
34     l = l->next;
35   }
36 }
37
38 /*******************************************************************************
39  *                              Viewport1/2 Creation functions
40  */
41 LPDIRECT3DVIEWPORT2 d3dviewport2_create(LPDIRECT3D2 d3d)
42 {
43   LPDIRECT3DVIEWPORT2 vp;
44   
45   vp = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DViewport2));
46   vp->ref = 1;
47   vp->lpvtbl = &viewport2_vtable;
48   vp->d3d.d3d2 = d3d;
49   vp->use_d3d2 = 1;
50
51   vp->device.active_device2 = NULL;
52   vp->activate = activate;
53
54   vp->lights = NULL;
55
56   vp->nextlight = GL_LIGHT0;
57   
58   return vp;
59 }
60
61 LPDIRECT3DVIEWPORT d3dviewport_create(LPDIRECT3D d3d)
62 {
63   LPDIRECT3DVIEWPORT2 vp;
64   
65   vp = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DViewport2));
66   vp->ref = 1;
67   vp->lpvtbl = &viewport2_vtable;
68   vp->d3d.d3d1 = d3d;
69   vp->use_d3d2 = 0;
70
71   vp->device.active_device1 = NULL;
72   vp->activate = activate;
73
74   vp->lights = NULL;
75
76   vp->nextlight = GL_LIGHT0;
77   
78   return (LPDIRECT3DVIEWPORT) vp;
79 }
80
81 /*******************************************************************************
82  *                              IDirect3DViewport2 methods
83  */
84
85 static HRESULT WINAPI IDirect3DViewport2_QueryInterface(LPDIRECT3DVIEWPORT2 this,
86                                                         REFIID riid,
87                                                         LPVOID* ppvObj)
88 {
89   char xrefiid[50];
90   
91   WINE_StringFromCLSID((LPCLSID)riid,xrefiid);
92   FIXME(ddraw, "(%p)->(%s,%p): stub\n", this, xrefiid,ppvObj);
93   
94   return S_OK;
95 }
96
97
98
99 static ULONG WINAPI IDirect3DViewport2_AddRef(LPDIRECT3DVIEWPORT2 this)
100 {
101   TRACE(ddraw, "(%p)->()incrementing from %lu.\n", this, this->ref );
102   
103   return ++(this->ref);
104 }
105
106
107
108 static ULONG WINAPI IDirect3DViewport2_Release(LPDIRECT3DVIEWPORT2 this)
109 {
110   FIXME( ddraw, "(%p)->() decrementing from %lu.\n", this, this->ref );
111   
112   if (!--(this->ref)) {
113     HeapFree(GetProcessHeap(),0,this);
114     return 0;
115   }
116   
117   return this->ref;
118 }
119
120 /*** IDirect3DViewport methods ***/
121 static HRESULT WINAPI IDirect3DViewport2_Initialize(LPDIRECT3DVIEWPORT2 this,
122                                                     LPDIRECT3D d3d)
123 {
124   FIXME(ddraw, "(%p)->(%p): stub\n", this, d3d);
125   
126   return DD_OK;
127 }
128
129 static HRESULT WINAPI IDirect3DViewport2_GetViewport(LPDIRECT3DVIEWPORT2 this,
130                                                      LPD3DVIEWPORT lpvp)
131 {
132   FIXME(ddraw, "(%p)->(%p): stub\n", this, lpvp);
133   
134   if (this->use_vp2 != 0)
135     return DDERR_INVALIDPARAMS;
136
137   *lpvp = this->viewport.vp1;
138   
139   return DD_OK;
140 }
141
142 static HRESULT WINAPI IDirect3DViewport2_SetViewport(LPDIRECT3DVIEWPORT2 this,
143                                                      LPD3DVIEWPORT lpvp)
144 {
145   FIXME(ddraw, "(%p)->(%p): stub\n", this, lpvp);
146
147   this->use_vp2 = 0;
148   this->viewport.vp1 = *lpvp;
149   
150   TRACE(ddraw, "dwSize = %ld   dwX = %ld   dwY = %ld\n",
151         lpvp->dwSize, lpvp->dwX, lpvp->dwY);
152   TRACE(ddraw, "dwWidth = %ld   dwHeight = %ld\n",
153         lpvp->dwWidth, lpvp->dwHeight);
154   TRACE(ddraw, "dvScaleX = %f   dvScaleY = %f\n",
155         lpvp->dvScaleX, lpvp->dvScaleY);
156   TRACE(ddraw, "dvMaxX = %f   dvMaxY = %f\n",
157         lpvp->dvMaxX, lpvp->dvMaxY);
158   TRACE(ddraw, "dvMinZ = %f   dvMaxZ = %f\n",
159         lpvp->dvMinZ, lpvp->dvMaxZ);
160
161   
162   return DD_OK;
163 }
164
165 static HRESULT WINAPI IDirect3DViewport2_TransformVertices(LPDIRECT3DVIEWPORT2 this,
166                                                            DWORD dwVertexCount,
167                                                            LPD3DTRANSFORMDATA lpData,
168                                                            DWORD dwFlags,
169                                                            LPDWORD lpOffScreen)
170 {
171   FIXME(ddraw, "(%p)->(%8ld,%p,%08lx,%p): stub\n",
172         this, dwVertexCount, lpData, dwFlags, lpOffScreen);
173   
174   return DD_OK;
175 }
176
177 static HRESULT WINAPI IDirect3DViewport2_LightElements(LPDIRECT3DVIEWPORT2 this,
178                                                        DWORD dwElementCount,
179                                                        LPD3DLIGHTDATA lpData)
180 {
181   FIXME(ddraw, "(%p)->(%8ld,%p): stub\n", this, dwElementCount, lpData);
182   
183   return DD_OK;
184 }
185
186 static HRESULT WINAPI IDirect3DViewport2_SetBackground(LPDIRECT3DVIEWPORT2 this,
187                                                        D3DMATERIALHANDLE hMat)
188 {
189   FIXME(ddraw, "(%p)->(%08lx): stub\n", this, (DWORD) hMat);
190   
191   return DD_OK;
192 }
193
194 static HRESULT WINAPI IDirect3DViewport2_GetBackground(LPDIRECT3DVIEWPORT2 this,
195                                                        LPD3DMATERIALHANDLE lphMat,
196                                                        LPBOOL lpValid)
197 {
198   FIXME(ddraw, "(%p)->(%p,%p): stub\n", this, lphMat, lpValid);
199   
200   return DD_OK;
201 }
202
203 static HRESULT WINAPI IDirect3DViewport2_SetBackgroundDepth(LPDIRECT3DVIEWPORT2 this,
204                                                             LPDIRECTDRAWSURFACE lpDDSurface)
205 {
206   FIXME(ddraw, "(%p)->(%p): stub\n", this, lpDDSurface);
207   
208   return DD_OK;
209 }
210
211 static HRESULT WINAPI IDirect3DViewport2_GetBackgroundDepth(LPDIRECT3DVIEWPORT2 this,
212                                                             LPDIRECTDRAWSURFACE* lplpDDSurface,
213                                                             LPBOOL lpValid)
214 {
215   FIXME(ddraw, "(%p)->(%p,%p): stub\n", this, lplpDDSurface, lpValid);
216   
217   return DD_OK;
218 }
219
220 static HRESULT WINAPI IDirect3DViewport2_Clear(LPDIRECT3DVIEWPORT2 this,
221                                                DWORD dwCount,
222                                                LPD3DRECT lpRects,
223                                                DWORD dwFlags)
224 {
225   GLboolean ztest;
226   FIXME(ddraw, "(%p)->(%8ld,%p,%08lx): stub\n", this, dwCount, lpRects, dwFlags);
227
228   /* For the moment, ignore the rectangles */
229   if (this->device.active_device1 != NULL) {
230     /* Get the rendering context */
231     if (this->use_d3d2)
232       this->device.active_device2->set_context(this->device.active_device2);
233     else
234       this->device.active_device1->set_context(this->device.active_device1);
235   }
236
237     /* Clears the screen */
238     glGetBooleanv(GL_DEPTH_TEST, &ztest);
239     glDepthMask(GL_TRUE); /* Enables Z writing to be sure to delete also the Z buffer */
240     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
241     glDepthMask(ztest);
242   
243   return DD_OK;
244 }
245
246 static HRESULT WINAPI IDirect3DViewport2_AddLight(LPDIRECT3DVIEWPORT2 this,
247                                                   LPDIRECT3DLIGHT lpLight)
248 {
249   FIXME(ddraw, "(%p)->(%p): stub\n", this, lpLight);
250
251   /* Add the light in the 'linked' chain */
252   lpLight->next = this->lights;
253   this->lights = lpLight;
254
255   /* If active, activate the light */
256   if (this->device.active_device1 != NULL) {
257     /* Get the rendering context */
258     if (this->use_d3d2)
259       this->device.active_device2->set_context(this->device.active_device2);
260     else
261       this->device.active_device1->set_context(this->device.active_device1);
262     
263     /* Activate the light */
264     lpLight->light_num = this->nextlight++;
265     lpLight->activate(lpLight);
266   }
267   
268   return DD_OK;
269 }
270
271 static HRESULT WINAPI IDirect3DViewport2_DeleteLight(LPDIRECT3DVIEWPORT2 this,
272                                                      LPDIRECT3DLIGHT lpLight)
273 {
274   FIXME(ddraw, "(%p)->(%p): stub\n", this, lpLight);
275   
276   return DD_OK;
277 }
278
279 static HRESULT WINAPI IDirect3DViewport2_NextLight(LPDIRECT3DVIEWPORT2 this,
280                                                    LPDIRECT3DLIGHT lpLight,
281                                                    LPDIRECT3DLIGHT* lplpLight,
282                                                    DWORD dwFlags)
283 {
284   FIXME(ddraw, "(%p)->(%p,%p,%08lx): stub\n", this, lpLight, lplpLight, dwFlags);
285   
286   return DD_OK;
287 }
288
289 /*** IDirect3DViewport2 methods ***/
290 static HRESULT WINAPI IDirect3DViewport2_GetViewport2(LPDIRECT3DVIEWPORT2 this,
291                                                       LPD3DVIEWPORT2 lpViewport2)
292 {
293   TRACE(ddraw, "(%p)->(%p)\n", this, lpViewport2);
294
295   if (this->use_vp2 != 1)
296     return DDERR_INVALIDPARAMS;
297
298   *lpViewport2 = this->viewport.vp2;
299   
300   return DD_OK;
301 }
302
303 static HRESULT WINAPI IDirect3DViewport2_SetViewport2(LPDIRECT3DVIEWPORT2 this,
304                                                       LPD3DVIEWPORT2 lpViewport2)
305 {
306   TRACE(ddraw, "(%p)->(%p)\n", this, lpViewport2);
307
308   TRACE(ddraw, "dwSize = %ld   dwX = %ld   dwY = %ld\n",
309         lpViewport2->dwSize, lpViewport2->dwX, lpViewport2->dwY);
310   TRACE(ddraw, "dwWidth = %ld   dwHeight = %ld\n",
311         lpViewport2->dwWidth, lpViewport2->dwHeight);
312   TRACE(ddraw, "dvClipX = %f   dvClipY = %f\n",
313         lpViewport2->dvClipX, lpViewport2->dvClipY);
314   TRACE(ddraw, "dvClipWidth = %f   dvClipHeight = %f\n",
315         lpViewport2->dvClipWidth, lpViewport2->dvClipHeight);
316   TRACE(ddraw, "dvMinZ = %f   dvMaxZ = %f\n",
317         lpViewport2->dvMinZ, lpViewport2->dvMaxZ);
318
319   this->viewport.vp2 = *lpViewport2;
320   this->use_vp2 = 1;
321   
322   return DD_OK;
323 }
324
325
326 /*******************************************************************************
327  *                              IDirect3DViewport1/2 VTable
328  */
329 static IDirect3DViewport2_VTable viewport2_vtable = {
330   /*** IUnknown methods ***/
331   IDirect3DViewport2_QueryInterface,
332   IDirect3DViewport2_AddRef,
333   IDirect3DViewport2_Release,
334   /*** IDirect3DViewport methods ***/
335   IDirect3DViewport2_Initialize,
336   IDirect3DViewport2_GetViewport,
337   IDirect3DViewport2_SetViewport,
338   IDirect3DViewport2_TransformVertices,
339   IDirect3DViewport2_LightElements,
340   IDirect3DViewport2_SetBackground,
341   IDirect3DViewport2_GetBackground,
342   IDirect3DViewport2_SetBackgroundDepth,
343   IDirect3DViewport2_GetBackgroundDepth,
344   IDirect3DViewport2_Clear,
345   IDirect3DViewport2_AddLight,
346   IDirect3DViewport2_DeleteLight,
347   IDirect3DViewport2_NextLight,
348   /*** IDirect3DViewport2 methods ***/
349   IDirect3DViewport2_GetViewport2,
350   IDirect3DViewport2_SetViewport2
351 };
352
353 #else /* HAVE_MESAGL */
354
355 LPDIRECT3DVIEWPORT d3dviewport_create(LPDIRECT3D d3d) {
356   ERR(ddraw, "Should not be called...\n");
357   return NULL;
358 }
359
360 LPDIRECT3DVIEWPORT2 d3dviewport2_create(LPDIRECT3D2 d3d) {
361   ERR(ddraw, "Should not be called...\n");
362   return NULL;
363 }
364
365 #endif /* HAVE_MESAGL */