2 * IDirect3D9 implementation
4 * Copyright 2002 Jason Edmeades
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "d3d9_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d
);
26 /* IDirect3D9 IUnknown parts follow: */
27 HRESULT WINAPI
IDirect3D9Impl_QueryInterface(LPDIRECT3D9 iface
, REFIID riid
, LPVOID
* ppobj
)
29 IDirect3D9Impl
*This
= (IDirect3D9Impl
*)iface
;
31 if (IsEqualGUID(riid
, &IID_IUnknown
)
32 || IsEqualGUID(riid
, &IID_IDirect3D9
)) {
33 IDirect3D9Impl_AddRef(iface
);
38 WARN("(%p)->(%s,%p),not found\n", This
, debugstr_guid(riid
), ppobj
);
42 ULONG WINAPI
IDirect3D9Impl_AddRef(LPDIRECT3D9 iface
) {
43 IDirect3D9Impl
*This
= (IDirect3D9Impl
*)iface
;
44 TRACE("(%p) : AddRef from %ld\n", This
, This
->ref
);
48 ULONG WINAPI
IDirect3D9Impl_Release(LPDIRECT3D9 iface
) {
49 IDirect3D9Impl
*This
= (IDirect3D9Impl
*)iface
;
50 ULONG ref
= --This
->ref
;
51 TRACE("(%p) : ReleaseRef to %ld\n", This
, This
->ref
);
53 IWineD3D_Release(This
->WineD3D
);
54 HeapFree(GetProcessHeap(), 0, This
);
60 /* IDirect3D9 Interface follow: */
61 HRESULT WINAPI
IDirect3D9Impl_RegisterSoftwareDevice(LPDIRECT3D9 iface
, void* pInitializeFunction
) {
62 IDirect3D9Impl
*This
= (IDirect3D9Impl
*)iface
;
63 return IWineD3D_RegisterSoftwareDevice(This
->WineD3D
, pInitializeFunction
);
66 UINT WINAPI
IDirect3D9Impl_GetAdapterCount(LPDIRECT3D9 iface
) {
67 IDirect3D9Impl
*This
= (IDirect3D9Impl
*)iface
;
68 return IWineD3D_GetAdapterCount(This
->WineD3D
);
71 HRESULT WINAPI
IDirect3D9Impl_GetAdapterIdentifier(LPDIRECT3D9 iface
, UINT Adapter
, DWORD Flags
, D3DADAPTER_IDENTIFIER9
* pIdentifier
) {
72 IDirect3D9Impl
*This
= (IDirect3D9Impl
*)iface
;
73 WINED3DADAPTER_IDENTIFIER adapter_id
;
75 /* dx8 and dx9 have different structures to be filled in, with incompatible
76 layouts so pass in pointers to the places to be filled via an internal
78 adapter_id
.Driver
= pIdentifier
->Driver
;
79 adapter_id
.Description
= pIdentifier
->Description
;
80 adapter_id
.DeviceName
= pIdentifier
->DeviceName
;
81 adapter_id
.DriverVersion
= &pIdentifier
->DriverVersion
;
82 adapter_id
.VendorId
= &pIdentifier
->VendorId
;
83 adapter_id
.DeviceId
= &pIdentifier
->DeviceId
;
84 adapter_id
.SubSysId
= &pIdentifier
->SubSysId
;
85 adapter_id
.Revision
= &pIdentifier
->Revision
;
86 adapter_id
.DeviceIdentifier
= &pIdentifier
->DeviceIdentifier
;
87 adapter_id
.WHQLLevel
= &pIdentifier
->WHQLLevel
;
89 return IWineD3D_GetAdapterIdentifier(This
->WineD3D
, Adapter
, Flags
, &adapter_id
);
92 UINT WINAPI
IDirect3D9Impl_GetAdapterModeCount(LPDIRECT3D9 iface
, UINT Adapter
, D3DFORMAT Format
) {
93 IDirect3D9Impl
*This
= (IDirect3D9Impl
*)iface
;
94 return IWineD3D_GetAdapterModeCount(This
->WineD3D
, Adapter
, Format
);
97 HRESULT WINAPI
IDirect3D9Impl_EnumAdapterModes(LPDIRECT3D9 iface
, UINT Adapter
, D3DFORMAT Format
, UINT Mode
, D3DDISPLAYMODE
* pMode
) {
98 IDirect3D9Impl
*This
= (IDirect3D9Impl
*)iface
;
99 return IWineD3D_EnumAdapterModes(This
->WineD3D
, Adapter
, Format
, Mode
, pMode
);
102 HRESULT WINAPI
IDirect3D9Impl_GetAdapterDisplayMode(LPDIRECT3D9 iface
, UINT Adapter
, D3DDISPLAYMODE
* pMode
) {
103 IDirect3D9Impl
*This
= (IDirect3D9Impl
*)iface
;
104 return IWineD3D_GetAdapterDisplayMode(This
->WineD3D
, Adapter
, pMode
);
107 HRESULT WINAPI
IDirect3D9Impl_CheckDeviceType(LPDIRECT3D9 iface
,
108 UINT Adapter
, D3DDEVTYPE CheckType
, D3DFORMAT DisplayFormat
,
109 D3DFORMAT BackBufferFormat
, BOOL Windowed
) {
110 IDirect3D9Impl
*This
= (IDirect3D9Impl
*)iface
;
111 return IWineD3D_CheckDeviceType(This
->WineD3D
, Adapter
, CheckType
, DisplayFormat
,
112 BackBufferFormat
, Windowed
);
115 HRESULT WINAPI
IDirect3D9Impl_CheckDeviceFormat(LPDIRECT3D9 iface
,
116 UINT Adapter
, D3DDEVTYPE DeviceType
, D3DFORMAT AdapterFormat
,
117 DWORD Usage
, D3DRESOURCETYPE RType
, D3DFORMAT CheckFormat
) {
118 IDirect3D9Impl
*This
= (IDirect3D9Impl
*)iface
;
119 return IWineD3D_CheckDeviceFormat(This
->WineD3D
, Adapter
, DeviceType
, AdapterFormat
,
120 Usage
, RType
, CheckFormat
);
123 HRESULT WINAPI
IDirect3D9Impl_CheckDeviceMultiSampleType(LPDIRECT3D9 iface
,
124 UINT Adapter
, D3DDEVTYPE DeviceType
, D3DFORMAT SurfaceFormat
,
125 BOOL Windowed
, D3DMULTISAMPLE_TYPE MultiSampleType
, DWORD
* pQualityLevels
) {
126 IDirect3D9Impl
*This
= (IDirect3D9Impl
*)iface
;
127 return IWineD3D_CheckDeviceMultiSampleType(This
->WineD3D
, Adapter
, DeviceType
, SurfaceFormat
,
128 Windowed
, MultiSampleType
, pQualityLevels
);
131 HRESULT WINAPI
IDirect3D9Impl_CheckDepthStencilMatch(LPDIRECT3D9 iface
,
132 UINT Adapter
, D3DDEVTYPE DeviceType
, D3DFORMAT AdapterFormat
,
133 D3DFORMAT RenderTargetFormat
, D3DFORMAT DepthStencilFormat
) {
134 IDirect3D9Impl
*This
= (IDirect3D9Impl
*)iface
;
135 return IWineD3D_CheckDepthStencilMatch(This
->WineD3D
, Adapter
, DeviceType
, AdapterFormat
,
136 RenderTargetFormat
, DepthStencilFormat
);
139 HRESULT WINAPI
IDirect3D9Impl_CheckDeviceFormatConversion(LPDIRECT3D9 iface
, UINT Adapter
, D3DDEVTYPE DeviceType
, D3DFORMAT SourceFormat
, D3DFORMAT TargetFormat
) {
140 IDirect3D9Impl
*This
= (IDirect3D9Impl
*)iface
;
141 return IWineD3D_CheckDeviceFormatConversion(This
->WineD3D
, Adapter
, DeviceType
, SourceFormat
,
145 HRESULT WINAPI
IDirect3D9Impl_GetDeviceCaps(LPDIRECT3D9 iface
, UINT Adapter
, D3DDEVTYPE DeviceType
, D3DCAPS9
* pCaps
) {
146 IDirect3D9Impl
*This
= (IDirect3D9Impl
*)iface
;
147 return IWineD3D_GetDeviceCaps(This
->WineD3D
, Adapter
, DeviceType
, (WINED3DCAPS
*)pCaps
);
150 HMONITOR WINAPI
IDirect3D9Impl_GetAdapterMonitor(LPDIRECT3D9 iface
, UINT Adapter
) {
151 IDirect3D9Impl
*This
= (IDirect3D9Impl
*)iface
;
152 return IWineD3D_GetAdapterMonitor(This
->WineD3D
, Adapter
);
155 /* Internal function called back during the CreateDevice to create a render target */
156 HRESULT WINAPI
D3D9CB_CreateRenderTarget(IUnknown
*device
, UINT Width
, UINT Height
,
157 D3DFORMAT Format
, D3DMULTISAMPLE_TYPE MultiSample
,
158 DWORD MultisampleQuality
, BOOL Lockable
,
159 IWineD3DSurface
** ppSurface
, HANDLE
* pSharedHandle
) {
160 HRESULT res
= D3D_OK
;
161 IDirect3DSurface9Impl
*d3dSurface
= NULL
;
163 res
= IDirect3DDevice9_CreateRenderTarget((IDirect3DDevice9
*)device
, Width
, Height
,
164 Format
, MultiSample
, MultisampleQuality
, Lockable
,
165 (IDirect3DSurface9
**)&d3dSurface
, pSharedHandle
);
167 *ppSurface
= d3dSurface
->wineD3DSurface
;
174 HRESULT WINAPI
IDirect3D9Impl_CreateDevice(LPDIRECT3D9 iface
, UINT Adapter
, D3DDEVTYPE DeviceType
, HWND hFocusWindow
,
175 DWORD BehaviourFlags
, D3DPRESENT_PARAMETERS
* pPresentationParameters
,
176 IDirect3DDevice9
** ppReturnedDeviceInterface
) {
178 IDirect3D9Impl
*This
= (IDirect3D9Impl
*)iface
;
179 IDirect3DDevice9Impl
*object
= NULL
;
180 WINED3DPRESENT_PARAMETERS localParameters
;
182 /* Check the validity range of the adapter parameter */
183 if (Adapter
>= IDirect3D9Impl_GetAdapterCount(iface
)) {
184 *ppReturnedDeviceInterface
= NULL
;
185 return D3DERR_INVALIDCALL
;
188 /* Allocate the storage for the device object */
189 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirect3DDevice9Impl
));
190 if (NULL
== object
) {
191 FIXME("Allocation of memory failed\n");
192 *ppReturnedDeviceInterface
= NULL
;
193 return D3DERR_OUTOFVIDEOMEMORY
;
196 object
->lpVtbl
= &Direct3DDevice9_Vtbl
;
198 object
->direct3d
= This
;
199 IDirect3D9_AddRef((LPDIRECT3D9
) object
->direct3d
);
200 *ppReturnedDeviceInterface
= (IDirect3DDevice9
*)object
;
202 /* Allocate an associated WineD3DDevice object */
203 localParameters
.BackBufferWidth
= &pPresentationParameters
->BackBufferWidth
;
204 localParameters
.BackBufferHeight
= &pPresentationParameters
->BackBufferHeight
;
205 localParameters
.BackBufferFormat
= &pPresentationParameters
->BackBufferFormat
;
206 localParameters
.BackBufferCount
= &pPresentationParameters
->BackBufferCount
;
207 localParameters
.MultiSampleType
= &pPresentationParameters
->MultiSampleType
;
208 localParameters
.MultiSampleQuality
= &pPresentationParameters
->MultiSampleQuality
;
209 localParameters
.SwapEffect
= &pPresentationParameters
->SwapEffect
;
210 localParameters
.hDeviceWindow
= &pPresentationParameters
->hDeviceWindow
;
211 localParameters
.Windowed
= &pPresentationParameters
->Windowed
;
212 localParameters
.EnableAutoDepthStencil
= &pPresentationParameters
->EnableAutoDepthStencil
;
213 localParameters
.AutoDepthStencilFormat
= &pPresentationParameters
->AutoDepthStencilFormat
;
214 localParameters
.Flags
= &pPresentationParameters
->Flags
;
215 localParameters
.FullScreen_RefreshRateInHz
= &pPresentationParameters
->FullScreen_RefreshRateInHz
;
216 localParameters
.PresentationInterval
= &pPresentationParameters
->PresentationInterval
;
217 return IWineD3D_CreateDevice(This
->WineD3D
, Adapter
, DeviceType
, hFocusWindow
, BehaviourFlags
, &localParameters
, &object
->WineD3DDevice
, (IUnknown
*)object
, D3D9CB_CreateRenderTarget
);
220 IDirect3D9Vtbl Direct3D9_Vtbl
=
222 IDirect3D9Impl_QueryInterface
,
223 IDirect3D9Impl_AddRef
,
224 IDirect3D9Impl_Release
,
225 IDirect3D9Impl_RegisterSoftwareDevice
,
226 IDirect3D9Impl_GetAdapterCount
,
227 IDirect3D9Impl_GetAdapterIdentifier
,
228 IDirect3D9Impl_GetAdapterModeCount
,
229 IDirect3D9Impl_EnumAdapterModes
,
230 IDirect3D9Impl_GetAdapterDisplayMode
,
231 IDirect3D9Impl_CheckDeviceType
,
232 IDirect3D9Impl_CheckDeviceFormat
,
233 IDirect3D9Impl_CheckDeviceMultiSampleType
,
234 IDirect3D9Impl_CheckDepthStencilMatch
,
235 IDirect3D9Impl_CheckDeviceFormatConversion
,
236 IDirect3D9Impl_GetDeviceCaps
,
237 IDirect3D9Impl_GetAdapterMonitor
,
238 IDirect3D9Impl_CreateDevice