Allow configuration of output devices to use and change standard
[wine] / dlls / ddraw / d3dviewport.c
1 /* Direct3D Viewport
2  * Copyright (c) 1998 Lionel ULMER
3  *
4  * This file contains the implementation of Direct3DViewport2.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22
23 #include <stdarg.h>
24
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winerror.h"
30 #include "objbase.h"
31 #include "wingdi.h"
32 #include "ddraw.h"
33 #include "d3d.h"
34 #include "wine/debug.h"
35
36 #include "d3d_private.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
39
40 static void activate(IDirect3DViewportImpl* This) {
41     IDirect3DLightImpl* light;
42     D3DVIEWPORT7 vp;
43     
44     /* Activate all the lights associated with this context */
45     light = This->lights;
46
47     while (light != NULL) {
48         light->activate(light);
49         light = light->next;
50     }
51
52     /* And copy the values in the structure used by the device */
53     if (This->use_vp2) {
54         vp.dwX = This->viewports.vp2.dwX;
55         vp.dwY = This->viewports.vp2.dwY;
56         vp.dwHeight = This->viewports.vp2.dwHeight;
57         vp.dwWidth = This->viewports.vp2.dwWidth;
58         vp.dvMinZ = This->viewports.vp2.dvMinZ;
59         vp.dvMaxZ = This->viewports.vp2.dvMaxZ;
60     } else {
61         vp.dwX = This->viewports.vp1.dwX;
62         vp.dwY = This->viewports.vp1.dwY;
63         vp.dwHeight = This->viewports.vp1.dwHeight;
64         vp.dwWidth = This->viewports.vp1.dwWidth;
65         vp.dvMinZ = This->viewports.vp1.dvMinZ;
66         vp.dvMaxZ = This->viewports.vp1.dvMaxZ;
67     }
68     
69     /* And also set the viewport */
70     IDirect3DDevice7_SetViewport(ICOM_INTERFACE(This->active_device, IDirect3DDevice7), &vp);
71 }
72
73
74 static void _dump_D3DVIEWPORT(D3DVIEWPORT *lpvp)
75 {
76     TRACE("    - dwSize = %ld   dwX = %ld   dwY = %ld\n",
77           lpvp->dwSize, lpvp->dwX, lpvp->dwY);
78     TRACE("    - dwWidth = %ld   dwHeight = %ld\n",
79           lpvp->dwWidth, lpvp->dwHeight);
80     TRACE("    - dvScaleX = %f   dvScaleY = %f\n",
81           lpvp->dvScaleX, lpvp->dvScaleY);
82     TRACE("    - dvMaxX = %f   dvMaxY = %f\n",
83           lpvp->dvMaxX, lpvp->dvMaxY);
84     TRACE("    - dvMinZ = %f   dvMaxZ = %f\n",
85           lpvp->dvMinZ, lpvp->dvMaxZ);
86 }
87
88 static void _dump_D3DVIEWPORT2(D3DVIEWPORT2 *lpvp)
89 {
90     TRACE("    - dwSize = %ld   dwX = %ld   dwY = %ld\n",
91           lpvp->dwSize, lpvp->dwX, lpvp->dwY);
92     TRACE("    - dwWidth = %ld   dwHeight = %ld\n",
93           lpvp->dwWidth, lpvp->dwHeight);
94     TRACE("    - dvClipX = %f   dvClipY = %f\n",
95           lpvp->dvClipX, lpvp->dvClipY);
96     TRACE("    - dvClipWidth = %f   dvClipHeight = %f\n",
97           lpvp->dvClipWidth, lpvp->dvClipHeight);
98     TRACE("    - dvMinZ = %f   dvMaxZ = %f\n",
99           lpvp->dvMinZ, lpvp->dvMaxZ);
100 }
101
102 HRESULT WINAPI
103 Main_IDirect3DViewportImpl_3_2_1_QueryInterface(LPDIRECT3DVIEWPORT3 iface,
104                                                 REFIID riid,
105                                                 LPVOID* obp)
106 {
107     ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
108     TRACE("(%p/%p)->(%s,%p)\n", This, iface, debugstr_guid(riid), obp);
109
110     *obp = NULL;
111
112     if ( IsEqualGUID(&IID_IUnknown,  riid) ||
113          IsEqualGUID(&IID_IDirect3DViewport, riid) ||
114          IsEqualGUID(&IID_IDirect3DViewport2, riid) ||
115          IsEqualGUID(&IID_IDirect3DViewport3, riid) ) {
116         IDirect3DViewport3_AddRef(ICOM_INTERFACE(This, IDirect3DViewport3));
117         *obp = ICOM_INTERFACE(This, IDirect3DViewport3);
118         TRACE("  Creating IDirect3DViewport1/2/3 interface %p\n", *obp);
119         return S_OK;
120     }
121     FIXME("(%p): interface for IID %s NOT found!\n", This, debugstr_guid(riid));
122     return OLE_E_ENUM_NOMORE;
123 }
124
125 ULONG WINAPI
126 Main_IDirect3DViewportImpl_3_2_1_AddRef(LPDIRECT3DVIEWPORT3 iface)
127 {
128     ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
129     TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, This->ref);
130     return ++(This->ref);
131 }
132
133 ULONG WINAPI
134 Main_IDirect3DViewportImpl_3_2_1_Release(LPDIRECT3DVIEWPORT3 iface)
135 {
136     ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
137     TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, This->ref);
138     if (!--(This->ref)) {
139         HeapFree(GetProcessHeap(), 0, This);
140         return 0;
141     }
142     return This->ref;
143 }
144
145
146 HRESULT WINAPI
147 Main_IDirect3DViewportImpl_3_2_1_Initialize(LPDIRECT3DVIEWPORT3 iface,
148                                             LPDIRECT3D lpDirect3D)
149 {
150     ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
151     TRACE("(%p/%p)->(%p) no-op...\n", This, iface, lpDirect3D);
152     return DD_OK;
153 }
154
155 HRESULT WINAPI
156 Main_IDirect3DViewportImpl_3_2_1_GetViewport(LPDIRECT3DVIEWPORT3 iface,
157                                              LPD3DVIEWPORT lpData)
158 {
159     ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
160     DWORD dwSize;
161     TRACE("(%p/%p)->(%p)\n", This, iface, lpData);
162     if (This->use_vp2 != 0) {
163         ERR("  Requesting to get a D3DVIEWPORT struct where a D3DVIEWPORT2 was set !\n");
164         return DDERR_INVALIDPARAMS;
165     }
166     dwSize = lpData->dwSize;
167     memset(lpData, 0, dwSize);
168     memcpy(lpData, &(This->viewports.vp1), dwSize);
169
170     if (TRACE_ON(ddraw)) {
171         TRACE("  returning D3DVIEWPORT :\n");
172         _dump_D3DVIEWPORT(lpData);
173     }
174     
175     return DD_OK;
176 }
177
178 HRESULT WINAPI
179 Main_IDirect3DViewportImpl_3_2_1_SetViewport(LPDIRECT3DVIEWPORT3 iface,
180                                              LPD3DVIEWPORT lpData)
181 {
182     ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
183     LPDIRECT3DVIEWPORT3 current_viewport;
184     TRACE("(%p/%p)->(%p)\n", This, iface, lpData);
185
186     if (TRACE_ON(ddraw)) {
187         TRACE("  getting D3DVIEWPORT :\n");
188         _dump_D3DVIEWPORT(lpData);
189     }
190
191     This->use_vp2 = 0;
192     memset(&(This->viewports.vp1), 0, sizeof(This->viewports.vp1));
193     memcpy(&(This->viewports.vp1), lpData, lpData->dwSize);
194
195     /* Tests on two games shows that these values are never used properly so overide
196        them with proper ones :-)
197     */
198     This->viewports.vp1.dvMinZ = 0.0;
199     This->viewports.vp1.dvMaxZ = 1.0;
200
201     if (This->active_device) {
202       IDirect3DDevice3_GetCurrentViewport(ICOM_INTERFACE(This->active_device, IDirect3DDevice3), &current_viewport);
203       if (ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, current_viewport) == This)
204           This->activate(This);
205       IDirect3DViewport3_Release(current_viewport);
206     }
207
208     return DD_OK;
209 }
210
211 HRESULT WINAPI
212 Main_IDirect3DViewportImpl_3_2_1_TransformVertices(LPDIRECT3DVIEWPORT3 iface,
213                                                    DWORD dwVertexCount,
214                                                    LPD3DTRANSFORMDATA lpData,
215                                                    DWORD dwFlags,
216                                                    LPDWORD lpOffScreen)
217 {
218     ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
219     FIXME("(%p/%p)->(%08lx,%p,%08lx,%p): stub!\n", This, iface, dwVertexCount, lpData, dwFlags, lpOffScreen);
220     return DD_OK;
221 }
222
223 HRESULT WINAPI
224 Main_IDirect3DViewportImpl_3_2_1_LightElements(LPDIRECT3DVIEWPORT3 iface,
225                                                DWORD dwElementCount,
226                                                LPD3DLIGHTDATA lpData)
227 {
228     ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
229     FIXME("(%p/%p)->(%08lx,%p): stub!\n", This, iface, dwElementCount, lpData);
230     return DD_OK;
231 }
232
233 HRESULT WINAPI
234 Main_IDirect3DViewportImpl_3_2_1_SetBackground(LPDIRECT3DVIEWPORT3 iface,
235                                                D3DMATERIALHANDLE hMat)
236 {
237     ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
238     TRACE("(%p/%p)->(%08lx)\n", This, iface, (DWORD) hMat);
239     
240     This->background = (IDirect3DMaterialImpl *) hMat;
241     TRACE(" setting background color : %f %f %f %f\n",
242           This->background->mat.u.diffuse.u1.r,
243           This->background->mat.u.diffuse.u2.g,
244           This->background->mat.u.diffuse.u3.b,
245           This->background->mat.u.diffuse.u4.a);
246
247     return DD_OK;
248 }
249
250 HRESULT WINAPI
251 Main_IDirect3DViewportImpl_3_2_1_GetBackground(LPDIRECT3DVIEWPORT3 iface,
252                                                LPD3DMATERIALHANDLE lphMat,
253                                                LPBOOL lpValid)
254 {
255     ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
256     FIXME("(%p/%p)->(%p,%p): stub!\n", This, iface, lphMat, lpValid);
257     return DD_OK;
258 }
259
260 HRESULT WINAPI
261 Main_IDirect3DViewportImpl_3_2_1_SetBackgroundDepth(LPDIRECT3DVIEWPORT3 iface,
262                                                     LPDIRECTDRAWSURFACE lpDDSurface)
263 {
264     ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
265     FIXME("(%p/%p)->(%p): stub!\n", This, iface, lpDDSurface);
266     return DD_OK;
267 }
268
269 HRESULT WINAPI
270 Main_IDirect3DViewportImpl_3_2_1_GetBackgroundDepth(LPDIRECT3DVIEWPORT3 iface,
271                                                     LPDIRECTDRAWSURFACE* lplpDDSurface,
272                                                     LPBOOL lpValid)
273 {
274     ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
275     FIXME("(%p/%p)->(%p,%p): stub!\n", This, iface, lplpDDSurface, lpValid);
276     return DD_OK;
277 }
278
279 HRESULT WINAPI
280 Main_IDirect3DViewportImpl_3_2_1_Clear(LPDIRECT3DVIEWPORT3 iface,
281                                        DWORD dwCount,
282                                        LPD3DRECT lpRects,
283                                        DWORD dwFlags)
284 {
285     ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
286     DWORD color = 0x00000000;
287     
288     TRACE("(%p/%p)->(%08lx,%p,%08lx)\n", This, iface, dwCount, lpRects, dwFlags);
289     if (This->active_device == NULL) {
290         ERR(" Trying to clear a viewport not attached to a device !\n");
291         return D3DERR_VIEWPORTHASNODEVICE;
292     }
293     if (dwFlags & D3DCLEAR_TARGET) {
294         if (This->background == NULL) {
295             ERR(" Trying to clear the color buffer without background material !\n");
296         } else {
297             color = 
298               ((int) ((This->background->mat.u.diffuse.u1.r) * 255) << 16) |
299               ((int) ((This->background->mat.u.diffuse.u2.g) * 255) <<  8) |
300               ((int) ((This->background->mat.u.diffuse.u3.b) * 255) <<  0) |
301               ((int) ((This->background->mat.u.diffuse.u4.a) * 255) << 24);
302         }
303     }
304     return This->active_device->clear(This->active_device, dwCount, lpRects, 
305                                       dwFlags & (D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET),
306                                       color, 1.0, 0x00000000);
307 }
308
309 HRESULT WINAPI
310 Main_IDirect3DViewportImpl_3_2_1_AddLight(LPDIRECT3DVIEWPORT3 iface,
311                                           LPDIRECT3DLIGHT lpDirect3DLight)
312 {
313     ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
314     IDirect3DLightImpl *lpDirect3DLightImpl = ICOM_OBJECT(IDirect3DLightImpl, IDirect3DLight, lpDirect3DLight);
315     DWORD i = 0;
316     DWORD map = This->map_lights;
317     
318     TRACE("(%p/%p)->(%p)\n", This, iface, lpDirect3DLight);
319     
320     if (This->num_lights >= 8)
321         return DDERR_INVALIDPARAMS;
322
323     /* Find a light number and update both light and viewports objects accordingly */
324     while(map&1) {
325         map>>=1;
326         i++;
327     }
328     lpDirect3DLightImpl->dwLightIndex = i;
329     This->num_lights++;
330     This->map_lights |= 1<<i;
331
332     /* Add the light in the 'linked' chain */
333     lpDirect3DLightImpl->next = This->lights;
334     This->lights = lpDirect3DLightImpl;
335
336     /* Attach the light to the viewport */
337     lpDirect3DLightImpl->active_viewport = This;
338     
339     /* If active, activate the light */
340     if (This->active_device != NULL) {
341         lpDirect3DLightImpl->activate(lpDirect3DLightImpl);
342     }
343     
344     return DD_OK;
345 }
346
347 HRESULT WINAPI
348 Main_IDirect3DViewportImpl_3_2_1_DeleteLight(LPDIRECT3DVIEWPORT3 iface,
349                                              LPDIRECT3DLIGHT lpDirect3DLight)
350 {
351     ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
352     IDirect3DLightImpl *lpDirect3DLightImpl = ICOM_OBJECT(IDirect3DLightImpl, IDirect3DLight, lpDirect3DLight);
353     IDirect3DLightImpl *cur_light, *prev_light = NULL;
354     
355     TRACE("(%p/%p)->(%p)\n", This, iface, lpDirect3DLight);
356     cur_light = This->lights;
357     while (cur_light != NULL) {
358         if (cur_light == lpDirect3DLightImpl) {
359             lpDirect3DLightImpl->desactivate(lpDirect3DLightImpl);
360             if (prev_light == NULL) This->lights = cur_light->next;
361             else prev_light->next = cur_light->next;
362             /* Detach the light to the viewport */
363             cur_light->active_viewport = NULL;
364             This->num_lights--;
365             This->map_lights &= ~(1<<lpDirect3DLightImpl->dwLightIndex);
366             return DD_OK;
367         }
368         prev_light = cur_light;
369         cur_light = cur_light->next;
370     }
371     return DDERR_INVALIDPARAMS;
372 }
373
374 HRESULT WINAPI
375 Main_IDirect3DViewportImpl_3_2_1_NextLight(LPDIRECT3DVIEWPORT3 iface,
376                                            LPDIRECT3DLIGHT lpDirect3DLight,
377                                            LPDIRECT3DLIGHT* lplpDirect3DLight,
378                                            DWORD dwFlags)
379 {
380     ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
381     FIXME("(%p/%p)->(%p,%p,%08lx): stub!\n", This, iface, lpDirect3DLight, lplpDirect3DLight, dwFlags);
382     return DD_OK;
383 }
384
385 HRESULT WINAPI
386 Main_IDirect3DViewportImpl_3_2_GetViewport2(LPDIRECT3DVIEWPORT3 iface,
387                                             LPD3DVIEWPORT2 lpData)
388 {
389     ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
390     DWORD dwSize;
391     TRACE("(%p/%p)->(%p)\n", This, iface, lpData);
392     if (This->use_vp2 != 1) {
393         ERR("  Requesting to get a D3DVIEWPORT2 struct where a D3DVIEWPORT was set !\n");
394         return DDERR_INVALIDPARAMS;
395     }
396     dwSize = lpData->dwSize;
397     memset(lpData, 0, dwSize);
398     memcpy(lpData, &(This->viewports.vp2), dwSize);
399
400     if (TRACE_ON(ddraw)) {
401         TRACE("  returning D3DVIEWPORT2 :\n");
402         _dump_D3DVIEWPORT2(lpData);
403     }
404     
405     return DD_OK;
406 }
407
408 HRESULT WINAPI
409 Main_IDirect3DViewportImpl_3_2_SetViewport2(LPDIRECT3DVIEWPORT3 iface,
410                                             LPD3DVIEWPORT2 lpData)
411 {
412     ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
413     LPDIRECT3DVIEWPORT3 current_viewport;
414     TRACE("(%p/%p)->(%p)\n", This, iface, lpData);
415
416     if (TRACE_ON(ddraw)) {
417         TRACE("  getting D3DVIEWPORT2 :\n");
418         _dump_D3DVIEWPORT2(lpData);
419     }
420
421     This->use_vp2 = 1;
422     memset(&(This->viewports.vp2), 0, sizeof(This->viewports.vp2));
423     memcpy(&(This->viewports.vp2), lpData, lpData->dwSize);
424
425     if (This->active_device) {
426       IDirect3DDevice3_GetCurrentViewport(ICOM_INTERFACE(This->active_device, IDirect3DDevice3), &current_viewport);
427       if (ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, current_viewport) == This)
428         This->activate(This);
429       IDirect3DViewport3_Release(current_viewport);
430     }
431
432     return DD_OK;
433 }
434
435 HRESULT WINAPI
436 Main_IDirect3DViewportImpl_3_SetBackgroundDepth2(LPDIRECT3DVIEWPORT3 iface,
437                                                  LPDIRECTDRAWSURFACE4 lpDDS)
438 {
439     ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
440     FIXME("(%p/%p)->(%p): stub!\n", This, iface, lpDDS);
441     return DD_OK;
442 }
443
444 HRESULT WINAPI
445 Main_IDirect3DViewportImpl_3_GetBackgroundDepth2(LPDIRECT3DVIEWPORT3 iface,
446                                                  LPDIRECTDRAWSURFACE4* lplpDDS,
447                                                  LPBOOL lpValid)
448 {
449     ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
450     FIXME("(%p/%p)->(%p,%p): stub!\n", This, iface, lplpDDS, lpValid);
451     return DD_OK;
452 }
453
454 HRESULT WINAPI
455 Main_IDirect3DViewportImpl_3_Clear2(LPDIRECT3DVIEWPORT3 iface,
456                                     DWORD dwCount,
457                                     LPD3DRECT lpRects,
458                                     DWORD dwFlags,
459                                     DWORD dwColor,
460                                     D3DVALUE dvZ,
461                                     DWORD dwStencil)
462 {
463     ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
464     TRACE("(%p/%p)->(%08lx,%p,%08lx,%08lx,%f,%08lx)\n", This, iface, dwCount, lpRects, dwFlags, dwColor, dvZ, dwStencil);
465     if (This->active_device == NULL) {
466         ERR(" Trying to clear a viewport not attached to a device !\n");
467         return D3DERR_VIEWPORTHASNODEVICE;
468     }
469     return This->active_device->clear(This->active_device, dwCount, lpRects, dwFlags, dwColor, dvZ, dwStencil);
470 }
471
472 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
473 # define XCAST(fun)     (typeof(VTABLE_IDirect3DViewport3.fun))
474 #else
475 # define XCAST(fun)     (void*)
476 #endif
477
478 ICOM_VTABLE(IDirect3DViewport3) VTABLE_IDirect3DViewport3 =
479 {
480     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
481     XCAST(QueryInterface) Main_IDirect3DViewportImpl_3_2_1_QueryInterface,
482     XCAST(AddRef) Main_IDirect3DViewportImpl_3_2_1_AddRef,
483     XCAST(Release) Main_IDirect3DViewportImpl_3_2_1_Release,
484     XCAST(Initialize) Main_IDirect3DViewportImpl_3_2_1_Initialize,
485     XCAST(GetViewport) Main_IDirect3DViewportImpl_3_2_1_GetViewport,
486     XCAST(SetViewport) Main_IDirect3DViewportImpl_3_2_1_SetViewport,
487     XCAST(TransformVertices) Main_IDirect3DViewportImpl_3_2_1_TransformVertices,
488     XCAST(LightElements) Main_IDirect3DViewportImpl_3_2_1_LightElements,
489     XCAST(SetBackground) Main_IDirect3DViewportImpl_3_2_1_SetBackground,
490     XCAST(GetBackground) Main_IDirect3DViewportImpl_3_2_1_GetBackground,
491     XCAST(SetBackgroundDepth) Main_IDirect3DViewportImpl_3_2_1_SetBackgroundDepth,
492     XCAST(GetBackgroundDepth) Main_IDirect3DViewportImpl_3_2_1_GetBackgroundDepth,
493     XCAST(Clear) Main_IDirect3DViewportImpl_3_2_1_Clear,
494     XCAST(AddLight) Main_IDirect3DViewportImpl_3_2_1_AddLight,
495     XCAST(DeleteLight) Main_IDirect3DViewportImpl_3_2_1_DeleteLight,
496     XCAST(NextLight) Main_IDirect3DViewportImpl_3_2_1_NextLight,
497     XCAST(GetViewport2) Main_IDirect3DViewportImpl_3_2_GetViewport2,
498     XCAST(SetViewport2) Main_IDirect3DViewportImpl_3_2_SetViewport2,
499     XCAST(SetBackgroundDepth2) Main_IDirect3DViewportImpl_3_SetBackgroundDepth2,
500     XCAST(GetBackgroundDepth2) Main_IDirect3DViewportImpl_3_GetBackgroundDepth2,
501     XCAST(Clear2) Main_IDirect3DViewportImpl_3_Clear2,
502 };
503
504 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
505 #undef XCAST
506 #endif
507
508
509
510
511 HRESULT d3dviewport_create(IDirect3DViewportImpl **obj, IDirectDrawImpl *d3d)
512 {
513     IDirect3DViewportImpl *object;
514
515     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DViewportImpl));
516     if (object == NULL) return DDERR_OUTOFMEMORY;
517
518     object->ref = 1;
519     object->d3d = d3d;
520     object->activate = activate;
521     object->use_vp2 = 0xFF;
522     object->next = NULL;
523     object->lights = NULL;
524     object->num_lights = 0;
525     object->map_lights = 0;
526     
527     ICOM_INIT_INTERFACE(object, IDirect3DViewport3, VTABLE_IDirect3DViewport3);
528
529     *obj = object;
530
531     TRACE(" creating implementation at %p.\n", *obj);
532     
533     return D3D_OK;
534 }