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 wined3d_swapchain_desc_from_present_parameters(struct wined3d_swapchain_desc
*swapchain_desc
,
168 const D3DPRESENT_PARAMETERS
*present_parameters
)
170 swapchain_desc
->backbuffer_width
= present_parameters
->BackBufferWidth
;
171 swapchain_desc
->backbuffer_height
= present_parameters
->BackBufferHeight
;
172 swapchain_desc
->backbuffer_format
= wined3dformat_from_d3dformat(present_parameters
->BackBufferFormat
);
173 swapchain_desc
->backbuffer_count
= max(1, present_parameters
->BackBufferCount
);
174 swapchain_desc
->multisample_type
= present_parameters
->MultiSampleType
;
175 swapchain_desc
->multisample_quality
= 0; /* d3d9 only */
176 swapchain_desc
->swap_effect
= present_parameters
->SwapEffect
;
177 swapchain_desc
->device_window
= present_parameters
->hDeviceWindow
;
178 swapchain_desc
->windowed
= present_parameters
->Windowed
;
179 swapchain_desc
->enable_auto_depth_stencil
= present_parameters
->EnableAutoDepthStencil
;
180 swapchain_desc
->auto_depth_stencil_format
181 = wined3dformat_from_d3dformat(present_parameters
->AutoDepthStencilFormat
);
182 swapchain_desc
->flags
= present_parameters
->Flags
;
183 swapchain_desc
->refresh_rate
= present_parameters
->FullScreen_RefreshRateInHz
;
184 swapchain_desc
->swap_interval
= present_parameters
->FullScreen_PresentationInterval
;
185 swapchain_desc
->auto_restore_display_mode
= TRUE
;
188 /* Handle table functions */
189 static DWORD
d3d8_allocate_handle(struct d3d8_handle_table
*t
, void *object
, enum d3d8_handle_type type
)
191 struct d3d8_handle_entry
*entry
;
195 DWORD index
= t
->free_entries
- t
->entries
;
196 /* Use a free handle */
197 entry
= t
->free_entries
;
198 if (entry
->type
!= D3D8_HANDLE_FREE
)
200 ERR("Handle %u(%p) is in the free list, but has type %#x.\n", index
, entry
, entry
->type
);
201 return D3D8_INVALID_HANDLE
;
203 t
->free_entries
= entry
->object
;
204 entry
->object
= object
;
210 if (!(t
->entry_count
< t
->table_size
))
213 UINT new_size
= t
->table_size
+ (t
->table_size
>> 1);
214 struct d3d8_handle_entry
*new_entries
= HeapReAlloc(GetProcessHeap(),
215 0, t
->entries
, new_size
* sizeof(*t
->entries
));
218 ERR("Failed to grow the handle table.\n");
219 return D3D8_INVALID_HANDLE
;
221 t
->entries
= new_entries
;
222 t
->table_size
= new_size
;
225 entry
= &t
->entries
[t
->entry_count
];
226 entry
->object
= object
;
229 return t
->entry_count
++;
232 static void *d3d8_free_handle(struct d3d8_handle_table
*t
, DWORD handle
, enum d3d8_handle_type type
)
234 struct d3d8_handle_entry
*entry
;
237 if (handle
== D3D8_INVALID_HANDLE
|| handle
>= t
->entry_count
)
239 WARN("Invalid handle %u passed.\n", handle
);
243 entry
= &t
->entries
[handle
];
244 if (entry
->type
!= type
)
246 WARN("Handle %u(%p) is not of type %#x.\n", handle
, entry
, type
);
250 object
= entry
->object
;
251 entry
->object
= t
->free_entries
;
252 entry
->type
= D3D8_HANDLE_FREE
;
253 t
->free_entries
= entry
;
258 static void *d3d8_get_object(struct d3d8_handle_table
*t
, DWORD handle
, enum d3d8_handle_type type
)
260 struct d3d8_handle_entry
*entry
;
262 if (handle
== D3D8_INVALID_HANDLE
|| handle
>= t
->entry_count
)
264 WARN("Invalid handle %u passed.\n", handle
);
268 entry
= &t
->entries
[handle
];
269 if (entry
->type
!= type
)
271 WARN("Handle %u(%p) is not of type %#x.\n", handle
, entry
, type
);
275 return entry
->object
;
278 static inline struct d3d8_device
*impl_from_IDirect3DDevice8(IDirect3DDevice8
*iface
)
280 return CONTAINING_RECORD(iface
, struct d3d8_device
, IDirect3DDevice8_iface
);
283 static HRESULT WINAPI
d3d8_device_QueryInterface(IDirect3DDevice8
*iface
, REFIID riid
, void **out
)
285 TRACE("iface %p, riid %s, out %p.\n",
286 iface
, debugstr_guid(riid
), out
);
288 if (IsEqualGUID(riid
, &IID_IDirect3DDevice8
)
289 || IsEqualGUID(riid
, &IID_IUnknown
))
291 IUnknown_AddRef(iface
);
296 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
299 return E_NOINTERFACE
;
302 static ULONG WINAPI
d3d8_device_AddRef(IDirect3DDevice8
*iface
)
304 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
305 ULONG ref
= InterlockedIncrement(&device
->ref
);
307 TRACE("%p increasing refcount to %u.\n", iface
, ref
);
312 static ULONG WINAPI
d3d8_device_Release(IDirect3DDevice8
*iface
)
314 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
317 if (device
->inDestruction
)
320 ref
= InterlockedDecrement(&device
->ref
);
322 TRACE("%p decreasing refcount to %u.\n", iface
, ref
);
326 IDirect3D8
*parent
= device
->d3d_parent
;
329 TRACE("Releasing wined3d device %p.\n", device
->wined3d_device
);
331 wined3d_mutex_lock();
333 device
->inDestruction
= TRUE
;
335 for (i
= 0; i
< device
->numConvertedDecls
; ++i
)
337 d3d8_vertex_declaration_destroy(device
->decls
[i
].declaration
);
339 HeapFree(GetProcessHeap(), 0, device
->decls
);
341 wined3d_device_uninit_3d(device
->wined3d_device
);
342 wined3d_device_release_focus_window(device
->wined3d_device
);
343 wined3d_device_decref(device
->wined3d_device
);
344 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
345 HeapFree(GetProcessHeap(), 0, device
);
347 wined3d_mutex_unlock();
349 IDirect3D8_Release(parent
);
354 static HRESULT WINAPI
d3d8_device_TestCooperativeLevel(IDirect3DDevice8
*iface
)
356 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
358 TRACE("iface %p.\n", iface
);
362 TRACE("Device is lost.\n");
363 return D3DERR_DEVICENOTRESET
;
369 static UINT WINAPI
d3d8_device_GetAvailableTextureMem(IDirect3DDevice8
*iface
)
371 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
374 TRACE("iface %p.\n", iface
);
376 wined3d_mutex_lock();
377 hr
= wined3d_device_get_available_texture_mem(device
->wined3d_device
);
378 wined3d_mutex_unlock();
383 static HRESULT WINAPI
d3d8_device_ResourceManagerDiscardBytes(IDirect3DDevice8
*iface
, DWORD byte_count
)
385 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
387 TRACE("iface %p, byte_count %u.\n", iface
, byte_count
);
390 FIXME("Byte count ignored.\n");
392 wined3d_mutex_lock();
393 wined3d_device_evict_managed_resources(device
->wined3d_device
);
394 wined3d_mutex_unlock();
399 static HRESULT WINAPI
d3d8_device_GetDirect3D(IDirect3DDevice8
*iface
, IDirect3D8
**d3d8
)
401 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
403 TRACE("iface %p, d3d8 %p.\n", iface
, d3d8
);
406 return D3DERR_INVALIDCALL
;
408 return IDirect3D8_QueryInterface(device
->d3d_parent
, &IID_IDirect3D8
, (void **)d3d8
);
411 static HRESULT WINAPI
d3d8_device_GetDeviceCaps(IDirect3DDevice8
*iface
, D3DCAPS8
*caps
)
413 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
414 WINED3DCAPS
*wined3d_caps
;
417 TRACE("iface %p, caps %p.\n", iface
, caps
);
420 return D3DERR_INVALIDCALL
;
422 if (!(wined3d_caps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*wined3d_caps
))))
423 return D3DERR_INVALIDCALL
; /* well this is what MSDN says to return */
425 wined3d_mutex_lock();
426 hr
= wined3d_device_get_device_caps(device
->wined3d_device
, wined3d_caps
);
427 wined3d_mutex_unlock();
429 fixup_caps(wined3d_caps
);
430 WINECAPSTOD3D8CAPS(caps
, wined3d_caps
)
431 HeapFree(GetProcessHeap(), 0, wined3d_caps
);
436 static HRESULT WINAPI
d3d8_device_GetDisplayMode(IDirect3DDevice8
*iface
, D3DDISPLAYMODE
*mode
)
438 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
439 struct wined3d_display_mode wined3d_mode
;
442 TRACE("iface %p, mode %p.\n", iface
, mode
);
444 wined3d_mutex_lock();
445 hr
= wined3d_device_get_display_mode(device
->wined3d_device
, 0, &wined3d_mode
, NULL
);
446 wined3d_mutex_unlock();
450 mode
->Width
= wined3d_mode
.width
;
451 mode
->Height
= wined3d_mode
.height
;
452 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
453 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
459 static HRESULT WINAPI
d3d8_device_GetCreationParameters(IDirect3DDevice8
*iface
,
460 D3DDEVICE_CREATION_PARAMETERS
*parameters
)
462 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
465 TRACE("iface %p, parameters %p.\n", iface
, parameters
);
467 wined3d_mutex_lock();
468 hr
= wined3d_device_get_creation_parameters(device
->wined3d_device
,
469 (struct wined3d_device_creation_parameters
*)parameters
);
470 wined3d_mutex_unlock();
475 static HRESULT WINAPI
d3d8_device_SetCursorProperties(IDirect3DDevice8
*iface
,
476 UINT hotspot_x
, UINT hotspot_y
, IDirect3DSurface8
*bitmap
)
478 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
479 struct d3d8_surface
*bitmap_impl
= unsafe_impl_from_IDirect3DSurface8(bitmap
);
482 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
483 iface
, hotspot_x
, hotspot_y
, bitmap
);
487 WARN("No cursor bitmap, returning D3DERR_INVALIDCALL.\n");
488 return D3DERR_INVALIDCALL
;
491 wined3d_mutex_lock();
492 hr
= wined3d_device_set_cursor_properties(device
->wined3d_device
,
493 hotspot_x
, hotspot_y
, bitmap_impl
->wined3d_surface
);
494 wined3d_mutex_unlock();
499 static void WINAPI
d3d8_device_SetCursorPosition(IDirect3DDevice8
*iface
, UINT x
, UINT y
, DWORD flags
)
501 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
503 TRACE("iface %p, x %u, y %u, flags %#x.\n", iface
, x
, y
, flags
);
505 wined3d_mutex_lock();
506 wined3d_device_set_cursor_position(device
->wined3d_device
, x
, y
, flags
);
507 wined3d_mutex_unlock();
510 static BOOL WINAPI
d3d8_device_ShowCursor(IDirect3DDevice8
*iface
, BOOL show
)
512 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
515 TRACE("iface %p, show %#x.\n", iface
, show
);
517 wined3d_mutex_lock();
518 ret
= wined3d_device_show_cursor(device
->wined3d_device
, show
);
519 wined3d_mutex_unlock();
524 static HRESULT WINAPI
d3d8_device_CreateAdditionalSwapChain(IDirect3DDevice8
*iface
,
525 D3DPRESENT_PARAMETERS
*present_parameters
, IDirect3DSwapChain8
**swapchain
)
527 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
528 struct wined3d_swapchain_desc desc
;
529 struct d3d8_swapchain
*object
;
532 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
533 iface
, present_parameters
, swapchain
);
535 wined3d_swapchain_desc_from_present_parameters(&desc
, present_parameters
);
536 if (SUCCEEDED(hr
= d3d8_swapchain_create(device
, &desc
, &object
)))
537 *swapchain
= &object
->IDirect3DSwapChain8_iface
;
539 present_parameters
->BackBufferWidth
= desc
.backbuffer_width
;
540 present_parameters
->BackBufferHeight
= desc
.backbuffer_height
;
541 present_parameters
->BackBufferFormat
= d3dformat_from_wined3dformat(desc
.backbuffer_format
);
542 present_parameters
->BackBufferCount
= desc
.backbuffer_count
;
543 present_parameters
->MultiSampleType
= desc
.multisample_type
;
544 present_parameters
->SwapEffect
= desc
.swap_effect
;
545 present_parameters
->hDeviceWindow
= desc
.device_window
;
546 present_parameters
->Windowed
= desc
.windowed
;
547 present_parameters
->EnableAutoDepthStencil
= desc
.enable_auto_depth_stencil
;
548 present_parameters
->AutoDepthStencilFormat
= d3dformat_from_wined3dformat(desc
.auto_depth_stencil_format
);
549 present_parameters
->Flags
= desc
.flags
;
550 present_parameters
->FullScreen_RefreshRateInHz
= desc
.refresh_rate
;
551 present_parameters
->FullScreen_PresentationInterval
= desc
.swap_interval
;
556 static HRESULT CDECL
reset_enum_callback(struct wined3d_resource
*resource
)
558 struct wined3d_resource_desc desc
;
560 wined3d_resource_get_desc(resource
, &desc
);
561 if (desc
.pool
== WINED3D_POOL_DEFAULT
)
563 struct d3d8_surface
*surface
;
565 if (desc
.resource_type
!= WINED3D_RTYPE_SURFACE
)
567 WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource
);
568 return D3DERR_DEVICELOST
;
571 surface
= wined3d_resource_get_parent(resource
);
572 if (surface
->refcount
)
574 WARN("Surface %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface
, resource
);
575 return D3DERR_DEVICELOST
;
578 WARN("Surface %p (resource %p) is an implicit resource with ref 0.\n", surface
, resource
);
584 static HRESULT WINAPI
d3d8_device_Reset(IDirect3DDevice8
*iface
,
585 D3DPRESENT_PARAMETERS
*present_parameters
)
587 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
588 struct wined3d_swapchain_desc swapchain_desc
;
591 TRACE("iface %p, present_parameters %p.\n", iface
, present_parameters
);
593 wined3d_mutex_lock();
594 wined3d_swapchain_desc_from_present_parameters(&swapchain_desc
, present_parameters
);
595 if (SUCCEEDED(hr
= wined3d_device_reset(device
->wined3d_device
, &swapchain_desc
, reset_enum_callback
)))
597 hr
= wined3d_device_set_render_state(device
->wined3d_device
, WINED3D_RS_POINTSIZE_MIN
, 0);
598 device
->lost
= FALSE
;
604 wined3d_mutex_unlock();
609 static HRESULT WINAPI
d3d8_device_Present(IDirect3DDevice8
*iface
, const RECT
*src_rect
,
610 const RECT
*dst_rect
, HWND dst_window_override
, const RGNDATA
*dirty_region
)
612 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
615 TRACE("iface %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p.\n",
616 iface
, wine_dbgstr_rect(src_rect
), wine_dbgstr_rect(dst_rect
), dst_window_override
, dirty_region
);
618 wined3d_mutex_lock();
619 hr
= wined3d_device_present(device
->wined3d_device
, src_rect
, dst_rect
,
620 dst_window_override
, dirty_region
, 0);
621 wined3d_mutex_unlock();
626 static HRESULT WINAPI
d3d8_device_GetBackBuffer(IDirect3DDevice8
*iface
,
627 UINT backbuffer_idx
, D3DBACKBUFFER_TYPE backbuffer_type
, IDirect3DSurface8
**backbuffer
)
629 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
630 struct wined3d_surface
*wined3d_surface
= NULL
;
631 struct d3d8_surface
*surface_impl
;
634 TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
635 iface
, backbuffer_idx
, backbuffer_type
, backbuffer
);
637 wined3d_mutex_lock();
638 hr
= wined3d_device_get_back_buffer(device
->wined3d_device
, 0, backbuffer_idx
,
639 (enum wined3d_backbuffer_type
)backbuffer_type
, &wined3d_surface
);
640 if (SUCCEEDED(hr
) && wined3d_surface
&& backbuffer
)
642 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
643 *backbuffer
= &surface_impl
->IDirect3DSurface8_iface
;
644 IDirect3DSurface8_AddRef(*backbuffer
);
645 wined3d_surface_decref(wined3d_surface
);
647 wined3d_mutex_unlock();
652 static HRESULT WINAPI
d3d8_device_GetRasterStatus(IDirect3DDevice8
*iface
, D3DRASTER_STATUS
*raster_status
)
654 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
657 TRACE("iface %p, raster_status %p.\n", iface
, raster_status
);
659 wined3d_mutex_lock();
660 hr
= wined3d_device_get_raster_status(device
->wined3d_device
, 0, (struct wined3d_raster_status
*)raster_status
);
661 wined3d_mutex_unlock();
666 static void WINAPI
d3d8_device_SetGammaRamp(IDirect3DDevice8
*iface
, DWORD flags
, const D3DGAMMARAMP
*ramp
)
668 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
670 TRACE("iface %p, flags %#x, ramp %p.\n", iface
, flags
, ramp
);
672 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
673 wined3d_mutex_lock();
674 wined3d_device_set_gamma_ramp(device
->wined3d_device
, 0, flags
, (const struct wined3d_gamma_ramp
*)ramp
);
675 wined3d_mutex_unlock();
678 static void WINAPI
d3d8_device_GetGammaRamp(IDirect3DDevice8
*iface
, D3DGAMMARAMP
*ramp
)
680 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
682 TRACE("iface %p, ramp %p.\n", iface
, ramp
);
684 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
685 wined3d_mutex_lock();
686 wined3d_device_get_gamma_ramp(device
->wined3d_device
, 0, (struct wined3d_gamma_ramp
*)ramp
);
687 wined3d_mutex_unlock();
690 static HRESULT WINAPI
d3d8_device_CreateTexture(IDirect3DDevice8
*iface
,
691 UINT width
, UINT height
, UINT levels
, DWORD usage
, D3DFORMAT format
,
692 D3DPOOL pool
, IDirect3DTexture8
**texture
)
694 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
695 struct d3d8_texture
*object
;
698 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
699 iface
, width
, height
, levels
, usage
, format
, pool
, texture
);
701 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
704 ERR("Failed to allocate texture memory.\n");
705 return D3DERR_OUTOFVIDEOMEMORY
;
708 hr
= texture_init(object
, device
, width
, height
, levels
, usage
, format
, pool
);
711 WARN("Failed to initialize texture, hr %#x.\n", hr
);
712 HeapFree(GetProcessHeap(), 0, object
);
716 TRACE("Created texture %p.\n", object
);
717 *texture
= (IDirect3DTexture8
*)&object
->IDirect3DBaseTexture8_iface
;
722 static HRESULT WINAPI
d3d8_device_CreateVolumeTexture(IDirect3DDevice8
*iface
,
723 UINT width
, UINT height
, UINT depth
, UINT levels
, DWORD usage
, D3DFORMAT format
,
724 D3DPOOL pool
, IDirect3DVolumeTexture8
**texture
)
726 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
727 struct d3d8_texture
*object
;
730 TRACE("iface %p, width %u, height %u, depth %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
731 iface
, width
, height
, depth
, levels
, usage
, format
, pool
, texture
);
733 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
736 ERR("Failed to allocate volume texture memory.\n");
737 return D3DERR_OUTOFVIDEOMEMORY
;
740 hr
= volumetexture_init(object
, device
, width
, height
, depth
, levels
, usage
, format
, pool
);
743 WARN("Failed to initialize volume texture, hr %#x.\n", hr
);
744 HeapFree(GetProcessHeap(), 0, object
);
748 TRACE("Created volume texture %p.\n", object
);
749 *texture
= (IDirect3DVolumeTexture8
*)&object
->IDirect3DBaseTexture8_iface
;
754 static HRESULT WINAPI
d3d8_device_CreateCubeTexture(IDirect3DDevice8
*iface
, UINT edge_length
,
755 UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DCubeTexture8
**texture
)
757 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
758 struct d3d8_texture
*object
;
761 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
762 iface
, edge_length
, levels
, usage
, format
, pool
, texture
);
764 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
767 ERR("Failed to allocate cube texture memory.\n");
768 return D3DERR_OUTOFVIDEOMEMORY
;
771 hr
= cubetexture_init(object
, device
, edge_length
, levels
, usage
, format
, pool
);
774 WARN("Failed to initialize cube texture, hr %#x.\n", hr
);
775 HeapFree(GetProcessHeap(), 0, object
);
779 TRACE("Created cube texture %p.\n", object
);
780 *texture
= (IDirect3DCubeTexture8
*)&object
->IDirect3DBaseTexture8_iface
;
785 static HRESULT WINAPI
d3d8_device_CreateVertexBuffer(IDirect3DDevice8
*iface
, UINT size
,
786 DWORD usage
, DWORD fvf
, D3DPOOL pool
, IDirect3DVertexBuffer8
**buffer
)
788 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
789 struct d3d8_vertexbuffer
*object
;
792 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p.\n",
793 iface
, size
, usage
, fvf
, pool
, buffer
);
795 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
798 ERR("Failed to allocate buffer memory.\n");
799 return D3DERR_OUTOFVIDEOMEMORY
;
802 hr
= vertexbuffer_init(object
, device
, size
, usage
, fvf
, pool
);
805 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr
);
806 HeapFree(GetProcessHeap(), 0, object
);
810 TRACE("Created vertex buffer %p.\n", object
);
811 *buffer
= &object
->IDirect3DVertexBuffer8_iface
;
816 static HRESULT WINAPI
d3d8_device_CreateIndexBuffer(IDirect3DDevice8
*iface
, UINT size
,
817 DWORD usage
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DIndexBuffer8
**buffer
)
819 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
820 struct d3d8_indexbuffer
*object
;
823 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p.\n",
824 iface
, size
, usage
, format
, pool
, buffer
);
826 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
829 ERR("Failed to allocate buffer memory.\n");
830 return D3DERR_OUTOFVIDEOMEMORY
;
833 hr
= indexbuffer_init(object
, device
, size
, usage
, format
, pool
);
836 WARN("Failed to initialize index buffer, hr %#x.\n", hr
);
837 HeapFree(GetProcessHeap(), 0, object
);
841 TRACE("Created index buffer %p.\n", object
);
842 *buffer
= &object
->IDirect3DIndexBuffer8_iface
;
847 static HRESULT
d3d8_device_CreateSurface(struct d3d8_device
*device
, UINT width
,
848 UINT height
, D3DFORMAT format
, BOOL lockable
, BOOL discard
, UINT level
,
849 IDirect3DSurface8
**surface
, UINT usage
, D3DPOOL pool
, D3DMULTISAMPLE_TYPE multisample_type
,
850 DWORD multisample_quality
)
852 struct d3d8_surface
*object
;
855 TRACE("device %p, width %u, height %u, format %#x, lockable %#x, discard %#x, level %u, surface %p,\n"
856 "\tusage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
857 device
, width
, height
, format
, lockable
, discard
, level
, surface
,
858 usage
, pool
, multisample_type
, multisample_quality
);
860 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
862 FIXME("Failed to allocate surface memory.\n");
863 return D3DERR_OUTOFVIDEOMEMORY
;
866 hr
= surface_init(object
, device
, width
, height
, format
, lockable
, discard
, level
, usage
,
867 pool
, multisample_type
, multisample_quality
);
870 WARN("Failed to initialize surface, hr %#x.\n", hr
);
871 HeapFree(GetProcessHeap(), 0, object
);
875 TRACE("Created surface %p.\n", object
);
876 *surface
= &object
->IDirect3DSurface8_iface
;
881 static HRESULT WINAPI
d3d8_device_CreateRenderTarget(IDirect3DDevice8
*iface
, UINT width
,
882 UINT height
, D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, BOOL lockable
,
883 IDirect3DSurface8
**surface
)
885 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
888 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, lockable %#x, surface %p.\n",
889 iface
, width
, height
, format
, multisample_type
, lockable
, surface
);
891 hr
= d3d8_device_CreateSurface(device
, width
, height
, format
, lockable
,
892 FALSE
, 0, surface
, D3DUSAGE_RENDERTARGET
, D3DPOOL_DEFAULT
,
893 multisample_type
, 0);
898 static HRESULT WINAPI
d3d8_device_CreateDepthStencilSurface(IDirect3DDevice8
*iface
,
899 UINT width
, UINT height
, D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
,
900 IDirect3DSurface8
**surface
)
902 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
905 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, surface %p.\n",
906 iface
, width
, height
, format
, multisample_type
, surface
);
908 /* TODO: Verify that Discard is false */
909 hr
= d3d8_device_CreateSurface(device
, width
, height
, format
, TRUE
, FALSE
,
910 0, surface
, D3DUSAGE_DEPTHSTENCIL
, D3DPOOL_DEFAULT
, multisample_type
, 0);
915 /* IDirect3DDevice8Impl::CreateImageSurface returns surface with pool type SYSTEMMEM */
916 static HRESULT WINAPI
d3d8_device_CreateImageSurface(IDirect3DDevice8
*iface
, UINT width
,
917 UINT height
, D3DFORMAT format
, IDirect3DSurface8
**surface
)
919 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
922 TRACE("iface %p, width %u, height %u, format %#x, surface %p.\n",
923 iface
, width
, height
, format
, surface
);
925 hr
= d3d8_device_CreateSurface(device
, width
, height
, format
, TRUE
, FALSE
,
926 0, surface
, 0, D3DPOOL_SYSTEMMEM
, D3DMULTISAMPLE_NONE
, 0);
931 static HRESULT WINAPI
d3d8_device_CopyRects(IDirect3DDevice8
*iface
,
932 IDirect3DSurface8
*src_surface
, const RECT
*src_rects
, UINT rect_count
,
933 IDirect3DSurface8
*dst_surface
, const POINT
*dst_points
)
935 struct d3d8_surface
*src
= unsafe_impl_from_IDirect3DSurface8(src_surface
);
936 struct d3d8_surface
*dst
= unsafe_impl_from_IDirect3DSurface8(dst_surface
);
937 enum wined3d_format_id src_format
, dst_format
;
938 struct wined3d_resource_desc wined3d_desc
;
939 struct wined3d_resource
*wined3d_resource
;
943 TRACE("iface %p, src_surface %p, src_rects %p, rect_count %u, dst_surface %p, dst_points %p.\n",
944 iface
, src_surface
, src_rects
, rect_count
, dst_surface
, dst_points
);
946 /* Check that the source texture is in WINED3D_POOL_SYSTEM_MEM and the
947 * destination texture is in WINED3D_POOL_DEFAULT. */
949 wined3d_mutex_lock();
950 wined3d_resource
= wined3d_surface_get_resource(src
->wined3d_surface
);
951 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
952 if (wined3d_desc
.usage
& WINED3DUSAGE_DEPTHSTENCIL
)
954 WARN("Source %p is a depth stencil surface, returning D3DERR_INVALIDCALL.\n", src_surface
);
955 wined3d_mutex_unlock();
956 return D3DERR_INVALIDCALL
;
958 src_format
= wined3d_desc
.format
;
959 src_w
= wined3d_desc
.width
;
960 src_h
= wined3d_desc
.height
;
962 wined3d_resource
= wined3d_surface_get_resource(dst
->wined3d_surface
);
963 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
964 if (wined3d_desc
.usage
& WINED3DUSAGE_DEPTHSTENCIL
)
966 WARN("Destination %p is a depth stencil surface, returning D3DERR_INVALIDCALL.\n", dst_surface
);
967 wined3d_mutex_unlock();
968 return D3DERR_INVALIDCALL
;
970 dst_format
= wined3d_desc
.format
;
972 /* Check that the source and destination formats match */
973 if (src_format
!= dst_format
&& WINED3DFMT_UNKNOWN
!= dst_format
)
975 WARN("Source %p format must match the destination %p format, returning D3DERR_INVALIDCALL.\n",
976 src_surface
, dst_surface
);
977 wined3d_mutex_unlock();
978 return D3DERR_INVALIDCALL
;
980 else if (WINED3DFMT_UNKNOWN
== dst_format
)
982 TRACE("Converting destination surface from WINED3DFMT_UNKNOWN to the source format.\n");
983 if (FAILED(hr
= wined3d_surface_update_desc(dst
->wined3d_surface
, wined3d_desc
.width
, wined3d_desc
.height
,
984 src_format
, wined3d_desc
.multisample_type
, wined3d_desc
.multisample_quality
)))
986 WARN("Failed to update surface desc, hr %#x.\n", hr
);
987 wined3d_mutex_unlock();
992 /* Quick if complete copy ... */
993 if (!rect_count
&& !src_rects
&& !dst_points
)
995 RECT rect
= {0, 0, src_w
, src_h
};
996 wined3d_surface_blt(dst
->wined3d_surface
, &rect
,
997 src
->wined3d_surface
, &rect
, 0, NULL
, WINED3D_TEXF_POINT
);
1002 /* Copy rect by rect */
1003 if (src_rects
&& dst_points
)
1005 for (i
= 0; i
< rect_count
; ++i
)
1007 UINT w
= src_rects
[i
].right
- src_rects
[i
].left
;
1008 UINT h
= src_rects
[i
].bottom
- src_rects
[i
].top
;
1009 RECT dst_rect
= {dst_points
[i
].x
, dst_points
[i
].y
,
1010 dst_points
[i
].x
+ w
, dst_points
[i
].y
+ h
};
1012 wined3d_surface_blt(dst
->wined3d_surface
, &dst_rect
,
1013 src
->wined3d_surface
, &src_rects
[i
], 0, NULL
, WINED3D_TEXF_POINT
);
1018 for (i
= 0; i
< rect_count
; ++i
)
1020 UINT w
= src_rects
[i
].right
- src_rects
[i
].left
;
1021 UINT h
= src_rects
[i
].bottom
- src_rects
[i
].top
;
1022 RECT dst_rect
= {0, 0, w
, h
};
1024 wined3d_surface_blt(dst
->wined3d_surface
, &dst_rect
,
1025 src
->wined3d_surface
, &src_rects
[i
], 0, NULL
, WINED3D_TEXF_POINT
);
1029 wined3d_mutex_unlock();
1034 static HRESULT WINAPI
d3d8_device_UpdateTexture(IDirect3DDevice8
*iface
,
1035 IDirect3DBaseTexture8
*src_texture
, IDirect3DBaseTexture8
*dst_texture
)
1037 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1038 struct d3d8_texture
*src_impl
, *dst_impl
;
1041 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface
, src_texture
, dst_texture
);
1043 src_impl
= unsafe_impl_from_IDirect3DBaseTexture8(src_texture
);
1044 dst_impl
= unsafe_impl_from_IDirect3DBaseTexture8(dst_texture
);
1046 wined3d_mutex_lock();
1047 hr
= wined3d_device_update_texture(device
->wined3d_device
,
1048 src_impl
->wined3d_texture
, dst_impl
->wined3d_texture
);
1049 wined3d_mutex_unlock();
1054 static HRESULT WINAPI
d3d8_device_GetFrontBuffer(IDirect3DDevice8
*iface
, IDirect3DSurface8
*dst_surface
)
1056 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1057 struct d3d8_surface
*dst_impl
= unsafe_impl_from_IDirect3DSurface8(dst_surface
);
1060 TRACE("iface %p, dst_surface %p.\n", iface
, dst_surface
);
1064 WARN("Invalid destination surface passed.\n");
1065 return D3DERR_INVALIDCALL
;
1068 wined3d_mutex_lock();
1069 hr
= wined3d_device_get_front_buffer_data(device
->wined3d_device
, 0, dst_impl
->wined3d_surface
);
1070 wined3d_mutex_unlock();
1075 static HRESULT WINAPI
d3d8_device_SetRenderTarget(IDirect3DDevice8
*iface
,
1076 IDirect3DSurface8
*render_target
, IDirect3DSurface8
*depth_stencil
)
1078 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1079 struct d3d8_surface
*rt_impl
= unsafe_impl_from_IDirect3DSurface8(render_target
);
1080 struct d3d8_surface
*ds_impl
= unsafe_impl_from_IDirect3DSurface8(depth_stencil
);
1081 struct wined3d_surface
*original_ds
= NULL
;
1084 TRACE("iface %p, render_target %p, depth_stencil %p.\n", iface
, render_target
, depth_stencil
);
1086 wined3d_mutex_lock();
1090 struct wined3d_resource_desc ds_desc
, rt_desc
;
1091 struct wined3d_resource
*wined3d_resource
;
1092 struct wined3d_surface
*original_rt
= NULL
;
1094 /* If no render target is passed in check the size against the current RT */
1097 hr
= wined3d_device_get_render_target(device
->wined3d_device
, 0, &original_rt
);
1098 if (FAILED(hr
) || !original_rt
)
1100 wined3d_mutex_unlock();
1103 wined3d_resource
= wined3d_surface_get_resource(original_rt
);
1104 wined3d_surface_decref(original_rt
);
1107 wined3d_resource
= wined3d_surface_get_resource(rt_impl
->wined3d_surface
);
1108 wined3d_resource_get_desc(wined3d_resource
, &rt_desc
);
1110 wined3d_resource
= wined3d_surface_get_resource(ds_impl
->wined3d_surface
);
1111 wined3d_resource_get_desc(wined3d_resource
, &ds_desc
);
1113 if (ds_desc
.width
< rt_desc
.width
|| ds_desc
.height
< rt_desc
.height
)
1115 WARN("Depth stencil is smaller than the render target, returning D3DERR_INVALIDCALL\n");
1116 wined3d_mutex_unlock();
1117 return D3DERR_INVALIDCALL
;
1121 hr
= wined3d_device_get_depth_stencil(device
->wined3d_device
, &original_ds
);
1122 if (hr
== WINED3D_OK
|| hr
== WINED3DERR_NOTFOUND
)
1124 hr
= wined3d_device_set_depth_stencil(device
->wined3d_device
, ds_impl
? ds_impl
->wined3d_surface
: NULL
);
1125 if (SUCCEEDED(hr
) && render_target
)
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
);
1133 wined3d_surface_decref(original_ds
);
1135 wined3d_mutex_unlock();
1140 static HRESULT WINAPI
d3d8_device_GetRenderTarget(IDirect3DDevice8
*iface
, IDirect3DSurface8
**render_target
)
1142 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1143 struct wined3d_surface
*wined3d_surface
;
1144 struct d3d8_surface
*surface_impl
;
1147 TRACE("iface %p, render_target %p.\n", iface
, render_target
);
1150 return D3DERR_INVALIDCALL
;
1152 wined3d_mutex_lock();
1153 hr
= wined3d_device_get_render_target(device
->wined3d_device
, 0, &wined3d_surface
);
1154 if (SUCCEEDED(hr
) && wined3d_surface
)
1156 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
1157 *render_target
= &surface_impl
->IDirect3DSurface8_iface
;
1158 IDirect3DSurface8_AddRef(*render_target
);
1159 wined3d_surface_decref(wined3d_surface
);
1163 ERR("Failed to get wined3d render target, hr %#x.\n", hr
);
1164 *render_target
= NULL
;
1166 wined3d_mutex_unlock();
1171 static HRESULT WINAPI
d3d8_device_GetDepthStencilSurface(IDirect3DDevice8
*iface
, IDirect3DSurface8
**depth_stencil
)
1173 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1174 struct wined3d_surface
*wined3d_surface
;
1175 struct d3d8_surface
*surface_impl
;
1178 TRACE("iface %p, depth_stencil %p.\n", iface
, depth_stencil
);
1181 return D3DERR_INVALIDCALL
;
1183 wined3d_mutex_lock();
1184 hr
= wined3d_device_get_depth_stencil(device
->wined3d_device
, &wined3d_surface
);
1187 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
1188 *depth_stencil
= &surface_impl
->IDirect3DSurface8_iface
;
1189 IDirect3DSurface8_AddRef(*depth_stencil
);
1190 wined3d_surface_decref(wined3d_surface
);
1194 if (hr
!= WINED3DERR_NOTFOUND
)
1195 ERR("Failed to get wined3d depth stencil, hr %#x.\n", hr
);
1196 *depth_stencil
= NULL
;
1198 wined3d_mutex_unlock();
1203 static HRESULT WINAPI
d3d8_device_BeginScene(IDirect3DDevice8
*iface
)
1205 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1208 TRACE("iface %p.\n", iface
);
1210 wined3d_mutex_lock();
1211 hr
= wined3d_device_begin_scene(device
->wined3d_device
);
1212 wined3d_mutex_unlock();
1217 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d8_device_EndScene(IDirect3DDevice8
*iface
)
1219 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1222 TRACE("iface %p.\n", iface
);
1224 wined3d_mutex_lock();
1225 hr
= wined3d_device_end_scene(device
->wined3d_device
);
1226 wined3d_mutex_unlock();
1231 static HRESULT WINAPI
d3d8_device_Clear(IDirect3DDevice8
*iface
, DWORD rect_count
,
1232 const D3DRECT
*rects
, DWORD flags
, D3DCOLOR color
, float z
, DWORD stencil
)
1234 const struct wined3d_color c
=
1236 ((color
>> 16) & 0xff) / 255.0f
,
1237 ((color
>> 8) & 0xff) / 255.0f
,
1238 (color
& 0xff) / 255.0f
,
1239 ((color
>> 24) & 0xff) / 255.0f
,
1241 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1244 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1245 iface
, rect_count
, rects
, flags
, color
, z
, stencil
);
1247 wined3d_mutex_lock();
1248 hr
= wined3d_device_clear(device
->wined3d_device
, rect_count
, (const RECT
*)rects
, flags
, &c
, z
, stencil
);
1249 wined3d_mutex_unlock();
1254 static HRESULT WINAPI
d3d8_device_SetTransform(IDirect3DDevice8
*iface
,
1255 D3DTRANSFORMSTATETYPE state
, const D3DMATRIX
*matrix
)
1257 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1260 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1262 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1263 wined3d_mutex_lock();
1264 hr
= wined3d_device_set_transform(device
->wined3d_device
, state
, (const struct wined3d_matrix
*)matrix
);
1265 wined3d_mutex_unlock();
1270 static HRESULT WINAPI
d3d8_device_GetTransform(IDirect3DDevice8
*iface
,
1271 D3DTRANSFORMSTATETYPE state
, D3DMATRIX
*matrix
)
1273 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1276 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1278 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1279 wined3d_mutex_lock();
1280 hr
= wined3d_device_get_transform(device
->wined3d_device
, state
, (struct wined3d_matrix
*)matrix
);
1281 wined3d_mutex_unlock();
1286 static HRESULT WINAPI
d3d8_device_MultiplyTransform(IDirect3DDevice8
*iface
,
1287 D3DTRANSFORMSTATETYPE state
, const D3DMATRIX
*matrix
)
1289 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1292 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1294 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1295 wined3d_mutex_lock();
1296 hr
= wined3d_device_multiply_transform(device
->wined3d_device
, state
, (const struct wined3d_matrix
*)matrix
);
1297 wined3d_mutex_unlock();
1302 static HRESULT WINAPI
d3d8_device_SetViewport(IDirect3DDevice8
*iface
, const D3DVIEWPORT8
*viewport
)
1304 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1307 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
1309 /* Note: D3DVIEWPORT8 is compatible with struct wined3d_viewport. */
1310 wined3d_mutex_lock();
1311 hr
= wined3d_device_set_viewport(device
->wined3d_device
, (const struct wined3d_viewport
*)viewport
);
1312 wined3d_mutex_unlock();
1317 static HRESULT WINAPI
d3d8_device_GetViewport(IDirect3DDevice8
*iface
, D3DVIEWPORT8
*viewport
)
1319 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1322 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
1324 /* Note: D3DVIEWPORT8 is compatible with struct wined3d_viewport. */
1325 wined3d_mutex_lock();
1326 hr
= wined3d_device_get_viewport(device
->wined3d_device
, (struct wined3d_viewport
*)viewport
);
1327 wined3d_mutex_unlock();
1332 static HRESULT WINAPI
d3d8_device_SetMaterial(IDirect3DDevice8
*iface
, const D3DMATERIAL8
*material
)
1334 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1337 TRACE("iface %p, material %p.\n", iface
, material
);
1339 /* Note: D3DMATERIAL8 is compatible with struct wined3d_material. */
1340 wined3d_mutex_lock();
1341 hr
= wined3d_device_set_material(device
->wined3d_device
, (const struct wined3d_material
*)material
);
1342 wined3d_mutex_unlock();
1347 static HRESULT WINAPI
d3d8_device_GetMaterial(IDirect3DDevice8
*iface
, D3DMATERIAL8
*material
)
1349 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1352 TRACE("iface %p, material %p.\n", iface
, material
);
1354 /* Note: D3DMATERIAL8 is compatible with struct wined3d_material. */
1355 wined3d_mutex_lock();
1356 hr
= wined3d_device_get_material(device
->wined3d_device
, (struct wined3d_material
*)material
);
1357 wined3d_mutex_unlock();
1362 static HRESULT WINAPI
d3d8_device_SetLight(IDirect3DDevice8
*iface
, DWORD index
, const D3DLIGHT8
*light
)
1364 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1367 TRACE("iface %p, index %u, light %p.\n", iface
, index
, light
);
1369 /* Note: D3DLIGHT8 is compatible with struct wined3d_light. */
1370 wined3d_mutex_lock();
1371 hr
= wined3d_device_set_light(device
->wined3d_device
, index
, (const struct wined3d_light
*)light
);
1372 wined3d_mutex_unlock();
1377 static HRESULT WINAPI
d3d8_device_GetLight(IDirect3DDevice8
*iface
, DWORD index
, D3DLIGHT8
*light
)
1379 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1382 TRACE("iface %p, index %u, light %p.\n", iface
, index
, light
);
1384 /* Note: D3DLIGHT8 is compatible with struct wined3d_light. */
1385 wined3d_mutex_lock();
1386 hr
= wined3d_device_get_light(device
->wined3d_device
, index
, (struct wined3d_light
*)light
);
1387 wined3d_mutex_unlock();
1392 static HRESULT WINAPI
d3d8_device_LightEnable(IDirect3DDevice8
*iface
, DWORD index
, BOOL enable
)
1394 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1397 TRACE("iface %p, index %u, enable %#x.\n", iface
, index
, enable
);
1399 wined3d_mutex_lock();
1400 hr
= wined3d_device_set_light_enable(device
->wined3d_device
, index
, enable
);
1401 wined3d_mutex_unlock();
1406 static HRESULT WINAPI
d3d8_device_GetLightEnable(IDirect3DDevice8
*iface
, DWORD index
, BOOL
*enable
)
1408 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1411 TRACE("iface %p, index %u, enable %p.\n", iface
, index
, enable
);
1413 wined3d_mutex_lock();
1414 hr
= wined3d_device_get_light_enable(device
->wined3d_device
, index
, enable
);
1415 wined3d_mutex_unlock();
1420 static HRESULT WINAPI
d3d8_device_SetClipPlane(IDirect3DDevice8
*iface
, DWORD index
, const float *plane
)
1422 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1425 TRACE("iface %p, index %u, plane %p.\n", iface
, index
, plane
);
1427 wined3d_mutex_lock();
1428 hr
= wined3d_device_set_clip_plane(device
->wined3d_device
, index
, (const struct wined3d_vec4
*)plane
);
1429 wined3d_mutex_unlock();
1434 static HRESULT WINAPI
d3d8_device_GetClipPlane(IDirect3DDevice8
*iface
, DWORD index
, float *plane
)
1436 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1439 TRACE("iface %p, index %u, plane %p.\n", iface
, index
, plane
);
1441 wined3d_mutex_lock();
1442 hr
= wined3d_device_get_clip_plane(device
->wined3d_device
, index
, (struct wined3d_vec4
*)plane
);
1443 wined3d_mutex_unlock();
1448 static HRESULT WINAPI
d3d8_device_SetRenderState(IDirect3DDevice8
*iface
,
1449 D3DRENDERSTATETYPE state
, DWORD value
)
1451 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1454 TRACE("iface %p, state %#x, value %#x.\n", iface
, state
, value
);
1456 wined3d_mutex_lock();
1460 hr
= wined3d_device_set_render_state(device
->wined3d_device
, WINED3D_RS_DEPTHBIAS
, value
);
1464 hr
= wined3d_device_set_render_state(device
->wined3d_device
, state
, value
);
1466 wined3d_mutex_unlock();
1471 static HRESULT WINAPI
d3d8_device_GetRenderState(IDirect3DDevice8
*iface
,
1472 D3DRENDERSTATETYPE state
, DWORD
*value
)
1474 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1477 TRACE("iface %p, state %#x, value %p.\n", iface
, state
, value
);
1479 wined3d_mutex_lock();
1483 hr
= wined3d_device_get_render_state(device
->wined3d_device
, WINED3D_RS_DEPTHBIAS
, value
);
1487 hr
= wined3d_device_get_render_state(device
->wined3d_device
, state
, value
);
1489 wined3d_mutex_unlock();
1494 static HRESULT WINAPI
d3d8_device_BeginStateBlock(IDirect3DDevice8
*iface
)
1496 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1499 TRACE("iface %p.\n", iface
);
1501 wined3d_mutex_lock();
1502 hr
= wined3d_device_begin_stateblock(device
->wined3d_device
);
1503 wined3d_mutex_unlock();
1508 static HRESULT WINAPI
d3d8_device_EndStateBlock(IDirect3DDevice8
*iface
, DWORD
*token
)
1510 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1511 struct wined3d_stateblock
*stateblock
;
1514 TRACE("iface %p, token %p.\n", iface
, token
);
1516 /* Tell wineD3D to endstateblock before anything else (in case we run out
1517 * of memory later and cause locking problems)
1519 wined3d_mutex_lock();
1520 hr
= wined3d_device_end_stateblock(device
->wined3d_device
, &stateblock
);
1523 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
1524 wined3d_mutex_unlock();
1528 *token
= d3d8_allocate_handle(&device
->handle_table
, stateblock
, D3D8_HANDLE_SB
);
1529 wined3d_mutex_unlock();
1531 if (*token
== D3D8_INVALID_HANDLE
)
1533 ERR("Failed to create a handle\n");
1534 wined3d_mutex_lock();
1535 wined3d_stateblock_decref(stateblock
);
1536 wined3d_mutex_unlock();
1541 TRACE("Returning %#x (%p).\n", *token
, stateblock
);
1546 static HRESULT WINAPI
d3d8_device_ApplyStateBlock(IDirect3DDevice8
*iface
, DWORD token
)
1548 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1549 struct wined3d_stateblock
*stateblock
;
1552 TRACE("iface %p, token %#x.\n", iface
, token
);
1557 wined3d_mutex_lock();
1558 stateblock
= d3d8_get_object(&device
->handle_table
, token
- 1, D3D8_HANDLE_SB
);
1561 WARN("Invalid handle (%#x) passed.\n", token
);
1562 wined3d_mutex_unlock();
1563 return D3DERR_INVALIDCALL
;
1565 hr
= wined3d_stateblock_apply(stateblock
);
1566 wined3d_mutex_unlock();
1571 static HRESULT WINAPI
d3d8_device_CaptureStateBlock(IDirect3DDevice8
*iface
, DWORD token
)
1573 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1574 struct wined3d_stateblock
*stateblock
;
1577 TRACE("iface %p, token %#x.\n", iface
, token
);
1579 wined3d_mutex_lock();
1580 stateblock
= d3d8_get_object(&device
->handle_table
, token
- 1, D3D8_HANDLE_SB
);
1583 WARN("Invalid handle (%#x) passed.\n", token
);
1584 wined3d_mutex_unlock();
1585 return D3DERR_INVALIDCALL
;
1587 hr
= wined3d_stateblock_capture(stateblock
);
1588 wined3d_mutex_unlock();
1593 static HRESULT WINAPI
d3d8_device_DeleteStateBlock(IDirect3DDevice8
*iface
, DWORD token
)
1595 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1596 struct wined3d_stateblock
*stateblock
;
1598 TRACE("iface %p, token %#x.\n", iface
, token
);
1600 wined3d_mutex_lock();
1601 stateblock
= d3d8_free_handle(&device
->handle_table
, token
- 1, D3D8_HANDLE_SB
);
1605 WARN("Invalid handle (%#x) passed.\n", token
);
1606 wined3d_mutex_unlock();
1607 return D3DERR_INVALIDCALL
;
1610 if (wined3d_stateblock_decref(stateblock
))
1612 ERR("Stateblock %p has references left, this shouldn't happen.\n", stateblock
);
1614 wined3d_mutex_unlock();
1619 static HRESULT WINAPI
d3d8_device_CreateStateBlock(IDirect3DDevice8
*iface
,
1620 D3DSTATEBLOCKTYPE type
, DWORD
*handle
)
1622 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1623 struct wined3d_stateblock
*stateblock
;
1626 TRACE("iface %p, type %#x, handle %p.\n", iface
, type
, handle
);
1628 if (type
!= D3DSBT_ALL
1629 && type
!= D3DSBT_PIXELSTATE
1630 && type
!= D3DSBT_VERTEXSTATE
)
1632 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1633 return D3DERR_INVALIDCALL
;
1636 wined3d_mutex_lock();
1637 hr
= wined3d_stateblock_create(device
->wined3d_device
, (enum wined3d_stateblock_type
)type
, &stateblock
);
1640 wined3d_mutex_unlock();
1641 ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr
);
1645 *handle
= d3d8_allocate_handle(&device
->handle_table
, stateblock
, D3D8_HANDLE_SB
);
1646 wined3d_mutex_unlock();
1648 if (*handle
== D3D8_INVALID_HANDLE
)
1650 ERR("Failed to allocate a handle.\n");
1651 wined3d_mutex_lock();
1652 wined3d_stateblock_decref(stateblock
);
1653 wined3d_mutex_unlock();
1658 TRACE("Returning %#x (%p).\n", *handle
, stateblock
);
1663 static HRESULT WINAPI
d3d8_device_SetClipStatus(IDirect3DDevice8
*iface
, const D3DCLIPSTATUS8
*clip_status
)
1665 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1668 TRACE("iface %p, clip_status %p.\n", iface
, clip_status
);
1669 /* FIXME: Verify that D3DCLIPSTATUS8 ~= struct wined3d_clip_status. */
1671 wined3d_mutex_lock();
1672 hr
= wined3d_device_set_clip_status(device
->wined3d_device
, (const struct wined3d_clip_status
*)clip_status
);
1673 wined3d_mutex_unlock();
1678 static HRESULT WINAPI
d3d8_device_GetClipStatus(IDirect3DDevice8
*iface
, D3DCLIPSTATUS8
*clip_status
)
1680 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1683 TRACE("iface %p, clip_status %p.\n", iface
, clip_status
);
1685 wined3d_mutex_lock();
1686 hr
= wined3d_device_get_clip_status(device
->wined3d_device
, (struct wined3d_clip_status
*)clip_status
);
1687 wined3d_mutex_unlock();
1692 static HRESULT WINAPI
d3d8_device_GetTexture(IDirect3DDevice8
*iface
, DWORD stage
, IDirect3DBaseTexture8
**texture
)
1694 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1695 struct wined3d_texture
*wined3d_texture
;
1696 struct d3d8_texture
*texture_impl
;
1699 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
1702 return D3DERR_INVALIDCALL
;
1704 wined3d_mutex_lock();
1705 hr
= wined3d_device_get_texture(device
->wined3d_device
, stage
, &wined3d_texture
);
1708 WARN("Failed to get texture for stage %u, hr %#x.\n", stage
, hr
);
1709 wined3d_mutex_unlock();
1714 if (wined3d_texture
)
1716 texture_impl
= wined3d_texture_get_parent(wined3d_texture
);
1717 *texture
= &texture_impl
->IDirect3DBaseTexture8_iface
;
1718 IDirect3DBaseTexture8_AddRef(*texture
);
1719 wined3d_texture_decref(wined3d_texture
);
1725 wined3d_mutex_unlock();
1730 static HRESULT WINAPI
d3d8_device_SetTexture(IDirect3DDevice8
*iface
, DWORD stage
, IDirect3DBaseTexture8
*texture
)
1732 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1733 struct d3d8_texture
*texture_impl
;
1736 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
1738 texture_impl
= unsafe_impl_from_IDirect3DBaseTexture8(texture
);
1740 wined3d_mutex_lock();
1741 hr
= wined3d_device_set_texture(device
->wined3d_device
, stage
,
1742 texture_impl
? texture_impl
->wined3d_texture
: NULL
);
1743 wined3d_mutex_unlock();
1748 static const struct tss_lookup
1751 enum wined3d_texture_stage_state state
;
1755 {FALSE
, WINED3D_TSS_INVALID
}, /* 0, unused */
1756 {FALSE
, WINED3D_TSS_COLOR_OP
}, /* 1, D3DTSS_COLOROP */
1757 {FALSE
, WINED3D_TSS_COLOR_ARG1
}, /* 2, D3DTSS_COLORARG1 */
1758 {FALSE
, WINED3D_TSS_COLOR_ARG2
}, /* 3, D3DTSS_COLORARG2 */
1759 {FALSE
, WINED3D_TSS_ALPHA_OP
}, /* 4, D3DTSS_ALPHAOP */
1760 {FALSE
, WINED3D_TSS_ALPHA_ARG1
}, /* 5, D3DTSS_ALPHAARG1 */
1761 {FALSE
, WINED3D_TSS_ALPHA_ARG2
}, /* 6, D3DTSS_ALPHAARG2 */
1762 {FALSE
, WINED3D_TSS_BUMPENV_MAT00
}, /* 7, D3DTSS_BUMPENVMAT00 */
1763 {FALSE
, WINED3D_TSS_BUMPENV_MAT01
}, /* 8, D3DTSS_BUMPENVMAT01 */
1764 {FALSE
, WINED3D_TSS_BUMPENV_MAT10
}, /* 9, D3DTSS_BUMPENVMAT10 */
1765 {FALSE
, WINED3D_TSS_BUMPENV_MAT11
}, /* 10, D3DTSS_BUMPENVMAT11 */
1766 {FALSE
, WINED3D_TSS_TEXCOORD_INDEX
}, /* 11, D3DTSS_TEXCOORDINDEX */
1767 {FALSE
, WINED3D_TSS_INVALID
}, /* 12, unused */
1768 {TRUE
, WINED3D_SAMP_ADDRESS_U
}, /* 13, D3DTSS_ADDRESSU */
1769 {TRUE
, WINED3D_SAMP_ADDRESS_V
}, /* 14, D3DTSS_ADDRESSV */
1770 {TRUE
, WINED3D_SAMP_BORDER_COLOR
}, /* 15, D3DTSS_BORDERCOLOR */
1771 {TRUE
, WINED3D_SAMP_MAG_FILTER
}, /* 16, D3DTSS_MAGFILTER */
1772 {TRUE
, WINED3D_SAMP_MIN_FILTER
}, /* 17, D3DTSS_MINFILTER */
1773 {TRUE
, WINED3D_SAMP_MIP_FILTER
}, /* 18, D3DTSS_MIPFILTER */
1774 {TRUE
, WINED3D_SAMP_MIPMAP_LOD_BIAS
}, /* 19, D3DTSS_MIPMAPLODBIAS */
1775 {TRUE
, WINED3D_SAMP_MAX_MIP_LEVEL
}, /* 20, D3DTSS_MAXMIPLEVEL */
1776 {TRUE
, WINED3D_SAMP_MAX_ANISOTROPY
}, /* 21, D3DTSS_MAXANISOTROPY */
1777 {FALSE
, WINED3D_TSS_BUMPENV_LSCALE
}, /* 22, D3DTSS_BUMPENVLSCALE */
1778 {FALSE
, WINED3D_TSS_BUMPENV_LOFFSET
}, /* 23, D3DTSS_BUMPENVLOFFSET */
1779 {FALSE
, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1780 {TRUE
, WINED3D_SAMP_ADDRESS_W
}, /* 25, D3DTSS_ADDRESSW */
1781 {FALSE
, WINED3D_TSS_COLOR_ARG0
}, /* 26, D3DTSS_COLORARG0 */
1782 {FALSE
, WINED3D_TSS_ALPHA_ARG0
}, /* 27, D3DTSS_ALPHAARG0 */
1783 {FALSE
, WINED3D_TSS_RESULT_ARG
}, /* 28, D3DTSS_RESULTARG */
1786 static HRESULT WINAPI
d3d8_device_GetTextureStageState(IDirect3DDevice8
*iface
,
1787 DWORD stage
, D3DTEXTURESTAGESTATETYPE Type
, DWORD
*value
)
1789 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1790 const struct tss_lookup
*l
;
1793 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface
, stage
, Type
, value
);
1795 if (Type
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
1797 WARN("Invalid Type %#x passed.\n", Type
);
1801 l
= &tss_lookup
[Type
];
1803 wined3d_mutex_lock();
1804 if (l
->sampler_state
)
1805 hr
= wined3d_device_get_sampler_state(device
->wined3d_device
, stage
, l
->state
, value
);
1807 hr
= wined3d_device_get_texture_stage_state(device
->wined3d_device
, stage
, l
->state
, value
);
1808 wined3d_mutex_unlock();
1813 static HRESULT WINAPI
d3d8_device_SetTextureStageState(IDirect3DDevice8
*iface
,
1814 DWORD stage
, D3DTEXTURESTAGESTATETYPE type
, DWORD value
)
1816 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1817 const struct tss_lookup
*l
;
1820 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface
, stage
, type
, value
);
1822 if (type
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
1824 WARN("Invalid type %#x passed.\n", type
);
1828 l
= &tss_lookup
[type
];
1830 wined3d_mutex_lock();
1831 if (l
->sampler_state
)
1832 hr
= wined3d_device_set_sampler_state(device
->wined3d_device
, stage
, l
->state
, value
);
1834 hr
= wined3d_device_set_texture_stage_state(device
->wined3d_device
, stage
, l
->state
, value
);
1835 wined3d_mutex_unlock();
1840 static HRESULT WINAPI
d3d8_device_ValidateDevice(IDirect3DDevice8
*iface
, DWORD
*pass_count
)
1842 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1845 TRACE("iface %p, pass_count %p.\n", iface
, pass_count
);
1847 wined3d_mutex_lock();
1848 hr
= wined3d_device_validate_device(device
->wined3d_device
, pass_count
);
1849 wined3d_mutex_unlock();
1854 static HRESULT WINAPI
d3d8_device_GetInfo(IDirect3DDevice8
*iface
,
1855 DWORD info_id
, void *info
, DWORD info_size
)
1857 FIXME("iface %p, info_id %#x, info %p, info_size %u stub!\n", iface
, info_id
, info
, info_size
);
1862 static HRESULT WINAPI
d3d8_device_SetPaletteEntries(IDirect3DDevice8
*iface
,
1863 UINT palette_idx
, const PALETTEENTRY
*entries
)
1865 FIXME("iface %p, palette_idx %u, entries %p unimplemented\n", iface
, palette_idx
, entries
);
1867 /* GPUs stopped supporting palettized textures with the Shader Model 1 generation. Wined3d
1868 * does not have a d3d8/9-style palette API */
1870 return D3DERR_INVALIDCALL
;
1873 static HRESULT WINAPI
d3d8_device_GetPaletteEntries(IDirect3DDevice8
*iface
,
1874 UINT palette_idx
, PALETTEENTRY
*entries
)
1876 FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface
, palette_idx
, entries
);
1878 return D3DERR_INVALIDCALL
;
1881 static HRESULT WINAPI
d3d8_device_SetCurrentTexturePalette(IDirect3DDevice8
*iface
, UINT palette_idx
)
1883 FIXME("iface %p, palette_idx %u unimplemented.\n", iface
, palette_idx
);
1885 return D3DERR_INVALIDCALL
;
1888 static HRESULT WINAPI
d3d8_device_GetCurrentTexturePalette(IDirect3DDevice8
*iface
, UINT
*palette_idx
)
1890 FIXME("iface %p, palette_idx %p unimplemented.\n", iface
, palette_idx
);
1892 return D3DERR_INVALIDCALL
;
1895 static HRESULT WINAPI
d3d8_device_DrawPrimitive(IDirect3DDevice8
*iface
,
1896 D3DPRIMITIVETYPE primitive_type
, UINT start_vertex
, UINT primitive_count
)
1898 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1901 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1902 iface
, primitive_type
, start_vertex
, primitive_count
);
1904 wined3d_mutex_lock();
1905 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
1906 hr
= wined3d_device_draw_primitive(device
->wined3d_device
, start_vertex
,
1907 vertex_count_from_primitive_count(primitive_type
, primitive_count
));
1908 wined3d_mutex_unlock();
1913 static HRESULT WINAPI
d3d8_device_DrawIndexedPrimitive(IDirect3DDevice8
*iface
,
1914 D3DPRIMITIVETYPE primitive_type
, UINT min_vertex_idx
, UINT vertex_count
,
1915 UINT start_idx
, UINT primitive_count
)
1917 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1920 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, start_idx %u, primitive_count %u.\n",
1921 iface
, primitive_type
, min_vertex_idx
, vertex_count
, start_idx
, primitive_count
);
1923 wined3d_mutex_lock();
1924 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
1925 hr
= wined3d_device_draw_indexed_primitive(device
->wined3d_device
, start_idx
,
1926 vertex_count_from_primitive_count(primitive_type
, primitive_count
));
1927 wined3d_mutex_unlock();
1932 static HRESULT WINAPI
d3d8_device_DrawPrimitiveUP(IDirect3DDevice8
*iface
,
1933 D3DPRIMITIVETYPE primitive_type
, UINT primitive_count
, const void *data
,
1936 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1939 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
1940 iface
, primitive_type
, primitive_count
, data
, stride
);
1942 wined3d_mutex_lock();
1943 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
1944 hr
= wined3d_device_draw_primitive_up(device
->wined3d_device
,
1945 vertex_count_from_primitive_count(primitive_type
, primitive_count
),
1947 wined3d_mutex_unlock();
1952 static HRESULT WINAPI
d3d8_device_DrawIndexedPrimitiveUP(IDirect3DDevice8
*iface
,
1953 D3DPRIMITIVETYPE primitive_type
, UINT min_vertex_idx
, UINT index_count
,
1954 UINT primitive_count
, const void *index_data
, D3DFORMAT index_format
,
1955 const void *vertex_data
, UINT vertex_stride
)
1957 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1960 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
1961 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
1962 iface
, primitive_type
, min_vertex_idx
, index_count
, primitive_count
,
1963 index_data
, index_format
, vertex_data
, vertex_stride
);
1965 wined3d_mutex_lock();
1966 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
1967 hr
= wined3d_device_draw_indexed_primitive_up(device
->wined3d_device
,
1968 vertex_count_from_primitive_count(primitive_type
, primitive_count
), index_data
,
1969 wined3dformat_from_d3dformat(index_format
), vertex_data
, vertex_stride
);
1970 wined3d_mutex_unlock();
1975 static HRESULT WINAPI
d3d8_device_ProcessVertices(IDirect3DDevice8
*iface
, UINT src_start_idx
,
1976 UINT dst_idx
, UINT vertex_count
, IDirect3DVertexBuffer8
*dst_buffer
, DWORD flags
)
1978 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1979 struct d3d8_vertexbuffer
*dst
= unsafe_impl_from_IDirect3DVertexBuffer8(dst_buffer
);
1982 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, flags %#x.\n",
1983 iface
, src_start_idx
, dst_idx
, vertex_count
, dst_buffer
, flags
);
1985 wined3d_mutex_lock();
1986 hr
= wined3d_device_process_vertices(device
->wined3d_device
, src_start_idx
, dst_idx
,
1987 vertex_count
, dst
->wined3d_buffer
, NULL
, flags
, dst
->fvf
);
1988 wined3d_mutex_unlock();
1993 static HRESULT WINAPI
d3d8_device_CreateVertexShader(IDirect3DDevice8
*iface
,
1994 const DWORD
*declaration
, const DWORD
*byte_code
, DWORD
*shader
, DWORD usage
)
1996 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1997 struct d3d8_vertex_shader
*object
;
1998 DWORD shader_handle
;
2002 TRACE("iface %p, declaration %p, byte_code %p, shader %p, usage %#x.\n",
2003 iface
, declaration
, byte_code
, shader
, usage
);
2005 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2008 ERR("Failed to allocate vertex shader memory.\n");
2010 return E_OUTOFMEMORY
;
2013 wined3d_mutex_lock();
2014 handle
= d3d8_allocate_handle(&device
->handle_table
, object
, D3D8_HANDLE_VS
);
2015 wined3d_mutex_unlock();
2016 if (handle
== D3D8_INVALID_HANDLE
)
2018 ERR("Failed to allocate vertex shader handle.\n");
2019 HeapFree(GetProcessHeap(), 0, object
);
2021 return E_OUTOFMEMORY
;
2024 shader_handle
= handle
+ VS_HIGHESTFIXEDFXF
+ 1;
2026 hr
= d3d8_vertex_shader_init(object
, device
, declaration
, byte_code
, shader_handle
, usage
);
2029 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
2030 wined3d_mutex_lock();
2031 d3d8_free_handle(&device
->handle_table
, handle
, D3D8_HANDLE_VS
);
2032 wined3d_mutex_unlock();
2033 HeapFree(GetProcessHeap(), 0, object
);
2038 TRACE("Created vertex shader %p (handle %#x).\n", object
, shader_handle
);
2039 *shader
= shader_handle
;
2044 static struct d3d8_vertex_declaration
*d3d8_device_get_fvf_declaration(struct d3d8_device
*device
, DWORD fvf
)
2046 struct d3d8_vertex_declaration
*d3d8_declaration
;
2047 struct FvfToDecl
*convertedDecls
= device
->decls
;
2048 int p
, low
, high
; /* deliberately signed */
2051 TRACE("Searching for declaration for fvf %08x... ", fvf
);
2054 high
= device
->numConvertedDecls
- 1;
2057 p
= (low
+ high
) >> 1;
2060 if (convertedDecls
[p
].fvf
== fvf
)
2062 TRACE("found %p\n", convertedDecls
[p
].declaration
);
2063 return convertedDecls
[p
].declaration
;
2066 if (convertedDecls
[p
].fvf
< fvf
)
2071 TRACE("not found. Creating and inserting at position %d.\n", low
);
2073 if (!(d3d8_declaration
= HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration
))))
2075 ERR("Memory allocation failed.\n");
2079 if (FAILED(hr
= d3d8_vertex_declaration_init_fvf(d3d8_declaration
, device
, fvf
)))
2081 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr
);
2082 HeapFree(GetProcessHeap(), 0, d3d8_declaration
);
2086 if (device
->declArraySize
== device
->numConvertedDecls
)
2088 UINT grow
= device
->declArraySize
/ 2;
2090 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
2091 sizeof(*convertedDecls
) * (device
->numConvertedDecls
+ grow
));
2092 if (!convertedDecls
)
2094 d3d8_vertex_declaration_destroy(d3d8_declaration
);
2097 device
->decls
= convertedDecls
;
2098 device
->declArraySize
+= grow
;
2101 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
,
2102 sizeof(*convertedDecls
) * (device
->numConvertedDecls
- low
));
2103 convertedDecls
[low
].declaration
= d3d8_declaration
;
2104 convertedDecls
[low
].fvf
= fvf
;
2105 ++device
->numConvertedDecls
;
2107 TRACE("Returning %p. %u decls in array.\n", d3d8_declaration
, device
->numConvertedDecls
);
2109 return d3d8_declaration
;
2112 static HRESULT WINAPI
d3d8_device_SetVertexShader(IDirect3DDevice8
*iface
, DWORD shader
)
2114 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2115 struct d3d8_vertex_shader
*shader_impl
;
2118 TRACE("iface %p, shader %#x.\n", iface
, shader
);
2120 if (VS_HIGHESTFIXEDFXF
>= shader
)
2122 TRACE("Setting FVF, %#x\n", shader
);
2124 wined3d_mutex_lock();
2125 wined3d_device_set_vertex_declaration(device
->wined3d_device
,
2126 d3d8_device_get_fvf_declaration(device
, shader
)->wined3d_vertex_declaration
);
2127 wined3d_device_set_vertex_shader(device
->wined3d_device
, NULL
);
2128 wined3d_mutex_unlock();
2133 TRACE("Setting shader\n");
2135 wined3d_mutex_lock();
2136 if (!(shader_impl
= d3d8_get_object(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
)))
2138 WARN("Invalid handle (%#x) passed.\n", shader
);
2139 wined3d_mutex_unlock();
2141 return D3DERR_INVALIDCALL
;
2144 hr
= wined3d_device_set_vertex_declaration(device
->wined3d_device
,
2145 shader_impl
->vertex_declaration
->wined3d_vertex_declaration
);
2147 hr
= wined3d_device_set_vertex_shader(device
->wined3d_device
, shader_impl
->wined3d_shader
);
2148 wined3d_mutex_unlock();
2150 TRACE("Returning hr %#x\n", hr
);
2155 static HRESULT WINAPI
d3d8_device_GetVertexShader(IDirect3DDevice8
*iface
, DWORD
*shader
)
2157 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2158 struct wined3d_vertex_declaration
*wined3d_declaration
;
2159 struct d3d8_vertex_declaration
*d3d8_declaration
;
2162 TRACE("iface %p, shader %p.\n", iface
, shader
);
2164 wined3d_mutex_lock();
2165 if (FAILED(hr
= wined3d_device_get_vertex_declaration(device
->wined3d_device
, &wined3d_declaration
)))
2167 wined3d_mutex_unlock();
2168 WARN("Failed to get wined3d vertex declaration, hr %#x.\n", hr
);
2172 if (!wined3d_declaration
)
2174 wined3d_mutex_unlock();
2179 d3d8_declaration
= wined3d_vertex_declaration_get_parent(wined3d_declaration
);
2180 wined3d_vertex_declaration_decref(wined3d_declaration
);
2181 wined3d_mutex_unlock();
2182 *shader
= d3d8_declaration
->shader_handle
;
2184 TRACE("Returning %#x.\n", *shader
);
2189 static HRESULT WINAPI
d3d8_device_DeleteVertexShader(IDirect3DDevice8
*iface
, DWORD shader
)
2191 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2192 struct d3d8_vertex_shader
*shader_impl
;
2193 struct wined3d_shader
*cur
;
2195 TRACE("iface %p, shader %#x.\n", iface
, shader
);
2197 wined3d_mutex_lock();
2198 if (!(shader_impl
= d3d8_free_handle(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
)))
2200 WARN("Invalid handle (%#x) passed.\n", shader
);
2201 wined3d_mutex_unlock();
2203 return D3DERR_INVALIDCALL
;
2206 if ((cur
= wined3d_device_get_vertex_shader(device
->wined3d_device
)))
2208 if (cur
== shader_impl
->wined3d_shader
)
2209 IDirect3DDevice8_SetVertexShader(iface
, 0);
2210 wined3d_shader_decref(cur
);
2213 wined3d_mutex_unlock();
2215 d3d8_vertex_shader_destroy(shader_impl
);
2220 static HRESULT WINAPI
d3d8_device_SetVertexShaderConstant(IDirect3DDevice8
*iface
,
2221 DWORD start_register
, const void *data
, DWORD count
)
2223 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2226 TRACE("iface %p, start_register %u, data %p, count %u.\n",
2227 iface
, start_register
, data
, count
);
2229 if (start_register
+ count
> D3D8_MAX_VERTEX_SHADER_CONSTANTF
)
2231 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2232 start_register
+ count
, D3D8_MAX_VERTEX_SHADER_CONSTANTF
);
2233 return D3DERR_INVALIDCALL
;
2236 wined3d_mutex_lock();
2237 hr
= wined3d_device_set_vs_consts_f(device
->wined3d_device
, start_register
, data
, count
);
2238 wined3d_mutex_unlock();
2243 static HRESULT WINAPI
d3d8_device_GetVertexShaderConstant(IDirect3DDevice8
*iface
,
2244 DWORD start_register
, void *data
, DWORD count
)
2246 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2249 TRACE("iface %p, start_register %u, data %p, count %u.\n",
2250 iface
, start_register
, data
, count
);
2252 if (start_register
+ count
> D3D8_MAX_VERTEX_SHADER_CONSTANTF
)
2254 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2255 start_register
+ count
, D3D8_MAX_VERTEX_SHADER_CONSTANTF
);
2256 return D3DERR_INVALIDCALL
;
2259 wined3d_mutex_lock();
2260 hr
= wined3d_device_get_vs_consts_f(device
->wined3d_device
, start_register
, data
, count
);
2261 wined3d_mutex_unlock();
2266 static HRESULT WINAPI
d3d8_device_GetVertexShaderDeclaration(IDirect3DDevice8
*iface
,
2267 DWORD shader
, void *data
, DWORD
*data_size
)
2269 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2270 struct d3d8_vertex_declaration
*declaration
;
2271 struct d3d8_vertex_shader
*shader_impl
;
2273 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2274 iface
, shader
, data
, data_size
);
2276 wined3d_mutex_lock();
2277 shader_impl
= d3d8_get_object(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
);
2278 wined3d_mutex_unlock();
2282 WARN("Invalid handle (%#x) passed.\n", shader
);
2283 return D3DERR_INVALIDCALL
;
2285 declaration
= shader_impl
->vertex_declaration
;
2289 *data_size
= declaration
->elements_size
;
2293 /* MSDN claims that if *data_size is smaller than the required size
2294 * we should write the required size and return D3DERR_MOREDATA.
2295 * That's not actually true. */
2296 if (*data_size
< declaration
->elements_size
)
2297 return D3DERR_INVALIDCALL
;
2299 memcpy(data
, declaration
->elements
, declaration
->elements_size
);
2304 static HRESULT WINAPI
d3d8_device_GetVertexShaderFunction(IDirect3DDevice8
*iface
,
2305 DWORD shader
, void *data
, DWORD
*data_size
)
2307 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2308 struct d3d8_vertex_shader
*shader_impl
= NULL
;
2311 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2312 iface
, shader
, data
, data_size
);
2314 wined3d_mutex_lock();
2315 if (!(shader_impl
= d3d8_get_object(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
)))
2317 WARN("Invalid handle (%#x) passed.\n", shader
);
2318 wined3d_mutex_unlock();
2320 return D3DERR_INVALIDCALL
;
2323 if (!shader_impl
->wined3d_shader
)
2325 wined3d_mutex_unlock();
2330 hr
= wined3d_shader_get_byte_code(shader_impl
->wined3d_shader
, data
, data_size
);
2331 wined3d_mutex_unlock();
2336 static HRESULT WINAPI
d3d8_device_SetIndices(IDirect3DDevice8
*iface
,
2337 IDirect3DIndexBuffer8
*buffer
, UINT base_vertex_idx
)
2339 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2340 struct d3d8_indexbuffer
*ib
= unsafe_impl_from_IDirect3DIndexBuffer8(buffer
);
2343 TRACE("iface %p, buffer %p, base_vertex_idx %u.\n", iface
, buffer
, base_vertex_idx
);
2345 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
2346 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
2347 * vertex buffers can't be created to address them with an index that requires the 32nd bit
2348 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
2351 wined3d_mutex_lock();
2352 wined3d_device_set_base_vertex_index(device
->wined3d_device
, base_vertex_idx
);
2353 hr
= wined3d_device_set_index_buffer(device
->wined3d_device
,
2354 ib
? ib
->wined3d_buffer
: NULL
,
2355 ib
? ib
->format
: WINED3DFMT_UNKNOWN
);
2356 wined3d_mutex_unlock();
2361 static HRESULT WINAPI
d3d8_device_GetIndices(IDirect3DDevice8
*iface
,
2362 IDirect3DIndexBuffer8
**buffer
, UINT
*base_vertex_index
)
2364 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2365 struct wined3d_buffer
*wined3d_buffer
= NULL
;
2366 struct d3d8_indexbuffer
*buffer_impl
;
2369 TRACE("iface %p, buffer %p, base_vertex_index %p.\n", iface
, buffer
, base_vertex_index
);
2372 return D3DERR_INVALIDCALL
;
2374 /* The case from UINT to INT is safe because d3d8 will never set negative values */
2375 wined3d_mutex_lock();
2376 *base_vertex_index
= wined3d_device_get_base_vertex_index(device
->wined3d_device
);
2377 hr
= wined3d_device_get_index_buffer(device
->wined3d_device
, &wined3d_buffer
);
2378 if (SUCCEEDED(hr
) && wined3d_buffer
)
2380 buffer_impl
= wined3d_buffer_get_parent(wined3d_buffer
);
2381 *buffer
= &buffer_impl
->IDirect3DIndexBuffer8_iface
;
2382 IDirect3DIndexBuffer8_AddRef(*buffer
);
2383 wined3d_buffer_decref(wined3d_buffer
);
2388 ERR("Failed to get wined3d index buffer, hr %#x.\n", hr
);
2391 wined3d_mutex_unlock();
2396 static HRESULT WINAPI
d3d8_device_CreatePixelShader(IDirect3DDevice8
*iface
,
2397 const DWORD
*byte_code
, DWORD
*shader
)
2399 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2400 struct d3d8_pixel_shader
*object
;
2401 DWORD shader_handle
;
2405 TRACE("iface %p, byte_code %p, shader %p.\n", iface
, byte_code
, shader
);
2408 return D3DERR_INVALIDCALL
;
2410 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2413 ERR("Failed to allocate pixel shader memmory.\n");
2414 return E_OUTOFMEMORY
;
2417 wined3d_mutex_lock();
2418 handle
= d3d8_allocate_handle(&device
->handle_table
, object
, D3D8_HANDLE_PS
);
2419 wined3d_mutex_unlock();
2420 if (handle
== D3D8_INVALID_HANDLE
)
2422 ERR("Failed to allocate pixel shader handle.\n");
2423 HeapFree(GetProcessHeap(), 0, object
);
2424 return E_OUTOFMEMORY
;
2427 shader_handle
= handle
+ VS_HIGHESTFIXEDFXF
+ 1;
2429 hr
= d3d8_pixel_shader_init(object
, device
, byte_code
, shader_handle
);
2432 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
2433 wined3d_mutex_lock();
2434 d3d8_free_handle(&device
->handle_table
, handle
, D3D8_HANDLE_PS
);
2435 wined3d_mutex_unlock();
2436 HeapFree(GetProcessHeap(), 0, object
);
2441 TRACE("Created pixel shader %p (handle %#x).\n", object
, shader_handle
);
2442 *shader
= shader_handle
;
2447 static HRESULT WINAPI
d3d8_device_SetPixelShader(IDirect3DDevice8
*iface
, DWORD shader
)
2449 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2450 struct d3d8_pixel_shader
*shader_impl
;
2453 TRACE("iface %p, shader %#x.\n", iface
, shader
);
2455 wined3d_mutex_lock();
2459 hr
= wined3d_device_set_pixel_shader(device
->wined3d_device
, NULL
);
2460 wined3d_mutex_unlock();
2464 if (!(shader_impl
= d3d8_get_object(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
)))
2466 WARN("Invalid handle (%#x) passed.\n", shader
);
2467 wined3d_mutex_unlock();
2468 return D3DERR_INVALIDCALL
;
2471 TRACE("Setting shader %p.\n", shader_impl
);
2472 hr
= wined3d_device_set_pixel_shader(device
->wined3d_device
, shader_impl
->wined3d_shader
);
2473 wined3d_mutex_unlock();
2478 static HRESULT WINAPI
d3d8_device_GetPixelShader(IDirect3DDevice8
*iface
, DWORD
*shader
)
2480 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2481 struct wined3d_shader
*object
;
2483 TRACE("iface %p, shader %p.\n", iface
, shader
);
2486 return D3DERR_INVALIDCALL
;
2488 wined3d_mutex_lock();
2489 if ((object
= wined3d_device_get_pixel_shader(device
->wined3d_device
)))
2491 struct d3d8_pixel_shader
*d3d8_shader
;
2492 d3d8_shader
= wined3d_shader_get_parent(object
);
2493 wined3d_shader_decref(object
);
2494 *shader
= d3d8_shader
->handle
;
2500 wined3d_mutex_unlock();
2502 TRACE("Returning %#x.\n", *shader
);
2507 static HRESULT WINAPI
d3d8_device_DeletePixelShader(IDirect3DDevice8
*iface
, DWORD shader
)
2509 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2510 struct d3d8_pixel_shader
*shader_impl
;
2511 struct wined3d_shader
*cur
;
2513 TRACE("iface %p, shader %#x.\n", iface
, shader
);
2515 wined3d_mutex_lock();
2517 if (!(shader_impl
= d3d8_free_handle(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
)))
2519 WARN("Invalid handle (%#x) passed.\n", shader
);
2520 wined3d_mutex_unlock();
2521 return D3DERR_INVALIDCALL
;
2524 if ((cur
= wined3d_device_get_pixel_shader(device
->wined3d_device
)))
2526 if (cur
== shader_impl
->wined3d_shader
)
2527 IDirect3DDevice8_SetPixelShader(iface
, 0);
2528 wined3d_shader_decref(cur
);
2531 wined3d_mutex_unlock();
2533 d3d8_pixel_shader_destroy(shader_impl
);
2538 static HRESULT WINAPI
d3d8_device_SetPixelShaderConstant(IDirect3DDevice8
*iface
,
2539 DWORD start_register
, const void *data
, DWORD count
)
2541 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2544 TRACE("iface %p, start_register %u, data %p, count %u.\n",
2545 iface
, start_register
, data
, count
);
2547 wined3d_mutex_lock();
2548 hr
= wined3d_device_set_ps_consts_f(device
->wined3d_device
, start_register
, data
, count
);
2549 wined3d_mutex_unlock();
2554 static HRESULT WINAPI
d3d8_device_GetPixelShaderConstant(IDirect3DDevice8
*iface
,
2555 DWORD start_register
, void *data
, DWORD count
)
2557 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2560 TRACE("iface %p, start_register %u, data %p, count %u.\n",
2561 iface
, start_register
, data
, count
);
2563 wined3d_mutex_lock();
2564 hr
= wined3d_device_get_ps_consts_f(device
->wined3d_device
, start_register
, data
, count
);
2565 wined3d_mutex_unlock();
2570 static HRESULT WINAPI
d3d8_device_GetPixelShaderFunction(IDirect3DDevice8
*iface
,
2571 DWORD shader
, void *data
, DWORD
*data_size
)
2573 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2574 struct d3d8_pixel_shader
*shader_impl
= NULL
;
2577 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2578 iface
, shader
, data
, data_size
);
2580 wined3d_mutex_lock();
2581 if (!(shader_impl
= d3d8_get_object(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
)))
2583 WARN("Invalid handle (%#x) passed.\n", shader
);
2584 wined3d_mutex_unlock();
2586 return D3DERR_INVALIDCALL
;
2589 hr
= wined3d_shader_get_byte_code(shader_impl
->wined3d_shader
, data
, data_size
);
2590 wined3d_mutex_unlock();
2595 static HRESULT WINAPI
d3d8_device_DrawRectPatch(IDirect3DDevice8
*iface
, UINT handle
,
2596 const float *segment_count
, const D3DRECTPATCH_INFO
*patch_info
)
2598 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2601 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2602 iface
, handle
, segment_count
, patch_info
);
2604 wined3d_mutex_lock();
2605 hr
= wined3d_device_draw_rect_patch(device
->wined3d_device
, handle
,
2606 segment_count
, (const struct wined3d_rect_patch_info
*)patch_info
);
2607 wined3d_mutex_unlock();
2612 static HRESULT WINAPI
d3d8_device_DrawTriPatch(IDirect3DDevice8
*iface
, UINT handle
,
2613 const float *segment_count
, const D3DTRIPATCH_INFO
*patch_info
)
2615 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2618 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2619 iface
, handle
, segment_count
, patch_info
);
2621 wined3d_mutex_lock();
2622 hr
= wined3d_device_draw_tri_patch(device
->wined3d_device
, handle
,
2623 segment_count
, (const struct wined3d_tri_patch_info
*)patch_info
);
2624 wined3d_mutex_unlock();
2629 static HRESULT WINAPI
d3d8_device_DeletePatch(IDirect3DDevice8
*iface
, UINT handle
)
2631 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2634 TRACE("iface %p, handle %#x.\n", iface
, handle
);
2636 wined3d_mutex_lock();
2637 hr
= wined3d_device_delete_patch(device
->wined3d_device
, handle
);
2638 wined3d_mutex_unlock();
2643 static HRESULT WINAPI
d3d8_device_SetStreamSource(IDirect3DDevice8
*iface
,
2644 UINT stream_idx
, IDirect3DVertexBuffer8
*buffer
, UINT stride
)
2646 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2647 struct d3d8_vertexbuffer
*buffer_impl
= unsafe_impl_from_IDirect3DVertexBuffer8(buffer
);
2650 TRACE("iface %p, stream_idx %u, buffer %p, stride %u.\n",
2651 iface
, stream_idx
, buffer
, stride
);
2653 wined3d_mutex_lock();
2654 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, stream_idx
,
2655 buffer_impl
? buffer_impl
->wined3d_buffer
: NULL
, 0, stride
);
2656 wined3d_mutex_unlock();
2661 static HRESULT WINAPI
d3d8_device_GetStreamSource(IDirect3DDevice8
*iface
,
2662 UINT stream_idx
, IDirect3DVertexBuffer8
**buffer
, UINT
*stride
)
2664 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2665 struct d3d8_vertexbuffer
*buffer_impl
;
2666 struct wined3d_buffer
*wined3d_buffer
= NULL
;
2669 TRACE("iface %p, stream_idx %u, buffer %p, stride %p.\n",
2670 iface
, stream_idx
, buffer
, stride
);
2673 return D3DERR_INVALIDCALL
;
2675 wined3d_mutex_lock();
2676 hr
= wined3d_device_get_stream_source(device
->wined3d_device
, stream_idx
, &wined3d_buffer
, 0, stride
);
2677 if (SUCCEEDED(hr
) && wined3d_buffer
)
2679 buffer_impl
= wined3d_buffer_get_parent(wined3d_buffer
);
2680 *buffer
= &buffer_impl
->IDirect3DVertexBuffer8_iface
;
2681 IDirect3DVertexBuffer8_AddRef(*buffer
);
2682 wined3d_buffer_decref(wined3d_buffer
);
2687 ERR("Failed to get wined3d stream source, hr %#x.\n", hr
);
2690 wined3d_mutex_unlock();
2695 static const struct IDirect3DDevice8Vtbl d3d8_device_vtbl
=
2697 d3d8_device_QueryInterface
,
2699 d3d8_device_Release
,
2700 d3d8_device_TestCooperativeLevel
,
2701 d3d8_device_GetAvailableTextureMem
,
2702 d3d8_device_ResourceManagerDiscardBytes
,
2703 d3d8_device_GetDirect3D
,
2704 d3d8_device_GetDeviceCaps
,
2705 d3d8_device_GetDisplayMode
,
2706 d3d8_device_GetCreationParameters
,
2707 d3d8_device_SetCursorProperties
,
2708 d3d8_device_SetCursorPosition
,
2709 d3d8_device_ShowCursor
,
2710 d3d8_device_CreateAdditionalSwapChain
,
2712 d3d8_device_Present
,
2713 d3d8_device_GetBackBuffer
,
2714 d3d8_device_GetRasterStatus
,
2715 d3d8_device_SetGammaRamp
,
2716 d3d8_device_GetGammaRamp
,
2717 d3d8_device_CreateTexture
,
2718 d3d8_device_CreateVolumeTexture
,
2719 d3d8_device_CreateCubeTexture
,
2720 d3d8_device_CreateVertexBuffer
,
2721 d3d8_device_CreateIndexBuffer
,
2722 d3d8_device_CreateRenderTarget
,
2723 d3d8_device_CreateDepthStencilSurface
,
2724 d3d8_device_CreateImageSurface
,
2725 d3d8_device_CopyRects
,
2726 d3d8_device_UpdateTexture
,
2727 d3d8_device_GetFrontBuffer
,
2728 d3d8_device_SetRenderTarget
,
2729 d3d8_device_GetRenderTarget
,
2730 d3d8_device_GetDepthStencilSurface
,
2731 d3d8_device_BeginScene
,
2732 d3d8_device_EndScene
,
2734 d3d8_device_SetTransform
,
2735 d3d8_device_GetTransform
,
2736 d3d8_device_MultiplyTransform
,
2737 d3d8_device_SetViewport
,
2738 d3d8_device_GetViewport
,
2739 d3d8_device_SetMaterial
,
2740 d3d8_device_GetMaterial
,
2741 d3d8_device_SetLight
,
2742 d3d8_device_GetLight
,
2743 d3d8_device_LightEnable
,
2744 d3d8_device_GetLightEnable
,
2745 d3d8_device_SetClipPlane
,
2746 d3d8_device_GetClipPlane
,
2747 d3d8_device_SetRenderState
,
2748 d3d8_device_GetRenderState
,
2749 d3d8_device_BeginStateBlock
,
2750 d3d8_device_EndStateBlock
,
2751 d3d8_device_ApplyStateBlock
,
2752 d3d8_device_CaptureStateBlock
,
2753 d3d8_device_DeleteStateBlock
,
2754 d3d8_device_CreateStateBlock
,
2755 d3d8_device_SetClipStatus
,
2756 d3d8_device_GetClipStatus
,
2757 d3d8_device_GetTexture
,
2758 d3d8_device_SetTexture
,
2759 d3d8_device_GetTextureStageState
,
2760 d3d8_device_SetTextureStageState
,
2761 d3d8_device_ValidateDevice
,
2762 d3d8_device_GetInfo
,
2763 d3d8_device_SetPaletteEntries
,
2764 d3d8_device_GetPaletteEntries
,
2765 d3d8_device_SetCurrentTexturePalette
,
2766 d3d8_device_GetCurrentTexturePalette
,
2767 d3d8_device_DrawPrimitive
,
2768 d3d8_device_DrawIndexedPrimitive
,
2769 d3d8_device_DrawPrimitiveUP
,
2770 d3d8_device_DrawIndexedPrimitiveUP
,
2771 d3d8_device_ProcessVertices
,
2772 d3d8_device_CreateVertexShader
,
2773 d3d8_device_SetVertexShader
,
2774 d3d8_device_GetVertexShader
,
2775 d3d8_device_DeleteVertexShader
,
2776 d3d8_device_SetVertexShaderConstant
,
2777 d3d8_device_GetVertexShaderConstant
,
2778 d3d8_device_GetVertexShaderDeclaration
,
2779 d3d8_device_GetVertexShaderFunction
,
2780 d3d8_device_SetStreamSource
,
2781 d3d8_device_GetStreamSource
,
2782 d3d8_device_SetIndices
,
2783 d3d8_device_GetIndices
,
2784 d3d8_device_CreatePixelShader
,
2785 d3d8_device_SetPixelShader
,
2786 d3d8_device_GetPixelShader
,
2787 d3d8_device_DeletePixelShader
,
2788 d3d8_device_SetPixelShaderConstant
,
2789 d3d8_device_GetPixelShaderConstant
,
2790 d3d8_device_GetPixelShaderFunction
,
2791 d3d8_device_DrawRectPatch
,
2792 d3d8_device_DrawTriPatch
,
2793 d3d8_device_DeletePatch
,
2796 static inline struct d3d8_device
*device_from_device_parent(struct wined3d_device_parent
*device_parent
)
2798 return CONTAINING_RECORD(device_parent
, struct d3d8_device
, device_parent
);
2801 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
2802 struct wined3d_device
*device
)
2804 TRACE("device_parent %p, device %p\n", device_parent
, device
);
2807 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
2809 TRACE("device_parent %p.\n", device_parent
);
2812 static HRESULT CDECL
device_parent_create_surface(struct wined3d_device_parent
*device_parent
,
2813 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
, DWORD usage
,
2814 enum wined3d_pool pool
, UINT level
, enum wined3d_cubemap_face face
, struct wined3d_surface
**surface
)
2816 struct d3d8_device
*device
= device_from_device_parent(device_parent
);
2817 struct d3d8_surface
*d3d_surface
;
2818 BOOL lockable
= TRUE
;
2821 TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
2822 "\tpool %#x, level %u, face %u, surface %p.\n",
2823 device_parent
, container_parent
, width
, height
, format
, usage
, pool
, level
, face
, surface
);
2826 if (pool
== WINED3D_POOL_DEFAULT
&& !(usage
& WINED3DUSAGE_DYNAMIC
))
2829 hr
= d3d8_device_CreateSurface(device
, width
, height
,
2830 d3dformat_from_wined3dformat(format
), lockable
, FALSE
/* Discard */, level
,
2831 (IDirect3DSurface8
**)&d3d_surface
, usage
, pool
, D3DMULTISAMPLE_NONE
, 0 /* MultisampleQuality */);
2834 WARN("Failed to create surface, hr %#x.\n", hr
);
2838 *surface
= d3d_surface
->wined3d_surface
;
2839 wined3d_surface_incref(*surface
);
2841 d3d_surface
->container
= container_parent
;
2842 IUnknown_Release(d3d_surface
->parent_device
);
2843 d3d_surface
->parent_device
= NULL
;
2845 IDirect3DSurface8_Release(&d3d_surface
->IDirect3DSurface8_iface
);
2846 d3d_surface
->forwardReference
= container_parent
;
2851 static HRESULT CDECL
device_parent_create_rendertarget(struct wined3d_device_parent
*device_parent
,
2852 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
,
2853 enum wined3d_multisample_type multisample_type
, DWORD multisample_quality
, BOOL lockable
,
2854 struct wined3d_surface
**surface
)
2856 struct d3d8_device
*device
= device_from_device_parent(device_parent
);
2857 struct d3d8_surface
*d3d_surface
;
2860 TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2861 "\tmultisample_quality %u, lockable %u, surface %p.\n",
2862 device_parent
, container_parent
, width
, height
, format
,
2863 multisample_type
, multisample_quality
, lockable
, surface
);
2865 hr
= IDirect3DDevice8_CreateRenderTarget(&device
->IDirect3DDevice8_iface
, width
, height
,
2866 d3dformat_from_wined3dformat(format
), multisample_type
, lockable
, (IDirect3DSurface8
**)&d3d_surface
);
2869 WARN("Failed to create rendertarget, hr %#x.\n", hr
);
2873 *surface
= d3d_surface
->wined3d_surface
;
2874 wined3d_surface_incref(*surface
);
2876 d3d_surface
->container
= (IUnknown
*)&device
->IDirect3DDevice8_iface
;
2877 /* Implicit surfaces are created with an refcount of 0 */
2878 IDirect3DSurface8_Release(&d3d_surface
->IDirect3DSurface8_iface
);
2883 static HRESULT CDECL
device_parent_create_depth_stencil(struct wined3d_device_parent
*device_parent
,
2884 UINT width
, UINT height
, enum wined3d_format_id format
, enum wined3d_multisample_type multisample_type
,
2885 DWORD multisample_quality
, BOOL discard
, struct wined3d_surface
**surface
)
2887 struct d3d8_device
*device
= device_from_device_parent(device_parent
);
2888 struct d3d8_surface
*d3d_surface
;
2891 TRACE("device_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2892 "\tmultisample_quality %u, discard %u, surface %p.\n",
2893 device_parent
, width
, height
, format
, multisample_type
, multisample_quality
, discard
, surface
);
2895 hr
= IDirect3DDevice8_CreateDepthStencilSurface(&device
->IDirect3DDevice8_iface
, width
, height
,
2896 d3dformat_from_wined3dformat(format
), multisample_type
, (IDirect3DSurface8
**)&d3d_surface
);
2899 WARN("Failed to create depth/stencil surface, hr %#x.\n", hr
);
2903 *surface
= d3d_surface
->wined3d_surface
;
2904 wined3d_surface_incref(*surface
);
2906 d3d_surface
->container
= (IUnknown
*)&device
->IDirect3DDevice8_iface
;
2907 /* Implicit surfaces are created with an refcount of 0 */
2908 IDirect3DSurface8_Release(&d3d_surface
->IDirect3DSurface8_iface
);
2913 static HRESULT CDECL
device_parent_create_volume(struct wined3d_device_parent
*device_parent
,
2914 void *container_parent
, UINT width
, UINT height
, UINT depth
, enum wined3d_format_id format
,
2915 enum wined3d_pool pool
, DWORD usage
, struct wined3d_volume
**volume
)
2917 struct d3d8_device
*device
= device_from_device_parent(device_parent
);
2918 struct d3d8_volume
*object
;
2921 TRACE("device_parent %p, container_parent %p, width %u, height %u, depth %u, "
2922 "format %#x, pool %#x, usage %#x, volume %p.\n",
2923 device_parent
, container_parent
, width
, height
, depth
,
2924 format
, pool
, usage
, volume
);
2926 /* Allocate the storage for the device */
2927 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2930 FIXME("Allocation of memory failed\n");
2932 return D3DERR_OUTOFVIDEOMEMORY
;
2935 hr
= volume_init(object
, device
, width
, height
, depth
, usage
, format
, pool
);
2938 WARN("Failed to initialize volume, hr %#x.\n", hr
);
2939 HeapFree(GetProcessHeap(), 0, object
);
2943 *volume
= object
->wined3d_volume
;
2944 wined3d_volume_incref(*volume
);
2945 IDirect3DVolume8_Release(&object
->IDirect3DVolume8_iface
);
2947 object
->container
= container_parent
;
2948 object
->forwardReference
= container_parent
;
2950 TRACE("Created volume %p.\n", object
);
2955 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
2956 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain
**swapchain
)
2958 struct d3d8_device
*device
= device_from_device_parent(device_parent
);
2959 struct d3d8_swapchain
*d3d_swapchain
;
2962 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent
, desc
, swapchain
);
2964 if (FAILED(hr
= d3d8_swapchain_create(device
, desc
, &d3d_swapchain
)))
2966 WARN("Failed to create swapchain, hr %#x.\n", hr
);
2971 *swapchain
= d3d_swapchain
->wined3d_swapchain
;
2972 wined3d_swapchain_incref(*swapchain
);
2973 IDirect3DSwapChain8_Release(&d3d_swapchain
->IDirect3DSwapChain8_iface
);
2978 static const struct wined3d_device_parent_ops d3d8_wined3d_device_parent_ops
=
2980 device_parent_wined3d_device_created
,
2981 device_parent_mode_changed
,
2982 device_parent_create_surface
,
2983 device_parent_create_rendertarget
,
2984 device_parent_create_depth_stencil
,
2985 device_parent_create_volume
,
2986 device_parent_create_swapchain
,
2989 static void setup_fpu(void)
2991 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
2993 __asm__
volatile ("fnstcw %0" : "=m" (cw
));
2994 cw
= (cw
& ~0xf3f) | 0x3f;
2995 __asm__
volatile ("fldcw %0" : : "m" (cw
));
2996 #elif defined(__i386__) && defined(_MSC_VER)
2999 cw
= (cw
& ~0xf3f) | 0x3f;
3002 FIXME("FPU setup not implemented for this platform.\n");
3006 HRESULT
device_init(struct d3d8_device
*device
, struct d3d8
*parent
, struct wined3d
*wined3d
, UINT adapter
,
3007 D3DDEVTYPE device_type
, HWND focus_window
, DWORD flags
, D3DPRESENT_PARAMETERS
*parameters
)
3009 struct wined3d_swapchain_desc swapchain_desc
;
3012 device
->IDirect3DDevice8_iface
.lpVtbl
= &d3d8_device_vtbl
;
3013 device
->device_parent
.ops
= &d3d8_wined3d_device_parent_ops
;
3015 device
->handle_table
.entries
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
3016 D3D8_INITIAL_HANDLE_TABLE_SIZE
* sizeof(*device
->handle_table
.entries
));
3017 if (!device
->handle_table
.entries
)
3019 ERR("Failed to allocate handle table memory.\n");
3020 return E_OUTOFMEMORY
;
3022 device
->handle_table
.table_size
= D3D8_INITIAL_HANDLE_TABLE_SIZE
;
3024 if (!(flags
& D3DCREATE_FPU_PRESERVE
)) setup_fpu();
3026 wined3d_mutex_lock();
3027 hr
= wined3d_device_create(wined3d
, adapter
, device_type
, focus_window
, flags
, 4,
3028 &device
->device_parent
, &device
->wined3d_device
);
3031 WARN("Failed to create wined3d device, hr %#x.\n", hr
);
3032 wined3d_mutex_unlock();
3033 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
3037 if (!parameters
->Windowed
)
3039 HWND device_window
= parameters
->hDeviceWindow
;
3042 focus_window
= device_window
;
3043 if (FAILED(hr
= wined3d_device_acquire_focus_window(device
->wined3d_device
, focus_window
)))
3045 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
3046 wined3d_device_decref(device
->wined3d_device
);
3047 wined3d_mutex_unlock();
3048 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
3053 device_window
= focus_window
;
3054 wined3d_device_setup_fullscreen_window(device
->wined3d_device
, device_window
,
3055 parameters
->BackBufferWidth
,
3056 parameters
->BackBufferHeight
);
3059 if (flags
& D3DCREATE_MULTITHREADED
)
3060 wined3d_device_set_multithreaded(device
->wined3d_device
);
3062 wined3d_swapchain_desc_from_present_parameters(&swapchain_desc
, parameters
);
3064 hr
= wined3d_device_init_3d(device
->wined3d_device
, &swapchain_desc
);
3067 WARN("Failed to initialize 3D, hr %#x.\n", hr
);
3068 wined3d_device_release_focus_window(device
->wined3d_device
);
3069 wined3d_device_decref(device
->wined3d_device
);
3070 wined3d_mutex_unlock();
3071 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
3075 hr
= wined3d_device_set_render_state(device
->wined3d_device
, WINED3D_RS_POINTSIZE_MIN
, 0);
3076 wined3d_mutex_unlock();
3079 ERR("Failed to set minimum pointsize, hr %#x.\n", hr
);
3083 parameters
->BackBufferWidth
= swapchain_desc
.backbuffer_width
;
3084 parameters
->BackBufferHeight
= swapchain_desc
.backbuffer_height
;
3085 parameters
->BackBufferFormat
= d3dformat_from_wined3dformat(swapchain_desc
.backbuffer_format
);
3086 parameters
->BackBufferCount
= swapchain_desc
.backbuffer_count
;
3087 parameters
->MultiSampleType
= swapchain_desc
.multisample_type
;
3088 parameters
->SwapEffect
= swapchain_desc
.swap_effect
;
3089 parameters
->hDeviceWindow
= swapchain_desc
.device_window
;
3090 parameters
->Windowed
= swapchain_desc
.windowed
;
3091 parameters
->EnableAutoDepthStencil
= swapchain_desc
.enable_auto_depth_stencil
;
3092 parameters
->AutoDepthStencilFormat
= d3dformat_from_wined3dformat(swapchain_desc
.auto_depth_stencil_format
);
3093 parameters
->Flags
= swapchain_desc
.flags
;
3094 parameters
->FullScreen_RefreshRateInHz
= swapchain_desc
.refresh_rate
;
3095 parameters
->FullScreen_PresentationInterval
= swapchain_desc
.swap_interval
;
3097 device
->declArraySize
= 16;
3098 device
->decls
= HeapAlloc(GetProcessHeap(), 0, device
->declArraySize
* sizeof(*device
->decls
));
3101 ERR("Failed to allocate FVF vertex declaration map memory.\n");
3106 device
->d3d_parent
= &parent
->IDirect3D8_iface
;
3107 IDirect3D8_AddRef(device
->d3d_parent
);
3112 wined3d_mutex_lock();
3113 wined3d_device_uninit_3d(device
->wined3d_device
);
3114 wined3d_device_release_focus_window(device
->wined3d_device
);
3115 wined3d_device_decref(device
->wined3d_device
);
3116 wined3d_mutex_unlock();
3117 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);