2 * IDirect3DDevice9 implementation
4 * Copyright 2002-2005 Jason Edmeades
5 * Copyright 2002-2005 Raphael Junqueira
6 * Copyright 2005 Oliver Stieber
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "d3d9_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d9
);
28 D3DFORMAT
d3dformat_from_wined3dformat(enum wined3d_format_id format
)
30 BYTE
*c
= (BYTE
*)&format
;
32 /* Don't translate FOURCC formats */
33 if (isprint(c
[0]) && isprint(c
[1]) && isprint(c
[2]) && isprint(c
[3])) return format
;
37 case WINED3DFMT_UNKNOWN
: return D3DFMT_UNKNOWN
;
38 case WINED3DFMT_B8G8R8_UNORM
: return D3DFMT_R8G8B8
;
39 case WINED3DFMT_B8G8R8A8_UNORM
: return D3DFMT_A8R8G8B8
;
40 case WINED3DFMT_B8G8R8X8_UNORM
: return D3DFMT_X8R8G8B8
;
41 case WINED3DFMT_B5G6R5_UNORM
: return D3DFMT_R5G6B5
;
42 case WINED3DFMT_B5G5R5X1_UNORM
: return D3DFMT_X1R5G5B5
;
43 case WINED3DFMT_B5G5R5A1_UNORM
: return D3DFMT_A1R5G5B5
;
44 case WINED3DFMT_B4G4R4A4_UNORM
: return D3DFMT_A4R4G4B4
;
45 case WINED3DFMT_B2G3R3_UNORM
: return D3DFMT_R3G3B2
;
46 case WINED3DFMT_A8_UNORM
: return D3DFMT_A8
;
47 case WINED3DFMT_B2G3R3A8_UNORM
: return D3DFMT_A8R3G3B2
;
48 case WINED3DFMT_B4G4R4X4_UNORM
: return D3DFMT_X4R4G4B4
;
49 case WINED3DFMT_R10G10B10A2_UNORM
: return D3DFMT_A2B10G10R10
;
50 case WINED3DFMT_R8G8B8A8_UNORM
: return D3DFMT_A8B8G8R8
;
51 case WINED3DFMT_R8G8B8X8_UNORM
: return D3DFMT_X8B8G8R8
;
52 case WINED3DFMT_R16G16_UNORM
: return D3DFMT_G16R16
;
53 case WINED3DFMT_B10G10R10A2_UNORM
: return D3DFMT_A2R10G10B10
;
54 case WINED3DFMT_R16G16B16A16_UNORM
: return D3DFMT_A16B16G16R16
;
55 case WINED3DFMT_P8_UINT_A8_UNORM
: return D3DFMT_A8P8
;
56 case WINED3DFMT_P8_UINT
: return D3DFMT_P8
;
57 case WINED3DFMT_L8_UNORM
: return D3DFMT_L8
;
58 case WINED3DFMT_L8A8_UNORM
: return D3DFMT_A8L8
;
59 case WINED3DFMT_L4A4_UNORM
: return D3DFMT_A4L4
;
60 case WINED3DFMT_R8G8_SNORM
: return D3DFMT_V8U8
;
61 case WINED3DFMT_R5G5_SNORM_L6_UNORM
: return D3DFMT_L6V5U5
;
62 case WINED3DFMT_R8G8_SNORM_L8X8_UNORM
: return D3DFMT_X8L8V8U8
;
63 case WINED3DFMT_R8G8B8A8_SNORM
: return D3DFMT_Q8W8V8U8
;
64 case WINED3DFMT_R16G16_SNORM
: return D3DFMT_V16U16
;
65 case WINED3DFMT_R10G10B10_SNORM_A2_UNORM
: return D3DFMT_A2W10V10U10
;
66 case WINED3DFMT_D16_LOCKABLE
: return D3DFMT_D16_LOCKABLE
;
67 case WINED3DFMT_D32_UNORM
: return D3DFMT_D32
;
68 case WINED3DFMT_S1_UINT_D15_UNORM
: return D3DFMT_D15S1
;
69 case WINED3DFMT_D24_UNORM_S8_UINT
: return D3DFMT_D24S8
;
70 case WINED3DFMT_X8D24_UNORM
: return D3DFMT_D24X8
;
71 case WINED3DFMT_S4X4_UINT_D24_UNORM
: return D3DFMT_D24X4S4
;
72 case WINED3DFMT_D16_UNORM
: return D3DFMT_D16
;
73 case WINED3DFMT_L16_UNORM
: return D3DFMT_L16
;
74 case WINED3DFMT_D32_FLOAT
: return D3DFMT_D32F_LOCKABLE
;
75 case WINED3DFMT_S8_UINT_D24_FLOAT
: return D3DFMT_D24FS8
;
76 case WINED3DFMT_VERTEXDATA
: return D3DFMT_VERTEXDATA
;
77 case WINED3DFMT_R16_UINT
: return D3DFMT_INDEX16
;
78 case WINED3DFMT_R32_UINT
: return D3DFMT_INDEX32
;
79 case WINED3DFMT_R16G16B16A16_SNORM
: return D3DFMT_Q16W16V16U16
;
80 case WINED3DFMT_R16_FLOAT
: return D3DFMT_R16F
;
81 case WINED3DFMT_R16G16_FLOAT
: return D3DFMT_G16R16F
;
82 case WINED3DFMT_R16G16B16A16_FLOAT
: return D3DFMT_A16B16G16R16F
;
83 case WINED3DFMT_R32_FLOAT
: return D3DFMT_R32F
;
84 case WINED3DFMT_R32G32_FLOAT
: return D3DFMT_G32R32F
;
85 case WINED3DFMT_R32G32B32A32_FLOAT
: return D3DFMT_A32B32G32R32F
;
86 case WINED3DFMT_R8G8_SNORM_Cx
: return D3DFMT_CxV8U8
;
88 FIXME("Unhandled wined3d format %#x.\n", format
);
89 return D3DFMT_UNKNOWN
;
93 enum wined3d_format_id
wined3dformat_from_d3dformat(D3DFORMAT format
)
95 BYTE
*c
= (BYTE
*)&format
;
97 /* Don't translate FOURCC formats */
98 if (isprint(c
[0]) && isprint(c
[1]) && isprint(c
[2]) && isprint(c
[3])) return format
;
102 case D3DFMT_UNKNOWN
: return WINED3DFMT_UNKNOWN
;
103 case D3DFMT_R8G8B8
: return WINED3DFMT_B8G8R8_UNORM
;
104 case D3DFMT_A8R8G8B8
: return WINED3DFMT_B8G8R8A8_UNORM
;
105 case D3DFMT_X8R8G8B8
: return WINED3DFMT_B8G8R8X8_UNORM
;
106 case D3DFMT_R5G6B5
: return WINED3DFMT_B5G6R5_UNORM
;
107 case D3DFMT_X1R5G5B5
: return WINED3DFMT_B5G5R5X1_UNORM
;
108 case D3DFMT_A1R5G5B5
: return WINED3DFMT_B5G5R5A1_UNORM
;
109 case D3DFMT_A4R4G4B4
: return WINED3DFMT_B4G4R4A4_UNORM
;
110 case D3DFMT_R3G3B2
: return WINED3DFMT_B2G3R3_UNORM
;
111 case D3DFMT_A8
: return WINED3DFMT_A8_UNORM
;
112 case D3DFMT_A8R3G3B2
: return WINED3DFMT_B2G3R3A8_UNORM
;
113 case D3DFMT_X4R4G4B4
: return WINED3DFMT_B4G4R4X4_UNORM
;
114 case D3DFMT_A2B10G10R10
: return WINED3DFMT_R10G10B10A2_UNORM
;
115 case D3DFMT_A8B8G8R8
: return WINED3DFMT_R8G8B8A8_UNORM
;
116 case D3DFMT_X8B8G8R8
: return WINED3DFMT_R8G8B8X8_UNORM
;
117 case D3DFMT_G16R16
: return WINED3DFMT_R16G16_UNORM
;
118 case D3DFMT_A2R10G10B10
: return WINED3DFMT_B10G10R10A2_UNORM
;
119 case D3DFMT_A16B16G16R16
: return WINED3DFMT_R16G16B16A16_UNORM
;
120 case D3DFMT_A8P8
: return WINED3DFMT_P8_UINT_A8_UNORM
;
121 case D3DFMT_P8
: return WINED3DFMT_P8_UINT
;
122 case D3DFMT_L8
: return WINED3DFMT_L8_UNORM
;
123 case D3DFMT_A8L8
: return WINED3DFMT_L8A8_UNORM
;
124 case D3DFMT_A4L4
: return WINED3DFMT_L4A4_UNORM
;
125 case D3DFMT_V8U8
: return WINED3DFMT_R8G8_SNORM
;
126 case D3DFMT_L6V5U5
: return WINED3DFMT_R5G5_SNORM_L6_UNORM
;
127 case D3DFMT_X8L8V8U8
: return WINED3DFMT_R8G8_SNORM_L8X8_UNORM
;
128 case D3DFMT_Q8W8V8U8
: return WINED3DFMT_R8G8B8A8_SNORM
;
129 case D3DFMT_V16U16
: return WINED3DFMT_R16G16_SNORM
;
130 case D3DFMT_A2W10V10U10
: return WINED3DFMT_R10G10B10_SNORM_A2_UNORM
;
131 case D3DFMT_D16_LOCKABLE
: return WINED3DFMT_D16_LOCKABLE
;
132 case D3DFMT_D32
: return WINED3DFMT_D32_UNORM
;
133 case D3DFMT_D15S1
: return WINED3DFMT_S1_UINT_D15_UNORM
;
134 case D3DFMT_D24S8
: return WINED3DFMT_D24_UNORM_S8_UINT
;
135 case D3DFMT_D24X8
: return WINED3DFMT_X8D24_UNORM
;
136 case D3DFMT_D24X4S4
: return WINED3DFMT_S4X4_UINT_D24_UNORM
;
137 case D3DFMT_D16
: return WINED3DFMT_D16_UNORM
;
138 case D3DFMT_L16
: return WINED3DFMT_L16_UNORM
;
139 case D3DFMT_D32F_LOCKABLE
: return WINED3DFMT_D32_FLOAT
;
140 case D3DFMT_D24FS8
: return WINED3DFMT_S8_UINT_D24_FLOAT
;
141 case D3DFMT_VERTEXDATA
: return WINED3DFMT_VERTEXDATA
;
142 case D3DFMT_INDEX16
: return WINED3DFMT_R16_UINT
;
143 case D3DFMT_INDEX32
: return WINED3DFMT_R32_UINT
;
144 case D3DFMT_Q16W16V16U16
: return WINED3DFMT_R16G16B16A16_SNORM
;
145 case D3DFMT_R16F
: return WINED3DFMT_R16_FLOAT
;
146 case D3DFMT_G16R16F
: return WINED3DFMT_R16G16_FLOAT
;
147 case D3DFMT_A16B16G16R16F
: return WINED3DFMT_R16G16B16A16_FLOAT
;
148 case D3DFMT_R32F
: return WINED3DFMT_R32_FLOAT
;
149 case D3DFMT_G32R32F
: return WINED3DFMT_R32G32_FLOAT
;
150 case D3DFMT_A32B32G32R32F
: return WINED3DFMT_R32G32B32A32_FLOAT
;
151 case D3DFMT_CxV8U8
: return WINED3DFMT_R8G8_SNORM_Cx
;
153 FIXME("Unhandled D3DFORMAT %#x\n", format
);
154 return WINED3DFMT_UNKNOWN
;
158 static UINT
vertex_count_from_primitive_count(D3DPRIMITIVETYPE primitive_type
, UINT primitive_count
)
160 switch(primitive_type
)
162 case D3DPT_POINTLIST
:
163 return primitive_count
;
166 return primitive_count
* 2;
168 case D3DPT_LINESTRIP
:
169 return primitive_count
+ 1;
171 case D3DPT_TRIANGLELIST
:
172 return primitive_count
* 3;
174 case D3DPT_TRIANGLESTRIP
:
175 case D3DPT_TRIANGLEFAN
:
176 return primitive_count
+ 2;
179 FIXME("Unhandled primitive type %#x\n", primitive_type
);
184 static inline IDirect3DDevice9Impl
*impl_from_IDirect3DDevice9Ex(IDirect3DDevice9Ex
*iface
)
186 return CONTAINING_RECORD(iface
, IDirect3DDevice9Impl
, IDirect3DDevice9Ex_iface
);
189 static HRESULT WINAPI
IDirect3DDevice9Impl_QueryInterface(IDirect3DDevice9Ex
*iface
, REFIID riid
,
192 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
194 IDirect3D9Impl
*d3dimpl
;
196 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), ppobj
);
198 if (IsEqualGUID(riid
, &IID_IUnknown
)
199 || IsEqualGUID(riid
, &IID_IDirect3DDevice9
)) {
200 IDirect3DDevice9Ex_AddRef(iface
);
202 TRACE("Returning IDirect3DDevice9 interface at %p\n", *ppobj
);
204 } else if(IsEqualGUID(riid
, &IID_IDirect3DDevice9Ex
)) {
205 /* Find out if the creating d3d9 interface was created with Direct3DCreate9Ex.
206 * It doesn't matter with which function the device was created.
208 IDirect3DDevice9_GetDirect3D(iface
, &d3d
);
209 d3dimpl
= (IDirect3D9Impl
*) d3d
;
211 if(d3dimpl
->extended
) {
213 IDirect3DDevice9Ex_AddRef((IDirect3DDevice9Ex
*) *ppobj
);
214 IDirect3D9_Release(d3d
);
215 TRACE("Returning IDirect3DDevice9Ex interface at %p\n", *ppobj
);
218 WARN("IDirect3D9 instance wasn't created with CreateDirect3D9Ex, returning E_NOINTERFACE\n");
219 IDirect3D9_Release(d3d
);
221 return E_NOINTERFACE
;
225 WARN("(%p)->(%s,%p),not found\n", This
, debugstr_guid(riid
), ppobj
);
227 return E_NOINTERFACE
;
230 static ULONG WINAPI
IDirect3DDevice9Impl_AddRef(IDirect3DDevice9Ex
*iface
)
232 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
233 ULONG ref
= InterlockedIncrement(&This
->ref
);
235 TRACE("%p increasing refcount to %u.\n", iface
, ref
);
240 static ULONG WINAPI DECLSPEC_HOTPATCH
IDirect3DDevice9Impl_Release(IDirect3DDevice9Ex
*iface
)
242 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
245 if (This
->inDestruction
) return 0;
246 ref
= InterlockedDecrement(&This
->ref
);
248 TRACE("%p decreasing refcount to %u.\n", iface
, ref
);
252 This
->inDestruction
= TRUE
;
254 wined3d_mutex_lock();
255 for(i
= 0; i
< This
->numConvertedDecls
; i
++) {
256 /* Unless Wine is buggy or the app has a bug the refcount will be 0, because decls hold a reference to the
259 IDirect3DVertexDeclaration9Impl_Destroy(This
->convertedDecls
[i
]);
261 HeapFree(GetProcessHeap(), 0, This
->convertedDecls
);
263 wined3d_device_uninit_3d(This
->wined3d_device
);
264 wined3d_device_release_focus_window(This
->wined3d_device
);
265 wined3d_device_decref(This
->wined3d_device
);
266 wined3d_mutex_unlock();
268 IDirect3D9_Release(This
->d3d_parent
);
270 HeapFree(GetProcessHeap(), 0, This
);
275 static HRESULT WINAPI
IDirect3DDevice9Impl_TestCooperativeLevel(IDirect3DDevice9Ex
*iface
)
277 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
279 TRACE("iface %p.\n", iface
);
283 TRACE("D3D9 device is marked not reset.\n");
284 return D3DERR_DEVICENOTRESET
;
290 static UINT WINAPI
IDirect3DDevice9Impl_GetAvailableTextureMem(IDirect3DDevice9Ex
*iface
)
292 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
295 TRACE("iface %p.\n", iface
);
297 wined3d_mutex_lock();
298 hr
= wined3d_device_get_available_texture_mem(This
->wined3d_device
);
299 wined3d_mutex_unlock();
304 static HRESULT WINAPI
IDirect3DDevice9Impl_EvictManagedResources(IDirect3DDevice9Ex
*iface
)
306 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
308 TRACE("iface %p.\n", iface
);
310 wined3d_mutex_lock();
311 wined3d_device_evict_managed_resources(This
->wined3d_device
);
312 wined3d_mutex_unlock();
317 static HRESULT WINAPI
IDirect3DDevice9Impl_GetDirect3D(IDirect3DDevice9Ex
*iface
,
320 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
322 TRACE("iface %p, d3d9 %p.\n", iface
, ppD3D9
);
324 if (NULL
== ppD3D9
) {
325 return D3DERR_INVALIDCALL
;
328 return IDirect3D9Ex_QueryInterface(This
->d3d_parent
, &IID_IDirect3D9
, (void **)ppD3D9
);
331 static HRESULT WINAPI
IDirect3DDevice9Impl_GetDeviceCaps(IDirect3DDevice9Ex
*iface
, D3DCAPS9
*pCaps
)
333 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
334 HRESULT hrc
= D3D_OK
;
335 WINED3DCAPS
*pWineCaps
;
337 TRACE("iface %p, caps %p.\n", iface
, pCaps
);
340 return D3DERR_INVALIDCALL
;
342 pWineCaps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WINED3DCAPS
));
343 if(pWineCaps
== NULL
){
344 return D3DERR_INVALIDCALL
; /* well this is what MSDN says to return */
347 memset(pCaps
, 0, sizeof(*pCaps
));
349 wined3d_mutex_lock();
350 hrc
= wined3d_device_get_device_caps(This
->wined3d_device
, pWineCaps
);
351 wined3d_mutex_unlock();
353 WINECAPSTOD3D9CAPS(pCaps
, pWineCaps
)
354 HeapFree(GetProcessHeap(), 0, pWineCaps
);
356 /* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps */
357 pCaps
->DevCaps2
|= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES
;
361 TRACE("Returning %p %p\n", This
, pCaps
);
365 static HRESULT WINAPI
IDirect3DDevice9Impl_GetDisplayMode(IDirect3DDevice9Ex
*iface
,
366 UINT iSwapChain
, D3DDISPLAYMODE
*pMode
)
368 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
371 TRACE("iface %p, swapchain %u, mode %p.\n", iface
, iSwapChain
, pMode
);
373 wined3d_mutex_lock();
374 hr
= wined3d_device_get_display_mode(This
->wined3d_device
, iSwapChain
, (struct wined3d_display_mode
*)pMode
);
375 wined3d_mutex_unlock();
377 if (SUCCEEDED(hr
)) pMode
->Format
= d3dformat_from_wined3dformat(pMode
->Format
);
382 static HRESULT WINAPI
IDirect3DDevice9Impl_GetCreationParameters(IDirect3DDevice9Ex
*iface
,
383 D3DDEVICE_CREATION_PARAMETERS
*pParameters
)
385 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
388 TRACE("iface %p, parameters %p.\n", iface
, pParameters
);
390 wined3d_mutex_lock();
391 hr
= wined3d_device_get_creation_parameters(This
->wined3d_device
,
392 (WINED3DDEVICE_CREATION_PARAMETERS
*)pParameters
);
393 wined3d_mutex_unlock();
398 static HRESULT WINAPI
IDirect3DDevice9Impl_SetCursorProperties(IDirect3DDevice9Ex
*iface
,
399 UINT XHotSpot
, UINT YHotSpot
, IDirect3DSurface9
*pCursorBitmap
)
401 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
402 IDirect3DSurface9Impl
*pSurface
= unsafe_impl_from_IDirect3DSurface9(pCursorBitmap
);
405 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
406 iface
, XHotSpot
, YHotSpot
, pCursorBitmap
);
410 WARN("No cursor bitmap, returning D3DERR_INVALIDCALL.\n");
411 return D3DERR_INVALIDCALL
;
414 wined3d_mutex_lock();
415 hr
= wined3d_device_set_cursor_properties(This
->wined3d_device
, XHotSpot
, YHotSpot
, pSurface
->wined3d_surface
);
416 wined3d_mutex_unlock();
421 static void WINAPI
IDirect3DDevice9Impl_SetCursorPosition(IDirect3DDevice9Ex
*iface
,
422 int XScreenSpace
, int YScreenSpace
, DWORD Flags
)
424 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
426 TRACE("iface %p, x %u, y %u, flags %#x.\n", iface
, XScreenSpace
, YScreenSpace
, Flags
);
428 wined3d_mutex_lock();
429 wined3d_device_set_cursor_position(This
->wined3d_device
, XScreenSpace
, YScreenSpace
, Flags
);
430 wined3d_mutex_unlock();
433 static BOOL WINAPI
IDirect3DDevice9Impl_ShowCursor(IDirect3DDevice9Ex
*iface
, BOOL bShow
)
435 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
438 TRACE("iface %p, show %#x.\n", iface
, bShow
);
440 wined3d_mutex_lock();
441 ret
= wined3d_device_show_cursor(This
->wined3d_device
, bShow
);
442 wined3d_mutex_unlock();
447 static HRESULT WINAPI DECLSPEC_HOTPATCH
IDirect3DDevice9Impl_CreateAdditionalSwapChain(IDirect3DDevice9Ex
*iface
,
448 D3DPRESENT_PARAMETERS
*present_parameters
, IDirect3DSwapChain9
**swapchain
)
450 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
451 IDirect3DSwapChain9Impl
*object
;
454 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
455 iface
, present_parameters
, swapchain
);
457 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
460 ERR("Failed to allocate swapchain memory.\n");
461 return E_OUTOFMEMORY
;
464 hr
= swapchain_init(object
, This
, present_parameters
);
467 WARN("Failed to initialize swapchain, hr %#x.\n", hr
);
468 HeapFree(GetProcessHeap(), 0, object
);
472 TRACE("Created swapchain %p.\n", object
);
473 *swapchain
= (IDirect3DSwapChain9
*)object
;
478 static HRESULT WINAPI DECLSPEC_HOTPATCH
IDirect3DDevice9Impl_GetSwapChain(IDirect3DDevice9Ex
*iface
,
479 UINT swapchain_idx
, IDirect3DSwapChain9
**swapchain
)
481 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
482 struct wined3d_swapchain
*wined3d_swapchain
= NULL
;
485 TRACE("iface %p, swapchain_idx %u, swapchain %p.\n", iface
, swapchain_idx
, swapchain
);
487 wined3d_mutex_lock();
488 hr
= wined3d_device_get_swapchain(This
->wined3d_device
, swapchain_idx
, &wined3d_swapchain
);
489 if (SUCCEEDED(hr
) && wined3d_swapchain
)
491 *swapchain
= wined3d_swapchain_get_parent(wined3d_swapchain
);
492 IDirect3DSwapChain9_AddRef(*swapchain
);
493 wined3d_swapchain_decref(wined3d_swapchain
);
499 wined3d_mutex_unlock();
504 static UINT WINAPI
IDirect3DDevice9Impl_GetNumberOfSwapChains(IDirect3DDevice9Ex
*iface
)
506 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
509 TRACE("iface %p.\n", iface
);
511 wined3d_mutex_lock();
512 count
= wined3d_device_get_swapchain_count(This
->wined3d_device
);
513 wined3d_mutex_unlock();
518 static HRESULT CDECL
reset_enum_callback(struct wined3d_resource
*resource
)
520 struct wined3d_resource_desc desc
;
522 wined3d_resource_get_desc(resource
, &desc
);
523 if (desc
.pool
== WINED3DPOOL_DEFAULT
)
525 IDirect3DSurface9
*surface
;
527 if (desc
.resource_type
!= WINED3DRTYPE_SURFACE
)
529 WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource
);
530 return D3DERR_INVALIDCALL
;
533 surface
= wined3d_resource_get_parent(resource
);
535 IDirect3DSurface9_AddRef(surface
);
536 if (IDirect3DSurface9_Release(surface
))
538 WARN("Surface %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface
, resource
);
539 return D3DERR_INVALIDCALL
;
542 WARN("Surface %p (resource %p) is an implicit resource with ref 0.\n", surface
, resource
);
548 static HRESULT WINAPI DECLSPEC_HOTPATCH
IDirect3DDevice9Impl_Reset(IDirect3DDevice9Ex
*iface
,
549 D3DPRESENT_PARAMETERS
*pPresentationParameters
)
551 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
552 WINED3DPRESENT_PARAMETERS localParameters
;
555 TRACE("iface %p, present_parameters %p.\n", iface
, pPresentationParameters
);
557 /* Reset states that hold a COM object. WineD3D holds an internal reference to set objects, because
558 * such objects can still be used for rendering after their external d3d9 object has been destroyed.
559 * These objects must not be enumerated. Unsetting them tells WineD3D that the application will not
560 * make use of the hidden reference and destroys the objects.
562 * Unsetting them is no problem, because the states are supposed to be reset anyway. If the validation
563 * below fails, the device is considered "lost", and _Reset and _Release are the only allowed calls
565 wined3d_mutex_lock();
567 localParameters
.BackBufferWidth
= pPresentationParameters
->BackBufferWidth
;
568 localParameters
.BackBufferHeight
= pPresentationParameters
->BackBufferHeight
;
569 localParameters
.BackBufferFormat
= wined3dformat_from_d3dformat(pPresentationParameters
->BackBufferFormat
);
570 localParameters
.BackBufferCount
= pPresentationParameters
->BackBufferCount
;
571 localParameters
.MultiSampleType
= pPresentationParameters
->MultiSampleType
;
572 localParameters
.MultiSampleQuality
= pPresentationParameters
->MultiSampleQuality
;
573 localParameters
.SwapEffect
= pPresentationParameters
->SwapEffect
;
574 localParameters
.hDeviceWindow
= pPresentationParameters
->hDeviceWindow
;
575 localParameters
.Windowed
= pPresentationParameters
->Windowed
;
576 localParameters
.EnableAutoDepthStencil
= pPresentationParameters
->EnableAutoDepthStencil
;
577 localParameters
.AutoDepthStencilFormat
= wined3dformat_from_d3dformat(pPresentationParameters
->AutoDepthStencilFormat
);
578 localParameters
.Flags
= pPresentationParameters
->Flags
;
579 localParameters
.FullScreen_RefreshRateInHz
= pPresentationParameters
->FullScreen_RefreshRateInHz
;
580 localParameters
.PresentationInterval
= pPresentationParameters
->PresentationInterval
;
581 localParameters
.AutoRestoreDisplayMode
= TRUE
;
583 hr
= wined3d_device_reset(This
->wined3d_device
, &localParameters
, reset_enum_callback
);
585 This
->notreset
= TRUE
;
587 This
->notreset
= FALSE
;
589 wined3d_mutex_unlock();
594 static HRESULT WINAPI DECLSPEC_HOTPATCH
IDirect3DDevice9Impl_Present(IDirect3DDevice9Ex
*iface
,
595 const RECT
*pSourceRect
, const RECT
*pDestRect
, HWND hDestWindowOverride
,
596 const RGNDATA
*pDirtyRegion
)
598 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
601 TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
602 iface
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
604 wined3d_mutex_lock();
605 hr
= wined3d_device_present(This
->wined3d_device
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
606 wined3d_mutex_unlock();
611 static HRESULT WINAPI
IDirect3DDevice9Impl_GetBackBuffer(IDirect3DDevice9Ex
*iface
,
612 UINT iSwapChain
, UINT BackBuffer
, D3DBACKBUFFER_TYPE Type
, IDirect3DSurface9
**ppBackBuffer
)
614 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
615 struct wined3d_surface
*wined3d_surface
= NULL
;
618 TRACE("iface %p, swapchain %u, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
619 iface
, iSwapChain
, BackBuffer
, Type
, ppBackBuffer
);
621 wined3d_mutex_lock();
622 hr
= wined3d_device_get_back_buffer(This
->wined3d_device
, iSwapChain
,
623 BackBuffer
, (WINED3DBACKBUFFER_TYPE
) Type
, &wined3d_surface
);
624 if (SUCCEEDED(hr
) && wined3d_surface
&& ppBackBuffer
)
626 *ppBackBuffer
= wined3d_surface_get_parent(wined3d_surface
);
627 IDirect3DSurface9_AddRef(*ppBackBuffer
);
628 wined3d_surface_decref(wined3d_surface
);
630 wined3d_mutex_unlock();
634 static HRESULT WINAPI
IDirect3DDevice9Impl_GetRasterStatus(IDirect3DDevice9Ex
*iface
,
635 UINT iSwapChain
, D3DRASTER_STATUS
*pRasterStatus
)
637 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
640 TRACE("iface %p, swapchain %u, raster_status %p.\n", iface
, iSwapChain
, pRasterStatus
);
642 wined3d_mutex_lock();
643 hr
= wined3d_device_get_raster_status(This
->wined3d_device
, iSwapChain
, (WINED3DRASTER_STATUS
*)pRasterStatus
);
644 wined3d_mutex_unlock();
649 static HRESULT WINAPI
IDirect3DDevice9Impl_SetDialogBoxMode(IDirect3DDevice9Ex
*iface
,
652 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
655 TRACE("iface %p, enable %#x.\n", iface
, bEnableDialogs
);
657 wined3d_mutex_lock();
658 hr
= wined3d_device_set_dialog_box_mode(This
->wined3d_device
, bEnableDialogs
);
659 wined3d_mutex_unlock();
664 static void WINAPI
IDirect3DDevice9Impl_SetGammaRamp(IDirect3DDevice9Ex
*iface
, UINT iSwapChain
,
665 DWORD Flags
, const D3DGAMMARAMP
*pRamp
)
667 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
669 TRACE("iface %p, swapchain %u, flags %#x, ramp %p.\n", iface
, iSwapChain
, Flags
, pRamp
);
671 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
672 wined3d_mutex_lock();
673 wined3d_device_set_gamma_ramp(This
->wined3d_device
, iSwapChain
, Flags
, (const struct wined3d_gamma_ramp
*)pRamp
);
674 wined3d_mutex_unlock();
677 static void WINAPI
IDirect3DDevice9Impl_GetGammaRamp(IDirect3DDevice9Ex
*iface
, UINT iSwapChain
,
680 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
682 TRACE("iface %p, swapchain %u, ramp %p.\n", iface
, iSwapChain
, pRamp
);
684 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
685 wined3d_mutex_lock();
686 wined3d_device_get_gamma_ramp(This
->wined3d_device
, iSwapChain
, (struct wined3d_gamma_ramp
*)pRamp
);
687 wined3d_mutex_unlock();
690 static HRESULT WINAPI
IDirect3DDevice9Impl_CreateTexture(IDirect3DDevice9Ex
*iface
,
691 UINT width
, UINT height
, UINT levels
, DWORD usage
, D3DFORMAT format
,
692 D3DPOOL pool
, IDirect3DTexture9
**texture
, HANDLE
*shared_handle
)
694 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
695 IDirect3DTexture9Impl
*object
;
698 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
699 iface
, width
, height
, levels
, usage
, format
, pool
, texture
, shared_handle
);
701 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
704 ERR("Failed to allocate texture memory.\n");
705 return D3DERR_OUTOFVIDEOMEMORY
;
708 hr
= texture_init(object
, This
, width
, height
, levels
, usage
, format
, pool
);
711 WARN("Failed to initialize texture, hr %#x.\n", hr
);
712 HeapFree(GetProcessHeap(), 0, object
);
716 TRACE("Created texture %p.\n", object
);
717 *texture
= &object
->IDirect3DTexture9_iface
;
722 static HRESULT WINAPI
IDirect3DDevice9Impl_CreateVolumeTexture(IDirect3DDevice9Ex
*iface
,
723 UINT width
, UINT height
, UINT depth
, UINT levels
, DWORD usage
, D3DFORMAT format
,
724 D3DPOOL pool
, IDirect3DVolumeTexture9
**texture
, HANDLE
*shared_handle
)
726 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
727 IDirect3DVolumeTexture9Impl
*object
;
730 TRACE("iface %p, width %u, height %u, depth %u, levels %u\n",
731 iface
, width
, height
, depth
, levels
);
732 TRACE("usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
733 usage
, format
, pool
, texture
, shared_handle
);
735 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
738 ERR("Failed to allocate volume texture memory.\n");
739 return D3DERR_OUTOFVIDEOMEMORY
;
742 hr
= volumetexture_init(object
, This
, width
, height
, depth
, levels
, usage
, format
, pool
);
745 WARN("Failed to initialize volume texture, hr %#x.\n", hr
);
746 HeapFree(GetProcessHeap(), 0, object
);
750 TRACE("Created volume texture %p.\n", object
);
751 *texture
= &object
->IDirect3DVolumeTexture9_iface
;
756 static HRESULT WINAPI
IDirect3DDevice9Impl_CreateCubeTexture(IDirect3DDevice9Ex
*iface
,
757 UINT edge_length
, UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
,
758 IDirect3DCubeTexture9
**texture
, HANDLE
*shared_handle
)
760 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
761 IDirect3DCubeTexture9Impl
*object
;
764 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
765 iface
, edge_length
, levels
, usage
, format
, pool
, texture
, shared_handle
);
767 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
770 ERR("Failed to allocate cube texture memory.\n");
771 return D3DERR_OUTOFVIDEOMEMORY
;
774 hr
= cubetexture_init(object
, This
, edge_length
, levels
, usage
, format
, pool
);
777 WARN("Failed to initialize cube texture, hr %#x.\n", hr
);
778 HeapFree(GetProcessHeap(), 0, object
);
782 TRACE("Created cube texture %p.\n", object
);
783 *texture
= &object
->IDirect3DCubeTexture9_iface
;
788 static HRESULT WINAPI
IDirect3DDevice9Impl_CreateVertexBuffer(IDirect3DDevice9Ex
*iface
, UINT size
,
789 DWORD usage
, DWORD fvf
, D3DPOOL pool
, IDirect3DVertexBuffer9
**buffer
,
790 HANDLE
*shared_handle
)
792 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
793 IDirect3DVertexBuffer9Impl
*object
;
796 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p, shared_handle %p.\n",
797 iface
, size
, usage
, fvf
, pool
, buffer
, shared_handle
);
799 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
802 ERR("Failed to allocate buffer memory.\n");
803 return D3DERR_OUTOFVIDEOMEMORY
;
806 hr
= vertexbuffer_init(object
, This
, size
, usage
, fvf
, pool
);
809 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr
);
810 HeapFree(GetProcessHeap(), 0, object
);
814 TRACE("Created vertex buffer %p.\n", object
);
815 *buffer
= &object
->IDirect3DVertexBuffer9_iface
;
820 static HRESULT WINAPI
IDirect3DDevice9Impl_CreateIndexBuffer(IDirect3DDevice9Ex
*iface
, UINT size
,
821 DWORD usage
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DIndexBuffer9
**buffer
,
822 HANDLE
*shared_handle
)
824 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
825 IDirect3DIndexBuffer9Impl
*object
;
828 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p, shared_handle %p.\n",
829 iface
, size
, usage
, format
, pool
, buffer
, shared_handle
);
831 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
834 ERR("Failed to allocate buffer memory.\n");
835 return D3DERR_OUTOFVIDEOMEMORY
;
838 hr
= indexbuffer_init(object
, This
, size
, usage
, format
, pool
);
841 WARN("Failed to initialize index buffer, hr %#x.\n", hr
);
842 HeapFree(GetProcessHeap(), 0, object
);
846 TRACE("Created index buffer %p.\n", object
);
847 *buffer
= &object
->IDirect3DIndexBuffer9_iface
;
852 static HRESULT
IDirect3DDevice9Impl_CreateSurface(IDirect3DDevice9Impl
*device
, UINT Width
,
853 UINT Height
, D3DFORMAT Format
, BOOL Lockable
, BOOL Discard
, UINT Level
,
854 IDirect3DSurface9
**ppSurface
, UINT Usage
, D3DPOOL Pool
, D3DMULTISAMPLE_TYPE MultiSample
,
855 DWORD MultisampleQuality
)
857 IDirect3DSurface9Impl
*object
;
860 TRACE("device %p, width %u, height %u, format %#x, lockable %#x, discard %#x, level %u, surface %p.\n"
861 "usage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
862 device
, Width
, Height
, Format
, Lockable
, Discard
, Level
, ppSurface
, Usage
, Pool
,
863 MultiSample
, MultisampleQuality
);
865 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirect3DSurface9Impl
));
868 FIXME("Failed to allocate surface memory.\n");
869 return D3DERR_OUTOFVIDEOMEMORY
;
872 hr
= surface_init(object
, device
, Width
, Height
, Format
, Lockable
, Discard
, Level
, Usage
, Pool
,
873 MultiSample
, MultisampleQuality
);
876 WARN("Failed to initialize surface, hr %#x.\n", hr
);
877 HeapFree(GetProcessHeap(), 0, object
);
881 TRACE("Created surface %p.\n", object
);
882 *ppSurface
= &object
->IDirect3DSurface9_iface
;
887 static HRESULT WINAPI
IDirect3DDevice9Impl_CreateRenderTarget(IDirect3DDevice9Ex
*iface
, UINT Width
,
888 UINT Height
, D3DFORMAT Format
, D3DMULTISAMPLE_TYPE MultiSample
, DWORD MultisampleQuality
,
889 BOOL Lockable
, IDirect3DSurface9
**ppSurface
, HANDLE
*pSharedHandle
)
891 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
894 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
895 "lockable %#x, surface %p, shared_handle %p.\n",
896 iface
, Width
, Height
, Format
, MultiSample
, MultisampleQuality
,
897 Lockable
, ppSurface
, pSharedHandle
);
899 hr
= IDirect3DDevice9Impl_CreateSurface(This
, Width
, Height
, Format
, Lockable
,
900 FALSE
/* Discard */, 0 /* Level */, ppSurface
, D3DUSAGE_RENDERTARGET
, D3DPOOL_DEFAULT
,
901 MultiSample
, MultisampleQuality
);
906 static HRESULT WINAPI
IDirect3DDevice9Impl_CreateDepthStencilSurface(IDirect3DDevice9Ex
*iface
,
907 UINT Width
, UINT Height
, D3DFORMAT Format
, D3DMULTISAMPLE_TYPE MultiSample
,
908 DWORD MultisampleQuality
, BOOL Discard
, IDirect3DSurface9
**ppSurface
,
909 HANDLE
*pSharedHandle
)
911 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
914 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
915 "discard %#x, surface %p, shared_handle %p.\n",
916 iface
, Width
, Height
, Format
, MultiSample
, MultisampleQuality
,
917 Discard
, ppSurface
, pSharedHandle
);
919 hr
= IDirect3DDevice9Impl_CreateSurface(This
, Width
, Height
, Format
, TRUE
/* Lockable */,
920 Discard
, 0 /* Level */, ppSurface
, D3DUSAGE_DEPTHSTENCIL
, D3DPOOL_DEFAULT
, MultiSample
,
927 static HRESULT WINAPI
IDirect3DDevice9Impl_UpdateSurface(IDirect3DDevice9Ex
*iface
,
928 IDirect3DSurface9
*pSourceSurface
, const RECT
*pSourceRect
,
929 IDirect3DSurface9
*pDestinationSurface
, const POINT
*pDestPoint
)
931 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
932 IDirect3DSurface9Impl
*src
= unsafe_impl_from_IDirect3DSurface9(pSourceSurface
);
933 IDirect3DSurface9Impl
*dst
= unsafe_impl_from_IDirect3DSurface9(pDestinationSurface
);
936 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_point %p.\n",
937 iface
, pSourceSurface
, pSourceRect
, pDestinationSurface
, pDestPoint
);
939 wined3d_mutex_lock();
940 hr
= wined3d_device_update_surface(This
->wined3d_device
, src
->wined3d_surface
, pSourceRect
,
941 dst
->wined3d_surface
, pDestPoint
);
942 wined3d_mutex_unlock();
947 static HRESULT WINAPI
IDirect3DDevice9Impl_UpdateTexture(IDirect3DDevice9Ex
*iface
,
948 IDirect3DBaseTexture9
*src_texture
, IDirect3DBaseTexture9
*dst_texture
)
950 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
953 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface
, src_texture
, dst_texture
);
955 wined3d_mutex_lock();
956 hr
= wined3d_device_update_texture(This
->wined3d_device
,
957 ((IDirect3DBaseTexture9Impl
*)src_texture
)->wined3d_texture
,
958 ((IDirect3DBaseTexture9Impl
*)dst_texture
)->wined3d_texture
);
959 wined3d_mutex_unlock();
964 static HRESULT WINAPI
IDirect3DDevice9Impl_GetRenderTargetData(IDirect3DDevice9Ex
*iface
,
965 IDirect3DSurface9
*pRenderTarget
, IDirect3DSurface9
*pDestSurface
)
967 IDirect3DSurface9Impl
*renderTarget
= unsafe_impl_from_IDirect3DSurface9(pRenderTarget
);
968 IDirect3DSurface9Impl
*destSurface
= unsafe_impl_from_IDirect3DSurface9(pDestSurface
);
971 TRACE("iface %p, render_target %p, dst_surface %p.\n", iface
, pRenderTarget
, pDestSurface
);
973 wined3d_mutex_lock();
974 hr
= wined3d_surface_get_render_target_data(destSurface
->wined3d_surface
, renderTarget
->wined3d_surface
);
975 wined3d_mutex_unlock();
980 static HRESULT WINAPI
IDirect3DDevice9Impl_GetFrontBufferData(IDirect3DDevice9Ex
*iface
,
981 UINT iSwapChain
, IDirect3DSurface9
*pDestSurface
)
983 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
984 IDirect3DSurface9Impl
*destSurface
= unsafe_impl_from_IDirect3DSurface9(pDestSurface
);
987 TRACE("iface %p, swapchain %u, dst_surface %p.\n", iface
, iSwapChain
, pDestSurface
);
989 wined3d_mutex_lock();
990 hr
= wined3d_device_get_front_buffer_data(This
->wined3d_device
, iSwapChain
, destSurface
->wined3d_surface
);
991 wined3d_mutex_unlock();
996 static HRESULT WINAPI
IDirect3DDevice9Impl_StretchRect(IDirect3DDevice9Ex
*iface
, IDirect3DSurface9
*pSourceSurface
,
997 const RECT
*pSourceRect
, IDirect3DSurface9
*pDestSurface
, const RECT
*pDestRect
, D3DTEXTUREFILTERTYPE Filter
)
999 IDirect3DSurface9Impl
*src
= unsafe_impl_from_IDirect3DSurface9(pSourceSurface
);
1000 IDirect3DSurface9Impl
*dst
= unsafe_impl_from_IDirect3DSurface9(pDestSurface
);
1003 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_rect %p, filter %#x.\n",
1004 iface
, pSourceSurface
, pSourceRect
, pDestSurface
, pDestRect
, Filter
);
1006 wined3d_mutex_lock();
1007 hr
= wined3d_surface_blt(dst
->wined3d_surface
, pDestRect
, src
->wined3d_surface
, pSourceRect
, 0, NULL
, Filter
);
1008 if (hr
== WINEDDERR_INVALIDRECT
)
1009 hr
= D3DERR_INVALIDCALL
;
1010 wined3d_mutex_unlock();
1015 static HRESULT WINAPI
IDirect3DDevice9Impl_ColorFill(IDirect3DDevice9Ex
*iface
,
1016 IDirect3DSurface9
*pSurface
, const RECT
*pRect
, D3DCOLOR color
)
1018 const struct wined3d_color c
=
1020 ((color
>> 16) & 0xff) / 255.0f
,
1021 ((color
>> 8) & 0xff) / 255.0f
,
1022 (color
& 0xff) / 255.0f
,
1023 ((color
>> 24) & 0xff) / 255.0f
,
1025 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1026 IDirect3DSurface9Impl
*surface
= unsafe_impl_from_IDirect3DSurface9(pSurface
);
1027 struct wined3d_resource
*wined3d_resource
;
1028 struct wined3d_resource_desc desc
;
1031 TRACE("iface %p, surface %p, rect %p, color 0x%08x.\n", iface
, pSurface
, pRect
, color
);
1033 wined3d_mutex_lock();
1035 wined3d_resource
= wined3d_surface_get_resource(surface
->wined3d_surface
);
1036 wined3d_resource_get_desc(wined3d_resource
, &desc
);
1038 /* This method is only allowed with surfaces that are render targets, or
1039 * offscreen plain surfaces in D3DPOOL_DEFAULT. */
1040 if (!(desc
.usage
& WINED3DUSAGE_RENDERTARGET
) && desc
.pool
!= WINED3DPOOL_DEFAULT
)
1042 wined3d_mutex_unlock();
1043 WARN("Surface is not a render target, or not a stand-alone D3DPOOL_DEFAULT surface\n");
1044 return D3DERR_INVALIDCALL
;
1047 /* Colorfill can only be used on rendertarget surfaces, or offscreen plain surfaces in D3DPOOL_DEFAULT */
1048 hr
= wined3d_device_color_fill(This
->wined3d_device
, surface
->wined3d_surface
, pRect
, &c
);
1050 wined3d_mutex_unlock();
1055 static HRESULT WINAPI
IDirect3DDevice9Impl_CreateOffscreenPlainSurface(IDirect3DDevice9Ex
*iface
,
1056 UINT Width
, UINT Height
, D3DFORMAT Format
, D3DPOOL Pool
, IDirect3DSurface9
**ppSurface
,
1057 HANDLE
*pSharedHandle
)
1059 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1062 TRACE("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p.\n",
1063 iface
, Width
, Height
, Format
, Pool
, ppSurface
, pSharedHandle
);
1065 if(Pool
== D3DPOOL_MANAGED
){
1066 FIXME("Attempting to create a managed offscreen plain surface\n");
1067 return D3DERR_INVALIDCALL
;
1070 'Off-screen plain surfaces are always lockable, regardless of their pool types.'
1072 D3DPOOL_DEFAULT is the appropriate pool for use with the IDirect3DDevice9::StretchRect and IDirect3DDevice9::ColorFill.
1073 Why, their always lockable?
1074 should I change the usage to dynamic?
1076 hr
= IDirect3DDevice9Impl_CreateSurface(This
, Width
, Height
, Format
, TRUE
/* Lockable */,
1077 FALSE
/* Discard */, 0 /* Level */, ppSurface
, 0 /* Usage (undefined/none) */,
1078 Pool
, D3DMULTISAMPLE_NONE
, 0 /* MultisampleQuality */);
1083 /* TODO: move to wineD3D */
1084 static HRESULT WINAPI
IDirect3DDevice9Impl_SetRenderTarget(IDirect3DDevice9Ex
*iface
,
1085 DWORD RenderTargetIndex
, IDirect3DSurface9
*pRenderTarget
)
1087 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1088 IDirect3DSurface9Impl
*pSurface
= unsafe_impl_from_IDirect3DSurface9(pRenderTarget
);
1091 TRACE("iface %p, idx %u, surface %p.\n", iface
, RenderTargetIndex
, pRenderTarget
);
1093 if (RenderTargetIndex
>= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS
)
1095 WARN("Invalid index %u specified.\n", RenderTargetIndex
);
1096 return D3DERR_INVALIDCALL
;
1099 wined3d_mutex_lock();
1100 hr
= wined3d_device_set_render_target(This
->wined3d_device
, RenderTargetIndex
,
1101 pSurface
? pSurface
->wined3d_surface
: NULL
, TRUE
);
1102 wined3d_mutex_unlock();
1107 static HRESULT WINAPI
IDirect3DDevice9Impl_GetRenderTarget(IDirect3DDevice9Ex
*iface
,
1108 DWORD RenderTargetIndex
, IDirect3DSurface9
**ppRenderTarget
)
1110 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1111 struct wined3d_surface
*wined3d_surface
;
1114 TRACE("iface %p, idx %u, surface %p.\n", iface
, RenderTargetIndex
, ppRenderTarget
);
1116 if (ppRenderTarget
== NULL
) {
1117 return D3DERR_INVALIDCALL
;
1120 if (RenderTargetIndex
>= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS
)
1122 WARN("Invalid index %u specified.\n", RenderTargetIndex
);
1123 return D3DERR_INVALIDCALL
;
1126 wined3d_mutex_lock();
1127 hr
= wined3d_device_get_render_target(This
->wined3d_device
, RenderTargetIndex
, &wined3d_surface
);
1130 *ppRenderTarget
= wined3d_surface_get_parent(wined3d_surface
);
1131 IDirect3DSurface9_AddRef(*ppRenderTarget
);
1132 wined3d_surface_decref(wined3d_surface
);
1136 if (hr
!= WINED3DERR_NOTFOUND
)
1137 WARN("Failed to get render target %u, hr %#x.\n", RenderTargetIndex
, hr
);
1138 *ppRenderTarget
= NULL
;
1140 wined3d_mutex_unlock();
1145 static HRESULT WINAPI
IDirect3DDevice9Impl_SetDepthStencilSurface(IDirect3DDevice9Ex
*iface
,
1146 IDirect3DSurface9
*pZStencilSurface
)
1148 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1149 IDirect3DSurface9Impl
*pSurface
= unsafe_impl_from_IDirect3DSurface9(pZStencilSurface
);
1152 TRACE("iface %p, depth_stencil %p.\n", iface
, pZStencilSurface
);
1154 wined3d_mutex_lock();
1155 hr
= wined3d_device_set_depth_stencil(This
->wined3d_device
, pSurface
? pSurface
->wined3d_surface
: NULL
);
1156 wined3d_mutex_unlock();
1161 static HRESULT WINAPI
IDirect3DDevice9Impl_GetDepthStencilSurface(IDirect3DDevice9Ex
*iface
,
1162 IDirect3DSurface9
**ppZStencilSurface
)
1164 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1165 struct wined3d_surface
*wined3d_surface
;
1168 TRACE("iface %p, depth_stencil %p.\n", iface
, ppZStencilSurface
);
1170 if(ppZStencilSurface
== NULL
){
1171 return D3DERR_INVALIDCALL
;
1174 wined3d_mutex_lock();
1175 hr
= wined3d_device_get_depth_stencil(This
->wined3d_device
, &wined3d_surface
);
1178 *ppZStencilSurface
= wined3d_surface_get_parent(wined3d_surface
);
1179 IDirect3DSurface9_AddRef(*ppZStencilSurface
);
1180 wined3d_surface_decref(wined3d_surface
);
1184 if (hr
!= WINED3DERR_NOTFOUND
)
1185 WARN("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr
);
1186 *ppZStencilSurface
= NULL
;
1188 wined3d_mutex_unlock();
1193 static HRESULT WINAPI
IDirect3DDevice9Impl_BeginScene(IDirect3DDevice9Ex
*iface
)
1195 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1198 TRACE("iface %p.\n", iface
);
1200 wined3d_mutex_lock();
1201 hr
= wined3d_device_begin_scene(This
->wined3d_device
);
1202 wined3d_mutex_unlock();
1207 static HRESULT WINAPI DECLSPEC_HOTPATCH
IDirect3DDevice9Impl_EndScene(IDirect3DDevice9Ex
*iface
)
1209 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1212 TRACE("iface %p.\n", iface
);
1214 wined3d_mutex_lock();
1215 hr
= wined3d_device_end_scene(This
->wined3d_device
);
1216 wined3d_mutex_unlock();
1221 static HRESULT WINAPI
IDirect3DDevice9Impl_Clear(IDirect3DDevice9Ex
*iface
, DWORD rect_count
,
1222 const D3DRECT
*rects
, DWORD flags
, D3DCOLOR color
, float z
, DWORD stencil
)
1224 const struct wined3d_color c
=
1226 ((color
>> 16) & 0xff) / 255.0f
,
1227 ((color
>> 8) & 0xff) / 255.0f
,
1228 (color
& 0xff) / 255.0f
,
1229 ((color
>> 24) & 0xff) / 255.0f
,
1231 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1234 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1235 iface
, rect_count
, rects
, flags
, color
, z
, stencil
);
1237 wined3d_mutex_lock();
1238 hr
= wined3d_device_clear(This
->wined3d_device
, rect_count
, (const RECT
*)rects
, flags
, &c
, z
, stencil
);
1239 wined3d_mutex_unlock();
1244 static HRESULT WINAPI
IDirect3DDevice9Impl_SetTransform(IDirect3DDevice9Ex
*iface
,
1245 D3DTRANSFORMSTATETYPE State
, const D3DMATRIX
*lpMatrix
)
1247 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1250 TRACE("iface %p, state %#x, matrix %p.\n", iface
, State
, lpMatrix
);
1252 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1253 wined3d_mutex_lock();
1254 hr
= wined3d_device_set_transform(This
->wined3d_device
, State
, (const struct wined3d_matrix
*)lpMatrix
);
1255 wined3d_mutex_unlock();
1260 static HRESULT WINAPI
IDirect3DDevice9Impl_GetTransform(IDirect3DDevice9Ex
*iface
,
1261 D3DTRANSFORMSTATETYPE State
, D3DMATRIX
*pMatrix
)
1263 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1266 TRACE("iface %p, state %#x, matrix %p.\n", iface
, State
, pMatrix
);
1268 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1269 wined3d_mutex_lock();
1270 hr
= wined3d_device_get_transform(This
->wined3d_device
, State
, (struct wined3d_matrix
*)pMatrix
);
1271 wined3d_mutex_unlock();
1276 static HRESULT WINAPI
IDirect3DDevice9Impl_MultiplyTransform(IDirect3DDevice9Ex
*iface
,
1277 D3DTRANSFORMSTATETYPE State
, const D3DMATRIX
*pMatrix
)
1279 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1282 TRACE("iface %p, state %#x, matrix %p.\n", iface
, State
, pMatrix
);
1284 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1285 wined3d_mutex_lock();
1286 hr
= wined3d_device_multiply_transform(This
->wined3d_device
, State
, (const struct wined3d_matrix
*)pMatrix
);
1287 wined3d_mutex_unlock();
1292 static HRESULT WINAPI
IDirect3DDevice9Impl_SetViewport(IDirect3DDevice9Ex
*iface
,
1293 const D3DVIEWPORT9
*pViewport
)
1295 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1298 TRACE("iface %p, viewport %p.\n", iface
, pViewport
);
1300 /* Note: D3DVIEWPORT9 is compatible with struct wined3d_viewport. */
1301 wined3d_mutex_lock();
1302 hr
= wined3d_device_set_viewport(This
->wined3d_device
, (const struct wined3d_viewport
*)pViewport
);
1303 wined3d_mutex_unlock();
1308 static HRESULT WINAPI
IDirect3DDevice9Impl_GetViewport(IDirect3DDevice9Ex
*iface
,
1309 D3DVIEWPORT9
*pViewport
)
1311 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1314 TRACE("iface %p, viewport %p.\n", iface
, pViewport
);
1316 /* Note: D3DVIEWPORT9 is compatible with struct wined3d_viewport. */
1317 wined3d_mutex_lock();
1318 hr
= wined3d_device_get_viewport(This
->wined3d_device
, (struct wined3d_viewport
*)pViewport
);
1319 wined3d_mutex_unlock();
1324 static HRESULT WINAPI
IDirect3DDevice9Impl_SetMaterial(IDirect3DDevice9Ex
*iface
,
1325 const D3DMATERIAL9
*pMaterial
)
1327 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1330 TRACE("iface %p, material %p.\n", iface
, pMaterial
);
1332 /* Note: D3DMATERIAL9 is compatible with struct wined3d_material. */
1333 wined3d_mutex_lock();
1334 hr
= wined3d_device_set_material(This
->wined3d_device
, (const struct wined3d_material
*)pMaterial
);
1335 wined3d_mutex_unlock();
1340 static HRESULT WINAPI
IDirect3DDevice9Impl_GetMaterial(IDirect3DDevice9Ex
*iface
,
1341 D3DMATERIAL9
*pMaterial
)
1343 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1346 TRACE("iface %p, material %p.\n", iface
, pMaterial
);
1348 /* Note: D3DMATERIAL9 is compatible with struct wined3d_material. */
1349 wined3d_mutex_lock();
1350 hr
= wined3d_device_get_material(This
->wined3d_device
, (struct wined3d_material
*)pMaterial
);
1351 wined3d_mutex_unlock();
1356 static HRESULT WINAPI
IDirect3DDevice9Impl_SetLight(IDirect3DDevice9Ex
*iface
, DWORD Index
,
1357 const D3DLIGHT9
*pLight
)
1359 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1362 TRACE("iface %p, index %u, light %p.\n", iface
, Index
, pLight
);
1364 /* Note: D3DLIGHT9 is compatible with struct wined3d_light. */
1365 wined3d_mutex_lock();
1366 hr
= wined3d_device_set_light(This
->wined3d_device
, Index
, (const struct wined3d_light
*)pLight
);
1367 wined3d_mutex_unlock();
1372 static HRESULT WINAPI
IDirect3DDevice9Impl_GetLight(IDirect3DDevice9Ex
*iface
, DWORD Index
,
1375 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1378 TRACE("iface %p, index %u, light %p.\n", iface
, Index
, pLight
);
1380 /* Note: D3DLIGHT9 is compatible with struct wined3d_light. */
1381 wined3d_mutex_lock();
1382 hr
= wined3d_device_get_light(This
->wined3d_device
, Index
, (struct wined3d_light
*)pLight
);
1383 wined3d_mutex_unlock();
1388 static HRESULT WINAPI
IDirect3DDevice9Impl_LightEnable(IDirect3DDevice9Ex
*iface
, DWORD Index
,
1391 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1394 TRACE("iface %p, index %u, enable %#x.\n", iface
, Index
, Enable
);
1396 wined3d_mutex_lock();
1397 hr
= wined3d_device_set_light_enable(This
->wined3d_device
, Index
, Enable
);
1398 wined3d_mutex_unlock();
1403 static HRESULT WINAPI
IDirect3DDevice9Impl_GetLightEnable(IDirect3DDevice9Ex
*iface
, DWORD Index
,
1406 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1409 TRACE("iface %p, index %u, enable %p.\n", iface
, Index
, pEnable
);
1411 wined3d_mutex_lock();
1412 hr
= wined3d_device_get_light_enable(This
->wined3d_device
, Index
, pEnable
);
1413 wined3d_mutex_unlock();
1418 static HRESULT WINAPI
IDirect3DDevice9Impl_SetClipPlane(IDirect3DDevice9Ex
*iface
, DWORD Index
,
1419 const float *pPlane
)
1421 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1424 TRACE("iface %p, index %u, plane %p.\n", iface
, Index
, pPlane
);
1426 wined3d_mutex_lock();
1427 hr
= wined3d_device_set_clip_plane(This
->wined3d_device
, Index
, pPlane
);
1428 wined3d_mutex_unlock();
1433 static HRESULT WINAPI
IDirect3DDevice9Impl_GetClipPlane(IDirect3DDevice9Ex
*iface
, DWORD Index
,
1436 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1439 TRACE("iface %p, index %u, plane %p.\n", iface
, Index
, pPlane
);
1441 wined3d_mutex_lock();
1442 hr
= wined3d_device_get_clip_plane(This
->wined3d_device
, Index
, pPlane
);
1443 wined3d_mutex_unlock();
1448 static HRESULT WINAPI DECLSPEC_HOTPATCH
IDirect3DDevice9Impl_SetRenderState(IDirect3DDevice9Ex
*iface
,
1449 D3DRENDERSTATETYPE State
, DWORD Value
)
1451 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1454 TRACE("iface %p, state %#x, value %#x.\n", iface
, State
, Value
);
1456 wined3d_mutex_lock();
1457 hr
= wined3d_device_set_render_state(This
->wined3d_device
, State
, Value
);
1458 wined3d_mutex_unlock();
1463 static HRESULT WINAPI
IDirect3DDevice9Impl_GetRenderState(IDirect3DDevice9Ex
*iface
,
1464 D3DRENDERSTATETYPE State
, DWORD
*pValue
)
1466 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1469 TRACE("iface %p, state %#x, value %p.\n", iface
, State
, pValue
);
1471 wined3d_mutex_lock();
1472 hr
= wined3d_device_get_render_state(This
->wined3d_device
, State
, pValue
);
1473 wined3d_mutex_unlock();
1478 static HRESULT WINAPI
IDirect3DDevice9Impl_CreateStateBlock(IDirect3DDevice9Ex
*iface
,
1479 D3DSTATEBLOCKTYPE type
, IDirect3DStateBlock9
**stateblock
)
1481 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1482 IDirect3DStateBlock9Impl
*object
;
1485 TRACE("iface %p, type %#x, stateblock %p.\n", iface
, type
, stateblock
);
1487 if (type
!= D3DSBT_ALL
&& type
!= D3DSBT_PIXELSTATE
&& type
!= D3DSBT_VERTEXSTATE
)
1489 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL.\n");
1490 return D3DERR_INVALIDCALL
;
1493 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1496 ERR("Failed to allocate stateblock memory.\n");
1497 return E_OUTOFMEMORY
;
1500 hr
= stateblock_init(object
, This
, type
, NULL
);
1503 WARN("Failed to initialize stateblock, hr %#x.\n", hr
);
1504 HeapFree(GetProcessHeap(), 0, object
);
1508 TRACE("Created stateblock %p.\n", object
);
1509 *stateblock
= &object
->IDirect3DStateBlock9_iface
;
1514 static HRESULT WINAPI
IDirect3DDevice9Impl_BeginStateBlock(IDirect3DDevice9Ex
*iface
)
1516 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1519 TRACE("iface %p.\n", iface
);
1521 wined3d_mutex_lock();
1522 hr
= wined3d_device_begin_stateblock(This
->wined3d_device
);
1523 wined3d_mutex_unlock();
1528 static HRESULT WINAPI
IDirect3DDevice9Impl_EndStateBlock(IDirect3DDevice9Ex
*iface
,
1529 IDirect3DStateBlock9
**stateblock
)
1531 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1532 struct wined3d_stateblock
*wined3d_stateblock
;
1533 IDirect3DStateBlock9Impl
*object
;
1536 TRACE("iface %p, stateblock %p.\n", iface
, stateblock
);
1538 wined3d_mutex_lock();
1539 hr
= wined3d_device_end_stateblock(This
->wined3d_device
, &wined3d_stateblock
);
1540 wined3d_mutex_unlock();
1543 WARN("IWineD3DDevice_EndStateBlock() failed, hr %#x.\n", hr
);
1547 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1550 ERR("Failed to allocate stateblock memory.\n");
1551 wined3d_mutex_lock();
1552 wined3d_stateblock_decref(wined3d_stateblock
);
1553 wined3d_mutex_unlock();
1554 return E_OUTOFMEMORY
;
1557 hr
= stateblock_init(object
, This
, 0, wined3d_stateblock
);
1560 WARN("Failed to initialize stateblock, hr %#x.\n", hr
);
1561 wined3d_mutex_lock();
1562 wined3d_stateblock_decref(wined3d_stateblock
);
1563 wined3d_mutex_unlock();
1564 HeapFree(GetProcessHeap(), 0, object
);
1568 TRACE("Created stateblock %p.\n", object
);
1569 *stateblock
= &object
->IDirect3DStateBlock9_iface
;
1574 static HRESULT WINAPI
IDirect3DDevice9Impl_SetClipStatus(IDirect3DDevice9Ex
*iface
,
1575 const D3DCLIPSTATUS9
*pClipStatus
)
1577 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1580 TRACE("iface %p, clip_status %p.\n", iface
, pClipStatus
);
1582 wined3d_mutex_lock();
1583 hr
= wined3d_device_set_clip_status(This
->wined3d_device
, (const struct wined3d_clip_status
*)pClipStatus
);
1584 wined3d_mutex_unlock();
1589 static HRESULT WINAPI
IDirect3DDevice9Impl_GetClipStatus(IDirect3DDevice9Ex
*iface
,
1590 D3DCLIPSTATUS9
*pClipStatus
)
1592 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1595 TRACE("iface %p, clip_status %p.\n", iface
, pClipStatus
);
1597 wined3d_mutex_lock();
1598 hr
= wined3d_device_get_clip_status(This
->wined3d_device
, (struct wined3d_clip_status
*)pClipStatus
);
1599 wined3d_mutex_unlock();
1604 static HRESULT WINAPI
IDirect3DDevice9Impl_GetTexture(IDirect3DDevice9Ex
*iface
, DWORD Stage
,
1605 IDirect3DBaseTexture9
**ppTexture
)
1607 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1608 struct wined3d_texture
*wined3d_texture
= NULL
;
1611 TRACE("iface %p, stage %u, texture %p.\n", iface
, Stage
, ppTexture
);
1613 if(ppTexture
== NULL
){
1614 return D3DERR_INVALIDCALL
;
1617 wined3d_mutex_lock();
1618 hr
= wined3d_device_get_texture(This
->wined3d_device
, Stage
, &wined3d_texture
);
1619 if (SUCCEEDED(hr
) && wined3d_texture
)
1621 *ppTexture
= wined3d_texture_get_parent(wined3d_texture
);
1622 IDirect3DBaseTexture9_AddRef(*ppTexture
);
1623 wined3d_texture_decref(wined3d_texture
);
1629 WARN("Call to get texture (%u) failed (%p).\n", Stage
, wined3d_texture
);
1633 wined3d_mutex_unlock();
1638 static HRESULT WINAPI
IDirect3DDevice9Impl_SetTexture(IDirect3DDevice9Ex
*iface
, DWORD stage
,
1639 IDirect3DBaseTexture9
*texture
)
1641 IDirect3DDevice9Impl
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1644 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
1646 wined3d_mutex_lock();
1647 hr
= wined3d_device_set_texture(device
->wined3d_device
, stage
,
1648 texture
? ((IDirect3DBaseTexture9Impl
*)texture
)->wined3d_texture
: NULL
);
1649 wined3d_mutex_unlock();
1654 static const WINED3DTEXTURESTAGESTATETYPE tss_lookup
[] =
1656 WINED3DTSS_FORCE_DWORD
, /* 0, unused */
1657 WINED3DTSS_COLOROP
, /* 1, D3DTSS_COLOROP */
1658 WINED3DTSS_COLORARG1
, /* 2, D3DTSS_COLORARG1 */
1659 WINED3DTSS_COLORARG2
, /* 3, D3DTSS_COLORARG2 */
1660 WINED3DTSS_ALPHAOP
, /* 4, D3DTSS_ALPHAOP */
1661 WINED3DTSS_ALPHAARG1
, /* 5, D3DTSS_ALPHAARG1 */
1662 WINED3DTSS_ALPHAARG2
, /* 6, D3DTSS_ALPHAARG2 */
1663 WINED3DTSS_BUMPENVMAT00
, /* 7, D3DTSS_BUMPENVMAT00 */
1664 WINED3DTSS_BUMPENVMAT01
, /* 8, D3DTSS_BUMPENVMAT01 */
1665 WINED3DTSS_BUMPENVMAT10
, /* 9, D3DTSS_BUMPENVMAT10 */
1666 WINED3DTSS_BUMPENVMAT11
, /* 10, D3DTSS_BUMPENVMAT11 */
1667 WINED3DTSS_TEXCOORDINDEX
, /* 11, D3DTSS_TEXCOORDINDEX */
1668 WINED3DTSS_FORCE_DWORD
, /* 12, unused */
1669 WINED3DTSS_FORCE_DWORD
, /* 13, unused */
1670 WINED3DTSS_FORCE_DWORD
, /* 14, unused */
1671 WINED3DTSS_FORCE_DWORD
, /* 15, unused */
1672 WINED3DTSS_FORCE_DWORD
, /* 16, unused */
1673 WINED3DTSS_FORCE_DWORD
, /* 17, unused */
1674 WINED3DTSS_FORCE_DWORD
, /* 18, unused */
1675 WINED3DTSS_FORCE_DWORD
, /* 19, unused */
1676 WINED3DTSS_FORCE_DWORD
, /* 20, unused */
1677 WINED3DTSS_FORCE_DWORD
, /* 21, unused */
1678 WINED3DTSS_BUMPENVLSCALE
, /* 22, D3DTSS_BUMPENVLSCALE */
1679 WINED3DTSS_BUMPENVLOFFSET
, /* 23, D3DTSS_BUMPENVLOFFSET */
1680 WINED3DTSS_TEXTURETRANSFORMFLAGS
, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1681 WINED3DTSS_FORCE_DWORD
, /* 25, unused */
1682 WINED3DTSS_COLORARG0
, /* 26, D3DTSS_COLORARG0 */
1683 WINED3DTSS_ALPHAARG0
, /* 27, D3DTSS_ALPHAARG0 */
1684 WINED3DTSS_RESULTARG
, /* 28, D3DTSS_RESULTARG */
1685 WINED3DTSS_FORCE_DWORD
, /* 29, unused */
1686 WINED3DTSS_FORCE_DWORD
, /* 30, unused */
1687 WINED3DTSS_FORCE_DWORD
, /* 31, unused */
1688 WINED3DTSS_CONSTANT
, /* 32, D3DTSS_CONSTANT */
1691 static HRESULT WINAPI
IDirect3DDevice9Impl_GetTextureStageState(IDirect3DDevice9Ex
*iface
,
1692 DWORD Stage
, D3DTEXTURESTAGESTATETYPE Type
, DWORD
*pValue
)
1694 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1697 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface
, Stage
, Type
, pValue
);
1699 if (Type
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
1701 WARN("Invalid Type %#x passed.\n", Type
);
1705 wined3d_mutex_lock();
1706 hr
= wined3d_device_get_texture_stage_state(This
->wined3d_device
, Stage
, tss_lookup
[Type
], pValue
);
1707 wined3d_mutex_unlock();
1712 static HRESULT WINAPI
IDirect3DDevice9Impl_SetTextureStageState(IDirect3DDevice9Ex
*iface
,
1713 DWORD Stage
, D3DTEXTURESTAGESTATETYPE Type
, DWORD Value
)
1715 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1718 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface
, Stage
, Type
, Value
);
1720 if (Type
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
1722 WARN("Invalid Type %#x passed.\n", Type
);
1726 wined3d_mutex_lock();
1727 hr
= wined3d_device_set_texture_stage_state(This
->wined3d_device
, Stage
, tss_lookup
[Type
], Value
);
1728 wined3d_mutex_unlock();
1733 static HRESULT WINAPI
IDirect3DDevice9Impl_GetSamplerState(IDirect3DDevice9Ex
*iface
, DWORD Sampler
,
1734 D3DSAMPLERSTATETYPE Type
, DWORD
*pValue
)
1736 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1739 TRACE("iface %p, sampler %u, state %#x, value %p.\n", iface
, Sampler
, Type
, pValue
);
1741 wined3d_mutex_lock();
1742 hr
= wined3d_device_get_sampler_state(This
->wined3d_device
, Sampler
, Type
, pValue
);
1743 wined3d_mutex_unlock();
1748 static HRESULT WINAPI DECLSPEC_HOTPATCH
IDirect3DDevice9Impl_SetSamplerState(IDirect3DDevice9Ex
*iface
,
1749 DWORD Sampler
, D3DSAMPLERSTATETYPE Type
, DWORD Value
)
1751 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1754 TRACE("iface %p, sampler %u, state %#x, value %#x.\n", iface
, Sampler
, Type
, Value
);
1756 wined3d_mutex_lock();
1757 hr
= wined3d_device_set_sampler_state(This
->wined3d_device
, Sampler
, Type
, Value
);
1758 wined3d_mutex_unlock();
1763 static HRESULT WINAPI
IDirect3DDevice9Impl_ValidateDevice(IDirect3DDevice9Ex
*iface
,
1766 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1769 TRACE("iface %p, pass_count %p.\n", iface
, pNumPasses
);
1771 wined3d_mutex_lock();
1772 hr
= wined3d_device_validate_device(This
->wined3d_device
, pNumPasses
);
1773 wined3d_mutex_unlock();
1778 static HRESULT WINAPI
IDirect3DDevice9Impl_SetPaletteEntries(IDirect3DDevice9Ex
*iface
,
1779 UINT PaletteNumber
, const PALETTEENTRY
*pEntries
)
1781 FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface
, PaletteNumber
, pEntries
);
1783 return D3DERR_INVALIDCALL
;
1786 static HRESULT WINAPI
IDirect3DDevice9Impl_GetPaletteEntries(IDirect3DDevice9Ex
*iface
,
1787 UINT PaletteNumber
, PALETTEENTRY
*pEntries
)
1789 FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface
, PaletteNumber
, pEntries
);
1791 return D3DERR_INVALIDCALL
;
1794 static HRESULT WINAPI
IDirect3DDevice9Impl_SetCurrentTexturePalette(IDirect3DDevice9Ex
*iface
,
1797 FIXME("iface %p, palette_idx %u unimplemented.\n", iface
, PaletteNumber
);
1799 return D3DERR_INVALIDCALL
;
1802 static HRESULT WINAPI
IDirect3DDevice9Impl_GetCurrentTexturePalette(IDirect3DDevice9Ex
*iface
,
1803 UINT
*PaletteNumber
)
1805 FIXME("iface %p, palette_idx %p.\n", iface
, PaletteNumber
);
1807 return D3DERR_INVALIDCALL
;
1810 static HRESULT WINAPI
IDirect3DDevice9Impl_SetScissorRect(IDirect3DDevice9Ex
*iface
,
1813 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1816 TRACE("iface %p, rect %p.\n", iface
, pRect
);
1818 wined3d_mutex_lock();
1819 hr
= wined3d_device_set_scissor_rect(This
->wined3d_device
, pRect
);
1820 wined3d_mutex_unlock();
1825 static HRESULT WINAPI
IDirect3DDevice9Impl_GetScissorRect(IDirect3DDevice9Ex
*iface
, RECT
*pRect
)
1827 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1830 TRACE("iface %p, rect %p.\n", iface
, pRect
);
1832 wined3d_mutex_lock();
1833 hr
= wined3d_device_get_scissor_rect(This
->wined3d_device
, pRect
);
1834 wined3d_mutex_unlock();
1839 static HRESULT WINAPI
IDirect3DDevice9Impl_SetSoftwareVertexProcessing(IDirect3DDevice9Ex
*iface
,
1842 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1845 TRACE("iface %p, software %#x.\n", iface
, bSoftware
);
1847 wined3d_mutex_lock();
1848 hr
= wined3d_device_set_software_vertex_processing(This
->wined3d_device
, bSoftware
);
1849 wined3d_mutex_unlock();
1854 static BOOL WINAPI
IDirect3DDevice9Impl_GetSoftwareVertexProcessing(IDirect3DDevice9Ex
*iface
)
1856 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1859 TRACE("iface %p.\n", iface
);
1861 wined3d_mutex_lock();
1862 ret
= wined3d_device_get_software_vertex_processing(This
->wined3d_device
);
1863 wined3d_mutex_unlock();
1868 static HRESULT WINAPI
IDirect3DDevice9Impl_SetNPatchMode(IDirect3DDevice9Ex
*iface
, float nSegments
)
1870 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1873 TRACE("iface %p, segment_count %.8e.\n", iface
, nSegments
);
1875 wined3d_mutex_lock();
1876 hr
= wined3d_device_set_npatch_mode(This
->wined3d_device
, nSegments
);
1877 wined3d_mutex_unlock();
1882 static float WINAPI
IDirect3DDevice9Impl_GetNPatchMode(IDirect3DDevice9Ex
*iface
)
1884 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1887 TRACE("iface %p.\n", iface
);
1889 wined3d_mutex_lock();
1890 ret
= wined3d_device_get_npatch_mode(This
->wined3d_device
);
1891 wined3d_mutex_unlock();
1896 static HRESULT WINAPI
IDirect3DDevice9Impl_DrawPrimitive(IDirect3DDevice9Ex
*iface
,
1897 D3DPRIMITIVETYPE PrimitiveType
, UINT StartVertex
, UINT PrimitiveCount
)
1899 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1902 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1903 iface
, PrimitiveType
, StartVertex
, PrimitiveCount
);
1905 wined3d_mutex_lock();
1906 wined3d_device_set_primitive_type(This
->wined3d_device
, PrimitiveType
);
1907 hr
= wined3d_device_draw_primitive(This
->wined3d_device
, StartVertex
,
1908 vertex_count_from_primitive_count(PrimitiveType
, PrimitiveCount
));
1909 wined3d_mutex_unlock();
1914 static HRESULT WINAPI
IDirect3DDevice9Impl_DrawIndexedPrimitive(IDirect3DDevice9Ex
*iface
,
1915 D3DPRIMITIVETYPE PrimitiveType
, INT BaseVertexIndex
, UINT MinVertexIndex
, UINT NumVertices
,
1916 UINT startIndex
, UINT primCount
)
1918 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1921 TRACE("iface %p, primitive_type %#x, base_vertex_idx %u, min_vertex_idx %u,\n"
1922 "vertex_count %u, start_idx %u, primitive_count %u.\n",
1923 iface
, PrimitiveType
, BaseVertexIndex
, MinVertexIndex
,
1924 NumVertices
, startIndex
, primCount
);
1926 wined3d_mutex_lock();
1927 wined3d_device_set_base_vertex_index(This
->wined3d_device
, BaseVertexIndex
);
1928 wined3d_device_set_primitive_type(This
->wined3d_device
, PrimitiveType
);
1929 hr
= wined3d_device_draw_indexed_primitive(This
->wined3d_device
, startIndex
,
1930 vertex_count_from_primitive_count(PrimitiveType
, primCount
));
1931 wined3d_mutex_unlock();
1936 static HRESULT WINAPI
IDirect3DDevice9Impl_DrawPrimitiveUP(IDirect3DDevice9Ex
*iface
,
1937 D3DPRIMITIVETYPE PrimitiveType
, UINT PrimitiveCount
, const void *pVertexStreamZeroData
,
1938 UINT VertexStreamZeroStride
)
1940 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1943 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
1944 iface
, PrimitiveType
, PrimitiveCount
, pVertexStreamZeroData
, VertexStreamZeroStride
);
1946 wined3d_mutex_lock();
1947 wined3d_device_set_primitive_type(This
->wined3d_device
, PrimitiveType
);
1948 hr
= wined3d_device_draw_primitive_up(This
->wined3d_device
,
1949 vertex_count_from_primitive_count(PrimitiveType
, PrimitiveCount
),
1950 pVertexStreamZeroData
, VertexStreamZeroStride
);
1951 wined3d_mutex_unlock();
1956 static HRESULT WINAPI
IDirect3DDevice9Impl_DrawIndexedPrimitiveUP(IDirect3DDevice9Ex
*iface
,
1957 D3DPRIMITIVETYPE PrimitiveType
, UINT MinVertexIndex
, UINT NumVertexIndices
,
1958 UINT PrimitiveCount
, const void *pIndexData
, D3DFORMAT IndexDataFormat
,
1959 const void *pVertexStreamZeroData
, UINT VertexStreamZeroStride
)
1961 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1964 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
1965 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
1966 iface
, PrimitiveType
, MinVertexIndex
, NumVertexIndices
, PrimitiveCount
,
1967 pIndexData
, IndexDataFormat
, pVertexStreamZeroData
, VertexStreamZeroStride
);
1969 wined3d_mutex_lock();
1970 wined3d_device_set_primitive_type(This
->wined3d_device
, PrimitiveType
);
1971 hr
= wined3d_device_draw_indexed_primitive_up(This
->wined3d_device
,
1972 vertex_count_from_primitive_count(PrimitiveType
, PrimitiveCount
), pIndexData
,
1973 wined3dformat_from_d3dformat(IndexDataFormat
), pVertexStreamZeroData
, VertexStreamZeroStride
);
1974 wined3d_mutex_unlock();
1979 static HRESULT WINAPI
IDirect3DDevice9Impl_ProcessVertices(IDirect3DDevice9Ex
*iface
,
1980 UINT SrcStartIndex
, UINT DestIndex
, UINT VertexCount
, IDirect3DVertexBuffer9
*pDestBuffer
,
1981 IDirect3DVertexDeclaration9
*pVertexDecl
, DWORD Flags
)
1983 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
1984 IDirect3DVertexBuffer9Impl
*dest
= unsafe_impl_from_IDirect3DVertexBuffer9(pDestBuffer
);
1985 IDirect3DVertexDeclaration9Impl
*Decl
= (IDirect3DVertexDeclaration9Impl
*) pVertexDecl
;
1988 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, declaration %p, flags %#x.\n",
1989 iface
, SrcStartIndex
, DestIndex
, VertexCount
, pDestBuffer
, pVertexDecl
, Flags
);
1991 wined3d_mutex_lock();
1992 hr
= wined3d_device_process_vertices(This
->wined3d_device
, SrcStartIndex
, DestIndex
, VertexCount
,
1993 dest
->wineD3DVertexBuffer
, Decl
? Decl
->wineD3DVertexDeclaration
: NULL
, Flags
, dest
->fvf
);
1994 wined3d_mutex_unlock();
1999 static HRESULT WINAPI
IDirect3DDevice9Impl_CreateVertexDeclaration(IDirect3DDevice9Ex
*iface
,
2000 const D3DVERTEXELEMENT9
*elements
, IDirect3DVertexDeclaration9
**declaration
)
2002 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2003 IDirect3DVertexDeclaration9Impl
*object
;
2006 TRACE("iface %p, elements %p, declaration %p.\n", iface
, elements
, declaration
);
2010 WARN("Caller passed a NULL declaration, returning D3DERR_INVALIDCALL.\n");
2011 return D3DERR_INVALIDCALL
;
2014 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2017 ERR("Failed to allocate vertex declaration memory.\n");
2018 return E_OUTOFMEMORY
;
2021 hr
= vertexdeclaration_init(object
, This
, elements
);
2024 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr
);
2025 HeapFree(GetProcessHeap(), 0, object
);
2029 TRACE("Created vertex declaration %p.\n", object
);
2030 *declaration
= (IDirect3DVertexDeclaration9
*)object
;
2035 static HRESULT WINAPI
IDirect3DDevice9Impl_SetVertexDeclaration(IDirect3DDevice9Ex
*iface
,
2036 IDirect3DVertexDeclaration9
*declaration
)
2038 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2041 TRACE("iface %p, declaration %p.\n", iface
, declaration
);
2043 wined3d_mutex_lock();
2044 hr
= wined3d_device_set_vertex_declaration(This
->wined3d_device
,
2045 declaration
? ((IDirect3DVertexDeclaration9Impl
*)declaration
)->wineD3DVertexDeclaration
: NULL
);
2046 wined3d_mutex_unlock();
2051 static HRESULT WINAPI
IDirect3DDevice9Impl_GetVertexDeclaration(IDirect3DDevice9Ex
*iface
,
2052 IDirect3DVertexDeclaration9
**declaration
)
2054 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2055 struct wined3d_vertex_declaration
*wined3d_declaration
= NULL
;
2058 TRACE("iface %p, declaration %p.\n", iface
, declaration
);
2060 if (!declaration
) return D3DERR_INVALIDCALL
;
2062 wined3d_mutex_lock();
2063 hr
= wined3d_device_get_vertex_declaration(This
->wined3d_device
, &wined3d_declaration
);
2064 if (SUCCEEDED(hr
) && wined3d_declaration
)
2066 *declaration
= wined3d_vertex_declaration_get_parent(wined3d_declaration
);
2067 IDirect3DVertexDeclaration9_AddRef(*declaration
);
2068 wined3d_vertex_declaration_decref(wined3d_declaration
);
2072 *declaration
= NULL
;
2074 wined3d_mutex_unlock();
2076 TRACE("Returning %p.\n", *declaration
);
2080 static IDirect3DVertexDeclaration9
*getConvertedDecl(IDirect3DDevice9Impl
*This
, DWORD fvf
) {
2082 D3DVERTEXELEMENT9
* elements
= NULL
;
2083 IDirect3DVertexDeclaration9
* pDecl
= NULL
;
2084 int p
, low
, high
; /* deliberately signed */
2085 IDirect3DVertexDeclaration9
**convertedDecls
= This
->convertedDecls
;
2087 TRACE("Searching for declaration for fvf %08x... ", fvf
);
2090 high
= This
->numConvertedDecls
- 1;
2091 while(low
<= high
) {
2092 p
= (low
+ high
) >> 1;
2094 if(((IDirect3DVertexDeclaration9Impl
*) convertedDecls
[p
])->convFVF
== fvf
) {
2095 TRACE("found %p\n", convertedDecls
[p
]);
2096 return convertedDecls
[p
];
2097 } else if(((IDirect3DVertexDeclaration9Impl
*) convertedDecls
[p
])->convFVF
< fvf
) {
2103 TRACE("not found. Creating and inserting at position %d.\n", low
);
2105 hr
= vdecl_convert_fvf(fvf
, &elements
);
2106 if (hr
!= S_OK
) return NULL
;
2108 hr
= IDirect3DDevice9Impl_CreateVertexDeclaration(&This
->IDirect3DDevice9Ex_iface
, elements
,
2110 HeapFree(GetProcessHeap(), 0, elements
); /* CreateVertexDeclaration makes a copy */
2111 if (hr
!= S_OK
) return NULL
;
2113 if(This
->declArraySize
== This
->numConvertedDecls
) {
2114 int grow
= max(This
->declArraySize
/ 2, 8);
2115 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
2116 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
2117 if(!convertedDecls
) {
2118 /* This will destroy it */
2119 IDirect3DVertexDeclaration9_Release(pDecl
);
2122 This
->convertedDecls
= convertedDecls
;
2123 This
->declArraySize
+= grow
;
2126 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(IDirect3DVertexDeclaration9Impl
*) * (This
->numConvertedDecls
- low
));
2127 convertedDecls
[low
] = pDecl
;
2128 This
->numConvertedDecls
++;
2130 /* Will prevent the decl from being destroyed */
2131 ((IDirect3DVertexDeclaration9Impl
*) pDecl
)->convFVF
= fvf
;
2132 IDirect3DVertexDeclaration9_Release(pDecl
); /* Does not destroy now */
2134 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);
2138 static HRESULT WINAPI
IDirect3DDevice9Impl_SetFVF(IDirect3DDevice9Ex
*iface
, DWORD FVF
)
2140 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2141 IDirect3DVertexDeclaration9
*decl
;
2144 TRACE("iface %p, fvf %#x.\n", iface
, FVF
);
2148 WARN("%#x is not a valid FVF\n", FVF
);
2152 wined3d_mutex_lock();
2153 decl
= getConvertedDecl(This
, FVF
);
2154 wined3d_mutex_unlock();
2158 /* Any situation when this should happen, except out of memory? */
2159 ERR("Failed to create a converted vertex declaration\n");
2160 return D3DERR_DRIVERINTERNALERROR
;
2163 hr
= IDirect3DDevice9Impl_SetVertexDeclaration(iface
, decl
);
2164 if (FAILED(hr
)) ERR("Failed to set vertex declaration\n");
2169 static HRESULT WINAPI
IDirect3DDevice9Impl_GetFVF(IDirect3DDevice9Ex
*iface
, DWORD
*pFVF
)
2171 IDirect3DVertexDeclaration9
*decl
;
2174 TRACE("iface %p, fvf %p.\n", iface
, pFVF
);
2176 hr
= IDirect3DDevice9_GetVertexDeclaration(iface
, &decl
);
2179 WARN("Failed to get vertex declaration, %#x\n", hr
);
2186 *pFVF
= ((IDirect3DVertexDeclaration9Impl
*)decl
)->convFVF
;
2187 IDirect3DVertexDeclaration9_Release(decl
);
2194 TRACE("Returning FVF %#x\n", *pFVF
);
2199 static HRESULT WINAPI
IDirect3DDevice9Impl_CreateVertexShader(IDirect3DDevice9Ex
*iface
,
2200 const DWORD
*byte_code
, IDirect3DVertexShader9
**shader
)
2202 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2203 IDirect3DVertexShader9Impl
*object
;
2206 TRACE("iface %p, byte_code %p, shader %p.\n", iface
, byte_code
, shader
);
2208 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2211 ERR("Failed to allocate vertex shader memory.\n");
2212 return E_OUTOFMEMORY
;
2215 hr
= vertexshader_init(object
, This
, byte_code
);
2218 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
2219 HeapFree(GetProcessHeap(), 0, object
);
2223 TRACE("Created vertex shader %p.\n", object
);
2224 *shader
= &object
->IDirect3DVertexShader9_iface
;
2229 static HRESULT WINAPI
IDirect3DDevice9Impl_SetVertexShader(IDirect3DDevice9Ex
*iface
,
2230 IDirect3DVertexShader9
*shader
)
2232 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2233 IDirect3DVertexShader9Impl
*shader_obj
= unsafe_impl_from_IDirect3DVertexShader9(shader
);
2236 TRACE("iface %p, shader %p.\n", iface
, shader
);
2238 wined3d_mutex_lock();
2239 hr
= wined3d_device_set_vertex_shader(This
->wined3d_device
,
2240 shader_obj
? shader_obj
->wined3d_shader
: NULL
);
2241 wined3d_mutex_unlock();
2246 static HRESULT WINAPI
IDirect3DDevice9Impl_GetVertexShader(IDirect3DDevice9Ex
*iface
,
2247 IDirect3DVertexShader9
**shader
)
2249 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2250 struct wined3d_shader
*wined3d_shader
;
2252 TRACE("iface %p, shader %p.\n", iface
, shader
);
2254 wined3d_mutex_lock();
2255 wined3d_shader
= wined3d_device_get_vertex_shader(This
->wined3d_device
);
2258 *shader
= wined3d_shader_get_parent(wined3d_shader
);
2259 IDirect3DVertexShader9_AddRef(*shader
);
2260 wined3d_shader_decref(wined3d_shader
);
2266 wined3d_mutex_unlock();
2268 TRACE("Returning %p.\n", *shader
);
2273 static HRESULT WINAPI
IDirect3DDevice9Impl_SetVertexShaderConstantF(IDirect3DDevice9Ex
*iface
,
2274 UINT reg_idx
, const float *data
, UINT count
)
2276 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2279 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2281 if (reg_idx
+ count
> D3D9_MAX_VERTEX_SHADER_CONSTANTF
)
2283 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
2284 reg_idx
+ count
, D3D9_MAX_VERTEX_SHADER_CONSTANTF
);
2285 return D3DERR_INVALIDCALL
;
2288 wined3d_mutex_lock();
2289 hr
= wined3d_device_set_vs_consts_f(This
->wined3d_device
, reg_idx
, data
, count
);
2290 wined3d_mutex_unlock();
2295 static HRESULT WINAPI
IDirect3DDevice9Impl_GetVertexShaderConstantF(IDirect3DDevice9Ex
*iface
,
2296 UINT reg_idx
, float *data
, UINT count
)
2298 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2301 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2303 if (reg_idx
+ count
> D3D9_MAX_VERTEX_SHADER_CONSTANTF
)
2305 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
2306 reg_idx
+ count
, D3D9_MAX_VERTEX_SHADER_CONSTANTF
);
2307 return D3DERR_INVALIDCALL
;
2310 wined3d_mutex_lock();
2311 hr
= wined3d_device_get_vs_consts_f(This
->wined3d_device
, reg_idx
, data
, count
);
2312 wined3d_mutex_unlock();
2317 static HRESULT WINAPI
IDirect3DDevice9Impl_SetVertexShaderConstantI(IDirect3DDevice9Ex
*iface
,
2318 UINT reg_idx
, const int *data
, UINT count
)
2320 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2323 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2325 wined3d_mutex_lock();
2326 hr
= wined3d_device_set_vs_consts_i(This
->wined3d_device
, reg_idx
, data
, count
);
2327 wined3d_mutex_unlock();
2332 static HRESULT WINAPI
IDirect3DDevice9Impl_GetVertexShaderConstantI(IDirect3DDevice9Ex
*iface
,
2333 UINT reg_idx
, int *data
, UINT count
)
2335 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2338 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2340 wined3d_mutex_lock();
2341 hr
= wined3d_device_get_vs_consts_i(This
->wined3d_device
, reg_idx
, data
, count
);
2342 wined3d_mutex_unlock();
2347 static HRESULT WINAPI
IDirect3DDevice9Impl_SetVertexShaderConstantB(IDirect3DDevice9Ex
*iface
,
2348 UINT reg_idx
, const BOOL
*data
, UINT count
)
2350 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2353 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2355 wined3d_mutex_lock();
2356 hr
= wined3d_device_set_vs_consts_b(This
->wined3d_device
, reg_idx
, data
, count
);
2357 wined3d_mutex_unlock();
2362 static HRESULT WINAPI
IDirect3DDevice9Impl_GetVertexShaderConstantB(IDirect3DDevice9Ex
*iface
,
2363 UINT reg_idx
, BOOL
*data
, UINT count
)
2365 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2368 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2370 wined3d_mutex_lock();
2371 hr
= wined3d_device_get_vs_consts_b(This
->wined3d_device
, reg_idx
, data
, count
);
2372 wined3d_mutex_unlock();
2377 static HRESULT WINAPI
IDirect3DDevice9Impl_SetStreamSource(IDirect3DDevice9Ex
*iface
,
2378 UINT StreamNumber
, IDirect3DVertexBuffer9
*pStreamData
, UINT OffsetInBytes
, UINT Stride
)
2380 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2381 IDirect3DVertexBuffer9Impl
*streamdata
= unsafe_impl_from_IDirect3DVertexBuffer9(pStreamData
);
2384 TRACE("iface %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
2385 iface
, StreamNumber
, pStreamData
, OffsetInBytes
, Stride
);
2387 wined3d_mutex_lock();
2388 hr
= wined3d_device_set_stream_source(This
->wined3d_device
, StreamNumber
,
2389 streamdata
? streamdata
->wineD3DVertexBuffer
: NULL
,
2390 OffsetInBytes
, Stride
);
2391 wined3d_mutex_unlock();
2396 static HRESULT WINAPI
IDirect3DDevice9Impl_GetStreamSource(IDirect3DDevice9Ex
*iface
,
2397 UINT StreamNumber
, IDirect3DVertexBuffer9
**pStream
, UINT
*OffsetInBytes
, UINT
*pStride
)
2399 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2400 struct wined3d_buffer
*retStream
= NULL
;
2403 TRACE("iface %p, stream_idx %u, buffer %p, offset %p, stride %p.\n",
2404 iface
, StreamNumber
, pStream
, OffsetInBytes
, pStride
);
2406 if(pStream
== NULL
){
2407 return D3DERR_INVALIDCALL
;
2410 wined3d_mutex_lock();
2411 hr
= wined3d_device_get_stream_source(This
->wined3d_device
, StreamNumber
, &retStream
, OffsetInBytes
, pStride
);
2412 if (SUCCEEDED(hr
) && retStream
)
2414 *pStream
= wined3d_buffer_get_parent(retStream
);
2415 IDirect3DVertexBuffer9_AddRef(*pStream
);
2416 wined3d_buffer_decref(retStream
);
2422 FIXME("Call to GetStreamSource failed %p %p\n", OffsetInBytes
, pStride
);
2426 wined3d_mutex_unlock();
2431 static HRESULT WINAPI
IDirect3DDevice9Impl_SetStreamSourceFreq(IDirect3DDevice9Ex
*iface
,
2432 UINT StreamNumber
, UINT Divider
)
2434 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2437 TRACE("iface %p, stream_idx %u, freq %u.\n", iface
, StreamNumber
, Divider
);
2439 wined3d_mutex_lock();
2440 hr
= wined3d_device_set_stream_source_freq(This
->wined3d_device
, StreamNumber
, Divider
);
2441 wined3d_mutex_unlock();
2446 static HRESULT WINAPI
IDirect3DDevice9Impl_GetStreamSourceFreq(IDirect3DDevice9Ex
*iface
,
2447 UINT StreamNumber
, UINT
*Divider
)
2449 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2452 TRACE("iface %p, stream_idx %u, freq %p.\n", iface
, StreamNumber
, Divider
);
2454 wined3d_mutex_lock();
2455 hr
= wined3d_device_get_stream_source_freq(This
->wined3d_device
, StreamNumber
, Divider
);
2456 wined3d_mutex_unlock();
2461 static HRESULT WINAPI
IDirect3DDevice9Impl_SetIndices(IDirect3DDevice9Ex
*iface
,
2462 IDirect3DIndexBuffer9
*pIndexData
)
2464 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2465 IDirect3DIndexBuffer9Impl
*ib
= unsafe_impl_from_IDirect3DIndexBuffer9(pIndexData
);
2468 TRACE("iface %p, buffer %p.\n", iface
, pIndexData
);
2470 wined3d_mutex_lock();
2471 hr
= wined3d_device_set_index_buffer(This
->wined3d_device
,
2472 ib
? ib
->wineD3DIndexBuffer
: NULL
,
2473 ib
? ib
->format
: WINED3DFMT_UNKNOWN
);
2474 wined3d_mutex_unlock();
2479 static HRESULT WINAPI
IDirect3DDevice9Impl_GetIndices(IDirect3DDevice9Ex
*iface
,
2480 IDirect3DIndexBuffer9
**ppIndexData
)
2482 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2483 struct wined3d_buffer
*retIndexData
= NULL
;
2486 TRACE("iface %p, buffer %p.\n", iface
, ppIndexData
);
2488 if(ppIndexData
== NULL
){
2489 return D3DERR_INVALIDCALL
;
2492 wined3d_mutex_lock();
2493 hr
= wined3d_device_get_index_buffer(This
->wined3d_device
, &retIndexData
);
2494 if (SUCCEEDED(hr
) && retIndexData
)
2496 *ppIndexData
= wined3d_buffer_get_parent(retIndexData
);
2497 IDirect3DIndexBuffer9_AddRef(*ppIndexData
);
2498 wined3d_buffer_decref(retIndexData
);
2502 if (FAILED(hr
)) FIXME("Call to GetIndices failed\n");
2503 *ppIndexData
= NULL
;
2505 wined3d_mutex_unlock();
2510 static HRESULT WINAPI
IDirect3DDevice9Impl_CreatePixelShader(IDirect3DDevice9Ex
*iface
,
2511 const DWORD
*byte_code
, IDirect3DPixelShader9
**shader
)
2513 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2514 IDirect3DPixelShader9Impl
*object
;
2517 TRACE("iface %p, byte_code %p, shader %p.\n", iface
, byte_code
, shader
);
2519 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2522 FIXME("Failed to allocate pixel shader memory.\n");
2523 return E_OUTOFMEMORY
;
2526 hr
= pixelshader_init(object
, This
, byte_code
);
2529 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
2530 HeapFree(GetProcessHeap(), 0, object
);
2534 TRACE("Created pixel shader %p.\n", object
);
2535 *shader
= &object
->IDirect3DPixelShader9_iface
;
2540 static HRESULT WINAPI
IDirect3DDevice9Impl_SetPixelShader(IDirect3DDevice9Ex
*iface
,
2541 IDirect3DPixelShader9
*shader
)
2543 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2544 IDirect3DPixelShader9Impl
*shader_obj
= unsafe_impl_from_IDirect3DPixelShader9(shader
);
2547 TRACE("iface %p, shader %p.\n", iface
, shader
);
2549 wined3d_mutex_lock();
2550 hr
= wined3d_device_set_pixel_shader(This
->wined3d_device
,
2551 shader_obj
? shader_obj
->wined3d_shader
: NULL
);
2552 wined3d_mutex_unlock();
2557 static HRESULT WINAPI
IDirect3DDevice9Impl_GetPixelShader(IDirect3DDevice9Ex
*iface
,
2558 IDirect3DPixelShader9
**shader
)
2560 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2561 struct wined3d_shader
*wined3d_shader
;
2563 TRACE("iface %p, shader %p.\n", iface
, shader
);
2565 if (!shader
) return D3DERR_INVALIDCALL
;
2567 wined3d_mutex_lock();
2568 wined3d_shader
= wined3d_device_get_pixel_shader(This
->wined3d_device
);
2571 *shader
= wined3d_shader_get_parent(wined3d_shader
);
2572 IDirect3DPixelShader9_AddRef(*shader
);
2573 wined3d_shader_decref(wined3d_shader
);
2579 wined3d_mutex_unlock();
2581 TRACE("Returning %p.\n", *shader
);
2586 static HRESULT WINAPI
IDirect3DDevice9Impl_SetPixelShaderConstantF(IDirect3DDevice9Ex
*iface
,
2587 UINT reg_idx
, const float *data
, UINT count
)
2589 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2592 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2594 wined3d_mutex_lock();
2595 hr
= wined3d_device_set_ps_consts_f(This
->wined3d_device
, reg_idx
, data
, count
);
2596 wined3d_mutex_unlock();
2601 static HRESULT WINAPI
IDirect3DDevice9Impl_GetPixelShaderConstantF(IDirect3DDevice9Ex
*iface
,
2602 UINT reg_idx
, float *data
, UINT count
)
2604 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2607 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2609 wined3d_mutex_lock();
2610 hr
= wined3d_device_get_ps_consts_f(This
->wined3d_device
, reg_idx
, data
, count
);
2611 wined3d_mutex_unlock();
2616 static HRESULT WINAPI
IDirect3DDevice9Impl_SetPixelShaderConstantI(IDirect3DDevice9Ex
*iface
,
2617 UINT reg_idx
, const int *data
, UINT count
)
2619 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2622 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2624 wined3d_mutex_lock();
2625 hr
= wined3d_device_set_ps_consts_i(This
->wined3d_device
, reg_idx
, data
, count
);
2626 wined3d_mutex_unlock();
2631 static HRESULT WINAPI
IDirect3DDevice9Impl_GetPixelShaderConstantI(IDirect3DDevice9Ex
*iface
,
2632 UINT reg_idx
, int *data
, UINT count
)
2634 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2637 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2639 wined3d_mutex_lock();
2640 hr
= wined3d_device_get_ps_consts_i(This
->wined3d_device
, reg_idx
, data
, count
);
2641 wined3d_mutex_unlock();
2646 static HRESULT WINAPI
IDirect3DDevice9Impl_SetPixelShaderConstantB(IDirect3DDevice9Ex
*iface
,
2647 UINT reg_idx
, const BOOL
*data
, UINT count
)
2649 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2652 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2654 wined3d_mutex_lock();
2655 hr
= wined3d_device_set_ps_consts_b(This
->wined3d_device
, reg_idx
, data
, count
);
2656 wined3d_mutex_unlock();
2661 static HRESULT WINAPI
IDirect3DDevice9Impl_GetPixelShaderConstantB(IDirect3DDevice9Ex
*iface
,
2662 UINT reg_idx
, BOOL
*data
, UINT count
)
2664 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2667 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2669 wined3d_mutex_lock();
2670 hr
= wined3d_device_get_ps_consts_b(This
->wined3d_device
, reg_idx
, data
, count
);
2671 wined3d_mutex_unlock();
2676 static HRESULT WINAPI
IDirect3DDevice9Impl_DrawRectPatch(IDirect3DDevice9Ex
*iface
, UINT Handle
,
2677 const float *pNumSegs
, const D3DRECTPATCH_INFO
*pRectPatchInfo
)
2679 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2682 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2683 iface
, Handle
, pNumSegs
, pRectPatchInfo
);
2685 wined3d_mutex_lock();
2686 hr
= wined3d_device_draw_rect_patch(This
->wined3d_device
, Handle
,
2687 pNumSegs
, (const struct wined3d_rect_patch_info
*)pRectPatchInfo
);
2688 wined3d_mutex_unlock();
2693 static HRESULT WINAPI
IDirect3DDevice9Impl_DrawTriPatch(IDirect3DDevice9Ex
*iface
, UINT Handle
,
2694 const float *pNumSegs
, const D3DTRIPATCH_INFO
*pTriPatchInfo
)
2696 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2699 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2700 iface
, Handle
, pNumSegs
, pTriPatchInfo
);
2702 wined3d_mutex_lock();
2703 hr
= wined3d_device_draw_tri_patch(This
->wined3d_device
, Handle
,
2704 pNumSegs
, (const struct wined3d_tri_patch_info
*)pTriPatchInfo
);
2705 wined3d_mutex_unlock();
2710 static HRESULT WINAPI
IDirect3DDevice9Impl_DeletePatch(IDirect3DDevice9Ex
*iface
, UINT Handle
)
2712 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2715 TRACE("iface %p, handle %#x.\n", iface
, Handle
);
2717 wined3d_mutex_lock();
2718 hr
= wined3d_device_delete_patch(This
->wined3d_device
, Handle
);
2719 wined3d_mutex_unlock();
2724 static HRESULT WINAPI
IDirect3DDevice9Impl_CreateQuery(IDirect3DDevice9Ex
*iface
, D3DQUERYTYPE type
,
2725 IDirect3DQuery9
**query
)
2727 IDirect3DDevice9Impl
*This
= impl_from_IDirect3DDevice9Ex(iface
);
2728 IDirect3DQuery9Impl
*object
;
2731 TRACE("iface %p, type %#x, query %p.\n", iface
, type
, query
);
2733 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2736 ERR("Failed to allocate query memory.\n");
2737 return E_OUTOFMEMORY
;
2740 hr
= query_init(object
, This
, type
);
2743 WARN("Failed to initialize query, hr %#x.\n", hr
);
2744 HeapFree(GetProcessHeap(), 0, object
);
2748 TRACE("Created query %p.\n", object
);
2749 if (query
) *query
= &object
->IDirect3DQuery9_iface
;
2750 else IDirect3DQuery9_Release(&object
->IDirect3DQuery9_iface
);
2755 static HRESULT WINAPI
IDirect3DDevice9ExImpl_SetConvolutionMonoKernel(IDirect3DDevice9Ex
*iface
,
2756 UINT width
, UINT height
, float *rows
, float *columns
)
2758 FIXME("iface %p, width %u, height %u, rows %p, columns %p stub!\n",
2759 iface
, width
, height
, rows
, columns
);
2764 static HRESULT WINAPI
IDirect3DDevice9ExImpl_ComposeRects(IDirect3DDevice9Ex
*iface
,
2765 IDirect3DSurface9
*src_surface
, IDirect3DSurface9
*dst_surface
, IDirect3DVertexBuffer9
*src_descs
,
2766 UINT rect_count
, IDirect3DVertexBuffer9
*dst_descs
, D3DCOMPOSERECTSOP operation
, INT offset_x
, INT offset_y
)
2768 FIXME("iface %p, src_surface %p, dst_surface %p, src_descs %p, rect_count %u,\n"
2769 "dst_descs %p, operation %#x, offset_x %u, offset_y %u stub!\n",
2770 iface
, src_surface
, dst_surface
, src_descs
, rect_count
,
2771 dst_descs
, operation
, offset_x
, offset_y
);
2776 static HRESULT WINAPI
IDirect3DDevice9ExImpl_PresentEx(IDirect3DDevice9Ex
*iface
,
2777 const RECT
*src_rect
, const RECT
*dst_rect
, HWND dst_window_override
,
2778 const RGNDATA
*dirty_region
, DWORD flags
)
2780 FIXME("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p, flags %#x stub!\n",
2781 iface
, src_rect
, dst_rect
, dst_window_override
, dirty_region
, flags
);
2786 static HRESULT WINAPI
IDirect3DDevice9ExImpl_GetGPUThreadPriority(IDirect3DDevice9Ex
*iface
, INT
*priority
)
2788 FIXME("iface %p, priority %p stub!\n", iface
, priority
);
2793 static HRESULT WINAPI
IDirect3DDevice9ExImpl_SetGPUThreadPriority(IDirect3DDevice9Ex
*iface
, INT priority
)
2795 FIXME("iface %p, priority %d stub!\n", iface
, priority
);
2800 static HRESULT WINAPI
IDirect3DDevice9ExImpl_WaitForVBlank(IDirect3DDevice9Ex
*iface
, UINT swapchain_idx
)
2802 FIXME("iface %p, swapchain_idx %u stub!\n", iface
, swapchain_idx
);
2807 static HRESULT WINAPI
IDirect3DDevice9ExImpl_CheckResourceResidency(IDirect3DDevice9Ex
*iface
,
2808 IDirect3DResource9
**resources
, UINT32 resource_count
)
2810 FIXME("iface %p, resources %p, resource_count %u stub!\n",
2811 iface
, resources
, resource_count
);
2816 static HRESULT WINAPI
IDirect3DDevice9ExImpl_SetMaximumFrameLatency(IDirect3DDevice9Ex
*iface
, UINT max_latency
)
2818 FIXME("iface %p, max_latency %u stub!\n", iface
, max_latency
);
2823 static HRESULT WINAPI
IDirect3DDevice9ExImpl_GetMaximumFrameLatency(IDirect3DDevice9Ex
*iface
, UINT
*max_latency
)
2825 FIXME("iface %p, max_latency %p stub!\n", iface
, max_latency
);
2832 static HRESULT WINAPI
IDirect3DDevice9ExImpl_CheckDeviceState(IDirect3DDevice9Ex
*iface
, HWND dst_window
)
2836 TRACE("iface %p, dst_window %p stub!\n", iface
, dst_window
);
2839 FIXME("iface %p, dst_window %p stub!\n", iface
, dst_window
);
2844 static HRESULT WINAPI
IDirect3DDevice9ExImpl_CreateRenderTargetEx(IDirect3DDevice9Ex
*iface
,
2845 UINT width
, UINT height
, D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
2846 BOOL lockable
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
, DWORD usage
)
2848 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
2849 "lockable %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2850 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
2851 lockable
, surface
, shared_handle
, usage
);
2856 static HRESULT WINAPI
IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx(IDirect3DDevice9Ex
*iface
,
2857 UINT width
, UINT height
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DSurface9
**surface
,
2858 HANDLE
*shared_handle
, DWORD usage
)
2860 FIXME("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2861 iface
, width
, height
, format
, pool
, surface
, shared_handle
, usage
);
2866 static HRESULT WINAPI
IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx(IDirect3DDevice9Ex
*iface
,
2867 UINT width
, UINT height
, D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
2868 BOOL discard
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
, DWORD usage
)
2870 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
2871 "discard %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2872 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
2873 discard
, surface
, shared_handle
, usage
);
2878 static HRESULT WINAPI
IDirect3DDevice9ExImpl_ResetEx(IDirect3DDevice9Ex
*iface
,
2879 D3DPRESENT_PARAMETERS
*present_parameters
, D3DDISPLAYMODEEX
*mode
)
2881 FIXME("iface %p, present_parameters %p, mode %p stub!\n", iface
, present_parameters
, mode
);
2886 static HRESULT WINAPI
IDirect3DDevice9ExImpl_GetDisplayModeEx(IDirect3DDevice9Ex
*iface
,
2887 UINT swapchain_idx
, D3DDISPLAYMODEEX
*mode
, D3DDISPLAYROTATION
*rotation
)
2889 FIXME("iface %p, swapchain_idx %u, mode %p, rotation %p stub!\n", iface
, swapchain_idx
, mode
, rotation
);
2894 static const IDirect3DDevice9ExVtbl Direct3DDevice9_Vtbl
=
2897 IDirect3DDevice9Impl_QueryInterface
,
2898 IDirect3DDevice9Impl_AddRef
,
2899 IDirect3DDevice9Impl_Release
,
2900 /* IDirect3DDevice9 */
2901 IDirect3DDevice9Impl_TestCooperativeLevel
,
2902 IDirect3DDevice9Impl_GetAvailableTextureMem
,
2903 IDirect3DDevice9Impl_EvictManagedResources
,
2904 IDirect3DDevice9Impl_GetDirect3D
,
2905 IDirect3DDevice9Impl_GetDeviceCaps
,
2906 IDirect3DDevice9Impl_GetDisplayMode
,
2907 IDirect3DDevice9Impl_GetCreationParameters
,
2908 IDirect3DDevice9Impl_SetCursorProperties
,
2909 IDirect3DDevice9Impl_SetCursorPosition
,
2910 IDirect3DDevice9Impl_ShowCursor
,
2911 IDirect3DDevice9Impl_CreateAdditionalSwapChain
,
2912 IDirect3DDevice9Impl_GetSwapChain
,
2913 IDirect3DDevice9Impl_GetNumberOfSwapChains
,
2914 IDirect3DDevice9Impl_Reset
,
2915 IDirect3DDevice9Impl_Present
,
2916 IDirect3DDevice9Impl_GetBackBuffer
,
2917 IDirect3DDevice9Impl_GetRasterStatus
,
2918 IDirect3DDevice9Impl_SetDialogBoxMode
,
2919 IDirect3DDevice9Impl_SetGammaRamp
,
2920 IDirect3DDevice9Impl_GetGammaRamp
,
2921 IDirect3DDevice9Impl_CreateTexture
,
2922 IDirect3DDevice9Impl_CreateVolumeTexture
,
2923 IDirect3DDevice9Impl_CreateCubeTexture
,
2924 IDirect3DDevice9Impl_CreateVertexBuffer
,
2925 IDirect3DDevice9Impl_CreateIndexBuffer
,
2926 IDirect3DDevice9Impl_CreateRenderTarget
,
2927 IDirect3DDevice9Impl_CreateDepthStencilSurface
,
2928 IDirect3DDevice9Impl_UpdateSurface
,
2929 IDirect3DDevice9Impl_UpdateTexture
,
2930 IDirect3DDevice9Impl_GetRenderTargetData
,
2931 IDirect3DDevice9Impl_GetFrontBufferData
,
2932 IDirect3DDevice9Impl_StretchRect
,
2933 IDirect3DDevice9Impl_ColorFill
,
2934 IDirect3DDevice9Impl_CreateOffscreenPlainSurface
,
2935 IDirect3DDevice9Impl_SetRenderTarget
,
2936 IDirect3DDevice9Impl_GetRenderTarget
,
2937 IDirect3DDevice9Impl_SetDepthStencilSurface
,
2938 IDirect3DDevice9Impl_GetDepthStencilSurface
,
2939 IDirect3DDevice9Impl_BeginScene
,
2940 IDirect3DDevice9Impl_EndScene
,
2941 IDirect3DDevice9Impl_Clear
,
2942 IDirect3DDevice9Impl_SetTransform
,
2943 IDirect3DDevice9Impl_GetTransform
,
2944 IDirect3DDevice9Impl_MultiplyTransform
,
2945 IDirect3DDevice9Impl_SetViewport
,
2946 IDirect3DDevice9Impl_GetViewport
,
2947 IDirect3DDevice9Impl_SetMaterial
,
2948 IDirect3DDevice9Impl_GetMaterial
,
2949 IDirect3DDevice9Impl_SetLight
,
2950 IDirect3DDevice9Impl_GetLight
,
2951 IDirect3DDevice9Impl_LightEnable
,
2952 IDirect3DDevice9Impl_GetLightEnable
,
2953 IDirect3DDevice9Impl_SetClipPlane
,
2954 IDirect3DDevice9Impl_GetClipPlane
,
2955 IDirect3DDevice9Impl_SetRenderState
,
2956 IDirect3DDevice9Impl_GetRenderState
,
2957 IDirect3DDevice9Impl_CreateStateBlock
,
2958 IDirect3DDevice9Impl_BeginStateBlock
,
2959 IDirect3DDevice9Impl_EndStateBlock
,
2960 IDirect3DDevice9Impl_SetClipStatus
,
2961 IDirect3DDevice9Impl_GetClipStatus
,
2962 IDirect3DDevice9Impl_GetTexture
,
2963 IDirect3DDevice9Impl_SetTexture
,
2964 IDirect3DDevice9Impl_GetTextureStageState
,
2965 IDirect3DDevice9Impl_SetTextureStageState
,
2966 IDirect3DDevice9Impl_GetSamplerState
,
2967 IDirect3DDevice9Impl_SetSamplerState
,
2968 IDirect3DDevice9Impl_ValidateDevice
,
2969 IDirect3DDevice9Impl_SetPaletteEntries
,
2970 IDirect3DDevice9Impl_GetPaletteEntries
,
2971 IDirect3DDevice9Impl_SetCurrentTexturePalette
,
2972 IDirect3DDevice9Impl_GetCurrentTexturePalette
,
2973 IDirect3DDevice9Impl_SetScissorRect
,
2974 IDirect3DDevice9Impl_GetScissorRect
,
2975 IDirect3DDevice9Impl_SetSoftwareVertexProcessing
,
2976 IDirect3DDevice9Impl_GetSoftwareVertexProcessing
,
2977 IDirect3DDevice9Impl_SetNPatchMode
,
2978 IDirect3DDevice9Impl_GetNPatchMode
,
2979 IDirect3DDevice9Impl_DrawPrimitive
,
2980 IDirect3DDevice9Impl_DrawIndexedPrimitive
,
2981 IDirect3DDevice9Impl_DrawPrimitiveUP
,
2982 IDirect3DDevice9Impl_DrawIndexedPrimitiveUP
,
2983 IDirect3DDevice9Impl_ProcessVertices
,
2984 IDirect3DDevice9Impl_CreateVertexDeclaration
,
2985 IDirect3DDevice9Impl_SetVertexDeclaration
,
2986 IDirect3DDevice9Impl_GetVertexDeclaration
,
2987 IDirect3DDevice9Impl_SetFVF
,
2988 IDirect3DDevice9Impl_GetFVF
,
2989 IDirect3DDevice9Impl_CreateVertexShader
,
2990 IDirect3DDevice9Impl_SetVertexShader
,
2991 IDirect3DDevice9Impl_GetVertexShader
,
2992 IDirect3DDevice9Impl_SetVertexShaderConstantF
,
2993 IDirect3DDevice9Impl_GetVertexShaderConstantF
,
2994 IDirect3DDevice9Impl_SetVertexShaderConstantI
,
2995 IDirect3DDevice9Impl_GetVertexShaderConstantI
,
2996 IDirect3DDevice9Impl_SetVertexShaderConstantB
,
2997 IDirect3DDevice9Impl_GetVertexShaderConstantB
,
2998 IDirect3DDevice9Impl_SetStreamSource
,
2999 IDirect3DDevice9Impl_GetStreamSource
,
3000 IDirect3DDevice9Impl_SetStreamSourceFreq
,
3001 IDirect3DDevice9Impl_GetStreamSourceFreq
,
3002 IDirect3DDevice9Impl_SetIndices
,
3003 IDirect3DDevice9Impl_GetIndices
,
3004 IDirect3DDevice9Impl_CreatePixelShader
,
3005 IDirect3DDevice9Impl_SetPixelShader
,
3006 IDirect3DDevice9Impl_GetPixelShader
,
3007 IDirect3DDevice9Impl_SetPixelShaderConstantF
,
3008 IDirect3DDevice9Impl_GetPixelShaderConstantF
,
3009 IDirect3DDevice9Impl_SetPixelShaderConstantI
,
3010 IDirect3DDevice9Impl_GetPixelShaderConstantI
,
3011 IDirect3DDevice9Impl_SetPixelShaderConstantB
,
3012 IDirect3DDevice9Impl_GetPixelShaderConstantB
,
3013 IDirect3DDevice9Impl_DrawRectPatch
,
3014 IDirect3DDevice9Impl_DrawTriPatch
,
3015 IDirect3DDevice9Impl_DeletePatch
,
3016 IDirect3DDevice9Impl_CreateQuery
,
3017 /* IDirect3DDevice9Ex */
3018 IDirect3DDevice9ExImpl_SetConvolutionMonoKernel
,
3019 IDirect3DDevice9ExImpl_ComposeRects
,
3020 IDirect3DDevice9ExImpl_PresentEx
,
3021 IDirect3DDevice9ExImpl_GetGPUThreadPriority
,
3022 IDirect3DDevice9ExImpl_SetGPUThreadPriority
,
3023 IDirect3DDevice9ExImpl_WaitForVBlank
,
3024 IDirect3DDevice9ExImpl_CheckResourceResidency
,
3025 IDirect3DDevice9ExImpl_SetMaximumFrameLatency
,
3026 IDirect3DDevice9ExImpl_GetMaximumFrameLatency
,
3027 IDirect3DDevice9ExImpl_CheckDeviceState
,
3028 IDirect3DDevice9ExImpl_CreateRenderTargetEx
,
3029 IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx
,
3030 IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx
,
3031 IDirect3DDevice9ExImpl_ResetEx
,
3032 IDirect3DDevice9ExImpl_GetDisplayModeEx
3035 static inline struct IDirect3DDevice9Impl
*device_from_device_parent(struct wined3d_device_parent
*device_parent
)
3037 return CONTAINING_RECORD(device_parent
, struct IDirect3DDevice9Impl
, device_parent
);
3040 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
3041 struct wined3d_device
*device
)
3043 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
3046 static HRESULT CDECL
device_parent_create_surface(struct wined3d_device_parent
*device_parent
,
3047 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
, DWORD usage
,
3048 WINED3DPOOL pool
, UINT level
, WINED3DCUBEMAP_FACES face
, struct wined3d_surface
**surface
)
3050 struct IDirect3DDevice9Impl
*device
= device_from_device_parent(device_parent
);
3051 IDirect3DSurface9Impl
*d3d_surface
;
3052 BOOL lockable
= TRUE
;
3055 TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
3056 "\tpool %#x, level %u, face %u, surface %p.\n",
3057 device_parent
, container_parent
, width
, height
, format
, usage
, pool
, level
, face
, surface
);
3059 if (pool
== WINED3DPOOL_DEFAULT
&& !(usage
& D3DUSAGE_DYNAMIC
))
3062 hr
= IDirect3DDevice9Impl_CreateSurface(device
, width
, height
,
3063 d3dformat_from_wined3dformat(format
), lockable
, FALSE
/* Discard */, level
,
3064 (IDirect3DSurface9
**)&d3d_surface
, usage
, pool
, D3DMULTISAMPLE_NONE
, 0 /* MultisampleQuality */);
3067 WARN("Failed to create surface, hr %#x.\n", hr
);
3071 *surface
= d3d_surface
->wined3d_surface
;
3072 wined3d_surface_incref(*surface
);
3074 d3d_surface
->container
= container_parent
;
3075 IDirect3DDevice9Ex_Release(d3d_surface
->parentDevice
);
3076 d3d_surface
->parentDevice
= NULL
;
3078 IDirect3DSurface9_Release(&d3d_surface
->IDirect3DSurface9_iface
);
3079 d3d_surface
->forwardReference
= container_parent
;
3084 static HRESULT CDECL
device_parent_create_rendertarget(struct wined3d_device_parent
*device_parent
,
3085 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
,
3086 WINED3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
, BOOL lockable
,
3087 struct wined3d_surface
**surface
)
3089 struct IDirect3DDevice9Impl
*device
= device_from_device_parent(device_parent
);
3090 IDirect3DSurface9Impl
*d3d_surface
;
3093 TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n"
3094 "\tmultisample_quality %u, lockable %u, surface %p.\n",
3095 device_parent
, container_parent
, width
, height
, format
, multisample_type
,
3096 multisample_quality
, lockable
, surface
);
3098 hr
= IDirect3DDevice9Impl_CreateRenderTarget(&device
->IDirect3DDevice9Ex_iface
, width
, height
,
3099 d3dformat_from_wined3dformat(format
), multisample_type
, multisample_quality
, lockable
,
3100 (IDirect3DSurface9
**)&d3d_surface
, NULL
);
3103 WARN("Failed to create rendertarget, hr %#x.\n", hr
);
3107 *surface
= d3d_surface
->wined3d_surface
;
3108 wined3d_surface_incref(*surface
);
3110 d3d_surface
->container
= container_parent
;
3111 /* Implicit surfaces are created with an refcount of 0 */
3112 IDirect3DSurface9_Release(&d3d_surface
->IDirect3DSurface9_iface
);
3117 static HRESULT CDECL
device_parent_create_depth_stencil(struct wined3d_device_parent
*device_parent
,
3118 UINT width
, UINT height
, enum wined3d_format_id format
, WINED3DMULTISAMPLE_TYPE multisample_type
,
3119 DWORD multisample_quality
, BOOL discard
, struct wined3d_surface
**surface
)
3121 struct IDirect3DDevice9Impl
*device
= device_from_device_parent(device_parent
);
3122 IDirect3DSurface9Impl
*d3d_surface
;
3125 TRACE("device_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n"
3126 "\tmultisample_quality %u, discard %u, surface %p.\n",
3127 device_parent
, width
, height
, format
, multisample_type
, multisample_quality
, discard
, surface
);
3129 hr
= IDirect3DDevice9Impl_CreateDepthStencilSurface(&device
->IDirect3DDevice9Ex_iface
, width
,
3130 height
, d3dformat_from_wined3dformat(format
), multisample_type
, multisample_quality
,
3131 discard
, (IDirect3DSurface9
**)&d3d_surface
, NULL
);
3134 WARN("Failed to create depth/stencil surface, hr %#x.\n", hr
);
3138 *surface
= d3d_surface
->wined3d_surface
;
3139 wined3d_surface_incref(*surface
);
3140 d3d_surface
->container
= (IUnknown
*)&device
->IDirect3DDevice9Ex_iface
;
3141 /* Implicit surfaces are created with an refcount of 0 */
3142 IDirect3DSurface9_Release(&d3d_surface
->IDirect3DSurface9_iface
);
3147 static HRESULT CDECL
device_parent_create_volume(struct wined3d_device_parent
*device_parent
,
3148 void *container_parent
, UINT width
, UINT height
, UINT depth
, enum wined3d_format_id format
,
3149 WINED3DPOOL pool
, DWORD usage
, struct wined3d_volume
**volume
)
3151 struct IDirect3DDevice9Impl
*device
= device_from_device_parent(device_parent
);
3152 IDirect3DVolume9Impl
*object
;
3155 TRACE("device_parent %p, container_parent %p, width %u, height %u, depth %u, "
3156 "format %#x, pool %#x, usage %#x, volume %p\n",
3157 device_parent
, container_parent
, width
, height
, depth
,
3158 format
, pool
, usage
, volume
);
3160 /* Allocate the storage for the device */
3161 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3164 FIXME("Allocation of memory failed\n");
3166 return D3DERR_OUTOFVIDEOMEMORY
;
3169 hr
= volume_init(object
, device
, width
, height
, depth
, usage
, format
, pool
);
3172 WARN("Failed to initialize volume, hr %#x.\n", hr
);
3173 HeapFree(GetProcessHeap(), 0, object
);
3177 *volume
= object
->wined3d_volume
;
3178 wined3d_volume_incref(*volume
);
3179 IDirect3DVolume9_Release(&object
->IDirect3DVolume9_iface
);
3181 object
->container
= container_parent
;
3182 object
->forwardReference
= container_parent
;
3184 TRACE("Created volume %p.\n", object
);
3189 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
3190 WINED3DPRESENT_PARAMETERS
*present_parameters
, struct wined3d_swapchain
**swapchain
)
3192 struct IDirect3DDevice9Impl
*device
= device_from_device_parent(device_parent
);
3193 D3DPRESENT_PARAMETERS local_parameters
;
3194 IDirect3DSwapChain9
*d3d_swapchain
;
3197 TRACE("device_parent %p, present_parameters %p, swapchain %p\n", device_parent
, present_parameters
, swapchain
);
3199 /* Copy the presentation parameters */
3200 local_parameters
.BackBufferWidth
= present_parameters
->BackBufferWidth
;
3201 local_parameters
.BackBufferHeight
= present_parameters
->BackBufferHeight
;
3202 local_parameters
.BackBufferFormat
= d3dformat_from_wined3dformat(present_parameters
->BackBufferFormat
);
3203 local_parameters
.BackBufferCount
= present_parameters
->BackBufferCount
;
3204 local_parameters
.MultiSampleType
= present_parameters
->MultiSampleType
;
3205 local_parameters
.MultiSampleQuality
= present_parameters
->MultiSampleQuality
;
3206 local_parameters
.SwapEffect
= present_parameters
->SwapEffect
;
3207 local_parameters
.hDeviceWindow
= present_parameters
->hDeviceWindow
;
3208 local_parameters
.Windowed
= present_parameters
->Windowed
;
3209 local_parameters
.EnableAutoDepthStencil
= present_parameters
->EnableAutoDepthStencil
;
3210 local_parameters
.AutoDepthStencilFormat
= d3dformat_from_wined3dformat(present_parameters
->AutoDepthStencilFormat
);
3211 local_parameters
.Flags
= present_parameters
->Flags
;
3212 local_parameters
.FullScreen_RefreshRateInHz
= present_parameters
->FullScreen_RefreshRateInHz
;
3213 local_parameters
.PresentationInterval
= present_parameters
->PresentationInterval
;
3215 hr
= IDirect3DDevice9Impl_CreateAdditionalSwapChain(&device
->IDirect3DDevice9Ex_iface
,
3216 &local_parameters
, &d3d_swapchain
);
3219 WARN("Failed to create swapchain, hr %#x.\n", hr
);
3224 *swapchain
= ((IDirect3DSwapChain9Impl
*)d3d_swapchain
)->wined3d_swapchain
;
3225 wined3d_swapchain_incref(*swapchain
);
3226 IDirect3DSwapChain9_Release((IDirect3DSwapChain9
*)d3d_swapchain
);
3228 /* Copy back the presentation parameters */
3229 present_parameters
->BackBufferWidth
= local_parameters
.BackBufferWidth
;
3230 present_parameters
->BackBufferHeight
= local_parameters
.BackBufferHeight
;
3231 present_parameters
->BackBufferFormat
= wined3dformat_from_d3dformat(local_parameters
.BackBufferFormat
);
3232 present_parameters
->BackBufferCount
= local_parameters
.BackBufferCount
;
3233 present_parameters
->MultiSampleType
= local_parameters
.MultiSampleType
;
3234 present_parameters
->MultiSampleQuality
= local_parameters
.MultiSampleQuality
;
3235 present_parameters
->SwapEffect
= local_parameters
.SwapEffect
;
3236 present_parameters
->hDeviceWindow
= local_parameters
.hDeviceWindow
;
3237 present_parameters
->Windowed
= local_parameters
.Windowed
;
3238 present_parameters
->EnableAutoDepthStencil
= local_parameters
.EnableAutoDepthStencil
;
3239 present_parameters
->AutoDepthStencilFormat
= wined3dformat_from_d3dformat(local_parameters
.AutoDepthStencilFormat
);
3240 present_parameters
->Flags
= local_parameters
.Flags
;
3241 present_parameters
->FullScreen_RefreshRateInHz
= local_parameters
.FullScreen_RefreshRateInHz
;
3242 present_parameters
->PresentationInterval
= local_parameters
.PresentationInterval
;
3247 static const struct wined3d_device_parent_ops d3d9_wined3d_device_parent_ops
=
3249 device_parent_wined3d_device_created
,
3250 device_parent_create_surface
,
3251 device_parent_create_rendertarget
,
3252 device_parent_create_depth_stencil
,
3253 device_parent_create_volume
,
3254 device_parent_create_swapchain
,
3257 static void setup_fpu(void)
3259 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3261 __asm__
volatile ("fnstcw %0" : "=m" (cw
));
3262 cw
= (cw
& ~0xf3f) | 0x3f;
3263 __asm__
volatile ("fldcw %0" : : "m" (cw
));
3264 #elif defined(__i386__) && defined(_MSC_VER)
3267 cw
= (cw
& ~0xf3f) | 0x3f;
3270 FIXME("FPU setup not implemented for this platform.\n");
3274 HRESULT
device_init(IDirect3DDevice9Impl
*device
, IDirect3D9Impl
*parent
, struct wined3d
*wined3d
, UINT adapter
, D3DDEVTYPE device_type
,
3275 HWND focus_window
, DWORD flags
, D3DPRESENT_PARAMETERS
*parameters
, D3DDISPLAYMODEEX
*mode
)
3277 WINED3DPRESENT_PARAMETERS
*wined3d_parameters
;
3282 FIXME("Ignoring display mode.\n");
3284 device
->IDirect3DDevice9Ex_iface
.lpVtbl
= &Direct3DDevice9_Vtbl
;
3285 device
->device_parent
.ops
= &d3d9_wined3d_device_parent_ops
;
3288 if (!(flags
& D3DCREATE_FPU_PRESERVE
)) setup_fpu();
3290 wined3d_mutex_lock();
3291 hr
= wined3d_device_create(wined3d
, adapter
, device_type
, focus_window
, flags
, 4,
3292 &device
->device_parent
, &device
->wined3d_device
);
3295 WARN("Failed to create wined3d device, hr %#x.\n", hr
);
3296 wined3d_mutex_unlock();
3300 if (flags
& D3DCREATE_ADAPTERGROUP_DEVICE
)
3304 wined3d_get_device_caps(wined3d
, adapter
, device_type
, &caps
);
3305 count
= caps
.NumberOfAdaptersInGroup
;
3308 if (flags
& D3DCREATE_MULTITHREADED
)
3309 wined3d_device_set_multithreaded(device
->wined3d_device
);
3311 if (!parameters
->Windowed
)
3314 focus_window
= parameters
->hDeviceWindow
;
3315 if (FAILED(hr
= wined3d_device_acquire_focus_window(device
->wined3d_device
, focus_window
)))
3317 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
3318 wined3d_device_decref(device
->wined3d_device
);
3319 wined3d_mutex_unlock();
3323 for (i
= 0; i
< count
; ++i
)
3325 HWND device_window
= parameters
[i
].hDeviceWindow
;
3327 if (!device_window
) device_window
= focus_window
;
3328 wined3d_device_setup_fullscreen_window(device
->wined3d_device
, device_window
,
3329 parameters
[i
].BackBufferWidth
,
3330 parameters
[i
].BackBufferHeight
);
3334 wined3d_parameters
= HeapAlloc(GetProcessHeap(), 0, sizeof(*wined3d_parameters
) * count
);
3335 if (!wined3d_parameters
)
3337 ERR("Failed to allocate wined3d parameters.\n");
3338 wined3d_device_decref(device
->wined3d_device
);
3339 wined3d_mutex_unlock();
3340 return E_OUTOFMEMORY
;
3343 for (i
= 0; i
< count
; ++i
)
3345 wined3d_parameters
[i
].BackBufferWidth
= parameters
[i
].BackBufferWidth
;
3346 wined3d_parameters
[i
].BackBufferHeight
= parameters
[i
].BackBufferHeight
;
3347 wined3d_parameters
[i
].BackBufferFormat
= wined3dformat_from_d3dformat(parameters
[i
].BackBufferFormat
);
3348 wined3d_parameters
[i
].BackBufferCount
= parameters
[i
].BackBufferCount
;
3349 wined3d_parameters
[i
].MultiSampleType
= parameters
[i
].MultiSampleType
;
3350 wined3d_parameters
[i
].MultiSampleQuality
= parameters
[i
].MultiSampleQuality
;
3351 wined3d_parameters
[i
].SwapEffect
= parameters
[i
].SwapEffect
;
3352 wined3d_parameters
[i
].hDeviceWindow
= parameters
[i
].hDeviceWindow
;
3353 wined3d_parameters
[i
].Windowed
= parameters
[i
].Windowed
;
3354 wined3d_parameters
[i
].EnableAutoDepthStencil
= parameters
[i
].EnableAutoDepthStencil
;
3355 wined3d_parameters
[i
].AutoDepthStencilFormat
=
3356 wined3dformat_from_d3dformat(parameters
[i
].AutoDepthStencilFormat
);
3357 wined3d_parameters
[i
].Flags
= parameters
[i
].Flags
;
3358 wined3d_parameters
[i
].FullScreen_RefreshRateInHz
= parameters
[i
].FullScreen_RefreshRateInHz
;
3359 wined3d_parameters
[i
].PresentationInterval
= parameters
[i
].PresentationInterval
;
3360 wined3d_parameters
[i
].AutoRestoreDisplayMode
= TRUE
;
3363 hr
= wined3d_device_init_3d(device
->wined3d_device
, wined3d_parameters
);
3366 WARN("Failed to initialize 3D, hr %#x.\n", hr
);
3367 wined3d_device_release_focus_window(device
->wined3d_device
);
3368 HeapFree(GetProcessHeap(), 0, wined3d_parameters
);
3369 wined3d_device_decref(device
->wined3d_device
);
3370 wined3d_mutex_unlock();
3374 wined3d_mutex_unlock();
3376 for (i
= 0; i
< count
; ++i
)
3378 parameters
[i
].BackBufferWidth
= wined3d_parameters
[i
].BackBufferWidth
;
3379 parameters
[i
].BackBufferHeight
= wined3d_parameters
[i
].BackBufferHeight
;
3380 parameters
[i
].BackBufferFormat
= d3dformat_from_wined3dformat(wined3d_parameters
[i
].BackBufferFormat
);
3381 parameters
[i
].BackBufferCount
= wined3d_parameters
[i
].BackBufferCount
;
3382 parameters
[i
].MultiSampleType
= wined3d_parameters
[i
].MultiSampleType
;
3383 parameters
[i
].MultiSampleQuality
= wined3d_parameters
[i
].MultiSampleQuality
;
3384 parameters
[i
].SwapEffect
= wined3d_parameters
[i
].SwapEffect
;
3385 parameters
[i
].hDeviceWindow
= wined3d_parameters
[i
].hDeviceWindow
;
3386 parameters
[i
].Windowed
= wined3d_parameters
[i
].Windowed
;
3387 parameters
[i
].EnableAutoDepthStencil
= wined3d_parameters
[i
].EnableAutoDepthStencil
;
3388 parameters
[i
].AutoDepthStencilFormat
=
3389 d3dformat_from_wined3dformat(wined3d_parameters
[i
].AutoDepthStencilFormat
);
3390 parameters
[i
].Flags
= wined3d_parameters
[i
].Flags
;
3391 parameters
[i
].FullScreen_RefreshRateInHz
= wined3d_parameters
[i
].FullScreen_RefreshRateInHz
;
3392 parameters
[i
].PresentationInterval
= wined3d_parameters
[i
].PresentationInterval
;
3394 HeapFree(GetProcessHeap(), 0, wined3d_parameters
);
3396 /* Initialize the converted declaration array. This creates a valid pointer
3397 * and when adding decls HeapReAlloc() can be used without further checking. */
3398 device
->convertedDecls
= HeapAlloc(GetProcessHeap(), 0, 0);
3399 if (!device
->convertedDecls
)
3401 ERR("Failed to allocate FVF vertex declaration map memory.\n");
3402 wined3d_mutex_lock();
3403 wined3d_device_uninit_3d(device
->wined3d_device
);
3404 wined3d_device_release_focus_window(device
->wined3d_device
);
3405 wined3d_device_decref(device
->wined3d_device
);
3406 wined3d_mutex_unlock();
3407 return E_OUTOFMEMORY
;
3410 device
->d3d_parent
= &parent
->IDirect3D9Ex_iface
;
3411 IDirect3D9_AddRef(device
->d3d_parent
);