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 * IDirect3D7::QueryInterface
48 * QueryInterface implementation with thunks to IDirectDraw7
50 *****************************************************************************/
52 Thunk_IDirect3DImpl_7_QueryInterface(IDirect3D7 *iface,
56 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
57 TRACE("(%p)->(%s,%p): Thunking to IDirectDraw7\n", This, debugstr_guid(refiid), obj);
59 return IDirectDraw7_QueryInterface(ICOM_INTERFACE(This, IDirectDraw7),
65 Thunk_IDirect3DImpl_3_QueryInterface(IDirect3D3 *iface,
69 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
70 TRACE("(%p)->(%s,%p): Thunking to IDirectDraw7\n", This, debugstr_guid(refiid), obj);
72 return IDirectDraw7_QueryInterface(ICOM_INTERFACE(This, IDirectDraw7),
78 Thunk_IDirect3DImpl_2_QueryInterface(IDirect3D2 *iface,
82 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
83 TRACE("(%p)->(%s,%p): Thunking to IDirectDraw7\n", This, debugstr_guid(refiid), obj);
85 return IDirectDraw7_QueryInterface(ICOM_INTERFACE(This, IDirectDraw7),
91 Thunk_IDirect3DImpl_1_QueryInterface(IDirect3D *iface,
95 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
96 TRACE("(%p)->(%s,%p): Thunking to IDirectDraw7\n", This, debugstr_guid(refiid), obj);
98 return IDirectDraw7_QueryInterface(ICOM_INTERFACE(This, IDirectDraw7),
103 /*****************************************************************************
106 * DirectDraw refcounting is a bit odd. Every version of the ddraw interface
107 * has its own refcount, but IDirect3D 1/2/3 refcounts are linked to
108 * IDirectDraw, and IDirect3D7 is linked to IDirectDraw7
110 * IDirect3D7 -> IDirectDraw7
111 * IDirect3D3 -> IDirectDraw
112 * IDirect3D2 -> IDirectDraw
113 * IDirect3D -> IDirectDraw
115 * So every AddRef implementation thunks to a different interface, and the
116 * IDirectDrawX::AddRef implementations have different counters...
121 *****************************************************************************/
123 Thunk_IDirect3DImpl_7_AddRef(IDirect3D7 *iface)
125 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
126 TRACE("(%p) : Thunking to IDirectDraw7.\n", This);
128 return IDirectDraw7_AddRef(ICOM_INTERFACE(This, IDirectDraw7));
132 Thunk_IDirect3DImpl_3_AddRef(IDirect3D3 *iface)
134 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
135 TRACE("(%p) : Thunking to IDirectDraw.\n", This);
137 return IDirectDraw_AddRef(ICOM_INTERFACE(This, IDirectDraw));
141 Thunk_IDirect3DImpl_2_AddRef(IDirect3D2 *iface)
143 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
144 TRACE("(%p) : Thunking to IDirectDraw.\n", This);
146 return IDirectDraw_AddRef(ICOM_INTERFACE(This, IDirectDraw));
150 Thunk_IDirect3DImpl_1_AddRef(IDirect3D *iface)
152 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
153 TRACE("(%p) : Thunking to IDirectDraw.\n", This);
155 return IDirectDraw_AddRef(ICOM_INTERFACE(This, IDirectDraw));
158 /*****************************************************************************
159 * IDirect3D7::Release
161 * Same story as IDirect3D7::AddRef
163 * Returns: The new refcount
165 *****************************************************************************/
167 Thunk_IDirect3DImpl_7_Release(IDirect3D7 *iface)
169 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
170 TRACE("(%p) : Thunking to IDirectDraw7.\n", This);
172 return IDirectDraw7_Release(ICOM_INTERFACE(This, IDirectDraw7));
176 Thunk_IDirect3DImpl_3_Release(IDirect3D3 *iface)
178 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
179 TRACE("(%p) : Thunking to IDirectDraw.\n", This);
181 return IDirectDraw_Release(ICOM_INTERFACE(This, IDirectDraw));
185 Thunk_IDirect3DImpl_2_Release(IDirect3D2 *iface)
187 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
188 TRACE("(%p) : Thunking to IDirectDraw.\n", This);
190 return IDirectDraw_Release(ICOM_INTERFACE(This, IDirectDraw));
194 Thunk_IDirect3DImpl_1_Release(IDirect3D *iface)
196 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
197 TRACE("(%p) : Thunking to IDirectDraw.\n", This);
199 return IDirectDraw_Release(ICOM_INTERFACE(This, IDirectDraw));
202 /*****************************************************************************
204 *****************************************************************************/
206 /*****************************************************************************
207 * IDirect3D::Initialize
209 * Initializes the IDirect3D interface. This is a no-op implementation,
210 * as all initialization is done at create time.
218 * D3D_OK, because it's a no-op
220 *****************************************************************************/
221 static HRESULT WINAPI
222 IDirect3DImpl_1_Initialize(IDirect3D *iface,
225 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
227 TRACE("(%p)->(%s) no-op...\n", This, debugstr_guid(refiid));
231 /*****************************************************************************
232 * IDirect3D7::EnumDevices
234 * The EnumDevices method for IDirect3D7. It enumerates all supported
235 * D3D7 devices. Currently there's only one.
238 * Callback: Function to call for each enumerated device
239 * Context: Pointer to pass back to the app
242 * D3D_OK, or the return value of the GetCaps call
244 *****************************************************************************/
245 static HRESULT WINAPI
246 IDirect3DImpl_7_EnumDevices(IDirect3D7 *iface,
247 LPD3DENUMDEVICESCALLBACK7 Callback,
250 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
251 char interface_name[] = "WINE Direct3D7 using WineD3D";
252 char device_name[] = "Wine D3D7 device";
253 D3DDEVICEDESC7 ddesc;
254 D3DDEVICEDESC oldDesc;
257 TRACE("(%p)->(%p,%p)\n", This, Callback, Context);
259 TRACE("(%p) Enumerating WineD3D D3Device7 interface\n", This);
260 hr = IDirect3DImpl_GetCaps(This->wineD3D, &oldDesc, &ddesc);
261 if(hr != D3D_OK) return hr;
262 Callback(interface_name, device_name, &ddesc, Context);
264 TRACE("(%p) End of enumeration\n", This);
268 /*****************************************************************************
269 * IDirect3D3::EnumDevices
271 * Enumerates all supported Direct3DDevice interfaces. This is the
272 * implementation for Direct3D 1 to Direc3D 3, Version 7 has its own.
277 * Callback: Application-provided routine to call for each enumerated device
278 * Context: Pointer to pass to the callback
282 * The result of IDirect3DImpl_GetCaps if it failed
284 *****************************************************************************/
285 static HRESULT WINAPI
286 IDirect3DImpl_3_EnumDevices(IDirect3D3 *iface,
287 LPD3DENUMDEVICESCALLBACK Callback,
290 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
291 D3DDEVICEDESC dref, d1, d2;
292 D3DDEVICEDESC7 newDesc;
293 static CHAR wined3d_description[] = "Wine D3DDevice using WineD3D and OpenGL";
296 /* Some games (Motoracer 2 demo) have the bad idea to modify the device name string.
297 Let's put the string in a sufficiently sized array in writable memory. */
298 char device_name[50];
299 strcpy(device_name,"direct3d");
301 TRACE("(%p)->(%p,%p)\n", This, Callback, Context);
303 hr = IDirect3DImpl_GetCaps(This->wineD3D, &dref, &newDesc);
304 if(hr != D3D_OK) return hr;
306 /* Do I have to enumerate the reference id? Note from old d3d7:
307 * "It seems that enumerating the reference IID on Direct3D 1 games
308 * (AvP / Motoracer2) breaks them". So do not enumerate this iid in V1
310 * There's a registry key HKLM\Software\Microsoft\Direct3D\Drivers, EnumReference
311 * which enables / disables enumerating the reference rasterizer. It's a DWORD,
312 * 0 means disabled, 2 means enabled. The enablerefrast.reg and disablerefrast.reg
313 * files in the DirectX 7.0 sdk demo directory suggest this.
315 * Some games(GTA 2) seem to use the second enumerated device, so I have to enumerate
316 * at least 2 devices. So enumerate the reference device to have 2 devices.
319 if(This->d3dversion != 1)
321 static CHAR reference_description[] = "Reference Direct3D ID";
323 TRACE("(%p) Enumerating WineD3D D3DDevice interface\n", This);
326 hr = Callback( (LPIID) &IID_IDirect3DRefDevice, reference_description, device_name, &d1, &d2, Context);
327 if(hr != D3DENUMRET_OK)
329 TRACE("Application cancelled the enumeration\n");
334 TRACE("(%p) Enumerating WineD3D D3DDevice interface\n", This);
337 hr = Callback( (LPIID) &IID_D3DDEVICE_WineD3D, wined3d_description, device_name, &d1, &d2, Context);
338 if(hr != D3DENUMRET_OK)
340 TRACE("Application cancelled the enumeration\n");
343 TRACE("(%p) End of enumeration\n", This);
348 static HRESULT WINAPI
349 Thunk_IDirect3DImpl_2_EnumDevices(IDirect3D2 *iface,
350 LPD3DENUMDEVICESCALLBACK Callback,
353 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
354 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This, Callback, Context);
355 return IDirect3D3_EnumDevices(ICOM_INTERFACE(This, IDirect3D3),
360 static HRESULT WINAPI
361 Thunk_IDirect3DImpl_1_EnumDevices(IDirect3D *iface,
362 LPD3DENUMDEVICESCALLBACK Callback,
365 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
366 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This, Callback, Context);
367 return IDirect3D3_EnumDevices(ICOM_INTERFACE(This, IDirect3D3),
372 /*****************************************************************************
373 * IDirect3D3::CreateLight
375 * Creates an IDirect3DLight interface. This interface is used in
376 * Direct3D3 or earlier for lighting. In Direct3D7 it has been replaced
377 * by the DIRECT3DLIGHT7 structure. Wine's Direct3DLight implementation
378 * uses the IDirect3DDevice7 interface with D3D7 lights.
383 * Light: Address to store the new interface pointer
384 * UnkOuter: Basically for aggregation, but ddraw doesn't support it.
389 * DDERR_OUTOFMEMORY if memory allocation failed
390 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
392 *****************************************************************************/
393 static HRESULT WINAPI
394 IDirect3DImpl_3_CreateLight(IDirect3D3 *iface,
395 IDirect3DLight **Light,
398 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
399 IDirect3DLightImpl *object;
401 TRACE("(%p)->(%p,%p)\n", This, Light, UnkOuter);
404 return CLASS_E_NOAGGREGATION;
406 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DLightImpl));
408 return DDERR_OUTOFMEMORY;
410 ICOM_INIT_INTERFACE(object, IDirect3DLight, IDirect3DLight_Vtbl);
412 object->ddraw = This;
414 object->active_viewport = NULL;
416 /* Update functions */
417 object->activate = light_update;
418 object->desactivate = light_activate;
419 object->update = light_desactivate;
420 object->active_viewport = NULL;
422 *Light = ICOM_INTERFACE(object, IDirect3DLight);
424 TRACE("(%p) creating implementation at %p.\n", This, object);
429 static HRESULT WINAPI
430 Thunk_IDirect3DImpl_2_CreateLight(IDirect3D2 *iface,
431 IDirect3DLight **Direct3DLight,
434 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
435 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This, Direct3DLight, UnkOuter);
436 return IDirect3D3_CreateLight(ICOM_INTERFACE(This, IDirect3D3),
441 static HRESULT WINAPI
442 Thunk_IDirect3DImpl_1_CreateLight(IDirect3D *iface,
443 IDirect3DLight **Direct3DLight,
446 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
447 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This, Direct3DLight, UnkOuter);
448 return IDirect3D3_CreateLight(ICOM_INTERFACE(This, IDirect3D3),
453 /*****************************************************************************
454 * IDirect3D3::CreateMaterial
456 * Creates an IDirect3DMaterial interface. This interface is used by Direct3D3
457 * and older versions. The IDirect3DMaterial implementation wraps its
458 * functionality to IDirect3DDevice7::SetMaterial and friends.
463 * Material: Address to store the new interface's pointer to
464 * UnkOuter: Basically for aggregation, but ddraw doesn't support it.
469 * DDERR_OUTOFMEMORY if memory allocation failed
470 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
472 *****************************************************************************/
473 static HRESULT WINAPI
474 IDirect3DImpl_3_CreateMaterial(IDirect3D3 *iface,
475 IDirect3DMaterial3 **Material,
478 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
479 IDirect3DMaterialImpl *object;
481 TRACE("(%p)->(%p,%p)\n", This, Material, UnkOuter);
484 return CLASS_E_NOAGGREGATION;
486 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DMaterialImpl));
488 return DDERR_OUTOFMEMORY;
490 ICOM_INIT_INTERFACE(object, IDirect3DMaterial3, IDirect3DMaterial3_Vtbl);
491 ICOM_INIT_INTERFACE(object, IDirect3DMaterial2, IDirect3DMaterial2_Vtbl);
492 ICOM_INIT_INTERFACE(object, IDirect3DMaterial, IDirect3DMaterial_Vtbl);
494 object->ddraw = This;
495 object->activate = material_activate;
497 *Material = ICOM_INTERFACE(object, IDirect3DMaterial3);
499 TRACE("(%p) creating implementation at %p.\n", This, object);
504 static HRESULT WINAPI
505 Thunk_IDirect3DImpl_2_CreateMaterial(IDirect3D2 *iface,
506 IDirect3DMaterial2 **Direct3DMaterial,
509 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
511 IDirect3DMaterial3 *ret_val;
513 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This, Direct3DMaterial, UnkOuter);
514 ret = IDirect3D3_CreateMaterial(ICOM_INTERFACE(This, IDirect3D3),
518 *Direct3DMaterial = COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial3, IDirect3DMaterial2, ret_val);
520 TRACE(" returning interface %p.\n", *Direct3DMaterial);
525 static HRESULT WINAPI
526 Thunk_IDirect3DImpl_1_CreateMaterial(IDirect3D *iface,
527 IDirect3DMaterial **Direct3DMaterial,
530 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
532 LPDIRECT3DMATERIAL3 ret_val;
534 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This, Direct3DMaterial, UnkOuter);
535 ret = IDirect3D3_CreateMaterial(ICOM_INTERFACE(This, IDirect3D3),
539 *Direct3DMaterial = COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial3, IDirect3DMaterial, ret_val);
541 TRACE(" returning interface %p.\n", *Direct3DMaterial);
546 /*****************************************************************************
547 * IDirect3D3::CreateViewport
549 * Creates an IDirect3DViewport interface. This interface is used
550 * by Direct3D and earlier versions for Viewport management. In Direct3D7
551 * it has been replaced by a viewport structure and
552 * IDirect3DDevice7::*Viewport. Wine's IDirect3DViewport implementation
553 * uses the IDirect3DDevice7 methods for its functionality
556 * Viewport: Address to store the new interface pointer
557 * UnkOuter: Basically for aggregation, but ddraw doesn't support it.
562 * DDERR_OUTOFMEMORY if memory allocation failed
563 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
565 *****************************************************************************/
566 static HRESULT WINAPI
567 IDirect3DImpl_3_CreateViewport(IDirect3D3 *iface,
568 IDirect3DViewport3 **Viewport,
571 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
572 IDirect3DViewportImpl *object;
575 return CLASS_E_NOAGGREGATION;
577 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DViewportImpl));
579 return DDERR_OUTOFMEMORY;
581 ICOM_INIT_INTERFACE(object, IDirect3DViewport3, IDirect3DViewport3_Vtbl);
583 object->ddraw = This;
584 object->activate = viewport_activate;
585 object->use_vp2 = 0xFF;
587 object->lights = NULL;
588 object->num_lights = 0;
589 object->map_lights = 0;
591 *Viewport = ICOM_INTERFACE(object, IDirect3DViewport3);
593 TRACE("(%p) creating implementation at %p.\n",This, object);
598 static HRESULT WINAPI
599 Thunk_IDirect3DImpl_2_CreateViewport(IDirect3D2 *iface,
600 IDirect3DViewport2 **D3DViewport2,
603 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
604 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This, D3DViewport2, UnkOuter);
606 return IDirect3D3_CreateViewport(ICOM_INTERFACE(This, IDirect3D3),
607 (IDirect3DViewport3 **) D3DViewport2 /* No need to cast here */,
611 static HRESULT WINAPI
612 Thunk_IDirect3DImpl_1_CreateViewport(IDirect3D *iface,
613 IDirect3DViewport **D3DViewport,
616 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
617 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This, D3DViewport, UnkOuter);
619 return IDirect3D3_CreateViewport(ICOM_INTERFACE(This, IDirect3D3),
620 (IDirect3DViewport3 **) D3DViewport /* No need to cast here */,
624 /*****************************************************************************
625 * IDirect3D3::FindDevice
627 * This method finds a device with the requested properties and returns a
632 * D3DDFS: Describes the requested device characteristics
633 * D3DFDR: Returns the device description
637 * DDERR_INVALIDPARAMS if no device was found
639 *****************************************************************************/
640 static HRESULT WINAPI
641 IDirect3DImpl_3_FindDevice(IDirect3D3 *iface,
642 D3DFINDDEVICESEARCH *D3DDFS,
643 D3DFINDDEVICERESULT *D3DFDR)
645 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
647 D3DDEVICEDESC7 newDesc;
650 TRACE("(%p)->(%p,%p)\n", This, D3DDFS, D3DFDR);
652 if ((D3DDFS->dwFlags & D3DFDS_COLORMODEL) &&
653 (D3DDFS->dcmColorModel != D3DCOLOR_RGB))
655 TRACE(" trying to request a non-RGB D3D color model. Not supported.\n");
656 return DDERR_INVALIDPARAMS; /* No real idea what to return here :-) */
658 if (D3DDFS->dwFlags & D3DFDS_GUID)
660 TRACE(" trying to match guid %s.\n", debugstr_guid(&(D3DDFS->guid)));
661 if ((IsEqualGUID(&IID_D3DDEVICE_WineD3D, &(D3DDFS->guid)) == 0) &&
662 (IsEqualGUID(&IID_IDirect3DHALDevice, &(D3DDFS->guid)) == 0) &&
663 (IsEqualGUID(&IID_IDirect3DRefDevice, &(D3DDFS->guid)) == 0))
665 TRACE(" no match for this GUID.\n");
666 return DDERR_INVALIDPARAMS;
671 hr = IDirect3DImpl_GetCaps(This->wineD3D, &desc, &newDesc);
672 if(hr != D3D_OK) return hr;
674 /* Now return our own GUID */
675 D3DFDR->guid = IID_D3DDEVICE_WineD3D;
676 D3DFDR->ddHwDesc = desc;
677 D3DFDR->ddSwDesc = desc;
679 TRACE(" returning Wine's WineD3D device with (undumped) capabilities\n");
684 static HRESULT WINAPI
685 Thunk_IDirect3DImpl_2_FindDevice(IDirect3D2 *iface,
686 D3DFINDDEVICESEARCH *D3DDFS,
687 D3DFINDDEVICERESULT *D3DFDR)
689 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
690 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", iface, D3DDFS, D3DFDR);
691 return IDirect3D3_FindDevice(ICOM_INTERFACE(This, IDirect3D3),
696 static HRESULT WINAPI
697 Thunk_IDirect3DImpl_1_FindDevice(IDirect3D *iface,
698 D3DFINDDEVICESEARCH *D3DDFS,
699 D3DFINDDEVICERESULT *D3DDevice)
701 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
702 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This, D3DDFS, D3DDevice);
703 return IDirect3D3_FindDevice(ICOM_INTERFACE(This, IDirect3D3),
708 /*****************************************************************************
709 * IDirect3D7::CreateDevice
711 * Creates an IDirect3DDevice7 interface.
713 * Version 2, 3 and 7. IDirect3DDevice 1 interfaces are interfaces to
714 * DirectDraw surfaces and are created with
715 * IDirectDrawSurface::QueryInterface. This method uses CreateDevice to
716 * create the device object and QueryInterfaces for IDirect3DDevice
719 * refiid: IID of the device to create
720 * Surface: Inititial rendertarget
721 * Device: Address to return the interface pointer
725 * DDERR_OUTOFMEMORY if memory allocation failed
726 * DDERR_INVALIDPARAMS if a device exists already
728 *****************************************************************************/
729 static HRESULT WINAPI
730 IDirect3DImpl_7_CreateDevice(IDirect3D7 *iface,
732 IDirectDrawSurface7 *Surface,
733 IDirect3DDevice7 **Device)
735 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
736 IDirect3DDeviceImpl *object;
737 IParentImpl *IndexBufferParent;
739 IDirectDrawSurfaceImpl *target = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Surface);
740 IDirectDrawSurface7 *depthbuffer = NULL;
741 static DDSCAPS2 depthcaps = { DDSCAPS_ZBUFFER, 0, 0, 0 };
742 TRACE("(%p)->(%s,%p,%p)\n", iface, debugstr_guid(refiid), Surface, Device);
746 /* Fail device creation if non-opengl surfaces are used */
747 if(This->ImplType != SURFACE_OPENGL)
749 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");
751 /* We only hit this path if a default surface is set in the registry. Incorrect autodetection
752 * is caught in CreateSurface or QueryInterface
757 /* So far we can only create one device per ddraw object */
760 FIXME("(%p): Only one Direct3D device per DirectDraw object supported\n", This);
761 return DDERR_INVALIDPARAMS;
764 object = HeapAlloc(GetProcessHeap(), 0, sizeof(IDirect3DDeviceImpl));
767 ERR("Out of memory when allocating a IDirect3DDevice implementation\n");
768 return DDERR_OUTOFMEMORY;
771 ICOM_INIT_INTERFACE(object, IDirect3DDevice7, IDirect3DDevice7_Vtbl);
772 ICOM_INIT_INTERFACE(object, IDirect3DDevice3, IDirect3DDevice3_Vtbl);
773 ICOM_INIT_INTERFACE(object, IDirect3DDevice2, IDirect3DDevice2_Vtbl);
774 ICOM_INIT_INTERFACE(object, IDirect3DDevice, IDirect3DDevice1_Vtbl);
777 object->ddraw = This;
778 object->viewport_list = NULL;
779 object->current_viewport = NULL;
780 object->material = 0;
781 object->target = target;
783 object->Handles = NULL;
784 object->numHandles = 0;
786 /* This is for convenience */
787 object->wineD3DDevice = This->wineD3DDevice;
789 /* Create an index buffer, it's needed for indexed drawing */
790 IndexBufferParent = HeapAlloc(GetProcessHeap(), 0, sizeof(IParentImpl *));
791 if(!IndexBufferParent)
793 ERR("Allocating memory for an index buffer parent failed\n");
794 HeapFree(GetProcessHeap(), 0, object);
795 return DDERR_OUTOFMEMORY;
797 ICOM_INIT_INTERFACE(IndexBufferParent, IParent, IParent_Vtbl);
798 IndexBufferParent->ref = 1;
800 /* Create an Index Buffer. WineD3D needs one for Drawing indexed primitives
801 * Create a (hopefully) long enough buffer, and copy the indices into it
802 * Ideally, a IWineD3DIndexBuffer::SetData method could be created, which
803 * takes the pointer and avoids the memcpy
805 hr = IWineD3DDevice_CreateIndexBuffer(This->wineD3DDevice,
806 0x40000, /* Length. Don't know how long it should be */
807 WINED3DUSAGE_DYNAMIC, /* Usage */
808 WINED3DFMT_INDEX16, /* Format. D3D7 uses WORDS */
810 &object->indexbuffer,
812 (IUnknown *) ICOM_INTERFACE(IndexBufferParent, IParent));
816 ERR("Failed to create an index buffer\n");
817 HeapFree(GetProcessHeap(), 0, object);
820 IndexBufferParent->child = (IUnknown *) object->indexbuffer;
822 /* No need to set the indices, it's done when necessary */
824 /* AddRef the WineD3D Device */
825 IWineD3DDevice_AddRef(This->wineD3DDevice);
827 /* Don't forget to return the interface ;) */
828 *Device = ICOM_INTERFACE(object, IDirect3DDevice7);
830 TRACE(" (%p) Created an IDirect3DDeviceImpl object at %p\n", This, object);
832 /* This is for apps which create a non-flip, non-d3d primary surface
833 * and an offscreen D3DDEVICE surface, then render to the offscreen surface
834 * and do a Blt from the offscreen to the primary surface.
836 * Set the offscreen D3DDDEVICE surface(=target) as the back buffer,
837 * and the primary surface(=This->d3d_target) as the front buffer.
839 * This way the app will render to the D3DDEVICE surface and WineD3D
840 * will catch the Blt was Back Buffer -> Front buffer blt and perform
841 * a flip instead. This way we don't have to deal with a mixed GL / GDI
844 * This should be checked against windowed apps. The only app tested with
845 * this is moto racer 2 during the loading screen.
847 TRACE("Isrendertarget: %s, d3d_target=%p\n", target->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE ? "true" : "false", This->d3d_target);
848 if(!(target->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) &&
849 (This->d3d_target != target))
851 TRACE("(%p) Using %p as front buffer, %p as back buffer\n", This, This->d3d_target, target);
852 hr = IWineD3DDevice_SetFrontBackBuffers(This->wineD3DDevice,
853 This->d3d_target->WineD3DSurface,
854 target->WineD3DSurface);
856 ERR("(%p) Error %08x setting the front and back buffer\n", This, hr);
858 /* Render to the back buffer */
859 IWineD3DDevice_SetRenderTarget(This->wineD3DDevice, 0,
860 target->WineD3DSurface);
862 object->OffScreenTarget = TRUE;
866 object->OffScreenTarget = FALSE;
869 /* AddRef the render target. Also AddRef the render target from ddraw,
870 * because if it is released before the app releases the D3D device, the D3D capabilities
871 * of WineD3D will be uninitialized, which has bad effects.
873 * In most cases, those surfaces are the surfaces are the same anyway, but this will simply
874 * add another ref which is released when the device is destroyed.
876 IDirectDrawSurface7_AddRef(Surface);
877 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(This->d3d_target, IDirectDrawSurface7));
879 This->d3ddevice = object;
881 /* Look for a depth buffer and enable the Z test if one is found */
882 hr = IDirectDrawSurface7_GetAttachedSurface(Surface,
887 TRACE("(%p) Depth buffer found, enabling Z test\n", object);
888 IWineD3DDevice_SetRenderState(This->wineD3DDevice,
891 IDirectDrawSurface7_Release(depthbuffer);
897 static HRESULT WINAPI
898 Thunk_IDirect3DImpl_3_CreateDevice(IDirect3D3 *iface,
900 IDirectDrawSurface4 *Surface,
901 IDirect3DDevice3 **Device,
904 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
906 TRACE("(%p)->(%s,%p,%p,%p): Thunking to IDirect3D7\n", This, debugstr_guid(refiid), Surface, Device, UnkOuter);
909 return CLASS_E_NOAGGREGATION;
911 hr = IDirect3D7_CreateDevice(ICOM_INTERFACE(This, IDirect3D7),
913 (IDirectDrawSurface7 *) Surface /* Same VTables */,
914 (IDirect3DDevice7 **) Device);
916 *Device = COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice7, IDirect3DDevice3, *Device);
920 static HRESULT WINAPI
921 Thunk_IDirect3DImpl_2_CreateDevice(IDirect3D2 *iface,
923 IDirectDrawSurface *Surface,
924 IDirect3DDevice2 **Device)
926 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
928 TRACE("(%p)->(%s,%p,%p): Thunking to IDirect3D7\n", This, debugstr_guid(refiid), Surface, Device);
930 hr = IDirect3D7_CreateDevice(ICOM_INTERFACE(This, IDirect3D7),
932 COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface3, IDirectDrawSurface7, Surface),
933 (IDirect3DDevice7 **) Device);
935 *Device = COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice7, IDirect3DDevice2, *Device);
939 /*****************************************************************************
940 * IDirect3D7::CreateVertexBuffer
942 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
948 * Desc: Requested Vertex buffer properties
949 * VertexBuffer: Address to return the interface pointer at
950 * Flags: Some flags, must be 0
954 * DDERR_OUTOFMEMORY if memory allocation failed
955 * The return value of IWineD3DDevice::CreateVertexBuffer if this call fails
956 * DDERR_INVALIDPARAMS if Desc or VertexBuffer are NULL, or Flags != 0
958 *****************************************************************************/
959 static HRESULT WINAPI
960 IDirect3DImpl_7_CreateVertexBuffer(IDirect3D7 *iface,
961 D3DVERTEXBUFFERDESC *Desc,
962 IDirect3DVertexBuffer7 **VertexBuffer,
965 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
966 IDirect3DVertexBufferImpl *object;
968 TRACE("(%p)->(%p,%p,%08x)\n", This, Desc, VertexBuffer, Flags);
970 TRACE("(%p) Vertex buffer description:\n", This);
971 TRACE("(%p) dwSize=%d\n", This, Desc->dwSize);
972 TRACE("(%p) dwCaps=%08x\n", This, Desc->dwCaps);
973 TRACE("(%p) FVF=%08x\n", This, Desc->dwFVF);
974 TRACE("(%p) dwNumVertices=%d\n", This, Desc->dwNumVertices);
976 /* D3D7 SDK: "No Flags are currently defined for this method. This
977 * parameter must be 0"
979 * Never trust the documentation - this is wrong
982 ERR("(%p) Flags is %08lx, returning DDERR_INVALIDPARAMS\n", This, Flags);
983 return DDERR_INVALIDPARAMS;
987 /* Well, this sounds sane */
988 if( (!VertexBuffer) || (!Desc) )
989 return DDERR_INVALIDPARAMS;
991 /* Now create the vertex buffer */
992 object = HeapAlloc(GetProcessHeap(), 0, sizeof(IDirect3DVertexBufferImpl));
995 ERR("(%p) Out of memory when allocating a IDirect3DVertexBufferImpl structure\n", This);
996 return DDERR_OUTOFMEMORY;
1000 ICOM_INIT_INTERFACE(object, IDirect3DVertexBuffer7, IDirect3DVertexBuffer7_Vtbl);
1001 ICOM_INIT_INTERFACE(object, IDirect3DVertexBuffer, IDirect3DVertexBuffer1_Vtbl);
1003 object->Caps = Desc->dwCaps;
1004 object->ddraw = This;
1006 hr = IWineD3DDevice_CreateVertexBuffer(This->wineD3DDevice,
1007 get_flexible_vertex_size(Desc->dwFVF) * Desc->dwNumVertices,
1008 Desc->dwCaps & D3DVBCAPS_WRITEONLY ? WINED3DUSAGE_WRITEONLY : 0,
1010 Desc->dwCaps & D3DVBCAPS_SYSTEMMEMORY ? WINED3DPOOL_SYSTEMMEM : WINED3DPOOL_DEFAULT,
1011 &object->wineD3DVertexBuffer,
1012 0 /* SharedHandle */,
1013 (IUnknown *) ICOM_INTERFACE(object, IDirect3DVertexBuffer7));
1016 ERR("(%p) IWineD3DDevice::CreateVertexBuffer failed with hr=%08x\n", This, hr);
1017 HeapFree(GetProcessHeap(), 0, object);
1018 if (hr == WINED3DERR_INVALIDCALL)
1019 return DDERR_INVALIDPARAMS;
1024 object->wineD3DVertexDeclaration = IDirectDrawImpl_FindDecl(This,
1026 if(!object->wineD3DVertexDeclaration)
1028 ERR("Cannot find the vertex declaration for fvf %08x\n", Desc->dwFVF);
1029 IWineD3DVertexBuffer_Release(object->wineD3DVertexBuffer);
1030 HeapFree(GetProcessHeap(), 0, object);
1031 return DDERR_INVALIDPARAMS;
1033 IWineD3DVertexDeclaration_AddRef(object->wineD3DVertexDeclaration);
1035 /* Return the interface */
1036 *VertexBuffer = ICOM_INTERFACE(object, IDirect3DVertexBuffer7);
1038 TRACE("(%p) Created new vertex buffer implementation at %p, returning interface at %p\n", This, object, *VertexBuffer);
1042 static HRESULT WINAPI
1043 Thunk_IDirect3DImpl_3_CreateVertexBuffer(IDirect3D3 *iface,
1044 D3DVERTEXBUFFERDESC *Desc,
1045 IDirect3DVertexBuffer **VertexBuffer,
1049 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
1051 TRACE("(%p)->(%p,%p,%08x,%p): Relaying to IDirect3D7\n", This, Desc, VertexBuffer, Flags, UnkOuter);
1053 if(UnkOuter != NULL) return CLASS_E_NOAGGREGATION;
1055 hr = IDirect3D7_CreateVertexBuffer(ICOM_INTERFACE(This, IDirect3D7),
1057 (IDirect3DVertexBuffer7 **) VertexBuffer,
1060 *VertexBuffer = COM_INTERFACE_CAST(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, IDirect3DVertexBuffer, *VertexBuffer);
1065 /*****************************************************************************
1066 * IDirect3D7::EnumZBufferFormats
1068 * Enumerates all supported Z buffer pixel formats
1074 * Callback: Callback to call for each pixel format
1075 * Context: Pointer to pass back to the callback
1079 * DDERR_INVALIDPARAMS if Callback is NULL
1080 * For details, see IWineD3DDevice::EnumZBufferFormats
1082 *****************************************************************************/
1083 static HRESULT WINAPI
1084 IDirect3DImpl_7_EnumZBufferFormats(IDirect3D7 *iface,
1085 REFCLSID refiidDevice,
1086 LPD3DENUMPIXELFORMATSCALLBACK Callback,
1089 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
1093 /* Order matters. Specifically, BattleZone II (full version) expects the
1094 * 16-bit depth formats to be listed before the 24 and 32 ones. */
1095 WINED3DFORMAT FormatList[] = {
1104 TRACE("(%p)->(%s,%p,%p): Relay\n", iface, debugstr_guid(refiidDevice), Callback, Context);
1107 return DDERR_INVALIDPARAMS;
1109 for(i = 0; i < sizeof(FormatList) / sizeof(WINED3DFORMAT); i++)
1111 hr = IWineD3D_CheckDeviceFormat(This->wineD3D,
1114 0 /* AdapterFormat */,
1115 WINED3DUSAGE_DEPTHSTENCIL /* Usage */,
1116 0 /* ResourceType */,
1120 DDPIXELFORMAT pformat;
1122 memset(&pformat, 0, sizeof(pformat));
1123 pformat.dwSize = sizeof(pformat);
1124 PixelFormat_WineD3DtoDD(&pformat, FormatList[i]);
1126 TRACE("Enumerating WineD3DFormat %d\n", FormatList[i]);
1127 hr = Callback(&pformat, Context);
1128 if(hr != DDENUMRET_OK)
1130 TRACE("Format enumeration cancelled by application\n");
1135 TRACE("End of enumeration\n");
1139 static HRESULT WINAPI
1140 Thunk_IDirect3DImpl_3_EnumZBufferFormats(IDirect3D3 *iface,
1141 REFCLSID riidDevice,
1142 LPD3DENUMPIXELFORMATSCALLBACK Callback,
1145 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
1146 TRACE("(%p)->(%s,%p,%p) thunking to IDirect3D7 interface.\n", This, debugstr_guid(riidDevice), Callback, Context);
1147 return IDirect3D7_EnumZBufferFormats(ICOM_INTERFACE(This, IDirect3D7),
1153 /*****************************************************************************
1154 * IDirect3D7::EvictManagedTextures
1156 * Removes all managed textures (=surfaces with DDSCAPS2_TEXTUREMANAGE or
1157 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
1162 * D3D_OK, because it's a stub
1164 *****************************************************************************/
1165 static HRESULT WINAPI
1166 IDirect3DImpl_7_EvictManagedTextures(IDirect3D7 *iface)
1168 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
1169 FIXME("(%p): Stub!\n", This);
1171 /* Implementation idea:
1172 * Add an IWineD3DSurface method which sets the opengl texture
1173 * priority low or even removes the opengl texture.
1179 static HRESULT WINAPI
1180 Thunk_IDirect3DImpl_3_EvictManagedTextures(IDirect3D3 *iface)
1182 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
1183 TRACE("(%p)->() thunking to IDirect3D7 interface.\n", This);
1184 return IDirect3D7_EvictManagedTextures(ICOM_INTERFACE(This, IDirect3D7));
1187 /*****************************************************************************
1188 * IDirect3DImpl_GetCaps
1190 * This function retrieves the device caps from wined3d
1191 * and converts it into a D3D7 and D3D - D3D3 structure
1192 * This is a helper function called from various places in ddraw
1195 * WineD3D: The interface to get the caps from
1196 * Desc123: Old D3D <3 structure to fill (needed)
1197 * Desc7: D3D7 device desc structure to fill (needed)
1200 * D3D_OK on success, or the return value of IWineD3D::GetCaps
1202 *****************************************************************************/
1204 IDirect3DImpl_GetCaps(IWineD3D *WineD3D,
1205 D3DDEVICEDESC *Desc123,
1206 D3DDEVICEDESC7 *Desc7)
1211 /* Some Variables to asign to the pointers in WCaps */
1212 WINED3DDEVTYPE DevType;
1215 DWORD dummy_dword, MaxTextureBlendStages, MaxSimultaneousTextures;
1216 DWORD MaxUserClipPlanes, MaxVertexBlendMatrices;
1218 TRACE("()->(%p,%p,%p\n", WineD3D, Desc123, Desc7);
1220 /* Asign the pointers in WCaps */
1221 WCaps.DeviceType = &DevType;
1222 WCaps.AdapterOrdinal = &dummy_uint;
1224 WCaps.Caps = &dummy_dword;
1225 WCaps.Caps2 = &dummy_dword;
1226 WCaps.Caps3 = &dummy_dword;
1227 WCaps.PresentationIntervals = &dummy_dword;
1229 WCaps.CursorCaps = &dummy_dword;
1231 WCaps.DevCaps = &Desc7->dwDevCaps;
1232 WCaps.PrimitiveMiscCaps = &dummy_dword;
1233 WCaps.RasterCaps = &Desc7->dpcLineCaps.dwRasterCaps;
1234 WCaps.ZCmpCaps = &Desc7->dpcLineCaps.dwZCmpCaps;
1235 WCaps.SrcBlendCaps = &Desc7->dpcLineCaps.dwSrcBlendCaps;
1236 WCaps.DestBlendCaps = &Desc7->dpcLineCaps.dwDestBlendCaps;
1237 WCaps.AlphaCmpCaps = &Desc7->dpcLineCaps.dwAlphaCmpCaps;
1238 WCaps.ShadeCaps = &Desc7->dpcLineCaps.dwShadeCaps;
1239 WCaps.TextureCaps = &Desc7->dpcLineCaps.dwTextureCaps;
1240 WCaps.TextureFilterCaps = &Desc7->dpcLineCaps.dwTextureFilterCaps;
1241 WCaps.CubeTextureFilterCaps = &dummy_dword;
1242 WCaps.VolumeTextureFilterCaps = &dummy_dword;
1243 WCaps.TextureAddressCaps = &Desc7->dpcLineCaps.dwTextureAddressCaps;
1244 WCaps.VolumeTextureAddressCaps = &dummy_dword;
1246 WCaps.LineCaps = &dummy_dword;
1247 WCaps.MaxTextureWidth = &Desc7->dwMaxTextureWidth;
1248 WCaps.MaxTextureHeight = &Desc7->dwMaxTextureHeight;
1249 WCaps.MaxVolumeExtent = &dummy_dword;
1251 WCaps.MaxTextureRepeat = &Desc7->dwMaxTextureRepeat;
1252 WCaps.MaxTextureAspectRatio = &Desc7->dwMaxTextureAspectRatio;
1253 WCaps.MaxAnisotropy = &Desc7->dwMaxAnisotropy;
1254 WCaps.MaxVertexW = &Desc7->dvMaxVertexW;
1256 WCaps.GuardBandLeft = &Desc7->dvGuardBandLeft;
1257 WCaps.GuardBandTop = &Desc7->dvGuardBandTop;
1258 WCaps.GuardBandRight = &Desc7->dvGuardBandRight;
1259 WCaps.GuardBandBottom = &Desc7->dvGuardBandBottom;
1261 WCaps.ExtentsAdjust = &Desc7->dvExtentsAdjust;
1262 WCaps.StencilCaps = &Desc7->dwStencilCaps;
1264 WCaps.FVFCaps = &Desc7->dwFVFCaps;
1265 WCaps.TextureOpCaps = &Desc7->dwTextureOpCaps;
1266 WCaps.MaxTextureBlendStages = &MaxTextureBlendStages;
1267 WCaps.MaxSimultaneousTextures = &MaxSimultaneousTextures;
1269 WCaps.VertexProcessingCaps = &Desc7->dwVertexProcessingCaps;
1270 WCaps.MaxActiveLights = &Desc7->dwMaxActiveLights;
1271 WCaps.MaxUserClipPlanes = &MaxUserClipPlanes;
1272 WCaps.MaxVertexBlendMatrices = &MaxVertexBlendMatrices;
1273 WCaps.MaxVertexBlendMatrixIndex = &dummy_dword;
1275 WCaps.MaxPointSize = &dummy_float;
1276 WCaps.MaxPrimitiveCount = &dummy_dword;
1277 WCaps.MaxVertexIndex = &dummy_dword;
1278 WCaps.MaxStreams = &dummy_dword;
1279 WCaps.MaxStreamStride = &dummy_dword;
1281 WCaps.VertexShaderVersion = &dummy_dword;
1282 WCaps.MaxVertexShaderConst = &dummy_dword;
1284 WCaps.PixelShaderVersion = &dummy_dword;
1285 WCaps.PixelShader1xMaxValue = &dummy_float;
1287 /* These are dx9 only, set them to NULL */
1288 WCaps.DevCaps2 = NULL;
1289 WCaps.MaxNpatchTessellationLevel = NULL;
1290 WCaps.Reserved5 = NULL;
1291 WCaps.MasterAdapterOrdinal = NULL;
1292 WCaps.AdapterOrdinalInGroup = NULL;
1293 WCaps.NumberOfAdaptersInGroup = NULL;
1294 WCaps.DeclTypes = NULL;
1295 WCaps.NumSimultaneousRTs = NULL;
1296 WCaps.StretchRectFilterCaps = NULL;
1297 /* WCaps.VS20Caps = NULL; */
1298 /* WCaps.PS20Caps = NULL; */
1299 WCaps.VertexTextureFilterCaps = NULL;
1300 WCaps.MaxVShaderInstructionsExecuted = NULL;
1301 WCaps.MaxPShaderInstructionsExecuted = NULL;
1302 WCaps.MaxVertexShader30InstructionSlots = NULL;
1303 WCaps.MaxPixelShader30InstructionSlots = NULL;
1304 WCaps.Reserved2 = NULL;
1305 WCaps.Reserved3 = NULL;
1307 /* Now get the caps */
1308 hr = IWineD3D_GetDeviceCaps(WineD3D, 0, WINED3DDEVTYPE_HAL, &WCaps);
1309 if(hr != D3D_OK) return hr;
1311 /* Fill the missing members, and do some fixup */
1312 Desc7->dpcLineCaps.dwSize = sizeof(Desc7->dpcLineCaps);
1313 Desc7->dpcLineCaps.dwTextureBlendCaps = D3DPTBLENDCAPS_ADD | D3DPTBLENDCAPS_MODULATEMASK |
1314 D3DPTBLENDCAPS_COPY | D3DPTBLENDCAPS_DECAL |
1315 D3DPTBLENDCAPS_DECALALPHA | D3DPTBLENDCAPS_DECALMASK |
1316 D3DPTBLENDCAPS_MODULATE | D3DPTBLENDCAPS_MODULATEALPHA;
1317 Desc7->dpcLineCaps.dwStippleWidth = 32;
1318 Desc7->dpcLineCaps.dwStippleHeight = 32;
1319 /* Use the same for the TriCaps */
1320 Desc7->dpcTriCaps = Desc7->dpcLineCaps;
1322 Desc7->dwDeviceRenderBitDepth = DDBD_16 | DDBD_24 | DDBD_32;
1323 Desc7->dwDeviceZBufferBitDepth = DDBD_16 | DDBD_24;
1324 Desc7->dwMinTextureWidth = 1;
1325 Desc7->dwMinTextureHeight = 1;
1327 /* Convert DWORDs safely to WORDs */
1328 if(MaxTextureBlendStages > 65535) Desc7->wMaxTextureBlendStages = 65535;
1329 else Desc7->wMaxTextureBlendStages = (WORD) MaxTextureBlendStages;
1330 if(MaxSimultaneousTextures > 65535) Desc7->wMaxSimultaneousTextures = 65535;
1331 else Desc7->wMaxSimultaneousTextures = (WORD) MaxSimultaneousTextures;
1333 if(MaxUserClipPlanes > 65535) Desc7->wMaxUserClipPlanes = 65535;
1334 else Desc7->wMaxUserClipPlanes = (WORD) MaxUserClipPlanes;
1335 if(MaxVertexBlendMatrices > 65535) Desc7->wMaxVertexBlendMatrices = 65535;
1336 else Desc7->wMaxVertexBlendMatrices = (WORD) MaxVertexBlendMatrices;
1338 Desc7->deviceGUID = IID_IDirect3DTnLHalDevice;
1340 Desc7->dwReserved1 = 0;
1341 Desc7->dwReserved2 = 0;
1342 Desc7->dwReserved3 = 0;
1343 Desc7->dwReserved4 = 0;
1345 /* Fill the old structure */
1346 memset(Desc123, 0x0, sizeof(D3DDEVICEDESC));
1347 Desc123->dwSize = sizeof(D3DDEVICEDESC);
1348 Desc123->dwFlags = D3DDD_COLORMODEL |
1350 D3DDD_TRANSFORMCAPS |
1352 D3DDD_LIGHTINGCAPS |
1355 D3DDD_DEVICERENDERBITDEPTH |
1356 D3DDD_DEVICEZBUFFERBITDEPTH |
1357 D3DDD_MAXBUFFERSIZE |
1358 D3DDD_MAXVERTEXCOUNT;
1359 Desc123->dcmColorModel = D3DCOLOR_RGB;
1360 Desc123->dwDevCaps = Desc7->dwDevCaps;
1361 Desc123->dtcTransformCaps.dwSize = sizeof(D3DTRANSFORMCAPS);
1362 Desc123->dtcTransformCaps.dwCaps = D3DTRANSFORMCAPS_CLIP;
1363 Desc123->bClipping = TRUE;
1364 Desc123->dlcLightingCaps.dwSize = sizeof(D3DLIGHTINGCAPS);
1365 Desc123->dlcLightingCaps.dwCaps = D3DLIGHTCAPS_DIRECTIONAL | D3DLIGHTCAPS_PARALLELPOINT | D3DLIGHTCAPS_POINT | D3DLIGHTCAPS_SPOT;
1366 Desc123->dlcLightingCaps.dwLightingModel = D3DLIGHTINGMODEL_RGB;
1367 Desc123->dlcLightingCaps.dwNumLights = Desc7->dwMaxActiveLights;
1369 Desc123->dpcLineCaps.dwSize = sizeof(D3DPRIMCAPS);
1370 Desc123->dpcLineCaps.dwMiscCaps = Desc7->dpcLineCaps.dwMiscCaps;
1371 Desc123->dpcLineCaps.dwRasterCaps = Desc7->dpcLineCaps.dwRasterCaps;
1372 Desc123->dpcLineCaps.dwZCmpCaps = Desc7->dpcLineCaps.dwZCmpCaps;
1373 Desc123->dpcLineCaps.dwSrcBlendCaps = Desc7->dpcLineCaps.dwSrcBlendCaps;
1374 Desc123->dpcLineCaps.dwDestBlendCaps = Desc7->dpcLineCaps.dwDestBlendCaps;
1375 Desc123->dpcLineCaps.dwShadeCaps = Desc7->dpcLineCaps.dwShadeCaps;
1376 Desc123->dpcLineCaps.dwTextureCaps = Desc7->dpcLineCaps.dwTextureCaps;
1377 Desc123->dpcLineCaps.dwTextureFilterCaps = Desc7->dpcLineCaps.dwTextureFilterCaps;
1378 Desc123->dpcLineCaps.dwTextureBlendCaps = Desc7->dpcLineCaps.dwTextureBlendCaps;
1379 Desc123->dpcLineCaps.dwTextureAddressCaps = Desc7->dpcLineCaps.dwTextureAddressCaps;
1380 Desc123->dpcLineCaps.dwStippleWidth = Desc7->dpcLineCaps.dwStippleWidth;
1381 Desc123->dpcLineCaps.dwAlphaCmpCaps = Desc7->dpcLineCaps.dwAlphaCmpCaps;
1383 Desc123->dpcTriCaps.dwSize = sizeof(D3DPRIMCAPS);
1384 Desc123->dpcTriCaps.dwMiscCaps = Desc7->dpcTriCaps.dwMiscCaps;
1385 Desc123->dpcTriCaps.dwRasterCaps = Desc7->dpcTriCaps.dwRasterCaps;
1386 Desc123->dpcTriCaps.dwZCmpCaps = Desc7->dpcTriCaps.dwZCmpCaps;
1387 Desc123->dpcTriCaps.dwSrcBlendCaps = Desc7->dpcTriCaps.dwSrcBlendCaps;
1388 Desc123->dpcTriCaps.dwDestBlendCaps = Desc7->dpcTriCaps.dwDestBlendCaps;
1389 Desc123->dpcTriCaps.dwShadeCaps = Desc7->dpcTriCaps.dwShadeCaps;
1390 Desc123->dpcTriCaps.dwTextureCaps = Desc7->dpcTriCaps.dwTextureCaps;
1391 Desc123->dpcTriCaps.dwTextureFilterCaps = Desc7->dpcTriCaps.dwTextureFilterCaps;
1392 Desc123->dpcTriCaps.dwTextureBlendCaps = Desc7->dpcTriCaps.dwTextureBlendCaps;
1393 Desc123->dpcTriCaps.dwTextureAddressCaps = Desc7->dpcTriCaps.dwTextureAddressCaps;
1394 Desc123->dpcTriCaps.dwStippleWidth = Desc7->dpcTriCaps.dwStippleWidth;
1395 Desc123->dpcTriCaps.dwAlphaCmpCaps = Desc7->dpcTriCaps.dwAlphaCmpCaps;
1397 Desc123->dwDeviceRenderBitDepth = Desc7->dwDeviceRenderBitDepth;
1398 Desc123->dwDeviceZBufferBitDepth = Desc7->dwDeviceZBufferBitDepth;
1399 Desc123->dwMaxBufferSize = 0;
1400 Desc123->dwMaxVertexCount = 65536;
1401 Desc123->dwMinTextureWidth = Desc7->dwMinTextureWidth;
1402 Desc123->dwMinTextureHeight = Desc7->dwMinTextureHeight;
1403 Desc123->dwMaxTextureWidth = Desc7->dwMaxTextureWidth;
1404 Desc123->dwMaxTextureHeight = Desc7->dwMaxTextureHeight;
1405 Desc123->dwMinStippleWidth = 1;
1406 Desc123->dwMinStippleHeight = 1;
1407 Desc123->dwMaxStippleWidth = 32;
1408 Desc123->dwMaxStippleHeight = 32;
1409 Desc123->dwMaxTextureRepeat = Desc7->dwMaxTextureRepeat;
1410 Desc123->dwMaxTextureAspectRatio = Desc7->dwMaxTextureAspectRatio;
1411 Desc123->dwMaxAnisotropy = Desc7->dwMaxAnisotropy;
1412 Desc123->dvGuardBandLeft = Desc7->dvGuardBandLeft;
1413 Desc123->dvGuardBandRight = Desc7->dvGuardBandRight;
1414 Desc123->dvGuardBandTop = Desc7->dvGuardBandTop;
1415 Desc123->dvGuardBandBottom = Desc7->dvGuardBandBottom;
1416 Desc123->dvExtentsAdjust = Desc7->dvExtentsAdjust;
1417 Desc123->dwStencilCaps = Desc7->dwStencilCaps;
1418 Desc123->dwFVFCaps = Desc7->dwFVFCaps;
1419 Desc123->dwTextureOpCaps = Desc7->dwTextureOpCaps;
1420 Desc123->wMaxTextureBlendStages = Desc7->wMaxTextureBlendStages;
1421 Desc123->wMaxSimultaneousTextures = Desc7->wMaxSimultaneousTextures;
1425 /*****************************************************************************
1426 * IDirect3D vtables in various versions
1427 *****************************************************************************/
1429 const IDirect3DVtbl IDirect3D1_Vtbl =
1431 /*** IUnknown methods ***/
1432 Thunk_IDirect3DImpl_1_QueryInterface,
1433 Thunk_IDirect3DImpl_1_AddRef,
1434 Thunk_IDirect3DImpl_1_Release,
1435 /*** IDirect3D methods ***/
1436 IDirect3DImpl_1_Initialize,
1437 Thunk_IDirect3DImpl_1_EnumDevices,
1438 Thunk_IDirect3DImpl_1_CreateLight,
1439 Thunk_IDirect3DImpl_1_CreateMaterial,
1440 Thunk_IDirect3DImpl_1_CreateViewport,
1441 Thunk_IDirect3DImpl_1_FindDevice
1444 const IDirect3D2Vtbl IDirect3D2_Vtbl =
1446 /*** IUnknown methods ***/
1447 Thunk_IDirect3DImpl_2_QueryInterface,
1448 Thunk_IDirect3DImpl_2_AddRef,
1449 Thunk_IDirect3DImpl_2_Release,
1450 /*** IDirect3D2 methods ***/
1451 Thunk_IDirect3DImpl_2_EnumDevices,
1452 Thunk_IDirect3DImpl_2_CreateLight,
1453 Thunk_IDirect3DImpl_2_CreateMaterial,
1454 Thunk_IDirect3DImpl_2_CreateViewport,
1455 Thunk_IDirect3DImpl_2_FindDevice,
1456 Thunk_IDirect3DImpl_2_CreateDevice
1459 const IDirect3D3Vtbl IDirect3D3_Vtbl =
1461 /*** IUnknown methods ***/
1462 Thunk_IDirect3DImpl_3_QueryInterface,
1463 Thunk_IDirect3DImpl_3_AddRef,
1464 Thunk_IDirect3DImpl_3_Release,
1465 /*** IDirect3D3 methods ***/
1466 IDirect3DImpl_3_EnumDevices,
1467 IDirect3DImpl_3_CreateLight,
1468 IDirect3DImpl_3_CreateMaterial,
1469 IDirect3DImpl_3_CreateViewport,
1470 IDirect3DImpl_3_FindDevice,
1471 Thunk_IDirect3DImpl_3_CreateDevice,
1472 Thunk_IDirect3DImpl_3_CreateVertexBuffer,
1473 Thunk_IDirect3DImpl_3_EnumZBufferFormats,
1474 Thunk_IDirect3DImpl_3_EvictManagedTextures
1477 const IDirect3D7Vtbl IDirect3D7_Vtbl =
1479 /*** IUnknown methods ***/
1480 Thunk_IDirect3DImpl_7_QueryInterface,
1481 Thunk_IDirect3DImpl_7_AddRef,
1482 Thunk_IDirect3DImpl_7_Release,
1483 /*** IDirect3D7 methods ***/
1484 IDirect3DImpl_7_EnumDevices,
1485 IDirect3DImpl_7_CreateDevice,
1486 IDirect3DImpl_7_CreateVertexBuffer,
1487 IDirect3DImpl_7_EnumZBufferFormats,
1488 IDirect3DImpl_7_EvictManagedTextures