2 * IDirect3DDevice8 implementation
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2004 Christian Costa
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
30 //#include "winbase.h"
31 //#include "winuser.h"
33 //#include "wine/debug.h"
35 #include "d3d8_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(d3d8
);
39 D3DFORMAT
d3dformat_from_wined3dformat(enum wined3d_format_id format
)
41 BYTE
*c
= (BYTE
*)&format
;
43 /* Don't translate FOURCC formats */
44 if (isprint(c
[0]) && isprint(c
[1]) && isprint(c
[2]) && isprint(c
[3])) return format
;
48 case WINED3DFMT_UNKNOWN
: return D3DFMT_UNKNOWN
;
49 case WINED3DFMT_B8G8R8_UNORM
: return D3DFMT_R8G8B8
;
50 case WINED3DFMT_B8G8R8A8_UNORM
: return D3DFMT_A8R8G8B8
;
51 case WINED3DFMT_B8G8R8X8_UNORM
: return D3DFMT_X8R8G8B8
;
52 case WINED3DFMT_B5G6R5_UNORM
: return D3DFMT_R5G6B5
;
53 case WINED3DFMT_B5G5R5X1_UNORM
: return D3DFMT_X1R5G5B5
;
54 case WINED3DFMT_B5G5R5A1_UNORM
: return D3DFMT_A1R5G5B5
;
55 case WINED3DFMT_B4G4R4A4_UNORM
: return D3DFMT_A4R4G4B4
;
56 case WINED3DFMT_B2G3R3_UNORM
: return D3DFMT_R3G3B2
;
57 case WINED3DFMT_A8_UNORM
: return D3DFMT_A8
;
58 case WINED3DFMT_B2G3R3A8_UNORM
: return D3DFMT_A8R3G3B2
;
59 case WINED3DFMT_B4G4R4X4_UNORM
: return D3DFMT_X4R4G4B4
;
60 case WINED3DFMT_R10G10B10A2_UNORM
: return D3DFMT_A2B10G10R10
;
61 case WINED3DFMT_R16G16_UNORM
: return D3DFMT_G16R16
;
62 case WINED3DFMT_P8_UINT_A8_UNORM
: return D3DFMT_A8P8
;
63 case WINED3DFMT_P8_UINT
: return D3DFMT_P8
;
64 case WINED3DFMT_L8_UNORM
: return D3DFMT_L8
;
65 case WINED3DFMT_L8A8_UNORM
: return D3DFMT_A8L8
;
66 case WINED3DFMT_L4A4_UNORM
: return D3DFMT_A4L4
;
67 case WINED3DFMT_R8G8_SNORM
: return D3DFMT_V8U8
;
68 case WINED3DFMT_R5G5_SNORM_L6_UNORM
: return D3DFMT_L6V5U5
;
69 case WINED3DFMT_R8G8_SNORM_L8X8_UNORM
: return D3DFMT_X8L8V8U8
;
70 case WINED3DFMT_R8G8B8A8_SNORM
: return D3DFMT_Q8W8V8U8
;
71 case WINED3DFMT_R16G16_SNORM
: return D3DFMT_V16U16
;
72 case WINED3DFMT_R10G11B11_SNORM
: return D3DFMT_W11V11U10
;
73 case WINED3DFMT_R10G10B10_SNORM_A2_UNORM
: return D3DFMT_A2W10V10U10
;
74 case WINED3DFMT_D16_LOCKABLE
: return D3DFMT_D16_LOCKABLE
;
75 case WINED3DFMT_D32_UNORM
: return D3DFMT_D32
;
76 case WINED3DFMT_S1_UINT_D15_UNORM
: return D3DFMT_D15S1
;
77 case WINED3DFMT_D24_UNORM_S8_UINT
: return D3DFMT_D24S8
;
78 case WINED3DFMT_X8D24_UNORM
: return D3DFMT_D24X8
;
79 case WINED3DFMT_S4X4_UINT_D24_UNORM
: return D3DFMT_D24X4S4
;
80 case WINED3DFMT_D16_UNORM
: return D3DFMT_D16
;
81 case WINED3DFMT_VERTEXDATA
: return D3DFMT_VERTEXDATA
;
82 case WINED3DFMT_R16_UINT
: return D3DFMT_INDEX16
;
83 case WINED3DFMT_R32_UINT
: return D3DFMT_INDEX32
;
85 FIXME("Unhandled wined3d format %#x.\n", format
);
86 return D3DFMT_UNKNOWN
;
90 enum wined3d_format_id
wined3dformat_from_d3dformat(D3DFORMAT format
)
92 BYTE
*c
= (BYTE
*)&format
;
94 /* Don't translate FOURCC formats */
95 if (isprint(c
[0]) && isprint(c
[1]) && isprint(c
[2]) && isprint(c
[3])) return format
;
99 case D3DFMT_UNKNOWN
: return WINED3DFMT_UNKNOWN
;
100 case D3DFMT_R8G8B8
: return WINED3DFMT_B8G8R8_UNORM
;
101 case D3DFMT_A8R8G8B8
: return WINED3DFMT_B8G8R8A8_UNORM
;
102 case D3DFMT_X8R8G8B8
: return WINED3DFMT_B8G8R8X8_UNORM
;
103 case D3DFMT_R5G6B5
: return WINED3DFMT_B5G6R5_UNORM
;
104 case D3DFMT_X1R5G5B5
: return WINED3DFMT_B5G5R5X1_UNORM
;
105 case D3DFMT_A1R5G5B5
: return WINED3DFMT_B5G5R5A1_UNORM
;
106 case D3DFMT_A4R4G4B4
: return WINED3DFMT_B4G4R4A4_UNORM
;
107 case D3DFMT_R3G3B2
: return WINED3DFMT_B2G3R3_UNORM
;
108 case D3DFMT_A8
: return WINED3DFMT_A8_UNORM
;
109 case D3DFMT_A8R3G3B2
: return WINED3DFMT_B2G3R3A8_UNORM
;
110 case D3DFMT_X4R4G4B4
: return WINED3DFMT_B4G4R4X4_UNORM
;
111 case D3DFMT_A2B10G10R10
: return WINED3DFMT_R10G10B10A2_UNORM
;
112 case D3DFMT_G16R16
: return WINED3DFMT_R16G16_UNORM
;
113 case D3DFMT_A8P8
: return WINED3DFMT_P8_UINT_A8_UNORM
;
114 case D3DFMT_P8
: return WINED3DFMT_P8_UINT
;
115 case D3DFMT_L8
: return WINED3DFMT_L8_UNORM
;
116 case D3DFMT_A8L8
: return WINED3DFMT_L8A8_UNORM
;
117 case D3DFMT_A4L4
: return WINED3DFMT_L4A4_UNORM
;
118 case D3DFMT_V8U8
: return WINED3DFMT_R8G8_SNORM
;
119 case D3DFMT_L6V5U5
: return WINED3DFMT_R5G5_SNORM_L6_UNORM
;
120 case D3DFMT_X8L8V8U8
: return WINED3DFMT_R8G8_SNORM_L8X8_UNORM
;
121 case D3DFMT_Q8W8V8U8
: return WINED3DFMT_R8G8B8A8_SNORM
;
122 case D3DFMT_V16U16
: return WINED3DFMT_R16G16_SNORM
;
123 case D3DFMT_W11V11U10
: return WINED3DFMT_R10G11B11_SNORM
;
124 case D3DFMT_A2W10V10U10
: return WINED3DFMT_R10G10B10_SNORM_A2_UNORM
;
125 case D3DFMT_D16_LOCKABLE
: return WINED3DFMT_D16_LOCKABLE
;
126 case D3DFMT_D32
: return WINED3DFMT_D32_UNORM
;
127 case D3DFMT_D15S1
: return WINED3DFMT_S1_UINT_D15_UNORM
;
128 case D3DFMT_D24S8
: return WINED3DFMT_D24_UNORM_S8_UINT
;
129 case D3DFMT_D24X8
: return WINED3DFMT_X8D24_UNORM
;
130 case D3DFMT_D24X4S4
: return WINED3DFMT_S4X4_UINT_D24_UNORM
;
131 case D3DFMT_D16
: return WINED3DFMT_D16_UNORM
;
132 case D3DFMT_VERTEXDATA
: return WINED3DFMT_VERTEXDATA
;
133 case D3DFMT_INDEX16
: return WINED3DFMT_R16_UINT
;
134 case D3DFMT_INDEX32
: return WINED3DFMT_R32_UINT
;
136 FIXME("Unhandled D3DFORMAT %#x\n", format
);
137 return WINED3DFMT_UNKNOWN
;
141 static UINT
vertex_count_from_primitive_count(D3DPRIMITIVETYPE primitive_type
, UINT primitive_count
)
143 switch(primitive_type
)
145 case D3DPT_POINTLIST
:
146 return primitive_count
;
149 return primitive_count
* 2;
151 case D3DPT_LINESTRIP
:
152 return primitive_count
+ 1;
154 case D3DPT_TRIANGLELIST
:
155 return primitive_count
* 3;
157 case D3DPT_TRIANGLESTRIP
:
158 case D3DPT_TRIANGLEFAN
:
159 return primitive_count
+ 2;
162 FIXME("Unhandled primitive type %#x\n", primitive_type
);
167 static void present_parameters_from_wined3d_swapchain_desc(D3DPRESENT_PARAMETERS
*present_parameters
,
168 const struct wined3d_swapchain_desc
*swapchain_desc
)
170 present_parameters
->BackBufferWidth
= swapchain_desc
->backbuffer_width
;
171 present_parameters
->BackBufferHeight
= swapchain_desc
->backbuffer_height
;
172 present_parameters
->BackBufferFormat
= d3dformat_from_wined3dformat(swapchain_desc
->backbuffer_format
);
173 present_parameters
->BackBufferCount
= swapchain_desc
->backbuffer_count
;
174 present_parameters
->MultiSampleType
= swapchain_desc
->multisample_type
;
175 present_parameters
->SwapEffect
= swapchain_desc
->swap_effect
;
176 present_parameters
->hDeviceWindow
= swapchain_desc
->device_window
;
177 present_parameters
->Windowed
= swapchain_desc
->windowed
;
178 present_parameters
->EnableAutoDepthStencil
= swapchain_desc
->enable_auto_depth_stencil
;
179 present_parameters
->AutoDepthStencilFormat
180 = d3dformat_from_wined3dformat(swapchain_desc
->auto_depth_stencil_format
);
181 present_parameters
->Flags
= swapchain_desc
->flags
;
182 present_parameters
->FullScreen_RefreshRateInHz
= swapchain_desc
->refresh_rate
;
183 present_parameters
->FullScreen_PresentationInterval
= swapchain_desc
->swap_interval
;
186 static void wined3d_swapchain_desc_from_present_parameters(struct wined3d_swapchain_desc
*swapchain_desc
,
187 const D3DPRESENT_PARAMETERS
*present_parameters
)
189 swapchain_desc
->backbuffer_width
= present_parameters
->BackBufferWidth
;
190 swapchain_desc
->backbuffer_height
= present_parameters
->BackBufferHeight
;
191 swapchain_desc
->backbuffer_format
= wined3dformat_from_d3dformat(present_parameters
->BackBufferFormat
);
192 swapchain_desc
->backbuffer_count
= max(1, present_parameters
->BackBufferCount
);
193 swapchain_desc
->multisample_type
= present_parameters
->MultiSampleType
;
194 swapchain_desc
->multisample_quality
= 0; /* d3d9 only */
195 swapchain_desc
->swap_effect
= present_parameters
->SwapEffect
;
196 swapchain_desc
->device_window
= present_parameters
->hDeviceWindow
;
197 swapchain_desc
->windowed
= present_parameters
->Windowed
;
198 swapchain_desc
->enable_auto_depth_stencil
= present_parameters
->EnableAutoDepthStencil
;
199 swapchain_desc
->auto_depth_stencil_format
200 = wined3dformat_from_d3dformat(present_parameters
->AutoDepthStencilFormat
);
201 swapchain_desc
->flags
= present_parameters
->Flags
;
202 swapchain_desc
->refresh_rate
= present_parameters
->FullScreen_RefreshRateInHz
;
203 swapchain_desc
->swap_interval
= present_parameters
->FullScreen_PresentationInterval
;
204 swapchain_desc
->auto_restore_display_mode
= TRUE
;
207 /* Handle table functions */
208 static DWORD
d3d8_allocate_handle(struct d3d8_handle_table
*t
, void *object
, enum d3d8_handle_type type
)
210 struct d3d8_handle_entry
*entry
;
214 DWORD index
= t
->free_entries
- t
->entries
;
215 /* Use a free handle */
216 entry
= t
->free_entries
;
217 if (entry
->type
!= D3D8_HANDLE_FREE
)
219 ERR("Handle %u(%p) is in the free list, but has type %#x.\n", index
, entry
, entry
->type
);
220 return D3D8_INVALID_HANDLE
;
222 t
->free_entries
= entry
->object
;
223 entry
->object
= object
;
229 if (!(t
->entry_count
< t
->table_size
))
232 UINT new_size
= t
->table_size
+ (t
->table_size
>> 1);
233 struct d3d8_handle_entry
*new_entries
= HeapReAlloc(GetProcessHeap(),
234 0, t
->entries
, new_size
* sizeof(*t
->entries
));
237 ERR("Failed to grow the handle table.\n");
238 return D3D8_INVALID_HANDLE
;
240 t
->entries
= new_entries
;
241 t
->table_size
= new_size
;
244 entry
= &t
->entries
[t
->entry_count
];
245 entry
->object
= object
;
248 return t
->entry_count
++;
251 static void *d3d8_free_handle(struct d3d8_handle_table
*t
, DWORD handle
, enum d3d8_handle_type type
)
253 struct d3d8_handle_entry
*entry
;
256 if (handle
== D3D8_INVALID_HANDLE
|| handle
>= t
->entry_count
)
258 WARN("Invalid handle %u passed.\n", handle
);
262 entry
= &t
->entries
[handle
];
263 if (entry
->type
!= type
)
265 WARN("Handle %u(%p) is not of type %#x.\n", handle
, entry
, type
);
269 object
= entry
->object
;
270 entry
->object
= t
->free_entries
;
271 entry
->type
= D3D8_HANDLE_FREE
;
272 t
->free_entries
= entry
;
277 static void *d3d8_get_object(struct d3d8_handle_table
*t
, DWORD handle
, enum d3d8_handle_type type
)
279 struct d3d8_handle_entry
*entry
;
281 if (handle
== D3D8_INVALID_HANDLE
|| handle
>= t
->entry_count
)
283 WARN("Invalid handle %u passed.\n", handle
);
287 entry
= &t
->entries
[handle
];
288 if (entry
->type
!= type
)
290 WARN("Handle %u(%p) is not of type %#x.\n", handle
, entry
, type
);
294 return entry
->object
;
297 static inline struct d3d8_device
*impl_from_IDirect3DDevice8(IDirect3DDevice8
*iface
)
299 return CONTAINING_RECORD(iface
, struct d3d8_device
, IDirect3DDevice8_iface
);
302 static HRESULT WINAPI
d3d8_device_QueryInterface(IDirect3DDevice8
*iface
, REFIID riid
, void **out
)
304 TRACE("iface %p, riid %s, out %p.\n",
305 iface
, debugstr_guid(riid
), out
);
307 if (IsEqualGUID(riid
, &IID_IDirect3DDevice8
)
308 || IsEqualGUID(riid
, &IID_IUnknown
))
310 IDirect3DDevice8_AddRef(iface
);
315 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
318 return E_NOINTERFACE
;
321 static ULONG WINAPI
d3d8_device_AddRef(IDirect3DDevice8
*iface
)
323 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
324 ULONG ref
= InterlockedIncrement(&device
->ref
);
326 TRACE("%p increasing refcount to %u.\n", iface
, ref
);
331 static ULONG WINAPI
d3d8_device_Release(IDirect3DDevice8
*iface
)
333 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
336 if (device
->inDestruction
)
339 ref
= InterlockedDecrement(&device
->ref
);
341 TRACE("%p decreasing refcount to %u.\n", iface
, ref
);
345 IDirect3D8
*parent
= device
->d3d_parent
;
348 TRACE("Releasing wined3d device %p.\n", device
->wined3d_device
);
350 wined3d_mutex_lock();
352 device
->inDestruction
= TRUE
;
354 for (i
= 0; i
< device
->numConvertedDecls
; ++i
)
356 d3d8_vertex_declaration_destroy(device
->decls
[i
].declaration
);
358 HeapFree(GetProcessHeap(), 0, device
->decls
);
360 if (device
->vertex_buffer
)
361 wined3d_buffer_decref(device
->vertex_buffer
);
362 if (device
->index_buffer
)
363 wined3d_buffer_decref(device
->index_buffer
);
365 wined3d_device_uninit_3d(device
->wined3d_device
);
366 wined3d_device_release_focus_window(device
->wined3d_device
);
367 wined3d_device_decref(device
->wined3d_device
);
368 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
369 HeapFree(GetProcessHeap(), 0, device
);
371 wined3d_mutex_unlock();
373 IDirect3D8_Release(parent
);
378 static HRESULT WINAPI
d3d8_device_TestCooperativeLevel(IDirect3DDevice8
*iface
)
380 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
382 TRACE("iface %p.\n", iface
);
386 TRACE("Device is lost.\n");
387 return D3DERR_DEVICENOTRESET
;
393 static UINT WINAPI
d3d8_device_GetAvailableTextureMem(IDirect3DDevice8
*iface
)
395 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
398 TRACE("iface %p.\n", iface
);
400 wined3d_mutex_lock();
401 hr
= wined3d_device_get_available_texture_mem(device
->wined3d_device
);
402 wined3d_mutex_unlock();
407 static HRESULT WINAPI
d3d8_device_ResourceManagerDiscardBytes(IDirect3DDevice8
*iface
, DWORD byte_count
)
409 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
411 TRACE("iface %p, byte_count %u.\n", iface
, byte_count
);
414 FIXME("Byte count ignored.\n");
416 wined3d_mutex_lock();
417 wined3d_device_evict_managed_resources(device
->wined3d_device
);
418 wined3d_mutex_unlock();
423 static HRESULT WINAPI
d3d8_device_GetDirect3D(IDirect3DDevice8
*iface
, IDirect3D8
**d3d8
)
425 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
427 TRACE("iface %p, d3d8 %p.\n", iface
, d3d8
);
430 return D3DERR_INVALIDCALL
;
432 return IDirect3D8_QueryInterface(device
->d3d_parent
, &IID_IDirect3D8
, (void **)d3d8
);
435 static HRESULT WINAPI
d3d8_device_GetDeviceCaps(IDirect3DDevice8
*iface
, D3DCAPS8
*caps
)
437 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
438 WINED3DCAPS
*wined3d_caps
;
441 TRACE("iface %p, caps %p.\n", iface
, caps
);
444 return D3DERR_INVALIDCALL
;
446 if (!(wined3d_caps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*wined3d_caps
))))
447 return D3DERR_INVALIDCALL
; /* well this is what MSDN says to return */
449 wined3d_mutex_lock();
450 hr
= wined3d_device_get_device_caps(device
->wined3d_device
, wined3d_caps
);
451 wined3d_mutex_unlock();
453 fixup_caps(wined3d_caps
);
454 WINECAPSTOD3D8CAPS(caps
, wined3d_caps
)
455 HeapFree(GetProcessHeap(), 0, wined3d_caps
);
460 static HRESULT WINAPI
d3d8_device_GetDisplayMode(IDirect3DDevice8
*iface
, D3DDISPLAYMODE
*mode
)
462 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
463 struct wined3d_display_mode wined3d_mode
;
466 TRACE("iface %p, mode %p.\n", iface
, mode
);
468 wined3d_mutex_lock();
469 hr
= wined3d_device_get_display_mode(device
->wined3d_device
, 0, &wined3d_mode
, NULL
);
470 wined3d_mutex_unlock();
474 mode
->Width
= wined3d_mode
.width
;
475 mode
->Height
= wined3d_mode
.height
;
476 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
477 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
483 static HRESULT WINAPI
d3d8_device_GetCreationParameters(IDirect3DDevice8
*iface
,
484 D3DDEVICE_CREATION_PARAMETERS
*parameters
)
486 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
488 TRACE("iface %p, parameters %p.\n", iface
, parameters
);
490 wined3d_mutex_lock();
491 wined3d_device_get_creation_parameters(device
->wined3d_device
,
492 (struct wined3d_device_creation_parameters
*)parameters
);
493 wined3d_mutex_unlock();
498 static HRESULT WINAPI
d3d8_device_SetCursorProperties(IDirect3DDevice8
*iface
,
499 UINT hotspot_x
, UINT hotspot_y
, IDirect3DSurface8
*bitmap
)
501 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
502 struct d3d8_surface
*bitmap_impl
= unsafe_impl_from_IDirect3DSurface8(bitmap
);
505 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
506 iface
, hotspot_x
, hotspot_y
, bitmap
);
510 WARN("No cursor bitmap, returning D3DERR_INVALIDCALL.\n");
511 return D3DERR_INVALIDCALL
;
514 wined3d_mutex_lock();
515 hr
= wined3d_device_set_cursor_properties(device
->wined3d_device
,
516 hotspot_x
, hotspot_y
, bitmap_impl
->wined3d_surface
);
517 wined3d_mutex_unlock();
522 static void WINAPI
d3d8_device_SetCursorPosition(IDirect3DDevice8
*iface
, UINT x
, UINT y
, DWORD flags
)
524 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
526 TRACE("iface %p, x %u, y %u, flags %#x.\n", iface
, x
, y
, flags
);
528 wined3d_mutex_lock();
529 wined3d_device_set_cursor_position(device
->wined3d_device
, x
, y
, flags
);
530 wined3d_mutex_unlock();
533 static BOOL WINAPI
d3d8_device_ShowCursor(IDirect3DDevice8
*iface
, BOOL show
)
535 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
538 TRACE("iface %p, show %#x.\n", iface
, show
);
540 wined3d_mutex_lock();
541 ret
= wined3d_device_show_cursor(device
->wined3d_device
, show
);
542 wined3d_mutex_unlock();
547 static HRESULT WINAPI
d3d8_device_CreateAdditionalSwapChain(IDirect3DDevice8
*iface
,
548 D3DPRESENT_PARAMETERS
*present_parameters
, IDirect3DSwapChain8
**swapchain
)
550 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
551 struct wined3d_swapchain_desc desc
;
552 struct d3d8_swapchain
*object
;
554 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
555 iface
, present_parameters
, swapchain
);
557 wined3d_swapchain_desc_from_present_parameters(&desc
, present_parameters
);
558 if (SUCCEEDED(d3d8_swapchain_create(device
, &desc
, &object
)))
559 *swapchain
= &object
->IDirect3DSwapChain8_iface
;
560 present_parameters_from_wined3d_swapchain_desc(present_parameters
, &desc
);
565 static HRESULT CDECL
reset_enum_callback(struct wined3d_resource
*resource
)
567 struct wined3d_resource_desc desc
;
569 wined3d_resource_get_desc(resource
, &desc
);
570 if (desc
.pool
== WINED3D_POOL_DEFAULT
)
572 struct d3d8_surface
*surface
;
574 if (desc
.resource_type
!= WINED3D_RTYPE_SURFACE
)
576 WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource
);
577 return D3DERR_DEVICELOST
;
580 surface
= wined3d_resource_get_parent(resource
);
581 if (surface
->refcount
)
583 WARN("Surface %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface
, resource
);
584 return D3DERR_DEVICELOST
;
587 WARN("Surface %p (resource %p) is an implicit resource with ref 0.\n", surface
, resource
);
593 static HRESULT WINAPI
d3d8_device_Reset(IDirect3DDevice8
*iface
,
594 D3DPRESENT_PARAMETERS
*present_parameters
)
596 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
597 struct wined3d_swapchain_desc swapchain_desc
;
600 TRACE("iface %p, present_parameters %p.\n", iface
, present_parameters
);
602 wined3d_mutex_lock();
604 if (device
->vertex_buffer
)
606 wined3d_buffer_decref(device
->vertex_buffer
);
607 device
->vertex_buffer
= NULL
;
608 device
->vertex_buffer_size
= 0;
610 if (device
->index_buffer
)
612 wined3d_buffer_decref(device
->index_buffer
);
613 device
->index_buffer
= NULL
;
614 device
->index_buffer_size
= 0;
617 wined3d_swapchain_desc_from_present_parameters(&swapchain_desc
, present_parameters
);
618 if (SUCCEEDED(hr
= wined3d_device_reset(device
->wined3d_device
, &swapchain_desc
,
619 NULL
, reset_enum_callback
, TRUE
)))
621 wined3d_device_set_render_state(device
->wined3d_device
, WINED3D_RS_POINTSIZE_MIN
, 0);
622 device
->lost
= FALSE
;
628 wined3d_mutex_unlock();
633 static HRESULT WINAPI
d3d8_device_Present(IDirect3DDevice8
*iface
, const RECT
*src_rect
,
634 const RECT
*dst_rect
, HWND dst_window_override
, const RGNDATA
*dirty_region
)
636 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
639 TRACE("iface %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p.\n",
640 iface
, wine_dbgstr_rect(src_rect
), wine_dbgstr_rect(dst_rect
), dst_window_override
, dirty_region
);
642 wined3d_mutex_lock();
643 hr
= wined3d_device_present(device
->wined3d_device
, src_rect
, dst_rect
,
644 dst_window_override
, dirty_region
, 0);
645 wined3d_mutex_unlock();
650 static HRESULT WINAPI
d3d8_device_GetBackBuffer(IDirect3DDevice8
*iface
,
651 UINT backbuffer_idx
, D3DBACKBUFFER_TYPE backbuffer_type
, IDirect3DSurface8
**backbuffer
)
653 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
654 struct wined3d_surface
*wined3d_surface
= NULL
;
655 struct d3d8_surface
*surface_impl
;
658 TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
659 iface
, backbuffer_idx
, backbuffer_type
, backbuffer
);
661 wined3d_mutex_lock();
662 hr
= wined3d_device_get_back_buffer(device
->wined3d_device
, 0, backbuffer_idx
,
663 (enum wined3d_backbuffer_type
)backbuffer_type
, &wined3d_surface
);
664 if (SUCCEEDED(hr
) && wined3d_surface
&& backbuffer
)
666 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
667 *backbuffer
= &surface_impl
->IDirect3DSurface8_iface
;
668 IDirect3DSurface8_AddRef(*backbuffer
);
670 wined3d_mutex_unlock();
675 static HRESULT WINAPI
d3d8_device_GetRasterStatus(IDirect3DDevice8
*iface
, D3DRASTER_STATUS
*raster_status
)
677 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
680 TRACE("iface %p, raster_status %p.\n", iface
, raster_status
);
682 wined3d_mutex_lock();
683 hr
= wined3d_device_get_raster_status(device
->wined3d_device
, 0, (struct wined3d_raster_status
*)raster_status
);
684 wined3d_mutex_unlock();
689 static void WINAPI
d3d8_device_SetGammaRamp(IDirect3DDevice8
*iface
, DWORD flags
, const D3DGAMMARAMP
*ramp
)
691 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
693 TRACE("iface %p, flags %#x, ramp %p.\n", iface
, flags
, ramp
);
695 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
696 wined3d_mutex_lock();
697 wined3d_device_set_gamma_ramp(device
->wined3d_device
, 0, flags
, (const struct wined3d_gamma_ramp
*)ramp
);
698 wined3d_mutex_unlock();
701 static void WINAPI
d3d8_device_GetGammaRamp(IDirect3DDevice8
*iface
, D3DGAMMARAMP
*ramp
)
703 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
705 TRACE("iface %p, ramp %p.\n", iface
, ramp
);
707 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
708 wined3d_mutex_lock();
709 wined3d_device_get_gamma_ramp(device
->wined3d_device
, 0, (struct wined3d_gamma_ramp
*)ramp
);
710 wined3d_mutex_unlock();
713 static HRESULT WINAPI
d3d8_device_CreateTexture(IDirect3DDevice8
*iface
,
714 UINT width
, UINT height
, UINT levels
, DWORD usage
, D3DFORMAT format
,
715 D3DPOOL pool
, IDirect3DTexture8
**texture
)
717 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
718 struct d3d8_texture
*object
;
721 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
722 iface
, width
, height
, levels
, usage
, format
, pool
, texture
);
724 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
726 return D3DERR_OUTOFVIDEOMEMORY
;
728 hr
= texture_init(object
, device
, width
, height
, levels
, usage
, format
, pool
);
731 WARN("Failed to initialize texture, hr %#x.\n", hr
);
732 HeapFree(GetProcessHeap(), 0, object
);
736 TRACE("Created texture %p.\n", object
);
737 *texture
= (IDirect3DTexture8
*)&object
->IDirect3DBaseTexture8_iface
;
742 static HRESULT WINAPI
d3d8_device_CreateVolumeTexture(IDirect3DDevice8
*iface
,
743 UINT width
, UINT height
, UINT depth
, UINT levels
, DWORD usage
, D3DFORMAT format
,
744 D3DPOOL pool
, IDirect3DVolumeTexture8
**texture
)
746 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
747 struct d3d8_texture
*object
;
750 TRACE("iface %p, width %u, height %u, depth %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
751 iface
, width
, height
, depth
, levels
, usage
, format
, pool
, texture
);
753 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
755 return D3DERR_OUTOFVIDEOMEMORY
;
757 hr
= volumetexture_init(object
, device
, width
, height
, depth
, levels
, usage
, format
, pool
);
760 WARN("Failed to initialize volume texture, hr %#x.\n", hr
);
761 HeapFree(GetProcessHeap(), 0, object
);
765 TRACE("Created volume texture %p.\n", object
);
766 *texture
= (IDirect3DVolumeTexture8
*)&object
->IDirect3DBaseTexture8_iface
;
771 static HRESULT WINAPI
d3d8_device_CreateCubeTexture(IDirect3DDevice8
*iface
, UINT edge_length
,
772 UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DCubeTexture8
**texture
)
774 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
775 struct d3d8_texture
*object
;
778 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
779 iface
, edge_length
, levels
, usage
, format
, pool
, texture
);
781 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
783 return D3DERR_OUTOFVIDEOMEMORY
;
785 hr
= cubetexture_init(object
, device
, edge_length
, levels
, usage
, format
, pool
);
788 WARN("Failed to initialize cube texture, hr %#x.\n", hr
);
789 HeapFree(GetProcessHeap(), 0, object
);
793 TRACE("Created cube texture %p.\n", object
);
794 *texture
= (IDirect3DCubeTexture8
*)&object
->IDirect3DBaseTexture8_iface
;
799 static HRESULT WINAPI
d3d8_device_CreateVertexBuffer(IDirect3DDevice8
*iface
, UINT size
,
800 DWORD usage
, DWORD fvf
, D3DPOOL pool
, IDirect3DVertexBuffer8
**buffer
)
802 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
803 struct d3d8_vertexbuffer
*object
;
806 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p.\n",
807 iface
, size
, usage
, fvf
, pool
, buffer
);
809 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
811 return D3DERR_OUTOFVIDEOMEMORY
;
813 hr
= vertexbuffer_init(object
, device
, size
, usage
, fvf
, pool
);
816 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr
);
817 HeapFree(GetProcessHeap(), 0, object
);
821 TRACE("Created vertex buffer %p.\n", object
);
822 *buffer
= &object
->IDirect3DVertexBuffer8_iface
;
827 static HRESULT WINAPI
d3d8_device_CreateIndexBuffer(IDirect3DDevice8
*iface
, UINT size
,
828 DWORD usage
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DIndexBuffer8
**buffer
)
830 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
831 struct d3d8_indexbuffer
*object
;
834 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p.\n",
835 iface
, size
, usage
, format
, pool
, buffer
);
837 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
839 return D3DERR_OUTOFVIDEOMEMORY
;
841 hr
= indexbuffer_init(object
, device
, size
, usage
, format
, pool
);
844 WARN("Failed to initialize index buffer, hr %#x.\n", hr
);
845 HeapFree(GetProcessHeap(), 0, object
);
849 TRACE("Created index buffer %p.\n", object
);
850 *buffer
= &object
->IDirect3DIndexBuffer8_iface
;
855 static HRESULT
d3d8_device_create_surface(struct d3d8_device
*device
, UINT width
, UINT height
,
856 D3DFORMAT format
, BOOL lockable
, BOOL discard
, IDirect3DSurface8
**surface
, UINT usage
,
857 D3DPOOL pool
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
)
859 struct d3d8_surface
*object
;
862 TRACE("device %p, width %u, height %u, format %#x, lockable %#x, discard %#x, surface %p,\n"
863 "\tusage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
864 device
, width
, height
, format
, lockable
, discard
, surface
,
865 usage
, pool
, multisample_type
, multisample_quality
);
867 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
869 FIXME("Failed to allocate surface memory.\n");
870 return D3DERR_OUTOFVIDEOMEMORY
;
873 if (FAILED(hr
= surface_init(object
, device
, width
, height
, format
, lockable
,
874 discard
, usage
, pool
, multisample_type
, multisample_quality
)))
876 WARN("Failed to initialize surface, hr %#x.\n", hr
);
877 HeapFree(GetProcessHeap(), 0, object
);
881 TRACE("Created surface %p.\n", object
);
882 *surface
= &object
->IDirect3DSurface8_iface
;
887 static HRESULT WINAPI
d3d8_device_CreateRenderTarget(IDirect3DDevice8
*iface
, UINT width
,
888 UINT height
, D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, BOOL lockable
,
889 IDirect3DSurface8
**surface
)
891 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
893 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, lockable %#x, surface %p.\n",
894 iface
, width
, height
, format
, multisample_type
, lockable
, surface
);
896 return d3d8_device_create_surface(device
, width
, height
, format
, lockable
, FALSE
,
897 surface
, D3DUSAGE_RENDERTARGET
, D3DPOOL_DEFAULT
, multisample_type
, 0);
900 static HRESULT WINAPI
d3d8_device_CreateDepthStencilSurface(IDirect3DDevice8
*iface
,
901 UINT width
, UINT height
, D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
,
902 IDirect3DSurface8
**surface
)
904 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
906 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, surface %p.\n",
907 iface
, width
, height
, format
, multisample_type
, surface
);
909 /* TODO: Verify that Discard is false */
910 return d3d8_device_create_surface(device
, width
, height
, format
, TRUE
, FALSE
,
911 surface
, D3DUSAGE_DEPTHSTENCIL
, D3DPOOL_DEFAULT
, multisample_type
, 0);
914 /* IDirect3DDevice8Impl::CreateImageSurface returns surface with pool type SYSTEMMEM */
915 static HRESULT WINAPI
d3d8_device_CreateImageSurface(IDirect3DDevice8
*iface
, UINT width
,
916 UINT height
, D3DFORMAT format
, IDirect3DSurface8
**surface
)
918 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
920 TRACE("iface %p, width %u, height %u, format %#x, surface %p.\n",
921 iface
, width
, height
, format
, surface
);
923 return d3d8_device_create_surface(device
, width
, height
, format
, TRUE
, FALSE
,
924 surface
, 0, D3DPOOL_SYSTEMMEM
, D3DMULTISAMPLE_NONE
, 0);
927 static HRESULT WINAPI
d3d8_device_CopyRects(IDirect3DDevice8
*iface
,
928 IDirect3DSurface8
*src_surface
, const RECT
*src_rects
, UINT rect_count
,
929 IDirect3DSurface8
*dst_surface
, const POINT
*dst_points
)
931 struct d3d8_surface
*src
= unsafe_impl_from_IDirect3DSurface8(src_surface
);
932 struct d3d8_surface
*dst
= unsafe_impl_from_IDirect3DSurface8(dst_surface
);
933 enum wined3d_format_id src_format
, dst_format
;
934 struct wined3d_resource_desc wined3d_desc
;
935 struct wined3d_resource
*wined3d_resource
;
939 TRACE("iface %p, src_surface %p, src_rects %p, rect_count %u, dst_surface %p, dst_points %p.\n",
940 iface
, src_surface
, src_rects
, rect_count
, dst_surface
, dst_points
);
942 /* Check that the source texture is in WINED3D_POOL_SYSTEM_MEM and the
943 * destination texture is in WINED3D_POOL_DEFAULT. */
945 wined3d_mutex_lock();
946 wined3d_resource
= wined3d_surface_get_resource(src
->wined3d_surface
);
947 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
948 if (wined3d_desc
.usage
& WINED3DUSAGE_DEPTHSTENCIL
)
950 WARN("Source %p is a depth stencil surface, returning D3DERR_INVALIDCALL.\n", src_surface
);
951 wined3d_mutex_unlock();
952 return D3DERR_INVALIDCALL
;
954 src_format
= wined3d_desc
.format
;
955 src_w
= wined3d_desc
.width
;
956 src_h
= wined3d_desc
.height
;
958 wined3d_resource
= wined3d_surface_get_resource(dst
->wined3d_surface
);
959 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
960 if (wined3d_desc
.usage
& WINED3DUSAGE_DEPTHSTENCIL
)
962 WARN("Destination %p is a depth stencil surface, returning D3DERR_INVALIDCALL.\n", dst_surface
);
963 wined3d_mutex_unlock();
964 return D3DERR_INVALIDCALL
;
966 dst_format
= wined3d_desc
.format
;
968 /* Check that the source and destination formats match */
969 if (src_format
!= dst_format
&& WINED3DFMT_UNKNOWN
!= dst_format
)
971 WARN("Source %p format must match the destination %p format, returning D3DERR_INVALIDCALL.\n",
972 src_surface
, dst_surface
);
973 wined3d_mutex_unlock();
974 return D3DERR_INVALIDCALL
;
976 else if (WINED3DFMT_UNKNOWN
== dst_format
)
978 TRACE("Converting destination surface from WINED3DFMT_UNKNOWN to the source format.\n");
979 if (FAILED(hr
= wined3d_surface_update_desc(dst
->wined3d_surface
, wined3d_desc
.width
, wined3d_desc
.height
,
980 src_format
, wined3d_desc
.multisample_type
, wined3d_desc
.multisample_quality
)))
982 WARN("Failed to update surface desc, hr %#x.\n", hr
);
983 wined3d_mutex_unlock();
988 /* Quick if complete copy ... */
989 if (!rect_count
&& !src_rects
&& !dst_points
)
991 RECT rect
= {0, 0, src_w
, src_h
};
992 wined3d_surface_blt(dst
->wined3d_surface
, &rect
,
993 src
->wined3d_surface
, &rect
, 0, NULL
, WINED3D_TEXF_POINT
);
998 /* Copy rect by rect */
999 if (src_rects
&& dst_points
)
1001 for (i
= 0; i
< rect_count
; ++i
)
1003 UINT w
= src_rects
[i
].right
- src_rects
[i
].left
;
1004 UINT h
= src_rects
[i
].bottom
- src_rects
[i
].top
;
1005 RECT dst_rect
= {dst_points
[i
].x
, dst_points
[i
].y
,
1006 dst_points
[i
].x
+ w
, dst_points
[i
].y
+ h
};
1008 wined3d_surface_blt(dst
->wined3d_surface
, &dst_rect
,
1009 src
->wined3d_surface
, &src_rects
[i
], 0, NULL
, WINED3D_TEXF_POINT
);
1014 for (i
= 0; i
< rect_count
; ++i
)
1016 UINT w
= src_rects
[i
].right
- src_rects
[i
].left
;
1017 UINT h
= src_rects
[i
].bottom
- src_rects
[i
].top
;
1018 RECT dst_rect
= {0, 0, w
, h
};
1020 wined3d_surface_blt(dst
->wined3d_surface
, &dst_rect
,
1021 src
->wined3d_surface
, &src_rects
[i
], 0, NULL
, WINED3D_TEXF_POINT
);
1025 wined3d_mutex_unlock();
1030 static HRESULT WINAPI
d3d8_device_UpdateTexture(IDirect3DDevice8
*iface
,
1031 IDirect3DBaseTexture8
*src_texture
, IDirect3DBaseTexture8
*dst_texture
)
1033 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1034 struct d3d8_texture
*src_impl
, *dst_impl
;
1037 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface
, src_texture
, dst_texture
);
1039 src_impl
= unsafe_impl_from_IDirect3DBaseTexture8(src_texture
);
1040 dst_impl
= unsafe_impl_from_IDirect3DBaseTexture8(dst_texture
);
1042 wined3d_mutex_lock();
1043 hr
= wined3d_device_update_texture(device
->wined3d_device
,
1044 src_impl
->wined3d_texture
, dst_impl
->wined3d_texture
);
1045 wined3d_mutex_unlock();
1050 static HRESULT WINAPI
d3d8_device_GetFrontBuffer(IDirect3DDevice8
*iface
, IDirect3DSurface8
*dst_surface
)
1052 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1053 struct d3d8_surface
*dst_impl
= unsafe_impl_from_IDirect3DSurface8(dst_surface
);
1056 TRACE("iface %p, dst_surface %p.\n", iface
, dst_surface
);
1060 WARN("Invalid destination surface passed.\n");
1061 return D3DERR_INVALIDCALL
;
1064 wined3d_mutex_lock();
1065 hr
= wined3d_device_get_front_buffer_data(device
->wined3d_device
, 0, dst_impl
->wined3d_surface
);
1066 wined3d_mutex_unlock();
1071 static HRESULT WINAPI
d3d8_device_SetRenderTarget(IDirect3DDevice8
*iface
,
1072 IDirect3DSurface8
*render_target
, IDirect3DSurface8
*depth_stencil
)
1074 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1075 struct d3d8_surface
*rt_impl
= unsafe_impl_from_IDirect3DSurface8(render_target
);
1076 struct d3d8_surface
*ds_impl
= unsafe_impl_from_IDirect3DSurface8(depth_stencil
);
1077 struct wined3d_surface
*original_ds
= NULL
;
1078 HRESULT hr
= D3D_OK
;
1080 TRACE("iface %p, render_target %p, depth_stencil %p.\n", iface
, render_target
, depth_stencil
);
1082 wined3d_mutex_lock();
1086 struct wined3d_resource_desc ds_desc
, rt_desc
;
1087 struct wined3d_resource
*wined3d_resource
;
1088 struct wined3d_surface
*original_rt
= NULL
;
1090 /* If no render target is passed in check the size against the current RT */
1093 if (!(original_rt
= wined3d_device_get_render_target(device
->wined3d_device
, 0)))
1095 wined3d_mutex_unlock();
1096 return D3DERR_NOTFOUND
;
1098 wined3d_resource
= wined3d_surface_get_resource(original_rt
);
1101 wined3d_resource
= wined3d_surface_get_resource(rt_impl
->wined3d_surface
);
1102 wined3d_resource_get_desc(wined3d_resource
, &rt_desc
);
1104 wined3d_resource
= wined3d_surface_get_resource(ds_impl
->wined3d_surface
);
1105 wined3d_resource_get_desc(wined3d_resource
, &ds_desc
);
1107 if (ds_desc
.width
< rt_desc
.width
|| ds_desc
.height
< rt_desc
.height
)
1109 WARN("Depth stencil is smaller than the render target, returning D3DERR_INVALIDCALL\n");
1110 wined3d_mutex_unlock();
1111 return D3DERR_INVALIDCALL
;
1115 original_ds
= wined3d_device_get_depth_stencil(device
->wined3d_device
);
1116 wined3d_device_set_depth_stencil(device
->wined3d_device
, ds_impl
? ds_impl
->wined3d_surface
: NULL
);
1119 hr
= wined3d_device_set_render_target(device
->wined3d_device
, 0, rt_impl
->wined3d_surface
, TRUE
);
1121 wined3d_device_set_depth_stencil(device
->wined3d_device
, original_ds
);
1124 wined3d_mutex_unlock();
1129 static HRESULT WINAPI
d3d8_device_GetRenderTarget(IDirect3DDevice8
*iface
, IDirect3DSurface8
**render_target
)
1131 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1132 struct wined3d_surface
*wined3d_surface
;
1133 struct d3d8_surface
*surface_impl
;
1136 TRACE("iface %p, render_target %p.\n", iface
, render_target
);
1139 return D3DERR_INVALIDCALL
;
1141 wined3d_mutex_lock();
1142 if ((wined3d_surface
= wined3d_device_get_render_target(device
->wined3d_device
, 0)))
1144 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
1145 *render_target
= &surface_impl
->IDirect3DSurface8_iface
;
1146 IDirect3DSurface8_AddRef(*render_target
);
1151 ERR("Failed to get wined3d render target.\n");
1152 *render_target
= NULL
;
1153 hr
= D3DERR_NOTFOUND
;
1155 wined3d_mutex_unlock();
1160 static HRESULT WINAPI
d3d8_device_GetDepthStencilSurface(IDirect3DDevice8
*iface
, IDirect3DSurface8
**depth_stencil
)
1162 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1163 struct wined3d_surface
*wined3d_surface
;
1164 struct d3d8_surface
*surface_impl
;
1165 HRESULT hr
= D3D_OK
;
1167 TRACE("iface %p, depth_stencil %p.\n", iface
, depth_stencil
);
1170 return D3DERR_INVALIDCALL
;
1172 wined3d_mutex_lock();
1173 if ((wined3d_surface
= wined3d_device_get_depth_stencil(device
->wined3d_device
)))
1175 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
1176 *depth_stencil
= &surface_impl
->IDirect3DSurface8_iface
;
1177 IDirect3DSurface8_AddRef(*depth_stencil
);
1181 hr
= WINED3DERR_NOTFOUND
;
1182 *depth_stencil
= NULL
;
1184 wined3d_mutex_unlock();
1189 static HRESULT WINAPI
d3d8_device_BeginScene(IDirect3DDevice8
*iface
)
1191 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1194 TRACE("iface %p.\n", iface
);
1196 wined3d_mutex_lock();
1197 hr
= wined3d_device_begin_scene(device
->wined3d_device
);
1198 wined3d_mutex_unlock();
1203 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d8_device_EndScene(IDirect3DDevice8
*iface
)
1205 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1208 TRACE("iface %p.\n", iface
);
1210 wined3d_mutex_lock();
1211 hr
= wined3d_device_end_scene(device
->wined3d_device
);
1212 wined3d_mutex_unlock();
1217 static HRESULT WINAPI
d3d8_device_Clear(IDirect3DDevice8
*iface
, DWORD rect_count
,
1218 const D3DRECT
*rects
, DWORD flags
, D3DCOLOR color
, float z
, DWORD stencil
)
1220 const struct wined3d_color c
=
1222 ((color
>> 16) & 0xff) / 255.0f
,
1223 ((color
>> 8) & 0xff) / 255.0f
,
1224 (color
& 0xff) / 255.0f
,
1225 ((color
>> 24) & 0xff) / 255.0f
,
1227 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1230 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1231 iface
, rect_count
, rects
, flags
, color
, z
, stencil
);
1233 wined3d_mutex_lock();
1234 hr
= wined3d_device_clear(device
->wined3d_device
, rect_count
, (const RECT
*)rects
, flags
, &c
, z
, stencil
);
1235 wined3d_mutex_unlock();
1240 static HRESULT WINAPI
d3d8_device_SetTransform(IDirect3DDevice8
*iface
,
1241 D3DTRANSFORMSTATETYPE state
, const D3DMATRIX
*matrix
)
1243 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1245 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1247 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1248 wined3d_mutex_lock();
1249 wined3d_device_set_transform(device
->wined3d_device
, state
, (const struct wined3d_matrix
*)matrix
);
1250 wined3d_mutex_unlock();
1255 static HRESULT WINAPI
d3d8_device_GetTransform(IDirect3DDevice8
*iface
,
1256 D3DTRANSFORMSTATETYPE state
, D3DMATRIX
*matrix
)
1258 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1260 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1262 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1263 wined3d_mutex_lock();
1264 wined3d_device_get_transform(device
->wined3d_device
, state
, (struct wined3d_matrix
*)matrix
);
1265 wined3d_mutex_unlock();
1270 static HRESULT WINAPI
d3d8_device_MultiplyTransform(IDirect3DDevice8
*iface
,
1271 D3DTRANSFORMSTATETYPE state
, const D3DMATRIX
*matrix
)
1273 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1275 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1277 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1278 wined3d_mutex_lock();
1279 wined3d_device_multiply_transform(device
->wined3d_device
, state
, (const struct wined3d_matrix
*)matrix
);
1280 wined3d_mutex_unlock();
1285 static HRESULT WINAPI
d3d8_device_SetViewport(IDirect3DDevice8
*iface
, const D3DVIEWPORT8
*viewport
)
1287 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1289 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
1291 /* Note: D3DVIEWPORT8 is compatible with struct wined3d_viewport. */
1292 wined3d_mutex_lock();
1293 wined3d_device_set_viewport(device
->wined3d_device
, (const struct wined3d_viewport
*)viewport
);
1294 wined3d_mutex_unlock();
1299 static HRESULT WINAPI
d3d8_device_GetViewport(IDirect3DDevice8
*iface
, D3DVIEWPORT8
*viewport
)
1301 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1303 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
1305 /* Note: D3DVIEWPORT8 is compatible with struct wined3d_viewport. */
1306 wined3d_mutex_lock();
1307 wined3d_device_get_viewport(device
->wined3d_device
, (struct wined3d_viewport
*)viewport
);
1308 wined3d_mutex_unlock();
1313 static HRESULT WINAPI
d3d8_device_SetMaterial(IDirect3DDevice8
*iface
, const D3DMATERIAL8
*material
)
1315 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1317 TRACE("iface %p, material %p.\n", iface
, material
);
1319 /* Note: D3DMATERIAL8 is compatible with struct wined3d_material. */
1320 wined3d_mutex_lock();
1321 wined3d_device_set_material(device
->wined3d_device
, (const struct wined3d_material
*)material
);
1322 wined3d_mutex_unlock();
1327 static HRESULT WINAPI
d3d8_device_GetMaterial(IDirect3DDevice8
*iface
, D3DMATERIAL8
*material
)
1329 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1331 TRACE("iface %p, material %p.\n", iface
, material
);
1333 /* Note: D3DMATERIAL8 is compatible with struct wined3d_material. */
1334 wined3d_mutex_lock();
1335 wined3d_device_get_material(device
->wined3d_device
, (struct wined3d_material
*)material
);
1336 wined3d_mutex_unlock();
1341 static HRESULT WINAPI
d3d8_device_SetLight(IDirect3DDevice8
*iface
, DWORD index
, const D3DLIGHT8
*light
)
1343 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1346 TRACE("iface %p, index %u, light %p.\n", iface
, index
, light
);
1348 /* Note: D3DLIGHT8 is compatible with struct wined3d_light. */
1349 wined3d_mutex_lock();
1350 hr
= wined3d_device_set_light(device
->wined3d_device
, index
, (const struct wined3d_light
*)light
);
1351 wined3d_mutex_unlock();
1356 static HRESULT WINAPI
d3d8_device_GetLight(IDirect3DDevice8
*iface
, DWORD index
, D3DLIGHT8
*light
)
1358 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1361 TRACE("iface %p, index %u, light %p.\n", iface
, index
, light
);
1363 /* Note: D3DLIGHT8 is compatible with struct wined3d_light. */
1364 wined3d_mutex_lock();
1365 hr
= wined3d_device_get_light(device
->wined3d_device
, index
, (struct wined3d_light
*)light
);
1366 wined3d_mutex_unlock();
1371 static HRESULT WINAPI
d3d8_device_LightEnable(IDirect3DDevice8
*iface
, DWORD index
, BOOL enable
)
1373 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1376 TRACE("iface %p, index %u, enable %#x.\n", iface
, index
, enable
);
1378 wined3d_mutex_lock();
1379 hr
= wined3d_device_set_light_enable(device
->wined3d_device
, index
, enable
);
1380 wined3d_mutex_unlock();
1385 static HRESULT WINAPI
d3d8_device_GetLightEnable(IDirect3DDevice8
*iface
, DWORD index
, BOOL
*enable
)
1387 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1390 TRACE("iface %p, index %u, enable %p.\n", iface
, index
, enable
);
1392 wined3d_mutex_lock();
1393 hr
= wined3d_device_get_light_enable(device
->wined3d_device
, index
, enable
);
1394 wined3d_mutex_unlock();
1399 static HRESULT WINAPI
d3d8_device_SetClipPlane(IDirect3DDevice8
*iface
, DWORD index
, const float *plane
)
1401 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1404 TRACE("iface %p, index %u, plane %p.\n", iface
, index
, plane
);
1406 wined3d_mutex_lock();
1407 hr
= wined3d_device_set_clip_plane(device
->wined3d_device
, index
, (const struct wined3d_vec4
*)plane
);
1408 wined3d_mutex_unlock();
1413 static HRESULT WINAPI
d3d8_device_GetClipPlane(IDirect3DDevice8
*iface
, DWORD index
, float *plane
)
1415 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1418 TRACE("iface %p, index %u, plane %p.\n", iface
, index
, plane
);
1420 wined3d_mutex_lock();
1421 hr
= wined3d_device_get_clip_plane(device
->wined3d_device
, index
, (struct wined3d_vec4
*)plane
);
1422 wined3d_mutex_unlock();
1427 static HRESULT WINAPI
d3d8_device_SetRenderState(IDirect3DDevice8
*iface
,
1428 D3DRENDERSTATETYPE state
, DWORD value
)
1430 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1432 TRACE("iface %p, state %#x, value %#x.\n", iface
, state
, value
);
1434 wined3d_mutex_lock();
1438 wined3d_device_set_render_state(device
->wined3d_device
, WINED3D_RS_DEPTHBIAS
, value
);
1442 wined3d_device_set_render_state(device
->wined3d_device
, state
, value
);
1444 wined3d_mutex_unlock();
1449 static HRESULT WINAPI
d3d8_device_GetRenderState(IDirect3DDevice8
*iface
,
1450 D3DRENDERSTATETYPE state
, DWORD
*value
)
1452 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1454 TRACE("iface %p, state %#x, value %p.\n", iface
, state
, value
);
1456 wined3d_mutex_lock();
1460 *value
= wined3d_device_get_render_state(device
->wined3d_device
, WINED3D_RS_DEPTHBIAS
);
1464 *value
= wined3d_device_get_render_state(device
->wined3d_device
, state
);
1466 wined3d_mutex_unlock();
1471 static HRESULT WINAPI
d3d8_device_BeginStateBlock(IDirect3DDevice8
*iface
)
1473 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1476 TRACE("iface %p.\n", iface
);
1478 wined3d_mutex_lock();
1479 hr
= wined3d_device_begin_stateblock(device
->wined3d_device
);
1480 wined3d_mutex_unlock();
1485 static HRESULT WINAPI
d3d8_device_EndStateBlock(IDirect3DDevice8
*iface
, DWORD
*token
)
1487 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1488 struct wined3d_stateblock
*stateblock
;
1491 TRACE("iface %p, token %p.\n", iface
, token
);
1493 /* Tell wineD3D to endstateblock before anything else (in case we run out
1494 * of memory later and cause locking problems)
1496 wined3d_mutex_lock();
1497 hr
= wined3d_device_end_stateblock(device
->wined3d_device
, &stateblock
);
1500 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
1501 wined3d_mutex_unlock();
1505 *token
= d3d8_allocate_handle(&device
->handle_table
, stateblock
, D3D8_HANDLE_SB
);
1506 wined3d_mutex_unlock();
1508 if (*token
== D3D8_INVALID_HANDLE
)
1510 ERR("Failed to create a handle\n");
1511 wined3d_mutex_lock();
1512 wined3d_stateblock_decref(stateblock
);
1513 wined3d_mutex_unlock();
1518 TRACE("Returning %#x (%p).\n", *token
, stateblock
);
1523 static HRESULT WINAPI
d3d8_device_ApplyStateBlock(IDirect3DDevice8
*iface
, DWORD token
)
1525 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1526 struct wined3d_stateblock
*stateblock
;
1528 TRACE("iface %p, token %#x.\n", iface
, token
);
1533 wined3d_mutex_lock();
1534 stateblock
= d3d8_get_object(&device
->handle_table
, token
- 1, D3D8_HANDLE_SB
);
1537 WARN("Invalid handle (%#x) passed.\n", token
);
1538 wined3d_mutex_unlock();
1539 return D3DERR_INVALIDCALL
;
1541 wined3d_stateblock_apply(stateblock
);
1542 wined3d_mutex_unlock();
1547 static HRESULT WINAPI
d3d8_device_CaptureStateBlock(IDirect3DDevice8
*iface
, DWORD token
)
1549 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1550 struct wined3d_stateblock
*stateblock
;
1552 TRACE("iface %p, token %#x.\n", iface
, token
);
1554 wined3d_mutex_lock();
1555 stateblock
= d3d8_get_object(&device
->handle_table
, token
- 1, D3D8_HANDLE_SB
);
1558 WARN("Invalid handle (%#x) passed.\n", token
);
1559 wined3d_mutex_unlock();
1560 return D3DERR_INVALIDCALL
;
1562 wined3d_stateblock_capture(stateblock
);
1563 wined3d_mutex_unlock();
1568 static HRESULT WINAPI
d3d8_device_DeleteStateBlock(IDirect3DDevice8
*iface
, DWORD token
)
1570 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1571 struct wined3d_stateblock
*stateblock
;
1573 TRACE("iface %p, token %#x.\n", iface
, token
);
1575 wined3d_mutex_lock();
1576 stateblock
= d3d8_free_handle(&device
->handle_table
, token
- 1, D3D8_HANDLE_SB
);
1580 WARN("Invalid handle (%#x) passed.\n", token
);
1581 wined3d_mutex_unlock();
1582 return D3DERR_INVALIDCALL
;
1585 if (wined3d_stateblock_decref(stateblock
))
1587 ERR("Stateblock %p has references left, this shouldn't happen.\n", stateblock
);
1589 wined3d_mutex_unlock();
1594 static HRESULT WINAPI
d3d8_device_CreateStateBlock(IDirect3DDevice8
*iface
,
1595 D3DSTATEBLOCKTYPE type
, DWORD
*handle
)
1597 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1598 struct wined3d_stateblock
*stateblock
;
1601 TRACE("iface %p, type %#x, handle %p.\n", iface
, type
, handle
);
1603 if (type
!= D3DSBT_ALL
1604 && type
!= D3DSBT_PIXELSTATE
1605 && type
!= D3DSBT_VERTEXSTATE
)
1607 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1608 return D3DERR_INVALIDCALL
;
1611 wined3d_mutex_lock();
1612 hr
= wined3d_stateblock_create(device
->wined3d_device
, (enum wined3d_stateblock_type
)type
, &stateblock
);
1615 wined3d_mutex_unlock();
1616 ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr
);
1620 *handle
= d3d8_allocate_handle(&device
->handle_table
, stateblock
, D3D8_HANDLE_SB
);
1621 wined3d_mutex_unlock();
1623 if (*handle
== D3D8_INVALID_HANDLE
)
1625 ERR("Failed to allocate a handle.\n");
1626 wined3d_mutex_lock();
1627 wined3d_stateblock_decref(stateblock
);
1628 wined3d_mutex_unlock();
1633 TRACE("Returning %#x (%p).\n", *handle
, stateblock
);
1638 static HRESULT WINAPI
d3d8_device_SetClipStatus(IDirect3DDevice8
*iface
, const D3DCLIPSTATUS8
*clip_status
)
1640 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1643 TRACE("iface %p, clip_status %p.\n", iface
, clip_status
);
1644 /* FIXME: Verify that D3DCLIPSTATUS8 ~= struct wined3d_clip_status. */
1646 wined3d_mutex_lock();
1647 hr
= wined3d_device_set_clip_status(device
->wined3d_device
, (const struct wined3d_clip_status
*)clip_status
);
1648 wined3d_mutex_unlock();
1653 static HRESULT WINAPI
d3d8_device_GetClipStatus(IDirect3DDevice8
*iface
, D3DCLIPSTATUS8
*clip_status
)
1655 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1658 TRACE("iface %p, clip_status %p.\n", iface
, clip_status
);
1660 wined3d_mutex_lock();
1661 hr
= wined3d_device_get_clip_status(device
->wined3d_device
, (struct wined3d_clip_status
*)clip_status
);
1662 wined3d_mutex_unlock();
1667 static HRESULT WINAPI
d3d8_device_GetTexture(IDirect3DDevice8
*iface
, DWORD stage
, IDirect3DBaseTexture8
**texture
)
1669 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1670 struct wined3d_texture
*wined3d_texture
;
1671 struct d3d8_texture
*texture_impl
;
1673 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
1676 return D3DERR_INVALIDCALL
;
1678 wined3d_mutex_lock();
1679 if ((wined3d_texture
= wined3d_device_get_texture(device
->wined3d_device
, stage
)))
1681 texture_impl
= wined3d_texture_get_parent(wined3d_texture
);
1682 *texture
= &texture_impl
->IDirect3DBaseTexture8_iface
;
1683 IDirect3DBaseTexture8_AddRef(*texture
);
1689 wined3d_mutex_unlock();
1694 static HRESULT WINAPI
d3d8_device_SetTexture(IDirect3DDevice8
*iface
, DWORD stage
, IDirect3DBaseTexture8
*texture
)
1696 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1697 struct d3d8_texture
*texture_impl
;
1700 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
1702 texture_impl
= unsafe_impl_from_IDirect3DBaseTexture8(texture
);
1704 wined3d_mutex_lock();
1705 hr
= wined3d_device_set_texture(device
->wined3d_device
, stage
,
1706 texture_impl
? texture_impl
->wined3d_texture
: NULL
);
1707 wined3d_mutex_unlock();
1712 static const struct tss_lookup
1715 enum wined3d_texture_stage_state state
;
1719 {FALSE
, WINED3D_TSS_INVALID
}, /* 0, unused */
1720 {FALSE
, WINED3D_TSS_COLOR_OP
}, /* 1, D3DTSS_COLOROP */
1721 {FALSE
, WINED3D_TSS_COLOR_ARG1
}, /* 2, D3DTSS_COLORARG1 */
1722 {FALSE
, WINED3D_TSS_COLOR_ARG2
}, /* 3, D3DTSS_COLORARG2 */
1723 {FALSE
, WINED3D_TSS_ALPHA_OP
}, /* 4, D3DTSS_ALPHAOP */
1724 {FALSE
, WINED3D_TSS_ALPHA_ARG1
}, /* 5, D3DTSS_ALPHAARG1 */
1725 {FALSE
, WINED3D_TSS_ALPHA_ARG2
}, /* 6, D3DTSS_ALPHAARG2 */
1726 {FALSE
, WINED3D_TSS_BUMPENV_MAT00
}, /* 7, D3DTSS_BUMPENVMAT00 */
1727 {FALSE
, WINED3D_TSS_BUMPENV_MAT01
}, /* 8, D3DTSS_BUMPENVMAT01 */
1728 {FALSE
, WINED3D_TSS_BUMPENV_MAT10
}, /* 9, D3DTSS_BUMPENVMAT10 */
1729 {FALSE
, WINED3D_TSS_BUMPENV_MAT11
}, /* 10, D3DTSS_BUMPENVMAT11 */
1730 {FALSE
, WINED3D_TSS_TEXCOORD_INDEX
}, /* 11, D3DTSS_TEXCOORDINDEX */
1731 {FALSE
, WINED3D_TSS_INVALID
}, /* 12, unused */
1732 {TRUE
, WINED3D_SAMP_ADDRESS_U
}, /* 13, D3DTSS_ADDRESSU */
1733 {TRUE
, WINED3D_SAMP_ADDRESS_V
}, /* 14, D3DTSS_ADDRESSV */
1734 {TRUE
, WINED3D_SAMP_BORDER_COLOR
}, /* 15, D3DTSS_BORDERCOLOR */
1735 {TRUE
, WINED3D_SAMP_MAG_FILTER
}, /* 16, D3DTSS_MAGFILTER */
1736 {TRUE
, WINED3D_SAMP_MIN_FILTER
}, /* 17, D3DTSS_MINFILTER */
1737 {TRUE
, WINED3D_SAMP_MIP_FILTER
}, /* 18, D3DTSS_MIPFILTER */
1738 {TRUE
, WINED3D_SAMP_MIPMAP_LOD_BIAS
}, /* 19, D3DTSS_MIPMAPLODBIAS */
1739 {TRUE
, WINED3D_SAMP_MAX_MIP_LEVEL
}, /* 20, D3DTSS_MAXMIPLEVEL */
1740 {TRUE
, WINED3D_SAMP_MAX_ANISOTROPY
}, /* 21, D3DTSS_MAXANISOTROPY */
1741 {FALSE
, WINED3D_TSS_BUMPENV_LSCALE
}, /* 22, D3DTSS_BUMPENVLSCALE */
1742 {FALSE
, WINED3D_TSS_BUMPENV_LOFFSET
}, /* 23, D3DTSS_BUMPENVLOFFSET */
1743 {FALSE
, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1744 {TRUE
, WINED3D_SAMP_ADDRESS_W
}, /* 25, D3DTSS_ADDRESSW */
1745 {FALSE
, WINED3D_TSS_COLOR_ARG0
}, /* 26, D3DTSS_COLORARG0 */
1746 {FALSE
, WINED3D_TSS_ALPHA_ARG0
}, /* 27, D3DTSS_ALPHAARG0 */
1747 {FALSE
, WINED3D_TSS_RESULT_ARG
}, /* 28, D3DTSS_RESULTARG */
1750 static HRESULT WINAPI
d3d8_device_GetTextureStageState(IDirect3DDevice8
*iface
,
1751 DWORD stage
, D3DTEXTURESTAGESTATETYPE Type
, DWORD
*value
)
1753 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1754 const struct tss_lookup
*l
;
1756 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface
, stage
, Type
, value
);
1758 if (Type
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
1760 WARN("Invalid Type %#x passed.\n", Type
);
1764 l
= &tss_lookup
[Type
];
1766 wined3d_mutex_lock();
1767 if (l
->sampler_state
)
1768 *value
= wined3d_device_get_sampler_state(device
->wined3d_device
, stage
, l
->state
);
1770 *value
= wined3d_device_get_texture_stage_state(device
->wined3d_device
, stage
, l
->state
);
1771 wined3d_mutex_unlock();
1776 static HRESULT WINAPI
d3d8_device_SetTextureStageState(IDirect3DDevice8
*iface
,
1777 DWORD stage
, D3DTEXTURESTAGESTATETYPE type
, DWORD value
)
1779 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1780 const struct tss_lookup
*l
;
1782 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface
, stage
, type
, value
);
1784 if (type
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
1786 WARN("Invalid type %#x passed.\n", type
);
1790 l
= &tss_lookup
[type
];
1792 wined3d_mutex_lock();
1793 if (l
->sampler_state
)
1794 wined3d_device_set_sampler_state(device
->wined3d_device
, stage
, l
->state
, value
);
1796 wined3d_device_set_texture_stage_state(device
->wined3d_device
, stage
, l
->state
, value
);
1797 wined3d_mutex_unlock();
1802 static HRESULT WINAPI
d3d8_device_ValidateDevice(IDirect3DDevice8
*iface
, DWORD
*pass_count
)
1804 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1807 TRACE("iface %p, pass_count %p.\n", iface
, pass_count
);
1809 wined3d_mutex_lock();
1810 hr
= wined3d_device_validate_device(device
->wined3d_device
, pass_count
);
1811 wined3d_mutex_unlock();
1816 static HRESULT WINAPI
d3d8_device_GetInfo(IDirect3DDevice8
*iface
,
1817 DWORD info_id
, void *info
, DWORD info_size
)
1819 FIXME("iface %p, info_id %#x, info %p, info_size %u stub!\n", iface
, info_id
, info
, info_size
);
1824 static HRESULT WINAPI
d3d8_device_SetPaletteEntries(IDirect3DDevice8
*iface
,
1825 UINT palette_idx
, const PALETTEENTRY
*entries
)
1827 WARN("iface %p, palette_idx %u, entries %p unimplemented\n", iface
, palette_idx
, entries
);
1829 /* GPUs stopped supporting palettized textures with the Shader Model 1 generation. Wined3d
1830 * does not have a d3d8/9-style palette API */
1835 static HRESULT WINAPI
d3d8_device_GetPaletteEntries(IDirect3DDevice8
*iface
,
1836 UINT palette_idx
, PALETTEENTRY
*entries
)
1838 FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface
, palette_idx
, entries
);
1840 return D3DERR_INVALIDCALL
;
1843 static HRESULT WINAPI
d3d8_device_SetCurrentTexturePalette(IDirect3DDevice8
*iface
, UINT palette_idx
)
1845 WARN("iface %p, palette_idx %u unimplemented.\n", iface
, palette_idx
);
1850 static HRESULT WINAPI
d3d8_device_GetCurrentTexturePalette(IDirect3DDevice8
*iface
, UINT
*palette_idx
)
1852 FIXME("iface %p, palette_idx %p unimplemented.\n", iface
, palette_idx
);
1854 return D3DERR_INVALIDCALL
;
1857 static HRESULT WINAPI
d3d8_device_DrawPrimitive(IDirect3DDevice8
*iface
,
1858 D3DPRIMITIVETYPE primitive_type
, UINT start_vertex
, UINT primitive_count
)
1860 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1863 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1864 iface
, primitive_type
, start_vertex
, primitive_count
);
1866 wined3d_mutex_lock();
1867 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
1868 hr
= wined3d_device_draw_primitive(device
->wined3d_device
, start_vertex
,
1869 vertex_count_from_primitive_count(primitive_type
, primitive_count
));
1870 wined3d_mutex_unlock();
1875 static HRESULT WINAPI
d3d8_device_DrawIndexedPrimitive(IDirect3DDevice8
*iface
,
1876 D3DPRIMITIVETYPE primitive_type
, UINT min_vertex_idx
, UINT vertex_count
,
1877 UINT start_idx
, UINT primitive_count
)
1879 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1882 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, start_idx %u, primitive_count %u.\n",
1883 iface
, primitive_type
, min_vertex_idx
, vertex_count
, start_idx
, primitive_count
);
1885 wined3d_mutex_lock();
1886 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
1887 hr
= wined3d_device_draw_indexed_primitive(device
->wined3d_device
, start_idx
,
1888 vertex_count_from_primitive_count(primitive_type
, primitive_count
));
1889 wined3d_mutex_unlock();
1894 static void STDMETHODCALLTYPE
d3d8_null_wined3d_object_destroyed(void *parent
) {}
1896 static const struct wined3d_parent_ops d3d8_null_wined3d_parent_ops
=
1898 d3d8_null_wined3d_object_destroyed
,
1901 /* The caller is responsible for wined3d locking */
1902 static HRESULT
d3d8_device_prepare_vertex_buffer(struct d3d8_device
*device
, UINT min_size
)
1906 if (device
->vertex_buffer_size
< min_size
|| !device
->vertex_buffer
)
1908 UINT size
= max(device
->vertex_buffer_size
* 2, min_size
);
1909 struct wined3d_buffer
*buffer
;
1911 TRACE("Growing vertex buffer to %u bytes\n", size
);
1913 hr
= wined3d_buffer_create_vb(device
->wined3d_device
, size
, WINED3DUSAGE_DYNAMIC
| WINED3DUSAGE_WRITEONLY
,
1914 WINED3D_POOL_DEFAULT
, NULL
, &d3d8_null_wined3d_parent_ops
, &buffer
);
1917 ERR("(%p) wined3d_buffer_create_vb failed with hr = %08x\n", device
, hr
);
1921 if (device
->vertex_buffer
)
1922 wined3d_buffer_decref(device
->vertex_buffer
);
1924 device
->vertex_buffer
= buffer
;
1925 device
->vertex_buffer_size
= size
;
1926 device
->vertex_buffer_pos
= 0;
1931 static HRESULT WINAPI
d3d8_device_DrawPrimitiveUP(IDirect3DDevice8
*iface
,
1932 D3DPRIMITIVETYPE primitive_type
, UINT primitive_count
, const void *data
,
1935 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
1937 UINT vtx_count
= vertex_count_from_primitive_count(primitive_type
, primitive_count
);
1938 UINT size
= vtx_count
* stride
;
1942 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
1943 iface
, primitive_type
, primitive_count
, data
, stride
);
1945 if (!primitive_count
)
1947 WARN("primitive_count is 0, returning D3D_OK\n");
1951 wined3d_mutex_lock();
1952 hr
= d3d8_device_prepare_vertex_buffer(device
, size
);
1956 vb_pos
= device
->vertex_buffer_pos
;
1957 align
= vb_pos
% stride
;
1958 if (align
) align
= stride
- align
;
1959 if (vb_pos
+ size
+ align
> device
->vertex_buffer_size
)
1964 hr
= wined3d_buffer_map(device
->vertex_buffer
, vb_pos
, size
, &buffer_data
,
1965 vb_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
);
1968 memcpy(buffer_data
, data
, size
);
1969 wined3d_buffer_unmap(device
->vertex_buffer
);
1970 device
->vertex_buffer_pos
= vb_pos
+ size
;
1972 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, 0, device
->vertex_buffer
, 0, stride
);
1976 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
1977 hr
= wined3d_device_draw_primitive(device
->wined3d_device
, vb_pos
/ stride
, vtx_count
);
1978 wined3d_device_set_stream_source(device
->wined3d_device
, 0, NULL
, 0, 0);
1981 wined3d_mutex_unlock();
1985 /* The caller is responsible for wined3d locking */
1986 static HRESULT
d3d8_device_prepare_index_buffer(struct d3d8_device
*device
, UINT min_size
)
1990 if (device
->index_buffer_size
< min_size
|| !device
->index_buffer
)
1992 UINT size
= max(device
->index_buffer_size
* 2, min_size
);
1993 struct wined3d_buffer
*buffer
;
1995 TRACE("Growing index buffer to %u bytes\n", size
);
1997 hr
= wined3d_buffer_create_ib(device
->wined3d_device
, size
, WINED3DUSAGE_DYNAMIC
| WINED3DUSAGE_WRITEONLY
,
1998 WINED3D_POOL_DEFAULT
, NULL
, &d3d8_null_wined3d_parent_ops
, &buffer
);
2001 ERR("(%p) wined3d_buffer_create_ib failed with hr = %08x\n", device
, hr
);
2005 if (device
->index_buffer
)
2006 wined3d_buffer_decref(device
->index_buffer
);
2008 device
->index_buffer
= buffer
;
2009 device
->index_buffer_size
= size
;
2010 device
->index_buffer_pos
= 0;
2015 static HRESULT WINAPI
d3d8_device_DrawIndexedPrimitiveUP(IDirect3DDevice8
*iface
,
2016 D3DPRIMITIVETYPE primitive_type
, UINT min_vertex_idx
, UINT vertex_count
,
2017 UINT primitive_count
, const void *index_data
, D3DFORMAT index_format
,
2018 const void *vertex_data
, UINT vertex_stride
)
2020 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2024 UINT idx_count
= vertex_count_from_primitive_count(primitive_type
, primitive_count
);
2025 UINT idx_fmt_size
= index_format
== D3DFMT_INDEX16
? 2 : 4;
2026 UINT idx_size
= idx_count
* idx_fmt_size
;
2029 UINT vtx_size
= vertex_count
* vertex_stride
;
2032 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, primitive_count %u,\n"
2033 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
2034 iface
, primitive_type
, min_vertex_idx
, vertex_count
, primitive_count
,
2035 index_data
, index_format
, vertex_data
, vertex_stride
);
2037 if (!primitive_count
)
2039 WARN("primitive_count is 0, returning D3D_OK\n");
2043 wined3d_mutex_lock();
2045 hr
= d3d8_device_prepare_vertex_buffer(device
, vtx_size
);
2049 vb_pos
= device
->vertex_buffer_pos
;
2050 align
= vb_pos
% vertex_stride
;
2051 if (align
) align
= vertex_stride
- align
;
2052 if (vb_pos
+ vtx_size
+ align
> device
->vertex_buffer_size
)
2057 hr
= wined3d_buffer_map(device
->vertex_buffer
, vb_pos
, vtx_size
, &buffer_data
,
2058 vb_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
);
2061 memcpy(buffer_data
, vertex_data
, vtx_size
);
2062 wined3d_buffer_unmap(device
->vertex_buffer
);
2063 device
->vertex_buffer_pos
= vb_pos
+ vtx_size
;
2065 hr
= d3d8_device_prepare_index_buffer(device
, idx_size
);
2069 ib_pos
= device
->index_buffer_pos
;
2070 align
= ib_pos
% idx_fmt_size
;
2071 if (align
) align
= idx_fmt_size
- align
;
2072 if (ib_pos
+ idx_size
+ align
> device
->index_buffer_size
)
2077 hr
= wined3d_buffer_map(device
->index_buffer
, ib_pos
, idx_size
, &buffer_data
,
2078 ib_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
);
2081 memcpy(buffer_data
, index_data
, idx_size
);
2082 wined3d_buffer_unmap(device
->index_buffer
);
2083 device
->index_buffer_pos
= ib_pos
+ idx_size
;
2085 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, 0, device
->vertex_buffer
, 0, vertex_stride
);
2089 wined3d_device_set_index_buffer(device
->wined3d_device
, device
->index_buffer
,
2090 wined3dformat_from_d3dformat(index_format
));
2091 wined3d_device_set_base_vertex_index(device
->wined3d_device
, vb_pos
/ vertex_stride
);
2093 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
2094 hr
= wined3d_device_draw_indexed_primitive(device
->wined3d_device
, ib_pos
/ idx_fmt_size
, idx_count
);
2096 wined3d_device_set_stream_source(device
->wined3d_device
, 0, NULL
, 0, 0);
2097 wined3d_device_set_index_buffer(device
->wined3d_device
, NULL
, WINED3DFMT_UNKNOWN
);
2098 wined3d_device_set_base_vertex_index(device
->wined3d_device
, 0);
2101 wined3d_mutex_unlock();
2105 static HRESULT WINAPI
d3d8_device_ProcessVertices(IDirect3DDevice8
*iface
, UINT src_start_idx
,
2106 UINT dst_idx
, UINT vertex_count
, IDirect3DVertexBuffer8
*dst_buffer
, DWORD flags
)
2108 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2109 struct d3d8_vertexbuffer
*dst
= unsafe_impl_from_IDirect3DVertexBuffer8(dst_buffer
);
2112 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, flags %#x.\n",
2113 iface
, src_start_idx
, dst_idx
, vertex_count
, dst_buffer
, flags
);
2115 wined3d_mutex_lock();
2116 hr
= wined3d_device_process_vertices(device
->wined3d_device
, src_start_idx
, dst_idx
,
2117 vertex_count
, dst
->wined3d_buffer
, NULL
, flags
, dst
->fvf
);
2118 wined3d_mutex_unlock();
2123 static HRESULT WINAPI
d3d8_device_CreateVertexShader(IDirect3DDevice8
*iface
,
2124 const DWORD
*declaration
, const DWORD
*byte_code
, DWORD
*shader
, DWORD usage
)
2126 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2127 struct d3d8_vertex_shader
*object
;
2128 DWORD shader_handle
;
2132 TRACE("iface %p, declaration %p, byte_code %p, shader %p, usage %#x.\n",
2133 iface
, declaration
, byte_code
, shader
, usage
);
2135 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2139 return E_OUTOFMEMORY
;
2142 wined3d_mutex_lock();
2143 handle
= d3d8_allocate_handle(&device
->handle_table
, object
, D3D8_HANDLE_VS
);
2144 wined3d_mutex_unlock();
2145 if (handle
== D3D8_INVALID_HANDLE
)
2147 ERR("Failed to allocate vertex shader handle.\n");
2148 HeapFree(GetProcessHeap(), 0, object
);
2150 return E_OUTOFMEMORY
;
2153 shader_handle
= handle
+ VS_HIGHESTFIXEDFXF
+ 1;
2155 hr
= d3d8_vertex_shader_init(object
, device
, declaration
, byte_code
, shader_handle
, usage
);
2158 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
2159 wined3d_mutex_lock();
2160 d3d8_free_handle(&device
->handle_table
, handle
, D3D8_HANDLE_VS
);
2161 wined3d_mutex_unlock();
2162 HeapFree(GetProcessHeap(), 0, object
);
2167 TRACE("Created vertex shader %p (handle %#x).\n", object
, shader_handle
);
2168 *shader
= shader_handle
;
2173 static struct d3d8_vertex_declaration
*d3d8_device_get_fvf_declaration(struct d3d8_device
*device
, DWORD fvf
)
2175 struct d3d8_vertex_declaration
*d3d8_declaration
;
2176 struct FvfToDecl
*convertedDecls
= device
->decls
;
2177 int p
, low
, high
; /* deliberately signed */
2180 TRACE("Searching for declaration for fvf %08x... ", fvf
);
2183 high
= device
->numConvertedDecls
- 1;
2186 p
= (low
+ high
) >> 1;
2189 if (convertedDecls
[p
].fvf
== fvf
)
2191 TRACE("found %p\n", convertedDecls
[p
].declaration
);
2192 return convertedDecls
[p
].declaration
;
2195 if (convertedDecls
[p
].fvf
< fvf
)
2200 TRACE("not found. Creating and inserting at position %d.\n", low
);
2202 if (!(d3d8_declaration
= HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration
))))
2205 if (FAILED(hr
= d3d8_vertex_declaration_init_fvf(d3d8_declaration
, device
, fvf
)))
2207 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr
);
2208 HeapFree(GetProcessHeap(), 0, d3d8_declaration
);
2212 if (device
->declArraySize
== device
->numConvertedDecls
)
2214 UINT grow
= device
->declArraySize
/ 2;
2216 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
2217 sizeof(*convertedDecls
) * (device
->numConvertedDecls
+ grow
));
2218 if (!convertedDecls
)
2220 d3d8_vertex_declaration_destroy(d3d8_declaration
);
2223 device
->decls
= convertedDecls
;
2224 device
->declArraySize
+= grow
;
2227 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
,
2228 sizeof(*convertedDecls
) * (device
->numConvertedDecls
- low
));
2229 convertedDecls
[low
].declaration
= d3d8_declaration
;
2230 convertedDecls
[low
].fvf
= fvf
;
2231 ++device
->numConvertedDecls
;
2233 TRACE("Returning %p. %u decls in array.\n", d3d8_declaration
, device
->numConvertedDecls
);
2235 return d3d8_declaration
;
2238 static HRESULT WINAPI
d3d8_device_SetVertexShader(IDirect3DDevice8
*iface
, DWORD shader
)
2240 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2241 struct d3d8_vertex_shader
*shader_impl
;
2243 TRACE("iface %p, shader %#x.\n", iface
, shader
);
2245 if (VS_HIGHESTFIXEDFXF
>= shader
)
2247 TRACE("Setting FVF, %#x\n", shader
);
2249 wined3d_mutex_lock();
2250 wined3d_device_set_vertex_declaration(device
->wined3d_device
,
2251 d3d8_device_get_fvf_declaration(device
, shader
)->wined3d_vertex_declaration
);
2252 wined3d_device_set_vertex_shader(device
->wined3d_device
, NULL
);
2253 wined3d_mutex_unlock();
2258 TRACE("Setting shader\n");
2260 wined3d_mutex_lock();
2261 if (!(shader_impl
= d3d8_get_object(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
)))
2263 WARN("Invalid handle (%#x) passed.\n", shader
);
2264 wined3d_mutex_unlock();
2266 return D3DERR_INVALIDCALL
;
2269 wined3d_device_set_vertex_declaration(device
->wined3d_device
,
2270 shader_impl
->vertex_declaration
->wined3d_vertex_declaration
);
2271 wined3d_device_set_vertex_shader(device
->wined3d_device
, shader_impl
->wined3d_shader
);
2272 wined3d_mutex_unlock();
2277 static HRESULT WINAPI
d3d8_device_GetVertexShader(IDirect3DDevice8
*iface
, DWORD
*shader
)
2279 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2280 struct wined3d_vertex_declaration
*wined3d_declaration
;
2281 struct d3d8_vertex_declaration
*d3d8_declaration
;
2283 TRACE("iface %p, shader %p.\n", iface
, shader
);
2285 wined3d_mutex_lock();
2286 if ((wined3d_declaration
= wined3d_device_get_vertex_declaration(device
->wined3d_device
)))
2288 d3d8_declaration
= wined3d_vertex_declaration_get_parent(wined3d_declaration
);
2289 *shader
= d3d8_declaration
->shader_handle
;
2295 wined3d_mutex_unlock();
2297 TRACE("Returning %#x.\n", *shader
);
2302 static HRESULT WINAPI
d3d8_device_DeleteVertexShader(IDirect3DDevice8
*iface
, DWORD shader
)
2304 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2305 struct d3d8_vertex_shader
*shader_impl
;
2307 TRACE("iface %p, shader %#x.\n", iface
, shader
);
2309 wined3d_mutex_lock();
2310 if (!(shader_impl
= d3d8_free_handle(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
)))
2312 WARN("Invalid handle (%#x) passed.\n", shader
);
2313 wined3d_mutex_unlock();
2315 return D3DERR_INVALIDCALL
;
2318 if (shader_impl
->wined3d_shader
2319 && wined3d_device_get_vertex_shader(device
->wined3d_device
) == shader_impl
->wined3d_shader
)
2320 IDirect3DDevice8_SetVertexShader(iface
, 0);
2322 wined3d_mutex_unlock();
2324 d3d8_vertex_shader_destroy(shader_impl
);
2329 static HRESULT WINAPI
d3d8_device_SetVertexShaderConstant(IDirect3DDevice8
*iface
,
2330 DWORD start_register
, const void *data
, DWORD count
)
2332 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2335 TRACE("iface %p, start_register %u, data %p, count %u.\n",
2336 iface
, start_register
, data
, count
);
2338 if (start_register
+ count
> D3D8_MAX_VERTEX_SHADER_CONSTANTF
)
2340 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2341 start_register
+ count
, D3D8_MAX_VERTEX_SHADER_CONSTANTF
);
2342 return D3DERR_INVALIDCALL
;
2345 wined3d_mutex_lock();
2346 hr
= wined3d_device_set_vs_consts_f(device
->wined3d_device
, start_register
, data
, count
);
2347 wined3d_mutex_unlock();
2352 static HRESULT WINAPI
d3d8_device_GetVertexShaderConstant(IDirect3DDevice8
*iface
,
2353 DWORD start_register
, void *data
, DWORD count
)
2355 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2358 TRACE("iface %p, start_register %u, data %p, count %u.\n",
2359 iface
, start_register
, data
, count
);
2361 if (start_register
+ count
> D3D8_MAX_VERTEX_SHADER_CONSTANTF
)
2363 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2364 start_register
+ count
, D3D8_MAX_VERTEX_SHADER_CONSTANTF
);
2365 return D3DERR_INVALIDCALL
;
2368 wined3d_mutex_lock();
2369 hr
= wined3d_device_get_vs_consts_f(device
->wined3d_device
, start_register
, data
, count
);
2370 wined3d_mutex_unlock();
2375 static HRESULT WINAPI
d3d8_device_GetVertexShaderDeclaration(IDirect3DDevice8
*iface
,
2376 DWORD shader
, void *data
, DWORD
*data_size
)
2378 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2379 struct d3d8_vertex_declaration
*declaration
;
2380 struct d3d8_vertex_shader
*shader_impl
;
2382 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2383 iface
, shader
, data
, data_size
);
2385 wined3d_mutex_lock();
2386 shader_impl
= d3d8_get_object(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
);
2387 wined3d_mutex_unlock();
2391 WARN("Invalid handle (%#x) passed.\n", shader
);
2392 return D3DERR_INVALIDCALL
;
2394 declaration
= shader_impl
->vertex_declaration
;
2398 *data_size
= declaration
->elements_size
;
2402 /* MSDN claims that if *data_size is smaller than the required size
2403 * we should write the required size and return D3DERR_MOREDATA.
2404 * That's not actually true. */
2405 if (*data_size
< declaration
->elements_size
)
2406 return D3DERR_INVALIDCALL
;
2408 memcpy(data
, declaration
->elements
, declaration
->elements_size
);
2413 static HRESULT WINAPI
d3d8_device_GetVertexShaderFunction(IDirect3DDevice8
*iface
,
2414 DWORD shader
, void *data
, DWORD
*data_size
)
2416 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2417 struct d3d8_vertex_shader
*shader_impl
= NULL
;
2420 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2421 iface
, shader
, data
, data_size
);
2423 wined3d_mutex_lock();
2424 if (!(shader_impl
= d3d8_get_object(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
)))
2426 WARN("Invalid handle (%#x) passed.\n", shader
);
2427 wined3d_mutex_unlock();
2429 return D3DERR_INVALIDCALL
;
2432 if (!shader_impl
->wined3d_shader
)
2434 wined3d_mutex_unlock();
2439 hr
= wined3d_shader_get_byte_code(shader_impl
->wined3d_shader
, data
, data_size
);
2440 wined3d_mutex_unlock();
2445 static HRESULT WINAPI
d3d8_device_SetIndices(IDirect3DDevice8
*iface
,
2446 IDirect3DIndexBuffer8
*buffer
, UINT base_vertex_idx
)
2448 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2449 struct d3d8_indexbuffer
*ib
= unsafe_impl_from_IDirect3DIndexBuffer8(buffer
);
2451 TRACE("iface %p, buffer %p, base_vertex_idx %u.\n", iface
, buffer
, base_vertex_idx
);
2453 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
2454 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
2455 * vertex buffers can't be created to address them with an index that requires the 32nd bit
2456 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
2459 wined3d_mutex_lock();
2460 wined3d_device_set_base_vertex_index(device
->wined3d_device
, base_vertex_idx
);
2461 wined3d_device_set_index_buffer(device
->wined3d_device
,
2462 ib
? ib
->wined3d_buffer
: NULL
,
2463 ib
? ib
->format
: WINED3DFMT_UNKNOWN
);
2464 wined3d_mutex_unlock();
2469 static HRESULT WINAPI
d3d8_device_GetIndices(IDirect3DDevice8
*iface
,
2470 IDirect3DIndexBuffer8
**buffer
, UINT
*base_vertex_index
)
2472 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2473 enum wined3d_format_id wined3d_format
;
2474 struct wined3d_buffer
*wined3d_buffer
;
2475 struct d3d8_indexbuffer
*buffer_impl
;
2477 TRACE("iface %p, buffer %p, base_vertex_index %p.\n", iface
, buffer
, base_vertex_index
);
2480 return D3DERR_INVALIDCALL
;
2482 /* The case from UINT to INT is safe because d3d8 will never set negative values */
2483 wined3d_mutex_lock();
2484 *base_vertex_index
= wined3d_device_get_base_vertex_index(device
->wined3d_device
);
2485 if ((wined3d_buffer
= wined3d_device_get_index_buffer(device
->wined3d_device
, &wined3d_format
)))
2487 buffer_impl
= wined3d_buffer_get_parent(wined3d_buffer
);
2488 *buffer
= &buffer_impl
->IDirect3DIndexBuffer8_iface
;
2489 IDirect3DIndexBuffer8_AddRef(*buffer
);
2495 wined3d_mutex_unlock();
2500 static HRESULT WINAPI
d3d8_device_CreatePixelShader(IDirect3DDevice8
*iface
,
2501 const DWORD
*byte_code
, DWORD
*shader
)
2503 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2504 struct d3d8_pixel_shader
*object
;
2505 DWORD shader_handle
;
2509 TRACE("iface %p, byte_code %p, shader %p.\n", iface
, byte_code
, shader
);
2512 return D3DERR_INVALIDCALL
;
2514 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2516 return E_OUTOFMEMORY
;
2518 wined3d_mutex_lock();
2519 handle
= d3d8_allocate_handle(&device
->handle_table
, object
, D3D8_HANDLE_PS
);
2520 wined3d_mutex_unlock();
2521 if (handle
== D3D8_INVALID_HANDLE
)
2523 ERR("Failed to allocate pixel shader handle.\n");
2524 HeapFree(GetProcessHeap(), 0, object
);
2525 return E_OUTOFMEMORY
;
2528 shader_handle
= handle
+ VS_HIGHESTFIXEDFXF
+ 1;
2530 hr
= d3d8_pixel_shader_init(object
, device
, byte_code
, shader_handle
);
2533 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
2534 wined3d_mutex_lock();
2535 d3d8_free_handle(&device
->handle_table
, handle
, D3D8_HANDLE_PS
);
2536 wined3d_mutex_unlock();
2537 HeapFree(GetProcessHeap(), 0, object
);
2542 TRACE("Created pixel shader %p (handle %#x).\n", object
, shader_handle
);
2543 *shader
= shader_handle
;
2548 static HRESULT WINAPI
d3d8_device_SetPixelShader(IDirect3DDevice8
*iface
, DWORD shader
)
2550 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2551 struct d3d8_pixel_shader
*shader_impl
;
2553 TRACE("iface %p, shader %#x.\n", iface
, shader
);
2555 wined3d_mutex_lock();
2559 wined3d_device_set_pixel_shader(device
->wined3d_device
, NULL
);
2560 wined3d_mutex_unlock();
2564 if (!(shader_impl
= d3d8_get_object(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
)))
2566 WARN("Invalid handle (%#x) passed.\n", shader
);
2567 wined3d_mutex_unlock();
2568 return D3DERR_INVALIDCALL
;
2571 TRACE("Setting shader %p.\n", shader_impl
);
2572 wined3d_device_set_pixel_shader(device
->wined3d_device
, shader_impl
->wined3d_shader
);
2573 wined3d_mutex_unlock();
2578 static HRESULT WINAPI
d3d8_device_GetPixelShader(IDirect3DDevice8
*iface
, DWORD
*shader
)
2580 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2581 struct wined3d_shader
*object
;
2583 TRACE("iface %p, shader %p.\n", iface
, shader
);
2586 return D3DERR_INVALIDCALL
;
2588 wined3d_mutex_lock();
2589 if ((object
= wined3d_device_get_pixel_shader(device
->wined3d_device
)))
2591 struct d3d8_pixel_shader
*d3d8_shader
;
2592 d3d8_shader
= wined3d_shader_get_parent(object
);
2593 *shader
= d3d8_shader
->handle
;
2599 wined3d_mutex_unlock();
2601 TRACE("Returning %#x.\n", *shader
);
2606 static HRESULT WINAPI
d3d8_device_DeletePixelShader(IDirect3DDevice8
*iface
, DWORD shader
)
2608 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2609 struct d3d8_pixel_shader
*shader_impl
;
2611 TRACE("iface %p, shader %#x.\n", iface
, shader
);
2613 wined3d_mutex_lock();
2615 if (!(shader_impl
= d3d8_free_handle(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
)))
2617 WARN("Invalid handle (%#x) passed.\n", shader
);
2618 wined3d_mutex_unlock();
2619 return D3DERR_INVALIDCALL
;
2622 if (wined3d_device_get_pixel_shader(device
->wined3d_device
) == shader_impl
->wined3d_shader
)
2623 IDirect3DDevice8_SetPixelShader(iface
, 0);
2625 wined3d_mutex_unlock();
2627 d3d8_pixel_shader_destroy(shader_impl
);
2632 static HRESULT WINAPI
d3d8_device_SetPixelShaderConstant(IDirect3DDevice8
*iface
,
2633 DWORD start_register
, const void *data
, DWORD count
)
2635 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2638 TRACE("iface %p, start_register %u, data %p, count %u.\n",
2639 iface
, start_register
, data
, count
);
2641 wined3d_mutex_lock();
2642 hr
= wined3d_device_set_ps_consts_f(device
->wined3d_device
, start_register
, data
, count
);
2643 wined3d_mutex_unlock();
2648 static HRESULT WINAPI
d3d8_device_GetPixelShaderConstant(IDirect3DDevice8
*iface
,
2649 DWORD start_register
, void *data
, DWORD count
)
2651 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2654 TRACE("iface %p, start_register %u, data %p, count %u.\n",
2655 iface
, start_register
, data
, count
);
2657 wined3d_mutex_lock();
2658 hr
= wined3d_device_get_ps_consts_f(device
->wined3d_device
, start_register
, data
, count
);
2659 wined3d_mutex_unlock();
2664 static HRESULT WINAPI
d3d8_device_GetPixelShaderFunction(IDirect3DDevice8
*iface
,
2665 DWORD shader
, void *data
, DWORD
*data_size
)
2667 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2668 struct d3d8_pixel_shader
*shader_impl
= NULL
;
2671 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2672 iface
, shader
, data
, data_size
);
2674 wined3d_mutex_lock();
2675 if (!(shader_impl
= d3d8_get_object(&device
->handle_table
, shader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
)))
2677 WARN("Invalid handle (%#x) passed.\n", shader
);
2678 wined3d_mutex_unlock();
2680 return D3DERR_INVALIDCALL
;
2683 hr
= wined3d_shader_get_byte_code(shader_impl
->wined3d_shader
, data
, data_size
);
2684 wined3d_mutex_unlock();
2689 static HRESULT WINAPI
d3d8_device_DrawRectPatch(IDirect3DDevice8
*iface
, UINT handle
,
2690 const float *segment_count
, const D3DRECTPATCH_INFO
*patch_info
)
2692 FIXME("iface %p, handle %#x, segment_count %p, patch_info %p unimplemented.\n",
2693 iface
, handle
, segment_count
, patch_info
);
2697 static HRESULT WINAPI
d3d8_device_DrawTriPatch(IDirect3DDevice8
*iface
, UINT handle
,
2698 const float *segment_count
, const D3DTRIPATCH_INFO
*patch_info
)
2700 FIXME("iface %p, handle %#x, segment_count %p, patch_info %p unimplemented.\n",
2701 iface
, handle
, segment_count
, patch_info
);
2705 static HRESULT WINAPI
d3d8_device_DeletePatch(IDirect3DDevice8
*iface
, UINT handle
)
2707 FIXME("iface %p, handle %#x unimplemented.\n", iface
, handle
);
2708 return D3DERR_INVALIDCALL
;
2711 static HRESULT WINAPI
d3d8_device_SetStreamSource(IDirect3DDevice8
*iface
,
2712 UINT stream_idx
, IDirect3DVertexBuffer8
*buffer
, UINT stride
)
2714 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2715 struct d3d8_vertexbuffer
*buffer_impl
= unsafe_impl_from_IDirect3DVertexBuffer8(buffer
);
2718 TRACE("iface %p, stream_idx %u, buffer %p, stride %u.\n",
2719 iface
, stream_idx
, buffer
, stride
);
2721 wined3d_mutex_lock();
2722 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, stream_idx
,
2723 buffer_impl
? buffer_impl
->wined3d_buffer
: NULL
, 0, stride
);
2724 wined3d_mutex_unlock();
2729 static HRESULT WINAPI
d3d8_device_GetStreamSource(IDirect3DDevice8
*iface
,
2730 UINT stream_idx
, IDirect3DVertexBuffer8
**buffer
, UINT
*stride
)
2732 struct d3d8_device
*device
= impl_from_IDirect3DDevice8(iface
);
2733 struct d3d8_vertexbuffer
*buffer_impl
;
2734 struct wined3d_buffer
*wined3d_buffer
= NULL
;
2737 TRACE("iface %p, stream_idx %u, buffer %p, stride %p.\n",
2738 iface
, stream_idx
, buffer
, stride
);
2741 return D3DERR_INVALIDCALL
;
2743 wined3d_mutex_lock();
2744 hr
= wined3d_device_get_stream_source(device
->wined3d_device
, stream_idx
, &wined3d_buffer
, 0, stride
);
2745 if (SUCCEEDED(hr
) && wined3d_buffer
)
2747 buffer_impl
= wined3d_buffer_get_parent(wined3d_buffer
);
2748 *buffer
= &buffer_impl
->IDirect3DVertexBuffer8_iface
;
2749 IDirect3DVertexBuffer8_AddRef(*buffer
);
2750 wined3d_buffer_decref(wined3d_buffer
);
2755 ERR("Failed to get wined3d stream source, hr %#x.\n", hr
);
2758 wined3d_mutex_unlock();
2763 static const struct IDirect3DDevice8Vtbl d3d8_device_vtbl
=
2765 d3d8_device_QueryInterface
,
2767 d3d8_device_Release
,
2768 d3d8_device_TestCooperativeLevel
,
2769 d3d8_device_GetAvailableTextureMem
,
2770 d3d8_device_ResourceManagerDiscardBytes
,
2771 d3d8_device_GetDirect3D
,
2772 d3d8_device_GetDeviceCaps
,
2773 d3d8_device_GetDisplayMode
,
2774 d3d8_device_GetCreationParameters
,
2775 d3d8_device_SetCursorProperties
,
2776 d3d8_device_SetCursorPosition
,
2777 d3d8_device_ShowCursor
,
2778 d3d8_device_CreateAdditionalSwapChain
,
2780 d3d8_device_Present
,
2781 d3d8_device_GetBackBuffer
,
2782 d3d8_device_GetRasterStatus
,
2783 d3d8_device_SetGammaRamp
,
2784 d3d8_device_GetGammaRamp
,
2785 d3d8_device_CreateTexture
,
2786 d3d8_device_CreateVolumeTexture
,
2787 d3d8_device_CreateCubeTexture
,
2788 d3d8_device_CreateVertexBuffer
,
2789 d3d8_device_CreateIndexBuffer
,
2790 d3d8_device_CreateRenderTarget
,
2791 d3d8_device_CreateDepthStencilSurface
,
2792 d3d8_device_CreateImageSurface
,
2793 d3d8_device_CopyRects
,
2794 d3d8_device_UpdateTexture
,
2795 d3d8_device_GetFrontBuffer
,
2796 d3d8_device_SetRenderTarget
,
2797 d3d8_device_GetRenderTarget
,
2798 d3d8_device_GetDepthStencilSurface
,
2799 d3d8_device_BeginScene
,
2800 d3d8_device_EndScene
,
2802 d3d8_device_SetTransform
,
2803 d3d8_device_GetTransform
,
2804 d3d8_device_MultiplyTransform
,
2805 d3d8_device_SetViewport
,
2806 d3d8_device_GetViewport
,
2807 d3d8_device_SetMaterial
,
2808 d3d8_device_GetMaterial
,
2809 d3d8_device_SetLight
,
2810 d3d8_device_GetLight
,
2811 d3d8_device_LightEnable
,
2812 d3d8_device_GetLightEnable
,
2813 d3d8_device_SetClipPlane
,
2814 d3d8_device_GetClipPlane
,
2815 d3d8_device_SetRenderState
,
2816 d3d8_device_GetRenderState
,
2817 d3d8_device_BeginStateBlock
,
2818 d3d8_device_EndStateBlock
,
2819 d3d8_device_ApplyStateBlock
,
2820 d3d8_device_CaptureStateBlock
,
2821 d3d8_device_DeleteStateBlock
,
2822 d3d8_device_CreateStateBlock
,
2823 d3d8_device_SetClipStatus
,
2824 d3d8_device_GetClipStatus
,
2825 d3d8_device_GetTexture
,
2826 d3d8_device_SetTexture
,
2827 d3d8_device_GetTextureStageState
,
2828 d3d8_device_SetTextureStageState
,
2829 d3d8_device_ValidateDevice
,
2830 d3d8_device_GetInfo
,
2831 d3d8_device_SetPaletteEntries
,
2832 d3d8_device_GetPaletteEntries
,
2833 d3d8_device_SetCurrentTexturePalette
,
2834 d3d8_device_GetCurrentTexturePalette
,
2835 d3d8_device_DrawPrimitive
,
2836 d3d8_device_DrawIndexedPrimitive
,
2837 d3d8_device_DrawPrimitiveUP
,
2838 d3d8_device_DrawIndexedPrimitiveUP
,
2839 d3d8_device_ProcessVertices
,
2840 d3d8_device_CreateVertexShader
,
2841 d3d8_device_SetVertexShader
,
2842 d3d8_device_GetVertexShader
,
2843 d3d8_device_DeleteVertexShader
,
2844 d3d8_device_SetVertexShaderConstant
,
2845 d3d8_device_GetVertexShaderConstant
,
2846 d3d8_device_GetVertexShaderDeclaration
,
2847 d3d8_device_GetVertexShaderFunction
,
2848 d3d8_device_SetStreamSource
,
2849 d3d8_device_GetStreamSource
,
2850 d3d8_device_SetIndices
,
2851 d3d8_device_GetIndices
,
2852 d3d8_device_CreatePixelShader
,
2853 d3d8_device_SetPixelShader
,
2854 d3d8_device_GetPixelShader
,
2855 d3d8_device_DeletePixelShader
,
2856 d3d8_device_SetPixelShaderConstant
,
2857 d3d8_device_GetPixelShaderConstant
,
2858 d3d8_device_GetPixelShaderFunction
,
2859 d3d8_device_DrawRectPatch
,
2860 d3d8_device_DrawTriPatch
,
2861 d3d8_device_DeletePatch
,
2864 static inline struct d3d8_device
*device_from_device_parent(struct wined3d_device_parent
*device_parent
)
2866 return CONTAINING_RECORD(device_parent
, struct d3d8_device
, device_parent
);
2869 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
2870 struct wined3d_device
*device
)
2872 TRACE("device_parent %p, device %p\n", device_parent
, device
);
2875 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
2877 TRACE("device_parent %p.\n", device_parent
);
2880 static HRESULT CDECL
device_parent_create_texture_surface(struct wined3d_device_parent
*device_parent
,
2881 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
, DWORD usage
,
2882 enum wined3d_pool pool
, UINT sub_resource_idx
, struct wined3d_surface
**surface
)
2884 struct d3d8_device
*device
= device_from_device_parent(device_parent
);
2885 struct d3d8_surface
*d3d_surface
;
2886 BOOL lockable
= TRUE
;
2889 TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
2890 "\tpool %#x, sub_resource_idx %u, surface %p.\n",
2891 device_parent
, container_parent
, width
, height
, format
, usage
, pool
, sub_resource_idx
, surface
);
2894 if (pool
== WINED3D_POOL_DEFAULT
&& !(usage
& WINED3DUSAGE_DYNAMIC
))
2897 if (FAILED(hr
= d3d8_device_create_surface(device
, width
, height
, d3dformat_from_wined3dformat(format
),
2898 lockable
, FALSE
, (IDirect3DSurface8
**)&d3d_surface
, usage
, pool
, D3DMULTISAMPLE_NONE
, 0)))
2900 WARN("Failed to create surface, hr %#x.\n", hr
);
2904 *surface
= d3d_surface
->wined3d_surface
;
2905 wined3d_surface_incref(*surface
);
2907 d3d_surface
->container
= container_parent
;
2908 IDirect3DDevice8_Release(d3d_surface
->parent_device
);
2909 d3d_surface
->parent_device
= NULL
;
2911 IDirect3DSurface8_Release(&d3d_surface
->IDirect3DSurface8_iface
);
2912 d3d_surface
->forwardReference
= container_parent
;
2917 static HRESULT CDECL
device_parent_create_swapchain_surface(struct wined3d_device_parent
*device_parent
,
2918 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format_id
, DWORD usage
,
2919 enum wined3d_multisample_type multisample_type
, DWORD multisample_quality
, struct wined3d_surface
**surface
)
2921 struct d3d8_device
*device
= device_from_device_parent(device_parent
);
2922 struct d3d8_surface
*d3d_surface
;
2925 TRACE("device_parent %p, container_parent %p, width %u, height %u, format_id %#x, usage %#x,\n"
2926 "\tmultisample_type %#x, multisample_quality %u, surface %p.\n",
2927 device_parent
, container_parent
, width
, height
, format_id
, usage
,
2928 multisample_type
, multisample_quality
, surface
);
2930 if (FAILED(hr
= d3d8_device_create_surface(device
, width
, height
, d3dformat_from_wined3dformat(format_id
),
2931 TRUE
, FALSE
, (IDirect3DSurface8
**)&d3d_surface
, usage
, D3DPOOL_DEFAULT
, multisample_type
,
2932 multisample_quality
)))
2934 WARN("Failed to create surface, hr %#x.\n", hr
);
2938 *surface
= d3d_surface
->wined3d_surface
;
2939 wined3d_surface_incref(*surface
);
2941 d3d_surface
->container
= (IUnknown
*)&device
->IDirect3DDevice8_iface
;
2942 /* Implicit surfaces are created with an refcount of 0 */
2943 IDirect3DSurface8_Release(&d3d_surface
->IDirect3DSurface8_iface
);
2948 static HRESULT CDECL
device_parent_create_volume(struct wined3d_device_parent
*device_parent
,
2949 void *container_parent
, UINT width
, UINT height
, UINT depth
, enum wined3d_format_id format
,
2950 enum wined3d_pool pool
, DWORD usage
, struct wined3d_volume
**volume
)
2952 struct d3d8_device
*device
= device_from_device_parent(device_parent
);
2953 struct d3d8_volume
*object
;
2956 TRACE("device_parent %p, container_parent %p, width %u, height %u, depth %u, "
2957 "format %#x, pool %#x, usage %#x, volume %p.\n",
2958 device_parent
, container_parent
, width
, height
, depth
,
2959 format
, pool
, usage
, volume
);
2961 /* Allocate the storage for the device */
2962 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2965 FIXME("Allocation of memory failed\n");
2967 return D3DERR_OUTOFVIDEOMEMORY
;
2970 hr
= volume_init(object
, device
, width
, height
, depth
, usage
, format
, pool
);
2973 WARN("Failed to initialize volume, hr %#x.\n", hr
);
2974 HeapFree(GetProcessHeap(), 0, object
);
2978 *volume
= object
->wined3d_volume
;
2979 wined3d_volume_incref(*volume
);
2980 IDirect3DVolume8_Release(&object
->IDirect3DVolume8_iface
);
2982 object
->container
= container_parent
;
2983 object
->forwardReference
= container_parent
;
2985 TRACE("Created volume %p.\n", object
);
2990 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
2991 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain
**swapchain
)
2993 struct d3d8_device
*device
= device_from_device_parent(device_parent
);
2994 struct d3d8_swapchain
*d3d_swapchain
;
2997 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent
, desc
, swapchain
);
2999 if (FAILED(hr
= d3d8_swapchain_create(device
, desc
, &d3d_swapchain
)))
3001 WARN("Failed to create swapchain, hr %#x.\n", hr
);
3006 *swapchain
= d3d_swapchain
->wined3d_swapchain
;
3007 wined3d_swapchain_incref(*swapchain
);
3008 IDirect3DSwapChain8_Release(&d3d_swapchain
->IDirect3DSwapChain8_iface
);
3013 static const struct wined3d_device_parent_ops d3d8_wined3d_device_parent_ops
=
3015 device_parent_wined3d_device_created
,
3016 device_parent_mode_changed
,
3017 device_parent_create_swapchain_surface
,
3018 device_parent_create_texture_surface
,
3019 device_parent_create_volume
,
3020 device_parent_create_swapchain
,
3023 static void setup_fpu(void)
3025 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3027 __asm__
volatile ("fnstcw %0" : "=m" (cw
));
3028 cw
= (cw
& ~0xf3f) | 0x3f;
3029 __asm__
volatile ("fldcw %0" : : "m" (cw
));
3030 #elif defined(__i386__) && defined(_MSC_VER)
3033 cw
= (cw
& ~0xf3f) | 0x3f;
3036 FIXME("FPU setup not implemented for this platform.\n");
3040 HRESULT
device_init(struct d3d8_device
*device
, struct d3d8
*parent
, struct wined3d
*wined3d
, UINT adapter
,
3041 D3DDEVTYPE device_type
, HWND focus_window
, DWORD flags
, D3DPRESENT_PARAMETERS
*parameters
)
3043 struct wined3d_swapchain_desc swapchain_desc
;
3046 device
->IDirect3DDevice8_iface
.lpVtbl
= &d3d8_device_vtbl
;
3047 device
->device_parent
.ops
= &d3d8_wined3d_device_parent_ops
;
3049 device
->handle_table
.entries
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
3050 D3D8_INITIAL_HANDLE_TABLE_SIZE
* sizeof(*device
->handle_table
.entries
));
3051 if (!device
->handle_table
.entries
)
3053 ERR("Failed to allocate handle table memory.\n");
3054 return E_OUTOFMEMORY
;
3056 device
->handle_table
.table_size
= D3D8_INITIAL_HANDLE_TABLE_SIZE
;
3058 if (!(flags
& D3DCREATE_FPU_PRESERVE
)) setup_fpu();
3060 wined3d_mutex_lock();
3061 hr
= wined3d_device_create(wined3d
, adapter
, device_type
, focus_window
, flags
, 4,
3062 &device
->device_parent
, &device
->wined3d_device
);
3065 WARN("Failed to create wined3d device, hr %#x.\n", hr
);
3066 wined3d_mutex_unlock();
3067 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
3071 if (!parameters
->Windowed
)
3073 HWND device_window
= parameters
->hDeviceWindow
;
3076 focus_window
= device_window
;
3077 if (FAILED(hr
= wined3d_device_acquire_focus_window(device
->wined3d_device
, focus_window
)))
3079 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
3080 wined3d_device_decref(device
->wined3d_device
);
3081 wined3d_mutex_unlock();
3082 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
3087 device_window
= focus_window
;
3088 wined3d_device_setup_fullscreen_window(device
->wined3d_device
, device_window
,
3089 parameters
->BackBufferWidth
,
3090 parameters
->BackBufferHeight
);
3093 if (flags
& D3DCREATE_MULTITHREADED
)
3094 wined3d_device_set_multithreaded(device
->wined3d_device
);
3096 wined3d_swapchain_desc_from_present_parameters(&swapchain_desc
, parameters
);
3098 hr
= wined3d_device_init_3d(device
->wined3d_device
, &swapchain_desc
);
3101 WARN("Failed to initialize 3D, hr %#x.\n", hr
);
3102 wined3d_device_release_focus_window(device
->wined3d_device
);
3103 wined3d_device_decref(device
->wined3d_device
);
3104 wined3d_mutex_unlock();
3105 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
3109 wined3d_device_set_render_state(device
->wined3d_device
, WINED3D_RS_POINTSIZE_MIN
, 0);
3110 wined3d_mutex_unlock();
3112 present_parameters_from_wined3d_swapchain_desc(parameters
, &swapchain_desc
);
3114 device
->declArraySize
= 16;
3115 device
->decls
= HeapAlloc(GetProcessHeap(), 0, device
->declArraySize
* sizeof(*device
->decls
));
3118 ERR("Failed to allocate FVF vertex declaration map memory.\n");
3123 device
->d3d_parent
= &parent
->IDirect3D8_iface
;
3124 IDirect3D8_AddRef(device
->d3d_parent
);
3129 wined3d_mutex_lock();
3130 wined3d_device_uninit_3d(device
->wined3d_device
);
3131 wined3d_device_release_focus_window(device
->wined3d_device
);
3132 wined3d_device_decref(device
->wined3d_device
);
3133 wined3d_mutex_unlock();
3134 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);