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 ULONG WINAPI
D3D9CB_DestroySwapChain(IWineD3DSwapChain
*swapchain
)
186 IDirect3DSwapChain9Impl
*parent
;
188 TRACE("swapchain %p.\n", swapchain
);
190 parent
= IWineD3DSwapChain_GetParent(swapchain
);
191 parent
->isImplicit
= FALSE
;
192 IDirect3DSwapChain9_AddRef((IDirect3DSwapChain9
*)parent
);
193 return IDirect3DSwapChain9_Release((IDirect3DSwapChain9
*)parent
);
196 /* IDirect3D IUnknown parts follow: */
197 static HRESULT WINAPI
IDirect3DDevice9Impl_QueryInterface(LPDIRECT3DDEVICE9EX iface
, REFIID riid
, LPVOID
* ppobj
) {
198 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
200 IDirect3D9Impl
*d3dimpl
;
202 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), ppobj
);
204 if (IsEqualGUID(riid
, &IID_IUnknown
)
205 || IsEqualGUID(riid
, &IID_IDirect3DDevice9
)) {
206 IDirect3DDevice9Ex_AddRef(iface
);
208 TRACE("Returning IDirect3DDevice9 interface at %p\n", *ppobj
);
210 } else if(IsEqualGUID(riid
, &IID_IDirect3DDevice9Ex
)) {
211 /* Find out if the creating d3d9 interface was created with Direct3DCreate9Ex.
212 * It doesn't matter with which function the device was created.
214 IDirect3DDevice9_GetDirect3D(iface
, &d3d
);
215 d3dimpl
= (IDirect3D9Impl
*) d3d
;
217 if(d3dimpl
->extended
) {
219 IDirect3DDevice9Ex_AddRef((IDirect3DDevice9Ex
*) *ppobj
);
220 IDirect3D9_Release(d3d
);
221 TRACE("Returning IDirect3DDevice9Ex interface at %p\n", *ppobj
);
224 WARN("IDirect3D9 instance wasn't created with CreateDirect3D9Ex, returning E_NOINTERFACE\n");
225 IDirect3D9_Release(d3d
);
227 return E_NOINTERFACE
;
231 if (IsEqualGUID(riid
, &IID_IWineD3DDeviceParent
))
233 IUnknown_AddRef((IUnknown
*)&This
->device_parent_vtbl
);
234 *ppobj
= &This
->device_parent_vtbl
;
238 WARN("(%p)->(%s,%p),not found\n", This
, debugstr_guid(riid
), ppobj
);
240 return E_NOINTERFACE
;
243 static ULONG WINAPI
IDirect3DDevice9Impl_AddRef(LPDIRECT3DDEVICE9EX iface
) {
244 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
245 ULONG ref
= InterlockedIncrement(&This
->ref
);
247 TRACE("%p increasing refcount to %u.\n", iface
, ref
);
252 static ULONG WINAPI DECLSPEC_HOTPATCH
IDirect3DDevice9Impl_Release(LPDIRECT3DDEVICE9EX iface
) {
253 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
256 if (This
->inDestruction
) return 0;
257 ref
= InterlockedDecrement(&This
->ref
);
259 TRACE("%p decreasing refcount to %u.\n", iface
, ref
);
263 This
->inDestruction
= TRUE
;
265 wined3d_mutex_lock();
266 for(i
= 0; i
< This
->numConvertedDecls
; i
++) {
267 /* Unless Wine is buggy or the app has a bug the refcount will be 0, because decls hold a reference to the
270 IDirect3DVertexDeclaration9Impl_Destroy(This
->convertedDecls
[i
]);
272 HeapFree(GetProcessHeap(), 0, This
->convertedDecls
);
274 IWineD3DDevice_Uninit3D(This
->WineD3DDevice
, D3D9CB_DestroySwapChain
);
275 IWineD3DDevice_ReleaseFocusWindow(This
->WineD3DDevice
);
276 IWineD3DDevice_Release(This
->WineD3DDevice
);
277 wined3d_mutex_unlock();
279 HeapFree(GetProcessHeap(), 0, This
);
284 /* IDirect3DDevice Interface follow: */
285 static HRESULT WINAPI
IDirect3DDevice9Impl_TestCooperativeLevel(IDirect3DDevice9Ex
*iface
)
287 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
289 TRACE("iface %p.\n", iface
);
293 TRACE("D3D9 device is marked not reset.\n");
294 return D3DERR_DEVICENOTRESET
;
300 static UINT WINAPI
IDirect3DDevice9Impl_GetAvailableTextureMem(LPDIRECT3DDEVICE9EX iface
) {
301 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
304 TRACE("iface %p.\n", iface
);
306 wined3d_mutex_lock();
307 hr
= IWineD3DDevice_GetAvailableTextureMem(This
->WineD3DDevice
);
308 wined3d_mutex_unlock();
313 static HRESULT WINAPI
IDirect3DDevice9Impl_EvictManagedResources(LPDIRECT3DDEVICE9EX iface
) {
314 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
317 TRACE("iface %p.\n", iface
);
319 wined3d_mutex_lock();
320 hr
= IWineD3DDevice_EvictManagedResources(This
->WineD3DDevice
);
321 wined3d_mutex_unlock();
326 static HRESULT WINAPI
IDirect3DDevice9Impl_GetDirect3D(IDirect3DDevice9Ex
*iface
, IDirect3D9
**ppD3D9
)
328 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
329 struct wined3d
*wined3d
;
332 TRACE("iface %p, d3d9 %p.\n", iface
, ppD3D9
);
334 if (NULL
== ppD3D9
) {
335 return D3DERR_INVALIDCALL
;
338 wined3d_mutex_lock();
339 hr
= IWineD3DDevice_GetDirect3D(This
->WineD3DDevice
, &wined3d
);
340 if (hr
== D3D_OK
&& wined3d
)
342 *ppD3D9
= wined3d_get_parent(wined3d
);
343 IDirect3D9_AddRef(*ppD3D9
);
344 wined3d_decref(wined3d
);
348 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
351 TRACE("(%p) returning %p\n", This
, *ppD3D9
);
352 wined3d_mutex_unlock();
357 static HRESULT WINAPI
IDirect3DDevice9Impl_GetDeviceCaps(LPDIRECT3DDEVICE9EX iface
, D3DCAPS9
* pCaps
) {
358 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
359 HRESULT hrc
= D3D_OK
;
360 WINED3DCAPS
*pWineCaps
;
362 TRACE("iface %p, caps %p.\n", iface
, pCaps
);
365 return D3DERR_INVALIDCALL
;
367 pWineCaps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WINED3DCAPS
));
368 if(pWineCaps
== NULL
){
369 return D3DERR_INVALIDCALL
; /* well this is what MSDN says to return */
372 memset(pCaps
, 0, sizeof(*pCaps
));
374 wined3d_mutex_lock();
375 hrc
= IWineD3DDevice_GetDeviceCaps(This
->WineD3DDevice
, pWineCaps
);
376 wined3d_mutex_unlock();
378 WINECAPSTOD3D9CAPS(pCaps
, pWineCaps
)
379 HeapFree(GetProcessHeap(), 0, pWineCaps
);
381 /* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps */
382 pCaps
->DevCaps2
|= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES
;
386 TRACE("Returning %p %p\n", This
, pCaps
);
390 static HRESULT WINAPI
IDirect3DDevice9Impl_GetDisplayMode(LPDIRECT3DDEVICE9EX iface
, UINT iSwapChain
, D3DDISPLAYMODE
* pMode
) {
391 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
394 TRACE("iface %p, swapchain %u, mode %p.\n", iface
, iSwapChain
, pMode
);
396 wined3d_mutex_lock();
397 hr
= IWineD3DDevice_GetDisplayMode(This
->WineD3DDevice
, iSwapChain
, (WINED3DDISPLAYMODE
*) pMode
);
398 wined3d_mutex_unlock();
400 if (SUCCEEDED(hr
)) pMode
->Format
= d3dformat_from_wined3dformat(pMode
->Format
);
405 static HRESULT WINAPI
IDirect3DDevice9Impl_GetCreationParameters(LPDIRECT3DDEVICE9EX iface
, D3DDEVICE_CREATION_PARAMETERS
*pParameters
) {
406 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
409 TRACE("iface %p, parameters %p.\n", iface
, pParameters
);
411 wined3d_mutex_lock();
412 hr
= IWineD3DDevice_GetCreationParameters(This
->WineD3DDevice
, (WINED3DDEVICE_CREATION_PARAMETERS
*) pParameters
);
413 wined3d_mutex_unlock();
418 static HRESULT WINAPI
IDirect3DDevice9Impl_SetCursorProperties(LPDIRECT3DDEVICE9EX iface
, UINT XHotSpot
, UINT YHotSpot
, IDirect3DSurface9
* pCursorBitmap
) {
419 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
420 IDirect3DSurface9Impl
*pSurface
= (IDirect3DSurface9Impl
*)pCursorBitmap
;
423 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
424 iface
, XHotSpot
, YHotSpot
, pCursorBitmap
);
428 WARN("No cursor bitmap, returning D3DERR_INVALIDCALL.\n");
429 return D3DERR_INVALIDCALL
;
432 wined3d_mutex_lock();
433 hr
= IWineD3DDevice_SetCursorProperties(This
->WineD3DDevice
, XHotSpot
, YHotSpot
, pSurface
->wineD3DSurface
);
434 wined3d_mutex_unlock();
439 static void WINAPI
IDirect3DDevice9Impl_SetCursorPosition(LPDIRECT3DDEVICE9EX iface
, int XScreenSpace
, int YScreenSpace
, DWORD Flags
) {
440 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
442 TRACE("iface %p, x %u, y %u, flags %#x.\n", iface
, XScreenSpace
, YScreenSpace
, Flags
);
444 wined3d_mutex_lock();
445 IWineD3DDevice_SetCursorPosition(This
->WineD3DDevice
, XScreenSpace
, YScreenSpace
, Flags
);
446 wined3d_mutex_unlock();
449 static BOOL WINAPI
IDirect3DDevice9Impl_ShowCursor(LPDIRECT3DDEVICE9EX iface
, BOOL bShow
) {
450 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
453 TRACE("iface %p, show %#x.\n", iface
, bShow
);
455 wined3d_mutex_lock();
456 ret
= IWineD3DDevice_ShowCursor(This
->WineD3DDevice
, bShow
);
457 wined3d_mutex_unlock();
462 static HRESULT WINAPI DECLSPEC_HOTPATCH
IDirect3DDevice9Impl_CreateAdditionalSwapChain(IDirect3DDevice9Ex
*iface
,
463 D3DPRESENT_PARAMETERS
*present_parameters
, IDirect3DSwapChain9
**swapchain
)
465 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
466 IDirect3DSwapChain9Impl
*object
;
469 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
470 iface
, present_parameters
, swapchain
);
472 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
475 ERR("Failed to allocate swapchain memory.\n");
476 return E_OUTOFMEMORY
;
479 hr
= swapchain_init(object
, This
, present_parameters
);
482 WARN("Failed to initialize swapchain, hr %#x.\n", hr
);
483 HeapFree(GetProcessHeap(), 0, object
);
487 TRACE("Created swapchain %p.\n", object
);
488 *swapchain
= (IDirect3DSwapChain9
*)object
;
493 static HRESULT WINAPI DECLSPEC_HOTPATCH
IDirect3DDevice9Impl_GetSwapChain(IDirect3DDevice9Ex
*iface
,
494 UINT swapchain_idx
, IDirect3DSwapChain9
**swapchain
)
496 IWineD3DSwapChain
*wined3d_swapchain
= NULL
;
499 TRACE("iface %p, swapchain_idx %u, swapchain %p.\n", iface
, swapchain_idx
, swapchain
);
501 wined3d_mutex_lock();
502 hr
= IWineD3DDevice_GetSwapChain(((IDirect3DDevice9Impl
*)iface
)->WineD3DDevice
,
503 swapchain_idx
, &wined3d_swapchain
);
504 if (SUCCEEDED(hr
) && wined3d_swapchain
)
506 *swapchain
= IWineD3DSwapChain_GetParent(wined3d_swapchain
);
507 IDirect3DSwapChain9_AddRef(*swapchain
);
508 IWineD3DSwapChain_Release(wined3d_swapchain
);
514 wined3d_mutex_unlock();
519 static UINT WINAPI
IDirect3DDevice9Impl_GetNumberOfSwapChains(IDirect3DDevice9Ex
*iface
)
523 TRACE("iface %p.\n", iface
);
525 wined3d_mutex_lock();
526 count
= IWineD3DDevice_GetNumberOfSwapChains(((IDirect3DDevice9Impl
*)iface
)->WineD3DDevice
);
527 wined3d_mutex_unlock();
532 static HRESULT WINAPI
reset_enum_callback(struct wined3d_resource
*resource
, void *data
)
534 BOOL
*resources_ok
= data
;
535 D3DRESOURCETYPE type
;
537 D3DSURFACE_DESC surface_desc
;
538 D3DVOLUME_DESC volume_desc
;
539 D3DINDEXBUFFER_DESC index_desc
;
540 D3DVERTEXBUFFER_DESC vertex_desc
;
542 IDirect3DResource9
*parent
;
544 parent
= wined3d_resource_get_parent(resource
);
545 type
= IDirect3DResource9_GetType(parent
);
547 case D3DRTYPE_SURFACE
:
548 IDirect3DSurface9_GetDesc((IDirect3DSurface9
*)parent
, &surface_desc
);
549 pool
= surface_desc
.Pool
;
552 case D3DRTYPE_VOLUME
:
553 IDirect3DVolume9_GetDesc((IDirect3DVolume9
*)parent
, &volume_desc
);
554 pool
= volume_desc
.Pool
;
557 case D3DRTYPE_INDEXBUFFER
:
558 IDirect3DIndexBuffer9_GetDesc((IDirect3DIndexBuffer9
*) parent
, &index_desc
);
559 pool
= index_desc
.Pool
;
562 case D3DRTYPE_VERTEXBUFFER
:
563 IDirect3DVertexBuffer9_GetDesc((IDirect3DVertexBuffer9
*)parent
, &vertex_desc
);
564 pool
= vertex_desc
.Pool
;
567 /* No need to check for textures. If there is a D3DPOOL_DEFAULT texture, there
568 * is a D3DPOOL_DEFAULT surface or volume as well
571 pool
= WINED3DPOOL_SCRATCH
; /* a harmless pool */
575 if (pool
== WINED3DPOOL_DEFAULT
)
577 IDirect3DResource9_AddRef(parent
);
578 if (IUnknown_Release(parent
) == 0)
580 TRACE("Parent %p is an implicit resource with ref 0\n", parent
);
582 WARN("Resource %p(wineD3D %p) with pool D3DPOOL_DEFAULT blocks the Reset call\n", parent
, resource
);
584 *resources_ok
= FALSE
;
591 static HRESULT WINAPI DECLSPEC_HOTPATCH
IDirect3DDevice9Impl_Reset(LPDIRECT3DDEVICE9EX iface
, D3DPRESENT_PARAMETERS
* pPresentationParameters
) {
592 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
593 WINED3DPRESENT_PARAMETERS localParameters
;
595 BOOL resources_ok
= TRUE
;
598 TRACE("iface %p, present_parameters %p.\n", iface
, pPresentationParameters
);
600 /* Reset states that hold a COM object. WineD3D holds an internal reference to set objects, because
601 * such objects can still be used for rendering after their external d3d9 object has been destroyed.
602 * These objects must not be enumerated. Unsetting them tells WineD3D that the application will not
603 * make use of the hidden reference and destroys the objects.
605 * Unsetting them is no problem, because the states are supposed to be reset anyway. If the validation
606 * below fails, the device is considered "lost", and _Reset and _Release are the only allowed calls
608 wined3d_mutex_lock();
609 IWineD3DDevice_SetIndexBuffer(This
->WineD3DDevice
, NULL
, WINED3DFMT_UNKNOWN
);
610 for(i
= 0; i
< 16; i
++) {
611 IWineD3DDevice_SetStreamSource(This
->WineD3DDevice
, i
, NULL
, 0, 0);
613 for(i
= 0; i
< 16; i
++) {
614 IWineD3DDevice_SetTexture(This
->WineD3DDevice
, i
, NULL
);
617 IWineD3DDevice_EnumResources(This
->WineD3DDevice
, reset_enum_callback
, &resources_ok
);
619 WARN("The application is holding D3DPOOL_DEFAULT resources, rejecting reset\n");
620 This
->notreset
= TRUE
;
621 wined3d_mutex_unlock();
623 return D3DERR_INVALIDCALL
;
626 localParameters
.BackBufferWidth
= pPresentationParameters
->BackBufferWidth
;
627 localParameters
.BackBufferHeight
= pPresentationParameters
->BackBufferHeight
;
628 localParameters
.BackBufferFormat
= wined3dformat_from_d3dformat(pPresentationParameters
->BackBufferFormat
);
629 localParameters
.BackBufferCount
= pPresentationParameters
->BackBufferCount
;
630 localParameters
.MultiSampleType
= pPresentationParameters
->MultiSampleType
;
631 localParameters
.MultiSampleQuality
= pPresentationParameters
->MultiSampleQuality
;
632 localParameters
.SwapEffect
= pPresentationParameters
->SwapEffect
;
633 localParameters
.hDeviceWindow
= pPresentationParameters
->hDeviceWindow
;
634 localParameters
.Windowed
= pPresentationParameters
->Windowed
;
635 localParameters
.EnableAutoDepthStencil
= pPresentationParameters
->EnableAutoDepthStencil
;
636 localParameters
.AutoDepthStencilFormat
= wined3dformat_from_d3dformat(pPresentationParameters
->AutoDepthStencilFormat
);
637 localParameters
.Flags
= pPresentationParameters
->Flags
;
638 localParameters
.FullScreen_RefreshRateInHz
= pPresentationParameters
->FullScreen_RefreshRateInHz
;
639 localParameters
.PresentationInterval
= pPresentationParameters
->PresentationInterval
;
640 localParameters
.AutoRestoreDisplayMode
= TRUE
;
642 hr
= IWineD3DDevice_Reset(This
->WineD3DDevice
, &localParameters
);
644 This
->notreset
= TRUE
;
646 pPresentationParameters
->BackBufferWidth
= localParameters
.BackBufferWidth
;
647 pPresentationParameters
->BackBufferHeight
= localParameters
.BackBufferHeight
;
648 pPresentationParameters
->BackBufferFormat
= d3dformat_from_wined3dformat(localParameters
.BackBufferFormat
);
649 pPresentationParameters
->BackBufferCount
= localParameters
.BackBufferCount
;
650 pPresentationParameters
->MultiSampleType
= localParameters
.MultiSampleType
;
651 pPresentationParameters
->MultiSampleQuality
= localParameters
.MultiSampleQuality
;
652 pPresentationParameters
->SwapEffect
= localParameters
.SwapEffect
;
653 pPresentationParameters
->hDeviceWindow
= localParameters
.hDeviceWindow
;
654 pPresentationParameters
->Windowed
= localParameters
.Windowed
;
655 pPresentationParameters
->EnableAutoDepthStencil
= localParameters
.EnableAutoDepthStencil
;
656 pPresentationParameters
->AutoDepthStencilFormat
= d3dformat_from_wined3dformat(localParameters
.AutoDepthStencilFormat
);
657 pPresentationParameters
->Flags
= localParameters
.Flags
;
658 pPresentationParameters
->FullScreen_RefreshRateInHz
= localParameters
.FullScreen_RefreshRateInHz
;
659 pPresentationParameters
->PresentationInterval
= localParameters
.PresentationInterval
;
661 This
->notreset
= FALSE
;
664 wined3d_mutex_unlock();
669 static HRESULT WINAPI DECLSPEC_HOTPATCH
IDirect3DDevice9Impl_Present(LPDIRECT3DDEVICE9EX iface
, CONST RECT
* pSourceRect
,CONST RECT
* pDestRect
,HWND hDestWindowOverride
,CONST RGNDATA
*
671 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
674 TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
675 iface
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
677 wined3d_mutex_lock();
678 hr
= IWineD3DDevice_Present(This
->WineD3DDevice
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
679 wined3d_mutex_unlock();
684 static HRESULT WINAPI
IDirect3DDevice9Impl_GetBackBuffer(IDirect3DDevice9Ex
*iface
,
685 UINT iSwapChain
, UINT BackBuffer
, D3DBACKBUFFER_TYPE Type
, IDirect3DSurface9
**ppBackBuffer
)
687 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
688 IWineD3DSurface
*retSurface
= NULL
;
691 TRACE("iface %p, swapchain %u, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
692 iface
, iSwapChain
, BackBuffer
, Type
, ppBackBuffer
);
694 wined3d_mutex_lock();
695 hr
= IWineD3DDevice_GetBackBuffer(This
->WineD3DDevice
, iSwapChain
,
696 BackBuffer
, (WINED3DBACKBUFFER_TYPE
) Type
, &retSurface
);
697 if (SUCCEEDED(hr
) && retSurface
&& ppBackBuffer
)
699 *ppBackBuffer
= IWineD3DSurface_GetParent(retSurface
);
700 IDirect3DSurface9_AddRef(*ppBackBuffer
);
701 IWineD3DSurface_Release(retSurface
);
703 wined3d_mutex_unlock();
707 static HRESULT WINAPI
IDirect3DDevice9Impl_GetRasterStatus(LPDIRECT3DDEVICE9EX iface
, UINT iSwapChain
, D3DRASTER_STATUS
* pRasterStatus
) {
708 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
711 TRACE("iface %p, swapchain %u, raster_status %p.\n", iface
, iSwapChain
, pRasterStatus
);
713 wined3d_mutex_lock();
714 hr
= IWineD3DDevice_GetRasterStatus(This
->WineD3DDevice
, iSwapChain
, (WINED3DRASTER_STATUS
*) pRasterStatus
);
715 wined3d_mutex_unlock();
720 static HRESULT WINAPI
IDirect3DDevice9Impl_SetDialogBoxMode(LPDIRECT3DDEVICE9EX iface
, BOOL bEnableDialogs
) {
721 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
724 TRACE("iface %p, enable %#x.\n", iface
, bEnableDialogs
);
726 wined3d_mutex_lock();
727 hr
= IWineD3DDevice_SetDialogBoxMode(This
->WineD3DDevice
, bEnableDialogs
);
728 wined3d_mutex_unlock();
733 static void WINAPI
IDirect3DDevice9Impl_SetGammaRamp(IDirect3DDevice9Ex
*iface
, UINT iSwapChain
,
734 DWORD Flags
, const D3DGAMMARAMP
*pRamp
)
736 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
738 TRACE("iface %p, swapchain %u, flags %#x, ramp %p.\n", iface
, iSwapChain
, Flags
, pRamp
);
740 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
741 wined3d_mutex_lock();
742 IWineD3DDevice_SetGammaRamp(This
->WineD3DDevice
, iSwapChain
, Flags
, (CONST WINED3DGAMMARAMP
*)pRamp
);
743 wined3d_mutex_unlock();
746 static void WINAPI
IDirect3DDevice9Impl_GetGammaRamp(LPDIRECT3DDEVICE9EX iface
, UINT iSwapChain
, D3DGAMMARAMP
* pRamp
) {
747 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
749 TRACE("iface %p, swapchain %u, ramp %p.\n", iface
, iSwapChain
, pRamp
);
751 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
752 wined3d_mutex_lock();
753 IWineD3DDevice_GetGammaRamp(This
->WineD3DDevice
, iSwapChain
, (WINED3DGAMMARAMP
*) pRamp
);
754 wined3d_mutex_unlock();
757 static HRESULT WINAPI
IDirect3DDevice9Impl_CreateTexture(IDirect3DDevice9Ex
*iface
,
758 UINT width
, UINT height
, UINT levels
, DWORD usage
, D3DFORMAT format
,
759 D3DPOOL pool
, IDirect3DTexture9
**texture
, HANDLE
*shared_handle
)
761 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
762 IDirect3DTexture9Impl
*object
;
765 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
766 iface
, width
, height
, levels
, usage
, format
, pool
, texture
, shared_handle
);
768 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
771 ERR("Failed to allocate texture memory.\n");
772 return D3DERR_OUTOFVIDEOMEMORY
;
775 hr
= texture_init(object
, This
, width
, height
, levels
, usage
, format
, pool
);
778 WARN("Failed to initialize texture, hr %#x.\n", hr
);
779 HeapFree(GetProcessHeap(), 0, object
);
783 TRACE("Created texture %p.\n", object
);
784 *texture
= (IDirect3DTexture9
*)object
;
789 static HRESULT WINAPI
IDirect3DDevice9Impl_CreateVolumeTexture(IDirect3DDevice9Ex
*iface
,
790 UINT width
, UINT height
, UINT depth
, UINT levels
, DWORD usage
, D3DFORMAT format
,
791 D3DPOOL pool
, IDirect3DVolumeTexture9
**texture
, HANDLE
*shared_handle
)
793 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
794 IDirect3DVolumeTexture9Impl
*object
;
797 TRACE("iface %p, width %u, height %u, depth %u, levels %u\n",
798 iface
, width
, height
, depth
, levels
);
799 TRACE("usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
800 usage
, format
, pool
, texture
, shared_handle
);
802 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
805 ERR("Failed to allocate volume texture memory.\n");
806 return D3DERR_OUTOFVIDEOMEMORY
;
809 hr
= volumetexture_init(object
, This
, width
, height
, depth
, levels
, usage
, format
, pool
);
812 WARN("Failed to initialize volume texture, hr %#x.\n", hr
);
813 HeapFree(GetProcessHeap(), 0, object
);
817 TRACE("Created volume texture %p.\n", object
);
818 *texture
= (IDirect3DVolumeTexture9
*)object
;
823 static HRESULT WINAPI
IDirect3DDevice9Impl_CreateCubeTexture(IDirect3DDevice9Ex
*iface
,
824 UINT edge_length
, UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
,
825 IDirect3DCubeTexture9
**texture
, HANDLE
*shared_handle
)
827 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
828 IDirect3DCubeTexture9Impl
*object
;
831 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
832 iface
, edge_length
, levels
, usage
, format
, pool
, texture
, shared_handle
);
834 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
837 ERR("Failed to allocate cube texture memory.\n");
838 return D3DERR_OUTOFVIDEOMEMORY
;
841 hr
= cubetexture_init(object
, This
, edge_length
, levels
, usage
, format
, pool
);
844 WARN("Failed to initialize cube texture, hr %#x.\n", hr
);
845 HeapFree(GetProcessHeap(), 0, object
);
849 TRACE("Created cube texture %p.\n", object
);
850 *texture
= (IDirect3DCubeTexture9
*)object
;
855 static HRESULT WINAPI
IDirect3DDevice9Impl_CreateVertexBuffer(IDirect3DDevice9Ex
*iface
, UINT size
, DWORD usage
,
856 DWORD fvf
, D3DPOOL pool
, IDirect3DVertexBuffer9
**buffer
, HANDLE
*shared_handle
)
858 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
859 IDirect3DVertexBuffer9Impl
*object
;
862 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p, shared_handle %p.\n",
863 iface
, size
, usage
, fvf
, pool
, buffer
, shared_handle
);
865 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
868 ERR("Failed to allocate buffer memory.\n");
869 return D3DERR_OUTOFVIDEOMEMORY
;
872 hr
= vertexbuffer_init(object
, This
, size
, usage
, fvf
, pool
);
875 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr
);
876 HeapFree(GetProcessHeap(), 0, object
);
880 TRACE("Created vertex buffer %p.\n", object
);
881 *buffer
= (IDirect3DVertexBuffer9
*)object
;
886 static HRESULT WINAPI
IDirect3DDevice9Impl_CreateIndexBuffer(IDirect3DDevice9Ex
*iface
, UINT size
, DWORD usage
,
887 D3DFORMAT format
, D3DPOOL pool
, IDirect3DIndexBuffer9
**buffer
, HANDLE
*shared_handle
)
889 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
890 IDirect3DIndexBuffer9Impl
*object
;
893 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p, shared_handle %p.\n",
894 iface
, size
, usage
, format
, pool
, buffer
, shared_handle
);
896 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
899 ERR("Failed to allocate buffer memory.\n");
900 return D3DERR_OUTOFVIDEOMEMORY
;
903 hr
= indexbuffer_init(object
, This
, size
, usage
, format
, pool
);
906 WARN("Failed to initialize index buffer, hr %#x.\n", hr
);
907 HeapFree(GetProcessHeap(), 0, object
);
911 TRACE("Created index buffer %p.\n", object
);
912 *buffer
= (IDirect3DIndexBuffer9
*)object
;
917 static HRESULT
IDirect3DDevice9Impl_CreateSurface(LPDIRECT3DDEVICE9EX iface
, UINT Width
, UINT Height
,
918 D3DFORMAT Format
, BOOL Lockable
, BOOL Discard
, UINT Level
, IDirect3DSurface9
**ppSurface
,
919 UINT Usage
, D3DPOOL Pool
, D3DMULTISAMPLE_TYPE MultiSample
, DWORD MultisampleQuality
)
921 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
922 IDirect3DSurface9Impl
*object
;
925 TRACE("iface %p, width %u, height %u, format %#x, lockable %#x, discard %#x, level %u, surface %p.\n"
926 "usage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
927 iface
, Width
, Height
, Format
, Lockable
, Discard
, Level
, ppSurface
,
928 Usage
, Pool
, MultiSample
, MultisampleQuality
);
930 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirect3DSurface9Impl
));
933 FIXME("Failed to allocate surface memory.\n");
934 return D3DERR_OUTOFVIDEOMEMORY
;
937 hr
= surface_init(object
, This
, Width
, Height
, Format
, Lockable
, Discard
,
938 Level
, Usage
, Pool
, MultiSample
, MultisampleQuality
);
941 WARN("Failed to initialize surface, hr %#x.\n", hr
);
942 HeapFree(GetProcessHeap(), 0, object
);
946 TRACE("Created surface %p.\n", object
);
947 *ppSurface
= (IDirect3DSurface9
*)object
;
952 static HRESULT WINAPI
IDirect3DDevice9Impl_CreateRenderTarget(IDirect3DDevice9Ex
*iface
, UINT Width
, UINT Height
,
953 D3DFORMAT Format
, D3DMULTISAMPLE_TYPE MultiSample
, DWORD MultisampleQuality
, BOOL Lockable
,
954 IDirect3DSurface9
**ppSurface
, HANDLE
*pSharedHandle
)
958 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
959 "lockable %#x, surface %p, shared_handle %p.\n",
960 iface
, Width
, Height
, Format
, MultiSample
, MultisampleQuality
,
961 Lockable
, ppSurface
, pSharedHandle
);
963 hr
= IDirect3DDevice9Impl_CreateSurface(iface
, Width
, Height
, Format
, Lockable
, FALSE
/* Discard */,
964 0 /* Level */, ppSurface
, D3DUSAGE_RENDERTARGET
, D3DPOOL_DEFAULT
, MultiSample
, MultisampleQuality
);
969 static HRESULT WINAPI
IDirect3DDevice9Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE9EX iface
, UINT Width
, UINT Height
,
970 D3DFORMAT Format
, D3DMULTISAMPLE_TYPE MultiSample
,
971 DWORD MultisampleQuality
, BOOL Discard
,
972 IDirect3DSurface9
**ppSurface
, HANDLE
* pSharedHandle
) {
975 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
976 "discard %#x, surface %p, shared_handle %p.\n",
977 iface
, Width
, Height
, Format
, MultiSample
, MultisampleQuality
,
978 Discard
, ppSurface
, pSharedHandle
);
980 hr
= IDirect3DDevice9Impl_CreateSurface(iface
, Width
, Height
, Format
, TRUE
/* Lockable */, Discard
,
981 0 /* Level */, ppSurface
, D3DUSAGE_DEPTHSTENCIL
, D3DPOOL_DEFAULT
, MultiSample
, MultisampleQuality
);
987 static HRESULT WINAPI
IDirect3DDevice9Impl_UpdateSurface(LPDIRECT3DDEVICE9EX iface
, IDirect3DSurface9
* pSourceSurface
, CONST RECT
* pSourceRect
, IDirect3DSurface9
* pDestinationSurface
, CONST POINT
* pDestPoint
) {
988 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
991 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_point %p.\n",
992 iface
, pSourceSurface
, pSourceRect
, pDestinationSurface
, pDestPoint
);
994 wined3d_mutex_lock();
995 hr
= IWineD3DDevice_UpdateSurface(This
->WineD3DDevice
, ((IDirect3DSurface9Impl
*)pSourceSurface
)->wineD3DSurface
, pSourceRect
, ((IDirect3DSurface9Impl
*)pDestinationSurface
)->wineD3DSurface
, pDestPoint
);
996 wined3d_mutex_unlock();
1001 static HRESULT WINAPI
IDirect3DDevice9Impl_UpdateTexture(IDirect3DDevice9Ex
*iface
,
1002 IDirect3DBaseTexture9
*src_texture
, IDirect3DBaseTexture9
*dst_texture
)
1004 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1007 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface
, src_texture
, dst_texture
);
1009 wined3d_mutex_lock();
1010 hr
= IWineD3DDevice_UpdateTexture(This
->WineD3DDevice
,
1011 ((IDirect3DBaseTexture9Impl
*)src_texture
)->wined3d_texture
,
1012 ((IDirect3DBaseTexture9Impl
*)dst_texture
)->wined3d_texture
);
1013 wined3d_mutex_unlock();
1018 static HRESULT WINAPI
IDirect3DDevice9Impl_GetRenderTargetData(IDirect3DDevice9Ex
*iface
,
1019 IDirect3DSurface9
*pRenderTarget
, IDirect3DSurface9
*pDestSurface
)
1021 IDirect3DSurface9Impl
*renderTarget
= (IDirect3DSurface9Impl
*)pRenderTarget
;
1022 IDirect3DSurface9Impl
*destSurface
= (IDirect3DSurface9Impl
*)pDestSurface
;
1025 TRACE("iface %p, render_target %p, dst_surface %p.\n", iface
, pRenderTarget
, pDestSurface
);
1027 wined3d_mutex_lock();
1028 hr
= IWineD3DSurface_BltFast(destSurface
->wineD3DSurface
, 0, 0, renderTarget
->wineD3DSurface
, NULL
, WINEDDBLTFAST_NOCOLORKEY
);
1029 wined3d_mutex_unlock();
1034 static HRESULT WINAPI
IDirect3DDevice9Impl_GetFrontBufferData(LPDIRECT3DDEVICE9EX iface
, UINT iSwapChain
, IDirect3DSurface9
* pDestSurface
) {
1035 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1036 IDirect3DSurface9Impl
*destSurface
= (IDirect3DSurface9Impl
*)pDestSurface
;
1039 TRACE("iface %p, swapchain %u, dst_surface %p.\n", iface
, iSwapChain
, pDestSurface
);
1041 wined3d_mutex_lock();
1042 hr
= IWineD3DDevice_GetFrontBufferData(This
->WineD3DDevice
, iSwapChain
, destSurface
->wineD3DSurface
);
1043 wined3d_mutex_unlock();
1048 static HRESULT WINAPI
IDirect3DDevice9Impl_StretchRect(IDirect3DDevice9Ex
*iface
, IDirect3DSurface9
*pSourceSurface
,
1049 const RECT
*pSourceRect
, IDirect3DSurface9
*pDestSurface
, const RECT
*pDestRect
, D3DTEXTUREFILTERTYPE Filter
)
1051 IDirect3DSurface9Impl
*src
= (IDirect3DSurface9Impl
*) pSourceSurface
;
1052 IDirect3DSurface9Impl
*dst
= (IDirect3DSurface9Impl
*) pDestSurface
;
1055 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_rect %p, filter %#x.\n",
1056 iface
, pSourceSurface
, pSourceRect
, pDestSurface
, pDestRect
, Filter
);
1058 wined3d_mutex_lock();
1059 hr
= IWineD3DSurface_Blt(dst
->wineD3DSurface
, pDestRect
, src
->wineD3DSurface
, pSourceRect
, 0, NULL
, Filter
);
1060 wined3d_mutex_unlock();
1065 static HRESULT WINAPI
IDirect3DDevice9Impl_ColorFill(IDirect3DDevice9Ex
*iface
,
1066 IDirect3DSurface9
*pSurface
, const RECT
*pRect
, D3DCOLOR color
)
1068 const WINED3DCOLORVALUE c
=
1070 ((color
>> 16) & 0xff) / 255.0f
,
1071 ((color
>> 8) & 0xff) / 255.0f
,
1072 (color
& 0xff) / 255.0f
,
1073 ((color
>> 24) & 0xff) / 255.0f
,
1075 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1076 IDirect3DSurface9Impl
*surface
= (IDirect3DSurface9Impl
*)pSurface
;
1077 struct wined3d_resource
*wined3d_resource
;
1078 struct wined3d_resource_desc desc
;
1081 TRACE("iface %p, surface %p, rect %p, color 0x%08x.\n", iface
, pSurface
, pRect
, color
);
1083 wined3d_mutex_lock();
1085 wined3d_resource
= IWineD3DSurface_GetResource(surface
->wineD3DSurface
);
1086 wined3d_resource_get_desc(wined3d_resource
, &desc
);
1088 /* This method is only allowed with surfaces that are render targets, or
1089 * offscreen plain surfaces in D3DPOOL_DEFAULT. */
1090 if (!(desc
.usage
& WINED3DUSAGE_RENDERTARGET
) && desc
.pool
!= WINED3DPOOL_DEFAULT
)
1092 wined3d_mutex_unlock();
1093 WARN("Surface is not a render target, or not a stand-alone D3DPOOL_DEFAULT surface\n");
1094 return D3DERR_INVALIDCALL
;
1097 /* Colorfill can only be used on rendertarget surfaces, or offscreen plain surfaces in D3DPOOL_DEFAULT */
1098 hr
= IWineD3DDevice_ColorFill(This
->WineD3DDevice
, surface
->wineD3DSurface
, pRect
, &c
);
1100 wined3d_mutex_unlock();
1105 static HRESULT WINAPI
IDirect3DDevice9Impl_CreateOffscreenPlainSurface(LPDIRECT3DDEVICE9EX iface
, UINT Width
, UINT Height
, D3DFORMAT Format
, D3DPOOL Pool
, IDirect3DSurface9
**ppSurface
, HANDLE
* pSharedHandle
) {
1108 TRACE("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p.\n",
1109 iface
, Width
, Height
, Format
, Pool
, ppSurface
, pSharedHandle
);
1111 if(Pool
== D3DPOOL_MANAGED
){
1112 FIXME("Attempting to create a managed offscreen plain surface\n");
1113 return D3DERR_INVALIDCALL
;
1116 'Off-screen plain surfaces are always lockable, regardless of their pool types.'
1118 D3DPOOL_DEFAULT is the appropriate pool for use with the IDirect3DDevice9::StretchRect and IDirect3DDevice9::ColorFill.
1119 Why, their always lockable?
1120 should I change the usage to dynamic?
1122 hr
= IDirect3DDevice9Impl_CreateSurface(iface
, Width
, Height
, Format
, TRUE
/* Lockable */, FALSE
/* Discard */,
1123 0 /* Level */, ppSurface
, 0 /* Usage (undefined/none) */, (WINED3DPOOL
)Pool
, D3DMULTISAMPLE_NONE
,
1124 0 /* MultisampleQuality */);
1129 /* TODO: move to wineD3D */
1130 static HRESULT WINAPI
IDirect3DDevice9Impl_SetRenderTarget(LPDIRECT3DDEVICE9EX iface
, DWORD RenderTargetIndex
, IDirect3DSurface9
* pRenderTarget
) {
1131 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1132 IDirect3DSurface9Impl
*pSurface
= (IDirect3DSurface9Impl
*)pRenderTarget
;
1135 TRACE("iface %p, idx %u, surface %p.\n", iface
, RenderTargetIndex
, pRenderTarget
);
1137 if (RenderTargetIndex
>= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS
)
1139 WARN("Invalid index %u specified.\n", RenderTargetIndex
);
1140 return D3DERR_INVALIDCALL
;
1143 wined3d_mutex_lock();
1144 hr
= IWineD3DDevice_SetRenderTarget(This
->WineD3DDevice
, RenderTargetIndex
, pSurface
? pSurface
->wineD3DSurface
: NULL
, TRUE
);
1145 wined3d_mutex_unlock();
1150 static HRESULT WINAPI
IDirect3DDevice9Impl_GetRenderTarget(IDirect3DDevice9Ex
*iface
,
1151 DWORD RenderTargetIndex
, IDirect3DSurface9
**ppRenderTarget
)
1153 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1154 IWineD3DSurface
*pRenderTarget
;
1157 TRACE("iface %p, idx %u, surface %p.\n", iface
, RenderTargetIndex
, ppRenderTarget
);
1159 if (ppRenderTarget
== NULL
) {
1160 return D3DERR_INVALIDCALL
;
1163 if (RenderTargetIndex
>= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS
)
1165 WARN("Invalid index %u specified.\n", RenderTargetIndex
);
1166 return D3DERR_INVALIDCALL
;
1169 wined3d_mutex_lock();
1171 hr
=IWineD3DDevice_GetRenderTarget(This
->WineD3DDevice
,RenderTargetIndex
,&pRenderTarget
);
1175 FIXME("Call to IWineD3DDevice_GetRenderTarget failed, hr %#x\n", hr
);
1177 else if (!pRenderTarget
)
1179 *ppRenderTarget
= NULL
;
1183 *ppRenderTarget
= IWineD3DSurface_GetParent(pRenderTarget
);
1184 IDirect3DSurface9_AddRef(*ppRenderTarget
);
1185 IWineD3DSurface_Release(pRenderTarget
);
1188 wined3d_mutex_unlock();
1193 static HRESULT WINAPI
IDirect3DDevice9Impl_SetDepthStencilSurface(LPDIRECT3DDEVICE9EX iface
, IDirect3DSurface9
* pZStencilSurface
) {
1194 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1195 IDirect3DSurface9Impl
*pSurface
;
1198 TRACE("iface %p, depth_stencil %p.\n", iface
, pZStencilSurface
);
1200 pSurface
= (IDirect3DSurface9Impl
*)pZStencilSurface
;
1202 wined3d_mutex_lock();
1203 hr
= IWineD3DDevice_SetDepthStencilSurface(This
->WineD3DDevice
, NULL
==pSurface
? NULL
: pSurface
->wineD3DSurface
);
1204 wined3d_mutex_unlock();
1209 static HRESULT WINAPI
IDirect3DDevice9Impl_GetDepthStencilSurface(IDirect3DDevice9Ex
*iface
,
1210 IDirect3DSurface9
**ppZStencilSurface
)
1212 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1213 IWineD3DSurface
*pZStencilSurface
;
1216 TRACE("iface %p, depth_stencil %p.\n", iface
, ppZStencilSurface
);
1218 if(ppZStencilSurface
== NULL
){
1219 return D3DERR_INVALIDCALL
;
1222 wined3d_mutex_lock();
1223 hr
= IWineD3DDevice_GetDepthStencilSurface(This
->WineD3DDevice
,&pZStencilSurface
);
1226 *ppZStencilSurface
= IWineD3DSurface_GetParent(pZStencilSurface
);
1227 IDirect3DSurface9_AddRef(*ppZStencilSurface
);
1228 IWineD3DSurface_Release(pZStencilSurface
);
1232 if (hr
!= WINED3DERR_NOTFOUND
)
1233 WARN("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr
);
1234 *ppZStencilSurface
= NULL
;
1236 wined3d_mutex_unlock();
1241 static HRESULT WINAPI
IDirect3DDevice9Impl_BeginScene(LPDIRECT3DDEVICE9EX iface
) {
1242 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1245 TRACE("iface %p.\n", iface
);
1247 wined3d_mutex_lock();
1248 hr
= IWineD3DDevice_BeginScene(This
->WineD3DDevice
);
1249 wined3d_mutex_unlock();
1254 static HRESULT WINAPI DECLSPEC_HOTPATCH
IDirect3DDevice9Impl_EndScene(LPDIRECT3DDEVICE9EX iface
) {
1255 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1258 TRACE("iface %p.\n", iface
);
1260 wined3d_mutex_lock();
1261 hr
= IWineD3DDevice_EndScene(This
->WineD3DDevice
);
1262 wined3d_mutex_unlock();
1267 static HRESULT WINAPI
IDirect3DDevice9Impl_Clear(LPDIRECT3DDEVICE9EX iface
, DWORD Count
, CONST D3DRECT
* pRects
, DWORD Flags
, D3DCOLOR Color
, float Z
, DWORD Stencil
) {
1268 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1271 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1272 iface
, Count
, pRects
, Flags
, Color
, Z
, Stencil
);
1274 /* Note: D3DRECT is compatible with WINED3DRECT */
1275 wined3d_mutex_lock();
1276 hr
= IWineD3DDevice_Clear(This
->WineD3DDevice
, Count
, (const RECT
*)pRects
, Flags
, Color
, Z
, Stencil
);
1277 wined3d_mutex_unlock();
1282 static HRESULT WINAPI
IDirect3DDevice9Impl_SetTransform(LPDIRECT3DDEVICE9EX iface
, D3DTRANSFORMSTATETYPE State
, CONST D3DMATRIX
* lpMatrix
) {
1283 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1286 TRACE("iface %p, state %#x, matrix %p.\n", iface
, State
, lpMatrix
);
1288 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1289 wined3d_mutex_lock();
1290 hr
= IWineD3DDevice_SetTransform(This
->WineD3DDevice
, State
, (CONST WINED3DMATRIX
*) lpMatrix
);
1291 wined3d_mutex_unlock();
1296 static HRESULT WINAPI
IDirect3DDevice9Impl_GetTransform(LPDIRECT3DDEVICE9EX iface
, D3DTRANSFORMSTATETYPE State
, D3DMATRIX
* pMatrix
) {
1297 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1300 TRACE("iface %p, state %#x, matrix %p.\n", iface
, State
, pMatrix
);
1302 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1303 wined3d_mutex_lock();
1304 hr
= IWineD3DDevice_GetTransform(This
->WineD3DDevice
, State
, (WINED3DMATRIX
*) pMatrix
);
1305 wined3d_mutex_unlock();
1310 static HRESULT WINAPI
IDirect3DDevice9Impl_MultiplyTransform(LPDIRECT3DDEVICE9EX iface
, D3DTRANSFORMSTATETYPE State
, CONST D3DMATRIX
* pMatrix
) {
1311 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1314 TRACE("iface %p, state %#x, matrix %p.\n", iface
, State
, pMatrix
);
1316 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1317 wined3d_mutex_lock();
1318 hr
= IWineD3DDevice_MultiplyTransform(This
->WineD3DDevice
, State
, (CONST WINED3DMATRIX
*) pMatrix
);
1319 wined3d_mutex_unlock();
1324 static HRESULT WINAPI
IDirect3DDevice9Impl_SetViewport(LPDIRECT3DDEVICE9EX iface
, CONST D3DVIEWPORT9
* pViewport
) {
1325 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1328 TRACE("iface %p, viewport %p.\n", iface
, pViewport
);
1330 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
1331 wined3d_mutex_lock();
1332 hr
= IWineD3DDevice_SetViewport(This
->WineD3DDevice
, (const WINED3DVIEWPORT
*)pViewport
);
1333 wined3d_mutex_unlock();
1338 static HRESULT WINAPI
IDirect3DDevice9Impl_GetViewport(LPDIRECT3DDEVICE9EX iface
, D3DVIEWPORT9
* pViewport
) {
1339 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1342 TRACE("iface %p, viewport %p.\n", iface
, pViewport
);
1344 /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
1345 wined3d_mutex_lock();
1346 hr
= IWineD3DDevice_GetViewport(This
->WineD3DDevice
, (WINED3DVIEWPORT
*)pViewport
);
1347 wined3d_mutex_unlock();
1352 static HRESULT WINAPI
IDirect3DDevice9Impl_SetMaterial(LPDIRECT3DDEVICE9EX iface
, CONST D3DMATERIAL9
* pMaterial
) {
1353 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1356 TRACE("iface %p, material %p.\n", iface
, pMaterial
);
1358 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
1359 wined3d_mutex_lock();
1360 hr
= IWineD3DDevice_SetMaterial(This
->WineD3DDevice
, (const WINED3DMATERIAL
*)pMaterial
);
1361 wined3d_mutex_unlock();
1366 static HRESULT WINAPI
IDirect3DDevice9Impl_GetMaterial(LPDIRECT3DDEVICE9EX iface
, D3DMATERIAL9
* pMaterial
) {
1367 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1370 TRACE("iface %p, material %p.\n", iface
, pMaterial
);
1372 /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
1373 wined3d_mutex_lock();
1374 hr
= IWineD3DDevice_GetMaterial(This
->WineD3DDevice
, (WINED3DMATERIAL
*)pMaterial
);
1375 wined3d_mutex_unlock();
1380 static HRESULT WINAPI
IDirect3DDevice9Impl_SetLight(LPDIRECT3DDEVICE9EX iface
, DWORD Index
, CONST D3DLIGHT9
* pLight
) {
1381 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1384 TRACE("iface %p, index %u, light %p.\n", iface
, Index
, pLight
);
1386 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1387 wined3d_mutex_lock();
1388 hr
= IWineD3DDevice_SetLight(This
->WineD3DDevice
, Index
, (const WINED3DLIGHT
*)pLight
);
1389 wined3d_mutex_unlock();
1394 static HRESULT WINAPI
IDirect3DDevice9Impl_GetLight(LPDIRECT3DDEVICE9EX iface
, DWORD Index
, D3DLIGHT9
* pLight
) {
1395 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1398 TRACE("iface %p, index %u, light %p.\n", iface
, Index
, pLight
);
1400 /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
1401 wined3d_mutex_lock();
1402 hr
= IWineD3DDevice_GetLight(This
->WineD3DDevice
, Index
, (WINED3DLIGHT
*)pLight
);
1403 wined3d_mutex_unlock();
1408 static HRESULT WINAPI
IDirect3DDevice9Impl_LightEnable(LPDIRECT3DDEVICE9EX iface
, DWORD Index
, BOOL Enable
) {
1409 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1412 TRACE("iface %p, index %u, enable %#x.\n", iface
, Index
, Enable
);
1414 wined3d_mutex_lock();
1415 hr
= IWineD3DDevice_SetLightEnable(This
->WineD3DDevice
, Index
, Enable
);
1416 wined3d_mutex_unlock();
1421 static HRESULT WINAPI
IDirect3DDevice9Impl_GetLightEnable(LPDIRECT3DDEVICE9EX iface
, DWORD Index
, BOOL
* pEnable
) {
1422 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1425 TRACE("iface %p, index %u, enable %p.\n", iface
, Index
, pEnable
);
1427 wined3d_mutex_lock();
1428 hr
= IWineD3DDevice_GetLightEnable(This
->WineD3DDevice
, Index
, pEnable
);
1429 wined3d_mutex_unlock();
1434 static HRESULT WINAPI
IDirect3DDevice9Impl_SetClipPlane(LPDIRECT3DDEVICE9EX iface
, DWORD Index
, CONST
float* pPlane
) {
1435 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1438 TRACE("iface %p, index %u, plane %p.\n", iface
, Index
, pPlane
);
1440 wined3d_mutex_lock();
1441 hr
= IWineD3DDevice_SetClipPlane(This
->WineD3DDevice
, Index
, pPlane
);
1442 wined3d_mutex_unlock();
1447 static HRESULT WINAPI
IDirect3DDevice9Impl_GetClipPlane(LPDIRECT3DDEVICE9EX iface
, DWORD Index
, float* pPlane
) {
1448 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1451 TRACE("iface %p, index %u, plane %p.\n", iface
, Index
, pPlane
);
1453 wined3d_mutex_lock();
1454 hr
= IWineD3DDevice_GetClipPlane(This
->WineD3DDevice
, Index
, pPlane
);
1455 wined3d_mutex_unlock();
1460 static HRESULT WINAPI DECLSPEC_HOTPATCH
IDirect3DDevice9Impl_SetRenderState(LPDIRECT3DDEVICE9EX iface
, D3DRENDERSTATETYPE State
, DWORD Value
) {
1461 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1464 TRACE("iface %p, state %#x, value %#x.\n", iface
, State
, Value
);
1466 wined3d_mutex_lock();
1467 hr
= IWineD3DDevice_SetRenderState(This
->WineD3DDevice
, State
, Value
);
1468 wined3d_mutex_unlock();
1473 static HRESULT WINAPI
IDirect3DDevice9Impl_GetRenderState(LPDIRECT3DDEVICE9EX iface
, D3DRENDERSTATETYPE State
, DWORD
* pValue
) {
1474 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1477 TRACE("iface %p, state %#x, value %p.\n", iface
, State
, pValue
);
1479 wined3d_mutex_lock();
1480 hr
= IWineD3DDevice_GetRenderState(This
->WineD3DDevice
, State
, pValue
);
1481 wined3d_mutex_unlock();
1486 static HRESULT WINAPI
IDirect3DDevice9Impl_CreateStateBlock(IDirect3DDevice9Ex
*iface
,
1487 D3DSTATEBLOCKTYPE type
, IDirect3DStateBlock9
**stateblock
)
1489 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1490 IDirect3DStateBlock9Impl
*object
;
1493 TRACE("iface %p, type %#x, stateblock %p.\n", iface
, type
, stateblock
);
1495 if (type
!= D3DSBT_ALL
&& type
!= D3DSBT_PIXELSTATE
&& type
!= D3DSBT_VERTEXSTATE
)
1497 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL.\n");
1498 return D3DERR_INVALIDCALL
;
1501 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1504 ERR("Failed to allocate stateblock memory.\n");
1505 return E_OUTOFMEMORY
;
1508 hr
= stateblock_init(object
, This
, type
, NULL
);
1511 WARN("Failed to initialize stateblock, hr %#x.\n", hr
);
1512 HeapFree(GetProcessHeap(), 0, object
);
1516 TRACE("Created stateblock %p.\n", object
);
1517 *stateblock
= (IDirect3DStateBlock9
*)object
;
1522 static HRESULT WINAPI
IDirect3DDevice9Impl_BeginStateBlock(IDirect3DDevice9Ex
*iface
)
1524 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1527 TRACE("iface %p.\n", iface
);
1529 wined3d_mutex_lock();
1530 hr
= IWineD3DDevice_BeginStateBlock(This
->WineD3DDevice
);
1531 wined3d_mutex_unlock();
1536 static HRESULT WINAPI
IDirect3DDevice9Impl_EndStateBlock(IDirect3DDevice9Ex
*iface
, IDirect3DStateBlock9
**stateblock
)
1538 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1539 struct wined3d_stateblock
*wined3d_stateblock
;
1540 IDirect3DStateBlock9Impl
*object
;
1543 TRACE("iface %p, stateblock %p.\n", iface
, stateblock
);
1545 wined3d_mutex_lock();
1546 hr
= IWineD3DDevice_EndStateBlock(This
->WineD3DDevice
, &wined3d_stateblock
);
1547 wined3d_mutex_unlock();
1550 WARN("IWineD3DDevice_EndStateBlock() failed, hr %#x.\n", hr
);
1554 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1557 ERR("Failed to allocate stateblock memory.\n");
1558 wined3d_mutex_lock();
1559 wined3d_stateblock_decref(wined3d_stateblock
);
1560 wined3d_mutex_unlock();
1561 return E_OUTOFMEMORY
;
1564 hr
= stateblock_init(object
, This
, 0, wined3d_stateblock
);
1567 WARN("Failed to initialize stateblock, hr %#x.\n", hr
);
1568 wined3d_mutex_lock();
1569 wined3d_stateblock_decref(wined3d_stateblock
);
1570 wined3d_mutex_unlock();
1571 HeapFree(GetProcessHeap(), 0, object
);
1575 TRACE("Created stateblock %p.\n", object
);
1576 *stateblock
= (IDirect3DStateBlock9
*)object
;
1581 static HRESULT WINAPI
IDirect3DDevice9Impl_SetClipStatus(LPDIRECT3DDEVICE9EX iface
, CONST D3DCLIPSTATUS9
* pClipStatus
) {
1582 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1585 TRACE("iface %p, clip_status %p.\n", iface
, pClipStatus
);
1587 wined3d_mutex_lock();
1588 hr
= IWineD3DDevice_SetClipStatus(This
->WineD3DDevice
, (const WINED3DCLIPSTATUS
*)pClipStatus
);
1589 wined3d_mutex_unlock();
1594 static HRESULT WINAPI
IDirect3DDevice9Impl_GetClipStatus(LPDIRECT3DDEVICE9EX iface
, D3DCLIPSTATUS9
* pClipStatus
) {
1595 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1598 TRACE("iface %p, clip_status %p.\n", iface
, pClipStatus
);
1600 wined3d_mutex_lock();
1601 hr
= IWineD3DDevice_GetClipStatus(This
->WineD3DDevice
, (WINED3DCLIPSTATUS
*)pClipStatus
);
1602 wined3d_mutex_unlock();
1607 static HRESULT WINAPI
IDirect3DDevice9Impl_GetTexture(IDirect3DDevice9Ex
*iface
,
1608 DWORD Stage
, IDirect3DBaseTexture9
**ppTexture
)
1610 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1611 struct wined3d_texture
*wined3d_texture
= NULL
;
1614 TRACE("iface %p, stage %u, texture %p.\n", iface
, Stage
, ppTexture
);
1616 if(ppTexture
== NULL
){
1617 return D3DERR_INVALIDCALL
;
1620 wined3d_mutex_lock();
1621 hr
= IWineD3DDevice_GetTexture(This
->WineD3DDevice
, Stage
, &wined3d_texture
);
1622 if (SUCCEEDED(hr
) && wined3d_texture
)
1624 *ppTexture
= wined3d_texture_get_parent(wined3d_texture
);
1625 IDirect3DBaseTexture9_AddRef(*ppTexture
);
1626 wined3d_texture_decref(wined3d_texture
);
1632 WARN("Call to get texture (%u) failed (%p).\n", Stage
, wined3d_texture
);
1636 wined3d_mutex_unlock();
1641 static HRESULT WINAPI
IDirect3DDevice9Impl_SetTexture(IDirect3DDevice9Ex
*iface
,
1642 DWORD stage
, IDirect3DBaseTexture9
*texture
)
1644 IDirect3DDevice9Impl
*device
= (IDirect3DDevice9Impl
*)iface
;
1647 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
1649 wined3d_mutex_lock();
1650 hr
= IWineD3DDevice_SetTexture(device
->WineD3DDevice
, stage
,
1651 texture
? ((IDirect3DBaseTexture9Impl
*)texture
)->wined3d_texture
: NULL
);
1652 wined3d_mutex_unlock();
1657 static const WINED3DTEXTURESTAGESTATETYPE tss_lookup
[] =
1659 WINED3DTSS_FORCE_DWORD
, /* 0, unused */
1660 WINED3DTSS_COLOROP
, /* 1, D3DTSS_COLOROP */
1661 WINED3DTSS_COLORARG1
, /* 2, D3DTSS_COLORARG1 */
1662 WINED3DTSS_COLORARG2
, /* 3, D3DTSS_COLORARG2 */
1663 WINED3DTSS_ALPHAOP
, /* 4, D3DTSS_ALPHAOP */
1664 WINED3DTSS_ALPHAARG1
, /* 5, D3DTSS_ALPHAARG1 */
1665 WINED3DTSS_ALPHAARG2
, /* 6, D3DTSS_ALPHAARG2 */
1666 WINED3DTSS_BUMPENVMAT00
, /* 7, D3DTSS_BUMPENVMAT00 */
1667 WINED3DTSS_BUMPENVMAT01
, /* 8, D3DTSS_BUMPENVMAT01 */
1668 WINED3DTSS_BUMPENVMAT10
, /* 9, D3DTSS_BUMPENVMAT10 */
1669 WINED3DTSS_BUMPENVMAT11
, /* 10, D3DTSS_BUMPENVMAT11 */
1670 WINED3DTSS_TEXCOORDINDEX
, /* 11, D3DTSS_TEXCOORDINDEX */
1671 WINED3DTSS_FORCE_DWORD
, /* 12, unused */
1672 WINED3DTSS_FORCE_DWORD
, /* 13, unused */
1673 WINED3DTSS_FORCE_DWORD
, /* 14, unused */
1674 WINED3DTSS_FORCE_DWORD
, /* 15, unused */
1675 WINED3DTSS_FORCE_DWORD
, /* 16, unused */
1676 WINED3DTSS_FORCE_DWORD
, /* 17, unused */
1677 WINED3DTSS_FORCE_DWORD
, /* 18, unused */
1678 WINED3DTSS_FORCE_DWORD
, /* 19, unused */
1679 WINED3DTSS_FORCE_DWORD
, /* 20, unused */
1680 WINED3DTSS_FORCE_DWORD
, /* 21, unused */
1681 WINED3DTSS_BUMPENVLSCALE
, /* 22, D3DTSS_BUMPENVLSCALE */
1682 WINED3DTSS_BUMPENVLOFFSET
, /* 23, D3DTSS_BUMPENVLOFFSET */
1683 WINED3DTSS_TEXTURETRANSFORMFLAGS
, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1684 WINED3DTSS_FORCE_DWORD
, /* 25, unused */
1685 WINED3DTSS_COLORARG0
, /* 26, D3DTSS_COLORARG0 */
1686 WINED3DTSS_ALPHAARG0
, /* 27, D3DTSS_ALPHAARG0 */
1687 WINED3DTSS_RESULTARG
, /* 28, D3DTSS_RESULTARG */
1688 WINED3DTSS_FORCE_DWORD
, /* 29, unused */
1689 WINED3DTSS_FORCE_DWORD
, /* 30, unused */
1690 WINED3DTSS_FORCE_DWORD
, /* 31, unused */
1691 WINED3DTSS_CONSTANT
, /* 32, D3DTSS_CONSTANT */
1694 static HRESULT WINAPI
IDirect3DDevice9Impl_GetTextureStageState(LPDIRECT3DDEVICE9EX iface
, DWORD Stage
, D3DTEXTURESTAGESTATETYPE Type
, DWORD
*pValue
)
1696 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1699 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface
, Stage
, Type
, pValue
);
1701 if (Type
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
1703 WARN("Invalid Type %#x passed.\n", Type
);
1707 wined3d_mutex_lock();
1708 hr
= IWineD3DDevice_GetTextureStageState(This
->WineD3DDevice
, Stage
, tss_lookup
[Type
], pValue
);
1709 wined3d_mutex_unlock();
1714 static HRESULT WINAPI
IDirect3DDevice9Impl_SetTextureStageState(LPDIRECT3DDEVICE9EX iface
, DWORD Stage
, D3DTEXTURESTAGESTATETYPE Type
, DWORD Value
)
1716 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1719 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface
, Stage
, Type
, Value
);
1721 if (Type
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
1723 WARN("Invalid Type %#x passed.\n", Type
);
1727 wined3d_mutex_lock();
1728 hr
= IWineD3DDevice_SetTextureStageState(This
->WineD3DDevice
, Stage
, tss_lookup
[Type
], Value
);
1729 wined3d_mutex_unlock();
1734 static HRESULT WINAPI
IDirect3DDevice9Impl_GetSamplerState(IDirect3DDevice9Ex
*iface
, DWORD Sampler
,
1735 D3DSAMPLERSTATETYPE Type
, DWORD
*pValue
)
1737 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1740 TRACE("iface %p, sampler %u, state %#x, value %p.\n", iface
, Sampler
, Type
, pValue
);
1742 wined3d_mutex_lock();
1743 hr
= IWineD3DDevice_GetSamplerState(This
->WineD3DDevice
, Sampler
, Type
, pValue
);
1744 wined3d_mutex_unlock();
1749 static HRESULT WINAPI DECLSPEC_HOTPATCH
IDirect3DDevice9Impl_SetSamplerState(LPDIRECT3DDEVICE9EX iface
, DWORD Sampler
, D3DSAMPLERSTATETYPE Type
, DWORD Value
) {
1750 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1753 TRACE("iface %p, sampler %u, state %#x, value %#x.\n", iface
, Sampler
, Type
, Value
);
1755 wined3d_mutex_lock();
1756 hr
= IWineD3DDevice_SetSamplerState(This
->WineD3DDevice
, Sampler
, Type
, Value
);
1757 wined3d_mutex_unlock();
1762 static HRESULT WINAPI
IDirect3DDevice9Impl_ValidateDevice(LPDIRECT3DDEVICE9EX iface
, DWORD
* pNumPasses
) {
1763 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1766 TRACE("iface %p, pass_count %p.\n", iface
, pNumPasses
);
1768 wined3d_mutex_lock();
1769 hr
= IWineD3DDevice_ValidateDevice(This
->WineD3DDevice
, pNumPasses
);
1770 wined3d_mutex_unlock();
1775 static HRESULT WINAPI
IDirect3DDevice9Impl_SetPaletteEntries(IDirect3DDevice9Ex
*iface
, UINT PaletteNumber
,
1776 const PALETTEENTRY
*pEntries
)
1778 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1781 TRACE("iface %p, palette_idx %u, entries %p.\n", iface
, PaletteNumber
, pEntries
);
1783 wined3d_mutex_lock();
1784 hr
= IWineD3DDevice_SetPaletteEntries(This
->WineD3DDevice
, PaletteNumber
, pEntries
);
1785 wined3d_mutex_unlock();
1790 static HRESULT WINAPI
IDirect3DDevice9Impl_GetPaletteEntries(LPDIRECT3DDEVICE9EX iface
, UINT PaletteNumber
, PALETTEENTRY
* pEntries
) {
1791 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1794 TRACE("iface %p, palette_idx %u, entries %p.\n", iface
, PaletteNumber
, pEntries
);
1796 wined3d_mutex_lock();
1797 hr
= IWineD3DDevice_GetPaletteEntries(This
->WineD3DDevice
, PaletteNumber
, pEntries
);
1798 wined3d_mutex_unlock();
1803 static HRESULT WINAPI
IDirect3DDevice9Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE9EX iface
, UINT PaletteNumber
) {
1804 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1807 TRACE("iface %p, palette_idx %u.\n", iface
, PaletteNumber
);
1809 wined3d_mutex_lock();
1810 hr
= IWineD3DDevice_SetCurrentTexturePalette(This
->WineD3DDevice
, PaletteNumber
);
1811 wined3d_mutex_unlock();
1816 static HRESULT WINAPI
IDirect3DDevice9Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE9EX iface
, UINT
* PaletteNumber
) {
1817 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1820 TRACE("iface %p, palette_idx %p.\n", iface
, PaletteNumber
);
1822 wined3d_mutex_lock();
1823 hr
= IWineD3DDevice_GetCurrentTexturePalette(This
->WineD3DDevice
, PaletteNumber
);
1824 wined3d_mutex_unlock();
1829 static HRESULT WINAPI
IDirect3DDevice9Impl_SetScissorRect(LPDIRECT3DDEVICE9EX iface
, CONST RECT
* pRect
) {
1830 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1833 TRACE("iface %p, rect %p.\n", iface
, pRect
);
1835 wined3d_mutex_lock();
1836 hr
= IWineD3DDevice_SetScissorRect(This
->WineD3DDevice
, pRect
);
1837 wined3d_mutex_unlock();
1842 static HRESULT WINAPI
IDirect3DDevice9Impl_GetScissorRect(LPDIRECT3DDEVICE9EX iface
, RECT
* pRect
) {
1843 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1846 TRACE("iface %p, rect %p.\n", iface
, pRect
);
1848 wined3d_mutex_lock();
1849 hr
= IWineD3DDevice_GetScissorRect(This
->WineD3DDevice
, pRect
);
1850 wined3d_mutex_unlock();
1855 static HRESULT WINAPI
IDirect3DDevice9Impl_SetSoftwareVertexProcessing(LPDIRECT3DDEVICE9EX iface
, BOOL bSoftware
) {
1856 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1859 TRACE("iface %p, software %#x.\n", iface
, bSoftware
);
1861 wined3d_mutex_lock();
1862 hr
= IWineD3DDevice_SetSoftwareVertexProcessing(This
->WineD3DDevice
, bSoftware
);
1863 wined3d_mutex_unlock();
1868 static BOOL WINAPI
IDirect3DDevice9Impl_GetSoftwareVertexProcessing(LPDIRECT3DDEVICE9EX iface
) {
1869 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1872 TRACE("iface %p.\n", iface
);
1874 wined3d_mutex_lock();
1875 ret
= IWineD3DDevice_GetSoftwareVertexProcessing(This
->WineD3DDevice
);
1876 wined3d_mutex_unlock();
1881 static HRESULT WINAPI
IDirect3DDevice9Impl_SetNPatchMode(LPDIRECT3DDEVICE9EX iface
, float nSegments
) {
1882 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1885 TRACE("iface %p, segment_count %.8e.\n", iface
, nSegments
);
1887 wined3d_mutex_lock();
1888 hr
= IWineD3DDevice_SetNPatchMode(This
->WineD3DDevice
, nSegments
);
1889 wined3d_mutex_unlock();
1894 static float WINAPI
IDirect3DDevice9Impl_GetNPatchMode(LPDIRECT3DDEVICE9EX iface
) {
1895 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1898 TRACE("iface %p.\n", iface
);
1900 wined3d_mutex_lock();
1901 ret
= IWineD3DDevice_GetNPatchMode(This
->WineD3DDevice
);
1902 wined3d_mutex_unlock();
1907 static HRESULT WINAPI
IDirect3DDevice9Impl_DrawPrimitive(IDirect3DDevice9Ex
*iface
, D3DPRIMITIVETYPE PrimitiveType
,
1908 UINT StartVertex
, UINT PrimitiveCount
)
1910 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1913 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1914 iface
, PrimitiveType
, StartVertex
, PrimitiveCount
);
1916 wined3d_mutex_lock();
1917 IWineD3DDevice_SetPrimitiveType(This
->WineD3DDevice
, PrimitiveType
);
1918 hr
= IWineD3DDevice_DrawPrimitive(This
->WineD3DDevice
, StartVertex
,
1919 vertex_count_from_primitive_count(PrimitiveType
, PrimitiveCount
));
1920 wined3d_mutex_unlock();
1925 static HRESULT WINAPI
IDirect3DDevice9Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE9EX iface
, D3DPRIMITIVETYPE PrimitiveType
,
1926 INT BaseVertexIndex
, UINT MinVertexIndex
, UINT NumVertices
, UINT startIndex
, UINT primCount
) {
1927 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1930 TRACE("iface %p, primitive_type %#x, base_vertex_idx %u, min_vertex_idx %u,\n"
1931 "vertex_count %u, start_idx %u, primitive_count %u.\n",
1932 iface
, PrimitiveType
, BaseVertexIndex
, MinVertexIndex
,
1933 NumVertices
, startIndex
, primCount
);
1935 wined3d_mutex_lock();
1936 IWineD3DDevice_SetBaseVertexIndex(This
->WineD3DDevice
, BaseVertexIndex
);
1937 IWineD3DDevice_SetPrimitiveType(This
->WineD3DDevice
, PrimitiveType
);
1938 hr
= IWineD3DDevice_DrawIndexedPrimitive(This
->WineD3DDevice
, startIndex
,
1939 vertex_count_from_primitive_count(PrimitiveType
, primCount
));
1940 wined3d_mutex_unlock();
1945 static HRESULT WINAPI
IDirect3DDevice9Impl_DrawPrimitiveUP(IDirect3DDevice9Ex
*iface
, D3DPRIMITIVETYPE PrimitiveType
,
1946 UINT PrimitiveCount
, const void *pVertexStreamZeroData
, UINT VertexStreamZeroStride
)
1948 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1951 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
1952 iface
, PrimitiveType
, PrimitiveCount
, pVertexStreamZeroData
, VertexStreamZeroStride
);
1954 wined3d_mutex_lock();
1955 IWineD3DDevice_SetPrimitiveType(This
->WineD3DDevice
, PrimitiveType
);
1956 hr
= IWineD3DDevice_DrawPrimitiveUP(This
->WineD3DDevice
,
1957 vertex_count_from_primitive_count(PrimitiveType
, PrimitiveCount
),
1958 pVertexStreamZeroData
, VertexStreamZeroStride
);
1959 wined3d_mutex_unlock();
1964 static HRESULT WINAPI
IDirect3DDevice9Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE9EX iface
, D3DPRIMITIVETYPE PrimitiveType
, UINT MinVertexIndex
,
1965 UINT NumVertexIndices
, UINT PrimitiveCount
, CONST
void* pIndexData
,
1966 D3DFORMAT IndexDataFormat
, CONST
void* pVertexStreamZeroData
, UINT VertexStreamZeroStride
) {
1967 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1970 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
1971 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
1972 iface
, PrimitiveType
, MinVertexIndex
, NumVertexIndices
, PrimitiveCount
,
1973 pIndexData
, IndexDataFormat
, pVertexStreamZeroData
, VertexStreamZeroStride
);
1975 wined3d_mutex_lock();
1976 IWineD3DDevice_SetPrimitiveType(This
->WineD3DDevice
, PrimitiveType
);
1977 hr
= IWineD3DDevice_DrawIndexedPrimitiveUP(This
->WineD3DDevice
,
1978 vertex_count_from_primitive_count(PrimitiveType
, PrimitiveCount
), pIndexData
,
1979 wined3dformat_from_d3dformat(IndexDataFormat
), pVertexStreamZeroData
, VertexStreamZeroStride
);
1980 wined3d_mutex_unlock();
1985 static HRESULT WINAPI
IDirect3DDevice9Impl_ProcessVertices(LPDIRECT3DDEVICE9EX iface
, UINT SrcStartIndex
, UINT DestIndex
, UINT VertexCount
, IDirect3DVertexBuffer9
* pDestBuffer
, IDirect3DVertexDeclaration9
* pVertexDecl
, DWORD Flags
) {
1986 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
1987 IDirect3DVertexDeclaration9Impl
*Decl
= (IDirect3DVertexDeclaration9Impl
*) pVertexDecl
;
1989 IDirect3DVertexBuffer9Impl
*dest
= (IDirect3DVertexBuffer9Impl
*) pDestBuffer
;
1991 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, declaration %p, flags %#x.\n",
1992 iface
, SrcStartIndex
, DestIndex
, VertexCount
, pDestBuffer
, pVertexDecl
, Flags
);
1994 wined3d_mutex_lock();
1995 hr
= IWineD3DDevice_ProcessVertices(This
->WineD3DDevice
,SrcStartIndex
, DestIndex
, VertexCount
, dest
->wineD3DVertexBuffer
, Decl
? Decl
->wineD3DVertexDeclaration
: NULL
, Flags
, dest
->fvf
);
1996 wined3d_mutex_unlock();
2001 static HRESULT WINAPI
IDirect3DDevice9Impl_CreateVertexDeclaration(IDirect3DDevice9Ex
*iface
,
2002 const D3DVERTEXELEMENT9
*elements
, IDirect3DVertexDeclaration9
**declaration
)
2004 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
2005 IDirect3DVertexDeclaration9Impl
*object
;
2008 TRACE("iface %p, elements %p, declaration %p.\n", iface
, elements
, declaration
);
2012 WARN("Caller passed a NULL declaration, returning D3DERR_INVALIDCALL.\n");
2013 return D3DERR_INVALIDCALL
;
2016 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2019 ERR("Failed to allocate vertex declaration memory.\n");
2020 return E_OUTOFMEMORY
;
2023 hr
= vertexdeclaration_init(object
, This
, elements
);
2026 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr
);
2027 HeapFree(GetProcessHeap(), 0, object
);
2031 TRACE("Created vertex declaration %p.\n", object
);
2032 *declaration
= (IDirect3DVertexDeclaration9
*)object
;
2037 static HRESULT WINAPI
IDirect3DDevice9Impl_SetVertexDeclaration(IDirect3DDevice9Ex
*iface
,
2038 IDirect3DVertexDeclaration9
*declaration
)
2042 TRACE("iface %p, declaration %p.\n", iface
, declaration
);
2044 wined3d_mutex_lock();
2045 hr
= IWineD3DDevice_SetVertexDeclaration(((IDirect3DDevice9Impl
*)iface
)->WineD3DDevice
,
2046 declaration
? ((IDirect3DVertexDeclaration9Impl
*)declaration
)->wineD3DVertexDeclaration
: NULL
);
2047 wined3d_mutex_unlock();
2052 static HRESULT WINAPI
IDirect3DDevice9Impl_GetVertexDeclaration(IDirect3DDevice9Ex
*iface
,
2053 IDirect3DVertexDeclaration9
**declaration
)
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
= IWineD3DDevice_GetVertexDeclaration(((IDirect3DDevice9Impl
*)iface
)->WineD3DDevice
, &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((IDirect3DDevice9Ex
*) This
, elements
, &pDecl
);
2109 HeapFree(GetProcessHeap(), 0, elements
); /* CreateVertexDeclaration makes a copy */
2110 if (hr
!= S_OK
) return NULL
;
2112 if(This
->declArraySize
== This
->numConvertedDecls
) {
2113 int grow
= max(This
->declArraySize
/ 2, 8);
2114 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
2115 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
2116 if(!convertedDecls
) {
2117 /* This will destroy it */
2118 IDirect3DVertexDeclaration9_Release(pDecl
);
2121 This
->convertedDecls
= convertedDecls
;
2122 This
->declArraySize
+= grow
;
2125 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(IDirect3DVertexDeclaration9Impl
*) * (This
->numConvertedDecls
- low
));
2126 convertedDecls
[low
] = pDecl
;
2127 This
->numConvertedDecls
++;
2129 /* Will prevent the decl from being destroyed */
2130 ((IDirect3DVertexDeclaration9Impl
*) pDecl
)->convFVF
= fvf
;
2131 IDirect3DVertexDeclaration9_Release(pDecl
); /* Does not destroy now */
2133 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);
2137 static HRESULT WINAPI
IDirect3DDevice9Impl_SetFVF(LPDIRECT3DDEVICE9EX iface
, DWORD FVF
) {
2138 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
2139 IDirect3DVertexDeclaration9
*decl
;
2142 TRACE("iface %p, fvf %#x.\n", iface
, FVF
);
2146 WARN("%#x is not a valid FVF\n", FVF
);
2150 wined3d_mutex_lock();
2151 decl
= getConvertedDecl(This
, FVF
);
2152 wined3d_mutex_unlock();
2156 /* Any situation when this should happen, except out of memory? */
2157 ERR("Failed to create a converted vertex declaration\n");
2158 return D3DERR_DRIVERINTERNALERROR
;
2161 hr
= IDirect3DDevice9Impl_SetVertexDeclaration(iface
, decl
);
2162 if (FAILED(hr
)) ERR("Failed to set vertex declaration\n");
2167 static HRESULT WINAPI
IDirect3DDevice9Impl_GetFVF(IDirect3DDevice9Ex
*iface
, DWORD
*pFVF
)
2169 IDirect3DVertexDeclaration9
*decl
;
2172 TRACE("iface %p, fvf %p.\n", iface
, pFVF
);
2174 hr
= IDirect3DDevice9_GetVertexDeclaration(iface
, &decl
);
2177 WARN("Failed to get vertex declaration, %#x\n", hr
);
2184 *pFVF
= ((IDirect3DVertexDeclaration9Impl
*)decl
)->convFVF
;
2185 IDirect3DVertexDeclaration9_Release(decl
);
2192 TRACE("Returning FVF %#x\n", *pFVF
);
2197 static HRESULT WINAPI
IDirect3DDevice9Impl_CreateVertexShader(IDirect3DDevice9Ex
*iface
,
2198 const DWORD
*byte_code
, IDirect3DVertexShader9
**shader
)
2200 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
2201 IDirect3DVertexShader9Impl
*object
;
2204 TRACE("iface %p, byte_code %p, shader %p.\n", iface
, byte_code
, shader
);
2206 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2209 ERR("Failed to allocate vertex shader memory.\n");
2210 return E_OUTOFMEMORY
;
2213 hr
= vertexshader_init(object
, This
, byte_code
);
2216 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
2217 HeapFree(GetProcessHeap(), 0, object
);
2221 TRACE("Created vertex shader %p.\n", object
);
2222 *shader
= (IDirect3DVertexShader9
*)object
;
2227 static HRESULT WINAPI
IDirect3DDevice9Impl_SetVertexShader(IDirect3DDevice9Ex
*iface
,
2228 IDirect3DVertexShader9
*shader
)
2232 TRACE("iface %p, shader %p.\n", iface
, shader
);
2234 wined3d_mutex_lock();
2235 hr
= IWineD3DDevice_SetVertexShader(((IDirect3DDevice9Impl
*)iface
)->WineD3DDevice
,
2236 shader
? ((IDirect3DVertexShader9Impl
*)shader
)->wined3d_shader
: NULL
);
2237 wined3d_mutex_unlock();
2242 static HRESULT WINAPI
IDirect3DDevice9Impl_GetVertexShader(IDirect3DDevice9Ex
*iface
,
2243 IDirect3DVertexShader9
**shader
)
2245 struct wined3d_shader
*wined3d_shader
;
2247 TRACE("iface %p, shader %p.\n", iface
, shader
);
2249 wined3d_mutex_lock();
2250 wined3d_shader
= IWineD3DDevice_GetVertexShader(((IDirect3DDevice9Impl
*)iface
)->WineD3DDevice
);
2253 *shader
= wined3d_shader_get_parent(wined3d_shader
);
2254 IDirect3DVertexShader9_AddRef(*shader
);
2255 wined3d_shader_decref(wined3d_shader
);
2261 wined3d_mutex_unlock();
2263 TRACE("Returning %p.\n", *shader
);
2268 static HRESULT WINAPI
IDirect3DDevice9Impl_SetVertexShaderConstantF(IDirect3DDevice9Ex
*iface
,
2269 UINT reg_idx
, const float *data
, UINT count
)
2273 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2275 if (reg_idx
+ count
> D3D9_MAX_VERTEX_SHADER_CONSTANTF
)
2277 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
2278 reg_idx
+ count
, D3D9_MAX_VERTEX_SHADER_CONSTANTF
);
2279 return D3DERR_INVALIDCALL
;
2282 wined3d_mutex_lock();
2283 hr
= IWineD3DDevice_SetVertexShaderConstantF(((IDirect3DDevice9Impl
*)iface
)->WineD3DDevice
, reg_idx
, data
, count
);
2284 wined3d_mutex_unlock();
2289 static HRESULT WINAPI
IDirect3DDevice9Impl_GetVertexShaderConstantF(IDirect3DDevice9Ex
*iface
,
2290 UINT reg_idx
, float *data
, UINT count
)
2294 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2296 if (reg_idx
+ count
> D3D9_MAX_VERTEX_SHADER_CONSTANTF
)
2298 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
2299 reg_idx
+ count
, D3D9_MAX_VERTEX_SHADER_CONSTANTF
);
2300 return D3DERR_INVALIDCALL
;
2303 wined3d_mutex_lock();
2304 hr
= IWineD3DDevice_GetVertexShaderConstantF(((IDirect3DDevice9Impl
*)iface
)->WineD3DDevice
, reg_idx
, data
, count
);
2305 wined3d_mutex_unlock();
2310 static HRESULT WINAPI
IDirect3DDevice9Impl_SetVertexShaderConstantI(IDirect3DDevice9Ex
*iface
,
2311 UINT reg_idx
, const int *data
, UINT count
)
2315 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2317 wined3d_mutex_lock();
2318 hr
= IWineD3DDevice_SetVertexShaderConstantI(((IDirect3DDevice9Impl
*)iface
)->WineD3DDevice
, reg_idx
, data
, count
);
2319 wined3d_mutex_unlock();
2324 static HRESULT WINAPI
IDirect3DDevice9Impl_GetVertexShaderConstantI(IDirect3DDevice9Ex
*iface
,
2325 UINT reg_idx
, int *data
, UINT count
)
2329 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2331 wined3d_mutex_lock();
2332 hr
= IWineD3DDevice_GetVertexShaderConstantI(((IDirect3DDevice9Impl
*)iface
)->WineD3DDevice
, reg_idx
, data
, count
);
2333 wined3d_mutex_unlock();
2338 static HRESULT WINAPI
IDirect3DDevice9Impl_SetVertexShaderConstantB(IDirect3DDevice9Ex
*iface
,
2339 UINT reg_idx
, const BOOL
*data
, UINT count
)
2343 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2345 wined3d_mutex_lock();
2346 hr
= IWineD3DDevice_SetVertexShaderConstantB(((IDirect3DDevice9Impl
*)iface
)->WineD3DDevice
, reg_idx
, data
, count
);
2347 wined3d_mutex_unlock();
2352 static HRESULT WINAPI
IDirect3DDevice9Impl_GetVertexShaderConstantB(IDirect3DDevice9Ex
*iface
,
2353 UINT reg_idx
, BOOL
*data
, UINT count
)
2357 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2359 wined3d_mutex_lock();
2360 hr
= IWineD3DDevice_GetVertexShaderConstantB(((IDirect3DDevice9Impl
*)iface
)->WineD3DDevice
, reg_idx
, data
, count
);
2361 wined3d_mutex_unlock();
2366 static HRESULT WINAPI
IDirect3DDevice9Impl_SetStreamSource(LPDIRECT3DDEVICE9EX iface
, UINT StreamNumber
, IDirect3DVertexBuffer9
* pStreamData
, UINT OffsetInBytes
, UINT Stride
) {
2367 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
2370 TRACE("iface %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
2371 iface
, StreamNumber
, pStreamData
, OffsetInBytes
, Stride
);
2373 wined3d_mutex_lock();
2374 hr
= IWineD3DDevice_SetStreamSource(This
->WineD3DDevice
, StreamNumber
,
2375 pStreamData
? ((IDirect3DVertexBuffer9Impl
*)pStreamData
)->wineD3DVertexBuffer
: NULL
,
2376 OffsetInBytes
, Stride
);
2377 wined3d_mutex_unlock();
2382 static HRESULT WINAPI
IDirect3DDevice9Impl_GetStreamSource(IDirect3DDevice9Ex
*iface
,
2383 UINT StreamNumber
, IDirect3DVertexBuffer9
**pStream
, UINT
* OffsetInBytes
, UINT
* pStride
)
2385 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
2386 struct wined3d_buffer
*retStream
= NULL
;
2389 TRACE("iface %p, stream_idx %u, buffer %p, offset %p, stride %p.\n",
2390 iface
, StreamNumber
, pStream
, OffsetInBytes
, pStride
);
2392 if(pStream
== NULL
){
2393 return D3DERR_INVALIDCALL
;
2396 wined3d_mutex_lock();
2397 hr
= IWineD3DDevice_GetStreamSource(This
->WineD3DDevice
, StreamNumber
, &retStream
, OffsetInBytes
, pStride
);
2398 if (SUCCEEDED(hr
) && retStream
)
2400 *pStream
= wined3d_buffer_get_parent(retStream
);
2401 IDirect3DVertexBuffer9_AddRef(*pStream
);
2402 wined3d_buffer_decref(retStream
);
2408 FIXME("Call to GetStreamSource failed %p %p\n", OffsetInBytes
, pStride
);
2412 wined3d_mutex_unlock();
2417 static HRESULT WINAPI
IDirect3DDevice9Impl_SetStreamSourceFreq(IDirect3DDevice9Ex
*iface
, UINT StreamNumber
,
2420 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
2423 TRACE("iface %p, stream_idx %u, freq %u.\n", iface
, StreamNumber
, Divider
);
2425 wined3d_mutex_lock();
2426 hr
= IWineD3DDevice_SetStreamSourceFreq(This
->WineD3DDevice
, StreamNumber
, Divider
);
2427 wined3d_mutex_unlock();
2432 static HRESULT WINAPI
IDirect3DDevice9Impl_GetStreamSourceFreq(LPDIRECT3DDEVICE9EX iface
, UINT StreamNumber
, UINT
* Divider
) {
2433 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
2436 TRACE("iface %p, stream_idx %u, freq %p.\n", iface
, StreamNumber
, Divider
);
2438 wined3d_mutex_lock();
2439 hr
= IWineD3DDevice_GetStreamSourceFreq(This
->WineD3DDevice
, StreamNumber
, Divider
);
2440 wined3d_mutex_unlock();
2445 static HRESULT WINAPI
IDirect3DDevice9Impl_SetIndices(LPDIRECT3DDEVICE9EX iface
, IDirect3DIndexBuffer9
* pIndexData
) {
2446 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
2448 IDirect3DIndexBuffer9Impl
*ib
= (IDirect3DIndexBuffer9Impl
*) pIndexData
;
2450 TRACE("iface %p, buffer %p.\n", iface
, pIndexData
);
2452 wined3d_mutex_lock();
2453 hr
= IWineD3DDevice_SetIndexBuffer(This
->WineD3DDevice
,
2454 ib
? ib
->wineD3DIndexBuffer
: NULL
,
2455 ib
? ib
->format
: WINED3DFMT_UNKNOWN
);
2456 wined3d_mutex_unlock();
2461 static HRESULT WINAPI
IDirect3DDevice9Impl_GetIndices(IDirect3DDevice9Ex
*iface
, IDirect3DIndexBuffer9
**ppIndexData
)
2463 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
2464 struct wined3d_buffer
*retIndexData
= NULL
;
2467 TRACE("iface %p, buffer %p.\n", iface
, ppIndexData
);
2469 if(ppIndexData
== NULL
){
2470 return D3DERR_INVALIDCALL
;
2473 wined3d_mutex_lock();
2474 hr
= IWineD3DDevice_GetIndexBuffer(This
->WineD3DDevice
, &retIndexData
);
2475 if (SUCCEEDED(hr
) && retIndexData
)
2477 *ppIndexData
= wined3d_buffer_get_parent(retIndexData
);
2478 IDirect3DIndexBuffer9_AddRef(*ppIndexData
);
2479 wined3d_buffer_decref(retIndexData
);
2483 if (FAILED(hr
)) FIXME("Call to GetIndices failed\n");
2484 *ppIndexData
= NULL
;
2486 wined3d_mutex_unlock();
2491 static HRESULT WINAPI
IDirect3DDevice9Impl_CreatePixelShader(IDirect3DDevice9Ex
*iface
,
2492 const DWORD
*byte_code
, IDirect3DPixelShader9
**shader
)
2494 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
2495 IDirect3DPixelShader9Impl
*object
;
2498 TRACE("iface %p, byte_code %p, shader %p.\n", iface
, byte_code
, shader
);
2500 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2503 FIXME("Failed to allocate pixel shader memory.\n");
2504 return E_OUTOFMEMORY
;
2507 hr
= pixelshader_init(object
, This
, byte_code
);
2510 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
2511 HeapFree(GetProcessHeap(), 0, object
);
2515 TRACE("Created pixel shader %p.\n", object
);
2516 *shader
= (IDirect3DPixelShader9
*)object
;
2521 static HRESULT WINAPI
IDirect3DDevice9Impl_SetPixelShader(IDirect3DDevice9Ex
*iface
,
2522 IDirect3DPixelShader9
*shader
)
2526 TRACE("iface %p, shader %p.\n", iface
, shader
);
2528 wined3d_mutex_lock();
2529 hr
= IWineD3DDevice_SetPixelShader(((IDirect3DDevice9Impl
*)iface
)->WineD3DDevice
,
2530 shader
? ((IDirect3DPixelShader9Impl
*)shader
)->wined3d_shader
: NULL
);
2531 wined3d_mutex_unlock();
2536 static HRESULT WINAPI
IDirect3DDevice9Impl_GetPixelShader(IDirect3DDevice9Ex
*iface
,
2537 IDirect3DPixelShader9
**shader
)
2539 struct wined3d_shader
*wined3d_shader
;
2541 TRACE("iface %p, shader %p.\n", iface
, shader
);
2543 if (!shader
) return D3DERR_INVALIDCALL
;
2545 wined3d_mutex_lock();
2546 wined3d_shader
= IWineD3DDevice_GetPixelShader(((IDirect3DDevice9Impl
*)iface
)->WineD3DDevice
);
2549 *shader
= wined3d_shader_get_parent(wined3d_shader
);
2550 IDirect3DPixelShader9_AddRef(*shader
);
2551 wined3d_shader_decref(wined3d_shader
);
2557 wined3d_mutex_unlock();
2559 TRACE("Returning %p.\n", *shader
);
2564 static HRESULT WINAPI
IDirect3DDevice9Impl_SetPixelShaderConstantF(IDirect3DDevice9Ex
*iface
,
2565 UINT reg_idx
, const float *data
, UINT count
)
2569 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2571 wined3d_mutex_lock();
2572 hr
= IWineD3DDevice_SetPixelShaderConstantF(((IDirect3DDevice9Impl
*)iface
)->WineD3DDevice
, reg_idx
, data
, count
);
2573 wined3d_mutex_unlock();
2578 static HRESULT WINAPI
IDirect3DDevice9Impl_GetPixelShaderConstantF(IDirect3DDevice9Ex
*iface
,
2579 UINT reg_idx
, float *data
, UINT count
)
2583 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2585 wined3d_mutex_lock();
2586 hr
= IWineD3DDevice_GetPixelShaderConstantF(((IDirect3DDevice9Impl
*)iface
)->WineD3DDevice
, reg_idx
, data
, count
);
2587 wined3d_mutex_unlock();
2592 static HRESULT WINAPI
IDirect3DDevice9Impl_SetPixelShaderConstantI(IDirect3DDevice9Ex
*iface
,
2593 UINT reg_idx
, const int *data
, UINT count
)
2597 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2599 wined3d_mutex_lock();
2600 hr
= IWineD3DDevice_SetPixelShaderConstantI(((IDirect3DDevice9Impl
*)iface
)->WineD3DDevice
, reg_idx
, data
, count
);
2601 wined3d_mutex_unlock();
2606 static HRESULT WINAPI
IDirect3DDevice9Impl_GetPixelShaderConstantI(IDirect3DDevice9Ex
*iface
,
2607 UINT reg_idx
, int *data
, UINT count
)
2611 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2613 wined3d_mutex_lock();
2614 hr
= IWineD3DDevice_GetPixelShaderConstantI(((IDirect3DDevice9Impl
*)iface
)->WineD3DDevice
, reg_idx
, data
, count
);
2615 wined3d_mutex_unlock();
2620 static HRESULT WINAPI
IDirect3DDevice9Impl_SetPixelShaderConstantB(IDirect3DDevice9Ex
*iface
,
2621 UINT reg_idx
, const BOOL
*data
, UINT count
)
2625 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2627 wined3d_mutex_lock();
2628 hr
= IWineD3DDevice_SetPixelShaderConstantB(((IDirect3DDevice9Impl
*)iface
)->WineD3DDevice
, reg_idx
, data
, count
);
2629 wined3d_mutex_unlock();
2634 static HRESULT WINAPI
IDirect3DDevice9Impl_GetPixelShaderConstantB(IDirect3DDevice9Ex
*iface
,
2635 UINT reg_idx
, BOOL
*data
, UINT count
)
2639 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2641 wined3d_mutex_lock();
2642 hr
= IWineD3DDevice_GetPixelShaderConstantB(((IDirect3DDevice9Impl
*)iface
)->WineD3DDevice
, reg_idx
, data
, count
);
2643 wined3d_mutex_unlock();
2648 static HRESULT WINAPI
IDirect3DDevice9Impl_DrawRectPatch(LPDIRECT3DDEVICE9EX iface
, UINT Handle
, CONST
float* pNumSegs
, CONST D3DRECTPATCH_INFO
* pRectPatchInfo
) {
2649 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
2652 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2653 iface
, Handle
, pNumSegs
, pRectPatchInfo
);
2655 wined3d_mutex_lock();
2656 hr
= IWineD3DDevice_DrawRectPatch(This
->WineD3DDevice
, Handle
, pNumSegs
, (CONST WINED3DRECTPATCH_INFO
*)pRectPatchInfo
);
2657 wined3d_mutex_unlock();
2662 static HRESULT WINAPI
IDirect3DDevice9Impl_DrawTriPatch(LPDIRECT3DDEVICE9EX iface
, UINT Handle
, CONST
float* pNumSegs
, CONST D3DTRIPATCH_INFO
* pTriPatchInfo
) {
2663 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
2666 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2667 iface
, Handle
, pNumSegs
, pTriPatchInfo
);
2669 wined3d_mutex_lock();
2670 hr
= IWineD3DDevice_DrawTriPatch(This
->WineD3DDevice
, Handle
, pNumSegs
, (CONST WINED3DTRIPATCH_INFO
*)pTriPatchInfo
);
2671 wined3d_mutex_unlock();
2676 static HRESULT WINAPI
IDirect3DDevice9Impl_DeletePatch(LPDIRECT3DDEVICE9EX iface
, UINT Handle
) {
2677 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
2680 TRACE("iface %p, handle %#x.\n", iface
, Handle
);
2682 wined3d_mutex_lock();
2683 hr
= IWineD3DDevice_DeletePatch(This
->WineD3DDevice
, Handle
);
2684 wined3d_mutex_unlock();
2689 static HRESULT WINAPI
IDirect3DDevice9Impl_CreateQuery(IDirect3DDevice9Ex
*iface
,
2690 D3DQUERYTYPE type
, IDirect3DQuery9
**query
)
2692 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
2693 IDirect3DQuery9Impl
*object
;
2696 TRACE("iface %p, type %#x, query %p.\n", iface
, type
, query
);
2698 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2701 ERR("Failed to allocate query memory.\n");
2702 return E_OUTOFMEMORY
;
2705 hr
= query_init(object
, This
, type
);
2708 WARN("Failed to initialize query, hr %#x.\n", hr
);
2709 HeapFree(GetProcessHeap(), 0, object
);
2713 TRACE("Created query %p.\n", object
);
2714 if (query
) *query
= (IDirect3DQuery9
*)object
;
2715 else IDirect3DQuery9_Release((IDirect3DQuery9
*)object
);
2720 static HRESULT WINAPI
IDirect3DDevice9ExImpl_SetConvolutionMonoKernel(IDirect3DDevice9Ex
*iface
,
2721 UINT width
, UINT height
, float *rows
, float *columns
)
2723 FIXME("iface %p, width %u, height %u, rows %p, columns %p stub!\n",
2724 iface
, width
, height
, rows
, columns
);
2729 static HRESULT WINAPI
IDirect3DDevice9ExImpl_ComposeRects(IDirect3DDevice9Ex
*iface
,
2730 IDirect3DSurface9
*src_surface
, IDirect3DSurface9
*dst_surface
, IDirect3DVertexBuffer9
*src_descs
,
2731 UINT rect_count
, IDirect3DVertexBuffer9
*dst_descs
, D3DCOMPOSERECTSOP operation
, INT offset_x
, INT offset_y
)
2733 FIXME("iface %p, src_surface %p, dst_surface %p, src_descs %p, rect_count %u,\n"
2734 "dst_descs %p, operation %#x, offset_x %u, offset_y %u stub!\n",
2735 iface
, src_surface
, dst_surface
, src_descs
, rect_count
,
2736 dst_descs
, operation
, offset_x
, offset_y
);
2741 static HRESULT WINAPI
IDirect3DDevice9ExImpl_PresentEx(IDirect3DDevice9Ex
*iface
,
2742 const RECT
*src_rect
, const RECT
*dst_rect
, HWND dst_window_override
,
2743 const RGNDATA
*dirty_region
, DWORD flags
)
2745 FIXME("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p, flags %#x stub!\n",
2746 iface
, src_rect
, dst_rect
, dst_window_override
, dirty_region
, flags
);
2751 static HRESULT WINAPI
IDirect3DDevice9ExImpl_GetGPUThreadPriority(IDirect3DDevice9Ex
*iface
, INT
*priority
)
2753 FIXME("iface %p, priority %p stub!\n", iface
, priority
);
2758 static HRESULT WINAPI
IDirect3DDevice9ExImpl_SetGPUThreadPriority(IDirect3DDevice9Ex
*iface
, INT priority
)
2760 FIXME("iface %p, priority %d stub!\n", iface
, priority
);
2765 static HRESULT WINAPI
IDirect3DDevice9ExImpl_WaitForVBlank(IDirect3DDevice9Ex
*iface
, UINT swapchain_idx
)
2767 FIXME("iface %p, swapchain_idx %u stub!\n", iface
, swapchain_idx
);
2772 static HRESULT WINAPI
IDirect3DDevice9ExImpl_CheckResourceResidency(IDirect3DDevice9Ex
*iface
,
2773 IDirect3DResource9
**resources
, UINT32 resource_count
)
2775 FIXME("iface %p, resources %p, resource_count %u stub!\n",
2776 iface
, resources
, resource_count
);
2781 static HRESULT WINAPI
IDirect3DDevice9ExImpl_SetMaximumFrameLatency(IDirect3DDevice9Ex
*iface
, UINT max_latency
)
2783 FIXME("iface %p, max_latency %u stub!\n", iface
, max_latency
);
2788 static HRESULT WINAPI
IDirect3DDevice9ExImpl_GetMaximumFrameLatency(IDirect3DDevice9Ex
*iface
, UINT
*max_latency
)
2790 FIXME("iface %p, max_latency %p stub!\n", iface
, max_latency
);
2797 static HRESULT WINAPI
IDirect3DDevice9ExImpl_CheckDeviceState(IDirect3DDevice9Ex
*iface
, HWND dst_window
)
2801 TRACE("iface %p, dst_window %p stub!\n", iface
, dst_window
);
2804 FIXME("iface %p, dst_window %p stub!\n", iface
, dst_window
);
2809 static HRESULT WINAPI
IDirect3DDevice9ExImpl_CreateRenderTargetEx(IDirect3DDevice9Ex
*iface
,
2810 UINT width
, UINT height
, D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
2811 BOOL lockable
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
, DWORD usage
)
2813 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
2814 "lockable %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2815 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
2816 lockable
, surface
, shared_handle
, usage
);
2821 static HRESULT WINAPI
IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx(IDirect3DDevice9Ex
*iface
,
2822 UINT width
, UINT height
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DSurface9
**surface
,
2823 HANDLE
*shared_handle
, DWORD usage
)
2825 FIXME("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2826 iface
, width
, height
, format
, pool
, surface
, shared_handle
, usage
);
2831 static HRESULT WINAPI
IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx(IDirect3DDevice9Ex
*iface
,
2832 UINT width
, UINT height
, D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
2833 BOOL discard
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
, DWORD usage
)
2835 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
2836 "discard %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2837 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
2838 discard
, surface
, shared_handle
, usage
);
2843 static HRESULT WINAPI
IDirect3DDevice9ExImpl_ResetEx(IDirect3DDevice9Ex
*iface
,
2844 D3DPRESENT_PARAMETERS
*present_parameters
, D3DDISPLAYMODEEX
*mode
)
2846 FIXME("iface %p, present_parameters %p, mode %p stub!\n", iface
, present_parameters
, mode
);
2851 static HRESULT WINAPI
IDirect3DDevice9ExImpl_GetDisplayModeEx(IDirect3DDevice9Ex
*iface
,
2852 UINT swapchain_idx
, D3DDISPLAYMODEEX
*mode
, D3DDISPLAYROTATION
*rotation
)
2854 FIXME("iface %p, swapchain_idx %u, mode %p, rotation %p stub!\n", iface
, swapchain_idx
, mode
, rotation
);
2859 static const IDirect3DDevice9ExVtbl Direct3DDevice9_Vtbl
=
2862 IDirect3DDevice9Impl_QueryInterface
,
2863 IDirect3DDevice9Impl_AddRef
,
2864 IDirect3DDevice9Impl_Release
,
2865 /* IDirect3DDevice9 */
2866 IDirect3DDevice9Impl_TestCooperativeLevel
,
2867 IDirect3DDevice9Impl_GetAvailableTextureMem
,
2868 IDirect3DDevice9Impl_EvictManagedResources
,
2869 IDirect3DDevice9Impl_GetDirect3D
,
2870 IDirect3DDevice9Impl_GetDeviceCaps
,
2871 IDirect3DDevice9Impl_GetDisplayMode
,
2872 IDirect3DDevice9Impl_GetCreationParameters
,
2873 IDirect3DDevice9Impl_SetCursorProperties
,
2874 IDirect3DDevice9Impl_SetCursorPosition
,
2875 IDirect3DDevice9Impl_ShowCursor
,
2876 IDirect3DDevice9Impl_CreateAdditionalSwapChain
,
2877 IDirect3DDevice9Impl_GetSwapChain
,
2878 IDirect3DDevice9Impl_GetNumberOfSwapChains
,
2879 IDirect3DDevice9Impl_Reset
,
2880 IDirect3DDevice9Impl_Present
,
2881 IDirect3DDevice9Impl_GetBackBuffer
,
2882 IDirect3DDevice9Impl_GetRasterStatus
,
2883 IDirect3DDevice9Impl_SetDialogBoxMode
,
2884 IDirect3DDevice9Impl_SetGammaRamp
,
2885 IDirect3DDevice9Impl_GetGammaRamp
,
2886 IDirect3DDevice9Impl_CreateTexture
,
2887 IDirect3DDevice9Impl_CreateVolumeTexture
,
2888 IDirect3DDevice9Impl_CreateCubeTexture
,
2889 IDirect3DDevice9Impl_CreateVertexBuffer
,
2890 IDirect3DDevice9Impl_CreateIndexBuffer
,
2891 IDirect3DDevice9Impl_CreateRenderTarget
,
2892 IDirect3DDevice9Impl_CreateDepthStencilSurface
,
2893 IDirect3DDevice9Impl_UpdateSurface
,
2894 IDirect3DDevice9Impl_UpdateTexture
,
2895 IDirect3DDevice9Impl_GetRenderTargetData
,
2896 IDirect3DDevice9Impl_GetFrontBufferData
,
2897 IDirect3DDevice9Impl_StretchRect
,
2898 IDirect3DDevice9Impl_ColorFill
,
2899 IDirect3DDevice9Impl_CreateOffscreenPlainSurface
,
2900 IDirect3DDevice9Impl_SetRenderTarget
,
2901 IDirect3DDevice9Impl_GetRenderTarget
,
2902 IDirect3DDevice9Impl_SetDepthStencilSurface
,
2903 IDirect3DDevice9Impl_GetDepthStencilSurface
,
2904 IDirect3DDevice9Impl_BeginScene
,
2905 IDirect3DDevice9Impl_EndScene
,
2906 IDirect3DDevice9Impl_Clear
,
2907 IDirect3DDevice9Impl_SetTransform
,
2908 IDirect3DDevice9Impl_GetTransform
,
2909 IDirect3DDevice9Impl_MultiplyTransform
,
2910 IDirect3DDevice9Impl_SetViewport
,
2911 IDirect3DDevice9Impl_GetViewport
,
2912 IDirect3DDevice9Impl_SetMaterial
,
2913 IDirect3DDevice9Impl_GetMaterial
,
2914 IDirect3DDevice9Impl_SetLight
,
2915 IDirect3DDevice9Impl_GetLight
,
2916 IDirect3DDevice9Impl_LightEnable
,
2917 IDirect3DDevice9Impl_GetLightEnable
,
2918 IDirect3DDevice9Impl_SetClipPlane
,
2919 IDirect3DDevice9Impl_GetClipPlane
,
2920 IDirect3DDevice9Impl_SetRenderState
,
2921 IDirect3DDevice9Impl_GetRenderState
,
2922 IDirect3DDevice9Impl_CreateStateBlock
,
2923 IDirect3DDevice9Impl_BeginStateBlock
,
2924 IDirect3DDevice9Impl_EndStateBlock
,
2925 IDirect3DDevice9Impl_SetClipStatus
,
2926 IDirect3DDevice9Impl_GetClipStatus
,
2927 IDirect3DDevice9Impl_GetTexture
,
2928 IDirect3DDevice9Impl_SetTexture
,
2929 IDirect3DDevice9Impl_GetTextureStageState
,
2930 IDirect3DDevice9Impl_SetTextureStageState
,
2931 IDirect3DDevice9Impl_GetSamplerState
,
2932 IDirect3DDevice9Impl_SetSamplerState
,
2933 IDirect3DDevice9Impl_ValidateDevice
,
2934 IDirect3DDevice9Impl_SetPaletteEntries
,
2935 IDirect3DDevice9Impl_GetPaletteEntries
,
2936 IDirect3DDevice9Impl_SetCurrentTexturePalette
,
2937 IDirect3DDevice9Impl_GetCurrentTexturePalette
,
2938 IDirect3DDevice9Impl_SetScissorRect
,
2939 IDirect3DDevice9Impl_GetScissorRect
,
2940 IDirect3DDevice9Impl_SetSoftwareVertexProcessing
,
2941 IDirect3DDevice9Impl_GetSoftwareVertexProcessing
,
2942 IDirect3DDevice9Impl_SetNPatchMode
,
2943 IDirect3DDevice9Impl_GetNPatchMode
,
2944 IDirect3DDevice9Impl_DrawPrimitive
,
2945 IDirect3DDevice9Impl_DrawIndexedPrimitive
,
2946 IDirect3DDevice9Impl_DrawPrimitiveUP
,
2947 IDirect3DDevice9Impl_DrawIndexedPrimitiveUP
,
2948 IDirect3DDevice9Impl_ProcessVertices
,
2949 IDirect3DDevice9Impl_CreateVertexDeclaration
,
2950 IDirect3DDevice9Impl_SetVertexDeclaration
,
2951 IDirect3DDevice9Impl_GetVertexDeclaration
,
2952 IDirect3DDevice9Impl_SetFVF
,
2953 IDirect3DDevice9Impl_GetFVF
,
2954 IDirect3DDevice9Impl_CreateVertexShader
,
2955 IDirect3DDevice9Impl_SetVertexShader
,
2956 IDirect3DDevice9Impl_GetVertexShader
,
2957 IDirect3DDevice9Impl_SetVertexShaderConstantF
,
2958 IDirect3DDevice9Impl_GetVertexShaderConstantF
,
2959 IDirect3DDevice9Impl_SetVertexShaderConstantI
,
2960 IDirect3DDevice9Impl_GetVertexShaderConstantI
,
2961 IDirect3DDevice9Impl_SetVertexShaderConstantB
,
2962 IDirect3DDevice9Impl_GetVertexShaderConstantB
,
2963 IDirect3DDevice9Impl_SetStreamSource
,
2964 IDirect3DDevice9Impl_GetStreamSource
,
2965 IDirect3DDevice9Impl_SetStreamSourceFreq
,
2966 IDirect3DDevice9Impl_GetStreamSourceFreq
,
2967 IDirect3DDevice9Impl_SetIndices
,
2968 IDirect3DDevice9Impl_GetIndices
,
2969 IDirect3DDevice9Impl_CreatePixelShader
,
2970 IDirect3DDevice9Impl_SetPixelShader
,
2971 IDirect3DDevice9Impl_GetPixelShader
,
2972 IDirect3DDevice9Impl_SetPixelShaderConstantF
,
2973 IDirect3DDevice9Impl_GetPixelShaderConstantF
,
2974 IDirect3DDevice9Impl_SetPixelShaderConstantI
,
2975 IDirect3DDevice9Impl_GetPixelShaderConstantI
,
2976 IDirect3DDevice9Impl_SetPixelShaderConstantB
,
2977 IDirect3DDevice9Impl_GetPixelShaderConstantB
,
2978 IDirect3DDevice9Impl_DrawRectPatch
,
2979 IDirect3DDevice9Impl_DrawTriPatch
,
2980 IDirect3DDevice9Impl_DeletePatch
,
2981 IDirect3DDevice9Impl_CreateQuery
,
2982 /* IDirect3DDevice9Ex */
2983 IDirect3DDevice9ExImpl_SetConvolutionMonoKernel
,
2984 IDirect3DDevice9ExImpl_ComposeRects
,
2985 IDirect3DDevice9ExImpl_PresentEx
,
2986 IDirect3DDevice9ExImpl_GetGPUThreadPriority
,
2987 IDirect3DDevice9ExImpl_SetGPUThreadPriority
,
2988 IDirect3DDevice9ExImpl_WaitForVBlank
,
2989 IDirect3DDevice9ExImpl_CheckResourceResidency
,
2990 IDirect3DDevice9ExImpl_SetMaximumFrameLatency
,
2991 IDirect3DDevice9ExImpl_GetMaximumFrameLatency
,
2992 IDirect3DDevice9ExImpl_CheckDeviceState
,
2993 IDirect3DDevice9ExImpl_CreateRenderTargetEx
,
2994 IDirect3DDevice9ExImpl_CreateOffscreenPlainSurfaceEx
,
2995 IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx
,
2996 IDirect3DDevice9ExImpl_ResetEx
,
2997 IDirect3DDevice9ExImpl_GetDisplayModeEx
3000 /* IWineD3DDeviceParent IUnknown methods */
3002 static inline struct IDirect3DDevice9Impl
*device_from_device_parent(IWineD3DDeviceParent
*iface
)
3004 return (struct IDirect3DDevice9Impl
*)((char*)iface
3005 - FIELD_OFFSET(struct IDirect3DDevice9Impl
, device_parent_vtbl
));
3008 static HRESULT STDMETHODCALLTYPE
device_parent_QueryInterface(IWineD3DDeviceParent
*iface
, REFIID riid
, void **object
)
3010 struct IDirect3DDevice9Impl
*This
= device_from_device_parent(iface
);
3011 return IDirect3DDevice9Impl_QueryInterface((IDirect3DDevice9Ex
*)This
, riid
, object
);
3014 static ULONG STDMETHODCALLTYPE
device_parent_AddRef(IWineD3DDeviceParent
*iface
)
3016 struct IDirect3DDevice9Impl
*This
= device_from_device_parent(iface
);
3017 return IDirect3DDevice9Impl_AddRef((IDirect3DDevice9Ex
*)This
);
3020 static ULONG STDMETHODCALLTYPE
device_parent_Release(IWineD3DDeviceParent
*iface
)
3022 struct IDirect3DDevice9Impl
*This
= device_from_device_parent(iface
);
3023 return IDirect3DDevice9Impl_Release((IDirect3DDevice9Ex
*)This
);
3026 /* IWineD3DDeviceParent methods */
3028 static void STDMETHODCALLTYPE
device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent
*iface
, IWineD3DDevice
*device
)
3030 TRACE("iface %p, device %p\n", iface
, device
);
3033 static HRESULT STDMETHODCALLTYPE
device_parent_CreateSurface(IWineD3DDeviceParent
*iface
,
3034 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
, DWORD usage
,
3035 WINED3DPOOL pool
, UINT level
, WINED3DCUBEMAP_FACES face
, IWineD3DSurface
**surface
)
3037 struct IDirect3DDevice9Impl
*This
= device_from_device_parent(iface
);
3038 IDirect3DSurface9Impl
*d3d_surface
;
3039 BOOL lockable
= TRUE
;
3042 TRACE("iface %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
3043 "\tpool %#x, level %u, face %u, surface %p\n",
3044 iface
, container_parent
, width
, height
, format
, usage
, pool
, level
, face
, surface
);
3046 if (pool
== WINED3DPOOL_DEFAULT
&& !(usage
& D3DUSAGE_DYNAMIC
))
3049 hr
= IDirect3DDevice9Impl_CreateSurface((IDirect3DDevice9Ex
*)This
, width
, height
,
3050 d3dformat_from_wined3dformat(format
), lockable
, FALSE
/* Discard */, level
,
3051 (IDirect3DSurface9
**)&d3d_surface
, usage
, pool
, D3DMULTISAMPLE_NONE
, 0 /* MultisampleQuality */);
3054 ERR("(%p) CreateSurface failed, returning %#x\n", iface
, hr
);
3058 *surface
= d3d_surface
->wineD3DSurface
;
3059 IWineD3DSurface_AddRef(*surface
);
3061 d3d_surface
->container
= container_parent
;
3062 IDirect3DDevice9Ex_Release(d3d_surface
->parentDevice
);
3063 d3d_surface
->parentDevice
= NULL
;
3065 IDirect3DSurface9_Release((IDirect3DSurface9
*)d3d_surface
);
3066 d3d_surface
->forwardReference
= container_parent
;
3071 static HRESULT STDMETHODCALLTYPE
device_parent_CreateRenderTarget(IWineD3DDeviceParent
*iface
,
3072 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
,
3073 WINED3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
, BOOL lockable
,
3074 IWineD3DSurface
**surface
)
3076 struct IDirect3DDevice9Impl
*This
= device_from_device_parent(iface
);
3077 IDirect3DSurface9Impl
*d3d_surface
;
3080 TRACE("iface %p, container_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n"
3081 "\tmultisample_quality %u, lockable %u, surface %p\n",
3082 iface
, container_parent
, width
, height
, format
, multisample_type
, multisample_quality
, lockable
, surface
);
3084 hr
= IDirect3DDevice9Impl_CreateRenderTarget((IDirect3DDevice9Ex
*)This
, width
, height
,
3085 d3dformat_from_wined3dformat(format
), multisample_type
, multisample_quality
, lockable
,
3086 (IDirect3DSurface9
**)&d3d_surface
, NULL
);
3089 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface
, hr
);
3093 *surface
= d3d_surface
->wineD3DSurface
;
3094 IWineD3DSurface_AddRef(*surface
);
3096 d3d_surface
->container
= container_parent
;
3097 /* Implicit surfaces are created with an refcount of 0 */
3098 IDirect3DSurface9_Release((IDirect3DSurface9
*)d3d_surface
);
3103 static HRESULT STDMETHODCALLTYPE
device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent
*iface
,
3104 UINT width
, UINT height
, enum wined3d_format_id format
, WINED3DMULTISAMPLE_TYPE multisample_type
,
3105 DWORD multisample_quality
, BOOL discard
, IWineD3DSurface
**surface
)
3107 struct IDirect3DDevice9Impl
*This
= device_from_device_parent(iface
);
3108 IDirect3DSurface9Impl
*d3d_surface
;
3111 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x,\n"
3112 "\tmultisample_quality %u, discard %u, surface %p\n",
3113 iface
, width
, height
, format
, multisample_type
, multisample_quality
, discard
, surface
);
3115 hr
= IDirect3DDevice9Impl_CreateDepthStencilSurface((IDirect3DDevice9Ex
*)This
, width
, height
,
3116 d3dformat_from_wined3dformat(format
), multisample_type
, multisample_quality
, discard
,
3117 (IDirect3DSurface9
**)&d3d_surface
, NULL
);
3120 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface
, hr
);
3124 *surface
= d3d_surface
->wineD3DSurface
;
3125 IWineD3DSurface_AddRef(*surface
);
3126 d3d_surface
->container
= (IUnknown
*)This
;
3127 /* Implicit surfaces are created with an refcount of 0 */
3128 IDirect3DSurface9_Release((IDirect3DSurface9
*)d3d_surface
);
3133 static HRESULT STDMETHODCALLTYPE
device_parent_CreateVolume(IWineD3DDeviceParent
*iface
,
3134 void *container_parent
, UINT width
, UINT height
, UINT depth
, enum wined3d_format_id format
,
3135 WINED3DPOOL pool
, DWORD usage
, IWineD3DVolume
**volume
)
3137 struct IDirect3DDevice9Impl
*This
= device_from_device_parent(iface
);
3138 IDirect3DVolume9Impl
*object
;
3141 TRACE("iface %p, container_parent %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
3142 iface
, container_parent
, width
, height
, depth
, format
, pool
, usage
, volume
);
3144 /* Allocate the storage for the device */
3145 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3148 FIXME("Allocation of memory failed\n");
3150 return D3DERR_OUTOFVIDEOMEMORY
;
3153 hr
= volume_init(object
, This
, width
, height
, depth
, usage
, format
, pool
);
3156 WARN("Failed to initialize volume, hr %#x.\n", hr
);
3157 HeapFree(GetProcessHeap(), 0, object
);
3161 *volume
= object
->wineD3DVolume
;
3162 IWineD3DVolume_AddRef(*volume
);
3163 IDirect3DVolume9_Release((IDirect3DVolume9
*)object
);
3165 object
->container
= container_parent
;
3166 object
->forwardReference
= container_parent
;
3168 TRACE("(%p) Created volume %p\n", iface
, object
);
3173 static HRESULT STDMETHODCALLTYPE
device_parent_CreateSwapChain(IWineD3DDeviceParent
*iface
,
3174 WINED3DPRESENT_PARAMETERS
*present_parameters
, IWineD3DSwapChain
**swapchain
)
3176 struct IDirect3DDevice9Impl
*This
= device_from_device_parent(iface
);
3177 IDirect3DSwapChain9Impl
*d3d_swapchain
;
3178 D3DPRESENT_PARAMETERS local_parameters
;
3181 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface
, present_parameters
, swapchain
);
3183 /* Copy the presentation parameters */
3184 local_parameters
.BackBufferWidth
= present_parameters
->BackBufferWidth
;
3185 local_parameters
.BackBufferHeight
= present_parameters
->BackBufferHeight
;
3186 local_parameters
.BackBufferFormat
= d3dformat_from_wined3dformat(present_parameters
->BackBufferFormat
);
3187 local_parameters
.BackBufferCount
= present_parameters
->BackBufferCount
;
3188 local_parameters
.MultiSampleType
= present_parameters
->MultiSampleType
;
3189 local_parameters
.MultiSampleQuality
= present_parameters
->MultiSampleQuality
;
3190 local_parameters
.SwapEffect
= present_parameters
->SwapEffect
;
3191 local_parameters
.hDeviceWindow
= present_parameters
->hDeviceWindow
;
3192 local_parameters
.Windowed
= present_parameters
->Windowed
;
3193 local_parameters
.EnableAutoDepthStencil
= present_parameters
->EnableAutoDepthStencil
;
3194 local_parameters
.AutoDepthStencilFormat
= d3dformat_from_wined3dformat(present_parameters
->AutoDepthStencilFormat
);
3195 local_parameters
.Flags
= present_parameters
->Flags
;
3196 local_parameters
.FullScreen_RefreshRateInHz
= present_parameters
->FullScreen_RefreshRateInHz
;
3197 local_parameters
.PresentationInterval
= present_parameters
->PresentationInterval
;
3199 hr
= IDirect3DDevice9Impl_CreateAdditionalSwapChain((IDirect3DDevice9Ex
*)This
,
3200 &local_parameters
, (IDirect3DSwapChain9
**)&d3d_swapchain
);
3203 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface
, hr
);
3208 *swapchain
= d3d_swapchain
->wineD3DSwapChain
;
3209 d3d_swapchain
->isImplicit
= TRUE
;
3210 /* Implicit swap chains are created with an refcount of 0 */
3211 IDirect3DSwapChain9_Release((IDirect3DSwapChain9
*)d3d_swapchain
);
3213 /* Copy back the presentation parameters */
3214 present_parameters
->BackBufferWidth
= local_parameters
.BackBufferWidth
;
3215 present_parameters
->BackBufferHeight
= local_parameters
.BackBufferHeight
;
3216 present_parameters
->BackBufferFormat
= wined3dformat_from_d3dformat(local_parameters
.BackBufferFormat
);
3217 present_parameters
->BackBufferCount
= local_parameters
.BackBufferCount
;
3218 present_parameters
->MultiSampleType
= local_parameters
.MultiSampleType
;
3219 present_parameters
->MultiSampleQuality
= local_parameters
.MultiSampleQuality
;
3220 present_parameters
->SwapEffect
= local_parameters
.SwapEffect
;
3221 present_parameters
->hDeviceWindow
= local_parameters
.hDeviceWindow
;
3222 present_parameters
->Windowed
= local_parameters
.Windowed
;
3223 present_parameters
->EnableAutoDepthStencil
= local_parameters
.EnableAutoDepthStencil
;
3224 present_parameters
->AutoDepthStencilFormat
= wined3dformat_from_d3dformat(local_parameters
.AutoDepthStencilFormat
);
3225 present_parameters
->Flags
= local_parameters
.Flags
;
3226 present_parameters
->FullScreen_RefreshRateInHz
= local_parameters
.FullScreen_RefreshRateInHz
;
3227 present_parameters
->PresentationInterval
= local_parameters
.PresentationInterval
;
3232 static const IWineD3DDeviceParentVtbl d3d9_wined3d_device_parent_vtbl
=
3234 /* IUnknown methods */
3235 device_parent_QueryInterface
,
3236 device_parent_AddRef
,
3237 device_parent_Release
,
3238 /* IWineD3DDeviceParent methods */
3239 device_parent_WineD3DDeviceCreated
,
3240 device_parent_CreateSurface
,
3241 device_parent_CreateRenderTarget
,
3242 device_parent_CreateDepthStencilSurface
,
3243 device_parent_CreateVolume
,
3244 device_parent_CreateSwapChain
,
3247 static void setup_fpu(void)
3249 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3251 __asm__
volatile ("fnstcw %0" : "=m" (cw
));
3252 cw
= (cw
& ~0xf3f) | 0x3f;
3253 __asm__
volatile ("fldcw %0" : : "m" (cw
));
3255 FIXME("FPU setup not implemented for this platform.\n");
3259 HRESULT
device_init(IDirect3DDevice9Impl
*device
, struct wined3d
*wined3d
, UINT adapter
, D3DDEVTYPE device_type
,
3260 HWND focus_window
, DWORD flags
, D3DPRESENT_PARAMETERS
*parameters
, D3DDISPLAYMODEEX
*mode
)
3262 WINED3DPRESENT_PARAMETERS
*wined3d_parameters
;
3267 FIXME("Ignoring display mode.\n");
3269 device
->lpVtbl
= &Direct3DDevice9_Vtbl
;
3270 device
->device_parent_vtbl
= &d3d9_wined3d_device_parent_vtbl
;
3273 if (!(flags
& D3DCREATE_FPU_PRESERVE
)) setup_fpu();
3275 wined3d_mutex_lock();
3276 hr
= wined3d_device_create(wined3d
, adapter
, device_type
, focus_window
, flags
,
3277 (IWineD3DDeviceParent
*)&device
->device_parent_vtbl
, &device
->WineD3DDevice
);
3280 WARN("Failed to create wined3d device, hr %#x.\n", hr
);
3281 wined3d_mutex_unlock();
3285 if (flags
& D3DCREATE_ADAPTERGROUP_DEVICE
)
3289 wined3d_get_device_caps(wined3d
, adapter
, device_type
, &caps
);
3290 count
= caps
.NumberOfAdaptersInGroup
;
3293 if (flags
& D3DCREATE_MULTITHREADED
) IWineD3DDevice_SetMultithreaded(device
->WineD3DDevice
);
3295 if (!parameters
->Windowed
)
3297 if (!focus_window
) focus_window
= parameters
->hDeviceWindow
;
3298 if (FAILED(hr
= IWineD3DDevice_AcquireFocusWindow(device
->WineD3DDevice
, focus_window
)))
3300 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
3301 IWineD3DDevice_Release(device
->WineD3DDevice
);
3302 wined3d_mutex_unlock();
3306 for (i
= 0; i
< count
; ++i
)
3308 HWND device_window
= parameters
[i
].hDeviceWindow
;
3310 if (!device_window
) device_window
= focus_window
;
3311 IWineD3DDevice_SetupFullscreenWindow(device
->WineD3DDevice
, device_window
,
3312 parameters
[i
].BackBufferWidth
,
3313 parameters
[i
].BackBufferHeight
);
3317 wined3d_parameters
= HeapAlloc(GetProcessHeap(), 0, sizeof(*wined3d_parameters
) * count
);
3318 if (!wined3d_parameters
)
3320 ERR("Failed to allocate wined3d parameters.\n");
3321 IWineD3DDevice_Release(device
->WineD3DDevice
);
3322 wined3d_mutex_unlock();
3323 return E_OUTOFMEMORY
;
3326 for (i
= 0; i
< count
; ++i
)
3328 wined3d_parameters
[i
].BackBufferWidth
= parameters
[i
].BackBufferWidth
;
3329 wined3d_parameters
[i
].BackBufferHeight
= parameters
[i
].BackBufferHeight
;
3330 wined3d_parameters
[i
].BackBufferFormat
= wined3dformat_from_d3dformat(parameters
[i
].BackBufferFormat
);
3331 wined3d_parameters
[i
].BackBufferCount
= parameters
[i
].BackBufferCount
;
3332 wined3d_parameters
[i
].MultiSampleType
= parameters
[i
].MultiSampleType
;
3333 wined3d_parameters
[i
].MultiSampleQuality
= parameters
[i
].MultiSampleQuality
;
3334 wined3d_parameters
[i
].SwapEffect
= parameters
[i
].SwapEffect
;
3335 wined3d_parameters
[i
].hDeviceWindow
= parameters
[i
].hDeviceWindow
;
3336 wined3d_parameters
[i
].Windowed
= parameters
[i
].Windowed
;
3337 wined3d_parameters
[i
].EnableAutoDepthStencil
= parameters
[i
].EnableAutoDepthStencil
;
3338 wined3d_parameters
[i
].AutoDepthStencilFormat
=
3339 wined3dformat_from_d3dformat(parameters
[i
].AutoDepthStencilFormat
);
3340 wined3d_parameters
[i
].Flags
= parameters
[i
].Flags
;
3341 wined3d_parameters
[i
].FullScreen_RefreshRateInHz
= parameters
[i
].FullScreen_RefreshRateInHz
;
3342 wined3d_parameters
[i
].PresentationInterval
= parameters
[i
].PresentationInterval
;
3343 wined3d_parameters
[i
].AutoRestoreDisplayMode
= TRUE
;
3346 hr
= IWineD3DDevice_Init3D(device
->WineD3DDevice
, wined3d_parameters
);
3349 WARN("Failed to initialize 3D, hr %#x.\n", hr
);
3350 IWineD3DDevice_ReleaseFocusWindow(device
->WineD3DDevice
);
3351 HeapFree(GetProcessHeap(), 0, wined3d_parameters
);
3352 IWineD3DDevice_Release(device
->WineD3DDevice
);
3353 wined3d_mutex_unlock();
3357 wined3d_mutex_unlock();
3359 for (i
= 0; i
< count
; ++i
)
3361 parameters
[i
].BackBufferWidth
= wined3d_parameters
[i
].BackBufferWidth
;
3362 parameters
[i
].BackBufferHeight
= wined3d_parameters
[i
].BackBufferHeight
;
3363 parameters
[i
].BackBufferFormat
= d3dformat_from_wined3dformat(wined3d_parameters
[i
].BackBufferFormat
);
3364 parameters
[i
].BackBufferCount
= wined3d_parameters
[i
].BackBufferCount
;
3365 parameters
[i
].MultiSampleType
= wined3d_parameters
[i
].MultiSampleType
;
3366 parameters
[i
].MultiSampleQuality
= wined3d_parameters
[i
].MultiSampleQuality
;
3367 parameters
[i
].SwapEffect
= wined3d_parameters
[i
].SwapEffect
;
3368 parameters
[i
].hDeviceWindow
= wined3d_parameters
[i
].hDeviceWindow
;
3369 parameters
[i
].Windowed
= wined3d_parameters
[i
].Windowed
;
3370 parameters
[i
].EnableAutoDepthStencil
= wined3d_parameters
[i
].EnableAutoDepthStencil
;
3371 parameters
[i
].AutoDepthStencilFormat
=
3372 d3dformat_from_wined3dformat(wined3d_parameters
[i
].AutoDepthStencilFormat
);
3373 parameters
[i
].Flags
= wined3d_parameters
[i
].Flags
;
3374 parameters
[i
].FullScreen_RefreshRateInHz
= wined3d_parameters
[i
].FullScreen_RefreshRateInHz
;
3375 parameters
[i
].PresentationInterval
= wined3d_parameters
[i
].PresentationInterval
;
3377 HeapFree(GetProcessHeap(), 0, wined3d_parameters
);
3379 /* Initialize the converted declaration array. This creates a valid pointer
3380 * and when adding decls HeapReAlloc() can be used without further checking. */
3381 device
->convertedDecls
= HeapAlloc(GetProcessHeap(), 0, 0);
3382 if (!device
->convertedDecls
)
3384 ERR("Failed to allocate FVF vertex declaration map memory.\n");
3385 wined3d_mutex_lock();
3386 IWineD3DDevice_Uninit3D(device
->WineD3DDevice
, D3D9CB_DestroySwapChain
);
3387 IWineD3DDevice_ReleaseFocusWindow(device
->WineD3DDevice
);
3388 IWineD3DDevice_Release(device
->WineD3DDevice
);
3389 wined3d_mutex_unlock();
3390 return E_OUTOFMEMORY
;