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 /* This is for convenience */
733 object
->wineD3DDevice
= This
->wineD3DDevice
;
735 /* Create an index buffer, it's needed for indexed drawing */
736 IndexBufferParent
= HeapAlloc(GetProcessHeap(), 0, sizeof(IParentImpl
*));
737 if(!IndexBufferParent
)
739 ERR("Allocating memory for an index buffer parent failed\n");
740 HeapFree(GetProcessHeap(), 0, object
);
741 return DDERR_OUTOFMEMORY
;
743 ICOM_INIT_INTERFACE(IndexBufferParent
, IParent
, IParent_Vtbl
);
744 IndexBufferParent
->ref
= 1;
746 /* Create an Index Buffer. WineD3D needs one for Drawing indexed primitives
747 * Create a (hopefully) long enought buffer, and copy the indices into it
748 * Ideally, a IWineD3DIndexBuffer::SetData method could be created, which
749 * takes the pointer and avoids the memcpy
751 hr
= IWineD3DDevice_CreateIndexBuffer(This
->wineD3DDevice
,
752 0x40000, /* Lenght. Don't know how long it should be */
754 WINED3DFMT_INDEX16
, /* Format. D3D7 uses WORDS */
756 &object
->indexbuffer
,
758 (IUnknown
*) ICOM_INTERFACE(IndexBufferParent
, IParent
));
762 ERR("Failed to create an index buffer\n");
763 HeapFree(GetProcessHeap(), 0, object
);
766 IndexBufferParent
->child
= (IUnknown
*) object
->indexbuffer
;
768 /* No need to set the indices, it's done when necessary */
770 /* AddRef the WineD3D Device */
771 IWineD3DDevice_AddRef(This
->wineD3DDevice
);
773 /* Don't forget to return the interface ;) */
774 *Device
= ICOM_INTERFACE(object
, IDirect3DDevice7
);
776 TRACE(" (%p) Created an IDirect3DDeviceImpl object at %p\n", This
, object
);
778 /* This is for apps which create a non-flip, non-d3d primary surface
779 * and an offscreen D3DDEVICE surface, then render to the offscreen surface
780 * and do a Blt from the offscreen to the primary surface.
782 * Set the offscreen D3DDDEVICE surface(=target) as the back buffer,
783 * and the primary surface(=This->d3d_target) as the front buffer.
785 * This way the app will render to the D3DDEVICE surface and WineD3D
786 * will catch the Blt was Back Buffer -> Front buffer blt and perform
787 * a flip instead. This way we don't have to deal with a mixed GL / GDI
790 * This should be checked against windowed apps. The only app tested with
791 * this is moto racer 2 during the loading screen.
793 TRACE("Isrendertarget: %s, d3d_target=%p\n", target
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
? "true" : "false", This
->d3d_target
);
794 if(!(target
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) &&
795 (This
->d3d_target
!= target
))
797 TRACE("(%p) Using %p as front buffer, %p as back buffer\n", This
, This
->d3d_target
, target
);
798 hr
= IWineD3DDevice_SetFrontBackBuffers(This
->wineD3DDevice
,
799 This
->d3d_target
->WineD3DSurface
,
800 target
->WineD3DSurface
);
802 ERR("(%p) Error %08lx setting the front and back buffer\n", This
, hr
);
804 object
->OffScreenTarget
= TRUE
;
808 object
->OffScreenTarget
= FALSE
;
811 /* AddRef the render target. Also AddRef the render target from ddraw,
812 * because if it released before the app releases the D3D device, the D3D capatiblities
813 * of WineD3D will be uninitialized, which has bad effects.
815 * In most cases, those surfaces are the surfaces are the same anyway, but this will simply
816 * add another ref which is released when the device is destroyed.
818 IDirectDrawSurface7_AddRef(Surface
);
819 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(This
->d3d_target
, IDirectDrawSurface7
));
821 This
->d3ddevice
= object
;
826 static HRESULT WINAPI
827 Thunk_IDirect3DImpl_3_CreateDevice(IDirect3D3
*iface
,
829 IDirectDrawSurface4
*Surface
,
830 IDirect3DDevice3
**Device
,
833 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D3
, iface
);
835 TRACE("(%p)->(%s,%p,%p,%p): Thunking to IDirect3D7\n", This
, debugstr_guid(refiid
), Surface
, Device
, UnkOuter
);
838 return CLASS_E_NOAGGREGATION
;
840 hr
= IDirect3D7_CreateDevice(ICOM_INTERFACE(This
, IDirect3D7
),
842 (IDirectDrawSurface7
*) Surface
/* Same VTables */,
843 (IDirect3DDevice7
**) Device
);
845 *Device
= COM_INTERFACE_CAST(IDirect3DDeviceImpl
, IDirect3DDevice7
, IDirect3DDevice3
, *Device
);
849 static HRESULT WINAPI
850 Thunk_IDirect3DImpl_2_CreateDevice(IDirect3D2
*iface
,
852 IDirectDrawSurface
*Surface
,
853 IDirect3DDevice2
**Device
)
855 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D2
, iface
);
857 TRACE("(%p)->(%s,%p,%p): Thunking to IDirect3D7\n", This
, debugstr_guid(refiid
), Surface
, Device
);
859 hr
= IDirect3D7_CreateDevice(ICOM_INTERFACE(This
, IDirect3D7
),
861 COM_INTERFACE_CAST(IDirectDrawSurfaceImpl
, IDirectDrawSurface3
, IDirectDrawSurface7
, Surface
),
862 (IDirect3DDevice7
**) Device
);
864 *Device
= COM_INTERFACE_CAST(IDirect3DDeviceImpl
, IDirect3DDevice7
, IDirect3DDevice2
, *Device
);
868 /*****************************************************************************
869 * IDirect3D7::CreateVertexBuffer
871 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
877 * Desc: Requested Vertex buffer properties
878 * VertexBuffer: Address to return the interface pointer at
879 * Flags: Some flags, must be 0
883 * DDERR_OUTOFMEMORY if memory allocation failed
884 * The return value of IWineD3DDevice::CreateVertexBuffer if this call fails
885 * DDERR_INVALIDPARAMS if Desc or VertexBuffer are NULL, or Flags != 0
887 *****************************************************************************/
888 static HRESULT WINAPI
889 IDirect3DImpl_7_CreateVertexBuffer(IDirect3D7
*iface
,
890 D3DVERTEXBUFFERDESC
*Desc
,
891 IDirect3DVertexBuffer7
**VertexBuffer
,
894 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D7
, iface
);
895 IDirect3DVertexBufferImpl
*object
;
897 TRACE("(%p)->(%p,%p,%08lx)\n", This
, Desc
, VertexBuffer
, Flags
);
899 TRACE("(%p) Vertex buffer description: \n", This
);
900 TRACE("(%p) dwSize=%ld\n", This
, Desc
->dwSize
);
901 TRACE("(%p) dwCaps=%08lx\n", This
, Desc
->dwCaps
);
902 TRACE("(%p) FVF=%08lx\n", This
, Desc
->dwFVF
);
903 TRACE("(%p) dwNumVertices=%ld\n", This
, Desc
->dwNumVertices
);
905 /* D3D7 SDK: "No Flags are currently defined for this method. This
906 * parameter must be 0"
908 * Never trust the documentation - this is wrong
911 ERR("(%p) Flags is %08lx, returning DDERR_INVALIDPARAMS\n", This, Flags);
912 return DDERR_INVALIDPARAMS;
916 /* Well, this sounds sane */
917 if( (!VertexBuffer
) || (!Desc
) )
918 return DDERR_INVALIDPARAMS
;
920 /* Now create the vertex buffer */
921 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(IDirect3DVertexBufferImpl
));
924 ERR("(%p) Out of memory when allocating a IDirect3DVertexBufferImpl structure\n", This
);
925 return DDERR_OUTOFMEMORY
;
929 ICOM_INIT_INTERFACE(object
, IDirect3DVertexBuffer7
, IDirect3DVertexBuffer7_Vtbl
);
930 ICOM_INIT_INTERFACE(object
, IDirect3DVertexBuffer
, IDirect3DVertexBuffer1_Vtbl
);
932 object
->Caps
= Desc
->dwCaps
;
934 hr
= IWineD3DDevice_CreateVertexBuffer(This
->wineD3DDevice
,
935 get_flexible_vertex_size(Desc
->dwFVF
) * Desc
->dwNumVertices
,
936 Desc
->dwCaps
& D3DVBCAPS_WRITEONLY
? WINED3DUSAGE_WRITEONLY
: 0,
938 Desc
->dwCaps
& D3DVBCAPS_SYSTEMMEMORY
? WINED3DPOOL_SYSTEMMEM
: WINED3DPOOL_DEFAULT
,
939 &object
->wineD3DVertexBuffer
,
940 0 /* SharedHandle */,
941 (IUnknown
*) ICOM_INTERFACE(object
, IDirect3DVertexBuffer7
));
944 ERR("(%p) IWineD3DDevice::CreateVertexBuffer failed with hr=%08lx\n", This
, hr
);
945 HeapFree(GetProcessHeap(), 0, object
);
949 /* Return the interface */
950 *VertexBuffer
= ICOM_INTERFACE(object
, IDirect3DVertexBuffer7
);
952 TRACE("(%p) Created new vertex buffer implementation at %p, returning interface at %p\n", This
, object
, *VertexBuffer
);
956 static HRESULT WINAPI
957 Thunk_IDirect3DImpl_3_CreateVertexBuffer(IDirect3D3
*iface
,
958 D3DVERTEXBUFFERDESC
*Desc
,
959 IDirect3DVertexBuffer
**VertexBuffer
,
963 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D3
, iface
);
965 TRACE("(%p)->(%p,%p,%08lx,%p): Relaying to IDirect3D7\n", This
, Desc
, VertexBuffer
, Flags
, UnkOuter
);
967 if(UnkOuter
!= NULL
) return CLASS_E_NOAGGREGATION
;
969 hr
= IDirect3D7_CreateVertexBuffer(ICOM_INTERFACE(This
, IDirect3D7
),
971 (IDirect3DVertexBuffer7
**) VertexBuffer
,
974 *VertexBuffer
= COM_INTERFACE_CAST(IDirect3DVertexBufferImpl
, IDirect3DVertexBuffer7
, IDirect3DVertexBuffer
, *VertexBuffer
);
978 /*****************************************************************************
979 * EnumZBufferFormatsCB
981 * Helper function for IDirect3D7::EnumZBufferFormats. Converts
982 * the WINED3DFORMAT into a DirectDraw pixelformat and calls the application
988 * Device: Parent of the IWineD3DDevice, our IDirectDraw7 interface
989 * fmt: The enumerated pixel format
990 * Context: Context passed to IWineD3DDevice::EnumZBufferFormat
993 * The return value of the application-provided callback
995 *****************************************************************************/
996 static HRESULT WINAPI
997 EnumZBufferFormatsCB(IUnknown
*Device
,
1001 struct EnumZBufferFormatsData
*cbdata
= (struct EnumZBufferFormatsData
*) Context
;
1002 DDPIXELFORMAT pformat
;
1004 memset(&pformat
, 0, sizeof(DDPIXELFORMAT
));
1005 pformat
.dwSize
=sizeof(DDPIXELFORMAT
);
1006 PixelFormat_WineD3DtoDD(&pformat
, fmt
);
1007 return cbdata
->Callback(&pformat
, cbdata
->Context
);
1010 /*****************************************************************************
1011 * IDirect3D7::EnumZBufferFormats
1013 * Enumerates all supported Z buffer pixel formats
1019 * Callback: Callback to call for each pixel format
1020 * Context: Pointer to pass back to the callback
1024 * DDERR_INVALIDPARAMS if Callback is NULL
1025 * For details, see IWineD3DDevice::EnumZBufferFormats
1027 *****************************************************************************/
1028 static HRESULT WINAPI
1029 IDirect3DImpl_7_EnumZBufferFormats(IDirect3D7
*iface
,
1030 REFCLSID refiidDevice
,
1031 LPD3DENUMPIXELFORMATSCALLBACK Callback
,
1034 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D7
, iface
);
1035 struct EnumZBufferFormatsData cbdata
= { Callback
, Context
};
1036 TRACE("(%p)->(%s,%p,%p): Relay\n", iface
, debugstr_guid(refiidDevice
), Callback
, Context
);
1039 return DDERR_INVALIDPARAMS
;
1041 return IWineD3DDevice_EnumZBufferFormats(This
->wineD3DDevice
, EnumZBufferFormatsCB
, &cbdata
);
1044 static HRESULT WINAPI
1045 Thunk_IDirect3DImpl_3_EnumZBufferFormats(IDirect3D3
*iface
,
1046 REFCLSID riidDevice
,
1047 LPD3DENUMPIXELFORMATSCALLBACK Callback
,
1050 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D3
, iface
);
1051 TRACE("(%p)->(%s,%p,%p) thunking to IDirect3D7 interface.\n", This
, debugstr_guid(riidDevice
), Callback
, Context
);
1052 return IDirect3D7_EnumZBufferFormats(ICOM_INTERFACE(This
, IDirect3D7
),
1058 /*****************************************************************************
1059 * IDirect3D7::EvictManagedTextures
1061 * Removes all managed textures(=surfaces with DDSCAPS2_TEXTUREMANAGE or
1062 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
1067 * D3D_OK, because it's a stub
1069 *****************************************************************************/
1070 static HRESULT WINAPI
1071 IDirect3DImpl_7_EvictManagedTextures(IDirect3D7
*iface
)
1073 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D7
, iface
);
1074 FIXME("(%p): Stub!\n", This
);
1076 /* Implementation idea:
1077 * Add an IWineD3DSurface method which sets the opengl texture
1078 * priority low or even removes the opengl texture.
1084 static HRESULT WINAPI
1085 Thunk_IDirect3DImpl_3_EvictManagedTextures(IDirect3D3
*iface
)
1087 ICOM_THIS_FROM(IDirectDrawImpl
, IDirect3D3
, iface
);
1088 TRACE("(%p)->() thunking to IDirect3D7 interface.\n", This
);
1089 return IDirect3D7_EvictManagedTextures(ICOM_INTERFACE(This
, IDirect3D7
));
1092 /*****************************************************************************
1093 * IDirect3DImpl_GetCaps
1095 * This function retrieves the device caps from wined3d
1096 * and converts it into a D3D7 and D3D - D3D3 structure
1097 * This is a helper function called from various places in ddraw
1100 * WineD3D: The interface to get the caps from
1101 * Desc123: Old D3D <3 structure to fill(needed)
1102 * Desc7: D3D7 device desc structure to fill(needed)
1105 * D3D_OK on success, or the return value of IWineD3D::GetCaps
1107 *****************************************************************************/
1109 IDirect3DImpl_GetCaps(IWineD3D
*WineD3D
,
1110 D3DDEVICEDESC
*Desc123
,
1111 D3DDEVICEDESC7
*Desc7
)
1116 /* Some Variables to asign to the pointers in WCaps */
1117 WINED3DDEVTYPE DevType
;
1120 DWORD dummy_dword
, MaxTextureBlendStages
, MaxSimultaneousTextures
;
1121 DWORD MaxUserClipPlanes
, MaxVertexBlendMatrices
;
1123 TRACE("()->(%p,%p,%p\n", WineD3D
, Desc123
, Desc7
);
1125 /* Asign the pointers in WCaps */
1126 WCaps
.DeviceType
= &DevType
;
1127 WCaps
.AdapterOrdinal
= &dummy_uint
;
1129 WCaps
.Caps
= &dummy_dword
;
1130 WCaps
.Caps2
= &dummy_dword
;
1131 WCaps
.Caps3
= &dummy_dword
;
1132 WCaps
.PresentationIntervals
= &dummy_dword
;
1134 WCaps
.CursorCaps
= &dummy_dword
;
1136 WCaps
.DevCaps
= &Desc7
->dwDevCaps
;
1137 WCaps
.PrimitiveMiscCaps
= &dummy_dword
;
1138 WCaps
.RasterCaps
= &Desc7
->dpcLineCaps
.dwRasterCaps
;
1139 WCaps
.ZCmpCaps
= &Desc7
->dpcLineCaps
.dwZCmpCaps
;
1140 WCaps
.SrcBlendCaps
= &Desc7
->dpcLineCaps
.dwSrcBlendCaps
;
1141 WCaps
.DestBlendCaps
= &Desc7
->dpcLineCaps
.dwDestBlendCaps
;
1142 WCaps
.AlphaCmpCaps
= &Desc7
->dpcLineCaps
.dwAlphaCmpCaps
;
1143 WCaps
.ShadeCaps
= &Desc7
->dpcLineCaps
.dwShadeCaps
;
1144 WCaps
.TextureCaps
= &Desc7
->dpcLineCaps
.dwTextureCaps
;
1145 WCaps
.TextureFilterCaps
= &Desc7
->dpcLineCaps
.dwTextureFilterCaps
;
1146 WCaps
.CubeTextureFilterCaps
= &dummy_dword
;
1147 WCaps
.VolumeTextureFilterCaps
= &dummy_dword
;
1148 WCaps
.TextureAddressCaps
= &Desc7
->dpcLineCaps
.dwTextureAddressCaps
;
1149 WCaps
.VolumeTextureAddressCaps
= &dummy_dword
;
1151 WCaps
.LineCaps
= &dummy_dword
;
1152 WCaps
.MaxTextureWidth
= &Desc7
->dwMaxTextureWidth
;
1153 WCaps
.MaxTextureHeight
= &Desc7
->dwMaxTextureHeight
;
1154 WCaps
.MaxVolumeExtent
= &dummy_dword
;
1156 WCaps
.MaxTextureRepeat
= &Desc7
->dwMaxTextureRepeat
;
1157 WCaps
.MaxTextureAspectRatio
= &Desc7
->dwMaxTextureAspectRatio
;
1158 WCaps
.MaxAnisotropy
= &Desc7
->dwMaxAnisotropy
;
1159 WCaps
.MaxVertexW
= &Desc7
->dvMaxVertexW
;
1161 WCaps
.GuardBandLeft
= &Desc7
->dvGuardBandLeft
;
1162 WCaps
.GuardBandTop
= &Desc7
->dvGuardBandTop
;
1163 WCaps
.GuardBandRight
= &Desc7
->dvGuardBandRight
;
1164 WCaps
.GuardBandBottom
= &Desc7
->dvGuardBandBottom
;
1166 WCaps
.ExtentsAdjust
= &Desc7
->dvExtentsAdjust
;
1167 WCaps
.StencilCaps
= &Desc7
->dwStencilCaps
;
1169 WCaps
.FVFCaps
= &Desc7
->dwFVFCaps
;
1170 WCaps
.TextureOpCaps
= &Desc7
->dwTextureOpCaps
;
1171 WCaps
.MaxTextureBlendStages
= &MaxTextureBlendStages
;
1172 WCaps
.MaxSimultaneousTextures
= &MaxSimultaneousTextures
;
1174 WCaps
.VertexProcessingCaps
= &Desc7
->dwVertexProcessingCaps
;
1175 WCaps
.MaxActiveLights
= &Desc7
->dwMaxActiveLights
;
1176 WCaps
.MaxUserClipPlanes
= &MaxUserClipPlanes
;
1177 WCaps
.MaxVertexBlendMatrices
= &MaxVertexBlendMatrices
;
1178 WCaps
.MaxVertexBlendMatrixIndex
= &dummy_dword
;
1180 WCaps
.MaxPointSize
= &dummy_float
;
1181 WCaps
.MaxPrimitiveCount
= &dummy_dword
;
1182 WCaps
.MaxVertexIndex
= &dummy_dword
;
1183 WCaps
.MaxStreams
= &dummy_dword
;
1184 WCaps
.MaxStreamStride
= &dummy_dword
;
1186 WCaps
.VertexShaderVersion
= &dummy_dword
;
1187 WCaps
.MaxVertexShaderConst
= &dummy_dword
;
1189 WCaps
.PixelShaderVersion
= &dummy_dword
;
1190 WCaps
.PixelShader1xMaxValue
= &dummy_float
;
1192 /* These are dx9 only, set them to NULL */
1193 WCaps
.DevCaps2
= NULL
;
1194 WCaps
.MaxNpatchTessellationLevel
= NULL
;
1195 WCaps
.Reserved5
= NULL
;
1196 WCaps
.MasterAdapterOrdinal
= NULL
;
1197 WCaps
.AdapterOrdinalInGroup
= NULL
;
1198 WCaps
.NumberOfAdaptersInGroup
= NULL
;
1199 WCaps
.DeclTypes
= NULL
;
1200 WCaps
.NumSimultaneousRTs
= NULL
;
1201 WCaps
.StretchRectFilterCaps
= NULL
;
1202 /* WCaps.VS20Caps = NULL; */
1203 /* WCaps.PS20Caps = NULL; */
1204 WCaps
.VertexTextureFilterCaps
= NULL
;
1205 WCaps
.MaxVShaderInstructionsExecuted
= NULL
;
1206 WCaps
.MaxPShaderInstructionsExecuted
= NULL
;
1207 WCaps
.MaxVertexShader30InstructionSlots
= NULL
;
1208 WCaps
.MaxPixelShader30InstructionSlots
= NULL
;
1209 WCaps
.Reserved2
= NULL
;
1210 WCaps
.Reserved3
= NULL
;
1212 /* Now get the caps */
1213 hr
= IWineD3D_GetDeviceCaps(WineD3D
, 0, WINED3DDEVTYPE_HAL
, &WCaps
);
1214 if(hr
!= D3D_OK
) return hr
;
1216 /* Fill the missing members, and do some fixup */
1217 Desc7
->dpcLineCaps
.dwSize
= sizeof(Desc7
->dpcLineCaps
);
1218 Desc7
->dpcLineCaps
.dwTextureBlendCaps
= D3DPTBLENDCAPS_ADD
| D3DPTBLENDCAPS_MODULATEMASK
|
1219 D3DPTBLENDCAPS_COPY
| D3DPTBLENDCAPS_DECAL
|
1220 D3DPTBLENDCAPS_DECALALPHA
| D3DPTBLENDCAPS_DECALMASK
|
1221 D3DPTBLENDCAPS_MODULATE
| D3DPTBLENDCAPS_MODULATEALPHA
;
1222 Desc7
->dpcLineCaps
.dwStippleWidth
= 32;
1223 Desc7
->dpcLineCaps
.dwStippleHeight
= 32;
1224 /* Use the same for the TriCaps */
1225 Desc7
->dpcTriCaps
= Desc7
->dpcLineCaps
;
1227 Desc7
->dwDeviceRenderBitDepth
= DDBD_16
| DDBD_24
| DDBD_32
;
1228 Desc7
->dwDeviceZBufferBitDepth
= DDBD_16
| DDBD_24
;
1229 Desc7
->dwMinTextureWidth
= 1;
1230 Desc7
->dwMinTextureHeight
= 1;
1232 /* Convert DWORDs safely to WORDs */
1233 if(MaxTextureBlendStages
> 65535) Desc7
->wMaxTextureBlendStages
= 65535;
1234 else Desc7
->wMaxTextureBlendStages
= (WORD
) MaxTextureBlendStages
;
1235 if(MaxSimultaneousTextures
> 65535) Desc7
->wMaxSimultaneousTextures
= 65535;
1236 else Desc7
->wMaxSimultaneousTextures
= (WORD
) MaxSimultaneousTextures
;
1238 if(MaxUserClipPlanes
> 65535) Desc7
->wMaxUserClipPlanes
= 65535;
1239 else Desc7
->wMaxUserClipPlanes
= (WORD
) MaxUserClipPlanes
;
1240 if(MaxVertexBlendMatrices
> 65535) Desc7
->wMaxVertexBlendMatrices
= 65535;
1241 else Desc7
->wMaxVertexBlendMatrices
= (WORD
) MaxVertexBlendMatrices
;
1243 Desc7
->deviceGUID
= IID_IDirect3DTnLHalDevice
;
1245 Desc7
->dwReserved1
= 0;
1246 Desc7
->dwReserved2
= 0;
1247 Desc7
->dwReserved3
= 0;
1248 Desc7
->dwReserved4
= 0;
1250 /* Fill the old structure */
1251 memset(Desc123
, 0x0, sizeof(D3DDEVICEDESC
));
1252 Desc123
->dwSize
= sizeof(D3DDEVICEDESC
);
1253 Desc123
->dwFlags
= D3DDD_COLORMODEL
|
1255 D3DDD_TRANSFORMCAPS
|
1257 D3DDD_LIGHTINGCAPS
|
1260 D3DDD_DEVICERENDERBITDEPTH
|
1261 D3DDD_DEVICEZBUFFERBITDEPTH
|
1262 D3DDD_MAXBUFFERSIZE
|
1263 D3DDD_MAXVERTEXCOUNT
;
1264 Desc123
->dcmColorModel
= D3DCOLOR_RGB
;
1265 Desc123
->dwDevCaps
= Desc7
->dwDevCaps
;
1266 Desc123
->dtcTransformCaps
.dwSize
= sizeof(D3DTRANSFORMCAPS
);
1267 Desc123
->dtcTransformCaps
.dwCaps
= D3DTRANSFORMCAPS_CLIP
;
1268 Desc123
->bClipping
= TRUE
;
1269 Desc123
->dlcLightingCaps
.dwSize
= sizeof(D3DLIGHTINGCAPS
);
1270 Desc123
->dlcLightingCaps
.dwCaps
= D3DLIGHTCAPS_DIRECTIONAL
| D3DLIGHTCAPS_PARALLELPOINT
| D3DLIGHTCAPS_POINT
| D3DLIGHTCAPS_SPOT
;
1271 Desc123
->dlcLightingCaps
.dwLightingModel
= D3DLIGHTINGMODEL_RGB
;
1272 Desc123
->dlcLightingCaps
.dwNumLights
= Desc7
->dwMaxActiveLights
;
1274 Desc123
->dpcLineCaps
.dwSize
= sizeof(D3DPRIMCAPS
);
1275 Desc123
->dpcLineCaps
.dwMiscCaps
= Desc7
->dpcLineCaps
.dwMiscCaps
;
1276 Desc123
->dpcLineCaps
.dwRasterCaps
= Desc7
->dpcLineCaps
.dwRasterCaps
;
1277 Desc123
->dpcLineCaps
.dwZCmpCaps
= Desc7
->dpcLineCaps
.dwZCmpCaps
;
1278 Desc123
->dpcLineCaps
.dwSrcBlendCaps
= Desc7
->dpcLineCaps
.dwSrcBlendCaps
;
1279 Desc123
->dpcLineCaps
.dwDestBlendCaps
= Desc7
->dpcLineCaps
.dwDestBlendCaps
;
1280 Desc123
->dpcLineCaps
.dwShadeCaps
= Desc7
->dpcLineCaps
.dwShadeCaps
;
1281 Desc123
->dpcLineCaps
.dwTextureCaps
= Desc7
->dpcLineCaps
.dwTextureCaps
;
1282 Desc123
->dpcLineCaps
.dwTextureFilterCaps
= Desc7
->dpcLineCaps
.dwTextureFilterCaps
;
1283 Desc123
->dpcLineCaps
.dwTextureBlendCaps
= Desc7
->dpcLineCaps
.dwTextureBlendCaps
;
1284 Desc123
->dpcLineCaps
.dwTextureAddressCaps
= Desc7
->dpcLineCaps
.dwTextureAddressCaps
;
1285 Desc123
->dpcLineCaps
.dwStippleWidth
= Desc7
->dpcLineCaps
.dwStippleWidth
;
1286 Desc123
->dpcLineCaps
.dwAlphaCmpCaps
= Desc7
->dpcLineCaps
.dwAlphaCmpCaps
;
1288 Desc123
->dpcTriCaps
.dwSize
= sizeof(D3DPRIMCAPS
);
1289 Desc123
->dpcTriCaps
.dwMiscCaps
= Desc7
->dpcTriCaps
.dwMiscCaps
;
1290 Desc123
->dpcTriCaps
.dwRasterCaps
= Desc7
->dpcTriCaps
.dwRasterCaps
;
1291 Desc123
->dpcTriCaps
.dwZCmpCaps
= Desc7
->dpcTriCaps
.dwZCmpCaps
;
1292 Desc123
->dpcTriCaps
.dwSrcBlendCaps
= Desc7
->dpcTriCaps
.dwSrcBlendCaps
;
1293 Desc123
->dpcTriCaps
.dwDestBlendCaps
= Desc7
->dpcTriCaps
.dwDestBlendCaps
;
1294 Desc123
->dpcTriCaps
.dwShadeCaps
= Desc7
->dpcTriCaps
.dwShadeCaps
;
1295 Desc123
->dpcTriCaps
.dwTextureCaps
= Desc7
->dpcTriCaps
.dwTextureCaps
;
1296 Desc123
->dpcTriCaps
.dwTextureFilterCaps
= Desc7
->dpcTriCaps
.dwTextureFilterCaps
;
1297 Desc123
->dpcTriCaps
.dwTextureBlendCaps
= Desc7
->dpcTriCaps
.dwTextureBlendCaps
;
1298 Desc123
->dpcTriCaps
.dwTextureAddressCaps
= Desc7
->dpcTriCaps
.dwTextureAddressCaps
;
1299 Desc123
->dpcTriCaps
.dwStippleWidth
= Desc7
->dpcTriCaps
.dwStippleWidth
;
1300 Desc123
->dpcTriCaps
.dwAlphaCmpCaps
= Desc7
->dpcTriCaps
.dwAlphaCmpCaps
;
1302 Desc123
->dwDeviceRenderBitDepth
= Desc7
->dwDeviceRenderBitDepth
;
1303 Desc123
->dwDeviceZBufferBitDepth
= Desc7
->dwDeviceZBufferBitDepth
;
1304 Desc123
->dwMaxBufferSize
= 0;
1305 Desc123
->dwMaxVertexCount
= 65536;
1306 Desc123
->dwMinTextureWidth
= Desc7
->dwMinTextureWidth
;
1307 Desc123
->dwMinTextureHeight
= Desc7
->dwMinTextureHeight
;
1308 Desc123
->dwMaxTextureWidth
= Desc7
->dwMaxTextureWidth
;
1309 Desc123
->dwMaxTextureHeight
= Desc7
->dwMaxTextureHeight
;
1310 Desc123
->dwMinStippleWidth
= 1;
1311 Desc123
->dwMinStippleHeight
= 1;
1312 Desc123
->dwMaxStippleWidth
= 32;
1313 Desc123
->dwMaxStippleHeight
= 32;
1314 Desc123
->dwMaxTextureRepeat
= Desc7
->dwMaxTextureRepeat
;
1315 Desc123
->dwMaxTextureAspectRatio
= Desc7
->dwMaxTextureAspectRatio
;
1316 Desc123
->dwMaxAnisotropy
= Desc7
->dwMaxAnisotropy
;
1317 Desc123
->dvGuardBandLeft
= Desc7
->dvGuardBandLeft
;
1318 Desc123
->dvGuardBandRight
= Desc7
->dvGuardBandRight
;
1319 Desc123
->dvGuardBandTop
= Desc7
->dvGuardBandTop
;
1320 Desc123
->dvGuardBandBottom
= Desc7
->dvGuardBandBottom
;
1321 Desc123
->dvExtentsAdjust
= Desc7
->dvExtentsAdjust
;
1322 Desc123
->dwStencilCaps
= Desc7
->dwStencilCaps
;
1323 Desc123
->dwFVFCaps
= Desc7
->dwFVFCaps
;
1324 Desc123
->dwTextureOpCaps
= Desc7
->dwTextureOpCaps
;
1325 Desc123
->wMaxTextureBlendStages
= Desc7
->wMaxTextureBlendStages
;
1326 Desc123
->wMaxSimultaneousTextures
= Desc7
->wMaxSimultaneousTextures
;
1330 /*****************************************************************************
1331 * IDirect3D vtables in various versions
1332 *****************************************************************************/
1334 const IDirect3DVtbl IDirect3D1_Vtbl
=
1336 /*** IUnknown methods ***/
1337 Thunk_IDirect3DImpl_1_QueryInterface
,
1338 Thunk_IDirect3DImpl_1_AddRef
,
1339 Thunk_IDirect3DImpl_1_Release
,
1340 /*** IDirect3D methods ***/
1341 IDirect3DImpl_1_Initialize
,
1342 Thunk_IDirect3DImpl_1_EnumDevices
,
1343 Thunk_IDirect3DImpl_1_CreateLight
,
1344 Thunk_IDirect3DImpl_1_CreateMaterial
,
1345 Thunk_IDirect3DImpl_1_CreateViewport
,
1346 Thunk_IDirect3DImpl_1_FindDevice
1349 const IDirect3D2Vtbl IDirect3D2_Vtbl
=
1351 /*** IUnknown methods ***/
1352 Thunk_IDirect3DImpl_2_QueryInterface
,
1353 Thunk_IDirect3DImpl_2_AddRef
,
1354 Thunk_IDirect3DImpl_2_Release
,
1355 /*** IDirect3D2 methods ***/
1356 Thunk_IDirect3DImpl_2_EnumDevices
,
1357 Thunk_IDirect3DImpl_2_CreateLight
,
1358 Thunk_IDirect3DImpl_2_CreateMaterial
,
1359 Thunk_IDirect3DImpl_2_CreateViewport
,
1360 Thunk_IDirect3DImpl_2_FindDevice
,
1361 Thunk_IDirect3DImpl_2_CreateDevice
1364 const IDirect3D3Vtbl IDirect3D3_Vtbl
=
1366 /*** IUnknown methods ***/
1367 Thunk_IDirect3DImpl_3_QueryInterface
,
1368 Thunk_IDirect3DImpl_3_AddRef
,
1369 Thunk_IDirect3DImpl_3_Release
,
1370 /*** IDirect3D3 methods ***/
1371 IDirect3DImpl_3_EnumDevices
,
1372 IDirect3DImpl_3_CreateLight
,
1373 IDirect3DImpl_3_CreateMaterial
,
1374 IDirect3DImpl_3_CreateViewport
,
1375 IDirect3DImpl_3_FindDevice
,
1376 Thunk_IDirect3DImpl_3_CreateDevice
,
1377 Thunk_IDirect3DImpl_3_CreateVertexBuffer
,
1378 Thunk_IDirect3DImpl_3_EnumZBufferFormats
,
1379 Thunk_IDirect3DImpl_3_EvictManagedTextures
1382 const IDirect3D7Vtbl IDirect3D7_Vtbl
=
1384 /*** IUnknown methods ***/
1385 Thunk_IDirect3DImpl_7_QueryInterface
,
1386 Thunk_IDirect3DImpl_7_AddRef
,
1387 Thunk_IDirect3DImpl_7_Release
,
1388 /*** IDirect3D7 methods ***/
1389 IDirect3DImpl_7_EnumDevices
,
1390 IDirect3DImpl_7_CreateDevice
,
1391 IDirect3DImpl_7_CreateVertexBuffer
,
1392 IDirect3DImpl_7_EnumZBufferFormats
,
1393 IDirect3DImpl_7_EvictManagedTextures