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 static void STDMETHODCALLTYPE
d3d9_null_wined3d_object_destroyed(void *parent
) {}
30 static const struct wined3d_parent_ops d3d9_null_wined3d_parent_ops
=
32 d3d9_null_wined3d_object_destroyed
,
35 D3DFORMAT
d3dformat_from_wined3dformat(enum wined3d_format_id format
)
37 BYTE
*c
= (BYTE
*)&format
;
39 /* Don't translate FOURCC formats */
40 if (isprint(c
[0]) && isprint(c
[1]) && isprint(c
[2]) && isprint(c
[3])) return format
;
44 case WINED3DFMT_UNKNOWN
: return D3DFMT_UNKNOWN
;
45 case WINED3DFMT_B8G8R8_UNORM
: return D3DFMT_R8G8B8
;
46 case WINED3DFMT_B8G8R8A8_UNORM
: return D3DFMT_A8R8G8B8
;
47 case WINED3DFMT_B8G8R8X8_UNORM
: return D3DFMT_X8R8G8B8
;
48 case WINED3DFMT_B5G6R5_UNORM
: return D3DFMT_R5G6B5
;
49 case WINED3DFMT_B5G5R5X1_UNORM
: return D3DFMT_X1R5G5B5
;
50 case WINED3DFMT_B5G5R5A1_UNORM
: return D3DFMT_A1R5G5B5
;
51 case WINED3DFMT_B4G4R4A4_UNORM
: return D3DFMT_A4R4G4B4
;
52 case WINED3DFMT_B2G3R3_UNORM
: return D3DFMT_R3G3B2
;
53 case WINED3DFMT_A8_UNORM
: return D3DFMT_A8
;
54 case WINED3DFMT_B2G3R3A8_UNORM
: return D3DFMT_A8R3G3B2
;
55 case WINED3DFMT_B4G4R4X4_UNORM
: return D3DFMT_X4R4G4B4
;
56 case WINED3DFMT_R10G10B10A2_UNORM
: return D3DFMT_A2B10G10R10
;
57 case WINED3DFMT_R8G8B8A8_UNORM
: return D3DFMT_A8B8G8R8
;
58 case WINED3DFMT_R8G8B8X8_UNORM
: return D3DFMT_X8B8G8R8
;
59 case WINED3DFMT_R16G16_UNORM
: return D3DFMT_G16R16
;
60 case WINED3DFMT_B10G10R10A2_UNORM
: return D3DFMT_A2R10G10B10
;
61 case WINED3DFMT_R16G16B16A16_UNORM
: return D3DFMT_A16B16G16R16
;
62 case WINED3DFMT_P8_UINT_A8_UNORM
: return D3DFMT_A8P8
;
63 case WINED3DFMT_P8_UINT
: return D3DFMT_P8
;
64 case WINED3DFMT_L8_UNORM
: return D3DFMT_L8
;
65 case WINED3DFMT_L8A8_UNORM
: return D3DFMT_A8L8
;
66 case WINED3DFMT_L4A4_UNORM
: return D3DFMT_A4L4
;
67 case WINED3DFMT_R8G8_SNORM
: return D3DFMT_V8U8
;
68 case WINED3DFMT_R5G5_SNORM_L6_UNORM
: return D3DFMT_L6V5U5
;
69 case WINED3DFMT_R8G8_SNORM_L8X8_UNORM
: return D3DFMT_X8L8V8U8
;
70 case WINED3DFMT_R8G8B8A8_SNORM
: return D3DFMT_Q8W8V8U8
;
71 case WINED3DFMT_R16G16_SNORM
: return D3DFMT_V16U16
;
72 case WINED3DFMT_R10G10B10_SNORM_A2_UNORM
: return D3DFMT_A2W10V10U10
;
73 case WINED3DFMT_D16_LOCKABLE
: return D3DFMT_D16_LOCKABLE
;
74 case WINED3DFMT_D32_UNORM
: return D3DFMT_D32
;
75 case WINED3DFMT_S1_UINT_D15_UNORM
: return D3DFMT_D15S1
;
76 case WINED3DFMT_D24_UNORM_S8_UINT
: return D3DFMT_D24S8
;
77 case WINED3DFMT_X8D24_UNORM
: return D3DFMT_D24X8
;
78 case WINED3DFMT_S4X4_UINT_D24_UNORM
: return D3DFMT_D24X4S4
;
79 case WINED3DFMT_D16_UNORM
: return D3DFMT_D16
;
80 case WINED3DFMT_L16_UNORM
: return D3DFMT_L16
;
81 case WINED3DFMT_D32_FLOAT
: return D3DFMT_D32F_LOCKABLE
;
82 case WINED3DFMT_S8_UINT_D24_FLOAT
: return D3DFMT_D24FS8
;
83 case WINED3DFMT_VERTEXDATA
: return D3DFMT_VERTEXDATA
;
84 case WINED3DFMT_R16_UINT
: return D3DFMT_INDEX16
;
85 case WINED3DFMT_R32_UINT
: return D3DFMT_INDEX32
;
86 case WINED3DFMT_R16G16B16A16_SNORM
: return D3DFMT_Q16W16V16U16
;
87 case WINED3DFMT_R16_FLOAT
: return D3DFMT_R16F
;
88 case WINED3DFMT_R16G16_FLOAT
: return D3DFMT_G16R16F
;
89 case WINED3DFMT_R16G16B16A16_FLOAT
: return D3DFMT_A16B16G16R16F
;
90 case WINED3DFMT_R32_FLOAT
: return D3DFMT_R32F
;
91 case WINED3DFMT_R32G32_FLOAT
: return D3DFMT_G32R32F
;
92 case WINED3DFMT_R32G32B32A32_FLOAT
: return D3DFMT_A32B32G32R32F
;
93 case WINED3DFMT_R8G8_SNORM_Cx
: return D3DFMT_CxV8U8
;
95 FIXME("Unhandled wined3d format %#x.\n", format
);
96 return D3DFMT_UNKNOWN
;
100 enum wined3d_format_id
wined3dformat_from_d3dformat(D3DFORMAT format
)
102 BYTE
*c
= (BYTE
*)&format
;
104 /* Don't translate FOURCC formats */
105 if (isprint(c
[0]) && isprint(c
[1]) && isprint(c
[2]) && isprint(c
[3])) return format
;
109 case D3DFMT_UNKNOWN
: return WINED3DFMT_UNKNOWN
;
110 case D3DFMT_R8G8B8
: return WINED3DFMT_B8G8R8_UNORM
;
111 case D3DFMT_A8R8G8B8
: return WINED3DFMT_B8G8R8A8_UNORM
;
112 case D3DFMT_X8R8G8B8
: return WINED3DFMT_B8G8R8X8_UNORM
;
113 case D3DFMT_R5G6B5
: return WINED3DFMT_B5G6R5_UNORM
;
114 case D3DFMT_X1R5G5B5
: return WINED3DFMT_B5G5R5X1_UNORM
;
115 case D3DFMT_A1R5G5B5
: return WINED3DFMT_B5G5R5A1_UNORM
;
116 case D3DFMT_A4R4G4B4
: return WINED3DFMT_B4G4R4A4_UNORM
;
117 case D3DFMT_R3G3B2
: return WINED3DFMT_B2G3R3_UNORM
;
118 case D3DFMT_A8
: return WINED3DFMT_A8_UNORM
;
119 case D3DFMT_A8R3G3B2
: return WINED3DFMT_B2G3R3A8_UNORM
;
120 case D3DFMT_X4R4G4B4
: return WINED3DFMT_B4G4R4X4_UNORM
;
121 case D3DFMT_A2B10G10R10
: return WINED3DFMT_R10G10B10A2_UNORM
;
122 case D3DFMT_A8B8G8R8
: return WINED3DFMT_R8G8B8A8_UNORM
;
123 case D3DFMT_X8B8G8R8
: return WINED3DFMT_R8G8B8X8_UNORM
;
124 case D3DFMT_G16R16
: return WINED3DFMT_R16G16_UNORM
;
125 case D3DFMT_A2R10G10B10
: return WINED3DFMT_B10G10R10A2_UNORM
;
126 case D3DFMT_A16B16G16R16
: return WINED3DFMT_R16G16B16A16_UNORM
;
127 case D3DFMT_A8P8
: return WINED3DFMT_P8_UINT_A8_UNORM
;
128 case D3DFMT_P8
: return WINED3DFMT_P8_UINT
;
129 case D3DFMT_L8
: return WINED3DFMT_L8_UNORM
;
130 case D3DFMT_A8L8
: return WINED3DFMT_L8A8_UNORM
;
131 case D3DFMT_A4L4
: return WINED3DFMT_L4A4_UNORM
;
132 case D3DFMT_V8U8
: return WINED3DFMT_R8G8_SNORM
;
133 case D3DFMT_L6V5U5
: return WINED3DFMT_R5G5_SNORM_L6_UNORM
;
134 case D3DFMT_X8L8V8U8
: return WINED3DFMT_R8G8_SNORM_L8X8_UNORM
;
135 case D3DFMT_Q8W8V8U8
: return WINED3DFMT_R8G8B8A8_SNORM
;
136 case D3DFMT_V16U16
: return WINED3DFMT_R16G16_SNORM
;
137 case D3DFMT_A2W10V10U10
: return WINED3DFMT_R10G10B10_SNORM_A2_UNORM
;
138 case D3DFMT_D16_LOCKABLE
: return WINED3DFMT_D16_LOCKABLE
;
139 case D3DFMT_D32
: return WINED3DFMT_D32_UNORM
;
140 case D3DFMT_D15S1
: return WINED3DFMT_S1_UINT_D15_UNORM
;
141 case D3DFMT_D24S8
: return WINED3DFMT_D24_UNORM_S8_UINT
;
142 case D3DFMT_D24X8
: return WINED3DFMT_X8D24_UNORM
;
143 case D3DFMT_D24X4S4
: return WINED3DFMT_S4X4_UINT_D24_UNORM
;
144 case D3DFMT_D16
: return WINED3DFMT_D16_UNORM
;
145 case D3DFMT_L16
: return WINED3DFMT_L16_UNORM
;
146 case D3DFMT_D32F_LOCKABLE
: return WINED3DFMT_D32_FLOAT
;
147 case D3DFMT_D24FS8
: return WINED3DFMT_S8_UINT_D24_FLOAT
;
148 case D3DFMT_VERTEXDATA
: return WINED3DFMT_VERTEXDATA
;
149 case D3DFMT_INDEX16
: return WINED3DFMT_R16_UINT
;
150 case D3DFMT_INDEX32
: return WINED3DFMT_R32_UINT
;
151 case D3DFMT_Q16W16V16U16
: return WINED3DFMT_R16G16B16A16_SNORM
;
152 case D3DFMT_R16F
: return WINED3DFMT_R16_FLOAT
;
153 case D3DFMT_G16R16F
: return WINED3DFMT_R16G16_FLOAT
;
154 case D3DFMT_A16B16G16R16F
: return WINED3DFMT_R16G16B16A16_FLOAT
;
155 case D3DFMT_R32F
: return WINED3DFMT_R32_FLOAT
;
156 case D3DFMT_G32R32F
: return WINED3DFMT_R32G32_FLOAT
;
157 case D3DFMT_A32B32G32R32F
: return WINED3DFMT_R32G32B32A32_FLOAT
;
158 case D3DFMT_CxV8U8
: return WINED3DFMT_R8G8_SNORM_Cx
;
160 FIXME("Unhandled D3DFORMAT %#x\n", format
);
161 return WINED3DFMT_UNKNOWN
;
165 static UINT
vertex_count_from_primitive_count(D3DPRIMITIVETYPE primitive_type
, UINT primitive_count
)
167 switch(primitive_type
)
169 case D3DPT_POINTLIST
:
170 return primitive_count
;
173 return primitive_count
* 2;
175 case D3DPT_LINESTRIP
:
176 return primitive_count
+ 1;
178 case D3DPT_TRIANGLELIST
:
179 return primitive_count
* 3;
181 case D3DPT_TRIANGLESTRIP
:
182 case D3DPT_TRIANGLEFAN
:
183 return primitive_count
+ 2;
186 FIXME("Unhandled primitive type %#x\n", primitive_type
);
191 void present_parameters_from_wined3d_swapchain_desc(D3DPRESENT_PARAMETERS
*present_parameters
,
192 const struct wined3d_swapchain_desc
*swapchain_desc
)
194 present_parameters
->BackBufferWidth
= swapchain_desc
->backbuffer_width
;
195 present_parameters
->BackBufferHeight
= swapchain_desc
->backbuffer_height
;
196 present_parameters
->BackBufferFormat
= d3dformat_from_wined3dformat(swapchain_desc
->backbuffer_format
);
197 present_parameters
->BackBufferCount
= swapchain_desc
->backbuffer_count
;
198 present_parameters
->MultiSampleType
= swapchain_desc
->multisample_type
;
199 present_parameters
->MultiSampleQuality
= swapchain_desc
->multisample_quality
;
200 present_parameters
->SwapEffect
= swapchain_desc
->swap_effect
;
201 present_parameters
->hDeviceWindow
= swapchain_desc
->device_window
;
202 present_parameters
->Windowed
= swapchain_desc
->windowed
;
203 present_parameters
->EnableAutoDepthStencil
= swapchain_desc
->enable_auto_depth_stencil
;
204 present_parameters
->AutoDepthStencilFormat
205 = d3dformat_from_wined3dformat(swapchain_desc
->auto_depth_stencil_format
);
206 present_parameters
->Flags
= swapchain_desc
->flags
;
207 present_parameters
->FullScreen_RefreshRateInHz
= swapchain_desc
->refresh_rate
;
208 present_parameters
->PresentationInterval
= swapchain_desc
->swap_interval
;
211 static BOOL
wined3d_swapchain_desc_from_present_parameters(struct wined3d_swapchain_desc
*swapchain_desc
,
212 const D3DPRESENT_PARAMETERS
*present_parameters
, BOOL extended
)
214 D3DSWAPEFFECT highest_swapeffect
= extended
? D3DSWAPEFFECT_FLIPEX
: D3DSWAPEFFECT_COPY
;
215 UINT highest_bb_count
= extended
? 30 : 3;
217 if (!present_parameters
->SwapEffect
|| present_parameters
->SwapEffect
> highest_swapeffect
)
219 WARN("Invalid swap effect %u passed.\n", present_parameters
->SwapEffect
);
222 if (present_parameters
->BackBufferCount
> highest_bb_count
223 || (present_parameters
->SwapEffect
== D3DSWAPEFFECT_COPY
224 && present_parameters
->BackBufferCount
> 1))
226 WARN("Invalid backbuffer count %u.\n", present_parameters
->BackBufferCount
);
230 swapchain_desc
->backbuffer_width
= present_parameters
->BackBufferWidth
;
231 swapchain_desc
->backbuffer_height
= present_parameters
->BackBufferHeight
;
232 swapchain_desc
->backbuffer_format
= wined3dformat_from_d3dformat(present_parameters
->BackBufferFormat
);
233 swapchain_desc
->backbuffer_count
= max(1, present_parameters
->BackBufferCount
);
234 swapchain_desc
->multisample_type
= present_parameters
->MultiSampleType
;
235 swapchain_desc
->multisample_quality
= present_parameters
->MultiSampleQuality
;
236 swapchain_desc
->swap_effect
= present_parameters
->SwapEffect
;
237 swapchain_desc
->device_window
= present_parameters
->hDeviceWindow
;
238 swapchain_desc
->windowed
= present_parameters
->Windowed
;
239 swapchain_desc
->enable_auto_depth_stencil
= present_parameters
->EnableAutoDepthStencil
;
240 swapchain_desc
->auto_depth_stencil_format
241 = wined3dformat_from_d3dformat(present_parameters
->AutoDepthStencilFormat
);
242 swapchain_desc
->flags
= present_parameters
->Flags
;
243 swapchain_desc
->refresh_rate
= present_parameters
->FullScreen_RefreshRateInHz
;
244 swapchain_desc
->swap_interval
= present_parameters
->PresentationInterval
;
245 swapchain_desc
->auto_restore_display_mode
= TRUE
;
250 static HRESULT WINAPI
d3d9_device_QueryInterface(IDirect3DDevice9Ex
*iface
, REFIID riid
, void **out
)
252 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
254 if (IsEqualGUID(riid
, &IID_IDirect3DDevice9
)
255 || IsEqualGUID(riid
, &IID_IUnknown
))
257 IDirect3DDevice9Ex_AddRef(iface
);
262 if (IsEqualGUID(riid
, &IID_IDirect3DDevice9Ex
))
264 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
266 /* Find out if the creating d3d9 interface was created with Direct3DCreate9Ex.
267 * It doesn't matter with which function the device was created. */
268 if (!device
->d3d_parent
->extended
)
270 WARN("IDirect3D9 instance wasn't created with CreateDirect3D9Ex, returning E_NOINTERFACE.\n");
272 return E_NOINTERFACE
;
275 IDirect3DDevice9Ex_AddRef(iface
);
280 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
283 return E_NOINTERFACE
;
286 static ULONG WINAPI
d3d9_device_AddRef(IDirect3DDevice9Ex
*iface
)
288 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
289 ULONG refcount
= InterlockedIncrement(&device
->refcount
);
291 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
296 static ULONG WINAPI DECLSPEC_HOTPATCH
d3d9_device_Release(IDirect3DDevice9Ex
*iface
)
298 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
301 if (device
->in_destruction
)
304 refcount
= InterlockedDecrement(&device
->refcount
);
306 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
311 device
->in_destruction
= TRUE
;
313 wined3d_mutex_lock();
314 for (i
= 0; i
< device
->fvf_decl_count
; ++i
)
316 wined3d_vertex_declaration_decref(device
->fvf_decls
[i
].decl
);
318 HeapFree(GetProcessHeap(), 0, device
->fvf_decls
);
320 if (device
->vertex_buffer
)
321 wined3d_buffer_decref(device
->vertex_buffer
);
322 if (device
->index_buffer
)
323 wined3d_buffer_decref(device
->index_buffer
);
325 wined3d_device_uninit_3d(device
->wined3d_device
);
326 wined3d_device_release_focus_window(device
->wined3d_device
);
327 wined3d_device_decref(device
->wined3d_device
);
328 wined3d_mutex_unlock();
330 IDirect3D9Ex_Release(&device
->d3d_parent
->IDirect3D9Ex_iface
);
332 HeapFree(GetProcessHeap(), 0, device
);
338 static HRESULT WINAPI
d3d9_device_TestCooperativeLevel(IDirect3DDevice9Ex
*iface
)
340 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
342 TRACE("iface %p.\n", iface
);
344 TRACE("device state: %#x.\n", device
->device_state
);
346 if (device
->d3d_parent
->extended
)
349 switch (device
->device_state
)
352 case D3D9_DEVICE_STATE_OK
:
354 case D3D9_DEVICE_STATE_LOST
:
355 return D3DERR_DEVICELOST
;
356 case D3D9_DEVICE_STATE_NOT_RESET
:
357 return D3DERR_DEVICENOTRESET
;
361 static UINT WINAPI
d3d9_device_GetAvailableTextureMem(IDirect3DDevice9Ex
*iface
)
363 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
366 TRACE("iface %p.\n", iface
);
368 wined3d_mutex_lock();
369 ret
= wined3d_device_get_available_texture_mem(device
->wined3d_device
);
370 wined3d_mutex_unlock();
375 static HRESULT WINAPI
d3d9_device_EvictManagedResources(IDirect3DDevice9Ex
*iface
)
377 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
379 TRACE("iface %p.\n", iface
);
381 wined3d_mutex_lock();
382 wined3d_device_evict_managed_resources(device
->wined3d_device
);
383 wined3d_mutex_unlock();
388 static HRESULT WINAPI
d3d9_device_GetDirect3D(IDirect3DDevice9Ex
*iface
, IDirect3D9
**d3d9
)
390 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
392 TRACE("iface %p, d3d9 %p.\n", iface
, d3d9
);
395 return D3DERR_INVALIDCALL
;
397 return IDirect3D9Ex_QueryInterface(&device
->d3d_parent
->IDirect3D9Ex_iface
, &IID_IDirect3D9
, (void **)d3d9
);
400 static HRESULT WINAPI
d3d9_device_GetDeviceCaps(IDirect3DDevice9Ex
*iface
, D3DCAPS9
*caps
)
402 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
403 WINED3DCAPS
*wined3d_caps
;
406 TRACE("iface %p, caps %p.\n", iface
, caps
);
409 return D3DERR_INVALIDCALL
;
411 if (!(wined3d_caps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*wined3d_caps
))))
412 return D3DERR_INVALIDCALL
; /* well this is what MSDN says to return */
414 memset(caps
, 0, sizeof(*caps
));
416 wined3d_mutex_lock();
417 hr
= wined3d_device_get_device_caps(device
->wined3d_device
, wined3d_caps
);
418 wined3d_mutex_unlock();
420 WINECAPSTOD3D9CAPS(caps
, wined3d_caps
)
421 HeapFree(GetProcessHeap(), 0, wined3d_caps
);
423 /* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps */
424 caps
->DevCaps2
|= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES
;
431 static HRESULT WINAPI
d3d9_device_GetDisplayMode(IDirect3DDevice9Ex
*iface
, UINT swapchain
, D3DDISPLAYMODE
*mode
)
433 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
434 struct wined3d_display_mode wined3d_mode
;
437 TRACE("iface %p, swapchain %u, mode %p.\n", iface
, swapchain
, mode
);
439 wined3d_mutex_lock();
440 hr
= wined3d_device_get_display_mode(device
->wined3d_device
, swapchain
, &wined3d_mode
, NULL
);
441 wined3d_mutex_unlock();
445 mode
->Width
= wined3d_mode
.width
;
446 mode
->Height
= wined3d_mode
.height
;
447 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
448 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
454 static HRESULT WINAPI
d3d9_device_GetCreationParameters(IDirect3DDevice9Ex
*iface
,
455 D3DDEVICE_CREATION_PARAMETERS
*parameters
)
457 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
459 TRACE("iface %p, parameters %p.\n", iface
, parameters
);
461 wined3d_mutex_lock();
462 wined3d_device_get_creation_parameters(device
->wined3d_device
,
463 (struct wined3d_device_creation_parameters
*)parameters
);
464 wined3d_mutex_unlock();
469 static HRESULT WINAPI
d3d9_device_SetCursorProperties(IDirect3DDevice9Ex
*iface
,
470 UINT hotspot_x
, UINT hotspot_y
, IDirect3DSurface9
*bitmap
)
472 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
473 struct d3d9_surface
*bitmap_impl
= unsafe_impl_from_IDirect3DSurface9(bitmap
);
476 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
477 iface
, hotspot_x
, hotspot_y
, bitmap
);
481 WARN("No cursor bitmap, returning D3DERR_INVALIDCALL.\n");
482 return D3DERR_INVALIDCALL
;
485 wined3d_mutex_lock();
486 hr
= wined3d_device_set_cursor_properties(device
->wined3d_device
,
487 hotspot_x
, hotspot_y
, bitmap_impl
->wined3d_surface
);
488 wined3d_mutex_unlock();
493 static void WINAPI
d3d9_device_SetCursorPosition(IDirect3DDevice9Ex
*iface
, int x
, int y
, DWORD flags
)
495 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
497 TRACE("iface %p, x %u, y %u, flags %#x.\n", iface
, x
, y
, flags
);
499 wined3d_mutex_lock();
500 wined3d_device_set_cursor_position(device
->wined3d_device
, x
, y
, flags
);
501 wined3d_mutex_unlock();
504 static BOOL WINAPI
d3d9_device_ShowCursor(IDirect3DDevice9Ex
*iface
, BOOL show
)
506 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
509 TRACE("iface %p, show %#x.\n", iface
, show
);
511 wined3d_mutex_lock();
512 ret
= wined3d_device_show_cursor(device
->wined3d_device
, show
);
513 wined3d_mutex_unlock();
518 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_CreateAdditionalSwapChain(IDirect3DDevice9Ex
*iface
,
519 D3DPRESENT_PARAMETERS
*present_parameters
, IDirect3DSwapChain9
**swapchain
)
521 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
522 struct wined3d_swapchain_desc desc
;
523 struct d3d9_swapchain
*object
;
527 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
528 iface
, present_parameters
, swapchain
);
530 if (!present_parameters
->Windowed
)
532 WARN("Trying to create an additional fullscreen swapchain, returning D3DERR_INVALIDCALL.\n");
533 return D3DERR_INVALIDCALL
;
536 wined3d_mutex_lock();
537 count
= wined3d_device_get_swapchain_count(device
->wined3d_device
);
538 for (i
= 0; i
< count
; ++i
)
540 struct wined3d_swapchain
*wined3d_swapchain
;
542 wined3d_swapchain
= wined3d_device_get_swapchain(device
->wined3d_device
, i
);
543 wined3d_swapchain_get_desc(wined3d_swapchain
, &desc
);
547 wined3d_mutex_unlock();
548 WARN("Trying to create an additional swapchain in fullscreen mode, returning D3DERR_INVALIDCALL.\n");
549 return D3DERR_INVALIDCALL
;
552 wined3d_mutex_unlock();
554 if (!wined3d_swapchain_desc_from_present_parameters(&desc
, present_parameters
,
555 device
->d3d_parent
->extended
))
556 return D3DERR_INVALIDCALL
;
557 if (SUCCEEDED(hr
= d3d9_swapchain_create(device
, &desc
, &object
)))
558 *swapchain
= (IDirect3DSwapChain9
*)&object
->IDirect3DSwapChain9Ex_iface
;
559 present_parameters_from_wined3d_swapchain_desc(present_parameters
, &desc
);
564 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_GetSwapChain(IDirect3DDevice9Ex
*iface
,
565 UINT swapchain_idx
, IDirect3DSwapChain9
**swapchain
)
567 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
568 struct wined3d_swapchain
*wined3d_swapchain
;
569 struct d3d9_swapchain
*swapchain_impl
;
572 TRACE("iface %p, swapchain_idx %u, swapchain %p.\n", iface
, swapchain_idx
, swapchain
);
574 wined3d_mutex_lock();
575 if ((wined3d_swapchain
= wined3d_device_get_swapchain(device
->wined3d_device
, swapchain_idx
)))
577 swapchain_impl
= wined3d_swapchain_get_parent(wined3d_swapchain
);
578 *swapchain
= (IDirect3DSwapChain9
*)&swapchain_impl
->IDirect3DSwapChain9Ex_iface
;
579 IDirect3DSwapChain9Ex_AddRef(*swapchain
);
585 hr
= D3DERR_INVALIDCALL
;
587 wined3d_mutex_unlock();
592 static UINT WINAPI
d3d9_device_GetNumberOfSwapChains(IDirect3DDevice9Ex
*iface
)
594 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
597 TRACE("iface %p.\n", iface
);
599 wined3d_mutex_lock();
600 count
= wined3d_device_get_swapchain_count(device
->wined3d_device
);
601 wined3d_mutex_unlock();
606 static HRESULT CDECL
reset_enum_callback(struct wined3d_resource
*resource
)
608 struct wined3d_resource_desc desc
;
610 wined3d_resource_get_desc(resource
, &desc
);
611 if (desc
.pool
== WINED3D_POOL_DEFAULT
)
613 struct d3d9_surface
*surface
;
615 if (desc
.resource_type
== WINED3D_RTYPE_TEXTURE
)
617 IUnknown
*parent
= wined3d_resource_get_parent(resource
);
618 IDirect3DBaseTexture9
*texture
;
620 if (SUCCEEDED(IUnknown_QueryInterface(parent
, &IID_IDirect3DBaseTexture9
, (void **)&texture
)))
622 IDirect3DBaseTexture9_Release(texture
);
623 WARN("Texture %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", texture
, resource
);
624 return D3DERR_INVALIDCALL
;
630 if (desc
.resource_type
!= WINED3D_RTYPE_SURFACE
)
632 WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource
);
633 return D3DERR_INVALIDCALL
;
636 surface
= wined3d_resource_get_parent(resource
);
637 if (surface
->resource
.refcount
)
639 WARN("Surface %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface
, resource
);
640 return D3DERR_INVALIDCALL
;
643 WARN("Surface %p (resource %p) is an implicit resource with ref 0.\n", surface
, resource
);
649 static HRESULT
d3d9_device_reset(struct d3d9_device
*device
,
650 D3DPRESENT_PARAMETERS
*present_parameters
, D3DDISPLAYMODEEX
*mode
)
652 struct wined3d_swapchain_desc swapchain_desc
;
653 struct wined3d_display_mode wined3d_mode
;
656 if (!device
->d3d_parent
->extended
&& device
->device_state
== D3D9_DEVICE_STATE_LOST
)
658 WARN("App not active, returning D3DERR_DEVICELOST.\n");
659 return D3DERR_DEVICELOST
;
664 wined3d_mode
.width
= mode
->Width
;
665 wined3d_mode
.height
= mode
->Height
;
666 wined3d_mode
.refresh_rate
= mode
->RefreshRate
;
667 wined3d_mode
.format_id
= wined3dformat_from_d3dformat(mode
->Format
);
668 wined3d_mode
.scanline_ordering
= mode
->ScanLineOrdering
;
671 if (!wined3d_swapchain_desc_from_present_parameters(&swapchain_desc
, present_parameters
,
672 device
->d3d_parent
->extended
))
673 return D3DERR_INVALIDCALL
;
675 wined3d_mutex_lock();
677 if (device
->vertex_buffer
)
679 wined3d_buffer_decref(device
->vertex_buffer
);
680 device
->vertex_buffer
= NULL
;
681 device
->vertex_buffer_size
= 0;
684 if (device
->index_buffer
)
686 wined3d_buffer_decref(device
->index_buffer
);
687 device
->index_buffer
= NULL
;
688 device
->index_buffer_size
= 0;
691 if (SUCCEEDED(hr
= wined3d_device_reset(device
->wined3d_device
, &swapchain_desc
,
692 mode
? &wined3d_mode
: NULL
, reset_enum_callback
, !device
->d3d_parent
->extended
)))
694 struct wined3d_swapchain
*wined3d_swapchain
;
696 wined3d_swapchain
= wined3d_device_get_swapchain(device
->wined3d_device
, 0);
697 wined3d_swapchain_get_desc(wined3d_swapchain
, &swapchain_desc
);
698 present_parameters
->BackBufferWidth
= swapchain_desc
.backbuffer_width
;
699 present_parameters
->BackBufferHeight
= swapchain_desc
.backbuffer_height
;
700 present_parameters
->BackBufferFormat
= d3dformat_from_wined3dformat(swapchain_desc
.backbuffer_format
);
701 present_parameters
->BackBufferCount
= swapchain_desc
.backbuffer_count
;
703 device
->device_state
= D3D9_DEVICE_STATE_OK
;
705 else if (!device
->d3d_parent
->extended
)
707 device
->device_state
= D3D9_DEVICE_STATE_NOT_RESET
;
710 wined3d_mutex_unlock();
715 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_Reset(IDirect3DDevice9Ex
*iface
,
716 D3DPRESENT_PARAMETERS
*present_parameters
)
718 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
720 TRACE("iface %p, present_parameters %p.\n", iface
, present_parameters
);
722 return d3d9_device_reset(device
, present_parameters
, NULL
);
725 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_Present(IDirect3DDevice9Ex
*iface
,
726 const RECT
*src_rect
, const RECT
*dst_rect
, HWND dst_window_override
, const RGNDATA
*dirty_region
)
728 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
731 TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
732 iface
, src_rect
, dst_rect
, dst_window_override
, dirty_region
);
734 if (device
->device_state
!= D3D9_DEVICE_STATE_OK
)
735 return device
->d3d_parent
->extended
? S_PRESENT_OCCLUDED
: D3DERR_DEVICELOST
;
737 wined3d_mutex_lock();
738 hr
= wined3d_device_present(device
->wined3d_device
, src_rect
, dst_rect
,
739 dst_window_override
, dirty_region
, 0);
740 wined3d_mutex_unlock();
745 static HRESULT WINAPI
d3d9_device_GetBackBuffer(IDirect3DDevice9Ex
*iface
, UINT swapchain
,
746 UINT backbuffer_idx
, D3DBACKBUFFER_TYPE backbuffer_type
, IDirect3DSurface9
**backbuffer
)
748 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
749 struct wined3d_swapchain
*wined3d_swapchain
;
750 struct wined3d_resource
*wined3d_resource
;
751 struct wined3d_texture
*wined3d_texture
;
752 struct d3d9_surface
*surface_impl
;
754 TRACE("iface %p, swapchain %u, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
755 iface
, swapchain
, backbuffer_idx
, backbuffer_type
, backbuffer
);
757 /* No need to check for backbuffer == NULL, Windows crashes in that case. */
758 wined3d_mutex_lock();
760 if (!(wined3d_swapchain
= wined3d_device_get_swapchain(device
->wined3d_device
, swapchain
)))
762 wined3d_mutex_unlock();
764 return D3DERR_INVALIDCALL
;
767 if (!(wined3d_texture
= wined3d_swapchain_get_back_buffer(wined3d_swapchain
,
768 backbuffer_idx
, (enum wined3d_backbuffer_type
)backbuffer_type
)))
770 wined3d_mutex_unlock();
772 return D3DERR_INVALIDCALL
;
775 wined3d_resource
= wined3d_texture_get_sub_resource(wined3d_texture
, 0);
776 surface_impl
= wined3d_resource_get_parent(wined3d_resource
);
777 *backbuffer
= &surface_impl
->IDirect3DSurface9_iface
;
778 IDirect3DSurface9_AddRef(*backbuffer
);
780 wined3d_mutex_unlock();
784 static HRESULT WINAPI
d3d9_device_GetRasterStatus(IDirect3DDevice9Ex
*iface
,
785 UINT swapchain
, D3DRASTER_STATUS
*raster_status
)
787 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
790 TRACE("iface %p, swapchain %u, raster_status %p.\n", iface
, swapchain
, raster_status
);
792 wined3d_mutex_lock();
793 hr
= wined3d_device_get_raster_status(device
->wined3d_device
,
794 swapchain
, (struct wined3d_raster_status
*)raster_status
);
795 wined3d_mutex_unlock();
800 static HRESULT WINAPI
d3d9_device_SetDialogBoxMode(IDirect3DDevice9Ex
*iface
, BOOL enable
)
802 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
805 TRACE("iface %p, enable %#x.\n", iface
, enable
);
807 wined3d_mutex_lock();
808 hr
= wined3d_device_set_dialog_box_mode(device
->wined3d_device
, enable
);
809 wined3d_mutex_unlock();
814 static void WINAPI
d3d9_device_SetGammaRamp(IDirect3DDevice9Ex
*iface
,
815 UINT swapchain
, DWORD flags
, const D3DGAMMARAMP
*ramp
)
817 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
819 TRACE("iface %p, swapchain %u, flags %#x, ramp %p.\n", iface
, swapchain
, flags
, ramp
);
821 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
822 wined3d_mutex_lock();
823 wined3d_device_set_gamma_ramp(device
->wined3d_device
, swapchain
, flags
, (const struct wined3d_gamma_ramp
*)ramp
);
824 wined3d_mutex_unlock();
827 static void WINAPI
d3d9_device_GetGammaRamp(IDirect3DDevice9Ex
*iface
, UINT swapchain
, D3DGAMMARAMP
*ramp
)
829 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
831 TRACE("iface %p, swapchain %u, ramp %p.\n", iface
, swapchain
, ramp
);
833 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
834 wined3d_mutex_lock();
835 wined3d_device_get_gamma_ramp(device
->wined3d_device
, swapchain
, (struct wined3d_gamma_ramp
*)ramp
);
836 wined3d_mutex_unlock();
839 static HRESULT WINAPI
d3d9_device_CreateTexture(IDirect3DDevice9Ex
*iface
,
840 UINT width
, UINT height
, UINT levels
, DWORD usage
, D3DFORMAT format
,
841 D3DPOOL pool
, IDirect3DTexture9
**texture
, HANDLE
*shared_handle
)
843 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
844 struct d3d9_texture
*object
;
845 BOOL set_mem
= FALSE
;
848 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
849 iface
, width
, height
, levels
, usage
, format
, pool
, texture
, shared_handle
);
854 if (!device
->d3d_parent
->extended
)
856 WARN("Trying to create a shared or user memory texture on a non-ex device.\n");
860 if (pool
== D3DPOOL_SYSTEMMEM
)
863 return D3DERR_INVALIDCALL
;
868 if (pool
!= D3DPOOL_DEFAULT
)
870 WARN("Trying to create a shared texture in pool %#x.\n", pool
);
871 return D3DERR_INVALIDCALL
;
873 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
877 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
879 return D3DERR_OUTOFVIDEOMEMORY
;
881 hr
= texture_init(object
, device
, width
, height
, levels
, usage
, format
, pool
);
884 WARN("Failed to initialize texture, hr %#x.\n", hr
);
885 HeapFree(GetProcessHeap(), 0, object
);
890 wined3d_texture_update_desc(object
->wined3d_texture
, width
, height
,
891 wined3dformat_from_d3dformat(format
), WINED3D_MULTISAMPLE_NONE
, 0,
894 TRACE("Created texture %p.\n", object
);
895 *texture
= (IDirect3DTexture9
*)&object
->IDirect3DBaseTexture9_iface
;
900 static HRESULT WINAPI
d3d9_device_CreateVolumeTexture(IDirect3DDevice9Ex
*iface
,
901 UINT width
, UINT height
, UINT depth
, UINT levels
, DWORD usage
, D3DFORMAT format
,
902 D3DPOOL pool
, IDirect3DVolumeTexture9
**texture
, HANDLE
*shared_handle
)
904 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
905 struct d3d9_texture
*object
;
908 TRACE("iface %p, width %u, height %u, depth %u, levels %u\n",
909 iface
, width
, height
, depth
, levels
);
910 TRACE("usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
911 usage
, format
, pool
, texture
, shared_handle
);
916 if (!device
->d3d_parent
->extended
)
918 WARN("Trying to create a shared volume texture on a non-ex device.\n");
922 if (pool
!= D3DPOOL_DEFAULT
)
924 WARN("Trying to create a shared volume texture in pool %#x.\n", pool
);
925 return D3DERR_INVALIDCALL
;
927 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
930 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
932 return D3DERR_OUTOFVIDEOMEMORY
;
934 hr
= volumetexture_init(object
, device
, width
, height
, depth
, levels
, usage
, format
, pool
);
937 WARN("Failed to initialize volume texture, hr %#x.\n", hr
);
938 HeapFree(GetProcessHeap(), 0, object
);
942 TRACE("Created volume texture %p.\n", object
);
943 *texture
= (IDirect3DVolumeTexture9
*)&object
->IDirect3DBaseTexture9_iface
;
948 static HRESULT WINAPI
d3d9_device_CreateCubeTexture(IDirect3DDevice9Ex
*iface
,
949 UINT edge_length
, UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
,
950 IDirect3DCubeTexture9
**texture
, HANDLE
*shared_handle
)
952 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
953 struct d3d9_texture
*object
;
956 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
957 iface
, edge_length
, levels
, usage
, format
, pool
, texture
, shared_handle
);
962 if (!device
->d3d_parent
->extended
)
964 WARN("Trying to create a shared cube texture on a non-ex device.\n");
968 if (pool
!= D3DPOOL_DEFAULT
)
970 WARN("Trying to create a shared cube texture in pool %#x.\n", pool
);
971 return D3DERR_INVALIDCALL
;
973 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
976 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
978 return D3DERR_OUTOFVIDEOMEMORY
;
980 hr
= cubetexture_init(object
, device
, edge_length
, levels
, usage
, format
, pool
);
983 WARN("Failed to initialize cube texture, hr %#x.\n", hr
);
984 HeapFree(GetProcessHeap(), 0, object
);
988 TRACE("Created cube texture %p.\n", object
);
989 *texture
= (IDirect3DCubeTexture9
*)&object
->IDirect3DBaseTexture9_iface
;
994 static HRESULT WINAPI
d3d9_device_CreateVertexBuffer(IDirect3DDevice9Ex
*iface
, UINT size
,
995 DWORD usage
, DWORD fvf
, D3DPOOL pool
, IDirect3DVertexBuffer9
**buffer
,
996 HANDLE
*shared_handle
)
998 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
999 struct d3d9_vertexbuffer
*object
;
1002 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p, shared_handle %p.\n",
1003 iface
, size
, usage
, fvf
, pool
, buffer
, shared_handle
);
1007 if (!device
->d3d_parent
->extended
)
1009 WARN("Trying to create a shared vertex buffer on a non-ex device.\n");
1013 if (pool
!= D3DPOOL_DEFAULT
)
1015 WARN("Trying to create a shared vertex buffer in pool %#x.\n", pool
);
1016 return D3DERR_NOTAVAILABLE
;
1018 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1021 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1023 return D3DERR_OUTOFVIDEOMEMORY
;
1025 hr
= vertexbuffer_init(object
, device
, size
, usage
, fvf
, pool
);
1028 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr
);
1029 HeapFree(GetProcessHeap(), 0, object
);
1033 TRACE("Created vertex buffer %p.\n", object
);
1034 *buffer
= &object
->IDirect3DVertexBuffer9_iface
;
1039 static HRESULT WINAPI
d3d9_device_CreateIndexBuffer(IDirect3DDevice9Ex
*iface
, UINT size
,
1040 DWORD usage
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DIndexBuffer9
**buffer
,
1041 HANDLE
*shared_handle
)
1043 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1044 struct d3d9_indexbuffer
*object
;
1047 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p, shared_handle %p.\n",
1048 iface
, size
, usage
, format
, pool
, buffer
, shared_handle
);
1052 if (!device
->d3d_parent
->extended
)
1054 WARN("Trying to create a shared index buffer on a non-ex device.\n");
1058 if (pool
!= D3DPOOL_DEFAULT
)
1060 WARN("Trying to create a shared index buffer in pool %#x.\n", pool
);
1061 return D3DERR_NOTAVAILABLE
;
1063 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1066 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1068 return D3DERR_OUTOFVIDEOMEMORY
;
1070 hr
= indexbuffer_init(object
, device
, size
, usage
, format
, pool
);
1073 WARN("Failed to initialize index buffer, hr %#x.\n", hr
);
1074 HeapFree(GetProcessHeap(), 0, object
);
1078 TRACE("Created index buffer %p.\n", object
);
1079 *buffer
= &object
->IDirect3DIndexBuffer9_iface
;
1084 static HRESULT
d3d9_device_create_surface(struct d3d9_device
*device
, UINT width
, UINT height
,
1085 D3DFORMAT format
, DWORD flags
, IDirect3DSurface9
**surface
, UINT usage
, D3DPOOL pool
,
1086 D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
, void *user_mem
)
1088 struct wined3d_resource
*sub_resource
;
1089 struct wined3d_resource_desc desc
;
1090 struct d3d9_surface
*surface_impl
;
1091 struct wined3d_texture
*texture
;
1094 TRACE("device %p, width %u, height %u, format %#x, flags %#x, surface %p.\n"
1095 "usage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
1096 device
, width
, height
, format
, flags
, surface
, usage
, pool
,
1097 multisample_type
, multisample_quality
);
1099 desc
.resource_type
= WINED3D_RTYPE_TEXTURE
;
1100 desc
.format
= wined3dformat_from_d3dformat(format
);
1101 desc
.multisample_type
= multisample_type
;
1102 desc
.multisample_quality
= multisample_quality
;
1103 desc
.usage
= usage
& WINED3DUSAGE_MASK
;
1106 desc
.height
= height
;
1110 wined3d_mutex_lock();
1112 if (FAILED(hr
= wined3d_texture_create(device
->wined3d_device
, &desc
,
1113 1, flags
, NULL
, NULL
, &d3d9_null_wined3d_parent_ops
, &texture
)))
1115 wined3d_mutex_unlock();
1116 WARN("Failed to create texture, hr %#x.\n", hr
);
1120 sub_resource
= wined3d_texture_get_sub_resource(texture
, 0);
1121 surface_impl
= wined3d_resource_get_parent(sub_resource
);
1122 surface_impl
->parent_device
= &device
->IDirect3DDevice9Ex_iface
;
1123 *surface
= &surface_impl
->IDirect3DSurface9_iface
;
1124 IDirect3DSurface9_AddRef(*surface
);
1127 wined3d_texture_update_desc(texture
, width
, height
,
1128 desc
.format
, multisample_type
, multisample_quality
, user_mem
, 0);
1130 wined3d_texture_decref(texture
);
1132 wined3d_mutex_unlock();
1137 static HRESULT WINAPI
d3d9_device_CreateRenderTarget(IDirect3DDevice9Ex
*iface
, UINT width
, UINT height
,
1138 D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
1139 BOOL lockable
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
)
1141 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1144 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
1145 "lockable %#x, surface %p, shared_handle %p.\n",
1146 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
1147 lockable
, surface
, shared_handle
);
1152 if (!device
->d3d_parent
->extended
)
1154 WARN("Trying to create a shared render target on a non-ex device.\n");
1158 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1162 flags
|= WINED3D_SURFACE_MAPPABLE
;
1164 return d3d9_device_create_surface(device
, width
, height
, format
, flags
, surface
,
1165 D3DUSAGE_RENDERTARGET
, D3DPOOL_DEFAULT
, multisample_type
, multisample_quality
, NULL
);
1168 static HRESULT WINAPI
d3d9_device_CreateDepthStencilSurface(IDirect3DDevice9Ex
*iface
, UINT width
, UINT height
,
1169 D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
1170 BOOL discard
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
)
1172 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1173 DWORD flags
= WINED3D_SURFACE_MAPPABLE
;
1175 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
1176 "discard %#x, surface %p, shared_handle %p.\n",
1177 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
1178 discard
, surface
, shared_handle
);
1183 if (!device
->d3d_parent
->extended
)
1185 WARN("Trying to create a shared depth stencil on a non-ex device.\n");
1189 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1193 flags
|= WINED3D_SURFACE_DISCARD
;
1195 return d3d9_device_create_surface(device
, width
, height
, format
, flags
, surface
,
1196 D3DUSAGE_DEPTHSTENCIL
, D3DPOOL_DEFAULT
, multisample_type
, multisample_quality
, NULL
);
1200 static HRESULT WINAPI
d3d9_device_UpdateSurface(IDirect3DDevice9Ex
*iface
,
1201 IDirect3DSurface9
*src_surface
, const RECT
*src_rect
,
1202 IDirect3DSurface9
*dst_surface
, const POINT
*dst_point
)
1204 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1205 struct d3d9_surface
*src
= unsafe_impl_from_IDirect3DSurface9(src_surface
);
1206 struct d3d9_surface
*dst
= unsafe_impl_from_IDirect3DSurface9(dst_surface
);
1209 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_point %p.\n",
1210 iface
, src_surface
, src_rect
, dst_surface
, dst_point
);
1212 wined3d_mutex_lock();
1213 hr
= wined3d_device_update_surface(device
->wined3d_device
, src
->wined3d_surface
, src_rect
,
1214 dst
->wined3d_surface
, dst_point
);
1215 wined3d_mutex_unlock();
1220 static HRESULT WINAPI
d3d9_device_UpdateTexture(IDirect3DDevice9Ex
*iface
,
1221 IDirect3DBaseTexture9
*src_texture
, IDirect3DBaseTexture9
*dst_texture
)
1223 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1224 struct d3d9_texture
*src_impl
, *dst_impl
;
1227 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface
, src_texture
, dst_texture
);
1229 src_impl
= unsafe_impl_from_IDirect3DBaseTexture9(src_texture
);
1230 dst_impl
= unsafe_impl_from_IDirect3DBaseTexture9(dst_texture
);
1232 wined3d_mutex_lock();
1233 hr
= wined3d_device_update_texture(device
->wined3d_device
,
1234 src_impl
->wined3d_texture
, dst_impl
->wined3d_texture
);
1235 wined3d_mutex_unlock();
1240 static HRESULT WINAPI
d3d9_device_GetRenderTargetData(IDirect3DDevice9Ex
*iface
,
1241 IDirect3DSurface9
*render_target
, IDirect3DSurface9
*dst_surface
)
1243 struct d3d9_surface
*rt_impl
= unsafe_impl_from_IDirect3DSurface9(render_target
);
1244 struct d3d9_surface
*dst_impl
= unsafe_impl_from_IDirect3DSurface9(dst_surface
);
1247 TRACE("iface %p, render_target %p, dst_surface %p.\n", iface
, render_target
, dst_surface
);
1249 wined3d_mutex_lock();
1250 hr
= wined3d_surface_get_render_target_data(dst_impl
->wined3d_surface
, rt_impl
->wined3d_surface
);
1251 wined3d_mutex_unlock();
1256 static HRESULT WINAPI
d3d9_device_GetFrontBufferData(IDirect3DDevice9Ex
*iface
,
1257 UINT swapchain
, IDirect3DSurface9
*dst_surface
)
1259 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1260 struct d3d9_surface
*dst_impl
= unsafe_impl_from_IDirect3DSurface9(dst_surface
);
1263 TRACE("iface %p, swapchain %u, dst_surface %p.\n", iface
, swapchain
, dst_surface
);
1265 wined3d_mutex_lock();
1266 hr
= wined3d_device_get_front_buffer_data(device
->wined3d_device
, swapchain
, dst_impl
->wined3d_surface
);
1267 wined3d_mutex_unlock();
1272 static HRESULT WINAPI
d3d9_device_StretchRect(IDirect3DDevice9Ex
*iface
, IDirect3DSurface9
*src_surface
,
1273 const RECT
*src_rect
, IDirect3DSurface9
*dst_surface
, const RECT
*dst_rect
, D3DTEXTUREFILTERTYPE filter
)
1275 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1276 struct d3d9_surface
*src
= unsafe_impl_from_IDirect3DSurface9(src_surface
);
1277 struct d3d9_surface
*dst
= unsafe_impl_from_IDirect3DSurface9(dst_surface
);
1278 HRESULT hr
= D3DERR_INVALIDCALL
;
1279 struct wined3d_resource_desc src_desc
, dst_desc
;
1280 struct wined3d_resource
*wined3d_resource
;
1282 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_rect %p, filter %#x.\n",
1283 iface
, src_surface
, src_rect
, dst_surface
, dst_rect
, filter
);
1285 wined3d_mutex_lock();
1286 wined3d_resource
= wined3d_surface_get_resource(dst
->wined3d_surface
);
1287 wined3d_resource_get_desc(wined3d_resource
, &dst_desc
);
1289 wined3d_resource
= wined3d_surface_get_resource(src
->wined3d_surface
);
1290 wined3d_resource_get_desc(wined3d_resource
, &src_desc
);
1292 if (src_desc
.usage
& WINED3DUSAGE_DEPTHSTENCIL
)
1294 if (device
->in_scene
)
1296 WARN("Rejecting depth / stencil blit while in scene.\n");
1302 if (src_rect
->left
|| src_rect
->top
|| src_rect
->right
!= src_desc
.width
1303 || src_rect
->bottom
!= src_desc
.height
)
1305 WARN("Rejecting depth / stencil blit with invalid source rect %s.\n",
1306 wine_dbgstr_rect(src_rect
));
1312 if (dst_rect
->left
|| dst_rect
->top
|| dst_rect
->right
!= dst_desc
.width
1313 || dst_rect
->bottom
!= dst_desc
.height
)
1315 WARN("Rejecting depth / stencil blit with invalid destination rect %s.\n",
1316 wine_dbgstr_rect(dst_rect
));
1320 if (src_desc
.width
!= dst_desc
.width
|| src_desc
.height
!= dst_desc
.height
)
1322 WARN("Rejecting depth / stencil blit with mismatched surface sizes.\n");
1327 hr
= wined3d_surface_blt(dst
->wined3d_surface
, dst_rect
, src
->wined3d_surface
, src_rect
, 0, NULL
, filter
);
1328 if (hr
== WINEDDERR_INVALIDRECT
)
1329 hr
= D3DERR_INVALIDCALL
;
1332 wined3d_mutex_unlock();
1336 static HRESULT WINAPI
d3d9_device_ColorFill(IDirect3DDevice9Ex
*iface
,
1337 IDirect3DSurface9
*surface
, const RECT
*rect
, D3DCOLOR color
)
1339 const struct wined3d_color c
=
1341 ((color
>> 16) & 0xff) / 255.0f
,
1342 ((color
>> 8) & 0xff) / 255.0f
,
1343 (color
& 0xff) / 255.0f
,
1344 ((color
>> 24) & 0xff) / 255.0f
,
1346 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1347 struct d3d9_surface
*surface_impl
= unsafe_impl_from_IDirect3DSurface9(surface
);
1348 struct wined3d_resource
*wined3d_resource
;
1349 struct wined3d_resource_desc desc
;
1352 TRACE("iface %p, surface %p, rect %p, color 0x%08x.\n", iface
, surface
, rect
, color
);
1354 wined3d_mutex_lock();
1356 wined3d_resource
= wined3d_surface_get_resource(surface_impl
->wined3d_surface
);
1357 wined3d_resource_get_desc(wined3d_resource
, &desc
);
1359 if (desc
.pool
!= WINED3D_POOL_DEFAULT
)
1361 wined3d_mutex_unlock();
1362 WARN("Colorfill is not allowed on surfaces in pool %#x, returning D3DERR_INVALIDCALL.\n", desc
.pool
);
1363 return D3DERR_INVALIDCALL
;
1365 if ((desc
.usage
& (WINED3DUSAGE_RENDERTARGET
| WINED3DUSAGE_TEXTURE
)) == WINED3DUSAGE_TEXTURE
)
1367 wined3d_mutex_unlock();
1368 WARN("Colorfill is not allowed on non-RT textures, returning D3DERR_INVALIDCALL.\n");
1369 return D3DERR_INVALIDCALL
;
1371 if (desc
.usage
& WINED3DUSAGE_DEPTHSTENCIL
)
1373 wined3d_mutex_unlock();
1374 WARN("Colorfill is not allowed on depth stencil surfaces, returning D3DERR_INVALIDCALL.\n");
1375 return D3DERR_INVALIDCALL
;
1378 hr
= wined3d_device_clear_rendertarget_view(device
->wined3d_device
,
1379 d3d9_surface_get_rendertarget_view(surface_impl
), rect
, &c
);
1381 wined3d_mutex_unlock();
1386 static HRESULT WINAPI
d3d9_device_CreateOffscreenPlainSurface(IDirect3DDevice9Ex
*iface
,
1387 UINT width
, UINT height
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DSurface9
**surface
,
1388 HANDLE
*shared_handle
)
1390 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1391 void *user_mem
= NULL
;
1393 TRACE("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p.\n",
1394 iface
, width
, height
, format
, pool
, surface
, shared_handle
);
1397 if (pool
== D3DPOOL_MANAGED
)
1399 WARN("Attempting to create a managed offscreen plain surface.\n");
1400 return D3DERR_INVALIDCALL
;
1405 if (!device
->d3d_parent
->extended
)
1407 WARN("Trying to create a shared or user memory surface on a non-ex device.\n");
1411 if (pool
== D3DPOOL_SYSTEMMEM
)
1412 user_mem
= *shared_handle
;
1415 if (pool
!= D3DPOOL_DEFAULT
)
1417 WARN("Trying to create a shared surface in pool %#x.\n", pool
);
1418 return D3DERR_INVALIDCALL
;
1420 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1424 /* FIXME: Offscreen surfaces are supposed to be always lockable,
1425 * regardless of the pool they're created in. Should we set dynamic usage
1427 return d3d9_device_create_surface(device
, width
, height
, format
,
1428 WINED3D_SURFACE_MAPPABLE
, surface
, 0, pool
, D3DMULTISAMPLE_NONE
, 0, user_mem
);
1431 static HRESULT WINAPI
d3d9_device_SetRenderTarget(IDirect3DDevice9Ex
*iface
, DWORD idx
, IDirect3DSurface9
*surface
)
1433 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1434 struct d3d9_surface
*surface_impl
= unsafe_impl_from_IDirect3DSurface9(surface
);
1437 TRACE("iface %p, idx %u, surface %p.\n", iface
, idx
, surface
);
1439 if (idx
>= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS
)
1441 WARN("Invalid index %u specified.\n", idx
);
1442 return D3DERR_INVALIDCALL
;
1445 if (!idx
&& !surface_impl
)
1447 WARN("Trying to set render target 0 to NULL.\n");
1448 return D3DERR_INVALIDCALL
;
1451 wined3d_mutex_lock();
1452 hr
= wined3d_device_set_rendertarget_view(device
->wined3d_device
, idx
,
1453 surface_impl
? d3d9_surface_get_rendertarget_view(surface_impl
) : NULL
, TRUE
);
1454 wined3d_mutex_unlock();
1459 static HRESULT WINAPI
d3d9_device_GetRenderTarget(IDirect3DDevice9Ex
*iface
, DWORD idx
, IDirect3DSurface9
**surface
)
1461 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1462 struct wined3d_rendertarget_view
*wined3d_rtv
;
1463 struct d3d9_surface
*surface_impl
;
1464 HRESULT hr
= D3D_OK
;
1466 TRACE("iface %p, idx %u, surface %p.\n", iface
, idx
, surface
);
1469 return D3DERR_INVALIDCALL
;
1471 if (idx
>= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS
)
1473 WARN("Invalid index %u specified.\n", idx
);
1474 return D3DERR_INVALIDCALL
;
1477 wined3d_mutex_lock();
1478 if ((wined3d_rtv
= wined3d_device_get_rendertarget_view(device
->wined3d_device
, idx
)))
1480 /* We want the sub resource parent here, since the view itself may be
1481 * internal to wined3d and may not have a parent. */
1482 surface_impl
= wined3d_rendertarget_view_get_sub_resource_parent(wined3d_rtv
);
1483 *surface
= &surface_impl
->IDirect3DSurface9_iface
;
1484 IDirect3DSurface9_AddRef(*surface
);
1488 hr
= WINED3DERR_NOTFOUND
;
1491 wined3d_mutex_unlock();
1496 static HRESULT WINAPI
d3d9_device_SetDepthStencilSurface(IDirect3DDevice9Ex
*iface
, IDirect3DSurface9
*depth_stencil
)
1498 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1499 struct d3d9_surface
*ds_impl
= unsafe_impl_from_IDirect3DSurface9(depth_stencil
);
1501 TRACE("iface %p, depth_stencil %p.\n", iface
, depth_stencil
);
1503 wined3d_mutex_lock();
1504 wined3d_device_set_depth_stencil_view(device
->wined3d_device
,
1505 ds_impl
? d3d9_surface_get_rendertarget_view(ds_impl
) : NULL
);
1506 wined3d_mutex_unlock();
1511 static HRESULT WINAPI
d3d9_device_GetDepthStencilSurface(IDirect3DDevice9Ex
*iface
, IDirect3DSurface9
**depth_stencil
)
1513 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1514 struct wined3d_rendertarget_view
*wined3d_dsv
;
1515 struct d3d9_surface
*surface_impl
;
1516 HRESULT hr
= D3D_OK
;
1518 TRACE("iface %p, depth_stencil %p.\n", iface
, depth_stencil
);
1521 return D3DERR_INVALIDCALL
;
1523 wined3d_mutex_lock();
1524 if ((wined3d_dsv
= wined3d_device_get_depth_stencil_view(device
->wined3d_device
)))
1526 /* We want the sub resource parent here, since the view itself may be
1527 * internal to wined3d and may not have a parent. */
1528 surface_impl
= wined3d_rendertarget_view_get_sub_resource_parent(wined3d_dsv
);
1529 *depth_stencil
= &surface_impl
->IDirect3DSurface9_iface
;
1530 IDirect3DSurface9_AddRef(*depth_stencil
);
1534 hr
= WINED3DERR_NOTFOUND
;
1535 *depth_stencil
= NULL
;
1537 wined3d_mutex_unlock();
1542 static HRESULT WINAPI
d3d9_device_BeginScene(IDirect3DDevice9Ex
*iface
)
1544 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1547 TRACE("iface %p.\n", iface
);
1549 wined3d_mutex_lock();
1550 if (SUCCEEDED(hr
= wined3d_device_begin_scene(device
->wined3d_device
)))
1551 device
->in_scene
= TRUE
;
1552 wined3d_mutex_unlock();
1557 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_EndScene(IDirect3DDevice9Ex
*iface
)
1559 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1562 TRACE("iface %p.\n", iface
);
1564 wined3d_mutex_lock();
1565 if (SUCCEEDED(hr
= wined3d_device_end_scene(device
->wined3d_device
)))
1566 device
->in_scene
= FALSE
;
1567 wined3d_mutex_unlock();
1572 static HRESULT WINAPI
d3d9_device_Clear(IDirect3DDevice9Ex
*iface
, DWORD rect_count
,
1573 const D3DRECT
*rects
, DWORD flags
, D3DCOLOR color
, float z
, DWORD stencil
)
1575 const struct wined3d_color c
=
1577 ((color
>> 16) & 0xff) / 255.0f
,
1578 ((color
>> 8) & 0xff) / 255.0f
,
1579 (color
& 0xff) / 255.0f
,
1580 ((color
>> 24) & 0xff) / 255.0f
,
1582 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1585 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1586 iface
, rect_count
, rects
, flags
, color
, z
, stencil
);
1588 wined3d_mutex_lock();
1589 hr
= wined3d_device_clear(device
->wined3d_device
, rect_count
, (const RECT
*)rects
, flags
, &c
, z
, stencil
);
1590 wined3d_mutex_unlock();
1595 static HRESULT WINAPI
d3d9_device_SetTransform(IDirect3DDevice9Ex
*iface
,
1596 D3DTRANSFORMSTATETYPE state
, const D3DMATRIX
*matrix
)
1598 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1600 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1602 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1603 wined3d_mutex_lock();
1604 wined3d_device_set_transform(device
->wined3d_device
, state
, (const struct wined3d_matrix
*)matrix
);
1605 wined3d_mutex_unlock();
1610 static HRESULT WINAPI
d3d9_device_GetTransform(IDirect3DDevice9Ex
*iface
,
1611 D3DTRANSFORMSTATETYPE state
, D3DMATRIX
*matrix
)
1613 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1615 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1617 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1618 wined3d_mutex_lock();
1619 wined3d_device_get_transform(device
->wined3d_device
, state
, (struct wined3d_matrix
*)matrix
);
1620 wined3d_mutex_unlock();
1625 static HRESULT WINAPI
d3d9_device_MultiplyTransform(IDirect3DDevice9Ex
*iface
,
1626 D3DTRANSFORMSTATETYPE state
, const D3DMATRIX
*matrix
)
1628 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1630 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1632 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1633 wined3d_mutex_lock();
1634 wined3d_device_multiply_transform(device
->wined3d_device
, state
, (const struct wined3d_matrix
*)matrix
);
1635 wined3d_mutex_unlock();
1640 static HRESULT WINAPI
d3d9_device_SetViewport(IDirect3DDevice9Ex
*iface
, const D3DVIEWPORT9
*viewport
)
1642 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1644 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
1646 /* Note: D3DVIEWPORT9 is compatible with struct wined3d_viewport. */
1647 wined3d_mutex_lock();
1648 wined3d_device_set_viewport(device
->wined3d_device
, (const struct wined3d_viewport
*)viewport
);
1649 wined3d_mutex_unlock();
1654 static HRESULT WINAPI
d3d9_device_GetViewport(IDirect3DDevice9Ex
*iface
, D3DVIEWPORT9
*viewport
)
1656 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1658 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
1660 /* Note: D3DVIEWPORT9 is compatible with struct wined3d_viewport. */
1661 wined3d_mutex_lock();
1662 wined3d_device_get_viewport(device
->wined3d_device
, (struct wined3d_viewport
*)viewport
);
1663 wined3d_mutex_unlock();
1668 static HRESULT WINAPI
d3d9_device_SetMaterial(IDirect3DDevice9Ex
*iface
, const D3DMATERIAL9
*material
)
1670 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1672 TRACE("iface %p, material %p.\n", iface
, material
);
1674 /* Note: D3DMATERIAL9 is compatible with struct wined3d_material. */
1675 wined3d_mutex_lock();
1676 wined3d_device_set_material(device
->wined3d_device
, (const struct wined3d_material
*)material
);
1677 wined3d_mutex_unlock();
1682 static HRESULT WINAPI
d3d9_device_GetMaterial(IDirect3DDevice9Ex
*iface
, D3DMATERIAL9
*material
)
1684 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1686 TRACE("iface %p, material %p.\n", iface
, material
);
1688 /* Note: D3DMATERIAL9 is compatible with struct wined3d_material. */
1689 wined3d_mutex_lock();
1690 wined3d_device_get_material(device
->wined3d_device
, (struct wined3d_material
*)material
);
1691 wined3d_mutex_unlock();
1696 static HRESULT WINAPI
d3d9_device_SetLight(IDirect3DDevice9Ex
*iface
, DWORD index
, const D3DLIGHT9
*light
)
1698 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1701 TRACE("iface %p, index %u, light %p.\n", iface
, index
, light
);
1703 /* Note: D3DLIGHT9 is compatible with struct wined3d_light. */
1704 wined3d_mutex_lock();
1705 hr
= wined3d_device_set_light(device
->wined3d_device
, index
, (const struct wined3d_light
*)light
);
1706 wined3d_mutex_unlock();
1711 static HRESULT WINAPI
d3d9_device_GetLight(IDirect3DDevice9Ex
*iface
, DWORD index
, D3DLIGHT9
*light
)
1713 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1716 TRACE("iface %p, index %u, light %p.\n", iface
, index
, light
);
1718 /* Note: D3DLIGHT9 is compatible with struct wined3d_light. */
1719 wined3d_mutex_lock();
1720 hr
= wined3d_device_get_light(device
->wined3d_device
, index
, (struct wined3d_light
*)light
);
1721 wined3d_mutex_unlock();
1726 static HRESULT WINAPI
d3d9_device_LightEnable(IDirect3DDevice9Ex
*iface
, DWORD index
, BOOL enable
)
1728 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1731 TRACE("iface %p, index %u, enable %#x.\n", iface
, index
, enable
);
1733 wined3d_mutex_lock();
1734 hr
= wined3d_device_set_light_enable(device
->wined3d_device
, index
, enable
);
1735 wined3d_mutex_unlock();
1740 static HRESULT WINAPI
d3d9_device_GetLightEnable(IDirect3DDevice9Ex
*iface
, DWORD index
, BOOL
*enable
)
1742 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1745 TRACE("iface %p, index %u, enable %p.\n", iface
, index
, enable
);
1747 wined3d_mutex_lock();
1748 hr
= wined3d_device_get_light_enable(device
->wined3d_device
, index
, enable
);
1749 wined3d_mutex_unlock();
1754 static HRESULT WINAPI
d3d9_device_SetClipPlane(IDirect3DDevice9Ex
*iface
, DWORD index
, const float *plane
)
1756 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1759 TRACE("iface %p, index %u, plane %p.\n", iface
, index
, plane
);
1761 wined3d_mutex_lock();
1762 hr
= wined3d_device_set_clip_plane(device
->wined3d_device
, index
, (const struct wined3d_vec4
*)plane
);
1763 wined3d_mutex_unlock();
1768 static HRESULT WINAPI
d3d9_device_GetClipPlane(IDirect3DDevice9Ex
*iface
, DWORD index
, float *plane
)
1770 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1773 TRACE("iface %p, index %u, plane %p.\n", iface
, index
, plane
);
1775 wined3d_mutex_lock();
1776 hr
= wined3d_device_get_clip_plane(device
->wined3d_device
, index
, (struct wined3d_vec4
*)plane
);
1777 wined3d_mutex_unlock();
1782 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_SetRenderState(IDirect3DDevice9Ex
*iface
,
1783 D3DRENDERSTATETYPE state
, DWORD value
)
1785 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1787 TRACE("iface %p, state %#x, value %#x.\n", iface
, state
, value
);
1789 wined3d_mutex_lock();
1790 wined3d_device_set_render_state(device
->wined3d_device
, state
, value
);
1791 wined3d_mutex_unlock();
1796 static HRESULT WINAPI
d3d9_device_GetRenderState(IDirect3DDevice9Ex
*iface
,
1797 D3DRENDERSTATETYPE state
, DWORD
*value
)
1799 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1801 TRACE("iface %p, state %#x, value %p.\n", iface
, state
, value
);
1803 wined3d_mutex_lock();
1804 *value
= wined3d_device_get_render_state(device
->wined3d_device
, state
);
1805 wined3d_mutex_unlock();
1810 static HRESULT WINAPI
d3d9_device_CreateStateBlock(IDirect3DDevice9Ex
*iface
,
1811 D3DSTATEBLOCKTYPE type
, IDirect3DStateBlock9
**stateblock
)
1813 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1814 struct d3d9_stateblock
*object
;
1817 TRACE("iface %p, type %#x, stateblock %p.\n", iface
, type
, stateblock
);
1819 if (type
!= D3DSBT_ALL
&& type
!= D3DSBT_PIXELSTATE
&& type
!= D3DSBT_VERTEXSTATE
)
1821 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL.\n");
1822 return D3DERR_INVALIDCALL
;
1825 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1827 return E_OUTOFMEMORY
;
1829 hr
= stateblock_init(object
, device
, type
, NULL
);
1832 WARN("Failed to initialize stateblock, hr %#x.\n", hr
);
1833 HeapFree(GetProcessHeap(), 0, object
);
1837 TRACE("Created stateblock %p.\n", object
);
1838 *stateblock
= &object
->IDirect3DStateBlock9_iface
;
1843 static HRESULT WINAPI
d3d9_device_BeginStateBlock(IDirect3DDevice9Ex
*iface
)
1845 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1848 TRACE("iface %p.\n", iface
);
1850 wined3d_mutex_lock();
1851 hr
= wined3d_device_begin_stateblock(device
->wined3d_device
);
1852 wined3d_mutex_unlock();
1857 static HRESULT WINAPI
d3d9_device_EndStateBlock(IDirect3DDevice9Ex
*iface
, IDirect3DStateBlock9
**stateblock
)
1859 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1860 struct wined3d_stateblock
*wined3d_stateblock
;
1861 struct d3d9_stateblock
*object
;
1864 TRACE("iface %p, stateblock %p.\n", iface
, stateblock
);
1866 wined3d_mutex_lock();
1867 hr
= wined3d_device_end_stateblock(device
->wined3d_device
, &wined3d_stateblock
);
1868 wined3d_mutex_unlock();
1871 WARN("IWineD3DDevice_EndStateBlock() failed, hr %#x.\n", hr
);
1875 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1878 wined3d_mutex_lock();
1879 wined3d_stateblock_decref(wined3d_stateblock
);
1880 wined3d_mutex_unlock();
1881 return E_OUTOFMEMORY
;
1884 hr
= stateblock_init(object
, device
, 0, wined3d_stateblock
);
1887 WARN("Failed to initialize stateblock, hr %#x.\n", hr
);
1888 wined3d_mutex_lock();
1889 wined3d_stateblock_decref(wined3d_stateblock
);
1890 wined3d_mutex_unlock();
1891 HeapFree(GetProcessHeap(), 0, object
);
1895 TRACE("Created stateblock %p.\n", object
);
1896 *stateblock
= &object
->IDirect3DStateBlock9_iface
;
1901 static HRESULT WINAPI
d3d9_device_SetClipStatus(IDirect3DDevice9Ex
*iface
, const D3DCLIPSTATUS9
*clip_status
)
1903 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1906 TRACE("iface %p, clip_status %p.\n", iface
, clip_status
);
1908 wined3d_mutex_lock();
1909 hr
= wined3d_device_set_clip_status(device
->wined3d_device
, (const struct wined3d_clip_status
*)clip_status
);
1910 wined3d_mutex_unlock();
1915 static HRESULT WINAPI
d3d9_device_GetClipStatus(IDirect3DDevice9Ex
*iface
, D3DCLIPSTATUS9
*clip_status
)
1917 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1920 TRACE("iface %p, clip_status %p.\n", iface
, clip_status
);
1922 wined3d_mutex_lock();
1923 hr
= wined3d_device_get_clip_status(device
->wined3d_device
, (struct wined3d_clip_status
*)clip_status
);
1924 wined3d_mutex_unlock();
1929 static HRESULT WINAPI
d3d9_device_GetTexture(IDirect3DDevice9Ex
*iface
, DWORD stage
, IDirect3DBaseTexture9
**texture
)
1931 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1932 struct wined3d_texture
*wined3d_texture
= NULL
;
1933 struct d3d9_texture
*texture_impl
;
1935 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
1938 return D3DERR_INVALIDCALL
;
1940 wined3d_mutex_lock();
1941 if ((wined3d_texture
= wined3d_device_get_texture(device
->wined3d_device
, stage
)))
1943 texture_impl
= wined3d_texture_get_parent(wined3d_texture
);
1944 *texture
= &texture_impl
->IDirect3DBaseTexture9_iface
;
1945 IDirect3DBaseTexture9_AddRef(*texture
);
1951 wined3d_mutex_unlock();
1956 static HRESULT WINAPI
d3d9_device_SetTexture(IDirect3DDevice9Ex
*iface
, DWORD stage
, IDirect3DBaseTexture9
*texture
)
1958 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1959 struct d3d9_texture
*texture_impl
;
1962 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
1964 texture_impl
= unsafe_impl_from_IDirect3DBaseTexture9(texture
);
1966 wined3d_mutex_lock();
1967 hr
= wined3d_device_set_texture(device
->wined3d_device
, stage
,
1968 texture_impl
? texture_impl
->wined3d_texture
: NULL
);
1969 wined3d_mutex_unlock();
1974 static const enum wined3d_texture_stage_state tss_lookup
[] =
1976 WINED3D_TSS_INVALID
, /* 0, unused */
1977 WINED3D_TSS_COLOR_OP
, /* 1, D3DTSS_COLOROP */
1978 WINED3D_TSS_COLOR_ARG1
, /* 2, D3DTSS_COLORARG1 */
1979 WINED3D_TSS_COLOR_ARG2
, /* 3, D3DTSS_COLORARG2 */
1980 WINED3D_TSS_ALPHA_OP
, /* 4, D3DTSS_ALPHAOP */
1981 WINED3D_TSS_ALPHA_ARG1
, /* 5, D3DTSS_ALPHAARG1 */
1982 WINED3D_TSS_ALPHA_ARG2
, /* 6, D3DTSS_ALPHAARG2 */
1983 WINED3D_TSS_BUMPENV_MAT00
, /* 7, D3DTSS_BUMPENVMAT00 */
1984 WINED3D_TSS_BUMPENV_MAT01
, /* 8, D3DTSS_BUMPENVMAT01 */
1985 WINED3D_TSS_BUMPENV_MAT10
, /* 9, D3DTSS_BUMPENVMAT10 */
1986 WINED3D_TSS_BUMPENV_MAT11
, /* 10, D3DTSS_BUMPENVMAT11 */
1987 WINED3D_TSS_TEXCOORD_INDEX
, /* 11, D3DTSS_TEXCOORDINDEX */
1988 WINED3D_TSS_INVALID
, /* 12, unused */
1989 WINED3D_TSS_INVALID
, /* 13, unused */
1990 WINED3D_TSS_INVALID
, /* 14, unused */
1991 WINED3D_TSS_INVALID
, /* 15, unused */
1992 WINED3D_TSS_INVALID
, /* 16, unused */
1993 WINED3D_TSS_INVALID
, /* 17, unused */
1994 WINED3D_TSS_INVALID
, /* 18, unused */
1995 WINED3D_TSS_INVALID
, /* 19, unused */
1996 WINED3D_TSS_INVALID
, /* 20, unused */
1997 WINED3D_TSS_INVALID
, /* 21, unused */
1998 WINED3D_TSS_BUMPENV_LSCALE
, /* 22, D3DTSS_BUMPENVLSCALE */
1999 WINED3D_TSS_BUMPENV_LOFFSET
, /* 23, D3DTSS_BUMPENVLOFFSET */
2000 WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
2001 WINED3D_TSS_INVALID
, /* 25, unused */
2002 WINED3D_TSS_COLOR_ARG0
, /* 26, D3DTSS_COLORARG0 */
2003 WINED3D_TSS_ALPHA_ARG0
, /* 27, D3DTSS_ALPHAARG0 */
2004 WINED3D_TSS_RESULT_ARG
, /* 28, D3DTSS_RESULTARG */
2005 WINED3D_TSS_INVALID
, /* 29, unused */
2006 WINED3D_TSS_INVALID
, /* 30, unused */
2007 WINED3D_TSS_INVALID
, /* 31, unused */
2008 WINED3D_TSS_CONSTANT
, /* 32, D3DTSS_CONSTANT */
2011 static HRESULT WINAPI
d3d9_device_GetTextureStageState(IDirect3DDevice9Ex
*iface
,
2012 DWORD stage
, D3DTEXTURESTAGESTATETYPE state
, DWORD
*value
)
2014 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2016 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface
, stage
, state
, value
);
2018 if (state
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
2020 WARN("Invalid state %#x passed.\n", state
);
2024 wined3d_mutex_lock();
2025 *value
= wined3d_device_get_texture_stage_state(device
->wined3d_device
, stage
, tss_lookup
[state
]);
2026 wined3d_mutex_unlock();
2031 static HRESULT WINAPI
d3d9_device_SetTextureStageState(IDirect3DDevice9Ex
*iface
,
2032 DWORD stage
, D3DTEXTURESTAGESTATETYPE state
, DWORD value
)
2034 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2036 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface
, stage
, state
, value
);
2038 if (state
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
2040 WARN("Invalid state %#x passed.\n", state
);
2044 wined3d_mutex_lock();
2045 wined3d_device_set_texture_stage_state(device
->wined3d_device
, stage
, tss_lookup
[state
], value
);
2046 wined3d_mutex_unlock();
2051 static HRESULT WINAPI
d3d9_device_GetSamplerState(IDirect3DDevice9Ex
*iface
,
2052 DWORD sampler
, D3DSAMPLERSTATETYPE state
, DWORD
*value
)
2054 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2056 TRACE("iface %p, sampler %u, state %#x, value %p.\n", iface
, sampler
, state
, value
);
2058 wined3d_mutex_lock();
2059 *value
= wined3d_device_get_sampler_state(device
->wined3d_device
, sampler
, state
);
2060 wined3d_mutex_unlock();
2065 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_SetSamplerState(IDirect3DDevice9Ex
*iface
,
2066 DWORD sampler
, D3DSAMPLERSTATETYPE state
, DWORD value
)
2068 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2070 TRACE("iface %p, sampler %u, state %#x, value %#x.\n", iface
, sampler
, state
, value
);
2072 wined3d_mutex_lock();
2073 wined3d_device_set_sampler_state(device
->wined3d_device
, sampler
, state
, value
);
2074 wined3d_mutex_unlock();
2079 static HRESULT WINAPI
d3d9_device_ValidateDevice(IDirect3DDevice9Ex
*iface
, DWORD
*pass_count
)
2081 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2084 TRACE("iface %p, pass_count %p.\n", iface
, pass_count
);
2086 wined3d_mutex_lock();
2087 hr
= wined3d_device_validate_device(device
->wined3d_device
, pass_count
);
2088 wined3d_mutex_unlock();
2093 static HRESULT WINAPI
d3d9_device_SetPaletteEntries(IDirect3DDevice9Ex
*iface
,
2094 UINT palette_idx
, const PALETTEENTRY
*entries
)
2096 WARN("iface %p, palette_idx %u, entries %p unimplemented.\n", iface
, palette_idx
, entries
);
2098 /* The d3d9 palette API is non-functional on Windows. Getters and setters are implemented,
2099 * and some drivers allow the creation of P8 surfaces. These surfaces can be copied to
2100 * other P8 surfaces with StretchRect, but cannot be converted to (A)RGB.
2102 * Some older(dx7) cards may have support for P8 textures, but games cannot rely on this. */
2106 static HRESULT WINAPI
d3d9_device_GetPaletteEntries(IDirect3DDevice9Ex
*iface
,
2107 UINT palette_idx
, PALETTEENTRY
*entries
)
2109 FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface
, palette_idx
, entries
);
2111 return D3DERR_INVALIDCALL
;
2114 static HRESULT WINAPI
d3d9_device_SetCurrentTexturePalette(IDirect3DDevice9Ex
*iface
, UINT palette_idx
)
2116 WARN("iface %p, palette_idx %u unimplemented.\n", iface
, palette_idx
);
2121 static HRESULT WINAPI
d3d9_device_GetCurrentTexturePalette(IDirect3DDevice9Ex
*iface
, UINT
*palette_idx
)
2123 FIXME("iface %p, palette_idx %p.\n", iface
, palette_idx
);
2125 return D3DERR_INVALIDCALL
;
2128 static HRESULT WINAPI
d3d9_device_SetScissorRect(IDirect3DDevice9Ex
*iface
, const RECT
*rect
)
2130 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2132 TRACE("iface %p, rect %p.\n", iface
, rect
);
2134 wined3d_mutex_lock();
2135 wined3d_device_set_scissor_rect(device
->wined3d_device
, rect
);
2136 wined3d_mutex_unlock();
2141 static HRESULT WINAPI
d3d9_device_GetScissorRect(IDirect3DDevice9Ex
*iface
, RECT
*rect
)
2143 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2145 TRACE("iface %p, rect %p.\n", iface
, rect
);
2147 wined3d_mutex_lock();
2148 wined3d_device_get_scissor_rect(device
->wined3d_device
, rect
);
2149 wined3d_mutex_unlock();
2154 static HRESULT WINAPI
d3d9_device_SetSoftwareVertexProcessing(IDirect3DDevice9Ex
*iface
, BOOL software
)
2156 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2158 TRACE("iface %p, software %#x.\n", iface
, software
);
2160 wined3d_mutex_lock();
2161 wined3d_device_set_software_vertex_processing(device
->wined3d_device
, software
);
2162 wined3d_mutex_unlock();
2167 static BOOL WINAPI
d3d9_device_GetSoftwareVertexProcessing(IDirect3DDevice9Ex
*iface
)
2169 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2172 TRACE("iface %p.\n", iface
);
2174 wined3d_mutex_lock();
2175 ret
= wined3d_device_get_software_vertex_processing(device
->wined3d_device
);
2176 wined3d_mutex_unlock();
2181 static HRESULT WINAPI
d3d9_device_SetNPatchMode(IDirect3DDevice9Ex
*iface
, float segment_count
)
2183 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2186 TRACE("iface %p, segment_count %.8e.\n", iface
, segment_count
);
2188 wined3d_mutex_lock();
2189 hr
= wined3d_device_set_npatch_mode(device
->wined3d_device
, segment_count
);
2190 wined3d_mutex_unlock();
2195 static float WINAPI
d3d9_device_GetNPatchMode(IDirect3DDevice9Ex
*iface
)
2197 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2200 TRACE("iface %p.\n", iface
);
2202 wined3d_mutex_lock();
2203 ret
= wined3d_device_get_npatch_mode(device
->wined3d_device
);
2204 wined3d_mutex_unlock();
2209 static HRESULT WINAPI
d3d9_device_DrawPrimitive(IDirect3DDevice9Ex
*iface
,
2210 D3DPRIMITIVETYPE primitive_type
, UINT start_vertex
, UINT primitive_count
)
2212 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2215 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
2216 iface
, primitive_type
, start_vertex
, primitive_count
);
2218 wined3d_mutex_lock();
2219 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
2220 hr
= wined3d_device_draw_primitive(device
->wined3d_device
, start_vertex
,
2221 vertex_count_from_primitive_count(primitive_type
, primitive_count
));
2222 wined3d_mutex_unlock();
2227 static HRESULT WINAPI
d3d9_device_DrawIndexedPrimitive(IDirect3DDevice9Ex
*iface
,
2228 D3DPRIMITIVETYPE primitive_type
, INT base_vertex_idx
, UINT min_vertex_idx
,
2229 UINT vertex_count
, UINT start_idx
, UINT primitive_count
)
2231 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2234 TRACE("iface %p, primitive_type %#x, base_vertex_idx %u, min_vertex_idx %u,\n"
2235 "vertex_count %u, start_idx %u, primitive_count %u.\n",
2236 iface
, primitive_type
, base_vertex_idx
, min_vertex_idx
,
2237 vertex_count
, start_idx
, primitive_count
);
2239 wined3d_mutex_lock();
2240 wined3d_device_set_base_vertex_index(device
->wined3d_device
, base_vertex_idx
);
2241 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
2242 hr
= wined3d_device_draw_indexed_primitive(device
->wined3d_device
, start_idx
,
2243 vertex_count_from_primitive_count(primitive_type
, primitive_count
));
2244 wined3d_mutex_unlock();
2249 /* The caller is responsible for wined3d locking */
2250 static HRESULT
d3d9_device_prepare_vertex_buffer(struct d3d9_device
*device
, UINT min_size
)
2254 if (device
->vertex_buffer_size
< min_size
|| !device
->vertex_buffer
)
2256 UINT size
= max(device
->vertex_buffer_size
* 2, min_size
);
2257 struct wined3d_buffer
*buffer
;
2259 TRACE("Growing vertex buffer to %u bytes\n", size
);
2261 hr
= wined3d_buffer_create_vb(device
->wined3d_device
, size
, WINED3DUSAGE_DYNAMIC
| WINED3DUSAGE_WRITEONLY
,
2262 WINED3D_POOL_DEFAULT
, NULL
, &d3d9_null_wined3d_parent_ops
, &buffer
);
2265 ERR("(%p) wined3d_buffer_create_vb failed with hr = %08x\n", device
, hr
);
2269 if (device
->vertex_buffer
)
2270 wined3d_buffer_decref(device
->vertex_buffer
);
2272 device
->vertex_buffer
= buffer
;
2273 device
->vertex_buffer_size
= size
;
2274 device
->vertex_buffer_pos
= 0;
2279 static HRESULT WINAPI
d3d9_device_DrawPrimitiveUP(IDirect3DDevice9Ex
*iface
,
2280 D3DPRIMITIVETYPE primitive_type
, UINT primitive_count
, const void *data
, UINT stride
)
2282 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2284 UINT vtx_count
= vertex_count_from_primitive_count(primitive_type
, primitive_count
);
2285 UINT size
= vtx_count
* stride
;
2289 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
2290 iface
, primitive_type
, primitive_count
, data
, stride
);
2292 if (!primitive_count
)
2294 WARN("primitive_count is 0, returning D3D_OK\n");
2298 wined3d_mutex_lock();
2300 hr
= d3d9_device_prepare_vertex_buffer(device
, size
);
2304 vb_pos
= device
->vertex_buffer_pos
;
2305 align
= vb_pos
% stride
;
2306 if (align
) align
= stride
- align
;
2307 if (vb_pos
+ size
+ align
> device
->vertex_buffer_size
)
2312 hr
= wined3d_buffer_map(device
->vertex_buffer
, vb_pos
, size
, &buffer_data
,
2313 vb_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
);
2316 memcpy(buffer_data
, data
, size
);
2317 wined3d_buffer_unmap(device
->vertex_buffer
);
2318 device
->vertex_buffer_pos
= vb_pos
+ size
;
2320 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, 0, device
->vertex_buffer
, 0, stride
);
2324 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
2325 hr
= wined3d_device_draw_primitive(device
->wined3d_device
, vb_pos
/ stride
, vtx_count
);
2326 wined3d_device_set_stream_source(device
->wined3d_device
, 0, NULL
, 0, 0);
2329 wined3d_mutex_unlock();
2333 /* The caller is responsible for wined3d locking */
2334 static HRESULT
d3d9_device_prepare_index_buffer(struct d3d9_device
*device
, UINT min_size
)
2338 if (device
->index_buffer_size
< min_size
|| !device
->index_buffer
)
2340 UINT size
= max(device
->index_buffer_size
* 2, min_size
);
2341 struct wined3d_buffer
*buffer
;
2343 TRACE("Growing index buffer to %u bytes\n", size
);
2345 hr
= wined3d_buffer_create_ib(device
->wined3d_device
, size
, WINED3DUSAGE_DYNAMIC
| WINED3DUSAGE_WRITEONLY
,
2346 WINED3D_POOL_DEFAULT
, NULL
, &d3d9_null_wined3d_parent_ops
, &buffer
);
2349 ERR("(%p) wined3d_buffer_create_ib failed with hr = %08x\n", device
, hr
);
2353 if (device
->index_buffer
)
2354 wined3d_buffer_decref(device
->index_buffer
);
2356 device
->index_buffer
= buffer
;
2357 device
->index_buffer_size
= size
;
2358 device
->index_buffer_pos
= 0;
2363 static HRESULT WINAPI
d3d9_device_DrawIndexedPrimitiveUP(IDirect3DDevice9Ex
*iface
,
2364 D3DPRIMITIVETYPE primitive_type
, UINT min_vertex_idx
, UINT vertex_count
,
2365 UINT primitive_count
, const void *index_data
, D3DFORMAT index_format
,
2366 const void *vertex_data
, UINT vertex_stride
)
2368 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2372 UINT idx_count
= vertex_count_from_primitive_count(primitive_type
, primitive_count
);
2373 UINT idx_fmt_size
= index_format
== D3DFMT_INDEX16
? 2 : 4;
2374 UINT idx_size
= idx_count
* idx_fmt_size
;
2377 UINT vtx_size
= vertex_count
* vertex_stride
;
2380 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, primitive_count %u,\n"
2381 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
2382 iface
, primitive_type
, min_vertex_idx
, vertex_count
, primitive_count
,
2383 index_data
, index_format
, vertex_data
, vertex_stride
);
2385 if (!primitive_count
)
2387 WARN("primitive_count is 0, returning D3D_OK\n");
2391 wined3d_mutex_lock();
2393 hr
= d3d9_device_prepare_vertex_buffer(device
, vtx_size
);
2397 vb_pos
= device
->vertex_buffer_pos
;
2398 align
= vb_pos
% vertex_stride
;
2399 if (align
) align
= vertex_stride
- align
;
2400 if (vb_pos
+ vtx_size
+ align
> device
->vertex_buffer_size
)
2405 hr
= wined3d_buffer_map(device
->vertex_buffer
, vb_pos
, vtx_size
, &buffer_data
,
2406 vb_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
);
2409 memcpy(buffer_data
, vertex_data
, vtx_size
);
2410 wined3d_buffer_unmap(device
->vertex_buffer
);
2411 device
->vertex_buffer_pos
= vb_pos
+ vtx_size
;
2413 hr
= d3d9_device_prepare_index_buffer(device
, idx_size
);
2417 ib_pos
= device
->index_buffer_pos
;
2418 align
= ib_pos
% idx_fmt_size
;
2419 if (align
) align
= idx_fmt_size
- align
;
2420 if (ib_pos
+ idx_size
+ align
> device
->index_buffer_size
)
2425 hr
= wined3d_buffer_map(device
->index_buffer
, ib_pos
, idx_size
, &buffer_data
,
2426 ib_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
);
2429 memcpy(buffer_data
, index_data
, idx_size
);
2430 wined3d_buffer_unmap(device
->index_buffer
);
2431 device
->index_buffer_pos
= ib_pos
+ idx_size
;
2433 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, 0, device
->vertex_buffer
, 0, vertex_stride
);
2437 wined3d_device_set_index_buffer(device
->wined3d_device
, device
->index_buffer
,
2438 wined3dformat_from_d3dformat(index_format
));
2439 wined3d_device_set_base_vertex_index(device
->wined3d_device
, vb_pos
/ vertex_stride
);
2441 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
2442 hr
= wined3d_device_draw_indexed_primitive(device
->wined3d_device
, ib_pos
/ idx_fmt_size
, idx_count
);
2444 wined3d_device_set_stream_source(device
->wined3d_device
, 0, NULL
, 0, 0);
2445 wined3d_device_set_index_buffer(device
->wined3d_device
, NULL
, WINED3DFMT_UNKNOWN
);
2446 wined3d_device_set_base_vertex_index(device
->wined3d_device
, 0);
2449 wined3d_mutex_unlock();
2453 static HRESULT WINAPI
d3d9_device_ProcessVertices(IDirect3DDevice9Ex
*iface
,
2454 UINT src_start_idx
, UINT dst_idx
, UINT vertex_count
, IDirect3DVertexBuffer9
*dst_buffer
,
2455 IDirect3DVertexDeclaration9
*declaration
, DWORD flags
)
2457 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2458 struct d3d9_vertexbuffer
*dst_impl
= unsafe_impl_from_IDirect3DVertexBuffer9(dst_buffer
);
2459 struct d3d9_vertex_declaration
*decl_impl
= unsafe_impl_from_IDirect3DVertexDeclaration9(declaration
);
2462 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, declaration %p, flags %#x.\n",
2463 iface
, src_start_idx
, dst_idx
, vertex_count
, dst_buffer
, declaration
, flags
);
2465 wined3d_mutex_lock();
2466 hr
= wined3d_device_process_vertices(device
->wined3d_device
, src_start_idx
, dst_idx
, vertex_count
,
2467 dst_impl
->wined3d_buffer
, decl_impl
? decl_impl
->wined3d_declaration
: NULL
,
2468 flags
, dst_impl
->fvf
);
2469 wined3d_mutex_unlock();
2474 static HRESULT WINAPI
d3d9_device_CreateVertexDeclaration(IDirect3DDevice9Ex
*iface
,
2475 const D3DVERTEXELEMENT9
*elements
, IDirect3DVertexDeclaration9
**declaration
)
2477 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2478 struct d3d9_vertex_declaration
*object
;
2481 TRACE("iface %p, elements %p, declaration %p.\n", iface
, elements
, declaration
);
2485 WARN("Caller passed a NULL declaration, returning D3DERR_INVALIDCALL.\n");
2486 return D3DERR_INVALIDCALL
;
2489 if (SUCCEEDED(hr
= d3d9_vertex_declaration_create(device
, elements
, &object
)))
2490 *declaration
= &object
->IDirect3DVertexDeclaration9_iface
;
2495 static HRESULT WINAPI
d3d9_device_SetVertexDeclaration(IDirect3DDevice9Ex
*iface
,
2496 IDirect3DVertexDeclaration9
*declaration
)
2498 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2499 struct d3d9_vertex_declaration
*decl_impl
= unsafe_impl_from_IDirect3DVertexDeclaration9(declaration
);
2501 TRACE("iface %p, declaration %p.\n", iface
, declaration
);
2503 wined3d_mutex_lock();
2504 wined3d_device_set_vertex_declaration(device
->wined3d_device
,
2505 decl_impl
? decl_impl
->wined3d_declaration
: NULL
);
2506 wined3d_mutex_unlock();
2511 static HRESULT WINAPI
d3d9_device_GetVertexDeclaration(IDirect3DDevice9Ex
*iface
,
2512 IDirect3DVertexDeclaration9
**declaration
)
2514 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2515 struct wined3d_vertex_declaration
*wined3d_declaration
;
2516 struct d3d9_vertex_declaration
*declaration_impl
;
2518 TRACE("iface %p, declaration %p.\n", iface
, declaration
);
2520 if (!declaration
) return D3DERR_INVALIDCALL
;
2522 wined3d_mutex_lock();
2523 if ((wined3d_declaration
= wined3d_device_get_vertex_declaration(device
->wined3d_device
)))
2525 declaration_impl
= wined3d_vertex_declaration_get_parent(wined3d_declaration
);
2526 *declaration
= &declaration_impl
->IDirect3DVertexDeclaration9_iface
;
2527 IDirect3DVertexDeclaration9_AddRef(*declaration
);
2531 *declaration
= NULL
;
2533 wined3d_mutex_unlock();
2535 TRACE("Returning %p.\n", *declaration
);
2539 static struct wined3d_vertex_declaration
*device_get_fvf_declaration(struct d3d9_device
*device
, DWORD fvf
)
2541 struct wined3d_vertex_declaration
*wined3d_declaration
;
2542 struct fvf_declaration
*fvf_decls
= device
->fvf_decls
;
2543 struct d3d9_vertex_declaration
*d3d9_declaration
;
2544 D3DVERTEXELEMENT9
*elements
;
2545 int p
, low
, high
; /* deliberately signed */
2548 TRACE("Searching for declaration for fvf %08x... ", fvf
);
2551 high
= device
->fvf_decl_count
- 1;
2554 p
= (low
+ high
) >> 1;
2557 if (fvf_decls
[p
].fvf
== fvf
)
2559 TRACE("found %p.\n", fvf_decls
[p
].decl
);
2560 return fvf_decls
[p
].decl
;
2563 if (fvf_decls
[p
].fvf
< fvf
)
2568 TRACE("not found. Creating and inserting at position %d.\n", low
);
2570 if (FAILED(hr
= vdecl_convert_fvf(fvf
, &elements
)))
2573 hr
= d3d9_vertex_declaration_create(device
, elements
, &d3d9_declaration
);
2574 HeapFree(GetProcessHeap(), 0, elements
);
2578 if (device
->fvf_decl_size
== device
->fvf_decl_count
)
2580 UINT grow
= max(device
->fvf_decl_size
/ 2, 8);
2582 fvf_decls
= HeapReAlloc(GetProcessHeap(), 0, fvf_decls
, sizeof(*fvf_decls
) * (device
->fvf_decl_size
+ grow
));
2585 IDirect3DVertexDeclaration9_Release(&d3d9_declaration
->IDirect3DVertexDeclaration9_iface
);
2588 device
->fvf_decls
= fvf_decls
;
2589 device
->fvf_decl_size
+= grow
;
2592 d3d9_declaration
->fvf
= fvf
;
2593 wined3d_declaration
= d3d9_declaration
->wined3d_declaration
;
2594 wined3d_vertex_declaration_incref(wined3d_declaration
);
2595 IDirect3DVertexDeclaration9_Release(&d3d9_declaration
->IDirect3DVertexDeclaration9_iface
);
2597 memmove(fvf_decls
+ low
+ 1, fvf_decls
+ low
, sizeof(*fvf_decls
) * (device
->fvf_decl_count
- low
));
2598 fvf_decls
[low
].decl
= wined3d_declaration
;
2599 fvf_decls
[low
].fvf
= fvf
;
2600 ++device
->fvf_decl_count
;
2602 TRACE("Returning %p. %u declarations in array.\n", wined3d_declaration
, device
->fvf_decl_count
);
2604 return wined3d_declaration
;
2607 static HRESULT WINAPI
d3d9_device_SetFVF(IDirect3DDevice9Ex
*iface
, DWORD fvf
)
2609 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2610 struct wined3d_vertex_declaration
*decl
;
2612 TRACE("iface %p, fvf %#x.\n", iface
, fvf
);
2616 WARN("%#x is not a valid FVF.\n", fvf
);
2620 wined3d_mutex_lock();
2621 if (!(decl
= device_get_fvf_declaration(device
, fvf
)))
2623 wined3d_mutex_unlock();
2624 ERR("Failed to create a vertex declaration for fvf %#x.\n", fvf
);
2625 return D3DERR_DRIVERINTERNALERROR
;
2628 wined3d_device_set_vertex_declaration(device
->wined3d_device
, decl
);
2629 wined3d_mutex_unlock();
2634 static HRESULT WINAPI
d3d9_device_GetFVF(IDirect3DDevice9Ex
*iface
, DWORD
*fvf
)
2636 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2637 struct wined3d_vertex_declaration
*wined3d_declaration
;
2638 struct d3d9_vertex_declaration
*d3d9_declaration
;
2640 TRACE("iface %p, fvf %p.\n", iface
, fvf
);
2642 wined3d_mutex_lock();
2643 if ((wined3d_declaration
= wined3d_device_get_vertex_declaration(device
->wined3d_device
)))
2645 d3d9_declaration
= wined3d_vertex_declaration_get_parent(wined3d_declaration
);
2646 *fvf
= d3d9_declaration
->fvf
;
2652 wined3d_mutex_unlock();
2654 TRACE("Returning FVF %#x.\n", *fvf
);
2659 static HRESULT WINAPI
d3d9_device_CreateVertexShader(IDirect3DDevice9Ex
*iface
,
2660 const DWORD
*byte_code
, IDirect3DVertexShader9
**shader
)
2662 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2663 struct d3d9_vertexshader
*object
;
2666 TRACE("iface %p, byte_code %p, shader %p.\n", iface
, byte_code
, shader
);
2668 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2670 return E_OUTOFMEMORY
;
2672 hr
= vertexshader_init(object
, device
, byte_code
);
2675 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
2676 HeapFree(GetProcessHeap(), 0, object
);
2680 TRACE("Created vertex shader %p.\n", object
);
2681 *shader
= &object
->IDirect3DVertexShader9_iface
;
2686 static HRESULT WINAPI
d3d9_device_SetVertexShader(IDirect3DDevice9Ex
*iface
, IDirect3DVertexShader9
*shader
)
2688 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2689 struct d3d9_vertexshader
*shader_obj
= unsafe_impl_from_IDirect3DVertexShader9(shader
);
2691 TRACE("iface %p, shader %p.\n", iface
, shader
);
2693 wined3d_mutex_lock();
2694 wined3d_device_set_vertex_shader(device
->wined3d_device
,
2695 shader_obj
? shader_obj
->wined3d_shader
: NULL
);
2696 wined3d_mutex_unlock();
2701 static HRESULT WINAPI
d3d9_device_GetVertexShader(IDirect3DDevice9Ex
*iface
, IDirect3DVertexShader9
**shader
)
2703 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2704 struct d3d9_vertexshader
*shader_impl
;
2705 struct wined3d_shader
*wined3d_shader
;
2707 TRACE("iface %p, shader %p.\n", iface
, shader
);
2709 wined3d_mutex_lock();
2710 if ((wined3d_shader
= wined3d_device_get_vertex_shader(device
->wined3d_device
)))
2712 shader_impl
= wined3d_shader_get_parent(wined3d_shader
);
2713 *shader
= &shader_impl
->IDirect3DVertexShader9_iface
;
2714 IDirect3DVertexShader9_AddRef(*shader
);
2720 wined3d_mutex_unlock();
2722 TRACE("Returning %p.\n", *shader
);
2727 static HRESULT WINAPI
d3d9_device_SetVertexShaderConstantF(IDirect3DDevice9Ex
*iface
,
2728 UINT reg_idx
, const float *data
, UINT count
)
2730 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2733 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2735 if (reg_idx
+ count
> D3D9_MAX_VERTEX_SHADER_CONSTANTF
)
2737 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
2738 reg_idx
+ count
, D3D9_MAX_VERTEX_SHADER_CONSTANTF
);
2739 return D3DERR_INVALIDCALL
;
2742 wined3d_mutex_lock();
2743 hr
= wined3d_device_set_vs_consts_f(device
->wined3d_device
, reg_idx
, data
, count
);
2744 wined3d_mutex_unlock();
2749 static HRESULT WINAPI
d3d9_device_GetVertexShaderConstantF(IDirect3DDevice9Ex
*iface
,
2750 UINT reg_idx
, float *data
, UINT count
)
2752 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2755 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2757 if (reg_idx
+ count
> D3D9_MAX_VERTEX_SHADER_CONSTANTF
)
2759 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
2760 reg_idx
+ count
, D3D9_MAX_VERTEX_SHADER_CONSTANTF
);
2761 return D3DERR_INVALIDCALL
;
2764 wined3d_mutex_lock();
2765 hr
= wined3d_device_get_vs_consts_f(device
->wined3d_device
, reg_idx
, data
, count
);
2766 wined3d_mutex_unlock();
2771 static HRESULT WINAPI
d3d9_device_SetVertexShaderConstantI(IDirect3DDevice9Ex
*iface
,
2772 UINT reg_idx
, const int *data
, UINT count
)
2774 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2777 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2779 wined3d_mutex_lock();
2780 hr
= wined3d_device_set_vs_consts_i(device
->wined3d_device
, reg_idx
, data
, count
);
2781 wined3d_mutex_unlock();
2786 static HRESULT WINAPI
d3d9_device_GetVertexShaderConstantI(IDirect3DDevice9Ex
*iface
,
2787 UINT reg_idx
, int *data
, UINT count
)
2789 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2792 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2794 wined3d_mutex_lock();
2795 hr
= wined3d_device_get_vs_consts_i(device
->wined3d_device
, reg_idx
, data
, count
);
2796 wined3d_mutex_unlock();
2801 static HRESULT WINAPI
d3d9_device_SetVertexShaderConstantB(IDirect3DDevice9Ex
*iface
,
2802 UINT reg_idx
, const BOOL
*data
, UINT count
)
2804 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2807 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2809 wined3d_mutex_lock();
2810 hr
= wined3d_device_set_vs_consts_b(device
->wined3d_device
, reg_idx
, data
, count
);
2811 wined3d_mutex_unlock();
2816 static HRESULT WINAPI
d3d9_device_GetVertexShaderConstantB(IDirect3DDevice9Ex
*iface
,
2817 UINT reg_idx
, BOOL
*data
, UINT count
)
2819 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2822 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2824 wined3d_mutex_lock();
2825 hr
= wined3d_device_get_vs_consts_b(device
->wined3d_device
, reg_idx
, data
, count
);
2826 wined3d_mutex_unlock();
2831 static HRESULT WINAPI
d3d9_device_SetStreamSource(IDirect3DDevice9Ex
*iface
,
2832 UINT stream_idx
, IDirect3DVertexBuffer9
*buffer
, UINT offset
, UINT stride
)
2834 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2835 struct d3d9_vertexbuffer
*buffer_impl
= unsafe_impl_from_IDirect3DVertexBuffer9(buffer
);
2838 TRACE("iface %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
2839 iface
, stream_idx
, buffer
, offset
, stride
);
2841 wined3d_mutex_lock();
2842 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, stream_idx
,
2843 buffer_impl
? buffer_impl
->wined3d_buffer
: NULL
, offset
, stride
);
2844 wined3d_mutex_unlock();
2849 static HRESULT WINAPI
d3d9_device_GetStreamSource(IDirect3DDevice9Ex
*iface
,
2850 UINT stream_idx
, IDirect3DVertexBuffer9
**buffer
, UINT
*offset
, UINT
*stride
)
2852 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2853 struct d3d9_vertexbuffer
*buffer_impl
;
2854 struct wined3d_buffer
*wined3d_buffer
;
2857 TRACE("iface %p, stream_idx %u, buffer %p, offset %p, stride %p.\n",
2858 iface
, stream_idx
, buffer
, offset
, stride
);
2861 return D3DERR_INVALIDCALL
;
2863 wined3d_mutex_lock();
2864 hr
= wined3d_device_get_stream_source(device
->wined3d_device
, stream_idx
, &wined3d_buffer
, offset
, stride
);
2865 if (SUCCEEDED(hr
) && wined3d_buffer
)
2867 buffer_impl
= wined3d_buffer_get_parent(wined3d_buffer
);
2868 *buffer
= &buffer_impl
->IDirect3DVertexBuffer9_iface
;
2869 IDirect3DVertexBuffer9_AddRef(*buffer
);
2874 FIXME("Call to GetStreamSource failed %p %p\n", offset
, stride
);
2877 wined3d_mutex_unlock();
2882 static HRESULT WINAPI
d3d9_device_SetStreamSourceFreq(IDirect3DDevice9Ex
*iface
, UINT stream_idx
, UINT freq
)
2884 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2887 TRACE("iface %p, stream_idx %u, freq %u.\n", iface
, stream_idx
, freq
);
2889 wined3d_mutex_lock();
2890 hr
= wined3d_device_set_stream_source_freq(device
->wined3d_device
, stream_idx
, freq
);
2891 wined3d_mutex_unlock();
2896 static HRESULT WINAPI
d3d9_device_GetStreamSourceFreq(IDirect3DDevice9Ex
*iface
, UINT stream_idx
, UINT
*freq
)
2898 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2901 TRACE("iface %p, stream_idx %u, freq %p.\n", iface
, stream_idx
, freq
);
2903 wined3d_mutex_lock();
2904 hr
= wined3d_device_get_stream_source_freq(device
->wined3d_device
, stream_idx
, freq
);
2905 wined3d_mutex_unlock();
2910 static HRESULT WINAPI
d3d9_device_SetIndices(IDirect3DDevice9Ex
*iface
, IDirect3DIndexBuffer9
*buffer
)
2912 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2913 struct d3d9_indexbuffer
*ib
= unsafe_impl_from_IDirect3DIndexBuffer9(buffer
);
2915 TRACE("iface %p, buffer %p.\n", iface
, buffer
);
2917 wined3d_mutex_lock();
2918 wined3d_device_set_index_buffer(device
->wined3d_device
,
2919 ib
? ib
->wined3d_buffer
: NULL
,
2920 ib
? ib
->format
: WINED3DFMT_UNKNOWN
);
2921 wined3d_mutex_unlock();
2926 static HRESULT WINAPI
d3d9_device_GetIndices(IDirect3DDevice9Ex
*iface
, IDirect3DIndexBuffer9
**buffer
)
2928 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2929 enum wined3d_format_id wined3d_format
;
2930 struct wined3d_buffer
*wined3d_buffer
;
2931 struct d3d9_indexbuffer
*buffer_impl
;
2933 TRACE("iface %p, buffer %p.\n", iface
, buffer
);
2936 return D3DERR_INVALIDCALL
;
2938 wined3d_mutex_lock();
2939 if ((wined3d_buffer
= wined3d_device_get_index_buffer(device
->wined3d_device
, &wined3d_format
)))
2941 buffer_impl
= wined3d_buffer_get_parent(wined3d_buffer
);
2942 *buffer
= &buffer_impl
->IDirect3DIndexBuffer9_iface
;
2943 IDirect3DIndexBuffer9_AddRef(*buffer
);
2949 wined3d_mutex_unlock();
2954 static HRESULT WINAPI
d3d9_device_CreatePixelShader(IDirect3DDevice9Ex
*iface
,
2955 const DWORD
*byte_code
, IDirect3DPixelShader9
**shader
)
2957 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2958 struct d3d9_pixelshader
*object
;
2961 TRACE("iface %p, byte_code %p, shader %p.\n", iface
, byte_code
, shader
);
2963 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2966 FIXME("Failed to allocate pixel shader memory.\n");
2967 return E_OUTOFMEMORY
;
2970 hr
= pixelshader_init(object
, device
, byte_code
);
2973 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
2974 HeapFree(GetProcessHeap(), 0, object
);
2978 TRACE("Created pixel shader %p.\n", object
);
2979 *shader
= &object
->IDirect3DPixelShader9_iface
;
2984 static HRESULT WINAPI
d3d9_device_SetPixelShader(IDirect3DDevice9Ex
*iface
, IDirect3DPixelShader9
*shader
)
2986 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2987 struct d3d9_pixelshader
*shader_obj
= unsafe_impl_from_IDirect3DPixelShader9(shader
);
2989 TRACE("iface %p, shader %p.\n", iface
, shader
);
2991 wined3d_mutex_lock();
2992 wined3d_device_set_pixel_shader(device
->wined3d_device
,
2993 shader_obj
? shader_obj
->wined3d_shader
: NULL
);
2994 wined3d_mutex_unlock();
2999 static HRESULT WINAPI
d3d9_device_GetPixelShader(IDirect3DDevice9Ex
*iface
, IDirect3DPixelShader9
**shader
)
3001 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3002 struct d3d9_pixelshader
*shader_impl
;
3003 struct wined3d_shader
*wined3d_shader
;
3005 TRACE("iface %p, shader %p.\n", iface
, shader
);
3007 if (!shader
) return D3DERR_INVALIDCALL
;
3009 wined3d_mutex_lock();
3010 if ((wined3d_shader
= wined3d_device_get_pixel_shader(device
->wined3d_device
)))
3012 shader_impl
= wined3d_shader_get_parent(wined3d_shader
);
3013 *shader
= &shader_impl
->IDirect3DPixelShader9_iface
;
3014 IDirect3DPixelShader9_AddRef(*shader
);
3020 wined3d_mutex_unlock();
3022 TRACE("Returning %p.\n", *shader
);
3027 static HRESULT WINAPI
d3d9_device_SetPixelShaderConstantF(IDirect3DDevice9Ex
*iface
,
3028 UINT reg_idx
, const float *data
, UINT count
)
3030 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3033 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3035 wined3d_mutex_lock();
3036 hr
= wined3d_device_set_ps_consts_f(device
->wined3d_device
, reg_idx
, data
, count
);
3037 wined3d_mutex_unlock();
3042 static HRESULT WINAPI
d3d9_device_GetPixelShaderConstantF(IDirect3DDevice9Ex
*iface
,
3043 UINT reg_idx
, float *data
, UINT count
)
3045 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3048 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3050 wined3d_mutex_lock();
3051 hr
= wined3d_device_get_ps_consts_f(device
->wined3d_device
, reg_idx
, data
, count
);
3052 wined3d_mutex_unlock();
3057 static HRESULT WINAPI
d3d9_device_SetPixelShaderConstantI(IDirect3DDevice9Ex
*iface
,
3058 UINT reg_idx
, const int *data
, UINT count
)
3060 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3063 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3065 wined3d_mutex_lock();
3066 hr
= wined3d_device_set_ps_consts_i(device
->wined3d_device
, reg_idx
, data
, count
);
3067 wined3d_mutex_unlock();
3072 static HRESULT WINAPI
d3d9_device_GetPixelShaderConstantI(IDirect3DDevice9Ex
*iface
,
3073 UINT reg_idx
, int *data
, UINT count
)
3075 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3078 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3080 wined3d_mutex_lock();
3081 hr
= wined3d_device_get_ps_consts_i(device
->wined3d_device
, reg_idx
, data
, count
);
3082 wined3d_mutex_unlock();
3087 static HRESULT WINAPI
d3d9_device_SetPixelShaderConstantB(IDirect3DDevice9Ex
*iface
,
3088 UINT reg_idx
, const BOOL
*data
, UINT count
)
3090 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3093 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3095 wined3d_mutex_lock();
3096 hr
= wined3d_device_set_ps_consts_b(device
->wined3d_device
, reg_idx
, data
, count
);
3097 wined3d_mutex_unlock();
3102 static HRESULT WINAPI
d3d9_device_GetPixelShaderConstantB(IDirect3DDevice9Ex
*iface
,
3103 UINT reg_idx
, BOOL
*data
, UINT count
)
3105 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3108 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3110 wined3d_mutex_lock();
3111 hr
= wined3d_device_get_ps_consts_b(device
->wined3d_device
, reg_idx
, data
, count
);
3112 wined3d_mutex_unlock();
3117 static HRESULT WINAPI
d3d9_device_DrawRectPatch(IDirect3DDevice9Ex
*iface
, UINT handle
,
3118 const float *segment_count
, const D3DRECTPATCH_INFO
*patch_info
)
3120 FIXME("iface %p, handle %#x, segment_count %p, patch_info %p unimplemented.\n",
3121 iface
, handle
, segment_count
, patch_info
);
3125 static HRESULT WINAPI
d3d9_device_DrawTriPatch(IDirect3DDevice9Ex
*iface
, UINT handle
,
3126 const float *segment_count
, const D3DTRIPATCH_INFO
*patch_info
)
3128 FIXME("iface %p, handle %#x, segment_count %p, patch_info %p unimplemented.\n",
3129 iface
, handle
, segment_count
, patch_info
);
3133 static HRESULT WINAPI
d3d9_device_DeletePatch(IDirect3DDevice9Ex
*iface
, UINT handle
)
3135 FIXME("iface %p, handle %#x unimplemented.\n", iface
, handle
);
3136 return D3DERR_INVALIDCALL
;
3139 static HRESULT WINAPI
d3d9_device_CreateQuery(IDirect3DDevice9Ex
*iface
, D3DQUERYTYPE type
, IDirect3DQuery9
**query
)
3141 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3142 struct d3d9_query
*object
;
3145 TRACE("iface %p, type %#x, query %p.\n", iface
, type
, query
);
3147 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3149 return E_OUTOFMEMORY
;
3151 hr
= query_init(object
, device
, type
);
3154 WARN("Failed to initialize query, hr %#x.\n", hr
);
3155 HeapFree(GetProcessHeap(), 0, object
);
3159 TRACE("Created query %p.\n", object
);
3160 if (query
) *query
= &object
->IDirect3DQuery9_iface
;
3161 else IDirect3DQuery9_Release(&object
->IDirect3DQuery9_iface
);
3166 static HRESULT WINAPI
d3d9_device_SetConvolutionMonoKernel(IDirect3DDevice9Ex
*iface
,
3167 UINT width
, UINT height
, float *rows
, float *columns
)
3169 FIXME("iface %p, width %u, height %u, rows %p, columns %p stub!\n",
3170 iface
, width
, height
, rows
, columns
);
3175 static HRESULT WINAPI
d3d9_device_ComposeRects(IDirect3DDevice9Ex
*iface
,
3176 IDirect3DSurface9
*src_surface
, IDirect3DSurface9
*dst_surface
, IDirect3DVertexBuffer9
*src_descs
,
3177 UINT rect_count
, IDirect3DVertexBuffer9
*dst_descs
, D3DCOMPOSERECTSOP operation
, INT offset_x
, INT offset_y
)
3179 FIXME("iface %p, src_surface %p, dst_surface %p, src_descs %p, rect_count %u,\n"
3180 "dst_descs %p, operation %#x, offset_x %u, offset_y %u stub!\n",
3181 iface
, src_surface
, dst_surface
, src_descs
, rect_count
,
3182 dst_descs
, operation
, offset_x
, offset_y
);
3187 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_PresentEx(IDirect3DDevice9Ex
*iface
,
3188 const RECT
*src_rect
, const RECT
*dst_rect
, HWND dst_window_override
,
3189 const RGNDATA
*dirty_region
, DWORD flags
)
3191 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3194 TRACE("iface %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p, flags %#x.\n",
3195 iface
, wine_dbgstr_rect(src_rect
), wine_dbgstr_rect(dst_rect
),
3196 dst_window_override
, dirty_region
, flags
);
3198 if (device
->device_state
!= D3D9_DEVICE_STATE_OK
)
3199 return S_PRESENT_OCCLUDED
;
3201 wined3d_mutex_lock();
3202 hr
= wined3d_device_present(device
->wined3d_device
, src_rect
, dst_rect
,
3203 dst_window_override
, dirty_region
, flags
);
3204 wined3d_mutex_unlock();
3209 static HRESULT WINAPI
d3d9_device_GetGPUThreadPriority(IDirect3DDevice9Ex
*iface
, INT
*priority
)
3211 FIXME("iface %p, priority %p stub!\n", iface
, priority
);
3216 static HRESULT WINAPI
d3d9_device_SetGPUThreadPriority(IDirect3DDevice9Ex
*iface
, INT priority
)
3218 FIXME("iface %p, priority %d stub!\n", iface
, priority
);
3223 static HRESULT WINAPI
d3d9_device_WaitForVBlank(IDirect3DDevice9Ex
*iface
, UINT swapchain_idx
)
3225 FIXME("iface %p, swapchain_idx %u stub!\n", iface
, swapchain_idx
);
3230 static HRESULT WINAPI
d3d9_device_CheckResourceResidency(IDirect3DDevice9Ex
*iface
,
3231 IDirect3DResource9
**resources
, UINT32 resource_count
)
3233 FIXME("iface %p, resources %p, resource_count %u stub!\n",
3234 iface
, resources
, resource_count
);
3239 static HRESULT WINAPI
d3d9_device_SetMaximumFrameLatency(IDirect3DDevice9Ex
*iface
, UINT max_latency
)
3241 FIXME("iface %p, max_latency %u stub!\n", iface
, max_latency
);
3246 static HRESULT WINAPI
d3d9_device_GetMaximumFrameLatency(IDirect3DDevice9Ex
*iface
, UINT
*max_latency
)
3248 FIXME("iface %p, max_latency %p stub!\n", iface
, max_latency
);
3255 static HRESULT WINAPI
d3d9_device_CheckDeviceState(IDirect3DDevice9Ex
*iface
, HWND dst_window
)
3257 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3258 struct wined3d_swapchain_desc swapchain_desc
;
3259 struct wined3d_swapchain
*swapchain
;
3261 TRACE("iface %p, dst_window %p.\n", iface
, dst_window
);
3263 wined3d_mutex_lock();
3264 swapchain
= wined3d_device_get_swapchain(device
->wined3d_device
, 0);
3265 wined3d_swapchain_get_desc(swapchain
, &swapchain_desc
);
3266 wined3d_mutex_unlock();
3268 if (swapchain_desc
.windowed
)
3271 /* FIXME: This is actually supposed to check if any other device is in
3272 * fullscreen mode. */
3273 if (dst_window
!= swapchain_desc
.device_window
)
3274 return device
->device_state
== D3D9_DEVICE_STATE_OK
? S_PRESENT_OCCLUDED
: D3D_OK
;
3276 return device
->device_state
== D3D9_DEVICE_STATE_OK
? D3D_OK
: S_PRESENT_OCCLUDED
;
3279 static HRESULT WINAPI
d3d9_device_CreateRenderTargetEx(IDirect3DDevice9Ex
*iface
,
3280 UINT width
, UINT height
, D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
3281 BOOL lockable
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
, DWORD usage
)
3283 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
3284 "lockable %#x, surface %p, shared_handle %p, usage %#x stub!\n",
3285 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
3286 lockable
, surface
, shared_handle
, usage
);
3290 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
3295 static HRESULT WINAPI
d3d9_device_CreateOffscreenPlainSurfaceEx(IDirect3DDevice9Ex
*iface
,
3296 UINT width
, UINT height
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DSurface9
**surface
,
3297 HANDLE
*shared_handle
, DWORD usage
)
3299 FIXME("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p, usage %#x stub!\n",
3300 iface
, width
, height
, format
, pool
, surface
, shared_handle
, usage
);
3305 static HRESULT WINAPI
d3d9_device_CreateDepthStencilSurfaceEx(IDirect3DDevice9Ex
*iface
,
3306 UINT width
, UINT height
, D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
3307 BOOL discard
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
, DWORD usage
)
3309 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
3310 "discard %#x, surface %p, shared_handle %p, usage %#x stub!\n",
3311 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
3312 discard
, surface
, shared_handle
, usage
);
3316 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
3321 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_ResetEx(IDirect3DDevice9Ex
*iface
,
3322 D3DPRESENT_PARAMETERS
*present_parameters
, D3DDISPLAYMODEEX
*mode
)
3324 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3326 TRACE("iface %p, present_parameters %p, mode %p.\n", iface
, present_parameters
, mode
);
3328 return d3d9_device_reset(device
, present_parameters
, mode
);
3331 static HRESULT WINAPI
d3d9_device_GetDisplayModeEx(IDirect3DDevice9Ex
*iface
,
3332 UINT swapchain_idx
, D3DDISPLAYMODEEX
*mode
, D3DDISPLAYROTATION
*rotation
)
3334 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3335 struct wined3d_display_mode wined3d_mode
;
3338 TRACE("iface %p, swapchain_idx %u, mode %p, rotation %p.\n",
3339 iface
, swapchain_idx
, mode
, rotation
);
3341 if (mode
->Size
!= sizeof(*mode
))
3342 return D3DERR_INVALIDCALL
;
3344 wined3d_mutex_lock();
3345 hr
= wined3d_device_get_display_mode(device
->wined3d_device
, swapchain_idx
, &wined3d_mode
,
3346 (enum wined3d_display_rotation
*)rotation
);
3347 wined3d_mutex_unlock();
3351 mode
->Width
= wined3d_mode
.width
;
3352 mode
->Height
= wined3d_mode
.height
;
3353 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
3354 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
3355 mode
->ScanLineOrdering
= wined3d_mode
.scanline_ordering
;
3361 static const struct IDirect3DDevice9ExVtbl d3d9_device_vtbl
=
3364 d3d9_device_QueryInterface
,
3366 d3d9_device_Release
,
3367 /* IDirect3DDevice9 */
3368 d3d9_device_TestCooperativeLevel
,
3369 d3d9_device_GetAvailableTextureMem
,
3370 d3d9_device_EvictManagedResources
,
3371 d3d9_device_GetDirect3D
,
3372 d3d9_device_GetDeviceCaps
,
3373 d3d9_device_GetDisplayMode
,
3374 d3d9_device_GetCreationParameters
,
3375 d3d9_device_SetCursorProperties
,
3376 d3d9_device_SetCursorPosition
,
3377 d3d9_device_ShowCursor
,
3378 d3d9_device_CreateAdditionalSwapChain
,
3379 d3d9_device_GetSwapChain
,
3380 d3d9_device_GetNumberOfSwapChains
,
3382 d3d9_device_Present
,
3383 d3d9_device_GetBackBuffer
,
3384 d3d9_device_GetRasterStatus
,
3385 d3d9_device_SetDialogBoxMode
,
3386 d3d9_device_SetGammaRamp
,
3387 d3d9_device_GetGammaRamp
,
3388 d3d9_device_CreateTexture
,
3389 d3d9_device_CreateVolumeTexture
,
3390 d3d9_device_CreateCubeTexture
,
3391 d3d9_device_CreateVertexBuffer
,
3392 d3d9_device_CreateIndexBuffer
,
3393 d3d9_device_CreateRenderTarget
,
3394 d3d9_device_CreateDepthStencilSurface
,
3395 d3d9_device_UpdateSurface
,
3396 d3d9_device_UpdateTexture
,
3397 d3d9_device_GetRenderTargetData
,
3398 d3d9_device_GetFrontBufferData
,
3399 d3d9_device_StretchRect
,
3400 d3d9_device_ColorFill
,
3401 d3d9_device_CreateOffscreenPlainSurface
,
3402 d3d9_device_SetRenderTarget
,
3403 d3d9_device_GetRenderTarget
,
3404 d3d9_device_SetDepthStencilSurface
,
3405 d3d9_device_GetDepthStencilSurface
,
3406 d3d9_device_BeginScene
,
3407 d3d9_device_EndScene
,
3409 d3d9_device_SetTransform
,
3410 d3d9_device_GetTransform
,
3411 d3d9_device_MultiplyTransform
,
3412 d3d9_device_SetViewport
,
3413 d3d9_device_GetViewport
,
3414 d3d9_device_SetMaterial
,
3415 d3d9_device_GetMaterial
,
3416 d3d9_device_SetLight
,
3417 d3d9_device_GetLight
,
3418 d3d9_device_LightEnable
,
3419 d3d9_device_GetLightEnable
,
3420 d3d9_device_SetClipPlane
,
3421 d3d9_device_GetClipPlane
,
3422 d3d9_device_SetRenderState
,
3423 d3d9_device_GetRenderState
,
3424 d3d9_device_CreateStateBlock
,
3425 d3d9_device_BeginStateBlock
,
3426 d3d9_device_EndStateBlock
,
3427 d3d9_device_SetClipStatus
,
3428 d3d9_device_GetClipStatus
,
3429 d3d9_device_GetTexture
,
3430 d3d9_device_SetTexture
,
3431 d3d9_device_GetTextureStageState
,
3432 d3d9_device_SetTextureStageState
,
3433 d3d9_device_GetSamplerState
,
3434 d3d9_device_SetSamplerState
,
3435 d3d9_device_ValidateDevice
,
3436 d3d9_device_SetPaletteEntries
,
3437 d3d9_device_GetPaletteEntries
,
3438 d3d9_device_SetCurrentTexturePalette
,
3439 d3d9_device_GetCurrentTexturePalette
,
3440 d3d9_device_SetScissorRect
,
3441 d3d9_device_GetScissorRect
,
3442 d3d9_device_SetSoftwareVertexProcessing
,
3443 d3d9_device_GetSoftwareVertexProcessing
,
3444 d3d9_device_SetNPatchMode
,
3445 d3d9_device_GetNPatchMode
,
3446 d3d9_device_DrawPrimitive
,
3447 d3d9_device_DrawIndexedPrimitive
,
3448 d3d9_device_DrawPrimitiveUP
,
3449 d3d9_device_DrawIndexedPrimitiveUP
,
3450 d3d9_device_ProcessVertices
,
3451 d3d9_device_CreateVertexDeclaration
,
3452 d3d9_device_SetVertexDeclaration
,
3453 d3d9_device_GetVertexDeclaration
,
3456 d3d9_device_CreateVertexShader
,
3457 d3d9_device_SetVertexShader
,
3458 d3d9_device_GetVertexShader
,
3459 d3d9_device_SetVertexShaderConstantF
,
3460 d3d9_device_GetVertexShaderConstantF
,
3461 d3d9_device_SetVertexShaderConstantI
,
3462 d3d9_device_GetVertexShaderConstantI
,
3463 d3d9_device_SetVertexShaderConstantB
,
3464 d3d9_device_GetVertexShaderConstantB
,
3465 d3d9_device_SetStreamSource
,
3466 d3d9_device_GetStreamSource
,
3467 d3d9_device_SetStreamSourceFreq
,
3468 d3d9_device_GetStreamSourceFreq
,
3469 d3d9_device_SetIndices
,
3470 d3d9_device_GetIndices
,
3471 d3d9_device_CreatePixelShader
,
3472 d3d9_device_SetPixelShader
,
3473 d3d9_device_GetPixelShader
,
3474 d3d9_device_SetPixelShaderConstantF
,
3475 d3d9_device_GetPixelShaderConstantF
,
3476 d3d9_device_SetPixelShaderConstantI
,
3477 d3d9_device_GetPixelShaderConstantI
,
3478 d3d9_device_SetPixelShaderConstantB
,
3479 d3d9_device_GetPixelShaderConstantB
,
3480 d3d9_device_DrawRectPatch
,
3481 d3d9_device_DrawTriPatch
,
3482 d3d9_device_DeletePatch
,
3483 d3d9_device_CreateQuery
,
3484 /* IDirect3DDevice9Ex */
3485 d3d9_device_SetConvolutionMonoKernel
,
3486 d3d9_device_ComposeRects
,
3487 d3d9_device_PresentEx
,
3488 d3d9_device_GetGPUThreadPriority
,
3489 d3d9_device_SetGPUThreadPriority
,
3490 d3d9_device_WaitForVBlank
,
3491 d3d9_device_CheckResourceResidency
,
3492 d3d9_device_SetMaximumFrameLatency
,
3493 d3d9_device_GetMaximumFrameLatency
,
3494 d3d9_device_CheckDeviceState
,
3495 d3d9_device_CreateRenderTargetEx
,
3496 d3d9_device_CreateOffscreenPlainSurfaceEx
,
3497 d3d9_device_CreateDepthStencilSurfaceEx
,
3498 d3d9_device_ResetEx
,
3499 d3d9_device_GetDisplayModeEx
,
3502 static inline struct d3d9_device
*device_from_device_parent(struct wined3d_device_parent
*device_parent
)
3504 return CONTAINING_RECORD(device_parent
, struct d3d9_device
, device_parent
);
3507 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
3508 struct wined3d_device
*device
)
3510 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
3513 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
3515 TRACE("device_parent %p.\n", device_parent
);
3518 static void CDECL
device_parent_activate(struct wined3d_device_parent
*device_parent
, BOOL activate
)
3520 struct d3d9_device
*device
= device_from_device_parent(device_parent
);
3522 TRACE("device_parent %p, activate %#x.\n", device_parent
, activate
);
3524 if (!device
->d3d_parent
)
3528 InterlockedCompareExchange(&device
->device_state
, D3D9_DEVICE_STATE_LOST
, D3D9_DEVICE_STATE_OK
);
3529 else if (device
->d3d_parent
->extended
)
3530 InterlockedCompareExchange(&device
->device_state
, D3D9_DEVICE_STATE_OK
, D3D9_DEVICE_STATE_LOST
);
3532 InterlockedCompareExchange(&device
->device_state
, D3D9_DEVICE_STATE_NOT_RESET
, D3D9_DEVICE_STATE_LOST
);
3535 static HRESULT CDECL
device_parent_surface_created(struct wined3d_device_parent
*device_parent
,
3536 void *container_parent
, struct wined3d_surface
*surface
, void **parent
,
3537 const struct wined3d_parent_ops
**parent_ops
)
3539 struct d3d9_surface
*d3d_surface
;
3541 TRACE("device_parent %p, container_parent %p, surface %p, parent %p, parent_ops %p.\n",
3542 device_parent
, container_parent
, surface
, parent
, parent_ops
);
3544 if (!(d3d_surface
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*d3d_surface
))))
3545 return E_OUTOFMEMORY
;
3547 surface_init(d3d_surface
, container_parent
, surface
, parent_ops
);
3548 *parent
= d3d_surface
;
3549 TRACE("Created surface %p.\n", d3d_surface
);
3554 static HRESULT CDECL
device_parent_volume_created(struct wined3d_device_parent
*device_parent
,
3555 void *container_parent
, struct wined3d_volume
*volume
, void **parent
,
3556 const struct wined3d_parent_ops
**parent_ops
)
3558 struct d3d9_volume
*d3d_volume
;
3560 TRACE("device_parent %p, container_parent %p, volume %p, parent %p, parent_ops %p.\n",
3561 device_parent
, container_parent
, volume
, parent
, parent_ops
);
3563 if (!(d3d_volume
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*d3d_volume
))))
3564 return E_OUTOFMEMORY
;
3566 volume_init(d3d_volume
, container_parent
, volume
, parent_ops
);
3567 *parent
= d3d_volume
;
3568 TRACE("Created volume %p.\n", d3d_volume
);
3573 static HRESULT CDECL
device_parent_create_swapchain_surface(struct wined3d_device_parent
*device_parent
,
3574 void *container_parent
, const struct wined3d_resource_desc
*desc
, struct wined3d_surface
**surface
)
3576 struct d3d9_device
*device
= device_from_device_parent(device_parent
);
3577 struct wined3d_resource_desc texture_desc
;
3578 struct d3d9_surface
*d3d_surface
;
3579 struct wined3d_texture
*texture
;
3582 TRACE("device_parent %p, container_parent %p, desc %p, surface %p.\n",
3583 device_parent
, container_parent
, desc
, surface
);
3585 if (container_parent
== device_parent
)
3586 container_parent
= &device
->IDirect3DDevice9Ex_iface
;
3588 texture_desc
= *desc
;
3589 texture_desc
.resource_type
= WINED3D_RTYPE_TEXTURE
;
3590 if (FAILED(hr
= wined3d_texture_create(device
->wined3d_device
, &texture_desc
, 1,
3591 WINED3D_SURFACE_MAPPABLE
, NULL
, container_parent
, &d3d9_null_wined3d_parent_ops
, &texture
)))
3593 WARN("Failed to create texture, hr %#x.\n", hr
);
3597 *surface
= wined3d_surface_from_resource(wined3d_texture_get_sub_resource(texture
, 0));
3598 wined3d_surface_incref(*surface
);
3599 wined3d_texture_decref(texture
);
3601 d3d_surface
= wined3d_surface_get_parent(*surface
);
3602 d3d_surface
->parent_device
= &device
->IDirect3DDevice9Ex_iface
;
3607 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
3608 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain
**swapchain
)
3610 struct d3d9_device
*device
= device_from_device_parent(device_parent
);
3611 struct d3d9_swapchain
*d3d_swapchain
;
3614 TRACE("device_parent %p, desc %p, swapchain %p\n", device_parent
, desc
, swapchain
);
3616 hr
= d3d9_swapchain_create(device
, desc
, &d3d_swapchain
);
3619 WARN("Failed to create swapchain, hr %#x.\n", hr
);
3624 *swapchain
= d3d_swapchain
->wined3d_swapchain
;
3625 wined3d_swapchain_incref(*swapchain
);
3626 IDirect3DSwapChain9Ex_Release(&d3d_swapchain
->IDirect3DSwapChain9Ex_iface
);
3631 static const struct wined3d_device_parent_ops d3d9_wined3d_device_parent_ops
=
3633 device_parent_wined3d_device_created
,
3634 device_parent_mode_changed
,
3635 device_parent_activate
,
3636 device_parent_surface_created
,
3637 device_parent_volume_created
,
3638 device_parent_create_swapchain_surface
,
3639 device_parent_create_swapchain
,
3642 static void setup_fpu(void)
3644 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3646 __asm__
volatile ("fnstcw %0" : "=m" (cw
));
3647 cw
= (cw
& ~0xf3f) | 0x3f;
3648 __asm__
volatile ("fldcw %0" : : "m" (cw
));
3649 #elif defined(__i386__) && defined(_MSC_VER)
3652 cw
= (cw
& ~0xf3f) | 0x3f;
3655 FIXME("FPU setup not implemented for this platform.\n");
3659 HRESULT
device_init(struct d3d9_device
*device
, struct d3d9
*parent
, struct wined3d
*wined3d
,
3660 UINT adapter
, D3DDEVTYPE device_type
, HWND focus_window
, DWORD flags
,
3661 D3DPRESENT_PARAMETERS
*parameters
, D3DDISPLAYMODEEX
*mode
)
3663 struct wined3d_swapchain_desc
*swapchain_desc
;
3668 FIXME("Ignoring display mode.\n");
3670 device
->IDirect3DDevice9Ex_iface
.lpVtbl
= &d3d9_device_vtbl
;
3671 device
->device_parent
.ops
= &d3d9_wined3d_device_parent_ops
;
3672 device
->refcount
= 1;
3674 if (!(flags
& D3DCREATE_FPU_PRESERVE
)) setup_fpu();
3676 wined3d_mutex_lock();
3677 hr
= wined3d_device_create(wined3d
, adapter
, device_type
, focus_window
, flags
, 4,
3678 &device
->device_parent
, &device
->wined3d_device
);
3681 WARN("Failed to create wined3d device, hr %#x.\n", hr
);
3682 wined3d_mutex_unlock();
3686 if (flags
& D3DCREATE_ADAPTERGROUP_DEVICE
)
3690 wined3d_get_device_caps(wined3d
, adapter
, device_type
, &caps
);
3691 count
= caps
.NumberOfAdaptersInGroup
;
3694 if (flags
& D3DCREATE_MULTITHREADED
)
3695 wined3d_device_set_multithreaded(device
->wined3d_device
);
3697 if (!parameters
->Windowed
)
3700 focus_window
= parameters
->hDeviceWindow
;
3701 if (FAILED(hr
= wined3d_device_acquire_focus_window(device
->wined3d_device
, focus_window
)))
3703 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
3704 wined3d_device_decref(device
->wined3d_device
);
3705 wined3d_mutex_unlock();
3709 for (i
= 0; i
< count
; ++i
)
3711 HWND device_window
= parameters
[i
].hDeviceWindow
;
3713 if (!device_window
) device_window
= focus_window
;
3714 wined3d_device_setup_fullscreen_window(device
->wined3d_device
, device_window
,
3715 parameters
[i
].BackBufferWidth
,
3716 parameters
[i
].BackBufferHeight
);
3720 swapchain_desc
= HeapAlloc(GetProcessHeap(), 0, sizeof(*swapchain_desc
) * count
);
3721 if (!swapchain_desc
)
3723 ERR("Failed to allocate wined3d parameters.\n");
3724 wined3d_device_release_focus_window(device
->wined3d_device
);
3725 wined3d_device_decref(device
->wined3d_device
);
3726 wined3d_mutex_unlock();
3727 return E_OUTOFMEMORY
;
3730 for (i
= 0; i
< count
; ++i
)
3732 if (!wined3d_swapchain_desc_from_present_parameters(&swapchain_desc
[i
], ¶meters
[i
],
3735 wined3d_device_release_focus_window(device
->wined3d_device
);
3736 wined3d_device_decref(device
->wined3d_device
);
3737 HeapFree(GetProcessHeap(), 0, swapchain_desc
);
3738 wined3d_mutex_unlock();
3739 return D3DERR_INVALIDCALL
;
3743 hr
= wined3d_device_init_3d(device
->wined3d_device
, swapchain_desc
);
3746 WARN("Failed to initialize 3D, hr %#x.\n", hr
);
3747 wined3d_device_release_focus_window(device
->wined3d_device
);
3748 HeapFree(GetProcessHeap(), 0, swapchain_desc
);
3749 wined3d_device_decref(device
->wined3d_device
);
3750 wined3d_mutex_unlock();
3754 wined3d_mutex_unlock();
3756 for (i
= 0; i
< count
; ++i
)
3758 present_parameters_from_wined3d_swapchain_desc(¶meters
[i
], &swapchain_desc
[i
]);
3760 HeapFree(GetProcessHeap(), 0, swapchain_desc
);
3762 /* Initialize the converted declaration array. This creates a valid pointer
3763 * and when adding decls HeapReAlloc() can be used without further checking. */
3764 device
->fvf_decls
= HeapAlloc(GetProcessHeap(), 0, 0);
3765 if (!device
->fvf_decls
)
3767 ERR("Failed to allocate FVF vertex declaration map memory.\n");
3768 wined3d_mutex_lock();
3769 wined3d_device_uninit_3d(device
->wined3d_device
);
3770 wined3d_device_release_focus_window(device
->wined3d_device
);
3771 wined3d_device_decref(device
->wined3d_device
);
3772 wined3d_mutex_unlock();
3773 return E_OUTOFMEMORY
;
3776 IDirect3D9Ex_AddRef(&parent
->IDirect3D9Ex_iface
);
3777 device
->d3d_parent
= parent
;