2 * IDirect3DDevice8 implementation
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2004 Christian Costa
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
33 #include "wine/debug.h"
35 #include "d3d8_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(d3d8
);
39 D3DFORMAT
d3dformat_from_wined3dformat(enum wined3d_format_id format
)
41 BYTE
*c
= (BYTE
*)&format
;
43 /* Don't translate FOURCC formats */
44 if (isprint(c
[0]) && isprint(c
[1]) && isprint(c
[2]) && isprint(c
[3])) return format
;
48 case WINED3DFMT_UNKNOWN
: return D3DFMT_UNKNOWN
;
49 case WINED3DFMT_B8G8R8_UNORM
: return D3DFMT_R8G8B8
;
50 case WINED3DFMT_B8G8R8A8_UNORM
: return D3DFMT_A8R8G8B8
;
51 case WINED3DFMT_B8G8R8X8_UNORM
: return D3DFMT_X8R8G8B8
;
52 case WINED3DFMT_B5G6R5_UNORM
: return D3DFMT_R5G6B5
;
53 case WINED3DFMT_B5G5R5X1_UNORM
: return D3DFMT_X1R5G5B5
;
54 case WINED3DFMT_B5G5R5A1_UNORM
: return D3DFMT_A1R5G5B5
;
55 case WINED3DFMT_B4G4R4A4_UNORM
: return D3DFMT_A4R4G4B4
;
56 case WINED3DFMT_B2G3R3_UNORM
: return D3DFMT_R3G3B2
;
57 case WINED3DFMT_A8_UNORM
: return D3DFMT_A8
;
58 case WINED3DFMT_B2G3R3A8_UNORM
: return D3DFMT_A8R3G3B2
;
59 case WINED3DFMT_B4G4R4X4_UNORM
: return D3DFMT_X4R4G4B4
;
60 case WINED3DFMT_R10G10B10A2_UNORM
: return D3DFMT_A2B10G10R10
;
61 case WINED3DFMT_R16G16_UNORM
: return D3DFMT_G16R16
;
62 case WINED3DFMT_P8_UINT_A8_UNORM
: return D3DFMT_A8P8
;
63 case WINED3DFMT_P8_UINT
: return D3DFMT_P8
;
64 case WINED3DFMT_L8_UNORM
: return D3DFMT_L8
;
65 case WINED3DFMT_L8A8_UNORM
: return D3DFMT_A8L8
;
66 case WINED3DFMT_L4A4_UNORM
: return D3DFMT_A4L4
;
67 case WINED3DFMT_R8G8_SNORM
: return D3DFMT_V8U8
;
68 case WINED3DFMT_R5G5_SNORM_L6_UNORM
: return D3DFMT_L6V5U5
;
69 case WINED3DFMT_R8G8_SNORM_L8X8_UNORM
: return D3DFMT_X8L8V8U8
;
70 case WINED3DFMT_R8G8B8A8_SNORM
: return D3DFMT_Q8W8V8U8
;
71 case WINED3DFMT_R16G16_SNORM
: return D3DFMT_V16U16
;
72 case WINED3DFMT_R10G11B11_SNORM
: return D3DFMT_W11V11U10
;
73 case WINED3DFMT_R10G10B10_SNORM_A2_UNORM
: return D3DFMT_A2W10V10U10
;
74 case WINED3DFMT_D16_LOCKABLE
: return D3DFMT_D16_LOCKABLE
;
75 case WINED3DFMT_D32_UNORM
: return D3DFMT_D32
;
76 case WINED3DFMT_S1_UINT_D15_UNORM
: return D3DFMT_D15S1
;
77 case WINED3DFMT_D24_UNORM_S8_UINT
: return D3DFMT_D24S8
;
78 case WINED3DFMT_X8D24_UNORM
: return D3DFMT_D24X8
;
79 case WINED3DFMT_S4X4_UINT_D24_UNORM
: return D3DFMT_D24X4S4
;
80 case WINED3DFMT_D16_UNORM
: return D3DFMT_D16
;
81 case WINED3DFMT_VERTEXDATA
: return D3DFMT_VERTEXDATA
;
82 case WINED3DFMT_R16_UINT
: return D3DFMT_INDEX16
;
83 case WINED3DFMT_R32_UINT
: return D3DFMT_INDEX32
;
85 FIXME("Unhandled wined3d format %#x.\n", format
);
86 return D3DFMT_UNKNOWN
;
90 enum wined3d_format_id
wined3dformat_from_d3dformat(D3DFORMAT format
)
92 BYTE
*c
= (BYTE
*)&format
;
94 /* Don't translate FOURCC formats */
95 if (isprint(c
[0]) && isprint(c
[1]) && isprint(c
[2]) && isprint(c
[3])) return format
;
99 case D3DFMT_UNKNOWN
: return WINED3DFMT_UNKNOWN
;
100 case D3DFMT_R8G8B8
: return WINED3DFMT_B8G8R8_UNORM
;
101 case D3DFMT_A8R8G8B8
: return WINED3DFMT_B8G8R8A8_UNORM
;
102 case D3DFMT_X8R8G8B8
: return WINED3DFMT_B8G8R8X8_UNORM
;
103 case D3DFMT_R5G6B5
: return WINED3DFMT_B5G6R5_UNORM
;
104 case D3DFMT_X1R5G5B5
: return WINED3DFMT_B5G5R5X1_UNORM
;
105 case D3DFMT_A1R5G5B5
: return WINED3DFMT_B5G5R5A1_UNORM
;
106 case D3DFMT_A4R4G4B4
: return WINED3DFMT_B4G4R4A4_UNORM
;
107 case D3DFMT_R3G3B2
: return WINED3DFMT_B2G3R3_UNORM
;
108 case D3DFMT_A8
: return WINED3DFMT_A8_UNORM
;
109 case D3DFMT_A8R3G3B2
: return WINED3DFMT_B2G3R3A8_UNORM
;
110 case D3DFMT_X4R4G4B4
: return WINED3DFMT_B4G4R4X4_UNORM
;
111 case D3DFMT_A2B10G10R10
: return WINED3DFMT_R10G10B10A2_UNORM
;
112 case D3DFMT_G16R16
: return WINED3DFMT_R16G16_UNORM
;
113 case D3DFMT_A8P8
: return WINED3DFMT_P8_UINT_A8_UNORM
;
114 case D3DFMT_P8
: return WINED3DFMT_P8_UINT
;
115 case D3DFMT_L8
: return WINED3DFMT_L8_UNORM
;
116 case D3DFMT_A8L8
: return WINED3DFMT_L8A8_UNORM
;
117 case D3DFMT_A4L4
: return WINED3DFMT_L4A4_UNORM
;
118 case D3DFMT_V8U8
: return WINED3DFMT_R8G8_SNORM
;
119 case D3DFMT_L6V5U5
: return WINED3DFMT_R5G5_SNORM_L6_UNORM
;
120 case D3DFMT_X8L8V8U8
: return WINED3DFMT_R8G8_SNORM_L8X8_UNORM
;
121 case D3DFMT_Q8W8V8U8
: return WINED3DFMT_R8G8B8A8_SNORM
;
122 case D3DFMT_V16U16
: return WINED3DFMT_R16G16_SNORM
;
123 case D3DFMT_W11V11U10
: return WINED3DFMT_R10G11B11_SNORM
;
124 case D3DFMT_A2W10V10U10
: return WINED3DFMT_R10G10B10_SNORM_A2_UNORM
;
125 case D3DFMT_D16_LOCKABLE
: return WINED3DFMT_D16_LOCKABLE
;
126 case D3DFMT_D32
: return WINED3DFMT_D32_UNORM
;
127 case D3DFMT_D15S1
: return WINED3DFMT_S1_UINT_D15_UNORM
;
128 case D3DFMT_D24S8
: return WINED3DFMT_D24_UNORM_S8_UINT
;
129 case D3DFMT_D24X8
: return WINED3DFMT_X8D24_UNORM
;
130 case D3DFMT_D24X4S4
: return WINED3DFMT_S4X4_UINT_D24_UNORM
;
131 case D3DFMT_D16
: return WINED3DFMT_D16_UNORM
;
132 case D3DFMT_VERTEXDATA
: return WINED3DFMT_VERTEXDATA
;
133 case D3DFMT_INDEX16
: return WINED3DFMT_R16_UINT
;
134 case D3DFMT_INDEX32
: return WINED3DFMT_R32_UINT
;
136 FIXME("Unhandled D3DFORMAT %#x\n", format
);
137 return WINED3DFMT_UNKNOWN
;
141 static UINT
vertex_count_from_primitive_count(D3DPRIMITIVETYPE primitive_type
, UINT primitive_count
)
143 switch(primitive_type
)
145 case D3DPT_POINTLIST
:
146 return primitive_count
;
149 return primitive_count
* 2;
151 case D3DPT_LINESTRIP
:
152 return primitive_count
+ 1;
154 case D3DPT_TRIANGLELIST
:
155 return primitive_count
* 3;
157 case D3DPT_TRIANGLESTRIP
:
158 case D3DPT_TRIANGLEFAN
:
159 return primitive_count
+ 2;
162 FIXME("Unhandled primitive type %#x\n", primitive_type
);
167 static void present_parameters_from_wined3d_swapchain_desc(D3DPRESENT_PARAMETERS
*present_parameters
,
168 const struct wined3d_swapchain_desc
*swapchain_desc
)
170 present_parameters
->BackBufferWidth
= swapchain_desc
->backbuffer_width
;
171 present_parameters
->BackBufferHeight
= swapchain_desc
->backbuffer_height
;
172 present_parameters
->BackBufferFormat
= d3dformat_from_wined3dformat(swapchain_desc
->backbuffer_format
);
173 present_parameters
->BackBufferCount
= swapchain_desc
->backbuffer_count
;
174 present_parameters
->MultiSampleType
= swapchain_desc
->multisample_type
;
175 present_parameters
->SwapEffect
= swapchain_desc
->swap_effect
;
176 present_parameters
->hDeviceWindow
= swapchain_desc
->device_window
;
177 present_parameters
->Windowed
= swapchain_desc
->windowed
;
178 present_parameters
->EnableAutoDepthStencil
= swapchain_desc
->enable_auto_depth_stencil
;
179 present_parameters
->AutoDepthStencilFormat
180 = d3dformat_from_wined3dformat(swapchain_desc
->auto_depth_stencil_format
);
181 present_parameters
->Flags
= swapchain_desc
->flags
;
182 present_parameters
->FullScreen_RefreshRateInHz
= swapchain_desc
->refresh_rate
;
183 present_parameters
->FullScreen_PresentationInterval
= swapchain_desc
->swap_interval
;
186 static void wined3d_swapchain_desc_from_present_parameters(struct wined3d_swapchain_desc
*swapchain_desc
,
187 const D3DPRESENT_PARAMETERS
*present_parameters
)
189 swapchain_desc
->backbuffer_width
= present_parameters
->BackBufferWidth
;
190 swapchain_desc
->backbuffer_height
= present_parameters
->BackBufferHeight
;
191 swapchain_desc
->backbuffer_format
= wined3dformat_from_d3dformat(present_parameters
->BackBufferFormat
);
192 swapchain_desc
->backbuffer_count
= max(1, present_parameters
->BackBufferCount
);
193 swapchain_desc
->multisample_type
= present_parameters
->MultiSampleType
;
194 swapchain_desc
->multisample_quality
= 0; /* d3d9 only */
195 swapchain_desc
->swap_effect
= present_parameters
->SwapEffect
;
196 swapchain_desc
->device_window
= present_parameters
->hDeviceWindow
;
197 swapchain_desc
->windowed
= present_parameters
->Windowed
;
198 swapchain_desc
->enable_auto_depth_stencil
= present_parameters
->EnableAutoDepthStencil
;
199 swapchain_desc
->auto_depth_stencil_format
200 = wined3dformat_from_d3dformat(present_parameters
->AutoDepthStencilFormat
);
201 swapchain_desc
->flags
= present_parameters
->Flags
;
202 swapchain_desc
->refresh_rate
= present_parameters
->FullScreen_RefreshRateInHz
;
203 swapchain_desc
->swap_interval
= present_parameters
->FullScreen_PresentationInterval
;
204 swapchain_desc
->auto_restore_display_mode
= TRUE
;
207 /* Handle table functions */
208 static DWORD
d3d8_allocate_handle(struct d3d8_handle_table
*t
, void *object
, enum d3d8_handle_type type
)
210 struct d3d8_handle_entry
*entry
;
214 DWORD index
= t
->free_entries
- t
->entries
;
215 /* Use a free handle */
216 entry
= t
->free_entries
;
217 if (entry
->type
!= D3D8_HANDLE_FREE
)
219 ERR("Handle %u(%p) is in the free list, but has type %#x.\n", index
, entry
, entry
->type
);
220 return D3D8_INVALID_HANDLE
;
222 t
->free_entries
= entry
->object
;
223 entry
->object
= object
;
229 if (!(t
->entry_count
< t
->table_size
))
232 UINT new_size
= t
->table_size
+ (t
->table_size
>> 1);
233 struct d3d8_handle_entry
*new_entries
= HeapReAlloc(GetProcessHeap(),
234 0, t
->entries
, new_size
* sizeof(*t
->entries
));
237 ERR("Failed to grow the handle table.\n");
238 return D3D8_INVALID_HANDLE
;
240 t
->entries
= new_entries
;
241 t
->table_size
= new_size
;
244 entry
= &t
->entries
[t
->entry_count
];
245 entry
->object
= object
;
248 return t
->entry_count
++;
251 static void *d3d8_free_handle(struct d3d8_handle_table
*t
, DWORD handle
, enum d3d8_handle_type type
)
253 struct d3d8_handle_entry
*entry
;
256 if (handle
== D3D8_INVALID_HANDLE
|| handle
>= t
->entry_count
)
258 WARN("Invalid handle %u passed.\n", handle
);
262 entry
= &t
->entries
[handle
];
263 if (entry
->type
!= type
)
265 WARN("Handle %u(%p) is not of type %#x.\n", handle
, entry
, type
);
269 object
= entry
->object
;
270 entry
->object
= t
->free_entries
;
271 entry
->type
= D3D8_HANDLE_FREE
;
272 t
->free_entries
= entry
;
277 static void *d3d8_get_object(struct d3d8_handle_table
*t
, DWORD handle
, enum d3d8_handle_type type
)
279 struct d3d8_handle_entry
*entry
;
281 if (handle
== D3D8_INVALID_HANDLE
|| handle
>= t
->entry_count
)
283 WARN("Invalid handle %u passed.\n", handle
);
287 entry
= &t
->entries
[handle
];
288 if (entry
->type
!= type
)
290 WARN("Handle %u(%p) is not of type %#x.\n", handle
, entry
, type
);
294 return entry
->object
;
297 static inline struct d3d8_device
*impl_from_IDirect3DDevice8(IDirect3DDevice8
*iface
)
299 return CONTAINING_RECORD(iface
, struct d3d8_device
, IDirect3DDevice8_iface
);
302 static HRESULT WINAPI
d3d8_device_QueryInterface(IDirect3DDevice8
*iface
, REFIID riid
, void **out
)
304 TRACE("iface %p, riid %s, out %p.\n",
305 iface
, debugstr_guid(riid
), out
);
307 if (IsEqualGUID(riid
, &IID_IDirect3DDevice8
)
308 || IsEqualGUID(riid
, &IID_IUnknown
))
310 IDirect3DDevice8_AddRef(iface
);
315 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
318 return E_NOINTERFACE
;
321 static ULONG WINAPI
d3d8_device_AddRef(IDirect3DDevice8
*iface
)
323 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
324 ULONG ref
= InterlockedIncrement(&device
->ref
);
326 TRACE("%p increasing refcount to %u.\n", iface
, ref
);
331 static ULONG WINAPI
d3d8_device_Release(IDirect3DDevice8
*iface
)
333 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
336 if (device
->inDestruction
)
339 ref
= InterlockedDecrement(&device
->ref
);
341 TRACE("%p decreasing refcount to %u.\n", iface
, ref
);
345 IDirect3D8
*parent
= device
->d3d_parent
;
348 TRACE("Releasing wined3d device %p.\n", device
->wined3d_device
);
350 wined3d_mutex_lock();
352 device
->inDestruction
= TRUE
;
354 for (i
= 0; i
< device
->numConvertedDecls
; ++i
)
356 d3d8_vertex_declaration_destroy(device
->decls
[i
].declaration
);
358 HeapFree(GetProcessHeap(), 0, device
->decls
);
360 wined3d_device_uninit_3d(device
->wined3d_device
);
361 wined3d_device_release_focus_window(device
->wined3d_device
);
362 wined3d_device_decref(device
->wined3d_device
);
363 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
364 HeapFree(GetProcessHeap(), 0, device
);
366 wined3d_mutex_unlock();
368 IDirect3D8_Release(parent
);
373 static HRESULT WINAPI
d3d8_device_TestCooperativeLevel(IDirect3DDevice8
*iface
)
375 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
377 TRACE("iface %p.\n", iface
);
381 TRACE("Device is lost.\n");
382 return D3DERR_DEVICENOTRESET
;
388 static UINT WINAPI
d3d8_device_GetAvailableTextureMem(IDirect3DDevice8
*iface
)
390 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
393 TRACE("iface %p.\n", iface
);
395 wined3d_mutex_lock();
396 hr
= wined3d_device_get_available_texture_mem(device
->wined3d_device
);
397 wined3d_mutex_unlock();
402 static HRESULT WINAPI
d3d8_device_ResourceManagerDiscardBytes(IDirect3DDevice8
*iface
, DWORD byte_count
)
404 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
406 TRACE("iface %p, byte_count %u.\n", iface
, byte_count
);
409 FIXME("Byte count ignored.\n");
411 wined3d_mutex_lock();
412 wined3d_device_evict_managed_resources(device
->wined3d_device
);
413 wined3d_mutex_unlock();
418 static HRESULT WINAPI
d3d8_device_GetDirect3D(IDirect3DDevice8
*iface
, IDirect3D8
**d3d8
)
420 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
422 TRACE("iface %p, d3d8 %p.\n", iface
, d3d8
);
425 return D3DERR_INVALIDCALL
;
427 return IDirect3D8_QueryInterface(device
->d3d_parent
, &IID_IDirect3D8
, (void **)d3d8
);
430 static HRESULT WINAPI
d3d8_device_GetDeviceCaps(IDirect3DDevice8
*iface
, D3DCAPS8
*caps
)
432 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
433 WINED3DCAPS
*wined3d_caps
;
436 TRACE("iface %p, caps %p.\n", iface
, caps
);
439 return D3DERR_INVALIDCALL
;
441 if (!(wined3d_caps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*wined3d_caps
))))
442 return D3DERR_INVALIDCALL
; /* well this is what MSDN says to return */
444 wined3d_mutex_lock();
445 hr
= wined3d_device_get_device_caps(device
->wined3d_device
, wined3d_caps
);
446 wined3d_mutex_unlock();
448 fixup_caps(wined3d_caps
);
449 WINECAPSTOD3D8CAPS(caps
, wined3d_caps
)
450 HeapFree(GetProcessHeap(), 0, wined3d_caps
);
455 static HRESULT WINAPI
d3d8_device_GetDisplayMode(IDirect3DDevice8
*iface
, D3DDISPLAYMODE
*mode
)
457 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
458 struct wined3d_display_mode wined3d_mode
;
461 TRACE("iface %p, mode %p.\n", iface
, mode
);
463 wined3d_mutex_lock();
464 hr
= wined3d_device_get_display_mode(device
->wined3d_device
, 0, &wined3d_mode
, NULL
);
465 wined3d_mutex_unlock();
469 mode
->Width
= wined3d_mode
.width
;
470 mode
->Height
= wined3d_mode
.height
;
471 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
472 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
478 static HRESULT WINAPI
d3d8_device_GetCreationParameters(IDirect3DDevice8
*iface
,
479 D3DDEVICE_CREATION_PARAMETERS
*parameters
)
481 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
483 TRACE("iface %p, parameters %p.\n", iface
, parameters
);
485 wined3d_mutex_lock();
486 wined3d_device_get_creation_parameters(device
->wined3d_device
,
487 (struct wined3d_device_creation_parameters
*)parameters
);
488 wined3d_mutex_unlock();
493 static HRESULT WINAPI
d3d8_device_SetCursorProperties(IDirect3DDevice8
*iface
,
494 UINT hotspot_x
, UINT hotspot_y
, IDirect3DSurface8
*bitmap
)
496 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
497 struct d3d8_surface
*bitmap_impl
= unsafe_impl_from_IDirect3DSurface8(bitmap
);
500 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
501 iface
, hotspot_x
, hotspot_y
, bitmap
);
505 WARN("No cursor bitmap, returning D3DERR_INVALIDCALL.\n");
506 return D3DERR_INVALIDCALL
;
509 wined3d_mutex_lock();
510 hr
= wined3d_device_set_cursor_properties(device
->wined3d_device
,
511 hotspot_x
, hotspot_y
, bitmap_impl
->wined3d_surface
);
512 wined3d_mutex_unlock();
517 static void WINAPI
d3d8_device_SetCursorPosition(IDirect3DDevice8
*iface
, UINT x
, UINT y
, DWORD flags
)
519 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
521 TRACE("iface %p, x %u, y %u, flags %#x.\n", iface
, x
, y
, flags
);
523 wined3d_mutex_lock();
524 wined3d_device_set_cursor_position(device
->wined3d_device
, x
, y
, flags
);
525 wined3d_mutex_unlock();
528 static BOOL WINAPI
d3d8_device_ShowCursor(IDirect3DDevice8
*iface
, BOOL show
)
530 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
533 TRACE("iface %p, show %#x.\n", iface
, show
);
535 wined3d_mutex_lock();
536 ret
= wined3d_device_show_cursor(device
->wined3d_device
, show
);
537 wined3d_mutex_unlock();
542 static HRESULT WINAPI
d3d8_device_CreateAdditionalSwapChain(IDirect3DDevice8
*iface
,
543 D3DPRESENT_PARAMETERS
*present_parameters
, IDirect3DSwapChain8
**swapchain
)
545 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
546 struct wined3d_swapchain_desc desc
;
547 struct d3d8_swapchain
*object
;
550 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
551 iface
, present_parameters
, swapchain
);
553 wined3d_swapchain_desc_from_present_parameters(&desc
, present_parameters
);
554 if (SUCCEEDED(hr
= d3d8_swapchain_create(device
, &desc
, &object
)))
555 *swapchain
= &object
->IDirect3DSwapChain8_iface
;
556 present_parameters_from_wined3d_swapchain_desc(present_parameters
, &desc
);
561 static HRESULT CDECL
reset_enum_callback(struct wined3d_resource
*resource
)
563 struct wined3d_resource_desc desc
;
565 wined3d_resource_get_desc(resource
, &desc
);
566 if (desc
.pool
== WINED3D_POOL_DEFAULT
)
568 struct d3d8_surface
*surface
;
570 if (desc
.resource_type
!= WINED3D_RTYPE_SURFACE
)
572 WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource
);
573 return D3DERR_DEVICELOST
;
576 surface
= wined3d_resource_get_parent(resource
);
577 if (surface
->refcount
)
579 WARN("Surface %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface
, resource
);
580 return D3DERR_DEVICELOST
;
583 WARN("Surface %p (resource %p) is an implicit resource with ref 0.\n", surface
, resource
);
589 static HRESULT WINAPI
d3d8_device_Reset(IDirect3DDevice8
*iface
,
590 D3DPRESENT_PARAMETERS
*present_parameters
)
592 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
593 struct wined3d_swapchain_desc swapchain_desc
;
596 TRACE("iface %p, present_parameters %p.\n", iface
, present_parameters
);
598 wined3d_mutex_lock();
599 wined3d_swapchain_desc_from_present_parameters(&swapchain_desc
, present_parameters
);
600 if (SUCCEEDED(hr
= wined3d_device_reset(device
->wined3d_device
, &swapchain_desc
, NULL
, reset_enum_callback
)))
602 wined3d_device_set_render_state(device
->wined3d_device
, WINED3D_RS_POINTSIZE_MIN
, 0);
603 device
->lost
= FALSE
;
609 wined3d_mutex_unlock();
614 static HRESULT WINAPI
d3d8_device_Present(IDirect3DDevice8
*iface
, const RECT
*src_rect
,
615 const RECT
*dst_rect
, HWND dst_window_override
, const RGNDATA
*dirty_region
)
617 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
620 TRACE("iface %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p.\n",
621 iface
, wine_dbgstr_rect(src_rect
), wine_dbgstr_rect(dst_rect
), dst_window_override
, dirty_region
);
623 wined3d_mutex_lock();
624 hr
= wined3d_device_present(device
->wined3d_device
, src_rect
, dst_rect
,
625 dst_window_override
, dirty_region
, 0);
626 wined3d_mutex_unlock();
631 static HRESULT WINAPI
d3d8_device_GetBackBuffer(IDirect3DDevice8
*iface
,
632 UINT backbuffer_idx
, D3DBACKBUFFER_TYPE backbuffer_type
, IDirect3DSurface8
**backbuffer
)
634 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
635 struct wined3d_surface
*wined3d_surface
= NULL
;
636 struct d3d8_surface
*surface_impl
;
639 TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
640 iface
, backbuffer_idx
, backbuffer_type
, backbuffer
);
642 wined3d_mutex_lock();
643 hr
= wined3d_device_get_back_buffer(device
->wined3d_device
, 0, backbuffer_idx
,
644 (enum wined3d_backbuffer_type
)backbuffer_type
, &wined3d_surface
);
645 if (SUCCEEDED(hr
) && wined3d_surface
&& backbuffer
)
647 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
648 *backbuffer
= &surface_impl
->IDirect3DSurface8_iface
;
649 IDirect3DSurface8_AddRef(*backbuffer
);
651 wined3d_mutex_unlock();
656 static HRESULT WINAPI
d3d8_device_GetRasterStatus(IDirect3DDevice8
*iface
, D3DRASTER_STATUS
*raster_status
)
658 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
661 TRACE("iface %p, raster_status %p.\n", iface
, raster_status
);
663 wined3d_mutex_lock();
664 hr
= wined3d_device_get_raster_status(device
->wined3d_device
, 0, (struct wined3d_raster_status
*)raster_status
);
665 wined3d_mutex_unlock();
670 static void WINAPI
d3d8_device_SetGammaRamp(IDirect3DDevice8
*iface
, DWORD flags
, const D3DGAMMARAMP
*ramp
)
672 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
674 TRACE("iface %p, flags %#x, ramp %p.\n", iface
, flags
, ramp
);
676 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
677 wined3d_mutex_lock();
678 wined3d_device_set_gamma_ramp(device
->wined3d_device
, 0, flags
, (const struct wined3d_gamma_ramp
*)ramp
);
679 wined3d_mutex_unlock();
682 static void WINAPI
d3d8_device_GetGammaRamp(IDirect3DDevice8
*iface
, D3DGAMMARAMP
*ramp
)
684 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
686 TRACE("iface %p, ramp %p.\n", iface
, ramp
);
688 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
689 wined3d_mutex_lock();
690 wined3d_device_get_gamma_ramp(device
->wined3d_device
, 0, (struct wined3d_gamma_ramp
*)ramp
);
691 wined3d_mutex_unlock();
694 static HRESULT WINAPI
d3d8_device_CreateTexture(IDirect3DDevice8
*iface
,
695 UINT width
, UINT height
, UINT levels
, DWORD usage
, D3DFORMAT format
,
696 D3DPOOL pool
, IDirect3DTexture8
**texture
)
698 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
699 struct d3d8_texture
*object
;
702 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
703 iface
, width
, height
, levels
, usage
, format
, pool
, texture
);
705 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
708 ERR("Failed to allocate texture memory.\n");
709 return D3DERR_OUTOFVIDEOMEMORY
;
712 hr
= texture_init(object
, device
, width
, height
, levels
, usage
, format
, pool
);
715 WARN("Failed to initialize texture, hr %#x.\n", hr
);
716 HeapFree(GetProcessHeap(), 0, object
);
720 TRACE("Created texture %p.\n", object
);
721 *texture
= (IDirect3DTexture8
*)&object
->IDirect3DBaseTexture8_iface
;
726 static HRESULT WINAPI
d3d8_device_CreateVolumeTexture(IDirect3DDevice8
*iface
,
727 UINT width
, UINT height
, UINT depth
, UINT levels
, DWORD usage
, D3DFORMAT format
,
728 D3DPOOL pool
, IDirect3DVolumeTexture8
**texture
)
730 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
731 struct d3d8_texture
*object
;
734 TRACE("iface %p, width %u, height %u, depth %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
735 iface
, width
, height
, depth
, levels
, usage
, format
, pool
, texture
);
737 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
740 ERR("Failed to allocate volume texture memory.\n");
741 return D3DERR_OUTOFVIDEOMEMORY
;
744 hr
= volumetexture_init(object
, device
, width
, height
, depth
, levels
, usage
, format
, pool
);
747 WARN("Failed to initialize volume texture, hr %#x.\n", hr
);
748 HeapFree(GetProcessHeap(), 0, object
);
752 TRACE("Created volume texture %p.\n", object
);
753 *texture
= (IDirect3DVolumeTexture8
*)&object
->IDirect3DBaseTexture8_iface
;
758 static HRESULT WINAPI
d3d8_device_CreateCubeTexture(IDirect3DDevice8
*iface
, UINT edge_length
,
759 UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DCubeTexture8
**texture
)
761 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
762 struct d3d8_texture
*object
;
765 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
766 iface
, edge_length
, levels
, usage
, format
, pool
, texture
);
768 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
771 ERR("Failed to allocate cube texture memory.\n");
772 return D3DERR_OUTOFVIDEOMEMORY
;
775 hr
= cubetexture_init(object
, device
, edge_length
, levels
, usage
, format
, pool
);
778 WARN("Failed to initialize cube texture, hr %#x.\n", hr
);
779 HeapFree(GetProcessHeap(), 0, object
);
783 TRACE("Created cube texture %p.\n", object
);
784 *texture
= (IDirect3DCubeTexture8
*)&object
->IDirect3DBaseTexture8_iface
;
789 static HRESULT WINAPI
d3d8_device_CreateVertexBuffer(IDirect3DDevice8
*iface
, UINT size
,
790 DWORD usage
, DWORD fvf
, D3DPOOL pool
, IDirect3DVertexBuffer8
**buffer
)
792 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
793 struct d3d8_vertexbuffer
*object
;
796 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p.\n",
797 iface
, size
, usage
, fvf
, pool
, buffer
);
799 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
802 ERR("Failed to allocate buffer memory.\n");
803 return D3DERR_OUTOFVIDEOMEMORY
;
806 hr
= vertexbuffer_init(object
, device
, size
, usage
, fvf
, pool
);
809 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr
);
810 HeapFree(GetProcessHeap(), 0, object
);
814 TRACE("Created vertex buffer %p.\n", object
);
815 *buffer
= &object
->IDirect3DVertexBuffer8_iface
;
820 static HRESULT WINAPI
d3d8_device_CreateIndexBuffer(IDirect3DDevice8
*iface
, UINT size
,
821 DWORD usage
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DIndexBuffer8
**buffer
)
823 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
824 struct d3d8_indexbuffer
*object
;
827 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p.\n",
828 iface
, size
, usage
, format
, pool
, buffer
);
830 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
833 ERR("Failed to allocate buffer memory.\n");
834 return D3DERR_OUTOFVIDEOMEMORY
;
837 hr
= indexbuffer_init(object
, device
, size
, usage
, format
, pool
);
840 WARN("Failed to initialize index buffer, hr %#x.\n", hr
);
841 HeapFree(GetProcessHeap(), 0, object
);
845 TRACE("Created index buffer %p.\n", object
);
846 *buffer
= &object
->IDirect3DIndexBuffer8_iface
;
851 static HRESULT
d3d8_device_CreateSurface(struct d3d8_device
*device
, UINT width
,
852 UINT height
, D3DFORMAT format
, BOOL lockable
, BOOL discard
, UINT level
,
853 IDirect3DSurface8
**surface
, UINT usage
, D3DPOOL pool
, D3DMULTISAMPLE_TYPE multisample_type
,
854 DWORD multisample_quality
)
856 struct d3d8_surface
*object
;
859 TRACE("device %p, width %u, height %u, format %#x, lockable %#x, discard %#x, level %u, surface %p,\n"
860 "\tusage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
861 device
, width
, height
, format
, lockable
, discard
, level
, surface
,
862 usage
, pool
, multisample_type
, multisample_quality
);
864 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
866 FIXME("Failed to allocate surface memory.\n");
867 return D3DERR_OUTOFVIDEOMEMORY
;
870 hr
= surface_init(object
, device
, width
, height
, format
, lockable
, discard
, level
, usage
,
871 pool
, multisample_type
, multisample_quality
);
874 WARN("Failed to initialize surface, hr %#x.\n", hr
);
875 HeapFree(GetProcessHeap(), 0, object
);
879 TRACE("Created surface %p.\n", object
);
880 *surface
= &object
->IDirect3DSurface8_iface
;
885 static HRESULT WINAPI
d3d8_device_CreateRenderTarget(IDirect3DDevice8
*iface
, UINT width
,
886 UINT height
, D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, BOOL lockable
,
887 IDirect3DSurface8
**surface
)
889 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
892 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, lockable %#x, surface %p.\n",
893 iface
, width
, height
, format
, multisample_type
, lockable
, surface
);
895 hr
= d3d8_device_CreateSurface(device
, width
, height
, format
, lockable
,
896 FALSE
, 0, surface
, D3DUSAGE_RENDERTARGET
, D3DPOOL_DEFAULT
,
897 multisample_type
, 0);
902 static HRESULT WINAPI
d3d8_device_CreateDepthStencilSurface(IDirect3DDevice8
*iface
,
903 UINT width
, UINT height
, D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
,
904 IDirect3DSurface8
**surface
)
906 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
909 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, surface %p.\n",
910 iface
, width
, height
, format
, multisample_type
, surface
);
912 /* TODO: Verify that Discard is false */
913 hr
= d3d8_device_CreateSurface(device
, width
, height
, format
, TRUE
, FALSE
,
914 0, surface
, D3DUSAGE_DEPTHSTENCIL
, D3DPOOL_DEFAULT
, multisample_type
, 0);
919 /* IDirect3DDevice8Impl::CreateImageSurface returns surface with pool type SYSTEMMEM */
920 static HRESULT WINAPI
d3d8_device_CreateImageSurface(IDirect3DDevice8
*iface
, UINT width
,
921 UINT height
, D3DFORMAT format
, IDirect3DSurface8
**surface
)
923 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
926 TRACE("iface %p, width %u, height %u, format %#x, surface %p.\n",
927 iface
, width
, height
, format
, surface
);
929 hr
= d3d8_device_CreateSurface(device
, width
, height
, format
, TRUE
, FALSE
,
930 0, surface
, 0, D3DPOOL_SYSTEMMEM
, D3DMULTISAMPLE_NONE
, 0);
935 static HRESULT WINAPI
d3d8_device_CopyRects(IDirect3DDevice8
*iface
,
936 IDirect3DSurface8
*src_surface
, const RECT
*src_rects
, UINT rect_count
,
937 IDirect3DSurface8
*dst_surface
, const POINT
*dst_points
)
939 struct d3d8_surface
*src
= unsafe_impl_from_IDirect3DSurface8(src_surface
);
940 struct d3d8_surface
*dst
= unsafe_impl_from_IDirect3DSurface8(dst_surface
);
941 enum wined3d_format_id src_format
, dst_format
;
942 struct wined3d_resource_desc wined3d_desc
;
943 struct wined3d_resource
*wined3d_resource
;
947 TRACE("iface %p, src_surface %p, src_rects %p, rect_count %u, dst_surface %p, dst_points %p.\n",
948 iface
, src_surface
, src_rects
, rect_count
, dst_surface
, dst_points
);
950 /* Check that the source texture is in WINED3D_POOL_SYSTEM_MEM and the
951 * destination texture is in WINED3D_POOL_DEFAULT. */
953 wined3d_mutex_lock();
954 wined3d_resource
= wined3d_surface_get_resource(src
->wined3d_surface
);
955 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
956 if (wined3d_desc
.usage
& WINED3DUSAGE_DEPTHSTENCIL
)
958 WARN("Source %p is a depth stencil surface, returning D3DERR_INVALIDCALL.\n", src_surface
);
959 wined3d_mutex_unlock();
960 return D3DERR_INVALIDCALL
;
962 src_format
= wined3d_desc
.format
;
963 src_w
= wined3d_desc
.width
;
964 src_h
= wined3d_desc
.height
;
966 wined3d_resource
= wined3d_surface_get_resource(dst
->wined3d_surface
);
967 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
968 if (wined3d_desc
.usage
& WINED3DUSAGE_DEPTHSTENCIL
)
970 WARN("Destination %p is a depth stencil surface, returning D3DERR_INVALIDCALL.\n", dst_surface
);
971 wined3d_mutex_unlock();
972 return D3DERR_INVALIDCALL
;
974 dst_format
= wined3d_desc
.format
;
976 /* Check that the source and destination formats match */
977 if (src_format
!= dst_format
&& WINED3DFMT_UNKNOWN
!= dst_format
)
979 WARN("Source %p format must match the destination %p format, returning D3DERR_INVALIDCALL.\n",
980 src_surface
, dst_surface
);
981 wined3d_mutex_unlock();
982 return D3DERR_INVALIDCALL
;
984 else if (WINED3DFMT_UNKNOWN
== dst_format
)
986 TRACE("Converting destination surface from WINED3DFMT_UNKNOWN to the source format.\n");
987 if (FAILED(hr
= wined3d_surface_update_desc(dst
->wined3d_surface
, wined3d_desc
.width
, wined3d_desc
.height
,
988 src_format
, wined3d_desc
.multisample_type
, wined3d_desc
.multisample_quality
)))
990 WARN("Failed to update surface desc, hr %#x.\n", hr
);
991 wined3d_mutex_unlock();
996 /* Quick if complete copy ... */
997 if (!rect_count
&& !src_rects
&& !dst_points
)
999 RECT rect
= {0, 0, src_w
, src_h
};
1000 wined3d_surface_blt(dst
->wined3d_surface
, &rect
,
1001 src
->wined3d_surface
, &rect
, 0, NULL
, WINED3D_TEXF_POINT
);
1006 /* Copy rect by rect */
1007 if (src_rects
&& dst_points
)
1009 for (i
= 0; i
< rect_count
; ++i
)
1011 UINT w
= src_rects
[i
].right
- src_rects
[i
].left
;
1012 UINT h
= src_rects
[i
].bottom
- src_rects
[i
].top
;
1013 RECT dst_rect
= {dst_points
[i
].x
, dst_points
[i
].y
,
1014 dst_points
[i
].x
+ w
, dst_points
[i
].y
+ h
};
1016 wined3d_surface_blt(dst
->wined3d_surface
, &dst_rect
,
1017 src
->wined3d_surface
, &src_rects
[i
], 0, NULL
, WINED3D_TEXF_POINT
);
1022 for (i
= 0; i
< rect_count
; ++i
)
1024 UINT w
= src_rects
[i
].right
- src_rects
[i
].left
;
1025 UINT h
= src_rects
[i
].bottom
- src_rects
[i
].top
;
1026 RECT dst_rect
= {0, 0, w
, h
};
1028 wined3d_surface_blt(dst
->wined3d_surface
, &dst_rect
,
1029 src
->wined3d_surface
, &src_rects
[i
], 0, NULL
, WINED3D_TEXF_POINT
);
1033 wined3d_mutex_unlock();
1038 static HRESULT WINAPI
d3d8_device_UpdateTexture(IDirect3DDevice8
*iface
,
1039 IDirect3DBaseTexture8
*src_texture
, IDirect3DBaseTexture8
*dst_texture
)
1041 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1042 struct d3d8_texture
*src_impl
, *dst_impl
;
1045 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface
, src_texture
, dst_texture
);
1047 src_impl
= unsafe_impl_from_IDirect3DBaseTexture8(src_texture
);
1048 dst_impl
= unsafe_impl_from_IDirect3DBaseTexture8(dst_texture
);
1050 wined3d_mutex_lock();
1051 hr
= wined3d_device_update_texture(device
->wined3d_device
,
1052 src_impl
->wined3d_texture
, dst_impl
->wined3d_texture
);
1053 wined3d_mutex_unlock();
1058 static HRESULT WINAPI
d3d8_device_GetFrontBuffer(IDirect3DDevice8
*iface
, IDirect3DSurface8
*dst_surface
)
1060 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1061 struct d3d8_surface
*dst_impl
= unsafe_impl_from_IDirect3DSurface8(dst_surface
);
1064 TRACE("iface %p, dst_surface %p.\n", iface
, dst_surface
);
1068 WARN("Invalid destination surface passed.\n");
1069 return D3DERR_INVALIDCALL
;
1072 wined3d_mutex_lock();
1073 hr
= wined3d_device_get_front_buffer_data(device
->wined3d_device
, 0, dst_impl
->wined3d_surface
);
1074 wined3d_mutex_unlock();
1079 static HRESULT WINAPI
d3d8_device_SetRenderTarget(IDirect3DDevice8
*iface
,
1080 IDirect3DSurface8
*render_target
, IDirect3DSurface8
*depth_stencil
)
1082 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1083 struct d3d8_surface
*rt_impl
= unsafe_impl_from_IDirect3DSurface8(render_target
);
1084 struct d3d8_surface
*ds_impl
= unsafe_impl_from_IDirect3DSurface8(depth_stencil
);
1085 struct wined3d_surface
*original_ds
= NULL
;
1086 HRESULT hr
= D3D_OK
;
1088 TRACE("iface %p, render_target %p, depth_stencil %p.\n", iface
, render_target
, depth_stencil
);
1090 wined3d_mutex_lock();
1094 struct wined3d_resource_desc ds_desc
, rt_desc
;
1095 struct wined3d_resource
*wined3d_resource
;
1096 struct wined3d_surface
*original_rt
= NULL
;
1098 /* If no render target is passed in check the size against the current RT */
1101 if (!(original_rt
= wined3d_device_get_render_target(device
->wined3d_device
, 0)))
1103 wined3d_mutex_unlock();
1104 return D3DERR_NOTFOUND
;
1106 wined3d_resource
= wined3d_surface_get_resource(original_rt
);
1109 wined3d_resource
= wined3d_surface_get_resource(rt_impl
->wined3d_surface
);
1110 wined3d_resource_get_desc(wined3d_resource
, &rt_desc
);
1112 wined3d_resource
= wined3d_surface_get_resource(ds_impl
->wined3d_surface
);
1113 wined3d_resource_get_desc(wined3d_resource
, &ds_desc
);
1115 if (ds_desc
.width
< rt_desc
.width
|| ds_desc
.height
< rt_desc
.height
)
1117 WARN("Depth stencil is smaller than the render target, returning D3DERR_INVALIDCALL\n");
1118 wined3d_mutex_unlock();
1119 return D3DERR_INVALIDCALL
;
1123 original_ds
= wined3d_device_get_depth_stencil(device
->wined3d_device
);
1124 wined3d_device_set_depth_stencil(device
->wined3d_device
, ds_impl
? ds_impl
->wined3d_surface
: NULL
);
1127 hr
= wined3d_device_set_render_target(device
->wined3d_device
, 0, rt_impl
->wined3d_surface
, TRUE
);
1129 wined3d_device_set_depth_stencil(device
->wined3d_device
, original_ds
);
1132 wined3d_mutex_unlock();
1137 static HRESULT WINAPI
d3d8_device_GetRenderTarget(IDirect3DDevice8
*iface
, IDirect3DSurface8
**render_target
)
1139 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1140 struct wined3d_surface
*wined3d_surface
;
1141 struct d3d8_surface
*surface_impl
;
1144 TRACE("iface %p, render_target %p.\n", iface
, render_target
);
1147 return D3DERR_INVALIDCALL
;
1149 wined3d_mutex_lock();
1150 if ((wined3d_surface
= wined3d_device_get_render_target(device
->wined3d_device
, 0)))
1152 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
1153 *render_target
= &surface_impl
->IDirect3DSurface8_iface
;
1154 IDirect3DSurface8_AddRef(*render_target
);
1159 ERR("Failed to get wined3d render target.\n");
1160 *render_target
= NULL
;
1161 hr
= D3DERR_NOTFOUND
;
1163 wined3d_mutex_unlock();
1168 static HRESULT WINAPI
d3d8_device_GetDepthStencilSurface(IDirect3DDevice8
*iface
, IDirect3DSurface8
**depth_stencil
)
1170 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1171 struct wined3d_surface
*wined3d_surface
;
1172 struct d3d8_surface
*surface_impl
;
1173 HRESULT hr
= D3D_OK
;
1175 TRACE("iface %p, depth_stencil %p.\n", iface
, depth_stencil
);
1178 return D3DERR_INVALIDCALL
;
1180 wined3d_mutex_lock();
1181 if ((wined3d_surface
= wined3d_device_get_depth_stencil(device
->wined3d_device
)))
1183 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
1184 *depth_stencil
= &surface_impl
->IDirect3DSurface8_iface
;
1185 IDirect3DSurface8_AddRef(*depth_stencil
);
1189 hr
= WINED3DERR_NOTFOUND
;
1190 *depth_stencil
= NULL
;
1192 wined3d_mutex_unlock();
1197 static HRESULT WINAPI
d3d8_device_BeginScene(IDirect3DDevice8
*iface
)
1199 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1202 TRACE("iface %p.\n", iface
);
1204 wined3d_mutex_lock();
1205 hr
= wined3d_device_begin_scene(device
->wined3d_device
);
1206 wined3d_mutex_unlock();
1211 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d8_device_EndScene(IDirect3DDevice8
*iface
)
1213 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1216 TRACE("iface %p.\n", iface
);
1218 wined3d_mutex_lock();
1219 hr
= wined3d_device_end_scene(device
->wined3d_device
);
1220 wined3d_mutex_unlock();
1225 static HRESULT WINAPI
d3d8_device_Clear(IDirect3DDevice8
*iface
, DWORD rect_count
,
1226 const D3DRECT
*rects
, DWORD flags
, D3DCOLOR color
, float z
, DWORD stencil
)
1228 const struct wined3d_color c
=
1230 ((color
>> 16) & 0xff) / 255.0f
,
1231 ((color
>> 8) & 0xff) / 255.0f
,
1232 (color
& 0xff) / 255.0f
,
1233 ((color
>> 24) & 0xff) / 255.0f
,
1235 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1238 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1239 iface
, rect_count
, rects
, flags
, color
, z
, stencil
);
1241 wined3d_mutex_lock();
1242 hr
= wined3d_device_clear(device
->wined3d_device
, rect_count
, (const RECT
*)rects
, flags
, &c
, z
, stencil
);
1243 wined3d_mutex_unlock();
1248 static HRESULT WINAPI
d3d8_device_SetTransform(IDirect3DDevice8
*iface
,
1249 D3DTRANSFORMSTATETYPE state
, const D3DMATRIX
*matrix
)
1251 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1253 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1255 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1256 wined3d_mutex_lock();
1257 wined3d_device_set_transform(device
->wined3d_device
, state
, (const struct wined3d_matrix
*)matrix
);
1258 wined3d_mutex_unlock();
1263 static HRESULT WINAPI
d3d8_device_GetTransform(IDirect3DDevice8
*iface
,
1264 D3DTRANSFORMSTATETYPE state
, D3DMATRIX
*matrix
)
1266 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1268 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1270 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1271 wined3d_mutex_lock();
1272 wined3d_device_get_transform(device
->wined3d_device
, state
, (struct wined3d_matrix
*)matrix
);
1273 wined3d_mutex_unlock();
1278 static HRESULT WINAPI
d3d8_device_MultiplyTransform(IDirect3DDevice8
*iface
,
1279 D3DTRANSFORMSTATETYPE state
, const D3DMATRIX
*matrix
)
1281 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1283 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1285 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1286 wined3d_mutex_lock();
1287 wined3d_device_multiply_transform(device
->wined3d_device
, state
, (const struct wined3d_matrix
*)matrix
);
1288 wined3d_mutex_unlock();
1293 static HRESULT WINAPI
d3d8_device_SetViewport(IDirect3DDevice8
*iface
, const D3DVIEWPORT8
*viewport
)
1295 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1297 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
1299 /* Note: D3DVIEWPORT8 is compatible with struct wined3d_viewport. */
1300 wined3d_mutex_lock();
1301 wined3d_device_set_viewport(device
->wined3d_device
, (const struct wined3d_viewport
*)viewport
);
1302 wined3d_mutex_unlock();
1307 static HRESULT WINAPI
d3d8_device_GetViewport(IDirect3DDevice8
*iface
, D3DVIEWPORT8
*viewport
)
1309 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1311 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
1313 /* Note: D3DVIEWPORT8 is compatible with struct wined3d_viewport. */
1314 wined3d_mutex_lock();
1315 wined3d_device_get_viewport(device
->wined3d_device
, (struct wined3d_viewport
*)viewport
);
1316 wined3d_mutex_unlock();
1321 static HRESULT WINAPI
d3d8_device_SetMaterial(IDirect3DDevice8
*iface
, const D3DMATERIAL8
*material
)
1323 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1325 TRACE("iface %p, material %p.\n", iface
, material
);
1327 /* Note: D3DMATERIAL8 is compatible with struct wined3d_material. */
1328 wined3d_mutex_lock();
1329 wined3d_device_set_material(device
->wined3d_device
, (const struct wined3d_material
*)material
);
1330 wined3d_mutex_unlock();
1335 static HRESULT WINAPI
d3d8_device_GetMaterial(IDirect3DDevice8
*iface
, D3DMATERIAL8
*material
)
1337 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1339 TRACE("iface %p, material %p.\n", iface
, material
);
1341 /* Note: D3DMATERIAL8 is compatible with struct wined3d_material. */
1342 wined3d_mutex_lock();
1343 wined3d_device_get_material(device
->wined3d_device
, (struct wined3d_material
*)material
);
1344 wined3d_mutex_unlock();
1349 static HRESULT WINAPI
d3d8_device_SetLight(IDirect3DDevice8
*iface
, DWORD index
, const D3DLIGHT8
*light
)
1351 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1354 TRACE("iface %p, index %u, light %p.\n", iface
, index
, light
);
1356 /* Note: D3DLIGHT8 is compatible with struct wined3d_light. */
1357 wined3d_mutex_lock();
1358 hr
= wined3d_device_set_light(device
->wined3d_device
, index
, (const struct wined3d_light
*)light
);
1359 wined3d_mutex_unlock();
1364 static HRESULT WINAPI
d3d8_device_GetLight(IDirect3DDevice8
*iface
, DWORD index
, D3DLIGHT8
*light
)
1366 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1369 TRACE("iface %p, index %u, light %p.\n", iface
, index
, light
);
1371 /* Note: D3DLIGHT8 is compatible with struct wined3d_light. */
1372 wined3d_mutex_lock();
1373 hr
= wined3d_device_get_light(device
->wined3d_device
, index
, (struct wined3d_light
*)light
);
1374 wined3d_mutex_unlock();
1379 static HRESULT WINAPI
d3d8_device_LightEnable(IDirect3DDevice8
*iface
, DWORD index
, BOOL enable
)
1381 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1384 TRACE("iface %p, index %u, enable %#x.\n", iface
, index
, enable
);
1386 wined3d_mutex_lock();
1387 hr
= wined3d_device_set_light_enable(device
->wined3d_device
, index
, enable
);
1388 wined3d_mutex_unlock();
1393 static HRESULT WINAPI
d3d8_device_GetLightEnable(IDirect3DDevice8
*iface
, DWORD index
, BOOL
*enable
)
1395 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1398 TRACE("iface %p, index %u, enable %p.\n", iface
, index
, enable
);
1400 wined3d_mutex_lock();
1401 hr
= wined3d_device_get_light_enable(device
->wined3d_device
, index
, enable
);
1402 wined3d_mutex_unlock();
1407 static HRESULT WINAPI
d3d8_device_SetClipPlane(IDirect3DDevice8
*iface
, DWORD index
, const float *plane
)
1409 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1412 TRACE("iface %p, index %u, plane %p.\n", iface
, index
, plane
);
1414 wined3d_mutex_lock();
1415 hr
= wined3d_device_set_clip_plane(device
->wined3d_device
, index
, (const struct wined3d_vec4
*)plane
);
1416 wined3d_mutex_unlock();
1421 static HRESULT WINAPI
d3d8_device_GetClipPlane(IDirect3DDevice8
*iface
, DWORD index
, float *plane
)
1423 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1426 TRACE("iface %p, index %u, plane %p.\n", iface
, index
, plane
);
1428 wined3d_mutex_lock();
1429 hr
= wined3d_device_get_clip_plane(device
->wined3d_device
, index
, (struct wined3d_vec4
*)plane
);
1430 wined3d_mutex_unlock();
1435 static HRESULT WINAPI
d3d8_device_SetRenderState(IDirect3DDevice8
*iface
,
1436 D3DRENDERSTATETYPE state
, DWORD value
)
1438 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1440 TRACE("iface %p, state %#x, value %#x.\n", iface
, state
, value
);
1442 wined3d_mutex_lock();
1446 wined3d_device_set_render_state(device
->wined3d_device
, WINED3D_RS_DEPTHBIAS
, value
);
1450 wined3d_device_set_render_state(device
->wined3d_device
, state
, value
);
1452 wined3d_mutex_unlock();
1457 static HRESULT WINAPI
d3d8_device_GetRenderState(IDirect3DDevice8
*iface
,
1458 D3DRENDERSTATETYPE state
, DWORD
*value
)
1460 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1462 TRACE("iface %p, state %#x, value %p.\n", iface
, state
, value
);
1464 wined3d_mutex_lock();
1468 *value
= wined3d_device_get_render_state(device
->wined3d_device
, WINED3D_RS_DEPTHBIAS
);
1472 *value
= wined3d_device_get_render_state(device
->wined3d_device
, state
);
1474 wined3d_mutex_unlock();
1479 static HRESULT WINAPI
d3d8_device_BeginStateBlock(IDirect3DDevice8
*iface
)
1481 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1484 TRACE("iface %p.\n", iface
);
1486 wined3d_mutex_lock();
1487 hr
= wined3d_device_begin_stateblock(device
->wined3d_device
);
1488 wined3d_mutex_unlock();
1493 static HRESULT WINAPI
d3d8_device_EndStateBlock(IDirect3DDevice8
*iface
, DWORD
*token
)
1495 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1496 struct wined3d_stateblock
*stateblock
;
1499 TRACE("iface %p, token %p.\n", iface
, token
);
1501 /* Tell wineD3D to endstateblock before anything else (in case we run out
1502 * of memory later and cause locking problems)
1504 wined3d_mutex_lock();
1505 hr
= wined3d_device_end_stateblock(device
->wined3d_device
, &stateblock
);
1508 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
1509 wined3d_mutex_unlock();
1513 *token
= d3d8_allocate_handle(&device
->handle_table
, stateblock
, D3D8_HANDLE_SB
);
1514 wined3d_mutex_unlock();
1516 if (*token
== D3D8_INVALID_HANDLE
)
1518 ERR("Failed to create a handle\n");
1519 wined3d_mutex_lock();
1520 wined3d_stateblock_decref(stateblock
);
1521 wined3d_mutex_unlock();
1526 TRACE("Returning %#x (%p).\n", *token
, stateblock
);
1531 static HRESULT WINAPI
d3d8_device_ApplyStateBlock(IDirect3DDevice8
*iface
, DWORD token
)
1533 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1534 struct wined3d_stateblock
*stateblock
;
1536 TRACE("iface %p, token %#x.\n", iface
, token
);
1541 wined3d_mutex_lock();
1542 stateblock
= d3d8_get_object(&device
->handle_table
, token
- 1, D3D8_HANDLE_SB
);
1545 WARN("Invalid handle (%#x) passed.\n", token
);
1546 wined3d_mutex_unlock();
1547 return D3DERR_INVALIDCALL
;
1549 wined3d_stateblock_apply(stateblock
);
1550 wined3d_mutex_unlock();
1555 static HRESULT WINAPI
d3d8_device_CaptureStateBlock(IDirect3DDevice8
*iface
, DWORD token
)
1557 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1558 struct wined3d_stateblock
*stateblock
;
1560 TRACE("iface %p, token %#x.\n", iface
, token
);
1562 wined3d_mutex_lock();
1563 stateblock
= d3d8_get_object(&device
->handle_table
, token
- 1, D3D8_HANDLE_SB
);
1566 WARN("Invalid handle (%#x) passed.\n", token
);
1567 wined3d_mutex_unlock();
1568 return D3DERR_INVALIDCALL
;
1570 wined3d_stateblock_capture(stateblock
);
1571 wined3d_mutex_unlock();
1576 static HRESULT WINAPI
d3d8_device_DeleteStateBlock(IDirect3DDevice8
*iface
, DWORD token
)
1578 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1579 struct wined3d_stateblock
*stateblock
;
1581 TRACE("iface %p, token %#x.\n", iface
, token
);
1583 wined3d_mutex_lock();
1584 stateblock
= d3d8_free_handle(&device
->handle_table
, token
- 1, D3D8_HANDLE_SB
);
1588 WARN("Invalid handle (%#x) passed.\n", token
);
1589 wined3d_mutex_unlock();
1590 return D3DERR_INVALIDCALL
;
1593 if (wined3d_stateblock_decref(stateblock
))
1595 ERR("Stateblock %p has references left, this shouldn't happen.\n", stateblock
);
1597 wined3d_mutex_unlock();
1602 static HRESULT WINAPI
d3d8_device_CreateStateBlock(IDirect3DDevice8
*iface
,
1603 D3DSTATEBLOCKTYPE type
, DWORD
*handle
)
1605 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1606 struct wined3d_stateblock
*stateblock
;
1609 TRACE("iface %p, type %#x, handle %p.\n", iface
, type
, handle
);
1611 if (type
!= D3DSBT_ALL
1612 && type
!= D3DSBT_PIXELSTATE
1613 && type
!= D3DSBT_VERTEXSTATE
)
1615 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1616 return D3DERR_INVALIDCALL
;
1619 wined3d_mutex_lock();
1620 hr
= wined3d_stateblock_create(device
->wined3d_device
, (enum wined3d_stateblock_type
)type
, &stateblock
);
1623 wined3d_mutex_unlock();
1624 ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr
);
1628 *handle
= d3d8_allocate_handle(&device
->handle_table
, stateblock
, D3D8_HANDLE_SB
);
1629 wined3d_mutex_unlock();
1631 if (*handle
== D3D8_INVALID_HANDLE
)
1633 ERR("Failed to allocate a handle.\n");
1634 wined3d_mutex_lock();
1635 wined3d_stateblock_decref(stateblock
);
1636 wined3d_mutex_unlock();
1641 TRACE("Returning %#x (%p).\n", *handle
, stateblock
);
1646 static HRESULT WINAPI
d3d8_device_SetClipStatus(IDirect3DDevice8
*iface
, const D3DCLIPSTATUS8
*clip_status
)
1648 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1651 TRACE("iface %p, clip_status %p.\n", iface
, clip_status
);
1652 /* FIXME: Verify that D3DCLIPSTATUS8 ~= struct wined3d_clip_status. */
1654 wined3d_mutex_lock();
1655 hr
= wined3d_device_set_clip_status(device
->wined3d_device
, (const struct wined3d_clip_status
*)clip_status
);
1656 wined3d_mutex_unlock();
1661 static HRESULT WINAPI
d3d8_device_GetClipStatus(IDirect3DDevice8
*iface
, D3DCLIPSTATUS8
*clip_status
)
1663 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1666 TRACE("iface %p, clip_status %p.\n", iface
, clip_status
);
1668 wined3d_mutex_lock();
1669 hr
= wined3d_device_get_clip_status(device
->wined3d_device
, (struct wined3d_clip_status
*)clip_status
);
1670 wined3d_mutex_unlock();
1675 static HRESULT WINAPI
d3d8_device_GetTexture(IDirect3DDevice8
*iface
, DWORD stage
, IDirect3DBaseTexture8
**texture
)
1677 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1678 struct wined3d_texture
*wined3d_texture
;
1679 struct d3d8_texture
*texture_impl
;
1681 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
1684 return D3DERR_INVALIDCALL
;
1686 wined3d_mutex_lock();
1687 if ((wined3d_texture
= wined3d_device_get_texture(device
->wined3d_device
, stage
)))
1689 texture_impl
= wined3d_texture_get_parent(wined3d_texture
);
1690 *texture
= &texture_impl
->IDirect3DBaseTexture8_iface
;
1691 IDirect3DBaseTexture8_AddRef(*texture
);
1697 wined3d_mutex_unlock();
1702 static HRESULT WINAPI
d3d8_device_SetTexture(IDirect3DDevice8
*iface
, DWORD stage
, IDirect3DBaseTexture8
*texture
)
1704 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1705 struct d3d8_texture
*texture_impl
;
1708 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
1710 texture_impl
= unsafe_impl_from_IDirect3DBaseTexture8(texture
);
1712 wined3d_mutex_lock();
1713 hr
= wined3d_device_set_texture(device
->wined3d_device
, stage
,
1714 texture_impl
? texture_impl
->wined3d_texture
: NULL
);
1715 wined3d_mutex_unlock();
1720 static const struct tss_lookup
1723 enum wined3d_texture_stage_state state
;
1727 {FALSE
, WINED3D_TSS_INVALID
}, /* 0, unused */
1728 {FALSE
, WINED3D_TSS_COLOR_OP
}, /* 1, D3DTSS_COLOROP */
1729 {FALSE
, WINED3D_TSS_COLOR_ARG1
}, /* 2, D3DTSS_COLORARG1 */
1730 {FALSE
, WINED3D_TSS_COLOR_ARG2
}, /* 3, D3DTSS_COLORARG2 */
1731 {FALSE
, WINED3D_TSS_ALPHA_OP
}, /* 4, D3DTSS_ALPHAOP */
1732 {FALSE
, WINED3D_TSS_ALPHA_ARG1
}, /* 5, D3DTSS_ALPHAARG1 */
1733 {FALSE
, WINED3D_TSS_ALPHA_ARG2
}, /* 6, D3DTSS_ALPHAARG2 */
1734 {FALSE
, WINED3D_TSS_BUMPENV_MAT00
}, /* 7, D3DTSS_BUMPENVMAT00 */
1735 {FALSE
, WINED3D_TSS_BUMPENV_MAT01
}, /* 8, D3DTSS_BUMPENVMAT01 */
1736 {FALSE
, WINED3D_TSS_BUMPENV_MAT10
}, /* 9, D3DTSS_BUMPENVMAT10 */
1737 {FALSE
, WINED3D_TSS_BUMPENV_MAT11
}, /* 10, D3DTSS_BUMPENVMAT11 */
1738 {FALSE
, WINED3D_TSS_TEXCOORD_INDEX
}, /* 11, D3DTSS_TEXCOORDINDEX */
1739 {FALSE
, WINED3D_TSS_INVALID
}, /* 12, unused */
1740 {TRUE
, WINED3D_SAMP_ADDRESS_U
}, /* 13, D3DTSS_ADDRESSU */
1741 {TRUE
, WINED3D_SAMP_ADDRESS_V
}, /* 14, D3DTSS_ADDRESSV */
1742 {TRUE
, WINED3D_SAMP_BORDER_COLOR
}, /* 15, D3DTSS_BORDERCOLOR */
1743 {TRUE
, WINED3D_SAMP_MAG_FILTER
}, /* 16, D3DTSS_MAGFILTER */
1744 {TRUE
, WINED3D_SAMP_MIN_FILTER
}, /* 17, D3DTSS_MINFILTER */
1745 {TRUE
, WINED3D_SAMP_MIP_FILTER
}, /* 18, D3DTSS_MIPFILTER */
1746 {TRUE
, WINED3D_SAMP_MIPMAP_LOD_BIAS
}, /* 19, D3DTSS_MIPMAPLODBIAS */
1747 {TRUE
, WINED3D_SAMP_MAX_MIP_LEVEL
}, /* 20, D3DTSS_MAXMIPLEVEL */
1748 {TRUE
, WINED3D_SAMP_MAX_ANISOTROPY
}, /* 21, D3DTSS_MAXANISOTROPY */
1749 {FALSE
, WINED3D_TSS_BUMPENV_LSCALE
}, /* 22, D3DTSS_BUMPENVLSCALE */
1750 {FALSE
, WINED3D_TSS_BUMPENV_LOFFSET
}, /* 23, D3DTSS_BUMPENVLOFFSET */
1751 {FALSE
, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1752 {TRUE
, WINED3D_SAMP_ADDRESS_W
}, /* 25, D3DTSS_ADDRESSW */
1753 {FALSE
, WINED3D_TSS_COLOR_ARG0
}, /* 26, D3DTSS_COLORARG0 */
1754 {FALSE
, WINED3D_TSS_ALPHA_ARG0
}, /* 27, D3DTSS_ALPHAARG0 */
1755 {FALSE
, WINED3D_TSS_RESULT_ARG
}, /* 28, D3DTSS_RESULTARG */
1758 static HRESULT WINAPI
d3d8_device_GetTextureStageState(IDirect3DDevice8
*iface
,
1759 DWORD stage
, D3DTEXTURESTAGESTATETYPE Type
, DWORD
*value
)
1761 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1762 const struct tss_lookup
*l
;
1764 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface
, stage
, Type
, value
);
1766 if (Type
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
1768 WARN("Invalid Type %#x passed.\n", Type
);
1772 l
= &tss_lookup
[Type
];
1774 wined3d_mutex_lock();
1775 if (l
->sampler_state
)
1776 *value
= wined3d_device_get_sampler_state(device
->wined3d_device
, stage
, l
->state
);
1778 *value
= wined3d_device_get_texture_stage_state(device
->wined3d_device
, stage
, l
->state
);
1779 wined3d_mutex_unlock();
1784 static HRESULT WINAPI
d3d8_device_SetTextureStageState(IDirect3DDevice8
*iface
,
1785 DWORD stage
, D3DTEXTURESTAGESTATETYPE type
, DWORD value
)
1787 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1788 const struct tss_lookup
*l
;
1790 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface
, stage
, type
, value
);
1792 if (type
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
1794 WARN("Invalid type %#x passed.\n", type
);
1798 l
= &tss_lookup
[type
];
1800 wined3d_mutex_lock();
1801 if (l
->sampler_state
)
1802 wined3d_device_set_sampler_state(device
->wined3d_device
, stage
, l
->state
, value
);
1804 wined3d_device_set_texture_stage_state(device
->wined3d_device
, stage
, l
->state
, value
);
1805 wined3d_mutex_unlock();
1810 static HRESULT WINAPI
d3d8_device_ValidateDevice(IDirect3DDevice8
*iface
, DWORD
*pass_count
)
1812 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1815 TRACE("iface %p, pass_count %p.\n", iface
, pass_count
);
1817 wined3d_mutex_lock();
1818 hr
= wined3d_device_validate_device(device
->wined3d_device
, pass_count
);
1819 wined3d_mutex_unlock();
1824 static HRESULT WINAPI
d3d8_device_GetInfo(IDirect3DDevice8
*iface
,
1825 DWORD info_id
, void *info
, DWORD info_size
)
1827 FIXME("iface %p, info_id %#x, info %p, info_size %u stub!\n", iface
, info_id
, info
, info_size
);
1832 static HRESULT WINAPI
d3d8_device_SetPaletteEntries(IDirect3DDevice8
*iface
,
1833 UINT palette_idx
, const PALETTEENTRY
*entries
)
1835 FIXME("iface %p, palette_idx %u, entries %p unimplemented\n", iface
, palette_idx
, entries
);
1837 /* GPUs stopped supporting palettized textures with the Shader Model 1 generation. Wined3d
1838 * does not have a d3d8/9-style palette API */
1840 return D3DERR_INVALIDCALL
;
1843 static HRESULT WINAPI
d3d8_device_GetPaletteEntries(IDirect3DDevice8
*iface
,
1844 UINT palette_idx
, PALETTEENTRY
*entries
)
1846 FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface
, palette_idx
, entries
);
1848 return D3DERR_INVALIDCALL
;
1851 static HRESULT WINAPI
d3d8_device_SetCurrentTexturePalette(IDirect3DDevice8
*iface
, UINT palette_idx
)
1853 FIXME("iface %p, palette_idx %u unimplemented.\n", iface
, palette_idx
);
1855 return D3DERR_INVALIDCALL
;
1858 static HRESULT WINAPI
d3d8_device_GetCurrentTexturePalette(IDirect3DDevice8
*iface
, UINT
*palette_idx
)
1860 FIXME("iface %p, palette_idx %p unimplemented.\n", iface
, palette_idx
);
1862 return D3DERR_INVALIDCALL
;
1865 static HRESULT WINAPI
d3d8_device_DrawPrimitive(IDirect3DDevice8
*iface
,
1866 D3DPRIMITIVETYPE primitive_type
, UINT start_vertex
, UINT primitive_count
)
1868 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1871 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1872 iface
, primitive_type
, start_vertex
, primitive_count
);
1874 wined3d_mutex_lock();
1875 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
1876 hr
= wined3d_device_draw_primitive(device
->wined3d_device
, start_vertex
,
1877 vertex_count_from_primitive_count(primitive_type
, primitive_count
));
1878 wined3d_mutex_unlock();
1883 static HRESULT WINAPI
d3d8_device_DrawIndexedPrimitive(IDirect3DDevice8
*iface
,
1884 D3DPRIMITIVETYPE primitive_type
, UINT min_vertex_idx
, UINT vertex_count
,
1885 UINT start_idx
, UINT primitive_count
)
1887 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1890 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, start_idx %u, primitive_count %u.\n",
1891 iface
, primitive_type
, min_vertex_idx
, vertex_count
, start_idx
, primitive_count
);
1893 wined3d_mutex_lock();
1894 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
1895 hr
= wined3d_device_draw_indexed_primitive(device
->wined3d_device
, start_idx
,
1896 vertex_count_from_primitive_count(primitive_type
, primitive_count
));
1897 wined3d_mutex_unlock();
1902 static HRESULT WINAPI
d3d8_device_DrawPrimitiveUP(IDirect3DDevice8
*iface
,
1903 D3DPRIMITIVETYPE primitive_type
, UINT primitive_count
, const void *data
,
1906 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1909 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
1910 iface
, primitive_type
, primitive_count
, data
, stride
);
1912 wined3d_mutex_lock();
1913 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
1914 hr
= wined3d_device_draw_primitive_up(device
->wined3d_device
,
1915 vertex_count_from_primitive_count(primitive_type
, primitive_count
),
1917 wined3d_mutex_unlock();
1922 static HRESULT WINAPI
d3d8_device_DrawIndexedPrimitiveUP(IDirect3DDevice8
*iface
,
1923 D3DPRIMITIVETYPE primitive_type
, UINT min_vertex_idx
, UINT index_count
,
1924 UINT primitive_count
, const void *index_data
, D3DFORMAT index_format
,
1925 const void *vertex_data
, UINT vertex_stride
)
1927 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1930 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
1931 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
1932 iface
, primitive_type
, min_vertex_idx
, index_count
, primitive_count
,
1933 index_data
, index_format
, vertex_data
, vertex_stride
);
1935 wined3d_mutex_lock();
1936 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
1937 hr
= wined3d_device_draw_indexed_primitive_up(device
->wined3d_device
,
1938 vertex_count_from_primitive_count(primitive_type
, primitive_count
), index_data
,
1939 wined3dformat_from_d3dformat(index_format
), vertex_data
, vertex_stride
);
1940 wined3d_mutex_unlock();
1945 static HRESULT WINAPI
d3d8_device_ProcessVertices(IDirect3DDevice8
*iface
, UINT src_start_idx
,
1946 UINT dst_idx
, UINT vertex_count
, IDirect3DVertexBuffer8
*dst_buffer
, DWORD flags
)
1948 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1949 struct d3d8_vertexbuffer
*dst
= unsafe_impl_from_IDirect3DVertexBuffer8(dst_buffer
);
1952 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, flags %#x.\n",
1953 iface
, src_start_idx
, dst_idx
, vertex_count
, dst_buffer
, flags
);
1955 wined3d_mutex_lock();
1956 hr
= wined3d_device_process_vertices(device
->wined3d_device
, src_start_idx
, dst_idx
,
1957 vertex_count
, dst
->wined3d_buffer
, NULL
, flags
, dst
->fvf
);
1958 wined3d_mutex_unlock();
1963 static HRESULT WINAPI
d3d8_device_CreateVertexShader(IDirect3DDevice8
*iface
,
1964 const DWORD
*declaration
, const DWORD
*byte_code
, DWORD
*shader
, DWORD usage
)
1966 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1967 struct d3d8_vertex_shader
*object
;
1968 DWORD shader_handle
;
1972 TRACE("iface %p, declaration %p, byte_code %p, shader %p, usage %#x.\n",
1973 iface
, declaration
, byte_code
, shader
, usage
);
1975 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1978 ERR("Failed to allocate vertex shader memory.\n");
1980 return E_OUTOFMEMORY
;
1983 wined3d_mutex_lock();
1984 handle
= d3d8_allocate_handle(&device
->handle_table
, object
, D3D8_HANDLE_VS
);
1985 wined3d_mutex_unlock();
1986 if (handle
== D3D8_INVALID_HANDLE
)
1988 ERR("Failed to allocate vertex shader handle.\n");
1989 HeapFree(GetProcessHeap(), 0, object
);
1991 return E_OUTOFMEMORY
;
1994 shader_handle
= handle
+ VS_HIGHESTFIXEDFXF
+ 1;
1996 hr
= d3d8_vertex_shader_init(object
, device
, declaration
, byte_code
, shader_handle
, usage
);
1999 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
2000 wined3d_mutex_lock();
2001 d3d8_free_handle(&device
->handle_table
, handle
, D3D8_HANDLE_VS
);
2002 wined3d_mutex_unlock();
2003 HeapFree(GetProcessHeap(), 0, object
);
2008 TRACE("Created vertex shader %p (handle %#x).\n", object
, shader_handle
);
2009 *shader
= shader_handle
;
2014 static struct d3d8_vertex_declaration
*d3d8_device_get_fvf_declaration(struct d3d8_device
*device
, DWORD fvf
)
2016 struct d3d8_vertex_declaration
*d3d8_declaration
;
2017 struct FvfToDecl
*convertedDecls
= device
->decls
;
2018 int p
, low
, high
; /* deliberately signed */
2021 TRACE("Searching for declaration for fvf %08x... ", fvf
);
2024 high
= device
->numConvertedDecls
- 1;
2027 p
= (low
+ high
) >> 1;
2030 if (convertedDecls
[p
].fvf
== fvf
)
2032 TRACE("found %p\n", convertedDecls
[p
].declaration
);
2033 return convertedDecls
[p
].declaration
;
2036 if (convertedDecls
[p
].fvf
< fvf
)
2041 TRACE("not found. Creating and inserting at position %d.\n", low
);
2043 if (!(d3d8_declaration
= HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration
))))
2045 ERR("Memory allocation failed.\n");
2049 if (FAILED(hr
= d3d8_vertex_declaration_init_fvf(d3d8_declaration
, device
, fvf
)))
2051 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr
);
2052 HeapFree(GetProcessHeap(), 0, d3d8_declaration
);
2056 if (device
->declArraySize
== device
->numConvertedDecls
)
2058 UINT grow
= device
->declArraySize
/ 2;
2060 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
2061 sizeof(*convertedDecls
) * (device
->numConvertedDecls
+ grow
));
2062 if (!convertedDecls
)
2064 d3d8_vertex_declaration_destroy(d3d8_declaration
);
2067 device
->decls
= convertedDecls
;
2068 device
->declArraySize
+= grow
;
2071 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
,
2072 sizeof(*convertedDecls
) * (device
->numConvertedDecls
- low
));
2073 convertedDecls
[low
].declaration
= d3d8_declaration
;
2074 convertedDecls
[low
].fvf
= fvf
;
2075 ++device
->numConvertedDecls
;
2077 TRACE("Returning %p. %u decls in array.\n", d3d8_declaration
, device
->numConvertedDecls
);
2079 return d3d8_declaration
;
2082 static HRESULT WINAPI
d3d8_device_SetVertexShader(IDirect3DDevice8
*iface
, DWORD shader
)
2084 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2085 struct d3d8_vertex_shader
*shader_impl
;
2087 TRACE("iface %p, shader %#x.\n", iface
, shader
);
2089 if (VS_HIGHESTFIXEDFXF
>= shader
)
2091 TRACE("Setting FVF, %#x\n", shader
);
2093 wined3d_mutex_lock();
2094 wined3d_device_set_vertex_declaration(device
->wined3d_device
,
2095 d3d8_device_get_fvf_declaration(device
, shader
)->wined3d_vertex_declaration
);
2096 wined3d_device_set_vertex_shader(device
->wined3d_device
, NULL
);
2097 wined3d_mutex_unlock();
2102 TRACE("Setting shader\n");
2104 wined3d_mutex_lock();
2105 if (!(shader_impl
= d3d8_get_object(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
)))
2107 WARN("Invalid handle (%#x) passed.\n", shader
);
2108 wined3d_mutex_unlock();
2110 return D3DERR_INVALIDCALL
;
2113 wined3d_device_set_vertex_declaration(device
->wined3d_device
,
2114 shader_impl
->vertex_declaration
->wined3d_vertex_declaration
);
2115 wined3d_device_set_vertex_shader(device
->wined3d_device
, shader_impl
->wined3d_shader
);
2116 wined3d_mutex_unlock();
2121 static HRESULT WINAPI
d3d8_device_GetVertexShader(IDirect3DDevice8
*iface
, DWORD
*shader
)
2123 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2124 struct wined3d_vertex_declaration
*wined3d_declaration
;
2125 struct d3d8_vertex_declaration
*d3d8_declaration
;
2127 TRACE("iface %p, shader %p.\n", iface
, shader
);
2129 wined3d_mutex_lock();
2130 if ((wined3d_declaration
= wined3d_device_get_vertex_declaration(device
->wined3d_device
)))
2132 d3d8_declaration
= wined3d_vertex_declaration_get_parent(wined3d_declaration
);
2133 *shader
= d3d8_declaration
->shader_handle
;
2139 wined3d_mutex_unlock();
2141 TRACE("Returning %#x.\n", *shader
);
2146 static HRESULT WINAPI
d3d8_device_DeleteVertexShader(IDirect3DDevice8
*iface
, DWORD shader
)
2148 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2149 struct d3d8_vertex_shader
*shader_impl
;
2151 TRACE("iface %p, shader %#x.\n", iface
, shader
);
2153 wined3d_mutex_lock();
2154 if (!(shader_impl
= d3d8_free_handle(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
)))
2156 WARN("Invalid handle (%#x) passed.\n", shader
);
2157 wined3d_mutex_unlock();
2159 return D3DERR_INVALIDCALL
;
2162 if (shader_impl
->wined3d_shader
2163 && wined3d_device_get_vertex_shader(device
->wined3d_device
) == shader_impl
->wined3d_shader
)
2164 IDirect3DDevice8_SetVertexShader(iface
, 0);
2166 wined3d_mutex_unlock();
2168 d3d8_vertex_shader_destroy(shader_impl
);
2173 static HRESULT WINAPI
d3d8_device_SetVertexShaderConstant(IDirect3DDevice8
*iface
,
2174 DWORD start_register
, const void *data
, DWORD count
)
2176 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2179 TRACE("iface %p, start_register %u, data %p, count %u.\n",
2180 iface
, start_register
, data
, count
);
2182 if (start_register
+ count
> D3D8_MAX_VERTEX_SHADER_CONSTANTF
)
2184 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2185 start_register
+ count
, D3D8_MAX_VERTEX_SHADER_CONSTANTF
);
2186 return D3DERR_INVALIDCALL
;
2189 wined3d_mutex_lock();
2190 hr
= wined3d_device_set_vs_consts_f(device
->wined3d_device
, start_register
, data
, count
);
2191 wined3d_mutex_unlock();
2196 static HRESULT WINAPI
d3d8_device_GetVertexShaderConstant(IDirect3DDevice8
*iface
,
2197 DWORD start_register
, void *data
, DWORD count
)
2199 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2202 TRACE("iface %p, start_register %u, data %p, count %u.\n",
2203 iface
, start_register
, data
, count
);
2205 if (start_register
+ count
> D3D8_MAX_VERTEX_SHADER_CONSTANTF
)
2207 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2208 start_register
+ count
, D3D8_MAX_VERTEX_SHADER_CONSTANTF
);
2209 return D3DERR_INVALIDCALL
;
2212 wined3d_mutex_lock();
2213 hr
= wined3d_device_get_vs_consts_f(device
->wined3d_device
, start_register
, data
, count
);
2214 wined3d_mutex_unlock();
2219 static HRESULT WINAPI
d3d8_device_GetVertexShaderDeclaration(IDirect3DDevice8
*iface
,
2220 DWORD shader
, void *data
, DWORD
*data_size
)
2222 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2223 struct d3d8_vertex_declaration
*declaration
;
2224 struct d3d8_vertex_shader
*shader_impl
;
2226 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2227 iface
, shader
, data
, data_size
);
2229 wined3d_mutex_lock();
2230 shader_impl
= d3d8_get_object(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
);
2231 wined3d_mutex_unlock();
2235 WARN("Invalid handle (%#x) passed.\n", shader
);
2236 return D3DERR_INVALIDCALL
;
2238 declaration
= shader_impl
->vertex_declaration
;
2242 *data_size
= declaration
->elements_size
;
2246 /* MSDN claims that if *data_size is smaller than the required size
2247 * we should write the required size and return D3DERR_MOREDATA.
2248 * That's not actually true. */
2249 if (*data_size
< declaration
->elements_size
)
2250 return D3DERR_INVALIDCALL
;
2252 memcpy(data
, declaration
->elements
, declaration
->elements_size
);
2257 static HRESULT WINAPI
d3d8_device_GetVertexShaderFunction(IDirect3DDevice8
*iface
,
2258 DWORD shader
, void *data
, DWORD
*data_size
)
2260 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2261 struct d3d8_vertex_shader
*shader_impl
= NULL
;
2264 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2265 iface
, shader
, data
, data_size
);
2267 wined3d_mutex_lock();
2268 if (!(shader_impl
= d3d8_get_object(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
)))
2270 WARN("Invalid handle (%#x) passed.\n", shader
);
2271 wined3d_mutex_unlock();
2273 return D3DERR_INVALIDCALL
;
2276 if (!shader_impl
->wined3d_shader
)
2278 wined3d_mutex_unlock();
2283 hr
= wined3d_shader_get_byte_code(shader_impl
->wined3d_shader
, data
, data_size
);
2284 wined3d_mutex_unlock();
2289 static HRESULT WINAPI
d3d8_device_SetIndices(IDirect3DDevice8
*iface
,
2290 IDirect3DIndexBuffer8
*buffer
, UINT base_vertex_idx
)
2292 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2293 struct d3d8_indexbuffer
*ib
= unsafe_impl_from_IDirect3DIndexBuffer8(buffer
);
2295 TRACE("iface %p, buffer %p, base_vertex_idx %u.\n", iface
, buffer
, base_vertex_idx
);
2297 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
2298 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
2299 * vertex buffers can't be created to address them with an index that requires the 32nd bit
2300 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
2303 wined3d_mutex_lock();
2304 wined3d_device_set_base_vertex_index(device
->wined3d_device
, base_vertex_idx
);
2305 wined3d_device_set_index_buffer(device
->wined3d_device
,
2306 ib
? ib
->wined3d_buffer
: NULL
,
2307 ib
? ib
->format
: WINED3DFMT_UNKNOWN
);
2308 wined3d_mutex_unlock();
2313 static HRESULT WINAPI
d3d8_device_GetIndices(IDirect3DDevice8
*iface
,
2314 IDirect3DIndexBuffer8
**buffer
, UINT
*base_vertex_index
)
2316 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2317 struct wined3d_buffer
*wined3d_buffer
;
2318 struct d3d8_indexbuffer
*buffer_impl
;
2320 TRACE("iface %p, buffer %p, base_vertex_index %p.\n", iface
, buffer
, base_vertex_index
);
2323 return D3DERR_INVALIDCALL
;
2325 /* The case from UINT to INT is safe because d3d8 will never set negative values */
2326 wined3d_mutex_lock();
2327 *base_vertex_index
= wined3d_device_get_base_vertex_index(device
->wined3d_device
);
2328 if ((wined3d_buffer
= wined3d_device_get_index_buffer(device
->wined3d_device
)))
2330 buffer_impl
= wined3d_buffer_get_parent(wined3d_buffer
);
2331 *buffer
= &buffer_impl
->IDirect3DIndexBuffer8_iface
;
2332 IDirect3DIndexBuffer8_AddRef(*buffer
);
2338 wined3d_mutex_unlock();
2343 static HRESULT WINAPI
d3d8_device_CreatePixelShader(IDirect3DDevice8
*iface
,
2344 const DWORD
*byte_code
, DWORD
*shader
)
2346 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2347 struct d3d8_pixel_shader
*object
;
2348 DWORD shader_handle
;
2352 TRACE("iface %p, byte_code %p, shader %p.\n", iface
, byte_code
, shader
);
2355 return D3DERR_INVALIDCALL
;
2357 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2360 ERR("Failed to allocate pixel shader memmory.\n");
2361 return E_OUTOFMEMORY
;
2364 wined3d_mutex_lock();
2365 handle
= d3d8_allocate_handle(&device
->handle_table
, object
, D3D8_HANDLE_PS
);
2366 wined3d_mutex_unlock();
2367 if (handle
== D3D8_INVALID_HANDLE
)
2369 ERR("Failed to allocate pixel shader handle.\n");
2370 HeapFree(GetProcessHeap(), 0, object
);
2371 return E_OUTOFMEMORY
;
2374 shader_handle
= handle
+ VS_HIGHESTFIXEDFXF
+ 1;
2376 hr
= d3d8_pixel_shader_init(object
, device
, byte_code
, shader_handle
);
2379 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
2380 wined3d_mutex_lock();
2381 d3d8_free_handle(&device
->handle_table
, handle
, D3D8_HANDLE_PS
);
2382 wined3d_mutex_unlock();
2383 HeapFree(GetProcessHeap(), 0, object
);
2388 TRACE("Created pixel shader %p (handle %#x).\n", object
, shader_handle
);
2389 *shader
= shader_handle
;
2394 static HRESULT WINAPI
d3d8_device_SetPixelShader(IDirect3DDevice8
*iface
, DWORD shader
)
2396 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2397 struct d3d8_pixel_shader
*shader_impl
;
2399 TRACE("iface %p, shader %#x.\n", iface
, shader
);
2401 wined3d_mutex_lock();
2405 wined3d_device_set_pixel_shader(device
->wined3d_device
, NULL
);
2406 wined3d_mutex_unlock();
2410 if (!(shader_impl
= d3d8_get_object(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
)))
2412 WARN("Invalid handle (%#x) passed.\n", shader
);
2413 wined3d_mutex_unlock();
2414 return D3DERR_INVALIDCALL
;
2417 TRACE("Setting shader %p.\n", shader_impl
);
2418 wined3d_device_set_pixel_shader(device
->wined3d_device
, shader_impl
->wined3d_shader
);
2419 wined3d_mutex_unlock();
2424 static HRESULT WINAPI
d3d8_device_GetPixelShader(IDirect3DDevice8
*iface
, DWORD
*shader
)
2426 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2427 struct wined3d_shader
*object
;
2429 TRACE("iface %p, shader %p.\n", iface
, shader
);
2432 return D3DERR_INVALIDCALL
;
2434 wined3d_mutex_lock();
2435 if ((object
= wined3d_device_get_pixel_shader(device
->wined3d_device
)))
2437 struct d3d8_pixel_shader
*d3d8_shader
;
2438 d3d8_shader
= wined3d_shader_get_parent(object
);
2439 *shader
= d3d8_shader
->handle
;
2445 wined3d_mutex_unlock();
2447 TRACE("Returning %#x.\n", *shader
);
2452 static HRESULT WINAPI
d3d8_device_DeletePixelShader(IDirect3DDevice8
*iface
, DWORD shader
)
2454 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2455 struct d3d8_pixel_shader
*shader_impl
;
2457 TRACE("iface %p, shader %#x.\n", iface
, shader
);
2459 wined3d_mutex_lock();
2461 if (!(shader_impl
= d3d8_free_handle(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
)))
2463 WARN("Invalid handle (%#x) passed.\n", shader
);
2464 wined3d_mutex_unlock();
2465 return D3DERR_INVALIDCALL
;
2468 if (wined3d_device_get_pixel_shader(device
->wined3d_device
) == shader_impl
->wined3d_shader
)
2469 IDirect3DDevice8_SetPixelShader(iface
, 0);
2471 wined3d_mutex_unlock();
2473 d3d8_pixel_shader_destroy(shader_impl
);
2478 static HRESULT WINAPI
d3d8_device_SetPixelShaderConstant(IDirect3DDevice8
*iface
,
2479 DWORD start_register
, const void *data
, DWORD count
)
2481 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2484 TRACE("iface %p, start_register %u, data %p, count %u.\n",
2485 iface
, start_register
, data
, count
);
2487 wined3d_mutex_lock();
2488 hr
= wined3d_device_set_ps_consts_f(device
->wined3d_device
, start_register
, data
, count
);
2489 wined3d_mutex_unlock();
2494 static HRESULT WINAPI
d3d8_device_GetPixelShaderConstant(IDirect3DDevice8
*iface
,
2495 DWORD start_register
, void *data
, DWORD count
)
2497 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2500 TRACE("iface %p, start_register %u, data %p, count %u.\n",
2501 iface
, start_register
, data
, count
);
2503 wined3d_mutex_lock();
2504 hr
= wined3d_device_get_ps_consts_f(device
->wined3d_device
, start_register
, data
, count
);
2505 wined3d_mutex_unlock();
2510 static HRESULT WINAPI
d3d8_device_GetPixelShaderFunction(IDirect3DDevice8
*iface
,
2511 DWORD shader
, void *data
, DWORD
*data_size
)
2513 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2514 struct d3d8_pixel_shader
*shader_impl
= NULL
;
2517 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2518 iface
, shader
, data
, data_size
);
2520 wined3d_mutex_lock();
2521 if (!(shader_impl
= d3d8_get_object(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
)))
2523 WARN("Invalid handle (%#x) passed.\n", shader
);
2524 wined3d_mutex_unlock();
2526 return D3DERR_INVALIDCALL
;
2529 hr
= wined3d_shader_get_byte_code(shader_impl
->wined3d_shader
, data
, data_size
);
2530 wined3d_mutex_unlock();
2535 static HRESULT WINAPI
d3d8_device_DrawRectPatch(IDirect3DDevice8
*iface
, UINT handle
,
2536 const float *segment_count
, const D3DRECTPATCH_INFO
*patch_info
)
2538 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2541 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2542 iface
, handle
, segment_count
, patch_info
);
2544 wined3d_mutex_lock();
2545 hr
= wined3d_device_draw_rect_patch(device
->wined3d_device
, handle
,
2546 segment_count
, (const struct wined3d_rect_patch_info
*)patch_info
);
2547 wined3d_mutex_unlock();
2552 static HRESULT WINAPI
d3d8_device_DrawTriPatch(IDirect3DDevice8
*iface
, UINT handle
,
2553 const float *segment_count
, const D3DTRIPATCH_INFO
*patch_info
)
2555 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2558 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2559 iface
, handle
, segment_count
, patch_info
);
2561 wined3d_mutex_lock();
2562 hr
= wined3d_device_draw_tri_patch(device
->wined3d_device
, handle
,
2563 segment_count
, (const struct wined3d_tri_patch_info
*)patch_info
);
2564 wined3d_mutex_unlock();
2569 static HRESULT WINAPI
d3d8_device_DeletePatch(IDirect3DDevice8
*iface
, UINT handle
)
2571 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2574 TRACE("iface %p, handle %#x.\n", iface
, handle
);
2576 wined3d_mutex_lock();
2577 hr
= wined3d_device_delete_patch(device
->wined3d_device
, handle
);
2578 wined3d_mutex_unlock();
2583 static HRESULT WINAPI
d3d8_device_SetStreamSource(IDirect3DDevice8
*iface
,
2584 UINT stream_idx
, IDirect3DVertexBuffer8
*buffer
, UINT stride
)
2586 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2587 struct d3d8_vertexbuffer
*buffer_impl
= unsafe_impl_from_IDirect3DVertexBuffer8(buffer
);
2590 TRACE("iface %p, stream_idx %u, buffer %p, stride %u.\n",
2591 iface
, stream_idx
, buffer
, stride
);
2593 wined3d_mutex_lock();
2594 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, stream_idx
,
2595 buffer_impl
? buffer_impl
->wined3d_buffer
: NULL
, 0, stride
);
2596 wined3d_mutex_unlock();
2601 static HRESULT WINAPI
d3d8_device_GetStreamSource(IDirect3DDevice8
*iface
,
2602 UINT stream_idx
, IDirect3DVertexBuffer8
**buffer
, UINT
*stride
)
2604 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2605 struct d3d8_vertexbuffer
*buffer_impl
;
2606 struct wined3d_buffer
*wined3d_buffer
= NULL
;
2609 TRACE("iface %p, stream_idx %u, buffer %p, stride %p.\n",
2610 iface
, stream_idx
, buffer
, stride
);
2613 return D3DERR_INVALIDCALL
;
2615 wined3d_mutex_lock();
2616 hr
= wined3d_device_get_stream_source(device
->wined3d_device
, stream_idx
, &wined3d_buffer
, 0, stride
);
2617 if (SUCCEEDED(hr
) && wined3d_buffer
)
2619 buffer_impl
= wined3d_buffer_get_parent(wined3d_buffer
);
2620 *buffer
= &buffer_impl
->IDirect3DVertexBuffer8_iface
;
2621 IDirect3DVertexBuffer8_AddRef(*buffer
);
2622 wined3d_buffer_decref(wined3d_buffer
);
2627 ERR("Failed to get wined3d stream source, hr %#x.\n", hr
);
2630 wined3d_mutex_unlock();
2635 static const struct IDirect3DDevice8Vtbl d3d8_device_vtbl
=
2637 d3d8_device_QueryInterface
,
2639 d3d8_device_Release
,
2640 d3d8_device_TestCooperativeLevel
,
2641 d3d8_device_GetAvailableTextureMem
,
2642 d3d8_device_ResourceManagerDiscardBytes
,
2643 d3d8_device_GetDirect3D
,
2644 d3d8_device_GetDeviceCaps
,
2645 d3d8_device_GetDisplayMode
,
2646 d3d8_device_GetCreationParameters
,
2647 d3d8_device_SetCursorProperties
,
2648 d3d8_device_SetCursorPosition
,
2649 d3d8_device_ShowCursor
,
2650 d3d8_device_CreateAdditionalSwapChain
,
2652 d3d8_device_Present
,
2653 d3d8_device_GetBackBuffer
,
2654 d3d8_device_GetRasterStatus
,
2655 d3d8_device_SetGammaRamp
,
2656 d3d8_device_GetGammaRamp
,
2657 d3d8_device_CreateTexture
,
2658 d3d8_device_CreateVolumeTexture
,
2659 d3d8_device_CreateCubeTexture
,
2660 d3d8_device_CreateVertexBuffer
,
2661 d3d8_device_CreateIndexBuffer
,
2662 d3d8_device_CreateRenderTarget
,
2663 d3d8_device_CreateDepthStencilSurface
,
2664 d3d8_device_CreateImageSurface
,
2665 d3d8_device_CopyRects
,
2666 d3d8_device_UpdateTexture
,
2667 d3d8_device_GetFrontBuffer
,
2668 d3d8_device_SetRenderTarget
,
2669 d3d8_device_GetRenderTarget
,
2670 d3d8_device_GetDepthStencilSurface
,
2671 d3d8_device_BeginScene
,
2672 d3d8_device_EndScene
,
2674 d3d8_device_SetTransform
,
2675 d3d8_device_GetTransform
,
2676 d3d8_device_MultiplyTransform
,
2677 d3d8_device_SetViewport
,
2678 d3d8_device_GetViewport
,
2679 d3d8_device_SetMaterial
,
2680 d3d8_device_GetMaterial
,
2681 d3d8_device_SetLight
,
2682 d3d8_device_GetLight
,
2683 d3d8_device_LightEnable
,
2684 d3d8_device_GetLightEnable
,
2685 d3d8_device_SetClipPlane
,
2686 d3d8_device_GetClipPlane
,
2687 d3d8_device_SetRenderState
,
2688 d3d8_device_GetRenderState
,
2689 d3d8_device_BeginStateBlock
,
2690 d3d8_device_EndStateBlock
,
2691 d3d8_device_ApplyStateBlock
,
2692 d3d8_device_CaptureStateBlock
,
2693 d3d8_device_DeleteStateBlock
,
2694 d3d8_device_CreateStateBlock
,
2695 d3d8_device_SetClipStatus
,
2696 d3d8_device_GetClipStatus
,
2697 d3d8_device_GetTexture
,
2698 d3d8_device_SetTexture
,
2699 d3d8_device_GetTextureStageState
,
2700 d3d8_device_SetTextureStageState
,
2701 d3d8_device_ValidateDevice
,
2702 d3d8_device_GetInfo
,
2703 d3d8_device_SetPaletteEntries
,
2704 d3d8_device_GetPaletteEntries
,
2705 d3d8_device_SetCurrentTexturePalette
,
2706 d3d8_device_GetCurrentTexturePalette
,
2707 d3d8_device_DrawPrimitive
,
2708 d3d8_device_DrawIndexedPrimitive
,
2709 d3d8_device_DrawPrimitiveUP
,
2710 d3d8_device_DrawIndexedPrimitiveUP
,
2711 d3d8_device_ProcessVertices
,
2712 d3d8_device_CreateVertexShader
,
2713 d3d8_device_SetVertexShader
,
2714 d3d8_device_GetVertexShader
,
2715 d3d8_device_DeleteVertexShader
,
2716 d3d8_device_SetVertexShaderConstant
,
2717 d3d8_device_GetVertexShaderConstant
,
2718 d3d8_device_GetVertexShaderDeclaration
,
2719 d3d8_device_GetVertexShaderFunction
,
2720 d3d8_device_SetStreamSource
,
2721 d3d8_device_GetStreamSource
,
2722 d3d8_device_SetIndices
,
2723 d3d8_device_GetIndices
,
2724 d3d8_device_CreatePixelShader
,
2725 d3d8_device_SetPixelShader
,
2726 d3d8_device_GetPixelShader
,
2727 d3d8_device_DeletePixelShader
,
2728 d3d8_device_SetPixelShaderConstant
,
2729 d3d8_device_GetPixelShaderConstant
,
2730 d3d8_device_GetPixelShaderFunction
,
2731 d3d8_device_DrawRectPatch
,
2732 d3d8_device_DrawTriPatch
,
2733 d3d8_device_DeletePatch
,
2736 static inline struct d3d8_device
*device_from_device_parent(struct wined3d_device_parent
*device_parent
)
2738 return CONTAINING_RECORD(device_parent
, struct d3d8_device
, device_parent
);
2741 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
2742 struct wined3d_device
*device
)
2744 TRACE("device_parent %p, device %p\n", device_parent
, device
);
2747 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
2749 TRACE("device_parent %p.\n", device_parent
);
2752 static HRESULT CDECL
device_parent_create_texture_surface(struct wined3d_device_parent
*device_parent
,
2753 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
, DWORD usage
,
2754 enum wined3d_pool pool
, UINT level
, enum wined3d_cubemap_face face
, struct wined3d_surface
**surface
)
2756 struct d3d8_device
*device
= device_from_device_parent(device_parent
);
2757 struct d3d8_surface
*d3d_surface
;
2758 BOOL lockable
= TRUE
;
2761 TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
2762 "\tpool %#x, level %u, face %u, surface %p.\n",
2763 device_parent
, container_parent
, width
, height
, format
, usage
, pool
, level
, face
, surface
);
2766 if (pool
== WINED3D_POOL_DEFAULT
&& !(usage
& WINED3DUSAGE_DYNAMIC
))
2769 hr
= d3d8_device_CreateSurface(device
, width
, height
,
2770 d3dformat_from_wined3dformat(format
), lockable
, FALSE
/* Discard */, level
,
2771 (IDirect3DSurface8
**)&d3d_surface
, usage
, pool
, D3DMULTISAMPLE_NONE
, 0 /* MultisampleQuality */);
2774 WARN("Failed to create surface, hr %#x.\n", hr
);
2778 *surface
= d3d_surface
->wined3d_surface
;
2779 wined3d_surface_incref(*surface
);
2781 d3d_surface
->container
= container_parent
;
2782 IDirect3DDevice8_Release(d3d_surface
->parent_device
);
2783 d3d_surface
->parent_device
= NULL
;
2785 IDirect3DSurface8_Release(&d3d_surface
->IDirect3DSurface8_iface
);
2786 d3d_surface
->forwardReference
= container_parent
;
2791 static HRESULT CDECL
device_parent_create_swapchain_surface(struct wined3d_device_parent
*device_parent
,
2792 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format_id
, DWORD usage
,
2793 enum wined3d_multisample_type multisample_type
, DWORD multisample_quality
, struct wined3d_surface
**surface
)
2795 struct d3d8_device
*device
= device_from_device_parent(device_parent
);
2796 struct d3d8_surface
*d3d_surface
;
2799 TRACE("device_parent %p, container_parent %p, width %u, height %u, format_id %#x, usage %#x,\n"
2800 "\tmultisample_type %#x, multisample_quality %u, surface %p.\n",
2801 device_parent
, container_parent
, width
, height
, format_id
, usage
,
2802 multisample_type
, multisample_quality
, surface
);
2804 if (FAILED(hr
= d3d8_device_CreateSurface(device
, width
, height
, d3dformat_from_wined3dformat(format_id
),
2805 TRUE
, FALSE
, 0, (IDirect3DSurface8
**)&d3d_surface
, usage
, D3DPOOL_DEFAULT
, multisample_type
,
2806 multisample_quality
)))
2808 WARN("Failed to create surface, hr %#x.\n", hr
);
2812 *surface
= d3d_surface
->wined3d_surface
;
2813 wined3d_surface_incref(*surface
);
2815 d3d_surface
->container
= (IUnknown
*)&device
->IDirect3DDevice8_iface
;
2816 /* Implicit surfaces are created with an refcount of 0 */
2817 IDirect3DSurface8_Release(&d3d_surface
->IDirect3DSurface8_iface
);
2822 static HRESULT CDECL
device_parent_create_volume(struct wined3d_device_parent
*device_parent
,
2823 void *container_parent
, UINT width
, UINT height
, UINT depth
, enum wined3d_format_id format
,
2824 enum wined3d_pool pool
, DWORD usage
, struct wined3d_volume
**volume
)
2826 struct d3d8_device
*device
= device_from_device_parent(device_parent
);
2827 struct d3d8_volume
*object
;
2830 TRACE("device_parent %p, container_parent %p, width %u, height %u, depth %u, "
2831 "format %#x, pool %#x, usage %#x, volume %p.\n",
2832 device_parent
, container_parent
, width
, height
, depth
,
2833 format
, pool
, usage
, volume
);
2835 /* Allocate the storage for the device */
2836 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2839 FIXME("Allocation of memory failed\n");
2841 return D3DERR_OUTOFVIDEOMEMORY
;
2844 hr
= volume_init(object
, device
, width
, height
, depth
, usage
, format
, pool
);
2847 WARN("Failed to initialize volume, hr %#x.\n", hr
);
2848 HeapFree(GetProcessHeap(), 0, object
);
2852 *volume
= object
->wined3d_volume
;
2853 wined3d_volume_incref(*volume
);
2854 IDirect3DVolume8_Release(&object
->IDirect3DVolume8_iface
);
2856 object
->container
= container_parent
;
2857 object
->forwardReference
= container_parent
;
2859 TRACE("Created volume %p.\n", object
);
2864 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
2865 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain
**swapchain
)
2867 struct d3d8_device
*device
= device_from_device_parent(device_parent
);
2868 struct d3d8_swapchain
*d3d_swapchain
;
2871 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent
, desc
, swapchain
);
2873 if (FAILED(hr
= d3d8_swapchain_create(device
, desc
, &d3d_swapchain
)))
2875 WARN("Failed to create swapchain, hr %#x.\n", hr
);
2880 *swapchain
= d3d_swapchain
->wined3d_swapchain
;
2881 wined3d_swapchain_incref(*swapchain
);
2882 IDirect3DSwapChain8_Release(&d3d_swapchain
->IDirect3DSwapChain8_iface
);
2887 static const struct wined3d_device_parent_ops d3d8_wined3d_device_parent_ops
=
2889 device_parent_wined3d_device_created
,
2890 device_parent_mode_changed
,
2891 device_parent_create_swapchain_surface
,
2892 device_parent_create_texture_surface
,
2893 device_parent_create_volume
,
2894 device_parent_create_swapchain
,
2897 static void setup_fpu(void)
2899 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
2901 __asm__
volatile ("fnstcw %0" : "=m" (cw
));
2902 cw
= (cw
& ~0xf3f) | 0x3f;
2903 __asm__
volatile ("fldcw %0" : : "m" (cw
));
2904 #elif defined(__i386__) && defined(_MSC_VER)
2907 cw
= (cw
& ~0xf3f) | 0x3f;
2910 FIXME("FPU setup not implemented for this platform.\n");
2914 HRESULT
device_init(struct d3d8_device
*device
, struct d3d8
*parent
, struct wined3d
*wined3d
, UINT adapter
,
2915 D3DDEVTYPE device_type
, HWND focus_window
, DWORD flags
, D3DPRESENT_PARAMETERS
*parameters
)
2917 struct wined3d_swapchain_desc swapchain_desc
;
2920 device
->IDirect3DDevice8_iface
.lpVtbl
= &d3d8_device_vtbl
;
2921 device
->device_parent
.ops
= &d3d8_wined3d_device_parent_ops
;
2923 device
->handle_table
.entries
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2924 D3D8_INITIAL_HANDLE_TABLE_SIZE
* sizeof(*device
->handle_table
.entries
));
2925 if (!device
->handle_table
.entries
)
2927 ERR("Failed to allocate handle table memory.\n");
2928 return E_OUTOFMEMORY
;
2930 device
->handle_table
.table_size
= D3D8_INITIAL_HANDLE_TABLE_SIZE
;
2932 if (!(flags
& D3DCREATE_FPU_PRESERVE
)) setup_fpu();
2934 wined3d_mutex_lock();
2935 hr
= wined3d_device_create(wined3d
, adapter
, device_type
, focus_window
, flags
, 4,
2936 &device
->device_parent
, &device
->wined3d_device
);
2939 WARN("Failed to create wined3d device, hr %#x.\n", hr
);
2940 wined3d_mutex_unlock();
2941 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
2945 if (!parameters
->Windowed
)
2947 HWND device_window
= parameters
->hDeviceWindow
;
2950 focus_window
= device_window
;
2951 if (FAILED(hr
= wined3d_device_acquire_focus_window(device
->wined3d_device
, focus_window
)))
2953 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
2954 wined3d_device_decref(device
->wined3d_device
);
2955 wined3d_mutex_unlock();
2956 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
2961 device_window
= focus_window
;
2962 wined3d_device_setup_fullscreen_window(device
->wined3d_device
, device_window
,
2963 parameters
->BackBufferWidth
,
2964 parameters
->BackBufferHeight
);
2967 if (flags
& D3DCREATE_MULTITHREADED
)
2968 wined3d_device_set_multithreaded(device
->wined3d_device
);
2970 wined3d_swapchain_desc_from_present_parameters(&swapchain_desc
, parameters
);
2972 hr
= wined3d_device_init_3d(device
->wined3d_device
, &swapchain_desc
);
2975 WARN("Failed to initialize 3D, hr %#x.\n", hr
);
2976 wined3d_device_release_focus_window(device
->wined3d_device
);
2977 wined3d_device_decref(device
->wined3d_device
);
2978 wined3d_mutex_unlock();
2979 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
2983 wined3d_device_set_render_state(device
->wined3d_device
, WINED3D_RS_POINTSIZE_MIN
, 0);
2984 wined3d_mutex_unlock();
2986 present_parameters_from_wined3d_swapchain_desc(parameters
, &swapchain_desc
);
2988 device
->declArraySize
= 16;
2989 device
->decls
= HeapAlloc(GetProcessHeap(), 0, device
->declArraySize
* sizeof(*device
->decls
));
2992 ERR("Failed to allocate FVF vertex declaration map memory.\n");
2997 device
->d3d_parent
= &parent
->IDirect3D8_iface
;
2998 IDirect3D8_AddRef(device
->d3d_parent
);
3003 wined3d_mutex_lock();
3004 wined3d_device_uninit_3d(device
->wined3d_device
);
3005 wined3d_device_release_focus_window(device
->wined3d_device
);
3006 wined3d_device_decref(device
->wined3d_device
);
3007 wined3d_mutex_unlock();
3008 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);