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 BOOL
wined3d_swapchain_desc_from_present_parameters(struct wined3d_swapchain_desc
*swapchain_desc
,
179 const D3DPRESENT_PARAMETERS
*present_parameters
)
181 if (!present_parameters
->SwapEffect
|| present_parameters
->SwapEffect
> D3DSWAPEFFECT_COPY_VSYNC
)
183 WARN("Invalid swap effect %u passed.\n", present_parameters
->SwapEffect
);
186 if (present_parameters
->BackBufferCount
> 3
187 || ((present_parameters
->SwapEffect
== D3DSWAPEFFECT_COPY
188 || present_parameters
->SwapEffect
== D3DSWAPEFFECT_COPY_VSYNC
)
189 && present_parameters
->BackBufferCount
> 1))
191 WARN("Invalid backbuffer count %u.\n", present_parameters
->BackBufferCount
);
195 swapchain_desc
->backbuffer_width
= present_parameters
->BackBufferWidth
;
196 swapchain_desc
->backbuffer_height
= present_parameters
->BackBufferHeight
;
197 swapchain_desc
->backbuffer_format
= wined3dformat_from_d3dformat(present_parameters
->BackBufferFormat
);
198 swapchain_desc
->backbuffer_count
= max(1, present_parameters
->BackBufferCount
);
199 swapchain_desc
->multisample_type
= present_parameters
->MultiSampleType
;
200 swapchain_desc
->multisample_quality
= 0; /* d3d9 only */
201 swapchain_desc
->swap_effect
= present_parameters
->SwapEffect
;
202 swapchain_desc
->device_window
= present_parameters
->hDeviceWindow
;
203 swapchain_desc
->windowed
= present_parameters
->Windowed
;
204 swapchain_desc
->enable_auto_depth_stencil
= present_parameters
->EnableAutoDepthStencil
;
205 swapchain_desc
->auto_depth_stencil_format
206 = wined3dformat_from_d3dformat(present_parameters
->AutoDepthStencilFormat
);
207 swapchain_desc
->flags
= present_parameters
->Flags
;
208 swapchain_desc
->refresh_rate
= present_parameters
->FullScreen_RefreshRateInHz
;
209 swapchain_desc
->swap_interval
= present_parameters
->FullScreen_PresentationInterval
;
210 swapchain_desc
->auto_restore_display_mode
= TRUE
;
215 /* Handle table functions */
216 static DWORD
d3d8_allocate_handle(struct d3d8_handle_table
*t
, void *object
, enum d3d8_handle_type type
)
218 struct d3d8_handle_entry
*entry
;
222 DWORD index
= t
->free_entries
- t
->entries
;
223 /* Use a free handle */
224 entry
= t
->free_entries
;
225 if (entry
->type
!= D3D8_HANDLE_FREE
)
227 ERR("Handle %u(%p) is in the free list, but has type %#x.\n", index
, entry
, entry
->type
);
228 return D3D8_INVALID_HANDLE
;
230 t
->free_entries
= entry
->object
;
231 entry
->object
= object
;
237 if (!(t
->entry_count
< t
->table_size
))
240 UINT new_size
= t
->table_size
+ (t
->table_size
>> 1);
241 struct d3d8_handle_entry
*new_entries
= HeapReAlloc(GetProcessHeap(),
242 0, t
->entries
, new_size
* sizeof(*t
->entries
));
245 ERR("Failed to grow the handle table.\n");
246 return D3D8_INVALID_HANDLE
;
248 t
->entries
= new_entries
;
249 t
->table_size
= new_size
;
252 entry
= &t
->entries
[t
->entry_count
];
253 entry
->object
= object
;
256 return t
->entry_count
++;
259 static void *d3d8_free_handle(struct d3d8_handle_table
*t
, DWORD handle
, enum d3d8_handle_type type
)
261 struct d3d8_handle_entry
*entry
;
264 if (handle
== D3D8_INVALID_HANDLE
|| handle
>= t
->entry_count
)
266 WARN("Invalid handle %u passed.\n", handle
);
270 entry
= &t
->entries
[handle
];
271 if (entry
->type
!= type
)
273 WARN("Handle %u(%p) is not of type %#x.\n", handle
, entry
, type
);
277 object
= entry
->object
;
278 entry
->object
= t
->free_entries
;
279 entry
->type
= D3D8_HANDLE_FREE
;
280 t
->free_entries
= entry
;
285 static void *d3d8_get_object(struct d3d8_handle_table
*t
, DWORD handle
, enum d3d8_handle_type type
)
287 struct d3d8_handle_entry
*entry
;
289 if (handle
== D3D8_INVALID_HANDLE
|| handle
>= t
->entry_count
)
291 WARN("Invalid handle %u passed.\n", handle
);
295 entry
= &t
->entries
[handle
];
296 if (entry
->type
!= type
)
298 WARN("Handle %u(%p) is not of type %#x.\n", handle
, entry
, type
);
302 return entry
->object
;
305 static HRESULT WINAPI
d3d8_device_QueryInterface(IDirect3DDevice8
*iface
, REFIID riid
, void **out
)
307 TRACE("iface %p, riid %s, out %p.\n",
308 iface
, debugstr_guid(riid
), out
);
310 if (IsEqualGUID(riid
, &IID_IDirect3DDevice8
)
311 || IsEqualGUID(riid
, &IID_IUnknown
))
313 IDirect3DDevice8_AddRef(iface
);
318 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
321 return E_NOINTERFACE
;
324 static ULONG WINAPI
d3d8_device_AddRef(IDirect3DDevice8
*iface
)
326 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
327 ULONG ref
= InterlockedIncrement(&device
->ref
);
329 TRACE("%p increasing refcount to %u.\n", iface
, ref
);
334 static ULONG WINAPI
d3d8_device_Release(IDirect3DDevice8
*iface
)
336 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
339 if (device
->inDestruction
)
342 ref
= InterlockedDecrement(&device
->ref
);
344 TRACE("%p decreasing refcount to %u.\n", iface
, ref
);
348 IDirect3D8
*parent
= device
->d3d_parent
;
351 TRACE("Releasing wined3d device %p.\n", device
->wined3d_device
);
353 wined3d_mutex_lock();
355 device
->inDestruction
= TRUE
;
357 for (i
= 0; i
< device
->numConvertedDecls
; ++i
)
359 d3d8_vertex_declaration_destroy(device
->decls
[i
].declaration
);
361 HeapFree(GetProcessHeap(), 0, device
->decls
);
363 if (device
->vertex_buffer
)
364 wined3d_buffer_decref(device
->vertex_buffer
);
365 if (device
->index_buffer
)
366 wined3d_buffer_decref(device
->index_buffer
);
368 wined3d_device_uninit_3d(device
->wined3d_device
);
369 wined3d_device_release_focus_window(device
->wined3d_device
);
370 wined3d_device_decref(device
->wined3d_device
);
371 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
372 HeapFree(GetProcessHeap(), 0, device
);
374 wined3d_mutex_unlock();
376 IDirect3D8_Release(parent
);
381 static HRESULT WINAPI
d3d8_device_TestCooperativeLevel(IDirect3DDevice8
*iface
)
383 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
385 TRACE("iface %p.\n", iface
);
387 TRACE("device state: %#x.\n", device
->device_state
);
389 switch (device
->device_state
)
392 case D3D8_DEVICE_STATE_OK
:
394 case D3D8_DEVICE_STATE_LOST
:
395 return D3DERR_DEVICELOST
;
396 case D3D8_DEVICE_STATE_NOT_RESET
:
397 return D3DERR_DEVICENOTRESET
;
401 static UINT WINAPI
d3d8_device_GetAvailableTextureMem(IDirect3DDevice8
*iface
)
403 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
406 TRACE("iface %p.\n", iface
);
408 wined3d_mutex_lock();
409 ret
= wined3d_device_get_available_texture_mem(device
->wined3d_device
);
410 wined3d_mutex_unlock();
415 static HRESULT WINAPI
d3d8_device_ResourceManagerDiscardBytes(IDirect3DDevice8
*iface
, DWORD byte_count
)
417 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
419 TRACE("iface %p, byte_count %u.\n", iface
, byte_count
);
422 FIXME("Byte count ignored.\n");
424 wined3d_mutex_lock();
425 wined3d_device_evict_managed_resources(device
->wined3d_device
);
426 wined3d_mutex_unlock();
431 static HRESULT WINAPI
d3d8_device_GetDirect3D(IDirect3DDevice8
*iface
, IDirect3D8
**d3d8
)
433 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
435 TRACE("iface %p, d3d8 %p.\n", iface
, d3d8
);
438 return D3DERR_INVALIDCALL
;
440 return IDirect3D8_QueryInterface(device
->d3d_parent
, &IID_IDirect3D8
, (void **)d3d8
);
443 static HRESULT WINAPI
d3d8_device_GetDeviceCaps(IDirect3DDevice8
*iface
, D3DCAPS8
*caps
)
445 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
446 WINED3DCAPS
*wined3d_caps
;
449 TRACE("iface %p, caps %p.\n", iface
, caps
);
452 return D3DERR_INVALIDCALL
;
454 if (!(wined3d_caps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*wined3d_caps
))))
455 return D3DERR_INVALIDCALL
; /* well this is what MSDN says to return */
457 wined3d_mutex_lock();
458 hr
= wined3d_device_get_device_caps(device
->wined3d_device
, wined3d_caps
);
459 wined3d_mutex_unlock();
461 fixup_caps(wined3d_caps
);
462 WINECAPSTOD3D8CAPS(caps
, wined3d_caps
)
463 HeapFree(GetProcessHeap(), 0, wined3d_caps
);
468 static HRESULT WINAPI
d3d8_device_GetDisplayMode(IDirect3DDevice8
*iface
, D3DDISPLAYMODE
*mode
)
470 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
471 struct wined3d_display_mode wined3d_mode
;
474 TRACE("iface %p, mode %p.\n", iface
, mode
);
476 wined3d_mutex_lock();
477 hr
= wined3d_device_get_display_mode(device
->wined3d_device
, 0, &wined3d_mode
, NULL
);
478 wined3d_mutex_unlock();
482 mode
->Width
= wined3d_mode
.width
;
483 mode
->Height
= wined3d_mode
.height
;
484 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
485 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
491 static HRESULT WINAPI
d3d8_device_GetCreationParameters(IDirect3DDevice8
*iface
,
492 D3DDEVICE_CREATION_PARAMETERS
*parameters
)
494 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
496 TRACE("iface %p, parameters %p.\n", iface
, parameters
);
498 wined3d_mutex_lock();
499 wined3d_device_get_creation_parameters(device
->wined3d_device
,
500 (struct wined3d_device_creation_parameters
*)parameters
);
501 wined3d_mutex_unlock();
506 static HRESULT WINAPI
d3d8_device_SetCursorProperties(IDirect3DDevice8
*iface
,
507 UINT hotspot_x
, UINT hotspot_y
, IDirect3DSurface8
*bitmap
)
509 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
510 struct d3d8_surface
*bitmap_impl
= unsafe_impl_from_IDirect3DSurface8(bitmap
);
513 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
514 iface
, hotspot_x
, hotspot_y
, bitmap
);
518 WARN("No cursor bitmap, returning D3DERR_INVALIDCALL.\n");
519 return D3DERR_INVALIDCALL
;
522 wined3d_mutex_lock();
523 hr
= wined3d_device_set_cursor_properties(device
->wined3d_device
,
524 hotspot_x
, hotspot_y
, bitmap_impl
->wined3d_texture
, bitmap_impl
->sub_resource_idx
);
525 wined3d_mutex_unlock();
530 static void WINAPI
d3d8_device_SetCursorPosition(IDirect3DDevice8
*iface
, UINT x
, UINT y
, DWORD flags
)
532 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
534 TRACE("iface %p, x %u, y %u, flags %#x.\n", iface
, x
, y
, flags
);
536 wined3d_mutex_lock();
537 wined3d_device_set_cursor_position(device
->wined3d_device
, x
, y
, flags
);
538 wined3d_mutex_unlock();
541 static BOOL WINAPI
d3d8_device_ShowCursor(IDirect3DDevice8
*iface
, BOOL show
)
543 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
546 TRACE("iface %p, show %#x.\n", iface
, show
);
548 wined3d_mutex_lock();
549 ret
= wined3d_device_show_cursor(device
->wined3d_device
, show
);
550 wined3d_mutex_unlock();
555 static HRESULT WINAPI
d3d8_device_CreateAdditionalSwapChain(IDirect3DDevice8
*iface
,
556 D3DPRESENT_PARAMETERS
*present_parameters
, IDirect3DSwapChain8
**swapchain
)
558 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
559 struct wined3d_swapchain_desc desc
;
560 struct d3d8_swapchain
*object
;
564 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
565 iface
, present_parameters
, swapchain
);
567 if (!present_parameters
->Windowed
)
569 WARN("Trying to create an additional fullscreen swapchain, returning D3DERR_INVALIDCALL.\n");
570 return D3DERR_INVALIDCALL
;
573 wined3d_mutex_lock();
574 count
= wined3d_device_get_swapchain_count(device
->wined3d_device
);
575 for (i
= 0; i
< count
; ++i
)
577 struct wined3d_swapchain
*wined3d_swapchain
;
579 wined3d_swapchain
= wined3d_device_get_swapchain(device
->wined3d_device
, i
);
580 wined3d_swapchain_get_desc(wined3d_swapchain
, &desc
);
584 wined3d_mutex_unlock();
585 WARN("Trying to create an additional swapchain in fullscreen mode, returning D3DERR_INVALIDCALL.\n");
586 return D3DERR_INVALIDCALL
;
589 wined3d_mutex_unlock();
591 if (!wined3d_swapchain_desc_from_present_parameters(&desc
, present_parameters
))
592 return D3DERR_INVALIDCALL
;
593 if (SUCCEEDED(hr
= d3d8_swapchain_create(device
, &desc
, &object
)))
594 *swapchain
= &object
->IDirect3DSwapChain8_iface
;
595 present_parameters_from_wined3d_swapchain_desc(present_parameters
, &desc
);
600 static HRESULT CDECL
reset_enum_callback(struct wined3d_resource
*resource
)
602 struct wined3d_resource_desc desc
;
604 wined3d_resource_get_desc(resource
, &desc
);
605 if (desc
.pool
== WINED3D_POOL_DEFAULT
)
607 struct d3d8_surface
*surface
;
609 if (desc
.resource_type
== WINED3D_RTYPE_TEXTURE
)
611 IUnknown
*parent
= wined3d_resource_get_parent(resource
);
612 IDirect3DBaseTexture8
*texture
;
614 if (SUCCEEDED(IUnknown_QueryInterface(parent
, &IID_IDirect3DBaseTexture8
, (void **)&texture
)))
616 IDirect3DBaseTexture8_Release(texture
);
617 WARN("Texture %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", texture
, resource
);
618 return D3DERR_DEVICELOST
;
624 if (desc
.resource_type
!= WINED3D_RTYPE_SURFACE
)
626 WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource
);
627 return D3DERR_DEVICELOST
;
630 surface
= wined3d_resource_get_parent(resource
);
631 if (surface
->resource
.refcount
)
633 WARN("Surface %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface
, resource
);
634 return D3DERR_DEVICELOST
;
637 WARN("Surface %p (resource %p) is an implicit resource with ref 0.\n", surface
, resource
);
643 static HRESULT WINAPI
d3d8_device_Reset(IDirect3DDevice8
*iface
,
644 D3DPRESENT_PARAMETERS
*present_parameters
)
646 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
647 struct wined3d_swapchain_desc swapchain_desc
;
650 TRACE("iface %p, present_parameters %p.\n", iface
, present_parameters
);
652 if (device
->device_state
== D3D8_DEVICE_STATE_LOST
)
654 WARN("App not active, returning D3DERR_DEVICELOST.\n");
655 return D3DERR_DEVICELOST
;
657 if (!wined3d_swapchain_desc_from_present_parameters(&swapchain_desc
, present_parameters
))
658 return D3DERR_INVALIDCALL
;
660 wined3d_mutex_lock();
662 if (device
->vertex_buffer
)
664 wined3d_buffer_decref(device
->vertex_buffer
);
665 device
->vertex_buffer
= NULL
;
666 device
->vertex_buffer_size
= 0;
668 if (device
->index_buffer
)
670 wined3d_buffer_decref(device
->index_buffer
);
671 device
->index_buffer
= NULL
;
672 device
->index_buffer_size
= 0;
675 if (SUCCEEDED(hr
= wined3d_device_reset(device
->wined3d_device
, &swapchain_desc
,
676 NULL
, reset_enum_callback
, TRUE
)))
678 present_parameters
->BackBufferCount
= swapchain_desc
.backbuffer_count
;
679 wined3d_device_set_render_state(device
->wined3d_device
, WINED3D_RS_POINTSIZE_MIN
, 0);
680 device
->device_state
= D3D8_DEVICE_STATE_OK
;
684 device
->device_state
= D3D8_DEVICE_STATE_NOT_RESET
;
686 wined3d_mutex_unlock();
691 static HRESULT WINAPI
d3d8_device_Present(IDirect3DDevice8
*iface
, const RECT
*src_rect
,
692 const RECT
*dst_rect
, HWND dst_window_override
, const RGNDATA
*dirty_region
)
694 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
696 TRACE("iface %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p.\n",
697 iface
, wine_dbgstr_rect(src_rect
), wine_dbgstr_rect(dst_rect
), dst_window_override
, dirty_region
);
699 /* Fraps does not hook IDirect3DDevice8::Present regardless of the hotpatch
700 * attribute. It only hooks IDirect3DSwapChain8::Present. Yet it properly
701 * shows a framerate on Windows in applications that only call the device
702 * method, like e.g. the dx8 sdk samples. The conclusion is that native
703 * calls the swapchain's public method from the device. */
704 return IDirect3DSwapChain8_Present(&device
->implicit_swapchain
->IDirect3DSwapChain8_iface
,
705 src_rect
, dst_rect
, dst_window_override
, dirty_region
);
708 static HRESULT WINAPI
d3d8_device_GetBackBuffer(IDirect3DDevice8
*iface
,
709 UINT backbuffer_idx
, D3DBACKBUFFER_TYPE backbuffer_type
, IDirect3DSurface8
**backbuffer
)
711 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
712 struct wined3d_swapchain
*wined3d_swapchain
;
713 struct wined3d_resource
*wined3d_resource
;
714 struct wined3d_texture
*wined3d_texture
;
715 struct d3d8_surface
*surface_impl
;
717 TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
718 iface
, backbuffer_idx
, backbuffer_type
, backbuffer
);
720 /* backbuffer_type is ignored by native. */
722 /* No need to check for backbuffer == NULL, Windows crashes in that case. */
723 wined3d_mutex_lock();
725 wined3d_swapchain
= device
->implicit_swapchain
->wined3d_swapchain
;
726 if (!(wined3d_texture
= wined3d_swapchain_get_back_buffer(wined3d_swapchain
, backbuffer_idx
)))
728 wined3d_mutex_unlock();
730 return D3DERR_INVALIDCALL
;
733 wined3d_resource
= wined3d_texture_get_sub_resource(wined3d_texture
, 0);
734 surface_impl
= wined3d_resource_get_parent(wined3d_resource
);
735 *backbuffer
= &surface_impl
->IDirect3DSurface8_iface
;
736 IDirect3DSurface8_AddRef(*backbuffer
);
738 wined3d_mutex_unlock();
742 static HRESULT WINAPI
d3d8_device_GetRasterStatus(IDirect3DDevice8
*iface
, D3DRASTER_STATUS
*raster_status
)
744 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
747 TRACE("iface %p, raster_status %p.\n", iface
, raster_status
);
749 wined3d_mutex_lock();
750 hr
= wined3d_device_get_raster_status(device
->wined3d_device
, 0, (struct wined3d_raster_status
*)raster_status
);
751 wined3d_mutex_unlock();
756 static void WINAPI
d3d8_device_SetGammaRamp(IDirect3DDevice8
*iface
, DWORD flags
, const D3DGAMMARAMP
*ramp
)
758 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
760 TRACE("iface %p, flags %#x, ramp %p.\n", iface
, flags
, ramp
);
762 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
763 wined3d_mutex_lock();
764 wined3d_device_set_gamma_ramp(device
->wined3d_device
, 0, flags
, (const struct wined3d_gamma_ramp
*)ramp
);
765 wined3d_mutex_unlock();
768 static void WINAPI
d3d8_device_GetGammaRamp(IDirect3DDevice8
*iface
, D3DGAMMARAMP
*ramp
)
770 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
772 TRACE("iface %p, ramp %p.\n", iface
, ramp
);
774 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
775 wined3d_mutex_lock();
776 wined3d_device_get_gamma_ramp(device
->wined3d_device
, 0, (struct wined3d_gamma_ramp
*)ramp
);
777 wined3d_mutex_unlock();
780 static HRESULT WINAPI
d3d8_device_CreateTexture(IDirect3DDevice8
*iface
,
781 UINT width
, UINT height
, UINT levels
, DWORD usage
, D3DFORMAT format
,
782 D3DPOOL pool
, IDirect3DTexture8
**texture
)
784 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
785 struct d3d8_texture
*object
;
788 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
789 iface
, width
, height
, levels
, usage
, format
, pool
, texture
);
792 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
794 return D3DERR_OUTOFVIDEOMEMORY
;
796 hr
= texture_init(object
, device
, width
, height
, levels
, usage
, format
, pool
);
799 WARN("Failed to initialize texture, hr %#x.\n", hr
);
800 HeapFree(GetProcessHeap(), 0, object
);
804 TRACE("Created texture %p.\n", object
);
805 *texture
= (IDirect3DTexture8
*)&object
->IDirect3DBaseTexture8_iface
;
810 static HRESULT WINAPI
d3d8_device_CreateVolumeTexture(IDirect3DDevice8
*iface
,
811 UINT width
, UINT height
, UINT depth
, UINT levels
, DWORD usage
, D3DFORMAT format
,
812 D3DPOOL pool
, IDirect3DVolumeTexture8
**texture
)
814 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
815 struct d3d8_texture
*object
;
818 TRACE("iface %p, width %u, height %u, depth %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
819 iface
, width
, height
, depth
, levels
, usage
, format
, pool
, texture
);
822 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
824 return D3DERR_OUTOFVIDEOMEMORY
;
826 hr
= volumetexture_init(object
, device
, width
, height
, depth
, levels
, usage
, format
, pool
);
829 WARN("Failed to initialize volume texture, hr %#x.\n", hr
);
830 HeapFree(GetProcessHeap(), 0, object
);
834 TRACE("Created volume texture %p.\n", object
);
835 *texture
= (IDirect3DVolumeTexture8
*)&object
->IDirect3DBaseTexture8_iface
;
840 static HRESULT WINAPI
d3d8_device_CreateCubeTexture(IDirect3DDevice8
*iface
, UINT edge_length
,
841 UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DCubeTexture8
**texture
)
843 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
844 struct d3d8_texture
*object
;
847 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
848 iface
, edge_length
, levels
, usage
, format
, pool
, texture
);
851 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
853 return D3DERR_OUTOFVIDEOMEMORY
;
855 hr
= cubetexture_init(object
, device
, edge_length
, levels
, usage
, format
, pool
);
858 WARN("Failed to initialize cube texture, hr %#x.\n", hr
);
859 HeapFree(GetProcessHeap(), 0, object
);
863 TRACE("Created cube texture %p.\n", object
);
864 *texture
= (IDirect3DCubeTexture8
*)&object
->IDirect3DBaseTexture8_iface
;
869 static HRESULT WINAPI
d3d8_device_CreateVertexBuffer(IDirect3DDevice8
*iface
, UINT size
,
870 DWORD usage
, DWORD fvf
, D3DPOOL pool
, IDirect3DVertexBuffer8
**buffer
)
872 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
873 struct d3d8_vertexbuffer
*object
;
876 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p.\n",
877 iface
, size
, usage
, fvf
, pool
, buffer
);
879 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
881 return D3DERR_OUTOFVIDEOMEMORY
;
883 hr
= vertexbuffer_init(object
, device
, size
, usage
, fvf
, pool
);
886 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr
);
887 HeapFree(GetProcessHeap(), 0, object
);
891 TRACE("Created vertex buffer %p.\n", object
);
892 *buffer
= &object
->IDirect3DVertexBuffer8_iface
;
897 static HRESULT WINAPI
d3d8_device_CreateIndexBuffer(IDirect3DDevice8
*iface
, UINT size
,
898 DWORD usage
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DIndexBuffer8
**buffer
)
900 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
901 struct d3d8_indexbuffer
*object
;
904 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p.\n",
905 iface
, size
, usage
, format
, pool
, buffer
);
907 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
909 return D3DERR_OUTOFVIDEOMEMORY
;
911 hr
= indexbuffer_init(object
, device
, size
, usage
, format
, pool
);
914 WARN("Failed to initialize index buffer, hr %#x.\n", hr
);
915 HeapFree(GetProcessHeap(), 0, object
);
919 TRACE("Created index buffer %p.\n", object
);
920 *buffer
= &object
->IDirect3DIndexBuffer8_iface
;
925 static HRESULT
d3d8_device_create_surface(struct d3d8_device
*device
, UINT width
, UINT height
,
926 D3DFORMAT format
, DWORD flags
, IDirect3DSurface8
**surface
, UINT usage
, D3DPOOL pool
,
927 D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
)
929 struct wined3d_resource
*sub_resource
;
930 struct wined3d_resource_desc desc
;
931 struct d3d8_surface
*surface_impl
;
932 struct wined3d_texture
*texture
;
935 TRACE("device %p, width %u, height %u, format %#x, flags %#x, surface %p,\n"
936 "\tusage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
937 device
, width
, height
, format
, flags
, surface
,
938 usage
, pool
, multisample_type
, multisample_quality
);
940 desc
.resource_type
= WINED3D_RTYPE_TEXTURE
;
941 desc
.format
= wined3dformat_from_d3dformat(format
);
942 desc
.multisample_type
= multisample_type
;
943 desc
.multisample_quality
= multisample_quality
;
944 desc
.usage
= usage
& WINED3DUSAGE_MASK
;
947 desc
.height
= height
;
951 wined3d_mutex_lock();
953 if (FAILED(hr
= wined3d_texture_create(device
->wined3d_device
, &desc
,
954 1, flags
, NULL
, NULL
, &d3d8_null_wined3d_parent_ops
, &texture
)))
956 wined3d_mutex_unlock();
957 WARN("Failed to create texture, hr %#x.\n", hr
);
961 sub_resource
= wined3d_texture_get_sub_resource(texture
, 0);
962 surface_impl
= wined3d_resource_get_parent(sub_resource
);
963 surface_impl
->parent_device
= &device
->IDirect3DDevice8_iface
;
964 *surface
= &surface_impl
->IDirect3DSurface8_iface
;
965 IDirect3DSurface8_AddRef(*surface
);
966 wined3d_texture_decref(texture
);
968 wined3d_mutex_unlock();
973 static HRESULT WINAPI
d3d8_device_CreateRenderTarget(IDirect3DDevice8
*iface
, UINT width
,
974 UINT height
, D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, BOOL lockable
,
975 IDirect3DSurface8
**surface
)
977 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
980 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, lockable %#x, surface %p.\n",
981 iface
, width
, height
, format
, multisample_type
, lockable
, surface
);
985 flags
|= WINED3D_SURFACE_MAPPABLE
;
987 return d3d8_device_create_surface(device
, width
, height
, format
, flags
, surface
,
988 D3DUSAGE_RENDERTARGET
, D3DPOOL_DEFAULT
, multisample_type
, 0);
991 static HRESULT WINAPI
d3d8_device_CreateDepthStencilSurface(IDirect3DDevice8
*iface
,
992 UINT width
, UINT height
, D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
,
993 IDirect3DSurface8
**surface
)
995 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
997 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, surface %p.\n",
998 iface
, width
, height
, format
, multisample_type
, surface
);
1002 /* TODO: Verify that Discard is false */
1003 return d3d8_device_create_surface(device
, width
, height
, format
, WINED3D_SURFACE_MAPPABLE
,
1004 surface
, D3DUSAGE_DEPTHSTENCIL
, D3DPOOL_DEFAULT
, multisample_type
, 0);
1007 /* IDirect3DDevice8Impl::CreateImageSurface returns surface with pool type SYSTEMMEM */
1008 static HRESULT WINAPI
d3d8_device_CreateImageSurface(IDirect3DDevice8
*iface
, UINT width
,
1009 UINT height
, D3DFORMAT format
, IDirect3DSurface8
**surface
)
1011 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1013 TRACE("iface %p, width %u, height %u, format %#x, surface %p.\n",
1014 iface
, width
, height
, format
, surface
);
1018 return d3d8_device_create_surface(device
, width
, height
, format
, WINED3D_SURFACE_MAPPABLE
,
1019 surface
, 0, D3DPOOL_SYSTEMMEM
, D3DMULTISAMPLE_NONE
, 0);
1022 static HRESULT WINAPI
d3d8_device_CopyRects(IDirect3DDevice8
*iface
,
1023 IDirect3DSurface8
*src_surface
, const RECT
*src_rects
, UINT rect_count
,
1024 IDirect3DSurface8
*dst_surface
, const POINT
*dst_points
)
1026 struct d3d8_surface
*src
= unsafe_impl_from_IDirect3DSurface8(src_surface
);
1027 struct d3d8_surface
*dst
= unsafe_impl_from_IDirect3DSurface8(dst_surface
);
1028 enum wined3d_format_id src_format
, dst_format
;
1029 struct wined3d_resource_desc wined3d_desc
;
1030 struct wined3d_resource
*wined3d_resource
;
1033 TRACE("iface %p, src_surface %p, src_rects %p, rect_count %u, dst_surface %p, dst_points %p.\n",
1034 iface
, src_surface
, src_rects
, rect_count
, dst_surface
, dst_points
);
1036 /* Check that the source texture is in WINED3D_POOL_SYSTEM_MEM and the
1037 * destination texture is in WINED3D_POOL_DEFAULT. */
1039 wined3d_mutex_lock();
1040 wined3d_resource
= wined3d_texture_get_sub_resource(src
->wined3d_texture
, src
->sub_resource_idx
);
1041 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
1042 if (wined3d_desc
.usage
& WINED3DUSAGE_DEPTHSTENCIL
)
1044 WARN("Source %p is a depth stencil surface, returning D3DERR_INVALIDCALL.\n", src_surface
);
1045 wined3d_mutex_unlock();
1046 return D3DERR_INVALIDCALL
;
1048 src_format
= wined3d_desc
.format
;
1049 src_w
= wined3d_desc
.width
;
1050 src_h
= wined3d_desc
.height
;
1052 wined3d_resource
= wined3d_texture_get_sub_resource(dst
->wined3d_texture
, dst
->sub_resource_idx
);
1053 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
1054 if (wined3d_desc
.usage
& WINED3DUSAGE_DEPTHSTENCIL
)
1056 WARN("Destination %p is a depth stencil surface, returning D3DERR_INVALIDCALL.\n", dst_surface
);
1057 wined3d_mutex_unlock();
1058 return D3DERR_INVALIDCALL
;
1060 dst_format
= wined3d_desc
.format
;
1062 /* Check that the source and destination formats match */
1063 if (src_format
!= dst_format
)
1065 WARN("Source %p format must match the destination %p format, returning D3DERR_INVALIDCALL.\n",
1066 src_surface
, dst_surface
);
1067 wined3d_mutex_unlock();
1068 return D3DERR_INVALIDCALL
;
1071 /* Quick if complete copy ... */
1072 if (!rect_count
&& !src_rects
&& !dst_points
)
1074 RECT rect
= {0, 0, src_w
, src_h
};
1075 wined3d_texture_blt(dst
->wined3d_texture
, dst
->sub_resource_idx
, &rect
,
1076 src
->wined3d_texture
, src
->sub_resource_idx
, &rect
, 0, NULL
, WINED3D_TEXF_POINT
);
1081 /* Copy rect by rect */
1082 if (src_rects
&& dst_points
)
1084 for (i
= 0; i
< rect_count
; ++i
)
1086 UINT w
= src_rects
[i
].right
- src_rects
[i
].left
;
1087 UINT h
= src_rects
[i
].bottom
- src_rects
[i
].top
;
1088 RECT dst_rect
= {dst_points
[i
].x
, dst_points
[i
].y
,
1089 dst_points
[i
].x
+ w
, dst_points
[i
].y
+ h
};
1091 wined3d_texture_blt(dst
->wined3d_texture
, dst
->sub_resource_idx
, &dst_rect
,
1092 src
->wined3d_texture
, src
->sub_resource_idx
, &src_rects
[i
], 0, NULL
, WINED3D_TEXF_POINT
);
1097 for (i
= 0; i
< rect_count
; ++i
)
1099 UINT w
= src_rects
[i
].right
- src_rects
[i
].left
;
1100 UINT h
= src_rects
[i
].bottom
- src_rects
[i
].top
;
1101 RECT dst_rect
= {0, 0, w
, h
};
1103 wined3d_texture_blt(dst
->wined3d_texture
, dst
->sub_resource_idx
, &dst_rect
,
1104 src
->wined3d_texture
, src
->sub_resource_idx
, &src_rects
[i
], 0, NULL
, WINED3D_TEXF_POINT
);
1108 wined3d_mutex_unlock();
1113 static HRESULT WINAPI
d3d8_device_UpdateTexture(IDirect3DDevice8
*iface
,
1114 IDirect3DBaseTexture8
*src_texture
, IDirect3DBaseTexture8
*dst_texture
)
1116 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1117 struct d3d8_texture
*src_impl
, *dst_impl
;
1120 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface
, src_texture
, dst_texture
);
1122 src_impl
= unsafe_impl_from_IDirect3DBaseTexture8(src_texture
);
1123 dst_impl
= unsafe_impl_from_IDirect3DBaseTexture8(dst_texture
);
1125 wined3d_mutex_lock();
1126 hr
= wined3d_device_update_texture(device
->wined3d_device
,
1127 src_impl
->wined3d_texture
, dst_impl
->wined3d_texture
);
1128 wined3d_mutex_unlock();
1133 static HRESULT WINAPI
d3d8_device_GetFrontBuffer(IDirect3DDevice8
*iface
, IDirect3DSurface8
*dst_surface
)
1135 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1136 struct d3d8_surface
*dst_impl
= unsafe_impl_from_IDirect3DSurface8(dst_surface
);
1139 TRACE("iface %p, dst_surface %p.\n", iface
, dst_surface
);
1143 WARN("Invalid destination surface passed.\n");
1144 return D3DERR_INVALIDCALL
;
1147 wined3d_mutex_lock();
1148 hr
= wined3d_swapchain_get_front_buffer_data(device
->implicit_swapchain
->wined3d_swapchain
,
1149 dst_impl
->wined3d_texture
, dst_impl
->sub_resource_idx
);
1150 wined3d_mutex_unlock();
1155 static HRESULT WINAPI
d3d8_device_SetRenderTarget(IDirect3DDevice8
*iface
,
1156 IDirect3DSurface8
*render_target
, IDirect3DSurface8
*depth_stencil
)
1158 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1159 struct d3d8_surface
*rt_impl
= unsafe_impl_from_IDirect3DSurface8(render_target
);
1160 struct d3d8_surface
*ds_impl
= unsafe_impl_from_IDirect3DSurface8(depth_stencil
);
1161 struct wined3d_rendertarget_view
*original_dsv
;
1162 HRESULT hr
= D3D_OK
;
1164 TRACE("iface %p, render_target %p, depth_stencil %p.\n", iface
, render_target
, depth_stencil
);
1166 wined3d_mutex_lock();
1170 struct wined3d_rendertarget_view
*original_rtv
;
1171 struct wined3d_resource_desc ds_desc
, rt_desc
;
1172 struct wined3d_resource
*wined3d_resource
;
1173 struct d3d8_surface
*original_surface
;
1175 /* If no render target is passed in check the size against the current RT */
1179 if (!(original_rtv
= wined3d_device_get_rendertarget_view(device
->wined3d_device
, 0)))
1181 wined3d_mutex_unlock();
1182 return D3DERR_NOTFOUND
;
1184 original_surface
= wined3d_rendertarget_view_get_sub_resource_parent(original_rtv
);
1185 wined3d_resource
= wined3d_texture_get_sub_resource(original_surface
->wined3d_texture
, original_surface
->sub_resource_idx
);
1188 wined3d_resource
= wined3d_texture_get_sub_resource(rt_impl
->wined3d_texture
, rt_impl
->sub_resource_idx
);
1189 wined3d_resource_get_desc(wined3d_resource
, &rt_desc
);
1191 wined3d_resource
= wined3d_texture_get_sub_resource(ds_impl
->wined3d_texture
, ds_impl
->sub_resource_idx
);
1192 wined3d_resource_get_desc(wined3d_resource
, &ds_desc
);
1194 if (ds_desc
.width
< rt_desc
.width
|| ds_desc
.height
< rt_desc
.height
)
1196 WARN("Depth stencil is smaller than the render target, returning D3DERR_INVALIDCALL\n");
1197 wined3d_mutex_unlock();
1198 return D3DERR_INVALIDCALL
;
1200 if (ds_desc
.multisample_type
!= rt_desc
.multisample_type
1201 || ds_desc
.multisample_quality
!= rt_desc
.multisample_quality
)
1203 WARN("Multisample settings do not match, returning D3DERR_INVALIDCALL\n");
1204 wined3d_mutex_unlock();
1205 return D3DERR_INVALIDCALL
;
1210 original_dsv
= wined3d_device_get_depth_stencil_view(device
->wined3d_device
);
1211 wined3d_device_set_depth_stencil_view(device
->wined3d_device
,
1212 ds_impl
? d3d8_surface_get_rendertarget_view(ds_impl
) : NULL
);
1213 if (render_target
&& FAILED(hr
= wined3d_device_set_rendertarget_view(device
->wined3d_device
, 0,
1214 d3d8_surface_get_rendertarget_view(rt_impl
), TRUE
)))
1215 wined3d_device_set_depth_stencil_view(device
->wined3d_device
, original_dsv
);
1217 wined3d_mutex_unlock();
1222 static HRESULT WINAPI
d3d8_device_GetRenderTarget(IDirect3DDevice8
*iface
, IDirect3DSurface8
**render_target
)
1224 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1225 struct wined3d_rendertarget_view
*wined3d_rtv
;
1226 struct d3d8_surface
*surface_impl
;
1229 TRACE("iface %p, render_target %p.\n", iface
, render_target
);
1232 return D3DERR_INVALIDCALL
;
1234 wined3d_mutex_lock();
1235 if ((wined3d_rtv
= wined3d_device_get_rendertarget_view(device
->wined3d_device
, 0)))
1237 /* We want the sub resource parent here, since the view itself may be
1238 * internal to wined3d and may not have a parent. */
1239 surface_impl
= wined3d_rendertarget_view_get_sub_resource_parent(wined3d_rtv
);
1240 *render_target
= &surface_impl
->IDirect3DSurface8_iface
;
1241 IDirect3DSurface8_AddRef(*render_target
);
1246 ERR("Failed to get wined3d render target.\n");
1247 *render_target
= NULL
;
1248 hr
= D3DERR_NOTFOUND
;
1250 wined3d_mutex_unlock();
1255 static HRESULT WINAPI
d3d8_device_GetDepthStencilSurface(IDirect3DDevice8
*iface
, IDirect3DSurface8
**depth_stencil
)
1257 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1258 struct wined3d_rendertarget_view
*wined3d_dsv
;
1259 struct d3d8_surface
*surface_impl
;
1260 HRESULT hr
= D3D_OK
;
1262 TRACE("iface %p, depth_stencil %p.\n", iface
, depth_stencil
);
1265 return D3DERR_INVALIDCALL
;
1267 wined3d_mutex_lock();
1268 if ((wined3d_dsv
= wined3d_device_get_depth_stencil_view(device
->wined3d_device
)))
1270 /* We want the sub resource parent here, since the view itself may be
1271 * internal to wined3d and may not have a parent. */
1272 surface_impl
= wined3d_rendertarget_view_get_sub_resource_parent(wined3d_dsv
);
1273 *depth_stencil
= &surface_impl
->IDirect3DSurface8_iface
;
1274 IDirect3DSurface8_AddRef(*depth_stencil
);
1278 hr
= WINED3DERR_NOTFOUND
;
1279 *depth_stencil
= NULL
;
1281 wined3d_mutex_unlock();
1286 static HRESULT WINAPI
d3d8_device_BeginScene(IDirect3DDevice8
*iface
)
1288 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1291 TRACE("iface %p.\n", iface
);
1293 wined3d_mutex_lock();
1294 hr
= wined3d_device_begin_scene(device
->wined3d_device
);
1295 wined3d_mutex_unlock();
1300 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d8_device_EndScene(IDirect3DDevice8
*iface
)
1302 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1305 TRACE("iface %p.\n", iface
);
1307 wined3d_mutex_lock();
1308 hr
= wined3d_device_end_scene(device
->wined3d_device
);
1309 wined3d_mutex_unlock();
1314 static HRESULT WINAPI
d3d8_device_Clear(IDirect3DDevice8
*iface
, DWORD rect_count
,
1315 const D3DRECT
*rects
, DWORD flags
, D3DCOLOR color
, float z
, DWORD stencil
)
1317 const struct wined3d_color c
=
1319 ((color
>> 16) & 0xff) / 255.0f
,
1320 ((color
>> 8) & 0xff) / 255.0f
,
1321 (color
& 0xff) / 255.0f
,
1322 ((color
>> 24) & 0xff) / 255.0f
,
1324 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1327 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1328 iface
, rect_count
, rects
, flags
, color
, z
, stencil
);
1330 wined3d_mutex_lock();
1331 hr
= wined3d_device_clear(device
->wined3d_device
, rect_count
, (const RECT
*)rects
, flags
, &c
, z
, stencil
);
1332 wined3d_mutex_unlock();
1337 static HRESULT WINAPI
d3d8_device_SetTransform(IDirect3DDevice8
*iface
,
1338 D3DTRANSFORMSTATETYPE state
, const D3DMATRIX
*matrix
)
1340 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1342 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1344 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1345 wined3d_mutex_lock();
1346 wined3d_device_set_transform(device
->wined3d_device
, state
, (const struct wined3d_matrix
*)matrix
);
1347 wined3d_mutex_unlock();
1352 static HRESULT WINAPI
d3d8_device_GetTransform(IDirect3DDevice8
*iface
,
1353 D3DTRANSFORMSTATETYPE state
, D3DMATRIX
*matrix
)
1355 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1357 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1359 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1360 wined3d_mutex_lock();
1361 wined3d_device_get_transform(device
->wined3d_device
, state
, (struct wined3d_matrix
*)matrix
);
1362 wined3d_mutex_unlock();
1367 static HRESULT WINAPI
d3d8_device_MultiplyTransform(IDirect3DDevice8
*iface
,
1368 D3DTRANSFORMSTATETYPE state
, const D3DMATRIX
*matrix
)
1370 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1372 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1374 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1375 wined3d_mutex_lock();
1376 wined3d_device_multiply_transform(device
->wined3d_device
, state
, (const struct wined3d_matrix
*)matrix
);
1377 wined3d_mutex_unlock();
1382 static HRESULT WINAPI
d3d8_device_SetViewport(IDirect3DDevice8
*iface
, const D3DVIEWPORT8
*viewport
)
1384 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1386 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
1388 /* Note: D3DVIEWPORT8 is compatible with struct wined3d_viewport. */
1389 wined3d_mutex_lock();
1390 wined3d_device_set_viewport(device
->wined3d_device
, (const struct wined3d_viewport
*)viewport
);
1391 wined3d_mutex_unlock();
1396 static HRESULT WINAPI
d3d8_device_GetViewport(IDirect3DDevice8
*iface
, D3DVIEWPORT8
*viewport
)
1398 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1400 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
1402 /* Note: D3DVIEWPORT8 is compatible with struct wined3d_viewport. */
1403 wined3d_mutex_lock();
1404 wined3d_device_get_viewport(device
->wined3d_device
, (struct wined3d_viewport
*)viewport
);
1405 wined3d_mutex_unlock();
1410 static HRESULT WINAPI
d3d8_device_SetMaterial(IDirect3DDevice8
*iface
, const D3DMATERIAL8
*material
)
1412 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1414 TRACE("iface %p, material %p.\n", iface
, material
);
1416 /* Note: D3DMATERIAL8 is compatible with struct wined3d_material. */
1417 wined3d_mutex_lock();
1418 wined3d_device_set_material(device
->wined3d_device
, (const struct wined3d_material
*)material
);
1419 wined3d_mutex_unlock();
1424 static HRESULT WINAPI
d3d8_device_GetMaterial(IDirect3DDevice8
*iface
, D3DMATERIAL8
*material
)
1426 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1428 TRACE("iface %p, material %p.\n", iface
, material
);
1430 /* Note: D3DMATERIAL8 is compatible with struct wined3d_material. */
1431 wined3d_mutex_lock();
1432 wined3d_device_get_material(device
->wined3d_device
, (struct wined3d_material
*)material
);
1433 wined3d_mutex_unlock();
1438 static HRESULT WINAPI
d3d8_device_SetLight(IDirect3DDevice8
*iface
, DWORD index
, const D3DLIGHT8
*light
)
1440 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1443 TRACE("iface %p, index %u, light %p.\n", iface
, index
, light
);
1445 /* Note: D3DLIGHT8 is compatible with struct wined3d_light. */
1446 wined3d_mutex_lock();
1447 hr
= wined3d_device_set_light(device
->wined3d_device
, index
, (const struct wined3d_light
*)light
);
1448 wined3d_mutex_unlock();
1453 static HRESULT WINAPI
d3d8_device_GetLight(IDirect3DDevice8
*iface
, DWORD index
, D3DLIGHT8
*light
)
1455 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1458 TRACE("iface %p, index %u, light %p.\n", iface
, index
, light
);
1460 /* Note: D3DLIGHT8 is compatible with struct wined3d_light. */
1461 wined3d_mutex_lock();
1462 hr
= wined3d_device_get_light(device
->wined3d_device
, index
, (struct wined3d_light
*)light
);
1463 wined3d_mutex_unlock();
1468 static HRESULT WINAPI
d3d8_device_LightEnable(IDirect3DDevice8
*iface
, DWORD index
, BOOL enable
)
1470 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1473 TRACE("iface %p, index %u, enable %#x.\n", iface
, index
, enable
);
1475 wined3d_mutex_lock();
1476 hr
= wined3d_device_set_light_enable(device
->wined3d_device
, index
, enable
);
1477 wined3d_mutex_unlock();
1482 static HRESULT WINAPI
d3d8_device_GetLightEnable(IDirect3DDevice8
*iface
, DWORD index
, BOOL
*enable
)
1484 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1487 TRACE("iface %p, index %u, enable %p.\n", iface
, index
, enable
);
1489 wined3d_mutex_lock();
1490 hr
= wined3d_device_get_light_enable(device
->wined3d_device
, index
, enable
);
1491 wined3d_mutex_unlock();
1496 static HRESULT WINAPI
d3d8_device_SetClipPlane(IDirect3DDevice8
*iface
, DWORD index
, const float *plane
)
1498 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1501 TRACE("iface %p, index %u, plane %p.\n", iface
, index
, plane
);
1503 wined3d_mutex_lock();
1504 hr
= wined3d_device_set_clip_plane(device
->wined3d_device
, index
, (const struct wined3d_vec4
*)plane
);
1505 wined3d_mutex_unlock();
1510 static HRESULT WINAPI
d3d8_device_GetClipPlane(IDirect3DDevice8
*iface
, DWORD index
, float *plane
)
1512 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1515 TRACE("iface %p, index %u, plane %p.\n", iface
, index
, plane
);
1517 wined3d_mutex_lock();
1518 hr
= wined3d_device_get_clip_plane(device
->wined3d_device
, index
, (struct wined3d_vec4
*)plane
);
1519 wined3d_mutex_unlock();
1524 static HRESULT WINAPI
d3d8_device_SetRenderState(IDirect3DDevice8
*iface
,
1525 D3DRENDERSTATETYPE state
, DWORD value
)
1527 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1529 TRACE("iface %p, state %#x, value %#x.\n", iface
, state
, value
);
1531 wined3d_mutex_lock();
1535 wined3d_device_set_render_state(device
->wined3d_device
, WINED3D_RS_DEPTHBIAS
, value
);
1539 wined3d_device_set_render_state(device
->wined3d_device
, state
, value
);
1541 wined3d_mutex_unlock();
1546 static HRESULT WINAPI
d3d8_device_GetRenderState(IDirect3DDevice8
*iface
,
1547 D3DRENDERSTATETYPE state
, DWORD
*value
)
1549 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1551 TRACE("iface %p, state %#x, value %p.\n", iface
, state
, value
);
1553 wined3d_mutex_lock();
1557 *value
= wined3d_device_get_render_state(device
->wined3d_device
, WINED3D_RS_DEPTHBIAS
);
1561 *value
= wined3d_device_get_render_state(device
->wined3d_device
, state
);
1563 wined3d_mutex_unlock();
1568 static HRESULT WINAPI
d3d8_device_BeginStateBlock(IDirect3DDevice8
*iface
)
1570 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1573 TRACE("iface %p.\n", iface
);
1575 wined3d_mutex_lock();
1576 hr
= wined3d_device_begin_stateblock(device
->wined3d_device
);
1577 wined3d_mutex_unlock();
1582 static HRESULT WINAPI
d3d8_device_EndStateBlock(IDirect3DDevice8
*iface
, DWORD
*token
)
1584 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1585 struct wined3d_stateblock
*stateblock
;
1588 TRACE("iface %p, token %p.\n", iface
, token
);
1590 /* Tell wineD3D to endstateblock before anything else (in case we run out
1591 * of memory later and cause locking problems)
1593 wined3d_mutex_lock();
1594 hr
= wined3d_device_end_stateblock(device
->wined3d_device
, &stateblock
);
1597 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
1598 wined3d_mutex_unlock();
1602 *token
= d3d8_allocate_handle(&device
->handle_table
, stateblock
, D3D8_HANDLE_SB
);
1603 wined3d_mutex_unlock();
1605 if (*token
== D3D8_INVALID_HANDLE
)
1607 ERR("Failed to create a handle\n");
1608 wined3d_mutex_lock();
1609 wined3d_stateblock_decref(stateblock
);
1610 wined3d_mutex_unlock();
1615 TRACE("Returning %#x (%p).\n", *token
, stateblock
);
1620 static HRESULT WINAPI
d3d8_device_ApplyStateBlock(IDirect3DDevice8
*iface
, DWORD token
)
1622 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1623 struct wined3d_stateblock
*stateblock
;
1625 TRACE("iface %p, token %#x.\n", iface
, token
);
1630 wined3d_mutex_lock();
1631 stateblock
= d3d8_get_object(&device
->handle_table
, token
- 1, D3D8_HANDLE_SB
);
1634 WARN("Invalid handle (%#x) passed.\n", token
);
1635 wined3d_mutex_unlock();
1636 return D3DERR_INVALIDCALL
;
1638 wined3d_stateblock_apply(stateblock
);
1639 wined3d_mutex_unlock();
1644 static HRESULT WINAPI
d3d8_device_CaptureStateBlock(IDirect3DDevice8
*iface
, DWORD token
)
1646 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1647 struct wined3d_stateblock
*stateblock
;
1649 TRACE("iface %p, token %#x.\n", iface
, token
);
1651 wined3d_mutex_lock();
1652 stateblock
= d3d8_get_object(&device
->handle_table
, token
- 1, D3D8_HANDLE_SB
);
1655 WARN("Invalid handle (%#x) passed.\n", token
);
1656 wined3d_mutex_unlock();
1657 return D3DERR_INVALIDCALL
;
1659 wined3d_stateblock_capture(stateblock
);
1660 wined3d_mutex_unlock();
1665 static HRESULT WINAPI
d3d8_device_DeleteStateBlock(IDirect3DDevice8
*iface
, DWORD token
)
1667 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1668 struct wined3d_stateblock
*stateblock
;
1670 TRACE("iface %p, token %#x.\n", iface
, token
);
1672 wined3d_mutex_lock();
1673 stateblock
= d3d8_free_handle(&device
->handle_table
, token
- 1, D3D8_HANDLE_SB
);
1677 WARN("Invalid handle (%#x) passed.\n", token
);
1678 wined3d_mutex_unlock();
1679 return D3DERR_INVALIDCALL
;
1682 if (wined3d_stateblock_decref(stateblock
))
1684 ERR("Stateblock %p has references left, this shouldn't happen.\n", stateblock
);
1686 wined3d_mutex_unlock();
1691 static HRESULT WINAPI
d3d8_device_CreateStateBlock(IDirect3DDevice8
*iface
,
1692 D3DSTATEBLOCKTYPE type
, DWORD
*handle
)
1694 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1695 struct wined3d_stateblock
*stateblock
;
1698 TRACE("iface %p, type %#x, handle %p.\n", iface
, type
, handle
);
1700 if (type
!= D3DSBT_ALL
1701 && type
!= D3DSBT_PIXELSTATE
1702 && type
!= D3DSBT_VERTEXSTATE
)
1704 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1705 return D3DERR_INVALIDCALL
;
1708 wined3d_mutex_lock();
1709 hr
= wined3d_stateblock_create(device
->wined3d_device
, (enum wined3d_stateblock_type
)type
, &stateblock
);
1712 wined3d_mutex_unlock();
1713 ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr
);
1717 *handle
= d3d8_allocate_handle(&device
->handle_table
, stateblock
, D3D8_HANDLE_SB
);
1718 wined3d_mutex_unlock();
1720 if (*handle
== D3D8_INVALID_HANDLE
)
1722 ERR("Failed to allocate a handle.\n");
1723 wined3d_mutex_lock();
1724 wined3d_stateblock_decref(stateblock
);
1725 wined3d_mutex_unlock();
1730 TRACE("Returning %#x (%p).\n", *handle
, stateblock
);
1735 static HRESULT WINAPI
d3d8_device_SetClipStatus(IDirect3DDevice8
*iface
, const D3DCLIPSTATUS8
*clip_status
)
1737 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1740 TRACE("iface %p, clip_status %p.\n", iface
, clip_status
);
1741 /* FIXME: Verify that D3DCLIPSTATUS8 ~= struct wined3d_clip_status. */
1743 wined3d_mutex_lock();
1744 hr
= wined3d_device_set_clip_status(device
->wined3d_device
, (const struct wined3d_clip_status
*)clip_status
);
1745 wined3d_mutex_unlock();
1750 static HRESULT WINAPI
d3d8_device_GetClipStatus(IDirect3DDevice8
*iface
, D3DCLIPSTATUS8
*clip_status
)
1752 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1755 TRACE("iface %p, clip_status %p.\n", iface
, clip_status
);
1757 wined3d_mutex_lock();
1758 hr
= wined3d_device_get_clip_status(device
->wined3d_device
, (struct wined3d_clip_status
*)clip_status
);
1759 wined3d_mutex_unlock();
1764 static HRESULT WINAPI
d3d8_device_GetTexture(IDirect3DDevice8
*iface
, DWORD stage
, IDirect3DBaseTexture8
**texture
)
1766 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1767 struct wined3d_texture
*wined3d_texture
;
1768 struct d3d8_texture
*texture_impl
;
1770 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
1773 return D3DERR_INVALIDCALL
;
1775 wined3d_mutex_lock();
1776 if ((wined3d_texture
= wined3d_device_get_texture(device
->wined3d_device
, stage
)))
1778 texture_impl
= wined3d_texture_get_parent(wined3d_texture
);
1779 *texture
= &texture_impl
->IDirect3DBaseTexture8_iface
;
1780 IDirect3DBaseTexture8_AddRef(*texture
);
1786 wined3d_mutex_unlock();
1791 static HRESULT WINAPI
d3d8_device_SetTexture(IDirect3DDevice8
*iface
, DWORD stage
, IDirect3DBaseTexture8
*texture
)
1793 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1794 struct d3d8_texture
*texture_impl
;
1797 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
1799 texture_impl
= unsafe_impl_from_IDirect3DBaseTexture8(texture
);
1801 wined3d_mutex_lock();
1802 hr
= wined3d_device_set_texture(device
->wined3d_device
, stage
,
1803 texture_impl
? texture_impl
->wined3d_texture
: NULL
);
1804 wined3d_mutex_unlock();
1809 static const struct tss_lookup
1812 enum wined3d_texture_stage_state state
;
1816 {FALSE
, WINED3D_TSS_INVALID
}, /* 0, unused */
1817 {FALSE
, WINED3D_TSS_COLOR_OP
}, /* 1, D3DTSS_COLOROP */
1818 {FALSE
, WINED3D_TSS_COLOR_ARG1
}, /* 2, D3DTSS_COLORARG1 */
1819 {FALSE
, WINED3D_TSS_COLOR_ARG2
}, /* 3, D3DTSS_COLORARG2 */
1820 {FALSE
, WINED3D_TSS_ALPHA_OP
}, /* 4, D3DTSS_ALPHAOP */
1821 {FALSE
, WINED3D_TSS_ALPHA_ARG1
}, /* 5, D3DTSS_ALPHAARG1 */
1822 {FALSE
, WINED3D_TSS_ALPHA_ARG2
}, /* 6, D3DTSS_ALPHAARG2 */
1823 {FALSE
, WINED3D_TSS_BUMPENV_MAT00
}, /* 7, D3DTSS_BUMPENVMAT00 */
1824 {FALSE
, WINED3D_TSS_BUMPENV_MAT01
}, /* 8, D3DTSS_BUMPENVMAT01 */
1825 {FALSE
, WINED3D_TSS_BUMPENV_MAT10
}, /* 9, D3DTSS_BUMPENVMAT10 */
1826 {FALSE
, WINED3D_TSS_BUMPENV_MAT11
}, /* 10, D3DTSS_BUMPENVMAT11 */
1827 {FALSE
, WINED3D_TSS_TEXCOORD_INDEX
}, /* 11, D3DTSS_TEXCOORDINDEX */
1828 {FALSE
, WINED3D_TSS_INVALID
}, /* 12, unused */
1829 {TRUE
, WINED3D_SAMP_ADDRESS_U
}, /* 13, D3DTSS_ADDRESSU */
1830 {TRUE
, WINED3D_SAMP_ADDRESS_V
}, /* 14, D3DTSS_ADDRESSV */
1831 {TRUE
, WINED3D_SAMP_BORDER_COLOR
}, /* 15, D3DTSS_BORDERCOLOR */
1832 {TRUE
, WINED3D_SAMP_MAG_FILTER
}, /* 16, D3DTSS_MAGFILTER */
1833 {TRUE
, WINED3D_SAMP_MIN_FILTER
}, /* 17, D3DTSS_MINFILTER */
1834 {TRUE
, WINED3D_SAMP_MIP_FILTER
}, /* 18, D3DTSS_MIPFILTER */
1835 {TRUE
, WINED3D_SAMP_MIPMAP_LOD_BIAS
}, /* 19, D3DTSS_MIPMAPLODBIAS */
1836 {TRUE
, WINED3D_SAMP_MAX_MIP_LEVEL
}, /* 20, D3DTSS_MAXMIPLEVEL */
1837 {TRUE
, WINED3D_SAMP_MAX_ANISOTROPY
}, /* 21, D3DTSS_MAXANISOTROPY */
1838 {FALSE
, WINED3D_TSS_BUMPENV_LSCALE
}, /* 22, D3DTSS_BUMPENVLSCALE */
1839 {FALSE
, WINED3D_TSS_BUMPENV_LOFFSET
}, /* 23, D3DTSS_BUMPENVLOFFSET */
1840 {FALSE
, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1841 {TRUE
, WINED3D_SAMP_ADDRESS_W
}, /* 25, D3DTSS_ADDRESSW */
1842 {FALSE
, WINED3D_TSS_COLOR_ARG0
}, /* 26, D3DTSS_COLORARG0 */
1843 {FALSE
, WINED3D_TSS_ALPHA_ARG0
}, /* 27, D3DTSS_ALPHAARG0 */
1844 {FALSE
, WINED3D_TSS_RESULT_ARG
}, /* 28, D3DTSS_RESULTARG */
1847 static HRESULT WINAPI
d3d8_device_GetTextureStageState(IDirect3DDevice8
*iface
,
1848 DWORD stage
, D3DTEXTURESTAGESTATETYPE Type
, DWORD
*value
)
1850 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1851 const struct tss_lookup
*l
;
1853 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface
, stage
, Type
, value
);
1855 if (Type
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
1857 WARN("Invalid Type %#x passed.\n", Type
);
1861 l
= &tss_lookup
[Type
];
1863 wined3d_mutex_lock();
1864 if (l
->sampler_state
)
1865 *value
= wined3d_device_get_sampler_state(device
->wined3d_device
, stage
, l
->state
);
1867 *value
= wined3d_device_get_texture_stage_state(device
->wined3d_device
, stage
, l
->state
);
1868 wined3d_mutex_unlock();
1873 static HRESULT WINAPI
d3d8_device_SetTextureStageState(IDirect3DDevice8
*iface
,
1874 DWORD stage
, D3DTEXTURESTAGESTATETYPE type
, DWORD value
)
1876 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1877 const struct tss_lookup
*l
;
1879 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface
, stage
, type
, value
);
1881 if (type
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
1883 WARN("Invalid type %#x passed.\n", type
);
1887 l
= &tss_lookup
[type
];
1889 wined3d_mutex_lock();
1890 if (l
->sampler_state
)
1891 wined3d_device_set_sampler_state(device
->wined3d_device
, stage
, l
->state
, value
);
1893 wined3d_device_set_texture_stage_state(device
->wined3d_device
, stage
, l
->state
, value
);
1894 wined3d_mutex_unlock();
1899 static HRESULT WINAPI
d3d8_device_ValidateDevice(IDirect3DDevice8
*iface
, DWORD
*pass_count
)
1901 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1904 TRACE("iface %p, pass_count %p.\n", iface
, pass_count
);
1906 wined3d_mutex_lock();
1907 hr
= wined3d_device_validate_device(device
->wined3d_device
, pass_count
);
1908 wined3d_mutex_unlock();
1913 static HRESULT WINAPI
d3d8_device_GetInfo(IDirect3DDevice8
*iface
,
1914 DWORD info_id
, void *info
, DWORD info_size
)
1916 FIXME("iface %p, info_id %#x, info %p, info_size %u stub!\n", iface
, info_id
, info
, info_size
);
1921 static HRESULT WINAPI
d3d8_device_SetPaletteEntries(IDirect3DDevice8
*iface
,
1922 UINT palette_idx
, const PALETTEENTRY
*entries
)
1924 WARN("iface %p, palette_idx %u, entries %p unimplemented\n", iface
, palette_idx
, entries
);
1926 /* GPUs stopped supporting palettized textures with the Shader Model 1 generation. Wined3d
1927 * does not have a d3d8/9-style palette API */
1932 static HRESULT WINAPI
d3d8_device_GetPaletteEntries(IDirect3DDevice8
*iface
,
1933 UINT palette_idx
, PALETTEENTRY
*entries
)
1935 FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface
, palette_idx
, entries
);
1937 return D3DERR_INVALIDCALL
;
1940 static HRESULT WINAPI
d3d8_device_SetCurrentTexturePalette(IDirect3DDevice8
*iface
, UINT palette_idx
)
1942 WARN("iface %p, palette_idx %u unimplemented.\n", iface
, palette_idx
);
1947 static HRESULT WINAPI
d3d8_device_GetCurrentTexturePalette(IDirect3DDevice8
*iface
, UINT
*palette_idx
)
1949 FIXME("iface %p, palette_idx %p unimplemented.\n", iface
, palette_idx
);
1951 return D3DERR_INVALIDCALL
;
1954 static HRESULT WINAPI
d3d8_device_DrawPrimitive(IDirect3DDevice8
*iface
,
1955 D3DPRIMITIVETYPE primitive_type
, UINT start_vertex
, UINT primitive_count
)
1957 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1960 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1961 iface
, primitive_type
, start_vertex
, primitive_count
);
1963 wined3d_mutex_lock();
1964 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
1965 hr
= wined3d_device_draw_primitive(device
->wined3d_device
, start_vertex
,
1966 vertex_count_from_primitive_count(primitive_type
, primitive_count
));
1967 wined3d_mutex_unlock();
1972 static HRESULT WINAPI
d3d8_device_DrawIndexedPrimitive(IDirect3DDevice8
*iface
,
1973 D3DPRIMITIVETYPE primitive_type
, UINT min_vertex_idx
, UINT vertex_count
,
1974 UINT start_idx
, UINT primitive_count
)
1976 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1979 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, start_idx %u, primitive_count %u.\n",
1980 iface
, primitive_type
, min_vertex_idx
, vertex_count
, start_idx
, primitive_count
);
1982 wined3d_mutex_lock();
1983 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
1984 hr
= wined3d_device_draw_indexed_primitive(device
->wined3d_device
, start_idx
,
1985 vertex_count_from_primitive_count(primitive_type
, primitive_count
));
1986 wined3d_mutex_unlock();
1991 /* The caller is responsible for wined3d locking */
1992 static HRESULT
d3d8_device_prepare_vertex_buffer(struct d3d8_device
*device
, UINT min_size
)
1996 if (device
->vertex_buffer_size
< min_size
|| !device
->vertex_buffer
)
1998 UINT size
= max(device
->vertex_buffer_size
* 2, min_size
);
1999 struct wined3d_buffer
*buffer
;
2001 TRACE("Growing vertex buffer to %u bytes\n", size
);
2003 hr
= wined3d_buffer_create_vb(device
->wined3d_device
, size
, WINED3DUSAGE_DYNAMIC
| WINED3DUSAGE_WRITEONLY
,
2004 WINED3D_POOL_DEFAULT
, NULL
, &d3d8_null_wined3d_parent_ops
, &buffer
);
2007 ERR("(%p) wined3d_buffer_create_vb failed with hr = %08x\n", device
, hr
);
2011 if (device
->vertex_buffer
)
2012 wined3d_buffer_decref(device
->vertex_buffer
);
2014 device
->vertex_buffer
= buffer
;
2015 device
->vertex_buffer_size
= size
;
2016 device
->vertex_buffer_pos
= 0;
2021 static HRESULT WINAPI
d3d8_device_DrawPrimitiveUP(IDirect3DDevice8
*iface
,
2022 D3DPRIMITIVETYPE primitive_type
, UINT primitive_count
, const void *data
,
2025 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2027 UINT vtx_count
= vertex_count_from_primitive_count(primitive_type
, primitive_count
);
2028 UINT size
= vtx_count
* stride
;
2032 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
2033 iface
, primitive_type
, primitive_count
, data
, stride
);
2035 if (!primitive_count
)
2037 WARN("primitive_count is 0, returning D3D_OK\n");
2041 wined3d_mutex_lock();
2042 hr
= d3d8_device_prepare_vertex_buffer(device
, size
);
2046 vb_pos
= device
->vertex_buffer_pos
;
2047 align
= vb_pos
% stride
;
2048 if (align
) align
= stride
- align
;
2049 if (vb_pos
+ size
+ align
> device
->vertex_buffer_size
)
2054 hr
= wined3d_buffer_map(device
->vertex_buffer
, vb_pos
, size
, &buffer_data
,
2055 vb_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
);
2058 memcpy(buffer_data
, data
, size
);
2059 wined3d_buffer_unmap(device
->vertex_buffer
);
2060 device
->vertex_buffer_pos
= vb_pos
+ size
;
2062 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, 0, device
->vertex_buffer
, 0, stride
);
2066 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
2067 hr
= wined3d_device_draw_primitive(device
->wined3d_device
, vb_pos
/ stride
, vtx_count
);
2068 wined3d_device_set_stream_source(device
->wined3d_device
, 0, NULL
, 0, 0);
2071 wined3d_mutex_unlock();
2075 /* The caller is responsible for wined3d locking */
2076 static HRESULT
d3d8_device_prepare_index_buffer(struct d3d8_device
*device
, UINT min_size
)
2080 if (device
->index_buffer_size
< min_size
|| !device
->index_buffer
)
2082 UINT size
= max(device
->index_buffer_size
* 2, min_size
);
2083 struct wined3d_buffer
*buffer
;
2085 TRACE("Growing index buffer to %u bytes\n", size
);
2087 hr
= wined3d_buffer_create_ib(device
->wined3d_device
, size
, WINED3DUSAGE_DYNAMIC
| WINED3DUSAGE_WRITEONLY
,
2088 WINED3D_POOL_DEFAULT
, NULL
, &d3d8_null_wined3d_parent_ops
, &buffer
);
2091 ERR("(%p) wined3d_buffer_create_ib failed with hr = %08x\n", device
, hr
);
2095 if (device
->index_buffer
)
2096 wined3d_buffer_decref(device
->index_buffer
);
2098 device
->index_buffer
= buffer
;
2099 device
->index_buffer_size
= size
;
2100 device
->index_buffer_pos
= 0;
2105 static HRESULT WINAPI
d3d8_device_DrawIndexedPrimitiveUP(IDirect3DDevice8
*iface
,
2106 D3DPRIMITIVETYPE primitive_type
, UINT min_vertex_idx
, UINT vertex_count
,
2107 UINT primitive_count
, const void *index_data
, D3DFORMAT index_format
,
2108 const void *vertex_data
, UINT vertex_stride
)
2110 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2114 UINT idx_count
= vertex_count_from_primitive_count(primitive_type
, primitive_count
);
2115 UINT idx_fmt_size
= index_format
== D3DFMT_INDEX16
? 2 : 4;
2116 UINT idx_size
= idx_count
* idx_fmt_size
;
2119 UINT vtx_size
= vertex_count
* vertex_stride
;
2122 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, primitive_count %u,\n"
2123 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
2124 iface
, primitive_type
, min_vertex_idx
, vertex_count
, primitive_count
,
2125 index_data
, index_format
, vertex_data
, vertex_stride
);
2127 if (!primitive_count
)
2129 WARN("primitive_count is 0, returning D3D_OK\n");
2133 wined3d_mutex_lock();
2135 hr
= d3d8_device_prepare_vertex_buffer(device
, vtx_size
);
2139 vb_pos
= device
->vertex_buffer_pos
;
2140 align
= vb_pos
% vertex_stride
;
2141 if (align
) align
= vertex_stride
- align
;
2142 if (vb_pos
+ vtx_size
+ align
> device
->vertex_buffer_size
)
2147 hr
= wined3d_buffer_map(device
->vertex_buffer
, vb_pos
, vtx_size
, &buffer_data
,
2148 vb_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
);
2151 memcpy(buffer_data
, vertex_data
, vtx_size
);
2152 wined3d_buffer_unmap(device
->vertex_buffer
);
2153 device
->vertex_buffer_pos
= vb_pos
+ vtx_size
;
2155 hr
= d3d8_device_prepare_index_buffer(device
, idx_size
);
2159 ib_pos
= device
->index_buffer_pos
;
2160 align
= ib_pos
% idx_fmt_size
;
2161 if (align
) align
= idx_fmt_size
- align
;
2162 if (ib_pos
+ idx_size
+ align
> device
->index_buffer_size
)
2167 hr
= wined3d_buffer_map(device
->index_buffer
, ib_pos
, idx_size
, &buffer_data
,
2168 ib_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
);
2171 memcpy(buffer_data
, index_data
, idx_size
);
2172 wined3d_buffer_unmap(device
->index_buffer
);
2173 device
->index_buffer_pos
= ib_pos
+ idx_size
;
2175 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, 0, device
->vertex_buffer
, 0, vertex_stride
);
2179 wined3d_device_set_index_buffer(device
->wined3d_device
, device
->index_buffer
,
2180 wined3dformat_from_d3dformat(index_format
));
2181 wined3d_device_set_base_vertex_index(device
->wined3d_device
, vb_pos
/ vertex_stride
);
2183 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
2184 hr
= wined3d_device_draw_indexed_primitive(device
->wined3d_device
, ib_pos
/ idx_fmt_size
, idx_count
);
2186 wined3d_device_set_stream_source(device
->wined3d_device
, 0, NULL
, 0, 0);
2187 wined3d_device_set_index_buffer(device
->wined3d_device
, NULL
, WINED3DFMT_UNKNOWN
);
2188 wined3d_device_set_base_vertex_index(device
->wined3d_device
, 0);
2191 wined3d_mutex_unlock();
2195 static HRESULT WINAPI
d3d8_device_ProcessVertices(IDirect3DDevice8
*iface
, UINT src_start_idx
,
2196 UINT dst_idx
, UINT vertex_count
, IDirect3DVertexBuffer8
*dst_buffer
, DWORD flags
)
2198 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2199 struct d3d8_vertexbuffer
*dst
= unsafe_impl_from_IDirect3DVertexBuffer8(dst_buffer
);
2202 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, flags %#x.\n",
2203 iface
, src_start_idx
, dst_idx
, vertex_count
, dst_buffer
, flags
);
2205 wined3d_mutex_lock();
2206 hr
= wined3d_device_process_vertices(device
->wined3d_device
, src_start_idx
, dst_idx
,
2207 vertex_count
, dst
->wined3d_buffer
, NULL
, flags
, dst
->fvf
);
2208 wined3d_mutex_unlock();
2213 static HRESULT WINAPI
d3d8_device_CreateVertexShader(IDirect3DDevice8
*iface
,
2214 const DWORD
*declaration
, const DWORD
*byte_code
, DWORD
*shader
, DWORD usage
)
2216 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2217 struct d3d8_vertex_shader
*object
;
2218 DWORD shader_handle
;
2222 TRACE("iface %p, declaration %p, byte_code %p, shader %p, usage %#x.\n",
2223 iface
, declaration
, byte_code
, shader
, usage
);
2225 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2229 return E_OUTOFMEMORY
;
2232 wined3d_mutex_lock();
2233 handle
= d3d8_allocate_handle(&device
->handle_table
, object
, D3D8_HANDLE_VS
);
2234 wined3d_mutex_unlock();
2235 if (handle
== D3D8_INVALID_HANDLE
)
2237 ERR("Failed to allocate vertex shader handle.\n");
2238 HeapFree(GetProcessHeap(), 0, object
);
2240 return E_OUTOFMEMORY
;
2243 shader_handle
= handle
+ VS_HIGHESTFIXEDFXF
+ 1;
2245 hr
= d3d8_vertex_shader_init(object
, device
, declaration
, byte_code
, shader_handle
, usage
);
2248 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
2249 wined3d_mutex_lock();
2250 d3d8_free_handle(&device
->handle_table
, handle
, D3D8_HANDLE_VS
);
2251 wined3d_mutex_unlock();
2252 HeapFree(GetProcessHeap(), 0, object
);
2257 TRACE("Created vertex shader %p (handle %#x).\n", object
, shader_handle
);
2258 *shader
= shader_handle
;
2263 static struct d3d8_vertex_declaration
*d3d8_device_get_fvf_declaration(struct d3d8_device
*device
, DWORD fvf
)
2265 struct d3d8_vertex_declaration
*d3d8_declaration
;
2266 struct FvfToDecl
*convertedDecls
= device
->decls
;
2267 int p
, low
, high
; /* deliberately signed */
2270 TRACE("Searching for declaration for fvf %08x... ", fvf
);
2273 high
= device
->numConvertedDecls
- 1;
2276 p
= (low
+ high
) >> 1;
2279 if (convertedDecls
[p
].fvf
== fvf
)
2281 TRACE("found %p\n", convertedDecls
[p
].declaration
);
2282 return convertedDecls
[p
].declaration
;
2285 if (convertedDecls
[p
].fvf
< fvf
)
2290 TRACE("not found. Creating and inserting at position %d.\n", low
);
2292 if (!(d3d8_declaration
= HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration
))))
2295 if (FAILED(hr
= d3d8_vertex_declaration_init_fvf(d3d8_declaration
, device
, fvf
)))
2297 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr
);
2298 HeapFree(GetProcessHeap(), 0, d3d8_declaration
);
2302 if (device
->declArraySize
== device
->numConvertedDecls
)
2304 UINT grow
= device
->declArraySize
/ 2;
2306 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
2307 sizeof(*convertedDecls
) * (device
->numConvertedDecls
+ grow
));
2308 if (!convertedDecls
)
2310 d3d8_vertex_declaration_destroy(d3d8_declaration
);
2313 device
->decls
= convertedDecls
;
2314 device
->declArraySize
+= grow
;
2317 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
,
2318 sizeof(*convertedDecls
) * (device
->numConvertedDecls
- low
));
2319 convertedDecls
[low
].declaration
= d3d8_declaration
;
2320 convertedDecls
[low
].fvf
= fvf
;
2321 ++device
->numConvertedDecls
;
2323 TRACE("Returning %p. %u decls in array.\n", d3d8_declaration
, device
->numConvertedDecls
);
2325 return d3d8_declaration
;
2328 static HRESULT WINAPI
d3d8_device_SetVertexShader(IDirect3DDevice8
*iface
, DWORD shader
)
2330 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2331 struct d3d8_vertex_shader
*shader_impl
;
2333 TRACE("iface %p, shader %#x.\n", iface
, shader
);
2335 if (VS_HIGHESTFIXEDFXF
>= shader
)
2337 TRACE("Setting FVF, %#x\n", shader
);
2339 wined3d_mutex_lock();
2340 wined3d_device_set_vertex_declaration(device
->wined3d_device
,
2341 d3d8_device_get_fvf_declaration(device
, shader
)->wined3d_vertex_declaration
);
2342 wined3d_device_set_vertex_shader(device
->wined3d_device
, NULL
);
2343 wined3d_mutex_unlock();
2348 TRACE("Setting shader\n");
2350 wined3d_mutex_lock();
2351 if (!(shader_impl
= d3d8_get_object(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
)))
2353 WARN("Invalid handle (%#x) passed.\n", shader
);
2354 wined3d_mutex_unlock();
2356 return D3DERR_INVALIDCALL
;
2359 wined3d_device_set_vertex_declaration(device
->wined3d_device
,
2360 shader_impl
->vertex_declaration
->wined3d_vertex_declaration
);
2361 wined3d_device_set_vertex_shader(device
->wined3d_device
, shader_impl
->wined3d_shader
);
2362 wined3d_mutex_unlock();
2367 static HRESULT WINAPI
d3d8_device_GetVertexShader(IDirect3DDevice8
*iface
, DWORD
*shader
)
2369 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2370 struct wined3d_vertex_declaration
*wined3d_declaration
;
2371 struct d3d8_vertex_declaration
*d3d8_declaration
;
2373 TRACE("iface %p, shader %p.\n", iface
, shader
);
2375 wined3d_mutex_lock();
2376 if ((wined3d_declaration
= wined3d_device_get_vertex_declaration(device
->wined3d_device
)))
2378 d3d8_declaration
= wined3d_vertex_declaration_get_parent(wined3d_declaration
);
2379 *shader
= d3d8_declaration
->shader_handle
;
2385 wined3d_mutex_unlock();
2387 TRACE("Returning %#x.\n", *shader
);
2392 static HRESULT WINAPI
d3d8_device_DeleteVertexShader(IDirect3DDevice8
*iface
, DWORD shader
)
2394 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2395 struct d3d8_vertex_shader
*shader_impl
;
2397 TRACE("iface %p, shader %#x.\n", iface
, shader
);
2399 wined3d_mutex_lock();
2400 if (!(shader_impl
= d3d8_free_handle(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
)))
2402 WARN("Invalid handle (%#x) passed.\n", shader
);
2403 wined3d_mutex_unlock();
2405 return D3DERR_INVALIDCALL
;
2408 if (shader_impl
->wined3d_shader
2409 && wined3d_device_get_vertex_shader(device
->wined3d_device
) == shader_impl
->wined3d_shader
)
2410 IDirect3DDevice8_SetVertexShader(iface
, 0);
2412 wined3d_mutex_unlock();
2414 d3d8_vertex_shader_destroy(shader_impl
);
2419 static HRESULT WINAPI
d3d8_device_SetVertexShaderConstant(IDirect3DDevice8
*iface
,
2420 DWORD start_register
, const void *data
, DWORD count
)
2422 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2425 TRACE("iface %p, start_register %u, data %p, count %u.\n",
2426 iface
, start_register
, data
, count
);
2428 if (start_register
+ count
> D3D8_MAX_VERTEX_SHADER_CONSTANTF
)
2430 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2431 start_register
+ count
, D3D8_MAX_VERTEX_SHADER_CONSTANTF
);
2432 return D3DERR_INVALIDCALL
;
2435 wined3d_mutex_lock();
2436 hr
= wined3d_device_set_vs_consts_f(device
->wined3d_device
, start_register
, data
, count
);
2437 wined3d_mutex_unlock();
2442 static HRESULT WINAPI
d3d8_device_GetVertexShaderConstant(IDirect3DDevice8
*iface
,
2443 DWORD start_register
, void *data
, DWORD count
)
2445 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2448 TRACE("iface %p, start_register %u, data %p, count %u.\n",
2449 iface
, start_register
, data
, count
);
2451 if (start_register
+ count
> D3D8_MAX_VERTEX_SHADER_CONSTANTF
)
2453 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2454 start_register
+ count
, D3D8_MAX_VERTEX_SHADER_CONSTANTF
);
2455 return D3DERR_INVALIDCALL
;
2458 wined3d_mutex_lock();
2459 hr
= wined3d_device_get_vs_consts_f(device
->wined3d_device
, start_register
, data
, count
);
2460 wined3d_mutex_unlock();
2465 static HRESULT WINAPI
d3d8_device_GetVertexShaderDeclaration(IDirect3DDevice8
*iface
,
2466 DWORD shader
, void *data
, DWORD
*data_size
)
2468 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2469 struct d3d8_vertex_declaration
*declaration
;
2470 struct d3d8_vertex_shader
*shader_impl
;
2472 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2473 iface
, shader
, data
, data_size
);
2475 wined3d_mutex_lock();
2476 shader_impl
= d3d8_get_object(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
);
2477 wined3d_mutex_unlock();
2481 WARN("Invalid handle (%#x) passed.\n", shader
);
2482 return D3DERR_INVALIDCALL
;
2484 declaration
= shader_impl
->vertex_declaration
;
2488 *data_size
= declaration
->elements_size
;
2492 /* MSDN claims that if *data_size is smaller than the required size
2493 * we should write the required size and return D3DERR_MOREDATA.
2494 * That's not actually true. */
2495 if (*data_size
< declaration
->elements_size
)
2496 return D3DERR_INVALIDCALL
;
2498 memcpy(data
, declaration
->elements
, declaration
->elements_size
);
2503 static HRESULT WINAPI
d3d8_device_GetVertexShaderFunction(IDirect3DDevice8
*iface
,
2504 DWORD shader
, void *data
, DWORD
*data_size
)
2506 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2507 struct d3d8_vertex_shader
*shader_impl
= NULL
;
2510 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2511 iface
, shader
, data
, data_size
);
2513 wined3d_mutex_lock();
2514 if (!(shader_impl
= d3d8_get_object(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
)))
2516 WARN("Invalid handle (%#x) passed.\n", shader
);
2517 wined3d_mutex_unlock();
2519 return D3DERR_INVALIDCALL
;
2522 if (!shader_impl
->wined3d_shader
)
2524 wined3d_mutex_unlock();
2529 hr
= wined3d_shader_get_byte_code(shader_impl
->wined3d_shader
, data
, data_size
);
2530 wined3d_mutex_unlock();
2535 static HRESULT WINAPI
d3d8_device_SetIndices(IDirect3DDevice8
*iface
,
2536 IDirect3DIndexBuffer8
*buffer
, UINT base_vertex_idx
)
2538 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2539 struct d3d8_indexbuffer
*ib
= unsafe_impl_from_IDirect3DIndexBuffer8(buffer
);
2541 TRACE("iface %p, buffer %p, base_vertex_idx %u.\n", iface
, buffer
, base_vertex_idx
);
2543 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
2544 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
2545 * vertex buffers can't be created to address them with an index that requires the 32nd bit
2546 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
2549 wined3d_mutex_lock();
2550 wined3d_device_set_base_vertex_index(device
->wined3d_device
, base_vertex_idx
);
2551 wined3d_device_set_index_buffer(device
->wined3d_device
,
2552 ib
? ib
->wined3d_buffer
: NULL
,
2553 ib
? ib
->format
: WINED3DFMT_UNKNOWN
);
2554 wined3d_mutex_unlock();
2559 static HRESULT WINAPI
d3d8_device_GetIndices(IDirect3DDevice8
*iface
,
2560 IDirect3DIndexBuffer8
**buffer
, UINT
*base_vertex_index
)
2562 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2563 enum wined3d_format_id wined3d_format
;
2564 struct wined3d_buffer
*wined3d_buffer
;
2565 struct d3d8_indexbuffer
*buffer_impl
;
2567 TRACE("iface %p, buffer %p, base_vertex_index %p.\n", iface
, buffer
, base_vertex_index
);
2570 return D3DERR_INVALIDCALL
;
2572 /* The case from UINT to INT is safe because d3d8 will never set negative values */
2573 wined3d_mutex_lock();
2574 *base_vertex_index
= wined3d_device_get_base_vertex_index(device
->wined3d_device
);
2575 if ((wined3d_buffer
= wined3d_device_get_index_buffer(device
->wined3d_device
, &wined3d_format
)))
2577 buffer_impl
= wined3d_buffer_get_parent(wined3d_buffer
);
2578 *buffer
= &buffer_impl
->IDirect3DIndexBuffer8_iface
;
2579 IDirect3DIndexBuffer8_AddRef(*buffer
);
2585 wined3d_mutex_unlock();
2590 static HRESULT WINAPI
d3d8_device_CreatePixelShader(IDirect3DDevice8
*iface
,
2591 const DWORD
*byte_code
, DWORD
*shader
)
2593 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2594 struct d3d8_pixel_shader
*object
;
2595 DWORD shader_handle
;
2599 TRACE("iface %p, byte_code %p, shader %p.\n", iface
, byte_code
, shader
);
2602 return D3DERR_INVALIDCALL
;
2604 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2606 return E_OUTOFMEMORY
;
2608 wined3d_mutex_lock();
2609 handle
= d3d8_allocate_handle(&device
->handle_table
, object
, D3D8_HANDLE_PS
);
2610 wined3d_mutex_unlock();
2611 if (handle
== D3D8_INVALID_HANDLE
)
2613 ERR("Failed to allocate pixel shader handle.\n");
2614 HeapFree(GetProcessHeap(), 0, object
);
2615 return E_OUTOFMEMORY
;
2618 shader_handle
= handle
+ VS_HIGHESTFIXEDFXF
+ 1;
2620 hr
= d3d8_pixel_shader_init(object
, device
, byte_code
, shader_handle
);
2623 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
2624 wined3d_mutex_lock();
2625 d3d8_free_handle(&device
->handle_table
, handle
, D3D8_HANDLE_PS
);
2626 wined3d_mutex_unlock();
2627 HeapFree(GetProcessHeap(), 0, object
);
2632 TRACE("Created pixel shader %p (handle %#x).\n", object
, shader_handle
);
2633 *shader
= shader_handle
;
2638 static HRESULT WINAPI
d3d8_device_SetPixelShader(IDirect3DDevice8
*iface
, DWORD shader
)
2640 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2641 struct d3d8_pixel_shader
*shader_impl
;
2643 TRACE("iface %p, shader %#x.\n", iface
, shader
);
2645 wined3d_mutex_lock();
2649 wined3d_device_set_pixel_shader(device
->wined3d_device
, NULL
);
2650 wined3d_mutex_unlock();
2654 if (!(shader_impl
= d3d8_get_object(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
)))
2656 WARN("Invalid handle (%#x) passed.\n", shader
);
2657 wined3d_mutex_unlock();
2658 return D3DERR_INVALIDCALL
;
2661 TRACE("Setting shader %p.\n", shader_impl
);
2662 wined3d_device_set_pixel_shader(device
->wined3d_device
, shader_impl
->wined3d_shader
);
2663 wined3d_mutex_unlock();
2668 static HRESULT WINAPI
d3d8_device_GetPixelShader(IDirect3DDevice8
*iface
, DWORD
*shader
)
2670 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2671 struct wined3d_shader
*object
;
2673 TRACE("iface %p, shader %p.\n", iface
, shader
);
2676 return D3DERR_INVALIDCALL
;
2678 wined3d_mutex_lock();
2679 if ((object
= wined3d_device_get_pixel_shader(device
->wined3d_device
)))
2681 struct d3d8_pixel_shader
*d3d8_shader
;
2682 d3d8_shader
= wined3d_shader_get_parent(object
);
2683 *shader
= d3d8_shader
->handle
;
2689 wined3d_mutex_unlock();
2691 TRACE("Returning %#x.\n", *shader
);
2696 static HRESULT WINAPI
d3d8_device_DeletePixelShader(IDirect3DDevice8
*iface
, DWORD shader
)
2698 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2699 struct d3d8_pixel_shader
*shader_impl
;
2701 TRACE("iface %p, shader %#x.\n", iface
, shader
);
2703 wined3d_mutex_lock();
2705 if (!(shader_impl
= d3d8_free_handle(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
)))
2707 WARN("Invalid handle (%#x) passed.\n", shader
);
2708 wined3d_mutex_unlock();
2709 return D3DERR_INVALIDCALL
;
2712 if (wined3d_device_get_pixel_shader(device
->wined3d_device
) == shader_impl
->wined3d_shader
)
2713 IDirect3DDevice8_SetPixelShader(iface
, 0);
2715 wined3d_mutex_unlock();
2717 d3d8_pixel_shader_destroy(shader_impl
);
2722 static HRESULT WINAPI
d3d8_device_SetPixelShaderConstant(IDirect3DDevice8
*iface
,
2723 DWORD start_register
, const void *data
, DWORD count
)
2725 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2728 TRACE("iface %p, start_register %u, data %p, count %u.\n",
2729 iface
, start_register
, data
, count
);
2731 wined3d_mutex_lock();
2732 hr
= wined3d_device_set_ps_consts_f(device
->wined3d_device
, start_register
, data
, count
);
2733 wined3d_mutex_unlock();
2738 static HRESULT WINAPI
d3d8_device_GetPixelShaderConstant(IDirect3DDevice8
*iface
,
2739 DWORD start_register
, void *data
, DWORD count
)
2741 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2744 TRACE("iface %p, start_register %u, data %p, count %u.\n",
2745 iface
, start_register
, data
, count
);
2747 wined3d_mutex_lock();
2748 hr
= wined3d_device_get_ps_consts_f(device
->wined3d_device
, start_register
, data
, count
);
2749 wined3d_mutex_unlock();
2754 static HRESULT WINAPI
d3d8_device_GetPixelShaderFunction(IDirect3DDevice8
*iface
,
2755 DWORD shader
, void *data
, DWORD
*data_size
)
2757 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2758 struct d3d8_pixel_shader
*shader_impl
= NULL
;
2761 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2762 iface
, shader
, data
, data_size
);
2764 wined3d_mutex_lock();
2765 if (!(shader_impl
= d3d8_get_object(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
)))
2767 WARN("Invalid handle (%#x) passed.\n", shader
);
2768 wined3d_mutex_unlock();
2770 return D3DERR_INVALIDCALL
;
2773 hr
= wined3d_shader_get_byte_code(shader_impl
->wined3d_shader
, data
, data_size
);
2774 wined3d_mutex_unlock();
2779 static HRESULT WINAPI
d3d8_device_DrawRectPatch(IDirect3DDevice8
*iface
, UINT handle
,
2780 const float *segment_count
, const D3DRECTPATCH_INFO
*patch_info
)
2782 FIXME("iface %p, handle %#x, segment_count %p, patch_info %p unimplemented.\n",
2783 iface
, handle
, segment_count
, patch_info
);
2787 static HRESULT WINAPI
d3d8_device_DrawTriPatch(IDirect3DDevice8
*iface
, UINT handle
,
2788 const float *segment_count
, const D3DTRIPATCH_INFO
*patch_info
)
2790 FIXME("iface %p, handle %#x, segment_count %p, patch_info %p unimplemented.\n",
2791 iface
, handle
, segment_count
, patch_info
);
2795 static HRESULT WINAPI
d3d8_device_DeletePatch(IDirect3DDevice8
*iface
, UINT handle
)
2797 FIXME("iface %p, handle %#x unimplemented.\n", iface
, handle
);
2798 return D3DERR_INVALIDCALL
;
2801 static HRESULT WINAPI
d3d8_device_SetStreamSource(IDirect3DDevice8
*iface
,
2802 UINT stream_idx
, IDirect3DVertexBuffer8
*buffer
, UINT stride
)
2804 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2805 struct d3d8_vertexbuffer
*buffer_impl
= unsafe_impl_from_IDirect3DVertexBuffer8(buffer
);
2808 TRACE("iface %p, stream_idx %u, buffer %p, stride %u.\n",
2809 iface
, stream_idx
, buffer
, stride
);
2811 wined3d_mutex_lock();
2812 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, stream_idx
,
2813 buffer_impl
? buffer_impl
->wined3d_buffer
: NULL
, 0, stride
);
2814 wined3d_mutex_unlock();
2819 static HRESULT WINAPI
d3d8_device_GetStreamSource(IDirect3DDevice8
*iface
,
2820 UINT stream_idx
, IDirect3DVertexBuffer8
**buffer
, UINT
*stride
)
2822 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2823 struct d3d8_vertexbuffer
*buffer_impl
;
2824 struct wined3d_buffer
*wined3d_buffer
= NULL
;
2827 TRACE("iface %p, stream_idx %u, buffer %p, stride %p.\n",
2828 iface
, stream_idx
, buffer
, stride
);
2831 return D3DERR_INVALIDCALL
;
2833 wined3d_mutex_lock();
2834 hr
= wined3d_device_get_stream_source(device
->wined3d_device
, stream_idx
, &wined3d_buffer
, 0, stride
);
2835 if (SUCCEEDED(hr
) && wined3d_buffer
)
2837 buffer_impl
= wined3d_buffer_get_parent(wined3d_buffer
);
2838 *buffer
= &buffer_impl
->IDirect3DVertexBuffer8_iface
;
2839 IDirect3DVertexBuffer8_AddRef(*buffer
);
2844 ERR("Failed to get wined3d stream source, hr %#x.\n", hr
);
2847 wined3d_mutex_unlock();
2852 static const struct IDirect3DDevice8Vtbl d3d8_device_vtbl
=
2854 d3d8_device_QueryInterface
,
2856 d3d8_device_Release
,
2857 d3d8_device_TestCooperativeLevel
,
2858 d3d8_device_GetAvailableTextureMem
,
2859 d3d8_device_ResourceManagerDiscardBytes
,
2860 d3d8_device_GetDirect3D
,
2861 d3d8_device_GetDeviceCaps
,
2862 d3d8_device_GetDisplayMode
,
2863 d3d8_device_GetCreationParameters
,
2864 d3d8_device_SetCursorProperties
,
2865 d3d8_device_SetCursorPosition
,
2866 d3d8_device_ShowCursor
,
2867 d3d8_device_CreateAdditionalSwapChain
,
2869 d3d8_device_Present
,
2870 d3d8_device_GetBackBuffer
,
2871 d3d8_device_GetRasterStatus
,
2872 d3d8_device_SetGammaRamp
,
2873 d3d8_device_GetGammaRamp
,
2874 d3d8_device_CreateTexture
,
2875 d3d8_device_CreateVolumeTexture
,
2876 d3d8_device_CreateCubeTexture
,
2877 d3d8_device_CreateVertexBuffer
,
2878 d3d8_device_CreateIndexBuffer
,
2879 d3d8_device_CreateRenderTarget
,
2880 d3d8_device_CreateDepthStencilSurface
,
2881 d3d8_device_CreateImageSurface
,
2882 d3d8_device_CopyRects
,
2883 d3d8_device_UpdateTexture
,
2884 d3d8_device_GetFrontBuffer
,
2885 d3d8_device_SetRenderTarget
,
2886 d3d8_device_GetRenderTarget
,
2887 d3d8_device_GetDepthStencilSurface
,
2888 d3d8_device_BeginScene
,
2889 d3d8_device_EndScene
,
2891 d3d8_device_SetTransform
,
2892 d3d8_device_GetTransform
,
2893 d3d8_device_MultiplyTransform
,
2894 d3d8_device_SetViewport
,
2895 d3d8_device_GetViewport
,
2896 d3d8_device_SetMaterial
,
2897 d3d8_device_GetMaterial
,
2898 d3d8_device_SetLight
,
2899 d3d8_device_GetLight
,
2900 d3d8_device_LightEnable
,
2901 d3d8_device_GetLightEnable
,
2902 d3d8_device_SetClipPlane
,
2903 d3d8_device_GetClipPlane
,
2904 d3d8_device_SetRenderState
,
2905 d3d8_device_GetRenderState
,
2906 d3d8_device_BeginStateBlock
,
2907 d3d8_device_EndStateBlock
,
2908 d3d8_device_ApplyStateBlock
,
2909 d3d8_device_CaptureStateBlock
,
2910 d3d8_device_DeleteStateBlock
,
2911 d3d8_device_CreateStateBlock
,
2912 d3d8_device_SetClipStatus
,
2913 d3d8_device_GetClipStatus
,
2914 d3d8_device_GetTexture
,
2915 d3d8_device_SetTexture
,
2916 d3d8_device_GetTextureStageState
,
2917 d3d8_device_SetTextureStageState
,
2918 d3d8_device_ValidateDevice
,
2919 d3d8_device_GetInfo
,
2920 d3d8_device_SetPaletteEntries
,
2921 d3d8_device_GetPaletteEntries
,
2922 d3d8_device_SetCurrentTexturePalette
,
2923 d3d8_device_GetCurrentTexturePalette
,
2924 d3d8_device_DrawPrimitive
,
2925 d3d8_device_DrawIndexedPrimitive
,
2926 d3d8_device_DrawPrimitiveUP
,
2927 d3d8_device_DrawIndexedPrimitiveUP
,
2928 d3d8_device_ProcessVertices
,
2929 d3d8_device_CreateVertexShader
,
2930 d3d8_device_SetVertexShader
,
2931 d3d8_device_GetVertexShader
,
2932 d3d8_device_DeleteVertexShader
,
2933 d3d8_device_SetVertexShaderConstant
,
2934 d3d8_device_GetVertexShaderConstant
,
2935 d3d8_device_GetVertexShaderDeclaration
,
2936 d3d8_device_GetVertexShaderFunction
,
2937 d3d8_device_SetStreamSource
,
2938 d3d8_device_GetStreamSource
,
2939 d3d8_device_SetIndices
,
2940 d3d8_device_GetIndices
,
2941 d3d8_device_CreatePixelShader
,
2942 d3d8_device_SetPixelShader
,
2943 d3d8_device_GetPixelShader
,
2944 d3d8_device_DeletePixelShader
,
2945 d3d8_device_SetPixelShaderConstant
,
2946 d3d8_device_GetPixelShaderConstant
,
2947 d3d8_device_GetPixelShaderFunction
,
2948 d3d8_device_DrawRectPatch
,
2949 d3d8_device_DrawTriPatch
,
2950 d3d8_device_DeletePatch
,
2953 static inline struct d3d8_device
*device_from_device_parent(struct wined3d_device_parent
*device_parent
)
2955 return CONTAINING_RECORD(device_parent
, struct d3d8_device
, device_parent
);
2958 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
2959 struct wined3d_device
*device
)
2961 TRACE("device_parent %p, device %p\n", device_parent
, device
);
2964 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
2966 TRACE("device_parent %p.\n", device_parent
);
2969 static void CDECL
device_parent_activate(struct wined3d_device_parent
*device_parent
, BOOL activate
)
2971 struct d3d8_device
*device
= device_from_device_parent(device_parent
);
2973 TRACE("device_parent %p, activate %#x.\n", device_parent
, activate
);
2976 InterlockedCompareExchange(&device
->device_state
, D3D8_DEVICE_STATE_LOST
, D3D8_DEVICE_STATE_OK
);
2978 InterlockedCompareExchange(&device
->device_state
, D3D8_DEVICE_STATE_NOT_RESET
, D3D8_DEVICE_STATE_LOST
);
2981 static HRESULT CDECL
device_parent_surface_created(struct wined3d_device_parent
*device_parent
,
2982 struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
, struct wined3d_surface
*surface
, void **parent
,
2983 const struct wined3d_parent_ops
**parent_ops
)
2985 struct d3d8_surface
*d3d_surface
;
2987 TRACE("device_parent %p, wined3d_texture %p, sub_resource_idx %u, surface %p, parent %p, parent_ops %p.\n",
2988 device_parent
, wined3d_texture
, sub_resource_idx
, surface
, parent
, parent_ops
);
2990 if (!(d3d_surface
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*d3d_surface
))))
2991 return E_OUTOFMEMORY
;
2993 surface_init(d3d_surface
, wined3d_texture
, sub_resource_idx
, parent_ops
);
2994 *parent
= d3d_surface
;
2995 TRACE("Created surface %p.\n", d3d_surface
);
3000 static HRESULT CDECL
device_parent_volume_created(struct wined3d_device_parent
*device_parent
,
3001 struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
,
3002 void **parent
, const struct wined3d_parent_ops
**parent_ops
)
3004 struct d3d8_volume
*d3d_volume
;
3006 TRACE("device_parent %p, texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
3007 device_parent
, wined3d_texture
, sub_resource_idx
, parent
, parent_ops
);
3009 if (!(d3d_volume
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*d3d_volume
))))
3010 return E_OUTOFMEMORY
;
3012 volume_init(d3d_volume
, wined3d_texture
, sub_resource_idx
, parent_ops
);
3013 *parent
= d3d_volume
;
3014 TRACE("Created volume %p.\n", d3d_volume
);
3019 static HRESULT CDECL
device_parent_create_swapchain_texture(struct wined3d_device_parent
*device_parent
,
3020 void *container_parent
, const struct wined3d_resource_desc
*desc
, struct wined3d_texture
**texture
)
3022 struct d3d8_device
*device
= device_from_device_parent(device_parent
);
3023 struct d3d8_surface
*d3d_surface
;
3026 TRACE("device_parent %p, container_parent %p, desc %p, texture %p.\n",
3027 device_parent
, container_parent
, desc
, texture
);
3029 if (FAILED(hr
= wined3d_texture_create(device
->wined3d_device
, desc
, 1,
3030 WINED3D_SURFACE_MAPPABLE
, NULL
, &device
->IDirect3DDevice8_iface
, &d3d8_null_wined3d_parent_ops
, texture
)))
3032 WARN("Failed to create texture, hr %#x.\n", hr
);
3036 d3d_surface
= wined3d_resource_get_parent(wined3d_texture_get_sub_resource(*texture
, 0));
3037 d3d_surface
->parent_device
= &device
->IDirect3DDevice8_iface
;
3042 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
3043 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain
**swapchain
)
3045 struct d3d8_device
*device
= device_from_device_parent(device_parent
);
3046 struct d3d8_swapchain
*d3d_swapchain
;
3049 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent
, desc
, swapchain
);
3051 if (FAILED(hr
= d3d8_swapchain_create(device
, desc
, &d3d_swapchain
)))
3053 WARN("Failed to create swapchain, hr %#x.\n", hr
);
3058 *swapchain
= d3d_swapchain
->wined3d_swapchain
;
3059 wined3d_swapchain_incref(*swapchain
);
3060 IDirect3DSwapChain8_Release(&d3d_swapchain
->IDirect3DSwapChain8_iface
);
3065 static const struct wined3d_device_parent_ops d3d8_wined3d_device_parent_ops
=
3067 device_parent_wined3d_device_created
,
3068 device_parent_mode_changed
,
3069 device_parent_activate
,
3070 device_parent_surface_created
,
3071 device_parent_volume_created
,
3072 device_parent_create_swapchain_texture
,
3073 device_parent_create_swapchain
,
3076 static void setup_fpu(void)
3078 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3080 __asm__
volatile ("fnstcw %0" : "=m" (cw
));
3081 cw
= (cw
& ~0xf3f) | 0x3f;
3082 __asm__
volatile ("fldcw %0" : : "m" (cw
));
3083 #elif defined(__i386__) && defined(_MSC_VER)
3086 cw
= (cw
& ~0xf3f) | 0x3f;
3089 FIXME("FPU setup not implemented for this platform.\n");
3093 HRESULT
device_init(struct d3d8_device
*device
, struct d3d8
*parent
, struct wined3d
*wined3d
, UINT adapter
,
3094 D3DDEVTYPE device_type
, HWND focus_window
, DWORD flags
, D3DPRESENT_PARAMETERS
*parameters
)
3096 struct wined3d_swapchain_desc swapchain_desc
;
3097 struct wined3d_swapchain
*wined3d_swapchain
;
3100 device
->IDirect3DDevice8_iface
.lpVtbl
= &d3d8_device_vtbl
;
3101 device
->device_parent
.ops
= &d3d8_wined3d_device_parent_ops
;
3103 device
->handle_table
.entries
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
3104 D3D8_INITIAL_HANDLE_TABLE_SIZE
* sizeof(*device
->handle_table
.entries
));
3105 if (!device
->handle_table
.entries
)
3107 ERR("Failed to allocate handle table memory.\n");
3108 return E_OUTOFMEMORY
;
3110 device
->handle_table
.table_size
= D3D8_INITIAL_HANDLE_TABLE_SIZE
;
3112 if (!(flags
& D3DCREATE_FPU_PRESERVE
)) setup_fpu();
3114 wined3d_mutex_lock();
3115 hr
= wined3d_device_create(wined3d
, adapter
, device_type
, focus_window
, flags
, 4,
3116 &device
->device_parent
, &device
->wined3d_device
);
3119 WARN("Failed to create wined3d device, hr %#x.\n", hr
);
3120 wined3d_mutex_unlock();
3121 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
3125 if (!parameters
->Windowed
)
3127 HWND device_window
= parameters
->hDeviceWindow
;
3130 focus_window
= device_window
;
3131 if (FAILED(hr
= wined3d_device_acquire_focus_window(device
->wined3d_device
, focus_window
)))
3133 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
3134 wined3d_device_decref(device
->wined3d_device
);
3135 wined3d_mutex_unlock();
3136 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
3141 device_window
= focus_window
;
3142 wined3d_device_setup_fullscreen_window(device
->wined3d_device
, device_window
,
3143 parameters
->BackBufferWidth
,
3144 parameters
->BackBufferHeight
);
3147 if (flags
& D3DCREATE_MULTITHREADED
)
3148 wined3d_device_set_multithreaded(device
->wined3d_device
);
3150 if (!wined3d_swapchain_desc_from_present_parameters(&swapchain_desc
, parameters
))
3152 wined3d_device_release_focus_window(device
->wined3d_device
);
3153 wined3d_device_decref(device
->wined3d_device
);
3154 wined3d_mutex_unlock();
3155 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
3156 return D3DERR_INVALIDCALL
;
3159 hr
= wined3d_device_init_3d(device
->wined3d_device
, &swapchain_desc
);
3162 WARN("Failed to initialize 3D, hr %#x.\n", hr
);
3163 wined3d_device_release_focus_window(device
->wined3d_device
);
3164 wined3d_device_decref(device
->wined3d_device
);
3165 wined3d_mutex_unlock();
3166 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
3170 wined3d_device_set_render_state(device
->wined3d_device
, WINED3D_RS_POINTSIZE_MIN
, 0);
3171 wined3d_mutex_unlock();
3173 present_parameters_from_wined3d_swapchain_desc(parameters
, &swapchain_desc
);
3175 device
->declArraySize
= 16;
3176 device
->decls
= HeapAlloc(GetProcessHeap(), 0, device
->declArraySize
* sizeof(*device
->decls
));
3179 ERR("Failed to allocate FVF vertex declaration map memory.\n");
3184 wined3d_swapchain
= wined3d_device_get_swapchain(device
->wined3d_device
, 0);
3185 device
->implicit_swapchain
= wined3d_swapchain_get_parent(wined3d_swapchain
);
3187 device
->d3d_parent
= &parent
->IDirect3D8_iface
;
3188 IDirect3D8_AddRef(device
->d3d_parent
);
3193 wined3d_mutex_lock();
3194 wined3d_device_uninit_3d(device
->wined3d_device
);
3195 wined3d_device_release_focus_window(device
->wined3d_device
);
3196 wined3d_device_decref(device
->wined3d_device
);
3197 wined3d_mutex_unlock();
3198 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);