1 | /*
|
---|
2 | * IDirect3D9 implementation
|
---|
3 | *
|
---|
4 | * Copyright 2002 Jason Edmeades
|
---|
5 | * Copyright 2005 Oliver Stieber
|
---|
6 | *
|
---|
7 | * This library is free software; you can redistribute it and/or
|
---|
8 | * modify it under the terms of the GNU Lesser General Public
|
---|
9 | * License as published by the Free Software Foundation; either
|
---|
10 | * version 2.1 of the License, or (at your option) any later version.
|
---|
11 | *
|
---|
12 | * This library is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
15 | * Lesser General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU Lesser General Public
|
---|
18 | * License along with this library; if not, write to the Free Software
|
---|
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
---|
20 | */
|
---|
21 |
|
---|
22 | /*
|
---|
23 | * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
24 | * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
|
---|
25 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
26 | * a choice of LGPL license versions is made available with the language indicating
|
---|
27 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
28 | * of the LGPL is applied is otherwise unspecified.
|
---|
29 | */
|
---|
30 |
|
---|
31 | #include "config.h"
|
---|
32 | #include "d3d9_private.h"
|
---|
33 |
|
---|
34 | #include <iprt/cdefs.h>
|
---|
35 |
|
---|
36 | WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
|
---|
37 |
|
---|
38 | /* IDirect3D9 IUnknown parts follow: */
|
---|
39 | static HRESULT WINAPI IDirect3D9Impl_QueryInterface(LPDIRECT3D9EX iface, REFIID riid, LPVOID* ppobj)
|
---|
40 | {
|
---|
41 | IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
---|
42 |
|
---|
43 | TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
|
---|
44 |
|
---|
45 | if (IsEqualGUID(riid, &IID_IUnknown)
|
---|
46 | || IsEqualGUID(riid, &IID_IDirect3D9)) {
|
---|
47 | IDirect3D9Ex_AddRef(iface);
|
---|
48 | *ppobj = This;
|
---|
49 | TRACE("Returning IDirect3D9 interface at %p\n", *ppobj);
|
---|
50 | return S_OK;
|
---|
51 | } else if(IsEqualGUID(riid, &IID_IDirect3D9Ex)) {
|
---|
52 | if(This->extended) {
|
---|
53 | *ppobj = This;
|
---|
54 | TRACE("Returning IDirect3D9Ex interface at %p\n", *ppobj);
|
---|
55 | IDirect3D9Ex_AddRef((IDirect3D9Ex *)*ppobj);
|
---|
56 | return S_OK;
|
---|
57 | } else {
|
---|
58 | WARN("Application asks for IDirect3D9Ex, but this instance wasn't created with Direct3DCreate9Ex\n");
|
---|
59 | WARN("Returning E_NOINTERFACE\n");
|
---|
60 | *ppobj = NULL;
|
---|
61 | ERR_D3D();
|
---|
62 | return E_NOINTERFACE;
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
|
---|
67 | *ppobj = NULL;
|
---|
68 | ERR_D3D();
|
---|
69 | return E_NOINTERFACE;
|
---|
70 | }
|
---|
71 |
|
---|
72 | static ULONG WINAPI IDirect3D9Impl_AddRef(LPDIRECT3D9EX iface) {
|
---|
73 | IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
---|
74 | ULONG ref = InterlockedIncrement(&This->ref);
|
---|
75 |
|
---|
76 | TRACE("%p increasing refcount to %u.\n", iface, ref);
|
---|
77 |
|
---|
78 | return ref;
|
---|
79 | }
|
---|
80 |
|
---|
81 | static ULONG WINAPI IDirect3D9Impl_Release(LPDIRECT3D9EX iface) {
|
---|
82 | IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
---|
83 | ULONG ref = InterlockedDecrement(&This->ref);
|
---|
84 |
|
---|
85 | TRACE("%p decreasing refcount to %u.\n", iface, ref);
|
---|
86 |
|
---|
87 | if (ref == 0) {
|
---|
88 | wined3d_mutex_lock();
|
---|
89 | IWineD3D_Release(This->WineD3D);
|
---|
90 | wined3d_mutex_unlock();
|
---|
91 |
|
---|
92 | HeapFree(GetProcessHeap(), 0, This);
|
---|
93 | }
|
---|
94 |
|
---|
95 | return ref;
|
---|
96 | }
|
---|
97 |
|
---|
98 | /* IDirect3D9 Interface follow: */
|
---|
99 | static HRESULT WINAPI IDirect3D9Impl_RegisterSoftwareDevice(LPDIRECT3D9EX iface, void* pInitializeFunction) {
|
---|
100 | IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
---|
101 | HRESULT hr;
|
---|
102 |
|
---|
103 | TRACE("iface %p, init_function %p.\n", iface, pInitializeFunction);
|
---|
104 |
|
---|
105 | wined3d_mutex_lock();
|
---|
106 | hr = IWineD3D_RegisterSoftwareDevice(This->WineD3D, pInitializeFunction);
|
---|
107 | wined3d_mutex_unlock();
|
---|
108 |
|
---|
109 | ASSERT_D3D(hr == S_OK);
|
---|
110 |
|
---|
111 | return hr;
|
---|
112 | }
|
---|
113 |
|
---|
114 | static UINT WINAPI IDirect3D9Impl_GetAdapterCount(LPDIRECT3D9EX iface) {
|
---|
115 | IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
---|
116 | HRESULT hr;
|
---|
117 |
|
---|
118 | TRACE("iface %p.\n", iface);
|
---|
119 |
|
---|
120 | wined3d_mutex_lock();
|
---|
121 | hr = IWineD3D_GetAdapterCount(This->WineD3D);
|
---|
122 | wined3d_mutex_unlock();
|
---|
123 |
|
---|
124 | ASSERT_D3D(hr == S_OK);
|
---|
125 |
|
---|
126 | return hr;
|
---|
127 | }
|
---|
128 |
|
---|
129 | static HRESULT WINAPI IDirect3D9Impl_GetAdapterIdentifier(LPDIRECT3D9EX iface, UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER9* pIdentifier) {
|
---|
130 | IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
---|
131 | WINED3DADAPTER_IDENTIFIER adapter_id;
|
---|
132 | HRESULT hr;
|
---|
133 |
|
---|
134 | TRACE("iface %p, adapter %u, flags %#x, identifier %p.\n",
|
---|
135 | iface, Adapter, Flags, pIdentifier);
|
---|
136 |
|
---|
137 | adapter_id.driver = pIdentifier->Driver;
|
---|
138 | adapter_id.driver_size = sizeof(pIdentifier->Driver);
|
---|
139 | adapter_id.description = pIdentifier->Description;
|
---|
140 | adapter_id.description_size = sizeof(pIdentifier->Description);
|
---|
141 | adapter_id.device_name = pIdentifier->DeviceName;
|
---|
142 | adapter_id.device_name_size = sizeof(pIdentifier->DeviceName);
|
---|
143 |
|
---|
144 | wined3d_mutex_lock();
|
---|
145 | hr = IWineD3D_GetAdapterIdentifier(This->WineD3D, Adapter, Flags, &adapter_id);
|
---|
146 | wined3d_mutex_unlock();
|
---|
147 |
|
---|
148 | pIdentifier->DriverVersion = adapter_id.driver_version;
|
---|
149 | pIdentifier->VendorId = adapter_id.vendor_id;
|
---|
150 | pIdentifier->DeviceId = adapter_id.device_id;
|
---|
151 | pIdentifier->SubSysId = adapter_id.subsystem_id;
|
---|
152 | pIdentifier->Revision = adapter_id.revision;
|
---|
153 | memcpy(&pIdentifier->DeviceIdentifier, &adapter_id.device_identifier, sizeof(pIdentifier->DeviceIdentifier));
|
---|
154 | pIdentifier->WHQLLevel = adapter_id.whql_level;
|
---|
155 |
|
---|
156 | ASSERT_D3D(hr == S_OK);
|
---|
157 |
|
---|
158 | return hr;
|
---|
159 | }
|
---|
160 |
|
---|
161 | static UINT WINAPI IDirect3D9Impl_GetAdapterModeCount(LPDIRECT3D9EX iface, UINT Adapter, D3DFORMAT Format) {
|
---|
162 | IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
---|
163 | HRESULT hr;
|
---|
164 |
|
---|
165 | TRACE("iface %p, adapter %u, format %#x.\n", iface, Adapter, Format);
|
---|
166 |
|
---|
167 | /* Others than that not supported by d3d9, but reported by wined3d for ddraw. Filter them out */
|
---|
168 | if(Format != D3DFMT_X8R8G8B8 && Format != D3DFMT_R5G6B5) {
|
---|
169 | ERR_D3D();
|
---|
170 | return 0;
|
---|
171 | }
|
---|
172 |
|
---|
173 | wined3d_mutex_lock();
|
---|
174 | hr = IWineD3D_GetAdapterModeCount(This->WineD3D, Adapter, wined3dformat_from_d3dformat(Format));
|
---|
175 | wined3d_mutex_unlock();
|
---|
176 |
|
---|
177 | ASSERT_D3D(hr == S_OK);
|
---|
178 | return hr;
|
---|
179 | }
|
---|
180 |
|
---|
181 | static HRESULT WINAPI IDirect3D9Impl_EnumAdapterModes(LPDIRECT3D9EX iface, UINT Adapter, D3DFORMAT Format, UINT Mode, D3DDISPLAYMODE* pMode) {
|
---|
182 | IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
---|
183 | HRESULT hr;
|
---|
184 |
|
---|
185 | TRACE("iface %p, adapter %u, format %#x, mode_idx %u, mode %p.\n",
|
---|
186 | iface, Adapter, Format, Mode, pMode);
|
---|
187 |
|
---|
188 | /* We can't pass this to WineD3D, otherwise it'll think it came from D3D8 or DDraw.
|
---|
189 | It's supposed to fail anyway, so no harm returning failure. */
|
---|
190 | if(Format != D3DFMT_X8R8G8B8 && Format != D3DFMT_R5G6B5)
|
---|
191 | {
|
---|
192 | ERR_D3D();
|
---|
193 | return D3DERR_INVALIDCALL;
|
---|
194 | }
|
---|
195 |
|
---|
196 | wined3d_mutex_lock();
|
---|
197 | hr = IWineD3D_EnumAdapterModes(This->WineD3D, Adapter, wined3dformat_from_d3dformat(Format),
|
---|
198 | Mode, (WINED3DDISPLAYMODE *) pMode);
|
---|
199 | wined3d_mutex_unlock();
|
---|
200 |
|
---|
201 | if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
|
---|
202 |
|
---|
203 | ASSERT_D3D(hr == S_OK);
|
---|
204 | return hr;
|
---|
205 | }
|
---|
206 |
|
---|
207 | static HRESULT WINAPI IDirect3D9Impl_GetAdapterDisplayMode(LPDIRECT3D9EX iface, UINT Adapter, D3DDISPLAYMODE* pMode) {
|
---|
208 | IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
---|
209 | HRESULT hr;
|
---|
210 |
|
---|
211 | TRACE("iface %p, adapter %u, mode %p.\n", iface, Adapter, pMode);
|
---|
212 |
|
---|
213 | wined3d_mutex_lock();
|
---|
214 | hr = IWineD3D_GetAdapterDisplayMode(This->WineD3D, Adapter, (WINED3DDISPLAYMODE *) pMode);
|
---|
215 | wined3d_mutex_unlock();
|
---|
216 |
|
---|
217 | if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
|
---|
218 |
|
---|
219 | ASSERT_D3D(hr == S_OK);
|
---|
220 | return hr;
|
---|
221 | }
|
---|
222 |
|
---|
223 | static HRESULT WINAPI IDirect3D9Impl_CheckDeviceType(IDirect3D9Ex *iface, UINT Adapter,
|
---|
224 | D3DDEVTYPE CheckType, D3DFORMAT DisplayFormat, D3DFORMAT BackBufferFormat, BOOL Windowed)
|
---|
225 | {
|
---|
226 | IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
---|
227 | HRESULT hr;
|
---|
228 |
|
---|
229 | TRACE("iface %p, adapter %u, device_type %#x, display_format %#x, backbuffer_format %#x, windowed %#x.\n",
|
---|
230 | iface, Adapter, CheckType, DisplayFormat, BackBufferFormat, Windowed);
|
---|
231 |
|
---|
232 | wined3d_mutex_lock();
|
---|
233 | hr = IWineD3D_CheckDeviceType(This->WineD3D, Adapter, CheckType, wined3dformat_from_d3dformat(DisplayFormat),
|
---|
234 | wined3dformat_from_d3dformat(BackBufferFormat), Windowed);
|
---|
235 | wined3d_mutex_unlock();
|
---|
236 |
|
---|
237 | ASSERT_D3D(hr == S_OK);
|
---|
238 | return hr;
|
---|
239 | }
|
---|
240 |
|
---|
241 | static HRESULT WINAPI IDirect3D9Impl_CheckDeviceFormat(IDirect3D9Ex *iface, UINT Adapter, D3DDEVTYPE DeviceType,
|
---|
242 | D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat)
|
---|
243 | {
|
---|
244 | IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
---|
245 | HRESULT hr;
|
---|
246 | WINED3DRESOURCETYPE WineD3DRType;
|
---|
247 |
|
---|
248 | TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, usage %#x, resource_type %#x, format %#x.\n",
|
---|
249 | iface, Adapter, DeviceType, AdapterFormat, Usage, RType, CheckFormat);
|
---|
250 |
|
---|
251 | /* This format is nothing special and it is supported perfectly.
|
---|
252 | * However, ati and nvidia driver on windows do not mark this format as
|
---|
253 | * supported (tested with the dxCapsViewer) and pretending to
|
---|
254 | * support this format uncovers a bug in Battlefield 1942 (fonts are missing)
|
---|
255 | * So do the same as Windows drivers and pretend not to support it on dx8 and 9
|
---|
256 | */
|
---|
257 | if(CheckFormat == D3DFMT_R8G8B8)
|
---|
258 | {
|
---|
259 | WARN("D3DFMT_R8G8B8 is not available on windows, returning D3DERR_NOTAVAILABLE\n");
|
---|
260 | ERR_D3D();
|
---|
261 | return D3DERR_NOTAVAILABLE;
|
---|
262 | }
|
---|
263 |
|
---|
264 | switch(RType) {
|
---|
265 | case D3DRTYPE_VERTEXBUFFER:
|
---|
266 | case D3DRTYPE_INDEXBUFFER:
|
---|
267 | WineD3DRType = WINED3DRTYPE_BUFFER;
|
---|
268 | break;
|
---|
269 |
|
---|
270 | default:
|
---|
271 | WineD3DRType = RType;
|
---|
272 | break;
|
---|
273 | }
|
---|
274 |
|
---|
275 | wined3d_mutex_lock();
|
---|
276 | hr = IWineD3D_CheckDeviceFormat(This->WineD3D, Adapter, DeviceType, wined3dformat_from_d3dformat(AdapterFormat),
|
---|
277 | Usage, WineD3DRType, wined3dformat_from_d3dformat(CheckFormat), SURFACE_OPENGL);
|
---|
278 | wined3d_mutex_unlock();
|
---|
279 |
|
---|
280 | ASSERT_D3D(hr == S_OK);
|
---|
281 | return hr;
|
---|
282 | }
|
---|
283 |
|
---|
284 | static HRESULT WINAPI IDirect3D9Impl_CheckDeviceMultiSampleType(IDirect3D9Ex *iface, UINT Adapter,
|
---|
285 | D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType,
|
---|
286 | DWORD *pQualityLevels)
|
---|
287 | {
|
---|
288 | IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
---|
289 | HRESULT hr;
|
---|
290 |
|
---|
291 | TRACE("iface %p, adapter %u, device_type %#x, format %#x, windowed %#x, multisample_type %#x, levels %p.\n",
|
---|
292 | iface, Adapter, DeviceType, SurfaceFormat, Windowed, MultiSampleType, pQualityLevels);
|
---|
293 |
|
---|
294 | wined3d_mutex_lock();
|
---|
295 | hr = IWineD3D_CheckDeviceMultiSampleType(This->WineD3D, Adapter, DeviceType,
|
---|
296 | wined3dformat_from_d3dformat(SurfaceFormat), Windowed, MultiSampleType, pQualityLevels);
|
---|
297 | wined3d_mutex_unlock();
|
---|
298 |
|
---|
299 | ASSERT_D3D(hr == S_OK);
|
---|
300 | return hr;
|
---|
301 | }
|
---|
302 |
|
---|
303 | static HRESULT WINAPI IDirect3D9Impl_CheckDepthStencilMatch(IDirect3D9Ex *iface, UINT Adapter,
|
---|
304 | D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat)
|
---|
305 | {
|
---|
306 | IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
---|
307 | HRESULT hr;
|
---|
308 |
|
---|
309 | TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, rt_format %#x, ds_format %#x.\n",
|
---|
310 | iface, Adapter, DeviceType, AdapterFormat, RenderTargetFormat, DepthStencilFormat);
|
---|
311 |
|
---|
312 | wined3d_mutex_lock();
|
---|
313 | hr = IWineD3D_CheckDepthStencilMatch(This->WineD3D, Adapter, DeviceType,
|
---|
314 | wined3dformat_from_d3dformat(AdapterFormat), wined3dformat_from_d3dformat(RenderTargetFormat),
|
---|
315 | wined3dformat_from_d3dformat(DepthStencilFormat));
|
---|
316 | wined3d_mutex_unlock();
|
---|
317 |
|
---|
318 | ASSERT_D3D(hr == S_OK);
|
---|
319 | return hr;
|
---|
320 | }
|
---|
321 |
|
---|
322 | static HRESULT WINAPI IDirect3D9Impl_CheckDeviceFormatConversion(LPDIRECT3D9EX iface, UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SourceFormat, D3DFORMAT TargetFormat) {
|
---|
323 | IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
---|
324 | HRESULT hr;
|
---|
325 |
|
---|
326 | TRACE("iface %p, adapter %u, device_type %#x, src_format %#x, dst_format %#x.\n",
|
---|
327 | iface, Adapter, DeviceType, SourceFormat, TargetFormat);
|
---|
328 |
|
---|
329 | wined3d_mutex_lock();
|
---|
330 | hr = IWineD3D_CheckDeviceFormatConversion(This->WineD3D, Adapter, DeviceType,
|
---|
331 | wined3dformat_from_d3dformat(SourceFormat), wined3dformat_from_d3dformat(TargetFormat));
|
---|
332 | wined3d_mutex_unlock();
|
---|
333 |
|
---|
334 | ASSERT_D3D(hr == S_OK);
|
---|
335 | return hr;
|
---|
336 | }
|
---|
337 |
|
---|
338 | void filter_caps(D3DCAPS9* pCaps)
|
---|
339 | {
|
---|
340 |
|
---|
341 | DWORD textureFilterCaps =
|
---|
342 | D3DPTFILTERCAPS_MINFPOINT | D3DPTFILTERCAPS_MINFLINEAR | D3DPTFILTERCAPS_MINFANISOTROPIC |
|
---|
343 | D3DPTFILTERCAPS_MINFPYRAMIDALQUAD | D3DPTFILTERCAPS_MINFGAUSSIANQUAD|
|
---|
344 | D3DPTFILTERCAPS_MIPFPOINT | D3DPTFILTERCAPS_MIPFLINEAR | D3DPTFILTERCAPS_MAGFPOINT |
|
---|
345 | D3DPTFILTERCAPS_MAGFLINEAR |D3DPTFILTERCAPS_MAGFANISOTROPIC|D3DPTFILTERCAPS_MAGFPYRAMIDALQUAD|
|
---|
346 | D3DPTFILTERCAPS_MAGFGAUSSIANQUAD;
|
---|
347 | pCaps->TextureFilterCaps &= textureFilterCaps;
|
---|
348 | pCaps->CubeTextureFilterCaps &= textureFilterCaps;
|
---|
349 | pCaps->VolumeTextureFilterCaps &= textureFilterCaps;
|
---|
350 |
|
---|
351 | pCaps->DevCaps &=
|
---|
352 | D3DDEVCAPS_EXECUTESYSTEMMEMORY | D3DDEVCAPS_EXECUTEVIDEOMEMORY | D3DDEVCAPS_TLVERTEXSYSTEMMEMORY |
|
---|
353 | D3DDEVCAPS_TLVERTEXVIDEOMEMORY | D3DDEVCAPS_TEXTURESYSTEMMEMORY| D3DDEVCAPS_TEXTUREVIDEOMEMORY |
|
---|
354 | D3DDEVCAPS_DRAWPRIMTLVERTEX | D3DDEVCAPS_CANRENDERAFTERFLIP | D3DDEVCAPS_TEXTURENONLOCALVIDMEM|
|
---|
355 | D3DDEVCAPS_DRAWPRIMITIVES2 | D3DDEVCAPS_SEPARATETEXTUREMEMORIES |
|
---|
356 | D3DDEVCAPS_DRAWPRIMITIVES2EX | D3DDEVCAPS_HWTRANSFORMANDLIGHT| D3DDEVCAPS_CANBLTSYSTONONLOCAL |
|
---|
357 | D3DDEVCAPS_HWRASTERIZATION | D3DDEVCAPS_PUREDEVICE | D3DDEVCAPS_QUINTICRTPATCHES |
|
---|
358 | D3DDEVCAPS_RTPATCHES | D3DDEVCAPS_RTPATCHHANDLEZERO | D3DDEVCAPS_NPATCHES;
|
---|
359 |
|
---|
360 | pCaps->ShadeCaps &=
|
---|
361 | D3DPSHADECAPS_COLORGOURAUDRGB | D3DPSHADECAPS_SPECULARGOURAUDRGB |
|
---|
362 | D3DPSHADECAPS_ALPHAGOURAUDBLEND | D3DPSHADECAPS_FOGGOURAUD;
|
---|
363 |
|
---|
364 | pCaps->RasterCaps &=
|
---|
365 | D3DPRASTERCAPS_DITHER | D3DPRASTERCAPS_ZTEST | D3DPRASTERCAPS_FOGVERTEX |
|
---|
366 | D3DPRASTERCAPS_FOGTABLE | D3DPRASTERCAPS_MIPMAPLODBIAS | D3DPRASTERCAPS_ZBUFFERLESSHSR |
|
---|
367 | D3DPRASTERCAPS_FOGRANGE | D3DPRASTERCAPS_ANISOTROPY | D3DPRASTERCAPS_WBUFFER |
|
---|
368 | D3DPRASTERCAPS_WFOG | D3DPRASTERCAPS_ZFOG | D3DPRASTERCAPS_COLORPERSPECTIVE |
|
---|
369 | D3DPRASTERCAPS_SCISSORTEST | D3DPRASTERCAPS_SLOPESCALEDEPTHBIAS |
|
---|
370 | D3DPRASTERCAPS_DEPTHBIAS | D3DPRASTERCAPS_MULTISAMPLE_TOGGLE;
|
---|
371 |
|
---|
372 | pCaps->DevCaps2 &=
|
---|
373 | D3DDEVCAPS2_STREAMOFFSET | D3DDEVCAPS2_DMAPNPATCH | D3DDEVCAPS2_ADAPTIVETESSRTPATCH |
|
---|
374 | D3DDEVCAPS2_ADAPTIVETESSNPATCH | D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES |
|
---|
375 | D3DDEVCAPS2_PRESAMPLEDDMAPNPATCH| D3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET;
|
---|
376 |
|
---|
377 | pCaps->Caps2 &=
|
---|
378 | D3DCAPS2_FULLSCREENGAMMA | D3DCAPS2_CANCALIBRATEGAMMA | D3DCAPS2_RESERVED |
|
---|
379 | D3DCAPS2_CANMANAGERESOURCE | D3DCAPS2_DYNAMICTEXTURES | D3DCAPS2_CANAUTOGENMIPMAP;
|
---|
380 |
|
---|
381 | pCaps->VertexProcessingCaps &=
|
---|
382 | D3DVTXPCAPS_TEXGEN | D3DVTXPCAPS_MATERIALSOURCE7 | D3DVTXPCAPS_DIRECTIONALLIGHTS |
|
---|
383 | D3DVTXPCAPS_POSITIONALLIGHTS | D3DVTXPCAPS_LOCALVIEWER | D3DVTXPCAPS_TWEENING |
|
---|
384 | D3DVTXPCAPS_TEXGEN_SPHEREMAP | D3DVTXPCAPS_NO_TEXGEN_NONLOCALVIEWER;
|
---|
385 |
|
---|
386 | pCaps->TextureCaps &=
|
---|
387 | D3DPTEXTURECAPS_PERSPECTIVE | D3DPTEXTURECAPS_POW2 | D3DPTEXTURECAPS_ALPHA |
|
---|
388 | D3DPTEXTURECAPS_SQUAREONLY | D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE |
|
---|
389 | D3DPTEXTURECAPS_ALPHAPALETTE | D3DPTEXTURECAPS_NONPOW2CONDITIONAL |
|
---|
390 | D3DPTEXTURECAPS_PROJECTED | D3DPTEXTURECAPS_CUBEMAP | D3DPTEXTURECAPS_VOLUMEMAP |
|
---|
391 | D3DPTEXTURECAPS_MIPMAP | D3DPTEXTURECAPS_MIPVOLUMEMAP | D3DPTEXTURECAPS_MIPCUBEMAP |
|
---|
392 | D3DPTEXTURECAPS_CUBEMAP_POW2 | D3DPTEXTURECAPS_VOLUMEMAP_POW2| D3DPTEXTURECAPS_NOPROJECTEDBUMPENV;
|
---|
393 |
|
---|
394 | pCaps->MaxVertexShaderConst = min(D3D9_MAX_VERTEX_SHADER_CONSTANTF, pCaps->MaxVertexShaderConst);
|
---|
395 | pCaps->NumSimultaneousRTs = min(D3D9_MAX_SIMULTANEOUS_RENDERTARGETS, pCaps->NumSimultaneousRTs);
|
---|
396 | }
|
---|
397 |
|
---|
398 | #ifndef VBOX_WINE_WITHOUT_LIBWINE
|
---|
399 | #define D3DDEVCAPS_FLOATTLVERTEX 0x00000001
|
---|
400 | #define D3DPMISCCAPS_FOGINFVF 0x00002000
|
---|
401 | #define D3DPRASTERCAPS_SUBPIXEL 0x00000020
|
---|
402 | #define D3DPRASTERCAPS_STIPPLE 0x00000200
|
---|
403 | #define D3DPTEXTURECAPS_TRANSPARENCY 0x00000008
|
---|
404 | #endif
|
---|
405 |
|
---|
406 | static HRESULT WINAPI IDirect3D9Impl_GetDeviceCaps(LPDIRECT3D9EX iface, UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS9* pCaps) {
|
---|
407 | IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
---|
408 | HRESULT hrc = D3D_OK;
|
---|
409 | WINED3DCAPS *pWineCaps;
|
---|
410 |
|
---|
411 | TRACE("iface %p, adapter %u, device_type %#x, caps %p.\n", iface, Adapter, DeviceType, pCaps);
|
---|
412 |
|
---|
413 | if(NULL == pCaps){
|
---|
414 | return D3DERR_INVALIDCALL;
|
---|
415 | }
|
---|
416 | pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
|
---|
417 | if(pWineCaps == NULL){
|
---|
418 | return D3DERR_INVALIDCALL; /*well this is what MSDN says to return*/
|
---|
419 | }
|
---|
420 | memset(pCaps, 0, sizeof(*pCaps));
|
---|
421 |
|
---|
422 | wined3d_mutex_lock();
|
---|
423 | hrc = IWineD3D_GetDeviceCaps(This->WineD3D, Adapter, DeviceType, pWineCaps);
|
---|
424 | wined3d_mutex_unlock();
|
---|
425 |
|
---|
426 | WINECAPSTOD3D9CAPS(pCaps, pWineCaps)
|
---|
427 | HeapFree(GetProcessHeap(), 0, pWineCaps);
|
---|
428 |
|
---|
429 | /* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps */
|
---|
430 | pCaps->DevCaps2 |= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES;
|
---|
431 |
|
---|
432 | filter_caps(pCaps);
|
---|
433 |
|
---|
434 | /* fixup caps */
|
---|
435 | #ifdef VBOX_WITH_WDDM
|
---|
436 | /* needed for Windows Media Player to work properly */
|
---|
437 | pCaps->Caps |= D3DCAPS_READ_SCANLINE;
|
---|
438 | pCaps->Caps2 |= 0x00080000 /*D3DCAPS2_CANRENDERWINDOWED*/;
|
---|
439 | pCaps->Caps2 |= D3DCAPS2_CANSHARERESOURCE;
|
---|
440 | pCaps->DevCaps |= D3DDEVCAPS_FLOATTLVERTEX /* <- must be set according to the docs */
|
---|
441 | /*| D3DDEVCAPS_HWVERTEXBUFFER | D3DDEVCAPS_HWINDEXBUFFER | D3DDEVCAPS_SUBVOLUMELOCK */;
|
---|
442 | pCaps->PrimitiveMiscCaps |= D3DPMISCCAPS_INDEPENDENTWRITEMASKS
|
---|
443 | | D3DPMISCCAPS_FOGINFVF
|
---|
444 | | D3DPMISCCAPS_SEPARATEALPHABLEND | D3DPMISCCAPS_MRTINDEPENDENTBITDEPTHS;
|
---|
445 | pCaps->RasterCaps |= D3DPRASTERCAPS_SUBPIXEL | D3DPRASTERCAPS_STIPPLE | D3DPRASTERCAPS_ZBIAS | D3DPRASTERCAPS_COLORPERSPECTIVE /* keep */;
|
---|
446 | pCaps->TextureCaps |= D3DPTEXTURECAPS_TRANSPARENCY | D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE;
|
---|
447 | pCaps->TextureAddressCaps |= D3DPTADDRESSCAPS_MIRRORONCE;
|
---|
448 | pCaps->VolumeTextureAddressCaps |= D3DPTADDRESSCAPS_MIRRORONCE;
|
---|
449 | pCaps->StencilCaps |= D3DSTENCILCAPS_TWOSIDED;
|
---|
450 | pCaps->DeclTypes |= D3DDTCAPS_FLOAT16_2 | D3DDTCAPS_FLOAT16_4;
|
---|
451 | pCaps->VertexTextureFilterCaps |= D3DPTFILTERCAPS_MINFPOINT | D3DPTFILTERCAPS_MAGFPOINT;
|
---|
452 | pCaps->GuardBandLeft = -8192.;
|
---|
453 | pCaps->GuardBandTop = -8192.;
|
---|
454 | pCaps->GuardBandRight = 8192.;
|
---|
455 | pCaps->GuardBandBottom = 8192.;
|
---|
456 | pCaps->VS20Caps.DynamicFlowControlDepth = 24;
|
---|
457 | pCaps->VS20Caps.NumTemps = D3DVS20_MAX_NUMTEMPS;
|
---|
458 | pCaps->PS20Caps.DynamicFlowControlDepth = 24;
|
---|
459 | pCaps->PS20Caps.NumTemps = D3DVS20_MAX_NUMTEMPS;
|
---|
460 | #endif
|
---|
461 | /* workaround for wine not returning InstructionSlots correctly for shaders v3.0 */
|
---|
462 | if ((pCaps->VertexShaderVersion & 0xff00) == 0x0300)
|
---|
463 | {
|
---|
464 | pCaps->MaxVertexShader30InstructionSlots = RT_MIN(32768, pCaps->MaxVertexShader30InstructionSlots);
|
---|
465 | pCaps->MaxPixelShader30InstructionSlots = RT_MIN(32768, pCaps->MaxPixelShader30InstructionSlots);
|
---|
466 | }
|
---|
467 | #if defined(DEBUG)
|
---|
468 | if ((pCaps->VertexShaderVersion & 0xff00) == 0x0300)
|
---|
469 | {
|
---|
470 | ASSERT_D3D(pCaps->MaxVertexShader30InstructionSlots >= 512);
|
---|
471 | ASSERT_D3D(pCaps->MaxVertexShader30InstructionSlots <= 32768);
|
---|
472 | ASSERT_D3D(pCaps->MaxPixelShader30InstructionSlots >= 512);
|
---|
473 | ASSERT_D3D(pCaps->MaxPixelShader30InstructionSlots <= 32768);
|
---|
474 | }
|
---|
475 | else if ((pCaps->VertexShaderVersion & 0xff00) == 0x0200)
|
---|
476 | {
|
---|
477 | ASSERT_D3D(pCaps->MaxVertexShader30InstructionSlots == 0);
|
---|
478 | ASSERT_D3D(pCaps->MaxPixelShader30InstructionSlots == 0);
|
---|
479 | }
|
---|
480 | else
|
---|
481 | {
|
---|
482 | ERR_D3D();
|
---|
483 | }
|
---|
484 | #endif
|
---|
485 |
|
---|
486 | TRACE("(%p) returning %p\n", This, pCaps);
|
---|
487 |
|
---|
488 | ASSERT_D3D(hrc == S_OK);
|
---|
489 | return hrc;
|
---|
490 | }
|
---|
491 |
|
---|
492 | static HMONITOR WINAPI IDirect3D9Impl_GetAdapterMonitor(LPDIRECT3D9EX iface, UINT Adapter) {
|
---|
493 | IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
---|
494 | HMONITOR ret;
|
---|
495 |
|
---|
496 | TRACE("iface %p, adapter %u.\n", iface, Adapter);
|
---|
497 |
|
---|
498 | wined3d_mutex_lock();
|
---|
499 | ret = IWineD3D_GetAdapterMonitor(This->WineD3D, Adapter);
|
---|
500 | wined3d_mutex_unlock();
|
---|
501 |
|
---|
502 | ASSERT_D3D(ret);
|
---|
503 | return ret;
|
---|
504 | }
|
---|
505 |
|
---|
506 | static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3D9Impl_CreateDevice(IDirect3D9Ex *iface, UINT adapter,
|
---|
507 | D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters,
|
---|
508 | IDirect3DDevice9 **device)
|
---|
509 | {
|
---|
510 | IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
---|
511 | IDirect3DDevice9Impl *object;
|
---|
512 | HRESULT hr;
|
---|
513 |
|
---|
514 | TRACE("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#x, parameters %p, device %p.\n",
|
---|
515 | iface, adapter, device_type, focus_window, flags, parameters, device);
|
---|
516 |
|
---|
517 | object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
---|
518 | if (!object)
|
---|
519 | {
|
---|
520 | ERR("Failed to allocate device memory.\n");
|
---|
521 | ERR_D3D();
|
---|
522 | return E_OUTOFMEMORY;
|
---|
523 | }
|
---|
524 |
|
---|
525 | hr = device_init(object, This->WineD3D, adapter, device_type, focus_window, flags, parameters);
|
---|
526 | if (FAILED(hr))
|
---|
527 | {
|
---|
528 | ERR_D3D();
|
---|
529 | WARN("Failed to initialize device, hr %#x.\n", hr);
|
---|
530 | HeapFree(GetProcessHeap(), 0, object);
|
---|
531 | return hr;
|
---|
532 | }
|
---|
533 |
|
---|
534 | TRACE("Created device %p.\n", object);
|
---|
535 | *device = (IDirect3DDevice9 *)object;
|
---|
536 |
|
---|
537 | return D3D_OK;
|
---|
538 | }
|
---|
539 |
|
---|
540 | static UINT WINAPI IDirect3D9ExImpl_GetAdapterModeCountEx(IDirect3D9Ex *iface,
|
---|
541 | UINT adapter, const D3DDISPLAYMODEFILTER *filter)
|
---|
542 | {
|
---|
543 | FIXME("iface %p, adapter %u, filter %p stub!\n", iface, adapter, filter);
|
---|
544 |
|
---|
545 | ERR_D3D();
|
---|
546 | return D3DERR_DRIVERINTERNALERROR;
|
---|
547 | }
|
---|
548 |
|
---|
549 | static HRESULT WINAPI IDirect3D9ExImpl_EnumAdapterModesEx(IDirect3D9Ex *iface,
|
---|
550 | UINT adapter, const D3DDISPLAYMODEFILTER *filter, UINT mode_idx, D3DDISPLAYMODEEX *mode)
|
---|
551 | {
|
---|
552 | FIXME("iface %p, adapter %u, filter %p, mode_idx %u, mode %p stub!\n",
|
---|
553 | iface, adapter, filter, mode_idx, mode);
|
---|
554 |
|
---|
555 | ERR_D3D();
|
---|
556 | return D3DERR_DRIVERINTERNALERROR;
|
---|
557 | }
|
---|
558 |
|
---|
559 | static HRESULT WINAPI IDirect3D9ExImpl_GetAdapterDisplayModeEx(IDirect3D9Ex *iface,
|
---|
560 | UINT Adapter, D3DDISPLAYMODEEX *pMode, D3DDISPLAYROTATION *pRotation)
|
---|
561 | {
|
---|
562 | IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
---|
563 | HRESULT hr;
|
---|
564 |
|
---|
565 | TRACE("iface %p, adapter %u, mode %p, rotation %p", iface, Adapter, pMode, pRotation);
|
---|
566 |
|
---|
567 | wined3d_mutex_lock();
|
---|
568 | hr = IWineD3D_GetAdapterDisplayModeEx(This->WineD3D, Adapter, (WINED3DDISPLAYMODEEX *) pMode, (WINED3DDISPLAYROTATION *) pRotation);
|
---|
569 | wined3d_mutex_unlock();
|
---|
570 |
|
---|
571 | if (SUCCEEDED(hr))
|
---|
572 | {
|
---|
573 | pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
|
---|
574 | }
|
---|
575 |
|
---|
576 | /*
|
---|
577 | if (mode)
|
---|
578 | {
|
---|
579 | D3DDISPLAYMODE* d3dmode;
|
---|
580 |
|
---|
581 | if (mode->Size != sizeof(D3DDISPLAYMODEEX))
|
---|
582 | {
|
---|
583 | WARN("Invalid mode->Size %u expected %u", mode->Size, sizeof(D3DDISPLAYMODEEX));
|
---|
584 | return D3DERR_INVALIDCALL;
|
---|
585 | }
|
---|
586 |
|
---|
587 | wined3d_mutex_lock();
|
---|
588 | hr = IWineD3D_GetAdapterDisplayMode(This->WineD3D, Adapter, (WINED3DDISPLAYMODE *) &d3dmode);
|
---|
589 | wined3d_mutex_unlock();
|
---|
590 |
|
---|
591 | if (SUCCEEDED(hr))
|
---|
592 | {
|
---|
593 | mode->Width = d3dmode.Width;
|
---|
594 | mode->Height = d3dmode.Height;
|
---|
595 | mode->RefreshRate = d3dmode.RefreshRate;
|
---|
596 | mode->Format = d3dformat_from_wined3dformat(d3dmode.Format);
|
---|
597 | mode->ScanLineOrdering = D3DSCANLINEORDERING_PROGRESSIVE; //D3DSCANLINEORDERING_INTERLACED
|
---|
598 | }
|
---|
599 | }
|
---|
600 | else
|
---|
601 | {
|
---|
602 | hr = WINED3D_OK;
|
---|
603 | }
|
---|
604 |
|
---|
605 | if (rotation)
|
---|
606 | {
|
---|
607 | *rotation = D3DDISPLAYROTATION_IDENTITY;
|
---|
608 | }
|
---|
609 | */
|
---|
610 | ASSERT_D3D(hr == S_OK);
|
---|
611 | return hr;
|
---|
612 | }
|
---|
613 |
|
---|
614 | static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3D9ExImpl_CreateDeviceEx(IDirect3D9Ex *iface,
|
---|
615 | UINT adapter, D3DDEVTYPE device_type, HWND focus_window, DWORD flags,
|
---|
616 | D3DPRESENT_PARAMETERS *parameters, D3DDISPLAYMODEEX *mode, IDirect3DDevice9Ex **device)
|
---|
617 | {
|
---|
618 | FIXME("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#x,\n"
|
---|
619 | "parameters %p, mode %p, device %p stub!\n",
|
---|
620 | iface, adapter, device_type, focus_window, flags,
|
---|
621 | parameters, mode, device);
|
---|
622 |
|
---|
623 | *device = NULL;
|
---|
624 |
|
---|
625 | ERR_D3D();
|
---|
626 | return D3DERR_DRIVERINTERNALERROR;
|
---|
627 | }
|
---|
628 |
|
---|
629 | static HRESULT WINAPI IDirect3D9ExImpl_GetAdapterLUID(IDirect3D9Ex *iface, UINT adapter, LUID *luid)
|
---|
630 | {
|
---|
631 | IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
---|
632 | WINED3DADAPTER_IDENTIFIER adapter_id;
|
---|
633 | HRESULT hr;
|
---|
634 |
|
---|
635 | TRACE("iface %p, adapter %u, luid %p.\n", iface, adapter, luid);
|
---|
636 |
|
---|
637 | adapter_id.driver_size = 0;
|
---|
638 | adapter_id.description_size = 0;
|
---|
639 | adapter_id.device_name_size = 0;
|
---|
640 |
|
---|
641 | wined3d_mutex_lock();
|
---|
642 | hr = IWineD3D_GetAdapterIdentifier(This->WineD3D, adapter, 0, &adapter_id);
|
---|
643 | wined3d_mutex_unlock();
|
---|
644 |
|
---|
645 | memcpy(luid, &adapter_id.adapter_luid, sizeof(*luid));
|
---|
646 |
|
---|
647 | ASSERT_D3D(hr == S_OK);
|
---|
648 | return hr;
|
---|
649 | }
|
---|
650 |
|
---|
651 |
|
---|
652 | const IDirect3D9ExVtbl Direct3D9_Vtbl =
|
---|
653 | {
|
---|
654 | /* IUnknown */
|
---|
655 | IDirect3D9Impl_QueryInterface,
|
---|
656 | IDirect3D9Impl_AddRef,
|
---|
657 | IDirect3D9Impl_Release,
|
---|
658 | /* IDirect3D9 */
|
---|
659 | IDirect3D9Impl_RegisterSoftwareDevice,
|
---|
660 | IDirect3D9Impl_GetAdapterCount,
|
---|
661 | IDirect3D9Impl_GetAdapterIdentifier,
|
---|
662 | IDirect3D9Impl_GetAdapterModeCount,
|
---|
663 | IDirect3D9Impl_EnumAdapterModes,
|
---|
664 | IDirect3D9Impl_GetAdapterDisplayMode,
|
---|
665 | IDirect3D9Impl_CheckDeviceType,
|
---|
666 | IDirect3D9Impl_CheckDeviceFormat,
|
---|
667 | IDirect3D9Impl_CheckDeviceMultiSampleType,
|
---|
668 | IDirect3D9Impl_CheckDepthStencilMatch,
|
---|
669 | IDirect3D9Impl_CheckDeviceFormatConversion,
|
---|
670 | IDirect3D9Impl_GetDeviceCaps,
|
---|
671 | IDirect3D9Impl_GetAdapterMonitor,
|
---|
672 | IDirect3D9Impl_CreateDevice,
|
---|
673 | /* IDirect3D9Ex */
|
---|
674 | IDirect3D9ExImpl_GetAdapterModeCountEx,
|
---|
675 | IDirect3D9ExImpl_EnumAdapterModesEx,
|
---|
676 | IDirect3D9ExImpl_GetAdapterDisplayModeEx,
|
---|
677 | IDirect3D9ExImpl_CreateDeviceEx,
|
---|
678 | IDirect3D9ExImpl_GetAdapterLUID
|
---|
679 |
|
---|
680 | };
|
---|