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
23 #include "d3d9_private.h"
25 static void STDMETHODCALLTYPE
d3d9_null_wined3d_object_destroyed(void *parent
) {}
27 static const struct wined3d_parent_ops d3d9_null_wined3d_parent_ops
=
29 d3d9_null_wined3d_object_destroyed
,
32 D3DFORMAT
d3dformat_from_wined3dformat(enum wined3d_format_id format
)
34 BYTE
*c
= (BYTE
*)&format
;
36 /* Don't translate FOURCC formats */
37 if (isprint(c
[0]) && isprint(c
[1]) && isprint(c
[2]) && isprint(c
[3])) return format
;
41 case WINED3DFMT_UNKNOWN
: return D3DFMT_UNKNOWN
;
42 case WINED3DFMT_B8G8R8_UNORM
: return D3DFMT_R8G8B8
;
43 case WINED3DFMT_B8G8R8A8_UNORM
: return D3DFMT_A8R8G8B8
;
44 case WINED3DFMT_B8G8R8X8_UNORM
: return D3DFMT_X8R8G8B8
;
45 case WINED3DFMT_B5G6R5_UNORM
: return D3DFMT_R5G6B5
;
46 case WINED3DFMT_B5G5R5X1_UNORM
: return D3DFMT_X1R5G5B5
;
47 case WINED3DFMT_B5G5R5A1_UNORM
: return D3DFMT_A1R5G5B5
;
48 case WINED3DFMT_B4G4R4A4_UNORM
: return D3DFMT_A4R4G4B4
;
49 case WINED3DFMT_B2G3R3_UNORM
: return D3DFMT_R3G3B2
;
50 case WINED3DFMT_A8_UNORM
: return D3DFMT_A8
;
51 case WINED3DFMT_B2G3R3A8_UNORM
: return D3DFMT_A8R3G3B2
;
52 case WINED3DFMT_B4G4R4X4_UNORM
: return D3DFMT_X4R4G4B4
;
53 case WINED3DFMT_R10G10B10A2_UNORM
: return D3DFMT_A2B10G10R10
;
54 case WINED3DFMT_R8G8B8A8_UNORM
: return D3DFMT_A8B8G8R8
;
55 case WINED3DFMT_R8G8B8X8_UNORM
: return D3DFMT_X8B8G8R8
;
56 case WINED3DFMT_R16G16_UNORM
: return D3DFMT_G16R16
;
57 case WINED3DFMT_B10G10R10A2_UNORM
: return D3DFMT_A2R10G10B10
;
58 case WINED3DFMT_R16G16B16A16_UNORM
: return D3DFMT_A16B16G16R16
;
59 case WINED3DFMT_P8_UINT_A8_UNORM
: return D3DFMT_A8P8
;
60 case WINED3DFMT_P8_UINT
: return D3DFMT_P8
;
61 case WINED3DFMT_L8_UNORM
: return D3DFMT_L8
;
62 case WINED3DFMT_L8A8_UNORM
: return D3DFMT_A8L8
;
63 case WINED3DFMT_L4A4_UNORM
: return D3DFMT_A4L4
;
64 case WINED3DFMT_R8G8_SNORM
: return D3DFMT_V8U8
;
65 case WINED3DFMT_R5G5_SNORM_L6_UNORM
: return D3DFMT_L6V5U5
;
66 case WINED3DFMT_R8G8_SNORM_L8X8_UNORM
: return D3DFMT_X8L8V8U8
;
67 case WINED3DFMT_R8G8B8A8_SNORM
: return D3DFMT_Q8W8V8U8
;
68 case WINED3DFMT_R16G16_SNORM
: return D3DFMT_V16U16
;
69 case WINED3DFMT_R10G10B10_SNORM_A2_UNORM
: return D3DFMT_A2W10V10U10
;
70 case WINED3DFMT_D16_LOCKABLE
: return D3DFMT_D16_LOCKABLE
;
71 case WINED3DFMT_D32_UNORM
: return D3DFMT_D32
;
72 case WINED3DFMT_S1_UINT_D15_UNORM
: return D3DFMT_D15S1
;
73 case WINED3DFMT_D24_UNORM_S8_UINT
: return D3DFMT_D24S8
;
74 case WINED3DFMT_X8D24_UNORM
: return D3DFMT_D24X8
;
75 case WINED3DFMT_S4X4_UINT_D24_UNORM
: return D3DFMT_D24X4S4
;
76 case WINED3DFMT_D16_UNORM
: return D3DFMT_D16
;
77 case WINED3DFMT_L16_UNORM
: return D3DFMT_L16
;
78 case WINED3DFMT_D32_FLOAT
: return D3DFMT_D32F_LOCKABLE
;
79 case WINED3DFMT_S8_UINT_D24_FLOAT
: return D3DFMT_D24FS8
;
80 case WINED3DFMT_VERTEXDATA
: return D3DFMT_VERTEXDATA
;
81 case WINED3DFMT_R16_UINT
: return D3DFMT_INDEX16
;
82 case WINED3DFMT_R32_UINT
: return D3DFMT_INDEX32
;
83 case WINED3DFMT_R16G16B16A16_SNORM
: return D3DFMT_Q16W16V16U16
;
84 case WINED3DFMT_R16_FLOAT
: return D3DFMT_R16F
;
85 case WINED3DFMT_R16G16_FLOAT
: return D3DFMT_G16R16F
;
86 case WINED3DFMT_R16G16B16A16_FLOAT
: return D3DFMT_A16B16G16R16F
;
87 case WINED3DFMT_R32_FLOAT
: return D3DFMT_R32F
;
88 case WINED3DFMT_R32G32_FLOAT
: return D3DFMT_G32R32F
;
89 case WINED3DFMT_R32G32B32A32_FLOAT
: return D3DFMT_A32B32G32R32F
;
90 case WINED3DFMT_R8G8_SNORM_Cx
: return D3DFMT_CxV8U8
;
92 FIXME("Unhandled wined3d format %#x.\n", format
);
93 return D3DFMT_UNKNOWN
;
97 enum wined3d_format_id
wined3dformat_from_d3dformat(D3DFORMAT format
)
99 BYTE
*c
= (BYTE
*)&format
;
101 /* Don't translate FOURCC formats */
102 if (isprint(c
[0]) && isprint(c
[1]) && isprint(c
[2]) && isprint(c
[3])) return format
;
106 case D3DFMT_UNKNOWN
: return WINED3DFMT_UNKNOWN
;
107 case D3DFMT_R8G8B8
: return WINED3DFMT_B8G8R8_UNORM
;
108 case D3DFMT_A8R8G8B8
: return WINED3DFMT_B8G8R8A8_UNORM
;
109 case D3DFMT_X8R8G8B8
: return WINED3DFMT_B8G8R8X8_UNORM
;
110 case D3DFMT_R5G6B5
: return WINED3DFMT_B5G6R5_UNORM
;
111 case D3DFMT_X1R5G5B5
: return WINED3DFMT_B5G5R5X1_UNORM
;
112 case D3DFMT_A1R5G5B5
: return WINED3DFMT_B5G5R5A1_UNORM
;
113 case D3DFMT_A4R4G4B4
: return WINED3DFMT_B4G4R4A4_UNORM
;
114 case D3DFMT_R3G3B2
: return WINED3DFMT_B2G3R3_UNORM
;
115 case D3DFMT_A8
: return WINED3DFMT_A8_UNORM
;
116 case D3DFMT_A8R3G3B2
: return WINED3DFMT_B2G3R3A8_UNORM
;
117 case D3DFMT_X4R4G4B4
: return WINED3DFMT_B4G4R4X4_UNORM
;
118 case D3DFMT_A2B10G10R10
: return WINED3DFMT_R10G10B10A2_UNORM
;
119 case D3DFMT_A8B8G8R8
: return WINED3DFMT_R8G8B8A8_UNORM
;
120 case D3DFMT_X8B8G8R8
: return WINED3DFMT_R8G8B8X8_UNORM
;
121 case D3DFMT_G16R16
: return WINED3DFMT_R16G16_UNORM
;
122 case D3DFMT_A2R10G10B10
: return WINED3DFMT_B10G10R10A2_UNORM
;
123 case D3DFMT_A16B16G16R16
: return WINED3DFMT_R16G16B16A16_UNORM
;
124 case D3DFMT_A8P8
: return WINED3DFMT_P8_UINT_A8_UNORM
;
125 case D3DFMT_P8
: return WINED3DFMT_P8_UINT
;
126 case D3DFMT_L8
: return WINED3DFMT_L8_UNORM
;
127 case D3DFMT_A8L8
: return WINED3DFMT_L8A8_UNORM
;
128 case D3DFMT_A4L4
: return WINED3DFMT_L4A4_UNORM
;
129 case D3DFMT_V8U8
: return WINED3DFMT_R8G8_SNORM
;
130 case D3DFMT_L6V5U5
: return WINED3DFMT_R5G5_SNORM_L6_UNORM
;
131 case D3DFMT_X8L8V8U8
: return WINED3DFMT_R8G8_SNORM_L8X8_UNORM
;
132 case D3DFMT_Q8W8V8U8
: return WINED3DFMT_R8G8B8A8_SNORM
;
133 case D3DFMT_V16U16
: return WINED3DFMT_R16G16_SNORM
;
134 case D3DFMT_A2W10V10U10
: return WINED3DFMT_R10G10B10_SNORM_A2_UNORM
;
135 case D3DFMT_D16_LOCKABLE
: return WINED3DFMT_D16_LOCKABLE
;
136 case D3DFMT_D32
: return WINED3DFMT_D32_UNORM
;
137 case D3DFMT_D15S1
: return WINED3DFMT_S1_UINT_D15_UNORM
;
138 case D3DFMT_D24S8
: return WINED3DFMT_D24_UNORM_S8_UINT
;
139 case D3DFMT_D24X8
: return WINED3DFMT_X8D24_UNORM
;
140 case D3DFMT_D24X4S4
: return WINED3DFMT_S4X4_UINT_D24_UNORM
;
141 case D3DFMT_D16
: return WINED3DFMT_D16_UNORM
;
142 case D3DFMT_L16
: return WINED3DFMT_L16_UNORM
;
143 case D3DFMT_D32F_LOCKABLE
: return WINED3DFMT_D32_FLOAT
;
144 case D3DFMT_D24FS8
: return WINED3DFMT_S8_UINT_D24_FLOAT
;
145 case D3DFMT_VERTEXDATA
: return WINED3DFMT_VERTEXDATA
;
146 case D3DFMT_INDEX16
: return WINED3DFMT_R16_UINT
;
147 case D3DFMT_INDEX32
: return WINED3DFMT_R32_UINT
;
148 case D3DFMT_Q16W16V16U16
: return WINED3DFMT_R16G16B16A16_SNORM
;
149 case D3DFMT_R16F
: return WINED3DFMT_R16_FLOAT
;
150 case D3DFMT_G16R16F
: return WINED3DFMT_R16G16_FLOAT
;
151 case D3DFMT_A16B16G16R16F
: return WINED3DFMT_R16G16B16A16_FLOAT
;
152 case D3DFMT_R32F
: return WINED3DFMT_R32_FLOAT
;
153 case D3DFMT_G32R32F
: return WINED3DFMT_R32G32_FLOAT
;
154 case D3DFMT_A32B32G32R32F
: return WINED3DFMT_R32G32B32A32_FLOAT
;
155 case D3DFMT_CxV8U8
: return WINED3DFMT_R8G8_SNORM_Cx
;
157 FIXME("Unhandled D3DFORMAT %#x\n", format
);
158 return WINED3DFMT_UNKNOWN
;
162 static UINT
vertex_count_from_primitive_count(D3DPRIMITIVETYPE primitive_type
, UINT primitive_count
)
164 switch(primitive_type
)
166 case D3DPT_POINTLIST
:
167 return primitive_count
;
170 return primitive_count
* 2;
172 case D3DPT_LINESTRIP
:
173 return primitive_count
+ 1;
175 case D3DPT_TRIANGLELIST
:
176 return primitive_count
* 3;
178 case D3DPT_TRIANGLESTRIP
:
179 case D3DPT_TRIANGLEFAN
:
180 return primitive_count
+ 2;
183 FIXME("Unhandled primitive type %#x\n", primitive_type
);
188 void present_parameters_from_wined3d_swapchain_desc(D3DPRESENT_PARAMETERS
*present_parameters
,
189 const struct wined3d_swapchain_desc
*swapchain_desc
)
191 present_parameters
->BackBufferWidth
= swapchain_desc
->backbuffer_width
;
192 present_parameters
->BackBufferHeight
= swapchain_desc
->backbuffer_height
;
193 present_parameters
->BackBufferFormat
= d3dformat_from_wined3dformat(swapchain_desc
->backbuffer_format
);
194 present_parameters
->BackBufferCount
= swapchain_desc
->backbuffer_count
;
195 present_parameters
->MultiSampleType
= swapchain_desc
->multisample_type
;
196 present_parameters
->MultiSampleQuality
= swapchain_desc
->multisample_quality
;
197 present_parameters
->SwapEffect
= swapchain_desc
->swap_effect
;
198 present_parameters
->hDeviceWindow
= swapchain_desc
->device_window
;
199 present_parameters
->Windowed
= swapchain_desc
->windowed
;
200 present_parameters
->EnableAutoDepthStencil
= swapchain_desc
->enable_auto_depth_stencil
;
201 present_parameters
->AutoDepthStencilFormat
202 = d3dformat_from_wined3dformat(swapchain_desc
->auto_depth_stencil_format
);
203 present_parameters
->Flags
= swapchain_desc
->flags
;
204 present_parameters
->FullScreen_RefreshRateInHz
= swapchain_desc
->refresh_rate
;
205 present_parameters
->PresentationInterval
= swapchain_desc
->swap_interval
;
208 static void wined3d_swapchain_desc_from_present_parameters(struct wined3d_swapchain_desc
*swapchain_desc
,
209 const D3DPRESENT_PARAMETERS
*present_parameters
)
211 swapchain_desc
->backbuffer_width
= present_parameters
->BackBufferWidth
;
212 swapchain_desc
->backbuffer_height
= present_parameters
->BackBufferHeight
;
213 swapchain_desc
->backbuffer_format
= wined3dformat_from_d3dformat(present_parameters
->BackBufferFormat
);
214 swapchain_desc
->backbuffer_count
= max(1, present_parameters
->BackBufferCount
);
215 swapchain_desc
->multisample_type
= present_parameters
->MultiSampleType
;
216 swapchain_desc
->multisample_quality
= present_parameters
->MultiSampleQuality
;
217 swapchain_desc
->swap_effect
= present_parameters
->SwapEffect
;
218 swapchain_desc
->device_window
= present_parameters
->hDeviceWindow
;
219 swapchain_desc
->windowed
= present_parameters
->Windowed
;
220 swapchain_desc
->enable_auto_depth_stencil
= present_parameters
->EnableAutoDepthStencil
;
221 swapchain_desc
->auto_depth_stencil_format
222 = wined3dformat_from_d3dformat(present_parameters
->AutoDepthStencilFormat
);
223 swapchain_desc
->flags
= present_parameters
->Flags
;
224 swapchain_desc
->refresh_rate
= present_parameters
->FullScreen_RefreshRateInHz
;
225 swapchain_desc
->swap_interval
= present_parameters
->PresentationInterval
;
226 swapchain_desc
->auto_restore_display_mode
= TRUE
;
229 static HRESULT WINAPI
d3d9_device_QueryInterface(IDirect3DDevice9Ex
*iface
, REFIID riid
, void **out
)
231 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
233 if (IsEqualGUID(riid
, &IID_IDirect3DDevice9
)
234 || IsEqualGUID(riid
, &IID_IUnknown
))
236 IDirect3DDevice9Ex_AddRef(iface
);
241 if (IsEqualGUID(riid
, &IID_IDirect3DDevice9Ex
))
243 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
245 /* Find out if the creating d3d9 interface was created with Direct3DCreate9Ex.
246 * It doesn't matter with which function the device was created. */
247 if (!device
->d3d_parent
->extended
)
249 WARN("IDirect3D9 instance wasn't created with CreateDirect3D9Ex, returning E_NOINTERFACE.\n");
251 return E_NOINTERFACE
;
254 IDirect3DDevice9Ex_AddRef(iface
);
259 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
262 return E_NOINTERFACE
;
265 static ULONG WINAPI
d3d9_device_AddRef(IDirect3DDevice9Ex
*iface
)
267 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
268 ULONG refcount
= InterlockedIncrement(&device
->refcount
);
270 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
275 static ULONG WINAPI DECLSPEC_HOTPATCH
d3d9_device_Release(IDirect3DDevice9Ex
*iface
)
277 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
280 if (device
->in_destruction
)
283 refcount
= InterlockedDecrement(&device
->refcount
);
285 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
290 device
->in_destruction
= TRUE
;
292 wined3d_mutex_lock();
293 for (i
= 0; i
< device
->fvf_decl_count
; ++i
)
295 wined3d_vertex_declaration_decref(device
->fvf_decls
[i
].decl
);
297 HeapFree(GetProcessHeap(), 0, device
->fvf_decls
);
299 if (device
->vertex_buffer
)
300 wined3d_buffer_decref(device
->vertex_buffer
);
301 if (device
->index_buffer
)
302 wined3d_buffer_decref(device
->index_buffer
);
304 wined3d_device_uninit_3d(device
->wined3d_device
);
305 wined3d_device_release_focus_window(device
->wined3d_device
);
306 wined3d_device_decref(device
->wined3d_device
);
307 wined3d_mutex_unlock();
309 IDirect3D9Ex_Release(&device
->d3d_parent
->IDirect3D9Ex_iface
);
311 HeapFree(GetProcessHeap(), 0, device
);
317 static HRESULT WINAPI
d3d9_device_TestCooperativeLevel(IDirect3DDevice9Ex
*iface
)
319 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
321 TRACE("iface %p.\n", iface
);
323 TRACE("device state: %#x.\n", device
->device_state
);
325 if (device
->d3d_parent
->extended
)
328 switch (device
->device_state
)
331 case D3D9_DEVICE_STATE_OK
:
333 case D3D9_DEVICE_STATE_LOST
:
334 return D3DERR_DEVICELOST
;
335 case D3D9_DEVICE_STATE_NOT_RESET
:
336 return D3DERR_DEVICENOTRESET
;
340 static UINT WINAPI
d3d9_device_GetAvailableTextureMem(IDirect3DDevice9Ex
*iface
)
342 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
345 TRACE("iface %p.\n", iface
);
347 wined3d_mutex_lock();
348 ret
= wined3d_device_get_available_texture_mem(device
->wined3d_device
);
349 wined3d_mutex_unlock();
354 static HRESULT WINAPI
d3d9_device_EvictManagedResources(IDirect3DDevice9Ex
*iface
)
356 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
358 TRACE("iface %p.\n", iface
);
360 wined3d_mutex_lock();
361 wined3d_device_evict_managed_resources(device
->wined3d_device
);
362 wined3d_mutex_unlock();
367 static HRESULT WINAPI
d3d9_device_GetDirect3D(IDirect3DDevice9Ex
*iface
, IDirect3D9
**d3d9
)
369 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
371 TRACE("iface %p, d3d9 %p.\n", iface
, d3d9
);
374 return D3DERR_INVALIDCALL
;
376 return IDirect3D9Ex_QueryInterface(&device
->d3d_parent
->IDirect3D9Ex_iface
, &IID_IDirect3D9
, (void **)d3d9
);
379 static HRESULT WINAPI
d3d9_device_GetDeviceCaps(IDirect3DDevice9Ex
*iface
, D3DCAPS9
*caps
)
381 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
382 WINED3DCAPS
*wined3d_caps
;
385 TRACE("iface %p, caps %p.\n", iface
, caps
);
388 return D3DERR_INVALIDCALL
;
390 if (!(wined3d_caps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*wined3d_caps
))))
391 return D3DERR_INVALIDCALL
; /* well this is what MSDN says to return */
393 memset(caps
, 0, sizeof(*caps
));
395 wined3d_mutex_lock();
396 hr
= wined3d_device_get_device_caps(device
->wined3d_device
, wined3d_caps
);
397 wined3d_mutex_unlock();
399 WINECAPSTOD3D9CAPS(caps
, wined3d_caps
)
400 HeapFree(GetProcessHeap(), 0, wined3d_caps
);
402 /* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps */
403 caps
->DevCaps2
|= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES
;
410 static HRESULT WINAPI
d3d9_device_GetDisplayMode(IDirect3DDevice9Ex
*iface
, UINT swapchain
, D3DDISPLAYMODE
*mode
)
412 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
413 struct wined3d_display_mode wined3d_mode
;
416 TRACE("iface %p, swapchain %u, mode %p.\n", iface
, swapchain
, mode
);
418 wined3d_mutex_lock();
419 hr
= wined3d_device_get_display_mode(device
->wined3d_device
, swapchain
, &wined3d_mode
, NULL
);
420 wined3d_mutex_unlock();
424 mode
->Width
= wined3d_mode
.width
;
425 mode
->Height
= wined3d_mode
.height
;
426 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
427 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
433 static HRESULT WINAPI
d3d9_device_GetCreationParameters(IDirect3DDevice9Ex
*iface
,
434 D3DDEVICE_CREATION_PARAMETERS
*parameters
)
436 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
438 TRACE("iface %p, parameters %p.\n", iface
, parameters
);
440 wined3d_mutex_lock();
441 wined3d_device_get_creation_parameters(device
->wined3d_device
,
442 (struct wined3d_device_creation_parameters
*)parameters
);
443 wined3d_mutex_unlock();
448 static HRESULT WINAPI
d3d9_device_SetCursorProperties(IDirect3DDevice9Ex
*iface
,
449 UINT hotspot_x
, UINT hotspot_y
, IDirect3DSurface9
*bitmap
)
451 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
452 struct d3d9_surface
*bitmap_impl
= unsafe_impl_from_IDirect3DSurface9(bitmap
);
455 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
456 iface
, hotspot_x
, hotspot_y
, bitmap
);
460 WARN("No cursor bitmap, returning D3DERR_INVALIDCALL.\n");
461 return D3DERR_INVALIDCALL
;
464 wined3d_mutex_lock();
465 hr
= wined3d_device_set_cursor_properties(device
->wined3d_device
,
466 hotspot_x
, hotspot_y
, bitmap_impl
->wined3d_surface
);
467 wined3d_mutex_unlock();
472 static void WINAPI
d3d9_device_SetCursorPosition(IDirect3DDevice9Ex
*iface
, int x
, int y
, DWORD flags
)
474 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
476 TRACE("iface %p, x %u, y %u, flags %#x.\n", iface
, x
, y
, flags
);
478 wined3d_mutex_lock();
479 wined3d_device_set_cursor_position(device
->wined3d_device
, x
, y
, flags
);
480 wined3d_mutex_unlock();
483 static BOOL WINAPI
d3d9_device_ShowCursor(IDirect3DDevice9Ex
*iface
, BOOL show
)
485 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
488 TRACE("iface %p, show %#x.\n", iface
, show
);
490 wined3d_mutex_lock();
491 ret
= wined3d_device_show_cursor(device
->wined3d_device
, show
);
492 wined3d_mutex_unlock();
497 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_CreateAdditionalSwapChain(IDirect3DDevice9Ex
*iface
,
498 D3DPRESENT_PARAMETERS
*present_parameters
, IDirect3DSwapChain9
**swapchain
)
500 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
501 struct wined3d_swapchain_desc desc
;
502 struct d3d9_swapchain
*object
;
505 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
506 iface
, present_parameters
, swapchain
);
508 wined3d_swapchain_desc_from_present_parameters(&desc
, present_parameters
);
509 if (SUCCEEDED(hr
= d3d9_swapchain_create(device
, &desc
, &object
)))
510 *swapchain
= (IDirect3DSwapChain9
*)&object
->IDirect3DSwapChain9Ex_iface
;
511 present_parameters_from_wined3d_swapchain_desc(present_parameters
, &desc
);
516 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_GetSwapChain(IDirect3DDevice9Ex
*iface
,
517 UINT swapchain_idx
, IDirect3DSwapChain9
**swapchain
)
519 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
520 struct wined3d_swapchain
*wined3d_swapchain
;
521 struct d3d9_swapchain
*swapchain_impl
;
524 TRACE("iface %p, swapchain_idx %u, swapchain %p.\n", iface
, swapchain_idx
, swapchain
);
526 wined3d_mutex_lock();
527 if ((wined3d_swapchain
= wined3d_device_get_swapchain(device
->wined3d_device
, swapchain_idx
)))
529 swapchain_impl
= wined3d_swapchain_get_parent(wined3d_swapchain
);
530 *swapchain
= (IDirect3DSwapChain9
*)&swapchain_impl
->IDirect3DSwapChain9Ex_iface
;
531 IDirect3DSwapChain9Ex_AddRef(*swapchain
);
537 hr
= D3DERR_INVALIDCALL
;
539 wined3d_mutex_unlock();
544 static UINT WINAPI
d3d9_device_GetNumberOfSwapChains(IDirect3DDevice9Ex
*iface
)
546 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
549 TRACE("iface %p.\n", iface
);
551 wined3d_mutex_lock();
552 count
= wined3d_device_get_swapchain_count(device
->wined3d_device
);
553 wined3d_mutex_unlock();
558 static HRESULT CDECL
reset_enum_callback(struct wined3d_resource
*resource
)
560 struct wined3d_resource_desc desc
;
562 wined3d_resource_get_desc(resource
, &desc
);
563 if (desc
.pool
== WINED3D_POOL_DEFAULT
)
565 struct d3d9_surface
*surface
;
567 if (desc
.resource_type
== WINED3D_RTYPE_TEXTURE
)
569 IUnknown
*parent
= wined3d_resource_get_parent(resource
);
570 IDirect3DBaseTexture9
*texture
;
572 if (SUCCEEDED(IUnknown_QueryInterface(parent
, &IID_IDirect3DBaseTexture9
, (void **)&texture
)))
574 IDirect3DBaseTexture9_Release(texture
);
575 WARN("Texture %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", texture
, resource
);
576 return D3DERR_INVALIDCALL
;
582 if (desc
.resource_type
!= WINED3D_RTYPE_SURFACE
)
584 WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource
);
585 return D3DERR_INVALIDCALL
;
588 surface
= wined3d_resource_get_parent(resource
);
589 if (surface
->resource
.refcount
)
591 WARN("Surface %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface
, resource
);
592 return D3DERR_INVALIDCALL
;
595 WARN("Surface %p (resource %p) is an implicit resource with ref 0.\n", surface
, resource
);
601 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_Reset(IDirect3DDevice9Ex
*iface
,
602 D3DPRESENT_PARAMETERS
*present_parameters
)
604 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
605 struct wined3d_swapchain_desc swapchain_desc
;
608 TRACE("iface %p, present_parameters %p.\n", iface
, present_parameters
);
610 wined3d_mutex_lock();
612 if (device
->vertex_buffer
)
614 wined3d_buffer_decref(device
->vertex_buffer
);
615 device
->vertex_buffer
= NULL
;
616 device
->vertex_buffer_size
= 0;
618 if (device
->index_buffer
)
620 wined3d_buffer_decref(device
->index_buffer
);
621 device
->index_buffer
= NULL
;
622 device
->index_buffer_size
= 0;
625 wined3d_swapchain_desc_from_present_parameters(&swapchain_desc
, present_parameters
);
626 hr
= wined3d_device_reset(device
->wined3d_device
, &swapchain_desc
,
627 NULL
, reset_enum_callback
, !device
->d3d_parent
->extended
);
628 if (FAILED(hr
) && !device
->d3d_parent
->extended
)
629 device
->device_state
= D3D9_DEVICE_STATE_NOT_RESET
;
631 device
->device_state
= D3D9_DEVICE_STATE_OK
;
632 wined3d_mutex_unlock();
637 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_Present(IDirect3DDevice9Ex
*iface
,
638 const RECT
*src_rect
, const RECT
*dst_rect
, HWND dst_window_override
, const RGNDATA
*dirty_region
)
640 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
643 TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
644 iface
, src_rect
, dst_rect
, dst_window_override
, dirty_region
);
646 if (device
->device_state
!= D3D9_DEVICE_STATE_OK
)
647 return device
->d3d_parent
->extended
? S_PRESENT_OCCLUDED
: D3DERR_DEVICELOST
;
649 wined3d_mutex_lock();
650 hr
= wined3d_device_present(device
->wined3d_device
, src_rect
, dst_rect
,
651 dst_window_override
, dirty_region
, 0);
652 wined3d_mutex_unlock();
657 static HRESULT WINAPI
d3d9_device_GetBackBuffer(IDirect3DDevice9Ex
*iface
, UINT swapchain
,
658 UINT backbuffer_idx
, D3DBACKBUFFER_TYPE backbuffer_type
, IDirect3DSurface9
**backbuffer
)
660 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
661 struct wined3d_surface
*wined3d_surface
= NULL
;
662 struct d3d9_surface
*surface_impl
;
665 TRACE("iface %p, swapchain %u, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
666 iface
, swapchain
, backbuffer_idx
, backbuffer_type
, backbuffer
);
668 wined3d_mutex_lock();
669 hr
= wined3d_device_get_back_buffer(device
->wined3d_device
, swapchain
,
670 backbuffer_idx
, (enum wined3d_backbuffer_type
)backbuffer_type
, &wined3d_surface
);
671 if (SUCCEEDED(hr
) && wined3d_surface
&& backbuffer
)
673 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
674 *backbuffer
= &surface_impl
->IDirect3DSurface9_iface
;
675 IDirect3DSurface9_AddRef(*backbuffer
);
677 wined3d_mutex_unlock();
681 static HRESULT WINAPI
d3d9_device_GetRasterStatus(IDirect3DDevice9Ex
*iface
,
682 UINT swapchain
, D3DRASTER_STATUS
*raster_status
)
684 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
687 TRACE("iface %p, swapchain %u, raster_status %p.\n", iface
, swapchain
, raster_status
);
689 wined3d_mutex_lock();
690 hr
= wined3d_device_get_raster_status(device
->wined3d_device
,
691 swapchain
, (struct wined3d_raster_status
*)raster_status
);
692 wined3d_mutex_unlock();
697 static HRESULT WINAPI
d3d9_device_SetDialogBoxMode(IDirect3DDevice9Ex
*iface
, BOOL enable
)
699 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
702 TRACE("iface %p, enable %#x.\n", iface
, enable
);
704 wined3d_mutex_lock();
705 hr
= wined3d_device_set_dialog_box_mode(device
->wined3d_device
, enable
);
706 wined3d_mutex_unlock();
711 static void WINAPI
d3d9_device_SetGammaRamp(IDirect3DDevice9Ex
*iface
,
712 UINT swapchain
, DWORD flags
, const D3DGAMMARAMP
*ramp
)
714 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
716 TRACE("iface %p, swapchain %u, flags %#x, ramp %p.\n", iface
, swapchain
, flags
, ramp
);
718 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
719 wined3d_mutex_lock();
720 wined3d_device_set_gamma_ramp(device
->wined3d_device
, swapchain
, flags
, (const struct wined3d_gamma_ramp
*)ramp
);
721 wined3d_mutex_unlock();
724 static void WINAPI
d3d9_device_GetGammaRamp(IDirect3DDevice9Ex
*iface
, UINT swapchain
, D3DGAMMARAMP
*ramp
)
726 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
728 TRACE("iface %p, swapchain %u, ramp %p.\n", iface
, swapchain
, ramp
);
730 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
731 wined3d_mutex_lock();
732 wined3d_device_get_gamma_ramp(device
->wined3d_device
, swapchain
, (struct wined3d_gamma_ramp
*)ramp
);
733 wined3d_mutex_unlock();
736 static HRESULT WINAPI
d3d9_device_CreateTexture(IDirect3DDevice9Ex
*iface
,
737 UINT width
, UINT height
, UINT levels
, DWORD usage
, D3DFORMAT format
,
738 D3DPOOL pool
, IDirect3DTexture9
**texture
, HANDLE
*shared_handle
)
740 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
741 struct d3d9_texture
*object
;
742 BOOL set_mem
= FALSE
;
745 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
746 iface
, width
, height
, levels
, usage
, format
, pool
, texture
, shared_handle
);
751 if (!device
->d3d_parent
->extended
)
753 WARN("Trying to create a shared or user memory texture on a non-ex device.\n");
757 if (pool
== D3DPOOL_SYSTEMMEM
)
760 return D3DERR_INVALIDCALL
;
765 if (pool
!= D3DPOOL_DEFAULT
)
767 WARN("Trying to create a shared texture in pool %#x.\n", pool
);
768 return D3DERR_INVALIDCALL
;
770 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
774 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
776 return D3DERR_OUTOFVIDEOMEMORY
;
778 hr
= texture_init(object
, device
, width
, height
, levels
, usage
, format
, pool
);
781 WARN("Failed to initialize texture, hr %#x.\n", hr
);
782 HeapFree(GetProcessHeap(), 0, object
);
788 struct wined3d_resource
*resource
;
789 struct d3d9_surface
*surface
;
791 resource
= wined3d_texture_get_sub_resource(object
->wined3d_texture
, 0);
792 surface
= wined3d_resource_get_parent(resource
);
793 wined3d_surface_update_desc(surface
->wined3d_surface
, width
, height
,
794 wined3dformat_from_d3dformat(format
), WINED3D_MULTISAMPLE_NONE
, 0,
798 TRACE("Created texture %p.\n", object
);
799 *texture
= (IDirect3DTexture9
*)&object
->IDirect3DBaseTexture9_iface
;
804 static HRESULT WINAPI
d3d9_device_CreateVolumeTexture(IDirect3DDevice9Ex
*iface
,
805 UINT width
, UINT height
, UINT depth
, UINT levels
, DWORD usage
, D3DFORMAT format
,
806 D3DPOOL pool
, IDirect3DVolumeTexture9
**texture
, HANDLE
*shared_handle
)
808 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
809 struct d3d9_texture
*object
;
812 TRACE("iface %p, width %u, height %u, depth %u, levels %u\n",
813 iface
, width
, height
, depth
, levels
);
814 TRACE("usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
815 usage
, format
, pool
, texture
, shared_handle
);
820 if (!device
->d3d_parent
->extended
)
822 WARN("Trying to create a shared volume texture on a non-ex device.\n");
826 if (pool
!= D3DPOOL_DEFAULT
)
828 WARN("Trying to create a shared volume texture in pool %#x.\n", pool
);
829 return D3DERR_INVALIDCALL
;
831 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
834 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
836 return D3DERR_OUTOFVIDEOMEMORY
;
838 hr
= volumetexture_init(object
, device
, width
, height
, depth
, levels
, usage
, format
, pool
);
841 WARN("Failed to initialize volume texture, hr %#x.\n", hr
);
842 HeapFree(GetProcessHeap(), 0, object
);
846 TRACE("Created volume texture %p.\n", object
);
847 *texture
= (IDirect3DVolumeTexture9
*)&object
->IDirect3DBaseTexture9_iface
;
852 static HRESULT WINAPI
d3d9_device_CreateCubeTexture(IDirect3DDevice9Ex
*iface
,
853 UINT edge_length
, UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
,
854 IDirect3DCubeTexture9
**texture
, HANDLE
*shared_handle
)
856 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
857 struct d3d9_texture
*object
;
860 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
861 iface
, edge_length
, levels
, usage
, format
, pool
, texture
, shared_handle
);
866 if (!device
->d3d_parent
->extended
)
868 WARN("Trying to create a shared cube texture on a non-ex device.\n");
872 if (pool
!= D3DPOOL_DEFAULT
)
874 WARN("Trying to create a shared cube texture in pool %#x.\n", pool
);
875 return D3DERR_INVALIDCALL
;
877 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
880 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
882 return D3DERR_OUTOFVIDEOMEMORY
;
884 hr
= cubetexture_init(object
, device
, edge_length
, levels
, usage
, format
, pool
);
887 WARN("Failed to initialize cube texture, hr %#x.\n", hr
);
888 HeapFree(GetProcessHeap(), 0, object
);
892 TRACE("Created cube texture %p.\n", object
);
893 *texture
= (IDirect3DCubeTexture9
*)&object
->IDirect3DBaseTexture9_iface
;
898 static HRESULT WINAPI
d3d9_device_CreateVertexBuffer(IDirect3DDevice9Ex
*iface
, UINT size
,
899 DWORD usage
, DWORD fvf
, D3DPOOL pool
, IDirect3DVertexBuffer9
**buffer
,
900 HANDLE
*shared_handle
)
902 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
903 struct d3d9_vertexbuffer
*object
;
906 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p, shared_handle %p.\n",
907 iface
, size
, usage
, fvf
, pool
, buffer
, shared_handle
);
911 if (!device
->d3d_parent
->extended
)
913 WARN("Trying to create a shared vertex buffer on a non-ex device.\n");
917 if (pool
!= D3DPOOL_DEFAULT
)
919 WARN("Trying to create a shared vertex buffer in pool %#x.\n", pool
);
920 return D3DERR_NOTAVAILABLE
;
922 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
925 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
927 return D3DERR_OUTOFVIDEOMEMORY
;
929 hr
= vertexbuffer_init(object
, device
, size
, usage
, fvf
, pool
);
932 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr
);
933 HeapFree(GetProcessHeap(), 0, object
);
937 TRACE("Created vertex buffer %p.\n", object
);
938 *buffer
= &object
->IDirect3DVertexBuffer9_iface
;
943 static HRESULT WINAPI
d3d9_device_CreateIndexBuffer(IDirect3DDevice9Ex
*iface
, UINT size
,
944 DWORD usage
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DIndexBuffer9
**buffer
,
945 HANDLE
*shared_handle
)
947 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
948 struct d3d9_indexbuffer
*object
;
951 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p, shared_handle %p.\n",
952 iface
, size
, usage
, format
, pool
, buffer
, shared_handle
);
956 if (!device
->d3d_parent
->extended
)
958 WARN("Trying to create a shared index buffer on a non-ex device.\n");
962 if (pool
!= D3DPOOL_DEFAULT
)
964 WARN("Trying to create a shared index buffer in pool %#x.\n", pool
);
965 return D3DERR_NOTAVAILABLE
;
967 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
970 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
972 return D3DERR_OUTOFVIDEOMEMORY
;
974 hr
= indexbuffer_init(object
, device
, size
, usage
, format
, pool
);
977 WARN("Failed to initialize index buffer, hr %#x.\n", hr
);
978 HeapFree(GetProcessHeap(), 0, object
);
982 TRACE("Created index buffer %p.\n", object
);
983 *buffer
= &object
->IDirect3DIndexBuffer9_iface
;
988 static HRESULT
d3d9_device_create_surface(struct d3d9_device
*device
, UINT width
, UINT height
,
989 D3DFORMAT format
, DWORD flags
, IDirect3DSurface9
**surface
, UINT usage
, D3DPOOL pool
,
990 D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
, void *user_mem
)
992 struct wined3d_resource
*sub_resource
;
993 struct wined3d_resource_desc desc
;
994 struct d3d9_surface
*surface_impl
;
995 struct wined3d_texture
*texture
;
998 TRACE("device %p, width %u, height %u, format %#x, flags %#x, surface %p.\n"
999 "usage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
1000 device
, width
, height
, format
, flags
, surface
, usage
, pool
,
1001 multisample_type
, multisample_quality
);
1003 desc
.resource_type
= WINED3D_RTYPE_TEXTURE
;
1004 desc
.format
= wined3dformat_from_d3dformat(format
);
1005 desc
.multisample_type
= multisample_type
;
1006 desc
.multisample_quality
= multisample_quality
;
1007 desc
.usage
= usage
& WINED3DUSAGE_MASK
;
1010 desc
.height
= height
;
1014 wined3d_mutex_lock();
1016 if (FAILED(hr
= wined3d_texture_create(device
->wined3d_device
, &desc
,
1017 1, flags
, NULL
, &d3d9_null_wined3d_parent_ops
, &texture
)))
1019 wined3d_mutex_unlock();
1020 WARN("Failed to create texture, hr %#x.\n", hr
);
1024 sub_resource
= wined3d_texture_get_sub_resource(texture
, 0);
1025 surface_impl
= wined3d_resource_get_parent(sub_resource
);
1026 surface_impl
->parent_device
= &device
->IDirect3DDevice9Ex_iface
;
1027 *surface
= &surface_impl
->IDirect3DSurface9_iface
;
1028 IDirect3DSurface9_AddRef(*surface
);
1029 wined3d_texture_decref(texture
);
1032 wined3d_surface_update_desc(surface_impl
->wined3d_surface
, width
, height
,
1033 desc
.format
, multisample_type
, multisample_quality
, user_mem
, 0);
1035 wined3d_mutex_unlock();
1040 static HRESULT WINAPI
d3d9_device_CreateRenderTarget(IDirect3DDevice9Ex
*iface
, UINT width
, UINT height
,
1041 D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
1042 BOOL lockable
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
)
1044 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1047 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
1048 "lockable %#x, surface %p, shared_handle %p.\n",
1049 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
1050 lockable
, surface
, shared_handle
);
1055 if (!device
->d3d_parent
->extended
)
1057 WARN("Trying to create a shared render target on a non-ex device.\n");
1061 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1065 flags
|= WINED3D_SURFACE_MAPPABLE
;
1067 return d3d9_device_create_surface(device
, width
, height
, format
, flags
, surface
,
1068 D3DUSAGE_RENDERTARGET
, D3DPOOL_DEFAULT
, multisample_type
, multisample_quality
, NULL
);
1071 static HRESULT WINAPI
d3d9_device_CreateDepthStencilSurface(IDirect3DDevice9Ex
*iface
, UINT width
, UINT height
,
1072 D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
1073 BOOL discard
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
)
1075 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1076 DWORD flags
= WINED3D_SURFACE_MAPPABLE
;
1078 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
1079 "discard %#x, surface %p, shared_handle %p.\n",
1080 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
1081 discard
, surface
, shared_handle
);
1086 if (!device
->d3d_parent
->extended
)
1088 WARN("Trying to create a shared depth stencil on a non-ex device.\n");
1092 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1096 flags
|= WINED3D_SURFACE_DISCARD
;
1098 return d3d9_device_create_surface(device
, width
, height
, format
, flags
, surface
,
1099 D3DUSAGE_DEPTHSTENCIL
, D3DPOOL_DEFAULT
, multisample_type
, multisample_quality
, NULL
);
1103 static HRESULT WINAPI
d3d9_device_UpdateSurface(IDirect3DDevice9Ex
*iface
,
1104 IDirect3DSurface9
*src_surface
, const RECT
*src_rect
,
1105 IDirect3DSurface9
*dst_surface
, const POINT
*dst_point
)
1107 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1108 struct d3d9_surface
*src
= unsafe_impl_from_IDirect3DSurface9(src_surface
);
1109 struct d3d9_surface
*dst
= unsafe_impl_from_IDirect3DSurface9(dst_surface
);
1112 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_point %p.\n",
1113 iface
, src_surface
, src_rect
, dst_surface
, dst_point
);
1115 wined3d_mutex_lock();
1116 hr
= wined3d_device_update_surface(device
->wined3d_device
, src
->wined3d_surface
, src_rect
,
1117 dst
->wined3d_surface
, dst_point
);
1118 wined3d_mutex_unlock();
1123 static HRESULT WINAPI
d3d9_device_UpdateTexture(IDirect3DDevice9Ex
*iface
,
1124 IDirect3DBaseTexture9
*src_texture
, IDirect3DBaseTexture9
*dst_texture
)
1126 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1127 struct d3d9_texture
*src_impl
, *dst_impl
;
1130 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface
, src_texture
, dst_texture
);
1132 src_impl
= unsafe_impl_from_IDirect3DBaseTexture9(src_texture
);
1133 dst_impl
= unsafe_impl_from_IDirect3DBaseTexture9(dst_texture
);
1135 wined3d_mutex_lock();
1136 hr
= wined3d_device_update_texture(device
->wined3d_device
,
1137 src_impl
->wined3d_texture
, dst_impl
->wined3d_texture
);
1138 wined3d_mutex_unlock();
1143 static HRESULT WINAPI
d3d9_device_GetRenderTargetData(IDirect3DDevice9Ex
*iface
,
1144 IDirect3DSurface9
*render_target
, IDirect3DSurface9
*dst_surface
)
1146 struct d3d9_surface
*rt_impl
= unsafe_impl_from_IDirect3DSurface9(render_target
);
1147 struct d3d9_surface
*dst_impl
= unsafe_impl_from_IDirect3DSurface9(dst_surface
);
1150 TRACE("iface %p, render_target %p, dst_surface %p.\n", iface
, render_target
, dst_surface
);
1152 wined3d_mutex_lock();
1153 hr
= wined3d_surface_get_render_target_data(dst_impl
->wined3d_surface
, rt_impl
->wined3d_surface
);
1154 wined3d_mutex_unlock();
1159 static HRESULT WINAPI
d3d9_device_GetFrontBufferData(IDirect3DDevice9Ex
*iface
,
1160 UINT swapchain
, IDirect3DSurface9
*dst_surface
)
1162 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1163 struct d3d9_surface
*dst_impl
= unsafe_impl_from_IDirect3DSurface9(dst_surface
);
1166 TRACE("iface %p, swapchain %u, dst_surface %p.\n", iface
, swapchain
, dst_surface
);
1168 wined3d_mutex_lock();
1169 hr
= wined3d_device_get_front_buffer_data(device
->wined3d_device
, swapchain
, dst_impl
->wined3d_surface
);
1170 wined3d_mutex_unlock();
1175 static HRESULT WINAPI
d3d9_device_StretchRect(IDirect3DDevice9Ex
*iface
, IDirect3DSurface9
*src_surface
,
1176 const RECT
*src_rect
, IDirect3DSurface9
*dst_surface
, const RECT
*dst_rect
, D3DTEXTUREFILTERTYPE filter
)
1178 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1179 struct d3d9_surface
*src
= unsafe_impl_from_IDirect3DSurface9(src_surface
);
1180 struct d3d9_surface
*dst
= unsafe_impl_from_IDirect3DSurface9(dst_surface
);
1181 HRESULT hr
= D3DERR_INVALIDCALL
;
1182 struct wined3d_resource_desc src_desc
, dst_desc
;
1183 struct wined3d_resource
*wined3d_resource
;
1185 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_rect %p, filter %#x.\n",
1186 iface
, src_surface
, src_rect
, dst_surface
, dst_rect
, filter
);
1188 wined3d_mutex_lock();
1189 wined3d_resource
= wined3d_surface_get_resource(dst
->wined3d_surface
);
1190 wined3d_resource_get_desc(wined3d_resource
, &dst_desc
);
1192 wined3d_resource
= wined3d_surface_get_resource(src
->wined3d_surface
);
1193 wined3d_resource_get_desc(wined3d_resource
, &src_desc
);
1195 if (src_desc
.usage
& WINED3DUSAGE_DEPTHSTENCIL
)
1197 if (device
->in_scene
)
1199 WARN("Rejecting depth / stencil blit while in scene.\n");
1205 if (src_rect
->left
|| src_rect
->top
|| src_rect
->right
!= src_desc
.width
1206 || src_rect
->bottom
!= src_desc
.height
)
1208 WARN("Rejecting depth / stencil blit with invalid source rect %s.\n",
1209 wine_dbgstr_rect(src_rect
));
1215 if (dst_rect
->left
|| dst_rect
->top
|| dst_rect
->right
!= dst_desc
.width
1216 || dst_rect
->bottom
!= dst_desc
.height
)
1218 WARN("Rejecting depth / stencil blit with invalid destination rect %s.\n",
1219 wine_dbgstr_rect(dst_rect
));
1223 if (src_desc
.width
!= dst_desc
.width
|| src_desc
.height
!= dst_desc
.height
)
1225 WARN("Rejecting depth / stencil blit with mismatched surface sizes.\n");
1230 hr
= wined3d_surface_blt(dst
->wined3d_surface
, dst_rect
, src
->wined3d_surface
, src_rect
, 0, NULL
, filter
);
1231 if (hr
== WINEDDERR_INVALIDRECT
)
1232 hr
= D3DERR_INVALIDCALL
;
1235 wined3d_mutex_unlock();
1239 static HRESULT WINAPI
d3d9_device_ColorFill(IDirect3DDevice9Ex
*iface
,
1240 IDirect3DSurface9
*surface
, const RECT
*rect
, D3DCOLOR color
)
1242 const struct wined3d_color c
=
1244 ((color
>> 16) & 0xff) / 255.0f
,
1245 ((color
>> 8) & 0xff) / 255.0f
,
1246 (color
& 0xff) / 255.0f
,
1247 ((color
>> 24) & 0xff) / 255.0f
,
1249 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1250 struct d3d9_surface
*surface_impl
= unsafe_impl_from_IDirect3DSurface9(surface
);
1251 struct wined3d_resource
*wined3d_resource
;
1252 struct wined3d_resource_desc desc
;
1255 TRACE("iface %p, surface %p, rect %p, color 0x%08x.\n", iface
, surface
, rect
, color
);
1257 wined3d_mutex_lock();
1259 wined3d_resource
= wined3d_surface_get_resource(surface_impl
->wined3d_surface
);
1260 wined3d_resource_get_desc(wined3d_resource
, &desc
);
1262 /* This method is only allowed with surfaces that are render targets, or
1263 * offscreen plain surfaces in D3DPOOL_DEFAULT. */
1264 if (!(desc
.usage
& WINED3DUSAGE_RENDERTARGET
) && desc
.pool
!= WINED3D_POOL_DEFAULT
)
1266 wined3d_mutex_unlock();
1267 WARN("Surface is not a render target, or not a stand-alone D3DPOOL_DEFAULT surface\n");
1268 return D3DERR_INVALIDCALL
;
1271 if (desc
.pool
!= WINED3D_POOL_DEFAULT
&& desc
.pool
!= WINED3D_POOL_SYSTEM_MEM
)
1273 WARN("Color-fill not allowed on surfaces in pool %#x.\n", desc
.pool
);
1274 return D3DERR_INVALIDCALL
;
1277 hr
= wined3d_device_clear_rendertarget_view(device
->wined3d_device
,
1278 d3d9_surface_get_rendertarget_view(surface_impl
), rect
, &c
);
1280 wined3d_mutex_unlock();
1285 static HRESULT WINAPI
d3d9_device_CreateOffscreenPlainSurface(IDirect3DDevice9Ex
*iface
,
1286 UINT width
, UINT height
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DSurface9
**surface
,
1287 HANDLE
*shared_handle
)
1289 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1290 void *user_mem
= NULL
;
1292 TRACE("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p.\n",
1293 iface
, width
, height
, format
, pool
, surface
, shared_handle
);
1296 if (pool
== D3DPOOL_MANAGED
)
1298 WARN("Attempting to create a managed offscreen plain surface.\n");
1299 return D3DERR_INVALIDCALL
;
1304 if (!device
->d3d_parent
->extended
)
1306 WARN("Trying to create a shared or user memory surface on a non-ex device.\n");
1310 if (pool
== D3DPOOL_SYSTEMMEM
)
1311 user_mem
= *shared_handle
;
1314 if (pool
!= D3DPOOL_DEFAULT
)
1316 WARN("Trying to create a shared surface in pool %#x.\n", pool
);
1317 return D3DERR_INVALIDCALL
;
1319 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1323 /* FIXME: Offscreen surfaces are supposed to be always lockable,
1324 * regardless of the pool they're created in. Should we set dynamic usage
1326 return d3d9_device_create_surface(device
, width
, height
, format
,
1327 WINED3D_SURFACE_MAPPABLE
, surface
, 0, pool
, D3DMULTISAMPLE_NONE
, 0, user_mem
);
1330 static HRESULT WINAPI
d3d9_device_SetRenderTarget(IDirect3DDevice9Ex
*iface
, DWORD idx
, IDirect3DSurface9
*surface
)
1332 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1333 struct d3d9_surface
*surface_impl
= unsafe_impl_from_IDirect3DSurface9(surface
);
1336 TRACE("iface %p, idx %u, surface %p.\n", iface
, idx
, surface
);
1338 if (idx
>= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS
)
1340 WARN("Invalid index %u specified.\n", idx
);
1341 return D3DERR_INVALIDCALL
;
1344 if (!idx
&& !surface_impl
)
1346 WARN("Trying to set render target 0 to NULL.\n");
1347 return D3DERR_INVALIDCALL
;
1350 wined3d_mutex_lock();
1351 hr
= wined3d_device_set_rendertarget_view(device
->wined3d_device
, idx
,
1352 surface_impl
? d3d9_surface_get_rendertarget_view(surface_impl
) : NULL
, TRUE
);
1353 wined3d_mutex_unlock();
1358 static HRESULT WINAPI
d3d9_device_GetRenderTarget(IDirect3DDevice9Ex
*iface
, DWORD idx
, IDirect3DSurface9
**surface
)
1360 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1361 struct wined3d_rendertarget_view
*wined3d_rtv
;
1362 struct d3d9_surface
*surface_impl
;
1363 HRESULT hr
= D3D_OK
;
1365 TRACE("iface %p, idx %u, surface %p.\n", iface
, idx
, surface
);
1368 return D3DERR_INVALIDCALL
;
1370 if (idx
>= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS
)
1372 WARN("Invalid index %u specified.\n", idx
);
1373 return D3DERR_INVALIDCALL
;
1376 wined3d_mutex_lock();
1377 if ((wined3d_rtv
= wined3d_device_get_rendertarget_view(device
->wined3d_device
, idx
)))
1379 /* We want the sub resource parent here, since the view itself may be
1380 * internal to wined3d and may not have a parent. */
1381 surface_impl
= wined3d_rendertarget_view_get_sub_resource_parent(wined3d_rtv
);
1382 *surface
= &surface_impl
->IDirect3DSurface9_iface
;
1383 IDirect3DSurface9_AddRef(*surface
);
1387 hr
= WINED3DERR_NOTFOUND
;
1390 wined3d_mutex_unlock();
1395 static HRESULT WINAPI
d3d9_device_SetDepthStencilSurface(IDirect3DDevice9Ex
*iface
, IDirect3DSurface9
*depth_stencil
)
1397 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1398 struct d3d9_surface
*ds_impl
= unsafe_impl_from_IDirect3DSurface9(depth_stencil
);
1400 TRACE("iface %p, depth_stencil %p.\n", iface
, depth_stencil
);
1402 wined3d_mutex_lock();
1403 wined3d_device_set_depth_stencil_view(device
->wined3d_device
,
1404 ds_impl
? d3d9_surface_get_rendertarget_view(ds_impl
) : NULL
);
1405 wined3d_mutex_unlock();
1410 static HRESULT WINAPI
d3d9_device_GetDepthStencilSurface(IDirect3DDevice9Ex
*iface
, IDirect3DSurface9
**depth_stencil
)
1412 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1413 struct wined3d_rendertarget_view
*wined3d_dsv
;
1414 struct d3d9_surface
*surface_impl
;
1415 HRESULT hr
= D3D_OK
;
1417 TRACE("iface %p, depth_stencil %p.\n", iface
, depth_stencil
);
1420 return D3DERR_INVALIDCALL
;
1422 wined3d_mutex_lock();
1423 if ((wined3d_dsv
= wined3d_device_get_depth_stencil_view(device
->wined3d_device
)))
1425 /* We want the sub resource parent here, since the view itself may be
1426 * internal to wined3d and may not have a parent. */
1427 surface_impl
= wined3d_rendertarget_view_get_sub_resource_parent(wined3d_dsv
);
1428 *depth_stencil
= &surface_impl
->IDirect3DSurface9_iface
;
1429 IDirect3DSurface9_AddRef(*depth_stencil
);
1433 hr
= WINED3DERR_NOTFOUND
;
1434 *depth_stencil
= NULL
;
1436 wined3d_mutex_unlock();
1441 static HRESULT WINAPI
d3d9_device_BeginScene(IDirect3DDevice9Ex
*iface
)
1443 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1446 TRACE("iface %p.\n", iface
);
1448 wined3d_mutex_lock();
1449 if (SUCCEEDED(hr
= wined3d_device_begin_scene(device
->wined3d_device
)))
1450 device
->in_scene
= TRUE
;
1451 wined3d_mutex_unlock();
1456 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_EndScene(IDirect3DDevice9Ex
*iface
)
1458 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1461 TRACE("iface %p.\n", iface
);
1463 wined3d_mutex_lock();
1464 if (SUCCEEDED(hr
= wined3d_device_end_scene(device
->wined3d_device
)))
1465 device
->in_scene
= FALSE
;
1466 wined3d_mutex_unlock();
1471 static HRESULT WINAPI
d3d9_device_Clear(IDirect3DDevice9Ex
*iface
, DWORD rect_count
,
1472 const D3DRECT
*rects
, DWORD flags
, D3DCOLOR color
, float z
, DWORD stencil
)
1474 const struct wined3d_color c
=
1476 ((color
>> 16) & 0xff) / 255.0f
,
1477 ((color
>> 8) & 0xff) / 255.0f
,
1478 (color
& 0xff) / 255.0f
,
1479 ((color
>> 24) & 0xff) / 255.0f
,
1481 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1484 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1485 iface
, rect_count
, rects
, flags
, color
, z
, stencil
);
1487 wined3d_mutex_lock();
1488 hr
= wined3d_device_clear(device
->wined3d_device
, rect_count
, (const RECT
*)rects
, flags
, &c
, z
, stencil
);
1489 wined3d_mutex_unlock();
1494 static HRESULT WINAPI
d3d9_device_SetTransform(IDirect3DDevice9Ex
*iface
,
1495 D3DTRANSFORMSTATETYPE state
, const D3DMATRIX
*matrix
)
1497 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1499 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1501 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1502 wined3d_mutex_lock();
1503 wined3d_device_set_transform(device
->wined3d_device
, state
, (const struct wined3d_matrix
*)matrix
);
1504 wined3d_mutex_unlock();
1509 static HRESULT WINAPI
d3d9_device_GetTransform(IDirect3DDevice9Ex
*iface
,
1510 D3DTRANSFORMSTATETYPE state
, D3DMATRIX
*matrix
)
1512 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1514 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1516 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1517 wined3d_mutex_lock();
1518 wined3d_device_get_transform(device
->wined3d_device
, state
, (struct wined3d_matrix
*)matrix
);
1519 wined3d_mutex_unlock();
1524 static HRESULT WINAPI
d3d9_device_MultiplyTransform(IDirect3DDevice9Ex
*iface
,
1525 D3DTRANSFORMSTATETYPE state
, const D3DMATRIX
*matrix
)
1527 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1529 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1531 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1532 wined3d_mutex_lock();
1533 wined3d_device_multiply_transform(device
->wined3d_device
, state
, (const struct wined3d_matrix
*)matrix
);
1534 wined3d_mutex_unlock();
1539 static HRESULT WINAPI
d3d9_device_SetViewport(IDirect3DDevice9Ex
*iface
, const D3DVIEWPORT9
*viewport
)
1541 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1543 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
1545 /* Note: D3DVIEWPORT9 is compatible with struct wined3d_viewport. */
1546 wined3d_mutex_lock();
1547 wined3d_device_set_viewport(device
->wined3d_device
, (const struct wined3d_viewport
*)viewport
);
1548 wined3d_mutex_unlock();
1553 static HRESULT WINAPI
d3d9_device_GetViewport(IDirect3DDevice9Ex
*iface
, D3DVIEWPORT9
*viewport
)
1555 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1557 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
1559 /* Note: D3DVIEWPORT9 is compatible with struct wined3d_viewport. */
1560 wined3d_mutex_lock();
1561 wined3d_device_get_viewport(device
->wined3d_device
, (struct wined3d_viewport
*)viewport
);
1562 wined3d_mutex_unlock();
1567 static HRESULT WINAPI
d3d9_device_SetMaterial(IDirect3DDevice9Ex
*iface
, const D3DMATERIAL9
*material
)
1569 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1571 TRACE("iface %p, material %p.\n", iface
, material
);
1573 /* Note: D3DMATERIAL9 is compatible with struct wined3d_material. */
1574 wined3d_mutex_lock();
1575 wined3d_device_set_material(device
->wined3d_device
, (const struct wined3d_material
*)material
);
1576 wined3d_mutex_unlock();
1581 static HRESULT WINAPI
d3d9_device_GetMaterial(IDirect3DDevice9Ex
*iface
, D3DMATERIAL9
*material
)
1583 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1585 TRACE("iface %p, material %p.\n", iface
, material
);
1587 /* Note: D3DMATERIAL9 is compatible with struct wined3d_material. */
1588 wined3d_mutex_lock();
1589 wined3d_device_get_material(device
->wined3d_device
, (struct wined3d_material
*)material
);
1590 wined3d_mutex_unlock();
1595 static HRESULT WINAPI
d3d9_device_SetLight(IDirect3DDevice9Ex
*iface
, DWORD index
, const D3DLIGHT9
*light
)
1597 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1600 TRACE("iface %p, index %u, light %p.\n", iface
, index
, light
);
1602 /* Note: D3DLIGHT9 is compatible with struct wined3d_light. */
1603 wined3d_mutex_lock();
1604 hr
= wined3d_device_set_light(device
->wined3d_device
, index
, (const struct wined3d_light
*)light
);
1605 wined3d_mutex_unlock();
1610 static HRESULT WINAPI
d3d9_device_GetLight(IDirect3DDevice9Ex
*iface
, DWORD index
, D3DLIGHT9
*light
)
1612 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1615 TRACE("iface %p, index %u, light %p.\n", iface
, index
, light
);
1617 /* Note: D3DLIGHT9 is compatible with struct wined3d_light. */
1618 wined3d_mutex_lock();
1619 hr
= wined3d_device_get_light(device
->wined3d_device
, index
, (struct wined3d_light
*)light
);
1620 wined3d_mutex_unlock();
1625 static HRESULT WINAPI
d3d9_device_LightEnable(IDirect3DDevice9Ex
*iface
, DWORD index
, BOOL enable
)
1627 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1630 TRACE("iface %p, index %u, enable %#x.\n", iface
, index
, enable
);
1632 wined3d_mutex_lock();
1633 hr
= wined3d_device_set_light_enable(device
->wined3d_device
, index
, enable
);
1634 wined3d_mutex_unlock();
1639 static HRESULT WINAPI
d3d9_device_GetLightEnable(IDirect3DDevice9Ex
*iface
, DWORD index
, BOOL
*enable
)
1641 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1644 TRACE("iface %p, index %u, enable %p.\n", iface
, index
, enable
);
1646 wined3d_mutex_lock();
1647 hr
= wined3d_device_get_light_enable(device
->wined3d_device
, index
, enable
);
1648 wined3d_mutex_unlock();
1653 static HRESULT WINAPI
d3d9_device_SetClipPlane(IDirect3DDevice9Ex
*iface
, DWORD index
, const float *plane
)
1655 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1658 TRACE("iface %p, index %u, plane %p.\n", iface
, index
, plane
);
1660 wined3d_mutex_lock();
1661 hr
= wined3d_device_set_clip_plane(device
->wined3d_device
, index
, (const struct wined3d_vec4
*)plane
);
1662 wined3d_mutex_unlock();
1667 static HRESULT WINAPI
d3d9_device_GetClipPlane(IDirect3DDevice9Ex
*iface
, DWORD index
, float *plane
)
1669 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1672 TRACE("iface %p, index %u, plane %p.\n", iface
, index
, plane
);
1674 wined3d_mutex_lock();
1675 hr
= wined3d_device_get_clip_plane(device
->wined3d_device
, index
, (struct wined3d_vec4
*)plane
);
1676 wined3d_mutex_unlock();
1681 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_SetRenderState(IDirect3DDevice9Ex
*iface
,
1682 D3DRENDERSTATETYPE state
, DWORD value
)
1684 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1686 TRACE("iface %p, state %#x, value %#x.\n", iface
, state
, value
);
1688 wined3d_mutex_lock();
1689 wined3d_device_set_render_state(device
->wined3d_device
, state
, value
);
1690 wined3d_mutex_unlock();
1695 static HRESULT WINAPI
d3d9_device_GetRenderState(IDirect3DDevice9Ex
*iface
,
1696 D3DRENDERSTATETYPE state
, DWORD
*value
)
1698 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1700 TRACE("iface %p, state %#x, value %p.\n", iface
, state
, value
);
1702 wined3d_mutex_lock();
1703 *value
= wined3d_device_get_render_state(device
->wined3d_device
, state
);
1704 wined3d_mutex_unlock();
1709 static HRESULT WINAPI
d3d9_device_CreateStateBlock(IDirect3DDevice9Ex
*iface
,
1710 D3DSTATEBLOCKTYPE type
, IDirect3DStateBlock9
**stateblock
)
1712 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1713 struct d3d9_stateblock
*object
;
1716 TRACE("iface %p, type %#x, stateblock %p.\n", iface
, type
, stateblock
);
1718 if (type
!= D3DSBT_ALL
&& type
!= D3DSBT_PIXELSTATE
&& type
!= D3DSBT_VERTEXSTATE
)
1720 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL.\n");
1721 return D3DERR_INVALIDCALL
;
1724 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1726 return E_OUTOFMEMORY
;
1728 hr
= stateblock_init(object
, device
, type
, NULL
);
1731 WARN("Failed to initialize stateblock, hr %#x.\n", hr
);
1732 HeapFree(GetProcessHeap(), 0, object
);
1736 TRACE("Created stateblock %p.\n", object
);
1737 *stateblock
= &object
->IDirect3DStateBlock9_iface
;
1742 static HRESULT WINAPI
d3d9_device_BeginStateBlock(IDirect3DDevice9Ex
*iface
)
1744 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1747 TRACE("iface %p.\n", iface
);
1749 wined3d_mutex_lock();
1750 hr
= wined3d_device_begin_stateblock(device
->wined3d_device
);
1751 wined3d_mutex_unlock();
1756 static HRESULT WINAPI
d3d9_device_EndStateBlock(IDirect3DDevice9Ex
*iface
, IDirect3DStateBlock9
**stateblock
)
1758 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1759 struct wined3d_stateblock
*wined3d_stateblock
;
1760 struct d3d9_stateblock
*object
;
1763 TRACE("iface %p, stateblock %p.\n", iface
, stateblock
);
1765 wined3d_mutex_lock();
1766 hr
= wined3d_device_end_stateblock(device
->wined3d_device
, &wined3d_stateblock
);
1767 wined3d_mutex_unlock();
1770 WARN("IWineD3DDevice_EndStateBlock() failed, hr %#x.\n", hr
);
1774 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1777 wined3d_mutex_lock();
1778 wined3d_stateblock_decref(wined3d_stateblock
);
1779 wined3d_mutex_unlock();
1780 return E_OUTOFMEMORY
;
1783 hr
= stateblock_init(object
, device
, 0, wined3d_stateblock
);
1786 WARN("Failed to initialize stateblock, hr %#x.\n", hr
);
1787 wined3d_mutex_lock();
1788 wined3d_stateblock_decref(wined3d_stateblock
);
1789 wined3d_mutex_unlock();
1790 HeapFree(GetProcessHeap(), 0, object
);
1794 TRACE("Created stateblock %p.\n", object
);
1795 *stateblock
= &object
->IDirect3DStateBlock9_iface
;
1800 static HRESULT WINAPI
d3d9_device_SetClipStatus(IDirect3DDevice9Ex
*iface
, const D3DCLIPSTATUS9
*clip_status
)
1802 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1805 TRACE("iface %p, clip_status %p.\n", iface
, clip_status
);
1807 wined3d_mutex_lock();
1808 hr
= wined3d_device_set_clip_status(device
->wined3d_device
, (const struct wined3d_clip_status
*)clip_status
);
1809 wined3d_mutex_unlock();
1814 static HRESULT WINAPI
d3d9_device_GetClipStatus(IDirect3DDevice9Ex
*iface
, D3DCLIPSTATUS9
*clip_status
)
1816 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1819 TRACE("iface %p, clip_status %p.\n", iface
, clip_status
);
1821 wined3d_mutex_lock();
1822 hr
= wined3d_device_get_clip_status(device
->wined3d_device
, (struct wined3d_clip_status
*)clip_status
);
1823 wined3d_mutex_unlock();
1828 static HRESULT WINAPI
d3d9_device_GetTexture(IDirect3DDevice9Ex
*iface
, DWORD stage
, IDirect3DBaseTexture9
**texture
)
1830 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1831 struct wined3d_texture
*wined3d_texture
= NULL
;
1832 struct d3d9_texture
*texture_impl
;
1834 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
1837 return D3DERR_INVALIDCALL
;
1839 wined3d_mutex_lock();
1840 if ((wined3d_texture
= wined3d_device_get_texture(device
->wined3d_device
, stage
)))
1842 texture_impl
= wined3d_texture_get_parent(wined3d_texture
);
1843 *texture
= &texture_impl
->IDirect3DBaseTexture9_iface
;
1844 IDirect3DBaseTexture9_AddRef(*texture
);
1850 wined3d_mutex_unlock();
1855 static HRESULT WINAPI
d3d9_device_SetTexture(IDirect3DDevice9Ex
*iface
, DWORD stage
, IDirect3DBaseTexture9
*texture
)
1857 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1858 struct d3d9_texture
*texture_impl
;
1861 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
1863 texture_impl
= unsafe_impl_from_IDirect3DBaseTexture9(texture
);
1865 wined3d_mutex_lock();
1866 hr
= wined3d_device_set_texture(device
->wined3d_device
, stage
,
1867 texture_impl
? texture_impl
->wined3d_texture
: NULL
);
1868 wined3d_mutex_unlock();
1873 static const enum wined3d_texture_stage_state tss_lookup
[] =
1875 WINED3D_TSS_INVALID
, /* 0, unused */
1876 WINED3D_TSS_COLOR_OP
, /* 1, D3DTSS_COLOROP */
1877 WINED3D_TSS_COLOR_ARG1
, /* 2, D3DTSS_COLORARG1 */
1878 WINED3D_TSS_COLOR_ARG2
, /* 3, D3DTSS_COLORARG2 */
1879 WINED3D_TSS_ALPHA_OP
, /* 4, D3DTSS_ALPHAOP */
1880 WINED3D_TSS_ALPHA_ARG1
, /* 5, D3DTSS_ALPHAARG1 */
1881 WINED3D_TSS_ALPHA_ARG2
, /* 6, D3DTSS_ALPHAARG2 */
1882 WINED3D_TSS_BUMPENV_MAT00
, /* 7, D3DTSS_BUMPENVMAT00 */
1883 WINED3D_TSS_BUMPENV_MAT01
, /* 8, D3DTSS_BUMPENVMAT01 */
1884 WINED3D_TSS_BUMPENV_MAT10
, /* 9, D3DTSS_BUMPENVMAT10 */
1885 WINED3D_TSS_BUMPENV_MAT11
, /* 10, D3DTSS_BUMPENVMAT11 */
1886 WINED3D_TSS_TEXCOORD_INDEX
, /* 11, D3DTSS_TEXCOORDINDEX */
1887 WINED3D_TSS_INVALID
, /* 12, unused */
1888 WINED3D_TSS_INVALID
, /* 13, unused */
1889 WINED3D_TSS_INVALID
, /* 14, unused */
1890 WINED3D_TSS_INVALID
, /* 15, unused */
1891 WINED3D_TSS_INVALID
, /* 16, unused */
1892 WINED3D_TSS_INVALID
, /* 17, unused */
1893 WINED3D_TSS_INVALID
, /* 18, unused */
1894 WINED3D_TSS_INVALID
, /* 19, unused */
1895 WINED3D_TSS_INVALID
, /* 20, unused */
1896 WINED3D_TSS_INVALID
, /* 21, unused */
1897 WINED3D_TSS_BUMPENV_LSCALE
, /* 22, D3DTSS_BUMPENVLSCALE */
1898 WINED3D_TSS_BUMPENV_LOFFSET
, /* 23, D3DTSS_BUMPENVLOFFSET */
1899 WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1900 WINED3D_TSS_INVALID
, /* 25, unused */
1901 WINED3D_TSS_COLOR_ARG0
, /* 26, D3DTSS_COLORARG0 */
1902 WINED3D_TSS_ALPHA_ARG0
, /* 27, D3DTSS_ALPHAARG0 */
1903 WINED3D_TSS_RESULT_ARG
, /* 28, D3DTSS_RESULTARG */
1904 WINED3D_TSS_INVALID
, /* 29, unused */
1905 WINED3D_TSS_INVALID
, /* 30, unused */
1906 WINED3D_TSS_INVALID
, /* 31, unused */
1907 WINED3D_TSS_CONSTANT
, /* 32, D3DTSS_CONSTANT */
1910 static HRESULT WINAPI
d3d9_device_GetTextureStageState(IDirect3DDevice9Ex
*iface
,
1911 DWORD stage
, D3DTEXTURESTAGESTATETYPE state
, DWORD
*value
)
1913 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1915 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface
, stage
, state
, value
);
1917 if (state
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
1919 WARN("Invalid state %#x passed.\n", state
);
1923 wined3d_mutex_lock();
1924 *value
= wined3d_device_get_texture_stage_state(device
->wined3d_device
, stage
, tss_lookup
[state
]);
1925 wined3d_mutex_unlock();
1930 static HRESULT WINAPI
d3d9_device_SetTextureStageState(IDirect3DDevice9Ex
*iface
,
1931 DWORD stage
, D3DTEXTURESTAGESTATETYPE state
, DWORD value
)
1933 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1935 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface
, stage
, state
, value
);
1937 if (state
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
1939 WARN("Invalid state %#x passed.\n", state
);
1943 wined3d_mutex_lock();
1944 wined3d_device_set_texture_stage_state(device
->wined3d_device
, stage
, tss_lookup
[state
], value
);
1945 wined3d_mutex_unlock();
1950 static HRESULT WINAPI
d3d9_device_GetSamplerState(IDirect3DDevice9Ex
*iface
,
1951 DWORD sampler
, D3DSAMPLERSTATETYPE state
, DWORD
*value
)
1953 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1955 TRACE("iface %p, sampler %u, state %#x, value %p.\n", iface
, sampler
, state
, value
);
1957 wined3d_mutex_lock();
1958 *value
= wined3d_device_get_sampler_state(device
->wined3d_device
, sampler
, state
);
1959 wined3d_mutex_unlock();
1964 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_SetSamplerState(IDirect3DDevice9Ex
*iface
,
1965 DWORD sampler
, D3DSAMPLERSTATETYPE state
, DWORD value
)
1967 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1969 TRACE("iface %p, sampler %u, state %#x, value %#x.\n", iface
, sampler
, state
, value
);
1971 wined3d_mutex_lock();
1972 wined3d_device_set_sampler_state(device
->wined3d_device
, sampler
, state
, value
);
1973 wined3d_mutex_unlock();
1978 static HRESULT WINAPI
d3d9_device_ValidateDevice(IDirect3DDevice9Ex
*iface
, DWORD
*pass_count
)
1980 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1983 TRACE("iface %p, pass_count %p.\n", iface
, pass_count
);
1985 wined3d_mutex_lock();
1986 hr
= wined3d_device_validate_device(device
->wined3d_device
, pass_count
);
1987 wined3d_mutex_unlock();
1992 static HRESULT WINAPI
d3d9_device_SetPaletteEntries(IDirect3DDevice9Ex
*iface
,
1993 UINT palette_idx
, const PALETTEENTRY
*entries
)
1995 WARN("iface %p, palette_idx %u, entries %p unimplemented.\n", iface
, palette_idx
, entries
);
1997 /* The d3d9 palette API is non-functional on Windows. Getters and setters are implemented,
1998 * and some drivers allow the creation of P8 surfaces. These surfaces can be copied to
1999 * other P8 surfaces with StretchRect, but cannot be converted to (A)RGB.
2001 * Some older(dx7) cards may have support for P8 textures, but games cannot rely on this. */
2005 static HRESULT WINAPI
d3d9_device_GetPaletteEntries(IDirect3DDevice9Ex
*iface
,
2006 UINT palette_idx
, PALETTEENTRY
*entries
)
2008 FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface
, palette_idx
, entries
);
2010 return D3DERR_INVALIDCALL
;
2013 static HRESULT WINAPI
d3d9_device_SetCurrentTexturePalette(IDirect3DDevice9Ex
*iface
, UINT palette_idx
)
2015 WARN("iface %p, palette_idx %u unimplemented.\n", iface
, palette_idx
);
2020 static HRESULT WINAPI
d3d9_device_GetCurrentTexturePalette(IDirect3DDevice9Ex
*iface
, UINT
*palette_idx
)
2022 FIXME("iface %p, palette_idx %p.\n", iface
, palette_idx
);
2024 return D3DERR_INVALIDCALL
;
2027 static HRESULT WINAPI
d3d9_device_SetScissorRect(IDirect3DDevice9Ex
*iface
, const RECT
*rect
)
2029 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2031 TRACE("iface %p, rect %p.\n", iface
, rect
);
2033 wined3d_mutex_lock();
2034 wined3d_device_set_scissor_rect(device
->wined3d_device
, rect
);
2035 wined3d_mutex_unlock();
2040 static HRESULT WINAPI
d3d9_device_GetScissorRect(IDirect3DDevice9Ex
*iface
, RECT
*rect
)
2042 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2044 TRACE("iface %p, rect %p.\n", iface
, rect
);
2046 wined3d_mutex_lock();
2047 wined3d_device_get_scissor_rect(device
->wined3d_device
, rect
);
2048 wined3d_mutex_unlock();
2053 static HRESULT WINAPI
d3d9_device_SetSoftwareVertexProcessing(IDirect3DDevice9Ex
*iface
, BOOL software
)
2055 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2057 TRACE("iface %p, software %#x.\n", iface
, software
);
2059 wined3d_mutex_lock();
2060 wined3d_device_set_software_vertex_processing(device
->wined3d_device
, software
);
2061 wined3d_mutex_unlock();
2066 static BOOL WINAPI
d3d9_device_GetSoftwareVertexProcessing(IDirect3DDevice9Ex
*iface
)
2068 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2071 TRACE("iface %p.\n", iface
);
2073 wined3d_mutex_lock();
2074 ret
= wined3d_device_get_software_vertex_processing(device
->wined3d_device
);
2075 wined3d_mutex_unlock();
2080 static HRESULT WINAPI
d3d9_device_SetNPatchMode(IDirect3DDevice9Ex
*iface
, float segment_count
)
2082 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2085 TRACE("iface %p, segment_count %.8e.\n", iface
, segment_count
);
2087 wined3d_mutex_lock();
2088 hr
= wined3d_device_set_npatch_mode(device
->wined3d_device
, segment_count
);
2089 wined3d_mutex_unlock();
2094 static float WINAPI
d3d9_device_GetNPatchMode(IDirect3DDevice9Ex
*iface
)
2096 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2099 TRACE("iface %p.\n", iface
);
2101 wined3d_mutex_lock();
2102 ret
= wined3d_device_get_npatch_mode(device
->wined3d_device
);
2103 wined3d_mutex_unlock();
2108 static HRESULT WINAPI
d3d9_device_DrawPrimitive(IDirect3DDevice9Ex
*iface
,
2109 D3DPRIMITIVETYPE primitive_type
, UINT start_vertex
, UINT primitive_count
)
2111 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2114 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
2115 iface
, primitive_type
, start_vertex
, primitive_count
);
2117 wined3d_mutex_lock();
2118 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
2119 hr
= wined3d_device_draw_primitive(device
->wined3d_device
, start_vertex
,
2120 vertex_count_from_primitive_count(primitive_type
, primitive_count
));
2121 wined3d_mutex_unlock();
2126 static HRESULT WINAPI
d3d9_device_DrawIndexedPrimitive(IDirect3DDevice9Ex
*iface
,
2127 D3DPRIMITIVETYPE primitive_type
, INT base_vertex_idx
, UINT min_vertex_idx
,
2128 UINT vertex_count
, UINT start_idx
, UINT primitive_count
)
2130 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2133 TRACE("iface %p, primitive_type %#x, base_vertex_idx %u, min_vertex_idx %u,\n"
2134 "vertex_count %u, start_idx %u, primitive_count %u.\n",
2135 iface
, primitive_type
, base_vertex_idx
, min_vertex_idx
,
2136 vertex_count
, start_idx
, primitive_count
);
2138 wined3d_mutex_lock();
2139 wined3d_device_set_base_vertex_index(device
->wined3d_device
, base_vertex_idx
);
2140 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
2141 hr
= wined3d_device_draw_indexed_primitive(device
->wined3d_device
, start_idx
,
2142 vertex_count_from_primitive_count(primitive_type
, primitive_count
));
2143 wined3d_mutex_unlock();
2148 /* The caller is responsible for wined3d locking */
2149 static HRESULT
d3d9_device_prepare_vertex_buffer(struct d3d9_device
*device
, UINT min_size
)
2153 if (device
->vertex_buffer_size
< min_size
|| !device
->vertex_buffer
)
2155 UINT size
= max(device
->vertex_buffer_size
* 2, min_size
);
2156 struct wined3d_buffer
*buffer
;
2158 TRACE("Growing vertex buffer to %u bytes\n", size
);
2160 hr
= wined3d_buffer_create_vb(device
->wined3d_device
, size
, WINED3DUSAGE_DYNAMIC
| WINED3DUSAGE_WRITEONLY
,
2161 WINED3D_POOL_DEFAULT
, NULL
, &d3d9_null_wined3d_parent_ops
, &buffer
);
2164 ERR("(%p) wined3d_buffer_create_vb failed with hr = %08x\n", device
, hr
);
2168 if (device
->vertex_buffer
)
2169 wined3d_buffer_decref(device
->vertex_buffer
);
2171 device
->vertex_buffer
= buffer
;
2172 device
->vertex_buffer_size
= size
;
2173 device
->vertex_buffer_pos
= 0;
2178 static HRESULT WINAPI
d3d9_device_DrawPrimitiveUP(IDirect3DDevice9Ex
*iface
,
2179 D3DPRIMITIVETYPE primitive_type
, UINT primitive_count
, const void *data
, UINT stride
)
2181 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2183 UINT vtx_count
= vertex_count_from_primitive_count(primitive_type
, primitive_count
);
2184 UINT size
= vtx_count
* stride
;
2188 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
2189 iface
, primitive_type
, primitive_count
, data
, stride
);
2191 if (!primitive_count
)
2193 WARN("primitive_count is 0, returning D3D_OK\n");
2197 wined3d_mutex_lock();
2199 hr
= d3d9_device_prepare_vertex_buffer(device
, size
);
2203 vb_pos
= device
->vertex_buffer_pos
;
2204 align
= vb_pos
% stride
;
2205 if (align
) align
= stride
- align
;
2206 if (vb_pos
+ size
+ align
> device
->vertex_buffer_size
)
2211 hr
= wined3d_buffer_map(device
->vertex_buffer
, vb_pos
, size
, &buffer_data
,
2212 vb_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
);
2215 memcpy(buffer_data
, data
, size
);
2216 wined3d_buffer_unmap(device
->vertex_buffer
);
2217 device
->vertex_buffer_pos
= vb_pos
+ size
;
2219 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, 0, device
->vertex_buffer
, 0, stride
);
2223 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
2224 hr
= wined3d_device_draw_primitive(device
->wined3d_device
, vb_pos
/ stride
, vtx_count
);
2225 wined3d_device_set_stream_source(device
->wined3d_device
, 0, NULL
, 0, 0);
2228 wined3d_mutex_unlock();
2232 /* The caller is responsible for wined3d locking */
2233 static HRESULT
d3d9_device_prepare_index_buffer(struct d3d9_device
*device
, UINT min_size
)
2237 if (device
->index_buffer_size
< min_size
|| !device
->index_buffer
)
2239 UINT size
= max(device
->index_buffer_size
* 2, min_size
);
2240 struct wined3d_buffer
*buffer
;
2242 TRACE("Growing index buffer to %u bytes\n", size
);
2244 hr
= wined3d_buffer_create_ib(device
->wined3d_device
, size
, WINED3DUSAGE_DYNAMIC
| WINED3DUSAGE_WRITEONLY
,
2245 WINED3D_POOL_DEFAULT
, NULL
, &d3d9_null_wined3d_parent_ops
, &buffer
);
2248 ERR("(%p) wined3d_buffer_create_ib failed with hr = %08x\n", device
, hr
);
2252 if (device
->index_buffer
)
2253 wined3d_buffer_decref(device
->index_buffer
);
2255 device
->index_buffer
= buffer
;
2256 device
->index_buffer_size
= size
;
2257 device
->index_buffer_pos
= 0;
2262 static HRESULT WINAPI
d3d9_device_DrawIndexedPrimitiveUP(IDirect3DDevice9Ex
*iface
,
2263 D3DPRIMITIVETYPE primitive_type
, UINT min_vertex_idx
, UINT vertex_count
,
2264 UINT primitive_count
, const void *index_data
, D3DFORMAT index_format
,
2265 const void *vertex_data
, UINT vertex_stride
)
2267 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2271 UINT idx_count
= vertex_count_from_primitive_count(primitive_type
, primitive_count
);
2272 UINT idx_fmt_size
= index_format
== D3DFMT_INDEX16
? 2 : 4;
2273 UINT idx_size
= idx_count
* idx_fmt_size
;
2276 UINT vtx_size
= vertex_count
* vertex_stride
;
2279 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, primitive_count %u,\n"
2280 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
2281 iface
, primitive_type
, min_vertex_idx
, vertex_count
, primitive_count
,
2282 index_data
, index_format
, vertex_data
, vertex_stride
);
2284 if (!primitive_count
)
2286 WARN("primitive_count is 0, returning D3D_OK\n");
2290 wined3d_mutex_lock();
2292 hr
= d3d9_device_prepare_vertex_buffer(device
, vtx_size
);
2296 vb_pos
= device
->vertex_buffer_pos
;
2297 align
= vb_pos
% vertex_stride
;
2298 if (align
) align
= vertex_stride
- align
;
2299 if (vb_pos
+ vtx_size
+ align
> device
->vertex_buffer_size
)
2304 hr
= wined3d_buffer_map(device
->vertex_buffer
, vb_pos
, vtx_size
, &buffer_data
,
2305 vb_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
);
2308 memcpy(buffer_data
, vertex_data
, vtx_size
);
2309 wined3d_buffer_unmap(device
->vertex_buffer
);
2310 device
->vertex_buffer_pos
= vb_pos
+ vtx_size
;
2312 hr
= d3d9_device_prepare_index_buffer(device
, idx_size
);
2316 ib_pos
= device
->index_buffer_pos
;
2317 align
= ib_pos
% idx_fmt_size
;
2318 if (align
) align
= idx_fmt_size
- align
;
2319 if (ib_pos
+ idx_size
+ align
> device
->index_buffer_size
)
2324 hr
= wined3d_buffer_map(device
->index_buffer
, ib_pos
, idx_size
, &buffer_data
,
2325 ib_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
);
2328 memcpy(buffer_data
, index_data
, idx_size
);
2329 wined3d_buffer_unmap(device
->index_buffer
);
2330 device
->index_buffer_pos
= ib_pos
+ idx_size
;
2332 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, 0, device
->vertex_buffer
, 0, vertex_stride
);
2336 wined3d_device_set_index_buffer(device
->wined3d_device
, device
->index_buffer
,
2337 wined3dformat_from_d3dformat(index_format
));
2338 wined3d_device_set_base_vertex_index(device
->wined3d_device
, vb_pos
/ vertex_stride
);
2340 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
2341 hr
= wined3d_device_draw_indexed_primitive(device
->wined3d_device
, ib_pos
/ idx_fmt_size
, idx_count
);
2343 wined3d_device_set_stream_source(device
->wined3d_device
, 0, NULL
, 0, 0);
2344 wined3d_device_set_index_buffer(device
->wined3d_device
, NULL
, WINED3DFMT_UNKNOWN
);
2345 wined3d_device_set_base_vertex_index(device
->wined3d_device
, 0);
2348 wined3d_mutex_unlock();
2352 static HRESULT WINAPI
d3d9_device_ProcessVertices(IDirect3DDevice9Ex
*iface
,
2353 UINT src_start_idx
, UINT dst_idx
, UINT vertex_count
, IDirect3DVertexBuffer9
*dst_buffer
,
2354 IDirect3DVertexDeclaration9
*declaration
, DWORD flags
)
2356 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2357 struct d3d9_vertexbuffer
*dst_impl
= unsafe_impl_from_IDirect3DVertexBuffer9(dst_buffer
);
2358 struct d3d9_vertex_declaration
*decl_impl
= unsafe_impl_from_IDirect3DVertexDeclaration9(declaration
);
2361 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, declaration %p, flags %#x.\n",
2362 iface
, src_start_idx
, dst_idx
, vertex_count
, dst_buffer
, declaration
, flags
);
2364 wined3d_mutex_lock();
2365 hr
= wined3d_device_process_vertices(device
->wined3d_device
, src_start_idx
, dst_idx
, vertex_count
,
2366 dst_impl
->wined3d_buffer
, decl_impl
? decl_impl
->wined3d_declaration
: NULL
,
2367 flags
, dst_impl
->fvf
);
2368 wined3d_mutex_unlock();
2373 static HRESULT WINAPI
d3d9_device_CreateVertexDeclaration(IDirect3DDevice9Ex
*iface
,
2374 const D3DVERTEXELEMENT9
*elements
, IDirect3DVertexDeclaration9
**declaration
)
2376 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2377 struct d3d9_vertex_declaration
*object
;
2380 TRACE("iface %p, elements %p, declaration %p.\n", iface
, elements
, declaration
);
2384 WARN("Caller passed a NULL declaration, returning D3DERR_INVALIDCALL.\n");
2385 return D3DERR_INVALIDCALL
;
2388 if (SUCCEEDED(hr
= d3d9_vertex_declaration_create(device
, elements
, &object
)))
2389 *declaration
= &object
->IDirect3DVertexDeclaration9_iface
;
2394 static HRESULT WINAPI
d3d9_device_SetVertexDeclaration(IDirect3DDevice9Ex
*iface
,
2395 IDirect3DVertexDeclaration9
*declaration
)
2397 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2398 struct d3d9_vertex_declaration
*decl_impl
= unsafe_impl_from_IDirect3DVertexDeclaration9(declaration
);
2400 TRACE("iface %p, declaration %p.\n", iface
, declaration
);
2402 wined3d_mutex_lock();
2403 wined3d_device_set_vertex_declaration(device
->wined3d_device
,
2404 decl_impl
? decl_impl
->wined3d_declaration
: NULL
);
2405 wined3d_mutex_unlock();
2410 static HRESULT WINAPI
d3d9_device_GetVertexDeclaration(IDirect3DDevice9Ex
*iface
,
2411 IDirect3DVertexDeclaration9
**declaration
)
2413 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2414 struct wined3d_vertex_declaration
*wined3d_declaration
;
2415 struct d3d9_vertex_declaration
*declaration_impl
;
2417 TRACE("iface %p, declaration %p.\n", iface
, declaration
);
2419 if (!declaration
) return D3DERR_INVALIDCALL
;
2421 wined3d_mutex_lock();
2422 if ((wined3d_declaration
= wined3d_device_get_vertex_declaration(device
->wined3d_device
)))
2424 declaration_impl
= wined3d_vertex_declaration_get_parent(wined3d_declaration
);
2425 *declaration
= &declaration_impl
->IDirect3DVertexDeclaration9_iface
;
2426 IDirect3DVertexDeclaration9_AddRef(*declaration
);
2430 *declaration
= NULL
;
2432 wined3d_mutex_unlock();
2434 TRACE("Returning %p.\n", *declaration
);
2438 static struct wined3d_vertex_declaration
*device_get_fvf_declaration(struct d3d9_device
*device
, DWORD fvf
)
2440 struct wined3d_vertex_declaration
*wined3d_declaration
;
2441 struct fvf_declaration
*fvf_decls
= device
->fvf_decls
;
2442 struct d3d9_vertex_declaration
*d3d9_declaration
;
2443 D3DVERTEXELEMENT9
*elements
;
2444 int p
, low
, high
; /* deliberately signed */
2447 TRACE("Searching for declaration for fvf %08x... ", fvf
);
2450 high
= device
->fvf_decl_count
- 1;
2453 p
= (low
+ high
) >> 1;
2456 if (fvf_decls
[p
].fvf
== fvf
)
2458 TRACE("found %p.\n", fvf_decls
[p
].decl
);
2459 return fvf_decls
[p
].decl
;
2462 if (fvf_decls
[p
].fvf
< fvf
)
2467 TRACE("not found. Creating and inserting at position %d.\n", low
);
2469 if (FAILED(hr
= vdecl_convert_fvf(fvf
, &elements
)))
2472 hr
= d3d9_vertex_declaration_create(device
, elements
, &d3d9_declaration
);
2473 HeapFree(GetProcessHeap(), 0, elements
);
2477 if (device
->fvf_decl_size
== device
->fvf_decl_count
)
2479 UINT grow
= max(device
->fvf_decl_size
/ 2, 8);
2481 fvf_decls
= HeapReAlloc(GetProcessHeap(), 0, fvf_decls
, sizeof(*fvf_decls
) * (device
->fvf_decl_size
+ grow
));
2484 IDirect3DVertexDeclaration9_Release(&d3d9_declaration
->IDirect3DVertexDeclaration9_iface
);
2487 device
->fvf_decls
= fvf_decls
;
2488 device
->fvf_decl_size
+= grow
;
2491 d3d9_declaration
->fvf
= fvf
;
2492 wined3d_declaration
= d3d9_declaration
->wined3d_declaration
;
2493 wined3d_vertex_declaration_incref(wined3d_declaration
);
2494 IDirect3DVertexDeclaration9_Release(&d3d9_declaration
->IDirect3DVertexDeclaration9_iface
);
2496 memmove(fvf_decls
+ low
+ 1, fvf_decls
+ low
, sizeof(*fvf_decls
) * (device
->fvf_decl_count
- low
));
2497 fvf_decls
[low
].decl
= wined3d_declaration
;
2498 fvf_decls
[low
].fvf
= fvf
;
2499 ++device
->fvf_decl_count
;
2501 TRACE("Returning %p. %u declarations in array.\n", wined3d_declaration
, device
->fvf_decl_count
);
2503 return wined3d_declaration
;
2506 static HRESULT WINAPI
d3d9_device_SetFVF(IDirect3DDevice9Ex
*iface
, DWORD fvf
)
2508 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2509 struct wined3d_vertex_declaration
*decl
;
2511 TRACE("iface %p, fvf %#x.\n", iface
, fvf
);
2515 WARN("%#x is not a valid FVF.\n", fvf
);
2519 wined3d_mutex_lock();
2520 if (!(decl
= device_get_fvf_declaration(device
, fvf
)))
2522 wined3d_mutex_unlock();
2523 ERR("Failed to create a vertex declaration for fvf %#x.\n", fvf
);
2524 return D3DERR_DRIVERINTERNALERROR
;
2527 wined3d_device_set_vertex_declaration(device
->wined3d_device
, decl
);
2528 wined3d_mutex_unlock();
2533 static HRESULT WINAPI
d3d9_device_GetFVF(IDirect3DDevice9Ex
*iface
, DWORD
*fvf
)
2535 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2536 struct wined3d_vertex_declaration
*wined3d_declaration
;
2537 struct d3d9_vertex_declaration
*d3d9_declaration
;
2539 TRACE("iface %p, fvf %p.\n", iface
, fvf
);
2541 wined3d_mutex_lock();
2542 if ((wined3d_declaration
= wined3d_device_get_vertex_declaration(device
->wined3d_device
)))
2544 d3d9_declaration
= wined3d_vertex_declaration_get_parent(wined3d_declaration
);
2545 *fvf
= d3d9_declaration
->fvf
;
2551 wined3d_mutex_unlock();
2553 TRACE("Returning FVF %#x.\n", *fvf
);
2558 static HRESULT WINAPI
d3d9_device_CreateVertexShader(IDirect3DDevice9Ex
*iface
,
2559 const DWORD
*byte_code
, IDirect3DVertexShader9
**shader
)
2561 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2562 struct d3d9_vertexshader
*object
;
2565 TRACE("iface %p, byte_code %p, shader %p.\n", iface
, byte_code
, shader
);
2567 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2569 return E_OUTOFMEMORY
;
2571 hr
= vertexshader_init(object
, device
, byte_code
);
2574 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
2575 HeapFree(GetProcessHeap(), 0, object
);
2579 TRACE("Created vertex shader %p.\n", object
);
2580 *shader
= &object
->IDirect3DVertexShader9_iface
;
2585 static HRESULT WINAPI
d3d9_device_SetVertexShader(IDirect3DDevice9Ex
*iface
, IDirect3DVertexShader9
*shader
)
2587 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2588 struct d3d9_vertexshader
*shader_obj
= unsafe_impl_from_IDirect3DVertexShader9(shader
);
2590 TRACE("iface %p, shader %p.\n", iface
, shader
);
2592 wined3d_mutex_lock();
2593 wined3d_device_set_vertex_shader(device
->wined3d_device
,
2594 shader_obj
? shader_obj
->wined3d_shader
: NULL
);
2595 wined3d_mutex_unlock();
2600 static HRESULT WINAPI
d3d9_device_GetVertexShader(IDirect3DDevice9Ex
*iface
, IDirect3DVertexShader9
**shader
)
2602 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2603 struct d3d9_vertexshader
*shader_impl
;
2604 struct wined3d_shader
*wined3d_shader
;
2606 TRACE("iface %p, shader %p.\n", iface
, shader
);
2608 wined3d_mutex_lock();
2609 if ((wined3d_shader
= wined3d_device_get_vertex_shader(device
->wined3d_device
)))
2611 shader_impl
= wined3d_shader_get_parent(wined3d_shader
);
2612 *shader
= &shader_impl
->IDirect3DVertexShader9_iface
;
2613 IDirect3DVertexShader9_AddRef(*shader
);
2619 wined3d_mutex_unlock();
2621 TRACE("Returning %p.\n", *shader
);
2626 static HRESULT WINAPI
d3d9_device_SetVertexShaderConstantF(IDirect3DDevice9Ex
*iface
,
2627 UINT reg_idx
, const float *data
, UINT count
)
2629 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2632 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2634 if (reg_idx
+ count
> D3D9_MAX_VERTEX_SHADER_CONSTANTF
)
2636 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
2637 reg_idx
+ count
, D3D9_MAX_VERTEX_SHADER_CONSTANTF
);
2638 return D3DERR_INVALIDCALL
;
2641 wined3d_mutex_lock();
2642 hr
= wined3d_device_set_vs_consts_f(device
->wined3d_device
, reg_idx
, data
, count
);
2643 wined3d_mutex_unlock();
2648 static HRESULT WINAPI
d3d9_device_GetVertexShaderConstantF(IDirect3DDevice9Ex
*iface
,
2649 UINT reg_idx
, float *data
, UINT count
)
2651 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2654 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2656 if (reg_idx
+ count
> D3D9_MAX_VERTEX_SHADER_CONSTANTF
)
2658 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
2659 reg_idx
+ count
, D3D9_MAX_VERTEX_SHADER_CONSTANTF
);
2660 return D3DERR_INVALIDCALL
;
2663 wined3d_mutex_lock();
2664 hr
= wined3d_device_get_vs_consts_f(device
->wined3d_device
, reg_idx
, data
, count
);
2665 wined3d_mutex_unlock();
2670 static HRESULT WINAPI
d3d9_device_SetVertexShaderConstantI(IDirect3DDevice9Ex
*iface
,
2671 UINT reg_idx
, const int *data
, UINT count
)
2673 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2676 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2678 wined3d_mutex_lock();
2679 hr
= wined3d_device_set_vs_consts_i(device
->wined3d_device
, reg_idx
, data
, count
);
2680 wined3d_mutex_unlock();
2685 static HRESULT WINAPI
d3d9_device_GetVertexShaderConstantI(IDirect3DDevice9Ex
*iface
,
2686 UINT reg_idx
, int *data
, UINT count
)
2688 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2691 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2693 wined3d_mutex_lock();
2694 hr
= wined3d_device_get_vs_consts_i(device
->wined3d_device
, reg_idx
, data
, count
);
2695 wined3d_mutex_unlock();
2700 static HRESULT WINAPI
d3d9_device_SetVertexShaderConstantB(IDirect3DDevice9Ex
*iface
,
2701 UINT reg_idx
, const BOOL
*data
, UINT count
)
2703 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2706 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2708 wined3d_mutex_lock();
2709 hr
= wined3d_device_set_vs_consts_b(device
->wined3d_device
, reg_idx
, data
, count
);
2710 wined3d_mutex_unlock();
2715 static HRESULT WINAPI
d3d9_device_GetVertexShaderConstantB(IDirect3DDevice9Ex
*iface
,
2716 UINT reg_idx
, BOOL
*data
, UINT count
)
2718 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2721 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2723 wined3d_mutex_lock();
2724 hr
= wined3d_device_get_vs_consts_b(device
->wined3d_device
, reg_idx
, data
, count
);
2725 wined3d_mutex_unlock();
2730 static HRESULT WINAPI
d3d9_device_SetStreamSource(IDirect3DDevice9Ex
*iface
,
2731 UINT stream_idx
, IDirect3DVertexBuffer9
*buffer
, UINT offset
, UINT stride
)
2733 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2734 struct d3d9_vertexbuffer
*buffer_impl
= unsafe_impl_from_IDirect3DVertexBuffer9(buffer
);
2737 TRACE("iface %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
2738 iface
, stream_idx
, buffer
, offset
, stride
);
2740 wined3d_mutex_lock();
2741 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, stream_idx
,
2742 buffer_impl
? buffer_impl
->wined3d_buffer
: NULL
, offset
, stride
);
2743 wined3d_mutex_unlock();
2748 static HRESULT WINAPI
d3d9_device_GetStreamSource(IDirect3DDevice9Ex
*iface
,
2749 UINT stream_idx
, IDirect3DVertexBuffer9
**buffer
, UINT
*offset
, UINT
*stride
)
2751 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2752 struct d3d9_vertexbuffer
*buffer_impl
;
2753 struct wined3d_buffer
*wined3d_buffer
;
2756 TRACE("iface %p, stream_idx %u, buffer %p, offset %p, stride %p.\n",
2757 iface
, stream_idx
, buffer
, offset
, stride
);
2760 return D3DERR_INVALIDCALL
;
2762 wined3d_mutex_lock();
2763 hr
= wined3d_device_get_stream_source(device
->wined3d_device
, stream_idx
, &wined3d_buffer
, offset
, stride
);
2764 if (SUCCEEDED(hr
) && wined3d_buffer
)
2766 buffer_impl
= wined3d_buffer_get_parent(wined3d_buffer
);
2767 *buffer
= &buffer_impl
->IDirect3DVertexBuffer9_iface
;
2768 IDirect3DVertexBuffer9_AddRef(*buffer
);
2773 FIXME("Call to GetStreamSource failed %p %p\n", offset
, stride
);
2776 wined3d_mutex_unlock();
2781 static HRESULT WINAPI
d3d9_device_SetStreamSourceFreq(IDirect3DDevice9Ex
*iface
, UINT stream_idx
, UINT freq
)
2783 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2786 TRACE("iface %p, stream_idx %u, freq %u.\n", iface
, stream_idx
, freq
);
2788 wined3d_mutex_lock();
2789 hr
= wined3d_device_set_stream_source_freq(device
->wined3d_device
, stream_idx
, freq
);
2790 wined3d_mutex_unlock();
2795 static HRESULT WINAPI
d3d9_device_GetStreamSourceFreq(IDirect3DDevice9Ex
*iface
, UINT stream_idx
, UINT
*freq
)
2797 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2800 TRACE("iface %p, stream_idx %u, freq %p.\n", iface
, stream_idx
, freq
);
2802 wined3d_mutex_lock();
2803 hr
= wined3d_device_get_stream_source_freq(device
->wined3d_device
, stream_idx
, freq
);
2804 wined3d_mutex_unlock();
2809 static HRESULT WINAPI
d3d9_device_SetIndices(IDirect3DDevice9Ex
*iface
, IDirect3DIndexBuffer9
*buffer
)
2811 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2812 struct d3d9_indexbuffer
*ib
= unsafe_impl_from_IDirect3DIndexBuffer9(buffer
);
2814 TRACE("iface %p, buffer %p.\n", iface
, buffer
);
2816 wined3d_mutex_lock();
2817 wined3d_device_set_index_buffer(device
->wined3d_device
,
2818 ib
? ib
->wined3d_buffer
: NULL
,
2819 ib
? ib
->format
: WINED3DFMT_UNKNOWN
);
2820 wined3d_mutex_unlock();
2825 static HRESULT WINAPI
d3d9_device_GetIndices(IDirect3DDevice9Ex
*iface
, IDirect3DIndexBuffer9
**buffer
)
2827 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2828 enum wined3d_format_id wined3d_format
;
2829 struct wined3d_buffer
*wined3d_buffer
;
2830 struct d3d9_indexbuffer
*buffer_impl
;
2832 TRACE("iface %p, buffer %p.\n", iface
, buffer
);
2835 return D3DERR_INVALIDCALL
;
2837 wined3d_mutex_lock();
2838 if ((wined3d_buffer
= wined3d_device_get_index_buffer(device
->wined3d_device
, &wined3d_format
)))
2840 buffer_impl
= wined3d_buffer_get_parent(wined3d_buffer
);
2841 *buffer
= &buffer_impl
->IDirect3DIndexBuffer9_iface
;
2842 IDirect3DIndexBuffer9_AddRef(*buffer
);
2848 wined3d_mutex_unlock();
2853 static HRESULT WINAPI
d3d9_device_CreatePixelShader(IDirect3DDevice9Ex
*iface
,
2854 const DWORD
*byte_code
, IDirect3DPixelShader9
**shader
)
2856 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2857 struct d3d9_pixelshader
*object
;
2860 TRACE("iface %p, byte_code %p, shader %p.\n", iface
, byte_code
, shader
);
2862 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2865 FIXME("Failed to allocate pixel shader memory.\n");
2866 return E_OUTOFMEMORY
;
2869 hr
= pixelshader_init(object
, device
, byte_code
);
2872 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
2873 HeapFree(GetProcessHeap(), 0, object
);
2877 TRACE("Created pixel shader %p.\n", object
);
2878 *shader
= &object
->IDirect3DPixelShader9_iface
;
2883 static HRESULT WINAPI
d3d9_device_SetPixelShader(IDirect3DDevice9Ex
*iface
, IDirect3DPixelShader9
*shader
)
2885 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2886 struct d3d9_pixelshader
*shader_obj
= unsafe_impl_from_IDirect3DPixelShader9(shader
);
2888 TRACE("iface %p, shader %p.\n", iface
, shader
);
2890 wined3d_mutex_lock();
2891 wined3d_device_set_pixel_shader(device
->wined3d_device
,
2892 shader_obj
? shader_obj
->wined3d_shader
: NULL
);
2893 wined3d_mutex_unlock();
2898 static HRESULT WINAPI
d3d9_device_GetPixelShader(IDirect3DDevice9Ex
*iface
, IDirect3DPixelShader9
**shader
)
2900 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2901 struct d3d9_pixelshader
*shader_impl
;
2902 struct wined3d_shader
*wined3d_shader
;
2904 TRACE("iface %p, shader %p.\n", iface
, shader
);
2906 if (!shader
) return D3DERR_INVALIDCALL
;
2908 wined3d_mutex_lock();
2909 if ((wined3d_shader
= wined3d_device_get_pixel_shader(device
->wined3d_device
)))
2911 shader_impl
= wined3d_shader_get_parent(wined3d_shader
);
2912 *shader
= &shader_impl
->IDirect3DPixelShader9_iface
;
2913 IDirect3DPixelShader9_AddRef(*shader
);
2919 wined3d_mutex_unlock();
2921 TRACE("Returning %p.\n", *shader
);
2926 static HRESULT WINAPI
d3d9_device_SetPixelShaderConstantF(IDirect3DDevice9Ex
*iface
,
2927 UINT reg_idx
, const float *data
, UINT count
)
2929 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2932 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2934 wined3d_mutex_lock();
2935 hr
= wined3d_device_set_ps_consts_f(device
->wined3d_device
, reg_idx
, data
, count
);
2936 wined3d_mutex_unlock();
2941 static HRESULT WINAPI
d3d9_device_GetPixelShaderConstantF(IDirect3DDevice9Ex
*iface
,
2942 UINT reg_idx
, float *data
, UINT count
)
2944 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2947 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2949 wined3d_mutex_lock();
2950 hr
= wined3d_device_get_ps_consts_f(device
->wined3d_device
, reg_idx
, data
, count
);
2951 wined3d_mutex_unlock();
2956 static HRESULT WINAPI
d3d9_device_SetPixelShaderConstantI(IDirect3DDevice9Ex
*iface
,
2957 UINT reg_idx
, const int *data
, UINT count
)
2959 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2962 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2964 wined3d_mutex_lock();
2965 hr
= wined3d_device_set_ps_consts_i(device
->wined3d_device
, reg_idx
, data
, count
);
2966 wined3d_mutex_unlock();
2971 static HRESULT WINAPI
d3d9_device_GetPixelShaderConstantI(IDirect3DDevice9Ex
*iface
,
2972 UINT reg_idx
, int *data
, UINT count
)
2974 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2977 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2979 wined3d_mutex_lock();
2980 hr
= wined3d_device_get_ps_consts_i(device
->wined3d_device
, reg_idx
, data
, count
);
2981 wined3d_mutex_unlock();
2986 static HRESULT WINAPI
d3d9_device_SetPixelShaderConstantB(IDirect3DDevice9Ex
*iface
,
2987 UINT reg_idx
, const BOOL
*data
, UINT count
)
2989 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2992 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2994 wined3d_mutex_lock();
2995 hr
= wined3d_device_set_ps_consts_b(device
->wined3d_device
, reg_idx
, data
, count
);
2996 wined3d_mutex_unlock();
3001 static HRESULT WINAPI
d3d9_device_GetPixelShaderConstantB(IDirect3DDevice9Ex
*iface
,
3002 UINT reg_idx
, BOOL
*data
, UINT count
)
3004 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3007 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3009 wined3d_mutex_lock();
3010 hr
= wined3d_device_get_ps_consts_b(device
->wined3d_device
, reg_idx
, data
, count
);
3011 wined3d_mutex_unlock();
3016 static HRESULT WINAPI
d3d9_device_DrawRectPatch(IDirect3DDevice9Ex
*iface
, UINT handle
,
3017 const float *segment_count
, const D3DRECTPATCH_INFO
*patch_info
)
3019 FIXME("iface %p, handle %#x, segment_count %p, patch_info %p unimplemented.\n",
3020 iface
, handle
, segment_count
, patch_info
);
3024 static HRESULT WINAPI
d3d9_device_DrawTriPatch(IDirect3DDevice9Ex
*iface
, UINT handle
,
3025 const float *segment_count
, const D3DTRIPATCH_INFO
*patch_info
)
3027 FIXME("iface %p, handle %#x, segment_count %p, patch_info %p unimplemented.\n",
3028 iface
, handle
, segment_count
, patch_info
);
3032 static HRESULT WINAPI
d3d9_device_DeletePatch(IDirect3DDevice9Ex
*iface
, UINT handle
)
3034 FIXME("iface %p, handle %#x unimplemented.\n", iface
, handle
);
3035 return D3DERR_INVALIDCALL
;
3038 static HRESULT WINAPI
d3d9_device_CreateQuery(IDirect3DDevice9Ex
*iface
, D3DQUERYTYPE type
, IDirect3DQuery9
**query
)
3040 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3041 struct d3d9_query
*object
;
3044 TRACE("iface %p, type %#x, query %p.\n", iface
, type
, query
);
3046 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3048 return E_OUTOFMEMORY
;
3050 hr
= query_init(object
, device
, type
);
3053 WARN("Failed to initialize query, hr %#x.\n", hr
);
3054 HeapFree(GetProcessHeap(), 0, object
);
3058 TRACE("Created query %p.\n", object
);
3059 if (query
) *query
= &object
->IDirect3DQuery9_iface
;
3060 else IDirect3DQuery9_Release(&object
->IDirect3DQuery9_iface
);
3065 static HRESULT WINAPI
d3d9_device_SetConvolutionMonoKernel(IDirect3DDevice9Ex
*iface
,
3066 UINT width
, UINT height
, float *rows
, float *columns
)
3068 FIXME("iface %p, width %u, height %u, rows %p, columns %p stub!\n",
3069 iface
, width
, height
, rows
, columns
);
3074 static HRESULT WINAPI
d3d9_device_ComposeRects(IDirect3DDevice9Ex
*iface
,
3075 IDirect3DSurface9
*src_surface
, IDirect3DSurface9
*dst_surface
, IDirect3DVertexBuffer9
*src_descs
,
3076 UINT rect_count
, IDirect3DVertexBuffer9
*dst_descs
, D3DCOMPOSERECTSOP operation
, INT offset_x
, INT offset_y
)
3078 FIXME("iface %p, src_surface %p, dst_surface %p, src_descs %p, rect_count %u,\n"
3079 "dst_descs %p, operation %#x, offset_x %u, offset_y %u stub!\n",
3080 iface
, src_surface
, dst_surface
, src_descs
, rect_count
,
3081 dst_descs
, operation
, offset_x
, offset_y
);
3086 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_PresentEx(IDirect3DDevice9Ex
*iface
,
3087 const RECT
*src_rect
, const RECT
*dst_rect
, HWND dst_window_override
,
3088 const RGNDATA
*dirty_region
, DWORD flags
)
3090 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3093 TRACE("iface %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p, flags %#x.\n",
3094 iface
, wine_dbgstr_rect(src_rect
), wine_dbgstr_rect(dst_rect
),
3095 dst_window_override
, dirty_region
, flags
);
3097 if (device
->device_state
!= D3D9_DEVICE_STATE_OK
)
3098 return S_PRESENT_OCCLUDED
;
3100 wined3d_mutex_lock();
3101 hr
= wined3d_device_present(device
->wined3d_device
, src_rect
, dst_rect
,
3102 dst_window_override
, dirty_region
, flags
);
3103 wined3d_mutex_unlock();
3108 static HRESULT WINAPI
d3d9_device_GetGPUThreadPriority(IDirect3DDevice9Ex
*iface
, INT
*priority
)
3110 FIXME("iface %p, priority %p stub!\n", iface
, priority
);
3115 static HRESULT WINAPI
d3d9_device_SetGPUThreadPriority(IDirect3DDevice9Ex
*iface
, INT priority
)
3117 FIXME("iface %p, priority %d stub!\n", iface
, priority
);
3122 static HRESULT WINAPI
d3d9_device_WaitForVBlank(IDirect3DDevice9Ex
*iface
, UINT swapchain_idx
)
3124 FIXME("iface %p, swapchain_idx %u stub!\n", iface
, swapchain_idx
);
3129 static HRESULT WINAPI
d3d9_device_CheckResourceResidency(IDirect3DDevice9Ex
*iface
,
3130 IDirect3DResource9
**resources
, UINT32 resource_count
)
3132 FIXME("iface %p, resources %p, resource_count %u stub!\n",
3133 iface
, resources
, resource_count
);
3138 static HRESULT WINAPI
d3d9_device_SetMaximumFrameLatency(IDirect3DDevice9Ex
*iface
, UINT max_latency
)
3140 FIXME("iface %p, max_latency %u stub!\n", iface
, max_latency
);
3145 static HRESULT WINAPI
d3d9_device_GetMaximumFrameLatency(IDirect3DDevice9Ex
*iface
, UINT
*max_latency
)
3147 FIXME("iface %p, max_latency %p stub!\n", iface
, max_latency
);
3154 static HRESULT WINAPI
d3d9_device_CheckDeviceState(IDirect3DDevice9Ex
*iface
, HWND dst_window
)
3156 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3157 struct wined3d_swapchain_desc swapchain_desc
;
3158 struct wined3d_swapchain
*swapchain
;
3160 TRACE("iface %p, dst_window %p.\n", iface
, dst_window
);
3162 wined3d_mutex_lock();
3163 swapchain
= wined3d_device_get_swapchain(device
->wined3d_device
, 0);
3164 wined3d_swapchain_get_desc(swapchain
, &swapchain_desc
);
3165 wined3d_mutex_unlock();
3167 if (swapchain_desc
.windowed
)
3170 /* FIXME: This is actually supposed to check if any other device is in
3171 * fullscreen mode. */
3172 if (dst_window
!= swapchain_desc
.device_window
)
3173 return device
->device_state
== D3D9_DEVICE_STATE_OK
? S_PRESENT_OCCLUDED
: D3D_OK
;
3175 return device
->device_state
== D3D9_DEVICE_STATE_OK
? D3D_OK
: S_PRESENT_OCCLUDED
;
3178 static HRESULT WINAPI
d3d9_device_CreateRenderTargetEx(IDirect3DDevice9Ex
*iface
,
3179 UINT width
, UINT height
, D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
3180 BOOL lockable
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
, DWORD usage
)
3182 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
3183 "lockable %#x, surface %p, shared_handle %p, usage %#x stub!\n",
3184 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
3185 lockable
, surface
, shared_handle
, usage
);
3189 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
3194 static HRESULT WINAPI
d3d9_device_CreateOffscreenPlainSurfaceEx(IDirect3DDevice9Ex
*iface
,
3195 UINT width
, UINT height
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DSurface9
**surface
,
3196 HANDLE
*shared_handle
, DWORD usage
)
3198 FIXME("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p, usage %#x stub!\n",
3199 iface
, width
, height
, format
, pool
, surface
, shared_handle
, usage
);
3204 static HRESULT WINAPI
d3d9_device_CreateDepthStencilSurfaceEx(IDirect3DDevice9Ex
*iface
,
3205 UINT width
, UINT height
, D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
3206 BOOL discard
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
, DWORD usage
)
3208 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
3209 "discard %#x, surface %p, shared_handle %p, usage %#x stub!\n",
3210 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
3211 discard
, surface
, shared_handle
, usage
);
3215 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
3220 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_ResetEx(IDirect3DDevice9Ex
*iface
,
3221 D3DPRESENT_PARAMETERS
*present_parameters
, D3DDISPLAYMODEEX
*mode
)
3223 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3224 struct wined3d_swapchain_desc swapchain_desc
;
3225 struct wined3d_display_mode wined3d_mode
;
3228 TRACE("iface %p, present_parameters %p, mode %p.\n", iface
, present_parameters
, mode
);
3232 wined3d_mode
.width
= mode
->Width
;
3233 wined3d_mode
.height
= mode
->Height
;
3234 wined3d_mode
.refresh_rate
= mode
->RefreshRate
;
3235 wined3d_mode
.format_id
= wined3dformat_from_d3dformat(mode
->Format
);
3236 wined3d_mode
.scanline_ordering
= mode
->ScanLineOrdering
;
3239 wined3d_mutex_lock();
3241 if (device
->vertex_buffer
)
3243 wined3d_buffer_decref(device
->vertex_buffer
);
3244 device
->vertex_buffer
= NULL
;
3245 device
->vertex_buffer_size
= 0;
3247 if (device
->index_buffer
)
3249 wined3d_buffer_decref(device
->index_buffer
);
3250 device
->index_buffer
= NULL
;
3251 device
->index_buffer_size
= 0;
3254 wined3d_swapchain_desc_from_present_parameters(&swapchain_desc
, present_parameters
);
3255 hr
= wined3d_device_reset(device
->wined3d_device
, &swapchain_desc
,
3256 mode
? &wined3d_mode
: NULL
, reset_enum_callback
, FALSE
);
3257 wined3d_mutex_unlock();
3262 static HRESULT WINAPI
d3d9_device_GetDisplayModeEx(IDirect3DDevice9Ex
*iface
,
3263 UINT swapchain_idx
, D3DDISPLAYMODEEX
*mode
, D3DDISPLAYROTATION
*rotation
)
3265 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3266 struct wined3d_display_mode wined3d_mode
;
3269 TRACE("iface %p, swapchain_idx %u, mode %p, rotation %p.\n",
3270 iface
, swapchain_idx
, mode
, rotation
);
3272 if (mode
->Size
!= sizeof(*mode
))
3273 return D3DERR_INVALIDCALL
;
3275 wined3d_mutex_lock();
3276 hr
= wined3d_device_get_display_mode(device
->wined3d_device
, swapchain_idx
, &wined3d_mode
,
3277 (enum wined3d_display_rotation
*)rotation
);
3278 wined3d_mutex_unlock();
3282 mode
->Width
= wined3d_mode
.width
;
3283 mode
->Height
= wined3d_mode
.height
;
3284 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
3285 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
3286 mode
->ScanLineOrdering
= wined3d_mode
.scanline_ordering
;
3292 static const struct IDirect3DDevice9ExVtbl d3d9_device_vtbl
=
3295 d3d9_device_QueryInterface
,
3297 d3d9_device_Release
,
3298 /* IDirect3DDevice9 */
3299 d3d9_device_TestCooperativeLevel
,
3300 d3d9_device_GetAvailableTextureMem
,
3301 d3d9_device_EvictManagedResources
,
3302 d3d9_device_GetDirect3D
,
3303 d3d9_device_GetDeviceCaps
,
3304 d3d9_device_GetDisplayMode
,
3305 d3d9_device_GetCreationParameters
,
3306 d3d9_device_SetCursorProperties
,
3307 d3d9_device_SetCursorPosition
,
3308 d3d9_device_ShowCursor
,
3309 d3d9_device_CreateAdditionalSwapChain
,
3310 d3d9_device_GetSwapChain
,
3311 d3d9_device_GetNumberOfSwapChains
,
3313 d3d9_device_Present
,
3314 d3d9_device_GetBackBuffer
,
3315 d3d9_device_GetRasterStatus
,
3316 d3d9_device_SetDialogBoxMode
,
3317 d3d9_device_SetGammaRamp
,
3318 d3d9_device_GetGammaRamp
,
3319 d3d9_device_CreateTexture
,
3320 d3d9_device_CreateVolumeTexture
,
3321 d3d9_device_CreateCubeTexture
,
3322 d3d9_device_CreateVertexBuffer
,
3323 d3d9_device_CreateIndexBuffer
,
3324 d3d9_device_CreateRenderTarget
,
3325 d3d9_device_CreateDepthStencilSurface
,
3326 d3d9_device_UpdateSurface
,
3327 d3d9_device_UpdateTexture
,
3328 d3d9_device_GetRenderTargetData
,
3329 d3d9_device_GetFrontBufferData
,
3330 d3d9_device_StretchRect
,
3331 d3d9_device_ColorFill
,
3332 d3d9_device_CreateOffscreenPlainSurface
,
3333 d3d9_device_SetRenderTarget
,
3334 d3d9_device_GetRenderTarget
,
3335 d3d9_device_SetDepthStencilSurface
,
3336 d3d9_device_GetDepthStencilSurface
,
3337 d3d9_device_BeginScene
,
3338 d3d9_device_EndScene
,
3340 d3d9_device_SetTransform
,
3341 d3d9_device_GetTransform
,
3342 d3d9_device_MultiplyTransform
,
3343 d3d9_device_SetViewport
,
3344 d3d9_device_GetViewport
,
3345 d3d9_device_SetMaterial
,
3346 d3d9_device_GetMaterial
,
3347 d3d9_device_SetLight
,
3348 d3d9_device_GetLight
,
3349 d3d9_device_LightEnable
,
3350 d3d9_device_GetLightEnable
,
3351 d3d9_device_SetClipPlane
,
3352 d3d9_device_GetClipPlane
,
3353 d3d9_device_SetRenderState
,
3354 d3d9_device_GetRenderState
,
3355 d3d9_device_CreateStateBlock
,
3356 d3d9_device_BeginStateBlock
,
3357 d3d9_device_EndStateBlock
,
3358 d3d9_device_SetClipStatus
,
3359 d3d9_device_GetClipStatus
,
3360 d3d9_device_GetTexture
,
3361 d3d9_device_SetTexture
,
3362 d3d9_device_GetTextureStageState
,
3363 d3d9_device_SetTextureStageState
,
3364 d3d9_device_GetSamplerState
,
3365 d3d9_device_SetSamplerState
,
3366 d3d9_device_ValidateDevice
,
3367 d3d9_device_SetPaletteEntries
,
3368 d3d9_device_GetPaletteEntries
,
3369 d3d9_device_SetCurrentTexturePalette
,
3370 d3d9_device_GetCurrentTexturePalette
,
3371 d3d9_device_SetScissorRect
,
3372 d3d9_device_GetScissorRect
,
3373 d3d9_device_SetSoftwareVertexProcessing
,
3374 d3d9_device_GetSoftwareVertexProcessing
,
3375 d3d9_device_SetNPatchMode
,
3376 d3d9_device_GetNPatchMode
,
3377 d3d9_device_DrawPrimitive
,
3378 d3d9_device_DrawIndexedPrimitive
,
3379 d3d9_device_DrawPrimitiveUP
,
3380 d3d9_device_DrawIndexedPrimitiveUP
,
3381 d3d9_device_ProcessVertices
,
3382 d3d9_device_CreateVertexDeclaration
,
3383 d3d9_device_SetVertexDeclaration
,
3384 d3d9_device_GetVertexDeclaration
,
3387 d3d9_device_CreateVertexShader
,
3388 d3d9_device_SetVertexShader
,
3389 d3d9_device_GetVertexShader
,
3390 d3d9_device_SetVertexShaderConstantF
,
3391 d3d9_device_GetVertexShaderConstantF
,
3392 d3d9_device_SetVertexShaderConstantI
,
3393 d3d9_device_GetVertexShaderConstantI
,
3394 d3d9_device_SetVertexShaderConstantB
,
3395 d3d9_device_GetVertexShaderConstantB
,
3396 d3d9_device_SetStreamSource
,
3397 d3d9_device_GetStreamSource
,
3398 d3d9_device_SetStreamSourceFreq
,
3399 d3d9_device_GetStreamSourceFreq
,
3400 d3d9_device_SetIndices
,
3401 d3d9_device_GetIndices
,
3402 d3d9_device_CreatePixelShader
,
3403 d3d9_device_SetPixelShader
,
3404 d3d9_device_GetPixelShader
,
3405 d3d9_device_SetPixelShaderConstantF
,
3406 d3d9_device_GetPixelShaderConstantF
,
3407 d3d9_device_SetPixelShaderConstantI
,
3408 d3d9_device_GetPixelShaderConstantI
,
3409 d3d9_device_SetPixelShaderConstantB
,
3410 d3d9_device_GetPixelShaderConstantB
,
3411 d3d9_device_DrawRectPatch
,
3412 d3d9_device_DrawTriPatch
,
3413 d3d9_device_DeletePatch
,
3414 d3d9_device_CreateQuery
,
3415 /* IDirect3DDevice9Ex */
3416 d3d9_device_SetConvolutionMonoKernel
,
3417 d3d9_device_ComposeRects
,
3418 d3d9_device_PresentEx
,
3419 d3d9_device_GetGPUThreadPriority
,
3420 d3d9_device_SetGPUThreadPriority
,
3421 d3d9_device_WaitForVBlank
,
3422 d3d9_device_CheckResourceResidency
,
3423 d3d9_device_SetMaximumFrameLatency
,
3424 d3d9_device_GetMaximumFrameLatency
,
3425 d3d9_device_CheckDeviceState
,
3426 d3d9_device_CreateRenderTargetEx
,
3427 d3d9_device_CreateOffscreenPlainSurfaceEx
,
3428 d3d9_device_CreateDepthStencilSurfaceEx
,
3429 d3d9_device_ResetEx
,
3430 d3d9_device_GetDisplayModeEx
,
3433 static inline struct d3d9_device
*device_from_device_parent(struct wined3d_device_parent
*device_parent
)
3435 return CONTAINING_RECORD(device_parent
, struct d3d9_device
, device_parent
);
3438 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
3439 struct wined3d_device
*device
)
3441 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
3444 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
3446 TRACE("device_parent %p.\n", device_parent
);
3449 static void CDECL
device_parent_activate(struct wined3d_device_parent
*device_parent
, BOOL activate
)
3451 struct d3d9_device
*device
= device_from_device_parent(device_parent
);
3453 TRACE("device_parent %p, activate %#x.\n", device_parent
, activate
);
3455 if (!device
->d3d_parent
)
3459 InterlockedCompareExchange(&device
->device_state
, D3D9_DEVICE_STATE_LOST
, D3D9_DEVICE_STATE_OK
);
3460 else if (device
->d3d_parent
->extended
)
3461 InterlockedCompareExchange(&device
->device_state
, D3D9_DEVICE_STATE_OK
, D3D9_DEVICE_STATE_LOST
);
3463 InterlockedCompareExchange(&device
->device_state
, D3D9_DEVICE_STATE_NOT_RESET
, D3D9_DEVICE_STATE_LOST
);
3466 static HRESULT CDECL
device_parent_surface_created(struct wined3d_device_parent
*device_parent
,
3467 void *container_parent
, struct wined3d_surface
*surface
, void **parent
,
3468 const struct wined3d_parent_ops
**parent_ops
)
3470 struct d3d9_surface
*d3d_surface
;
3472 TRACE("device_parent %p, container_parent %p, surface %p, parent %p, parent_ops %p.\n",
3473 device_parent
, container_parent
, surface
, parent
, parent_ops
);
3475 if (!(d3d_surface
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*d3d_surface
))))
3476 return E_OUTOFMEMORY
;
3478 surface_init(d3d_surface
, container_parent
, surface
, parent_ops
);
3479 *parent
= d3d_surface
;
3480 TRACE("Created surface %p.\n", d3d_surface
);
3485 static HRESULT CDECL
device_parent_volume_created(struct wined3d_device_parent
*device_parent
,
3486 void *container_parent
, struct wined3d_volume
*volume
, void **parent
,
3487 const struct wined3d_parent_ops
**parent_ops
)
3489 struct d3d9_volume
*d3d_volume
;
3491 TRACE("device_parent %p, container_parent %p, volume %p, parent %p, parent_ops %p.\n",
3492 device_parent
, container_parent
, volume
, parent
, parent_ops
);
3494 if (!(d3d_volume
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*d3d_volume
))))
3495 return E_OUTOFMEMORY
;
3497 volume_init(d3d_volume
, container_parent
, volume
, parent_ops
);
3498 *parent
= d3d_volume
;
3499 TRACE("Created volume %p.\n", d3d_volume
);
3504 static HRESULT CDECL
device_parent_create_swapchain_surface(struct wined3d_device_parent
*device_parent
,
3505 void *container_parent
, const struct wined3d_resource_desc
*desc
, struct wined3d_surface
**surface
)
3507 struct d3d9_device
*device
= device_from_device_parent(device_parent
);
3508 struct wined3d_resource_desc texture_desc
;
3509 struct d3d9_surface
*d3d_surface
;
3510 struct wined3d_texture
*texture
;
3513 TRACE("device_parent %p, container_parent %p, desc %p, surface %p.\n",
3514 device_parent
, container_parent
, desc
, surface
);
3516 if (container_parent
== device_parent
)
3517 container_parent
= &device
->IDirect3DDevice9Ex_iface
;
3519 texture_desc
= *desc
;
3520 texture_desc
.resource_type
= WINED3D_RTYPE_TEXTURE
;
3521 if (FAILED(hr
= wined3d_texture_create(device
->wined3d_device
, &texture_desc
, 1,
3522 WINED3D_SURFACE_MAPPABLE
, container_parent
, &d3d9_null_wined3d_parent_ops
, &texture
)))
3524 WARN("Failed to create texture, hr %#x.\n", hr
);
3528 *surface
= wined3d_surface_from_resource(wined3d_texture_get_sub_resource(texture
, 0));
3529 wined3d_surface_incref(*surface
);
3530 wined3d_texture_decref(texture
);
3532 d3d_surface
= wined3d_surface_get_parent(*surface
);
3533 d3d_surface
->parent_device
= &device
->IDirect3DDevice9Ex_iface
;
3538 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
3539 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain
**swapchain
)
3541 struct d3d9_device
*device
= device_from_device_parent(device_parent
);
3542 struct d3d9_swapchain
*d3d_swapchain
;
3545 TRACE("device_parent %p, desc %p, swapchain %p\n", device_parent
, desc
, swapchain
);
3547 hr
= d3d9_swapchain_create(device
, desc
, &d3d_swapchain
);
3550 WARN("Failed to create swapchain, hr %#x.\n", hr
);
3555 *swapchain
= d3d_swapchain
->wined3d_swapchain
;
3556 wined3d_swapchain_incref(*swapchain
);
3557 IDirect3DSwapChain9Ex_Release(&d3d_swapchain
->IDirect3DSwapChain9Ex_iface
);
3562 static const struct wined3d_device_parent_ops d3d9_wined3d_device_parent_ops
=
3564 device_parent_wined3d_device_created
,
3565 device_parent_mode_changed
,
3566 device_parent_activate
,
3567 device_parent_surface_created
,
3568 device_parent_volume_created
,
3569 device_parent_create_swapchain_surface
,
3570 device_parent_create_swapchain
,
3573 static void setup_fpu(void)
3575 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3577 __asm__
volatile ("fnstcw %0" : "=m" (cw
));
3578 cw
= (cw
& ~0xf3f) | 0x3f;
3579 __asm__
volatile ("fldcw %0" : : "m" (cw
));
3580 #elif defined(__i386__) && defined(_MSC_VER)
3583 cw
= (cw
& ~0xf3f) | 0x3f;
3586 FIXME("FPU setup not implemented for this platform.\n");
3590 HRESULT
device_init(struct d3d9_device
*device
, struct d3d9
*parent
, struct wined3d
*wined3d
,
3591 UINT adapter
, D3DDEVTYPE device_type
, HWND focus_window
, DWORD flags
,
3592 D3DPRESENT_PARAMETERS
*parameters
, D3DDISPLAYMODEEX
*mode
)
3594 struct wined3d_swapchain_desc
*swapchain_desc
;
3599 FIXME("Ignoring display mode.\n");
3601 device
->IDirect3DDevice9Ex_iface
.lpVtbl
= &d3d9_device_vtbl
;
3602 device
->device_parent
.ops
= &d3d9_wined3d_device_parent_ops
;
3603 device
->refcount
= 1;
3605 if (!(flags
& D3DCREATE_FPU_PRESERVE
)) setup_fpu();
3607 wined3d_mutex_lock();
3608 hr
= wined3d_device_create(wined3d
, adapter
, device_type
, focus_window
, flags
, 4,
3609 &device
->device_parent
, &device
->wined3d_device
);
3612 WARN("Failed to create wined3d device, hr %#x.\n", hr
);
3613 wined3d_mutex_unlock();
3617 if (flags
& D3DCREATE_ADAPTERGROUP_DEVICE
)
3621 wined3d_get_device_caps(wined3d
, adapter
, device_type
, &caps
);
3622 count
= caps
.NumberOfAdaptersInGroup
;
3625 if (flags
& D3DCREATE_MULTITHREADED
)
3626 wined3d_device_set_multithreaded(device
->wined3d_device
);
3628 if (!parameters
->Windowed
)
3631 focus_window
= parameters
->hDeviceWindow
;
3632 if (FAILED(hr
= wined3d_device_acquire_focus_window(device
->wined3d_device
, focus_window
)))
3634 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
3635 wined3d_device_decref(device
->wined3d_device
);
3636 wined3d_mutex_unlock();
3640 for (i
= 0; i
< count
; ++i
)
3642 HWND device_window
= parameters
[i
].hDeviceWindow
;
3644 if (!device_window
) device_window
= focus_window
;
3645 wined3d_device_setup_fullscreen_window(device
->wined3d_device
, device_window
,
3646 parameters
[i
].BackBufferWidth
,
3647 parameters
[i
].BackBufferHeight
);
3651 swapchain_desc
= HeapAlloc(GetProcessHeap(), 0, sizeof(*swapchain_desc
) * count
);
3652 if (!swapchain_desc
)
3654 ERR("Failed to allocate wined3d parameters.\n");
3655 wined3d_device_decref(device
->wined3d_device
);
3656 wined3d_mutex_unlock();
3657 return E_OUTOFMEMORY
;
3660 for (i
= 0; i
< count
; ++i
)
3662 wined3d_swapchain_desc_from_present_parameters(&swapchain_desc
[i
], ¶meters
[i
]);
3665 hr
= wined3d_device_init_3d(device
->wined3d_device
, swapchain_desc
);
3668 WARN("Failed to initialize 3D, hr %#x.\n", hr
);
3669 wined3d_device_release_focus_window(device
->wined3d_device
);
3670 HeapFree(GetProcessHeap(), 0, swapchain_desc
);
3671 wined3d_device_decref(device
->wined3d_device
);
3672 wined3d_mutex_unlock();
3676 wined3d_mutex_unlock();
3678 for (i
= 0; i
< count
; ++i
)
3680 present_parameters_from_wined3d_swapchain_desc(¶meters
[i
], &swapchain_desc
[i
]);
3682 HeapFree(GetProcessHeap(), 0, swapchain_desc
);
3684 /* Initialize the converted declaration array. This creates a valid pointer
3685 * and when adding decls HeapReAlloc() can be used without further checking. */
3686 device
->fvf_decls
= HeapAlloc(GetProcessHeap(), 0, 0);
3687 if (!device
->fvf_decls
)
3689 ERR("Failed to allocate FVF vertex declaration map memory.\n");
3690 wined3d_mutex_lock();
3691 wined3d_device_uninit_3d(device
->wined3d_device
);
3692 wined3d_device_release_focus_window(device
->wined3d_device
);
3693 wined3d_device_decref(device
->wined3d_device
);
3694 wined3d_mutex_unlock();
3695 return E_OUTOFMEMORY
;
3698 IDirect3D9Ex_AddRef(&parent
->IDirect3D9Ex_iface
);
3699 device
->d3d_parent
= parent
;