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"
34 #include "wine/exception.h"
39 #include "ddraw_private.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(d3d7);
43 /*****************************************************************************
44 * IDirect3D7::QueryInterface
46 * QueryInterface implementation with thunks to IDirectDraw7
48 *****************************************************************************/
50 Thunk_IDirect3DImpl_7_QueryInterface(IDirect3D7 *iface,
54 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
55 TRACE("(%p)->(%s,%p): Thunking to IDirectDraw7\n", This, debugstr_guid(refiid), obj);
57 return IDirectDraw7_QueryInterface(ICOM_INTERFACE(This, IDirectDraw7),
63 Thunk_IDirect3DImpl_3_QueryInterface(IDirect3D3 *iface,
67 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
68 TRACE("(%p)->(%s,%p): Thunking to IDirectDraw7\n", This, debugstr_guid(refiid), obj);
70 return IDirectDraw7_QueryInterface(ICOM_INTERFACE(This, IDirectDraw7),
76 Thunk_IDirect3DImpl_2_QueryInterface(IDirect3D2 *iface,
80 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
81 TRACE("(%p)->(%s,%p): Thunking to IDirectDraw7\n", This, debugstr_guid(refiid), obj);
83 return IDirectDraw7_QueryInterface(ICOM_INTERFACE(This, IDirectDraw7),
89 Thunk_IDirect3DImpl_1_QueryInterface(IDirect3D *iface,
93 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
94 TRACE("(%p)->(%s,%p): Thunking to IDirectDraw7\n", This, debugstr_guid(refiid), obj);
96 return IDirectDraw7_QueryInterface(ICOM_INTERFACE(This, IDirectDraw7),
101 /*****************************************************************************
104 * DirectDraw refcounting is a bit odd. Every version of the ddraw interface
105 * has its own refcount, but IDirect3D 1/2/3 refcounts are linked to
106 * IDirectDraw, and IDirect3D7 is linked to IDirectDraw7
108 * IDirect3D7 -> IDirectDraw7
109 * IDirect3D3 -> IDirectDraw
110 * IDirect3D2 -> IDirectDraw
111 * IDirect3D -> IDirectDraw
113 * So every AddRef implementation thunks to a different interface, and the
114 * IDirectDrawX::AddRef implementations have different counters...
119 *****************************************************************************/
121 Thunk_IDirect3DImpl_7_AddRef(IDirect3D7 *iface)
123 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
124 TRACE("(%p) : Thunking to IDirectDraw7.\n", This);
126 return IDirectDraw7_AddRef(ICOM_INTERFACE(This, IDirectDraw7));
130 Thunk_IDirect3DImpl_3_AddRef(IDirect3D3 *iface)
132 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
133 TRACE("(%p) : Thunking to IDirectDraw.\n", This);
135 return IDirectDraw_AddRef(ICOM_INTERFACE(This, IDirectDraw));
139 Thunk_IDirect3DImpl_2_AddRef(IDirect3D2 *iface)
141 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
142 TRACE("(%p) : Thunking to IDirectDraw.\n", This);
144 return IDirectDraw_AddRef(ICOM_INTERFACE(This, IDirectDraw));
148 Thunk_IDirect3DImpl_1_AddRef(IDirect3D *iface)
150 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
151 TRACE("(%p) : Thunking to IDirectDraw.\n", This);
153 return IDirectDraw_AddRef(ICOM_INTERFACE(This, IDirectDraw));
156 /*****************************************************************************
157 * IDirect3D7::Release
159 * Same story as IDirect3D7::AddRef
161 * Returns: The new refcount
163 *****************************************************************************/
165 Thunk_IDirect3DImpl_7_Release(IDirect3D7 *iface)
167 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
168 TRACE("(%p) : Thunking to IDirectDraw7.\n", This);
170 return IDirectDraw7_Release(ICOM_INTERFACE(This, IDirectDraw7));
174 Thunk_IDirect3DImpl_3_Release(IDirect3D3 *iface)
176 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
177 TRACE("(%p) : Thunking to IDirectDraw.\n", This);
179 return IDirectDraw_Release(ICOM_INTERFACE(This, IDirectDraw));
183 Thunk_IDirect3DImpl_2_Release(IDirect3D2 *iface)
185 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
186 TRACE("(%p) : Thunking to IDirectDraw.\n", This);
188 return IDirectDraw_Release(ICOM_INTERFACE(This, IDirectDraw));
192 Thunk_IDirect3DImpl_1_Release(IDirect3D *iface)
194 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
195 TRACE("(%p) : Thunking to IDirectDraw.\n", This);
197 return IDirectDraw_Release(ICOM_INTERFACE(This, IDirectDraw));
200 /*****************************************************************************
202 *****************************************************************************/
204 /*****************************************************************************
205 * IDirect3D::Initialize
207 * Initializes the IDirect3D interface. This is a no-op implementation,
208 * as all initialization is done at create time.
216 * D3D_OK, because it's a no-op
218 *****************************************************************************/
219 static HRESULT WINAPI
220 IDirect3DImpl_1_Initialize(IDirect3D *iface,
223 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
225 TRACE("(%p)->(%s) no-op...\n", This, debugstr_guid(refiid));
229 /*****************************************************************************
230 * IDirect3D7::EnumDevices
232 * The EnumDevices method for IDirect3D7. It enumerates all supported
233 * D3D7 devices. Currently there's only one.
236 * Callback: Function to call for each enumerated device
237 * Context: Pointer to pass back to the app
240 * D3D_OK, or the return value of the GetCaps call
242 *****************************************************************************/
243 static HRESULT WINAPI
244 IDirect3DImpl_7_EnumDevices(IDirect3D7 *iface,
245 LPD3DENUMDEVICESCALLBACK7 Callback,
248 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
249 char interface_name[] = "WINE Direct3D7 using WineD3D";
250 char device_name[] = "Wine D3D7 device";
251 D3DDEVICEDESC7 ddesc;
252 D3DDEVICEDESC oldDesc;
255 TRACE("(%p)->(%p,%p)\n", This, Callback, Context);
257 TRACE("(%p) Enumerating WineD3D D3Device7 interface\n", This);
258 hr = IDirect3DImpl_GetCaps(This->wineD3D, &oldDesc, &ddesc);
259 if(hr != D3D_OK) return hr;
260 Callback(interface_name, device_name, &ddesc, Context);
262 TRACE("(%p) End of enumeration\n", This);
266 /*****************************************************************************
267 * IDirect3D3::EnumDevices
269 * Enumerates all supported Direct3DDevice interfaces. This is the
270 * implementation for Direct3D 1 to Direc3D 3, Version 7 has its own.
275 * Callback: Application-provided routine to call for each enumerated device
276 * Context: Pointer to pass to the callback
280 * The result of IDirect3DImpl_GetCaps if it failed
282 *****************************************************************************/
283 static HRESULT WINAPI
284 IDirect3DImpl_3_EnumDevices(IDirect3D3 *iface,
285 LPD3DENUMDEVICESCALLBACK Callback,
288 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
289 D3DDEVICEDESC dref, d1, d2;
290 D3DDEVICEDESC7 newDesc;
291 static CHAR wined3d_description[] = "Wine D3DDevice using WineD3D and OpenGL";
294 /* Some games (Motoracer 2 demo) have the bad idea to modify the device name string.
295 Let's put the string in a sufficiently sized array in writable memory. */
296 char device_name[50];
297 strcpy(device_name,"direct3d");
299 TRACE("(%p)->(%p,%p)\n", This, Callback, Context);
301 hr = IDirect3DImpl_GetCaps(This->wineD3D, &dref, &newDesc);
302 if(hr != D3D_OK) return hr;
304 /* Do I have to enumerate the reference id? Note from old d3d7:
305 * "It seems that enumerating the reference IID on Direct3D 1 games
306 * (AvP / Motoracer2) breaks them". So do not enumerate this iid in V1
308 * There's a registry key HKLM\Software\Microsoft\Direct3D\Drivers, EnumReference
309 * which enables / disables enumerating the reference rasterizer. It's a DWORD,
310 * 0 means disabled, 2 means enabled. The enablerefrast.reg and disablerefrast.reg
311 * files in the DirectX 7.0 sdk demo directory suggest this.
313 * Some games(GTA 2) seem to use the second enumerated device, so I have to enumerate
314 * at least 2 devices. So enumerate the reference device to have 2 devices.
317 if(This->d3dversion != 1)
319 static CHAR reference_description[] = "Reference Direct3D ID";
321 TRACE("(%p) Enumerating WineD3D D3DDevice interface\n", This);
324 hr = Callback( (LPIID) &IID_IDirect3DRefDevice, reference_description, device_name, &d1, &d2, Context);
325 if(hr != D3DENUMRET_OK)
327 TRACE("Application cancelled the enumeration\n");
332 TRACE("(%p) Enumerating WineD3D D3DDevice interface\n", This);
335 hr = Callback( (LPIID) &IID_D3DDEVICE_WineD3D, wined3d_description, device_name, &d1, &d2, Context);
336 if(hr != D3DENUMRET_OK)
338 TRACE("Application cancelled the enumeration\n");
341 TRACE("(%p) End of enumeration\n", This);
346 static HRESULT WINAPI
347 Thunk_IDirect3DImpl_2_EnumDevices(IDirect3D2 *iface,
348 LPD3DENUMDEVICESCALLBACK Callback,
351 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
352 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This, Callback, Context);
353 return IDirect3D3_EnumDevices(ICOM_INTERFACE(This, IDirect3D3),
358 static HRESULT WINAPI
359 Thunk_IDirect3DImpl_1_EnumDevices(IDirect3D *iface,
360 LPD3DENUMDEVICESCALLBACK Callback,
363 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
364 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This, Callback, Context);
365 return IDirect3D3_EnumDevices(ICOM_INTERFACE(This, IDirect3D3),
370 /*****************************************************************************
371 * IDirect3D3::CreateLight
373 * Creates an IDirect3DLight interface. This interface is used in
374 * Direct3D3 or earlier for lighting. In Direct3D7 it has been replaced
375 * by the DIRECT3DLIGHT7 structure. Wine's Direct3DLight implementation
376 * uses the IDirect3DDevice7 interface with D3D7 lights.
381 * Light: Address to store the new interface pointer
382 * UnkOuter: Basically for aggregation, but ddraw doesn't support it.
387 * DDERR_OUTOFMEMORY if memory allocation failed
388 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
390 *****************************************************************************/
391 static HRESULT WINAPI
392 IDirect3DImpl_3_CreateLight(IDirect3D3 *iface,
393 IDirect3DLight **Light,
396 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
397 IDirect3DLightImpl *object;
399 TRACE("(%p)->(%p,%p)\n", This, Light, UnkOuter);
402 return CLASS_E_NOAGGREGATION;
404 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DLightImpl));
406 return DDERR_OUTOFMEMORY;
408 ICOM_INIT_INTERFACE(object, IDirect3DLight, IDirect3DLight_Vtbl);
410 object->ddraw = This;
412 object->active_viewport = NULL;
414 /* Update functions */
415 object->activate = light_update;
416 object->desactivate = light_activate;
417 object->update = light_desactivate;
418 object->active_viewport = NULL;
420 *Light = ICOM_INTERFACE(object, IDirect3DLight);
422 TRACE("(%p) creating implementation at %p.\n", This, object);
427 static HRESULT WINAPI
428 Thunk_IDirect3DImpl_2_CreateLight(IDirect3D2 *iface,
429 IDirect3DLight **Direct3DLight,
432 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
433 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This, Direct3DLight, UnkOuter);
434 return IDirect3D3_CreateLight(ICOM_INTERFACE(This, IDirect3D3),
439 static HRESULT WINAPI
440 Thunk_IDirect3DImpl_1_CreateLight(IDirect3D *iface,
441 IDirect3DLight **Direct3DLight,
444 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
445 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This, Direct3DLight, UnkOuter);
446 return IDirect3D3_CreateLight(ICOM_INTERFACE(This, IDirect3D3),
451 /*****************************************************************************
452 * IDirect3D3::CreateMaterial
454 * Creates an IDirect3DMaterial interface. This interface is used by Direct3D3
455 * and older versions. The IDirect3DMaterial implementation wraps its
456 * functionality to IDirect3DDevice7::SetMaterial and friends.
461 * Material: Address to store the new interface's pointer to
462 * UnkOuter: Basically for aggregation, but ddraw doesn't support it.
467 * DDERR_OUTOFMEMORY if memory allocation failed
468 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
470 *****************************************************************************/
471 static HRESULT WINAPI
472 IDirect3DImpl_3_CreateMaterial(IDirect3D3 *iface,
473 IDirect3DMaterial3 **Material,
476 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
477 IDirect3DMaterialImpl *object;
479 TRACE("(%p)->(%p,%p)\n", This, Material, UnkOuter);
482 return CLASS_E_NOAGGREGATION;
484 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DMaterialImpl));
486 return DDERR_OUTOFMEMORY;
488 ICOM_INIT_INTERFACE(object, IDirect3DMaterial3, IDirect3DMaterial3_Vtbl);
489 ICOM_INIT_INTERFACE(object, IDirect3DMaterial2, IDirect3DMaterial2_Vtbl);
490 ICOM_INIT_INTERFACE(object, IDirect3DMaterial, IDirect3DMaterial_Vtbl);
492 object->ddraw = This;
493 object->activate = material_activate;
495 *Material = ICOM_INTERFACE(object, IDirect3DMaterial3);
497 TRACE("(%p) creating implementation at %p.\n", This, object);
502 static HRESULT WINAPI
503 Thunk_IDirect3DImpl_2_CreateMaterial(IDirect3D2 *iface,
504 IDirect3DMaterial2 **Direct3DMaterial,
507 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
509 IDirect3DMaterial3 *ret_val;
511 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This, Direct3DMaterial, UnkOuter);
512 ret = IDirect3D3_CreateMaterial(ICOM_INTERFACE(This, IDirect3D3),
516 *Direct3DMaterial = COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial3, IDirect3DMaterial2, ret_val);
518 TRACE(" returning interface %p.\n", *Direct3DMaterial);
523 static HRESULT WINAPI
524 Thunk_IDirect3DImpl_1_CreateMaterial(IDirect3D *iface,
525 IDirect3DMaterial **Direct3DMaterial,
528 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
530 LPDIRECT3DMATERIAL3 ret_val;
532 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This, Direct3DMaterial, UnkOuter);
533 ret = IDirect3D3_CreateMaterial(ICOM_INTERFACE(This, IDirect3D3),
537 *Direct3DMaterial = COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial3, IDirect3DMaterial, ret_val);
539 TRACE(" returning interface %p.\n", *Direct3DMaterial);
544 /*****************************************************************************
545 * IDirect3D3::CreateViewport
547 * Creates an IDirect3DViewport interface. This interface is used
548 * by Direct3D and earlier versions for Viewport management. In Direct3D7
549 * it has been replaced by a viewport structure and
550 * IDirect3DDevice7::*Viewport. Wine's IDirect3DViewport implementation
551 * uses the IDirect3DDevice7 methods for its functionality
554 * Viewport: Address to store the new interface pointer
555 * UnkOuter: Basically for aggregation, but ddraw doesn't support it.
560 * DDERR_OUTOFMEMORY if memory allocation failed
561 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
563 *****************************************************************************/
564 static HRESULT WINAPI
565 IDirect3DImpl_3_CreateViewport(IDirect3D3 *iface,
566 IDirect3DViewport3 **Viewport,
569 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
570 IDirect3DViewportImpl *object;
573 return CLASS_E_NOAGGREGATION;
575 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DViewportImpl));
577 return DDERR_OUTOFMEMORY;
579 ICOM_INIT_INTERFACE(object, IDirect3DViewport3, IDirect3DViewport3_Vtbl);
581 object->ddraw = This;
582 object->activate = viewport_activate;
583 object->use_vp2 = 0xFF;
585 object->lights = NULL;
586 object->num_lights = 0;
587 object->map_lights = 0;
589 *Viewport = ICOM_INTERFACE(object, IDirect3DViewport3);
591 TRACE("(%p) creating implementation at %p.\n",This, object);
596 static HRESULT WINAPI
597 Thunk_IDirect3DImpl_2_CreateViewport(IDirect3D2 *iface,
598 IDirect3DViewport2 **D3DViewport2,
601 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
602 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This, D3DViewport2, UnkOuter);
604 return IDirect3D3_CreateViewport(ICOM_INTERFACE(This, IDirect3D3),
605 (IDirect3DViewport3 **) D3DViewport2 /* No need to cast here */,
609 static HRESULT WINAPI
610 Thunk_IDirect3DImpl_1_CreateViewport(IDirect3D *iface,
611 IDirect3DViewport **D3DViewport,
614 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
615 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This, D3DViewport, UnkOuter);
617 return IDirect3D3_CreateViewport(ICOM_INTERFACE(This, IDirect3D3),
618 (IDirect3DViewport3 **) D3DViewport /* No need to cast here */,
622 /*****************************************************************************
623 * IDirect3D3::FindDevice
625 * This method finds a device with the requested properties and returns a
630 * D3DDFS: Describes the requested device characteristics
631 * D3DFDR: Returns the device description
635 * DDERR_INVALIDPARAMS if no device was found
637 *****************************************************************************/
638 static HRESULT WINAPI
639 IDirect3DImpl_3_FindDevice(IDirect3D3 *iface,
640 D3DFINDDEVICESEARCH *D3DDFS,
641 D3DFINDDEVICERESULT *D3DFDR)
643 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
645 D3DDEVICEDESC7 newDesc;
648 TRACE("(%p)->(%p,%p)\n", This, D3DDFS, D3DFDR);
650 if ((D3DDFS->dwFlags & D3DFDS_COLORMODEL) &&
651 (D3DDFS->dcmColorModel != D3DCOLOR_RGB))
653 TRACE(" trying to request a non-RGB D3D color model. Not supported.\n");
654 return DDERR_INVALIDPARAMS; /* No real idea what to return here :-) */
656 if (D3DDFS->dwFlags & D3DFDS_GUID)
658 TRACE(" trying to match guid %s.\n", debugstr_guid(&(D3DDFS->guid)));
659 if ((IsEqualGUID(&IID_D3DDEVICE_WineD3D, &(D3DDFS->guid)) == 0) &&
660 (IsEqualGUID(&IID_IDirect3DHALDevice, &(D3DDFS->guid)) == 0) &&
661 (IsEqualGUID(&IID_IDirect3DRefDevice, &(D3DDFS->guid)) == 0))
663 TRACE(" no match for this GUID.\n");
664 return DDERR_INVALIDPARAMS;
669 hr = IDirect3DImpl_GetCaps(This->wineD3D, &desc, &newDesc);
670 if(hr != D3D_OK) return hr;
672 /* Now return our own GUID */
673 D3DFDR->guid = IID_D3DDEVICE_WineD3D;
674 D3DFDR->ddHwDesc = desc;
675 D3DFDR->ddSwDesc = desc;
677 TRACE(" returning Wine's WineD3D device with (undumped) capabilities\n");
682 static HRESULT WINAPI
683 Thunk_IDirect3DImpl_2_FindDevice(IDirect3D2 *iface,
684 D3DFINDDEVICESEARCH *D3DDFS,
685 D3DFINDDEVICERESULT *D3DFDR)
687 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
688 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", iface, D3DDFS, D3DFDR);
689 return IDirect3D3_FindDevice(ICOM_INTERFACE(This, IDirect3D3),
694 static HRESULT WINAPI
695 Thunk_IDirect3DImpl_1_FindDevice(IDirect3D *iface,
696 D3DFINDDEVICESEARCH *D3DDFS,
697 D3DFINDDEVICERESULT *D3DDevice)
699 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
700 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This, D3DDFS, D3DDevice);
701 return IDirect3D3_FindDevice(ICOM_INTERFACE(This, IDirect3D3),
706 /*****************************************************************************
707 * IDirect3D7::CreateDevice
709 * Creates an IDirect3DDevice7 interface.
711 * Version 2, 3 and 7. IDirect3DDevice 1 interfaces are interfaces to
712 * DirectDraw surfaces and are created with
713 * IDirectDrawSurface::QueryInterface. This method uses CreateDevice to
714 * create the device object and QueryInterfaces for IDirect3DDevice
717 * refiid: IID of the device to create
718 * Surface: Inititial rendertarget
719 * Device: Address to return the interface pointer
723 * DDERR_OUTOFMEMORY if memory allocation failed
724 * DDERR_INVALIDPARAMS if a device exists already
726 *****************************************************************************/
727 static HRESULT WINAPI
728 IDirect3DImpl_7_CreateDevice(IDirect3D7 *iface,
730 IDirectDrawSurface7 *Surface,
731 IDirect3DDevice7 **Device)
733 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
734 IDirect3DDeviceImpl *object;
735 IParentImpl *IndexBufferParent;
737 IDirectDrawSurfaceImpl *target = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Surface);
738 TRACE("(%p)->(%s,%p,%p)\n", iface, debugstr_guid(refiid), Surface, Device);
742 /* Fail device creation if non-opengl surfaces are used */
743 if(This->ImplType != SURFACE_OPENGL)
745 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");
747 /* We only hit this path if a default surface is set in the registry. Incorrect autodetection
748 * is caught in CreateSurface or QueryInterface
753 /* So far we can only create one device per ddraw object */
756 FIXME("(%p): Only one Direct3D device per DirectDraw object supported\n", This);
757 return DDERR_INVALIDPARAMS;
760 object = HeapAlloc(GetProcessHeap(), 0, sizeof(IDirect3DDeviceImpl));
763 ERR("Out of memory when allocating a IDirect3DDevice implementation\n");
764 return DDERR_OUTOFMEMORY;
767 ICOM_INIT_INTERFACE(object, IDirect3DDevice7, IDirect3DDevice7_Vtbl);
768 ICOM_INIT_INTERFACE(object, IDirect3DDevice3, IDirect3DDevice3_Vtbl);
769 ICOM_INIT_INTERFACE(object, IDirect3DDevice2, IDirect3DDevice2_Vtbl);
770 ICOM_INIT_INTERFACE(object, IDirect3DDevice, IDirect3DDevice1_Vtbl);
773 object->ddraw = This;
774 object->viewport_list = NULL;
775 object->current_viewport = NULL;
776 object->material = 0;
777 object->target = target;
779 object->Handles = NULL;
780 object->numHandles = 0;
782 /* This is for convenience */
783 object->wineD3DDevice = This->wineD3DDevice;
785 /* Create an index buffer, it's needed for indexed drawing */
786 IndexBufferParent = HeapAlloc(GetProcessHeap(), 0, sizeof(IParentImpl *));
787 if(!IndexBufferParent)
789 ERR("Allocating memory for an index buffer parent failed\n");
790 HeapFree(GetProcessHeap(), 0, object);
791 return DDERR_OUTOFMEMORY;
793 ICOM_INIT_INTERFACE(IndexBufferParent, IParent, IParent_Vtbl);
794 IndexBufferParent->ref = 1;
796 /* Create an Index Buffer. WineD3D needs one for Drawing indexed primitives
797 * Create a (hopefully) long enough buffer, and copy the indices into it
798 * Ideally, a IWineD3DIndexBuffer::SetData method could be created, which
799 * takes the pointer and avoids the memcpy
801 hr = IWineD3DDevice_CreateIndexBuffer(This->wineD3DDevice,
802 0x40000, /* Length. Don't know how long it should be */
803 WINED3DUSAGE_DYNAMIC, /* Usage */
804 WINED3DFMT_INDEX16, /* Format. D3D7 uses WORDS */
806 &object->indexbuffer,
808 (IUnknown *) ICOM_INTERFACE(IndexBufferParent, IParent));
812 ERR("Failed to create an index buffer\n");
813 HeapFree(GetProcessHeap(), 0, object);
816 IndexBufferParent->child = (IUnknown *) object->indexbuffer;
818 /* No need to set the indices, it's done when necessary */
820 /* AddRef the WineD3D Device */
821 IWineD3DDevice_AddRef(This->wineD3DDevice);
823 /* Don't forget to return the interface ;) */
824 *Device = ICOM_INTERFACE(object, IDirect3DDevice7);
826 TRACE(" (%p) Created an IDirect3DDeviceImpl object at %p\n", This, object);
828 /* This is for apps which create a non-flip, non-d3d primary surface
829 * and an offscreen D3DDEVICE surface, then render to the offscreen surface
830 * and do a Blt from the offscreen to the primary surface.
832 * Set the offscreen D3DDDEVICE surface(=target) as the back buffer,
833 * and the primary surface(=This->d3d_target) as the front buffer.
835 * This way the app will render to the D3DDEVICE surface and WineD3D
836 * will catch the Blt was Back Buffer -> Front buffer blt and perform
837 * a flip instead. This way we don't have to deal with a mixed GL / GDI
840 * This should be checked against windowed apps. The only app tested with
841 * this is moto racer 2 during the loading screen.
843 TRACE("Isrendertarget: %s, d3d_target=%p\n", target->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE ? "true" : "false", This->d3d_target);
844 if(!(target->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) &&
845 (This->d3d_target != target))
847 TRACE("(%p) Using %p as front buffer, %p as back buffer\n", This, This->d3d_target, target);
848 hr = IWineD3DDevice_SetFrontBackBuffers(This->wineD3DDevice,
849 This->d3d_target->WineD3DSurface,
850 target->WineD3DSurface);
852 ERR("(%p) Error %08x setting the front and back buffer\n", This, hr);
854 /* Render to the back buffer */
855 IWineD3DDevice_SetRenderTarget(This->wineD3DDevice, 0,
856 target->WineD3DSurface);
858 object->OffScreenTarget = TRUE;
862 object->OffScreenTarget = FALSE;
865 /* AddRef the render target. Also AddRef the render target from ddraw,
866 * because if it is released before the app releases the D3D device, the D3D capabilities
867 * of WineD3D will be uninitialized, which has bad effects.
869 * In most cases, those surfaces are the surfaces are the same anyway, but this will simply
870 * add another ref which is released when the device is destroyed.
872 IDirectDrawSurface7_AddRef(Surface);
873 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(This->d3d_target, IDirectDrawSurface7));
875 This->d3ddevice = object;
877 IWineD3DDevice_SetRenderState(This->wineD3DDevice,
879 IDirect3DDeviceImpl_UpdateDepthStencil(object));
883 static HRESULT WINAPI
884 Thunk_IDirect3DImpl_3_CreateDevice(IDirect3D3 *iface,
886 IDirectDrawSurface4 *Surface,
887 IDirect3DDevice3 **Device,
890 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
892 TRACE("(%p)->(%s,%p,%p,%p): Thunking to IDirect3D7\n", This, debugstr_guid(refiid), Surface, Device, UnkOuter);
895 return CLASS_E_NOAGGREGATION;
897 hr = IDirect3D7_CreateDevice(ICOM_INTERFACE(This, IDirect3D7),
899 (IDirectDrawSurface7 *) Surface /* Same VTables */,
900 (IDirect3DDevice7 **) Device);
902 *Device = COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice7, IDirect3DDevice3, *Device);
906 static HRESULT WINAPI
907 Thunk_IDirect3DImpl_2_CreateDevice(IDirect3D2 *iface,
909 IDirectDrawSurface *Surface,
910 IDirect3DDevice2 **Device)
912 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
914 TRACE("(%p)->(%s,%p,%p): Thunking to IDirect3D7\n", This, debugstr_guid(refiid), Surface, Device);
916 hr = IDirect3D7_CreateDevice(ICOM_INTERFACE(This, IDirect3D7),
918 COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface3, IDirectDrawSurface7, Surface),
919 (IDirect3DDevice7 **) Device);
921 *Device = COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice7, IDirect3DDevice2, *Device);
925 /*****************************************************************************
926 * IDirect3D7::CreateVertexBuffer
928 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
934 * Desc: Requested Vertex buffer properties
935 * VertexBuffer: Address to return the interface pointer at
936 * Flags: Some flags, must be 0
940 * DDERR_OUTOFMEMORY if memory allocation failed
941 * The return value of IWineD3DDevice::CreateVertexBuffer if this call fails
942 * DDERR_INVALIDPARAMS if Desc or VertexBuffer are NULL, or Flags != 0
944 *****************************************************************************/
945 static HRESULT WINAPI
946 IDirect3DImpl_7_CreateVertexBuffer(IDirect3D7 *iface,
947 D3DVERTEXBUFFERDESC *Desc,
948 IDirect3DVertexBuffer7 **VertexBuffer,
951 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
952 IDirect3DVertexBufferImpl *object;
954 TRACE("(%p)->(%p,%p,%08x)\n", This, Desc, VertexBuffer, Flags);
956 TRACE("(%p) Vertex buffer description:\n", This);
957 TRACE("(%p) dwSize=%d\n", This, Desc->dwSize);
958 TRACE("(%p) dwCaps=%08x\n", This, Desc->dwCaps);
959 TRACE("(%p) FVF=%08x\n", This, Desc->dwFVF);
960 TRACE("(%p) dwNumVertices=%d\n", This, Desc->dwNumVertices);
962 /* D3D7 SDK: "No Flags are currently defined for this method. This
963 * parameter must be 0"
965 * Never trust the documentation - this is wrong
968 ERR("(%p) Flags is %08lx, returning DDERR_INVALIDPARAMS\n", This, Flags);
969 return DDERR_INVALIDPARAMS;
973 /* Well, this sounds sane */
974 if( (!VertexBuffer) || (!Desc) )
975 return DDERR_INVALIDPARAMS;
977 /* Now create the vertex buffer */
978 object = HeapAlloc(GetProcessHeap(), 0, sizeof(IDirect3DVertexBufferImpl));
981 ERR("(%p) Out of memory when allocating a IDirect3DVertexBufferImpl structure\n", This);
982 return DDERR_OUTOFMEMORY;
986 ICOM_INIT_INTERFACE(object, IDirect3DVertexBuffer7, IDirect3DVertexBuffer7_Vtbl);
987 ICOM_INIT_INTERFACE(object, IDirect3DVertexBuffer, IDirect3DVertexBuffer1_Vtbl);
989 object->Caps = Desc->dwCaps;
990 object->ddraw = This;
992 hr = IWineD3DDevice_CreateVertexBuffer(This->wineD3DDevice,
993 get_flexible_vertex_size(Desc->dwFVF) * Desc->dwNumVertices,
994 Desc->dwCaps & D3DVBCAPS_WRITEONLY ? WINED3DUSAGE_WRITEONLY : 0,
996 Desc->dwCaps & D3DVBCAPS_SYSTEMMEMORY ? WINED3DPOOL_SYSTEMMEM : WINED3DPOOL_DEFAULT,
997 &object->wineD3DVertexBuffer,
998 0 /* SharedHandle */,
999 (IUnknown *) ICOM_INTERFACE(object, IDirect3DVertexBuffer7));
1002 ERR("(%p) IWineD3DDevice::CreateVertexBuffer failed with hr=%08x\n", This, hr);
1003 HeapFree(GetProcessHeap(), 0, object);
1004 if (hr == WINED3DERR_INVALIDCALL)
1005 return DDERR_INVALIDPARAMS;
1010 object->wineD3DVertexDeclaration = IDirectDrawImpl_FindDecl(This,
1012 if(!object->wineD3DVertexDeclaration)
1014 ERR("Cannot find the vertex declaration for fvf %08x\n", Desc->dwFVF);
1015 IWineD3DVertexBuffer_Release(object->wineD3DVertexBuffer);
1016 HeapFree(GetProcessHeap(), 0, object);
1017 return DDERR_INVALIDPARAMS;
1019 IWineD3DVertexDeclaration_AddRef(object->wineD3DVertexDeclaration);
1021 /* Return the interface */
1022 *VertexBuffer = ICOM_INTERFACE(object, IDirect3DVertexBuffer7);
1024 TRACE("(%p) Created new vertex buffer implementation at %p, returning interface at %p\n", This, object, *VertexBuffer);
1028 static HRESULT WINAPI
1029 Thunk_IDirect3DImpl_3_CreateVertexBuffer(IDirect3D3 *iface,
1030 D3DVERTEXBUFFERDESC *Desc,
1031 IDirect3DVertexBuffer **VertexBuffer,
1035 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
1037 TRACE("(%p)->(%p,%p,%08x,%p): Relaying to IDirect3D7\n", This, Desc, VertexBuffer, Flags, UnkOuter);
1039 if(UnkOuter != NULL) return CLASS_E_NOAGGREGATION;
1041 hr = IDirect3D7_CreateVertexBuffer(ICOM_INTERFACE(This, IDirect3D7),
1043 (IDirect3DVertexBuffer7 **) VertexBuffer,
1046 *VertexBuffer = COM_INTERFACE_CAST(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, IDirect3DVertexBuffer, *VertexBuffer);
1051 /*****************************************************************************
1052 * IDirect3D7::EnumZBufferFormats
1054 * Enumerates all supported Z buffer pixel formats
1060 * Callback: Callback to call for each pixel format
1061 * Context: Pointer to pass back to the callback
1065 * DDERR_INVALIDPARAMS if Callback is NULL
1066 * For details, see IWineD3DDevice::EnumZBufferFormats
1068 *****************************************************************************/
1069 static HRESULT WINAPI
1070 IDirect3DImpl_7_EnumZBufferFormats(IDirect3D7 *iface,
1071 REFCLSID refiidDevice,
1072 LPD3DENUMPIXELFORMATSCALLBACK Callback,
1075 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
1079 /* Order matters. Specifically, BattleZone II (full version) expects the
1080 * 16-bit depth formats to be listed before the 24 and 32 ones. */
1081 WINED3DFORMAT FormatList[] = {
1090 TRACE("(%p)->(%s,%p,%p): Relay\n", iface, debugstr_guid(refiidDevice), Callback, Context);
1093 return DDERR_INVALIDPARAMS;
1095 for(i = 0; i < sizeof(FormatList) / sizeof(WINED3DFORMAT); i++)
1097 hr = IWineD3D_CheckDeviceFormat(This->wineD3D,
1100 0 /* AdapterFormat */,
1101 WINED3DUSAGE_DEPTHSTENCIL /* Usage */,
1102 0 /* ResourceType */,
1106 DDPIXELFORMAT pformat;
1108 memset(&pformat, 0, sizeof(pformat));
1109 pformat.dwSize = sizeof(pformat);
1110 PixelFormat_WineD3DtoDD(&pformat, FormatList[i]);
1112 TRACE("Enumerating WineD3DFormat %d\n", FormatList[i]);
1113 hr = Callback(&pformat, Context);
1114 if(hr != DDENUMRET_OK)
1116 TRACE("Format enumeration cancelled by application\n");
1121 TRACE("End of enumeration\n");
1125 static HRESULT WINAPI
1126 Thunk_IDirect3DImpl_3_EnumZBufferFormats(IDirect3D3 *iface,
1127 REFCLSID riidDevice,
1128 LPD3DENUMPIXELFORMATSCALLBACK Callback,
1131 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
1132 TRACE("(%p)->(%s,%p,%p) thunking to IDirect3D7 interface.\n", This, debugstr_guid(riidDevice), Callback, Context);
1133 return IDirect3D7_EnumZBufferFormats(ICOM_INTERFACE(This, IDirect3D7),
1139 /*****************************************************************************
1140 * IDirect3D7::EvictManagedTextures
1142 * Removes all managed textures (=surfaces with DDSCAPS2_TEXTUREMANAGE or
1143 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
1148 * D3D_OK, because it's a stub
1150 *****************************************************************************/
1151 static HRESULT WINAPI
1152 IDirect3DImpl_7_EvictManagedTextures(IDirect3D7 *iface)
1154 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
1155 FIXME("(%p): Stub!\n", This);
1157 /* Implementation idea:
1158 * Add an IWineD3DSurface method which sets the opengl texture
1159 * priority low or even removes the opengl texture.
1165 static HRESULT WINAPI
1166 Thunk_IDirect3DImpl_3_EvictManagedTextures(IDirect3D3 *iface)
1168 ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
1169 TRACE("(%p)->() thunking to IDirect3D7 interface.\n", This);
1170 return IDirect3D7_EvictManagedTextures(ICOM_INTERFACE(This, IDirect3D7));
1173 /*****************************************************************************
1174 * IDirect3DImpl_GetCaps
1176 * This function retrieves the device caps from wined3d
1177 * and converts it into a D3D7 and D3D - D3D3 structure
1178 * This is a helper function called from various places in ddraw
1181 * WineD3D: The interface to get the caps from
1182 * Desc123: Old D3D <3 structure to fill (needed)
1183 * Desc7: D3D7 device desc structure to fill (needed)
1186 * D3D_OK on success, or the return value of IWineD3D::GetCaps
1188 *****************************************************************************/
1190 IDirect3DImpl_GetCaps(IWineD3D *WineD3D,
1191 D3DDEVICEDESC *Desc123,
1192 D3DDEVICEDESC7 *Desc7)
1197 /* Some Variables to asign to the pointers in WCaps */
1198 WINED3DDEVTYPE DevType;
1201 DWORD dummy_dword, MaxTextureBlendStages, MaxSimultaneousTextures;
1202 DWORD MaxUserClipPlanes, MaxVertexBlendMatrices;
1204 TRACE("()->(%p,%p,%p\n", WineD3D, Desc123, Desc7);
1206 /* Asign the pointers in WCaps */
1207 WCaps.DeviceType = &DevType;
1208 WCaps.AdapterOrdinal = &dummy_uint;
1210 WCaps.Caps = &dummy_dword;
1211 WCaps.Caps2 = &dummy_dword;
1212 WCaps.Caps3 = &dummy_dword;
1213 WCaps.PresentationIntervals = &dummy_dword;
1215 WCaps.CursorCaps = &dummy_dword;
1217 WCaps.DevCaps = &Desc7->dwDevCaps;
1218 WCaps.PrimitiveMiscCaps = &dummy_dword;
1219 WCaps.RasterCaps = &Desc7->dpcLineCaps.dwRasterCaps;
1220 WCaps.ZCmpCaps = &Desc7->dpcLineCaps.dwZCmpCaps;
1221 WCaps.SrcBlendCaps = &Desc7->dpcLineCaps.dwSrcBlendCaps;
1222 WCaps.DestBlendCaps = &Desc7->dpcLineCaps.dwDestBlendCaps;
1223 WCaps.AlphaCmpCaps = &Desc7->dpcLineCaps.dwAlphaCmpCaps;
1224 WCaps.ShadeCaps = &Desc7->dpcLineCaps.dwShadeCaps;
1225 WCaps.TextureCaps = &Desc7->dpcLineCaps.dwTextureCaps;
1226 WCaps.TextureFilterCaps = &Desc7->dpcLineCaps.dwTextureFilterCaps;
1227 WCaps.CubeTextureFilterCaps = &dummy_dword;
1228 WCaps.VolumeTextureFilterCaps = &dummy_dword;
1229 WCaps.TextureAddressCaps = &Desc7->dpcLineCaps.dwTextureAddressCaps;
1230 WCaps.VolumeTextureAddressCaps = &dummy_dword;
1232 WCaps.LineCaps = &dummy_dword;
1233 WCaps.MaxTextureWidth = &Desc7->dwMaxTextureWidth;
1234 WCaps.MaxTextureHeight = &Desc7->dwMaxTextureHeight;
1235 WCaps.MaxVolumeExtent = &dummy_dword;
1237 WCaps.MaxTextureRepeat = &Desc7->dwMaxTextureRepeat;
1238 WCaps.MaxTextureAspectRatio = &Desc7->dwMaxTextureAspectRatio;
1239 WCaps.MaxAnisotropy = &Desc7->dwMaxAnisotropy;
1240 WCaps.MaxVertexW = &Desc7->dvMaxVertexW;
1242 WCaps.GuardBandLeft = &Desc7->dvGuardBandLeft;
1243 WCaps.GuardBandTop = &Desc7->dvGuardBandTop;
1244 WCaps.GuardBandRight = &Desc7->dvGuardBandRight;
1245 WCaps.GuardBandBottom = &Desc7->dvGuardBandBottom;
1247 WCaps.ExtentsAdjust = &Desc7->dvExtentsAdjust;
1248 WCaps.StencilCaps = &Desc7->dwStencilCaps;
1250 WCaps.FVFCaps = &Desc7->dwFVFCaps;
1251 WCaps.TextureOpCaps = &Desc7->dwTextureOpCaps;
1252 WCaps.MaxTextureBlendStages = &MaxTextureBlendStages;
1253 WCaps.MaxSimultaneousTextures = &MaxSimultaneousTextures;
1255 WCaps.VertexProcessingCaps = &Desc7->dwVertexProcessingCaps;
1256 WCaps.MaxActiveLights = &Desc7->dwMaxActiveLights;
1257 WCaps.MaxUserClipPlanes = &MaxUserClipPlanes;
1258 WCaps.MaxVertexBlendMatrices = &MaxVertexBlendMatrices;
1259 WCaps.MaxVertexBlendMatrixIndex = &dummy_dword;
1261 WCaps.MaxPointSize = &dummy_float;
1262 WCaps.MaxPrimitiveCount = &dummy_dword;
1263 WCaps.MaxVertexIndex = &dummy_dword;
1264 WCaps.MaxStreams = &dummy_dword;
1265 WCaps.MaxStreamStride = &dummy_dword;
1267 WCaps.VertexShaderVersion = &dummy_dword;
1268 WCaps.MaxVertexShaderConst = &dummy_dword;
1270 WCaps.PixelShaderVersion = &dummy_dword;
1271 WCaps.PixelShader1xMaxValue = &dummy_float;
1273 /* These are dx9 only, set them to NULL */
1274 WCaps.DevCaps2 = NULL;
1275 WCaps.MaxNpatchTessellationLevel = NULL;
1276 WCaps.Reserved5 = NULL;
1277 WCaps.MasterAdapterOrdinal = NULL;
1278 WCaps.AdapterOrdinalInGroup = NULL;
1279 WCaps.NumberOfAdaptersInGroup = NULL;
1280 WCaps.DeclTypes = NULL;
1281 WCaps.NumSimultaneousRTs = NULL;
1282 WCaps.StretchRectFilterCaps = NULL;
1283 /* WCaps.VS20Caps = NULL; */
1284 /* WCaps.PS20Caps = NULL; */
1285 WCaps.VertexTextureFilterCaps = NULL;
1286 WCaps.MaxVShaderInstructionsExecuted = NULL;
1287 WCaps.MaxPShaderInstructionsExecuted = NULL;
1288 WCaps.MaxVertexShader30InstructionSlots = NULL;
1289 WCaps.MaxPixelShader30InstructionSlots = NULL;
1290 WCaps.Reserved2 = NULL;
1291 WCaps.Reserved3 = NULL;
1293 /* Now get the caps */
1294 hr = IWineD3D_GetDeviceCaps(WineD3D, 0, WINED3DDEVTYPE_HAL, &WCaps);
1295 if(hr != D3D_OK) return hr;
1297 /* Fill the missing members, and do some fixup */
1298 Desc7->dpcLineCaps.dwSize = sizeof(Desc7->dpcLineCaps);
1299 Desc7->dpcLineCaps.dwTextureBlendCaps = D3DPTBLENDCAPS_ADD | D3DPTBLENDCAPS_MODULATEMASK |
1300 D3DPTBLENDCAPS_COPY | D3DPTBLENDCAPS_DECAL |
1301 D3DPTBLENDCAPS_DECALALPHA | D3DPTBLENDCAPS_DECALMASK |
1302 D3DPTBLENDCAPS_MODULATE | D3DPTBLENDCAPS_MODULATEALPHA;
1303 Desc7->dpcLineCaps.dwStippleWidth = 32;
1304 Desc7->dpcLineCaps.dwStippleHeight = 32;
1305 /* Use the same for the TriCaps */
1306 Desc7->dpcTriCaps = Desc7->dpcLineCaps;
1308 Desc7->dwDeviceRenderBitDepth = DDBD_16 | DDBD_24 | DDBD_32;
1309 Desc7->dwDeviceZBufferBitDepth = DDBD_16 | DDBD_24;
1310 Desc7->dwMinTextureWidth = 1;
1311 Desc7->dwMinTextureHeight = 1;
1313 /* Convert DWORDs safely to WORDs */
1314 if(MaxTextureBlendStages > 65535) Desc7->wMaxTextureBlendStages = 65535;
1315 else Desc7->wMaxTextureBlendStages = (WORD) MaxTextureBlendStages;
1316 if(MaxSimultaneousTextures > 65535) Desc7->wMaxSimultaneousTextures = 65535;
1317 else Desc7->wMaxSimultaneousTextures = (WORD) MaxSimultaneousTextures;
1319 if(MaxUserClipPlanes > 65535) Desc7->wMaxUserClipPlanes = 65535;
1320 else Desc7->wMaxUserClipPlanes = (WORD) MaxUserClipPlanes;
1321 if(MaxVertexBlendMatrices > 65535) Desc7->wMaxVertexBlendMatrices = 65535;
1322 else Desc7->wMaxVertexBlendMatrices = (WORD) MaxVertexBlendMatrices;
1324 Desc7->deviceGUID = IID_IDirect3DTnLHalDevice;
1326 Desc7->dwReserved1 = 0;
1327 Desc7->dwReserved2 = 0;
1328 Desc7->dwReserved3 = 0;
1329 Desc7->dwReserved4 = 0;
1331 /* Fill the old structure */
1332 memset(Desc123, 0x0, sizeof(D3DDEVICEDESC));
1333 Desc123->dwSize = sizeof(D3DDEVICEDESC);
1334 Desc123->dwFlags = D3DDD_COLORMODEL |
1336 D3DDD_TRANSFORMCAPS |
1338 D3DDD_LIGHTINGCAPS |
1341 D3DDD_DEVICERENDERBITDEPTH |
1342 D3DDD_DEVICEZBUFFERBITDEPTH |
1343 D3DDD_MAXBUFFERSIZE |
1344 D3DDD_MAXVERTEXCOUNT;
1345 Desc123->dcmColorModel = D3DCOLOR_RGB;
1346 Desc123->dwDevCaps = Desc7->dwDevCaps;
1347 Desc123->dtcTransformCaps.dwSize = sizeof(D3DTRANSFORMCAPS);
1348 Desc123->dtcTransformCaps.dwCaps = D3DTRANSFORMCAPS_CLIP;
1349 Desc123->bClipping = TRUE;
1350 Desc123->dlcLightingCaps.dwSize = sizeof(D3DLIGHTINGCAPS);
1351 Desc123->dlcLightingCaps.dwCaps = D3DLIGHTCAPS_DIRECTIONAL | D3DLIGHTCAPS_PARALLELPOINT | D3DLIGHTCAPS_POINT | D3DLIGHTCAPS_SPOT;
1352 Desc123->dlcLightingCaps.dwLightingModel = D3DLIGHTINGMODEL_RGB;
1353 Desc123->dlcLightingCaps.dwNumLights = Desc7->dwMaxActiveLights;
1355 Desc123->dpcLineCaps.dwSize = sizeof(D3DPRIMCAPS);
1356 Desc123->dpcLineCaps.dwMiscCaps = Desc7->dpcLineCaps.dwMiscCaps;
1357 Desc123->dpcLineCaps.dwRasterCaps = Desc7->dpcLineCaps.dwRasterCaps;
1358 Desc123->dpcLineCaps.dwZCmpCaps = Desc7->dpcLineCaps.dwZCmpCaps;
1359 Desc123->dpcLineCaps.dwSrcBlendCaps = Desc7->dpcLineCaps.dwSrcBlendCaps;
1360 Desc123->dpcLineCaps.dwDestBlendCaps = Desc7->dpcLineCaps.dwDestBlendCaps;
1361 Desc123->dpcLineCaps.dwShadeCaps = Desc7->dpcLineCaps.dwShadeCaps;
1362 Desc123->dpcLineCaps.dwTextureCaps = Desc7->dpcLineCaps.dwTextureCaps;
1363 Desc123->dpcLineCaps.dwTextureFilterCaps = Desc7->dpcLineCaps.dwTextureFilterCaps;
1364 Desc123->dpcLineCaps.dwTextureBlendCaps = Desc7->dpcLineCaps.dwTextureBlendCaps;
1365 Desc123->dpcLineCaps.dwTextureAddressCaps = Desc7->dpcLineCaps.dwTextureAddressCaps;
1366 Desc123->dpcLineCaps.dwStippleWidth = Desc7->dpcLineCaps.dwStippleWidth;
1367 Desc123->dpcLineCaps.dwAlphaCmpCaps = Desc7->dpcLineCaps.dwAlphaCmpCaps;
1369 Desc123->dpcTriCaps.dwSize = sizeof(D3DPRIMCAPS);
1370 Desc123->dpcTriCaps.dwMiscCaps = Desc7->dpcTriCaps.dwMiscCaps;
1371 Desc123->dpcTriCaps.dwRasterCaps = Desc7->dpcTriCaps.dwRasterCaps;
1372 Desc123->dpcTriCaps.dwZCmpCaps = Desc7->dpcTriCaps.dwZCmpCaps;
1373 Desc123->dpcTriCaps.dwSrcBlendCaps = Desc7->dpcTriCaps.dwSrcBlendCaps;
1374 Desc123->dpcTriCaps.dwDestBlendCaps = Desc7->dpcTriCaps.dwDestBlendCaps;
1375 Desc123->dpcTriCaps.dwShadeCaps = Desc7->dpcTriCaps.dwShadeCaps;
1376 Desc123->dpcTriCaps.dwTextureCaps = Desc7->dpcTriCaps.dwTextureCaps;
1377 Desc123->dpcTriCaps.dwTextureFilterCaps = Desc7->dpcTriCaps.dwTextureFilterCaps;
1378 Desc123->dpcTriCaps.dwTextureBlendCaps = Desc7->dpcTriCaps.dwTextureBlendCaps;
1379 Desc123->dpcTriCaps.dwTextureAddressCaps = Desc7->dpcTriCaps.dwTextureAddressCaps;
1380 Desc123->dpcTriCaps.dwStippleWidth = Desc7->dpcTriCaps.dwStippleWidth;
1381 Desc123->dpcTriCaps.dwAlphaCmpCaps = Desc7->dpcTriCaps.dwAlphaCmpCaps;
1383 Desc123->dwDeviceRenderBitDepth = Desc7->dwDeviceRenderBitDepth;
1384 Desc123->dwDeviceZBufferBitDepth = Desc7->dwDeviceZBufferBitDepth;
1385 Desc123->dwMaxBufferSize = 0;
1386 Desc123->dwMaxVertexCount = 65536;
1387 Desc123->dwMinTextureWidth = Desc7->dwMinTextureWidth;
1388 Desc123->dwMinTextureHeight = Desc7->dwMinTextureHeight;
1389 Desc123->dwMaxTextureWidth = Desc7->dwMaxTextureWidth;
1390 Desc123->dwMaxTextureHeight = Desc7->dwMaxTextureHeight;
1391 Desc123->dwMinStippleWidth = 1;
1392 Desc123->dwMinStippleHeight = 1;
1393 Desc123->dwMaxStippleWidth = 32;
1394 Desc123->dwMaxStippleHeight = 32;
1395 Desc123->dwMaxTextureRepeat = Desc7->dwMaxTextureRepeat;
1396 Desc123->dwMaxTextureAspectRatio = Desc7->dwMaxTextureAspectRatio;
1397 Desc123->dwMaxAnisotropy = Desc7->dwMaxAnisotropy;
1398 Desc123->dvGuardBandLeft = Desc7->dvGuardBandLeft;
1399 Desc123->dvGuardBandRight = Desc7->dvGuardBandRight;
1400 Desc123->dvGuardBandTop = Desc7->dvGuardBandTop;
1401 Desc123->dvGuardBandBottom = Desc7->dvGuardBandBottom;
1402 Desc123->dvExtentsAdjust = Desc7->dvExtentsAdjust;
1403 Desc123->dwStencilCaps = Desc7->dwStencilCaps;
1404 Desc123->dwFVFCaps = Desc7->dwFVFCaps;
1405 Desc123->dwTextureOpCaps = Desc7->dwTextureOpCaps;
1406 Desc123->wMaxTextureBlendStages = Desc7->wMaxTextureBlendStages;
1407 Desc123->wMaxSimultaneousTextures = Desc7->wMaxSimultaneousTextures;
1411 /*****************************************************************************
1412 * IDirect3D vtables in various versions
1413 *****************************************************************************/
1415 const IDirect3DVtbl IDirect3D1_Vtbl =
1417 /*** IUnknown methods ***/
1418 Thunk_IDirect3DImpl_1_QueryInterface,
1419 Thunk_IDirect3DImpl_1_AddRef,
1420 Thunk_IDirect3DImpl_1_Release,
1421 /*** IDirect3D methods ***/
1422 IDirect3DImpl_1_Initialize,
1423 Thunk_IDirect3DImpl_1_EnumDevices,
1424 Thunk_IDirect3DImpl_1_CreateLight,
1425 Thunk_IDirect3DImpl_1_CreateMaterial,
1426 Thunk_IDirect3DImpl_1_CreateViewport,
1427 Thunk_IDirect3DImpl_1_FindDevice
1430 const IDirect3D2Vtbl IDirect3D2_Vtbl =
1432 /*** IUnknown methods ***/
1433 Thunk_IDirect3DImpl_2_QueryInterface,
1434 Thunk_IDirect3DImpl_2_AddRef,
1435 Thunk_IDirect3DImpl_2_Release,
1436 /*** IDirect3D2 methods ***/
1437 Thunk_IDirect3DImpl_2_EnumDevices,
1438 Thunk_IDirect3DImpl_2_CreateLight,
1439 Thunk_IDirect3DImpl_2_CreateMaterial,
1440 Thunk_IDirect3DImpl_2_CreateViewport,
1441 Thunk_IDirect3DImpl_2_FindDevice,
1442 Thunk_IDirect3DImpl_2_CreateDevice
1445 const IDirect3D3Vtbl IDirect3D3_Vtbl =
1447 /*** IUnknown methods ***/
1448 Thunk_IDirect3DImpl_3_QueryInterface,
1449 Thunk_IDirect3DImpl_3_AddRef,
1450 Thunk_IDirect3DImpl_3_Release,
1451 /*** IDirect3D3 methods ***/
1452 IDirect3DImpl_3_EnumDevices,
1453 IDirect3DImpl_3_CreateLight,
1454 IDirect3DImpl_3_CreateMaterial,
1455 IDirect3DImpl_3_CreateViewport,
1456 IDirect3DImpl_3_FindDevice,
1457 Thunk_IDirect3DImpl_3_CreateDevice,
1458 Thunk_IDirect3DImpl_3_CreateVertexBuffer,
1459 Thunk_IDirect3DImpl_3_EnumZBufferFormats,
1460 Thunk_IDirect3DImpl_3_EvictManagedTextures
1463 const IDirect3D7Vtbl IDirect3D7_Vtbl =
1465 /*** IUnknown methods ***/
1466 Thunk_IDirect3DImpl_7_QueryInterface,
1467 Thunk_IDirect3DImpl_7_AddRef,
1468 Thunk_IDirect3DImpl_7_Release,
1469 /*** IDirect3D7 methods ***/
1470 IDirect3DImpl_7_EnumDevices,
1471 IDirect3DImpl_7_CreateDevice,
1472 IDirect3DImpl_7_CreateVertexBuffer,
1473 IDirect3DImpl_7_EnumZBufferFormats,
1474 IDirect3DImpl_7_EvictManagedTextures