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
22 #include "d3d8_private.h"
24 static void STDMETHODCALLTYPE
d3d8_null_wined3d_object_destroyed(void *parent
) {}
26 static const struct wined3d_parent_ops d3d8_null_wined3d_parent_ops
=
28 d3d8_null_wined3d_object_destroyed
,
31 D3DFORMAT
d3dformat_from_wined3dformat(enum wined3d_format_id format
)
33 BYTE
*c
= (BYTE
*)&format
;
35 /* Don't translate FOURCC formats */
36 if (isprint(c
[0]) && isprint(c
[1]) && isprint(c
[2]) && isprint(c
[3])) return format
;
40 case WINED3DFMT_UNKNOWN
: return D3DFMT_UNKNOWN
;
41 case WINED3DFMT_B8G8R8_UNORM
: return D3DFMT_R8G8B8
;
42 case WINED3DFMT_B8G8R8A8_UNORM
: return D3DFMT_A8R8G8B8
;
43 case WINED3DFMT_B8G8R8X8_UNORM
: return D3DFMT_X8R8G8B8
;
44 case WINED3DFMT_B5G6R5_UNORM
: return D3DFMT_R5G6B5
;
45 case WINED3DFMT_B5G5R5X1_UNORM
: return D3DFMT_X1R5G5B5
;
46 case WINED3DFMT_B5G5R5A1_UNORM
: return D3DFMT_A1R5G5B5
;
47 case WINED3DFMT_B4G4R4A4_UNORM
: return D3DFMT_A4R4G4B4
;
48 case WINED3DFMT_B2G3R3_UNORM
: return D3DFMT_R3G3B2
;
49 case WINED3DFMT_A8_UNORM
: return D3DFMT_A8
;
50 case WINED3DFMT_B2G3R3A8_UNORM
: return D3DFMT_A8R3G3B2
;
51 case WINED3DFMT_B4G4R4X4_UNORM
: return D3DFMT_X4R4G4B4
;
52 case WINED3DFMT_R10G10B10A2_UNORM
: return D3DFMT_A2B10G10R10
;
53 case WINED3DFMT_R16G16_UNORM
: return D3DFMT_G16R16
;
54 case WINED3DFMT_P8_UINT_A8_UNORM
: return D3DFMT_A8P8
;
55 case WINED3DFMT_P8_UINT
: return D3DFMT_P8
;
56 case WINED3DFMT_L8_UNORM
: return D3DFMT_L8
;
57 case WINED3DFMT_L8A8_UNORM
: return D3DFMT_A8L8
;
58 case WINED3DFMT_L4A4_UNORM
: return D3DFMT_A4L4
;
59 case WINED3DFMT_R8G8_SNORM
: return D3DFMT_V8U8
;
60 case WINED3DFMT_R5G5_SNORM_L6_UNORM
: return D3DFMT_L6V5U5
;
61 case WINED3DFMT_R8G8_SNORM_L8X8_UNORM
: return D3DFMT_X8L8V8U8
;
62 case WINED3DFMT_R8G8B8A8_SNORM
: return D3DFMT_Q8W8V8U8
;
63 case WINED3DFMT_R16G16_SNORM
: return D3DFMT_V16U16
;
64 case WINED3DFMT_R10G11B11_SNORM
: return D3DFMT_W11V11U10
;
65 case WINED3DFMT_R10G10B10_SNORM_A2_UNORM
: return D3DFMT_A2W10V10U10
;
66 case WINED3DFMT_D16_LOCKABLE
: return D3DFMT_D16_LOCKABLE
;
67 case WINED3DFMT_D32_UNORM
: return D3DFMT_D32
;
68 case WINED3DFMT_S1_UINT_D15_UNORM
: return D3DFMT_D15S1
;
69 case WINED3DFMT_D24_UNORM_S8_UINT
: return D3DFMT_D24S8
;
70 case WINED3DFMT_X8D24_UNORM
: return D3DFMT_D24X8
;
71 case WINED3DFMT_S4X4_UINT_D24_UNORM
: return D3DFMT_D24X4S4
;
72 case WINED3DFMT_D16_UNORM
: return D3DFMT_D16
;
73 case WINED3DFMT_VERTEXDATA
: return D3DFMT_VERTEXDATA
;
74 case WINED3DFMT_R16_UINT
: return D3DFMT_INDEX16
;
75 case WINED3DFMT_R32_UINT
: return D3DFMT_INDEX32
;
77 FIXME("Unhandled wined3d format %#x.\n", format
);
78 return D3DFMT_UNKNOWN
;
82 enum wined3d_format_id
wined3dformat_from_d3dformat(D3DFORMAT format
)
84 BYTE
*c
= (BYTE
*)&format
;
86 /* Don't translate FOURCC formats */
87 if (isprint(c
[0]) && isprint(c
[1]) && isprint(c
[2]) && isprint(c
[3])) return format
;
91 case D3DFMT_UNKNOWN
: return WINED3DFMT_UNKNOWN
;
92 case D3DFMT_R8G8B8
: return WINED3DFMT_B8G8R8_UNORM
;
93 case D3DFMT_A8R8G8B8
: return WINED3DFMT_B8G8R8A8_UNORM
;
94 case D3DFMT_X8R8G8B8
: return WINED3DFMT_B8G8R8X8_UNORM
;
95 case D3DFMT_R5G6B5
: return WINED3DFMT_B5G6R5_UNORM
;
96 case D3DFMT_X1R5G5B5
: return WINED3DFMT_B5G5R5X1_UNORM
;
97 case D3DFMT_A1R5G5B5
: return WINED3DFMT_B5G5R5A1_UNORM
;
98 case D3DFMT_A4R4G4B4
: return WINED3DFMT_B4G4R4A4_UNORM
;
99 case D3DFMT_R3G3B2
: return WINED3DFMT_B2G3R3_UNORM
;
100 case D3DFMT_A8
: return WINED3DFMT_A8_UNORM
;
101 case D3DFMT_A8R3G3B2
: return WINED3DFMT_B2G3R3A8_UNORM
;
102 case D3DFMT_X4R4G4B4
: return WINED3DFMT_B4G4R4X4_UNORM
;
103 case D3DFMT_A2B10G10R10
: return WINED3DFMT_R10G10B10A2_UNORM
;
104 case D3DFMT_G16R16
: return WINED3DFMT_R16G16_UNORM
;
105 case D3DFMT_A8P8
: return WINED3DFMT_P8_UINT_A8_UNORM
;
106 case D3DFMT_P8
: return WINED3DFMT_P8_UINT
;
107 case D3DFMT_L8
: return WINED3DFMT_L8_UNORM
;
108 case D3DFMT_A8L8
: return WINED3DFMT_L8A8_UNORM
;
109 case D3DFMT_A4L4
: return WINED3DFMT_L4A4_UNORM
;
110 case D3DFMT_V8U8
: return WINED3DFMT_R8G8_SNORM
;
111 case D3DFMT_L6V5U5
: return WINED3DFMT_R5G5_SNORM_L6_UNORM
;
112 case D3DFMT_X8L8V8U8
: return WINED3DFMT_R8G8_SNORM_L8X8_UNORM
;
113 case D3DFMT_Q8W8V8U8
: return WINED3DFMT_R8G8B8A8_SNORM
;
114 case D3DFMT_V16U16
: return WINED3DFMT_R16G16_SNORM
;
115 case D3DFMT_W11V11U10
: return WINED3DFMT_R10G11B11_SNORM
;
116 case D3DFMT_A2W10V10U10
: return WINED3DFMT_R10G10B10_SNORM_A2_UNORM
;
117 case D3DFMT_D16_LOCKABLE
: return WINED3DFMT_D16_LOCKABLE
;
118 case D3DFMT_D32
: return WINED3DFMT_D32_UNORM
;
119 case D3DFMT_D15S1
: return WINED3DFMT_S1_UINT_D15_UNORM
;
120 case D3DFMT_D24S8
: return WINED3DFMT_D24_UNORM_S8_UINT
;
121 case D3DFMT_D24X8
: return WINED3DFMT_X8D24_UNORM
;
122 case D3DFMT_D24X4S4
: return WINED3DFMT_S4X4_UINT_D24_UNORM
;
123 case D3DFMT_D16
: return WINED3DFMT_D16_UNORM
;
124 case D3DFMT_VERTEXDATA
: return WINED3DFMT_VERTEXDATA
;
125 case D3DFMT_INDEX16
: return WINED3DFMT_R16_UINT
;
126 case D3DFMT_INDEX32
: return WINED3DFMT_R32_UINT
;
128 FIXME("Unhandled D3DFORMAT %#x\n", format
);
129 return WINED3DFMT_UNKNOWN
;
133 static UINT
vertex_count_from_primitive_count(D3DPRIMITIVETYPE primitive_type
, UINT primitive_count
)
135 switch(primitive_type
)
137 case D3DPT_POINTLIST
:
138 return primitive_count
;
141 return primitive_count
* 2;
143 case D3DPT_LINESTRIP
:
144 return primitive_count
+ 1;
146 case D3DPT_TRIANGLELIST
:
147 return primitive_count
* 3;
149 case D3DPT_TRIANGLESTRIP
:
150 case D3DPT_TRIANGLEFAN
:
151 return primitive_count
+ 2;
154 FIXME("Unhandled primitive type %#x\n", primitive_type
);
159 static void present_parameters_from_wined3d_swapchain_desc(D3DPRESENT_PARAMETERS
*present_parameters
,
160 const struct wined3d_swapchain_desc
*swapchain_desc
)
162 present_parameters
->BackBufferWidth
= swapchain_desc
->backbuffer_width
;
163 present_parameters
->BackBufferHeight
= swapchain_desc
->backbuffer_height
;
164 present_parameters
->BackBufferFormat
= d3dformat_from_wined3dformat(swapchain_desc
->backbuffer_format
);
165 present_parameters
->BackBufferCount
= swapchain_desc
->backbuffer_count
;
166 present_parameters
->MultiSampleType
= swapchain_desc
->multisample_type
;
167 present_parameters
->SwapEffect
= swapchain_desc
->swap_effect
;
168 present_parameters
->hDeviceWindow
= swapchain_desc
->device_window
;
169 present_parameters
->Windowed
= swapchain_desc
->windowed
;
170 present_parameters
->EnableAutoDepthStencil
= swapchain_desc
->enable_auto_depth_stencil
;
171 present_parameters
->AutoDepthStencilFormat
172 = d3dformat_from_wined3dformat(swapchain_desc
->auto_depth_stencil_format
);
173 present_parameters
->Flags
= swapchain_desc
->flags
;
174 present_parameters
->FullScreen_RefreshRateInHz
= swapchain_desc
->refresh_rate
;
175 present_parameters
->FullScreen_PresentationInterval
= swapchain_desc
->swap_interval
;
178 static void wined3d_swapchain_desc_from_present_parameters(struct wined3d_swapchain_desc
*swapchain_desc
,
179 const D3DPRESENT_PARAMETERS
*present_parameters
)
181 swapchain_desc
->backbuffer_width
= present_parameters
->BackBufferWidth
;
182 swapchain_desc
->backbuffer_height
= present_parameters
->BackBufferHeight
;
183 swapchain_desc
->backbuffer_format
= wined3dformat_from_d3dformat(present_parameters
->BackBufferFormat
);
184 swapchain_desc
->backbuffer_count
= max(1, present_parameters
->BackBufferCount
);
185 swapchain_desc
->multisample_type
= present_parameters
->MultiSampleType
;
186 swapchain_desc
->multisample_quality
= 0; /* d3d9 only */
187 swapchain_desc
->swap_effect
= present_parameters
->SwapEffect
;
188 swapchain_desc
->device_window
= present_parameters
->hDeviceWindow
;
189 swapchain_desc
->windowed
= present_parameters
->Windowed
;
190 swapchain_desc
->enable_auto_depth_stencil
= present_parameters
->EnableAutoDepthStencil
;
191 swapchain_desc
->auto_depth_stencil_format
192 = wined3dformat_from_d3dformat(present_parameters
->AutoDepthStencilFormat
);
193 swapchain_desc
->flags
= present_parameters
->Flags
;
194 swapchain_desc
->refresh_rate
= present_parameters
->FullScreen_RefreshRateInHz
;
195 swapchain_desc
->swap_interval
= present_parameters
->FullScreen_PresentationInterval
;
196 swapchain_desc
->auto_restore_display_mode
= TRUE
;
199 /* Handle table functions */
200 static DWORD
d3d8_allocate_handle(struct d3d8_handle_table
*t
, void *object
, enum d3d8_handle_type type
)
202 struct d3d8_handle_entry
*entry
;
206 DWORD index
= t
->free_entries
- t
->entries
;
207 /* Use a free handle */
208 entry
= t
->free_entries
;
209 if (entry
->type
!= D3D8_HANDLE_FREE
)
211 ERR("Handle %u(%p) is in the free list, but has type %#x.\n", index
, entry
, entry
->type
);
212 return D3D8_INVALID_HANDLE
;
214 t
->free_entries
= entry
->object
;
215 entry
->object
= object
;
221 if (!(t
->entry_count
< t
->table_size
))
224 UINT new_size
= t
->table_size
+ (t
->table_size
>> 1);
225 struct d3d8_handle_entry
*new_entries
= HeapReAlloc(GetProcessHeap(),
226 0, t
->entries
, new_size
* sizeof(*t
->entries
));
229 ERR("Failed to grow the handle table.\n");
230 return D3D8_INVALID_HANDLE
;
232 t
->entries
= new_entries
;
233 t
->table_size
= new_size
;
236 entry
= &t
->entries
[t
->entry_count
];
237 entry
->object
= object
;
240 return t
->entry_count
++;
243 static void *d3d8_free_handle(struct d3d8_handle_table
*t
, DWORD handle
, enum d3d8_handle_type type
)
245 struct d3d8_handle_entry
*entry
;
248 if (handle
== D3D8_INVALID_HANDLE
|| handle
>= t
->entry_count
)
250 WARN("Invalid handle %u passed.\n", handle
);
254 entry
= &t
->entries
[handle
];
255 if (entry
->type
!= type
)
257 WARN("Handle %u(%p) is not of type %#x.\n", handle
, entry
, type
);
261 object
= entry
->object
;
262 entry
->object
= t
->free_entries
;
263 entry
->type
= D3D8_HANDLE_FREE
;
264 t
->free_entries
= entry
;
269 static void *d3d8_get_object(struct d3d8_handle_table
*t
, DWORD handle
, enum d3d8_handle_type type
)
271 struct d3d8_handle_entry
*entry
;
273 if (handle
== D3D8_INVALID_HANDLE
|| handle
>= t
->entry_count
)
275 WARN("Invalid handle %u passed.\n", handle
);
279 entry
= &t
->entries
[handle
];
280 if (entry
->type
!= type
)
282 WARN("Handle %u(%p) is not of type %#x.\n", handle
, entry
, type
);
286 return entry
->object
;
289 static HRESULT WINAPI
d3d8_device_QueryInterface(IDirect3DDevice8
*iface
, REFIID riid
, void **out
)
291 TRACE("iface %p, riid %s, out %p.\n",
292 iface
, debugstr_guid(riid
), out
);
294 if (IsEqualGUID(riid
, &IID_IDirect3DDevice8
)
295 || IsEqualGUID(riid
, &IID_IUnknown
))
297 IDirect3DDevice8_AddRef(iface
);
302 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
305 return E_NOINTERFACE
;
308 static ULONG WINAPI
d3d8_device_AddRef(IDirect3DDevice8
*iface
)
310 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
311 ULONG ref
= InterlockedIncrement(&device
->ref
);
313 TRACE("%p increasing refcount to %u.\n", iface
, ref
);
318 static ULONG WINAPI
d3d8_device_Release(IDirect3DDevice8
*iface
)
320 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
323 if (device
->inDestruction
)
326 ref
= InterlockedDecrement(&device
->ref
);
328 TRACE("%p decreasing refcount to %u.\n", iface
, ref
);
332 IDirect3D8
*parent
= device
->d3d_parent
;
335 TRACE("Releasing wined3d device %p.\n", device
->wined3d_device
);
337 wined3d_mutex_lock();
339 device
->inDestruction
= TRUE
;
341 for (i
= 0; i
< device
->numConvertedDecls
; ++i
)
343 d3d8_vertex_declaration_destroy(device
->decls
[i
].declaration
);
345 HeapFree(GetProcessHeap(), 0, device
->decls
);
347 if (device
->vertex_buffer
)
348 wined3d_buffer_decref(device
->vertex_buffer
);
349 if (device
->index_buffer
)
350 wined3d_buffer_decref(device
->index_buffer
);
352 wined3d_device_uninit_3d(device
->wined3d_device
);
353 wined3d_device_release_focus_window(device
->wined3d_device
);
354 wined3d_device_decref(device
->wined3d_device
);
355 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
356 HeapFree(GetProcessHeap(), 0, device
);
358 wined3d_mutex_unlock();
360 IDirect3D8_Release(parent
);
365 static HRESULT WINAPI
d3d8_device_TestCooperativeLevel(IDirect3DDevice8
*iface
)
367 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
369 TRACE("iface %p.\n", iface
);
371 TRACE("device state: %#x.\n", device
->device_state
);
373 switch (device
->device_state
)
376 case D3D8_DEVICE_STATE_OK
:
378 case D3D8_DEVICE_STATE_LOST
:
379 return D3DERR_DEVICELOST
;
380 case D3D8_DEVICE_STATE_NOT_RESET
:
381 return D3DERR_DEVICENOTRESET
;
385 static UINT WINAPI
d3d8_device_GetAvailableTextureMem(IDirect3DDevice8
*iface
)
387 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
390 TRACE("iface %p.\n", iface
);
392 wined3d_mutex_lock();
393 ret
= wined3d_device_get_available_texture_mem(device
->wined3d_device
);
394 wined3d_mutex_unlock();
399 static HRESULT WINAPI
d3d8_device_ResourceManagerDiscardBytes(IDirect3DDevice8
*iface
, DWORD byte_count
)
401 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
403 TRACE("iface %p, byte_count %u.\n", iface
, byte_count
);
406 FIXME("Byte count ignored.\n");
408 wined3d_mutex_lock();
409 wined3d_device_evict_managed_resources(device
->wined3d_device
);
410 wined3d_mutex_unlock();
415 static HRESULT WINAPI
d3d8_device_GetDirect3D(IDirect3DDevice8
*iface
, IDirect3D8
**d3d8
)
417 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
419 TRACE("iface %p, d3d8 %p.\n", iface
, d3d8
);
422 return D3DERR_INVALIDCALL
;
424 return IDirect3D8_QueryInterface(device
->d3d_parent
, &IID_IDirect3D8
, (void **)d3d8
);
427 static HRESULT WINAPI
d3d8_device_GetDeviceCaps(IDirect3DDevice8
*iface
, D3DCAPS8
*caps
)
429 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
430 WINED3DCAPS
*wined3d_caps
;
433 TRACE("iface %p, caps %p.\n", iface
, caps
);
436 return D3DERR_INVALIDCALL
;
438 if (!(wined3d_caps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*wined3d_caps
))))
439 return D3DERR_INVALIDCALL
; /* well this is what MSDN says to return */
441 wined3d_mutex_lock();
442 hr
= wined3d_device_get_device_caps(device
->wined3d_device
, wined3d_caps
);
443 wined3d_mutex_unlock();
445 fixup_caps(wined3d_caps
);
446 WINECAPSTOD3D8CAPS(caps
, wined3d_caps
)
447 HeapFree(GetProcessHeap(), 0, wined3d_caps
);
452 static HRESULT WINAPI
d3d8_device_GetDisplayMode(IDirect3DDevice8
*iface
, D3DDISPLAYMODE
*mode
)
454 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
455 struct wined3d_display_mode wined3d_mode
;
458 TRACE("iface %p, mode %p.\n", iface
, mode
);
460 wined3d_mutex_lock();
461 hr
= wined3d_device_get_display_mode(device
->wined3d_device
, 0, &wined3d_mode
, NULL
);
462 wined3d_mutex_unlock();
466 mode
->Width
= wined3d_mode
.width
;
467 mode
->Height
= wined3d_mode
.height
;
468 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
469 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
475 static HRESULT WINAPI
d3d8_device_GetCreationParameters(IDirect3DDevice8
*iface
,
476 D3DDEVICE_CREATION_PARAMETERS
*parameters
)
478 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
480 TRACE("iface %p, parameters %p.\n", iface
, parameters
);
482 wined3d_mutex_lock();
483 wined3d_device_get_creation_parameters(device
->wined3d_device
,
484 (struct wined3d_device_creation_parameters
*)parameters
);
485 wined3d_mutex_unlock();
490 static HRESULT WINAPI
d3d8_device_SetCursorProperties(IDirect3DDevice8
*iface
,
491 UINT hotspot_x
, UINT hotspot_y
, IDirect3DSurface8
*bitmap
)
493 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
494 struct d3d8_surface
*bitmap_impl
= unsafe_impl_from_IDirect3DSurface8(bitmap
);
497 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
498 iface
, hotspot_x
, hotspot_y
, bitmap
);
502 WARN("No cursor bitmap, returning D3DERR_INVALIDCALL.\n");
503 return D3DERR_INVALIDCALL
;
506 wined3d_mutex_lock();
507 hr
= wined3d_device_set_cursor_properties(device
->wined3d_device
,
508 hotspot_x
, hotspot_y
, bitmap_impl
->wined3d_surface
);
509 wined3d_mutex_unlock();
514 static void WINAPI
d3d8_device_SetCursorPosition(IDirect3DDevice8
*iface
, UINT x
, UINT y
, DWORD flags
)
516 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
518 TRACE("iface %p, x %u, y %u, flags %#x.\n", iface
, x
, y
, flags
);
520 wined3d_mutex_lock();
521 wined3d_device_set_cursor_position(device
->wined3d_device
, x
, y
, flags
);
522 wined3d_mutex_unlock();
525 static BOOL WINAPI
d3d8_device_ShowCursor(IDirect3DDevice8
*iface
, BOOL show
)
527 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
530 TRACE("iface %p, show %#x.\n", iface
, show
);
532 wined3d_mutex_lock();
533 ret
= wined3d_device_show_cursor(device
->wined3d_device
, show
);
534 wined3d_mutex_unlock();
539 static HRESULT WINAPI
d3d8_device_CreateAdditionalSwapChain(IDirect3DDevice8
*iface
,
540 D3DPRESENT_PARAMETERS
*present_parameters
, IDirect3DSwapChain8
**swapchain
)
542 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
543 struct wined3d_swapchain_desc desc
;
544 struct d3d8_swapchain
*object
;
548 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
549 iface
, present_parameters
, swapchain
);
551 if (!present_parameters
->Windowed
)
553 WARN("Trying to create an additional fullscreen swapchain, returning D3DERR_INVALIDCALL.\n");
554 return D3DERR_INVALIDCALL
;
557 wined3d_mutex_lock();
558 count
= wined3d_device_get_swapchain_count(device
->wined3d_device
);
559 for (i
= 0; i
< count
; ++i
)
561 struct wined3d_swapchain
*wined3d_swapchain
;
563 wined3d_swapchain
= wined3d_device_get_swapchain(device
->wined3d_device
, i
);
564 wined3d_swapchain_get_desc(wined3d_swapchain
, &desc
);
568 wined3d_mutex_unlock();
569 WARN("Trying to create an additional swapchain in fullscreen mode, returning D3DERR_INVALIDCALL.\n");
570 return D3DERR_INVALIDCALL
;
573 wined3d_mutex_unlock();
575 wined3d_swapchain_desc_from_present_parameters(&desc
, present_parameters
);
576 if (SUCCEEDED(hr
= d3d8_swapchain_create(device
, &desc
, &object
)))
577 *swapchain
= &object
->IDirect3DSwapChain8_iface
;
578 present_parameters_from_wined3d_swapchain_desc(present_parameters
, &desc
);
583 static HRESULT CDECL
reset_enum_callback(struct wined3d_resource
*resource
)
585 struct wined3d_resource_desc desc
;
587 wined3d_resource_get_desc(resource
, &desc
);
588 if (desc
.pool
== WINED3D_POOL_DEFAULT
)
590 struct d3d8_surface
*surface
;
592 if (desc
.resource_type
== WINED3D_RTYPE_TEXTURE
)
594 IUnknown
*parent
= wined3d_resource_get_parent(resource
);
595 IDirect3DBaseTexture8
*texture
;
597 if (SUCCEEDED(IUnknown_QueryInterface(parent
, &IID_IDirect3DBaseTexture8
, (void **)&texture
)))
599 IDirect3DBaseTexture8_Release(texture
);
600 WARN("Texture %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", texture
, resource
);
601 return D3DERR_DEVICELOST
;
607 if (desc
.resource_type
!= WINED3D_RTYPE_SURFACE
)
609 WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource
);
610 return D3DERR_DEVICELOST
;
613 surface
= wined3d_resource_get_parent(resource
);
614 if (surface
->resource
.refcount
)
616 WARN("Surface %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface
, resource
);
617 return D3DERR_DEVICELOST
;
620 WARN("Surface %p (resource %p) is an implicit resource with ref 0.\n", surface
, resource
);
626 static HRESULT WINAPI
d3d8_device_Reset(IDirect3DDevice8
*iface
,
627 D3DPRESENT_PARAMETERS
*present_parameters
)
629 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
630 struct wined3d_swapchain_desc swapchain_desc
;
633 TRACE("iface %p, present_parameters %p.\n", iface
, present_parameters
);
635 if (device
->device_state
== D3D8_DEVICE_STATE_LOST
)
637 WARN("App not active, returning D3DERR_DEVICELOST.\n");
638 return D3DERR_DEVICELOST
;
641 wined3d_mutex_lock();
643 if (device
->vertex_buffer
)
645 wined3d_buffer_decref(device
->vertex_buffer
);
646 device
->vertex_buffer
= NULL
;
647 device
->vertex_buffer_size
= 0;
649 if (device
->index_buffer
)
651 wined3d_buffer_decref(device
->index_buffer
);
652 device
->index_buffer
= NULL
;
653 device
->index_buffer_size
= 0;
656 wined3d_swapchain_desc_from_present_parameters(&swapchain_desc
, present_parameters
);
657 if (SUCCEEDED(hr
= wined3d_device_reset(device
->wined3d_device
, &swapchain_desc
,
658 NULL
, reset_enum_callback
, TRUE
)))
660 present_parameters
->BackBufferCount
= swapchain_desc
.backbuffer_count
;
661 wined3d_device_set_render_state(device
->wined3d_device
, WINED3D_RS_POINTSIZE_MIN
, 0);
662 device
->device_state
= D3D8_DEVICE_STATE_OK
;
666 device
->device_state
= D3D8_DEVICE_STATE_NOT_RESET
;
668 wined3d_mutex_unlock();
673 static HRESULT WINAPI
d3d8_device_Present(IDirect3DDevice8
*iface
, const RECT
*src_rect
,
674 const RECT
*dst_rect
, HWND dst_window_override
, const RGNDATA
*dirty_region
)
676 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
679 TRACE("iface %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p.\n",
680 iface
, wine_dbgstr_rect(src_rect
), wine_dbgstr_rect(dst_rect
), dst_window_override
, dirty_region
);
682 if (device
->device_state
!= D3D8_DEVICE_STATE_OK
)
683 return D3DERR_DEVICELOST
;
685 wined3d_mutex_lock();
686 hr
= wined3d_device_present(device
->wined3d_device
, src_rect
, dst_rect
,
687 dst_window_override
, dirty_region
, 0);
688 wined3d_mutex_unlock();
693 static HRESULT WINAPI
d3d8_device_GetBackBuffer(IDirect3DDevice8
*iface
,
694 UINT backbuffer_idx
, D3DBACKBUFFER_TYPE backbuffer_type
, IDirect3DSurface8
**backbuffer
)
696 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
697 struct wined3d_surface
*wined3d_surface
= NULL
;
698 struct d3d8_surface
*surface_impl
;
701 TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
702 iface
, backbuffer_idx
, backbuffer_type
, backbuffer
);
704 wined3d_mutex_lock();
705 hr
= wined3d_device_get_back_buffer(device
->wined3d_device
, 0, backbuffer_idx
,
706 (enum wined3d_backbuffer_type
)backbuffer_type
, &wined3d_surface
);
707 if (SUCCEEDED(hr
) && wined3d_surface
&& backbuffer
)
709 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
710 *backbuffer
= &surface_impl
->IDirect3DSurface8_iface
;
711 IDirect3DSurface8_AddRef(*backbuffer
);
713 wined3d_mutex_unlock();
718 static HRESULT WINAPI
d3d8_device_GetRasterStatus(IDirect3DDevice8
*iface
, D3DRASTER_STATUS
*raster_status
)
720 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
723 TRACE("iface %p, raster_status %p.\n", iface
, raster_status
);
725 wined3d_mutex_lock();
726 hr
= wined3d_device_get_raster_status(device
->wined3d_device
, 0, (struct wined3d_raster_status
*)raster_status
);
727 wined3d_mutex_unlock();
732 static void WINAPI
d3d8_device_SetGammaRamp(IDirect3DDevice8
*iface
, DWORD flags
, const D3DGAMMARAMP
*ramp
)
734 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
736 TRACE("iface %p, flags %#x, ramp %p.\n", iface
, flags
, ramp
);
738 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
739 wined3d_mutex_lock();
740 wined3d_device_set_gamma_ramp(device
->wined3d_device
, 0, flags
, (const struct wined3d_gamma_ramp
*)ramp
);
741 wined3d_mutex_unlock();
744 static void WINAPI
d3d8_device_GetGammaRamp(IDirect3DDevice8
*iface
, D3DGAMMARAMP
*ramp
)
746 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
748 TRACE("iface %p, ramp %p.\n", iface
, ramp
);
750 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
751 wined3d_mutex_lock();
752 wined3d_device_get_gamma_ramp(device
->wined3d_device
, 0, (struct wined3d_gamma_ramp
*)ramp
);
753 wined3d_mutex_unlock();
756 static HRESULT WINAPI
d3d8_device_CreateTexture(IDirect3DDevice8
*iface
,
757 UINT width
, UINT height
, UINT levels
, DWORD usage
, D3DFORMAT format
,
758 D3DPOOL pool
, IDirect3DTexture8
**texture
)
760 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
761 struct d3d8_texture
*object
;
764 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
765 iface
, width
, height
, levels
, usage
, format
, pool
, texture
);
768 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
770 return D3DERR_OUTOFVIDEOMEMORY
;
772 hr
= texture_init(object
, device
, width
, height
, levels
, usage
, format
, pool
);
775 WARN("Failed to initialize texture, hr %#x.\n", hr
);
776 HeapFree(GetProcessHeap(), 0, object
);
780 TRACE("Created texture %p.\n", object
);
781 *texture
= (IDirect3DTexture8
*)&object
->IDirect3DBaseTexture8_iface
;
786 static HRESULT WINAPI
d3d8_device_CreateVolumeTexture(IDirect3DDevice8
*iface
,
787 UINT width
, UINT height
, UINT depth
, UINT levels
, DWORD usage
, D3DFORMAT format
,
788 D3DPOOL pool
, IDirect3DVolumeTexture8
**texture
)
790 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
791 struct d3d8_texture
*object
;
794 TRACE("iface %p, width %u, height %u, depth %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
795 iface
, width
, height
, depth
, levels
, usage
, format
, pool
, texture
);
798 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
800 return D3DERR_OUTOFVIDEOMEMORY
;
802 hr
= volumetexture_init(object
, device
, width
, height
, depth
, levels
, usage
, format
, pool
);
805 WARN("Failed to initialize volume texture, hr %#x.\n", hr
);
806 HeapFree(GetProcessHeap(), 0, object
);
810 TRACE("Created volume texture %p.\n", object
);
811 *texture
= (IDirect3DVolumeTexture8
*)&object
->IDirect3DBaseTexture8_iface
;
816 static HRESULT WINAPI
d3d8_device_CreateCubeTexture(IDirect3DDevice8
*iface
, UINT edge_length
,
817 UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DCubeTexture8
**texture
)
819 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
820 struct d3d8_texture
*object
;
823 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
824 iface
, edge_length
, levels
, usage
, format
, pool
, texture
);
827 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
829 return D3DERR_OUTOFVIDEOMEMORY
;
831 hr
= cubetexture_init(object
, device
, edge_length
, levels
, usage
, format
, pool
);
834 WARN("Failed to initialize cube texture, hr %#x.\n", hr
);
835 HeapFree(GetProcessHeap(), 0, object
);
839 TRACE("Created cube texture %p.\n", object
);
840 *texture
= (IDirect3DCubeTexture8
*)&object
->IDirect3DBaseTexture8_iface
;
845 static HRESULT WINAPI
d3d8_device_CreateVertexBuffer(IDirect3DDevice8
*iface
, UINT size
,
846 DWORD usage
, DWORD fvf
, D3DPOOL pool
, IDirect3DVertexBuffer8
**buffer
)
848 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
849 struct d3d8_vertexbuffer
*object
;
852 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p.\n",
853 iface
, size
, usage
, fvf
, pool
, buffer
);
855 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
857 return D3DERR_OUTOFVIDEOMEMORY
;
859 hr
= vertexbuffer_init(object
, device
, size
, usage
, fvf
, pool
);
862 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr
);
863 HeapFree(GetProcessHeap(), 0, object
);
867 TRACE("Created vertex buffer %p.\n", object
);
868 *buffer
= &object
->IDirect3DVertexBuffer8_iface
;
873 static HRESULT WINAPI
d3d8_device_CreateIndexBuffer(IDirect3DDevice8
*iface
, UINT size
,
874 DWORD usage
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DIndexBuffer8
**buffer
)
876 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
877 struct d3d8_indexbuffer
*object
;
880 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p.\n",
881 iface
, size
, usage
, format
, pool
, buffer
);
883 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
885 return D3DERR_OUTOFVIDEOMEMORY
;
887 hr
= indexbuffer_init(object
, device
, size
, usage
, format
, pool
);
890 WARN("Failed to initialize index buffer, hr %#x.\n", hr
);
891 HeapFree(GetProcessHeap(), 0, object
);
895 TRACE("Created index buffer %p.\n", object
);
896 *buffer
= &object
->IDirect3DIndexBuffer8_iface
;
901 static HRESULT
d3d8_device_create_surface(struct d3d8_device
*device
, UINT width
, UINT height
,
902 D3DFORMAT format
, DWORD flags
, IDirect3DSurface8
**surface
, UINT usage
, D3DPOOL pool
,
903 D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
)
905 struct wined3d_resource
*sub_resource
;
906 struct wined3d_resource_desc desc
;
907 struct d3d8_surface
*surface_impl
;
908 struct wined3d_texture
*texture
;
911 TRACE("device %p, width %u, height %u, format %#x, flags %#x, surface %p,\n"
912 "\tusage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
913 device
, width
, height
, format
, flags
, surface
,
914 usage
, pool
, multisample_type
, multisample_quality
);
916 desc
.resource_type
= WINED3D_RTYPE_TEXTURE
;
917 desc
.format
= wined3dformat_from_d3dformat(format
);
918 desc
.multisample_type
= multisample_type
;
919 desc
.multisample_quality
= multisample_quality
;
920 desc
.usage
= usage
& WINED3DUSAGE_MASK
;
923 desc
.height
= height
;
927 wined3d_mutex_lock();
929 if (FAILED(hr
= wined3d_texture_create(device
->wined3d_device
, &desc
,
930 1, flags
, NULL
, NULL
, &d3d8_null_wined3d_parent_ops
, &texture
)))
932 wined3d_mutex_unlock();
933 WARN("Failed to create texture, hr %#x.\n", hr
);
937 sub_resource
= wined3d_texture_get_sub_resource(texture
, 0);
938 surface_impl
= wined3d_resource_get_parent(sub_resource
);
939 surface_impl
->parent_device
= &device
->IDirect3DDevice8_iface
;
940 *surface
= &surface_impl
->IDirect3DSurface8_iface
;
941 IDirect3DSurface8_AddRef(*surface
);
942 wined3d_texture_decref(texture
);
944 wined3d_mutex_unlock();
949 static HRESULT WINAPI
d3d8_device_CreateRenderTarget(IDirect3DDevice8
*iface
, UINT width
,
950 UINT height
, D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, BOOL lockable
,
951 IDirect3DSurface8
**surface
)
953 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
956 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, lockable %#x, surface %p.\n",
957 iface
, width
, height
, format
, multisample_type
, lockable
, surface
);
961 flags
|= WINED3D_SURFACE_MAPPABLE
;
963 return d3d8_device_create_surface(device
, width
, height
, format
, flags
, surface
,
964 D3DUSAGE_RENDERTARGET
, D3DPOOL_DEFAULT
, multisample_type
, 0);
967 static HRESULT WINAPI
d3d8_device_CreateDepthStencilSurface(IDirect3DDevice8
*iface
,
968 UINT width
, UINT height
, D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
,
969 IDirect3DSurface8
**surface
)
971 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
973 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, surface %p.\n",
974 iface
, width
, height
, format
, multisample_type
, surface
);
978 /* TODO: Verify that Discard is false */
979 return d3d8_device_create_surface(device
, width
, height
, format
, WINED3D_SURFACE_MAPPABLE
,
980 surface
, D3DUSAGE_DEPTHSTENCIL
, D3DPOOL_DEFAULT
, multisample_type
, 0);
983 /* IDirect3DDevice8Impl::CreateImageSurface returns surface with pool type SYSTEMMEM */
984 static HRESULT WINAPI
d3d8_device_CreateImageSurface(IDirect3DDevice8
*iface
, UINT width
,
985 UINT height
, D3DFORMAT format
, IDirect3DSurface8
**surface
)
987 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
989 TRACE("iface %p, width %u, height %u, format %#x, surface %p.\n",
990 iface
, width
, height
, format
, surface
);
994 return d3d8_device_create_surface(device
, width
, height
, format
, WINED3D_SURFACE_MAPPABLE
,
995 surface
, 0, D3DPOOL_SYSTEMMEM
, D3DMULTISAMPLE_NONE
, 0);
998 static HRESULT WINAPI
d3d8_device_CopyRects(IDirect3DDevice8
*iface
,
999 IDirect3DSurface8
*src_surface
, const RECT
*src_rects
, UINT rect_count
,
1000 IDirect3DSurface8
*dst_surface
, const POINT
*dst_points
)
1002 struct d3d8_surface
*src
= unsafe_impl_from_IDirect3DSurface8(src_surface
);
1003 struct d3d8_surface
*dst
= unsafe_impl_from_IDirect3DSurface8(dst_surface
);
1004 enum wined3d_format_id src_format
, dst_format
;
1005 struct wined3d_resource_desc wined3d_desc
;
1006 struct wined3d_resource
*wined3d_resource
;
1009 TRACE("iface %p, src_surface %p, src_rects %p, rect_count %u, dst_surface %p, dst_points %p.\n",
1010 iface
, src_surface
, src_rects
, rect_count
, dst_surface
, dst_points
);
1012 /* Check that the source texture is in WINED3D_POOL_SYSTEM_MEM and the
1013 * destination texture is in WINED3D_POOL_DEFAULT. */
1015 wined3d_mutex_lock();
1016 wined3d_resource
= wined3d_surface_get_resource(src
->wined3d_surface
);
1017 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
1018 if (wined3d_desc
.usage
& WINED3DUSAGE_DEPTHSTENCIL
)
1020 WARN("Source %p is a depth stencil surface, returning D3DERR_INVALIDCALL.\n", src_surface
);
1021 wined3d_mutex_unlock();
1022 return D3DERR_INVALIDCALL
;
1024 src_format
= wined3d_desc
.format
;
1025 src_w
= wined3d_desc
.width
;
1026 src_h
= wined3d_desc
.height
;
1028 wined3d_resource
= wined3d_surface_get_resource(dst
->wined3d_surface
);
1029 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
1030 if (wined3d_desc
.usage
& WINED3DUSAGE_DEPTHSTENCIL
)
1032 WARN("Destination %p is a depth stencil surface, returning D3DERR_INVALIDCALL.\n", dst_surface
);
1033 wined3d_mutex_unlock();
1034 return D3DERR_INVALIDCALL
;
1036 dst_format
= wined3d_desc
.format
;
1038 /* Check that the source and destination formats match */
1039 if (src_format
!= dst_format
)
1041 WARN("Source %p format must match the destination %p format, returning D3DERR_INVALIDCALL.\n",
1042 src_surface
, dst_surface
);
1043 wined3d_mutex_unlock();
1044 return D3DERR_INVALIDCALL
;
1047 /* Quick if complete copy ... */
1048 if (!rect_count
&& !src_rects
&& !dst_points
)
1050 RECT rect
= {0, 0, src_w
, src_h
};
1051 wined3d_surface_blt(dst
->wined3d_surface
, &rect
,
1052 src
->wined3d_surface
, &rect
, 0, NULL
, WINED3D_TEXF_POINT
);
1057 /* Copy rect by rect */
1058 if (src_rects
&& dst_points
)
1060 for (i
= 0; i
< rect_count
; ++i
)
1062 UINT w
= src_rects
[i
].right
- src_rects
[i
].left
;
1063 UINT h
= src_rects
[i
].bottom
- src_rects
[i
].top
;
1064 RECT dst_rect
= {dst_points
[i
].x
, dst_points
[i
].y
,
1065 dst_points
[i
].x
+ w
, dst_points
[i
].y
+ h
};
1067 wined3d_surface_blt(dst
->wined3d_surface
, &dst_rect
,
1068 src
->wined3d_surface
, &src_rects
[i
], 0, NULL
, WINED3D_TEXF_POINT
);
1073 for (i
= 0; i
< rect_count
; ++i
)
1075 UINT w
= src_rects
[i
].right
- src_rects
[i
].left
;
1076 UINT h
= src_rects
[i
].bottom
- src_rects
[i
].top
;
1077 RECT dst_rect
= {0, 0, w
, h
};
1079 wined3d_surface_blt(dst
->wined3d_surface
, &dst_rect
,
1080 src
->wined3d_surface
, &src_rects
[i
], 0, NULL
, WINED3D_TEXF_POINT
);
1084 wined3d_mutex_unlock();
1089 static HRESULT WINAPI
d3d8_device_UpdateTexture(IDirect3DDevice8
*iface
,
1090 IDirect3DBaseTexture8
*src_texture
, IDirect3DBaseTexture8
*dst_texture
)
1092 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1093 struct d3d8_texture
*src_impl
, *dst_impl
;
1096 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface
, src_texture
, dst_texture
);
1098 src_impl
= unsafe_impl_from_IDirect3DBaseTexture8(src_texture
);
1099 dst_impl
= unsafe_impl_from_IDirect3DBaseTexture8(dst_texture
);
1101 wined3d_mutex_lock();
1102 hr
= wined3d_device_update_texture(device
->wined3d_device
,
1103 src_impl
->wined3d_texture
, dst_impl
->wined3d_texture
);
1104 wined3d_mutex_unlock();
1109 static HRESULT WINAPI
d3d8_device_GetFrontBuffer(IDirect3DDevice8
*iface
, IDirect3DSurface8
*dst_surface
)
1111 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1112 struct d3d8_surface
*dst_impl
= unsafe_impl_from_IDirect3DSurface8(dst_surface
);
1115 TRACE("iface %p, dst_surface %p.\n", iface
, dst_surface
);
1119 WARN("Invalid destination surface passed.\n");
1120 return D3DERR_INVALIDCALL
;
1123 wined3d_mutex_lock();
1124 hr
= wined3d_device_get_front_buffer_data(device
->wined3d_device
, 0, dst_impl
->wined3d_surface
);
1125 wined3d_mutex_unlock();
1130 static HRESULT WINAPI
d3d8_device_SetRenderTarget(IDirect3DDevice8
*iface
,
1131 IDirect3DSurface8
*render_target
, IDirect3DSurface8
*depth_stencil
)
1133 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1134 struct d3d8_surface
*rt_impl
= unsafe_impl_from_IDirect3DSurface8(render_target
);
1135 struct d3d8_surface
*ds_impl
= unsafe_impl_from_IDirect3DSurface8(depth_stencil
);
1136 struct wined3d_rendertarget_view
*original_dsv
;
1137 HRESULT hr
= D3D_OK
;
1139 TRACE("iface %p, render_target %p, depth_stencil %p.\n", iface
, render_target
, depth_stencil
);
1141 wined3d_mutex_lock();
1145 struct wined3d_rendertarget_view
*original_rtv
;
1146 struct wined3d_resource_desc ds_desc
, rt_desc
;
1147 struct wined3d_resource
*wined3d_resource
;
1148 struct d3d8_surface
*original_surface
;
1150 /* If no render target is passed in check the size against the current RT */
1154 if (!(original_rtv
= wined3d_device_get_rendertarget_view(device
->wined3d_device
, 0)))
1156 wined3d_mutex_unlock();
1157 return D3DERR_NOTFOUND
;
1159 original_surface
= wined3d_rendertarget_view_get_sub_resource_parent(original_rtv
);
1160 wined3d_resource
= wined3d_surface_get_resource(original_surface
->wined3d_surface
);
1163 wined3d_resource
= wined3d_surface_get_resource(rt_impl
->wined3d_surface
);
1164 wined3d_resource_get_desc(wined3d_resource
, &rt_desc
);
1166 wined3d_resource
= wined3d_surface_get_resource(ds_impl
->wined3d_surface
);
1167 wined3d_resource_get_desc(wined3d_resource
, &ds_desc
);
1169 if (ds_desc
.width
< rt_desc
.width
|| ds_desc
.height
< rt_desc
.height
)
1171 WARN("Depth stencil is smaller than the render target, returning D3DERR_INVALIDCALL\n");
1172 wined3d_mutex_unlock();
1173 return D3DERR_INVALIDCALL
;
1175 if (ds_desc
.multisample_type
!= rt_desc
.multisample_type
1176 || ds_desc
.multisample_quality
!= rt_desc
.multisample_quality
)
1178 WARN("Multisample settings do not match, returing D3DERR_INVALIDCALL\n");
1179 wined3d_mutex_unlock();
1180 return D3DERR_INVALIDCALL
;
1185 original_dsv
= wined3d_device_get_depth_stencil_view(device
->wined3d_device
);
1186 wined3d_device_set_depth_stencil_view(device
->wined3d_device
,
1187 ds_impl
? d3d8_surface_get_rendertarget_view(ds_impl
) : NULL
);
1188 if (render_target
&& FAILED(hr
= wined3d_device_set_rendertarget_view(device
->wined3d_device
, 0,
1189 d3d8_surface_get_rendertarget_view(rt_impl
), TRUE
)))
1190 wined3d_device_set_depth_stencil_view(device
->wined3d_device
, original_dsv
);
1192 wined3d_mutex_unlock();
1197 static HRESULT WINAPI
d3d8_device_GetRenderTarget(IDirect3DDevice8
*iface
, IDirect3DSurface8
**render_target
)
1199 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1200 struct wined3d_rendertarget_view
*wined3d_rtv
;
1201 struct d3d8_surface
*surface_impl
;
1204 TRACE("iface %p, render_target %p.\n", iface
, render_target
);
1207 return D3DERR_INVALIDCALL
;
1209 wined3d_mutex_lock();
1210 if ((wined3d_rtv
= wined3d_device_get_rendertarget_view(device
->wined3d_device
, 0)))
1212 /* We want the sub resource parent here, since the view itself may be
1213 * internal to wined3d and may not have a parent. */
1214 surface_impl
= wined3d_rendertarget_view_get_sub_resource_parent(wined3d_rtv
);
1215 *render_target
= &surface_impl
->IDirect3DSurface8_iface
;
1216 IDirect3DSurface8_AddRef(*render_target
);
1221 ERR("Failed to get wined3d render target.\n");
1222 *render_target
= NULL
;
1223 hr
= D3DERR_NOTFOUND
;
1225 wined3d_mutex_unlock();
1230 static HRESULT WINAPI
d3d8_device_GetDepthStencilSurface(IDirect3DDevice8
*iface
, IDirect3DSurface8
**depth_stencil
)
1232 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1233 struct wined3d_rendertarget_view
*wined3d_dsv
;
1234 struct d3d8_surface
*surface_impl
;
1235 HRESULT hr
= D3D_OK
;
1237 TRACE("iface %p, depth_stencil %p.\n", iface
, depth_stencil
);
1240 return D3DERR_INVALIDCALL
;
1242 wined3d_mutex_lock();
1243 if ((wined3d_dsv
= wined3d_device_get_depth_stencil_view(device
->wined3d_device
)))
1245 /* We want the sub resource parent here, since the view itself may be
1246 * internal to wined3d and may not have a parent. */
1247 surface_impl
= wined3d_rendertarget_view_get_sub_resource_parent(wined3d_dsv
);
1248 *depth_stencil
= &surface_impl
->IDirect3DSurface8_iface
;
1249 IDirect3DSurface8_AddRef(*depth_stencil
);
1253 hr
= WINED3DERR_NOTFOUND
;
1254 *depth_stencil
= NULL
;
1256 wined3d_mutex_unlock();
1261 static HRESULT WINAPI
d3d8_device_BeginScene(IDirect3DDevice8
*iface
)
1263 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1266 TRACE("iface %p.\n", iface
);
1268 wined3d_mutex_lock();
1269 hr
= wined3d_device_begin_scene(device
->wined3d_device
);
1270 wined3d_mutex_unlock();
1275 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d8_device_EndScene(IDirect3DDevice8
*iface
)
1277 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1280 TRACE("iface %p.\n", iface
);
1282 wined3d_mutex_lock();
1283 hr
= wined3d_device_end_scene(device
->wined3d_device
);
1284 wined3d_mutex_unlock();
1289 static HRESULT WINAPI
d3d8_device_Clear(IDirect3DDevice8
*iface
, DWORD rect_count
,
1290 const D3DRECT
*rects
, DWORD flags
, D3DCOLOR color
, float z
, DWORD stencil
)
1292 const struct wined3d_color c
=
1294 ((color
>> 16) & 0xff) / 255.0f
,
1295 ((color
>> 8) & 0xff) / 255.0f
,
1296 (color
& 0xff) / 255.0f
,
1297 ((color
>> 24) & 0xff) / 255.0f
,
1299 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1302 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1303 iface
, rect_count
, rects
, flags
, color
, z
, stencil
);
1305 wined3d_mutex_lock();
1306 hr
= wined3d_device_clear(device
->wined3d_device
, rect_count
, (const RECT
*)rects
, flags
, &c
, z
, stencil
);
1307 wined3d_mutex_unlock();
1312 static HRESULT WINAPI
d3d8_device_SetTransform(IDirect3DDevice8
*iface
,
1313 D3DTRANSFORMSTATETYPE state
, const D3DMATRIX
*matrix
)
1315 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1317 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1319 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1320 wined3d_mutex_lock();
1321 wined3d_device_set_transform(device
->wined3d_device
, state
, (const struct wined3d_matrix
*)matrix
);
1322 wined3d_mutex_unlock();
1327 static HRESULT WINAPI
d3d8_device_GetTransform(IDirect3DDevice8
*iface
,
1328 D3DTRANSFORMSTATETYPE state
, D3DMATRIX
*matrix
)
1330 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1332 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1334 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1335 wined3d_mutex_lock();
1336 wined3d_device_get_transform(device
->wined3d_device
, state
, (struct wined3d_matrix
*)matrix
);
1337 wined3d_mutex_unlock();
1342 static HRESULT WINAPI
d3d8_device_MultiplyTransform(IDirect3DDevice8
*iface
,
1343 D3DTRANSFORMSTATETYPE state
, const D3DMATRIX
*matrix
)
1345 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1347 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1349 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1350 wined3d_mutex_lock();
1351 wined3d_device_multiply_transform(device
->wined3d_device
, state
, (const struct wined3d_matrix
*)matrix
);
1352 wined3d_mutex_unlock();
1357 static HRESULT WINAPI
d3d8_device_SetViewport(IDirect3DDevice8
*iface
, const D3DVIEWPORT8
*viewport
)
1359 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1361 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
1363 /* Note: D3DVIEWPORT8 is compatible with struct wined3d_viewport. */
1364 wined3d_mutex_lock();
1365 wined3d_device_set_viewport(device
->wined3d_device
, (const struct wined3d_viewport
*)viewport
);
1366 wined3d_mutex_unlock();
1371 static HRESULT WINAPI
d3d8_device_GetViewport(IDirect3DDevice8
*iface
, D3DVIEWPORT8
*viewport
)
1373 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1375 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
1377 /* Note: D3DVIEWPORT8 is compatible with struct wined3d_viewport. */
1378 wined3d_mutex_lock();
1379 wined3d_device_get_viewport(device
->wined3d_device
, (struct wined3d_viewport
*)viewport
);
1380 wined3d_mutex_unlock();
1385 static HRESULT WINAPI
d3d8_device_SetMaterial(IDirect3DDevice8
*iface
, const D3DMATERIAL8
*material
)
1387 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1389 TRACE("iface %p, material %p.\n", iface
, material
);
1391 /* Note: D3DMATERIAL8 is compatible with struct wined3d_material. */
1392 wined3d_mutex_lock();
1393 wined3d_device_set_material(device
->wined3d_device
, (const struct wined3d_material
*)material
);
1394 wined3d_mutex_unlock();
1399 static HRESULT WINAPI
d3d8_device_GetMaterial(IDirect3DDevice8
*iface
, D3DMATERIAL8
*material
)
1401 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1403 TRACE("iface %p, material %p.\n", iface
, material
);
1405 /* Note: D3DMATERIAL8 is compatible with struct wined3d_material. */
1406 wined3d_mutex_lock();
1407 wined3d_device_get_material(device
->wined3d_device
, (struct wined3d_material
*)material
);
1408 wined3d_mutex_unlock();
1413 static HRESULT WINAPI
d3d8_device_SetLight(IDirect3DDevice8
*iface
, DWORD index
, const D3DLIGHT8
*light
)
1415 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1418 TRACE("iface %p, index %u, light %p.\n", iface
, index
, light
);
1420 /* Note: D3DLIGHT8 is compatible with struct wined3d_light. */
1421 wined3d_mutex_lock();
1422 hr
= wined3d_device_set_light(device
->wined3d_device
, index
, (const struct wined3d_light
*)light
);
1423 wined3d_mutex_unlock();
1428 static HRESULT WINAPI
d3d8_device_GetLight(IDirect3DDevice8
*iface
, DWORD index
, D3DLIGHT8
*light
)
1430 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1433 TRACE("iface %p, index %u, light %p.\n", iface
, index
, light
);
1435 /* Note: D3DLIGHT8 is compatible with struct wined3d_light. */
1436 wined3d_mutex_lock();
1437 hr
= wined3d_device_get_light(device
->wined3d_device
, index
, (struct wined3d_light
*)light
);
1438 wined3d_mutex_unlock();
1443 static HRESULT WINAPI
d3d8_device_LightEnable(IDirect3DDevice8
*iface
, DWORD index
, BOOL enable
)
1445 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1448 TRACE("iface %p, index %u, enable %#x.\n", iface
, index
, enable
);
1450 wined3d_mutex_lock();
1451 hr
= wined3d_device_set_light_enable(device
->wined3d_device
, index
, enable
);
1452 wined3d_mutex_unlock();
1457 static HRESULT WINAPI
d3d8_device_GetLightEnable(IDirect3DDevice8
*iface
, DWORD index
, BOOL
*enable
)
1459 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1462 TRACE("iface %p, index %u, enable %p.\n", iface
, index
, enable
);
1464 wined3d_mutex_lock();
1465 hr
= wined3d_device_get_light_enable(device
->wined3d_device
, index
, enable
);
1466 wined3d_mutex_unlock();
1471 static HRESULT WINAPI
d3d8_device_SetClipPlane(IDirect3DDevice8
*iface
, DWORD index
, const float *plane
)
1473 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1476 TRACE("iface %p, index %u, plane %p.\n", iface
, index
, plane
);
1478 wined3d_mutex_lock();
1479 hr
= wined3d_device_set_clip_plane(device
->wined3d_device
, index
, (const struct wined3d_vec4
*)plane
);
1480 wined3d_mutex_unlock();
1485 static HRESULT WINAPI
d3d8_device_GetClipPlane(IDirect3DDevice8
*iface
, DWORD index
, float *plane
)
1487 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1490 TRACE("iface %p, index %u, plane %p.\n", iface
, index
, plane
);
1492 wined3d_mutex_lock();
1493 hr
= wined3d_device_get_clip_plane(device
->wined3d_device
, index
, (struct wined3d_vec4
*)plane
);
1494 wined3d_mutex_unlock();
1499 static HRESULT WINAPI
d3d8_device_SetRenderState(IDirect3DDevice8
*iface
,
1500 D3DRENDERSTATETYPE state
, DWORD value
)
1502 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1504 TRACE("iface %p, state %#x, value %#x.\n", iface
, state
, value
);
1506 wined3d_mutex_lock();
1510 wined3d_device_set_render_state(device
->wined3d_device
, WINED3D_RS_DEPTHBIAS
, value
);
1514 wined3d_device_set_render_state(device
->wined3d_device
, state
, value
);
1516 wined3d_mutex_unlock();
1521 static HRESULT WINAPI
d3d8_device_GetRenderState(IDirect3DDevice8
*iface
,
1522 D3DRENDERSTATETYPE state
, DWORD
*value
)
1524 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1526 TRACE("iface %p, state %#x, value %p.\n", iface
, state
, value
);
1528 wined3d_mutex_lock();
1532 *value
= wined3d_device_get_render_state(device
->wined3d_device
, WINED3D_RS_DEPTHBIAS
);
1536 *value
= wined3d_device_get_render_state(device
->wined3d_device
, state
);
1538 wined3d_mutex_unlock();
1543 static HRESULT WINAPI
d3d8_device_BeginStateBlock(IDirect3DDevice8
*iface
)
1545 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1548 TRACE("iface %p.\n", iface
);
1550 wined3d_mutex_lock();
1551 hr
= wined3d_device_begin_stateblock(device
->wined3d_device
);
1552 wined3d_mutex_unlock();
1557 static HRESULT WINAPI
d3d8_device_EndStateBlock(IDirect3DDevice8
*iface
, DWORD
*token
)
1559 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1560 struct wined3d_stateblock
*stateblock
;
1563 TRACE("iface %p, token %p.\n", iface
, token
);
1565 /* Tell wineD3D to endstateblock before anything else (in case we run out
1566 * of memory later and cause locking problems)
1568 wined3d_mutex_lock();
1569 hr
= wined3d_device_end_stateblock(device
->wined3d_device
, &stateblock
);
1572 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
1573 wined3d_mutex_unlock();
1577 *token
= d3d8_allocate_handle(&device
->handle_table
, stateblock
, D3D8_HANDLE_SB
);
1578 wined3d_mutex_unlock();
1580 if (*token
== D3D8_INVALID_HANDLE
)
1582 ERR("Failed to create a handle\n");
1583 wined3d_mutex_lock();
1584 wined3d_stateblock_decref(stateblock
);
1585 wined3d_mutex_unlock();
1590 TRACE("Returning %#x (%p).\n", *token
, stateblock
);
1595 static HRESULT WINAPI
d3d8_device_ApplyStateBlock(IDirect3DDevice8
*iface
, DWORD token
)
1597 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1598 struct wined3d_stateblock
*stateblock
;
1600 TRACE("iface %p, token %#x.\n", iface
, token
);
1605 wined3d_mutex_lock();
1606 stateblock
= d3d8_get_object(&device
->handle_table
, token
- 1, D3D8_HANDLE_SB
);
1609 WARN("Invalid handle (%#x) passed.\n", token
);
1610 wined3d_mutex_unlock();
1611 return D3DERR_INVALIDCALL
;
1613 wined3d_stateblock_apply(stateblock
);
1614 wined3d_mutex_unlock();
1619 static HRESULT WINAPI
d3d8_device_CaptureStateBlock(IDirect3DDevice8
*iface
, DWORD token
)
1621 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1622 struct wined3d_stateblock
*stateblock
;
1624 TRACE("iface %p, token %#x.\n", iface
, token
);
1626 wined3d_mutex_lock();
1627 stateblock
= d3d8_get_object(&device
->handle_table
, token
- 1, D3D8_HANDLE_SB
);
1630 WARN("Invalid handle (%#x) passed.\n", token
);
1631 wined3d_mutex_unlock();
1632 return D3DERR_INVALIDCALL
;
1634 wined3d_stateblock_capture(stateblock
);
1635 wined3d_mutex_unlock();
1640 static HRESULT WINAPI
d3d8_device_DeleteStateBlock(IDirect3DDevice8
*iface
, DWORD token
)
1642 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1643 struct wined3d_stateblock
*stateblock
;
1645 TRACE("iface %p, token %#x.\n", iface
, token
);
1647 wined3d_mutex_lock();
1648 stateblock
= d3d8_free_handle(&device
->handle_table
, token
- 1, D3D8_HANDLE_SB
);
1652 WARN("Invalid handle (%#x) passed.\n", token
);
1653 wined3d_mutex_unlock();
1654 return D3DERR_INVALIDCALL
;
1657 if (wined3d_stateblock_decref(stateblock
))
1659 ERR("Stateblock %p has references left, this shouldn't happen.\n", stateblock
);
1661 wined3d_mutex_unlock();
1666 static HRESULT WINAPI
d3d8_device_CreateStateBlock(IDirect3DDevice8
*iface
,
1667 D3DSTATEBLOCKTYPE type
, DWORD
*handle
)
1669 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1670 struct wined3d_stateblock
*stateblock
;
1673 TRACE("iface %p, type %#x, handle %p.\n", iface
, type
, handle
);
1675 if (type
!= D3DSBT_ALL
1676 && type
!= D3DSBT_PIXELSTATE
1677 && type
!= D3DSBT_VERTEXSTATE
)
1679 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1680 return D3DERR_INVALIDCALL
;
1683 wined3d_mutex_lock();
1684 hr
= wined3d_stateblock_create(device
->wined3d_device
, (enum wined3d_stateblock_type
)type
, &stateblock
);
1687 wined3d_mutex_unlock();
1688 ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr
);
1692 *handle
= d3d8_allocate_handle(&device
->handle_table
, stateblock
, D3D8_HANDLE_SB
);
1693 wined3d_mutex_unlock();
1695 if (*handle
== D3D8_INVALID_HANDLE
)
1697 ERR("Failed to allocate a handle.\n");
1698 wined3d_mutex_lock();
1699 wined3d_stateblock_decref(stateblock
);
1700 wined3d_mutex_unlock();
1705 TRACE("Returning %#x (%p).\n", *handle
, stateblock
);
1710 static HRESULT WINAPI
d3d8_device_SetClipStatus(IDirect3DDevice8
*iface
, const D3DCLIPSTATUS8
*clip_status
)
1712 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1715 TRACE("iface %p, clip_status %p.\n", iface
, clip_status
);
1716 /* FIXME: Verify that D3DCLIPSTATUS8 ~= struct wined3d_clip_status. */
1718 wined3d_mutex_lock();
1719 hr
= wined3d_device_set_clip_status(device
->wined3d_device
, (const struct wined3d_clip_status
*)clip_status
);
1720 wined3d_mutex_unlock();
1725 static HRESULT WINAPI
d3d8_device_GetClipStatus(IDirect3DDevice8
*iface
, D3DCLIPSTATUS8
*clip_status
)
1727 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1730 TRACE("iface %p, clip_status %p.\n", iface
, clip_status
);
1732 wined3d_mutex_lock();
1733 hr
= wined3d_device_get_clip_status(device
->wined3d_device
, (struct wined3d_clip_status
*)clip_status
);
1734 wined3d_mutex_unlock();
1739 static HRESULT WINAPI
d3d8_device_GetTexture(IDirect3DDevice8
*iface
, DWORD stage
, IDirect3DBaseTexture8
**texture
)
1741 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1742 struct wined3d_texture
*wined3d_texture
;
1743 struct d3d8_texture
*texture_impl
;
1745 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
1748 return D3DERR_INVALIDCALL
;
1750 wined3d_mutex_lock();
1751 if ((wined3d_texture
= wined3d_device_get_texture(device
->wined3d_device
, stage
)))
1753 texture_impl
= wined3d_texture_get_parent(wined3d_texture
);
1754 *texture
= &texture_impl
->IDirect3DBaseTexture8_iface
;
1755 IDirect3DBaseTexture8_AddRef(*texture
);
1761 wined3d_mutex_unlock();
1766 static HRESULT WINAPI
d3d8_device_SetTexture(IDirect3DDevice8
*iface
, DWORD stage
, IDirect3DBaseTexture8
*texture
)
1768 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1769 struct d3d8_texture
*texture_impl
;
1772 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
1774 texture_impl
= unsafe_impl_from_IDirect3DBaseTexture8(texture
);
1776 wined3d_mutex_lock();
1777 hr
= wined3d_device_set_texture(device
->wined3d_device
, stage
,
1778 texture_impl
? texture_impl
->wined3d_texture
: NULL
);
1779 wined3d_mutex_unlock();
1784 static const struct tss_lookup
1787 enum wined3d_texture_stage_state state
;
1791 {FALSE
, WINED3D_TSS_INVALID
}, /* 0, unused */
1792 {FALSE
, WINED3D_TSS_COLOR_OP
}, /* 1, D3DTSS_COLOROP */
1793 {FALSE
, WINED3D_TSS_COLOR_ARG1
}, /* 2, D3DTSS_COLORARG1 */
1794 {FALSE
, WINED3D_TSS_COLOR_ARG2
}, /* 3, D3DTSS_COLORARG2 */
1795 {FALSE
, WINED3D_TSS_ALPHA_OP
}, /* 4, D3DTSS_ALPHAOP */
1796 {FALSE
, WINED3D_TSS_ALPHA_ARG1
}, /* 5, D3DTSS_ALPHAARG1 */
1797 {FALSE
, WINED3D_TSS_ALPHA_ARG2
}, /* 6, D3DTSS_ALPHAARG2 */
1798 {FALSE
, WINED3D_TSS_BUMPENV_MAT00
}, /* 7, D3DTSS_BUMPENVMAT00 */
1799 {FALSE
, WINED3D_TSS_BUMPENV_MAT01
}, /* 8, D3DTSS_BUMPENVMAT01 */
1800 {FALSE
, WINED3D_TSS_BUMPENV_MAT10
}, /* 9, D3DTSS_BUMPENVMAT10 */
1801 {FALSE
, WINED3D_TSS_BUMPENV_MAT11
}, /* 10, D3DTSS_BUMPENVMAT11 */
1802 {FALSE
, WINED3D_TSS_TEXCOORD_INDEX
}, /* 11, D3DTSS_TEXCOORDINDEX */
1803 {FALSE
, WINED3D_TSS_INVALID
}, /* 12, unused */
1804 {TRUE
, WINED3D_SAMP_ADDRESS_U
}, /* 13, D3DTSS_ADDRESSU */
1805 {TRUE
, WINED3D_SAMP_ADDRESS_V
}, /* 14, D3DTSS_ADDRESSV */
1806 {TRUE
, WINED3D_SAMP_BORDER_COLOR
}, /* 15, D3DTSS_BORDERCOLOR */
1807 {TRUE
, WINED3D_SAMP_MAG_FILTER
}, /* 16, D3DTSS_MAGFILTER */
1808 {TRUE
, WINED3D_SAMP_MIN_FILTER
}, /* 17, D3DTSS_MINFILTER */
1809 {TRUE
, WINED3D_SAMP_MIP_FILTER
}, /* 18, D3DTSS_MIPFILTER */
1810 {TRUE
, WINED3D_SAMP_MIPMAP_LOD_BIAS
}, /* 19, D3DTSS_MIPMAPLODBIAS */
1811 {TRUE
, WINED3D_SAMP_MAX_MIP_LEVEL
}, /* 20, D3DTSS_MAXMIPLEVEL */
1812 {TRUE
, WINED3D_SAMP_MAX_ANISOTROPY
}, /* 21, D3DTSS_MAXANISOTROPY */
1813 {FALSE
, WINED3D_TSS_BUMPENV_LSCALE
}, /* 22, D3DTSS_BUMPENVLSCALE */
1814 {FALSE
, WINED3D_TSS_BUMPENV_LOFFSET
}, /* 23, D3DTSS_BUMPENVLOFFSET */
1815 {FALSE
, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1816 {TRUE
, WINED3D_SAMP_ADDRESS_W
}, /* 25, D3DTSS_ADDRESSW */
1817 {FALSE
, WINED3D_TSS_COLOR_ARG0
}, /* 26, D3DTSS_COLORARG0 */
1818 {FALSE
, WINED3D_TSS_ALPHA_ARG0
}, /* 27, D3DTSS_ALPHAARG0 */
1819 {FALSE
, WINED3D_TSS_RESULT_ARG
}, /* 28, D3DTSS_RESULTARG */
1822 static HRESULT WINAPI
d3d8_device_GetTextureStageState(IDirect3DDevice8
*iface
,
1823 DWORD stage
, D3DTEXTURESTAGESTATETYPE Type
, DWORD
*value
)
1825 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1826 const struct tss_lookup
*l
;
1828 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface
, stage
, Type
, value
);
1830 if (Type
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
1832 WARN("Invalid Type %#x passed.\n", Type
);
1836 l
= &tss_lookup
[Type
];
1838 wined3d_mutex_lock();
1839 if (l
->sampler_state
)
1840 *value
= wined3d_device_get_sampler_state(device
->wined3d_device
, stage
, l
->state
);
1842 *value
= wined3d_device_get_texture_stage_state(device
->wined3d_device
, stage
, l
->state
);
1843 wined3d_mutex_unlock();
1848 static HRESULT WINAPI
d3d8_device_SetTextureStageState(IDirect3DDevice8
*iface
,
1849 DWORD stage
, D3DTEXTURESTAGESTATETYPE type
, DWORD value
)
1851 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1852 const struct tss_lookup
*l
;
1854 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface
, stage
, type
, value
);
1856 if (type
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
1858 WARN("Invalid type %#x passed.\n", type
);
1862 l
= &tss_lookup
[type
];
1864 wined3d_mutex_lock();
1865 if (l
->sampler_state
)
1866 wined3d_device_set_sampler_state(device
->wined3d_device
, stage
, l
->state
, value
);
1868 wined3d_device_set_texture_stage_state(device
->wined3d_device
, stage
, l
->state
, value
);
1869 wined3d_mutex_unlock();
1874 static HRESULT WINAPI
d3d8_device_ValidateDevice(IDirect3DDevice8
*iface
, DWORD
*pass_count
)
1876 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1879 TRACE("iface %p, pass_count %p.\n", iface
, pass_count
);
1881 wined3d_mutex_lock();
1882 hr
= wined3d_device_validate_device(device
->wined3d_device
, pass_count
);
1883 wined3d_mutex_unlock();
1888 static HRESULT WINAPI
d3d8_device_GetInfo(IDirect3DDevice8
*iface
,
1889 DWORD info_id
, void *info
, DWORD info_size
)
1891 FIXME("iface %p, info_id %#x, info %p, info_size %u stub!\n", iface
, info_id
, info
, info_size
);
1896 static HRESULT WINAPI
d3d8_device_SetPaletteEntries(IDirect3DDevice8
*iface
,
1897 UINT palette_idx
, const PALETTEENTRY
*entries
)
1899 WARN("iface %p, palette_idx %u, entries %p unimplemented\n", iface
, palette_idx
, entries
);
1901 /* GPUs stopped supporting palettized textures with the Shader Model 1 generation. Wined3d
1902 * does not have a d3d8/9-style palette API */
1907 static HRESULT WINAPI
d3d8_device_GetPaletteEntries(IDirect3DDevice8
*iface
,
1908 UINT palette_idx
, PALETTEENTRY
*entries
)
1910 FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface
, palette_idx
, entries
);
1912 return D3DERR_INVALIDCALL
;
1915 static HRESULT WINAPI
d3d8_device_SetCurrentTexturePalette(IDirect3DDevice8
*iface
, UINT palette_idx
)
1917 WARN("iface %p, palette_idx %u unimplemented.\n", iface
, palette_idx
);
1922 static HRESULT WINAPI
d3d8_device_GetCurrentTexturePalette(IDirect3DDevice8
*iface
, UINT
*palette_idx
)
1924 FIXME("iface %p, palette_idx %p unimplemented.\n", iface
, palette_idx
);
1926 return D3DERR_INVALIDCALL
;
1929 static HRESULT WINAPI
d3d8_device_DrawPrimitive(IDirect3DDevice8
*iface
,
1930 D3DPRIMITIVETYPE primitive_type
, UINT start_vertex
, UINT primitive_count
)
1932 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1935 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1936 iface
, primitive_type
, start_vertex
, primitive_count
);
1938 wined3d_mutex_lock();
1939 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
1940 hr
= wined3d_device_draw_primitive(device
->wined3d_device
, start_vertex
,
1941 vertex_count_from_primitive_count(primitive_type
, primitive_count
));
1942 wined3d_mutex_unlock();
1947 static HRESULT WINAPI
d3d8_device_DrawIndexedPrimitive(IDirect3DDevice8
*iface
,
1948 D3DPRIMITIVETYPE primitive_type
, UINT min_vertex_idx
, UINT vertex_count
,
1949 UINT start_idx
, UINT primitive_count
)
1951 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1954 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, start_idx %u, primitive_count %u.\n",
1955 iface
, primitive_type
, min_vertex_idx
, vertex_count
, start_idx
, primitive_count
);
1957 wined3d_mutex_lock();
1958 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
1959 hr
= wined3d_device_draw_indexed_primitive(device
->wined3d_device
, start_idx
,
1960 vertex_count_from_primitive_count(primitive_type
, primitive_count
));
1961 wined3d_mutex_unlock();
1966 /* The caller is responsible for wined3d locking */
1967 static HRESULT
d3d8_device_prepare_vertex_buffer(struct d3d8_device
*device
, UINT min_size
)
1971 if (device
->vertex_buffer_size
< min_size
|| !device
->vertex_buffer
)
1973 UINT size
= max(device
->vertex_buffer_size
* 2, min_size
);
1974 struct wined3d_buffer
*buffer
;
1976 TRACE("Growing vertex buffer to %u bytes\n", size
);
1978 hr
= wined3d_buffer_create_vb(device
->wined3d_device
, size
, WINED3DUSAGE_DYNAMIC
| WINED3DUSAGE_WRITEONLY
,
1979 WINED3D_POOL_DEFAULT
, NULL
, &d3d8_null_wined3d_parent_ops
, &buffer
);
1982 ERR("(%p) wined3d_buffer_create_vb failed with hr = %08x\n", device
, hr
);
1986 if (device
->vertex_buffer
)
1987 wined3d_buffer_decref(device
->vertex_buffer
);
1989 device
->vertex_buffer
= buffer
;
1990 device
->vertex_buffer_size
= size
;
1991 device
->vertex_buffer_pos
= 0;
1996 static HRESULT WINAPI
d3d8_device_DrawPrimitiveUP(IDirect3DDevice8
*iface
,
1997 D3DPRIMITIVETYPE primitive_type
, UINT primitive_count
, const void *data
,
2000 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2002 UINT vtx_count
= vertex_count_from_primitive_count(primitive_type
, primitive_count
);
2003 UINT size
= vtx_count
* stride
;
2007 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
2008 iface
, primitive_type
, primitive_count
, data
, stride
);
2010 if (!primitive_count
)
2012 WARN("primitive_count is 0, returning D3D_OK\n");
2016 wined3d_mutex_lock();
2017 hr
= d3d8_device_prepare_vertex_buffer(device
, size
);
2021 vb_pos
= device
->vertex_buffer_pos
;
2022 align
= vb_pos
% stride
;
2023 if (align
) align
= stride
- align
;
2024 if (vb_pos
+ size
+ align
> device
->vertex_buffer_size
)
2029 hr
= wined3d_buffer_map(device
->vertex_buffer
, vb_pos
, size
, &buffer_data
,
2030 vb_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
);
2033 memcpy(buffer_data
, data
, size
);
2034 wined3d_buffer_unmap(device
->vertex_buffer
);
2035 device
->vertex_buffer_pos
= vb_pos
+ size
;
2037 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, 0, device
->vertex_buffer
, 0, stride
);
2041 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
2042 hr
= wined3d_device_draw_primitive(device
->wined3d_device
, vb_pos
/ stride
, vtx_count
);
2043 wined3d_device_set_stream_source(device
->wined3d_device
, 0, NULL
, 0, 0);
2046 wined3d_mutex_unlock();
2050 /* The caller is responsible for wined3d locking */
2051 static HRESULT
d3d8_device_prepare_index_buffer(struct d3d8_device
*device
, UINT min_size
)
2055 if (device
->index_buffer_size
< min_size
|| !device
->index_buffer
)
2057 UINT size
= max(device
->index_buffer_size
* 2, min_size
);
2058 struct wined3d_buffer
*buffer
;
2060 TRACE("Growing index buffer to %u bytes\n", size
);
2062 hr
= wined3d_buffer_create_ib(device
->wined3d_device
, size
, WINED3DUSAGE_DYNAMIC
| WINED3DUSAGE_WRITEONLY
,
2063 WINED3D_POOL_DEFAULT
, NULL
, &d3d8_null_wined3d_parent_ops
, &buffer
);
2066 ERR("(%p) wined3d_buffer_create_ib failed with hr = %08x\n", device
, hr
);
2070 if (device
->index_buffer
)
2071 wined3d_buffer_decref(device
->index_buffer
);
2073 device
->index_buffer
= buffer
;
2074 device
->index_buffer_size
= size
;
2075 device
->index_buffer_pos
= 0;
2080 static HRESULT WINAPI
d3d8_device_DrawIndexedPrimitiveUP(IDirect3DDevice8
*iface
,
2081 D3DPRIMITIVETYPE primitive_type
, UINT min_vertex_idx
, UINT vertex_count
,
2082 UINT primitive_count
, const void *index_data
, D3DFORMAT index_format
,
2083 const void *vertex_data
, UINT vertex_stride
)
2085 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2089 UINT idx_count
= vertex_count_from_primitive_count(primitive_type
, primitive_count
);
2090 UINT idx_fmt_size
= index_format
== D3DFMT_INDEX16
? 2 : 4;
2091 UINT idx_size
= idx_count
* idx_fmt_size
;
2094 UINT vtx_size
= vertex_count
* vertex_stride
;
2097 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, primitive_count %u,\n"
2098 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
2099 iface
, primitive_type
, min_vertex_idx
, vertex_count
, primitive_count
,
2100 index_data
, index_format
, vertex_data
, vertex_stride
);
2102 if (!primitive_count
)
2104 WARN("primitive_count is 0, returning D3D_OK\n");
2108 wined3d_mutex_lock();
2110 hr
= d3d8_device_prepare_vertex_buffer(device
, vtx_size
);
2114 vb_pos
= device
->vertex_buffer_pos
;
2115 align
= vb_pos
% vertex_stride
;
2116 if (align
) align
= vertex_stride
- align
;
2117 if (vb_pos
+ vtx_size
+ align
> device
->vertex_buffer_size
)
2122 hr
= wined3d_buffer_map(device
->vertex_buffer
, vb_pos
, vtx_size
, &buffer_data
,
2123 vb_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
);
2126 memcpy(buffer_data
, vertex_data
, vtx_size
);
2127 wined3d_buffer_unmap(device
->vertex_buffer
);
2128 device
->vertex_buffer_pos
= vb_pos
+ vtx_size
;
2130 hr
= d3d8_device_prepare_index_buffer(device
, idx_size
);
2134 ib_pos
= device
->index_buffer_pos
;
2135 align
= ib_pos
% idx_fmt_size
;
2136 if (align
) align
= idx_fmt_size
- align
;
2137 if (ib_pos
+ idx_size
+ align
> device
->index_buffer_size
)
2142 hr
= wined3d_buffer_map(device
->index_buffer
, ib_pos
, idx_size
, &buffer_data
,
2143 ib_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
);
2146 memcpy(buffer_data
, index_data
, idx_size
);
2147 wined3d_buffer_unmap(device
->index_buffer
);
2148 device
->index_buffer_pos
= ib_pos
+ idx_size
;
2150 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, 0, device
->vertex_buffer
, 0, vertex_stride
);
2154 wined3d_device_set_index_buffer(device
->wined3d_device
, device
->index_buffer
,
2155 wined3dformat_from_d3dformat(index_format
));
2156 wined3d_device_set_base_vertex_index(device
->wined3d_device
, vb_pos
/ vertex_stride
);
2158 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
2159 hr
= wined3d_device_draw_indexed_primitive(device
->wined3d_device
, ib_pos
/ idx_fmt_size
, idx_count
);
2161 wined3d_device_set_stream_source(device
->wined3d_device
, 0, NULL
, 0, 0);
2162 wined3d_device_set_index_buffer(device
->wined3d_device
, NULL
, WINED3DFMT_UNKNOWN
);
2163 wined3d_device_set_base_vertex_index(device
->wined3d_device
, 0);
2166 wined3d_mutex_unlock();
2170 static HRESULT WINAPI
d3d8_device_ProcessVertices(IDirect3DDevice8
*iface
, UINT src_start_idx
,
2171 UINT dst_idx
, UINT vertex_count
, IDirect3DVertexBuffer8
*dst_buffer
, DWORD flags
)
2173 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2174 struct d3d8_vertexbuffer
*dst
= unsafe_impl_from_IDirect3DVertexBuffer8(dst_buffer
);
2177 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, flags %#x.\n",
2178 iface
, src_start_idx
, dst_idx
, vertex_count
, dst_buffer
, flags
);
2180 wined3d_mutex_lock();
2181 hr
= wined3d_device_process_vertices(device
->wined3d_device
, src_start_idx
, dst_idx
,
2182 vertex_count
, dst
->wined3d_buffer
, NULL
, flags
, dst
->fvf
);
2183 wined3d_mutex_unlock();
2188 static HRESULT WINAPI
d3d8_device_CreateVertexShader(IDirect3DDevice8
*iface
,
2189 const DWORD
*declaration
, const DWORD
*byte_code
, DWORD
*shader
, DWORD usage
)
2191 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2192 struct d3d8_vertex_shader
*object
;
2193 DWORD shader_handle
;
2197 TRACE("iface %p, declaration %p, byte_code %p, shader %p, usage %#x.\n",
2198 iface
, declaration
, byte_code
, shader
, usage
);
2200 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2204 return E_OUTOFMEMORY
;
2207 wined3d_mutex_lock();
2208 handle
= d3d8_allocate_handle(&device
->handle_table
, object
, D3D8_HANDLE_VS
);
2209 wined3d_mutex_unlock();
2210 if (handle
== D3D8_INVALID_HANDLE
)
2212 ERR("Failed to allocate vertex shader handle.\n");
2213 HeapFree(GetProcessHeap(), 0, object
);
2215 return E_OUTOFMEMORY
;
2218 shader_handle
= handle
+ VS_HIGHESTFIXEDFXF
+ 1;
2220 hr
= d3d8_vertex_shader_init(object
, device
, declaration
, byte_code
, shader_handle
, usage
);
2223 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
2224 wined3d_mutex_lock();
2225 d3d8_free_handle(&device
->handle_table
, handle
, D3D8_HANDLE_VS
);
2226 wined3d_mutex_unlock();
2227 HeapFree(GetProcessHeap(), 0, object
);
2232 TRACE("Created vertex shader %p (handle %#x).\n", object
, shader_handle
);
2233 *shader
= shader_handle
;
2238 static struct d3d8_vertex_declaration
*d3d8_device_get_fvf_declaration(struct d3d8_device
*device
, DWORD fvf
)
2240 struct d3d8_vertex_declaration
*d3d8_declaration
;
2241 struct FvfToDecl
*convertedDecls
= device
->decls
;
2242 int p
, low
, high
; /* deliberately signed */
2245 TRACE("Searching for declaration for fvf %08x... ", fvf
);
2248 high
= device
->numConvertedDecls
- 1;
2251 p
= (low
+ high
) >> 1;
2254 if (convertedDecls
[p
].fvf
== fvf
)
2256 TRACE("found %p\n", convertedDecls
[p
].declaration
);
2257 return convertedDecls
[p
].declaration
;
2260 if (convertedDecls
[p
].fvf
< fvf
)
2265 TRACE("not found. Creating and inserting at position %d.\n", low
);
2267 if (!(d3d8_declaration
= HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration
))))
2270 if (FAILED(hr
= d3d8_vertex_declaration_init_fvf(d3d8_declaration
, device
, fvf
)))
2272 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr
);
2273 HeapFree(GetProcessHeap(), 0, d3d8_declaration
);
2277 if (device
->declArraySize
== device
->numConvertedDecls
)
2279 UINT grow
= device
->declArraySize
/ 2;
2281 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
2282 sizeof(*convertedDecls
) * (device
->numConvertedDecls
+ grow
));
2283 if (!convertedDecls
)
2285 d3d8_vertex_declaration_destroy(d3d8_declaration
);
2288 device
->decls
= convertedDecls
;
2289 device
->declArraySize
+= grow
;
2292 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
,
2293 sizeof(*convertedDecls
) * (device
->numConvertedDecls
- low
));
2294 convertedDecls
[low
].declaration
= d3d8_declaration
;
2295 convertedDecls
[low
].fvf
= fvf
;
2296 ++device
->numConvertedDecls
;
2298 TRACE("Returning %p. %u decls in array.\n", d3d8_declaration
, device
->numConvertedDecls
);
2300 return d3d8_declaration
;
2303 static HRESULT WINAPI
d3d8_device_SetVertexShader(IDirect3DDevice8
*iface
, DWORD shader
)
2305 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2306 struct d3d8_vertex_shader
*shader_impl
;
2308 TRACE("iface %p, shader %#x.\n", iface
, shader
);
2310 if (VS_HIGHESTFIXEDFXF
>= shader
)
2312 TRACE("Setting FVF, %#x\n", shader
);
2314 wined3d_mutex_lock();
2315 wined3d_device_set_vertex_declaration(device
->wined3d_device
,
2316 d3d8_device_get_fvf_declaration(device
, shader
)->wined3d_vertex_declaration
);
2317 wined3d_device_set_vertex_shader(device
->wined3d_device
, NULL
);
2318 wined3d_mutex_unlock();
2323 TRACE("Setting shader\n");
2325 wined3d_mutex_lock();
2326 if (!(shader_impl
= d3d8_get_object(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
)))
2328 WARN("Invalid handle (%#x) passed.\n", shader
);
2329 wined3d_mutex_unlock();
2331 return D3DERR_INVALIDCALL
;
2334 wined3d_device_set_vertex_declaration(device
->wined3d_device
,
2335 shader_impl
->vertex_declaration
->wined3d_vertex_declaration
);
2336 wined3d_device_set_vertex_shader(device
->wined3d_device
, shader_impl
->wined3d_shader
);
2337 wined3d_mutex_unlock();
2342 static HRESULT WINAPI
d3d8_device_GetVertexShader(IDirect3DDevice8
*iface
, DWORD
*shader
)
2344 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2345 struct wined3d_vertex_declaration
*wined3d_declaration
;
2346 struct d3d8_vertex_declaration
*d3d8_declaration
;
2348 TRACE("iface %p, shader %p.\n", iface
, shader
);
2350 wined3d_mutex_lock();
2351 if ((wined3d_declaration
= wined3d_device_get_vertex_declaration(device
->wined3d_device
)))
2353 d3d8_declaration
= wined3d_vertex_declaration_get_parent(wined3d_declaration
);
2354 *shader
= d3d8_declaration
->shader_handle
;
2360 wined3d_mutex_unlock();
2362 TRACE("Returning %#x.\n", *shader
);
2367 static HRESULT WINAPI
d3d8_device_DeleteVertexShader(IDirect3DDevice8
*iface
, DWORD shader
)
2369 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2370 struct d3d8_vertex_shader
*shader_impl
;
2372 TRACE("iface %p, shader %#x.\n", iface
, shader
);
2374 wined3d_mutex_lock();
2375 if (!(shader_impl
= d3d8_free_handle(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
)))
2377 WARN("Invalid handle (%#x) passed.\n", shader
);
2378 wined3d_mutex_unlock();
2380 return D3DERR_INVALIDCALL
;
2383 if (shader_impl
->wined3d_shader
2384 && wined3d_device_get_vertex_shader(device
->wined3d_device
) == shader_impl
->wined3d_shader
)
2385 IDirect3DDevice8_SetVertexShader(iface
, 0);
2387 wined3d_mutex_unlock();
2389 d3d8_vertex_shader_destroy(shader_impl
);
2394 static HRESULT WINAPI
d3d8_device_SetVertexShaderConstant(IDirect3DDevice8
*iface
,
2395 DWORD start_register
, const void *data
, DWORD count
)
2397 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2400 TRACE("iface %p, start_register %u, data %p, count %u.\n",
2401 iface
, start_register
, data
, count
);
2403 if (start_register
+ count
> D3D8_MAX_VERTEX_SHADER_CONSTANTF
)
2405 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2406 start_register
+ count
, D3D8_MAX_VERTEX_SHADER_CONSTANTF
);
2407 return D3DERR_INVALIDCALL
;
2410 wined3d_mutex_lock();
2411 hr
= wined3d_device_set_vs_consts_f(device
->wined3d_device
, start_register
, data
, count
);
2412 wined3d_mutex_unlock();
2417 static HRESULT WINAPI
d3d8_device_GetVertexShaderConstant(IDirect3DDevice8
*iface
,
2418 DWORD start_register
, void *data
, DWORD count
)
2420 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2423 TRACE("iface %p, start_register %u, data %p, count %u.\n",
2424 iface
, start_register
, data
, count
);
2426 if (start_register
+ count
> D3D8_MAX_VERTEX_SHADER_CONSTANTF
)
2428 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2429 start_register
+ count
, D3D8_MAX_VERTEX_SHADER_CONSTANTF
);
2430 return D3DERR_INVALIDCALL
;
2433 wined3d_mutex_lock();
2434 hr
= wined3d_device_get_vs_consts_f(device
->wined3d_device
, start_register
, data
, count
);
2435 wined3d_mutex_unlock();
2440 static HRESULT WINAPI
d3d8_device_GetVertexShaderDeclaration(IDirect3DDevice8
*iface
,
2441 DWORD shader
, void *data
, DWORD
*data_size
)
2443 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2444 struct d3d8_vertex_declaration
*declaration
;
2445 struct d3d8_vertex_shader
*shader_impl
;
2447 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2448 iface
, shader
, data
, data_size
);
2450 wined3d_mutex_lock();
2451 shader_impl
= d3d8_get_object(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
);
2452 wined3d_mutex_unlock();
2456 WARN("Invalid handle (%#x) passed.\n", shader
);
2457 return D3DERR_INVALIDCALL
;
2459 declaration
= shader_impl
->vertex_declaration
;
2463 *data_size
= declaration
->elements_size
;
2467 /* MSDN claims that if *data_size is smaller than the required size
2468 * we should write the required size and return D3DERR_MOREDATA.
2469 * That's not actually true. */
2470 if (*data_size
< declaration
->elements_size
)
2471 return D3DERR_INVALIDCALL
;
2473 memcpy(data
, declaration
->elements
, declaration
->elements_size
);
2478 static HRESULT WINAPI
d3d8_device_GetVertexShaderFunction(IDirect3DDevice8
*iface
,
2479 DWORD shader
, void *data
, DWORD
*data_size
)
2481 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2482 struct d3d8_vertex_shader
*shader_impl
= NULL
;
2485 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2486 iface
, shader
, data
, data_size
);
2488 wined3d_mutex_lock();
2489 if (!(shader_impl
= d3d8_get_object(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
)))
2491 WARN("Invalid handle (%#x) passed.\n", shader
);
2492 wined3d_mutex_unlock();
2494 return D3DERR_INVALIDCALL
;
2497 if (!shader_impl
->wined3d_shader
)
2499 wined3d_mutex_unlock();
2504 hr
= wined3d_shader_get_byte_code(shader_impl
->wined3d_shader
, data
, data_size
);
2505 wined3d_mutex_unlock();
2510 static HRESULT WINAPI
d3d8_device_SetIndices(IDirect3DDevice8
*iface
,
2511 IDirect3DIndexBuffer8
*buffer
, UINT base_vertex_idx
)
2513 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2514 struct d3d8_indexbuffer
*ib
= unsafe_impl_from_IDirect3DIndexBuffer8(buffer
);
2516 TRACE("iface %p, buffer %p, base_vertex_idx %u.\n", iface
, buffer
, base_vertex_idx
);
2518 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
2519 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
2520 * vertex buffers can't be created to address them with an index that requires the 32nd bit
2521 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
2524 wined3d_mutex_lock();
2525 wined3d_device_set_base_vertex_index(device
->wined3d_device
, base_vertex_idx
);
2526 wined3d_device_set_index_buffer(device
->wined3d_device
,
2527 ib
? ib
->wined3d_buffer
: NULL
,
2528 ib
? ib
->format
: WINED3DFMT_UNKNOWN
);
2529 wined3d_mutex_unlock();
2534 static HRESULT WINAPI
d3d8_device_GetIndices(IDirect3DDevice8
*iface
,
2535 IDirect3DIndexBuffer8
**buffer
, UINT
*base_vertex_index
)
2537 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2538 enum wined3d_format_id wined3d_format
;
2539 struct wined3d_buffer
*wined3d_buffer
;
2540 struct d3d8_indexbuffer
*buffer_impl
;
2542 TRACE("iface %p, buffer %p, base_vertex_index %p.\n", iface
, buffer
, base_vertex_index
);
2545 return D3DERR_INVALIDCALL
;
2547 /* The case from UINT to INT is safe because d3d8 will never set negative values */
2548 wined3d_mutex_lock();
2549 *base_vertex_index
= wined3d_device_get_base_vertex_index(device
->wined3d_device
);
2550 if ((wined3d_buffer
= wined3d_device_get_index_buffer(device
->wined3d_device
, &wined3d_format
)))
2552 buffer_impl
= wined3d_buffer_get_parent(wined3d_buffer
);
2553 *buffer
= &buffer_impl
->IDirect3DIndexBuffer8_iface
;
2554 IDirect3DIndexBuffer8_AddRef(*buffer
);
2560 wined3d_mutex_unlock();
2565 static HRESULT WINAPI
d3d8_device_CreatePixelShader(IDirect3DDevice8
*iface
,
2566 const DWORD
*byte_code
, DWORD
*shader
)
2568 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2569 struct d3d8_pixel_shader
*object
;
2570 DWORD shader_handle
;
2574 TRACE("iface %p, byte_code %p, shader %p.\n", iface
, byte_code
, shader
);
2577 return D3DERR_INVALIDCALL
;
2579 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2581 return E_OUTOFMEMORY
;
2583 wined3d_mutex_lock();
2584 handle
= d3d8_allocate_handle(&device
->handle_table
, object
, D3D8_HANDLE_PS
);
2585 wined3d_mutex_unlock();
2586 if (handle
== D3D8_INVALID_HANDLE
)
2588 ERR("Failed to allocate pixel shader handle.\n");
2589 HeapFree(GetProcessHeap(), 0, object
);
2590 return E_OUTOFMEMORY
;
2593 shader_handle
= handle
+ VS_HIGHESTFIXEDFXF
+ 1;
2595 hr
= d3d8_pixel_shader_init(object
, device
, byte_code
, shader_handle
);
2598 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
2599 wined3d_mutex_lock();
2600 d3d8_free_handle(&device
->handle_table
, handle
, D3D8_HANDLE_PS
);
2601 wined3d_mutex_unlock();
2602 HeapFree(GetProcessHeap(), 0, object
);
2607 TRACE("Created pixel shader %p (handle %#x).\n", object
, shader_handle
);
2608 *shader
= shader_handle
;
2613 static HRESULT WINAPI
d3d8_device_SetPixelShader(IDirect3DDevice8
*iface
, DWORD shader
)
2615 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2616 struct d3d8_pixel_shader
*shader_impl
;
2618 TRACE("iface %p, shader %#x.\n", iface
, shader
);
2620 wined3d_mutex_lock();
2624 wined3d_device_set_pixel_shader(device
->wined3d_device
, NULL
);
2625 wined3d_mutex_unlock();
2629 if (!(shader_impl
= d3d8_get_object(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
)))
2631 WARN("Invalid handle (%#x) passed.\n", shader
);
2632 wined3d_mutex_unlock();
2633 return D3DERR_INVALIDCALL
;
2636 TRACE("Setting shader %p.\n", shader_impl
);
2637 wined3d_device_set_pixel_shader(device
->wined3d_device
, shader_impl
->wined3d_shader
);
2638 wined3d_mutex_unlock();
2643 static HRESULT WINAPI
d3d8_device_GetPixelShader(IDirect3DDevice8
*iface
, DWORD
*shader
)
2645 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2646 struct wined3d_shader
*object
;
2648 TRACE("iface %p, shader %p.\n", iface
, shader
);
2651 return D3DERR_INVALIDCALL
;
2653 wined3d_mutex_lock();
2654 if ((object
= wined3d_device_get_pixel_shader(device
->wined3d_device
)))
2656 struct d3d8_pixel_shader
*d3d8_shader
;
2657 d3d8_shader
= wined3d_shader_get_parent(object
);
2658 *shader
= d3d8_shader
->handle
;
2664 wined3d_mutex_unlock();
2666 TRACE("Returning %#x.\n", *shader
);
2671 static HRESULT WINAPI
d3d8_device_DeletePixelShader(IDirect3DDevice8
*iface
, DWORD shader
)
2673 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2674 struct d3d8_pixel_shader
*shader_impl
;
2676 TRACE("iface %p, shader %#x.\n", iface
, shader
);
2678 wined3d_mutex_lock();
2680 if (!(shader_impl
= d3d8_free_handle(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
)))
2682 WARN("Invalid handle (%#x) passed.\n", shader
);
2683 wined3d_mutex_unlock();
2684 return D3DERR_INVALIDCALL
;
2687 if (wined3d_device_get_pixel_shader(device
->wined3d_device
) == shader_impl
->wined3d_shader
)
2688 IDirect3DDevice8_SetPixelShader(iface
, 0);
2690 wined3d_mutex_unlock();
2692 d3d8_pixel_shader_destroy(shader_impl
);
2697 static HRESULT WINAPI
d3d8_device_SetPixelShaderConstant(IDirect3DDevice8
*iface
,
2698 DWORD start_register
, const void *data
, DWORD count
)
2700 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2703 TRACE("iface %p, start_register %u, data %p, count %u.\n",
2704 iface
, start_register
, data
, count
);
2706 wined3d_mutex_lock();
2707 hr
= wined3d_device_set_ps_consts_f(device
->wined3d_device
, start_register
, data
, count
);
2708 wined3d_mutex_unlock();
2713 static HRESULT WINAPI
d3d8_device_GetPixelShaderConstant(IDirect3DDevice8
*iface
,
2714 DWORD start_register
, void *data
, DWORD count
)
2716 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2719 TRACE("iface %p, start_register %u, data %p, count %u.\n",
2720 iface
, start_register
, data
, count
);
2722 wined3d_mutex_lock();
2723 hr
= wined3d_device_get_ps_consts_f(device
->wined3d_device
, start_register
, data
, count
);
2724 wined3d_mutex_unlock();
2729 static HRESULT WINAPI
d3d8_device_GetPixelShaderFunction(IDirect3DDevice8
*iface
,
2730 DWORD shader
, void *data
, DWORD
*data_size
)
2732 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2733 struct d3d8_pixel_shader
*shader_impl
= NULL
;
2736 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2737 iface
, shader
, data
, data_size
);
2739 wined3d_mutex_lock();
2740 if (!(shader_impl
= d3d8_get_object(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
)))
2742 WARN("Invalid handle (%#x) passed.\n", shader
);
2743 wined3d_mutex_unlock();
2745 return D3DERR_INVALIDCALL
;
2748 hr
= wined3d_shader_get_byte_code(shader_impl
->wined3d_shader
, data
, data_size
);
2749 wined3d_mutex_unlock();
2754 static HRESULT WINAPI
d3d8_device_DrawRectPatch(IDirect3DDevice8
*iface
, UINT handle
,
2755 const float *segment_count
, const D3DRECTPATCH_INFO
*patch_info
)
2757 FIXME("iface %p, handle %#x, segment_count %p, patch_info %p unimplemented.\n",
2758 iface
, handle
, segment_count
, patch_info
);
2762 static HRESULT WINAPI
d3d8_device_DrawTriPatch(IDirect3DDevice8
*iface
, UINT handle
,
2763 const float *segment_count
, const D3DTRIPATCH_INFO
*patch_info
)
2765 FIXME("iface %p, handle %#x, segment_count %p, patch_info %p unimplemented.\n",
2766 iface
, handle
, segment_count
, patch_info
);
2770 static HRESULT WINAPI
d3d8_device_DeletePatch(IDirect3DDevice8
*iface
, UINT handle
)
2772 FIXME("iface %p, handle %#x unimplemented.\n", iface
, handle
);
2773 return D3DERR_INVALIDCALL
;
2776 static HRESULT WINAPI
d3d8_device_SetStreamSource(IDirect3DDevice8
*iface
,
2777 UINT stream_idx
, IDirect3DVertexBuffer8
*buffer
, UINT stride
)
2779 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2780 struct d3d8_vertexbuffer
*buffer_impl
= unsafe_impl_from_IDirect3DVertexBuffer8(buffer
);
2783 TRACE("iface %p, stream_idx %u, buffer %p, stride %u.\n",
2784 iface
, stream_idx
, buffer
, stride
);
2786 wined3d_mutex_lock();
2787 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, stream_idx
,
2788 buffer_impl
? buffer_impl
->wined3d_buffer
: NULL
, 0, stride
);
2789 wined3d_mutex_unlock();
2794 static HRESULT WINAPI
d3d8_device_GetStreamSource(IDirect3DDevice8
*iface
,
2795 UINT stream_idx
, IDirect3DVertexBuffer8
**buffer
, UINT
*stride
)
2797 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2798 struct d3d8_vertexbuffer
*buffer_impl
;
2799 struct wined3d_buffer
*wined3d_buffer
= NULL
;
2802 TRACE("iface %p, stream_idx %u, buffer %p, stride %p.\n",
2803 iface
, stream_idx
, buffer
, stride
);
2806 return D3DERR_INVALIDCALL
;
2808 wined3d_mutex_lock();
2809 hr
= wined3d_device_get_stream_source(device
->wined3d_device
, stream_idx
, &wined3d_buffer
, 0, stride
);
2810 if (SUCCEEDED(hr
) && wined3d_buffer
)
2812 buffer_impl
= wined3d_buffer_get_parent(wined3d_buffer
);
2813 *buffer
= &buffer_impl
->IDirect3DVertexBuffer8_iface
;
2814 IDirect3DVertexBuffer8_AddRef(*buffer
);
2819 ERR("Failed to get wined3d stream source, hr %#x.\n", hr
);
2822 wined3d_mutex_unlock();
2827 static const struct IDirect3DDevice8Vtbl d3d8_device_vtbl
=
2829 d3d8_device_QueryInterface
,
2831 d3d8_device_Release
,
2832 d3d8_device_TestCooperativeLevel
,
2833 d3d8_device_GetAvailableTextureMem
,
2834 d3d8_device_ResourceManagerDiscardBytes
,
2835 d3d8_device_GetDirect3D
,
2836 d3d8_device_GetDeviceCaps
,
2837 d3d8_device_GetDisplayMode
,
2838 d3d8_device_GetCreationParameters
,
2839 d3d8_device_SetCursorProperties
,
2840 d3d8_device_SetCursorPosition
,
2841 d3d8_device_ShowCursor
,
2842 d3d8_device_CreateAdditionalSwapChain
,
2844 d3d8_device_Present
,
2845 d3d8_device_GetBackBuffer
,
2846 d3d8_device_GetRasterStatus
,
2847 d3d8_device_SetGammaRamp
,
2848 d3d8_device_GetGammaRamp
,
2849 d3d8_device_CreateTexture
,
2850 d3d8_device_CreateVolumeTexture
,
2851 d3d8_device_CreateCubeTexture
,
2852 d3d8_device_CreateVertexBuffer
,
2853 d3d8_device_CreateIndexBuffer
,
2854 d3d8_device_CreateRenderTarget
,
2855 d3d8_device_CreateDepthStencilSurface
,
2856 d3d8_device_CreateImageSurface
,
2857 d3d8_device_CopyRects
,
2858 d3d8_device_UpdateTexture
,
2859 d3d8_device_GetFrontBuffer
,
2860 d3d8_device_SetRenderTarget
,
2861 d3d8_device_GetRenderTarget
,
2862 d3d8_device_GetDepthStencilSurface
,
2863 d3d8_device_BeginScene
,
2864 d3d8_device_EndScene
,
2866 d3d8_device_SetTransform
,
2867 d3d8_device_GetTransform
,
2868 d3d8_device_MultiplyTransform
,
2869 d3d8_device_SetViewport
,
2870 d3d8_device_GetViewport
,
2871 d3d8_device_SetMaterial
,
2872 d3d8_device_GetMaterial
,
2873 d3d8_device_SetLight
,
2874 d3d8_device_GetLight
,
2875 d3d8_device_LightEnable
,
2876 d3d8_device_GetLightEnable
,
2877 d3d8_device_SetClipPlane
,
2878 d3d8_device_GetClipPlane
,
2879 d3d8_device_SetRenderState
,
2880 d3d8_device_GetRenderState
,
2881 d3d8_device_BeginStateBlock
,
2882 d3d8_device_EndStateBlock
,
2883 d3d8_device_ApplyStateBlock
,
2884 d3d8_device_CaptureStateBlock
,
2885 d3d8_device_DeleteStateBlock
,
2886 d3d8_device_CreateStateBlock
,
2887 d3d8_device_SetClipStatus
,
2888 d3d8_device_GetClipStatus
,
2889 d3d8_device_GetTexture
,
2890 d3d8_device_SetTexture
,
2891 d3d8_device_GetTextureStageState
,
2892 d3d8_device_SetTextureStageState
,
2893 d3d8_device_ValidateDevice
,
2894 d3d8_device_GetInfo
,
2895 d3d8_device_SetPaletteEntries
,
2896 d3d8_device_GetPaletteEntries
,
2897 d3d8_device_SetCurrentTexturePalette
,
2898 d3d8_device_GetCurrentTexturePalette
,
2899 d3d8_device_DrawPrimitive
,
2900 d3d8_device_DrawIndexedPrimitive
,
2901 d3d8_device_DrawPrimitiveUP
,
2902 d3d8_device_DrawIndexedPrimitiveUP
,
2903 d3d8_device_ProcessVertices
,
2904 d3d8_device_CreateVertexShader
,
2905 d3d8_device_SetVertexShader
,
2906 d3d8_device_GetVertexShader
,
2907 d3d8_device_DeleteVertexShader
,
2908 d3d8_device_SetVertexShaderConstant
,
2909 d3d8_device_GetVertexShaderConstant
,
2910 d3d8_device_GetVertexShaderDeclaration
,
2911 d3d8_device_GetVertexShaderFunction
,
2912 d3d8_device_SetStreamSource
,
2913 d3d8_device_GetStreamSource
,
2914 d3d8_device_SetIndices
,
2915 d3d8_device_GetIndices
,
2916 d3d8_device_CreatePixelShader
,
2917 d3d8_device_SetPixelShader
,
2918 d3d8_device_GetPixelShader
,
2919 d3d8_device_DeletePixelShader
,
2920 d3d8_device_SetPixelShaderConstant
,
2921 d3d8_device_GetPixelShaderConstant
,
2922 d3d8_device_GetPixelShaderFunction
,
2923 d3d8_device_DrawRectPatch
,
2924 d3d8_device_DrawTriPatch
,
2925 d3d8_device_DeletePatch
,
2928 static inline struct d3d8_device
*device_from_device_parent(struct wined3d_device_parent
*device_parent
)
2930 return CONTAINING_RECORD(device_parent
, struct d3d8_device
, device_parent
);
2933 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
2934 struct wined3d_device
*device
)
2936 TRACE("device_parent %p, device %p\n", device_parent
, device
);
2939 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
2941 TRACE("device_parent %p.\n", device_parent
);
2944 static void CDECL
device_parent_activate(struct wined3d_device_parent
*device_parent
, BOOL activate
)
2946 struct d3d8_device
*device
= device_from_device_parent(device_parent
);
2948 TRACE("device_parent %p, activate %#x.\n", device_parent
, activate
);
2951 InterlockedCompareExchange(&device
->device_state
, D3D8_DEVICE_STATE_LOST
, D3D8_DEVICE_STATE_OK
);
2953 InterlockedCompareExchange(&device
->device_state
, D3D8_DEVICE_STATE_NOT_RESET
, D3D8_DEVICE_STATE_LOST
);
2956 static HRESULT CDECL
device_parent_surface_created(struct wined3d_device_parent
*device_parent
,
2957 void *container_parent
, struct wined3d_surface
*surface
, void **parent
,
2958 const struct wined3d_parent_ops
**parent_ops
)
2960 struct d3d8_surface
*d3d_surface
;
2962 TRACE("device_parent %p, container_parent %p, surface %p, parent %p, parent_ops %p.\n",
2963 device_parent
, container_parent
, surface
, parent
, parent_ops
);
2965 if (!(d3d_surface
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*d3d_surface
))))
2966 return E_OUTOFMEMORY
;
2968 surface_init(d3d_surface
, container_parent
, surface
, parent_ops
);
2969 *parent
= d3d_surface
;
2970 TRACE("Created surface %p.\n", d3d_surface
);
2975 static HRESULT CDECL
device_parent_volume_created(struct wined3d_device_parent
*device_parent
,
2976 void *container_parent
, struct wined3d_volume
*volume
, void **parent
,
2977 const struct wined3d_parent_ops
**parent_ops
)
2979 struct d3d8_volume
*d3d_volume
;
2981 TRACE("device_parent %p, container_parent %p, volume %p, parent %p, parent_ops %p.\n",
2982 device_parent
, container_parent
, volume
, parent
, parent_ops
);
2984 if (!(d3d_volume
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*d3d_volume
))))
2985 return E_OUTOFMEMORY
;
2987 volume_init(d3d_volume
, container_parent
, volume
, parent_ops
);
2988 *parent
= d3d_volume
;
2989 TRACE("Created volume %p.\n", d3d_volume
);
2994 static HRESULT CDECL
device_parent_create_swapchain_surface(struct wined3d_device_parent
*device_parent
,
2995 void *container_parent
, const struct wined3d_resource_desc
*desc
, struct wined3d_surface
**surface
)
2997 struct d3d8_device
*device
= device_from_device_parent(device_parent
);
2998 struct wined3d_resource_desc texture_desc
;
2999 struct d3d8_surface
*d3d_surface
;
3000 struct wined3d_texture
*texture
;
3003 TRACE("device_parent %p, container_parent %p, desc %p, surface %p.\n",
3004 device_parent
, container_parent
, desc
, surface
);
3006 texture_desc
= *desc
;
3007 texture_desc
.resource_type
= WINED3D_RTYPE_TEXTURE
;
3008 if (FAILED(hr
= wined3d_texture_create(device
->wined3d_device
, &texture_desc
, 1,
3009 WINED3D_SURFACE_MAPPABLE
, NULL
, &device
->IDirect3DDevice8_iface
, &d3d8_null_wined3d_parent_ops
, &texture
)))
3011 WARN("Failed to create texture, hr %#x.\n", hr
);
3015 *surface
= wined3d_surface_from_resource(wined3d_texture_get_sub_resource(texture
, 0));
3016 wined3d_surface_incref(*surface
);
3017 wined3d_texture_decref(texture
);
3019 d3d_surface
= wined3d_surface_get_parent(*surface
);
3020 d3d_surface
->parent_device
= &device
->IDirect3DDevice8_iface
;
3025 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
3026 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain
**swapchain
)
3028 struct d3d8_device
*device
= device_from_device_parent(device_parent
);
3029 struct d3d8_swapchain
*d3d_swapchain
;
3032 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent
, desc
, swapchain
);
3034 if (FAILED(hr
= d3d8_swapchain_create(device
, desc
, &d3d_swapchain
)))
3036 WARN("Failed to create swapchain, hr %#x.\n", hr
);
3041 *swapchain
= d3d_swapchain
->wined3d_swapchain
;
3042 wined3d_swapchain_incref(*swapchain
);
3043 IDirect3DSwapChain8_Release(&d3d_swapchain
->IDirect3DSwapChain8_iface
);
3048 static const struct wined3d_device_parent_ops d3d8_wined3d_device_parent_ops
=
3050 device_parent_wined3d_device_created
,
3051 device_parent_mode_changed
,
3052 device_parent_activate
,
3053 device_parent_surface_created
,
3054 device_parent_volume_created
,
3055 device_parent_create_swapchain_surface
,
3056 device_parent_create_swapchain
,
3059 static void setup_fpu(void)
3061 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3063 __asm__
volatile ("fnstcw %0" : "=m" (cw
));
3064 cw
= (cw
& ~0xf3f) | 0x3f;
3065 __asm__
volatile ("fldcw %0" : : "m" (cw
));
3066 #elif defined(__i386__) && defined(_MSC_VER)
3069 cw
= (cw
& ~0xf3f) | 0x3f;
3072 FIXME("FPU setup not implemented for this platform.\n");
3076 HRESULT
device_init(struct d3d8_device
*device
, struct d3d8
*parent
, struct wined3d
*wined3d
, UINT adapter
,
3077 D3DDEVTYPE device_type
, HWND focus_window
, DWORD flags
, D3DPRESENT_PARAMETERS
*parameters
)
3079 struct wined3d_swapchain_desc swapchain_desc
;
3082 device
->IDirect3DDevice8_iface
.lpVtbl
= &d3d8_device_vtbl
;
3083 device
->device_parent
.ops
= &d3d8_wined3d_device_parent_ops
;
3085 device
->handle_table
.entries
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
3086 D3D8_INITIAL_HANDLE_TABLE_SIZE
* sizeof(*device
->handle_table
.entries
));
3087 if (!device
->handle_table
.entries
)
3089 ERR("Failed to allocate handle table memory.\n");
3090 return E_OUTOFMEMORY
;
3092 device
->handle_table
.table_size
= D3D8_INITIAL_HANDLE_TABLE_SIZE
;
3094 if (!(flags
& D3DCREATE_FPU_PRESERVE
)) setup_fpu();
3096 wined3d_mutex_lock();
3097 hr
= wined3d_device_create(wined3d
, adapter
, device_type
, focus_window
, flags
, 4,
3098 &device
->device_parent
, &device
->wined3d_device
);
3101 WARN("Failed to create wined3d device, hr %#x.\n", hr
);
3102 wined3d_mutex_unlock();
3103 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
3107 if (!parameters
->Windowed
)
3109 HWND device_window
= parameters
->hDeviceWindow
;
3112 focus_window
= device_window
;
3113 if (FAILED(hr
= wined3d_device_acquire_focus_window(device
->wined3d_device
, focus_window
)))
3115 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
3116 wined3d_device_decref(device
->wined3d_device
);
3117 wined3d_mutex_unlock();
3118 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
3123 device_window
= focus_window
;
3124 wined3d_device_setup_fullscreen_window(device
->wined3d_device
, device_window
,
3125 parameters
->BackBufferWidth
,
3126 parameters
->BackBufferHeight
);
3129 if (flags
& D3DCREATE_MULTITHREADED
)
3130 wined3d_device_set_multithreaded(device
->wined3d_device
);
3132 wined3d_swapchain_desc_from_present_parameters(&swapchain_desc
, parameters
);
3134 hr
= wined3d_device_init_3d(device
->wined3d_device
, &swapchain_desc
);
3137 WARN("Failed to initialize 3D, hr %#x.\n", hr
);
3138 wined3d_device_release_focus_window(device
->wined3d_device
);
3139 wined3d_device_decref(device
->wined3d_device
);
3140 wined3d_mutex_unlock();
3141 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
3145 wined3d_device_set_render_state(device
->wined3d_device
, WINED3D_RS_POINTSIZE_MIN
, 0);
3146 wined3d_mutex_unlock();
3148 present_parameters_from_wined3d_swapchain_desc(parameters
, &swapchain_desc
);
3150 device
->declArraySize
= 16;
3151 device
->decls
= HeapAlloc(GetProcessHeap(), 0, device
->declArraySize
* sizeof(*device
->decls
));
3154 ERR("Failed to allocate FVF vertex declaration map memory.\n");
3159 device
->d3d_parent
= &parent
->IDirect3D8_iface
;
3160 IDirect3D8_AddRef(device
->d3d_parent
);
3165 wined3d_mutex_lock();
3166 wined3d_device_uninit_3d(device
->wined3d_device
);
3167 wined3d_device_release_focus_window(device
->wined3d_device
);
3168 wined3d_device_decref(device
->wined3d_device
);
3169 wined3d_mutex_unlock();
3170 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);