2 * Copyright (c) 2006 Stefan Dösinger
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "wine/port.h"
21 #include "wine/debug.h"
35 #include "wine/exception.h"
41 #include "ddraw_private.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(d3d7);
45 /*****************************************************************************
46 * IUnknown Methods. Common for Version 1, 2, 3 and 7
48 * These are thunks which relay to IDirectDraw. See ddraw.c for
51 *****************************************************************************/
53 Thunk_IDirect3DImpl_7_QueryInterface(IDirect3D7 *iface,
57 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
58 TRACE("(%p)->(%s,%p): Thunking to IDirectDraw7\n", This, debugstr_guid(refiid), obj);
60 return IDirectDraw7_QueryInterface(ICOM_INTERFACE(This, IDirectDraw7),
66 Thunk_IDirect3DImpl_3_QueryInterface(IDirect3D3 *iface,
70 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
71 TRACE("(%p)->(%s,%p): Thunking to IDirectDraw7\n", This, debugstr_guid(refiid), obj);
73 return IDirectDraw7_QueryInterface(ICOM_INTERFACE(This, IDirectDraw7),
79 Thunk_IDirect3DImpl_2_QueryInterface(IDirect3D2 *iface,
83 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
84 TRACE("(%p)->(%s,%p): Thunking to IDirectDraw7\n", This, debugstr_guid(refiid), obj);
86 return IDirectDraw7_QueryInterface(ICOM_INTERFACE(This, IDirectDraw7),
92 Thunk_IDirect3DImpl_1_QueryInterface(IDirect3D *iface,
96 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
97 TRACE("(%p)->(%s,%p): Thunking to IDirectDraw7\n", This, debugstr_guid(refiid), obj);
99 return IDirectDraw7_QueryInterface(ICOM_INTERFACE(This, IDirectDraw7),
105 Thunk_IDirect3DImpl_7_AddRef(IDirect3D7 *iface)
107 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
108 TRACE("(%p) : Thunking to IDirectDraw7\n", This);
110 return IDirectDraw7_AddRef(ICOM_INTERFACE(This, IDirectDraw7));
114 Thunk_IDirect3DImpl_3_AddRef(IDirect3D3 *iface)
116 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
117 TRACE("(%p) : Thunking to IDirectDraw7\n", This);
119 return IDirectDraw7_AddRef(ICOM_INTERFACE(This, IDirectDraw7));
123 Thunk_IDirect3DImpl_2_AddRef(IDirect3D2 *iface)
125 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
126 TRACE("(%p) : Thunking to IDirectDraw7\n", This);
128 return IDirectDraw7_AddRef(ICOM_INTERFACE(This, IDirectDraw7));
132 Thunk_IDirect3DImpl_1_AddRef(IDirect3D *iface)
134 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
135 TRACE("(%p) : Thunking to IDirectDraw7\n", This);
137 return IDirectDraw7_AddRef(ICOM_INTERFACE(This, IDirectDraw7));
141 Thunk_IDirect3DImpl_7_Release(IDirect3D7 *iface)
143 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
144 TRACE("(%p) : Thunking to IDirectDraw7", This);
146 return IDirectDraw7_Release(ICOM_INTERFACE(This, IDirectDraw7));
150 Thunk_IDirect3DImpl_3_Release(IDirect3D3 *iface)
152 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
153 TRACE("(%p) : Thunking to IDirectDraw7", This);
155 return IDirectDraw7_Release(ICOM_INTERFACE(This, IDirectDraw7));
159 Thunk_IDirect3DImpl_2_Release(IDirect3D2 *iface)
161 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
162 TRACE("(%p) : Thunking to IDirectDraw7", This);
164 return IDirectDraw7_Release(ICOM_INTERFACE(This, IDirectDraw7));
168 Thunk_IDirect3DImpl_1_Release(IDirect3D *iface)
170 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
171 TRACE("(%p) : Thunking to IDirectDraw7", This);
173 return IDirectDraw7_Release(ICOM_INTERFACE(This, IDirectDraw7));
176 /*****************************************************************************
178 *****************************************************************************/
180 /*****************************************************************************
181 * IDirect3D::Initialize
183 * Initializes the IDirect3D interface. This is a no-op implementation,
184 * as all initialization is done at create time.
192 * D3D_OK, because it's a no-op
194 *****************************************************************************/
195 static HRESULT WINAPI
196 IDirect3DImpl_1_Initialize(IDirect3D *iface,
199 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
201 TRACE("(%p)->(%s) no-op...\n", This, debugstr_guid(refiid));
205 /*****************************************************************************
206 * IDirect3D7::EnumDevices
208 * The EnumDevices method for IDirect3D7. It enumerates all supported
209 * D3D7 devices. Currently there's only one.
212 * Callback: Function to call for each enumerated device
213 * Context: Pointer to pass back to the app
216 * D3D_OK, or the return value of the GetCaps call
218 *****************************************************************************/
219 static HRESULT WINAPI
220 IDirect3DImpl_7_EnumDevices(IDirect3D7 *iface,
221 LPD3DENUMDEVICESCALLBACK7 Callback,
224 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
225 char interface_name[] = "WINE Direct3D7 using WineD3D";
226 char device_name[] = "Wine D3D7 device";
227 D3DDEVICEDESC7 ddesc;
228 D3DDEVICEDESC oldDesc;
231 TRACE("(%p)->(%p,%p)\n", This, Callback, Context);
233 TRACE("(%p) Enumerating WineD3D D3Device7 interface\n", This);
234 hr = IDirect3DImpl_GetCaps(This->wineD3D, &oldDesc, &ddesc);
235 if(hr != D3D_OK) return hr;
236 Callback(interface_name, device_name, &ddesc, Context);
238 TRACE("(%p) End of enumeration\n", This);
242 /*****************************************************************************
243 * IDirect3D3::EnumDevices
245 * Enumerates all supported Direct3DDevice interfaces. This is the
246 * implementation for Direct3D 1 to Direc3D 3, Version 7 has its own.
251 * Callback: Application-provided routine to call for each enumerated device
252 * Context: Pointer to pass to the callback
256 * The result of IDirect3DImpl_GetCaps if it failed
258 *****************************************************************************/
259 static HRESULT WINAPI
260 IDirect3DImpl_3_EnumDevices(IDirect3D3 *iface,
261 LPD3DENUMDEVICESCALLBACK Callback,
264 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
265 D3DDEVICEDESC dref, d1, d2;
266 D3DDEVICEDESC7 newDesc;
269 /* Some games (Motoracer 2 demo) have the bad idea to modify the device name string.
270 Let's put the string in a sufficiently sized array in writable memory. */
271 char device_name[50];
272 strcpy(device_name,"direct3d");
274 TRACE("(%p)->(%p,%p)\n", This, Callback, Context);
276 hr = IDirect3DImpl_GetCaps(This->wineD3D, &dref, &newDesc);
277 if(hr != D3D_OK) return hr;
279 /* Do I have to enumerate the reference id? Note from old d3d7:
280 * "It seems that enumerating the reference IID on Direct3D 1 games
281 * (AvP / Motoracer2) breaks them". So do not enumerate this iid in V1
283 * There's a registry key HKLM\Software\Microsoft\Direct3D\Drivers, EnumReference
284 * which enables / disables enumerating the reference rasterizer. It's a DWORD,
285 * 0 means disabled, 2 means enabled. The enablerefrast.reg and disablerefrast.reg
286 * files in the DirectX 7.0 sdk demo directory suggest this.
288 * Some games(GTA 2) seem to use the secound enumerated device, so I have to enumerate
289 * at least 2 devices. So enumerate the reference device to have 2 devices.
292 if(This->d3dversion != 1)
294 TRACE("(%p) Enumerating WineD3D D3DDevice interface\n", This);
297 hr = Callback( (LPIID) &IID_IDirect3DRefDevice, "Reference Direct3D ID", device_name, &d1, &d2, Context);
298 if(hr != D3DENUMRET_OK)
300 TRACE("Application cancelled the enumeration\n");
305 TRACE("(%p) Enumerating WineD3D D3DDevice interface\n", This);
308 hr = Callback( (LPIID) &IID_D3DDEVICE_WineD3D, "Wine D3DDevice using WineD3D and OpenGL", device_name, &d1, &d2, Context);
309 if(hr != D3DENUMRET_OK)
311 TRACE("Application cancelled the enumeration\n");
314 TRACE("(%p) End of enumeration\n", This);
319 static HRESULT WINAPI
320 Thunk_IDirect3DImpl_2_EnumDevices(IDirect3D2 *iface,
321 LPD3DENUMDEVICESCALLBACK Callback,
324 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
325 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This, Callback, Context);
326 return IDirect3D3_EnumDevices(ICOM_INTERFACE(This, IDirect3D3),
331 static HRESULT WINAPI
332 Thunk_IDirect3DImpl_1_EnumDevices(IDirect3D *iface,
333 LPD3DENUMDEVICESCALLBACK Callback,
336 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
337 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This, Callback, Context);
338 return IDirect3D3_EnumDevices(ICOM_INTERFACE(This, IDirect3D3),
343 /*****************************************************************************
344 * IDirect3D3::CreateLight
346 * Creates an IDirect3DLight interface. This interface is used in
347 * Direct3D3 or earlier for lighting. In Direct3D7 it has been replaced
348 * by the DIRECT3DLIGHT7 structure. Wine's Direct3DLight implementation
349 * uses the IDirect3DDevice7 interface with D3D7 lights.
354 * Light: Address to store the new interface pointer
355 * UnkOuter: Basically for aggregation, but ddraw doesn't support it.
360 * DDERR_OUTOFMEMORY if memory allocation failed
361 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
363 *****************************************************************************/
364 static HRESULT WINAPI
365 IDirect3DImpl_3_CreateLight(IDirect3D3 *iface,
366 IDirect3DLight **Light,
369 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
370 IDirect3DLightImpl *object;
372 TRACE("(%p)->(%p,%p)\n", This, Light, UnkOuter);
375 return CLASS_E_NOAGGREGATION;
377 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DLightImpl));
379 return DDERR_OUTOFMEMORY;
381 ICOM_INIT_INTERFACE(object, IDirect3DLight, IDirect3DLight_Vtbl);
383 object->ddraw = This;
385 object->active_viewport = NULL;
387 /* Update functions */
388 object->activate = light_update;
389 object->desactivate = light_activate;
390 object->update = light_desactivate;
391 object->active_viewport = NULL;
393 *Light = ICOM_INTERFACE(object, IDirect3DLight);
395 TRACE("(%p) creating implementation at %p.\n", This, object);
400 static HRESULT WINAPI
401 Thunk_IDirect3DImpl_2_CreateLight(IDirect3D2 *iface,
402 IDirect3DLight **Direct3DLight,
405 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
406 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This, Direct3DLight, UnkOuter);
407 return IDirect3D3_CreateLight(ICOM_INTERFACE(This, IDirect3D3),
412 static HRESULT WINAPI
413 Thunk_IDirect3DImpl_1_CreateLight(IDirect3D *iface,
414 IDirect3DLight **Direct3DLight,
417 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
418 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This, Direct3DLight, UnkOuter);
419 return IDirect3D3_CreateLight(ICOM_INTERFACE(This, IDirect3D3),
424 /*****************************************************************************
425 * IDirect3D3::CreateMaterial
427 * Creates an IDirect3DMaterial interface. This interface is used by Direct3D3
428 * and older versions. The IDirect3DMaterial implementation wraps its
429 * functionality to IDirect3DDevice7::SetMaterial and friends.
434 * Material: Address to store the new interface's pointer to
435 * UnkOuter: Basically for aggregation, but ddraw doesn't support it.
440 * DDERR_OUTOFMEMORY if memory allocation failed
441 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
443 *****************************************************************************/
444 static HRESULT WINAPI
445 IDirect3DImpl_3_CreateMaterial(IDirect3D3 *iface,
446 IDirect3DMaterial3 **Material,
449 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
450 IDirect3DMaterialImpl *object;
452 TRACE("(%p)->(%p,%p)\n", This, Material, UnkOuter);
455 return CLASS_E_NOAGGREGATION;
457 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DMaterialImpl));
459 return DDERR_OUTOFMEMORY;
461 ICOM_INIT_INTERFACE(object, IDirect3DMaterial3, IDirect3DMaterial3_Vtbl);
462 ICOM_INIT_INTERFACE(object, IDirect3DMaterial2, IDirect3DMaterial2_Vtbl);
463 ICOM_INIT_INTERFACE(object, IDirect3DMaterial, IDirect3DMaterial_Vtbl);
465 object->ddraw = This;
466 object->activate = material_activate;
468 *Material = ICOM_INTERFACE(object, IDirect3DMaterial3);
470 TRACE("(%p) creating implementation at %p.\n", This, object);
475 static HRESULT WINAPI
476 Thunk_IDirect3DImpl_2_CreateMaterial(IDirect3D2 *iface,
477 IDirect3DMaterial2 **Direct3DMaterial,
480 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
482 IDirect3DMaterial3 *ret_val;
484 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This, Direct3DMaterial, UnkOuter);
485 ret = IDirect3D3_CreateMaterial(ICOM_INTERFACE(This, IDirect3D3),
489 *Direct3DMaterial = COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial3, IDirect3DMaterial2, ret_val);
491 TRACE(" returning interface %p.\n", *Direct3DMaterial);
496 static HRESULT WINAPI
497 Thunk_IDirect3DImpl_1_CreateMaterial(IDirect3D *iface,
498 IDirect3DMaterial **Direct3DMaterial,
501 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
503 LPDIRECT3DMATERIAL3 ret_val;
505 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This, Direct3DMaterial, UnkOuter);
506 ret = IDirect3D3_CreateMaterial(ICOM_INTERFACE(This, IDirect3D3),
510 *Direct3DMaterial = COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial3, IDirect3DMaterial, ret_val);
512 TRACE(" returning interface %p.\n", *Direct3DMaterial);
517 /*****************************************************************************
518 * IDirect3D3::CreateViewport
520 * Creates an IDirect3DViewport interface. This interface is used
521 * by Direct3D and earlier versions for Viewport management. In Direct3D7
522 * it has been replaced by a viewport structure and
523 * IDirect3DDevice7::*Viewport. Wine's IDirect3DViewport implementation
524 * uses the IDirect3DDevice7 methods for its functionality
527 * Viewport: Address to store the new interface pointer
528 * UnkOuter: Basically for aggregation, but ddraw doesn't support it.
533 * DDERR_OUTOFMEMORY if memory allocation failed
534 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
536 *****************************************************************************/
537 static HRESULT WINAPI
538 IDirect3DImpl_3_CreateViewport(IDirect3D3 *iface,
539 IDirect3DViewport3 **Viewport,
542 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
543 IDirect3DViewportImpl *object;
546 return CLASS_E_NOAGGREGATION;
548 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DViewportImpl));
550 return DDERR_OUTOFMEMORY;
552 ICOM_INIT_INTERFACE(object, IDirect3DViewport3, IDirect3DViewport3_Vtbl);
554 object->ddraw = This;
555 object->activate = viewport_activate;
556 object->use_vp2 = 0xFF;
558 object->lights = NULL;
559 object->num_lights = 0;
560 object->map_lights = 0;
562 *Viewport = ICOM_INTERFACE(object, IDirect3DViewport3);
564 TRACE("(%p) creating implementation at %p.\n",This, object);
569 static HRESULT WINAPI
570 Thunk_IDirect3DImpl_2_CreateViewport(IDirect3D2 *iface,
571 IDirect3DViewport2 **D3DViewport2,
574 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
575 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This, D3DViewport2, UnkOuter);
577 return IDirect3D3_CreateViewport(ICOM_INTERFACE(This, IDirect3D3),
578 (IDirect3DViewport3 **) D3DViewport2 /* No need to cast here */,
582 static HRESULT WINAPI
583 Thunk_IDirect3DImpl_1_CreateViewport(IDirect3D *iface,
584 IDirect3DViewport **D3DViewport,
587 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
588 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This, D3DViewport, UnkOuter);
590 return IDirect3D3_CreateViewport(ICOM_INTERFACE(This, IDirect3D3),
591 (IDirect3DViewport3 **) D3DViewport /* No need to cast here */,
595 /*****************************************************************************
596 * IDirect3D3::FindDevice
598 * This method finds a device with the requested properties and returns a
603 * D3DDFS: Describes the requested device characteristics
604 * D3DFDR: Returns the device description
608 * DDERR_INVALIDPARAMS if no device was found
610 *****************************************************************************/
611 static HRESULT WINAPI
612 IDirect3DImpl_3_FindDevice(IDirect3D3 *iface,
613 D3DFINDDEVICESEARCH *D3DDFS,
614 D3DFINDDEVICERESULT *D3DFDR)
616 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
618 D3DDEVICEDESC7 newDesc;
621 TRACE("(%p)->(%p,%p)\n", This, D3DDFS, D3DFDR);
623 if ((D3DDFS->dwFlags & D3DFDS_COLORMODEL) &&
624 (D3DDFS->dcmColorModel != D3DCOLOR_RGB))
626 TRACE(" trying to request a non-RGB D3D color model. Not supported.\n");
627 return DDERR_INVALIDPARAMS; /* No real idea what to return here :-) */
629 if (D3DDFS->dwFlags & D3DFDS_GUID)
631 TRACE(" trying to match guid %s.\n", debugstr_guid(&(D3DDFS->guid)));
632 if ((IsEqualGUID(&IID_D3DDEVICE_WineD3D, &(D3DDFS->guid)) == 0) &&
633 (IsEqualGUID(&IID_IDirect3DHALDevice, &(D3DDFS->guid)) == 0) &&
634 (IsEqualGUID(&IID_IDirect3DRefDevice, &(D3DDFS->guid)) == 0))
636 TRACE(" no match for this GUID.\n");
637 return DDERR_INVALIDPARAMS;
642 hr = IDirect3DImpl_GetCaps(This->wineD3D, &desc, &newDesc);
643 if(hr != D3D_OK) return hr;
645 /* Now return our own GUID */
646 D3DFDR->guid = IID_D3DDEVICE_WineD3D;
647 D3DFDR->ddHwDesc = desc;
648 D3DFDR->ddSwDesc = desc;
650 TRACE(" returning Wine's WineD3D device with (undumped) capabilities\n");
655 static HRESULT WINAPI
656 Thunk_IDirect3DImpl_2_FindDevice(IDirect3D2 *iface,
657 D3DFINDDEVICESEARCH *D3DDFS,
658 D3DFINDDEVICERESULT *D3DFDR)
660 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
661 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", iface, D3DDFS, D3DFDR);
662 return IDirect3D3_FindDevice(ICOM_INTERFACE(This, IDirect3D3),
667 static HRESULT WINAPI
668 Thunk_IDirect3DImpl_1_FindDevice(IDirect3D *iface,
669 D3DFINDDEVICESEARCH *D3DDFS,
670 D3DFINDDEVICERESULT *D3DDevice)
672 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
673 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This, D3DDFS, D3DDevice);
674 return IDirect3D3_FindDevice(ICOM_INTERFACE(This, IDirect3D3),
679 /*****************************************************************************
680 * IDirect3D7::CreateDevice
682 * Creates an IDirect3DDevice7 interface.
684 * Version 2, 3 and 7. IDirect3DDevice 1 interfaces are interfaces to
685 * DirectDraw surfaces and are created with
686 * IDirectDrawSurface::QueryInterface. This method uses CreateDevice to
687 * create the device object and QueryInterfaces for IDirect3DDevice
690 * refiid: IID of the device to create
691 * Surface: Inititial rendertarget
692 * Device: Address to return the interface pointer
696 * DDERR_OUTOFMEMORY if memory allocation failed
697 * DDERR_INVALIDPARAMS if a device exists already
699 *****************************************************************************/
700 static HRESULT WINAPI
701 IDirect3DImpl_7_CreateDevice(IDirect3D7 *iface,
703 IDirectDrawSurface7 *Surface,
704 IDirect3DDevice7 **Device)
706 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
707 IDirect3DDeviceImpl *object;
708 IParentImpl *IndexBufferParent;
710 IDirectDrawSurfaceImpl *target = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Surface);
711 TRACE("(%p)->(%s,%p,%p)\n", iface, debugstr_guid(refiid), Surface, Device);
715 /* Fail device creation if non-opengl surfaces are used */
716 if(This->ImplType != SURFACE_OPENGL)
718 ERR("The application wants to create a Direct3D device, but non-opengl surfaces are set in the registry. Please set the surface implementation to opengl or autodetection to allow 3D rendering\n");
720 /* We only hit this path if a default surface is set in the registry. Incorrect autodetection
721 * is caught in CreateSurface or QueryInterface
726 /* So far we can only create one device per ddraw object */
729 FIXME("(%p): Only one Direct3D device per DirectDraw object supported\n", This);
730 return DDERR_INVALIDPARAMS;
733 object = HeapAlloc(GetProcessHeap(), 0, sizeof(IDirect3DDeviceImpl));
736 ERR("Out of memory when allocating a IDirect3DDevice implementation\n");
737 return DDERR_OUTOFMEMORY;
740 ICOM_INIT_INTERFACE(object, IDirect3DDevice7, IDirect3DDevice7_Vtbl);
741 ICOM_INIT_INTERFACE(object, IDirect3DDevice3, IDirect3DDevice3_Vtbl);
742 ICOM_INIT_INTERFACE(object, IDirect3DDevice2, IDirect3DDevice2_Vtbl);
743 ICOM_INIT_INTERFACE(object, IDirect3DDevice, IDirect3DDevice1_Vtbl);
746 object->ddraw = This;
747 object->viewport_list = NULL;
748 object->current_viewport = NULL;
749 object->material = 0;
750 object->target = target;
752 object->Handles = NULL;
753 object->numHandles = 0;
755 /* This is for convenience */
756 object->wineD3DDevice = This->wineD3DDevice;
758 /* Create an index buffer, it's needed for indexed drawing */
759 IndexBufferParent = HeapAlloc(GetProcessHeap(), 0, sizeof(IParentImpl *));
760 if(!IndexBufferParent)
762 ERR("Allocating memory for an index buffer parent failed\n");
763 HeapFree(GetProcessHeap(), 0, object);
764 return DDERR_OUTOFMEMORY;
766 ICOM_INIT_INTERFACE(IndexBufferParent, IParent, IParent_Vtbl);
767 IndexBufferParent->ref = 1;
769 /* Create an Index Buffer. WineD3D needs one for Drawing indexed primitives
770 * Create a (hopefully) long enough buffer, and copy the indices into it
771 * Ideally, a IWineD3DIndexBuffer::SetData method could be created, which
772 * takes the pointer and avoids the memcpy
774 hr = IWineD3DDevice_CreateIndexBuffer(This->wineD3DDevice,
775 0x40000, /* Length. Don't know how long it should be */
777 WINED3DFMT_INDEX16, /* Format. D3D7 uses WORDS */
779 &object->indexbuffer,
781 (IUnknown *) ICOM_INTERFACE(IndexBufferParent, IParent));
785 ERR("Failed to create an index buffer\n");
786 HeapFree(GetProcessHeap(), 0, object);
789 IndexBufferParent->child = (IUnknown *) object->indexbuffer;
791 /* No need to set the indices, it's done when necessary */
793 /* AddRef the WineD3D Device */
794 IWineD3DDevice_AddRef(This->wineD3DDevice);
796 /* Don't forget to return the interface ;) */
797 *Device = ICOM_INTERFACE(object, IDirect3DDevice7);
799 TRACE(" (%p) Created an IDirect3DDeviceImpl object at %p\n", This, object);
801 /* This is for apps which create a non-flip, non-d3d primary surface
802 * and an offscreen D3DDEVICE surface, then render to the offscreen surface
803 * and do a Blt from the offscreen to the primary surface.
805 * Set the offscreen D3DDDEVICE surface(=target) as the back buffer,
806 * and the primary surface(=This->d3d_target) as the front buffer.
808 * This way the app will render to the D3DDEVICE surface and WineD3D
809 * will catch the Blt was Back Buffer -> Front buffer blt and perform
810 * a flip instead. This way we don't have to deal with a mixed GL / GDI
813 * This should be checked against windowed apps. The only app tested with
814 * this is moto racer 2 during the loading screen.
816 TRACE("Isrendertarget: %s, d3d_target=%p\n", target->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE ? "true" : "false", This->d3d_target);
817 if(!(target->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) &&
818 (This->d3d_target != target))
820 TRACE("(%p) Using %p as front buffer, %p as back buffer\n", This, This->d3d_target, target);
821 hr = IWineD3DDevice_SetFrontBackBuffers(This->wineD3DDevice,
822 This->d3d_target->WineD3DSurface,
823 target->WineD3DSurface);
825 ERR("(%p) Error %08lx setting the front and back buffer\n", This, hr);
827 object->OffScreenTarget = TRUE;
831 object->OffScreenTarget = FALSE;
834 /* AddRef the render target. Also AddRef the render target from ddraw,
835 * because if it is released before the app releases the D3D device, the D3D capabilities
836 * of WineD3D will be uninitialized, which has bad effects.
838 * In most cases, those surfaces are the surfaces are the same anyway, but this will simply
839 * add another ref which is released when the device is destroyed.
841 IDirectDrawSurface7_AddRef(Surface);
842 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(This->d3d_target, IDirectDrawSurface7));
844 This->d3ddevice = object;
849 static HRESULT WINAPI
850 Thunk_IDirect3DImpl_3_CreateDevice(IDirect3D3 *iface,
852 IDirectDrawSurface4 *Surface,
853 IDirect3DDevice3 **Device,
856 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
858 TRACE("(%p)->(%s,%p,%p,%p): Thunking to IDirect3D7\n", This, debugstr_guid(refiid), Surface, Device, UnkOuter);
861 return CLASS_E_NOAGGREGATION;
863 hr = IDirect3D7_CreateDevice(ICOM_INTERFACE(This, IDirect3D7),
865 (IDirectDrawSurface7 *) Surface /* Same VTables */,
866 (IDirect3DDevice7 **) Device);
868 *Device = COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice7, IDirect3DDevice3, *Device);
872 static HRESULT WINAPI
873 Thunk_IDirect3DImpl_2_CreateDevice(IDirect3D2 *iface,
875 IDirectDrawSurface *Surface,
876 IDirect3DDevice2 **Device)
878 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
880 TRACE("(%p)->(%s,%p,%p): Thunking to IDirect3D7\n", This, debugstr_guid(refiid), Surface, Device);
882 hr = IDirect3D7_CreateDevice(ICOM_INTERFACE(This, IDirect3D7),
884 COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface3, IDirectDrawSurface7, Surface),
885 (IDirect3DDevice7 **) Device);
887 *Device = COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice7, IDirect3DDevice2, *Device);
891 /*****************************************************************************
892 * IDirect3D7::CreateVertexBuffer
894 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
900 * Desc: Requested Vertex buffer properties
901 * VertexBuffer: Address to return the interface pointer at
902 * Flags: Some flags, must be 0
906 * DDERR_OUTOFMEMORY if memory allocation failed
907 * The return value of IWineD3DDevice::CreateVertexBuffer if this call fails
908 * DDERR_INVALIDPARAMS if Desc or VertexBuffer are NULL, or Flags != 0
910 *****************************************************************************/
911 static HRESULT WINAPI
912 IDirect3DImpl_7_CreateVertexBuffer(IDirect3D7 *iface,
913 D3DVERTEXBUFFERDESC *Desc,
914 IDirect3DVertexBuffer7 **VertexBuffer,
917 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
918 IDirect3DVertexBufferImpl *object;
920 TRACE("(%p)->(%p,%p,%08lx)\n", This, Desc, VertexBuffer, Flags);
922 TRACE("(%p) Vertex buffer description:\n", This);
923 TRACE("(%p) dwSize=%ld\n", This, Desc->dwSize);
924 TRACE("(%p) dwCaps=%08lx\n", This, Desc->dwCaps);
925 TRACE("(%p) FVF=%08lx\n", This, Desc->dwFVF);
926 TRACE("(%p) dwNumVertices=%ld\n", This, Desc->dwNumVertices);
928 /* D3D7 SDK: "No Flags are currently defined for this method. This
929 * parameter must be 0"
931 * Never trust the documentation - this is wrong
934 ERR("(%p) Flags is %08lx, returning DDERR_INVALIDPARAMS\n", This, Flags);
935 return DDERR_INVALIDPARAMS;
939 /* Well, this sounds sane */
940 if( (!VertexBuffer) || (!Desc) )
941 return DDERR_INVALIDPARAMS;
943 /* Now create the vertex buffer */
944 object = HeapAlloc(GetProcessHeap(), 0, sizeof(IDirect3DVertexBufferImpl));
947 ERR("(%p) Out of memory when allocating a IDirect3DVertexBufferImpl structure\n", This);
948 return DDERR_OUTOFMEMORY;
952 ICOM_INIT_INTERFACE(object, IDirect3DVertexBuffer7, IDirect3DVertexBuffer7_Vtbl);
953 ICOM_INIT_INTERFACE(object, IDirect3DVertexBuffer, IDirect3DVertexBuffer1_Vtbl);
955 object->Caps = Desc->dwCaps;
957 hr = IWineD3DDevice_CreateVertexBuffer(This->wineD3DDevice,
958 get_flexible_vertex_size(Desc->dwFVF) * Desc->dwNumVertices,
959 Desc->dwCaps & D3DVBCAPS_WRITEONLY ? WINED3DUSAGE_WRITEONLY : 0,
961 Desc->dwCaps & D3DVBCAPS_SYSTEMMEMORY ? WINED3DPOOL_SYSTEMMEM : WINED3DPOOL_DEFAULT,
962 &object->wineD3DVertexBuffer,
963 0 /* SharedHandle */,
964 (IUnknown *) ICOM_INTERFACE(object, IDirect3DVertexBuffer7));
967 ERR("(%p) IWineD3DDevice::CreateVertexBuffer failed with hr=%08lx\n", This, hr);
968 HeapFree(GetProcessHeap(), 0, object);
972 /* Return the interface */
973 *VertexBuffer = ICOM_INTERFACE(object, IDirect3DVertexBuffer7);
975 TRACE("(%p) Created new vertex buffer implementation at %p, returning interface at %p\n", This, object, *VertexBuffer);
979 static HRESULT WINAPI
980 Thunk_IDirect3DImpl_3_CreateVertexBuffer(IDirect3D3 *iface,
981 D3DVERTEXBUFFERDESC *Desc,
982 IDirect3DVertexBuffer **VertexBuffer,
986 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
988 TRACE("(%p)->(%p,%p,%08lx,%p): Relaying to IDirect3D7\n", This, Desc, VertexBuffer, Flags, UnkOuter);
990 if(UnkOuter != NULL) return CLASS_E_NOAGGREGATION;
992 hr = IDirect3D7_CreateVertexBuffer(ICOM_INTERFACE(This, IDirect3D7),
994 (IDirect3DVertexBuffer7 **) VertexBuffer,
997 *VertexBuffer = COM_INTERFACE_CAST(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, IDirect3DVertexBuffer, *VertexBuffer);
1001 /*****************************************************************************
1002 * EnumZBufferFormatsCB
1004 * Helper function for IDirect3D7::EnumZBufferFormats. Converts
1005 * the WINED3DFORMAT into a DirectDraw pixelformat and calls the application
1011 * Device: Parent of the IWineD3DDevice, our IDirectDraw7 interface
1012 * fmt: The enumerated pixel format
1013 * Context: Context passed to IWineD3DDevice::EnumZBufferFormat
1016 * The return value of the application-provided callback
1018 *****************************************************************************/
1019 static HRESULT WINAPI
1020 EnumZBufferFormatsCB(IUnknown *Device,
1024 struct EnumZBufferFormatsData *cbdata = (struct EnumZBufferFormatsData *) Context;
1025 DDPIXELFORMAT pformat;
1027 memset(&pformat, 0, sizeof(DDPIXELFORMAT));
1028 pformat.dwSize=sizeof(DDPIXELFORMAT);
1029 PixelFormat_WineD3DtoDD(&pformat, fmt);
1030 return cbdata->Callback(&pformat, cbdata->Context);
1033 /*****************************************************************************
1034 * IDirect3D7::EnumZBufferFormats
1036 * Enumerates all supported Z buffer pixel formats
1042 * Callback: Callback to call for each pixel format
1043 * Context: Pointer to pass back to the callback
1047 * DDERR_INVALIDPARAMS if Callback is NULL
1048 * For details, see IWineD3DDevice::EnumZBufferFormats
1050 *****************************************************************************/
1051 static HRESULT WINAPI
1052 IDirect3DImpl_7_EnumZBufferFormats(IDirect3D7 *iface,
1053 REFCLSID refiidDevice,
1054 LPD3DENUMPIXELFORMATSCALLBACK Callback,
1057 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
1058 struct EnumZBufferFormatsData cbdata = { Callback, Context };
1059 TRACE("(%p)->(%s,%p,%p): Relay\n", iface, debugstr_guid(refiidDevice), Callback, Context);
1062 return DDERR_INVALIDPARAMS;
1064 return IWineD3DDevice_EnumZBufferFormats(This->wineD3DDevice, EnumZBufferFormatsCB, &cbdata);
1067 static HRESULT WINAPI
1068 Thunk_IDirect3DImpl_3_EnumZBufferFormats(IDirect3D3 *iface,
1069 REFCLSID riidDevice,
1070 LPD3DENUMPIXELFORMATSCALLBACK Callback,
1073 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
1074 TRACE("(%p)->(%s,%p,%p) thunking to IDirect3D7 interface.\n", This, debugstr_guid(riidDevice), Callback, Context);
1075 return IDirect3D7_EnumZBufferFormats(ICOM_INTERFACE(This, IDirect3D7),
1081 /*****************************************************************************
1082 * IDirect3D7::EvictManagedTextures
1084 * Removes all managed textures (=surfaces with DDSCAPS2_TEXTUREMANAGE or
1085 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
1090 * D3D_OK, because it's a stub
1092 *****************************************************************************/
1093 static HRESULT WINAPI
1094 IDirect3DImpl_7_EvictManagedTextures(IDirect3D7 *iface)
1096 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
1097 FIXME("(%p): Stub!\n", This);
1099 /* Implementation idea:
1100 * Add an IWineD3DSurface method which sets the opengl texture
1101 * priority low or even removes the opengl texture.
1107 static HRESULT WINAPI
1108 Thunk_IDirect3DImpl_3_EvictManagedTextures(IDirect3D3 *iface)
1110 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
1111 TRACE("(%p)->() thunking to IDirect3D7 interface.\n", This);
1112 return IDirect3D7_EvictManagedTextures(ICOM_INTERFACE(This, IDirect3D7));
1115 /*****************************************************************************
1116 * IDirect3DImpl_GetCaps
1118 * This function retrieves the device caps from wined3d
1119 * and converts it into a D3D7 and D3D - D3D3 structure
1120 * This is a helper function called from various places in ddraw
1123 * WineD3D: The interface to get the caps from
1124 * Desc123: Old D3D <3 structure to fill (needed)
1125 * Desc7: D3D7 device desc structure to fill (needed)
1128 * D3D_OK on success, or the return value of IWineD3D::GetCaps
1130 *****************************************************************************/
1132 IDirect3DImpl_GetCaps(IWineD3D *WineD3D,
1133 D3DDEVICEDESC *Desc123,
1134 D3DDEVICEDESC7 *Desc7)
1139 /* Some Variables to asign to the pointers in WCaps */
1140 WINED3DDEVTYPE DevType;
1143 DWORD dummy_dword, MaxTextureBlendStages, MaxSimultaneousTextures;
1144 DWORD MaxUserClipPlanes, MaxVertexBlendMatrices;
1146 TRACE("()->(%p,%p,%p\n", WineD3D, Desc123, Desc7);
1148 /* Asign the pointers in WCaps */
1149 WCaps.DeviceType = &DevType;
1150 WCaps.AdapterOrdinal = &dummy_uint;
1152 WCaps.Caps = &dummy_dword;
1153 WCaps.Caps2 = &dummy_dword;
1154 WCaps.Caps3 = &dummy_dword;
1155 WCaps.PresentationIntervals = &dummy_dword;
1157 WCaps.CursorCaps = &dummy_dword;
1159 WCaps.DevCaps = &Desc7->dwDevCaps;
1160 WCaps.PrimitiveMiscCaps = &dummy_dword;
1161 WCaps.RasterCaps = &Desc7->dpcLineCaps.dwRasterCaps;
1162 WCaps.ZCmpCaps = &Desc7->dpcLineCaps.dwZCmpCaps;
1163 WCaps.SrcBlendCaps = &Desc7->dpcLineCaps.dwSrcBlendCaps;
1164 WCaps.DestBlendCaps = &Desc7->dpcLineCaps.dwDestBlendCaps;
1165 WCaps.AlphaCmpCaps = &Desc7->dpcLineCaps.dwAlphaCmpCaps;
1166 WCaps.ShadeCaps = &Desc7->dpcLineCaps.dwShadeCaps;
1167 WCaps.TextureCaps = &Desc7->dpcLineCaps.dwTextureCaps;
1168 WCaps.TextureFilterCaps = &Desc7->dpcLineCaps.dwTextureFilterCaps;
1169 WCaps.CubeTextureFilterCaps = &dummy_dword;
1170 WCaps.VolumeTextureFilterCaps = &dummy_dword;
1171 WCaps.TextureAddressCaps = &Desc7->dpcLineCaps.dwTextureAddressCaps;
1172 WCaps.VolumeTextureAddressCaps = &dummy_dword;
1174 WCaps.LineCaps = &dummy_dword;
1175 WCaps.MaxTextureWidth = &Desc7->dwMaxTextureWidth;
1176 WCaps.MaxTextureHeight = &Desc7->dwMaxTextureHeight;
1177 WCaps.MaxVolumeExtent = &dummy_dword;
1179 WCaps.MaxTextureRepeat = &Desc7->dwMaxTextureRepeat;
1180 WCaps.MaxTextureAspectRatio = &Desc7->dwMaxTextureAspectRatio;
1181 WCaps.MaxAnisotropy = &Desc7->dwMaxAnisotropy;
1182 WCaps.MaxVertexW = &Desc7->dvMaxVertexW;
1184 WCaps.GuardBandLeft = &Desc7->dvGuardBandLeft;
1185 WCaps.GuardBandTop = &Desc7->dvGuardBandTop;
1186 WCaps.GuardBandRight = &Desc7->dvGuardBandRight;
1187 WCaps.GuardBandBottom = &Desc7->dvGuardBandBottom;
1189 WCaps.ExtentsAdjust = &Desc7->dvExtentsAdjust;
1190 WCaps.StencilCaps = &Desc7->dwStencilCaps;
1192 WCaps.FVFCaps = &Desc7->dwFVFCaps;
1193 WCaps.TextureOpCaps = &Desc7->dwTextureOpCaps;
1194 WCaps.MaxTextureBlendStages = &MaxTextureBlendStages;
1195 WCaps.MaxSimultaneousTextures = &MaxSimultaneousTextures;
1197 WCaps.VertexProcessingCaps = &Desc7->dwVertexProcessingCaps;
1198 WCaps.MaxActiveLights = &Desc7->dwMaxActiveLights;
1199 WCaps.MaxUserClipPlanes = &MaxUserClipPlanes;
1200 WCaps.MaxVertexBlendMatrices = &MaxVertexBlendMatrices;
1201 WCaps.MaxVertexBlendMatrixIndex = &dummy_dword;
1203 WCaps.MaxPointSize = &dummy_float;
1204 WCaps.MaxPrimitiveCount = &dummy_dword;
1205 WCaps.MaxVertexIndex = &dummy_dword;
1206 WCaps.MaxStreams = &dummy_dword;
1207 WCaps.MaxStreamStride = &dummy_dword;
1209 WCaps.VertexShaderVersion = &dummy_dword;
1210 WCaps.MaxVertexShaderConst = &dummy_dword;
1212 WCaps.PixelShaderVersion = &dummy_dword;
1213 WCaps.PixelShader1xMaxValue = &dummy_float;
1215 /* These are dx9 only, set them to NULL */
1216 WCaps.DevCaps2 = NULL;
1217 WCaps.MaxNpatchTessellationLevel = NULL;
1218 WCaps.Reserved5 = NULL;
1219 WCaps.MasterAdapterOrdinal = NULL;
1220 WCaps.AdapterOrdinalInGroup = NULL;
1221 WCaps.NumberOfAdaptersInGroup = NULL;
1222 WCaps.DeclTypes = NULL;
1223 WCaps.NumSimultaneousRTs = NULL;
1224 WCaps.StretchRectFilterCaps = NULL;
1225 /* WCaps.VS20Caps = NULL; */
1226 /* WCaps.PS20Caps = NULL; */
1227 WCaps.VertexTextureFilterCaps = NULL;
1228 WCaps.MaxVShaderInstructionsExecuted = NULL;
1229 WCaps.MaxPShaderInstructionsExecuted = NULL;
1230 WCaps.MaxVertexShader30InstructionSlots = NULL;
1231 WCaps.MaxPixelShader30InstructionSlots = NULL;
1232 WCaps.Reserved2 = NULL;
1233 WCaps.Reserved3 = NULL;
1235 /* Now get the caps */
1236 hr = IWineD3D_GetDeviceCaps(WineD3D, 0, WINED3DDEVTYPE_HAL, &WCaps);
1237 if(hr != D3D_OK) return hr;
1239 /* Fill the missing members, and do some fixup */
1240 Desc7->dpcLineCaps.dwSize = sizeof(Desc7->dpcLineCaps);
1241 Desc7->dpcLineCaps.dwTextureBlendCaps = D3DPTBLENDCAPS_ADD | D3DPTBLENDCAPS_MODULATEMASK |
1242 D3DPTBLENDCAPS_COPY | D3DPTBLENDCAPS_DECAL |
1243 D3DPTBLENDCAPS_DECALALPHA | D3DPTBLENDCAPS_DECALMASK |
1244 D3DPTBLENDCAPS_MODULATE | D3DPTBLENDCAPS_MODULATEALPHA;
1245 Desc7->dpcLineCaps.dwStippleWidth = 32;
1246 Desc7->dpcLineCaps.dwStippleHeight = 32;
1247 /* Use the same for the TriCaps */
1248 Desc7->dpcTriCaps = Desc7->dpcLineCaps;
1250 Desc7->dwDeviceRenderBitDepth = DDBD_16 | DDBD_24 | DDBD_32;
1251 Desc7->dwDeviceZBufferBitDepth = DDBD_16 | DDBD_24;
1252 Desc7->dwMinTextureWidth = 1;
1253 Desc7->dwMinTextureHeight = 1;
1255 /* Convert DWORDs safely to WORDs */
1256 if(MaxTextureBlendStages > 65535) Desc7->wMaxTextureBlendStages = 65535;
1257 else Desc7->wMaxTextureBlendStages = (WORD) MaxTextureBlendStages;
1258 if(MaxSimultaneousTextures > 65535) Desc7->wMaxSimultaneousTextures = 65535;
1259 else Desc7->wMaxSimultaneousTextures = (WORD) MaxSimultaneousTextures;
1261 if(MaxUserClipPlanes > 65535) Desc7->wMaxUserClipPlanes = 65535;
1262 else Desc7->wMaxUserClipPlanes = (WORD) MaxUserClipPlanes;
1263 if(MaxVertexBlendMatrices > 65535) Desc7->wMaxVertexBlendMatrices = 65535;
1264 else Desc7->wMaxVertexBlendMatrices = (WORD) MaxVertexBlendMatrices;
1266 Desc7->deviceGUID = IID_IDirect3DTnLHalDevice;
1268 Desc7->dwReserved1 = 0;
1269 Desc7->dwReserved2 = 0;
1270 Desc7->dwReserved3 = 0;
1271 Desc7->dwReserved4 = 0;
1273 /* Fill the old structure */
1274 memset(Desc123, 0x0, sizeof(D3DDEVICEDESC));
1275 Desc123->dwSize = sizeof(D3DDEVICEDESC);
1276 Desc123->dwFlags = D3DDD_COLORMODEL |
1278 D3DDD_TRANSFORMCAPS |
1280 D3DDD_LIGHTINGCAPS |
1283 D3DDD_DEVICERENDERBITDEPTH |
1284 D3DDD_DEVICEZBUFFERBITDEPTH |
1285 D3DDD_MAXBUFFERSIZE |
1286 D3DDD_MAXVERTEXCOUNT;
1287 Desc123->dcmColorModel = D3DCOLOR_RGB;
1288 Desc123->dwDevCaps = Desc7->dwDevCaps;
1289 Desc123->dtcTransformCaps.dwSize = sizeof(D3DTRANSFORMCAPS);
1290 Desc123->dtcTransformCaps.dwCaps = D3DTRANSFORMCAPS_CLIP;
1291 Desc123->bClipping = TRUE;
1292 Desc123->dlcLightingCaps.dwSize = sizeof(D3DLIGHTINGCAPS);
1293 Desc123->dlcLightingCaps.dwCaps = D3DLIGHTCAPS_DIRECTIONAL | D3DLIGHTCAPS_PARALLELPOINT | D3DLIGHTCAPS_POINT | D3DLIGHTCAPS_SPOT;
1294 Desc123->dlcLightingCaps.dwLightingModel = D3DLIGHTINGMODEL_RGB;
1295 Desc123->dlcLightingCaps.dwNumLights = Desc7->dwMaxActiveLights;
1297 Desc123->dpcLineCaps.dwSize = sizeof(D3DPRIMCAPS);
1298 Desc123->dpcLineCaps.dwMiscCaps = Desc7->dpcLineCaps.dwMiscCaps;
1299 Desc123->dpcLineCaps.dwRasterCaps = Desc7->dpcLineCaps.dwRasterCaps;
1300 Desc123->dpcLineCaps.dwZCmpCaps = Desc7->dpcLineCaps.dwZCmpCaps;
1301 Desc123->dpcLineCaps.dwSrcBlendCaps = Desc7->dpcLineCaps.dwSrcBlendCaps;
1302 Desc123->dpcLineCaps.dwDestBlendCaps = Desc7->dpcLineCaps.dwDestBlendCaps;
1303 Desc123->dpcLineCaps.dwShadeCaps = Desc7->dpcLineCaps.dwShadeCaps;
1304 Desc123->dpcLineCaps.dwTextureCaps = Desc7->dpcLineCaps.dwTextureCaps;
1305 Desc123->dpcLineCaps.dwTextureFilterCaps = Desc7->dpcLineCaps.dwTextureFilterCaps;
1306 Desc123->dpcLineCaps.dwTextureBlendCaps = Desc7->dpcLineCaps.dwTextureBlendCaps;
1307 Desc123->dpcLineCaps.dwTextureAddressCaps = Desc7->dpcLineCaps.dwTextureAddressCaps;
1308 Desc123->dpcLineCaps.dwStippleWidth = Desc7->dpcLineCaps.dwStippleWidth;
1309 Desc123->dpcLineCaps.dwAlphaCmpCaps = Desc7->dpcLineCaps.dwAlphaCmpCaps;
1311 Desc123->dpcTriCaps.dwSize = sizeof(D3DPRIMCAPS);
1312 Desc123->dpcTriCaps.dwMiscCaps = Desc7->dpcTriCaps.dwMiscCaps;
1313 Desc123->dpcTriCaps.dwRasterCaps = Desc7->dpcTriCaps.dwRasterCaps;
1314 Desc123->dpcTriCaps.dwZCmpCaps = Desc7->dpcTriCaps.dwZCmpCaps;
1315 Desc123->dpcTriCaps.dwSrcBlendCaps = Desc7->dpcTriCaps.dwSrcBlendCaps;
1316 Desc123->dpcTriCaps.dwDestBlendCaps = Desc7->dpcTriCaps.dwDestBlendCaps;
1317 Desc123->dpcTriCaps.dwShadeCaps = Desc7->dpcTriCaps.dwShadeCaps;
1318 Desc123->dpcTriCaps.dwTextureCaps = Desc7->dpcTriCaps.dwTextureCaps;
1319 Desc123->dpcTriCaps.dwTextureFilterCaps = Desc7->dpcTriCaps.dwTextureFilterCaps;
1320 Desc123->dpcTriCaps.dwTextureBlendCaps = Desc7->dpcTriCaps.dwTextureBlendCaps;
1321 Desc123->dpcTriCaps.dwTextureAddressCaps = Desc7->dpcTriCaps.dwTextureAddressCaps;
1322 Desc123->dpcTriCaps.dwStippleWidth = Desc7->dpcTriCaps.dwStippleWidth;
1323 Desc123->dpcTriCaps.dwAlphaCmpCaps = Desc7->dpcTriCaps.dwAlphaCmpCaps;
1325 Desc123->dwDeviceRenderBitDepth = Desc7->dwDeviceRenderBitDepth;
1326 Desc123->dwDeviceZBufferBitDepth = Desc7->dwDeviceZBufferBitDepth;
1327 Desc123->dwMaxBufferSize = 0;
1328 Desc123->dwMaxVertexCount = 65536;
1329 Desc123->dwMinTextureWidth = Desc7->dwMinTextureWidth;
1330 Desc123->dwMinTextureHeight = Desc7->dwMinTextureHeight;
1331 Desc123->dwMaxTextureWidth = Desc7->dwMaxTextureWidth;
1332 Desc123->dwMaxTextureHeight = Desc7->dwMaxTextureHeight;
1333 Desc123->dwMinStippleWidth = 1;
1334 Desc123->dwMinStippleHeight = 1;
1335 Desc123->dwMaxStippleWidth = 32;
1336 Desc123->dwMaxStippleHeight = 32;
1337 Desc123->dwMaxTextureRepeat = Desc7->dwMaxTextureRepeat;
1338 Desc123->dwMaxTextureAspectRatio = Desc7->dwMaxTextureAspectRatio;
1339 Desc123->dwMaxAnisotropy = Desc7->dwMaxAnisotropy;
1340 Desc123->dvGuardBandLeft = Desc7->dvGuardBandLeft;
1341 Desc123->dvGuardBandRight = Desc7->dvGuardBandRight;
1342 Desc123->dvGuardBandTop = Desc7->dvGuardBandTop;
1343 Desc123->dvGuardBandBottom = Desc7->dvGuardBandBottom;
1344 Desc123->dvExtentsAdjust = Desc7->dvExtentsAdjust;
1345 Desc123->dwStencilCaps = Desc7->dwStencilCaps;
1346 Desc123->dwFVFCaps = Desc7->dwFVFCaps;
1347 Desc123->dwTextureOpCaps = Desc7->dwTextureOpCaps;
1348 Desc123->wMaxTextureBlendStages = Desc7->wMaxTextureBlendStages;
1349 Desc123->wMaxSimultaneousTextures = Desc7->wMaxSimultaneousTextures;
1353 /*****************************************************************************
1354 * IDirect3D vtables in various versions
1355 *****************************************************************************/
1357 const IDirect3DVtbl IDirect3D1_Vtbl =
1359 /*** IUnknown methods ***/
1360 Thunk_IDirect3DImpl_1_QueryInterface,
1361 Thunk_IDirect3DImpl_1_AddRef,
1362 Thunk_IDirect3DImpl_1_Release,
1363 /*** IDirect3D methods ***/
1364 IDirect3DImpl_1_Initialize,
1365 Thunk_IDirect3DImpl_1_EnumDevices,
1366 Thunk_IDirect3DImpl_1_CreateLight,
1367 Thunk_IDirect3DImpl_1_CreateMaterial,
1368 Thunk_IDirect3DImpl_1_CreateViewport,
1369 Thunk_IDirect3DImpl_1_FindDevice
1372 const IDirect3D2Vtbl IDirect3D2_Vtbl =
1374 /*** IUnknown methods ***/
1375 Thunk_IDirect3DImpl_2_QueryInterface,
1376 Thunk_IDirect3DImpl_2_AddRef,
1377 Thunk_IDirect3DImpl_2_Release,
1378 /*** IDirect3D2 methods ***/
1379 Thunk_IDirect3DImpl_2_EnumDevices,
1380 Thunk_IDirect3DImpl_2_CreateLight,
1381 Thunk_IDirect3DImpl_2_CreateMaterial,
1382 Thunk_IDirect3DImpl_2_CreateViewport,
1383 Thunk_IDirect3DImpl_2_FindDevice,
1384 Thunk_IDirect3DImpl_2_CreateDevice
1387 const IDirect3D3Vtbl IDirect3D3_Vtbl =
1389 /*** IUnknown methods ***/
1390 Thunk_IDirect3DImpl_3_QueryInterface,
1391 Thunk_IDirect3DImpl_3_AddRef,
1392 Thunk_IDirect3DImpl_3_Release,
1393 /*** IDirect3D3 methods ***/
1394 IDirect3DImpl_3_EnumDevices,
1395 IDirect3DImpl_3_CreateLight,
1396 IDirect3DImpl_3_CreateMaterial,
1397 IDirect3DImpl_3_CreateViewport,
1398 IDirect3DImpl_3_FindDevice,
1399 Thunk_IDirect3DImpl_3_CreateDevice,
1400 Thunk_IDirect3DImpl_3_CreateVertexBuffer,
1401 Thunk_IDirect3DImpl_3_EnumZBufferFormats,
1402 Thunk_IDirect3DImpl_3_EvictManagedTextures
1405 const IDirect3D7Vtbl IDirect3D7_Vtbl =
1407 /*** IUnknown methods ***/
1408 Thunk_IDirect3DImpl_7_QueryInterface,
1409 Thunk_IDirect3DImpl_7_AddRef,
1410 Thunk_IDirect3DImpl_7_Release,
1411 /*** IDirect3D7 methods ***/
1412 IDirect3DImpl_7_EnumDevices,
1413 IDirect3DImpl_7_CreateDevice,
1414 IDirect3DImpl_7_CreateVertexBuffer,
1415 IDirect3DImpl_7_EnumZBufferFormats,
1416 IDirect3DImpl_7_EvictManagedTextures