2 * Copyright (c) 2006 Stefan Dösinger
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "wine/port.h"
21 #include "wine/debug.h"
35 #include "wine/exception.h"
41 #include "ddraw_private.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(d3d7
);
45 /*****************************************************************************
46 * IUnknown Methods. Common for Version 1, 2, 3 and 7
48 * These are thunks which relay to IDirectDraw. See ddraw.c for
51 *****************************************************************************/
53 Thunk_IDirect3DImpl_7_QueryInterface(IDirect3D7
*iface
,
57 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D7
, iface
);
58 TRACE("(%p)->(%s,%p): Thunking to IDirectDraw7\n", This
, debugstr_guid(refiid
), obj
);
60 return IDirectDraw7_QueryInterface(ICOM_INTERFACE(This
, IDirectDraw7
),
66 Thunk_IDirect3DImpl_3_QueryInterface(IDirect3D3
*iface
,
70 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D3
, iface
);
71 TRACE("(%p)->(%s,%p): Thunking to IDirectDraw7\n", This
, debugstr_guid(refiid
), obj
);
73 return IDirectDraw7_QueryInterface(ICOM_INTERFACE(This
, IDirectDraw7
),
79 Thunk_IDirect3DImpl_2_QueryInterface(IDirect3D2
*iface
,
83 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D2
, iface
);
84 TRACE("(%p)->(%s,%p): Thunking to IDirectDraw7\n", This
, debugstr_guid(refiid
), obj
);
86 return IDirectDraw7_QueryInterface(ICOM_INTERFACE(This
, IDirectDraw7
),
92 Thunk_IDirect3DImpl_1_QueryInterface(IDirect3D
*iface
,
96 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D
, iface
);
97 TRACE("(%p)->(%s,%p): Thunking to IDirectDraw7\n", This
, debugstr_guid(refiid
), obj
);
99 return IDirectDraw7_QueryInterface(ICOM_INTERFACE(This
, IDirectDraw7
),
105 Thunk_IDirect3DImpl_7_AddRef(IDirect3D7
*iface
)
107 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D7
, iface
);
108 TRACE("(%p) : Thunking to IDirectDraw7\n", This
);
110 return IDirectDraw7_AddRef(ICOM_INTERFACE(This
, IDirectDraw7
));
114 Thunk_IDirect3DImpl_3_AddRef(IDirect3D3
*iface
)
116 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D3
, iface
);
117 TRACE("(%p) : Thunking to IDirectDraw7\n", This
);
119 return IDirectDraw7_AddRef(ICOM_INTERFACE(This
, IDirectDraw7
));
123 Thunk_IDirect3DImpl_2_AddRef(IDirect3D2
*iface
)
125 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D2
, iface
);
126 TRACE("(%p) : Thunking to IDirectDraw7\n", This
);
128 return IDirectDraw7_AddRef(ICOM_INTERFACE(This
, IDirectDraw7
));
132 Thunk_IDirect3DImpl_1_AddRef(IDirect3D
*iface
)
134 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D
, iface
);
135 TRACE("(%p) : Thunking to IDirectDraw7\n", This
);
137 return IDirectDraw7_AddRef(ICOM_INTERFACE(This
, IDirectDraw7
));
141 Thunk_IDirect3DImpl_7_Release(IDirect3D7
*iface
)
143 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D7
, iface
);
144 TRACE("(%p) : Thunking to IDirectDraw7", This
);
146 return IDirectDraw7_Release(ICOM_INTERFACE(This
, IDirectDraw7
));
150 Thunk_IDirect3DImpl_3_Release(IDirect3D3
*iface
)
152 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D3
, iface
);
153 TRACE("(%p) : Thunking to IDirectDraw7", This
);
155 return IDirectDraw7_Release(ICOM_INTERFACE(This
, IDirectDraw7
));
159 Thunk_IDirect3DImpl_2_Release(IDirect3D2
*iface
)
161 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D2
, iface
);
162 TRACE("(%p) : Thunking to IDirectDraw7", This
);
164 return IDirectDraw7_Release(ICOM_INTERFACE(This
, IDirectDraw7
));
168 Thunk_IDirect3DImpl_1_Release(IDirect3D
*iface
)
170 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D
, iface
);
171 TRACE("(%p) : Thunking to IDirectDraw7", This
);
173 return IDirectDraw7_Release(ICOM_INTERFACE(This
, IDirectDraw7
));
176 /*****************************************************************************
178 *****************************************************************************/
180 /*****************************************************************************
181 * IDirect3D::Initialize
183 * Initializes the IDirect3D interface. This is a no-op implementation,
184 * as all initialization is done at create time.
192 * D3D_OK, because it's a no-op
194 *****************************************************************************/
195 static HRESULT WINAPI
196 IDirect3DImpl_1_Initialize(IDirect3D
*iface
,
199 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D
, iface
);
201 TRACE("(%p)->(%s) no-op...\n", This
, debugstr_guid(refiid
));
205 /*****************************************************************************
206 * IDirect3D7::EnumDevices
208 * The EnumDevices method for IDirect3D7. It enumerates all supported
209 * D3D7 devices. Currently there's only one.
212 * Callback: Function to call for each enumerated device
213 * Context: Pointer to pass back to the app
216 * D3D_OK, or the return value of the GetCaps call
218 *****************************************************************************/
219 static HRESULT WINAPI
220 IDirect3DImpl_7_EnumDevices(IDirect3D7
*iface
,
221 LPD3DENUMDEVICESCALLBACK7 Callback
,
224 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D7
, iface
);
225 char interface_name
[] = "WINE Direct3D7 using WineD3D";
226 char device_name
[] = "Wine D3D7 device";
227 D3DDEVICEDESC7 ddesc
;
228 D3DDEVICEDESC oldDesc
;
231 TRACE("(%p)->(%p,%p)\n", This
, Callback
, Context
);
233 TRACE("(%p) Enumerating WineD3D D3Device7 interface\n", This
);
234 hr
= IDirect3DImpl_GetCaps(This
->wineD3D
, &oldDesc
, &ddesc
);
235 if(hr
!= D3D_OK
) return hr
;
236 Callback(interface_name
, device_name
, &ddesc
, Context
);
238 TRACE("(%p) End of enumeration\n", This
);
242 /*****************************************************************************
243 * IDirect3D3::EnumDevices
245 * Enumerates all supported Direct3DDevice interfaces. This is the
246 * implementation for Direct3D 1 to Direc3D 3, Version 7 has it's own.
251 * Callback: Application-provided routine to call for each enumerated device
252 * Context: Pointer to pass to the callback
256 * The result of IDirect3DImpl_GetCaps if it failed
258 *****************************************************************************/
259 static HRESULT WINAPI
260 IDirect3DImpl_3_EnumDevices(IDirect3D3
*iface
,
261 LPD3DENUMDEVICESCALLBACK Callback
,
264 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D3
, iface
);
265 D3DDEVICEDESC dref
, d1
, d2
;
266 D3DDEVICEDESC7 newDesc
;
269 /* Some games (Motoracer 2 demo) have the bad idea to modify the device name string.
270 Let's put the string in a sufficiently sized array in writable memory. */
271 char device_name
[50];
272 strcpy(device_name
,"direct3d");
274 TRACE("(%p)->(%p,%p)\n", This
, Callback
, Context
);
276 hr
= IDirect3DImpl_GetCaps(This
->wineD3D
, &dref
, &newDesc
);
277 if(hr
!= D3D_OK
) return hr
;
279 /* Do I have to enumerate the reference id? I try without. Note from old d3d7:
280 * "It seems that enumerating the reference IID on Direct3D 1 games
281 * (AvP / Motoracer2) breaks them". So do not enumerate this iid in V1
283 * There's a registry key HKLM\Software\Microsoft\Direct3D\Drivers, EnumReference
284 * which enables / disables enumerating the reference rasterizer. It's a DWORD,
285 * 0 means disabled, 2 means enabled. The enablerefrast.reg and disablerefrast.reg
286 * files in the DirectX 7.0 sdk demo directory suggest this.
289 TRACE("(%p) Enumerating WineD3D D3DDevice interface\n", This
);
292 Callback( (LPIID
) &IID_D3DDEVICE_WineD3D
, "Wine D3DDevice using WineD3D and OpenGL", device_name
, &d1
, &d2
, Context
);
293 TRACE("(%p) End of enumeration\n", This
);
294 if(hr
!= D3DENUMRET_OK
) return D3D_OK
;
299 static HRESULT WINAPI
300 Thunk_IDirect3DImpl_2_EnumDevices(IDirect3D2
*iface
,
301 LPD3DENUMDEVICESCALLBACK Callback
,
304 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D2
, iface
);
305 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This
, Callback
, Context
);
306 return IDirect3D3_EnumDevices(ICOM_INTERFACE(This
, IDirect3D3
),
311 static HRESULT WINAPI
312 Thunk_IDirect3DImpl_1_EnumDevices(IDirect3D
*iface
,
313 LPD3DENUMDEVICESCALLBACK Callback
,
316 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D
, iface
);
317 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This
, Callback
, Context
);
318 return IDirect3D3_EnumDevices(ICOM_INTERFACE(This
, IDirect3D3
),
323 /*****************************************************************************
324 * IDirect3D3::CreateLight
326 * Creates an IDirect3DLight interface. This interface is used in
327 * Direct3D3 or earlier for lighting. In Direct3D7 it has been replaced
328 * by the DIRECT3DLIGHT7 structure. Wine's Direct3DLight implementation
329 * uses the IDirect3DDevice7 interface with D3D7 lights.
334 * Light: Address to store the new interface pointer
335 * UnkOuter: Basically for aggregation, but ddraw doesn't support it.
340 * DDERR_OUTOFMEMORY if memory allocation failed
341 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
343 *****************************************************************************/
344 static HRESULT WINAPI
345 IDirect3DImpl_3_CreateLight(IDirect3D3
*iface
,
346 IDirect3DLight
**Light
,
349 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D3
, iface
);
350 IDirect3DLightImpl
*object
;
352 TRACE("(%p)->(%p,%p)\n", This
, Light
, UnkOuter
);
355 return CLASS_E_NOAGGREGATION
;
357 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirect3DLightImpl
));
359 return DDERR_OUTOFMEMORY
;
361 ICOM_INIT_INTERFACE(object
, IDirect3DLight
, IDirect3DLight_Vtbl
);
363 object
->ddraw
= This
;
365 object
->active_viewport
= NULL
;
367 /* Update functions */
368 object
->activate
= light_update
;
369 object
->desactivate
= light_activate
;
370 object
->update
= light_desactivate
;
371 object
->active_viewport
= NULL
;
373 *Light
= ICOM_INTERFACE(object
, IDirect3DLight
);
375 TRACE("(%p) creating implementation at %p.\n", This
, object
);
380 static HRESULT WINAPI
381 Thunk_IDirect3DImpl_2_CreateLight(IDirect3D2
*iface
,
382 IDirect3DLight
**Direct3DLight
,
385 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D2
, iface
);
386 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This
, Direct3DLight
, UnkOuter
);
387 return IDirect3D3_CreateLight(ICOM_INTERFACE(This
, IDirect3D3
),
392 static HRESULT WINAPI
393 Thunk_IDirect3DImpl_1_CreateLight(IDirect3D
*iface
,
394 IDirect3DLight
**Direct3DLight
,
397 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D
, iface
);
398 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This
, Direct3DLight
, UnkOuter
);
399 return IDirect3D3_CreateLight(ICOM_INTERFACE(This
, IDirect3D3
),
404 /*****************************************************************************
405 * IDirect3D3::CreateMaterial
407 * Creates an IDirect3DMaterial interface. This interface is used by Direct3D3
408 * and older versions. The IDirect3DMaterial implementation wraps it's
409 * functionality to IDirect3DDevice7::SetMaterial and friends.
414 * Material: Address to store the new interface's pointer to
415 * UnkOuter: Basically for aggregation, but ddraw doesn't support it.
420 * DDERR_OUTOFMEMORY if memory allocation failed
421 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
423 *****************************************************************************/
424 static HRESULT WINAPI
425 IDirect3DImpl_3_CreateMaterial(IDirect3D3
*iface
,
426 IDirect3DMaterial3
**Material
,
429 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D3
, iface
);
430 IDirect3DMaterialImpl
*object
;
432 TRACE("(%p)->(%p,%p)\n", This
, Material
, UnkOuter
);
435 return CLASS_E_NOAGGREGATION
;
437 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirect3DMaterialImpl
));
439 return DDERR_OUTOFMEMORY
;
441 ICOM_INIT_INTERFACE(object
, IDirect3DMaterial3
, IDirect3DMaterial3_Vtbl
);
442 ICOM_INIT_INTERFACE(object
, IDirect3DMaterial2
, IDirect3DMaterial2_Vtbl
);
443 ICOM_INIT_INTERFACE(object
, IDirect3DMaterial
, IDirect3DMaterial_Vtbl
);
445 object
->ddraw
= This
;
446 object
->activate
= material_activate
;
448 *Material
= ICOM_INTERFACE(object
, IDirect3DMaterial3
);
450 TRACE("(%p) creating implementation at %p.\n", This
, object
);
455 static HRESULT WINAPI
456 Thunk_IDirect3DImpl_2_CreateMaterial(IDirect3D2
*iface
,
457 IDirect3DMaterial2
**Direct3DMaterial
,
460 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D2
, iface
);
462 IDirect3DMaterial3
*ret_val
;
464 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This
, Direct3DMaterial
, UnkOuter
);
465 ret
= IDirect3D3_CreateMaterial(ICOM_INTERFACE(This
, IDirect3D3
),
469 *Direct3DMaterial
= COM_INTERFACE_CAST(IDirect3DMaterialImpl
, IDirect3DMaterial3
, IDirect3DMaterial2
, ret_val
);
471 TRACE(" returning interface %p.\n", *Direct3DMaterial
);
476 static HRESULT WINAPI
477 Thunk_IDirect3DImpl_1_CreateMaterial(IDirect3D
*iface
,
478 IDirect3DMaterial
**Direct3DMaterial
,
481 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D
, iface
);
483 LPDIRECT3DMATERIAL3 ret_val
;
485 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This
, Direct3DMaterial
, UnkOuter
);
486 ret
= IDirect3D3_CreateMaterial(ICOM_INTERFACE(This
, IDirect3D3
),
490 *Direct3DMaterial
= COM_INTERFACE_CAST(IDirect3DMaterialImpl
, IDirect3DMaterial3
, IDirect3DMaterial
, ret_val
);
492 TRACE(" returning interface %p.\n", *Direct3DMaterial
);
497 /*****************************************************************************
498 * IDirect3D3::CreateViewport
500 * Creates an IDirect3DViewport interface. This interface is used
501 * by Direct3D and earlier versions for Viewport management. In Direct3D7
502 * it has been replaced by a viewport structure and
503 * IDirect3DDevice7::*Viewport. Wine's IDirect3DViewport implementation
504 * uses the IDirect3DDevice7 methods for it's functionality
507 * Viewport: Address to store the new interface pointer
508 * UnkOuter: Basically for aggregation, but ddraw doesn't support it.
513 * DDERR_OUTOFMEMORY if memory allocation failed
514 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
516 *****************************************************************************/
517 static HRESULT WINAPI
518 IDirect3DImpl_3_CreateViewport(IDirect3D3
*iface
,
519 IDirect3DViewport3
**Viewport
,
522 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D3
, iface
);
523 IDirect3DViewportImpl
*object
;
526 return CLASS_E_NOAGGREGATION
;
528 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirect3DViewportImpl
));
530 return DDERR_OUTOFMEMORY
;
532 ICOM_INIT_INTERFACE(object
, IDirect3DViewport3
, IDirect3DViewport3_Vtbl
);
534 object
->ddraw
= This
;
535 object
->activate
= viewport_activate
;
536 object
->use_vp2
= 0xFF;
538 object
->lights
= NULL
;
539 object
->num_lights
= 0;
540 object
->map_lights
= 0;
542 *Viewport
= ICOM_INTERFACE(object
, IDirect3DViewport3
);
544 TRACE("(%p) creating implementation at %p.\n",This
, object
);
549 static HRESULT WINAPI
550 Thunk_IDirect3DImpl_2_CreateViewport(IDirect3D2
*iface
,
551 IDirect3DViewport2
**D3DViewport2
,
554 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D2
, iface
);
555 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This
, D3DViewport2
, UnkOuter
);
557 return IDirect3D3_CreateViewport(ICOM_INTERFACE(This
, IDirect3D3
),
558 (IDirect3DViewport3
**) D3DViewport2
/* No need to cast here */,
562 static HRESULT WINAPI
563 Thunk_IDirect3DImpl_1_CreateViewport(IDirect3D
*iface
,
564 IDirect3DViewport
**D3DViewport
,
567 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D
, iface
);
568 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This
, D3DViewport
, UnkOuter
);
570 return IDirect3D3_CreateViewport(ICOM_INTERFACE(This
, IDirect3D3
),
571 (IDirect3DViewport3
**) D3DViewport
/* No need to cast here */,
575 /*****************************************************************************
576 * IDirect3D3::FindDevice
578 * This method finds a device with the requested properties and returns a
583 * D3DDFS: Describes the requested device charakteristics
584 * D3DFDR: Returns the device description
588 * DDERR_INVALIDPARAMS if no device was found
590 *****************************************************************************/
591 static HRESULT WINAPI
592 IDirect3DImpl_3_FindDevice(IDirect3D3
*iface
,
593 D3DFINDDEVICESEARCH
*D3DDFS
,
594 D3DFINDDEVICERESULT
*D3DFDR
)
596 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D3
, iface
);
598 D3DDEVICEDESC7 newDesc
;
601 TRACE("(%p)->(%p,%p)\n", This
, D3DDFS
, D3DFDR
);
603 if ((D3DDFS
->dwFlags
& D3DFDS_COLORMODEL
) &&
604 (D3DDFS
->dcmColorModel
!= D3DCOLOR_RGB
))
606 TRACE(" trying to request a non-RGB D3D color model. Not supported.\n");
607 return DDERR_INVALIDPARAMS
; /* No real idea what to return here :-) */
609 if (D3DDFS
->dwFlags
& D3DFDS_GUID
)
611 TRACE(" trying to match guid %s.\n", debugstr_guid(&(D3DDFS
->guid
)));
612 if ((IsEqualGUID(&IID_D3DDEVICE_WineD3D
, &(D3DDFS
->guid
)) == 0) &&
613 (IsEqualGUID(&IID_IDirect3DHALDevice
, &(D3DDFS
->guid
)) == 0) &&
614 (IsEqualGUID(&IID_IDirect3DRefDevice
, &(D3DDFS
->guid
)) == 0))
616 TRACE(" no match for this GUID.\n");
617 return DDERR_INVALIDPARAMS
;
622 hr
= IDirect3DImpl_GetCaps(This
->wineD3D
, &desc
, &newDesc
);
623 if(hr
!= D3D_OK
) return hr
;
625 /* Now return our own GUID */
626 D3DFDR
->guid
= IID_D3DDEVICE_WineD3D
;
627 D3DFDR
->ddHwDesc
= desc
;
628 D3DFDR
->ddSwDesc
= desc
;
630 TRACE(" returning Wine's WineD3D device with (undumped) capabilities\n");
635 static HRESULT WINAPI
636 Thunk_IDirect3DImpl_2_FindDevice(IDirect3D2
*iface
,
637 D3DFINDDEVICESEARCH
*D3DDFS
,
638 D3DFINDDEVICERESULT
*D3DFDR
)
640 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D2
, iface
);
641 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", iface
, D3DDFS
, D3DFDR
);
642 return IDirect3D3_FindDevice(ICOM_INTERFACE(This
, IDirect3D3
),
647 static HRESULT WINAPI
648 Thunk_IDirect3DImpl_1_FindDevice(IDirect3D
*iface
,
649 D3DFINDDEVICESEARCH
*D3DDFS
,
650 D3DFINDDEVICERESULT
*D3DDevice
)
652 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D
, iface
);
653 TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", This
, D3DDFS
, D3DDevice
);
654 return IDirect3D3_FindDevice(ICOM_INTERFACE(This
, IDirect3D3
),
659 /*****************************************************************************
660 * IDirect3D7::CreateDevice
662 * Creates an IDirect3DDevice7 interface.
664 * Version 2, 3 and 7. IDirect3DDevice 1 interfaces are interfaces to
665 * DirectDraw surfaces and are created with
666 * IDirectDrawSurface::QueryInterface. This method uses CreateDevice to
667 * create the device object and QueryInterfaces for IDirect3DDevice
670 * refiid: IID of the device to create
671 * Surface: Inititial rendertarget
672 * Device: Address to return the interface pointer
676 * DDERR_OUTOFMEMORY if memory allocation failed
677 * DDERR_INVALIDPARAMS if a device exists already
679 *****************************************************************************/
680 static HRESULT WINAPI
681 IDirect3DImpl_7_CreateDevice(IDirect3D7
*iface
,
683 IDirectDrawSurface7
*Surface
,
684 IDirect3DDevice7
**Device
)
686 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D7
, iface
);
687 IDirect3DDeviceImpl
*object
;
688 IParentImpl
*IndexBufferParent
;
690 IDirectDrawSurfaceImpl
*target
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, Surface
);
691 TRACE("(%p)->(%s,%p,%p)\n", iface
, debugstr_guid(refiid
), Surface
, Device
);
695 /* Fail device creation if non-opengl surfaces are used */
696 if(This
->ImplType
!= SURFACE_OPENGL
)
698 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");
700 /* We only hit this path if a default surface is set in the registry. Incorrect autodetection
701 * is caught in CreateSurface or QueryInterface
706 /* So far we can only create one device per ddraw object */
709 FIXME("(%p): Only one Direct3D device per DirectDraw object supported\n", This
);
710 return DDERR_INVALIDPARAMS
;
713 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(IDirect3DDeviceImpl
));
716 ERR("Out of memory when allocating a IDirect3DDevice implementation\n");
717 return DDERR_OUTOFMEMORY
;
720 ICOM_INIT_INTERFACE(object
, IDirect3DDevice7
, IDirect3DDevice7_Vtbl
);
721 ICOM_INIT_INTERFACE(object
, IDirect3DDevice3
, IDirect3DDevice3_Vtbl
);
722 ICOM_INIT_INTERFACE(object
, IDirect3DDevice2
, IDirect3DDevice2_Vtbl
);
723 ICOM_INIT_INTERFACE(object
, IDirect3DDevice
, IDirect3DDevice1_Vtbl
);
726 object
->ddraw
= This
;
727 object
->viewport_list
= NULL
;
728 object
->current_viewport
= NULL
;
729 object
->material
= 0;
730 object
->target
= target
;
732 object
->Handles
= NULL
;
733 object
->numHandles
= 0;
735 /* This is for convenience */
736 object
->wineD3DDevice
= This
->wineD3DDevice
;
738 /* Create an index buffer, it's needed for indexed drawing */
739 IndexBufferParent
= HeapAlloc(GetProcessHeap(), 0, sizeof(IParentImpl
*));
740 if(!IndexBufferParent
)
742 ERR("Allocating memory for an index buffer parent failed\n");
743 HeapFree(GetProcessHeap(), 0, object
);
744 return DDERR_OUTOFMEMORY
;
746 ICOM_INIT_INTERFACE(IndexBufferParent
, IParent
, IParent_Vtbl
);
747 IndexBufferParent
->ref
= 1;
749 /* Create an Index Buffer. WineD3D needs one for Drawing indexed primitives
750 * Create a (hopefully) long enought buffer, and copy the indices into it
751 * Ideally, a IWineD3DIndexBuffer::SetData method could be created, which
752 * takes the pointer and avoids the memcpy
754 hr
= IWineD3DDevice_CreateIndexBuffer(This
->wineD3DDevice
,
755 0x40000, /* Lenght. Don't know how long it should be */
757 WINED3DFMT_INDEX16
, /* Format. D3D7 uses WORDS */
759 &object
->indexbuffer
,
761 (IUnknown
*) ICOM_INTERFACE(IndexBufferParent
, IParent
));
765 ERR("Failed to create an index buffer\n");
766 HeapFree(GetProcessHeap(), 0, object
);
769 IndexBufferParent
->child
= (IUnknown
*) object
->indexbuffer
;
771 /* No need to set the indices, it's done when necessary */
773 /* AddRef the WineD3D Device */
774 IWineD3DDevice_AddRef(This
->wineD3DDevice
);
776 /* Don't forget to return the interface ;) */
777 *Device
= ICOM_INTERFACE(object
, IDirect3DDevice7
);
779 TRACE(" (%p) Created an IDirect3DDeviceImpl object at %p\n", This
, object
);
781 /* This is for apps which create a non-flip, non-d3d primary surface
782 * and an offscreen D3DDEVICE surface, then render to the offscreen surface
783 * and do a Blt from the offscreen to the primary surface.
785 * Set the offscreen D3DDDEVICE surface(=target) as the back buffer,
786 * and the primary surface(=This->d3d_target) as the front buffer.
788 * This way the app will render to the D3DDEVICE surface and WineD3D
789 * will catch the Blt was Back Buffer -> Front buffer blt and perform
790 * a flip instead. This way we don't have to deal with a mixed GL / GDI
793 * This should be checked against windowed apps. The only app tested with
794 * this is moto racer 2 during the loading screen.
796 TRACE("Isrendertarget: %s, d3d_target=%p\n", target
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
? "true" : "false", This
->d3d_target
);
797 if(!(target
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) &&
798 (This
->d3d_target
!= target
))
800 TRACE("(%p) Using %p as front buffer, %p as back buffer\n", This
, This
->d3d_target
, target
);
801 hr
= IWineD3DDevice_SetFrontBackBuffers(This
->wineD3DDevice
,
802 This
->d3d_target
->WineD3DSurface
,
803 target
->WineD3DSurface
);
805 ERR("(%p) Error %08lx setting the front and back buffer\n", This
, hr
);
807 object
->OffScreenTarget
= TRUE
;
811 object
->OffScreenTarget
= FALSE
;
814 /* AddRef the render target. Also AddRef the render target from ddraw,
815 * because if it released before the app releases the D3D device, the D3D capatiblities
816 * of WineD3D will be uninitialized, which has bad effects.
818 * In most cases, those surfaces are the surfaces are the same anyway, but this will simply
819 * add another ref which is released when the device is destroyed.
821 IDirectDrawSurface7_AddRef(Surface
);
822 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(This
->d3d_target
, IDirectDrawSurface7
));
824 This
->d3ddevice
= object
;
829 static HRESULT WINAPI
830 Thunk_IDirect3DImpl_3_CreateDevice(IDirect3D3
*iface
,
832 IDirectDrawSurface4
*Surface
,
833 IDirect3DDevice3
**Device
,
836 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D3
, iface
);
838 TRACE("(%p)->(%s,%p,%p,%p): Thunking to IDirect3D7\n", This
, debugstr_guid(refiid
), Surface
, Device
, UnkOuter
);
841 return CLASS_E_NOAGGREGATION
;
843 hr
= IDirect3D7_CreateDevice(ICOM_INTERFACE(This
, IDirect3D7
),
845 (IDirectDrawSurface7
*) Surface
/* Same VTables */,
846 (IDirect3DDevice7
**) Device
);
848 *Device
= COM_INTERFACE_CAST(IDirect3DDeviceImpl
, IDirect3DDevice7
, IDirect3DDevice3
, *Device
);
852 static HRESULT WINAPI
853 Thunk_IDirect3DImpl_2_CreateDevice(IDirect3D2
*iface
,
855 IDirectDrawSurface
*Surface
,
856 IDirect3DDevice2
**Device
)
858 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D2
, iface
);
860 TRACE("(%p)->(%s,%p,%p): Thunking to IDirect3D7\n", This
, debugstr_guid(refiid
), Surface
, Device
);
862 hr
= IDirect3D7_CreateDevice(ICOM_INTERFACE(This
, IDirect3D7
),
864 COM_INTERFACE_CAST(IDirectDrawSurfaceImpl
, IDirectDrawSurface3
, IDirectDrawSurface7
, Surface
),
865 (IDirect3DDevice7
**) Device
);
867 *Device
= COM_INTERFACE_CAST(IDirect3DDeviceImpl
, IDirect3DDevice7
, IDirect3DDevice2
, *Device
);
871 /*****************************************************************************
872 * IDirect3D7::CreateVertexBuffer
874 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
880 * Desc: Requested Vertex buffer properties
881 * VertexBuffer: Address to return the interface pointer at
882 * Flags: Some flags, must be 0
886 * DDERR_OUTOFMEMORY if memory allocation failed
887 * The return value of IWineD3DDevice::CreateVertexBuffer if this call fails
888 * DDERR_INVALIDPARAMS if Desc or VertexBuffer are NULL, or Flags != 0
890 *****************************************************************************/
891 static HRESULT WINAPI
892 IDirect3DImpl_7_CreateVertexBuffer(IDirect3D7
*iface
,
893 D3DVERTEXBUFFERDESC
*Desc
,
894 IDirect3DVertexBuffer7
**VertexBuffer
,
897 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D7
, iface
);
898 IDirect3DVertexBufferImpl
*object
;
900 TRACE("(%p)->(%p,%p,%08lx)\n", This
, Desc
, VertexBuffer
, Flags
);
902 TRACE("(%p) Vertex buffer description: \n", This
);
903 TRACE("(%p) dwSize=%ld\n", This
, Desc
->dwSize
);
904 TRACE("(%p) dwCaps=%08lx\n", This
, Desc
->dwCaps
);
905 TRACE("(%p) FVF=%08lx\n", This
, Desc
->dwFVF
);
906 TRACE("(%p) dwNumVertices=%ld\n", This
, Desc
->dwNumVertices
);
908 /* D3D7 SDK: "No Flags are currently defined for this method. This
909 * parameter must be 0"
911 * Never trust the documentation - this is wrong
914 ERR("(%p) Flags is %08lx, returning DDERR_INVALIDPARAMS\n", This, Flags);
915 return DDERR_INVALIDPARAMS;
919 /* Well, this sounds sane */
920 if( (!VertexBuffer
) || (!Desc
) )
921 return DDERR_INVALIDPARAMS
;
923 /* Now create the vertex buffer */
924 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(IDirect3DVertexBufferImpl
));
927 ERR("(%p) Out of memory when allocating a IDirect3DVertexBufferImpl structure\n", This
);
928 return DDERR_OUTOFMEMORY
;
932 ICOM_INIT_INTERFACE(object
, IDirect3DVertexBuffer7
, IDirect3DVertexBuffer7_Vtbl
);
933 ICOM_INIT_INTERFACE(object
, IDirect3DVertexBuffer
, IDirect3DVertexBuffer1_Vtbl
);
935 object
->Caps
= Desc
->dwCaps
;
937 hr
= IWineD3DDevice_CreateVertexBuffer(This
->wineD3DDevice
,
938 get_flexible_vertex_size(Desc
->dwFVF
) * Desc
->dwNumVertices
,
939 Desc
->dwCaps
& D3DVBCAPS_WRITEONLY
? WINED3DUSAGE_WRITEONLY
: 0,
941 Desc
->dwCaps
& D3DVBCAPS_SYSTEMMEMORY
? WINED3DPOOL_SYSTEMMEM
: WINED3DPOOL_DEFAULT
,
942 &object
->wineD3DVertexBuffer
,
943 0 /* SharedHandle */,
944 (IUnknown
*) ICOM_INTERFACE(object
, IDirect3DVertexBuffer7
));
947 ERR("(%p) IWineD3DDevice::CreateVertexBuffer failed with hr=%08lx\n", This
, hr
);
948 HeapFree(GetProcessHeap(), 0, object
);
952 /* Return the interface */
953 *VertexBuffer
= ICOM_INTERFACE(object
, IDirect3DVertexBuffer7
);
955 TRACE("(%p) Created new vertex buffer implementation at %p, returning interface at %p\n", This
, object
, *VertexBuffer
);
959 static HRESULT WINAPI
960 Thunk_IDirect3DImpl_3_CreateVertexBuffer(IDirect3D3
*iface
,
961 D3DVERTEXBUFFERDESC
*Desc
,
962 IDirect3DVertexBuffer
**VertexBuffer
,
966 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D3
, iface
);
968 TRACE("(%p)->(%p,%p,%08lx,%p): Relaying to IDirect3D7\n", This
, Desc
, VertexBuffer
, Flags
, UnkOuter
);
970 if(UnkOuter
!= NULL
) return CLASS_E_NOAGGREGATION
;
972 hr
= IDirect3D7_CreateVertexBuffer(ICOM_INTERFACE(This
, IDirect3D7
),
974 (IDirect3DVertexBuffer7
**) VertexBuffer
,
977 *VertexBuffer
= COM_INTERFACE_CAST(IDirect3DVertexBufferImpl
, IDirect3DVertexBuffer7
, IDirect3DVertexBuffer
, *VertexBuffer
);
981 /*****************************************************************************
982 * EnumZBufferFormatsCB
984 * Helper function for IDirect3D7::EnumZBufferFormats. Converts
985 * the WINED3DFORMAT into a DirectDraw pixelformat and calls the application
991 * Device: Parent of the IWineD3DDevice, our IDirectDraw7 interface
992 * fmt: The enumerated pixel format
993 * Context: Context passed to IWineD3DDevice::EnumZBufferFormat
996 * The return value of the application-provided callback
998 *****************************************************************************/
999 static HRESULT WINAPI
1000 EnumZBufferFormatsCB(IUnknown
*Device
,
1004 struct EnumZBufferFormatsData
*cbdata
= (struct EnumZBufferFormatsData
*) Context
;
1005 DDPIXELFORMAT pformat
;
1007 memset(&pformat
, 0, sizeof(DDPIXELFORMAT
));
1008 pformat
.dwSize
=sizeof(DDPIXELFORMAT
);
1009 PixelFormat_WineD3DtoDD(&pformat
, fmt
);
1010 return cbdata
->Callback(&pformat
, cbdata
->Context
);
1013 /*****************************************************************************
1014 * IDirect3D7::EnumZBufferFormats
1016 * Enumerates all supported Z buffer pixel formats
1022 * Callback: Callback to call for each pixel format
1023 * Context: Pointer to pass back to the callback
1027 * DDERR_INVALIDPARAMS if Callback is NULL
1028 * For details, see IWineD3DDevice::EnumZBufferFormats
1030 *****************************************************************************/
1031 static HRESULT WINAPI
1032 IDirect3DImpl_7_EnumZBufferFormats(IDirect3D7
*iface
,
1033 REFCLSID refiidDevice
,
1034 LPD3DENUMPIXELFORMATSCALLBACK Callback
,
1037 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D7
, iface
);
1038 struct EnumZBufferFormatsData cbdata
= { Callback
, Context
};
1039 TRACE("(%p)->(%s,%p,%p): Relay\n", iface
, debugstr_guid(refiidDevice
), Callback
, Context
);
1042 return DDERR_INVALIDPARAMS
;
1044 return IWineD3DDevice_EnumZBufferFormats(This
->wineD3DDevice
, EnumZBufferFormatsCB
, &cbdata
);
1047 static HRESULT WINAPI
1048 Thunk_IDirect3DImpl_3_EnumZBufferFormats(IDirect3D3
*iface
,
1049 REFCLSID riidDevice
,
1050 LPD3DENUMPIXELFORMATSCALLBACK Callback
,
1053 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D3
, iface
);
1054 TRACE("(%p)->(%s,%p,%p) thunking to IDirect3D7 interface.\n", This
, debugstr_guid(riidDevice
), Callback
, Context
);
1055 return IDirect3D7_EnumZBufferFormats(ICOM_INTERFACE(This
, IDirect3D7
),
1061 /*****************************************************************************
1062 * IDirect3D7::EvictManagedTextures
1064 * Removes all managed textures(=surfaces with DDSCAPS2_TEXTUREMANAGE or
1065 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
1070 * D3D_OK, because it's a stub
1072 *****************************************************************************/
1073 static HRESULT WINAPI
1074 IDirect3DImpl_7_EvictManagedTextures(IDirect3D7
*iface
)
1076 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D7
, iface
);
1077 FIXME("(%p): Stub!\n", This
);
1079 /* Implementation idea:
1080 * Add an IWineD3DSurface method which sets the opengl texture
1081 * priority low or even removes the opengl texture.
1087 static HRESULT WINAPI
1088 Thunk_IDirect3DImpl_3_EvictManagedTextures(IDirect3D3
*iface
)
1090 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D3
, iface
);
1091 TRACE("(%p)->() thunking to IDirect3D7 interface.\n", This
);
1092 return IDirect3D7_EvictManagedTextures(ICOM_INTERFACE(This
, IDirect3D7
));
1095 /*****************************************************************************
1096 * IDirect3DImpl_GetCaps
1098 * This function retrieves the device caps from wined3d
1099 * and converts it into a D3D7 and D3D - D3D3 structure
1100 * This is a helper function called from various places in ddraw
1103 * WineD3D: The interface to get the caps from
1104 * Desc123: Old D3D <3 structure to fill(needed)
1105 * Desc7: D3D7 device desc structure to fill(needed)
1108 * D3D_OK on success, or the return value of IWineD3D::GetCaps
1110 *****************************************************************************/
1112 IDirect3DImpl_GetCaps(IWineD3D
*WineD3D
,
1113 D3DDEVICEDESC
*Desc123
,
1114 D3DDEVICEDESC7
*Desc7
)
1119 /* Some Variables to asign to the pointers in WCaps */
1120 WINED3DDEVTYPE DevType
;
1123 DWORD dummy_dword
, MaxTextureBlendStages
, MaxSimultaneousTextures
;
1124 DWORD MaxUserClipPlanes
, MaxVertexBlendMatrices
;
1126 TRACE("()->(%p,%p,%p\n", WineD3D
, Desc123
, Desc7
);
1128 /* Asign the pointers in WCaps */
1129 WCaps
.DeviceType
= &DevType
;
1130 WCaps
.AdapterOrdinal
= &dummy_uint
;
1132 WCaps
.Caps
= &dummy_dword
;
1133 WCaps
.Caps2
= &dummy_dword
;
1134 WCaps
.Caps3
= &dummy_dword
;
1135 WCaps
.PresentationIntervals
= &dummy_dword
;
1137 WCaps
.CursorCaps
= &dummy_dword
;
1139 WCaps
.DevCaps
= &Desc7
->dwDevCaps
;
1140 WCaps
.PrimitiveMiscCaps
= &dummy_dword
;
1141 WCaps
.RasterCaps
= &Desc7
->dpcLineCaps
.dwRasterCaps
;
1142 WCaps
.ZCmpCaps
= &Desc7
->dpcLineCaps
.dwZCmpCaps
;
1143 WCaps
.SrcBlendCaps
= &Desc7
->dpcLineCaps
.dwSrcBlendCaps
;
1144 WCaps
.DestBlendCaps
= &Desc7
->dpcLineCaps
.dwDestBlendCaps
;
1145 WCaps
.AlphaCmpCaps
= &Desc7
->dpcLineCaps
.dwAlphaCmpCaps
;
1146 WCaps
.ShadeCaps
= &Desc7
->dpcLineCaps
.dwShadeCaps
;
1147 WCaps
.TextureCaps
= &Desc7
->dpcLineCaps
.dwTextureCaps
;
1148 WCaps
.TextureFilterCaps
= &Desc7
->dpcLineCaps
.dwTextureFilterCaps
;
1149 WCaps
.CubeTextureFilterCaps
= &dummy_dword
;
1150 WCaps
.VolumeTextureFilterCaps
= &dummy_dword
;
1151 WCaps
.TextureAddressCaps
= &Desc7
->dpcLineCaps
.dwTextureAddressCaps
;
1152 WCaps
.VolumeTextureAddressCaps
= &dummy_dword
;
1154 WCaps
.LineCaps
= &dummy_dword
;
1155 WCaps
.MaxTextureWidth
= &Desc7
->dwMaxTextureWidth
;
1156 WCaps
.MaxTextureHeight
= &Desc7
->dwMaxTextureHeight
;
1157 WCaps
.MaxVolumeExtent
= &dummy_dword
;
1159 WCaps
.MaxTextureRepeat
= &Desc7
->dwMaxTextureRepeat
;
1160 WCaps
.MaxTextureAspectRatio
= &Desc7
->dwMaxTextureAspectRatio
;
1161 WCaps
.MaxAnisotropy
= &Desc7
->dwMaxAnisotropy
;
1162 WCaps
.MaxVertexW
= &Desc7
->dvMaxVertexW
;
1164 WCaps
.GuardBandLeft
= &Desc7
->dvGuardBandLeft
;
1165 WCaps
.GuardBandTop
= &Desc7
->dvGuardBandTop
;
1166 WCaps
.GuardBandRight
= &Desc7
->dvGuardBandRight
;
1167 WCaps
.GuardBandBottom
= &Desc7
->dvGuardBandBottom
;
1169 WCaps
.ExtentsAdjust
= &Desc7
->dvExtentsAdjust
;
1170 WCaps
.StencilCaps
= &Desc7
->dwStencilCaps
;
1172 WCaps
.FVFCaps
= &Desc7
->dwFVFCaps
;
1173 WCaps
.TextureOpCaps
= &Desc7
->dwTextureOpCaps
;
1174 WCaps
.MaxTextureBlendStages
= &MaxTextureBlendStages
;
1175 WCaps
.MaxSimultaneousTextures
= &MaxSimultaneousTextures
;
1177 WCaps
.VertexProcessingCaps
= &Desc7
->dwVertexProcessingCaps
;
1178 WCaps
.MaxActiveLights
= &Desc7
->dwMaxActiveLights
;
1179 WCaps
.MaxUserClipPlanes
= &MaxUserClipPlanes
;
1180 WCaps
.MaxVertexBlendMatrices
= &MaxVertexBlendMatrices
;
1181 WCaps
.MaxVertexBlendMatrixIndex
= &dummy_dword
;
1183 WCaps
.MaxPointSize
= &dummy_float
;
1184 WCaps
.MaxPrimitiveCount
= &dummy_dword
;
1185 WCaps
.MaxVertexIndex
= &dummy_dword
;
1186 WCaps
.MaxStreams
= &dummy_dword
;
1187 WCaps
.MaxStreamStride
= &dummy_dword
;
1189 WCaps
.VertexShaderVersion
= &dummy_dword
;
1190 WCaps
.MaxVertexShaderConst
= &dummy_dword
;
1192 WCaps
.PixelShaderVersion
= &dummy_dword
;
1193 WCaps
.PixelShader1xMaxValue
= &dummy_float
;
1195 /* These are dx9 only, set them to NULL */
1196 WCaps
.DevCaps2
= NULL
;
1197 WCaps
.MaxNpatchTessellationLevel
= NULL
;
1198 WCaps
.Reserved5
= NULL
;
1199 WCaps
.MasterAdapterOrdinal
= NULL
;
1200 WCaps
.AdapterOrdinalInGroup
= NULL
;
1201 WCaps
.NumberOfAdaptersInGroup
= NULL
;
1202 WCaps
.DeclTypes
= NULL
;
1203 WCaps
.NumSimultaneousRTs
= NULL
;
1204 WCaps
.StretchRectFilterCaps
= NULL
;
1205 /* WCaps.VS20Caps = NULL; */
1206 /* WCaps.PS20Caps = NULL; */
1207 WCaps
.VertexTextureFilterCaps
= NULL
;
1208 WCaps
.MaxVShaderInstructionsExecuted
= NULL
;
1209 WCaps
.MaxPShaderInstructionsExecuted
= NULL
;
1210 WCaps
.MaxVertexShader30InstructionSlots
= NULL
;
1211 WCaps
.MaxPixelShader30InstructionSlots
= NULL
;
1212 WCaps
.Reserved2
= NULL
;
1213 WCaps
.Reserved3
= NULL
;
1215 /* Now get the caps */
1216 hr
= IWineD3D_GetDeviceCaps(WineD3D
, 0, WINED3DDEVTYPE_HAL
, &WCaps
);
1217 if(hr
!= D3D_OK
) return hr
;
1219 /* Fill the missing members, and do some fixup */
1220 Desc7
->dpcLineCaps
.dwSize
= sizeof(Desc7
->dpcLineCaps
);
1221 Desc7
->dpcLineCaps
.dwTextureBlendCaps
= D3DPTBLENDCAPS_ADD
| D3DPTBLENDCAPS_MODULATEMASK
|
1222 D3DPTBLENDCAPS_COPY
| D3DPTBLENDCAPS_DECAL
|
1223 D3DPTBLENDCAPS_DECALALPHA
| D3DPTBLENDCAPS_DECALMASK
|
1224 D3DPTBLENDCAPS_MODULATE
| D3DPTBLENDCAPS_MODULATEALPHA
;
1225 Desc7
->dpcLineCaps
.dwStippleWidth
= 32;
1226 Desc7
->dpcLineCaps
.dwStippleHeight
= 32;
1227 /* Use the same for the TriCaps */
1228 Desc7
->dpcTriCaps
= Desc7
->dpcLineCaps
;
1230 Desc7
->dwDeviceRenderBitDepth
= DDBD_16
| DDBD_24
| DDBD_32
;
1231 Desc7
->dwDeviceZBufferBitDepth
= DDBD_16
| DDBD_24
;
1232 Desc7
->dwMinTextureWidth
= 1;
1233 Desc7
->dwMinTextureHeight
= 1;
1235 /* Convert DWORDs safely to WORDs */
1236 if(MaxTextureBlendStages
> 65535) Desc7
->wMaxTextureBlendStages
= 65535;
1237 else Desc7
->wMaxTextureBlendStages
= (WORD
) MaxTextureBlendStages
;
1238 if(MaxSimultaneousTextures
> 65535) Desc7
->wMaxSimultaneousTextures
= 65535;
1239 else Desc7
->wMaxSimultaneousTextures
= (WORD
) MaxSimultaneousTextures
;
1241 if(MaxUserClipPlanes
> 65535) Desc7
->wMaxUserClipPlanes
= 65535;
1242 else Desc7
->wMaxUserClipPlanes
= (WORD
) MaxUserClipPlanes
;
1243 if(MaxVertexBlendMatrices
> 65535) Desc7
->wMaxVertexBlendMatrices
= 65535;
1244 else Desc7
->wMaxVertexBlendMatrices
= (WORD
) MaxVertexBlendMatrices
;
1246 Desc7
->deviceGUID
= IID_IDirect3DTnLHalDevice
;
1248 Desc7
->dwReserved1
= 0;
1249 Desc7
->dwReserved2
= 0;
1250 Desc7
->dwReserved3
= 0;
1251 Desc7
->dwReserved4
= 0;
1253 /* Fill the old structure */
1254 memset(Desc123
, 0x0, sizeof(D3DDEVICEDESC
));
1255 Desc123
->dwSize
= sizeof(D3DDEVICEDESC
);
1256 Desc123
->dwFlags
= D3DDD_COLORMODEL
|
1258 D3DDD_TRANSFORMCAPS
|
1260 D3DDD_LIGHTINGCAPS
|
1263 D3DDD_DEVICERENDERBITDEPTH
|
1264 D3DDD_DEVICEZBUFFERBITDEPTH
|
1265 D3DDD_MAXBUFFERSIZE
|
1266 D3DDD_MAXVERTEXCOUNT
;
1267 Desc123
->dcmColorModel
= D3DCOLOR_RGB
;
1268 Desc123
->dwDevCaps
= Desc7
->dwDevCaps
;
1269 Desc123
->dtcTransformCaps
.dwSize
= sizeof(D3DTRANSFORMCAPS
);
1270 Desc123
->dtcTransformCaps
.dwCaps
= D3DTRANSFORMCAPS_CLIP
;
1271 Desc123
->bClipping
= TRUE
;
1272 Desc123
->dlcLightingCaps
.dwSize
= sizeof(D3DLIGHTINGCAPS
);
1273 Desc123
->dlcLightingCaps
.dwCaps
= D3DLIGHTCAPS_DIRECTIONAL
| D3DLIGHTCAPS_PARALLELPOINT
| D3DLIGHTCAPS_POINT
| D3DLIGHTCAPS_SPOT
;
1274 Desc123
->dlcLightingCaps
.dwLightingModel
= D3DLIGHTINGMODEL_RGB
;
1275 Desc123
->dlcLightingCaps
.dwNumLights
= Desc7
->dwMaxActiveLights
;
1277 Desc123
->dpcLineCaps
.dwSize
= sizeof(D3DPRIMCAPS
);
1278 Desc123
->dpcLineCaps
.dwMiscCaps
= Desc7
->dpcLineCaps
.dwMiscCaps
;
1279 Desc123
->dpcLineCaps
.dwRasterCaps
= Desc7
->dpcLineCaps
.dwRasterCaps
;
1280 Desc123
->dpcLineCaps
.dwZCmpCaps
= Desc7
->dpcLineCaps
.dwZCmpCaps
;
1281 Desc123
->dpcLineCaps
.dwSrcBlendCaps
= Desc7
->dpcLineCaps
.dwSrcBlendCaps
;
1282 Desc123
->dpcLineCaps
.dwDestBlendCaps
= Desc7
->dpcLineCaps
.dwDestBlendCaps
;
1283 Desc123
->dpcLineCaps
.dwShadeCaps
= Desc7
->dpcLineCaps
.dwShadeCaps
;
1284 Desc123
->dpcLineCaps
.dwTextureCaps
= Desc7
->dpcLineCaps
.dwTextureCaps
;
1285 Desc123
->dpcLineCaps
.dwTextureFilterCaps
= Desc7
->dpcLineCaps
.dwTextureFilterCaps
;
1286 Desc123
->dpcLineCaps
.dwTextureBlendCaps
= Desc7
->dpcLineCaps
.dwTextureBlendCaps
;
1287 Desc123
->dpcLineCaps
.dwTextureAddressCaps
= Desc7
->dpcLineCaps
.dwTextureAddressCaps
;
1288 Desc123
->dpcLineCaps
.dwStippleWidth
= Desc7
->dpcLineCaps
.dwStippleWidth
;
1289 Desc123
->dpcLineCaps
.dwAlphaCmpCaps
= Desc7
->dpcLineCaps
.dwAlphaCmpCaps
;
1291 Desc123
->dpcTriCaps
.dwSize
= sizeof(D3DPRIMCAPS
);
1292 Desc123
->dpcTriCaps
.dwMiscCaps
= Desc7
->dpcTriCaps
.dwMiscCaps
;
1293 Desc123
->dpcTriCaps
.dwRasterCaps
= Desc7
->dpcTriCaps
.dwRasterCaps
;
1294 Desc123
->dpcTriCaps
.dwZCmpCaps
= Desc7
->dpcTriCaps
.dwZCmpCaps
;
1295 Desc123
->dpcTriCaps
.dwSrcBlendCaps
= Desc7
->dpcTriCaps
.dwSrcBlendCaps
;
1296 Desc123
->dpcTriCaps
.dwDestBlendCaps
= Desc7
->dpcTriCaps
.dwDestBlendCaps
;
1297 Desc123
->dpcTriCaps
.dwShadeCaps
= Desc7
->dpcTriCaps
.dwShadeCaps
;
1298 Desc123
->dpcTriCaps
.dwTextureCaps
= Desc7
->dpcTriCaps
.dwTextureCaps
;
1299 Desc123
->dpcTriCaps
.dwTextureFilterCaps
= Desc7
->dpcTriCaps
.dwTextureFilterCaps
;
1300 Desc123
->dpcTriCaps
.dwTextureBlendCaps
= Desc7
->dpcTriCaps
.dwTextureBlendCaps
;
1301 Desc123
->dpcTriCaps
.dwTextureAddressCaps
= Desc7
->dpcTriCaps
.dwTextureAddressCaps
;
1302 Desc123
->dpcTriCaps
.dwStippleWidth
= Desc7
->dpcTriCaps
.dwStippleWidth
;
1303 Desc123
->dpcTriCaps
.dwAlphaCmpCaps
= Desc7
->dpcTriCaps
.dwAlphaCmpCaps
;
1305 Desc123
->dwDeviceRenderBitDepth
= Desc7
->dwDeviceRenderBitDepth
;
1306 Desc123
->dwDeviceZBufferBitDepth
= Desc7
->dwDeviceZBufferBitDepth
;
1307 Desc123
->dwMaxBufferSize
= 0;
1308 Desc123
->dwMaxVertexCount
= 65536;
1309 Desc123
->dwMinTextureWidth
= Desc7
->dwMinTextureWidth
;
1310 Desc123
->dwMinTextureHeight
= Desc7
->dwMinTextureHeight
;
1311 Desc123
->dwMaxTextureWidth
= Desc7
->dwMaxTextureWidth
;
1312 Desc123
->dwMaxTextureHeight
= Desc7
->dwMaxTextureHeight
;
1313 Desc123
->dwMinStippleWidth
= 1;
1314 Desc123
->dwMinStippleHeight
= 1;
1315 Desc123
->dwMaxStippleWidth
= 32;
1316 Desc123
->dwMaxStippleHeight
= 32;
1317 Desc123
->dwMaxTextureRepeat
= Desc7
->dwMaxTextureRepeat
;
1318 Desc123
->dwMaxTextureAspectRatio
= Desc7
->dwMaxTextureAspectRatio
;
1319 Desc123
->dwMaxAnisotropy
= Desc7
->dwMaxAnisotropy
;
1320 Desc123
->dvGuardBandLeft
= Desc7
->dvGuardBandLeft
;
1321 Desc123
->dvGuardBandRight
= Desc7
->dvGuardBandRight
;
1322 Desc123
->dvGuardBandTop
= Desc7
->dvGuardBandTop
;
1323 Desc123
->dvGuardBandBottom
= Desc7
->dvGuardBandBottom
;
1324 Desc123
->dvExtentsAdjust
= Desc7
->dvExtentsAdjust
;
1325 Desc123
->dwStencilCaps
= Desc7
->dwStencilCaps
;
1326 Desc123
->dwFVFCaps
= Desc7
->dwFVFCaps
;
1327 Desc123
->dwTextureOpCaps
= Desc7
->dwTextureOpCaps
;
1328 Desc123
->wMaxTextureBlendStages
= Desc7
->wMaxTextureBlendStages
;
1329 Desc123
->wMaxSimultaneousTextures
= Desc7
->wMaxSimultaneousTextures
;
1333 /*****************************************************************************
1334 * IDirect3D vtables in various versions
1335 *****************************************************************************/
1337 const IDirect3DVtbl IDirect3D1_Vtbl
=
1339 /*** IUnknown methods ***/
1340 Thunk_IDirect3DImpl_1_QueryInterface
,
1341 Thunk_IDirect3DImpl_1_AddRef
,
1342 Thunk_IDirect3DImpl_1_Release
,
1343 /*** IDirect3D methods ***/
1344 IDirect3DImpl_1_Initialize
,
1345 Thunk_IDirect3DImpl_1_EnumDevices
,
1346 Thunk_IDirect3DImpl_1_CreateLight
,
1347 Thunk_IDirect3DImpl_1_CreateMaterial
,
1348 Thunk_IDirect3DImpl_1_CreateViewport
,
1349 Thunk_IDirect3DImpl_1_FindDevice
1352 const IDirect3D2Vtbl IDirect3D2_Vtbl
=
1354 /*** IUnknown methods ***/
1355 Thunk_IDirect3DImpl_2_QueryInterface
,
1356 Thunk_IDirect3DImpl_2_AddRef
,
1357 Thunk_IDirect3DImpl_2_Release
,
1358 /*** IDirect3D2 methods ***/
1359 Thunk_IDirect3DImpl_2_EnumDevices
,
1360 Thunk_IDirect3DImpl_2_CreateLight
,
1361 Thunk_IDirect3DImpl_2_CreateMaterial
,
1362 Thunk_IDirect3DImpl_2_CreateViewport
,
1363 Thunk_IDirect3DImpl_2_FindDevice
,
1364 Thunk_IDirect3DImpl_2_CreateDevice
1367 const IDirect3D3Vtbl IDirect3D3_Vtbl
=
1369 /*** IUnknown methods ***/
1370 Thunk_IDirect3DImpl_3_QueryInterface
,
1371 Thunk_IDirect3DImpl_3_AddRef
,
1372 Thunk_IDirect3DImpl_3_Release
,
1373 /*** IDirect3D3 methods ***/
1374 IDirect3DImpl_3_EnumDevices
,
1375 IDirect3DImpl_3_CreateLight
,
1376 IDirect3DImpl_3_CreateMaterial
,
1377 IDirect3DImpl_3_CreateViewport
,
1378 IDirect3DImpl_3_FindDevice
,
1379 Thunk_IDirect3DImpl_3_CreateDevice
,
1380 Thunk_IDirect3DImpl_3_CreateVertexBuffer
,
1381 Thunk_IDirect3DImpl_3_EnumZBufferFormats
,
1382 Thunk_IDirect3DImpl_3_EvictManagedTextures
1385 const IDirect3D7Vtbl IDirect3D7_Vtbl
=
1387 /*** IUnknown methods ***/
1388 Thunk_IDirect3DImpl_7_QueryInterface
,
1389 Thunk_IDirect3DImpl_7_AddRef
,
1390 Thunk_IDirect3DImpl_7_Release
,
1391 /*** IDirect3D7 methods ***/
1392 IDirect3DImpl_7_EnumDevices
,
1393 IDirect3DImpl_7_CreateDevice
,
1394 IDirect3DImpl_7_CreateVertexBuffer
,
1395 IDirect3DImpl_7_EnumZBufferFormats
,
1396 IDirect3DImpl_7_EvictManagedTextures