2 * IDirect3DDevice9 implementation
4 * Copyright 2002-2005 Jason Edmeades
5 * Copyright 2002-2005 Raphael Junqueira
6 * Copyright 2005 Oliver Stieber
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "d3d9_private.h"
25 static void STDMETHODCALLTYPE
d3d9_null_wined3d_object_destroyed(void *parent
) {}
27 const struct wined3d_parent_ops d3d9_null_wined3d_parent_ops
=
29 d3d9_null_wined3d_object_destroyed
,
32 D3DFORMAT
d3dformat_from_wined3dformat(enum wined3d_format_id format
)
34 BYTE
*c
= (BYTE
*)&format
;
36 /* Don't translate FOURCC formats */
37 if (isprint(c
[0]) && isprint(c
[1]) && isprint(c
[2]) && isprint(c
[3])) return format
;
41 case WINED3DFMT_UNKNOWN
: return D3DFMT_UNKNOWN
;
42 case WINED3DFMT_B8G8R8_UNORM
: return D3DFMT_R8G8B8
;
43 case WINED3DFMT_B8G8R8A8_UNORM
: return D3DFMT_A8R8G8B8
;
44 case WINED3DFMT_B8G8R8X8_UNORM
: return D3DFMT_X8R8G8B8
;
45 case WINED3DFMT_B5G6R5_UNORM
: return D3DFMT_R5G6B5
;
46 case WINED3DFMT_B5G5R5X1_UNORM
: return D3DFMT_X1R5G5B5
;
47 case WINED3DFMT_B5G5R5A1_UNORM
: return D3DFMT_A1R5G5B5
;
48 case WINED3DFMT_B4G4R4A4_UNORM
: return D3DFMT_A4R4G4B4
;
49 case WINED3DFMT_B2G3R3_UNORM
: return D3DFMT_R3G3B2
;
50 case WINED3DFMT_A8_UNORM
: return D3DFMT_A8
;
51 case WINED3DFMT_B2G3R3A8_UNORM
: return D3DFMT_A8R3G3B2
;
52 case WINED3DFMT_B4G4R4X4_UNORM
: return D3DFMT_X4R4G4B4
;
53 case WINED3DFMT_R10G10B10A2_UNORM
: return D3DFMT_A2B10G10R10
;
54 case WINED3DFMT_R8G8B8A8_UNORM
: return D3DFMT_A8B8G8R8
;
55 case WINED3DFMT_R8G8B8X8_UNORM
: return D3DFMT_X8B8G8R8
;
56 case WINED3DFMT_R16G16_UNORM
: return D3DFMT_G16R16
;
57 case WINED3DFMT_B10G10R10A2_UNORM
: return D3DFMT_A2R10G10B10
;
58 case WINED3DFMT_R16G16B16A16_UNORM
: return D3DFMT_A16B16G16R16
;
59 case WINED3DFMT_P8_UINT_A8_UNORM
: return D3DFMT_A8P8
;
60 case WINED3DFMT_P8_UINT
: return D3DFMT_P8
;
61 case WINED3DFMT_L8_UNORM
: return D3DFMT_L8
;
62 case WINED3DFMT_L8A8_UNORM
: return D3DFMT_A8L8
;
63 case WINED3DFMT_L4A4_UNORM
: return D3DFMT_A4L4
;
64 case WINED3DFMT_R8G8_SNORM
: return D3DFMT_V8U8
;
65 case WINED3DFMT_R5G5_SNORM_L6_UNORM
: return D3DFMT_L6V5U5
;
66 case WINED3DFMT_R8G8_SNORM_L8X8_UNORM
: return D3DFMT_X8L8V8U8
;
67 case WINED3DFMT_R8G8B8A8_SNORM
: return D3DFMT_Q8W8V8U8
;
68 case WINED3DFMT_R16G16_SNORM
: return D3DFMT_V16U16
;
69 case WINED3DFMT_R10G10B10_SNORM_A2_UNORM
: return D3DFMT_A2W10V10U10
;
70 case WINED3DFMT_D16_LOCKABLE
: return D3DFMT_D16_LOCKABLE
;
71 case WINED3DFMT_D32_UNORM
: return D3DFMT_D32
;
72 case WINED3DFMT_S1_UINT_D15_UNORM
: return D3DFMT_D15S1
;
73 case WINED3DFMT_D24_UNORM_S8_UINT
: return D3DFMT_D24S8
;
74 case WINED3DFMT_X8D24_UNORM
: return D3DFMT_D24X8
;
75 case WINED3DFMT_S4X4_UINT_D24_UNORM
: return D3DFMT_D24X4S4
;
76 case WINED3DFMT_D16_UNORM
: return D3DFMT_D16
;
77 case WINED3DFMT_L16_UNORM
: return D3DFMT_L16
;
78 case WINED3DFMT_D32_FLOAT
: return D3DFMT_D32F_LOCKABLE
;
79 case WINED3DFMT_S8_UINT_D24_FLOAT
: return D3DFMT_D24FS8
;
80 case WINED3DFMT_R16_UINT
: return D3DFMT_INDEX16
;
81 case WINED3DFMT_R32_UINT
: return D3DFMT_INDEX32
;
82 case WINED3DFMT_R16G16B16A16_SNORM
: return D3DFMT_Q16W16V16U16
;
83 case WINED3DFMT_R16_FLOAT
: return D3DFMT_R16F
;
84 case WINED3DFMT_R16G16_FLOAT
: return D3DFMT_G16R16F
;
85 case WINED3DFMT_R16G16B16A16_FLOAT
: return D3DFMT_A16B16G16R16F
;
86 case WINED3DFMT_R32_FLOAT
: return D3DFMT_R32F
;
87 case WINED3DFMT_R32G32_FLOAT
: return D3DFMT_G32R32F
;
88 case WINED3DFMT_R32G32B32A32_FLOAT
: return D3DFMT_A32B32G32R32F
;
89 case WINED3DFMT_R8G8_SNORM_Cx
: return D3DFMT_CxV8U8
;
91 FIXME("Unhandled wined3d format %#x.\n", format
);
92 return D3DFMT_UNKNOWN
;
96 enum wined3d_format_id
wined3dformat_from_d3dformat(D3DFORMAT format
)
98 BYTE
*c
= (BYTE
*)&format
;
100 /* Don't translate FOURCC formats */
101 if (isprint(c
[0]) && isprint(c
[1]) && isprint(c
[2]) && isprint(c
[3])) return format
;
105 case D3DFMT_UNKNOWN
: return WINED3DFMT_UNKNOWN
;
106 case D3DFMT_R8G8B8
: return WINED3DFMT_B8G8R8_UNORM
;
107 case D3DFMT_A8R8G8B8
: return WINED3DFMT_B8G8R8A8_UNORM
;
108 case D3DFMT_X8R8G8B8
: return WINED3DFMT_B8G8R8X8_UNORM
;
109 case D3DFMT_R5G6B5
: return WINED3DFMT_B5G6R5_UNORM
;
110 case D3DFMT_X1R5G5B5
: return WINED3DFMT_B5G5R5X1_UNORM
;
111 case D3DFMT_A1R5G5B5
: return WINED3DFMT_B5G5R5A1_UNORM
;
112 case D3DFMT_A4R4G4B4
: return WINED3DFMT_B4G4R4A4_UNORM
;
113 case D3DFMT_R3G3B2
: return WINED3DFMT_B2G3R3_UNORM
;
114 case D3DFMT_A8
: return WINED3DFMT_A8_UNORM
;
115 case D3DFMT_A8R3G3B2
: return WINED3DFMT_B2G3R3A8_UNORM
;
116 case D3DFMT_X4R4G4B4
: return WINED3DFMT_B4G4R4X4_UNORM
;
117 case D3DFMT_A2B10G10R10
: return WINED3DFMT_R10G10B10A2_UNORM
;
118 case D3DFMT_A8B8G8R8
: return WINED3DFMT_R8G8B8A8_UNORM
;
119 case D3DFMT_X8B8G8R8
: return WINED3DFMT_R8G8B8X8_UNORM
;
120 case D3DFMT_G16R16
: return WINED3DFMT_R16G16_UNORM
;
121 case D3DFMT_A2R10G10B10
: return WINED3DFMT_B10G10R10A2_UNORM
;
122 case D3DFMT_A16B16G16R16
: return WINED3DFMT_R16G16B16A16_UNORM
;
123 case D3DFMT_A8P8
: return WINED3DFMT_P8_UINT_A8_UNORM
;
124 case D3DFMT_P8
: return WINED3DFMT_P8_UINT
;
125 case D3DFMT_L8
: return WINED3DFMT_L8_UNORM
;
126 case D3DFMT_A8L8
: return WINED3DFMT_L8A8_UNORM
;
127 case D3DFMT_A4L4
: return WINED3DFMT_L4A4_UNORM
;
128 case D3DFMT_V8U8
: return WINED3DFMT_R8G8_SNORM
;
129 case D3DFMT_L6V5U5
: return WINED3DFMT_R5G5_SNORM_L6_UNORM
;
130 case D3DFMT_X8L8V8U8
: return WINED3DFMT_R8G8_SNORM_L8X8_UNORM
;
131 case D3DFMT_Q8W8V8U8
: return WINED3DFMT_R8G8B8A8_SNORM
;
132 case D3DFMT_V16U16
: return WINED3DFMT_R16G16_SNORM
;
133 case D3DFMT_A2W10V10U10
: return WINED3DFMT_R10G10B10_SNORM_A2_UNORM
;
134 case D3DFMT_D16_LOCKABLE
: return WINED3DFMT_D16_LOCKABLE
;
135 case D3DFMT_D32
: return WINED3DFMT_D32_UNORM
;
136 case D3DFMT_D15S1
: return WINED3DFMT_S1_UINT_D15_UNORM
;
137 case D3DFMT_D24S8
: return WINED3DFMT_D24_UNORM_S8_UINT
;
138 case D3DFMT_D24X8
: return WINED3DFMT_X8D24_UNORM
;
139 case D3DFMT_D24X4S4
: return WINED3DFMT_S4X4_UINT_D24_UNORM
;
140 case D3DFMT_D16
: return WINED3DFMT_D16_UNORM
;
141 case D3DFMT_L16
: return WINED3DFMT_L16_UNORM
;
142 case D3DFMT_D32F_LOCKABLE
: return WINED3DFMT_D32_FLOAT
;
143 case D3DFMT_D24FS8
: return WINED3DFMT_S8_UINT_D24_FLOAT
;
144 case D3DFMT_INDEX16
: return WINED3DFMT_R16_UINT
;
145 case D3DFMT_INDEX32
: return WINED3DFMT_R32_UINT
;
146 case D3DFMT_Q16W16V16U16
: return WINED3DFMT_R16G16B16A16_SNORM
;
147 case D3DFMT_R16F
: return WINED3DFMT_R16_FLOAT
;
148 case D3DFMT_G16R16F
: return WINED3DFMT_R16G16_FLOAT
;
149 case D3DFMT_A16B16G16R16F
: return WINED3DFMT_R16G16B16A16_FLOAT
;
150 case D3DFMT_R32F
: return WINED3DFMT_R32_FLOAT
;
151 case D3DFMT_G32R32F
: return WINED3DFMT_R32G32_FLOAT
;
152 case D3DFMT_A32B32G32R32F
: return WINED3DFMT_R32G32B32A32_FLOAT
;
153 case D3DFMT_CxV8U8
: return WINED3DFMT_R8G8_SNORM_Cx
;
155 FIXME("Unhandled D3DFORMAT %#x.\n", format
);
156 return WINED3DFMT_UNKNOWN
;
160 static UINT
vertex_count_from_primitive_count(D3DPRIMITIVETYPE primitive_type
, UINT primitive_count
)
162 switch (primitive_type
)
164 case D3DPT_POINTLIST
:
165 return primitive_count
;
168 return primitive_count
* 2;
170 case D3DPT_LINESTRIP
:
171 return primitive_count
+ 1;
173 case D3DPT_TRIANGLELIST
:
174 return primitive_count
* 3;
176 case D3DPT_TRIANGLESTRIP
:
177 case D3DPT_TRIANGLEFAN
:
178 return primitive_count
+ 2;
181 FIXME("Unhandled primitive type %#x.\n", primitive_type
);
186 void present_parameters_from_wined3d_swapchain_desc(D3DPRESENT_PARAMETERS
*present_parameters
,
187 const struct wined3d_swapchain_desc
*swapchain_desc
)
189 present_parameters
->BackBufferWidth
= swapchain_desc
->backbuffer_width
;
190 present_parameters
->BackBufferHeight
= swapchain_desc
->backbuffer_height
;
191 present_parameters
->BackBufferFormat
= d3dformat_from_wined3dformat(swapchain_desc
->backbuffer_format
);
192 present_parameters
->BackBufferCount
= swapchain_desc
->backbuffer_count
;
193 present_parameters
->MultiSampleType
= swapchain_desc
->multisample_type
;
194 present_parameters
->MultiSampleQuality
= swapchain_desc
->multisample_quality
;
195 present_parameters
->SwapEffect
= swapchain_desc
->swap_effect
;
196 present_parameters
->hDeviceWindow
= swapchain_desc
->device_window
;
197 present_parameters
->Windowed
= swapchain_desc
->windowed
;
198 present_parameters
->EnableAutoDepthStencil
= swapchain_desc
->enable_auto_depth_stencil
;
199 present_parameters
->AutoDepthStencilFormat
200 = d3dformat_from_wined3dformat(swapchain_desc
->auto_depth_stencil_format
);
201 present_parameters
->Flags
= swapchain_desc
->flags
& D3DPRESENTFLAGS_MASK
;
202 present_parameters
->FullScreen_RefreshRateInHz
= swapchain_desc
->refresh_rate
;
203 present_parameters
->PresentationInterval
= swapchain_desc
->swap_interval
;
206 static BOOL
wined3d_swapchain_desc_from_present_parameters(struct wined3d_swapchain_desc
*swapchain_desc
,
207 const D3DPRESENT_PARAMETERS
*present_parameters
, BOOL extended
)
209 D3DSWAPEFFECT highest_swapeffect
= extended
? D3DSWAPEFFECT_FLIPEX
: D3DSWAPEFFECT_COPY
;
210 UINT highest_bb_count
= extended
? 30 : 3;
212 if (!present_parameters
->SwapEffect
|| present_parameters
->SwapEffect
> highest_swapeffect
)
214 WARN("Invalid swap effect %u passed.\n", present_parameters
->SwapEffect
);
217 if (present_parameters
->BackBufferCount
> highest_bb_count
218 || (present_parameters
->SwapEffect
== D3DSWAPEFFECT_COPY
219 && present_parameters
->BackBufferCount
> 1))
221 WARN("Invalid backbuffer count %u.\n", present_parameters
->BackBufferCount
);
225 swapchain_desc
->backbuffer_width
= present_parameters
->BackBufferWidth
;
226 swapchain_desc
->backbuffer_height
= present_parameters
->BackBufferHeight
;
227 swapchain_desc
->backbuffer_format
= wined3dformat_from_d3dformat(present_parameters
->BackBufferFormat
);
228 swapchain_desc
->backbuffer_count
= max(1, present_parameters
->BackBufferCount
);
229 swapchain_desc
->multisample_type
= present_parameters
->MultiSampleType
;
230 swapchain_desc
->multisample_quality
= present_parameters
->MultiSampleQuality
;
231 swapchain_desc
->swap_effect
= present_parameters
->SwapEffect
;
232 swapchain_desc
->device_window
= present_parameters
->hDeviceWindow
;
233 swapchain_desc
->windowed
= present_parameters
->Windowed
;
234 swapchain_desc
->enable_auto_depth_stencil
= present_parameters
->EnableAutoDepthStencil
;
235 swapchain_desc
->auto_depth_stencil_format
236 = wined3dformat_from_d3dformat(present_parameters
->AutoDepthStencilFormat
);
237 swapchain_desc
->flags
238 = (present_parameters
->Flags
& D3DPRESENTFLAGS_MASK
) | WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH
;
239 if (is_gdi_compat_wined3dformat(swapchain_desc
->backbuffer_format
))
240 swapchain_desc
->flags
|= WINED3D_SWAPCHAIN_GDI_COMPATIBLE
;
241 swapchain_desc
->refresh_rate
= present_parameters
->FullScreen_RefreshRateInHz
;
242 swapchain_desc
->swap_interval
= present_parameters
->PresentationInterval
;
243 swapchain_desc
->auto_restore_display_mode
= TRUE
;
245 if (present_parameters
->Flags
& ~D3DPRESENTFLAGS_MASK
)
246 FIXME("Unhandled flags %#x.\n", present_parameters
->Flags
& ~D3DPRESENTFLAGS_MASK
);
251 void d3dcaps_from_wined3dcaps(D3DCAPS9
*caps
, const WINED3DCAPS
*wined3d_caps
)
253 static const DWORD ps_minor_version
[] = {0, 4, 0, 0};
254 static const DWORD vs_minor_version
[] = {0, 1, 0, 0};
255 static const DWORD texture_filter_caps
=
256 D3DPTFILTERCAPS_MINFPOINT
| D3DPTFILTERCAPS_MINFLINEAR
| D3DPTFILTERCAPS_MINFANISOTROPIC
|
257 D3DPTFILTERCAPS_MINFPYRAMIDALQUAD
| D3DPTFILTERCAPS_MINFGAUSSIANQUAD
|
258 D3DPTFILTERCAPS_MIPFPOINT
| D3DPTFILTERCAPS_MIPFLINEAR
| D3DPTFILTERCAPS_MAGFPOINT
|
259 D3DPTFILTERCAPS_MAGFLINEAR
|D3DPTFILTERCAPS_MAGFANISOTROPIC
|D3DPTFILTERCAPS_MAGFPYRAMIDALQUAD
|
260 D3DPTFILTERCAPS_MAGFGAUSSIANQUAD
;
262 caps
->DeviceType
= (D3DDEVTYPE
)wined3d_caps
->DeviceType
;
263 caps
->AdapterOrdinal
= wined3d_caps
->AdapterOrdinal
;
264 caps
->Caps
= wined3d_caps
->Caps
;
265 caps
->Caps2
= wined3d_caps
->Caps2
;
266 caps
->Caps3
= wined3d_caps
->Caps3
;
267 caps
->PresentationIntervals
= wined3d_caps
->PresentationIntervals
;
268 caps
->CursorCaps
= wined3d_caps
->CursorCaps
;
269 caps
->DevCaps
= wined3d_caps
->DevCaps
;
270 caps
->PrimitiveMiscCaps
= wined3d_caps
->PrimitiveMiscCaps
;
271 caps
->RasterCaps
= wined3d_caps
->RasterCaps
;
272 caps
->ZCmpCaps
= wined3d_caps
->ZCmpCaps
;
273 caps
->SrcBlendCaps
= wined3d_caps
->SrcBlendCaps
;
274 caps
->DestBlendCaps
= wined3d_caps
->DestBlendCaps
;
275 caps
->AlphaCmpCaps
= wined3d_caps
->AlphaCmpCaps
;
276 caps
->ShadeCaps
= wined3d_caps
->ShadeCaps
;
277 caps
->TextureCaps
= wined3d_caps
->TextureCaps
;
278 caps
->TextureFilterCaps
= wined3d_caps
->TextureFilterCaps
;
279 caps
->CubeTextureFilterCaps
= wined3d_caps
->CubeTextureFilterCaps
;
280 caps
->VolumeTextureFilterCaps
= wined3d_caps
->VolumeTextureFilterCaps
;
281 caps
->TextureAddressCaps
= wined3d_caps
->TextureAddressCaps
;
282 caps
->VolumeTextureAddressCaps
= wined3d_caps
->VolumeTextureAddressCaps
;
283 caps
->LineCaps
= wined3d_caps
->LineCaps
;
284 caps
->MaxTextureWidth
= wined3d_caps
->MaxTextureWidth
;
285 caps
->MaxTextureHeight
= wined3d_caps
->MaxTextureHeight
;
286 caps
->MaxVolumeExtent
= wined3d_caps
->MaxVolumeExtent
;
287 caps
->MaxTextureRepeat
= wined3d_caps
->MaxTextureRepeat
;
288 caps
->MaxTextureAspectRatio
= wined3d_caps
->MaxTextureAspectRatio
;
289 caps
->MaxAnisotropy
= wined3d_caps
->MaxAnisotropy
;
290 caps
->MaxVertexW
= wined3d_caps
->MaxVertexW
;
291 caps
->GuardBandLeft
= wined3d_caps
->GuardBandLeft
;
292 caps
->GuardBandTop
= wined3d_caps
->GuardBandTop
;
293 caps
->GuardBandRight
= wined3d_caps
->GuardBandRight
;
294 caps
->GuardBandBottom
= wined3d_caps
->GuardBandBottom
;
295 caps
->ExtentsAdjust
= wined3d_caps
->ExtentsAdjust
;
296 caps
->StencilCaps
= wined3d_caps
->StencilCaps
;
297 caps
->FVFCaps
= wined3d_caps
->FVFCaps
;
298 caps
->TextureOpCaps
= wined3d_caps
->TextureOpCaps
;
299 caps
->MaxTextureBlendStages
= wined3d_caps
->MaxTextureBlendStages
;
300 caps
->MaxSimultaneousTextures
= wined3d_caps
->MaxSimultaneousTextures
;
301 caps
->VertexProcessingCaps
= wined3d_caps
->VertexProcessingCaps
;
302 caps
->MaxActiveLights
= wined3d_caps
->MaxActiveLights
;
303 caps
->MaxUserClipPlanes
= wined3d_caps
->MaxUserClipPlanes
;
304 caps
->MaxVertexBlendMatrices
= wined3d_caps
->MaxVertexBlendMatrices
;
305 caps
->MaxVertexBlendMatrixIndex
= wined3d_caps
->MaxVertexBlendMatrixIndex
;
306 caps
->MaxPointSize
= wined3d_caps
->MaxPointSize
;
307 caps
->MaxPrimitiveCount
= wined3d_caps
->MaxPrimitiveCount
;
308 caps
->MaxVertexIndex
= wined3d_caps
->MaxVertexIndex
;
309 caps
->MaxStreams
= wined3d_caps
->MaxStreams
;
310 caps
->MaxStreamStride
= wined3d_caps
->MaxStreamStride
;
311 caps
->VertexShaderVersion
= wined3d_caps
->VertexShaderVersion
;
312 caps
->MaxVertexShaderConst
= wined3d_caps
->MaxVertexShaderConst
;
313 caps
->PixelShaderVersion
= wined3d_caps
->PixelShaderVersion
;
314 caps
->PixelShader1xMaxValue
= wined3d_caps
->PixelShader1xMaxValue
;
315 caps
->DevCaps2
= wined3d_caps
->DevCaps2
;
316 caps
->MaxNpatchTessellationLevel
= wined3d_caps
->MaxNpatchTessellationLevel
;
317 caps
->MasterAdapterOrdinal
= wined3d_caps
->MasterAdapterOrdinal
;
318 caps
->AdapterOrdinalInGroup
= wined3d_caps
->AdapterOrdinalInGroup
;
319 caps
->NumberOfAdaptersInGroup
= wined3d_caps
->NumberOfAdaptersInGroup
;
320 caps
->DeclTypes
= wined3d_caps
->DeclTypes
;
321 caps
->NumSimultaneousRTs
= wined3d_caps
->NumSimultaneousRTs
;
322 caps
->StretchRectFilterCaps
= wined3d_caps
->StretchRectFilterCaps
;
323 caps
->VS20Caps
.Caps
= wined3d_caps
->VS20Caps
.caps
;
324 caps
->VS20Caps
.DynamicFlowControlDepth
= wined3d_caps
->VS20Caps
.dynamic_flow_control_depth
;
325 caps
->VS20Caps
.NumTemps
= wined3d_caps
->VS20Caps
.temp_count
;
326 caps
->VS20Caps
.StaticFlowControlDepth
= wined3d_caps
->VS20Caps
.static_flow_control_depth
;
327 caps
->PS20Caps
.Caps
= wined3d_caps
->PS20Caps
.caps
;
328 caps
->PS20Caps
.DynamicFlowControlDepth
= wined3d_caps
->PS20Caps
.dynamic_flow_control_depth
;
329 caps
->PS20Caps
.NumTemps
= wined3d_caps
->PS20Caps
.temp_count
;
330 caps
->PS20Caps
.StaticFlowControlDepth
= wined3d_caps
->PS20Caps
.static_flow_control_depth
;
331 caps
->PS20Caps
.NumInstructionSlots
= wined3d_caps
->PS20Caps
.instruction_slot_count
;
332 caps
->VertexTextureFilterCaps
= wined3d_caps
->VertexTextureFilterCaps
;
333 caps
->MaxVShaderInstructionsExecuted
= wined3d_caps
->MaxVShaderInstructionsExecuted
;
334 caps
->MaxPShaderInstructionsExecuted
= wined3d_caps
->MaxPShaderInstructionsExecuted
;
335 caps
->MaxVertexShader30InstructionSlots
= wined3d_caps
->MaxVertexShader30InstructionSlots
;
336 caps
->MaxPixelShader30InstructionSlots
= wined3d_caps
->MaxPixelShader30InstructionSlots
;
338 /* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps. */
339 caps
->DevCaps2
|= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES
;
341 /* Filter wined3d caps. */
342 caps
->TextureFilterCaps
&= texture_filter_caps
;
343 caps
->CubeTextureFilterCaps
&= texture_filter_caps
;
344 caps
->VolumeTextureFilterCaps
&= texture_filter_caps
;
347 D3DDEVCAPS_EXECUTESYSTEMMEMORY
| D3DDEVCAPS_EXECUTEVIDEOMEMORY
| D3DDEVCAPS_TLVERTEXSYSTEMMEMORY
|
348 D3DDEVCAPS_TLVERTEXVIDEOMEMORY
| D3DDEVCAPS_TEXTURESYSTEMMEMORY
| D3DDEVCAPS_TEXTUREVIDEOMEMORY
|
349 D3DDEVCAPS_DRAWPRIMTLVERTEX
| D3DDEVCAPS_CANRENDERAFTERFLIP
| D3DDEVCAPS_TEXTURENONLOCALVIDMEM
|
350 D3DDEVCAPS_DRAWPRIMITIVES2
| D3DDEVCAPS_SEPARATETEXTUREMEMORIES
|
351 D3DDEVCAPS_DRAWPRIMITIVES2EX
| D3DDEVCAPS_HWTRANSFORMANDLIGHT
| D3DDEVCAPS_CANBLTSYSTONONLOCAL
|
352 D3DDEVCAPS_HWRASTERIZATION
| D3DDEVCAPS_PUREDEVICE
| D3DDEVCAPS_QUINTICRTPATCHES
|
353 D3DDEVCAPS_RTPATCHES
| D3DDEVCAPS_RTPATCHHANDLEZERO
| D3DDEVCAPS_NPATCHES
;
356 D3DPSHADECAPS_COLORGOURAUDRGB
| D3DPSHADECAPS_SPECULARGOURAUDRGB
|
357 D3DPSHADECAPS_ALPHAGOURAUDBLEND
| D3DPSHADECAPS_FOGGOURAUD
;
360 D3DPRASTERCAPS_DITHER
| D3DPRASTERCAPS_ZTEST
| D3DPRASTERCAPS_FOGVERTEX
|
361 D3DPRASTERCAPS_FOGTABLE
| D3DPRASTERCAPS_MIPMAPLODBIAS
| D3DPRASTERCAPS_ZBUFFERLESSHSR
|
362 D3DPRASTERCAPS_FOGRANGE
| D3DPRASTERCAPS_ANISOTROPY
| D3DPRASTERCAPS_WBUFFER
|
363 D3DPRASTERCAPS_WFOG
| D3DPRASTERCAPS_ZFOG
| D3DPRASTERCAPS_COLORPERSPECTIVE
|
364 D3DPRASTERCAPS_SCISSORTEST
| D3DPRASTERCAPS_SLOPESCALEDEPTHBIAS
|
365 D3DPRASTERCAPS_DEPTHBIAS
| D3DPRASTERCAPS_MULTISAMPLE_TOGGLE
;
368 D3DDEVCAPS2_STREAMOFFSET
| D3DDEVCAPS2_DMAPNPATCH
| D3DDEVCAPS2_ADAPTIVETESSRTPATCH
|
369 D3DDEVCAPS2_ADAPTIVETESSNPATCH
| D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES
|
370 D3DDEVCAPS2_PRESAMPLEDDMAPNPATCH
| D3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET
;
373 D3DCAPS2_FULLSCREENGAMMA
| D3DCAPS2_CANCALIBRATEGAMMA
| D3DCAPS2_RESERVED
|
374 D3DCAPS2_CANMANAGERESOURCE
| D3DCAPS2_DYNAMICTEXTURES
| D3DCAPS2_CANAUTOGENMIPMAP
;
376 caps
->VertexProcessingCaps
&=
377 D3DVTXPCAPS_TEXGEN
| D3DVTXPCAPS_MATERIALSOURCE7
| D3DVTXPCAPS_DIRECTIONALLIGHTS
|
378 D3DVTXPCAPS_POSITIONALLIGHTS
| D3DVTXPCAPS_LOCALVIEWER
| D3DVTXPCAPS_TWEENING
|
379 D3DVTXPCAPS_TEXGEN_SPHEREMAP
| D3DVTXPCAPS_NO_TEXGEN_NONLOCALVIEWER
;
382 D3DPTEXTURECAPS_PERSPECTIVE
| D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_ALPHA
|
383 D3DPTEXTURECAPS_SQUAREONLY
| D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE
|
384 D3DPTEXTURECAPS_ALPHAPALETTE
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
|
385 D3DPTEXTURECAPS_PROJECTED
| D3DPTEXTURECAPS_CUBEMAP
| D3DPTEXTURECAPS_VOLUMEMAP
|
386 D3DPTEXTURECAPS_MIPMAP
| D3DPTEXTURECAPS_MIPVOLUMEMAP
| D3DPTEXTURECAPS_MIPCUBEMAP
|
387 D3DPTEXTURECAPS_CUBEMAP_POW2
| D3DPTEXTURECAPS_VOLUMEMAP_POW2
| D3DPTEXTURECAPS_NOPROJECTEDBUMPENV
;
389 caps
->MaxVertexShaderConst
= min(D3D9_MAX_VERTEX_SHADER_CONSTANTF
, caps
->MaxVertexShaderConst
);
390 caps
->NumSimultaneousRTs
= min(D3D9_MAX_SIMULTANEOUS_RENDERTARGETS
, caps
->NumSimultaneousRTs
);
392 if (caps
->PixelShaderVersion
> 3)
394 caps
->PixelShaderVersion
= D3DPS_VERSION(3, 0);
398 DWORD major
= caps
->PixelShaderVersion
;
399 caps
->PixelShaderVersion
= D3DPS_VERSION(major
, ps_minor_version
[major
]);
402 if (caps
->VertexShaderVersion
> 3)
404 caps
->VertexShaderVersion
= D3DVS_VERSION(3, 0);
408 DWORD major
= caps
->VertexShaderVersion
;
409 caps
->VertexShaderVersion
= D3DVS_VERSION(major
, vs_minor_version
[major
]);
413 static HRESULT WINAPI
d3d9_device_QueryInterface(IDirect3DDevice9Ex
*iface
, REFIID riid
, void **out
)
415 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
417 if (IsEqualGUID(riid
, &IID_IDirect3DDevice9
)
418 || IsEqualGUID(riid
, &IID_IUnknown
))
420 IDirect3DDevice9Ex_AddRef(iface
);
425 if (IsEqualGUID(riid
, &IID_IDirect3DDevice9Ex
))
427 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
429 /* Find out if the creating d3d9 interface was created with Direct3DCreate9Ex.
430 * It doesn't matter with which function the device was created. */
431 if (!device
->d3d_parent
->extended
)
433 WARN("IDirect3D9 instance wasn't created with CreateDirect3D9Ex, returning E_NOINTERFACE.\n");
435 return E_NOINTERFACE
;
438 IDirect3DDevice9Ex_AddRef(iface
);
443 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
446 return E_NOINTERFACE
;
449 static ULONG WINAPI
d3d9_device_AddRef(IDirect3DDevice9Ex
*iface
)
451 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
452 ULONG refcount
= InterlockedIncrement(&device
->refcount
);
454 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
459 static ULONG WINAPI DECLSPEC_HOTPATCH
d3d9_device_Release(IDirect3DDevice9Ex
*iface
)
461 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
464 if (device
->in_destruction
)
467 refcount
= InterlockedDecrement(&device
->refcount
);
469 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
474 device
->in_destruction
= TRUE
;
476 wined3d_mutex_lock();
477 for (i
= 0; i
< device
->fvf_decl_count
; ++i
)
479 wined3d_vertex_declaration_decref(device
->fvf_decls
[i
].decl
);
481 HeapFree(GetProcessHeap(), 0, device
->fvf_decls
);
483 if (device
->vertex_buffer
)
484 wined3d_buffer_decref(device
->vertex_buffer
);
485 if (device
->index_buffer
)
486 wined3d_buffer_decref(device
->index_buffer
);
488 HeapFree(GetProcessHeap(), 0, device
->implicit_swapchains
);
490 wined3d_device_uninit_3d(device
->wined3d_device
);
491 wined3d_device_release_focus_window(device
->wined3d_device
);
492 wined3d_device_decref(device
->wined3d_device
);
493 wined3d_mutex_unlock();
495 IDirect3D9Ex_Release(&device
->d3d_parent
->IDirect3D9Ex_iface
);
497 HeapFree(GetProcessHeap(), 0, device
);
503 static HRESULT WINAPI
d3d9_device_TestCooperativeLevel(IDirect3DDevice9Ex
*iface
)
505 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
507 TRACE("iface %p.\n", iface
);
509 TRACE("device state: %#x.\n", device
->device_state
);
511 if (device
->d3d_parent
->extended
)
514 switch (device
->device_state
)
517 case D3D9_DEVICE_STATE_OK
:
519 case D3D9_DEVICE_STATE_LOST
:
520 return D3DERR_DEVICELOST
;
521 case D3D9_DEVICE_STATE_NOT_RESET
:
522 return D3DERR_DEVICENOTRESET
;
526 static UINT WINAPI
d3d9_device_GetAvailableTextureMem(IDirect3DDevice9Ex
*iface
)
528 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
531 TRACE("iface %p.\n", iface
);
533 wined3d_mutex_lock();
534 ret
= wined3d_device_get_available_texture_mem(device
->wined3d_device
);
535 wined3d_mutex_unlock();
540 static HRESULT WINAPI
d3d9_device_EvictManagedResources(IDirect3DDevice9Ex
*iface
)
542 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
544 TRACE("iface %p.\n", iface
);
546 wined3d_mutex_lock();
547 wined3d_device_evict_managed_resources(device
->wined3d_device
);
548 wined3d_mutex_unlock();
553 static HRESULT WINAPI
d3d9_device_GetDirect3D(IDirect3DDevice9Ex
*iface
, IDirect3D9
**d3d9
)
555 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
557 TRACE("iface %p, d3d9 %p.\n", iface
, d3d9
);
560 return D3DERR_INVALIDCALL
;
562 return IDirect3D9Ex_QueryInterface(&device
->d3d_parent
->IDirect3D9Ex_iface
, &IID_IDirect3D9
, (void **)d3d9
);
565 static HRESULT WINAPI
d3d9_device_GetDeviceCaps(IDirect3DDevice9Ex
*iface
, D3DCAPS9
*caps
)
567 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
568 WINED3DCAPS wined3d_caps
;
571 TRACE("iface %p, caps %p.\n", iface
, caps
);
574 return D3DERR_INVALIDCALL
;
576 memset(caps
, 0, sizeof(*caps
));
578 wined3d_mutex_lock();
579 hr
= wined3d_device_get_device_caps(device
->wined3d_device
, &wined3d_caps
);
580 wined3d_mutex_unlock();
582 d3dcaps_from_wined3dcaps(caps
, &wined3d_caps
);
587 static HRESULT WINAPI
d3d9_device_GetDisplayMode(IDirect3DDevice9Ex
*iface
, UINT swapchain
, D3DDISPLAYMODE
*mode
)
589 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
590 struct wined3d_display_mode wined3d_mode
;
593 TRACE("iface %p, swapchain %u, mode %p.\n", iface
, swapchain
, mode
);
595 wined3d_mutex_lock();
596 hr
= wined3d_device_get_display_mode(device
->wined3d_device
, swapchain
, &wined3d_mode
, NULL
);
597 wined3d_mutex_unlock();
601 mode
->Width
= wined3d_mode
.width
;
602 mode
->Height
= wined3d_mode
.height
;
603 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
604 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
610 static HRESULT WINAPI
d3d9_device_GetCreationParameters(IDirect3DDevice9Ex
*iface
,
611 D3DDEVICE_CREATION_PARAMETERS
*parameters
)
613 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
615 TRACE("iface %p, parameters %p.\n", iface
, parameters
);
617 wined3d_mutex_lock();
618 wined3d_device_get_creation_parameters(device
->wined3d_device
,
619 (struct wined3d_device_creation_parameters
*)parameters
);
620 wined3d_mutex_unlock();
625 static HRESULT WINAPI
d3d9_device_SetCursorProperties(IDirect3DDevice9Ex
*iface
,
626 UINT hotspot_x
, UINT hotspot_y
, IDirect3DSurface9
*bitmap
)
628 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
629 struct d3d9_surface
*bitmap_impl
= unsafe_impl_from_IDirect3DSurface9(bitmap
);
632 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
633 iface
, hotspot_x
, hotspot_y
, bitmap
);
637 WARN("No cursor bitmap, returning D3DERR_INVALIDCALL.\n");
638 return D3DERR_INVALIDCALL
;
641 wined3d_mutex_lock();
642 hr
= wined3d_device_set_cursor_properties(device
->wined3d_device
,
643 hotspot_x
, hotspot_y
, bitmap_impl
->wined3d_texture
, bitmap_impl
->sub_resource_idx
);
644 wined3d_mutex_unlock();
649 static void WINAPI
d3d9_device_SetCursorPosition(IDirect3DDevice9Ex
*iface
, int x
, int y
, DWORD flags
)
651 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
653 TRACE("iface %p, x %u, y %u, flags %#x.\n", iface
, x
, y
, flags
);
655 wined3d_mutex_lock();
656 wined3d_device_set_cursor_position(device
->wined3d_device
, x
, y
, flags
);
657 wined3d_mutex_unlock();
660 static BOOL WINAPI
d3d9_device_ShowCursor(IDirect3DDevice9Ex
*iface
, BOOL show
)
662 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
665 TRACE("iface %p, show %#x.\n", iface
, show
);
667 wined3d_mutex_lock();
668 ret
= wined3d_device_show_cursor(device
->wined3d_device
, show
);
669 wined3d_mutex_unlock();
674 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_CreateAdditionalSwapChain(IDirect3DDevice9Ex
*iface
,
675 D3DPRESENT_PARAMETERS
*present_parameters
, IDirect3DSwapChain9
**swapchain
)
677 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
678 struct wined3d_swapchain_desc desc
;
679 struct d3d9_swapchain
*object
;
683 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
684 iface
, present_parameters
, swapchain
);
686 if (!present_parameters
->Windowed
)
688 WARN("Trying to create an additional fullscreen swapchain, returning D3DERR_INVALIDCALL.\n");
689 return D3DERR_INVALIDCALL
;
692 wined3d_mutex_lock();
693 count
= wined3d_device_get_swapchain_count(device
->wined3d_device
);
694 for (i
= 0; i
< count
; ++i
)
696 struct wined3d_swapchain
*wined3d_swapchain
;
698 wined3d_swapchain
= wined3d_device_get_swapchain(device
->wined3d_device
, i
);
699 wined3d_swapchain_get_desc(wined3d_swapchain
, &desc
);
703 wined3d_mutex_unlock();
704 WARN("Trying to create an additional swapchain in fullscreen mode, returning D3DERR_INVALIDCALL.\n");
705 return D3DERR_INVALIDCALL
;
708 wined3d_mutex_unlock();
710 if (!wined3d_swapchain_desc_from_present_parameters(&desc
, present_parameters
,
711 device
->d3d_parent
->extended
))
712 return D3DERR_INVALIDCALL
;
713 if (SUCCEEDED(hr
= d3d9_swapchain_create(device
, &desc
, &object
)))
714 *swapchain
= (IDirect3DSwapChain9
*)&object
->IDirect3DSwapChain9Ex_iface
;
715 present_parameters_from_wined3d_swapchain_desc(present_parameters
, &desc
);
720 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_GetSwapChain(IDirect3DDevice9Ex
*iface
,
721 UINT swapchain_idx
, IDirect3DSwapChain9
**swapchain
)
723 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
726 TRACE("iface %p, swapchain_idx %u, swapchain %p.\n", iface
, swapchain_idx
, swapchain
);
728 wined3d_mutex_lock();
729 if (swapchain_idx
< device
->implicit_swapchain_count
)
731 *swapchain
= (IDirect3DSwapChain9
*)&device
->implicit_swapchains
[swapchain_idx
]->IDirect3DSwapChain9Ex_iface
;
732 IDirect3DSwapChain9Ex_AddRef(*swapchain
);
738 hr
= D3DERR_INVALIDCALL
;
740 wined3d_mutex_unlock();
745 static UINT WINAPI
d3d9_device_GetNumberOfSwapChains(IDirect3DDevice9Ex
*iface
)
747 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
750 TRACE("iface %p.\n", iface
);
752 wined3d_mutex_lock();
753 count
= wined3d_device_get_swapchain_count(device
->wined3d_device
);
754 wined3d_mutex_unlock();
759 static HRESULT CDECL
reset_enum_callback(struct wined3d_resource
*resource
)
761 struct wined3d_resource_desc desc
;
762 IDirect3DBaseTexture9
*texture
;
763 struct d3d9_surface
*surface
;
766 wined3d_resource_get_desc(resource
, &desc
);
767 if (desc
.pool
!= WINED3D_POOL_DEFAULT
)
770 if (desc
.resource_type
!= WINED3D_RTYPE_TEXTURE_2D
)
772 WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource
);
773 return D3DERR_INVALIDCALL
;
776 parent
= wined3d_resource_get_parent(resource
);
777 if (parent
&& SUCCEEDED(IUnknown_QueryInterface(parent
, &IID_IDirect3DBaseTexture9
, (void **)&texture
)))
779 IDirect3DBaseTexture9_Release(texture
);
780 WARN("Texture %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", texture
, resource
);
781 return D3DERR_INVALIDCALL
;
784 surface
= wined3d_texture_get_sub_resource_parent(wined3d_texture_from_resource(resource
), 0);
785 if (!surface
->resource
.refcount
)
788 WARN("Surface %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface
);
789 return D3DERR_INVALIDCALL
;
792 static HRESULT
d3d9_device_get_swapchains(struct d3d9_device
*device
)
794 UINT i
, new_swapchain_count
= wined3d_device_get_swapchain_count(device
->wined3d_device
);
795 struct wined3d_swapchain
*wined3d_swapchain
;
797 if (!(device
->implicit_swapchains
= HeapAlloc(GetProcessHeap(), 0,
798 new_swapchain_count
* sizeof(*device
->implicit_swapchains
))))
799 return E_OUTOFMEMORY
;
801 for (i
= 0; i
< new_swapchain_count
; ++i
)
803 wined3d_swapchain
= wined3d_device_get_swapchain(device
->wined3d_device
, i
);
804 device
->implicit_swapchains
[i
] = wined3d_swapchain_get_parent(wined3d_swapchain
);
806 device
->implicit_swapchain_count
= new_swapchain_count
;
811 static HRESULT
d3d9_device_reset(struct d3d9_device
*device
,
812 D3DPRESENT_PARAMETERS
*present_parameters
, D3DDISPLAYMODEEX
*mode
)
814 struct wined3d_swapchain_desc swapchain_desc
;
815 struct wined3d_display_mode wined3d_mode
;
818 if (!device
->d3d_parent
->extended
&& device
->device_state
== D3D9_DEVICE_STATE_LOST
)
820 WARN("App not active, returning D3DERR_DEVICELOST.\n");
821 return D3DERR_DEVICELOST
;
826 wined3d_mode
.width
= mode
->Width
;
827 wined3d_mode
.height
= mode
->Height
;
828 wined3d_mode
.refresh_rate
= mode
->RefreshRate
;
829 wined3d_mode
.format_id
= wined3dformat_from_d3dformat(mode
->Format
);
830 wined3d_mode
.scanline_ordering
= mode
->ScanLineOrdering
;
833 if (!wined3d_swapchain_desc_from_present_parameters(&swapchain_desc
, present_parameters
,
834 device
->d3d_parent
->extended
))
835 return D3DERR_INVALIDCALL
;
837 wined3d_mutex_lock();
839 if (device
->vertex_buffer
)
841 wined3d_buffer_decref(device
->vertex_buffer
);
842 device
->vertex_buffer
= NULL
;
843 device
->vertex_buffer_size
= 0;
846 if (device
->index_buffer
)
848 wined3d_buffer_decref(device
->index_buffer
);
849 device
->index_buffer
= NULL
;
850 device
->index_buffer_size
= 0;
853 if (SUCCEEDED(hr
= wined3d_device_reset(device
->wined3d_device
, &swapchain_desc
,
854 mode
? &wined3d_mode
: NULL
, reset_enum_callback
, !device
->d3d_parent
->extended
)))
856 HeapFree(GetProcessHeap(), 0, device
->implicit_swapchains
);
858 if (FAILED(hr
= d3d9_device_get_swapchains(device
)))
860 device
->device_state
= D3D9_DEVICE_STATE_NOT_RESET
;
864 wined3d_swapchain_get_desc(device
->implicit_swapchains
[0]->wined3d_swapchain
, &swapchain_desc
);
865 present_parameters
->BackBufferWidth
= swapchain_desc
.backbuffer_width
;
866 present_parameters
->BackBufferHeight
= swapchain_desc
.backbuffer_height
;
867 present_parameters
->BackBufferFormat
= d3dformat_from_wined3dformat(swapchain_desc
.backbuffer_format
);
868 present_parameters
->BackBufferCount
= swapchain_desc
.backbuffer_count
;
870 device
->device_state
= D3D9_DEVICE_STATE_OK
;
873 else if (!device
->d3d_parent
->extended
)
875 device
->device_state
= D3D9_DEVICE_STATE_NOT_RESET
;
878 wined3d_mutex_unlock();
883 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_Reset(IDirect3DDevice9Ex
*iface
,
884 D3DPRESENT_PARAMETERS
*present_parameters
)
886 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
888 TRACE("iface %p, present_parameters %p.\n", iface
, present_parameters
);
890 return d3d9_device_reset(device
, present_parameters
, NULL
);
893 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_Present(IDirect3DDevice9Ex
*iface
,
894 const RECT
*src_rect
, const RECT
*dst_rect
, HWND dst_window_override
, const RGNDATA
*dirty_region
)
896 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
900 TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
901 iface
, src_rect
, dst_rect
, dst_window_override
, dirty_region
);
903 if (device
->device_state
!= D3D9_DEVICE_STATE_OK
)
904 return device
->d3d_parent
->extended
? S_PRESENT_OCCLUDED
: D3DERR_DEVICELOST
;
907 FIXME("Ignoring dirty_region %p.\n", dirty_region
);
909 wined3d_mutex_lock();
910 for (i
= 0; i
< device
->implicit_swapchain_count
; ++i
)
912 if (FAILED(hr
= wined3d_swapchain_present(device
->implicit_swapchains
[i
]->wined3d_swapchain
,
913 src_rect
, dst_rect
, dst_window_override
, 0)))
915 wined3d_mutex_unlock();
919 wined3d_mutex_unlock();
924 static HRESULT WINAPI
d3d9_device_GetBackBuffer(IDirect3DDevice9Ex
*iface
, UINT swapchain
,
925 UINT backbuffer_idx
, D3DBACKBUFFER_TYPE backbuffer_type
, IDirect3DSurface9
**backbuffer
)
927 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
930 TRACE("iface %p, swapchain %u, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
931 iface
, swapchain
, backbuffer_idx
, backbuffer_type
, backbuffer
);
933 /* backbuffer_type is ignored by native. */
935 /* No need to check for backbuffer == NULL, Windows crashes in that case. */
938 wined3d_mutex_lock();
939 if (swapchain
>= device
->implicit_swapchain_count
)
941 wined3d_mutex_unlock();
942 WARN("Swapchain index %u is out of range, returning D3DERR_INVALIDCALL.\n", swapchain
);
943 return D3DERR_INVALIDCALL
;
946 hr
= IDirect3DSwapChain9Ex_GetBackBuffer(&device
->implicit_swapchains
[swapchain
]->IDirect3DSwapChain9Ex_iface
,
947 backbuffer_idx
, backbuffer_type
, backbuffer
);
948 wined3d_mutex_unlock();
953 static HRESULT WINAPI
d3d9_device_GetRasterStatus(IDirect3DDevice9Ex
*iface
,
954 UINT swapchain
, D3DRASTER_STATUS
*raster_status
)
956 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
959 TRACE("iface %p, swapchain %u, raster_status %p.\n", iface
, swapchain
, raster_status
);
961 wined3d_mutex_lock();
962 hr
= wined3d_device_get_raster_status(device
->wined3d_device
,
963 swapchain
, (struct wined3d_raster_status
*)raster_status
);
964 wined3d_mutex_unlock();
969 static HRESULT WINAPI
d3d9_device_SetDialogBoxMode(IDirect3DDevice9Ex
*iface
, BOOL enable
)
971 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
974 TRACE("iface %p, enable %#x.\n", iface
, enable
);
976 wined3d_mutex_lock();
977 hr
= wined3d_device_set_dialog_box_mode(device
->wined3d_device
, enable
);
978 wined3d_mutex_unlock();
983 static void WINAPI
d3d9_device_SetGammaRamp(IDirect3DDevice9Ex
*iface
,
984 UINT swapchain
, DWORD flags
, const D3DGAMMARAMP
*ramp
)
986 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
988 TRACE("iface %p, swapchain %u, flags %#x, ramp %p.\n", iface
, swapchain
, flags
, ramp
);
990 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
991 wined3d_mutex_lock();
992 wined3d_device_set_gamma_ramp(device
->wined3d_device
, swapchain
, flags
, (const struct wined3d_gamma_ramp
*)ramp
);
993 wined3d_mutex_unlock();
996 static void WINAPI
d3d9_device_GetGammaRamp(IDirect3DDevice9Ex
*iface
, UINT swapchain
, D3DGAMMARAMP
*ramp
)
998 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1000 TRACE("iface %p, swapchain %u, ramp %p.\n", iface
, swapchain
, ramp
);
1002 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
1003 wined3d_mutex_lock();
1004 wined3d_device_get_gamma_ramp(device
->wined3d_device
, swapchain
, (struct wined3d_gamma_ramp
*)ramp
);
1005 wined3d_mutex_unlock();
1008 static HRESULT WINAPI
d3d9_device_CreateTexture(IDirect3DDevice9Ex
*iface
,
1009 UINT width
, UINT height
, UINT levels
, DWORD usage
, D3DFORMAT format
,
1010 D3DPOOL pool
, IDirect3DTexture9
**texture
, HANDLE
*shared_handle
)
1012 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1013 struct d3d9_texture
*object
;
1014 BOOL set_mem
= FALSE
;
1017 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
1018 iface
, width
, height
, levels
, usage
, format
, pool
, texture
, shared_handle
);
1023 if (!device
->d3d_parent
->extended
)
1025 WARN("Trying to create a shared or user memory texture on a non-ex device.\n");
1029 if (pool
== D3DPOOL_SYSTEMMEM
)
1032 return D3DERR_INVALIDCALL
;
1037 if (pool
!= D3DPOOL_DEFAULT
)
1039 WARN("Trying to create a shared texture in pool %#x.\n", pool
);
1040 return D3DERR_INVALIDCALL
;
1042 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1046 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1048 return D3DERR_OUTOFVIDEOMEMORY
;
1050 hr
= texture_init(object
, device
, width
, height
, levels
, usage
, format
, pool
);
1053 WARN("Failed to initialize texture, hr %#x.\n", hr
);
1054 HeapFree(GetProcessHeap(), 0, object
);
1059 wined3d_texture_update_desc(object
->wined3d_texture
, width
, height
,
1060 wined3dformat_from_d3dformat(format
), WINED3D_MULTISAMPLE_NONE
, 0,
1063 TRACE("Created texture %p.\n", object
);
1064 *texture
= (IDirect3DTexture9
*)&object
->IDirect3DBaseTexture9_iface
;
1069 static HRESULT WINAPI
d3d9_device_CreateVolumeTexture(IDirect3DDevice9Ex
*iface
,
1070 UINT width
, UINT height
, UINT depth
, UINT levels
, DWORD usage
, D3DFORMAT format
,
1071 D3DPOOL pool
, IDirect3DVolumeTexture9
**texture
, HANDLE
*shared_handle
)
1073 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1074 struct d3d9_texture
*object
;
1077 TRACE("iface %p, width %u, height %u, depth %u, levels %u, "
1078 "usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
1079 iface
, width
, height
, depth
, levels
,
1080 usage
, format
, pool
, texture
, shared_handle
);
1085 if (!device
->d3d_parent
->extended
)
1087 WARN("Trying to create a shared volume texture on a non-ex device.\n");
1091 if (pool
!= D3DPOOL_DEFAULT
)
1093 WARN("Trying to create a shared volume texture in pool %#x.\n", pool
);
1094 return D3DERR_INVALIDCALL
;
1096 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1099 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1101 return D3DERR_OUTOFVIDEOMEMORY
;
1103 hr
= volumetexture_init(object
, device
, width
, height
, depth
, levels
, usage
, format
, pool
);
1106 WARN("Failed to initialize volume texture, hr %#x.\n", hr
);
1107 HeapFree(GetProcessHeap(), 0, object
);
1111 TRACE("Created volume texture %p.\n", object
);
1112 *texture
= (IDirect3DVolumeTexture9
*)&object
->IDirect3DBaseTexture9_iface
;
1117 static HRESULT WINAPI
d3d9_device_CreateCubeTexture(IDirect3DDevice9Ex
*iface
,
1118 UINT edge_length
, UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
,
1119 IDirect3DCubeTexture9
**texture
, HANDLE
*shared_handle
)
1121 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1122 struct d3d9_texture
*object
;
1125 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
1126 iface
, edge_length
, levels
, usage
, format
, pool
, texture
, shared_handle
);
1131 if (!device
->d3d_parent
->extended
)
1133 WARN("Trying to create a shared cube texture on a non-ex device.\n");
1137 if (pool
!= D3DPOOL_DEFAULT
)
1139 WARN("Trying to create a shared cube texture in pool %#x.\n", pool
);
1140 return D3DERR_INVALIDCALL
;
1142 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1145 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1147 return D3DERR_OUTOFVIDEOMEMORY
;
1149 hr
= cubetexture_init(object
, device
, edge_length
, levels
, usage
, format
, pool
);
1152 WARN("Failed to initialize cube texture, hr %#x.\n", hr
);
1153 HeapFree(GetProcessHeap(), 0, object
);
1157 TRACE("Created cube texture %p.\n", object
);
1158 *texture
= (IDirect3DCubeTexture9
*)&object
->IDirect3DBaseTexture9_iface
;
1163 static HRESULT WINAPI
d3d9_device_CreateVertexBuffer(IDirect3DDevice9Ex
*iface
, UINT size
,
1164 DWORD usage
, DWORD fvf
, D3DPOOL pool
, IDirect3DVertexBuffer9
**buffer
,
1165 HANDLE
*shared_handle
)
1167 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1168 struct d3d9_vertexbuffer
*object
;
1171 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p, shared_handle %p.\n",
1172 iface
, size
, usage
, fvf
, pool
, buffer
, shared_handle
);
1176 if (!device
->d3d_parent
->extended
)
1178 WARN("Trying to create a shared vertex buffer on a non-ex device.\n");
1182 if (pool
!= D3DPOOL_DEFAULT
)
1184 WARN("Trying to create a shared vertex buffer in pool %#x.\n", pool
);
1185 return D3DERR_NOTAVAILABLE
;
1187 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1190 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1192 return D3DERR_OUTOFVIDEOMEMORY
;
1194 hr
= vertexbuffer_init(object
, device
, size
, usage
, fvf
, pool
);
1197 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr
);
1198 HeapFree(GetProcessHeap(), 0, object
);
1202 TRACE("Created vertex buffer %p.\n", object
);
1203 *buffer
= &object
->IDirect3DVertexBuffer9_iface
;
1208 static HRESULT WINAPI
d3d9_device_CreateIndexBuffer(IDirect3DDevice9Ex
*iface
, UINT size
,
1209 DWORD usage
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DIndexBuffer9
**buffer
,
1210 HANDLE
*shared_handle
)
1212 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1213 struct d3d9_indexbuffer
*object
;
1216 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p, shared_handle %p.\n",
1217 iface
, size
, usage
, format
, pool
, buffer
, shared_handle
);
1221 if (!device
->d3d_parent
->extended
)
1223 WARN("Trying to create a shared index buffer on a non-ex device.\n");
1227 if (pool
!= D3DPOOL_DEFAULT
)
1229 WARN("Trying to create a shared index buffer in pool %#x.\n", pool
);
1230 return D3DERR_NOTAVAILABLE
;
1232 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1235 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1237 return D3DERR_OUTOFVIDEOMEMORY
;
1239 hr
= indexbuffer_init(object
, device
, size
, usage
, format
, pool
);
1242 WARN("Failed to initialize index buffer, hr %#x.\n", hr
);
1243 HeapFree(GetProcessHeap(), 0, object
);
1247 TRACE("Created index buffer %p.\n", object
);
1248 *buffer
= &object
->IDirect3DIndexBuffer9_iface
;
1253 static HRESULT
d3d9_device_create_surface(struct d3d9_device
*device
, UINT width
, UINT height
,
1254 D3DFORMAT format
, DWORD flags
, IDirect3DSurface9
**surface
, UINT usage
, D3DPOOL pool
,
1255 D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
, void *user_mem
)
1257 struct wined3d_resource_desc desc
;
1258 struct d3d9_surface
*surface_impl
;
1259 struct wined3d_texture
*texture
;
1262 TRACE("device %p, width %u, height %u, format %#x, flags %#x, surface %p.\n"
1263 "usage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
1264 device
, width
, height
, format
, flags
, surface
, usage
, pool
,
1265 multisample_type
, multisample_quality
);
1267 desc
.resource_type
= WINED3D_RTYPE_TEXTURE_2D
;
1268 desc
.format
= wined3dformat_from_d3dformat(format
);
1269 desc
.multisample_type
= multisample_type
;
1270 desc
.multisample_quality
= multisample_quality
;
1271 desc
.usage
= usage
& WINED3DUSAGE_MASK
;
1274 desc
.height
= height
;
1278 if (is_gdi_compat_wined3dformat(desc
.format
))
1279 flags
|= WINED3D_TEXTURE_CREATE_GET_DC
;
1281 wined3d_mutex_lock();
1283 if (FAILED(hr
= wined3d_texture_create(device
->wined3d_device
, &desc
,
1284 1, 1, flags
, NULL
, NULL
, &d3d9_null_wined3d_parent_ops
, &texture
)))
1286 wined3d_mutex_unlock();
1287 WARN("Failed to create texture, hr %#x.\n", hr
);
1288 if (hr
== WINED3DERR_NOTAVAILABLE
)
1289 hr
= D3DERR_INVALIDCALL
;
1293 surface_impl
= wined3d_texture_get_sub_resource_parent(texture
, 0);
1294 surface_impl
->parent_device
= &device
->IDirect3DDevice9Ex_iface
;
1295 *surface
= &surface_impl
->IDirect3DSurface9_iface
;
1296 IDirect3DSurface9_AddRef(*surface
);
1299 wined3d_texture_update_desc(texture
, width
, height
,
1300 desc
.format
, multisample_type
, multisample_quality
, user_mem
, 0);
1302 wined3d_texture_decref(texture
);
1304 wined3d_mutex_unlock();
1309 BOOL
is_gdi_compat_wined3dformat(enum wined3d_format_id format
)
1313 case WINED3DFMT_B8G8R8A8_UNORM
:
1314 case WINED3DFMT_B8G8R8X8_UNORM
:
1315 case WINED3DFMT_B5G6R5_UNORM
:
1316 case WINED3DFMT_B5G5R5X1_UNORM
:
1317 case WINED3DFMT_B5G5R5A1_UNORM
:
1318 case WINED3DFMT_B8G8R8_UNORM
:
1325 static HRESULT WINAPI
d3d9_device_CreateRenderTarget(IDirect3DDevice9Ex
*iface
, UINT width
, UINT height
,
1326 D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
1327 BOOL lockable
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
)
1329 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1332 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
1333 "lockable %#x, surface %p, shared_handle %p.\n",
1334 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
1335 lockable
, surface
, shared_handle
);
1340 if (!device
->d3d_parent
->extended
)
1342 WARN("Trying to create a shared render target on a non-ex device.\n");
1346 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1350 flags
|= WINED3D_TEXTURE_CREATE_MAPPABLE
;
1352 return d3d9_device_create_surface(device
, width
, height
, format
, flags
, surface
,
1353 D3DUSAGE_RENDERTARGET
, D3DPOOL_DEFAULT
, multisample_type
, multisample_quality
, NULL
);
1356 static HRESULT WINAPI
d3d9_device_CreateDepthStencilSurface(IDirect3DDevice9Ex
*iface
, UINT width
, UINT height
,
1357 D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
1358 BOOL discard
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
)
1360 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1361 DWORD flags
= WINED3D_TEXTURE_CREATE_MAPPABLE
;
1363 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
1364 "discard %#x, surface %p, shared_handle %p.\n",
1365 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
1366 discard
, surface
, shared_handle
);
1371 if (!device
->d3d_parent
->extended
)
1373 WARN("Trying to create a shared depth stencil on a non-ex device.\n");
1377 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1381 flags
|= WINED3D_TEXTURE_CREATE_DISCARD
;
1383 return d3d9_device_create_surface(device
, width
, height
, format
, flags
, surface
,
1384 D3DUSAGE_DEPTHSTENCIL
, D3DPOOL_DEFAULT
, multisample_type
, multisample_quality
, NULL
);
1388 static HRESULT WINAPI
d3d9_device_UpdateSurface(IDirect3DDevice9Ex
*iface
,
1389 IDirect3DSurface9
*src_surface
, const RECT
*src_rect
,
1390 IDirect3DSurface9
*dst_surface
, const POINT
*dst_point
)
1392 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1393 struct d3d9_surface
*src
= unsafe_impl_from_IDirect3DSurface9(src_surface
);
1394 struct d3d9_surface
*dst
= unsafe_impl_from_IDirect3DSurface9(dst_surface
);
1395 struct wined3d_box src_box
;
1398 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_point %p.\n",
1399 iface
, src_surface
, src_rect
, dst_surface
, dst_point
);
1402 wined3d_box_set(&src_box
, src_rect
->left
, src_rect
->top
, src_rect
->right
, src_rect
->bottom
, 0, 1);
1404 wined3d_mutex_lock();
1405 hr
= wined3d_device_copy_sub_resource_region(device
->wined3d_device
,
1406 wined3d_texture_get_resource(dst
->wined3d_texture
), dst
->sub_resource_idx
, dst_point
? dst_point
->x
: 0,
1407 dst_point
? dst_point
->y
: 0, 0, wined3d_texture_get_resource(src
->wined3d_texture
),
1408 src
->sub_resource_idx
, src_rect
? &src_box
: NULL
);
1409 wined3d_mutex_unlock();
1412 return D3DERR_INVALIDCALL
;
1417 static HRESULT WINAPI
d3d9_device_UpdateTexture(IDirect3DDevice9Ex
*iface
,
1418 IDirect3DBaseTexture9
*src_texture
, IDirect3DBaseTexture9
*dst_texture
)
1420 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1421 struct d3d9_texture
*src_impl
, *dst_impl
;
1424 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface
, src_texture
, dst_texture
);
1426 src_impl
= unsafe_impl_from_IDirect3DBaseTexture9(src_texture
);
1427 dst_impl
= unsafe_impl_from_IDirect3DBaseTexture9(dst_texture
);
1429 wined3d_mutex_lock();
1430 hr
= wined3d_device_update_texture(device
->wined3d_device
,
1431 src_impl
->wined3d_texture
, dst_impl
->wined3d_texture
);
1432 wined3d_mutex_unlock();
1437 static HRESULT WINAPI
d3d9_device_GetRenderTargetData(IDirect3DDevice9Ex
*iface
,
1438 IDirect3DSurface9
*render_target
, IDirect3DSurface9
*dst_surface
)
1440 struct d3d9_surface
*rt_impl
= unsafe_impl_from_IDirect3DSurface9(render_target
);
1441 struct d3d9_surface
*dst_impl
= unsafe_impl_from_IDirect3DSurface9(dst_surface
);
1442 struct wined3d_sub_resource_desc wined3d_desc
;
1443 RECT dst_rect
, src_rect
;
1446 TRACE("iface %p, render_target %p, dst_surface %p.\n", iface
, render_target
, dst_surface
);
1448 if (!render_target
|| !dst_surface
)
1449 return D3DERR_INVALIDCALL
;
1451 wined3d_mutex_lock();
1452 wined3d_texture_get_sub_resource_desc(dst_impl
->wined3d_texture
, dst_impl
->sub_resource_idx
, &wined3d_desc
);
1453 SetRect(&dst_rect
, 0, 0, wined3d_desc
.width
, wined3d_desc
.height
);
1455 wined3d_texture_get_sub_resource_desc(rt_impl
->wined3d_texture
, rt_impl
->sub_resource_idx
, &wined3d_desc
);
1456 SetRect(&src_rect
, 0, 0, wined3d_desc
.width
, wined3d_desc
.height
);
1458 /* TODO: Check surface sizes, pools, etc. */
1459 if (wined3d_desc
.multisample_type
)
1460 hr
= D3DERR_INVALIDCALL
;
1462 hr
= wined3d_texture_blt(dst_impl
->wined3d_texture
, dst_impl
->sub_resource_idx
, &dst_rect
,
1463 rt_impl
->wined3d_texture
, rt_impl
->sub_resource_idx
, &src_rect
, 0, NULL
, WINED3D_TEXF_POINT
);
1464 wined3d_mutex_unlock();
1469 static HRESULT WINAPI
d3d9_device_GetFrontBufferData(IDirect3DDevice9Ex
*iface
,
1470 UINT swapchain
, IDirect3DSurface9
*dst_surface
)
1472 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1473 struct d3d9_surface
*dst_impl
= unsafe_impl_from_IDirect3DSurface9(dst_surface
);
1474 HRESULT hr
= D3DERR_INVALIDCALL
;
1476 TRACE("iface %p, swapchain %u, dst_surface %p.\n", iface
, swapchain
, dst_surface
);
1478 wined3d_mutex_lock();
1479 if (swapchain
< device
->implicit_swapchain_count
)
1480 hr
= wined3d_swapchain_get_front_buffer_data(device
->implicit_swapchains
[swapchain
]->wined3d_swapchain
,
1481 dst_impl
->wined3d_texture
, dst_impl
->sub_resource_idx
);
1482 wined3d_mutex_unlock();
1487 static HRESULT WINAPI
d3d9_device_StretchRect(IDirect3DDevice9Ex
*iface
, IDirect3DSurface9
*src_surface
,
1488 const RECT
*src_rect
, IDirect3DSurface9
*dst_surface
, const RECT
*dst_rect
, D3DTEXTUREFILTERTYPE filter
)
1490 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1491 struct d3d9_surface
*src
= unsafe_impl_from_IDirect3DSurface9(src_surface
);
1492 struct d3d9_surface
*dst
= unsafe_impl_from_IDirect3DSurface9(dst_surface
);
1493 struct wined3d_sub_resource_desc src_desc
, dst_desc
;
1494 HRESULT hr
= D3DERR_INVALIDCALL
;
1497 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_rect %p, filter %#x.\n",
1498 iface
, src_surface
, src_rect
, dst_surface
, dst_rect
, filter
);
1500 wined3d_mutex_lock();
1501 wined3d_texture_get_sub_resource_desc(dst
->wined3d_texture
, dst
->sub_resource_idx
, &dst_desc
);
1504 SetRect(&d
, 0, 0, dst_desc
.width
, dst_desc
.height
);
1508 wined3d_texture_get_sub_resource_desc(src
->wined3d_texture
, src
->sub_resource_idx
, &src_desc
);
1511 SetRect(&s
, 0, 0, src_desc
.width
, src_desc
.height
);
1515 if (src_desc
.usage
& WINED3DUSAGE_DEPTHSTENCIL
)
1517 if (device
->in_scene
)
1519 WARN("Rejecting depth / stencil blit while in scene.\n");
1523 if (src_rect
->left
|| src_rect
->top
|| src_rect
->right
!= src_desc
.width
1524 || src_rect
->bottom
!= src_desc
.height
)
1526 WARN("Rejecting depth / stencil blit with invalid source rect %s.\n",
1527 wine_dbgstr_rect(src_rect
));
1531 if (dst_rect
->left
|| dst_rect
->top
|| dst_rect
->right
!= dst_desc
.width
1532 || dst_rect
->bottom
!= dst_desc
.height
)
1534 WARN("Rejecting depth / stencil blit with invalid destination rect %s.\n",
1535 wine_dbgstr_rect(dst_rect
));
1539 if (src_desc
.width
!= dst_desc
.width
|| src_desc
.height
!= dst_desc
.height
)
1541 WARN("Rejecting depth / stencil blit with mismatched surface sizes.\n");
1546 hr
= wined3d_texture_blt(dst
->wined3d_texture
, dst
->sub_resource_idx
, dst_rect
,
1547 src
->wined3d_texture
, src
->sub_resource_idx
, src_rect
, 0, NULL
, filter
);
1548 if (hr
== WINEDDERR_INVALIDRECT
)
1549 hr
= D3DERR_INVALIDCALL
;
1552 wined3d_mutex_unlock();
1556 static HRESULT WINAPI
d3d9_device_ColorFill(IDirect3DDevice9Ex
*iface
,
1557 IDirect3DSurface9
*surface
, const RECT
*rect
, D3DCOLOR color
)
1559 const struct wined3d_color c
=
1561 ((color
>> 16) & 0xff) / 255.0f
,
1562 ((color
>> 8) & 0xff) / 255.0f
,
1563 (color
& 0xff) / 255.0f
,
1564 ((color
>> 24) & 0xff) / 255.0f
,
1566 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1567 struct d3d9_surface
*surface_impl
= unsafe_impl_from_IDirect3DSurface9(surface
);
1568 struct wined3d_sub_resource_desc desc
;
1569 struct wined3d_rendertarget_view
*rtv
;
1572 TRACE("iface %p, surface %p, rect %p, color 0x%08x.\n", iface
, surface
, rect
, color
);
1574 wined3d_mutex_lock();
1576 if (FAILED(wined3d_texture_get_sub_resource_desc(surface_impl
->wined3d_texture
,
1577 surface_impl
->sub_resource_idx
, &desc
)))
1579 wined3d_mutex_unlock();
1580 return D3DERR_INVALIDCALL
;
1583 if (desc
.pool
!= WINED3D_POOL_DEFAULT
)
1585 wined3d_mutex_unlock();
1586 WARN("Colorfill is not allowed on surfaces in pool %#x, returning D3DERR_INVALIDCALL.\n", desc
.pool
);
1587 return D3DERR_INVALIDCALL
;
1589 if ((desc
.usage
& (WINED3DUSAGE_RENDERTARGET
| WINED3DUSAGE_TEXTURE
)) == WINED3DUSAGE_TEXTURE
)
1591 wined3d_mutex_unlock();
1592 WARN("Colorfill is not allowed on non-RT textures, returning D3DERR_INVALIDCALL.\n");
1593 return D3DERR_INVALIDCALL
;
1595 if (desc
.usage
& WINED3DUSAGE_DEPTHSTENCIL
)
1597 wined3d_mutex_unlock();
1598 WARN("Colorfill is not allowed on depth stencil surfaces, returning D3DERR_INVALIDCALL.\n");
1599 return D3DERR_INVALIDCALL
;
1602 rtv
= d3d9_surface_acquire_rendertarget_view(surface_impl
);
1603 hr
= wined3d_device_clear_rendertarget_view(device
->wined3d_device
,
1604 rtv
, rect
, WINED3DCLEAR_TARGET
, &c
, 0.0f
, 0);
1605 d3d9_surface_release_rendertarget_view(surface_impl
, rtv
);
1607 wined3d_mutex_unlock();
1612 static HRESULT WINAPI
d3d9_device_CreateOffscreenPlainSurface(IDirect3DDevice9Ex
*iface
,
1613 UINT width
, UINT height
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DSurface9
**surface
,
1614 HANDLE
*shared_handle
)
1616 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1617 void *user_mem
= NULL
;
1619 TRACE("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p.\n",
1620 iface
, width
, height
, format
, pool
, surface
, shared_handle
);
1623 if (pool
== D3DPOOL_MANAGED
)
1625 WARN("Attempting to create a managed offscreen plain surface.\n");
1626 return D3DERR_INVALIDCALL
;
1631 if (!device
->d3d_parent
->extended
)
1633 WARN("Trying to create a shared or user memory surface on a non-ex device.\n");
1637 if (pool
== D3DPOOL_SYSTEMMEM
)
1638 user_mem
= *shared_handle
;
1641 if (pool
!= D3DPOOL_DEFAULT
)
1643 WARN("Trying to create a shared surface in pool %#x.\n", pool
);
1644 return D3DERR_INVALIDCALL
;
1646 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1650 /* FIXME: Offscreen surfaces are supposed to be always lockable,
1651 * regardless of the pool they're created in. Should we set dynamic usage
1653 return d3d9_device_create_surface(device
, width
, height
, format
,
1654 WINED3D_TEXTURE_CREATE_MAPPABLE
, surface
, 0, pool
, D3DMULTISAMPLE_NONE
, 0, user_mem
);
1657 static HRESULT WINAPI
d3d9_device_SetRenderTarget(IDirect3DDevice9Ex
*iface
, DWORD idx
, IDirect3DSurface9
*surface
)
1659 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1660 struct d3d9_surface
*surface_impl
= unsafe_impl_from_IDirect3DSurface9(surface
);
1661 struct wined3d_rendertarget_view
*rtv
;
1664 TRACE("iface %p, idx %u, surface %p.\n", iface
, idx
, surface
);
1666 if (idx
>= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS
)
1668 WARN("Invalid index %u specified.\n", idx
);
1669 return D3DERR_INVALIDCALL
;
1672 if (!idx
&& !surface_impl
)
1674 WARN("Trying to set render target 0 to NULL.\n");
1675 return D3DERR_INVALIDCALL
;
1678 if (surface_impl
&& d3d9_surface_get_device(surface_impl
) != device
)
1680 WARN("Render target surface does not match device.\n");
1681 return D3DERR_INVALIDCALL
;
1684 wined3d_mutex_lock();
1685 rtv
= surface_impl
? d3d9_surface_acquire_rendertarget_view(surface_impl
) : NULL
;
1686 hr
= wined3d_device_set_rendertarget_view(device
->wined3d_device
, idx
, rtv
, TRUE
);
1687 d3d9_surface_release_rendertarget_view(surface_impl
, rtv
);
1688 wined3d_mutex_unlock();
1693 static HRESULT WINAPI
d3d9_device_GetRenderTarget(IDirect3DDevice9Ex
*iface
, DWORD idx
, IDirect3DSurface9
**surface
)
1695 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1696 struct wined3d_rendertarget_view
*wined3d_rtv
;
1697 struct d3d9_surface
*surface_impl
;
1698 HRESULT hr
= D3D_OK
;
1700 TRACE("iface %p, idx %u, surface %p.\n", iface
, idx
, surface
);
1703 return D3DERR_INVALIDCALL
;
1705 if (idx
>= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS
)
1707 WARN("Invalid index %u specified.\n", idx
);
1708 return D3DERR_INVALIDCALL
;
1711 wined3d_mutex_lock();
1712 if ((wined3d_rtv
= wined3d_device_get_rendertarget_view(device
->wined3d_device
, idx
)))
1714 /* We want the sub resource parent here, since the view itself may be
1715 * internal to wined3d and may not have a parent. */
1716 surface_impl
= wined3d_rendertarget_view_get_sub_resource_parent(wined3d_rtv
);
1717 *surface
= &surface_impl
->IDirect3DSurface9_iface
;
1718 IDirect3DSurface9_AddRef(*surface
);
1722 hr
= D3DERR_NOTFOUND
;
1725 wined3d_mutex_unlock();
1730 static HRESULT WINAPI
d3d9_device_SetDepthStencilSurface(IDirect3DDevice9Ex
*iface
, IDirect3DSurface9
*depth_stencil
)
1732 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1733 struct d3d9_surface
*ds_impl
= unsafe_impl_from_IDirect3DSurface9(depth_stencil
);
1734 struct wined3d_rendertarget_view
*rtv
;
1736 TRACE("iface %p, depth_stencil %p.\n", iface
, depth_stencil
);
1738 wined3d_mutex_lock();
1739 rtv
= ds_impl
? d3d9_surface_acquire_rendertarget_view(ds_impl
) : NULL
;
1740 wined3d_device_set_depth_stencil_view(device
->wined3d_device
, rtv
);
1741 d3d9_surface_release_rendertarget_view(ds_impl
, rtv
);
1742 wined3d_mutex_unlock();
1747 static HRESULT WINAPI
d3d9_device_GetDepthStencilSurface(IDirect3DDevice9Ex
*iface
, IDirect3DSurface9
**depth_stencil
)
1749 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1750 struct wined3d_rendertarget_view
*wined3d_dsv
;
1751 struct d3d9_surface
*surface_impl
;
1752 HRESULT hr
= D3D_OK
;
1754 TRACE("iface %p, depth_stencil %p.\n", iface
, depth_stencil
);
1757 return D3DERR_INVALIDCALL
;
1759 wined3d_mutex_lock();
1760 if ((wined3d_dsv
= wined3d_device_get_depth_stencil_view(device
->wined3d_device
)))
1762 /* We want the sub resource parent here, since the view itself may be
1763 * internal to wined3d and may not have a parent. */
1764 surface_impl
= wined3d_rendertarget_view_get_sub_resource_parent(wined3d_dsv
);
1765 *depth_stencil
= &surface_impl
->IDirect3DSurface9_iface
;
1766 IDirect3DSurface9_AddRef(*depth_stencil
);
1770 hr
= D3DERR_NOTFOUND
;
1771 *depth_stencil
= NULL
;
1773 wined3d_mutex_unlock();
1778 static HRESULT WINAPI
d3d9_device_BeginScene(IDirect3DDevice9Ex
*iface
)
1780 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1783 TRACE("iface %p.\n", iface
);
1785 wined3d_mutex_lock();
1786 if (SUCCEEDED(hr
= wined3d_device_begin_scene(device
->wined3d_device
)))
1787 device
->in_scene
= TRUE
;
1788 wined3d_mutex_unlock();
1793 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_EndScene(IDirect3DDevice9Ex
*iface
)
1795 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1798 TRACE("iface %p.\n", iface
);
1800 wined3d_mutex_lock();
1801 if (SUCCEEDED(hr
= wined3d_device_end_scene(device
->wined3d_device
)))
1802 device
->in_scene
= FALSE
;
1803 wined3d_mutex_unlock();
1808 static HRESULT WINAPI
d3d9_device_Clear(IDirect3DDevice9Ex
*iface
, DWORD rect_count
,
1809 const D3DRECT
*rects
, DWORD flags
, D3DCOLOR color
, float z
, DWORD stencil
)
1811 const struct wined3d_color c
=
1813 ((color
>> 16) & 0xff) / 255.0f
,
1814 ((color
>> 8) & 0xff) / 255.0f
,
1815 (color
& 0xff) / 255.0f
,
1816 ((color
>> 24) & 0xff) / 255.0f
,
1818 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1821 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1822 iface
, rect_count
, rects
, flags
, color
, z
, stencil
);
1824 if (rect_count
&& !rects
)
1826 WARN("count %u with NULL rects.\n", rect_count
);
1830 wined3d_mutex_lock();
1831 hr
= wined3d_device_clear(device
->wined3d_device
, rect_count
, (const RECT
*)rects
, flags
, &c
, z
, stencil
);
1832 wined3d_mutex_unlock();
1837 static HRESULT WINAPI
d3d9_device_SetTransform(IDirect3DDevice9Ex
*iface
,
1838 D3DTRANSFORMSTATETYPE state
, const D3DMATRIX
*matrix
)
1840 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1842 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1844 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1845 wined3d_mutex_lock();
1846 wined3d_device_set_transform(device
->wined3d_device
, state
, (const struct wined3d_matrix
*)matrix
);
1847 wined3d_mutex_unlock();
1852 static HRESULT WINAPI
d3d9_device_GetTransform(IDirect3DDevice9Ex
*iface
,
1853 D3DTRANSFORMSTATETYPE state
, D3DMATRIX
*matrix
)
1855 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1857 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1859 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1860 wined3d_mutex_lock();
1861 wined3d_device_get_transform(device
->wined3d_device
, state
, (struct wined3d_matrix
*)matrix
);
1862 wined3d_mutex_unlock();
1867 static HRESULT WINAPI
d3d9_device_MultiplyTransform(IDirect3DDevice9Ex
*iface
,
1868 D3DTRANSFORMSTATETYPE state
, const D3DMATRIX
*matrix
)
1870 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1872 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1874 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1875 wined3d_mutex_lock();
1876 wined3d_device_multiply_transform(device
->wined3d_device
, state
, (const struct wined3d_matrix
*)matrix
);
1877 wined3d_mutex_unlock();
1882 static HRESULT WINAPI
d3d9_device_SetViewport(IDirect3DDevice9Ex
*iface
, const D3DVIEWPORT9
*viewport
)
1884 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1885 struct wined3d_viewport vp
;
1887 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
1891 vp
.width
= viewport
->Width
;
1892 vp
.height
= viewport
->Height
;
1893 vp
.min_z
= viewport
->MinZ
;
1894 vp
.max_z
= viewport
->MaxZ
;
1896 wined3d_mutex_lock();
1897 wined3d_device_set_viewport(device
->wined3d_device
, &vp
);
1898 wined3d_mutex_unlock();
1903 static HRESULT WINAPI
d3d9_device_GetViewport(IDirect3DDevice9Ex
*iface
, D3DVIEWPORT9
*viewport
)
1905 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1906 struct wined3d_viewport wined3d_viewport
;
1908 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
1910 wined3d_mutex_lock();
1911 wined3d_device_get_viewport(device
->wined3d_device
, &wined3d_viewport
);
1912 wined3d_mutex_unlock();
1914 viewport
->X
= wined3d_viewport
.x
;
1915 viewport
->Y
= wined3d_viewport
.y
;
1916 viewport
->Width
= wined3d_viewport
.width
;
1917 viewport
->Height
= wined3d_viewport
.height
;
1918 viewport
->MinZ
= wined3d_viewport
.min_z
;
1919 viewport
->MaxZ
= wined3d_viewport
.max_z
;
1924 static HRESULT WINAPI
d3d9_device_SetMaterial(IDirect3DDevice9Ex
*iface
, const D3DMATERIAL9
*material
)
1926 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1928 TRACE("iface %p, material %p.\n", iface
, material
);
1930 /* Note: D3DMATERIAL9 is compatible with struct wined3d_material. */
1931 wined3d_mutex_lock();
1932 wined3d_device_set_material(device
->wined3d_device
, (const struct wined3d_material
*)material
);
1933 wined3d_mutex_unlock();
1938 static HRESULT WINAPI
d3d9_device_GetMaterial(IDirect3DDevice9Ex
*iface
, D3DMATERIAL9
*material
)
1940 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1942 TRACE("iface %p, material %p.\n", iface
, material
);
1944 /* Note: D3DMATERIAL9 is compatible with struct wined3d_material. */
1945 wined3d_mutex_lock();
1946 wined3d_device_get_material(device
->wined3d_device
, (struct wined3d_material
*)material
);
1947 wined3d_mutex_unlock();
1952 static HRESULT WINAPI
d3d9_device_SetLight(IDirect3DDevice9Ex
*iface
, DWORD index
, const D3DLIGHT9
*light
)
1954 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1957 TRACE("iface %p, index %u, light %p.\n", iface
, index
, light
);
1959 /* Note: D3DLIGHT9 is compatible with struct wined3d_light. */
1960 wined3d_mutex_lock();
1961 hr
= wined3d_device_set_light(device
->wined3d_device
, index
, (const struct wined3d_light
*)light
);
1962 wined3d_mutex_unlock();
1967 static HRESULT WINAPI
d3d9_device_GetLight(IDirect3DDevice9Ex
*iface
, DWORD index
, D3DLIGHT9
*light
)
1969 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1972 TRACE("iface %p, index %u, light %p.\n", iface
, index
, light
);
1974 /* Note: D3DLIGHT9 is compatible with struct wined3d_light. */
1975 wined3d_mutex_lock();
1976 hr
= wined3d_device_get_light(device
->wined3d_device
, index
, (struct wined3d_light
*)light
);
1977 wined3d_mutex_unlock();
1982 static HRESULT WINAPI
d3d9_device_LightEnable(IDirect3DDevice9Ex
*iface
, DWORD index
, BOOL enable
)
1984 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1987 TRACE("iface %p, index %u, enable %#x.\n", iface
, index
, enable
);
1989 wined3d_mutex_lock();
1990 hr
= wined3d_device_set_light_enable(device
->wined3d_device
, index
, enable
);
1991 wined3d_mutex_unlock();
1996 static HRESULT WINAPI
d3d9_device_GetLightEnable(IDirect3DDevice9Ex
*iface
, DWORD index
, BOOL
*enable
)
1998 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2001 TRACE("iface %p, index %u, enable %p.\n", iface
, index
, enable
);
2003 wined3d_mutex_lock();
2004 hr
= wined3d_device_get_light_enable(device
->wined3d_device
, index
, enable
);
2005 wined3d_mutex_unlock();
2010 static HRESULT WINAPI
d3d9_device_SetClipPlane(IDirect3DDevice9Ex
*iface
, DWORD index
, const float *plane
)
2012 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2015 TRACE("iface %p, index %u, plane %p.\n", iface
, index
, plane
);
2017 wined3d_mutex_lock();
2018 hr
= wined3d_device_set_clip_plane(device
->wined3d_device
, index
, (const struct wined3d_vec4
*)plane
);
2019 wined3d_mutex_unlock();
2024 static HRESULT WINAPI
d3d9_device_GetClipPlane(IDirect3DDevice9Ex
*iface
, DWORD index
, float *plane
)
2026 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2029 TRACE("iface %p, index %u, plane %p.\n", iface
, index
, plane
);
2031 wined3d_mutex_lock();
2032 hr
= wined3d_device_get_clip_plane(device
->wined3d_device
, index
, (struct wined3d_vec4
*)plane
);
2033 wined3d_mutex_unlock();
2038 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_SetRenderState(IDirect3DDevice9Ex
*iface
,
2039 D3DRENDERSTATETYPE state
, DWORD value
)
2041 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2043 TRACE("iface %p, state %#x, value %#x.\n", iface
, state
, value
);
2045 wined3d_mutex_lock();
2046 wined3d_device_set_render_state(device
->wined3d_device
, state
, value
);
2047 wined3d_mutex_unlock();
2052 static HRESULT WINAPI
d3d9_device_GetRenderState(IDirect3DDevice9Ex
*iface
,
2053 D3DRENDERSTATETYPE state
, DWORD
*value
)
2055 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2057 TRACE("iface %p, state %#x, value %p.\n", iface
, state
, value
);
2059 wined3d_mutex_lock();
2060 *value
= wined3d_device_get_render_state(device
->wined3d_device
, state
);
2061 wined3d_mutex_unlock();
2066 static HRESULT WINAPI
d3d9_device_CreateStateBlock(IDirect3DDevice9Ex
*iface
,
2067 D3DSTATEBLOCKTYPE type
, IDirect3DStateBlock9
**stateblock
)
2069 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2070 struct d3d9_stateblock
*object
;
2073 TRACE("iface %p, type %#x, stateblock %p.\n", iface
, type
, stateblock
);
2075 if (type
!= D3DSBT_ALL
&& type
!= D3DSBT_PIXELSTATE
&& type
!= D3DSBT_VERTEXSTATE
)
2077 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL.\n");
2078 return D3DERR_INVALIDCALL
;
2081 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2083 return E_OUTOFMEMORY
;
2085 hr
= stateblock_init(object
, device
, type
, NULL
);
2088 WARN("Failed to initialize stateblock, hr %#x.\n", hr
);
2089 HeapFree(GetProcessHeap(), 0, object
);
2093 TRACE("Created stateblock %p.\n", object
);
2094 *stateblock
= &object
->IDirect3DStateBlock9_iface
;
2099 static HRESULT WINAPI
d3d9_device_BeginStateBlock(IDirect3DDevice9Ex
*iface
)
2101 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2104 TRACE("iface %p.\n", iface
);
2106 wined3d_mutex_lock();
2107 hr
= wined3d_device_begin_stateblock(device
->wined3d_device
);
2108 wined3d_mutex_unlock();
2113 static HRESULT WINAPI
d3d9_device_EndStateBlock(IDirect3DDevice9Ex
*iface
, IDirect3DStateBlock9
**stateblock
)
2115 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2116 struct wined3d_stateblock
*wined3d_stateblock
;
2117 struct d3d9_stateblock
*object
;
2120 TRACE("iface %p, stateblock %p.\n", iface
, stateblock
);
2122 wined3d_mutex_lock();
2123 hr
= wined3d_device_end_stateblock(device
->wined3d_device
, &wined3d_stateblock
);
2124 wined3d_mutex_unlock();
2127 WARN("Failed to end the state block, hr %#x.\n", hr
);
2131 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2134 wined3d_mutex_lock();
2135 wined3d_stateblock_decref(wined3d_stateblock
);
2136 wined3d_mutex_unlock();
2137 return E_OUTOFMEMORY
;
2140 hr
= stateblock_init(object
, device
, 0, wined3d_stateblock
);
2143 WARN("Failed to initialize stateblock, hr %#x.\n", hr
);
2144 wined3d_mutex_lock();
2145 wined3d_stateblock_decref(wined3d_stateblock
);
2146 wined3d_mutex_unlock();
2147 HeapFree(GetProcessHeap(), 0, object
);
2151 TRACE("Created stateblock %p.\n", object
);
2152 *stateblock
= &object
->IDirect3DStateBlock9_iface
;
2157 static HRESULT WINAPI
d3d9_device_SetClipStatus(IDirect3DDevice9Ex
*iface
, const D3DCLIPSTATUS9
*clip_status
)
2159 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2162 TRACE("iface %p, clip_status %p.\n", iface
, clip_status
);
2164 wined3d_mutex_lock();
2165 hr
= wined3d_device_set_clip_status(device
->wined3d_device
, (const struct wined3d_clip_status
*)clip_status
);
2166 wined3d_mutex_unlock();
2171 static HRESULT WINAPI
d3d9_device_GetClipStatus(IDirect3DDevice9Ex
*iface
, D3DCLIPSTATUS9
*clip_status
)
2173 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2176 TRACE("iface %p, clip_status %p.\n", iface
, clip_status
);
2178 wined3d_mutex_lock();
2179 hr
= wined3d_device_get_clip_status(device
->wined3d_device
, (struct wined3d_clip_status
*)clip_status
);
2180 wined3d_mutex_unlock();
2185 static HRESULT WINAPI
d3d9_device_GetTexture(IDirect3DDevice9Ex
*iface
, DWORD stage
, IDirect3DBaseTexture9
**texture
)
2187 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2188 struct wined3d_texture
*wined3d_texture
= NULL
;
2189 struct d3d9_texture
*texture_impl
;
2191 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
2194 return D3DERR_INVALIDCALL
;
2196 wined3d_mutex_lock();
2197 if ((wined3d_texture
= wined3d_device_get_texture(device
->wined3d_device
, stage
)))
2199 texture_impl
= wined3d_texture_get_parent(wined3d_texture
);
2200 *texture
= &texture_impl
->IDirect3DBaseTexture9_iface
;
2201 IDirect3DBaseTexture9_AddRef(*texture
);
2207 wined3d_mutex_unlock();
2212 static HRESULT WINAPI
d3d9_device_SetTexture(IDirect3DDevice9Ex
*iface
, DWORD stage
, IDirect3DBaseTexture9
*texture
)
2214 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2215 struct d3d9_texture
*texture_impl
;
2218 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
2220 texture_impl
= unsafe_impl_from_IDirect3DBaseTexture9(texture
);
2222 wined3d_mutex_lock();
2223 hr
= wined3d_device_set_texture(device
->wined3d_device
, stage
,
2224 texture_impl
? texture_impl
->wined3d_texture
: NULL
);
2225 wined3d_mutex_unlock();
2230 static const enum wined3d_texture_stage_state tss_lookup
[] =
2232 WINED3D_TSS_INVALID
, /* 0, unused */
2233 WINED3D_TSS_COLOR_OP
, /* 1, D3DTSS_COLOROP */
2234 WINED3D_TSS_COLOR_ARG1
, /* 2, D3DTSS_COLORARG1 */
2235 WINED3D_TSS_COLOR_ARG2
, /* 3, D3DTSS_COLORARG2 */
2236 WINED3D_TSS_ALPHA_OP
, /* 4, D3DTSS_ALPHAOP */
2237 WINED3D_TSS_ALPHA_ARG1
, /* 5, D3DTSS_ALPHAARG1 */
2238 WINED3D_TSS_ALPHA_ARG2
, /* 6, D3DTSS_ALPHAARG2 */
2239 WINED3D_TSS_BUMPENV_MAT00
, /* 7, D3DTSS_BUMPENVMAT00 */
2240 WINED3D_TSS_BUMPENV_MAT01
, /* 8, D3DTSS_BUMPENVMAT01 */
2241 WINED3D_TSS_BUMPENV_MAT10
, /* 9, D3DTSS_BUMPENVMAT10 */
2242 WINED3D_TSS_BUMPENV_MAT11
, /* 10, D3DTSS_BUMPENVMAT11 */
2243 WINED3D_TSS_TEXCOORD_INDEX
, /* 11, D3DTSS_TEXCOORDINDEX */
2244 WINED3D_TSS_INVALID
, /* 12, unused */
2245 WINED3D_TSS_INVALID
, /* 13, unused */
2246 WINED3D_TSS_INVALID
, /* 14, unused */
2247 WINED3D_TSS_INVALID
, /* 15, unused */
2248 WINED3D_TSS_INVALID
, /* 16, unused */
2249 WINED3D_TSS_INVALID
, /* 17, unused */
2250 WINED3D_TSS_INVALID
, /* 18, unused */
2251 WINED3D_TSS_INVALID
, /* 19, unused */
2252 WINED3D_TSS_INVALID
, /* 20, unused */
2253 WINED3D_TSS_INVALID
, /* 21, unused */
2254 WINED3D_TSS_BUMPENV_LSCALE
, /* 22, D3DTSS_BUMPENVLSCALE */
2255 WINED3D_TSS_BUMPENV_LOFFSET
, /* 23, D3DTSS_BUMPENVLOFFSET */
2256 WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
2257 WINED3D_TSS_INVALID
, /* 25, unused */
2258 WINED3D_TSS_COLOR_ARG0
, /* 26, D3DTSS_COLORARG0 */
2259 WINED3D_TSS_ALPHA_ARG0
, /* 27, D3DTSS_ALPHAARG0 */
2260 WINED3D_TSS_RESULT_ARG
, /* 28, D3DTSS_RESULTARG */
2261 WINED3D_TSS_INVALID
, /* 29, unused */
2262 WINED3D_TSS_INVALID
, /* 30, unused */
2263 WINED3D_TSS_INVALID
, /* 31, unused */
2264 WINED3D_TSS_CONSTANT
, /* 32, D3DTSS_CONSTANT */
2267 static HRESULT WINAPI
d3d9_device_GetTextureStageState(IDirect3DDevice9Ex
*iface
,
2268 DWORD stage
, D3DTEXTURESTAGESTATETYPE state
, DWORD
*value
)
2270 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2272 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface
, stage
, state
, value
);
2274 if (state
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
2276 WARN("Invalid state %#x passed.\n", state
);
2280 wined3d_mutex_lock();
2281 *value
= wined3d_device_get_texture_stage_state(device
->wined3d_device
, stage
, tss_lookup
[state
]);
2282 wined3d_mutex_unlock();
2287 static HRESULT WINAPI
d3d9_device_SetTextureStageState(IDirect3DDevice9Ex
*iface
,
2288 DWORD stage
, D3DTEXTURESTAGESTATETYPE state
, DWORD value
)
2290 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2292 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface
, stage
, state
, value
);
2294 if (state
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
2296 WARN("Invalid state %#x passed.\n", state
);
2300 wined3d_mutex_lock();
2301 wined3d_device_set_texture_stage_state(device
->wined3d_device
, stage
, tss_lookup
[state
], value
);
2302 wined3d_mutex_unlock();
2307 static HRESULT WINAPI
d3d9_device_GetSamplerState(IDirect3DDevice9Ex
*iface
,
2308 DWORD sampler
, D3DSAMPLERSTATETYPE state
, DWORD
*value
)
2310 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2312 TRACE("iface %p, sampler %u, state %#x, value %p.\n", iface
, sampler
, state
, value
);
2314 wined3d_mutex_lock();
2315 *value
= wined3d_device_get_sampler_state(device
->wined3d_device
, sampler
, state
);
2316 wined3d_mutex_unlock();
2321 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_SetSamplerState(IDirect3DDevice9Ex
*iface
,
2322 DWORD sampler
, D3DSAMPLERSTATETYPE state
, DWORD value
)
2324 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2326 TRACE("iface %p, sampler %u, state %#x, value %#x.\n", iface
, sampler
, state
, value
);
2328 wined3d_mutex_lock();
2329 wined3d_device_set_sampler_state(device
->wined3d_device
, sampler
, state
, value
);
2330 wined3d_mutex_unlock();
2335 static HRESULT WINAPI
d3d9_device_ValidateDevice(IDirect3DDevice9Ex
*iface
, DWORD
*pass_count
)
2337 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2340 TRACE("iface %p, pass_count %p.\n", iface
, pass_count
);
2342 wined3d_mutex_lock();
2343 hr
= wined3d_device_validate_device(device
->wined3d_device
, pass_count
);
2344 wined3d_mutex_unlock();
2349 static HRESULT WINAPI
d3d9_device_SetPaletteEntries(IDirect3DDevice9Ex
*iface
,
2350 UINT palette_idx
, const PALETTEENTRY
*entries
)
2352 WARN("iface %p, palette_idx %u, entries %p unimplemented.\n", iface
, palette_idx
, entries
);
2354 /* The d3d9 palette API is non-functional on Windows. Getters and setters are implemented,
2355 * and some drivers allow the creation of P8 surfaces. These surfaces can be copied to
2356 * other P8 surfaces with StretchRect, but cannot be converted to (A)RGB.
2358 * Some older(dx7) cards may have support for P8 textures, but games cannot rely on this. */
2362 static HRESULT WINAPI
d3d9_device_GetPaletteEntries(IDirect3DDevice9Ex
*iface
,
2363 UINT palette_idx
, PALETTEENTRY
*entries
)
2365 FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface
, palette_idx
, entries
);
2367 return D3DERR_INVALIDCALL
;
2370 static HRESULT WINAPI
d3d9_device_SetCurrentTexturePalette(IDirect3DDevice9Ex
*iface
, UINT palette_idx
)
2372 WARN("iface %p, palette_idx %u unimplemented.\n", iface
, palette_idx
);
2377 static HRESULT WINAPI
d3d9_device_GetCurrentTexturePalette(IDirect3DDevice9Ex
*iface
, UINT
*palette_idx
)
2379 FIXME("iface %p, palette_idx %p.\n", iface
, palette_idx
);
2381 return D3DERR_INVALIDCALL
;
2384 static HRESULT WINAPI
d3d9_device_SetScissorRect(IDirect3DDevice9Ex
*iface
, const RECT
*rect
)
2386 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2388 TRACE("iface %p, rect %p.\n", iface
, rect
);
2390 wined3d_mutex_lock();
2391 wined3d_device_set_scissor_rect(device
->wined3d_device
, rect
);
2392 wined3d_mutex_unlock();
2397 static HRESULT WINAPI
d3d9_device_GetScissorRect(IDirect3DDevice9Ex
*iface
, RECT
*rect
)
2399 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2401 TRACE("iface %p, rect %p.\n", iface
, rect
);
2403 wined3d_mutex_lock();
2404 wined3d_device_get_scissor_rect(device
->wined3d_device
, rect
);
2405 wined3d_mutex_unlock();
2410 static HRESULT WINAPI
d3d9_device_SetSoftwareVertexProcessing(IDirect3DDevice9Ex
*iface
, BOOL software
)
2412 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2414 TRACE("iface %p, software %#x.\n", iface
, software
);
2416 wined3d_mutex_lock();
2417 wined3d_device_set_software_vertex_processing(device
->wined3d_device
, software
);
2418 wined3d_mutex_unlock();
2423 static BOOL WINAPI
d3d9_device_GetSoftwareVertexProcessing(IDirect3DDevice9Ex
*iface
)
2425 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2428 TRACE("iface %p.\n", iface
);
2430 wined3d_mutex_lock();
2431 ret
= wined3d_device_get_software_vertex_processing(device
->wined3d_device
);
2432 wined3d_mutex_unlock();
2437 static HRESULT WINAPI
d3d9_device_SetNPatchMode(IDirect3DDevice9Ex
*iface
, float segment_count
)
2439 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2442 TRACE("iface %p, segment_count %.8e.\n", iface
, segment_count
);
2444 wined3d_mutex_lock();
2445 hr
= wined3d_device_set_npatch_mode(device
->wined3d_device
, segment_count
);
2446 wined3d_mutex_unlock();
2451 static float WINAPI
d3d9_device_GetNPatchMode(IDirect3DDevice9Ex
*iface
)
2453 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2456 TRACE("iface %p.\n", iface
);
2458 wined3d_mutex_lock();
2459 ret
= wined3d_device_get_npatch_mode(device
->wined3d_device
);
2460 wined3d_mutex_unlock();
2465 static HRESULT WINAPI
d3d9_device_DrawPrimitive(IDirect3DDevice9Ex
*iface
,
2466 D3DPRIMITIVETYPE primitive_type
, UINT start_vertex
, UINT primitive_count
)
2468 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2471 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
2472 iface
, primitive_type
, start_vertex
, primitive_count
);
2474 wined3d_mutex_lock();
2475 if (!device
->has_vertex_declaration
)
2477 wined3d_mutex_unlock();
2478 WARN("Called without a valid vertex declaration set.\n");
2479 return D3DERR_INVALIDCALL
;
2481 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
, 0);
2482 hr
= wined3d_device_draw_primitive(device
->wined3d_device
, start_vertex
,
2483 vertex_count_from_primitive_count(primitive_type
, primitive_count
));
2484 wined3d_mutex_unlock();
2489 static HRESULT WINAPI
d3d9_device_DrawIndexedPrimitive(IDirect3DDevice9Ex
*iface
,
2490 D3DPRIMITIVETYPE primitive_type
, INT base_vertex_idx
, UINT min_vertex_idx
,
2491 UINT vertex_count
, UINT start_idx
, UINT primitive_count
)
2493 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2496 TRACE("iface %p, primitive_type %#x, base_vertex_idx %u, min_vertex_idx %u, "
2497 "vertex_count %u, start_idx %u, primitive_count %u.\n",
2498 iface
, primitive_type
, base_vertex_idx
, min_vertex_idx
,
2499 vertex_count
, start_idx
, primitive_count
);
2501 wined3d_mutex_lock();
2502 if (!device
->has_vertex_declaration
)
2504 wined3d_mutex_unlock();
2505 WARN("Called without a valid vertex declaration set.\n");
2506 return D3DERR_INVALIDCALL
;
2508 wined3d_device_set_base_vertex_index(device
->wined3d_device
, base_vertex_idx
);
2509 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
, 0);
2510 hr
= wined3d_device_draw_indexed_primitive(device
->wined3d_device
, start_idx
,
2511 vertex_count_from_primitive_count(primitive_type
, primitive_count
));
2512 wined3d_mutex_unlock();
2517 /* The caller is responsible for wined3d locking */
2518 static HRESULT
d3d9_device_prepare_vertex_buffer(struct d3d9_device
*device
, UINT min_size
)
2522 if (device
->vertex_buffer_size
< min_size
|| !device
->vertex_buffer
)
2524 UINT size
= max(device
->vertex_buffer_size
* 2, min_size
);
2525 struct wined3d_buffer
*buffer
;
2527 TRACE("Growing vertex buffer to %u bytes.\n", size
);
2529 hr
= wined3d_buffer_create_vb(device
->wined3d_device
, size
, WINED3DUSAGE_DYNAMIC
| WINED3DUSAGE_WRITEONLY
,
2530 WINED3D_POOL_DEFAULT
, NULL
, &d3d9_null_wined3d_parent_ops
, &buffer
);
2533 ERR("(%p) wined3d_buffer_create_vb failed with hr = %08x.\n", device
, hr
);
2537 if (device
->vertex_buffer
)
2538 wined3d_buffer_decref(device
->vertex_buffer
);
2540 device
->vertex_buffer
= buffer
;
2541 device
->vertex_buffer_size
= size
;
2542 device
->vertex_buffer_pos
= 0;
2547 static HRESULT WINAPI
d3d9_device_DrawPrimitiveUP(IDirect3DDevice9Ex
*iface
,
2548 D3DPRIMITIVETYPE primitive_type
, UINT primitive_count
, const void *data
, UINT stride
)
2550 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2552 UINT vtx_count
= vertex_count_from_primitive_count(primitive_type
, primitive_count
);
2553 struct wined3d_map_desc wined3d_map_desc
;
2554 struct wined3d_box wined3d_box
= {0};
2555 UINT size
= vtx_count
* stride
;
2556 struct wined3d_resource
*vb
;
2559 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
2560 iface
, primitive_type
, primitive_count
, data
, stride
);
2562 if (!primitive_count
)
2564 WARN("primitive_count is 0, returning D3D_OK\n");
2568 wined3d_mutex_lock();
2570 if (!device
->has_vertex_declaration
)
2572 wined3d_mutex_unlock();
2573 WARN("Called without a valid vertex declaration set.\n");
2574 return D3DERR_INVALIDCALL
;
2577 hr
= d3d9_device_prepare_vertex_buffer(device
, size
);
2581 vb_pos
= device
->vertex_buffer_pos
;
2582 align
= vb_pos
% stride
;
2583 if (align
) align
= stride
- align
;
2584 if (vb_pos
+ size
+ align
> device
->vertex_buffer_size
)
2589 wined3d_box
.left
= vb_pos
;
2590 wined3d_box
.right
= vb_pos
+ size
;
2591 vb
= wined3d_buffer_get_resource(device
->vertex_buffer
);
2592 if (FAILED(hr
= wined3d_resource_map(vb
, 0, &wined3d_map_desc
, &wined3d_box
,
2593 vb_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
)))
2595 memcpy(wined3d_map_desc
.data
, data
, size
);
2596 wined3d_resource_unmap(vb
, 0);
2597 device
->vertex_buffer_pos
= vb_pos
+ size
;
2599 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, 0, device
->vertex_buffer
, 0, stride
);
2603 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
, 0);
2604 hr
= wined3d_device_draw_primitive(device
->wined3d_device
, vb_pos
/ stride
, vtx_count
);
2605 wined3d_device_set_stream_source(device
->wined3d_device
, 0, NULL
, 0, 0);
2608 wined3d_mutex_unlock();
2612 /* The caller is responsible for wined3d locking */
2613 static HRESULT
d3d9_device_prepare_index_buffer(struct d3d9_device
*device
, UINT min_size
)
2617 if (device
->index_buffer_size
< min_size
|| !device
->index_buffer
)
2619 UINT size
= max(device
->index_buffer_size
* 2, min_size
);
2620 struct wined3d_buffer
*buffer
;
2622 TRACE("Growing index buffer to %u bytes.\n", size
);
2624 hr
= wined3d_buffer_create_ib(device
->wined3d_device
, size
, WINED3DUSAGE_DYNAMIC
| WINED3DUSAGE_WRITEONLY
,
2625 WINED3D_POOL_DEFAULT
, NULL
, &d3d9_null_wined3d_parent_ops
, &buffer
);
2628 ERR("(%p) wined3d_buffer_create_ib failed with hr = %08x.\n", device
, hr
);
2632 if (device
->index_buffer
)
2633 wined3d_buffer_decref(device
->index_buffer
);
2635 device
->index_buffer
= buffer
;
2636 device
->index_buffer_size
= size
;
2637 device
->index_buffer_pos
= 0;
2642 static HRESULT WINAPI
d3d9_device_DrawIndexedPrimitiveUP(IDirect3DDevice9Ex
*iface
,
2643 D3DPRIMITIVETYPE primitive_type
, UINT min_vertex_idx
, UINT vertex_count
,
2644 UINT primitive_count
, const void *index_data
, D3DFORMAT index_format
,
2645 const void *vertex_data
, UINT vertex_stride
)
2647 UINT idx_count
= vertex_count_from_primitive_count(primitive_type
, primitive_count
);
2648 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2649 UINT idx_fmt_size
= index_format
== D3DFMT_INDEX16
? 2 : 4;
2650 UINT vtx_size
= vertex_count
* vertex_stride
;
2651 UINT idx_size
= idx_count
* idx_fmt_size
;
2652 struct wined3d_map_desc wined3d_map_desc
;
2653 struct wined3d_box wined3d_box
= {0};
2654 struct wined3d_resource
*ib
, *vb
;
2655 UINT vb_pos
, ib_pos
, align
;
2658 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, primitive_count %u, "
2659 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
2660 iface
, primitive_type
, min_vertex_idx
, vertex_count
, primitive_count
,
2661 index_data
, index_format
, vertex_data
, vertex_stride
);
2663 if (!primitive_count
)
2665 WARN("primitive_count is 0, returning D3D_OK.\n");
2669 wined3d_mutex_lock();
2671 if (!device
->has_vertex_declaration
)
2673 wined3d_mutex_unlock();
2674 WARN("Called without a valid vertex declaration set.\n");
2675 return D3DERR_INVALIDCALL
;
2678 hr
= d3d9_device_prepare_vertex_buffer(device
, vtx_size
);
2682 vb_pos
= device
->vertex_buffer_pos
;
2683 align
= vb_pos
% vertex_stride
;
2684 if (align
) align
= vertex_stride
- align
;
2685 if (vb_pos
+ vtx_size
+ align
> device
->vertex_buffer_size
)
2690 wined3d_box
.left
= vb_pos
;
2691 wined3d_box
.right
= vb_pos
+ vtx_size
;
2692 vb
= wined3d_buffer_get_resource(device
->vertex_buffer
);
2693 if (FAILED(hr
= wined3d_resource_map(vb
, 0, &wined3d_map_desc
, &wined3d_box
,
2694 vb_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
)))
2696 memcpy(wined3d_map_desc
.data
, (char *)vertex_data
+ min_vertex_idx
* vertex_stride
, vtx_size
);
2697 wined3d_resource_unmap(vb
, 0);
2698 device
->vertex_buffer_pos
= vb_pos
+ vtx_size
;
2700 hr
= d3d9_device_prepare_index_buffer(device
, idx_size
);
2704 ib_pos
= device
->index_buffer_pos
;
2705 align
= ib_pos
% idx_fmt_size
;
2706 if (align
) align
= idx_fmt_size
- align
;
2707 if (ib_pos
+ idx_size
+ align
> device
->index_buffer_size
)
2712 wined3d_box
.left
= ib_pos
;
2713 wined3d_box
.right
= ib_pos
+ idx_size
;
2714 ib
= wined3d_buffer_get_resource(device
->index_buffer
);
2715 if (FAILED(hr
= wined3d_resource_map(ib
, 0, &wined3d_map_desc
, &wined3d_box
,
2716 ib_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
)))
2718 memcpy(wined3d_map_desc
.data
, index_data
, idx_size
);
2719 wined3d_resource_unmap(ib
, 0);
2720 device
->index_buffer_pos
= ib_pos
+ idx_size
;
2722 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, 0, device
->vertex_buffer
, 0, vertex_stride
);
2726 wined3d_device_set_index_buffer(device
->wined3d_device
, device
->index_buffer
,
2727 wined3dformat_from_d3dformat(index_format
), 0);
2728 wined3d_device_set_base_vertex_index(device
->wined3d_device
, vb_pos
/ vertex_stride
- min_vertex_idx
);
2730 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
, 0);
2731 hr
= wined3d_device_draw_indexed_primitive(device
->wined3d_device
, ib_pos
/ idx_fmt_size
, idx_count
);
2733 wined3d_device_set_stream_source(device
->wined3d_device
, 0, NULL
, 0, 0);
2734 wined3d_device_set_index_buffer(device
->wined3d_device
, NULL
, WINED3DFMT_UNKNOWN
, 0);
2735 wined3d_device_set_base_vertex_index(device
->wined3d_device
, 0);
2738 wined3d_mutex_unlock();
2742 static HRESULT WINAPI
d3d9_device_ProcessVertices(IDirect3DDevice9Ex
*iface
,
2743 UINT src_start_idx
, UINT dst_idx
, UINT vertex_count
, IDirect3DVertexBuffer9
*dst_buffer
,
2744 IDirect3DVertexDeclaration9
*declaration
, DWORD flags
)
2746 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2747 struct d3d9_vertexbuffer
*dst_impl
= unsafe_impl_from_IDirect3DVertexBuffer9(dst_buffer
);
2748 struct d3d9_vertex_declaration
*decl_impl
= unsafe_impl_from_IDirect3DVertexDeclaration9(declaration
);
2751 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, declaration %p, flags %#x.\n",
2752 iface
, src_start_idx
, dst_idx
, vertex_count
, dst_buffer
, declaration
, flags
);
2754 wined3d_mutex_lock();
2755 hr
= wined3d_device_process_vertices(device
->wined3d_device
, src_start_idx
, dst_idx
, vertex_count
,
2756 dst_impl
->wined3d_buffer
, decl_impl
? decl_impl
->wined3d_declaration
: NULL
,
2757 flags
, dst_impl
->fvf
);
2758 wined3d_mutex_unlock();
2763 static HRESULT WINAPI
d3d9_device_CreateVertexDeclaration(IDirect3DDevice9Ex
*iface
,
2764 const D3DVERTEXELEMENT9
*elements
, IDirect3DVertexDeclaration9
**declaration
)
2766 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2767 struct d3d9_vertex_declaration
*object
;
2770 TRACE("iface %p, elements %p, declaration %p.\n", iface
, elements
, declaration
);
2774 WARN("Caller passed a NULL declaration, returning D3DERR_INVALIDCALL.\n");
2775 return D3DERR_INVALIDCALL
;
2778 if (SUCCEEDED(hr
= d3d9_vertex_declaration_create(device
, elements
, &object
)))
2779 *declaration
= &object
->IDirect3DVertexDeclaration9_iface
;
2784 static HRESULT WINAPI
d3d9_device_SetVertexDeclaration(IDirect3DDevice9Ex
*iface
,
2785 IDirect3DVertexDeclaration9
*declaration
)
2787 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2788 struct d3d9_vertex_declaration
*decl_impl
= unsafe_impl_from_IDirect3DVertexDeclaration9(declaration
);
2790 TRACE("iface %p, declaration %p.\n", iface
, declaration
);
2792 wined3d_mutex_lock();
2793 wined3d_device_set_vertex_declaration(device
->wined3d_device
,
2794 decl_impl
? decl_impl
->wined3d_declaration
: NULL
);
2795 device
->has_vertex_declaration
= !!decl_impl
;
2796 wined3d_mutex_unlock();
2801 static HRESULT WINAPI
d3d9_device_GetVertexDeclaration(IDirect3DDevice9Ex
*iface
,
2802 IDirect3DVertexDeclaration9
**declaration
)
2804 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2805 struct wined3d_vertex_declaration
*wined3d_declaration
;
2806 struct d3d9_vertex_declaration
*declaration_impl
;
2808 TRACE("iface %p, declaration %p.\n", iface
, declaration
);
2810 if (!declaration
) return D3DERR_INVALIDCALL
;
2812 wined3d_mutex_lock();
2813 if ((wined3d_declaration
= wined3d_device_get_vertex_declaration(device
->wined3d_device
)))
2815 declaration_impl
= wined3d_vertex_declaration_get_parent(wined3d_declaration
);
2816 *declaration
= &declaration_impl
->IDirect3DVertexDeclaration9_iface
;
2817 IDirect3DVertexDeclaration9_AddRef(*declaration
);
2821 *declaration
= NULL
;
2823 wined3d_mutex_unlock();
2825 TRACE("Returning %p.\n", *declaration
);
2829 static struct wined3d_vertex_declaration
*device_get_fvf_declaration(struct d3d9_device
*device
, DWORD fvf
)
2831 struct wined3d_vertex_declaration
*wined3d_declaration
;
2832 struct fvf_declaration
*fvf_decls
= device
->fvf_decls
;
2833 struct d3d9_vertex_declaration
*d3d9_declaration
;
2834 D3DVERTEXELEMENT9
*elements
;
2835 int p
, low
, high
; /* deliberately signed */
2838 TRACE("Searching for declaration for fvf %08x... ", fvf
);
2841 high
= device
->fvf_decl_count
- 1;
2844 p
= (low
+ high
) >> 1;
2847 if (fvf_decls
[p
].fvf
== fvf
)
2849 TRACE("found %p.\n", fvf_decls
[p
].decl
);
2850 return fvf_decls
[p
].decl
;
2853 if (fvf_decls
[p
].fvf
< fvf
)
2858 TRACE("not found. Creating and inserting at position %d.\n", low
);
2860 if (FAILED(hr
= vdecl_convert_fvf(fvf
, &elements
)))
2863 hr
= d3d9_vertex_declaration_create(device
, elements
, &d3d9_declaration
);
2864 HeapFree(GetProcessHeap(), 0, elements
);
2868 if (device
->fvf_decl_size
== device
->fvf_decl_count
)
2870 UINT grow
= max(device
->fvf_decl_size
/ 2, 8);
2872 fvf_decls
= HeapReAlloc(GetProcessHeap(), 0, fvf_decls
, sizeof(*fvf_decls
) * (device
->fvf_decl_size
+ grow
));
2875 IDirect3DVertexDeclaration9_Release(&d3d9_declaration
->IDirect3DVertexDeclaration9_iface
);
2878 device
->fvf_decls
= fvf_decls
;
2879 device
->fvf_decl_size
+= grow
;
2882 d3d9_declaration
->fvf
= fvf
;
2883 wined3d_declaration
= d3d9_declaration
->wined3d_declaration
;
2884 wined3d_vertex_declaration_incref(wined3d_declaration
);
2885 IDirect3DVertexDeclaration9_Release(&d3d9_declaration
->IDirect3DVertexDeclaration9_iface
);
2887 memmove(fvf_decls
+ low
+ 1, fvf_decls
+ low
, sizeof(*fvf_decls
) * (device
->fvf_decl_count
- low
));
2888 fvf_decls
[low
].decl
= wined3d_declaration
;
2889 fvf_decls
[low
].fvf
= fvf
;
2890 ++device
->fvf_decl_count
;
2892 TRACE("Returning %p. %u declarations in array.\n", wined3d_declaration
, device
->fvf_decl_count
);
2894 return wined3d_declaration
;
2897 static HRESULT WINAPI
d3d9_device_SetFVF(IDirect3DDevice9Ex
*iface
, DWORD fvf
)
2899 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2900 struct wined3d_vertex_declaration
*decl
;
2902 TRACE("iface %p, fvf %#x.\n", iface
, fvf
);
2906 WARN("%#x is not a valid FVF.\n", fvf
);
2910 wined3d_mutex_lock();
2911 if (!(decl
= device_get_fvf_declaration(device
, fvf
)))
2913 wined3d_mutex_unlock();
2914 ERR("Failed to create a vertex declaration for fvf %#x.\n", fvf
);
2915 return D3DERR_DRIVERINTERNALERROR
;
2918 wined3d_device_set_vertex_declaration(device
->wined3d_device
, decl
);
2919 device
->has_vertex_declaration
= TRUE
;
2920 wined3d_mutex_unlock();
2925 static HRESULT WINAPI
d3d9_device_GetFVF(IDirect3DDevice9Ex
*iface
, DWORD
*fvf
)
2927 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2928 struct wined3d_vertex_declaration
*wined3d_declaration
;
2929 struct d3d9_vertex_declaration
*d3d9_declaration
;
2931 TRACE("iface %p, fvf %p.\n", iface
, fvf
);
2933 wined3d_mutex_lock();
2934 if ((wined3d_declaration
= wined3d_device_get_vertex_declaration(device
->wined3d_device
)))
2936 d3d9_declaration
= wined3d_vertex_declaration_get_parent(wined3d_declaration
);
2937 *fvf
= d3d9_declaration
->fvf
;
2943 wined3d_mutex_unlock();
2945 TRACE("Returning FVF %#x.\n", *fvf
);
2950 static HRESULT WINAPI
d3d9_device_CreateVertexShader(IDirect3DDevice9Ex
*iface
,
2951 const DWORD
*byte_code
, IDirect3DVertexShader9
**shader
)
2953 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2954 struct d3d9_vertexshader
*object
;
2957 TRACE("iface %p, byte_code %p, shader %p.\n", iface
, byte_code
, shader
);
2959 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2961 return E_OUTOFMEMORY
;
2963 hr
= vertexshader_init(object
, device
, byte_code
);
2966 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
2967 HeapFree(GetProcessHeap(), 0, object
);
2971 TRACE("Created vertex shader %p.\n", object
);
2972 *shader
= &object
->IDirect3DVertexShader9_iface
;
2977 static HRESULT WINAPI
d3d9_device_SetVertexShader(IDirect3DDevice9Ex
*iface
, IDirect3DVertexShader9
*shader
)
2979 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2980 struct d3d9_vertexshader
*shader_obj
= unsafe_impl_from_IDirect3DVertexShader9(shader
);
2982 TRACE("iface %p, shader %p.\n", iface
, shader
);
2984 wined3d_mutex_lock();
2985 wined3d_device_set_vertex_shader(device
->wined3d_device
,
2986 shader_obj
? shader_obj
->wined3d_shader
: NULL
);
2987 wined3d_mutex_unlock();
2992 static HRESULT WINAPI
d3d9_device_GetVertexShader(IDirect3DDevice9Ex
*iface
, IDirect3DVertexShader9
**shader
)
2994 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2995 struct d3d9_vertexshader
*shader_impl
;
2996 struct wined3d_shader
*wined3d_shader
;
2998 TRACE("iface %p, shader %p.\n", iface
, shader
);
3000 wined3d_mutex_lock();
3001 if ((wined3d_shader
= wined3d_device_get_vertex_shader(device
->wined3d_device
)))
3003 shader_impl
= wined3d_shader_get_parent(wined3d_shader
);
3004 *shader
= &shader_impl
->IDirect3DVertexShader9_iface
;
3005 IDirect3DVertexShader9_AddRef(*shader
);
3011 wined3d_mutex_unlock();
3013 TRACE("Returning %p.\n", *shader
);
3018 static HRESULT WINAPI
d3d9_device_SetVertexShaderConstantF(IDirect3DDevice9Ex
*iface
,
3019 UINT reg_idx
, const float *data
, UINT count
)
3021 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3024 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3026 if (reg_idx
+ count
> D3D9_MAX_VERTEX_SHADER_CONSTANTF
)
3028 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
3029 reg_idx
+ count
, D3D9_MAX_VERTEX_SHADER_CONSTANTF
);
3030 return D3DERR_INVALIDCALL
;
3033 wined3d_mutex_lock();
3034 hr
= wined3d_device_set_vs_consts_f(device
->wined3d_device
,
3035 reg_idx
, count
, (const struct wined3d_vec4
*)data
);
3036 wined3d_mutex_unlock();
3041 static HRESULT WINAPI
d3d9_device_GetVertexShaderConstantF(IDirect3DDevice9Ex
*iface
,
3042 UINT reg_idx
, float *data
, UINT count
)
3044 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3047 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3049 if (reg_idx
+ count
> D3D9_MAX_VERTEX_SHADER_CONSTANTF
)
3051 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
3052 reg_idx
+ count
, D3D9_MAX_VERTEX_SHADER_CONSTANTF
);
3053 return D3DERR_INVALIDCALL
;
3056 wined3d_mutex_lock();
3057 hr
= wined3d_device_get_vs_consts_f(device
->wined3d_device
,
3058 reg_idx
, count
, (struct wined3d_vec4
*)data
);
3059 wined3d_mutex_unlock();
3064 static HRESULT WINAPI
d3d9_device_SetVertexShaderConstantI(IDirect3DDevice9Ex
*iface
,
3065 UINT reg_idx
, const int *data
, UINT count
)
3067 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3070 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3072 wined3d_mutex_lock();
3073 hr
= wined3d_device_set_vs_consts_i(device
->wined3d_device
,
3074 reg_idx
, count
, (const struct wined3d_ivec4
*)data
);
3075 wined3d_mutex_unlock();
3080 static HRESULT WINAPI
d3d9_device_GetVertexShaderConstantI(IDirect3DDevice9Ex
*iface
,
3081 UINT reg_idx
, int *data
, UINT count
)
3083 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3086 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3088 wined3d_mutex_lock();
3089 hr
= wined3d_device_get_vs_consts_i(device
->wined3d_device
,
3090 reg_idx
, count
, (struct wined3d_ivec4
*)data
);
3091 wined3d_mutex_unlock();
3096 static HRESULT WINAPI
d3d9_device_SetVertexShaderConstantB(IDirect3DDevice9Ex
*iface
,
3097 UINT reg_idx
, const BOOL
*data
, UINT count
)
3099 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3102 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3104 wined3d_mutex_lock();
3105 hr
= wined3d_device_set_vs_consts_b(device
->wined3d_device
, reg_idx
, count
, data
);
3106 wined3d_mutex_unlock();
3111 static HRESULT WINAPI
d3d9_device_GetVertexShaderConstantB(IDirect3DDevice9Ex
*iface
,
3112 UINT reg_idx
, BOOL
*data
, UINT count
)
3114 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3117 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3119 wined3d_mutex_lock();
3120 hr
= wined3d_device_get_vs_consts_b(device
->wined3d_device
, reg_idx
, count
, data
);
3121 wined3d_mutex_unlock();
3126 static HRESULT WINAPI
d3d9_device_SetStreamSource(IDirect3DDevice9Ex
*iface
,
3127 UINT stream_idx
, IDirect3DVertexBuffer9
*buffer
, UINT offset
, UINT stride
)
3129 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3130 struct d3d9_vertexbuffer
*buffer_impl
= unsafe_impl_from_IDirect3DVertexBuffer9(buffer
);
3133 TRACE("iface %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
3134 iface
, stream_idx
, buffer
, offset
, stride
);
3136 wined3d_mutex_lock();
3137 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, stream_idx
,
3138 buffer_impl
? buffer_impl
->wined3d_buffer
: NULL
, offset
, stride
);
3139 wined3d_mutex_unlock();
3144 static HRESULT WINAPI
d3d9_device_GetStreamSource(IDirect3DDevice9Ex
*iface
,
3145 UINT stream_idx
, IDirect3DVertexBuffer9
**buffer
, UINT
*offset
, UINT
*stride
)
3147 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3148 struct d3d9_vertexbuffer
*buffer_impl
;
3149 struct wined3d_buffer
*wined3d_buffer
;
3152 TRACE("iface %p, stream_idx %u, buffer %p, offset %p, stride %p.\n",
3153 iface
, stream_idx
, buffer
, offset
, stride
);
3156 return D3DERR_INVALIDCALL
;
3158 wined3d_mutex_lock();
3159 hr
= wined3d_device_get_stream_source(device
->wined3d_device
, stream_idx
, &wined3d_buffer
, offset
, stride
);
3160 if (SUCCEEDED(hr
) && wined3d_buffer
)
3162 buffer_impl
= wined3d_buffer_get_parent(wined3d_buffer
);
3163 *buffer
= &buffer_impl
->IDirect3DVertexBuffer9_iface
;
3164 IDirect3DVertexBuffer9_AddRef(*buffer
);
3169 FIXME("Call to GetStreamSource failed %p %p\n", offset
, stride
);
3172 wined3d_mutex_unlock();
3177 static HRESULT WINAPI
d3d9_device_SetStreamSourceFreq(IDirect3DDevice9Ex
*iface
, UINT stream_idx
, UINT freq
)
3179 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3182 TRACE("iface %p, stream_idx %u, freq %u.\n", iface
, stream_idx
, freq
);
3184 wined3d_mutex_lock();
3185 hr
= wined3d_device_set_stream_source_freq(device
->wined3d_device
, stream_idx
, freq
);
3186 wined3d_mutex_unlock();
3191 static HRESULT WINAPI
d3d9_device_GetStreamSourceFreq(IDirect3DDevice9Ex
*iface
, UINT stream_idx
, UINT
*freq
)
3193 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3196 TRACE("iface %p, stream_idx %u, freq %p.\n", iface
, stream_idx
, freq
);
3198 wined3d_mutex_lock();
3199 hr
= wined3d_device_get_stream_source_freq(device
->wined3d_device
, stream_idx
, freq
);
3200 wined3d_mutex_unlock();
3205 static HRESULT WINAPI
d3d9_device_SetIndices(IDirect3DDevice9Ex
*iface
, IDirect3DIndexBuffer9
*buffer
)
3207 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3208 struct d3d9_indexbuffer
*ib
= unsafe_impl_from_IDirect3DIndexBuffer9(buffer
);
3210 TRACE("iface %p, buffer %p.\n", iface
, buffer
);
3212 wined3d_mutex_lock();
3213 wined3d_device_set_index_buffer(device
->wined3d_device
,
3214 ib
? ib
->wined3d_buffer
: NULL
, ib
? ib
->format
: WINED3DFMT_UNKNOWN
, 0);
3215 wined3d_mutex_unlock();
3220 static HRESULT WINAPI
d3d9_device_GetIndices(IDirect3DDevice9Ex
*iface
, IDirect3DIndexBuffer9
**buffer
)
3222 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3223 enum wined3d_format_id wined3d_format
;
3224 struct wined3d_buffer
*wined3d_buffer
;
3225 struct d3d9_indexbuffer
*buffer_impl
;
3227 TRACE("iface %p, buffer %p.\n", iface
, buffer
);
3230 return D3DERR_INVALIDCALL
;
3232 wined3d_mutex_lock();
3233 if ((wined3d_buffer
= wined3d_device_get_index_buffer(device
->wined3d_device
, &wined3d_format
, NULL
)))
3235 buffer_impl
= wined3d_buffer_get_parent(wined3d_buffer
);
3236 *buffer
= &buffer_impl
->IDirect3DIndexBuffer9_iface
;
3237 IDirect3DIndexBuffer9_AddRef(*buffer
);
3243 wined3d_mutex_unlock();
3248 static HRESULT WINAPI
d3d9_device_CreatePixelShader(IDirect3DDevice9Ex
*iface
,
3249 const DWORD
*byte_code
, IDirect3DPixelShader9
**shader
)
3251 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3252 struct d3d9_pixelshader
*object
;
3255 TRACE("iface %p, byte_code %p, shader %p.\n", iface
, byte_code
, shader
);
3257 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3260 FIXME("Failed to allocate pixel shader memory.\n");
3261 return E_OUTOFMEMORY
;
3264 hr
= pixelshader_init(object
, device
, byte_code
);
3267 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
3268 HeapFree(GetProcessHeap(), 0, object
);
3272 TRACE("Created pixel shader %p.\n", object
);
3273 *shader
= &object
->IDirect3DPixelShader9_iface
;
3278 static HRESULT WINAPI
d3d9_device_SetPixelShader(IDirect3DDevice9Ex
*iface
, IDirect3DPixelShader9
*shader
)
3280 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3281 struct d3d9_pixelshader
*shader_obj
= unsafe_impl_from_IDirect3DPixelShader9(shader
);
3283 TRACE("iface %p, shader %p.\n", iface
, shader
);
3285 wined3d_mutex_lock();
3286 wined3d_device_set_pixel_shader(device
->wined3d_device
,
3287 shader_obj
? shader_obj
->wined3d_shader
: NULL
);
3288 wined3d_mutex_unlock();
3293 static HRESULT WINAPI
d3d9_device_GetPixelShader(IDirect3DDevice9Ex
*iface
, IDirect3DPixelShader9
**shader
)
3295 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3296 struct d3d9_pixelshader
*shader_impl
;
3297 struct wined3d_shader
*wined3d_shader
;
3299 TRACE("iface %p, shader %p.\n", iface
, shader
);
3301 if (!shader
) return D3DERR_INVALIDCALL
;
3303 wined3d_mutex_lock();
3304 if ((wined3d_shader
= wined3d_device_get_pixel_shader(device
->wined3d_device
)))
3306 shader_impl
= wined3d_shader_get_parent(wined3d_shader
);
3307 *shader
= &shader_impl
->IDirect3DPixelShader9_iface
;
3308 IDirect3DPixelShader9_AddRef(*shader
);
3314 wined3d_mutex_unlock();
3316 TRACE("Returning %p.\n", *shader
);
3321 static HRESULT WINAPI
d3d9_device_SetPixelShaderConstantF(IDirect3DDevice9Ex
*iface
,
3322 UINT reg_idx
, const float *data
, UINT count
)
3324 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3327 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3329 wined3d_mutex_lock();
3330 hr
= wined3d_device_set_ps_consts_f(device
->wined3d_device
,
3331 reg_idx
, count
, (const struct wined3d_vec4
*)data
);
3332 wined3d_mutex_unlock();
3337 static HRESULT WINAPI
d3d9_device_GetPixelShaderConstantF(IDirect3DDevice9Ex
*iface
,
3338 UINT reg_idx
, float *data
, UINT count
)
3340 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3343 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3345 wined3d_mutex_lock();
3346 hr
= wined3d_device_get_ps_consts_f(device
->wined3d_device
,
3347 reg_idx
, count
, (struct wined3d_vec4
*)data
);
3348 wined3d_mutex_unlock();
3353 static HRESULT WINAPI
d3d9_device_SetPixelShaderConstantI(IDirect3DDevice9Ex
*iface
,
3354 UINT reg_idx
, const int *data
, UINT count
)
3356 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3359 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3361 wined3d_mutex_lock();
3362 hr
= wined3d_device_set_ps_consts_i(device
->wined3d_device
,
3363 reg_idx
, count
, (const struct wined3d_ivec4
*)data
);
3364 wined3d_mutex_unlock();
3369 static HRESULT WINAPI
d3d9_device_GetPixelShaderConstantI(IDirect3DDevice9Ex
*iface
,
3370 UINT reg_idx
, int *data
, UINT count
)
3372 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3375 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3377 wined3d_mutex_lock();
3378 hr
= wined3d_device_get_ps_consts_i(device
->wined3d_device
,
3379 reg_idx
, count
, (struct wined3d_ivec4
*)data
);
3380 wined3d_mutex_unlock();
3385 static HRESULT WINAPI
d3d9_device_SetPixelShaderConstantB(IDirect3DDevice9Ex
*iface
,
3386 UINT reg_idx
, const BOOL
*data
, UINT count
)
3388 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3391 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3393 wined3d_mutex_lock();
3394 hr
= wined3d_device_set_ps_consts_b(device
->wined3d_device
, reg_idx
, count
, data
);
3395 wined3d_mutex_unlock();
3400 static HRESULT WINAPI
d3d9_device_GetPixelShaderConstantB(IDirect3DDevice9Ex
*iface
,
3401 UINT reg_idx
, BOOL
*data
, UINT count
)
3403 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3406 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
3408 wined3d_mutex_lock();
3409 hr
= wined3d_device_get_ps_consts_b(device
->wined3d_device
, reg_idx
, count
, data
);
3410 wined3d_mutex_unlock();
3415 static HRESULT WINAPI
d3d9_device_DrawRectPatch(IDirect3DDevice9Ex
*iface
, UINT handle
,
3416 const float *segment_count
, const D3DRECTPATCH_INFO
*patch_info
)
3418 FIXME("iface %p, handle %#x, segment_count %p, patch_info %p unimplemented.\n",
3419 iface
, handle
, segment_count
, patch_info
);
3423 static HRESULT WINAPI
d3d9_device_DrawTriPatch(IDirect3DDevice9Ex
*iface
, UINT handle
,
3424 const float *segment_count
, const D3DTRIPATCH_INFO
*patch_info
)
3426 FIXME("iface %p, handle %#x, segment_count %p, patch_info %p unimplemented.\n",
3427 iface
, handle
, segment_count
, patch_info
);
3431 static HRESULT WINAPI
d3d9_device_DeletePatch(IDirect3DDevice9Ex
*iface
, UINT handle
)
3433 FIXME("iface %p, handle %#x unimplemented.\n", iface
, handle
);
3434 return D3DERR_INVALIDCALL
;
3437 static HRESULT WINAPI
d3d9_device_CreateQuery(IDirect3DDevice9Ex
*iface
, D3DQUERYTYPE type
, IDirect3DQuery9
**query
)
3439 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3440 struct d3d9_query
*object
;
3443 TRACE("iface %p, type %#x, query %p.\n", iface
, type
, query
);
3445 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3447 return E_OUTOFMEMORY
;
3449 hr
= query_init(object
, device
, type
);
3452 WARN("Failed to initialize query, hr %#x.\n", hr
);
3453 HeapFree(GetProcessHeap(), 0, object
);
3457 TRACE("Created query %p.\n", object
);
3458 if (query
) *query
= &object
->IDirect3DQuery9_iface
;
3459 else IDirect3DQuery9_Release(&object
->IDirect3DQuery9_iface
);
3464 static HRESULT WINAPI
d3d9_device_SetConvolutionMonoKernel(IDirect3DDevice9Ex
*iface
,
3465 UINT width
, UINT height
, float *rows
, float *columns
)
3467 FIXME("iface %p, width %u, height %u, rows %p, columns %p stub!\n",
3468 iface
, width
, height
, rows
, columns
);
3473 static HRESULT WINAPI
d3d9_device_ComposeRects(IDirect3DDevice9Ex
*iface
,
3474 IDirect3DSurface9
*src_surface
, IDirect3DSurface9
*dst_surface
, IDirect3DVertexBuffer9
*src_descs
,
3475 UINT rect_count
, IDirect3DVertexBuffer9
*dst_descs
, D3DCOMPOSERECTSOP operation
, INT offset_x
, INT offset_y
)
3477 FIXME("iface %p, src_surface %p, dst_surface %p, src_descs %p, rect_count %u, "
3478 "dst_descs %p, operation %#x, offset_x %u, offset_y %u stub!\n",
3479 iface
, src_surface
, dst_surface
, src_descs
, rect_count
,
3480 dst_descs
, operation
, offset_x
, offset_y
);
3485 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_PresentEx(IDirect3DDevice9Ex
*iface
,
3486 const RECT
*src_rect
, const RECT
*dst_rect
, HWND dst_window_override
,
3487 const RGNDATA
*dirty_region
, DWORD flags
)
3489 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3493 TRACE("iface %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p, flags %#x.\n",
3494 iface
, wine_dbgstr_rect(src_rect
), wine_dbgstr_rect(dst_rect
),
3495 dst_window_override
, dirty_region
, flags
);
3497 if (device
->device_state
!= D3D9_DEVICE_STATE_OK
)
3498 return S_PRESENT_OCCLUDED
;
3501 FIXME("Ignoring dirty_region %p.\n", dirty_region
);
3503 wined3d_mutex_lock();
3504 for (i
= 0; i
< device
->implicit_swapchain_count
; ++i
)
3506 if (FAILED(hr
= wined3d_swapchain_present(device
->implicit_swapchains
[i
]->wined3d_swapchain
,
3507 src_rect
, dst_rect
, dst_window_override
, flags
)))
3509 wined3d_mutex_unlock();
3513 wined3d_mutex_unlock();
3518 static HRESULT WINAPI
d3d9_device_GetGPUThreadPriority(IDirect3DDevice9Ex
*iface
, INT
*priority
)
3520 FIXME("iface %p, priority %p stub!\n", iface
, priority
);
3525 static HRESULT WINAPI
d3d9_device_SetGPUThreadPriority(IDirect3DDevice9Ex
*iface
, INT priority
)
3527 FIXME("iface %p, priority %d stub!\n", iface
, priority
);
3532 static HRESULT WINAPI
d3d9_device_WaitForVBlank(IDirect3DDevice9Ex
*iface
, UINT swapchain_idx
)
3534 FIXME("iface %p, swapchain_idx %u stub!\n", iface
, swapchain_idx
);
3539 static HRESULT WINAPI
d3d9_device_CheckResourceResidency(IDirect3DDevice9Ex
*iface
,
3540 IDirect3DResource9
**resources
, UINT32 resource_count
)
3542 FIXME("iface %p, resources %p, resource_count %u stub!\n",
3543 iface
, resources
, resource_count
);
3548 static HRESULT WINAPI
d3d9_device_SetMaximumFrameLatency(IDirect3DDevice9Ex
*iface
, UINT max_latency
)
3550 FIXME("iface %p, max_latency %u stub!\n", iface
, max_latency
);
3555 static HRESULT WINAPI
d3d9_device_GetMaximumFrameLatency(IDirect3DDevice9Ex
*iface
, UINT
*max_latency
)
3557 FIXME("iface %p, max_latency %p stub!\n", iface
, max_latency
);
3564 static HRESULT WINAPI
d3d9_device_CheckDeviceState(IDirect3DDevice9Ex
*iface
, HWND dst_window
)
3566 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3567 struct wined3d_swapchain_desc swapchain_desc
;
3569 TRACE("iface %p, dst_window %p.\n", iface
, dst_window
);
3571 wined3d_mutex_lock();
3572 wined3d_swapchain_get_desc(device
->implicit_swapchains
[0]->wined3d_swapchain
, &swapchain_desc
);
3573 wined3d_mutex_unlock();
3575 if (swapchain_desc
.windowed
)
3578 /* FIXME: This is actually supposed to check if any other device is in
3579 * fullscreen mode. */
3580 if (dst_window
!= swapchain_desc
.device_window
)
3581 return device
->device_state
== D3D9_DEVICE_STATE_OK
? S_PRESENT_OCCLUDED
: D3D_OK
;
3583 return device
->device_state
== D3D9_DEVICE_STATE_OK
? D3D_OK
: S_PRESENT_OCCLUDED
;
3586 static HRESULT WINAPI
d3d9_device_CreateRenderTargetEx(IDirect3DDevice9Ex
*iface
,
3587 UINT width
, UINT height
, D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
3588 BOOL lockable
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
, DWORD usage
)
3590 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u, "
3591 "lockable %#x, surface %p, shared_handle %p, usage %#x stub!\n",
3592 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
3593 lockable
, surface
, shared_handle
, usage
);
3597 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
3602 static HRESULT WINAPI
d3d9_device_CreateOffscreenPlainSurfaceEx(IDirect3DDevice9Ex
*iface
,
3603 UINT width
, UINT height
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DSurface9
**surface
,
3604 HANDLE
*shared_handle
, DWORD usage
)
3606 FIXME("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p, usage %#x stub!\n",
3607 iface
, width
, height
, format
, pool
, surface
, shared_handle
, usage
);
3612 static HRESULT WINAPI
d3d9_device_CreateDepthStencilSurfaceEx(IDirect3DDevice9Ex
*iface
,
3613 UINT width
, UINT height
, D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
3614 BOOL discard
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
, DWORD usage
)
3616 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3617 DWORD flags
= WINED3D_TEXTURE_CREATE_MAPPABLE
;
3619 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u, "
3620 "discard %#x, surface %p, shared_handle %p, usage %#x.\n",
3621 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
3622 discard
, surface
, shared_handle
, usage
);
3624 if (usage
& D3DUSAGE_DEPTHSTENCIL
)
3626 WARN("Invalid usage %#x.\n", usage
);
3627 return D3DERR_INVALIDCALL
;
3631 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
3634 flags
|= WINED3D_TEXTURE_CREATE_DISCARD
;
3637 return d3d9_device_create_surface(device
, width
, height
, format
, flags
, surface
,
3638 D3DUSAGE_DEPTHSTENCIL
| usage
, D3DPOOL_DEFAULT
, multisample_type
, multisample_quality
, NULL
);
3641 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_ResetEx(IDirect3DDevice9Ex
*iface
,
3642 D3DPRESENT_PARAMETERS
*present_parameters
, D3DDISPLAYMODEEX
*mode
)
3644 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3646 TRACE("iface %p, present_parameters %p, mode %p.\n", iface
, present_parameters
, mode
);
3648 if (!present_parameters
->Windowed
== !mode
)
3650 WARN("Mode can be passed if and only if Windowed is FALSE.\n");
3651 return D3DERR_INVALIDCALL
;
3654 if (mode
&& (mode
->Width
!= present_parameters
->BackBufferWidth
3655 || mode
->Height
!= present_parameters
->BackBufferHeight
))
3657 WARN("Mode and back buffer mismatch (mode %ux%u, backbuffer %ux%u).\n",
3658 mode
->Width
, mode
->Height
,
3659 present_parameters
->BackBufferWidth
, present_parameters
->BackBufferHeight
);
3660 return D3DERR_INVALIDCALL
;
3663 return d3d9_device_reset(device
, present_parameters
, mode
);
3666 static HRESULT WINAPI
d3d9_device_GetDisplayModeEx(IDirect3DDevice9Ex
*iface
,
3667 UINT swapchain_idx
, D3DDISPLAYMODEEX
*mode
, D3DDISPLAYROTATION
*rotation
)
3669 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3670 struct wined3d_display_mode wined3d_mode
;
3673 TRACE("iface %p, swapchain_idx %u, mode %p, rotation %p.\n",
3674 iface
, swapchain_idx
, mode
, rotation
);
3676 if (mode
->Size
!= sizeof(*mode
))
3677 return D3DERR_INVALIDCALL
;
3679 wined3d_mutex_lock();
3680 hr
= wined3d_device_get_display_mode(device
->wined3d_device
, swapchain_idx
, &wined3d_mode
,
3681 (enum wined3d_display_rotation
*)rotation
);
3682 wined3d_mutex_unlock();
3686 mode
->Width
= wined3d_mode
.width
;
3687 mode
->Height
= wined3d_mode
.height
;
3688 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
3689 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
3690 mode
->ScanLineOrdering
= wined3d_mode
.scanline_ordering
;
3696 static const struct IDirect3DDevice9ExVtbl d3d9_device_vtbl
=
3699 d3d9_device_QueryInterface
,
3701 d3d9_device_Release
,
3702 /* IDirect3DDevice9 */
3703 d3d9_device_TestCooperativeLevel
,
3704 d3d9_device_GetAvailableTextureMem
,
3705 d3d9_device_EvictManagedResources
,
3706 d3d9_device_GetDirect3D
,
3707 d3d9_device_GetDeviceCaps
,
3708 d3d9_device_GetDisplayMode
,
3709 d3d9_device_GetCreationParameters
,
3710 d3d9_device_SetCursorProperties
,
3711 d3d9_device_SetCursorPosition
,
3712 d3d9_device_ShowCursor
,
3713 d3d9_device_CreateAdditionalSwapChain
,
3714 d3d9_device_GetSwapChain
,
3715 d3d9_device_GetNumberOfSwapChains
,
3717 d3d9_device_Present
,
3718 d3d9_device_GetBackBuffer
,
3719 d3d9_device_GetRasterStatus
,
3720 d3d9_device_SetDialogBoxMode
,
3721 d3d9_device_SetGammaRamp
,
3722 d3d9_device_GetGammaRamp
,
3723 d3d9_device_CreateTexture
,
3724 d3d9_device_CreateVolumeTexture
,
3725 d3d9_device_CreateCubeTexture
,
3726 d3d9_device_CreateVertexBuffer
,
3727 d3d9_device_CreateIndexBuffer
,
3728 d3d9_device_CreateRenderTarget
,
3729 d3d9_device_CreateDepthStencilSurface
,
3730 d3d9_device_UpdateSurface
,
3731 d3d9_device_UpdateTexture
,
3732 d3d9_device_GetRenderTargetData
,
3733 d3d9_device_GetFrontBufferData
,
3734 d3d9_device_StretchRect
,
3735 d3d9_device_ColorFill
,
3736 d3d9_device_CreateOffscreenPlainSurface
,
3737 d3d9_device_SetRenderTarget
,
3738 d3d9_device_GetRenderTarget
,
3739 d3d9_device_SetDepthStencilSurface
,
3740 d3d9_device_GetDepthStencilSurface
,
3741 d3d9_device_BeginScene
,
3742 d3d9_device_EndScene
,
3744 d3d9_device_SetTransform
,
3745 d3d9_device_GetTransform
,
3746 d3d9_device_MultiplyTransform
,
3747 d3d9_device_SetViewport
,
3748 d3d9_device_GetViewport
,
3749 d3d9_device_SetMaterial
,
3750 d3d9_device_GetMaterial
,
3751 d3d9_device_SetLight
,
3752 d3d9_device_GetLight
,
3753 d3d9_device_LightEnable
,
3754 d3d9_device_GetLightEnable
,
3755 d3d9_device_SetClipPlane
,
3756 d3d9_device_GetClipPlane
,
3757 d3d9_device_SetRenderState
,
3758 d3d9_device_GetRenderState
,
3759 d3d9_device_CreateStateBlock
,
3760 d3d9_device_BeginStateBlock
,
3761 d3d9_device_EndStateBlock
,
3762 d3d9_device_SetClipStatus
,
3763 d3d9_device_GetClipStatus
,
3764 d3d9_device_GetTexture
,
3765 d3d9_device_SetTexture
,
3766 d3d9_device_GetTextureStageState
,
3767 d3d9_device_SetTextureStageState
,
3768 d3d9_device_GetSamplerState
,
3769 d3d9_device_SetSamplerState
,
3770 d3d9_device_ValidateDevice
,
3771 d3d9_device_SetPaletteEntries
,
3772 d3d9_device_GetPaletteEntries
,
3773 d3d9_device_SetCurrentTexturePalette
,
3774 d3d9_device_GetCurrentTexturePalette
,
3775 d3d9_device_SetScissorRect
,
3776 d3d9_device_GetScissorRect
,
3777 d3d9_device_SetSoftwareVertexProcessing
,
3778 d3d9_device_GetSoftwareVertexProcessing
,
3779 d3d9_device_SetNPatchMode
,
3780 d3d9_device_GetNPatchMode
,
3781 d3d9_device_DrawPrimitive
,
3782 d3d9_device_DrawIndexedPrimitive
,
3783 d3d9_device_DrawPrimitiveUP
,
3784 d3d9_device_DrawIndexedPrimitiveUP
,
3785 d3d9_device_ProcessVertices
,
3786 d3d9_device_CreateVertexDeclaration
,
3787 d3d9_device_SetVertexDeclaration
,
3788 d3d9_device_GetVertexDeclaration
,
3791 d3d9_device_CreateVertexShader
,
3792 d3d9_device_SetVertexShader
,
3793 d3d9_device_GetVertexShader
,
3794 d3d9_device_SetVertexShaderConstantF
,
3795 d3d9_device_GetVertexShaderConstantF
,
3796 d3d9_device_SetVertexShaderConstantI
,
3797 d3d9_device_GetVertexShaderConstantI
,
3798 d3d9_device_SetVertexShaderConstantB
,
3799 d3d9_device_GetVertexShaderConstantB
,
3800 d3d9_device_SetStreamSource
,
3801 d3d9_device_GetStreamSource
,
3802 d3d9_device_SetStreamSourceFreq
,
3803 d3d9_device_GetStreamSourceFreq
,
3804 d3d9_device_SetIndices
,
3805 d3d9_device_GetIndices
,
3806 d3d9_device_CreatePixelShader
,
3807 d3d9_device_SetPixelShader
,
3808 d3d9_device_GetPixelShader
,
3809 d3d9_device_SetPixelShaderConstantF
,
3810 d3d9_device_GetPixelShaderConstantF
,
3811 d3d9_device_SetPixelShaderConstantI
,
3812 d3d9_device_GetPixelShaderConstantI
,
3813 d3d9_device_SetPixelShaderConstantB
,
3814 d3d9_device_GetPixelShaderConstantB
,
3815 d3d9_device_DrawRectPatch
,
3816 d3d9_device_DrawTriPatch
,
3817 d3d9_device_DeletePatch
,
3818 d3d9_device_CreateQuery
,
3819 /* IDirect3DDevice9Ex */
3820 d3d9_device_SetConvolutionMonoKernel
,
3821 d3d9_device_ComposeRects
,
3822 d3d9_device_PresentEx
,
3823 d3d9_device_GetGPUThreadPriority
,
3824 d3d9_device_SetGPUThreadPriority
,
3825 d3d9_device_WaitForVBlank
,
3826 d3d9_device_CheckResourceResidency
,
3827 d3d9_device_SetMaximumFrameLatency
,
3828 d3d9_device_GetMaximumFrameLatency
,
3829 d3d9_device_CheckDeviceState
,
3830 d3d9_device_CreateRenderTargetEx
,
3831 d3d9_device_CreateOffscreenPlainSurfaceEx
,
3832 d3d9_device_CreateDepthStencilSurfaceEx
,
3833 d3d9_device_ResetEx
,
3834 d3d9_device_GetDisplayModeEx
,
3837 static inline struct d3d9_device
*device_from_device_parent(struct wined3d_device_parent
*device_parent
)
3839 return CONTAINING_RECORD(device_parent
, struct d3d9_device
, device_parent
);
3842 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
3843 struct wined3d_device
*device
)
3845 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
3848 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
3850 TRACE("device_parent %p.\n", device_parent
);
3853 static void CDECL
device_parent_activate(struct wined3d_device_parent
*device_parent
, BOOL activate
)
3855 struct d3d9_device
*device
= device_from_device_parent(device_parent
);
3857 TRACE("device_parent %p, activate %#x.\n", device_parent
, activate
);
3859 if (!device
->d3d_parent
)
3863 InterlockedCompareExchange(&device
->device_state
, D3D9_DEVICE_STATE_LOST
, D3D9_DEVICE_STATE_OK
);
3864 else if (device
->d3d_parent
->extended
)
3865 InterlockedCompareExchange(&device
->device_state
, D3D9_DEVICE_STATE_OK
, D3D9_DEVICE_STATE_LOST
);
3867 InterlockedCompareExchange(&device
->device_state
, D3D9_DEVICE_STATE_NOT_RESET
, D3D9_DEVICE_STATE_LOST
);
3870 static HRESULT CDECL
device_parent_surface_created(struct wined3d_device_parent
*device_parent
,
3871 struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
,
3872 void **parent
, const struct wined3d_parent_ops
**parent_ops
)
3874 struct d3d9_surface
*d3d_surface
;
3876 TRACE("device_parent %p, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
3877 device_parent
, wined3d_texture
, sub_resource_idx
, parent
, parent_ops
);
3879 if (!(d3d_surface
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*d3d_surface
))))
3880 return E_OUTOFMEMORY
;
3882 surface_init(d3d_surface
, wined3d_texture
, sub_resource_idx
, parent_ops
);
3883 *parent
= d3d_surface
;
3884 TRACE("Created surface %p.\n", d3d_surface
);
3889 static HRESULT CDECL
device_parent_volume_created(struct wined3d_device_parent
*device_parent
,
3890 struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
,
3891 void **parent
, const struct wined3d_parent_ops
**parent_ops
)
3893 struct d3d9_volume
*d3d_volume
;
3895 TRACE("device_parent %p, texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
3896 device_parent
, wined3d_texture
, sub_resource_idx
, parent
, parent_ops
);
3898 if (!(d3d_volume
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*d3d_volume
))))
3899 return E_OUTOFMEMORY
;
3901 volume_init(d3d_volume
, wined3d_texture
, sub_resource_idx
, parent_ops
);
3902 *parent
= d3d_volume
;
3903 TRACE("Created volume %p.\n", d3d_volume
);
3908 static HRESULT CDECL
device_parent_create_swapchain_texture(struct wined3d_device_parent
*device_parent
,
3909 void *container_parent
, const struct wined3d_resource_desc
*desc
, DWORD texture_flags
,
3910 struct wined3d_texture
**texture
)
3912 struct d3d9_device
*device
= device_from_device_parent(device_parent
);
3913 struct d3d9_surface
*d3d_surface
;
3916 TRACE("device_parent %p, container_parent %p, desc %p, texture flags %#x, texture %p.\n",
3917 device_parent
, container_parent
, desc
, texture_flags
, texture
);
3919 if (container_parent
== device_parent
)
3920 container_parent
= &device
->IDirect3DDevice9Ex_iface
;
3922 if (FAILED(hr
= wined3d_texture_create(device
->wined3d_device
, desc
, 1, 1,
3923 texture_flags
| WINED3D_TEXTURE_CREATE_MAPPABLE
, NULL
, container_parent
,
3924 &d3d9_null_wined3d_parent_ops
, texture
)))
3926 WARN("Failed to create texture, hr %#x.\n", hr
);
3930 d3d_surface
= wined3d_texture_get_sub_resource_parent(*texture
, 0);
3931 d3d_surface
->parent_device
= &device
->IDirect3DDevice9Ex_iface
;
3936 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
3937 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain
**swapchain
)
3939 struct d3d9_device
*device
= device_from_device_parent(device_parent
);
3940 struct d3d9_swapchain
*d3d_swapchain
;
3943 TRACE("device_parent %p, desc %p, swapchain %p\n", device_parent
, desc
, swapchain
);
3945 hr
= d3d9_swapchain_create(device
, desc
, &d3d_swapchain
);
3948 WARN("Failed to create swapchain, hr %#x.\n", hr
);
3953 *swapchain
= d3d_swapchain
->wined3d_swapchain
;
3954 wined3d_swapchain_incref(*swapchain
);
3955 IDirect3DSwapChain9Ex_Release(&d3d_swapchain
->IDirect3DSwapChain9Ex_iface
);
3960 static const struct wined3d_device_parent_ops d3d9_wined3d_device_parent_ops
=
3962 device_parent_wined3d_device_created
,
3963 device_parent_mode_changed
,
3964 device_parent_activate
,
3965 device_parent_surface_created
,
3966 device_parent_volume_created
,
3967 device_parent_create_swapchain_texture
,
3968 device_parent_create_swapchain
,
3971 static void setup_fpu(void)
3973 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3975 __asm__
volatile ("fnstcw %0" : "=m" (cw
));
3976 cw
= (cw
& ~0xf3f) | 0x3f;
3977 __asm__
volatile ("fldcw %0" : : "m" (cw
));
3978 #elif defined(__i386__) && defined(_MSC_VER)
3981 cw
= (cw
& ~0xf3f) | 0x3f;
3984 FIXME("FPU setup not implemented for this platform.\n");
3988 HRESULT
device_init(struct d3d9_device
*device
, struct d3d9
*parent
, struct wined3d
*wined3d
,
3989 UINT adapter
, D3DDEVTYPE device_type
, HWND focus_window
, DWORD flags
,
3990 D3DPRESENT_PARAMETERS
*parameters
, D3DDISPLAYMODEEX
*mode
)
3992 struct wined3d_swapchain_desc
*swapchain_desc
;
3997 FIXME("Ignoring display mode.\n");
3999 device
->IDirect3DDevice9Ex_iface
.lpVtbl
= &d3d9_device_vtbl
;
4000 device
->device_parent
.ops
= &d3d9_wined3d_device_parent_ops
;
4001 device
->refcount
= 1;
4003 if (!(flags
& D3DCREATE_FPU_PRESERVE
)) setup_fpu();
4005 wined3d_mutex_lock();
4006 hr
= wined3d_device_create(wined3d
, adapter
, device_type
, focus_window
, flags
, 4,
4007 &device
->device_parent
, &device
->wined3d_device
);
4010 WARN("Failed to create wined3d device, hr %#x.\n", hr
);
4011 wined3d_mutex_unlock();
4015 if (flags
& D3DCREATE_ADAPTERGROUP_DEVICE
)
4019 wined3d_get_device_caps(wined3d
, adapter
, device_type
, &caps
);
4020 count
= caps
.NumberOfAdaptersInGroup
;
4023 if (flags
& D3DCREATE_MULTITHREADED
)
4024 wined3d_device_set_multithreaded(device
->wined3d_device
);
4026 if (!parameters
->Windowed
)
4029 focus_window
= parameters
->hDeviceWindow
;
4030 if (FAILED(hr
= wined3d_device_acquire_focus_window(device
->wined3d_device
, focus_window
)))
4032 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
4033 wined3d_device_decref(device
->wined3d_device
);
4034 wined3d_mutex_unlock();
4038 for (i
= 0; i
< count
; ++i
)
4040 HWND device_window
= parameters
[i
].hDeviceWindow
;
4042 if (!device_window
) device_window
= focus_window
;
4043 wined3d_device_setup_fullscreen_window(device
->wined3d_device
, device_window
,
4044 parameters
[i
].BackBufferWidth
,
4045 parameters
[i
].BackBufferHeight
);
4049 swapchain_desc
= HeapAlloc(GetProcessHeap(), 0, sizeof(*swapchain_desc
) * count
);
4050 if (!swapchain_desc
)
4052 ERR("Failed to allocate wined3d parameters.\n");
4053 wined3d_device_release_focus_window(device
->wined3d_device
);
4054 wined3d_device_decref(device
->wined3d_device
);
4055 wined3d_mutex_unlock();
4056 return E_OUTOFMEMORY
;
4059 for (i
= 0; i
< count
; ++i
)
4061 if (!wined3d_swapchain_desc_from_present_parameters(&swapchain_desc
[i
], ¶meters
[i
],
4064 wined3d_device_release_focus_window(device
->wined3d_device
);
4065 wined3d_device_decref(device
->wined3d_device
);
4066 HeapFree(GetProcessHeap(), 0, swapchain_desc
);
4067 wined3d_mutex_unlock();
4068 return D3DERR_INVALIDCALL
;
4072 hr
= wined3d_device_init_3d(device
->wined3d_device
, swapchain_desc
);
4075 WARN("Failed to initialize 3D, hr %#x.\n", hr
);
4076 wined3d_device_release_focus_window(device
->wined3d_device
);
4077 HeapFree(GetProcessHeap(), 0, swapchain_desc
);
4078 wined3d_device_decref(device
->wined3d_device
);
4079 wined3d_mutex_unlock();
4083 if (FAILED(hr
= d3d9_device_get_swapchains(device
)))
4085 wined3d_device_uninit_3d(device
->wined3d_device
);
4086 wined3d_device_release_focus_window(device
->wined3d_device
);
4087 wined3d_device_decref(device
->wined3d_device
);
4088 wined3d_mutex_unlock();
4089 return E_OUTOFMEMORY
;
4092 for (i
= 0; i
< count
; ++i
)
4094 present_parameters_from_wined3d_swapchain_desc(¶meters
[i
], &swapchain_desc
[i
]);
4097 wined3d_mutex_unlock();
4099 HeapFree(GetProcessHeap(), 0, swapchain_desc
);
4101 /* Initialize the converted declaration array. This creates a valid pointer
4102 * and when adding decls HeapReAlloc() can be used without further checking. */
4103 device
->fvf_decls
= HeapAlloc(GetProcessHeap(), 0, 0);
4104 if (!device
->fvf_decls
)
4106 ERR("Failed to allocate FVF vertex declaration map memory.\n");
4107 wined3d_mutex_lock();
4108 HeapFree(GetProcessHeap(), 0, device
->implicit_swapchains
);
4109 wined3d_device_uninit_3d(device
->wined3d_device
);
4110 wined3d_device_release_focus_window(device
->wined3d_device
);
4111 wined3d_device_decref(device
->wined3d_device
);
4112 wined3d_mutex_unlock();
4113 return E_OUTOFMEMORY
;
4116 IDirect3D9Ex_AddRef(&parent
->IDirect3D9Ex_iface
);
4117 device
->d3d_parent
= parent
;