2 * IDirect3DDevice9 implementation
4 * Copyright 2002-2005 Jason Edmeades
5 * Copyright 2002-2005 Raphael Junqueira
6 * Copyright 2005 Oliver Stieber
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "d3d9_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d9
);
28 static void STDMETHODCALLTYPE
d3d9_null_wined3d_object_destroyed(void *parent
) {}
30 const struct wined3d_parent_ops d3d9_null_wined3d_parent_ops
=
32 d3d9_null_wined3d_object_destroyed
,
35 static void wined3d_color_from_d3dcolor(struct wined3d_color
*wined3d_colour
, D3DCOLOR d3d_colour
)
37 wined3d_colour
->r
= ((d3d_colour
>> 16) & 0xff) / 255.0f
;
38 wined3d_colour
->g
= ((d3d_colour
>> 8) & 0xff) / 255.0f
;
39 wined3d_colour
->b
= (d3d_colour
& 0xff) / 255.0f
;
40 wined3d_colour
->a
= ((d3d_colour
>> 24) & 0xff) / 255.0f
;
43 D3DFORMAT
d3dformat_from_wined3dformat(enum wined3d_format_id format
)
45 BYTE
*c
= (BYTE
*)&format
;
47 /* Don't translate FOURCC formats */
48 if (isprint(c
[0]) && isprint(c
[1]) && isprint(c
[2]) && isprint(c
[3])) return format
;
52 case WINED3DFMT_UNKNOWN
: return D3DFMT_UNKNOWN
;
53 case WINED3DFMT_B8G8R8_UNORM
: return D3DFMT_R8G8B8
;
54 case WINED3DFMT_B8G8R8A8_UNORM
: return D3DFMT_A8R8G8B8
;
55 case WINED3DFMT_B8G8R8X8_UNORM
: return D3DFMT_X8R8G8B8
;
56 case WINED3DFMT_B5G6R5_UNORM
: return D3DFMT_R5G6B5
;
57 case WINED3DFMT_B5G5R5X1_UNORM
: return D3DFMT_X1R5G5B5
;
58 case WINED3DFMT_B5G5R5A1_UNORM
: return D3DFMT_A1R5G5B5
;
59 case WINED3DFMT_B4G4R4A4_UNORM
: return D3DFMT_A4R4G4B4
;
60 case WINED3DFMT_B2G3R3_UNORM
: return D3DFMT_R3G3B2
;
61 case WINED3DFMT_A8_UNORM
: return D3DFMT_A8
;
62 case WINED3DFMT_B2G3R3A8_UNORM
: return D3DFMT_A8R3G3B2
;
63 case WINED3DFMT_B4G4R4X4_UNORM
: return D3DFMT_X4R4G4B4
;
64 case WINED3DFMT_R10G10B10A2_UNORM
: return D3DFMT_A2B10G10R10
;
65 case WINED3DFMT_R8G8B8A8_UNORM
: return D3DFMT_A8B8G8R8
;
66 case WINED3DFMT_R8G8B8X8_UNORM
: return D3DFMT_X8B8G8R8
;
67 case WINED3DFMT_R16G16_UNORM
: return D3DFMT_G16R16
;
68 case WINED3DFMT_B10G10R10A2_UNORM
: return D3DFMT_A2R10G10B10
;
69 case WINED3DFMT_R16G16B16A16_UNORM
: return D3DFMT_A16B16G16R16
;
70 case WINED3DFMT_P8_UINT_A8_UNORM
: return D3DFMT_A8P8
;
71 case WINED3DFMT_P8_UINT
: return D3DFMT_P8
;
72 case WINED3DFMT_L8_UNORM
: return D3DFMT_L8
;
73 case WINED3DFMT_L8A8_UNORM
: return D3DFMT_A8L8
;
74 case WINED3DFMT_L4A4_UNORM
: return D3DFMT_A4L4
;
75 case WINED3DFMT_R8G8_SNORM
: return D3DFMT_V8U8
;
76 case WINED3DFMT_R5G5_SNORM_L6_UNORM
: return D3DFMT_L6V5U5
;
77 case WINED3DFMT_R8G8_SNORM_L8X8_UNORM
: return D3DFMT_X8L8V8U8
;
78 case WINED3DFMT_R8G8B8A8_SNORM
: return D3DFMT_Q8W8V8U8
;
79 case WINED3DFMT_R16G16_SNORM
: return D3DFMT_V16U16
;
80 case WINED3DFMT_R10G10B10_SNORM_A2_UNORM
: return D3DFMT_A2W10V10U10
;
81 case WINED3DFMT_D16_LOCKABLE
: return D3DFMT_D16_LOCKABLE
;
82 case WINED3DFMT_D32_UNORM
: return D3DFMT_D32
;
83 case WINED3DFMT_S1_UINT_D15_UNORM
: return D3DFMT_D15S1
;
84 case WINED3DFMT_D24_UNORM_S8_UINT
: return D3DFMT_D24S8
;
85 case WINED3DFMT_X8D24_UNORM
: return D3DFMT_D24X8
;
86 case WINED3DFMT_S4X4_UINT_D24_UNORM
: return D3DFMT_D24X4S4
;
87 case WINED3DFMT_D16_UNORM
: return D3DFMT_D16
;
88 case WINED3DFMT_L16_UNORM
: return D3DFMT_L16
;
89 case WINED3DFMT_D32_FLOAT
: return D3DFMT_D32F_LOCKABLE
;
90 case WINED3DFMT_S8_UINT_D24_FLOAT
: return D3DFMT_D24FS8
;
91 case WINED3DFMT_R16_UINT
: return D3DFMT_INDEX16
;
92 case WINED3DFMT_R32_UINT
: return D3DFMT_INDEX32
;
93 case WINED3DFMT_R16G16B16A16_SNORM
: return D3DFMT_Q16W16V16U16
;
94 case WINED3DFMT_R16_FLOAT
: return D3DFMT_R16F
;
95 case WINED3DFMT_R16G16_FLOAT
: return D3DFMT_G16R16F
;
96 case WINED3DFMT_R16G16B16A16_FLOAT
: return D3DFMT_A16B16G16R16F
;
97 case WINED3DFMT_R32_FLOAT
: return D3DFMT_R32F
;
98 case WINED3DFMT_R32G32_FLOAT
: return D3DFMT_G32R32F
;
99 case WINED3DFMT_R32G32B32A32_FLOAT
: return D3DFMT_A32B32G32R32F
;
100 case WINED3DFMT_R8G8_SNORM_Cx
: return D3DFMT_CxV8U8
;
102 FIXME("Unhandled wined3d format %#x.\n", format
);
103 return D3DFMT_UNKNOWN
;
107 enum wined3d_format_id
wined3dformat_from_d3dformat(D3DFORMAT format
)
109 BYTE
*c
= (BYTE
*)&format
;
111 /* Don't translate FOURCC formats */
112 if (isprint(c
[0]) && isprint(c
[1]) && isprint(c
[2]) && isprint(c
[3])) return format
;
116 case D3DFMT_UNKNOWN
: return WINED3DFMT_UNKNOWN
;
117 case D3DFMT_R8G8B8
: return WINED3DFMT_B8G8R8_UNORM
;
118 case D3DFMT_A8R8G8B8
: return WINED3DFMT_B8G8R8A8_UNORM
;
119 case D3DFMT_X8R8G8B8
: return WINED3DFMT_B8G8R8X8_UNORM
;
120 case D3DFMT_R5G6B5
: return WINED3DFMT_B5G6R5_UNORM
;
121 case D3DFMT_X1R5G5B5
: return WINED3DFMT_B5G5R5X1_UNORM
;
122 case D3DFMT_A1R5G5B5
: return WINED3DFMT_B5G5R5A1_UNORM
;
123 case D3DFMT_A4R4G4B4
: return WINED3DFMT_B4G4R4A4_UNORM
;
124 case D3DFMT_R3G3B2
: return WINED3DFMT_B2G3R3_UNORM
;
125 case D3DFMT_A8
: return WINED3DFMT_A8_UNORM
;
126 case D3DFMT_A8R3G3B2
: return WINED3DFMT_B2G3R3A8_UNORM
;
127 case D3DFMT_X4R4G4B4
: return WINED3DFMT_B4G4R4X4_UNORM
;
128 case D3DFMT_A2B10G10R10
: return WINED3DFMT_R10G10B10A2_UNORM
;
129 case D3DFMT_A8B8G8R8
: return WINED3DFMT_R8G8B8A8_UNORM
;
130 case D3DFMT_X8B8G8R8
: return WINED3DFMT_R8G8B8X8_UNORM
;
131 case D3DFMT_G16R16
: return WINED3DFMT_R16G16_UNORM
;
132 case D3DFMT_A2R10G10B10
: return WINED3DFMT_B10G10R10A2_UNORM
;
133 case D3DFMT_A16B16G16R16
: return WINED3DFMT_R16G16B16A16_UNORM
;
134 case D3DFMT_A8P8
: return WINED3DFMT_P8_UINT_A8_UNORM
;
135 case D3DFMT_P8
: return WINED3DFMT_P8_UINT
;
136 case D3DFMT_L8
: return WINED3DFMT_L8_UNORM
;
137 case D3DFMT_A8L8
: return WINED3DFMT_L8A8_UNORM
;
138 case D3DFMT_A4L4
: return WINED3DFMT_L4A4_UNORM
;
139 case D3DFMT_V8U8
: return WINED3DFMT_R8G8_SNORM
;
140 case D3DFMT_L6V5U5
: return WINED3DFMT_R5G5_SNORM_L6_UNORM
;
141 case D3DFMT_X8L8V8U8
: return WINED3DFMT_R8G8_SNORM_L8X8_UNORM
;
142 case D3DFMT_Q8W8V8U8
: return WINED3DFMT_R8G8B8A8_SNORM
;
143 case D3DFMT_V16U16
: return WINED3DFMT_R16G16_SNORM
;
144 case D3DFMT_A2W10V10U10
: return WINED3DFMT_R10G10B10_SNORM_A2_UNORM
;
145 case D3DFMT_D16_LOCKABLE
: return WINED3DFMT_D16_LOCKABLE
;
146 case D3DFMT_D32
: return WINED3DFMT_D32_UNORM
;
147 case D3DFMT_D15S1
: return WINED3DFMT_S1_UINT_D15_UNORM
;
148 case D3DFMT_D24S8
: return WINED3DFMT_D24_UNORM_S8_UINT
;
149 case D3DFMT_D24X8
: return WINED3DFMT_X8D24_UNORM
;
150 case D3DFMT_D24X4S4
: return WINED3DFMT_S4X4_UINT_D24_UNORM
;
151 case D3DFMT_D16
: return WINED3DFMT_D16_UNORM
;
152 case D3DFMT_L16
: return WINED3DFMT_L16_UNORM
;
153 case D3DFMT_D32F_LOCKABLE
: return WINED3DFMT_D32_FLOAT
;
154 case D3DFMT_D24FS8
: return WINED3DFMT_S8_UINT_D24_FLOAT
;
155 case D3DFMT_INDEX16
: return WINED3DFMT_R16_UINT
;
156 case D3DFMT_INDEX32
: return WINED3DFMT_R32_UINT
;
157 case D3DFMT_Q16W16V16U16
: return WINED3DFMT_R16G16B16A16_SNORM
;
158 case D3DFMT_R16F
: return WINED3DFMT_R16_FLOAT
;
159 case D3DFMT_G16R16F
: return WINED3DFMT_R16G16_FLOAT
;
160 case D3DFMT_A16B16G16R16F
: return WINED3DFMT_R16G16B16A16_FLOAT
;
161 case D3DFMT_R32F
: return WINED3DFMT_R32_FLOAT
;
162 case D3DFMT_G32R32F
: return WINED3DFMT_R32G32_FLOAT
;
163 case D3DFMT_A32B32G32R32F
: return WINED3DFMT_R32G32B32A32_FLOAT
;
164 case D3DFMT_CxV8U8
: return WINED3DFMT_R8G8_SNORM_Cx
;
166 FIXME("Unhandled D3DFORMAT %#x.\n", format
);
167 return WINED3DFMT_UNKNOWN
;
171 unsigned int wined3dmapflags_from_d3dmapflags(unsigned int flags
)
173 static const unsigned int handled
= D3DLOCK_NOSYSLOCK
174 | D3DLOCK_NOOVERWRITE
177 | D3DLOCK_NO_DIRTY_UPDATE
;
178 unsigned int wined3d_flags
;
180 wined3d_flags
= flags
& handled
;
181 if (!(flags
& (D3DLOCK_NOOVERWRITE
| D3DLOCK_DISCARD
)))
182 wined3d_flags
|= WINED3D_MAP_READ
;
183 if (!(flags
& D3DLOCK_READONLY
))
184 wined3d_flags
|= WINED3D_MAP_WRITE
;
185 if (!(wined3d_flags
& (WINED3D_MAP_READ
| WINED3D_MAP_WRITE
)))
186 wined3d_flags
|= WINED3D_MAP_READ
| WINED3D_MAP_WRITE
;
187 flags
&= ~(handled
| D3DLOCK_READONLY
);
190 FIXME("Unhandled flags %#x.\n", flags
);
192 return wined3d_flags
;
195 static UINT
vertex_count_from_primitive_count(D3DPRIMITIVETYPE primitive_type
, UINT primitive_count
)
197 switch (primitive_type
)
199 case D3DPT_POINTLIST
:
200 return primitive_count
;
203 return primitive_count
* 2;
205 case D3DPT_LINESTRIP
:
206 return primitive_count
+ 1;
208 case D3DPT_TRIANGLELIST
:
209 return primitive_count
* 3;
211 case D3DPT_TRIANGLESTRIP
:
212 case D3DPT_TRIANGLEFAN
:
213 return primitive_count
+ 2;
216 FIXME("Unhandled primitive type %#x.\n", primitive_type
);
221 static D3DSWAPEFFECT
d3dswapeffect_from_wined3dswapeffect(enum wined3d_swap_effect effect
)
225 case WINED3D_SWAP_EFFECT_DISCARD
:
226 return D3DSWAPEFFECT_DISCARD
;
227 case WINED3D_SWAP_EFFECT_SEQUENTIAL
:
228 return D3DSWAPEFFECT_FLIP
;
229 case WINED3D_SWAP_EFFECT_COPY
:
230 return D3DSWAPEFFECT_COPY
;
231 case WINED3D_SWAP_EFFECT_OVERLAY
:
232 return D3DSWAPEFFECT_OVERLAY
;
233 case WINED3D_SWAP_EFFECT_FLIP_SEQUENTIAL
:
234 return D3DSWAPEFFECT_FLIPEX
;
236 FIXME("Unhandled swap effect %#x.\n", effect
);
237 return D3DSWAPEFFECT_FLIP
;
241 void present_parameters_from_wined3d_swapchain_desc(D3DPRESENT_PARAMETERS
*present_parameters
,
242 const struct wined3d_swapchain_desc
*swapchain_desc
, DWORD presentation_interval
)
244 present_parameters
->BackBufferWidth
= swapchain_desc
->backbuffer_width
;
245 present_parameters
->BackBufferHeight
= swapchain_desc
->backbuffer_height
;
246 present_parameters
->BackBufferFormat
= d3dformat_from_wined3dformat(swapchain_desc
->backbuffer_format
);
247 present_parameters
->BackBufferCount
= swapchain_desc
->backbuffer_count
;
248 present_parameters
->MultiSampleType
= swapchain_desc
->multisample_type
;
249 present_parameters
->MultiSampleQuality
= swapchain_desc
->multisample_quality
;
250 present_parameters
->SwapEffect
= d3dswapeffect_from_wined3dswapeffect(swapchain_desc
->swap_effect
);
251 present_parameters
->hDeviceWindow
= swapchain_desc
->device_window
;
252 present_parameters
->Windowed
= swapchain_desc
->windowed
;
253 present_parameters
->EnableAutoDepthStencil
= swapchain_desc
->enable_auto_depth_stencil
;
254 present_parameters
->AutoDepthStencilFormat
255 = d3dformat_from_wined3dformat(swapchain_desc
->auto_depth_stencil_format
);
256 present_parameters
->Flags
= swapchain_desc
->flags
& D3DPRESENTFLAGS_MASK
;
257 present_parameters
->FullScreen_RefreshRateInHz
= swapchain_desc
->refresh_rate
;
258 present_parameters
->PresentationInterval
= presentation_interval
;
261 static enum wined3d_swap_effect
wined3dswapeffect_from_d3dswapeffect(D3DSWAPEFFECT effect
)
265 case D3DSWAPEFFECT_DISCARD
:
266 return WINED3D_SWAP_EFFECT_DISCARD
;
267 case D3DSWAPEFFECT_FLIP
:
268 return WINED3D_SWAP_EFFECT_SEQUENTIAL
;
269 case D3DSWAPEFFECT_COPY
:
270 return WINED3D_SWAP_EFFECT_COPY
;
271 case D3DSWAPEFFECT_OVERLAY
:
272 return WINED3D_SWAP_EFFECT_OVERLAY
;
273 case D3DSWAPEFFECT_FLIPEX
:
274 return WINED3D_SWAP_EFFECT_FLIP_SEQUENTIAL
;
276 FIXME("Unhandled swap effect %#x.\n", effect
);
277 return WINED3D_SWAP_EFFECT_SEQUENTIAL
;
281 static enum wined3d_swap_interval
wined3dswapinterval_from_d3d(DWORD interval
)
285 case D3DPRESENT_INTERVAL_IMMEDIATE
:
286 return WINED3D_SWAP_INTERVAL_IMMEDIATE
;
287 case D3DPRESENT_INTERVAL_ONE
:
288 return WINED3D_SWAP_INTERVAL_ONE
;
289 case D3DPRESENT_INTERVAL_TWO
:
290 return WINED3D_SWAP_INTERVAL_TWO
;
291 case D3DPRESENT_INTERVAL_THREE
:
292 return WINED3D_SWAP_INTERVAL_THREE
;
293 case D3DPRESENT_INTERVAL_FOUR
:
294 return WINED3D_SWAP_INTERVAL_FOUR
;
296 FIXME("Unhandled presentation interval %#x.\n", interval
);
297 case D3DPRESENT_INTERVAL_DEFAULT
:
298 return WINED3D_SWAP_INTERVAL_DEFAULT
;
302 static BOOL
wined3d_swapchain_desc_from_present_parameters(struct wined3d_swapchain_desc
*swapchain_desc
,
303 const D3DPRESENT_PARAMETERS
*present_parameters
, BOOL extended
)
305 D3DSWAPEFFECT highest_swapeffect
= extended
? D3DSWAPEFFECT_FLIPEX
: D3DSWAPEFFECT_COPY
;
306 UINT highest_bb_count
= extended
? 30 : 3;
308 if (!present_parameters
->SwapEffect
|| present_parameters
->SwapEffect
> highest_swapeffect
)
310 WARN("Invalid swap effect %u passed.\n", present_parameters
->SwapEffect
);
313 if (present_parameters
->BackBufferCount
> highest_bb_count
314 || (present_parameters
->SwapEffect
== D3DSWAPEFFECT_COPY
315 && present_parameters
->BackBufferCount
> 1))
317 WARN("Invalid backbuffer count %u.\n", present_parameters
->BackBufferCount
);
320 switch (present_parameters
->PresentationInterval
)
322 case D3DPRESENT_INTERVAL_DEFAULT
:
323 case D3DPRESENT_INTERVAL_ONE
:
324 case D3DPRESENT_INTERVAL_TWO
:
325 case D3DPRESENT_INTERVAL_THREE
:
326 case D3DPRESENT_INTERVAL_FOUR
:
327 case D3DPRESENT_INTERVAL_IMMEDIATE
:
330 WARN("Invalid presentation interval %#x.\n", present_parameters
->PresentationInterval
);
334 swapchain_desc
->backbuffer_width
= present_parameters
->BackBufferWidth
;
335 swapchain_desc
->backbuffer_height
= present_parameters
->BackBufferHeight
;
336 swapchain_desc
->backbuffer_format
= wined3dformat_from_d3dformat(present_parameters
->BackBufferFormat
);
337 swapchain_desc
->backbuffer_count
= max(1, present_parameters
->BackBufferCount
);
338 swapchain_desc
->backbuffer_bind_flags
= WINED3D_BIND_RENDER_TARGET
;
339 swapchain_desc
->multisample_type
= present_parameters
->MultiSampleType
;
340 swapchain_desc
->multisample_quality
= present_parameters
->MultiSampleQuality
;
341 swapchain_desc
->swap_effect
= wined3dswapeffect_from_d3dswapeffect(present_parameters
->SwapEffect
);
342 swapchain_desc
->device_window
= present_parameters
->hDeviceWindow
;
343 swapchain_desc
->windowed
= present_parameters
->Windowed
;
344 swapchain_desc
->enable_auto_depth_stencil
= present_parameters
->EnableAutoDepthStencil
;
345 swapchain_desc
->auto_depth_stencil_format
346 = wined3dformat_from_d3dformat(present_parameters
->AutoDepthStencilFormat
);
347 swapchain_desc
->flags
348 = (present_parameters
->Flags
& D3DPRESENTFLAGS_MASK
) | WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH
;
349 if ((present_parameters
->Flags
& D3DPRESENTFLAG_LOCKABLE_BACKBUFFER
)
350 && (is_gdi_compat_wined3dformat(swapchain_desc
->backbuffer_format
)
351 /* WINED3DFMT_UNKNOWN creates the swapchain with the current
352 * display format, which is always GDI-compatible. */
353 || swapchain_desc
->backbuffer_format
== WINED3DFMT_UNKNOWN
))
354 swapchain_desc
->flags
|= WINED3D_SWAPCHAIN_GDI_COMPATIBLE
;
355 swapchain_desc
->refresh_rate
= present_parameters
->FullScreen_RefreshRateInHz
;
356 swapchain_desc
->auto_restore_display_mode
= TRUE
;
358 if (present_parameters
->Flags
& ~D3DPRESENTFLAGS_MASK
)
359 FIXME("Unhandled flags %#x.\n", present_parameters
->Flags
& ~D3DPRESENTFLAGS_MASK
);
364 void d3dcaps_from_wined3dcaps(D3DCAPS9
*caps
, const struct wined3d_caps
*wined3d_caps
)
366 static const DWORD ps_minor_version
[] = {0, 4, 0, 0};
367 static const DWORD vs_minor_version
[] = {0, 1, 0, 0};
368 static const DWORD texture_filter_caps
=
369 D3DPTFILTERCAPS_MINFPOINT
| D3DPTFILTERCAPS_MINFLINEAR
| D3DPTFILTERCAPS_MINFANISOTROPIC
|
370 D3DPTFILTERCAPS_MINFPYRAMIDALQUAD
| D3DPTFILTERCAPS_MINFGAUSSIANQUAD
|
371 D3DPTFILTERCAPS_MIPFPOINT
| D3DPTFILTERCAPS_MIPFLINEAR
| D3DPTFILTERCAPS_MAGFPOINT
|
372 D3DPTFILTERCAPS_MAGFLINEAR
|D3DPTFILTERCAPS_MAGFANISOTROPIC
|D3DPTFILTERCAPS_MAGFPYRAMIDALQUAD
|
373 D3DPTFILTERCAPS_MAGFGAUSSIANQUAD
;
375 caps
->DeviceType
= (D3DDEVTYPE
)wined3d_caps
->DeviceType
;
376 caps
->AdapterOrdinal
= wined3d_caps
->AdapterOrdinal
;
377 caps
->Caps
= wined3d_caps
->Caps
;
378 caps
->Caps2
= wined3d_caps
->Caps2
;
379 caps
->Caps3
= wined3d_caps
->Caps3
;
380 caps
->PresentationIntervals
= D3DPRESENT_INTERVAL_IMMEDIATE
| D3DPRESENT_INTERVAL_ONE
;
381 caps
->CursorCaps
= wined3d_caps
->CursorCaps
;
382 caps
->DevCaps
= wined3d_caps
->DevCaps
;
383 caps
->PrimitiveMiscCaps
= wined3d_caps
->PrimitiveMiscCaps
;
384 caps
->RasterCaps
= wined3d_caps
->RasterCaps
;
385 caps
->ZCmpCaps
= wined3d_caps
->ZCmpCaps
;
386 caps
->SrcBlendCaps
= wined3d_caps
->SrcBlendCaps
;
387 caps
->DestBlendCaps
= wined3d_caps
->DestBlendCaps
;
388 caps
->AlphaCmpCaps
= wined3d_caps
->AlphaCmpCaps
;
389 caps
->ShadeCaps
= wined3d_caps
->ShadeCaps
;
390 caps
->TextureCaps
= wined3d_caps
->TextureCaps
;
391 caps
->TextureFilterCaps
= wined3d_caps
->TextureFilterCaps
;
392 caps
->CubeTextureFilterCaps
= wined3d_caps
->CubeTextureFilterCaps
;
393 caps
->VolumeTextureFilterCaps
= wined3d_caps
->VolumeTextureFilterCaps
;
394 caps
->TextureAddressCaps
= wined3d_caps
->TextureAddressCaps
;
395 caps
->VolumeTextureAddressCaps
= wined3d_caps
->VolumeTextureAddressCaps
;
396 caps
->LineCaps
= wined3d_caps
->LineCaps
;
397 caps
->MaxTextureWidth
= wined3d_caps
->MaxTextureWidth
;
398 caps
->MaxTextureHeight
= wined3d_caps
->MaxTextureHeight
;
399 caps
->MaxVolumeExtent
= wined3d_caps
->MaxVolumeExtent
;
400 caps
->MaxTextureRepeat
= wined3d_caps
->MaxTextureRepeat
;
401 caps
->MaxTextureAspectRatio
= wined3d_caps
->MaxTextureAspectRatio
;
402 caps
->MaxAnisotropy
= wined3d_caps
->MaxAnisotropy
;
403 caps
->MaxVertexW
= wined3d_caps
->MaxVertexW
;
404 caps
->GuardBandLeft
= wined3d_caps
->GuardBandLeft
;
405 caps
->GuardBandTop
= wined3d_caps
->GuardBandTop
;
406 caps
->GuardBandRight
= wined3d_caps
->GuardBandRight
;
407 caps
->GuardBandBottom
= wined3d_caps
->GuardBandBottom
;
408 caps
->ExtentsAdjust
= wined3d_caps
->ExtentsAdjust
;
409 caps
->StencilCaps
= wined3d_caps
->StencilCaps
;
410 caps
->FVFCaps
= wined3d_caps
->FVFCaps
;
411 caps
->TextureOpCaps
= wined3d_caps
->TextureOpCaps
;
412 caps
->MaxTextureBlendStages
= wined3d_caps
->MaxTextureBlendStages
;
413 caps
->MaxSimultaneousTextures
= wined3d_caps
->MaxSimultaneousTextures
;
414 caps
->VertexProcessingCaps
= wined3d_caps
->VertexProcessingCaps
;
415 caps
->MaxActiveLights
= wined3d_caps
->MaxActiveLights
;
416 caps
->MaxUserClipPlanes
= wined3d_caps
->MaxUserClipPlanes
;
417 caps
->MaxVertexBlendMatrices
= wined3d_caps
->MaxVertexBlendMatrices
;
418 caps
->MaxVertexBlendMatrixIndex
= wined3d_caps
->MaxVertexBlendMatrixIndex
;
419 caps
->MaxPointSize
= wined3d_caps
->MaxPointSize
;
420 caps
->MaxPrimitiveCount
= wined3d_caps
->MaxPrimitiveCount
;
421 caps
->MaxVertexIndex
= wined3d_caps
->MaxVertexIndex
;
422 caps
->MaxStreams
= wined3d_caps
->MaxStreams
;
423 caps
->MaxStreamStride
= wined3d_caps
->MaxStreamStride
;
424 caps
->VertexShaderVersion
= wined3d_caps
->VertexShaderVersion
;
425 caps
->MaxVertexShaderConst
= wined3d_caps
->MaxVertexShaderConst
;
426 caps
->PixelShaderVersion
= wined3d_caps
->PixelShaderVersion
;
427 caps
->PixelShader1xMaxValue
= wined3d_caps
->PixelShader1xMaxValue
;
428 caps
->DevCaps2
= wined3d_caps
->DevCaps2
;
429 caps
->MaxNpatchTessellationLevel
= wined3d_caps
->MaxNpatchTessellationLevel
;
430 caps
->MasterAdapterOrdinal
= wined3d_caps
->MasterAdapterOrdinal
;
431 caps
->AdapterOrdinalInGroup
= wined3d_caps
->AdapterOrdinalInGroup
;
432 caps
->NumberOfAdaptersInGroup
= wined3d_caps
->NumberOfAdaptersInGroup
;
433 caps
->DeclTypes
= wined3d_caps
->DeclTypes
;
434 caps
->NumSimultaneousRTs
= wined3d_caps
->NumSimultaneousRTs
;
435 caps
->StretchRectFilterCaps
= wined3d_caps
->StretchRectFilterCaps
;
436 caps
->VS20Caps
.Caps
= wined3d_caps
->VS20Caps
.caps
;
437 caps
->VS20Caps
.DynamicFlowControlDepth
= wined3d_caps
->VS20Caps
.dynamic_flow_control_depth
;
438 caps
->VS20Caps
.NumTemps
= wined3d_caps
->VS20Caps
.temp_count
;
439 caps
->VS20Caps
.StaticFlowControlDepth
= wined3d_caps
->VS20Caps
.static_flow_control_depth
;
440 caps
->PS20Caps
.Caps
= wined3d_caps
->PS20Caps
.caps
;
441 caps
->PS20Caps
.DynamicFlowControlDepth
= wined3d_caps
->PS20Caps
.dynamic_flow_control_depth
;
442 caps
->PS20Caps
.NumTemps
= wined3d_caps
->PS20Caps
.temp_count
;
443 caps
->PS20Caps
.StaticFlowControlDepth
= wined3d_caps
->PS20Caps
.static_flow_control_depth
;
444 caps
->PS20Caps
.NumInstructionSlots
= wined3d_caps
->PS20Caps
.instruction_slot_count
;
445 caps
->VertexTextureFilterCaps
= wined3d_caps
->VertexTextureFilterCaps
;
446 caps
->MaxVShaderInstructionsExecuted
= wined3d_caps
->MaxVShaderInstructionsExecuted
;
447 caps
->MaxPShaderInstructionsExecuted
= wined3d_caps
->MaxPShaderInstructionsExecuted
;
448 caps
->MaxVertexShader30InstructionSlots
= wined3d_caps
->MaxVertexShader30InstructionSlots
;
449 caps
->MaxPixelShader30InstructionSlots
= wined3d_caps
->MaxPixelShader30InstructionSlots
;
451 /* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps. */
452 caps
->DevCaps2
|= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES
;
454 /* Filter wined3d caps. */
455 caps
->TextureFilterCaps
&= texture_filter_caps
;
456 caps
->CubeTextureFilterCaps
&= texture_filter_caps
;
457 caps
->VolumeTextureFilterCaps
&= texture_filter_caps
;
460 D3DDEVCAPS_EXECUTESYSTEMMEMORY
| D3DDEVCAPS_EXECUTEVIDEOMEMORY
| D3DDEVCAPS_TLVERTEXSYSTEMMEMORY
|
461 D3DDEVCAPS_TLVERTEXVIDEOMEMORY
| D3DDEVCAPS_TEXTURESYSTEMMEMORY
| D3DDEVCAPS_TEXTUREVIDEOMEMORY
|
462 D3DDEVCAPS_DRAWPRIMTLVERTEX
| D3DDEVCAPS_CANRENDERAFTERFLIP
| D3DDEVCAPS_TEXTURENONLOCALVIDMEM
|
463 D3DDEVCAPS_DRAWPRIMITIVES2
| D3DDEVCAPS_SEPARATETEXTUREMEMORIES
|
464 D3DDEVCAPS_DRAWPRIMITIVES2EX
| D3DDEVCAPS_HWTRANSFORMANDLIGHT
| D3DDEVCAPS_CANBLTSYSTONONLOCAL
|
465 D3DDEVCAPS_HWRASTERIZATION
| D3DDEVCAPS_PUREDEVICE
| D3DDEVCAPS_QUINTICRTPATCHES
|
466 D3DDEVCAPS_RTPATCHES
| D3DDEVCAPS_RTPATCHHANDLEZERO
| D3DDEVCAPS_NPATCHES
;
469 D3DPSHADECAPS_COLORGOURAUDRGB
| D3DPSHADECAPS_SPECULARGOURAUDRGB
|
470 D3DPSHADECAPS_ALPHAGOURAUDBLEND
| D3DPSHADECAPS_FOGGOURAUD
;
473 D3DPRASTERCAPS_DITHER
| D3DPRASTERCAPS_ZTEST
| D3DPRASTERCAPS_FOGVERTEX
|
474 D3DPRASTERCAPS_FOGTABLE
| D3DPRASTERCAPS_MIPMAPLODBIAS
| D3DPRASTERCAPS_ZBUFFERLESSHSR
|
475 D3DPRASTERCAPS_FOGRANGE
| D3DPRASTERCAPS_ANISOTROPY
| D3DPRASTERCAPS_WBUFFER
|
476 D3DPRASTERCAPS_WFOG
| D3DPRASTERCAPS_ZFOG
| D3DPRASTERCAPS_COLORPERSPECTIVE
|
477 D3DPRASTERCAPS_SCISSORTEST
| D3DPRASTERCAPS_SLOPESCALEDEPTHBIAS
|
478 D3DPRASTERCAPS_DEPTHBIAS
| D3DPRASTERCAPS_MULTISAMPLE_TOGGLE
;
481 D3DDEVCAPS2_STREAMOFFSET
| D3DDEVCAPS2_DMAPNPATCH
| D3DDEVCAPS2_ADAPTIVETESSRTPATCH
|
482 D3DDEVCAPS2_ADAPTIVETESSNPATCH
| D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES
|
483 D3DDEVCAPS2_PRESAMPLEDDMAPNPATCH
| D3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET
;
486 D3DCAPS2_FULLSCREENGAMMA
| D3DCAPS2_CANCALIBRATEGAMMA
| D3DCAPS2_RESERVED
|
487 D3DCAPS2_CANMANAGERESOURCE
| D3DCAPS2_DYNAMICTEXTURES
| D3DCAPS2_CANAUTOGENMIPMAP
;
489 caps
->VertexProcessingCaps
&=
490 D3DVTXPCAPS_TEXGEN
| D3DVTXPCAPS_MATERIALSOURCE7
| D3DVTXPCAPS_DIRECTIONALLIGHTS
|
491 D3DVTXPCAPS_POSITIONALLIGHTS
| D3DVTXPCAPS_LOCALVIEWER
| D3DVTXPCAPS_TWEENING
|
492 D3DVTXPCAPS_TEXGEN_SPHEREMAP
| D3DVTXPCAPS_NO_TEXGEN_NONLOCALVIEWER
;
495 D3DPTEXTURECAPS_PERSPECTIVE
| D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_ALPHA
|
496 D3DPTEXTURECAPS_SQUAREONLY
| D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE
|
497 D3DPTEXTURECAPS_ALPHAPALETTE
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
|
498 D3DPTEXTURECAPS_PROJECTED
| D3DPTEXTURECAPS_CUBEMAP
| D3DPTEXTURECAPS_VOLUMEMAP
|
499 D3DPTEXTURECAPS_MIPMAP
| D3DPTEXTURECAPS_MIPVOLUMEMAP
| D3DPTEXTURECAPS_MIPCUBEMAP
|
500 D3DPTEXTURECAPS_CUBEMAP_POW2
| D3DPTEXTURECAPS_VOLUMEMAP_POW2
| D3DPTEXTURECAPS_NOPROJECTEDBUMPENV
;
502 caps
->MaxVertexShaderConst
= min(D3D9_MAX_VERTEX_SHADER_CONSTANTF
, caps
->MaxVertexShaderConst
);
503 caps
->NumSimultaneousRTs
= min(D3D_MAX_SIMULTANEOUS_RENDERTARGETS
, caps
->NumSimultaneousRTs
);
505 if (caps
->PixelShaderVersion
> 3)
507 caps
->PixelShaderVersion
= D3DPS_VERSION(3, 0);
511 DWORD major
= caps
->PixelShaderVersion
;
512 caps
->PixelShaderVersion
= D3DPS_VERSION(major
, ps_minor_version
[major
]);
515 if (caps
->VertexShaderVersion
> 3)
517 caps
->VertexShaderVersion
= D3DVS_VERSION(3, 0);
521 DWORD major
= caps
->VertexShaderVersion
;
522 caps
->VertexShaderVersion
= D3DVS_VERSION(major
, vs_minor_version
[major
]);
526 static HRESULT WINAPI
d3d9_device_QueryInterface(IDirect3DDevice9Ex
*iface
, REFIID riid
, void **out
)
528 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
530 if (IsEqualGUID(riid
, &IID_IDirect3DDevice9
)
531 || IsEqualGUID(riid
, &IID_IUnknown
))
533 IDirect3DDevice9Ex_AddRef(iface
);
538 if (IsEqualGUID(riid
, &IID_IDirect3DDevice9Ex
))
540 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
542 /* Find out if the creating d3d9 interface was created with Direct3DCreate9Ex.
543 * It doesn't matter with which function the device was created. */
544 if (!device
->d3d_parent
->extended
)
546 WARN("IDirect3D9 instance wasn't created with CreateDirect3D9Ex, returning E_NOINTERFACE.\n");
548 return E_NOINTERFACE
;
551 IDirect3DDevice9Ex_AddRef(iface
);
556 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
559 return E_NOINTERFACE
;
562 static ULONG WINAPI
d3d9_device_AddRef(IDirect3DDevice9Ex
*iface
)
564 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
565 ULONG refcount
= InterlockedIncrement(&device
->refcount
);
567 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
572 static ULONG WINAPI DECLSPEC_HOTPATCH
d3d9_device_Release(IDirect3DDevice9Ex
*iface
)
574 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
577 if (device
->in_destruction
)
580 refcount
= InterlockedDecrement(&device
->refcount
);
582 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
587 device
->in_destruction
= TRUE
;
589 wined3d_mutex_lock();
590 for (i
= 0; i
< device
->fvf_decl_count
; ++i
)
592 wined3d_vertex_declaration_decref(device
->fvf_decls
[i
].decl
);
594 heap_free(device
->fvf_decls
);
596 if (device
->vertex_buffer
)
597 wined3d_buffer_decref(device
->vertex_buffer
);
598 if (device
->index_buffer
)
599 wined3d_buffer_decref(device
->index_buffer
);
601 heap_free(device
->implicit_swapchains
);
603 wined3d_device_uninit_3d(device
->wined3d_device
);
604 wined3d_device_release_focus_window(device
->wined3d_device
);
605 wined3d_device_decref(device
->wined3d_device
);
606 wined3d_mutex_unlock();
608 IDirect3D9Ex_Release(&device
->d3d_parent
->IDirect3D9Ex_iface
);
616 static HRESULT WINAPI
d3d9_device_TestCooperativeLevel(IDirect3DDevice9Ex
*iface
)
618 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
620 TRACE("iface %p.\n", iface
);
622 TRACE("device state: %#x.\n", device
->device_state
);
624 if (device
->d3d_parent
->extended
)
627 switch (device
->device_state
)
630 case D3D9_DEVICE_STATE_OK
:
632 case D3D9_DEVICE_STATE_LOST
:
633 return D3DERR_DEVICELOST
;
634 case D3D9_DEVICE_STATE_NOT_RESET
:
635 return D3DERR_DEVICENOTRESET
;
639 static UINT WINAPI
d3d9_device_GetAvailableTextureMem(IDirect3DDevice9Ex
*iface
)
641 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
644 TRACE("iface %p.\n", iface
);
646 wined3d_mutex_lock();
647 ret
= wined3d_device_get_available_texture_mem(device
->wined3d_device
);
648 wined3d_mutex_unlock();
653 static HRESULT WINAPI
d3d9_device_EvictManagedResources(IDirect3DDevice9Ex
*iface
)
655 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
657 TRACE("iface %p.\n", iface
);
659 wined3d_mutex_lock();
660 wined3d_device_evict_managed_resources(device
->wined3d_device
);
661 wined3d_mutex_unlock();
666 static HRESULT WINAPI
d3d9_device_GetDirect3D(IDirect3DDevice9Ex
*iface
, IDirect3D9
**d3d9
)
668 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
670 TRACE("iface %p, d3d9 %p.\n", iface
, d3d9
);
673 return D3DERR_INVALIDCALL
;
675 return IDirect3D9Ex_QueryInterface(&device
->d3d_parent
->IDirect3D9Ex_iface
, &IID_IDirect3D9
, (void **)d3d9
);
678 static HRESULT WINAPI
d3d9_device_GetDeviceCaps(IDirect3DDevice9Ex
*iface
, D3DCAPS9
*caps
)
680 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
681 struct wined3d_caps wined3d_caps
;
684 TRACE("iface %p, caps %p.\n", iface
, caps
);
687 return D3DERR_INVALIDCALL
;
689 memset(caps
, 0, sizeof(*caps
));
691 wined3d_mutex_lock();
692 hr
= wined3d_device_get_device_caps(device
->wined3d_device
, &wined3d_caps
);
693 wined3d_mutex_unlock();
695 d3dcaps_from_wined3dcaps(caps
, &wined3d_caps
);
700 static HRESULT WINAPI
d3d9_device_GetDisplayMode(IDirect3DDevice9Ex
*iface
, UINT swapchain
, D3DDISPLAYMODE
*mode
)
702 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
703 struct wined3d_display_mode wined3d_mode
;
706 TRACE("iface %p, swapchain %u, mode %p.\n", iface
, swapchain
, mode
);
708 wined3d_mutex_lock();
709 hr
= wined3d_device_get_display_mode(device
->wined3d_device
, swapchain
, &wined3d_mode
, NULL
);
710 wined3d_mutex_unlock();
714 mode
->Width
= wined3d_mode
.width
;
715 mode
->Height
= wined3d_mode
.height
;
716 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
717 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
723 static HRESULT WINAPI
d3d9_device_GetCreationParameters(IDirect3DDevice9Ex
*iface
,
724 D3DDEVICE_CREATION_PARAMETERS
*parameters
)
726 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
728 TRACE("iface %p, parameters %p.\n", iface
, parameters
);
730 wined3d_mutex_lock();
731 wined3d_device_get_creation_parameters(device
->wined3d_device
,
732 (struct wined3d_device_creation_parameters
*)parameters
);
733 wined3d_mutex_unlock();
738 static HRESULT WINAPI
d3d9_device_SetCursorProperties(IDirect3DDevice9Ex
*iface
,
739 UINT hotspot_x
, UINT hotspot_y
, IDirect3DSurface9
*bitmap
)
741 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
742 struct d3d9_surface
*bitmap_impl
= unsafe_impl_from_IDirect3DSurface9(bitmap
);
745 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
746 iface
, hotspot_x
, hotspot_y
, bitmap
);
750 WARN("No cursor bitmap, returning D3DERR_INVALIDCALL.\n");
751 return D3DERR_INVALIDCALL
;
754 wined3d_mutex_lock();
755 hr
= wined3d_device_set_cursor_properties(device
->wined3d_device
,
756 hotspot_x
, hotspot_y
, bitmap_impl
->wined3d_texture
, bitmap_impl
->sub_resource_idx
);
757 wined3d_mutex_unlock();
762 static void WINAPI
d3d9_device_SetCursorPosition(IDirect3DDevice9Ex
*iface
, int x
, int y
, DWORD flags
)
764 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
766 TRACE("iface %p, x %u, y %u, flags %#x.\n", iface
, x
, y
, flags
);
768 wined3d_mutex_lock();
769 wined3d_device_set_cursor_position(device
->wined3d_device
, x
, y
, flags
);
770 wined3d_mutex_unlock();
773 static BOOL WINAPI
d3d9_device_ShowCursor(IDirect3DDevice9Ex
*iface
, BOOL show
)
775 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
778 TRACE("iface %p, show %#x.\n", iface
, show
);
780 wined3d_mutex_lock();
781 ret
= wined3d_device_show_cursor(device
->wined3d_device
, show
);
782 wined3d_mutex_unlock();
787 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_CreateAdditionalSwapChain(IDirect3DDevice9Ex
*iface
,
788 D3DPRESENT_PARAMETERS
*present_parameters
, IDirect3DSwapChain9
**swapchain
)
790 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
791 struct wined3d_swapchain_desc desc
;
792 struct d3d9_swapchain
*object
;
793 unsigned int swap_interval
;
794 unsigned int i
, count
;
797 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
798 iface
, present_parameters
, swapchain
);
800 if (!present_parameters
->Windowed
)
802 WARN("Trying to create an additional fullscreen swapchain, returning D3DERR_INVALIDCALL.\n");
803 return D3DERR_INVALIDCALL
;
806 wined3d_mutex_lock();
807 count
= wined3d_device_get_swapchain_count(device
->wined3d_device
);
808 for (i
= 0; i
< count
; ++i
)
810 struct wined3d_swapchain
*wined3d_swapchain
;
812 wined3d_swapchain
= wined3d_device_get_swapchain(device
->wined3d_device
, i
);
813 wined3d_swapchain_get_desc(wined3d_swapchain
, &desc
);
817 wined3d_mutex_unlock();
818 WARN("Trying to create an additional swapchain in fullscreen mode, returning D3DERR_INVALIDCALL.\n");
819 return D3DERR_INVALIDCALL
;
822 wined3d_mutex_unlock();
824 if (!wined3d_swapchain_desc_from_present_parameters(&desc
, present_parameters
,
825 device
->d3d_parent
->extended
))
826 return D3DERR_INVALIDCALL
;
827 swap_interval
= wined3dswapinterval_from_d3d(present_parameters
->PresentationInterval
);
828 if (SUCCEEDED(hr
= d3d9_swapchain_create(device
, &desc
, swap_interval
, &object
)))
829 *swapchain
= (IDirect3DSwapChain9
*)&object
->IDirect3DSwapChain9Ex_iface
;
830 present_parameters_from_wined3d_swapchain_desc(present_parameters
,
831 &desc
, present_parameters
->PresentationInterval
);
836 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_GetSwapChain(IDirect3DDevice9Ex
*iface
,
837 UINT swapchain_idx
, IDirect3DSwapChain9
**swapchain
)
839 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
842 TRACE("iface %p, swapchain_idx %u, swapchain %p.\n", iface
, swapchain_idx
, swapchain
);
844 wined3d_mutex_lock();
845 if (swapchain_idx
< device
->implicit_swapchain_count
)
847 *swapchain
= (IDirect3DSwapChain9
*)&device
->implicit_swapchains
[swapchain_idx
]->IDirect3DSwapChain9Ex_iface
;
848 IDirect3DSwapChain9Ex_AddRef(*swapchain
);
854 hr
= D3DERR_INVALIDCALL
;
856 wined3d_mutex_unlock();
861 static UINT WINAPI
d3d9_device_GetNumberOfSwapChains(IDirect3DDevice9Ex
*iface
)
863 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
866 TRACE("iface %p.\n", iface
);
868 wined3d_mutex_lock();
869 count
= wined3d_device_get_swapchain_count(device
->wined3d_device
);
870 wined3d_mutex_unlock();
875 static HRESULT CDECL
reset_enum_callback(struct wined3d_resource
*resource
)
877 struct wined3d_resource_desc desc
;
878 IDirect3DBaseTexture9
*texture
;
879 struct d3d9_surface
*surface
;
882 wined3d_resource_get_desc(resource
, &desc
);
883 if (desc
.access
& WINED3D_RESOURCE_ACCESS_CPU
)
886 if (desc
.resource_type
!= WINED3D_RTYPE_TEXTURE_2D
)
888 WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource
);
889 return D3DERR_INVALIDCALL
;
892 parent
= wined3d_resource_get_parent(resource
);
893 if (parent
&& SUCCEEDED(IUnknown_QueryInterface(parent
, &IID_IDirect3DBaseTexture9
, (void **)&texture
)))
895 IDirect3DBaseTexture9_Release(texture
);
896 WARN("Texture %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", texture
, resource
);
897 return D3DERR_INVALIDCALL
;
900 surface
= wined3d_texture_get_sub_resource_parent(wined3d_texture_from_resource(resource
), 0);
901 if (!surface
->resource
.refcount
)
904 WARN("Surface %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface
);
905 return D3DERR_INVALIDCALL
;
908 static HRESULT
d3d9_device_get_swapchains(struct d3d9_device
*device
)
910 UINT i
, new_swapchain_count
= wined3d_device_get_swapchain_count(device
->wined3d_device
);
911 struct wined3d_swapchain
*wined3d_swapchain
;
913 if (!(device
->implicit_swapchains
= heap_alloc(new_swapchain_count
* sizeof(*device
->implicit_swapchains
))))
914 return E_OUTOFMEMORY
;
916 for (i
= 0; i
< new_swapchain_count
; ++i
)
918 wined3d_swapchain
= wined3d_device_get_swapchain(device
->wined3d_device
, i
);
919 device
->implicit_swapchains
[i
] = wined3d_swapchain_get_parent(wined3d_swapchain
);
921 device
->implicit_swapchain_count
= new_swapchain_count
;
926 static HRESULT
d3d9_device_reset(struct d3d9_device
*device
,
927 D3DPRESENT_PARAMETERS
*present_parameters
, D3DDISPLAYMODEEX
*mode
)
929 BOOL extended
= device
->d3d_parent
->extended
;
930 struct wined3d_swapchain_desc swapchain_desc
;
931 struct wined3d_display_mode wined3d_mode
;
932 struct wined3d_rendertarget_view
*rtv
;
936 if (!extended
&& device
->device_state
== D3D9_DEVICE_STATE_LOST
)
938 WARN("App not active, returning D3DERR_DEVICELOST.\n");
939 return D3DERR_DEVICELOST
;
944 wined3d_mode
.width
= mode
->Width
;
945 wined3d_mode
.height
= mode
->Height
;
946 wined3d_mode
.refresh_rate
= mode
->RefreshRate
;
947 wined3d_mode
.format_id
= wined3dformat_from_d3dformat(mode
->Format
);
948 wined3d_mode
.scanline_ordering
= mode
->ScanLineOrdering
;
951 if (!wined3d_swapchain_desc_from_present_parameters(&swapchain_desc
, present_parameters
, extended
))
952 return D3DERR_INVALIDCALL
;
954 wined3d_mutex_lock();
956 if (device
->vertex_buffer
)
958 wined3d_buffer_decref(device
->vertex_buffer
);
959 device
->vertex_buffer
= NULL
;
960 device
->vertex_buffer_size
= 0;
963 if (device
->index_buffer
)
965 wined3d_buffer_decref(device
->index_buffer
);
966 device
->index_buffer
= NULL
;
967 device
->index_buffer_size
= 0;
970 if (SUCCEEDED(hr
= wined3d_device_reset(device
->wined3d_device
, &swapchain_desc
,
971 mode
? &wined3d_mode
: NULL
, reset_enum_callback
, !extended
)))
973 heap_free(device
->implicit_swapchains
);
977 wined3d_device_set_render_state(device
->wined3d_device
, WINED3D_RS_ZENABLE
,
978 !!swapchain_desc
.enable_auto_depth_stencil
);
981 if (FAILED(hr
= d3d9_device_get_swapchains(device
)))
983 device
->device_state
= D3D9_DEVICE_STATE_NOT_RESET
;
987 device
->implicit_swapchains
[0]->swap_interval
988 = wined3dswapinterval_from_d3d(present_parameters
->PresentationInterval
);
989 wined3d_swapchain_get_desc(device
->implicit_swapchains
[0]->wined3d_swapchain
, &swapchain_desc
);
990 present_parameters
->BackBufferWidth
= swapchain_desc
.backbuffer_width
;
991 present_parameters
->BackBufferHeight
= swapchain_desc
.backbuffer_height
;
992 present_parameters
->BackBufferFormat
= d3dformat_from_wined3dformat(swapchain_desc
.backbuffer_format
);
993 present_parameters
->BackBufferCount
= swapchain_desc
.backbuffer_count
;
995 device
->device_state
= D3D9_DEVICE_STATE_OK
;
998 rtv
= wined3d_device_get_rendertarget_view(device
->wined3d_device
, 0);
999 device
->render_targets
[0] = wined3d_rendertarget_view_get_sub_resource_parent(rtv
);
1000 for (i
= 1; i
< ARRAY_SIZE(device
->render_targets
); ++i
)
1001 device
->render_targets
[i
] = NULL
;
1005 device
->device_state
= D3D9_DEVICE_STATE_NOT_RESET
;
1008 wined3d_mutex_unlock();
1013 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_Reset(IDirect3DDevice9Ex
*iface
,
1014 D3DPRESENT_PARAMETERS
*present_parameters
)
1016 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1018 TRACE("iface %p, present_parameters %p.\n", iface
, present_parameters
);
1020 return d3d9_device_reset(device
, present_parameters
, NULL
);
1023 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_Present(IDirect3DDevice9Ex
*iface
,
1024 const RECT
*src_rect
, const RECT
*dst_rect
, HWND dst_window_override
, const RGNDATA
*dirty_region
)
1026 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1027 struct d3d9_swapchain
*swapchain
;
1031 TRACE("iface %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p.\n",
1032 iface
, wine_dbgstr_rect(src_rect
), wine_dbgstr_rect(dst_rect
), dst_window_override
, dirty_region
);
1034 if (device
->device_state
!= D3D9_DEVICE_STATE_OK
)
1035 return device
->d3d_parent
->extended
? S_PRESENT_OCCLUDED
: D3DERR_DEVICELOST
;
1038 FIXME("Ignoring dirty_region %p.\n", dirty_region
);
1040 wined3d_mutex_lock();
1041 for (i
= 0; i
< device
->implicit_swapchain_count
; ++i
)
1043 swapchain
= device
->implicit_swapchains
[i
];
1044 if (FAILED(hr
= wined3d_swapchain_present(swapchain
->wined3d_swapchain
,
1045 src_rect
, dst_rect
, dst_window_override
, swapchain
->swap_interval
, 0)))
1047 wined3d_mutex_unlock();
1051 wined3d_mutex_unlock();
1056 static HRESULT WINAPI
d3d9_device_GetBackBuffer(IDirect3DDevice9Ex
*iface
, UINT swapchain
,
1057 UINT backbuffer_idx
, D3DBACKBUFFER_TYPE backbuffer_type
, IDirect3DSurface9
**backbuffer
)
1059 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1062 TRACE("iface %p, swapchain %u, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
1063 iface
, swapchain
, backbuffer_idx
, backbuffer_type
, backbuffer
);
1065 /* backbuffer_type is ignored by native. */
1067 /* No need to check for backbuffer == NULL, Windows crashes in that case. */
1070 wined3d_mutex_lock();
1071 if (swapchain
>= device
->implicit_swapchain_count
)
1073 wined3d_mutex_unlock();
1074 WARN("Swapchain index %u is out of range, returning D3DERR_INVALIDCALL.\n", swapchain
);
1075 return D3DERR_INVALIDCALL
;
1078 hr
= IDirect3DSwapChain9Ex_GetBackBuffer(&device
->implicit_swapchains
[swapchain
]->IDirect3DSwapChain9Ex_iface
,
1079 backbuffer_idx
, backbuffer_type
, backbuffer
);
1080 wined3d_mutex_unlock();
1085 static HRESULT WINAPI
d3d9_device_GetRasterStatus(IDirect3DDevice9Ex
*iface
,
1086 UINT swapchain
, D3DRASTER_STATUS
*raster_status
)
1088 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1091 TRACE("iface %p, swapchain %u, raster_status %p.\n", iface
, swapchain
, raster_status
);
1093 wined3d_mutex_lock();
1094 hr
= wined3d_device_get_raster_status(device
->wined3d_device
,
1095 swapchain
, (struct wined3d_raster_status
*)raster_status
);
1096 wined3d_mutex_unlock();
1101 static HRESULT WINAPI
d3d9_device_SetDialogBoxMode(IDirect3DDevice9Ex
*iface
, BOOL enable
)
1103 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1106 TRACE("iface %p, enable %#x.\n", iface
, enable
);
1108 wined3d_mutex_lock();
1109 hr
= wined3d_device_set_dialog_box_mode(device
->wined3d_device
, enable
);
1110 wined3d_mutex_unlock();
1115 static void WINAPI
d3d9_device_SetGammaRamp(IDirect3DDevice9Ex
*iface
,
1116 UINT swapchain
, DWORD flags
, const D3DGAMMARAMP
*ramp
)
1118 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1120 TRACE("iface %p, swapchain %u, flags %#x, ramp %p.\n", iface
, swapchain
, flags
, ramp
);
1122 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
1123 wined3d_mutex_lock();
1124 wined3d_device_set_gamma_ramp(device
->wined3d_device
, swapchain
, flags
, (const struct wined3d_gamma_ramp
*)ramp
);
1125 wined3d_mutex_unlock();
1128 static void WINAPI
d3d9_device_GetGammaRamp(IDirect3DDevice9Ex
*iface
, UINT swapchain
, D3DGAMMARAMP
*ramp
)
1130 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1132 TRACE("iface %p, swapchain %u, ramp %p.\n", iface
, swapchain
, ramp
);
1134 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
1135 wined3d_mutex_lock();
1136 wined3d_device_get_gamma_ramp(device
->wined3d_device
, swapchain
, (struct wined3d_gamma_ramp
*)ramp
);
1137 wined3d_mutex_unlock();
1140 static HRESULT WINAPI
d3d9_device_CreateTexture(IDirect3DDevice9Ex
*iface
,
1141 UINT width
, UINT height
, UINT levels
, DWORD usage
, D3DFORMAT format
,
1142 D3DPOOL pool
, IDirect3DTexture9
**texture
, HANDLE
*shared_handle
)
1144 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1145 struct d3d9_texture
*object
;
1146 BOOL set_mem
= FALSE
;
1149 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
1150 iface
, width
, height
, levels
, usage
, format
, pool
, texture
, shared_handle
);
1155 if (!device
->d3d_parent
->extended
)
1157 WARN("Trying to create a shared or user memory texture on a non-ex device.\n");
1161 if (pool
== D3DPOOL_SYSTEMMEM
)
1164 return D3DERR_INVALIDCALL
;
1169 if (pool
!= D3DPOOL_DEFAULT
)
1171 WARN("Trying to create a shared texture in pool %#x.\n", pool
);
1172 return D3DERR_INVALIDCALL
;
1174 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1178 if (!(object
= heap_alloc_zero(sizeof(*object
))))
1179 return D3DERR_OUTOFVIDEOMEMORY
;
1181 hr
= texture_init(object
, device
, width
, height
, levels
, usage
, format
, pool
);
1184 WARN("Failed to initialize texture, hr %#x.\n", hr
);
1190 wined3d_texture_update_desc(object
->wined3d_texture
, width
, height
,
1191 wined3dformat_from_d3dformat(format
), WINED3D_MULTISAMPLE_NONE
, 0,
1194 TRACE("Created texture %p.\n", object
);
1195 *texture
= (IDirect3DTexture9
*)&object
->IDirect3DBaseTexture9_iface
;
1200 static HRESULT WINAPI
d3d9_device_CreateVolumeTexture(IDirect3DDevice9Ex
*iface
,
1201 UINT width
, UINT height
, UINT depth
, UINT levels
, DWORD usage
, D3DFORMAT format
,
1202 D3DPOOL pool
, IDirect3DVolumeTexture9
**texture
, HANDLE
*shared_handle
)
1204 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1205 struct d3d9_texture
*object
;
1208 TRACE("iface %p, width %u, height %u, depth %u, levels %u, "
1209 "usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
1210 iface
, width
, height
, depth
, levels
,
1211 usage
, format
, pool
, texture
, shared_handle
);
1216 if (!device
->d3d_parent
->extended
)
1218 WARN("Trying to create a shared volume texture on a non-ex device.\n");
1222 if (pool
!= D3DPOOL_DEFAULT
)
1224 WARN("Trying to create a shared volume texture in pool %#x.\n", pool
);
1225 return D3DERR_INVALIDCALL
;
1227 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1230 if (!(object
= heap_alloc_zero(sizeof(*object
))))
1231 return D3DERR_OUTOFVIDEOMEMORY
;
1233 hr
= volumetexture_init(object
, device
, width
, height
, depth
, levels
, usage
, format
, pool
);
1236 WARN("Failed to initialize volume texture, hr %#x.\n", hr
);
1241 TRACE("Created volume texture %p.\n", object
);
1242 *texture
= (IDirect3DVolumeTexture9
*)&object
->IDirect3DBaseTexture9_iface
;
1247 static HRESULT WINAPI
d3d9_device_CreateCubeTexture(IDirect3DDevice9Ex
*iface
,
1248 UINT edge_length
, UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
,
1249 IDirect3DCubeTexture9
**texture
, HANDLE
*shared_handle
)
1251 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1252 struct d3d9_texture
*object
;
1255 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
1256 iface
, edge_length
, levels
, usage
, format
, pool
, texture
, shared_handle
);
1261 if (!device
->d3d_parent
->extended
)
1263 WARN("Trying to create a shared cube texture on a non-ex device.\n");
1267 if (pool
!= D3DPOOL_DEFAULT
)
1269 WARN("Trying to create a shared cube texture in pool %#x.\n", pool
);
1270 return D3DERR_INVALIDCALL
;
1272 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1275 if (!(object
= heap_alloc_zero(sizeof(*object
))))
1276 return D3DERR_OUTOFVIDEOMEMORY
;
1278 hr
= cubetexture_init(object
, device
, edge_length
, levels
, usage
, format
, pool
);
1281 WARN("Failed to initialize cube texture, hr %#x.\n", hr
);
1286 TRACE("Created cube texture %p.\n", object
);
1287 *texture
= (IDirect3DCubeTexture9
*)&object
->IDirect3DBaseTexture9_iface
;
1292 static HRESULT WINAPI
d3d9_device_CreateVertexBuffer(IDirect3DDevice9Ex
*iface
, UINT size
,
1293 DWORD usage
, DWORD fvf
, D3DPOOL pool
, IDirect3DVertexBuffer9
**buffer
,
1294 HANDLE
*shared_handle
)
1296 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1297 struct d3d9_vertexbuffer
*object
;
1300 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p, shared_handle %p.\n",
1301 iface
, size
, usage
, fvf
, pool
, buffer
, shared_handle
);
1305 if (!device
->d3d_parent
->extended
)
1307 WARN("Trying to create a shared vertex buffer on a non-ex device.\n");
1311 if (pool
!= D3DPOOL_DEFAULT
)
1313 WARN("Trying to create a shared vertex buffer in pool %#x.\n", pool
);
1314 return D3DERR_NOTAVAILABLE
;
1316 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1319 if (!(object
= heap_alloc_zero(sizeof(*object
))))
1320 return D3DERR_OUTOFVIDEOMEMORY
;
1322 hr
= vertexbuffer_init(object
, device
, size
, usage
, fvf
, pool
);
1325 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr
);
1330 TRACE("Created vertex buffer %p.\n", object
);
1331 *buffer
= &object
->IDirect3DVertexBuffer9_iface
;
1336 static HRESULT WINAPI
d3d9_device_CreateIndexBuffer(IDirect3DDevice9Ex
*iface
, UINT size
,
1337 DWORD usage
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DIndexBuffer9
**buffer
,
1338 HANDLE
*shared_handle
)
1340 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1341 struct d3d9_indexbuffer
*object
;
1344 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p, shared_handle %p.\n",
1345 iface
, size
, usage
, format
, pool
, buffer
, shared_handle
);
1349 if (!device
->d3d_parent
->extended
)
1351 WARN("Trying to create a shared index buffer on a non-ex device.\n");
1355 if (pool
!= D3DPOOL_DEFAULT
)
1357 WARN("Trying to create a shared index buffer in pool %#x.\n", pool
);
1358 return D3DERR_NOTAVAILABLE
;
1360 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1363 if (!(object
= heap_alloc_zero(sizeof(*object
))))
1364 return D3DERR_OUTOFVIDEOMEMORY
;
1366 hr
= indexbuffer_init(object
, device
, size
, usage
, format
, pool
);
1369 WARN("Failed to initialize index buffer, hr %#x.\n", hr
);
1374 TRACE("Created index buffer %p.\n", object
);
1375 *buffer
= &object
->IDirect3DIndexBuffer9_iface
;
1380 static HRESULT
d3d9_device_create_surface(struct d3d9_device
*device
, UINT width
, UINT height
,
1381 D3DFORMAT format
, DWORD flags
, IDirect3DSurface9
**surface
, UINT usage
, D3DPOOL pool
,
1382 D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
, void *user_mem
)
1384 struct wined3d_resource_desc desc
;
1385 struct d3d9_surface
*surface_impl
;
1386 struct wined3d_texture
*texture
;
1389 TRACE("device %p, width %u, height %u, format %#x, flags %#x, surface %p.\n"
1390 "usage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
1391 device
, width
, height
, format
, flags
, surface
, usage
, pool
,
1392 multisample_type
, multisample_quality
);
1394 desc
.resource_type
= WINED3D_RTYPE_TEXTURE_2D
;
1395 desc
.format
= wined3dformat_from_d3dformat(format
);
1396 desc
.multisample_type
= multisample_type
;
1397 desc
.multisample_quality
= multisample_quality
;
1398 desc
.usage
= usage
& WINED3DUSAGE_MASK
;
1399 if (pool
== D3DPOOL_SCRATCH
)
1400 desc
.usage
|= WINED3DUSAGE_SCRATCH
;
1401 desc
.bind_flags
= wined3d_bind_flags_from_d3d9_usage(usage
);
1402 desc
.access
= wined3daccess_from_d3dpool(pool
, usage
)
1403 | WINED3D_RESOURCE_ACCESS_MAP_R
| WINED3D_RESOURCE_ACCESS_MAP_W
;
1405 desc
.height
= height
;
1409 if (is_gdi_compat_wined3dformat(desc
.format
))
1410 flags
|= WINED3D_TEXTURE_CREATE_GET_DC
;
1412 wined3d_mutex_lock();
1414 if (FAILED(hr
= wined3d_texture_create(device
->wined3d_device
, &desc
,
1415 1, 1, flags
, NULL
, NULL
, &d3d9_null_wined3d_parent_ops
, &texture
)))
1417 wined3d_mutex_unlock();
1418 WARN("Failed to create texture, hr %#x.\n", hr
);
1419 if (hr
== WINED3DERR_NOTAVAILABLE
)
1420 hr
= D3DERR_INVALIDCALL
;
1424 surface_impl
= wined3d_texture_get_sub_resource_parent(texture
, 0);
1425 surface_impl
->parent_device
= &device
->IDirect3DDevice9Ex_iface
;
1426 *surface
= &surface_impl
->IDirect3DSurface9_iface
;
1427 IDirect3DSurface9_AddRef(*surface
);
1430 wined3d_texture_update_desc(texture
, width
, height
,
1431 desc
.format
, multisample_type
, multisample_quality
, user_mem
, 0);
1433 wined3d_texture_decref(texture
);
1435 wined3d_mutex_unlock();
1440 BOOL
is_gdi_compat_wined3dformat(enum wined3d_format_id format
)
1444 case WINED3DFMT_B8G8R8A8_UNORM
:
1445 case WINED3DFMT_B8G8R8X8_UNORM
:
1446 case WINED3DFMT_B5G6R5_UNORM
:
1447 case WINED3DFMT_B5G5R5X1_UNORM
:
1448 case WINED3DFMT_B5G5R5A1_UNORM
:
1449 case WINED3DFMT_B8G8R8_UNORM
:
1456 static HRESULT WINAPI
d3d9_device_CreateRenderTarget(IDirect3DDevice9Ex
*iface
, UINT width
, UINT height
,
1457 D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
1458 BOOL lockable
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
)
1460 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1463 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
1464 "lockable %#x, surface %p, shared_handle %p.\n",
1465 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
1466 lockable
, surface
, shared_handle
);
1471 if (!device
->d3d_parent
->extended
)
1473 WARN("Trying to create a shared render target on a non-ex device.\n");
1477 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1481 flags
|= WINED3D_TEXTURE_CREATE_MAPPABLE
;
1483 return d3d9_device_create_surface(device
, width
, height
, format
, flags
, surface
,
1484 D3DUSAGE_RENDERTARGET
, D3DPOOL_DEFAULT
, multisample_type
, multisample_quality
, NULL
);
1487 static HRESULT WINAPI
d3d9_device_CreateDepthStencilSurface(IDirect3DDevice9Ex
*iface
, UINT width
, UINT height
,
1488 D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
1489 BOOL discard
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
)
1491 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1492 DWORD flags
= WINED3D_TEXTURE_CREATE_MAPPABLE
;
1494 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
1495 "discard %#x, surface %p, shared_handle %p.\n",
1496 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
1497 discard
, surface
, shared_handle
);
1502 if (!device
->d3d_parent
->extended
)
1504 WARN("Trying to create a shared depth stencil on a non-ex device.\n");
1508 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1512 flags
|= WINED3D_TEXTURE_CREATE_DISCARD
;
1514 return d3d9_device_create_surface(device
, width
, height
, format
, flags
, surface
,
1515 D3DUSAGE_DEPTHSTENCIL
, D3DPOOL_DEFAULT
, multisample_type
, multisample_quality
, NULL
);
1519 static HRESULT WINAPI
d3d9_device_UpdateSurface(IDirect3DDevice9Ex
*iface
,
1520 IDirect3DSurface9
*src_surface
, const RECT
*src_rect
,
1521 IDirect3DSurface9
*dst_surface
, const POINT
*dst_point
)
1523 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1524 struct d3d9_surface
*src
= unsafe_impl_from_IDirect3DSurface9(src_surface
);
1525 struct d3d9_surface
*dst
= unsafe_impl_from_IDirect3DSurface9(dst_surface
);
1526 struct wined3d_sub_resource_desc src_desc
, dst_desc
;
1527 struct wined3d_box src_box
;
1530 TRACE("iface %p, src_surface %p, src_rect %s, dst_surface %p, dst_point %p.\n",
1531 iface
, src_surface
, wine_dbgstr_rect(src_rect
), dst_surface
, dst_point
);
1533 wined3d_mutex_lock();
1535 wined3d_texture_get_sub_resource_desc(src
->wined3d_texture
, src
->sub_resource_idx
, &src_desc
);
1536 wined3d_texture_get_sub_resource_desc(dst
->wined3d_texture
, dst
->sub_resource_idx
, &dst_desc
);
1537 if (src_desc
.format
!= dst_desc
.format
)
1539 wined3d_mutex_unlock();
1540 WARN("Surface formats (%#x/%#x) don't match.\n",
1541 d3dformat_from_wined3dformat(src_desc
.format
),
1542 d3dformat_from_wined3dformat(dst_desc
.format
));
1543 return D3DERR_INVALIDCALL
;
1547 wined3d_box_set(&src_box
, src_rect
->left
, src_rect
->top
, src_rect
->right
, src_rect
->bottom
, 0, 1);
1549 wined3d_box_set(&src_box
, 0, 0, src_desc
.width
, src_desc
.height
, 0, 1);
1551 hr
= wined3d_device_copy_sub_resource_region(device
->wined3d_device
,
1552 wined3d_texture_get_resource(dst
->wined3d_texture
), dst
->sub_resource_idx
, dst_point
? dst_point
->x
: 0,
1553 dst_point
? dst_point
->y
: 0, 0, wined3d_texture_get_resource(src
->wined3d_texture
),
1554 src
->sub_resource_idx
, &src_box
, 0);
1555 if (SUCCEEDED(hr
) && dst
->texture
)
1556 d3d9_texture_flag_auto_gen_mipmap(dst
->texture
);
1558 wined3d_mutex_unlock();
1561 return D3DERR_INVALIDCALL
;
1566 static HRESULT WINAPI
d3d9_device_UpdateTexture(IDirect3DDevice9Ex
*iface
,
1567 IDirect3DBaseTexture9
*src_texture
, IDirect3DBaseTexture9
*dst_texture
)
1569 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1570 struct d3d9_texture
*src_impl
, *dst_impl
;
1573 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface
, src_texture
, dst_texture
);
1575 src_impl
= unsafe_impl_from_IDirect3DBaseTexture9(src_texture
);
1576 dst_impl
= unsafe_impl_from_IDirect3DBaseTexture9(dst_texture
);
1578 wined3d_mutex_lock();
1579 hr
= wined3d_device_update_texture(device
->wined3d_device
,
1580 src_impl
->wined3d_texture
, dst_impl
->wined3d_texture
);
1582 d3d9_texture_flag_auto_gen_mipmap(dst_impl
);
1583 wined3d_mutex_unlock();
1588 static HRESULT WINAPI
d3d9_device_GetRenderTargetData(IDirect3DDevice9Ex
*iface
,
1589 IDirect3DSurface9
*render_target
, IDirect3DSurface9
*dst_surface
)
1591 struct d3d9_surface
*rt_impl
= unsafe_impl_from_IDirect3DSurface9(render_target
);
1592 struct d3d9_surface
*dst_impl
= unsafe_impl_from_IDirect3DSurface9(dst_surface
);
1593 struct wined3d_sub_resource_desc wined3d_desc
;
1594 RECT dst_rect
, src_rect
;
1597 TRACE("iface %p, render_target %p, dst_surface %p.\n", iface
, render_target
, dst_surface
);
1599 if (!render_target
|| !dst_surface
)
1600 return D3DERR_INVALIDCALL
;
1602 wined3d_mutex_lock();
1603 wined3d_texture_get_sub_resource_desc(dst_impl
->wined3d_texture
, dst_impl
->sub_resource_idx
, &wined3d_desc
);
1604 SetRect(&dst_rect
, 0, 0, wined3d_desc
.width
, wined3d_desc
.height
);
1606 wined3d_texture_get_sub_resource_desc(rt_impl
->wined3d_texture
, rt_impl
->sub_resource_idx
, &wined3d_desc
);
1607 SetRect(&src_rect
, 0, 0, wined3d_desc
.width
, wined3d_desc
.height
);
1609 /* TODO: Check surface sizes, pools, etc. */
1610 if (wined3d_desc
.multisample_type
)
1611 hr
= D3DERR_INVALIDCALL
;
1613 hr
= wined3d_texture_blt(dst_impl
->wined3d_texture
, dst_impl
->sub_resource_idx
, &dst_rect
,
1614 rt_impl
->wined3d_texture
, rt_impl
->sub_resource_idx
, &src_rect
, 0, NULL
, WINED3D_TEXF_POINT
);
1615 wined3d_mutex_unlock();
1620 static HRESULT WINAPI
d3d9_device_GetFrontBufferData(IDirect3DDevice9Ex
*iface
,
1621 UINT swapchain
, IDirect3DSurface9
*dst_surface
)
1623 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1624 struct d3d9_surface
*dst_impl
= unsafe_impl_from_IDirect3DSurface9(dst_surface
);
1625 HRESULT hr
= D3DERR_INVALIDCALL
;
1627 TRACE("iface %p, swapchain %u, dst_surface %p.\n", iface
, swapchain
, dst_surface
);
1629 wined3d_mutex_lock();
1630 if (swapchain
< device
->implicit_swapchain_count
)
1631 hr
= wined3d_swapchain_get_front_buffer_data(device
->implicit_swapchains
[swapchain
]->wined3d_swapchain
,
1632 dst_impl
->wined3d_texture
, dst_impl
->sub_resource_idx
);
1633 wined3d_mutex_unlock();
1638 static HRESULT WINAPI
d3d9_device_StretchRect(IDirect3DDevice9Ex
*iface
, IDirect3DSurface9
*src_surface
,
1639 const RECT
*src_rect
, IDirect3DSurface9
*dst_surface
, const RECT
*dst_rect
, D3DTEXTUREFILTERTYPE filter
)
1641 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1642 struct d3d9_surface
*src
= unsafe_impl_from_IDirect3DSurface9(src_surface
);
1643 struct d3d9_surface
*dst
= unsafe_impl_from_IDirect3DSurface9(dst_surface
);
1644 struct wined3d_sub_resource_desc src_desc
, dst_desc
;
1645 HRESULT hr
= D3DERR_INVALIDCALL
;
1648 TRACE("iface %p, src_surface %p, src_rect %s, dst_surface %p, dst_rect %s, filter %#x.\n",
1649 iface
, src_surface
, wine_dbgstr_rect(src_rect
), dst_surface
, wine_dbgstr_rect(dst_rect
), filter
);
1651 wined3d_mutex_lock();
1652 wined3d_texture_get_sub_resource_desc(dst
->wined3d_texture
, dst
->sub_resource_idx
, &dst_desc
);
1655 SetRect(&d
, 0, 0, dst_desc
.width
, dst_desc
.height
);
1659 wined3d_texture_get_sub_resource_desc(src
->wined3d_texture
, src
->sub_resource_idx
, &src_desc
);
1662 SetRect(&s
, 0, 0, src_desc
.width
, src_desc
.height
);
1666 if (dst_desc
.access
& WINED3D_RESOURCE_ACCESS_CPU
)
1668 WARN("Destination resource is not in DEFAULT pool.\n");
1671 if (src_desc
.access
& WINED3D_RESOURCE_ACCESS_CPU
)
1673 WARN("Source resource is not in DEFAULT pool.\n");
1677 if (dst
->texture
&& !(dst_desc
.bind_flags
& (WINED3D_BIND_RENDER_TARGET
| WINED3D_BIND_DEPTH_STENCIL
)))
1679 WARN("Destination is a regular texture.\n");
1683 if (src_desc
.bind_flags
& WINED3D_BIND_DEPTH_STENCIL
)
1685 if (device
->in_scene
)
1687 WARN("Rejecting depth / stencil blit while in scene.\n");
1691 if (src_rect
->left
|| src_rect
->top
|| src_rect
->right
!= src_desc
.width
1692 || src_rect
->bottom
!= src_desc
.height
)
1694 WARN("Rejecting depth / stencil blit with invalid source rect %s.\n",
1695 wine_dbgstr_rect(src_rect
));
1699 if (dst_rect
->left
|| dst_rect
->top
|| dst_rect
->right
!= dst_desc
.width
1700 || dst_rect
->bottom
!= dst_desc
.height
)
1702 WARN("Rejecting depth / stencil blit with invalid destination rect %s.\n",
1703 wine_dbgstr_rect(dst_rect
));
1707 if (src_desc
.width
!= dst_desc
.width
|| src_desc
.height
!= dst_desc
.height
)
1709 WARN("Rejecting depth / stencil blit with mismatched surface sizes.\n");
1714 hr
= wined3d_texture_blt(dst
->wined3d_texture
, dst
->sub_resource_idx
, dst_rect
,
1715 src
->wined3d_texture
, src
->sub_resource_idx
, src_rect
, 0, NULL
, filter
);
1716 if (hr
== WINEDDERR_INVALIDRECT
)
1717 hr
= D3DERR_INVALIDCALL
;
1718 if (SUCCEEDED(hr
) && dst
->texture
)
1719 d3d9_texture_flag_auto_gen_mipmap(dst
->texture
);
1722 wined3d_mutex_unlock();
1726 static HRESULT WINAPI
d3d9_device_ColorFill(IDirect3DDevice9Ex
*iface
,
1727 IDirect3DSurface9
*surface
, const RECT
*rect
, D3DCOLOR color
)
1729 const struct wined3d_color c
=
1731 ((color
>> 16) & 0xff) / 255.0f
,
1732 ((color
>> 8) & 0xff) / 255.0f
,
1733 (color
& 0xff) / 255.0f
,
1734 ((color
>> 24) & 0xff) / 255.0f
,
1736 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1737 struct d3d9_surface
*surface_impl
= unsafe_impl_from_IDirect3DSurface9(surface
);
1738 struct wined3d_sub_resource_desc desc
;
1739 struct wined3d_rendertarget_view
*rtv
;
1742 TRACE("iface %p, surface %p, rect %p, color 0x%08x.\n", iface
, surface
, rect
, color
);
1744 wined3d_mutex_lock();
1746 if (FAILED(wined3d_texture_get_sub_resource_desc(surface_impl
->wined3d_texture
,
1747 surface_impl
->sub_resource_idx
, &desc
)))
1749 wined3d_mutex_unlock();
1750 return D3DERR_INVALIDCALL
;
1753 if (desc
.access
& WINED3D_RESOURCE_ACCESS_CPU
)
1755 wined3d_mutex_unlock();
1756 WARN("Colour fills are not allowed on surfaces with resource access %#x.\n", desc
.access
);
1757 return D3DERR_INVALIDCALL
;
1759 if ((desc
.bind_flags
& (WINED3D_BIND_RENDER_TARGET
| WINED3D_BIND_SHADER_RESOURCE
)) == WINED3D_BIND_SHADER_RESOURCE
)
1761 wined3d_mutex_unlock();
1762 WARN("Colorfill is not allowed on non-RT textures, returning D3DERR_INVALIDCALL.\n");
1763 return D3DERR_INVALIDCALL
;
1765 if (desc
.bind_flags
& WINED3D_BIND_DEPTH_STENCIL
)
1767 wined3d_mutex_unlock();
1768 WARN("Colorfill is not allowed on depth stencil surfaces, returning D3DERR_INVALIDCALL.\n");
1769 return D3DERR_INVALIDCALL
;
1772 rtv
= d3d9_surface_acquire_rendertarget_view(surface_impl
);
1773 hr
= wined3d_device_clear_rendertarget_view(device
->wined3d_device
,
1774 rtv
, rect
, WINED3DCLEAR_TARGET
, &c
, 0.0f
, 0);
1775 d3d9_surface_release_rendertarget_view(surface_impl
, rtv
);
1776 if (SUCCEEDED(hr
) && surface_impl
->texture
)
1777 d3d9_texture_flag_auto_gen_mipmap(surface_impl
->texture
);
1779 wined3d_mutex_unlock();
1784 static HRESULT WINAPI
d3d9_device_CreateOffscreenPlainSurface(IDirect3DDevice9Ex
*iface
,
1785 UINT width
, UINT height
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DSurface9
**surface
,
1786 HANDLE
*shared_handle
)
1788 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1789 void *user_mem
= NULL
;
1791 TRACE("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p.\n",
1792 iface
, width
, height
, format
, pool
, surface
, shared_handle
);
1795 if (pool
== D3DPOOL_MANAGED
)
1797 WARN("Attempting to create a managed offscreen plain surface.\n");
1798 return D3DERR_INVALIDCALL
;
1803 if (!device
->d3d_parent
->extended
)
1805 WARN("Trying to create a shared or user memory surface on a non-ex device.\n");
1809 if (pool
== D3DPOOL_SYSTEMMEM
)
1810 user_mem
= *shared_handle
;
1813 if (pool
!= D3DPOOL_DEFAULT
)
1815 WARN("Trying to create a shared surface in pool %#x.\n", pool
);
1816 return D3DERR_INVALIDCALL
;
1818 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1822 return d3d9_device_create_surface(device
, width
, height
, format
,
1823 WINED3D_TEXTURE_CREATE_MAPPABLE
, surface
, 0, pool
, D3DMULTISAMPLE_NONE
, 0, user_mem
);
1826 static HRESULT WINAPI
d3d9_device_SetRenderTarget(IDirect3DDevice9Ex
*iface
, DWORD idx
, IDirect3DSurface9
*surface
)
1828 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1829 struct d3d9_surface
*surface_impl
= unsafe_impl_from_IDirect3DSurface9(surface
);
1830 struct wined3d_rendertarget_view
*rtv
;
1833 TRACE("iface %p, idx %u, surface %p.\n", iface
, idx
, surface
);
1835 if (idx
>= D3D_MAX_SIMULTANEOUS_RENDERTARGETS
)
1837 WARN("Invalid index %u specified.\n", idx
);
1838 return D3DERR_INVALIDCALL
;
1841 if (!idx
&& !surface_impl
)
1843 WARN("Trying to set render target 0 to NULL.\n");
1844 return D3DERR_INVALIDCALL
;
1847 if (surface_impl
&& d3d9_surface_get_device(surface_impl
) != device
)
1849 WARN("Render target surface does not match device.\n");
1850 return D3DERR_INVALIDCALL
;
1853 wined3d_mutex_lock();
1854 rtv
= surface_impl
? d3d9_surface_acquire_rendertarget_view(surface_impl
) : NULL
;
1855 hr
= wined3d_device_set_rendertarget_view(device
->wined3d_device
, idx
, rtv
, TRUE
);
1856 d3d9_surface_release_rendertarget_view(surface_impl
, rtv
);
1858 device
->render_targets
[idx
] = surface_impl
;
1859 wined3d_mutex_unlock();
1864 static HRESULT WINAPI
d3d9_device_GetRenderTarget(IDirect3DDevice9Ex
*iface
, DWORD idx
, IDirect3DSurface9
**surface
)
1866 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1867 struct wined3d_rendertarget_view
*wined3d_rtv
;
1868 struct d3d9_surface
*surface_impl
;
1869 HRESULT hr
= D3D_OK
;
1871 TRACE("iface %p, idx %u, surface %p.\n", iface
, idx
, surface
);
1874 return D3DERR_INVALIDCALL
;
1876 if (idx
>= D3D_MAX_SIMULTANEOUS_RENDERTARGETS
)
1878 WARN("Invalid index %u specified.\n", idx
);
1879 return D3DERR_INVALIDCALL
;
1882 wined3d_mutex_lock();
1883 if ((wined3d_rtv
= wined3d_device_get_rendertarget_view(device
->wined3d_device
, idx
)))
1885 /* We want the sub resource parent here, since the view itself may be
1886 * internal to wined3d and may not have a parent. */
1887 surface_impl
= wined3d_rendertarget_view_get_sub_resource_parent(wined3d_rtv
);
1888 *surface
= &surface_impl
->IDirect3DSurface9_iface
;
1889 IDirect3DSurface9_AddRef(*surface
);
1893 hr
= D3DERR_NOTFOUND
;
1896 wined3d_mutex_unlock();
1901 static HRESULT WINAPI
d3d9_device_SetDepthStencilSurface(IDirect3DDevice9Ex
*iface
, IDirect3DSurface9
*depth_stencil
)
1903 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1904 struct d3d9_surface
*ds_impl
= unsafe_impl_from_IDirect3DSurface9(depth_stencil
);
1905 struct wined3d_rendertarget_view
*rtv
;
1907 TRACE("iface %p, depth_stencil %p.\n", iface
, depth_stencil
);
1909 wined3d_mutex_lock();
1910 rtv
= ds_impl
? d3d9_surface_acquire_rendertarget_view(ds_impl
) : NULL
;
1911 wined3d_device_set_depth_stencil_view(device
->wined3d_device
, rtv
);
1912 d3d9_surface_release_rendertarget_view(ds_impl
, rtv
);
1913 wined3d_mutex_unlock();
1918 static HRESULT WINAPI
d3d9_device_GetDepthStencilSurface(IDirect3DDevice9Ex
*iface
, IDirect3DSurface9
**depth_stencil
)
1920 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1921 struct wined3d_rendertarget_view
*wined3d_dsv
;
1922 struct d3d9_surface
*surface_impl
;
1923 HRESULT hr
= D3D_OK
;
1925 TRACE("iface %p, depth_stencil %p.\n", iface
, depth_stencil
);
1928 return D3DERR_INVALIDCALL
;
1930 wined3d_mutex_lock();
1931 if ((wined3d_dsv
= wined3d_device_get_depth_stencil_view(device
->wined3d_device
)))
1933 /* We want the sub resource parent here, since the view itself may be
1934 * internal to wined3d and may not have a parent. */
1935 surface_impl
= wined3d_rendertarget_view_get_sub_resource_parent(wined3d_dsv
);
1936 *depth_stencil
= &surface_impl
->IDirect3DSurface9_iface
;
1937 IDirect3DSurface9_AddRef(*depth_stencil
);
1941 hr
= D3DERR_NOTFOUND
;
1942 *depth_stencil
= NULL
;
1944 wined3d_mutex_unlock();
1949 static HRESULT WINAPI
d3d9_device_BeginScene(IDirect3DDevice9Ex
*iface
)
1951 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1954 TRACE("iface %p.\n", iface
);
1956 wined3d_mutex_lock();
1957 if (SUCCEEDED(hr
= wined3d_device_begin_scene(device
->wined3d_device
)))
1958 device
->in_scene
= TRUE
;
1959 wined3d_mutex_unlock();
1964 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_EndScene(IDirect3DDevice9Ex
*iface
)
1966 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1969 TRACE("iface %p.\n", iface
);
1971 wined3d_mutex_lock();
1972 if (SUCCEEDED(hr
= wined3d_device_end_scene(device
->wined3d_device
)))
1973 device
->in_scene
= FALSE
;
1974 wined3d_mutex_unlock();
1979 static void d3d9_rts_flag_auto_gen_mipmap(struct d3d9_device
*device
)
1983 for (i
= 0; i
< ARRAY_SIZE(device
->render_targets
); ++i
)
1985 struct d3d9_surface
*surface
= device
->render_targets
[i
];
1987 if (surface
&& surface
->texture
)
1988 d3d9_texture_flag_auto_gen_mipmap(surface
->texture
);
1992 static HRESULT WINAPI
d3d9_device_Clear(IDirect3DDevice9Ex
*iface
, DWORD rect_count
,
1993 const D3DRECT
*rects
, DWORD flags
, D3DCOLOR color
, float z
, DWORD stencil
)
1995 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1996 struct wined3d_color c
;
1999 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
2000 iface
, rect_count
, rects
, flags
, color
, z
, stencil
);
2002 if (rect_count
&& !rects
)
2004 WARN("count %u with NULL rects.\n", rect_count
);
2008 wined3d_color_from_d3dcolor(&c
, color
);
2009 wined3d_mutex_lock();
2010 hr
= wined3d_device_clear(device
->wined3d_device
, rect_count
, (const RECT
*)rects
, flags
, &c
, z
, stencil
);
2012 d3d9_rts_flag_auto_gen_mipmap(device
);
2013 wined3d_mutex_unlock();
2018 static HRESULT WINAPI
d3d9_device_SetTransform(IDirect3DDevice9Ex
*iface
,
2019 D3DTRANSFORMSTATETYPE state
, const D3DMATRIX
*matrix
)
2021 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2023 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
2025 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
2026 wined3d_mutex_lock();
2027 wined3d_device_set_transform(device
->wined3d_device
, state
, (const struct wined3d_matrix
*)matrix
);
2028 wined3d_mutex_unlock();
2033 static HRESULT WINAPI
d3d9_device_GetTransform(IDirect3DDevice9Ex
*iface
,
2034 D3DTRANSFORMSTATETYPE state
, D3DMATRIX
*matrix
)
2036 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2038 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
2040 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
2041 wined3d_mutex_lock();
2042 wined3d_device_get_transform(device
->wined3d_device
, state
, (struct wined3d_matrix
*)matrix
);
2043 wined3d_mutex_unlock();
2048 static HRESULT WINAPI
d3d9_device_MultiplyTransform(IDirect3DDevice9Ex
*iface
,
2049 D3DTRANSFORMSTATETYPE state
, const D3DMATRIX
*matrix
)
2051 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2053 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
2055 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
2056 wined3d_mutex_lock();
2057 wined3d_device_multiply_transform(device
->wined3d_device
, state
, (const struct wined3d_matrix
*)matrix
);
2058 wined3d_mutex_unlock();
2063 static HRESULT WINAPI
d3d9_device_SetViewport(IDirect3DDevice9Ex
*iface
, const D3DVIEWPORT9
*viewport
)
2065 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2066 struct wined3d_viewport vp
;
2068 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
2072 vp
.width
= viewport
->Width
;
2073 vp
.height
= viewport
->Height
;
2074 vp
.min_z
= viewport
->MinZ
;
2075 vp
.max_z
= viewport
->MaxZ
;
2077 wined3d_mutex_lock();
2078 wined3d_device_set_viewports(device
->wined3d_device
, 1, &vp
);
2079 wined3d_mutex_unlock();
2084 static HRESULT WINAPI
d3d9_device_GetViewport(IDirect3DDevice9Ex
*iface
, D3DVIEWPORT9
*viewport
)
2086 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2087 struct wined3d_viewport wined3d_viewport
;
2089 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
2091 wined3d_mutex_lock();
2092 wined3d_device_get_viewports(device
->wined3d_device
, NULL
, &wined3d_viewport
);
2093 wined3d_mutex_unlock();
2095 viewport
->X
= wined3d_viewport
.x
;
2096 viewport
->Y
= wined3d_viewport
.y
;
2097 viewport
->Width
= wined3d_viewport
.width
;
2098 viewport
->Height
= wined3d_viewport
.height
;
2099 viewport
->MinZ
= wined3d_viewport
.min_z
;
2100 viewport
->MaxZ
= wined3d_viewport
.max_z
;
2105 static HRESULT WINAPI
d3d9_device_SetMaterial(IDirect3DDevice9Ex
*iface
, const D3DMATERIAL9
*material
)
2107 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2109 TRACE("iface %p, material %p.\n", iface
, material
);
2111 /* Note: D3DMATERIAL9 is compatible with struct wined3d_material. */
2112 wined3d_mutex_lock();
2113 wined3d_device_set_material(device
->wined3d_device
, (const struct wined3d_material
*)material
);
2114 wined3d_mutex_unlock();
2119 static HRESULT WINAPI
d3d9_device_GetMaterial(IDirect3DDevice9Ex
*iface
, D3DMATERIAL9
*material
)
2121 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2123 TRACE("iface %p, material %p.\n", iface
, material
);
2125 /* Note: D3DMATERIAL9 is compatible with struct wined3d_material. */
2126 wined3d_mutex_lock();
2127 wined3d_device_get_material(device
->wined3d_device
, (struct wined3d_material
*)material
);
2128 wined3d_mutex_unlock();
2133 static HRESULT WINAPI
d3d9_device_SetLight(IDirect3DDevice9Ex
*iface
, DWORD index
, const D3DLIGHT9
*light
)
2135 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2138 TRACE("iface %p, index %u, light %p.\n", iface
, index
, light
);
2140 /* Note: D3DLIGHT9 is compatible with struct wined3d_light. */
2141 wined3d_mutex_lock();
2142 hr
= wined3d_device_set_light(device
->wined3d_device
, index
, (const struct wined3d_light
*)light
);
2143 wined3d_mutex_unlock();
2148 static HRESULT WINAPI
d3d9_device_GetLight(IDirect3DDevice9Ex
*iface
, DWORD index
, D3DLIGHT9
*light
)
2150 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2153 TRACE("iface %p, index %u, light %p.\n", iface
, index
, light
);
2155 /* Note: D3DLIGHT9 is compatible with struct wined3d_light. */
2156 wined3d_mutex_lock();
2157 hr
= wined3d_device_get_light(device
->wined3d_device
, index
, (struct wined3d_light
*)light
);
2158 wined3d_mutex_unlock();
2163 static HRESULT WINAPI
d3d9_device_LightEnable(IDirect3DDevice9Ex
*iface
, DWORD index
, BOOL enable
)
2165 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2168 TRACE("iface %p, index %u, enable %#x.\n", iface
, index
, enable
);
2170 wined3d_mutex_lock();
2171 hr
= wined3d_device_set_light_enable(device
->wined3d_device
, index
, enable
);
2172 wined3d_mutex_unlock();
2177 static HRESULT WINAPI
d3d9_device_GetLightEnable(IDirect3DDevice9Ex
*iface
, DWORD index
, BOOL
*enable
)
2179 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2182 TRACE("iface %p, index %u, enable %p.\n", iface
, index
, enable
);
2184 wined3d_mutex_lock();
2185 hr
= wined3d_device_get_light_enable(device
->wined3d_device
, index
, enable
);
2186 wined3d_mutex_unlock();
2191 static HRESULT WINAPI
d3d9_device_SetClipPlane(IDirect3DDevice9Ex
*iface
, DWORD index
, const float *plane
)
2193 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2196 TRACE("iface %p, index %u, plane %p.\n", iface
, index
, plane
);
2198 index
= min(index
, device
->max_user_clip_planes
- 1);
2200 wined3d_mutex_lock();
2201 hr
= wined3d_device_set_clip_plane(device
->wined3d_device
, index
, (const struct wined3d_vec4
*)plane
);
2202 wined3d_mutex_unlock();
2207 static HRESULT WINAPI
d3d9_device_GetClipPlane(IDirect3DDevice9Ex
*iface
, DWORD index
, float *plane
)
2209 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2212 TRACE("iface %p, index %u, plane %p.\n", iface
, index
, plane
);
2214 index
= min(index
, device
->max_user_clip_planes
- 1);
2216 wined3d_mutex_lock();
2217 hr
= wined3d_device_get_clip_plane(device
->wined3d_device
, index
, (struct wined3d_vec4
*)plane
);
2218 wined3d_mutex_unlock();
2223 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_SetRenderState(IDirect3DDevice9Ex
*iface
,
2224 D3DRENDERSTATETYPE state
, DWORD value
)
2226 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2227 struct wined3d_color factor
;
2229 TRACE("iface %p, state %#x, value %#x.\n", iface
, state
, value
);
2231 if (state
== D3DRS_BLENDFACTOR
)
2233 wined3d_color_from_d3dcolor(&factor
, value
);
2234 wined3d_mutex_lock();
2235 wined3d_device_set_blend_state(device
->wined3d_device
, NULL
, &factor
);
2236 wined3d_mutex_unlock();
2241 wined3d_mutex_lock();
2242 wined3d_device_set_render_state(device
->wined3d_device
, state
, value
);
2243 wined3d_mutex_unlock();
2248 static HRESULT WINAPI
d3d9_device_GetRenderState(IDirect3DDevice9Ex
*iface
,
2249 D3DRENDERSTATETYPE state
, DWORD
*value
)
2251 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2252 struct wined3d_color factor
;
2254 TRACE("iface %p, state %#x, value %p.\n", iface
, state
, value
);
2256 if (state
== D3DRS_BLENDFACTOR
)
2258 wined3d_mutex_lock();
2259 wined3d_device_get_blend_state(device
->wined3d_device
, &factor
);
2260 wined3d_mutex_unlock();
2261 *value
= D3DCOLOR_COLORVALUE(factor
.r
, factor
.g
, factor
.b
, factor
.a
);
2266 wined3d_mutex_lock();
2267 *value
= wined3d_device_get_render_state(device
->wined3d_device
, state
);
2268 wined3d_mutex_unlock();
2273 static HRESULT WINAPI
d3d9_device_CreateStateBlock(IDirect3DDevice9Ex
*iface
,
2274 D3DSTATEBLOCKTYPE type
, IDirect3DStateBlock9
**stateblock
)
2276 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2277 struct d3d9_stateblock
*object
;
2280 TRACE("iface %p, type %#x, stateblock %p.\n", iface
, type
, stateblock
);
2282 if (type
!= D3DSBT_ALL
&& type
!= D3DSBT_PIXELSTATE
&& type
!= D3DSBT_VERTEXSTATE
)
2284 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL.\n");
2285 return D3DERR_INVALIDCALL
;
2288 if (!(object
= heap_alloc_zero(sizeof(*object
))))
2289 return E_OUTOFMEMORY
;
2291 hr
= stateblock_init(object
, device
, type
, NULL
);
2294 WARN("Failed to initialize stateblock, hr %#x.\n", hr
);
2299 TRACE("Created stateblock %p.\n", object
);
2300 *stateblock
= &object
->IDirect3DStateBlock9_iface
;
2305 static HRESULT WINAPI
d3d9_device_BeginStateBlock(IDirect3DDevice9Ex
*iface
)
2307 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2310 TRACE("iface %p.\n", iface
);
2312 wined3d_mutex_lock();
2313 hr
= wined3d_device_begin_stateblock(device
->wined3d_device
);
2314 wined3d_mutex_unlock();
2319 static HRESULT WINAPI
d3d9_device_EndStateBlock(IDirect3DDevice9Ex
*iface
, IDirect3DStateBlock9
**stateblock
)
2321 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2322 struct wined3d_stateblock
*wined3d_stateblock
;
2323 struct d3d9_stateblock
*object
;
2326 TRACE("iface %p, stateblock %p.\n", iface
, stateblock
);
2328 wined3d_mutex_lock();
2329 hr
= wined3d_device_end_stateblock(device
->wined3d_device
, &wined3d_stateblock
);
2330 wined3d_mutex_unlock();
2333 WARN("Failed to end the state block, hr %#x.\n", hr
);
2337 if (!(object
= heap_alloc_zero(sizeof(*object
))))
2339 wined3d_mutex_lock();
2340 wined3d_stateblock_decref(wined3d_stateblock
);
2341 wined3d_mutex_unlock();
2342 return E_OUTOFMEMORY
;
2345 hr
= stateblock_init(object
, device
, 0, wined3d_stateblock
);
2348 WARN("Failed to initialize stateblock, hr %#x.\n", hr
);
2349 wined3d_mutex_lock();
2350 wined3d_stateblock_decref(wined3d_stateblock
);
2351 wined3d_mutex_unlock();
2356 TRACE("Created stateblock %p.\n", object
);
2357 *stateblock
= &object
->IDirect3DStateBlock9_iface
;
2362 static HRESULT WINAPI
d3d9_device_SetClipStatus(IDirect3DDevice9Ex
*iface
, const D3DCLIPSTATUS9
*clip_status
)
2364 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2367 TRACE("iface %p, clip_status %p.\n", iface
, clip_status
);
2369 wined3d_mutex_lock();
2370 hr
= wined3d_device_set_clip_status(device
->wined3d_device
, (const struct wined3d_clip_status
*)clip_status
);
2371 wined3d_mutex_unlock();
2376 static HRESULT WINAPI
d3d9_device_GetClipStatus(IDirect3DDevice9Ex
*iface
, D3DCLIPSTATUS9
*clip_status
)
2378 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2381 TRACE("iface %p, clip_status %p.\n", iface
, clip_status
);
2383 wined3d_mutex_lock();
2384 hr
= wined3d_device_get_clip_status(device
->wined3d_device
, (struct wined3d_clip_status
*)clip_status
);
2385 wined3d_mutex_unlock();
2390 static HRESULT WINAPI
d3d9_device_GetTexture(IDirect3DDevice9Ex
*iface
, DWORD stage
, IDirect3DBaseTexture9
**texture
)
2392 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2393 struct wined3d_texture
*wined3d_texture
= NULL
;
2394 struct d3d9_texture
*texture_impl
;
2396 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
2399 return D3DERR_INVALIDCALL
;
2401 wined3d_mutex_lock();
2402 if ((wined3d_texture
= wined3d_device_get_texture(device
->wined3d_device
, stage
)))
2404 texture_impl
= wined3d_texture_get_parent(wined3d_texture
);
2405 *texture
= &texture_impl
->IDirect3DBaseTexture9_iface
;
2406 IDirect3DBaseTexture9_AddRef(*texture
);
2412 wined3d_mutex_unlock();
2417 static HRESULT WINAPI
d3d9_device_SetTexture(IDirect3DDevice9Ex
*iface
, DWORD stage
, IDirect3DBaseTexture9
*texture
)
2419 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2420 struct d3d9_texture
*texture_impl
;
2423 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
2425 texture_impl
= unsafe_impl_from_IDirect3DBaseTexture9(texture
);
2427 wined3d_mutex_lock();
2428 hr
= wined3d_device_set_texture(device
->wined3d_device
, stage
,
2429 texture_impl
? texture_impl
->wined3d_texture
: NULL
);
2430 wined3d_mutex_unlock();
2435 static const enum wined3d_texture_stage_state tss_lookup
[] =
2437 WINED3D_TSS_INVALID
, /* 0, unused */
2438 WINED3D_TSS_COLOR_OP
, /* 1, D3DTSS_COLOROP */
2439 WINED3D_TSS_COLOR_ARG1
, /* 2, D3DTSS_COLORARG1 */
2440 WINED3D_TSS_COLOR_ARG2
, /* 3, D3DTSS_COLORARG2 */
2441 WINED3D_TSS_ALPHA_OP
, /* 4, D3DTSS_ALPHAOP */
2442 WINED3D_TSS_ALPHA_ARG1
, /* 5, D3DTSS_ALPHAARG1 */
2443 WINED3D_TSS_ALPHA_ARG2
, /* 6, D3DTSS_ALPHAARG2 */
2444 WINED3D_TSS_BUMPENV_MAT00
, /* 7, D3DTSS_BUMPENVMAT00 */
2445 WINED3D_TSS_BUMPENV_MAT01
, /* 8, D3DTSS_BUMPENVMAT01 */
2446 WINED3D_TSS_BUMPENV_MAT10
, /* 9, D3DTSS_BUMPENVMAT10 */
2447 WINED3D_TSS_BUMPENV_MAT11
, /* 10, D3DTSS_BUMPENVMAT11 */
2448 WINED3D_TSS_TEXCOORD_INDEX
, /* 11, D3DTSS_TEXCOORDINDEX */
2449 WINED3D_TSS_INVALID
, /* 12, unused */
2450 WINED3D_TSS_INVALID
, /* 13, unused */
2451 WINED3D_TSS_INVALID
, /* 14, unused */
2452 WINED3D_TSS_INVALID
, /* 15, unused */
2453 WINED3D_TSS_INVALID
, /* 16, unused */
2454 WINED3D_TSS_INVALID
, /* 17, unused */
2455 WINED3D_TSS_INVALID
, /* 18, unused */
2456 WINED3D_TSS_INVALID
, /* 19, unused */
2457 WINED3D_TSS_INVALID
, /* 20, unused */
2458 WINED3D_TSS_INVALID
, /* 21, unused */
2459 WINED3D_TSS_BUMPENV_LSCALE
, /* 22, D3DTSS_BUMPENVLSCALE */
2460 WINED3D_TSS_BUMPENV_LOFFSET
, /* 23, D3DTSS_BUMPENVLOFFSET */
2461 WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
2462 WINED3D_TSS_INVALID
, /* 25, unused */
2463 WINED3D_TSS_COLOR_ARG0
, /* 26, D3DTSS_COLORARG0 */
2464 WINED3D_TSS_ALPHA_ARG0
, /* 27, D3DTSS_ALPHAARG0 */
2465 WINED3D_TSS_RESULT_ARG
, /* 28, D3DTSS_RESULTARG */
2466 WINED3D_TSS_INVALID
, /* 29, unused */
2467 WINED3D_TSS_INVALID
, /* 30, unused */
2468 WINED3D_TSS_INVALID
, /* 31, unused */
2469 WINED3D_TSS_CONSTANT
, /* 32, D3DTSS_CONSTANT */
2472 static HRESULT WINAPI
d3d9_device_GetTextureStageState(IDirect3DDevice9Ex
*iface
,
2473 DWORD stage
, D3DTEXTURESTAGESTATETYPE state
, DWORD
*value
)
2475 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2477 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface
, stage
, state
, value
);
2479 if (state
>= ARRAY_SIZE(tss_lookup
))
2481 WARN("Invalid state %#x passed.\n", state
);
2485 wined3d_mutex_lock();
2486 *value
= wined3d_device_get_texture_stage_state(device
->wined3d_device
, stage
, tss_lookup
[state
]);
2487 wined3d_mutex_unlock();
2492 static HRESULT WINAPI
d3d9_device_SetTextureStageState(IDirect3DDevice9Ex
*iface
,
2493 DWORD stage
, D3DTEXTURESTAGESTATETYPE state
, DWORD value
)
2495 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2497 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface
, stage
, state
, value
);
2499 if (state
>= ARRAY_SIZE(tss_lookup
))
2501 WARN("Invalid state %#x passed.\n", state
);
2505 wined3d_mutex_lock();
2506 wined3d_device_set_texture_stage_state(device
->wined3d_device
, stage
, tss_lookup
[state
], value
);
2507 wined3d_mutex_unlock();
2512 static HRESULT WINAPI
d3d9_device_GetSamplerState(IDirect3DDevice9Ex
*iface
,
2513 DWORD sampler
, D3DSAMPLERSTATETYPE state
, DWORD
*value
)
2515 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2517 TRACE("iface %p, sampler %u, state %#x, value %p.\n", iface
, sampler
, state
, value
);
2519 wined3d_mutex_lock();
2520 *value
= wined3d_device_get_sampler_state(device
->wined3d_device
, sampler
, state
);
2521 wined3d_mutex_unlock();
2526 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_SetSamplerState(IDirect3DDevice9Ex
*iface
,
2527 DWORD sampler
, D3DSAMPLERSTATETYPE state
, DWORD value
)
2529 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2531 TRACE("iface %p, sampler %u, state %#x, value %#x.\n", iface
, sampler
, state
, value
);
2533 wined3d_mutex_lock();
2534 wined3d_device_set_sampler_state(device
->wined3d_device
, sampler
, state
, value
);
2535 wined3d_mutex_unlock();
2540 static HRESULT WINAPI
d3d9_device_ValidateDevice(IDirect3DDevice9Ex
*iface
, DWORD
*pass_count
)
2542 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2545 TRACE("iface %p, pass_count %p.\n", iface
, pass_count
);
2547 wined3d_mutex_lock();
2548 hr
= wined3d_device_validate_device(device
->wined3d_device
, pass_count
);
2549 wined3d_mutex_unlock();
2554 static HRESULT WINAPI
d3d9_device_SetPaletteEntries(IDirect3DDevice9Ex
*iface
,
2555 UINT palette_idx
, const PALETTEENTRY
*entries
)
2557 WARN("iface %p, palette_idx %u, entries %p unimplemented.\n", iface
, palette_idx
, entries
);
2559 /* The d3d9 palette API is non-functional on Windows. Getters and setters are implemented,
2560 * and some drivers allow the creation of P8 surfaces. These surfaces can be copied to
2561 * other P8 surfaces with StretchRect, but cannot be converted to (A)RGB.
2563 * Some older(dx7) cards may have support for P8 textures, but games cannot rely on this. */
2567 static HRESULT WINAPI
d3d9_device_GetPaletteEntries(IDirect3DDevice9Ex
*iface
,
2568 UINT palette_idx
, PALETTEENTRY
*entries
)
2570 FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface
, palette_idx
, entries
);
2572 return D3DERR_INVALIDCALL
;
2575 static HRESULT WINAPI
d3d9_device_SetCurrentTexturePalette(IDirect3DDevice9Ex
*iface
, UINT palette_idx
)
2577 WARN("iface %p, palette_idx %u unimplemented.\n", iface
, palette_idx
);
2582 static HRESULT WINAPI
d3d9_device_GetCurrentTexturePalette(IDirect3DDevice9Ex
*iface
, UINT
*palette_idx
)
2584 FIXME("iface %p, palette_idx %p.\n", iface
, palette_idx
);
2586 return D3DERR_INVALIDCALL
;
2589 static HRESULT WINAPI
d3d9_device_SetScissorRect(IDirect3DDevice9Ex
*iface
, const RECT
*rect
)
2591 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2593 TRACE("iface %p, rect %p.\n", iface
, rect
);
2595 wined3d_mutex_lock();
2596 wined3d_device_set_scissor_rects(device
->wined3d_device
, 1, rect
);
2597 wined3d_mutex_unlock();
2602 static HRESULT WINAPI
d3d9_device_GetScissorRect(IDirect3DDevice9Ex
*iface
, RECT
*rect
)
2604 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2606 TRACE("iface %p, rect %p.\n", iface
, rect
);
2608 wined3d_mutex_lock();
2609 wined3d_device_get_scissor_rects(device
->wined3d_device
, NULL
, rect
);
2610 wined3d_mutex_unlock();
2615 static HRESULT WINAPI
d3d9_device_SetSoftwareVertexProcessing(IDirect3DDevice9Ex
*iface
, BOOL software
)
2617 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2619 TRACE("iface %p, software %#x.\n", iface
, software
);
2621 wined3d_mutex_lock();
2622 wined3d_device_set_software_vertex_processing(device
->wined3d_device
, software
);
2623 wined3d_mutex_unlock();
2628 static BOOL WINAPI
d3d9_device_GetSoftwareVertexProcessing(IDirect3DDevice9Ex
*iface
)
2630 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2633 TRACE("iface %p.\n", iface
);
2635 wined3d_mutex_lock();
2636 ret
= wined3d_device_get_software_vertex_processing(device
->wined3d_device
);
2637 wined3d_mutex_unlock();
2642 static HRESULT WINAPI
d3d9_device_SetNPatchMode(IDirect3DDevice9Ex
*iface
, float segment_count
)
2644 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2647 TRACE("iface %p, segment_count %.8e.\n", iface
, segment_count
);
2649 wined3d_mutex_lock();
2650 hr
= wined3d_device_set_npatch_mode(device
->wined3d_device
, segment_count
);
2651 wined3d_mutex_unlock();
2656 static float WINAPI
d3d9_device_GetNPatchMode(IDirect3DDevice9Ex
*iface
)
2658 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2661 TRACE("iface %p.\n", iface
);
2663 wined3d_mutex_lock();
2664 ret
= wined3d_device_get_npatch_mode(device
->wined3d_device
);
2665 wined3d_mutex_unlock();
2670 /* wined3d critical section must be taken by the caller. */
2671 static void d3d9_generate_auto_mipmaps(struct d3d9_device
*device
)
2673 struct wined3d_texture
*texture
;
2674 unsigned int i
, stage
;
2676 for (i
= 0; i
< D3D9_MAX_TEXTURE_UNITS
; ++i
)
2678 stage
= i
>= 16 ? i
- 16 + D3DVERTEXTEXTURESAMPLER0
: i
;
2679 if ((texture
= wined3d_device_get_texture(device
->wined3d_device
, stage
)))
2680 d3d9_texture_gen_auto_mipmap(wined3d_texture_get_parent(texture
));
2684 static HRESULT WINAPI
d3d9_device_DrawPrimitive(IDirect3DDevice9Ex
*iface
,
2685 D3DPRIMITIVETYPE primitive_type
, UINT start_vertex
, UINT primitive_count
)
2687 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2690 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
2691 iface
, primitive_type
, start_vertex
, primitive_count
);
2693 wined3d_mutex_lock();
2694 if (!device
->has_vertex_declaration
)
2696 wined3d_mutex_unlock();
2697 WARN("Called without a valid vertex declaration set.\n");
2698 return D3DERR_INVALIDCALL
;
2700 d3d9_generate_auto_mipmaps(device
);
2701 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
, 0);
2702 hr
= wined3d_device_draw_primitive(device
->wined3d_device
, start_vertex
,
2703 vertex_count_from_primitive_count(primitive_type
, primitive_count
));
2705 d3d9_rts_flag_auto_gen_mipmap(device
);
2706 wined3d_mutex_unlock();
2711 static HRESULT WINAPI
d3d9_device_DrawIndexedPrimitive(IDirect3DDevice9Ex
*iface
,
2712 D3DPRIMITIVETYPE primitive_type
, INT base_vertex_idx
, UINT min_vertex_idx
,
2713 UINT vertex_count
, UINT start_idx
, UINT primitive_count
)
2715 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2718 TRACE("iface %p, primitive_type %#x, base_vertex_idx %u, min_vertex_idx %u, "
2719 "vertex_count %u, start_idx %u, primitive_count %u.\n",
2720 iface
, primitive_type
, base_vertex_idx
, min_vertex_idx
,
2721 vertex_count
, start_idx
, primitive_count
);
2723 wined3d_mutex_lock();
2724 if (!device
->has_vertex_declaration
)
2726 wined3d_mutex_unlock();
2727 WARN("Called without a valid vertex declaration set.\n");
2728 return D3DERR_INVALIDCALL
;
2730 d3d9_generate_auto_mipmaps(device
);
2731 wined3d_device_set_base_vertex_index(device
->wined3d_device
, base_vertex_idx
);
2732 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
, 0);
2733 hr
= wined3d_device_draw_indexed_primitive(device
->wined3d_device
, start_idx
,
2734 vertex_count_from_primitive_count(primitive_type
, primitive_count
));
2736 d3d9_rts_flag_auto_gen_mipmap(device
);
2737 wined3d_mutex_unlock();
2742 /* The caller is responsible for wined3d locking */
2743 static HRESULT
d3d9_device_prepare_vertex_buffer(struct d3d9_device
*device
, UINT min_size
)
2747 if (device
->vertex_buffer_size
< min_size
|| !device
->vertex_buffer
)
2749 UINT size
= max(device
->vertex_buffer_size
* 2, min_size
);
2750 struct wined3d_buffer_desc desc
;
2751 struct wined3d_buffer
*buffer
;
2753 TRACE("Growing vertex buffer to %u bytes.\n", size
);
2755 desc
.byte_width
= size
;
2756 desc
.usage
= WINED3DUSAGE_DYNAMIC
| WINED3DUSAGE_WRITEONLY
;
2757 desc
.bind_flags
= WINED3D_BIND_VERTEX_BUFFER
;
2758 desc
.access
= WINED3D_RESOURCE_ACCESS_GPU
| WINED3D_RESOURCE_ACCESS_MAP_R
| WINED3D_RESOURCE_ACCESS_MAP_W
;
2759 desc
.misc_flags
= 0;
2760 desc
.structure_byte_stride
= 0;
2762 if (FAILED(hr
= wined3d_buffer_create(device
->wined3d_device
, &desc
,
2763 NULL
, NULL
, &d3d9_null_wined3d_parent_ops
, &buffer
)))
2765 ERR("Failed to create vertex buffer, hr %#x.\n", hr
);
2769 if (device
->vertex_buffer
)
2770 wined3d_buffer_decref(device
->vertex_buffer
);
2772 device
->vertex_buffer
= buffer
;
2773 device
->vertex_buffer_size
= size
;
2774 device
->vertex_buffer_pos
= 0;
2779 static HRESULT WINAPI
d3d9_device_DrawPrimitiveUP(IDirect3DDevice9Ex
*iface
,
2780 D3DPRIMITIVETYPE primitive_type
, UINT primitive_count
, const void *data
, UINT stride
)
2782 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2784 UINT vtx_count
= vertex_count_from_primitive_count(primitive_type
, primitive_count
);
2785 struct wined3d_map_desc wined3d_map_desc
;
2786 struct wined3d_box wined3d_box
= {0};
2787 UINT size
= vtx_count
* stride
;
2788 struct wined3d_resource
*vb
;
2791 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
2792 iface
, primitive_type
, primitive_count
, data
, stride
);
2794 if (!primitive_count
)
2796 WARN("primitive_count is 0, returning D3D_OK\n");
2800 wined3d_mutex_lock();
2802 if (!device
->has_vertex_declaration
)
2804 wined3d_mutex_unlock();
2805 WARN("Called without a valid vertex declaration set.\n");
2806 return D3DERR_INVALIDCALL
;
2809 hr
= d3d9_device_prepare_vertex_buffer(device
, size
);
2813 vb_pos
= device
->vertex_buffer_pos
;
2814 align
= vb_pos
% stride
;
2815 if (align
) align
= stride
- align
;
2816 if (vb_pos
+ size
+ align
> device
->vertex_buffer_size
)
2821 wined3d_box
.left
= vb_pos
;
2822 wined3d_box
.right
= vb_pos
+ size
;
2823 vb
= wined3d_buffer_get_resource(device
->vertex_buffer
);
2824 if (FAILED(hr
= wined3d_resource_map(vb
, 0, &wined3d_map_desc
, &wined3d_box
,
2825 WINED3D_MAP_WRITE
| (vb_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
))))
2827 memcpy(wined3d_map_desc
.data
, data
, size
);
2828 wined3d_resource_unmap(vb
, 0);
2829 device
->vertex_buffer_pos
= vb_pos
+ size
;
2831 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, 0, device
->vertex_buffer
, 0, stride
);
2835 d3d9_generate_auto_mipmaps(device
);
2836 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
, 0);
2837 hr
= wined3d_device_draw_primitive(device
->wined3d_device
, vb_pos
/ stride
, vtx_count
);
2838 wined3d_device_set_stream_source(device
->wined3d_device
, 0, NULL
, 0, 0);
2840 d3d9_rts_flag_auto_gen_mipmap(device
);
2843 wined3d_mutex_unlock();
2847 /* The caller is responsible for wined3d locking */
2848 static HRESULT
d3d9_device_prepare_index_buffer(struct d3d9_device
*device
, UINT min_size
)
2852 if (device
->index_buffer_size
< min_size
|| !device
->index_buffer
)
2854 UINT size
= max(device
->index_buffer_size
* 2, min_size
);
2855 struct wined3d_buffer_desc desc
;
2856 struct wined3d_buffer
*buffer
;
2858 TRACE("Growing index buffer to %u bytes.\n", size
);
2860 desc
.byte_width
= size
;
2861 desc
.usage
= WINED3DUSAGE_DYNAMIC
| WINED3DUSAGE_WRITEONLY
| WINED3DUSAGE_STATICDECL
;
2862 desc
.bind_flags
= WINED3D_BIND_INDEX_BUFFER
;
2863 desc
.access
= WINED3D_RESOURCE_ACCESS_GPU
| WINED3D_RESOURCE_ACCESS_MAP_R
| WINED3D_RESOURCE_ACCESS_MAP_W
;
2864 desc
.misc_flags
= 0;
2865 desc
.structure_byte_stride
= 0;
2867 if (FAILED(hr
= wined3d_buffer_create(device
->wined3d_device
, &desc
,
2868 NULL
, NULL
, &d3d9_null_wined3d_parent_ops
, &buffer
)))
2870 ERR("Failed to create index buffer, hr %#x.\n", hr
);
2874 if (device
->index_buffer
)
2875 wined3d_buffer_decref(device
->index_buffer
);
2877 device
->index_buffer
= buffer
;
2878 device
->index_buffer_size
= size
;
2879 device
->index_buffer_pos
= 0;
2884 static HRESULT WINAPI
d3d9_device_DrawIndexedPrimitiveUP(IDirect3DDevice9Ex
*iface
,
2885 D3DPRIMITIVETYPE primitive_type
, UINT min_vertex_idx
, UINT vertex_count
,
2886 UINT primitive_count
, const void *index_data
, D3DFORMAT index_format
,
2887 const void *vertex_data
, UINT vertex_stride
)
2889 UINT idx_count
= vertex_count_from_primitive_count(primitive_type
, primitive_count
);
2890 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2891 UINT idx_fmt_size
= index_format
== D3DFMT_INDEX16
? 2 : 4;
2892 UINT vtx_size
= vertex_count
* vertex_stride
;
2893 UINT idx_size
= idx_count
* idx_fmt_size
;
2894 struct wined3d_map_desc wined3d_map_desc
;
2895 struct wined3d_box wined3d_box
= {0};
2896 struct wined3d_resource
*ib
, *vb
;
2897 UINT vb_pos
, ib_pos
, align
;
2900 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, primitive_count %u, "
2901 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
2902 iface
, primitive_type
, min_vertex_idx
, vertex_count
, primitive_count
,
2903 index_data
, index_format
, vertex_data
, vertex_stride
);
2905 if (!primitive_count
)
2907 WARN("primitive_count is 0, returning D3D_OK.\n");
2911 wined3d_mutex_lock();
2913 if (!device
->has_vertex_declaration
)
2915 wined3d_mutex_unlock();
2916 WARN("Called without a valid vertex declaration set.\n");
2917 return D3DERR_INVALIDCALL
;
2920 hr
= d3d9_device_prepare_vertex_buffer(device
, vtx_size
);
2924 vb_pos
= device
->vertex_buffer_pos
;
2925 align
= vb_pos
% vertex_stride
;
2926 if (align
) align
= vertex_stride
- align
;
2927 if (vb_pos
+ vtx_size
+ align
> device
->vertex_buffer_size
)
2932 wined3d_box
.left
= vb_pos
;
2933 wined3d_box
.right
= vb_pos
+ vtx_size
;
2934 vb
= wined3d_buffer_get_resource(device
->vertex_buffer
);
2935 if (FAILED(hr
= wined3d_resource_map(vb
, 0, &wined3d_map_desc
, &wined3d_box
,
2936 WINED3D_MAP_WRITE
| (vb_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
))))
2938 memcpy(wined3d_map_desc
.data
, (char *)vertex_data
+ min_vertex_idx
* vertex_stride
, vtx_size
);
2939 wined3d_resource_unmap(vb
, 0);
2940 device
->vertex_buffer_pos
= vb_pos
+ vtx_size
;
2942 hr
= d3d9_device_prepare_index_buffer(device
, idx_size
);
2946 ib_pos
= device
->index_buffer_pos
;
2947 align
= ib_pos
% idx_fmt_size
;
2948 if (align
) align
= idx_fmt_size
- align
;
2949 if (ib_pos
+ idx_size
+ align
> device
->index_buffer_size
)
2954 wined3d_box
.left
= ib_pos
;
2955 wined3d_box
.right
= ib_pos
+ idx_size
;
2956 ib
= wined3d_buffer_get_resource(device
->index_buffer
);
2957 if (FAILED(hr
= wined3d_resource_map(ib
, 0, &wined3d_map_desc
, &wined3d_box
,
2958 WINED3D_MAP_WRITE
| (ib_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
))))
2960 memcpy(wined3d_map_desc
.data
, index_data
, idx_size
);
2961 wined3d_resource_unmap(ib
, 0);
2962 device
->index_buffer_pos
= ib_pos
+ idx_size
;
2964 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, 0, device
->vertex_buffer
, 0, vertex_stride
);
2968 d3d9_generate_auto_mipmaps(device
);
2969 wined3d_device_set_index_buffer(device
->wined3d_device
, device
->index_buffer
,
2970 wined3dformat_from_d3dformat(index_format
), 0);
2971 wined3d_device_set_base_vertex_index(device
->wined3d_device
, vb_pos
/ vertex_stride
- min_vertex_idx
);
2973 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
, 0);
2974 hr
= wined3d_device_draw_indexed_primitive(device
->wined3d_device
, ib_pos
/ idx_fmt_size
, idx_count
);
2976 wined3d_device_set_stream_source(device
->wined3d_device
, 0, NULL
, 0, 0);
2977 wined3d_device_set_index_buffer(device
->wined3d_device
, NULL
, WINED3DFMT_UNKNOWN
, 0);
2980 d3d9_rts_flag_auto_gen_mipmap(device
);
2983 wined3d_mutex_unlock();
2987 static HRESULT WINAPI
d3d9_device_ProcessVertices(IDirect3DDevice9Ex
*iface
,
2988 UINT src_start_idx
, UINT dst_idx
, UINT vertex_count
, IDirect3DVertexBuffer9
*dst_buffer
,
2989 IDirect3DVertexDeclaration9
*declaration
, DWORD flags
)
2991 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2992 struct d3d9_vertexbuffer
*dst_impl
= unsafe_impl_from_IDirect3DVertexBuffer9(dst_buffer
);
2993 struct d3d9_vertex_declaration
*decl_impl
= unsafe_impl_from_IDirect3DVertexDeclaration9(declaration
);
2996 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, declaration %p, flags %#x.\n",
2997 iface
, src_start_idx
, dst_idx
, vertex_count
, dst_buffer
, declaration
, flags
);
2999 wined3d_mutex_lock();
3000 hr
= wined3d_device_process_vertices(device
->wined3d_device
, src_start_idx
, dst_idx
, vertex_count
,
3001 dst_impl
->wined3d_buffer
, decl_impl
? decl_impl
->wined3d_declaration
: NULL
,
3002 flags
, dst_impl
->fvf
);
3003 wined3d_mutex_unlock();
3008 static HRESULT WINAPI
d3d9_device_CreateVertexDeclaration(IDirect3DDevice9Ex
*iface
,
3009 const D3DVERTEXELEMENT9
*elements
, IDirect3DVertexDeclaration9
**declaration
)
3011 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3012 struct d3d9_vertex_declaration
*object
;
3015 TRACE("iface %p, elements %p, declaration %p.\n", iface
, elements
, declaration
);
3019 WARN("Caller passed a NULL declaration, returning D3DERR_INVALIDCALL.\n");
3020 return D3DERR_INVALIDCALL
;
3023 if (SUCCEEDED(hr
= d3d9_vertex_declaration_create(device
, elements
, &object
)))
3024 *declaration
= &object
->IDirect3DVertexDeclaration9_iface
;
3029 static HRESULT WINAPI
d3d9_device_SetVertexDeclaration(IDirect3DDevice9Ex
*iface
,
3030 IDirect3DVertexDeclaration9
*declaration
)
3032 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3033 struct d3d9_vertex_declaration
*decl_impl
= unsafe_impl_from_IDirect3DVertexDeclaration9(declaration
);
3035 TRACE("iface %p, declaration %p.\n", iface
, declaration
);
3037 wined3d_mutex_lock();
3038 wined3d_device_set_vertex_declaration(device
->wined3d_device
,
3039 decl_impl
? decl_impl
->wined3d_declaration
: NULL
);
3040 device
->has_vertex_declaration
= !!decl_impl
;
3041 wined3d_mutex_unlock();
3046 static HRESULT WINAPI
d3d9_device_GetVertexDeclaration(IDirect3DDevice9Ex
*iface
,
3047 IDirect3DVertexDeclaration9
**declaration
)
3049 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3050 struct wined3d_vertex_declaration
*wined3d_declaration
;
3051 struct d3d9_vertex_declaration
*declaration_impl
;
3053 TRACE("iface %p, declaration %p.\n", iface
, declaration
);
3055 if (!declaration
) return D3DERR_INVALIDCALL
;
3057 wined3d_mutex_lock();
3058 if ((wined3d_declaration
= wined3d_device_get_vertex_declaration(device
->wined3d_device
)))
3060 declaration_impl
= wined3d_vertex_declaration_get_parent(wined3d_declaration
);
3061 *declaration
= &declaration_impl
->IDirect3DVertexDeclaration9_iface
;
3062 IDirect3DVertexDeclaration9_AddRef(*declaration
);
3066 *declaration
= NULL
;
3068 wined3d_mutex_unlock();
3070 TRACE("Returning %p.\n", *declaration
);
3074 static struct wined3d_vertex_declaration
*device_get_fvf_declaration(struct d3d9_device
*device
, DWORD fvf
)
3076 struct wined3d_vertex_declaration
*wined3d_declaration
;
3077 struct fvf_declaration
*fvf_decls
= device
->fvf_decls
;
3078 struct d3d9_vertex_declaration
*d3d9_declaration
;
3079 D3DVERTEXELEMENT9
*elements
;
3080 int p
, low
, high
; /* deliberately signed */
3083 TRACE("Searching for declaration for fvf %08x... ", fvf
);
3086 high
= device
->fvf_decl_count
- 1;
3089 p
= (low
+ high
) >> 1;
3092 if (fvf_decls
[p
].fvf
== fvf
)
3094 TRACE("found %p.\n", fvf_decls
[p
].decl
);
3095 return fvf_decls
[p
].decl
;
3098 if (fvf_decls
[p
].fvf
< fvf
)
3103 TRACE("not found. Creating and inserting at position %d.\n", low
);
3105 if (FAILED(hr
= vdecl_convert_fvf(fvf
, &elements
)))
3108 hr
= d3d9_vertex_declaration_create(device
, elements
, &d3d9_declaration
);
3109 heap_free(elements
);
3113 if (device
->fvf_decl_size
== device
->fvf_decl_count
)
3115 UINT grow
= max(device
->fvf_decl_size
/ 2, 8);
3117 if (!(fvf_decls
= heap_realloc(fvf_decls
, sizeof(*fvf_decls
) * (device
->fvf_decl_size
+ grow
))))
3119 IDirect3DVertexDeclaration9_Release(&d3d9_declaration
->IDirect3DVertexDeclaration9_iface
);
3122 device
->fvf_decls
= fvf_decls
;
3123 device
->fvf_decl_size
+= grow
;
3126 d3d9_declaration
->fvf
= fvf
;
3127 wined3d_declaration
= d3d9_declaration
->wined3d_declaration
;
3128 wined3d_vertex_declaration_incref(wined3d_declaration
);
3129 IDirect3DVertexDeclaration9_Release(&d3d9_declaration
->IDirect3DVertexDeclaration9_iface
);
3131 memmove(fvf_decls
+ low
+ 1, fvf_decls
+ low
, sizeof(*fvf_decls
) * (device
->fvf_decl_count
- low
));
3132 fvf_decls
[low
].decl
= wined3d_declaration
;
3133 fvf_decls
[low
].fvf
= fvf
;
3134 ++device
->fvf_decl_count
;
3136 TRACE("Returning %p. %u declarations in array.\n", wined3d_declaration
, device
->fvf_decl_count
);
3138 return wined3d_declaration
;
3141 static HRESULT WINAPI
d3d9_device_SetFVF(IDirect3DDevice9Ex
*iface
, DWORD fvf
)
3143 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3144 struct wined3d_vertex_declaration
*decl
;
3146 TRACE("iface %p, fvf %#x.\n", iface
, fvf
);
3150 WARN("%#x is not a valid FVF.\n", fvf
);
3154 wined3d_mutex_lock();
3155 if (!(decl
= device_get_fvf_declaration(device
, fvf
)))
3157 wined3d_mutex_unlock();
3158 ERR("Failed to create a vertex declaration for fvf %#x.\n", fvf
);
3159 return D3DERR_DRIVERINTERNALERROR
;
3162 wined3d_device_set_vertex_declaration(device
->wined3d_device
, decl
);
3163 device
->has_vertex_declaration
= TRUE
;
3164 wined3d_mutex_unlock();
3169 static HRESULT WINAPI
d3d9_device_GetFVF(IDirect3DDevice9Ex
*iface
, DWORD
*fvf
)
3171 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3172 struct wined3d_vertex_declaration
*wined3d_declaration
;
3173 struct d3d9_vertex_declaration
*d3d9_declaration
;
3175 TRACE("iface %p, fvf %p.\n", iface
, fvf
);
3177 wined3d_mutex_lock();
3178 if ((wined3d_declaration
= wined3d_device_get_vertex_declaration(device
->wined3d_device
)))
3180 d3d9_declaration
= wined3d_vertex_declaration_get_parent(wined3d_declaration
);
3181 *fvf
= d3d9_declaration
->fvf
;
3187 wined3d_mutex_unlock();
3189 TRACE("Returning FVF %#x.\n", *fvf
);
3194 static HRESULT WINAPI
d3d9_device_CreateVertexShader(IDirect3DDevice9Ex
*iface
,
3195 const DWORD
*byte_code
, IDirect3DVertexShader9
**shader
)
3197 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3198 struct d3d9_vertexshader
*object
;
3201 TRACE("iface %p, byte_code %p, shader %p.\n", iface
, byte_code
, shader
);
3203 if (!(object
= heap_alloc_zero(sizeof(*object
))))
3204 return E_OUTOFMEMORY
;
3206 hr
= vertexshader_init(object
, device
, byte_code
);
3209 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
3214 TRACE("Created vertex shader %p.\n", object
);
3215 *shader
= &object
->IDirect3DVertexShader9_iface
;
3220 static HRESULT WINAPI
d3d9_device_SetVertexShader(IDirect3DDevice9Ex
*iface
, IDirect3DVertexShader9
*shader
)
3222 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3223 struct d3d9_vertexshader
*shader_obj
= unsafe_impl_from_IDirect3DVertexShader9(shader
);
3225 TRACE("iface %p, shader %p.\n", iface
, shader
);
3227 wined3d_mutex_lock();
3228 wined3d_device_set_vertex_shader(device
->wined3d_device
,
3229 shader_obj
? shader_obj
->wined3d_shader
: NULL
);
3230 wined3d_mutex_unlock();
3235 static HRESULT WINAPI
d3d9_device_GetVertexShader(IDirect3DDevice9Ex
*iface
, IDirect3DVertexShader9
**shader
)
3237 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3238 struct d3d9_vertexshader
*shader_impl
;
3239 struct wined3d_shader
*wined3d_shader
;
3241 TRACE("iface %p, shader %p.\n", iface
, shader
);
3243 wined3d_mutex_lock();
3244 if ((wined3d_shader
= wined3d_device_get_vertex_shader(device
->wined3d_device
)))
3246 shader_impl
= wined3d_shader_get_parent(wined3d_shader
);
3247 *shader
= &shader_impl
->IDirect3DVertexShader9_iface
;
3248 IDirect3DVertexShader9_AddRef(*shader
);
3254 wined3d_mutex_unlock();
3256 TRACE("Returning %p.\n", *shader
);
3261 static HRESULT WINAPI
d3d9_device_SetVertexShaderConstantF(IDirect3DDevice9Ex
*iface
,
3262 UINT reg_idx
, const float *data
, UINT count
)
3264 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3267 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3269 if (reg_idx
+ count
> D3D9_MAX_VERTEX_SHADER_CONSTANTF
)
3271 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
3272 reg_idx
+ count
, D3D9_MAX_VERTEX_SHADER_CONSTANTF
);
3273 return D3DERR_INVALIDCALL
;
3276 wined3d_mutex_lock();
3277 hr
= wined3d_device_set_vs_consts_f(device
->wined3d_device
,
3278 reg_idx
, count
, (const struct wined3d_vec4
*)data
);
3279 wined3d_mutex_unlock();
3284 static HRESULT WINAPI
d3d9_device_GetVertexShaderConstantF(IDirect3DDevice9Ex
*iface
,
3285 UINT reg_idx
, float *data
, UINT count
)
3287 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3290 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3292 if (reg_idx
+ count
> D3D9_MAX_VERTEX_SHADER_CONSTANTF
)
3294 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
3295 reg_idx
+ count
, D3D9_MAX_VERTEX_SHADER_CONSTANTF
);
3296 return D3DERR_INVALIDCALL
;
3299 wined3d_mutex_lock();
3300 hr
= wined3d_device_get_vs_consts_f(device
->wined3d_device
,
3301 reg_idx
, count
, (struct wined3d_vec4
*)data
);
3302 wined3d_mutex_unlock();
3307 static HRESULT WINAPI
d3d9_device_SetVertexShaderConstantI(IDirect3DDevice9Ex
*iface
,
3308 UINT reg_idx
, const int *data
, UINT count
)
3310 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3313 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3315 wined3d_mutex_lock();
3316 hr
= wined3d_device_set_vs_consts_i(device
->wined3d_device
,
3317 reg_idx
, count
, (const struct wined3d_ivec4
*)data
);
3318 wined3d_mutex_unlock();
3323 static HRESULT WINAPI
d3d9_device_GetVertexShaderConstantI(IDirect3DDevice9Ex
*iface
,
3324 UINT reg_idx
, int *data
, UINT count
)
3326 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3329 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3331 wined3d_mutex_lock();
3332 hr
= wined3d_device_get_vs_consts_i(device
->wined3d_device
,
3333 reg_idx
, count
, (struct wined3d_ivec4
*)data
);
3334 wined3d_mutex_unlock();
3339 static HRESULT WINAPI
d3d9_device_SetVertexShaderConstantB(IDirect3DDevice9Ex
*iface
,
3340 UINT reg_idx
, const BOOL
*data
, UINT count
)
3342 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3345 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3347 wined3d_mutex_lock();
3348 hr
= wined3d_device_set_vs_consts_b(device
->wined3d_device
, reg_idx
, count
, data
);
3349 wined3d_mutex_unlock();
3354 static HRESULT WINAPI
d3d9_device_GetVertexShaderConstantB(IDirect3DDevice9Ex
*iface
,
3355 UINT reg_idx
, BOOL
*data
, UINT count
)
3357 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3360 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3362 wined3d_mutex_lock();
3363 hr
= wined3d_device_get_vs_consts_b(device
->wined3d_device
, reg_idx
, count
, data
);
3364 wined3d_mutex_unlock();
3369 static HRESULT WINAPI
d3d9_device_SetStreamSource(IDirect3DDevice9Ex
*iface
,
3370 UINT stream_idx
, IDirect3DVertexBuffer9
*buffer
, UINT offset
, UINT stride
)
3372 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3373 struct d3d9_vertexbuffer
*buffer_impl
= unsafe_impl_from_IDirect3DVertexBuffer9(buffer
);
3376 TRACE("iface %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
3377 iface
, stream_idx
, buffer
, offset
, stride
);
3379 wined3d_mutex_lock();
3382 struct wined3d_buffer
*wined3d_buffer
;
3383 unsigned int cur_offset
;
3385 hr
= wined3d_device_get_stream_source(device
->wined3d_device
, stream_idx
, &wined3d_buffer
,
3386 &cur_offset
, &stride
);
3388 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, stream_idx
,
3389 buffer_impl
? buffer_impl
->wined3d_buffer
: NULL
, offset
, stride
);
3390 wined3d_mutex_unlock();
3395 static HRESULT WINAPI
d3d9_device_GetStreamSource(IDirect3DDevice9Ex
*iface
,
3396 UINT stream_idx
, IDirect3DVertexBuffer9
**buffer
, UINT
*offset
, UINT
*stride
)
3398 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3399 struct d3d9_vertexbuffer
*buffer_impl
;
3400 struct wined3d_buffer
*wined3d_buffer
;
3403 TRACE("iface %p, stream_idx %u, buffer %p, offset %p, stride %p.\n",
3404 iface
, stream_idx
, buffer
, offset
, stride
);
3407 return D3DERR_INVALIDCALL
;
3409 wined3d_mutex_lock();
3410 hr
= wined3d_device_get_stream_source(device
->wined3d_device
, stream_idx
, &wined3d_buffer
, offset
, stride
);
3411 if (SUCCEEDED(hr
) && wined3d_buffer
)
3413 buffer_impl
= wined3d_buffer_get_parent(wined3d_buffer
);
3414 *buffer
= &buffer_impl
->IDirect3DVertexBuffer9_iface
;
3415 IDirect3DVertexBuffer9_AddRef(*buffer
);
3420 FIXME("Call to GetStreamSource failed %p %p\n", offset
, stride
);
3423 wined3d_mutex_unlock();
3428 static HRESULT WINAPI
d3d9_device_SetStreamSourceFreq(IDirect3DDevice9Ex
*iface
, UINT stream_idx
, UINT freq
)
3430 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3433 TRACE("iface %p, stream_idx %u, freq %u.\n", iface
, stream_idx
, freq
);
3435 wined3d_mutex_lock();
3436 hr
= wined3d_device_set_stream_source_freq(device
->wined3d_device
, stream_idx
, freq
);
3437 wined3d_mutex_unlock();
3442 static HRESULT WINAPI
d3d9_device_GetStreamSourceFreq(IDirect3DDevice9Ex
*iface
, UINT stream_idx
, UINT
*freq
)
3444 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3447 TRACE("iface %p, stream_idx %u, freq %p.\n", iface
, stream_idx
, freq
);
3449 wined3d_mutex_lock();
3450 hr
= wined3d_device_get_stream_source_freq(device
->wined3d_device
, stream_idx
, freq
);
3451 wined3d_mutex_unlock();
3456 static HRESULT WINAPI
d3d9_device_SetIndices(IDirect3DDevice9Ex
*iface
, IDirect3DIndexBuffer9
*buffer
)
3458 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3459 struct d3d9_indexbuffer
*ib
= unsafe_impl_from_IDirect3DIndexBuffer9(buffer
);
3461 TRACE("iface %p, buffer %p.\n", iface
, buffer
);
3463 wined3d_mutex_lock();
3464 wined3d_device_set_index_buffer(device
->wined3d_device
,
3465 ib
? ib
->wined3d_buffer
: NULL
, ib
? ib
->format
: WINED3DFMT_UNKNOWN
, 0);
3466 wined3d_mutex_unlock();
3471 static HRESULT WINAPI
d3d9_device_GetIndices(IDirect3DDevice9Ex
*iface
, IDirect3DIndexBuffer9
**buffer
)
3473 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3474 enum wined3d_format_id wined3d_format
;
3475 struct wined3d_buffer
*wined3d_buffer
;
3476 struct d3d9_indexbuffer
*buffer_impl
;
3478 TRACE("iface %p, buffer %p.\n", iface
, buffer
);
3481 return D3DERR_INVALIDCALL
;
3483 wined3d_mutex_lock();
3484 if ((wined3d_buffer
= wined3d_device_get_index_buffer(device
->wined3d_device
, &wined3d_format
, NULL
)))
3486 buffer_impl
= wined3d_buffer_get_parent(wined3d_buffer
);
3487 *buffer
= &buffer_impl
->IDirect3DIndexBuffer9_iface
;
3488 IDirect3DIndexBuffer9_AddRef(*buffer
);
3494 wined3d_mutex_unlock();
3499 static HRESULT WINAPI
d3d9_device_CreatePixelShader(IDirect3DDevice9Ex
*iface
,
3500 const DWORD
*byte_code
, IDirect3DPixelShader9
**shader
)
3502 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3503 struct d3d9_pixelshader
*object
;
3506 TRACE("iface %p, byte_code %p, shader %p.\n", iface
, byte_code
, shader
);
3508 if (!(object
= heap_alloc_zero(sizeof(*object
))))
3510 FIXME("Failed to allocate pixel shader memory.\n");
3511 return E_OUTOFMEMORY
;
3514 hr
= pixelshader_init(object
, device
, byte_code
);
3517 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
3522 TRACE("Created pixel shader %p.\n", object
);
3523 *shader
= &object
->IDirect3DPixelShader9_iface
;
3528 static HRESULT WINAPI
d3d9_device_SetPixelShader(IDirect3DDevice9Ex
*iface
, IDirect3DPixelShader9
*shader
)
3530 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3531 struct d3d9_pixelshader
*shader_obj
= unsafe_impl_from_IDirect3DPixelShader9(shader
);
3533 TRACE("iface %p, shader %p.\n", iface
, shader
);
3535 wined3d_mutex_lock();
3536 wined3d_device_set_pixel_shader(device
->wined3d_device
,
3537 shader_obj
? shader_obj
->wined3d_shader
: NULL
);
3538 wined3d_mutex_unlock();
3543 static HRESULT WINAPI
d3d9_device_GetPixelShader(IDirect3DDevice9Ex
*iface
, IDirect3DPixelShader9
**shader
)
3545 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3546 struct d3d9_pixelshader
*shader_impl
;
3547 struct wined3d_shader
*wined3d_shader
;
3549 TRACE("iface %p, shader %p.\n", iface
, shader
);
3551 if (!shader
) return D3DERR_INVALIDCALL
;
3553 wined3d_mutex_lock();
3554 if ((wined3d_shader
= wined3d_device_get_pixel_shader(device
->wined3d_device
)))
3556 shader_impl
= wined3d_shader_get_parent(wined3d_shader
);
3557 *shader
= &shader_impl
->IDirect3DPixelShader9_iface
;
3558 IDirect3DPixelShader9_AddRef(*shader
);
3564 wined3d_mutex_unlock();
3566 TRACE("Returning %p.\n", *shader
);
3571 static HRESULT WINAPI
d3d9_device_SetPixelShaderConstantF(IDirect3DDevice9Ex
*iface
,
3572 UINT reg_idx
, const float *data
, UINT count
)
3574 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3577 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3579 wined3d_mutex_lock();
3580 hr
= wined3d_device_set_ps_consts_f(device
->wined3d_device
,
3581 reg_idx
, count
, (const struct wined3d_vec4
*)data
);
3582 wined3d_mutex_unlock();
3587 static HRESULT WINAPI
d3d9_device_GetPixelShaderConstantF(IDirect3DDevice9Ex
*iface
,
3588 UINT reg_idx
, float *data
, UINT count
)
3590 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3593 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3595 wined3d_mutex_lock();
3596 hr
= wined3d_device_get_ps_consts_f(device
->wined3d_device
,
3597 reg_idx
, count
, (struct wined3d_vec4
*)data
);
3598 wined3d_mutex_unlock();
3603 static HRESULT WINAPI
d3d9_device_SetPixelShaderConstantI(IDirect3DDevice9Ex
*iface
,
3604 UINT reg_idx
, const int *data
, UINT count
)
3606 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3609 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3611 wined3d_mutex_lock();
3612 hr
= wined3d_device_set_ps_consts_i(device
->wined3d_device
,
3613 reg_idx
, count
, (const struct wined3d_ivec4
*)data
);
3614 wined3d_mutex_unlock();
3619 static HRESULT WINAPI
d3d9_device_GetPixelShaderConstantI(IDirect3DDevice9Ex
*iface
,
3620 UINT reg_idx
, int *data
, UINT count
)
3622 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3625 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3627 wined3d_mutex_lock();
3628 hr
= wined3d_device_get_ps_consts_i(device
->wined3d_device
,
3629 reg_idx
, count
, (struct wined3d_ivec4
*)data
);
3630 wined3d_mutex_unlock();
3635 static HRESULT WINAPI
d3d9_device_SetPixelShaderConstantB(IDirect3DDevice9Ex
*iface
,
3636 UINT reg_idx
, const BOOL
*data
, UINT count
)
3638 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3641 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3643 wined3d_mutex_lock();
3644 hr
= wined3d_device_set_ps_consts_b(device
->wined3d_device
, reg_idx
, count
, data
);
3645 wined3d_mutex_unlock();
3650 static HRESULT WINAPI
d3d9_device_GetPixelShaderConstantB(IDirect3DDevice9Ex
*iface
,
3651 UINT reg_idx
, BOOL
*data
, UINT count
)
3653 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3656 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3658 wined3d_mutex_lock();
3659 hr
= wined3d_device_get_ps_consts_b(device
->wined3d_device
, reg_idx
, count
, data
);
3660 wined3d_mutex_unlock();
3665 static HRESULT WINAPI
d3d9_device_DrawRectPatch(IDirect3DDevice9Ex
*iface
, UINT handle
,
3666 const float *segment_count
, const D3DRECTPATCH_INFO
*patch_info
)
3668 FIXME("iface %p, handle %#x, segment_count %p, patch_info %p unimplemented.\n",
3669 iface
, handle
, segment_count
, patch_info
);
3673 static HRESULT WINAPI
d3d9_device_DrawTriPatch(IDirect3DDevice9Ex
*iface
, UINT handle
,
3674 const float *segment_count
, const D3DTRIPATCH_INFO
*patch_info
)
3676 FIXME("iface %p, handle %#x, segment_count %p, patch_info %p unimplemented.\n",
3677 iface
, handle
, segment_count
, patch_info
);
3681 static HRESULT WINAPI
d3d9_device_DeletePatch(IDirect3DDevice9Ex
*iface
, UINT handle
)
3683 FIXME("iface %p, handle %#x unimplemented.\n", iface
, handle
);
3684 return D3DERR_INVALIDCALL
;
3687 static HRESULT WINAPI
d3d9_device_CreateQuery(IDirect3DDevice9Ex
*iface
, D3DQUERYTYPE type
, IDirect3DQuery9
**query
)
3689 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3690 struct d3d9_query
*object
;
3693 TRACE("iface %p, type %#x, query %p.\n", iface
, type
, query
);
3695 if (!(object
= heap_alloc_zero(sizeof(*object
))))
3696 return E_OUTOFMEMORY
;
3698 hr
= query_init(object
, device
, type
);
3701 WARN("Failed to initialize query, hr %#x.\n", hr
);
3706 TRACE("Created query %p.\n", object
);
3707 if (query
) *query
= &object
->IDirect3DQuery9_iface
;
3708 else IDirect3DQuery9_Release(&object
->IDirect3DQuery9_iface
);
3713 static HRESULT WINAPI
d3d9_device_SetConvolutionMonoKernel(IDirect3DDevice9Ex
*iface
,
3714 UINT width
, UINT height
, float *rows
, float *columns
)
3716 FIXME("iface %p, width %u, height %u, rows %p, columns %p stub!\n",
3717 iface
, width
, height
, rows
, columns
);
3722 static HRESULT WINAPI
d3d9_device_ComposeRects(IDirect3DDevice9Ex
*iface
,
3723 IDirect3DSurface9
*src_surface
, IDirect3DSurface9
*dst_surface
, IDirect3DVertexBuffer9
*src_descs
,
3724 UINT rect_count
, IDirect3DVertexBuffer9
*dst_descs
, D3DCOMPOSERECTSOP operation
, INT offset_x
, INT offset_y
)
3726 FIXME("iface %p, src_surface %p, dst_surface %p, src_descs %p, rect_count %u, "
3727 "dst_descs %p, operation %#x, offset_x %u, offset_y %u stub!\n",
3728 iface
, src_surface
, dst_surface
, src_descs
, rect_count
,
3729 dst_descs
, operation
, offset_x
, offset_y
);
3734 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_PresentEx(IDirect3DDevice9Ex
*iface
,
3735 const RECT
*src_rect
, const RECT
*dst_rect
, HWND dst_window_override
,
3736 const RGNDATA
*dirty_region
, DWORD flags
)
3738 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3739 struct d3d9_swapchain
*swapchain
;
3743 TRACE("iface %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p, flags %#x.\n",
3744 iface
, wine_dbgstr_rect(src_rect
), wine_dbgstr_rect(dst_rect
),
3745 dst_window_override
, dirty_region
, flags
);
3747 if (device
->device_state
!= D3D9_DEVICE_STATE_OK
)
3748 return S_PRESENT_OCCLUDED
;
3751 FIXME("Ignoring dirty_region %p.\n", dirty_region
);
3753 wined3d_mutex_lock();
3754 for (i
= 0; i
< device
->implicit_swapchain_count
; ++i
)
3756 swapchain
= device
->implicit_swapchains
[i
];
3757 if (FAILED(hr
= wined3d_swapchain_present(swapchain
->wined3d_swapchain
,
3758 src_rect
, dst_rect
, dst_window_override
, swapchain
->swap_interval
, flags
)))
3760 wined3d_mutex_unlock();
3764 wined3d_mutex_unlock();
3769 static HRESULT WINAPI
d3d9_device_GetGPUThreadPriority(IDirect3DDevice9Ex
*iface
, INT
*priority
)
3771 FIXME("iface %p, priority %p stub!\n", iface
, priority
);
3776 static HRESULT WINAPI
d3d9_device_SetGPUThreadPriority(IDirect3DDevice9Ex
*iface
, INT priority
)
3778 FIXME("iface %p, priority %d stub!\n", iface
, priority
);
3783 static HRESULT WINAPI
d3d9_device_WaitForVBlank(IDirect3DDevice9Ex
*iface
, UINT swapchain_idx
)
3785 FIXME("iface %p, swapchain_idx %u stub!\n", iface
, swapchain_idx
);
3790 static HRESULT WINAPI
d3d9_device_CheckResourceResidency(IDirect3DDevice9Ex
*iface
,
3791 IDirect3DResource9
**resources
, UINT32 resource_count
)
3793 FIXME("iface %p, resources %p, resource_count %u stub!\n",
3794 iface
, resources
, resource_count
);
3799 static HRESULT WINAPI
d3d9_device_SetMaximumFrameLatency(IDirect3DDevice9Ex
*iface
, UINT max_latency
)
3801 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3803 TRACE("iface %p, max_latency %u.\n", iface
, max_latency
);
3805 if (max_latency
> 30)
3806 return D3DERR_INVALIDCALL
;
3808 wined3d_mutex_lock();
3809 wined3d_device_set_max_frame_latency(device
->wined3d_device
, max_latency
);
3810 wined3d_mutex_unlock();
3815 static HRESULT WINAPI
d3d9_device_GetMaximumFrameLatency(IDirect3DDevice9Ex
*iface
, UINT
*max_latency
)
3817 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3819 TRACE("iface %p, max_latency %p.\n", iface
, max_latency
);
3821 wined3d_mutex_lock();
3822 *max_latency
= wined3d_device_get_max_frame_latency(device
->wined3d_device
);
3823 wined3d_mutex_unlock();
3828 static HRESULT WINAPI
d3d9_device_CheckDeviceState(IDirect3DDevice9Ex
*iface
, HWND dst_window
)
3830 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3831 struct wined3d_swapchain_desc swapchain_desc
;
3833 TRACE("iface %p, dst_window %p.\n", iface
, dst_window
);
3835 wined3d_mutex_lock();
3836 wined3d_swapchain_get_desc(device
->implicit_swapchains
[0]->wined3d_swapchain
, &swapchain_desc
);
3837 wined3d_mutex_unlock();
3839 if (swapchain_desc
.windowed
)
3842 /* FIXME: This is actually supposed to check if any other device is in
3843 * fullscreen mode. */
3844 if (dst_window
!= swapchain_desc
.device_window
)
3845 return device
->device_state
== D3D9_DEVICE_STATE_OK
? S_PRESENT_OCCLUDED
: D3D_OK
;
3847 return device
->device_state
== D3D9_DEVICE_STATE_OK
? D3D_OK
: S_PRESENT_OCCLUDED
;
3850 static HRESULT WINAPI
d3d9_device_CreateRenderTargetEx(IDirect3DDevice9Ex
*iface
,
3851 UINT width
, UINT height
, D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
3852 BOOL lockable
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
, DWORD usage
)
3854 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u, "
3855 "lockable %#x, surface %p, shared_handle %p, usage %#x stub!\n",
3856 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
3857 lockable
, surface
, shared_handle
, usage
);
3861 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
3866 static HRESULT WINAPI
d3d9_device_CreateOffscreenPlainSurfaceEx(IDirect3DDevice9Ex
*iface
,
3867 UINT width
, UINT height
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DSurface9
**surface
,
3868 HANDLE
*shared_handle
, DWORD usage
)
3870 FIXME("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p, usage %#x stub!\n",
3871 iface
, width
, height
, format
, pool
, surface
, shared_handle
, usage
);
3876 static HRESULT WINAPI
d3d9_device_CreateDepthStencilSurfaceEx(IDirect3DDevice9Ex
*iface
,
3877 UINT width
, UINT height
, D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
3878 BOOL discard
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
, DWORD usage
)
3880 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3881 DWORD flags
= WINED3D_TEXTURE_CREATE_MAPPABLE
;
3883 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u, "
3884 "discard %#x, surface %p, shared_handle %p, usage %#x.\n",
3885 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
3886 discard
, surface
, shared_handle
, usage
);
3888 if (usage
& D3DUSAGE_DEPTHSTENCIL
)
3890 WARN("Invalid usage %#x.\n", usage
);
3891 return D3DERR_INVALIDCALL
;
3895 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
3898 flags
|= WINED3D_TEXTURE_CREATE_DISCARD
;
3901 return d3d9_device_create_surface(device
, width
, height
, format
, flags
, surface
,
3902 D3DUSAGE_DEPTHSTENCIL
| usage
, D3DPOOL_DEFAULT
, multisample_type
, multisample_quality
, NULL
);
3905 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_ResetEx(IDirect3DDevice9Ex
*iface
,
3906 D3DPRESENT_PARAMETERS
*present_parameters
, D3DDISPLAYMODEEX
*mode
)
3908 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3910 TRACE("iface %p, present_parameters %p, mode %p.\n", iface
, present_parameters
, mode
);
3912 if (!present_parameters
->Windowed
== !mode
)
3914 WARN("Mode can be passed if and only if Windowed is FALSE.\n");
3915 return D3DERR_INVALIDCALL
;
3918 if (mode
&& (mode
->Width
!= present_parameters
->BackBufferWidth
3919 || mode
->Height
!= present_parameters
->BackBufferHeight
))
3921 WARN("Mode and back buffer mismatch (mode %ux%u, backbuffer %ux%u).\n",
3922 mode
->Width
, mode
->Height
,
3923 present_parameters
->BackBufferWidth
, present_parameters
->BackBufferHeight
);
3924 return D3DERR_INVALIDCALL
;
3927 return d3d9_device_reset(device
, present_parameters
, mode
);
3930 static HRESULT WINAPI
d3d9_device_GetDisplayModeEx(IDirect3DDevice9Ex
*iface
,
3931 UINT swapchain_idx
, D3DDISPLAYMODEEX
*mode
, D3DDISPLAYROTATION
*rotation
)
3933 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3934 struct wined3d_display_mode wined3d_mode
;
3937 TRACE("iface %p, swapchain_idx %u, mode %p, rotation %p.\n",
3938 iface
, swapchain_idx
, mode
, rotation
);
3940 if (mode
->Size
!= sizeof(*mode
))
3941 return D3DERR_INVALIDCALL
;
3943 wined3d_mutex_lock();
3944 hr
= wined3d_device_get_display_mode(device
->wined3d_device
, swapchain_idx
, &wined3d_mode
,
3945 (enum wined3d_display_rotation
*)rotation
);
3946 wined3d_mutex_unlock();
3950 mode
->Width
= wined3d_mode
.width
;
3951 mode
->Height
= wined3d_mode
.height
;
3952 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
3953 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
3954 mode
->ScanLineOrdering
= wined3d_mode
.scanline_ordering
;
3960 static const struct IDirect3DDevice9ExVtbl d3d9_device_vtbl
=
3963 d3d9_device_QueryInterface
,
3965 d3d9_device_Release
,
3966 /* IDirect3DDevice9 */
3967 d3d9_device_TestCooperativeLevel
,
3968 d3d9_device_GetAvailableTextureMem
,
3969 d3d9_device_EvictManagedResources
,
3970 d3d9_device_GetDirect3D
,
3971 d3d9_device_GetDeviceCaps
,
3972 d3d9_device_GetDisplayMode
,
3973 d3d9_device_GetCreationParameters
,
3974 d3d9_device_SetCursorProperties
,
3975 d3d9_device_SetCursorPosition
,
3976 d3d9_device_ShowCursor
,
3977 d3d9_device_CreateAdditionalSwapChain
,
3978 d3d9_device_GetSwapChain
,
3979 d3d9_device_GetNumberOfSwapChains
,
3981 d3d9_device_Present
,
3982 d3d9_device_GetBackBuffer
,
3983 d3d9_device_GetRasterStatus
,
3984 d3d9_device_SetDialogBoxMode
,
3985 d3d9_device_SetGammaRamp
,
3986 d3d9_device_GetGammaRamp
,
3987 d3d9_device_CreateTexture
,
3988 d3d9_device_CreateVolumeTexture
,
3989 d3d9_device_CreateCubeTexture
,
3990 d3d9_device_CreateVertexBuffer
,
3991 d3d9_device_CreateIndexBuffer
,
3992 d3d9_device_CreateRenderTarget
,
3993 d3d9_device_CreateDepthStencilSurface
,
3994 d3d9_device_UpdateSurface
,
3995 d3d9_device_UpdateTexture
,
3996 d3d9_device_GetRenderTargetData
,
3997 d3d9_device_GetFrontBufferData
,
3998 d3d9_device_StretchRect
,
3999 d3d9_device_ColorFill
,
4000 d3d9_device_CreateOffscreenPlainSurface
,
4001 d3d9_device_SetRenderTarget
,
4002 d3d9_device_GetRenderTarget
,
4003 d3d9_device_SetDepthStencilSurface
,
4004 d3d9_device_GetDepthStencilSurface
,
4005 d3d9_device_BeginScene
,
4006 d3d9_device_EndScene
,
4008 d3d9_device_SetTransform
,
4009 d3d9_device_GetTransform
,
4010 d3d9_device_MultiplyTransform
,
4011 d3d9_device_SetViewport
,
4012 d3d9_device_GetViewport
,
4013 d3d9_device_SetMaterial
,
4014 d3d9_device_GetMaterial
,
4015 d3d9_device_SetLight
,
4016 d3d9_device_GetLight
,
4017 d3d9_device_LightEnable
,
4018 d3d9_device_GetLightEnable
,
4019 d3d9_device_SetClipPlane
,
4020 d3d9_device_GetClipPlane
,
4021 d3d9_device_SetRenderState
,
4022 d3d9_device_GetRenderState
,
4023 d3d9_device_CreateStateBlock
,
4024 d3d9_device_BeginStateBlock
,
4025 d3d9_device_EndStateBlock
,
4026 d3d9_device_SetClipStatus
,
4027 d3d9_device_GetClipStatus
,
4028 d3d9_device_GetTexture
,
4029 d3d9_device_SetTexture
,
4030 d3d9_device_GetTextureStageState
,
4031 d3d9_device_SetTextureStageState
,
4032 d3d9_device_GetSamplerState
,
4033 d3d9_device_SetSamplerState
,
4034 d3d9_device_ValidateDevice
,
4035 d3d9_device_SetPaletteEntries
,
4036 d3d9_device_GetPaletteEntries
,
4037 d3d9_device_SetCurrentTexturePalette
,
4038 d3d9_device_GetCurrentTexturePalette
,
4039 d3d9_device_SetScissorRect
,
4040 d3d9_device_GetScissorRect
,
4041 d3d9_device_SetSoftwareVertexProcessing
,
4042 d3d9_device_GetSoftwareVertexProcessing
,
4043 d3d9_device_SetNPatchMode
,
4044 d3d9_device_GetNPatchMode
,
4045 d3d9_device_DrawPrimitive
,
4046 d3d9_device_DrawIndexedPrimitive
,
4047 d3d9_device_DrawPrimitiveUP
,
4048 d3d9_device_DrawIndexedPrimitiveUP
,
4049 d3d9_device_ProcessVertices
,
4050 d3d9_device_CreateVertexDeclaration
,
4051 d3d9_device_SetVertexDeclaration
,
4052 d3d9_device_GetVertexDeclaration
,
4055 d3d9_device_CreateVertexShader
,
4056 d3d9_device_SetVertexShader
,
4057 d3d9_device_GetVertexShader
,
4058 d3d9_device_SetVertexShaderConstantF
,
4059 d3d9_device_GetVertexShaderConstantF
,
4060 d3d9_device_SetVertexShaderConstantI
,
4061 d3d9_device_GetVertexShaderConstantI
,
4062 d3d9_device_SetVertexShaderConstantB
,
4063 d3d9_device_GetVertexShaderConstantB
,
4064 d3d9_device_SetStreamSource
,
4065 d3d9_device_GetStreamSource
,
4066 d3d9_device_SetStreamSourceFreq
,
4067 d3d9_device_GetStreamSourceFreq
,
4068 d3d9_device_SetIndices
,
4069 d3d9_device_GetIndices
,
4070 d3d9_device_CreatePixelShader
,
4071 d3d9_device_SetPixelShader
,
4072 d3d9_device_GetPixelShader
,
4073 d3d9_device_SetPixelShaderConstantF
,
4074 d3d9_device_GetPixelShaderConstantF
,
4075 d3d9_device_SetPixelShaderConstantI
,
4076 d3d9_device_GetPixelShaderConstantI
,
4077 d3d9_device_SetPixelShaderConstantB
,
4078 d3d9_device_GetPixelShaderConstantB
,
4079 d3d9_device_DrawRectPatch
,
4080 d3d9_device_DrawTriPatch
,
4081 d3d9_device_DeletePatch
,
4082 d3d9_device_CreateQuery
,
4083 /* IDirect3DDevice9Ex */
4084 d3d9_device_SetConvolutionMonoKernel
,
4085 d3d9_device_ComposeRects
,
4086 d3d9_device_PresentEx
,
4087 d3d9_device_GetGPUThreadPriority
,
4088 d3d9_device_SetGPUThreadPriority
,
4089 d3d9_device_WaitForVBlank
,
4090 d3d9_device_CheckResourceResidency
,
4091 d3d9_device_SetMaximumFrameLatency
,
4092 d3d9_device_GetMaximumFrameLatency
,
4093 d3d9_device_CheckDeviceState
,
4094 d3d9_device_CreateRenderTargetEx
,
4095 d3d9_device_CreateOffscreenPlainSurfaceEx
,
4096 d3d9_device_CreateDepthStencilSurfaceEx
,
4097 d3d9_device_ResetEx
,
4098 d3d9_device_GetDisplayModeEx
,
4101 static inline struct d3d9_device
*device_from_device_parent(struct wined3d_device_parent
*device_parent
)
4103 return CONTAINING_RECORD(device_parent
, struct d3d9_device
, device_parent
);
4106 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
4107 struct wined3d_device
*device
)
4109 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
4112 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
4114 TRACE("device_parent %p.\n", device_parent
);
4117 static void CDECL
device_parent_activate(struct wined3d_device_parent
*device_parent
, BOOL activate
)
4119 struct d3d9_device
*device
= device_from_device_parent(device_parent
);
4121 TRACE("device_parent %p, activate %#x.\n", device_parent
, activate
);
4123 if (!device
->d3d_parent
)
4127 InterlockedCompareExchange(&device
->device_state
, D3D9_DEVICE_STATE_LOST
, D3D9_DEVICE_STATE_OK
);
4128 else if (device
->d3d_parent
->extended
)
4129 InterlockedCompareExchange(&device
->device_state
, D3D9_DEVICE_STATE_OK
, D3D9_DEVICE_STATE_LOST
);
4131 InterlockedCompareExchange(&device
->device_state
, D3D9_DEVICE_STATE_NOT_RESET
, D3D9_DEVICE_STATE_LOST
);
4134 static HRESULT CDECL
device_parent_texture_sub_resource_created(struct wined3d_device_parent
*device_parent
,
4135 enum wined3d_resource_type type
, struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
,
4136 void **parent
, const struct wined3d_parent_ops
**parent_ops
)
4138 TRACE("device_parent %p, type %#x, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
4139 device_parent
, type
, wined3d_texture
, sub_resource_idx
, parent
, parent_ops
);
4141 if (type
== WINED3D_RTYPE_TEXTURE_2D
)
4143 struct d3d9_surface
*d3d_surface
;
4145 if (!(d3d_surface
= heap_alloc_zero(sizeof(*d3d_surface
))))
4146 return E_OUTOFMEMORY
;
4148 surface_init(d3d_surface
, wined3d_texture
, sub_resource_idx
, parent_ops
);
4149 *parent
= d3d_surface
;
4150 TRACE("Created surface %p.\n", d3d_surface
);
4152 else if (type
== WINED3D_RTYPE_TEXTURE_3D
)
4154 struct d3d9_volume
*d3d_volume
;
4156 if (!(d3d_volume
= heap_alloc_zero(sizeof(*d3d_volume
))))
4157 return E_OUTOFMEMORY
;
4159 volume_init(d3d_volume
, wined3d_texture
, sub_resource_idx
, parent_ops
);
4160 *parent
= d3d_volume
;
4161 TRACE("Created volume %p.\n", d3d_volume
);
4165 ERR("Unhandled resource type %#x.\n", type
);
4172 static HRESULT CDECL
device_parent_create_swapchain_texture(struct wined3d_device_parent
*device_parent
,
4173 void *container_parent
, const struct wined3d_resource_desc
*desc
, DWORD texture_flags
,
4174 struct wined3d_texture
**texture
)
4176 struct d3d9_device
*device
= device_from_device_parent(device_parent
);
4177 struct d3d9_surface
*d3d_surface
;
4180 TRACE("device_parent %p, container_parent %p, desc %p, texture flags %#x, texture %p.\n",
4181 device_parent
, container_parent
, desc
, texture_flags
, texture
);
4183 if (container_parent
== device_parent
)
4184 container_parent
= &device
->IDirect3DDevice9Ex_iface
;
4186 if (FAILED(hr
= wined3d_texture_create(device
->wined3d_device
, desc
, 1, 1,
4187 texture_flags
, NULL
, container_parent
, &d3d9_null_wined3d_parent_ops
, texture
)))
4189 WARN("Failed to create texture, hr %#x.\n", hr
);
4193 d3d_surface
= wined3d_texture_get_sub_resource_parent(*texture
, 0);
4194 d3d_surface
->parent_device
= &device
->IDirect3DDevice9Ex_iface
;
4199 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
4200 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain
**swapchain
)
4202 struct d3d9_device
*device
= device_from_device_parent(device_parent
);
4203 struct d3d9_swapchain
*d3d_swapchain
;
4206 TRACE("device_parent %p, desc %p, swapchain %p\n", device_parent
, desc
, swapchain
);
4208 if (FAILED(hr
= d3d9_swapchain_create(device
, desc
, WINED3D_SWAP_INTERVAL_DEFAULT
, &d3d_swapchain
)))
4210 WARN("Failed to create swapchain, hr %#x.\n", hr
);
4215 *swapchain
= d3d_swapchain
->wined3d_swapchain
;
4216 wined3d_swapchain_incref(*swapchain
);
4217 IDirect3DSwapChain9Ex_Release(&d3d_swapchain
->IDirect3DSwapChain9Ex_iface
);
4222 static const struct wined3d_device_parent_ops d3d9_wined3d_device_parent_ops
=
4224 device_parent_wined3d_device_created
,
4225 device_parent_mode_changed
,
4226 device_parent_activate
,
4227 device_parent_texture_sub_resource_created
,
4228 device_parent_create_swapchain_texture
,
4229 device_parent_create_swapchain
,
4232 static void setup_fpu(void)
4234 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
4236 __asm__
volatile ("fnstcw %0" : "=m" (cw
));
4237 cw
= (cw
& ~0xf3f) | 0x3f;
4238 __asm__
volatile ("fldcw %0" : : "m" (cw
));
4239 #elif defined(__i386__) && defined(_MSC_VER)
4242 cw
= (cw
& ~0xf3f) | 0x3f;
4245 FIXME("FPU setup not implemented for this platform.\n");
4249 HRESULT
device_init(struct d3d9_device
*device
, struct d3d9
*parent
, struct wined3d
*wined3d
,
4250 UINT adapter
, D3DDEVTYPE device_type
, HWND focus_window
, DWORD flags
,
4251 D3DPRESENT_PARAMETERS
*parameters
, D3DDISPLAYMODEEX
*mode
)
4253 struct wined3d_swapchain_desc
*swapchain_desc
;
4254 struct wined3d_caps caps
;
4255 unsigned i
, count
= 1;
4258 static const enum wined3d_feature_level feature_levels
[] =
4260 WINED3D_FEATURE_LEVEL_9_SM3
,
4261 WINED3D_FEATURE_LEVEL_9_SM2
,
4262 WINED3D_FEATURE_LEVEL_9_1
,
4263 WINED3D_FEATURE_LEVEL_8
,
4264 WINED3D_FEATURE_LEVEL_7
,
4265 WINED3D_FEATURE_LEVEL_6
,
4266 WINED3D_FEATURE_LEVEL_5
,
4270 FIXME("Ignoring display mode.\n");
4272 device
->IDirect3DDevice9Ex_iface
.lpVtbl
= &d3d9_device_vtbl
;
4273 device
->device_parent
.ops
= &d3d9_wined3d_device_parent_ops
;
4274 device
->refcount
= 1;
4276 if (!(flags
& D3DCREATE_FPU_PRESERVE
)) setup_fpu();
4278 wined3d_mutex_lock();
4279 if (FAILED(hr
= wined3d_device_create(wined3d
, adapter
, device_type
,
4280 focus_window
, flags
, 4, feature_levels
, ARRAY_SIZE(feature_levels
),
4281 &device
->device_parent
, &device
->wined3d_device
)))
4283 WARN("Failed to create wined3d device, hr %#x.\n", hr
);
4284 wined3d_mutex_unlock();
4288 wined3d_get_device_caps(wined3d
, adapter
, device_type
, &caps
);
4289 device
->max_user_clip_planes
= caps
.MaxUserClipPlanes
;
4290 if (flags
& D3DCREATE_ADAPTERGROUP_DEVICE
)
4291 count
= caps
.NumberOfAdaptersInGroup
;
4293 if (flags
& D3DCREATE_MULTITHREADED
)
4294 wined3d_device_set_multithreaded(device
->wined3d_device
);
4296 if (!parameters
->Windowed
)
4299 focus_window
= parameters
->hDeviceWindow
;
4300 if (FAILED(hr
= wined3d_device_acquire_focus_window(device
->wined3d_device
, focus_window
)))
4302 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
4303 wined3d_device_decref(device
->wined3d_device
);
4304 wined3d_mutex_unlock();
4308 for (i
= 0; i
< count
; ++i
)
4310 HWND device_window
= parameters
[i
].hDeviceWindow
;
4312 if (!device_window
) device_window
= focus_window
;
4313 wined3d_device_setup_fullscreen_window(device
->wined3d_device
, device_window
,
4314 parameters
[i
].BackBufferWidth
,
4315 parameters
[i
].BackBufferHeight
);
4319 if (!(swapchain_desc
= heap_alloc(sizeof(*swapchain_desc
) * count
)))
4321 ERR("Failed to allocate wined3d parameters.\n");
4322 wined3d_device_release_focus_window(device
->wined3d_device
);
4323 wined3d_device_decref(device
->wined3d_device
);
4324 wined3d_mutex_unlock();
4325 return E_OUTOFMEMORY
;
4328 for (i
= 0; i
< count
; ++i
)
4330 if (!wined3d_swapchain_desc_from_present_parameters(&swapchain_desc
[i
], ¶meters
[i
],
4333 wined3d_device_release_focus_window(device
->wined3d_device
);
4334 wined3d_device_decref(device
->wined3d_device
);
4335 heap_free(swapchain_desc
);
4336 wined3d_mutex_unlock();
4337 return D3DERR_INVALIDCALL
;
4341 if (FAILED(hr
= wined3d_device_init_3d(device
->wined3d_device
, swapchain_desc
)))
4343 WARN("Failed to initialize 3D, hr %#x.\n", hr
);
4344 wined3d_device_release_focus_window(device
->wined3d_device
);
4345 heap_free(swapchain_desc
);
4346 wined3d_device_decref(device
->wined3d_device
);
4347 wined3d_mutex_unlock();
4351 wined3d_device_set_render_state(device
->wined3d_device
,
4352 WINED3D_RS_ZENABLE
, !!swapchain_desc
->enable_auto_depth_stencil
);
4354 if (FAILED(hr
= d3d9_device_get_swapchains(device
)))
4356 wined3d_device_uninit_3d(device
->wined3d_device
);
4357 wined3d_device_release_focus_window(device
->wined3d_device
);
4358 wined3d_device_decref(device
->wined3d_device
);
4359 wined3d_mutex_unlock();
4360 return E_OUTOFMEMORY
;
4362 for (i
= 0; i
< device
->implicit_swapchain_count
; ++i
)
4364 device
->implicit_swapchains
[i
]->swap_interval
4365 = wined3dswapinterval_from_d3d(parameters
[i
].PresentationInterval
);
4368 for (i
= 0; i
< count
; ++i
)
4370 present_parameters_from_wined3d_swapchain_desc(¶meters
[i
],
4371 &swapchain_desc
[i
], parameters
[i
].PresentationInterval
);
4374 wined3d_mutex_unlock();
4376 heap_free(swapchain_desc
);
4378 /* Initialize the converted declaration array. This creates a valid pointer
4379 * and when adding decls HeapReAlloc() can be used without further checking. */
4380 if (!(device
->fvf_decls
= heap_alloc(0)))
4382 ERR("Failed to allocate FVF vertex declaration map memory.\n");
4383 wined3d_mutex_lock();
4384 heap_free(device
->implicit_swapchains
);
4385 wined3d_device_uninit_3d(device
->wined3d_device
);
4386 wined3d_device_release_focus_window(device
->wined3d_device
);
4387 wined3d_device_decref(device
->wined3d_device
);
4388 wined3d_mutex_unlock();
4389 return E_OUTOFMEMORY
;
4392 /* We could also simply ignore the initial rendertarget since it's known
4393 * not to be a texture (we currently use these only for automatic mipmap
4395 wined3d_mutex_lock();
4396 device
->render_targets
[0] = wined3d_rendertarget_view_get_sub_resource_parent(
4397 wined3d_device_get_rendertarget_view(device
->wined3d_device
, 0));
4398 wined3d_mutex_unlock();
4400 IDirect3D9Ex_AddRef(&parent
->IDirect3D9Ex_iface
);
4401 device
->d3d_parent
= parent
;