2 * IDirect3DDevice8 implementation
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2004 Christian Costa
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
33 #include "wine/debug.h"
35 #include "d3d8_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
39 D3DFORMAT d3dformat_from_wined3dformat(enum wined3d_format_id format)
41 BYTE *c = (BYTE *)&format;
43 /* Don't translate FOURCC formats */
44 if (isprint(c[0]) && isprint(c[1]) && isprint(c[2]) && isprint(c[3])) return format;
48 case WINED3DFMT_UNKNOWN: return D3DFMT_UNKNOWN;
49 case WINED3DFMT_B8G8R8_UNORM: return D3DFMT_R8G8B8;
50 case WINED3DFMT_B8G8R8A8_UNORM: return D3DFMT_A8R8G8B8;
51 case WINED3DFMT_B8G8R8X8_UNORM: return D3DFMT_X8R8G8B8;
52 case WINED3DFMT_B5G6R5_UNORM: return D3DFMT_R5G6B5;
53 case WINED3DFMT_B5G5R5X1_UNORM: return D3DFMT_X1R5G5B5;
54 case WINED3DFMT_B5G5R5A1_UNORM: return D3DFMT_A1R5G5B5;
55 case WINED3DFMT_B4G4R4A4_UNORM: return D3DFMT_A4R4G4B4;
56 case WINED3DFMT_B2G3R3_UNORM: return D3DFMT_R3G3B2;
57 case WINED3DFMT_A8_UNORM: return D3DFMT_A8;
58 case WINED3DFMT_B2G3R3A8_UNORM: return D3DFMT_A8R3G3B2;
59 case WINED3DFMT_B4G4R4X4_UNORM: return D3DFMT_X4R4G4B4;
60 case WINED3DFMT_R10G10B10A2_UNORM: return D3DFMT_A2B10G10R10;
61 case WINED3DFMT_R16G16_UNORM: return D3DFMT_G16R16;
62 case WINED3DFMT_P8_UINT_A8_UNORM: return D3DFMT_A8P8;
63 case WINED3DFMT_P8_UINT: return D3DFMT_P8;
64 case WINED3DFMT_L8_UNORM: return D3DFMT_L8;
65 case WINED3DFMT_L8A8_UNORM: return D3DFMT_A8L8;
66 case WINED3DFMT_L4A4_UNORM: return D3DFMT_A4L4;
67 case WINED3DFMT_R8G8_SNORM: return D3DFMT_V8U8;
68 case WINED3DFMT_R5G5_SNORM_L6_UNORM: return D3DFMT_L6V5U5;
69 case WINED3DFMT_R8G8_SNORM_L8X8_UNORM: return D3DFMT_X8L8V8U8;
70 case WINED3DFMT_R8G8B8A8_SNORM: return D3DFMT_Q8W8V8U8;
71 case WINED3DFMT_R16G16_SNORM: return D3DFMT_V16U16;
72 case WINED3DFMT_R10G11B11_SNORM: return D3DFMT_W11V11U10;
73 case WINED3DFMT_R10G10B10_SNORM_A2_UNORM: return D3DFMT_A2W10V10U10;
74 case WINED3DFMT_D16_LOCKABLE: return D3DFMT_D16_LOCKABLE;
75 case WINED3DFMT_D32_UNORM: return D3DFMT_D32;
76 case WINED3DFMT_S1_UINT_D15_UNORM: return D3DFMT_D15S1;
77 case WINED3DFMT_D24_UNORM_S8_UINT: return D3DFMT_D24S8;
78 case WINED3DFMT_X8D24_UNORM: return D3DFMT_D24X8;
79 case WINED3DFMT_S4X4_UINT_D24_UNORM: return D3DFMT_D24X4S4;
80 case WINED3DFMT_D16_UNORM: return D3DFMT_D16;
81 case WINED3DFMT_VERTEXDATA: return D3DFMT_VERTEXDATA;
82 case WINED3DFMT_R16_UINT: return D3DFMT_INDEX16;
83 case WINED3DFMT_R32_UINT: return D3DFMT_INDEX32;
85 FIXME("Unhandled wined3d format %#x.\n", format);
86 return D3DFMT_UNKNOWN;
90 enum wined3d_format_id wined3dformat_from_d3dformat(D3DFORMAT format)
92 BYTE *c = (BYTE *)&format;
94 /* Don't translate FOURCC formats */
95 if (isprint(c[0]) && isprint(c[1]) && isprint(c[2]) && isprint(c[3])) return format;
99 case D3DFMT_UNKNOWN: return WINED3DFMT_UNKNOWN;
100 case D3DFMT_R8G8B8: return WINED3DFMT_B8G8R8_UNORM;
101 case D3DFMT_A8R8G8B8: return WINED3DFMT_B8G8R8A8_UNORM;
102 case D3DFMT_X8R8G8B8: return WINED3DFMT_B8G8R8X8_UNORM;
103 case D3DFMT_R5G6B5: return WINED3DFMT_B5G6R5_UNORM;
104 case D3DFMT_X1R5G5B5: return WINED3DFMT_B5G5R5X1_UNORM;
105 case D3DFMT_A1R5G5B5: return WINED3DFMT_B5G5R5A1_UNORM;
106 case D3DFMT_A4R4G4B4: return WINED3DFMT_B4G4R4A4_UNORM;
107 case D3DFMT_R3G3B2: return WINED3DFMT_B2G3R3_UNORM;
108 case D3DFMT_A8: return WINED3DFMT_A8_UNORM;
109 case D3DFMT_A8R3G3B2: return WINED3DFMT_B2G3R3A8_UNORM;
110 case D3DFMT_X4R4G4B4: return WINED3DFMT_B4G4R4X4_UNORM;
111 case D3DFMT_A2B10G10R10: return WINED3DFMT_R10G10B10A2_UNORM;
112 case D3DFMT_G16R16: return WINED3DFMT_R16G16_UNORM;
113 case D3DFMT_A8P8: return WINED3DFMT_P8_UINT_A8_UNORM;
114 case D3DFMT_P8: return WINED3DFMT_P8_UINT;
115 case D3DFMT_L8: return WINED3DFMT_L8_UNORM;
116 case D3DFMT_A8L8: return WINED3DFMT_L8A8_UNORM;
117 case D3DFMT_A4L4: return WINED3DFMT_L4A4_UNORM;
118 case D3DFMT_V8U8: return WINED3DFMT_R8G8_SNORM;
119 case D3DFMT_L6V5U5: return WINED3DFMT_R5G5_SNORM_L6_UNORM;
120 case D3DFMT_X8L8V8U8: return WINED3DFMT_R8G8_SNORM_L8X8_UNORM;
121 case D3DFMT_Q8W8V8U8: return WINED3DFMT_R8G8B8A8_SNORM;
122 case D3DFMT_V16U16: return WINED3DFMT_R16G16_SNORM;
123 case D3DFMT_W11V11U10: return WINED3DFMT_R10G11B11_SNORM;
124 case D3DFMT_A2W10V10U10: return WINED3DFMT_R10G10B10_SNORM_A2_UNORM;
125 case D3DFMT_D16_LOCKABLE: return WINED3DFMT_D16_LOCKABLE;
126 case D3DFMT_D32: return WINED3DFMT_D32_UNORM;
127 case D3DFMT_D15S1: return WINED3DFMT_S1_UINT_D15_UNORM;
128 case D3DFMT_D24S8: return WINED3DFMT_D24_UNORM_S8_UINT;
129 case D3DFMT_D24X8: return WINED3DFMT_X8D24_UNORM;
130 case D3DFMT_D24X4S4: return WINED3DFMT_S4X4_UINT_D24_UNORM;
131 case D3DFMT_D16: return WINED3DFMT_D16_UNORM;
132 case D3DFMT_VERTEXDATA: return WINED3DFMT_VERTEXDATA;
133 case D3DFMT_INDEX16: return WINED3DFMT_R16_UINT;
134 case D3DFMT_INDEX32: return WINED3DFMT_R32_UINT;
136 FIXME("Unhandled D3DFORMAT %#x\n", format);
137 return WINED3DFMT_UNKNOWN;
141 static UINT vertex_count_from_primitive_count(D3DPRIMITIVETYPE primitive_type, UINT primitive_count)
143 switch(primitive_type)
145 case D3DPT_POINTLIST:
146 return primitive_count;
149 return primitive_count * 2;
151 case D3DPT_LINESTRIP:
152 return primitive_count + 1;
154 case D3DPT_TRIANGLELIST:
155 return primitive_count * 3;
157 case D3DPT_TRIANGLESTRIP:
158 case D3DPT_TRIANGLEFAN:
159 return primitive_count + 2;
162 FIXME("Unhandled primitive type %#x\n", primitive_type);
167 static void present_parameters_from_wined3d_swapchain_desc(D3DPRESENT_PARAMETERS *present_parameters,
168 const struct wined3d_swapchain_desc *swapchain_desc)
170 present_parameters->BackBufferWidth = swapchain_desc->backbuffer_width;
171 present_parameters->BackBufferHeight = swapchain_desc->backbuffer_height;
172 present_parameters->BackBufferFormat = d3dformat_from_wined3dformat(swapchain_desc->backbuffer_format);
173 present_parameters->BackBufferCount = swapchain_desc->backbuffer_count;
174 present_parameters->MultiSampleType = swapchain_desc->multisample_type;
175 present_parameters->SwapEffect = swapchain_desc->swap_effect;
176 present_parameters->hDeviceWindow = swapchain_desc->device_window;
177 present_parameters->Windowed = swapchain_desc->windowed;
178 present_parameters->EnableAutoDepthStencil = swapchain_desc->enable_auto_depth_stencil;
179 present_parameters->AutoDepthStencilFormat
180 = d3dformat_from_wined3dformat(swapchain_desc->auto_depth_stencil_format);
181 present_parameters->Flags = swapchain_desc->flags;
182 present_parameters->FullScreen_RefreshRateInHz = swapchain_desc->refresh_rate;
183 present_parameters->FullScreen_PresentationInterval = swapchain_desc->swap_interval;
186 static void wined3d_swapchain_desc_from_present_parameters(struct wined3d_swapchain_desc *swapchain_desc,
187 const D3DPRESENT_PARAMETERS *present_parameters)
189 swapchain_desc->backbuffer_width = present_parameters->BackBufferWidth;
190 swapchain_desc->backbuffer_height = present_parameters->BackBufferHeight;
191 swapchain_desc->backbuffer_format = wined3dformat_from_d3dformat(present_parameters->BackBufferFormat);
192 swapchain_desc->backbuffer_count = max(1, present_parameters->BackBufferCount);
193 swapchain_desc->multisample_type = present_parameters->MultiSampleType;
194 swapchain_desc->multisample_quality = 0; /* d3d9 only */
195 swapchain_desc->swap_effect = present_parameters->SwapEffect;
196 swapchain_desc->device_window = present_parameters->hDeviceWindow;
197 swapchain_desc->windowed = present_parameters->Windowed;
198 swapchain_desc->enable_auto_depth_stencil = present_parameters->EnableAutoDepthStencil;
199 swapchain_desc->auto_depth_stencil_format
200 = wined3dformat_from_d3dformat(present_parameters->AutoDepthStencilFormat);
201 swapchain_desc->flags = present_parameters->Flags;
202 swapchain_desc->refresh_rate = present_parameters->FullScreen_RefreshRateInHz;
203 swapchain_desc->swap_interval = present_parameters->FullScreen_PresentationInterval;
204 swapchain_desc->auto_restore_display_mode = TRUE;
207 /* Handle table functions */
208 static DWORD d3d8_allocate_handle(struct d3d8_handle_table *t, void *object, enum d3d8_handle_type type)
210 struct d3d8_handle_entry *entry;
214 DWORD index = t->free_entries - t->entries;
215 /* Use a free handle */
216 entry = t->free_entries;
217 if (entry->type != D3D8_HANDLE_FREE)
219 ERR("Handle %u(%p) is in the free list, but has type %#x.\n", index, entry, entry->type);
220 return D3D8_INVALID_HANDLE;
222 t->free_entries = entry->object;
223 entry->object = object;
229 if (!(t->entry_count < t->table_size))
232 UINT new_size = t->table_size + (t->table_size >> 1);
233 struct d3d8_handle_entry *new_entries = HeapReAlloc(GetProcessHeap(),
234 0, t->entries, new_size * sizeof(*t->entries));
237 ERR("Failed to grow the handle table.\n");
238 return D3D8_INVALID_HANDLE;
240 t->entries = new_entries;
241 t->table_size = new_size;
244 entry = &t->entries[t->entry_count];
245 entry->object = object;
248 return t->entry_count++;
251 static void *d3d8_free_handle(struct d3d8_handle_table *t, DWORD handle, enum d3d8_handle_type type)
253 struct d3d8_handle_entry *entry;
256 if (handle == D3D8_INVALID_HANDLE || handle >= t->entry_count)
258 WARN("Invalid handle %u passed.\n", handle);
262 entry = &t->entries[handle];
263 if (entry->type != type)
265 WARN("Handle %u(%p) is not of type %#x.\n", handle, entry, type);
269 object = entry->object;
270 entry->object = t->free_entries;
271 entry->type = D3D8_HANDLE_FREE;
272 t->free_entries = entry;
277 static void *d3d8_get_object(struct d3d8_handle_table *t, DWORD handle, enum d3d8_handle_type type)
279 struct d3d8_handle_entry *entry;
281 if (handle == D3D8_INVALID_HANDLE || handle >= t->entry_count)
283 WARN("Invalid handle %u passed.\n", handle);
287 entry = &t->entries[handle];
288 if (entry->type != type)
290 WARN("Handle %u(%p) is not of type %#x.\n", handle, entry, type);
294 return entry->object;
297 static inline struct d3d8_device *impl_from_IDirect3DDevice8(IDirect3DDevice8 *iface)
299 return CONTAINING_RECORD(iface, struct d3d8_device, IDirect3DDevice8_iface);
302 static HRESULT WINAPI d3d8_device_QueryInterface(IDirect3DDevice8 *iface, REFIID riid, void **out)
304 TRACE("iface %p, riid %s, out %p.\n",
305 iface, debugstr_guid(riid), out);
307 if (IsEqualGUID(riid, &IID_IDirect3DDevice8)
308 || IsEqualGUID(riid, &IID_IUnknown))
310 IDirect3DDevice8_AddRef(iface);
315 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
318 return E_NOINTERFACE;
321 static ULONG WINAPI d3d8_device_AddRef(IDirect3DDevice8 *iface)
323 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
324 ULONG ref = InterlockedIncrement(&device->ref);
326 TRACE("%p increasing refcount to %u.\n", iface, ref);
331 static ULONG WINAPI d3d8_device_Release(IDirect3DDevice8 *iface)
333 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
336 if (device->inDestruction)
339 ref = InterlockedDecrement(&device->ref);
341 TRACE("%p decreasing refcount to %u.\n", iface, ref);
345 IDirect3D8 *parent = device->d3d_parent;
348 TRACE("Releasing wined3d device %p.\n", device->wined3d_device);
350 wined3d_mutex_lock();
352 device->inDestruction = TRUE;
354 for (i = 0; i < device->numConvertedDecls; ++i)
356 d3d8_vertex_declaration_destroy(device->decls[i].declaration);
358 HeapFree(GetProcessHeap(), 0, device->decls);
360 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));
727 ERR("Failed to allocate texture memory.\n");
728 return D3DERR_OUTOFVIDEOMEMORY;
731 hr = texture_init(object, device, width, height, levels, usage, format, pool);
734 WARN("Failed to initialize texture, hr %#x.\n", hr);
735 HeapFree(GetProcessHeap(), 0, object);
739 TRACE("Created texture %p.\n", object);
740 *texture = (IDirect3DTexture8 *)&object->IDirect3DBaseTexture8_iface;
745 static HRESULT WINAPI d3d8_device_CreateVolumeTexture(IDirect3DDevice8 *iface,
746 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
747 D3DPOOL pool, IDirect3DVolumeTexture8 **texture)
749 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
750 struct d3d8_texture *object;
753 TRACE("iface %p, width %u, height %u, depth %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
754 iface, width, height, depth, levels, usage, format, pool, texture);
756 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
759 ERR("Failed to allocate volume texture memory.\n");
760 return D3DERR_OUTOFVIDEOMEMORY;
763 hr = volumetexture_init(object, device, width, height, depth, levels, usage, format, pool);
766 WARN("Failed to initialize volume texture, hr %#x.\n", hr);
767 HeapFree(GetProcessHeap(), 0, object);
771 TRACE("Created volume texture %p.\n", object);
772 *texture = (IDirect3DVolumeTexture8 *)&object->IDirect3DBaseTexture8_iface;
777 static HRESULT WINAPI d3d8_device_CreateCubeTexture(IDirect3DDevice8 *iface, UINT edge_length,
778 UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool, IDirect3DCubeTexture8 **texture)
780 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
781 struct d3d8_texture *object;
784 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
785 iface, edge_length, levels, usage, format, pool, texture);
787 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
790 ERR("Failed to allocate cube texture memory.\n");
791 return D3DERR_OUTOFVIDEOMEMORY;
794 hr = cubetexture_init(object, device, edge_length, levels, usage, format, pool);
797 WARN("Failed to initialize cube texture, hr %#x.\n", hr);
798 HeapFree(GetProcessHeap(), 0, object);
802 TRACE("Created cube texture %p.\n", object);
803 *texture = (IDirect3DCubeTexture8 *)&object->IDirect3DBaseTexture8_iface;
808 static HRESULT WINAPI d3d8_device_CreateVertexBuffer(IDirect3DDevice8 *iface, UINT size,
809 DWORD usage, DWORD fvf, D3DPOOL pool, IDirect3DVertexBuffer8 **buffer)
811 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
812 struct d3d8_vertexbuffer *object;
815 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p.\n",
816 iface, size, usage, fvf, pool, buffer);
818 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
821 ERR("Failed to allocate buffer memory.\n");
822 return D3DERR_OUTOFVIDEOMEMORY;
825 hr = vertexbuffer_init(object, device, size, usage, fvf, pool);
828 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr);
829 HeapFree(GetProcessHeap(), 0, object);
833 TRACE("Created vertex buffer %p.\n", object);
834 *buffer = &object->IDirect3DVertexBuffer8_iface;
839 static HRESULT WINAPI d3d8_device_CreateIndexBuffer(IDirect3DDevice8 *iface, UINT size,
840 DWORD usage, D3DFORMAT format, D3DPOOL pool, IDirect3DIndexBuffer8 **buffer)
842 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
843 struct d3d8_indexbuffer *object;
846 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p.\n",
847 iface, size, usage, format, pool, buffer);
849 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
852 ERR("Failed to allocate buffer memory.\n");
853 return D3DERR_OUTOFVIDEOMEMORY;
856 hr = indexbuffer_init(object, device, size, usage, format, pool);
859 WARN("Failed to initialize index buffer, hr %#x.\n", hr);
860 HeapFree(GetProcessHeap(), 0, object);
864 TRACE("Created index buffer %p.\n", object);
865 *buffer = &object->IDirect3DIndexBuffer8_iface;
870 static HRESULT d3d8_device_create_surface(struct d3d8_device *device, UINT width, UINT height,
871 D3DFORMAT format, BOOL lockable, BOOL discard, IDirect3DSurface8 **surface, UINT usage,
872 D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality)
874 struct d3d8_surface *object;
877 TRACE("device %p, width %u, height %u, format %#x, lockable %#x, discard %#x, surface %p,\n"
878 "\tusage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
879 device, width, height, format, lockable, discard, surface,
880 usage, pool, multisample_type, multisample_quality);
882 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
884 FIXME("Failed to allocate surface memory.\n");
885 return D3DERR_OUTOFVIDEOMEMORY;
888 if (FAILED(hr = surface_init(object, device, width, height, format, lockable,
889 discard, usage, pool, multisample_type, multisample_quality)))
891 WARN("Failed to initialize surface, hr %#x.\n", hr);
892 HeapFree(GetProcessHeap(), 0, object);
896 TRACE("Created surface %p.\n", object);
897 *surface = &object->IDirect3DSurface8_iface;
902 static HRESULT WINAPI d3d8_device_CreateRenderTarget(IDirect3DDevice8 *iface, UINT width,
903 UINT height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, BOOL lockable,
904 IDirect3DSurface8 **surface)
906 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
908 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, lockable %#x, surface %p.\n",
909 iface, width, height, format, multisample_type, lockable, surface);
911 return d3d8_device_create_surface(device, width, height, format, lockable, FALSE,
912 surface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, multisample_type, 0);
915 static HRESULT WINAPI d3d8_device_CreateDepthStencilSurface(IDirect3DDevice8 *iface,
916 UINT width, UINT height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type,
917 IDirect3DSurface8 **surface)
919 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
921 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, surface %p.\n",
922 iface, width, height, format, multisample_type, surface);
924 /* TODO: Verify that Discard is false */
925 return d3d8_device_create_surface(device, width, height, format, TRUE, FALSE,
926 surface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, multisample_type, 0);
929 /* IDirect3DDevice8Impl::CreateImageSurface returns surface with pool type SYSTEMMEM */
930 static HRESULT WINAPI d3d8_device_CreateImageSurface(IDirect3DDevice8 *iface, UINT width,
931 UINT height, D3DFORMAT format, IDirect3DSurface8 **surface)
933 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
935 TRACE("iface %p, width %u, height %u, format %#x, surface %p.\n",
936 iface, width, height, format, surface);
938 return d3d8_device_create_surface(device, width, height, format, TRUE, FALSE,
939 surface, 0, D3DPOOL_SYSTEMMEM, D3DMULTISAMPLE_NONE, 0);
942 static HRESULT WINAPI d3d8_device_CopyRects(IDirect3DDevice8 *iface,
943 IDirect3DSurface8 *src_surface, const RECT *src_rects, UINT rect_count,
944 IDirect3DSurface8 *dst_surface, const POINT *dst_points)
946 struct d3d8_surface *src = unsafe_impl_from_IDirect3DSurface8(src_surface);
947 struct d3d8_surface *dst = unsafe_impl_from_IDirect3DSurface8(dst_surface);
948 enum wined3d_format_id src_format, dst_format;
949 struct wined3d_resource_desc wined3d_desc;
950 struct wined3d_resource *wined3d_resource;
954 TRACE("iface %p, src_surface %p, src_rects %p, rect_count %u, dst_surface %p, dst_points %p.\n",
955 iface, src_surface, src_rects, rect_count, dst_surface, dst_points);
957 /* Check that the source texture is in WINED3D_POOL_SYSTEM_MEM and the
958 * destination texture is in WINED3D_POOL_DEFAULT. */
960 wined3d_mutex_lock();
961 wined3d_resource = wined3d_surface_get_resource(src->wined3d_surface);
962 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
963 if (wined3d_desc.usage & WINED3DUSAGE_DEPTHSTENCIL)
965 WARN("Source %p is a depth stencil surface, returning D3DERR_INVALIDCALL.\n", src_surface);
966 wined3d_mutex_unlock();
967 return D3DERR_INVALIDCALL;
969 src_format = wined3d_desc.format;
970 src_w = wined3d_desc.width;
971 src_h = wined3d_desc.height;
973 wined3d_resource = wined3d_surface_get_resource(dst->wined3d_surface);
974 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
975 if (wined3d_desc.usage & WINED3DUSAGE_DEPTHSTENCIL)
977 WARN("Destination %p is a depth stencil surface, returning D3DERR_INVALIDCALL.\n", dst_surface);
978 wined3d_mutex_unlock();
979 return D3DERR_INVALIDCALL;
981 dst_format = wined3d_desc.format;
983 /* Check that the source and destination formats match */
984 if (src_format != dst_format && WINED3DFMT_UNKNOWN != dst_format)
986 WARN("Source %p format must match the destination %p format, returning D3DERR_INVALIDCALL.\n",
987 src_surface, dst_surface);
988 wined3d_mutex_unlock();
989 return D3DERR_INVALIDCALL;
991 else if (WINED3DFMT_UNKNOWN == dst_format)
993 TRACE("Converting destination surface from WINED3DFMT_UNKNOWN to the source format.\n");
994 if (FAILED(hr = wined3d_surface_update_desc(dst->wined3d_surface, wined3d_desc.width, wined3d_desc.height,
995 src_format, wined3d_desc.multisample_type, wined3d_desc.multisample_quality)))
997 WARN("Failed to update surface desc, hr %#x.\n", hr);
998 wined3d_mutex_unlock();
1003 /* Quick if complete copy ... */
1004 if (!rect_count && !src_rects && !dst_points)
1006 RECT rect = {0, 0, src_w, src_h};
1007 wined3d_surface_blt(dst->wined3d_surface, &rect,
1008 src->wined3d_surface, &rect, 0, NULL, WINED3D_TEXF_POINT);
1013 /* Copy rect by rect */
1014 if (src_rects && dst_points)
1016 for (i = 0; i < rect_count; ++i)
1018 UINT w = src_rects[i].right - src_rects[i].left;
1019 UINT h = src_rects[i].bottom - src_rects[i].top;
1020 RECT dst_rect = {dst_points[i].x, dst_points[i].y,
1021 dst_points[i].x + w, dst_points[i].y + h};
1023 wined3d_surface_blt(dst->wined3d_surface, &dst_rect,
1024 src->wined3d_surface, &src_rects[i], 0, NULL, WINED3D_TEXF_POINT);
1029 for (i = 0; i < rect_count; ++i)
1031 UINT w = src_rects[i].right - src_rects[i].left;
1032 UINT h = src_rects[i].bottom - src_rects[i].top;
1033 RECT dst_rect = {0, 0, w, h};
1035 wined3d_surface_blt(dst->wined3d_surface, &dst_rect,
1036 src->wined3d_surface, &src_rects[i], 0, NULL, WINED3D_TEXF_POINT);
1040 wined3d_mutex_unlock();
1045 static HRESULT WINAPI d3d8_device_UpdateTexture(IDirect3DDevice8 *iface,
1046 IDirect3DBaseTexture8 *src_texture, IDirect3DBaseTexture8 *dst_texture)
1048 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1049 struct d3d8_texture *src_impl, *dst_impl;
1052 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface, src_texture, dst_texture);
1054 src_impl = unsafe_impl_from_IDirect3DBaseTexture8(src_texture);
1055 dst_impl = unsafe_impl_from_IDirect3DBaseTexture8(dst_texture);
1057 wined3d_mutex_lock();
1058 hr = wined3d_device_update_texture(device->wined3d_device,
1059 src_impl->wined3d_texture, dst_impl->wined3d_texture);
1060 wined3d_mutex_unlock();
1065 static HRESULT WINAPI d3d8_device_GetFrontBuffer(IDirect3DDevice8 *iface, IDirect3DSurface8 *dst_surface)
1067 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1068 struct d3d8_surface *dst_impl = unsafe_impl_from_IDirect3DSurface8(dst_surface);
1071 TRACE("iface %p, dst_surface %p.\n", iface, dst_surface);
1075 WARN("Invalid destination surface passed.\n");
1076 return D3DERR_INVALIDCALL;
1079 wined3d_mutex_lock();
1080 hr = wined3d_device_get_front_buffer_data(device->wined3d_device, 0, dst_impl->wined3d_surface);
1081 wined3d_mutex_unlock();
1086 static HRESULT WINAPI d3d8_device_SetRenderTarget(IDirect3DDevice8 *iface,
1087 IDirect3DSurface8 *render_target, IDirect3DSurface8 *depth_stencil)
1089 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1090 struct d3d8_surface *rt_impl = unsafe_impl_from_IDirect3DSurface8(render_target);
1091 struct d3d8_surface *ds_impl = unsafe_impl_from_IDirect3DSurface8(depth_stencil);
1092 struct wined3d_surface *original_ds = NULL;
1093 HRESULT hr = D3D_OK;
1095 TRACE("iface %p, render_target %p, depth_stencil %p.\n", iface, render_target, depth_stencil);
1097 wined3d_mutex_lock();
1101 struct wined3d_resource_desc ds_desc, rt_desc;
1102 struct wined3d_resource *wined3d_resource;
1103 struct wined3d_surface *original_rt = NULL;
1105 /* If no render target is passed in check the size against the current RT */
1108 if (!(original_rt = wined3d_device_get_render_target(device->wined3d_device, 0)))
1110 wined3d_mutex_unlock();
1111 return D3DERR_NOTFOUND;
1113 wined3d_resource = wined3d_surface_get_resource(original_rt);
1116 wined3d_resource = wined3d_surface_get_resource(rt_impl->wined3d_surface);
1117 wined3d_resource_get_desc(wined3d_resource, &rt_desc);
1119 wined3d_resource = wined3d_surface_get_resource(ds_impl->wined3d_surface);
1120 wined3d_resource_get_desc(wined3d_resource, &ds_desc);
1122 if (ds_desc.width < rt_desc.width || ds_desc.height < rt_desc.height)
1124 WARN("Depth stencil is smaller than the render target, returning D3DERR_INVALIDCALL\n");
1125 wined3d_mutex_unlock();
1126 return D3DERR_INVALIDCALL;
1130 original_ds = wined3d_device_get_depth_stencil(device->wined3d_device);
1131 wined3d_device_set_depth_stencil(device->wined3d_device, ds_impl ? ds_impl->wined3d_surface : NULL);
1134 hr = wined3d_device_set_render_target(device->wined3d_device, 0, rt_impl->wined3d_surface, TRUE);
1136 wined3d_device_set_depth_stencil(device->wined3d_device, original_ds);
1139 wined3d_mutex_unlock();
1144 static HRESULT WINAPI d3d8_device_GetRenderTarget(IDirect3DDevice8 *iface, IDirect3DSurface8 **render_target)
1146 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1147 struct wined3d_surface *wined3d_surface;
1148 struct d3d8_surface *surface_impl;
1151 TRACE("iface %p, render_target %p.\n", iface, render_target);
1154 return D3DERR_INVALIDCALL;
1156 wined3d_mutex_lock();
1157 if ((wined3d_surface = wined3d_device_get_render_target(device->wined3d_device, 0)))
1159 surface_impl = wined3d_surface_get_parent(wined3d_surface);
1160 *render_target = &surface_impl->IDirect3DSurface8_iface;
1161 IDirect3DSurface8_AddRef(*render_target);
1166 ERR("Failed to get wined3d render target.\n");
1167 *render_target = NULL;
1168 hr = D3DERR_NOTFOUND;
1170 wined3d_mutex_unlock();
1175 static HRESULT WINAPI d3d8_device_GetDepthStencilSurface(IDirect3DDevice8 *iface, IDirect3DSurface8 **depth_stencil)
1177 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1178 struct wined3d_surface *wined3d_surface;
1179 struct d3d8_surface *surface_impl;
1180 HRESULT hr = D3D_OK;
1182 TRACE("iface %p, depth_stencil %p.\n", iface, depth_stencil);
1185 return D3DERR_INVALIDCALL;
1187 wined3d_mutex_lock();
1188 if ((wined3d_surface = wined3d_device_get_depth_stencil(device->wined3d_device)))
1190 surface_impl = wined3d_surface_get_parent(wined3d_surface);
1191 *depth_stencil = &surface_impl->IDirect3DSurface8_iface;
1192 IDirect3DSurface8_AddRef(*depth_stencil);
1196 hr = WINED3DERR_NOTFOUND;
1197 *depth_stencil = NULL;
1199 wined3d_mutex_unlock();
1204 static HRESULT WINAPI d3d8_device_BeginScene(IDirect3DDevice8 *iface)
1206 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1209 TRACE("iface %p.\n", iface);
1211 wined3d_mutex_lock();
1212 hr = wined3d_device_begin_scene(device->wined3d_device);
1213 wined3d_mutex_unlock();
1218 static HRESULT WINAPI DECLSPEC_HOTPATCH d3d8_device_EndScene(IDirect3DDevice8 *iface)
1220 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1223 TRACE("iface %p.\n", iface);
1225 wined3d_mutex_lock();
1226 hr = wined3d_device_end_scene(device->wined3d_device);
1227 wined3d_mutex_unlock();
1232 static HRESULT WINAPI d3d8_device_Clear(IDirect3DDevice8 *iface, DWORD rect_count,
1233 const D3DRECT *rects, DWORD flags, D3DCOLOR color, float z, DWORD stencil)
1235 const struct wined3d_color c =
1237 ((color >> 16) & 0xff) / 255.0f,
1238 ((color >> 8) & 0xff) / 255.0f,
1239 (color & 0xff) / 255.0f,
1240 ((color >> 24) & 0xff) / 255.0f,
1242 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1245 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1246 iface, rect_count, rects, flags, color, z, stencil);
1248 wined3d_mutex_lock();
1249 hr = wined3d_device_clear(device->wined3d_device, rect_count, (const RECT *)rects, flags, &c, z, stencil);
1250 wined3d_mutex_unlock();
1255 static HRESULT WINAPI d3d8_device_SetTransform(IDirect3DDevice8 *iface,
1256 D3DTRANSFORMSTATETYPE state, const 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_set_transform(device->wined3d_device, state, (const struct wined3d_matrix *)matrix);
1265 wined3d_mutex_unlock();
1270 static HRESULT WINAPI d3d8_device_GetTransform(IDirect3DDevice8 *iface,
1271 D3DTRANSFORMSTATETYPE state, D3DMATRIX *matrix)
1273 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
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_get_transform(device->wined3d_device, state, (struct wined3d_matrix *)matrix);
1280 wined3d_mutex_unlock();
1285 static HRESULT WINAPI d3d8_device_MultiplyTransform(IDirect3DDevice8 *iface,
1286 D3DTRANSFORMSTATETYPE state, const D3DMATRIX *matrix)
1288 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1290 TRACE("iface %p, state %#x, matrix %p.\n", iface, state, matrix);
1292 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1293 wined3d_mutex_lock();
1294 wined3d_device_multiply_transform(device->wined3d_device, state, (const struct wined3d_matrix *)matrix);
1295 wined3d_mutex_unlock();
1300 static HRESULT WINAPI d3d8_device_SetViewport(IDirect3DDevice8 *iface, const D3DVIEWPORT8 *viewport)
1302 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1304 TRACE("iface %p, viewport %p.\n", iface, viewport);
1306 /* Note: D3DVIEWPORT8 is compatible with struct wined3d_viewport. */
1307 wined3d_mutex_lock();
1308 wined3d_device_set_viewport(device->wined3d_device, (const struct wined3d_viewport *)viewport);
1309 wined3d_mutex_unlock();
1314 static HRESULT WINAPI d3d8_device_GetViewport(IDirect3DDevice8 *iface, D3DVIEWPORT8 *viewport)
1316 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1318 TRACE("iface %p, viewport %p.\n", iface, viewport);
1320 /* Note: D3DVIEWPORT8 is compatible with struct wined3d_viewport. */
1321 wined3d_mutex_lock();
1322 wined3d_device_get_viewport(device->wined3d_device, (struct wined3d_viewport *)viewport);
1323 wined3d_mutex_unlock();
1328 static HRESULT WINAPI d3d8_device_SetMaterial(IDirect3DDevice8 *iface, const D3DMATERIAL8 *material)
1330 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1332 TRACE("iface %p, material %p.\n", iface, material);
1334 /* Note: D3DMATERIAL8 is compatible with struct wined3d_material. */
1335 wined3d_mutex_lock();
1336 wined3d_device_set_material(device->wined3d_device, (const struct wined3d_material *)material);
1337 wined3d_mutex_unlock();
1342 static HRESULT WINAPI d3d8_device_GetMaterial(IDirect3DDevice8 *iface, D3DMATERIAL8 *material)
1344 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1346 TRACE("iface %p, material %p.\n", iface, material);
1348 /* Note: D3DMATERIAL8 is compatible with struct wined3d_material. */
1349 wined3d_mutex_lock();
1350 wined3d_device_get_material(device->wined3d_device, (struct wined3d_material *)material);
1351 wined3d_mutex_unlock();
1356 static HRESULT WINAPI d3d8_device_SetLight(IDirect3DDevice8 *iface, DWORD index, const 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_set_light(device->wined3d_device, index, (const struct wined3d_light *)light);
1366 wined3d_mutex_unlock();
1371 static HRESULT WINAPI d3d8_device_GetLight(IDirect3DDevice8 *iface, DWORD index, D3DLIGHT8 *light)
1373 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1376 TRACE("iface %p, index %u, light %p.\n", iface, index, light);
1378 /* Note: D3DLIGHT8 is compatible with struct wined3d_light. */
1379 wined3d_mutex_lock();
1380 hr = wined3d_device_get_light(device->wined3d_device, index, (struct wined3d_light *)light);
1381 wined3d_mutex_unlock();
1386 static HRESULT WINAPI d3d8_device_LightEnable(IDirect3DDevice8 *iface, DWORD index, BOOL enable)
1388 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1391 TRACE("iface %p, index %u, enable %#x.\n", iface, index, enable);
1393 wined3d_mutex_lock();
1394 hr = wined3d_device_set_light_enable(device->wined3d_device, index, enable);
1395 wined3d_mutex_unlock();
1400 static HRESULT WINAPI d3d8_device_GetLightEnable(IDirect3DDevice8 *iface, DWORD index, BOOL *enable)
1402 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1405 TRACE("iface %p, index %u, enable %p.\n", iface, index, enable);
1407 wined3d_mutex_lock();
1408 hr = wined3d_device_get_light_enable(device->wined3d_device, index, enable);
1409 wined3d_mutex_unlock();
1414 static HRESULT WINAPI d3d8_device_SetClipPlane(IDirect3DDevice8 *iface, DWORD index, const float *plane)
1416 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1419 TRACE("iface %p, index %u, plane %p.\n", iface, index, plane);
1421 wined3d_mutex_lock();
1422 hr = wined3d_device_set_clip_plane(device->wined3d_device, index, (const struct wined3d_vec4 *)plane);
1423 wined3d_mutex_unlock();
1428 static HRESULT WINAPI d3d8_device_GetClipPlane(IDirect3DDevice8 *iface, DWORD index, float *plane)
1430 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1433 TRACE("iface %p, index %u, plane %p.\n", iface, index, plane);
1435 wined3d_mutex_lock();
1436 hr = wined3d_device_get_clip_plane(device->wined3d_device, index, (struct wined3d_vec4 *)plane);
1437 wined3d_mutex_unlock();
1442 static HRESULT WINAPI d3d8_device_SetRenderState(IDirect3DDevice8 *iface,
1443 D3DRENDERSTATETYPE state, DWORD value)
1445 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1447 TRACE("iface %p, state %#x, value %#x.\n", iface, state, value);
1449 wined3d_mutex_lock();
1453 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DEPTHBIAS, value);
1457 wined3d_device_set_render_state(device->wined3d_device, state, value);
1459 wined3d_mutex_unlock();
1464 static HRESULT WINAPI d3d8_device_GetRenderState(IDirect3DDevice8 *iface,
1465 D3DRENDERSTATETYPE state, DWORD *value)
1467 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1469 TRACE("iface %p, state %#x, value %p.\n", iface, state, value);
1471 wined3d_mutex_lock();
1475 *value = wined3d_device_get_render_state(device->wined3d_device, WINED3D_RS_DEPTHBIAS);
1479 *value = wined3d_device_get_render_state(device->wined3d_device, state);
1481 wined3d_mutex_unlock();
1486 static HRESULT WINAPI d3d8_device_BeginStateBlock(IDirect3DDevice8 *iface)
1488 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1491 TRACE("iface %p.\n", iface);
1493 wined3d_mutex_lock();
1494 hr = wined3d_device_begin_stateblock(device->wined3d_device);
1495 wined3d_mutex_unlock();
1500 static HRESULT WINAPI d3d8_device_EndStateBlock(IDirect3DDevice8 *iface, DWORD *token)
1502 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1503 struct wined3d_stateblock *stateblock;
1506 TRACE("iface %p, token %p.\n", iface, token);
1508 /* Tell wineD3D to endstateblock before anything else (in case we run out
1509 * of memory later and cause locking problems)
1511 wined3d_mutex_lock();
1512 hr = wined3d_device_end_stateblock(device->wined3d_device, &stateblock);
1515 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
1516 wined3d_mutex_unlock();
1520 *token = d3d8_allocate_handle(&device->handle_table, stateblock, D3D8_HANDLE_SB);
1521 wined3d_mutex_unlock();
1523 if (*token == D3D8_INVALID_HANDLE)
1525 ERR("Failed to create a handle\n");
1526 wined3d_mutex_lock();
1527 wined3d_stateblock_decref(stateblock);
1528 wined3d_mutex_unlock();
1533 TRACE("Returning %#x (%p).\n", *token, stateblock);
1538 static HRESULT WINAPI d3d8_device_ApplyStateBlock(IDirect3DDevice8 *iface, DWORD token)
1540 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1541 struct wined3d_stateblock *stateblock;
1543 TRACE("iface %p, token %#x.\n", iface, token);
1548 wined3d_mutex_lock();
1549 stateblock = d3d8_get_object(&device->handle_table, token - 1, D3D8_HANDLE_SB);
1552 WARN("Invalid handle (%#x) passed.\n", token);
1553 wined3d_mutex_unlock();
1554 return D3DERR_INVALIDCALL;
1556 wined3d_stateblock_apply(stateblock);
1557 wined3d_mutex_unlock();
1562 static HRESULT WINAPI d3d8_device_CaptureStateBlock(IDirect3DDevice8 *iface, DWORD token)
1564 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1565 struct wined3d_stateblock *stateblock;
1567 TRACE("iface %p, token %#x.\n", iface, token);
1569 wined3d_mutex_lock();
1570 stateblock = d3d8_get_object(&device->handle_table, token - 1, D3D8_HANDLE_SB);
1573 WARN("Invalid handle (%#x) passed.\n", token);
1574 wined3d_mutex_unlock();
1575 return D3DERR_INVALIDCALL;
1577 wined3d_stateblock_capture(stateblock);
1578 wined3d_mutex_unlock();
1583 static HRESULT WINAPI d3d8_device_DeleteStateBlock(IDirect3DDevice8 *iface, DWORD token)
1585 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1586 struct wined3d_stateblock *stateblock;
1588 TRACE("iface %p, token %#x.\n", iface, token);
1590 wined3d_mutex_lock();
1591 stateblock = d3d8_free_handle(&device->handle_table, token - 1, D3D8_HANDLE_SB);
1595 WARN("Invalid handle (%#x) passed.\n", token);
1596 wined3d_mutex_unlock();
1597 return D3DERR_INVALIDCALL;
1600 if (wined3d_stateblock_decref(stateblock))
1602 ERR("Stateblock %p has references left, this shouldn't happen.\n", stateblock);
1604 wined3d_mutex_unlock();
1609 static HRESULT WINAPI d3d8_device_CreateStateBlock(IDirect3DDevice8 *iface,
1610 D3DSTATEBLOCKTYPE type, DWORD *handle)
1612 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1613 struct wined3d_stateblock *stateblock;
1616 TRACE("iface %p, type %#x, handle %p.\n", iface, type, handle);
1618 if (type != D3DSBT_ALL
1619 && type != D3DSBT_PIXELSTATE
1620 && type != D3DSBT_VERTEXSTATE)
1622 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1623 return D3DERR_INVALIDCALL;
1626 wined3d_mutex_lock();
1627 hr = wined3d_stateblock_create(device->wined3d_device, (enum wined3d_stateblock_type)type, &stateblock);
1630 wined3d_mutex_unlock();
1631 ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr);
1635 *handle = d3d8_allocate_handle(&device->handle_table, stateblock, D3D8_HANDLE_SB);
1636 wined3d_mutex_unlock();
1638 if (*handle == D3D8_INVALID_HANDLE)
1640 ERR("Failed to allocate a handle.\n");
1641 wined3d_mutex_lock();
1642 wined3d_stateblock_decref(stateblock);
1643 wined3d_mutex_unlock();
1648 TRACE("Returning %#x (%p).\n", *handle, stateblock);
1653 static HRESULT WINAPI d3d8_device_SetClipStatus(IDirect3DDevice8 *iface, const D3DCLIPSTATUS8 *clip_status)
1655 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1658 TRACE("iface %p, clip_status %p.\n", iface, clip_status);
1659 /* FIXME: Verify that D3DCLIPSTATUS8 ~= struct wined3d_clip_status. */
1661 wined3d_mutex_lock();
1662 hr = wined3d_device_set_clip_status(device->wined3d_device, (const struct wined3d_clip_status *)clip_status);
1663 wined3d_mutex_unlock();
1668 static HRESULT WINAPI d3d8_device_GetClipStatus(IDirect3DDevice8 *iface, D3DCLIPSTATUS8 *clip_status)
1670 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1673 TRACE("iface %p, clip_status %p.\n", iface, clip_status);
1675 wined3d_mutex_lock();
1676 hr = wined3d_device_get_clip_status(device->wined3d_device, (struct wined3d_clip_status *)clip_status);
1677 wined3d_mutex_unlock();
1682 static HRESULT WINAPI d3d8_device_GetTexture(IDirect3DDevice8 *iface, DWORD stage, IDirect3DBaseTexture8 **texture)
1684 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1685 struct wined3d_texture *wined3d_texture;
1686 struct d3d8_texture *texture_impl;
1688 TRACE("iface %p, stage %u, texture %p.\n", iface, stage, texture);
1691 return D3DERR_INVALIDCALL;
1693 wined3d_mutex_lock();
1694 if ((wined3d_texture = wined3d_device_get_texture(device->wined3d_device, stage)))
1696 texture_impl = wined3d_texture_get_parent(wined3d_texture);
1697 *texture = &texture_impl->IDirect3DBaseTexture8_iface;
1698 IDirect3DBaseTexture8_AddRef(*texture);
1704 wined3d_mutex_unlock();
1709 static HRESULT WINAPI d3d8_device_SetTexture(IDirect3DDevice8 *iface, DWORD stage, IDirect3DBaseTexture8 *texture)
1711 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1712 struct d3d8_texture *texture_impl;
1715 TRACE("iface %p, stage %u, texture %p.\n", iface, stage, texture);
1717 texture_impl = unsafe_impl_from_IDirect3DBaseTexture8(texture);
1719 wined3d_mutex_lock();
1720 hr = wined3d_device_set_texture(device->wined3d_device, stage,
1721 texture_impl ? texture_impl->wined3d_texture : NULL);
1722 wined3d_mutex_unlock();
1727 static const struct tss_lookup
1730 enum wined3d_texture_stage_state state;
1734 {FALSE, WINED3D_TSS_INVALID}, /* 0, unused */
1735 {FALSE, WINED3D_TSS_COLOR_OP}, /* 1, D3DTSS_COLOROP */
1736 {FALSE, WINED3D_TSS_COLOR_ARG1}, /* 2, D3DTSS_COLORARG1 */
1737 {FALSE, WINED3D_TSS_COLOR_ARG2}, /* 3, D3DTSS_COLORARG2 */
1738 {FALSE, WINED3D_TSS_ALPHA_OP}, /* 4, D3DTSS_ALPHAOP */
1739 {FALSE, WINED3D_TSS_ALPHA_ARG1}, /* 5, D3DTSS_ALPHAARG1 */
1740 {FALSE, WINED3D_TSS_ALPHA_ARG2}, /* 6, D3DTSS_ALPHAARG2 */
1741 {FALSE, WINED3D_TSS_BUMPENV_MAT00}, /* 7, D3DTSS_BUMPENVMAT00 */
1742 {FALSE, WINED3D_TSS_BUMPENV_MAT01}, /* 8, D3DTSS_BUMPENVMAT01 */
1743 {FALSE, WINED3D_TSS_BUMPENV_MAT10}, /* 9, D3DTSS_BUMPENVMAT10 */
1744 {FALSE, WINED3D_TSS_BUMPENV_MAT11}, /* 10, D3DTSS_BUMPENVMAT11 */
1745 {FALSE, WINED3D_TSS_TEXCOORD_INDEX}, /* 11, D3DTSS_TEXCOORDINDEX */
1746 {FALSE, WINED3D_TSS_INVALID}, /* 12, unused */
1747 {TRUE, WINED3D_SAMP_ADDRESS_U}, /* 13, D3DTSS_ADDRESSU */
1748 {TRUE, WINED3D_SAMP_ADDRESS_V}, /* 14, D3DTSS_ADDRESSV */
1749 {TRUE, WINED3D_SAMP_BORDER_COLOR}, /* 15, D3DTSS_BORDERCOLOR */
1750 {TRUE, WINED3D_SAMP_MAG_FILTER}, /* 16, D3DTSS_MAGFILTER */
1751 {TRUE, WINED3D_SAMP_MIN_FILTER}, /* 17, D3DTSS_MINFILTER */
1752 {TRUE, WINED3D_SAMP_MIP_FILTER}, /* 18, D3DTSS_MIPFILTER */
1753 {TRUE, WINED3D_SAMP_MIPMAP_LOD_BIAS}, /* 19, D3DTSS_MIPMAPLODBIAS */
1754 {TRUE, WINED3D_SAMP_MAX_MIP_LEVEL}, /* 20, D3DTSS_MAXMIPLEVEL */
1755 {TRUE, WINED3D_SAMP_MAX_ANISOTROPY}, /* 21, D3DTSS_MAXANISOTROPY */
1756 {FALSE, WINED3D_TSS_BUMPENV_LSCALE}, /* 22, D3DTSS_BUMPENVLSCALE */
1757 {FALSE, WINED3D_TSS_BUMPENV_LOFFSET}, /* 23, D3DTSS_BUMPENVLOFFSET */
1758 {FALSE, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1759 {TRUE, WINED3D_SAMP_ADDRESS_W}, /* 25, D3DTSS_ADDRESSW */
1760 {FALSE, WINED3D_TSS_COLOR_ARG0}, /* 26, D3DTSS_COLORARG0 */
1761 {FALSE, WINED3D_TSS_ALPHA_ARG0}, /* 27, D3DTSS_ALPHAARG0 */
1762 {FALSE, WINED3D_TSS_RESULT_ARG}, /* 28, D3DTSS_RESULTARG */
1765 static HRESULT WINAPI d3d8_device_GetTextureStageState(IDirect3DDevice8 *iface,
1766 DWORD stage, D3DTEXTURESTAGESTATETYPE Type, DWORD *value)
1768 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1769 const struct tss_lookup *l;
1771 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface, stage, Type, value);
1773 if (Type >= sizeof(tss_lookup) / sizeof(*tss_lookup))
1775 WARN("Invalid Type %#x passed.\n", Type);
1779 l = &tss_lookup[Type];
1781 wined3d_mutex_lock();
1782 if (l->sampler_state)
1783 *value = wined3d_device_get_sampler_state(device->wined3d_device, stage, l->state);
1785 *value = wined3d_device_get_texture_stage_state(device->wined3d_device, stage, l->state);
1786 wined3d_mutex_unlock();
1791 static HRESULT WINAPI d3d8_device_SetTextureStageState(IDirect3DDevice8 *iface,
1792 DWORD stage, D3DTEXTURESTAGESTATETYPE type, DWORD value)
1794 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1795 const struct tss_lookup *l;
1797 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface, stage, type, value);
1799 if (type >= sizeof(tss_lookup) / sizeof(*tss_lookup))
1801 WARN("Invalid type %#x passed.\n", type);
1805 l = &tss_lookup[type];
1807 wined3d_mutex_lock();
1808 if (l->sampler_state)
1809 wined3d_device_set_sampler_state(device->wined3d_device, stage, l->state, value);
1811 wined3d_device_set_texture_stage_state(device->wined3d_device, stage, l->state, value);
1812 wined3d_mutex_unlock();
1817 static HRESULT WINAPI d3d8_device_ValidateDevice(IDirect3DDevice8 *iface, DWORD *pass_count)
1819 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1822 TRACE("iface %p, pass_count %p.\n", iface, pass_count);
1824 wined3d_mutex_lock();
1825 hr = wined3d_device_validate_device(device->wined3d_device, pass_count);
1826 wined3d_mutex_unlock();
1831 static HRESULT WINAPI d3d8_device_GetInfo(IDirect3DDevice8 *iface,
1832 DWORD info_id, void *info, DWORD info_size)
1834 FIXME("iface %p, info_id %#x, info %p, info_size %u stub!\n", iface, info_id, info, info_size);
1839 static HRESULT WINAPI d3d8_device_SetPaletteEntries(IDirect3DDevice8 *iface,
1840 UINT palette_idx, const PALETTEENTRY *entries)
1842 FIXME("iface %p, palette_idx %u, entries %p unimplemented\n", iface, palette_idx, entries);
1844 /* GPUs stopped supporting palettized textures with the Shader Model 1 generation. Wined3d
1845 * does not have a d3d8/9-style palette API */
1847 return D3DERR_INVALIDCALL;
1850 static HRESULT WINAPI d3d8_device_GetPaletteEntries(IDirect3DDevice8 *iface,
1851 UINT palette_idx, PALETTEENTRY *entries)
1853 FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface, palette_idx, entries);
1855 return D3DERR_INVALIDCALL;
1858 static HRESULT WINAPI d3d8_device_SetCurrentTexturePalette(IDirect3DDevice8 *iface, UINT palette_idx)
1860 FIXME("iface %p, palette_idx %u unimplemented.\n", iface, palette_idx);
1862 return D3DERR_INVALIDCALL;
1865 static HRESULT WINAPI d3d8_device_GetCurrentTexturePalette(IDirect3DDevice8 *iface, UINT *palette_idx)
1867 FIXME("iface %p, palette_idx %p unimplemented.\n", iface, palette_idx);
1869 return D3DERR_INVALIDCALL;
1872 static HRESULT WINAPI d3d8_device_DrawPrimitive(IDirect3DDevice8 *iface,
1873 D3DPRIMITIVETYPE primitive_type, UINT start_vertex, UINT primitive_count)
1875 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1878 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1879 iface, primitive_type, start_vertex, primitive_count);
1881 wined3d_mutex_lock();
1882 wined3d_device_set_primitive_type(device->wined3d_device, primitive_type);
1883 hr = wined3d_device_draw_primitive(device->wined3d_device, start_vertex,
1884 vertex_count_from_primitive_count(primitive_type, primitive_count));
1885 wined3d_mutex_unlock();
1890 static HRESULT WINAPI d3d8_device_DrawIndexedPrimitive(IDirect3DDevice8 *iface,
1891 D3DPRIMITIVETYPE primitive_type, UINT min_vertex_idx, UINT vertex_count,
1892 UINT start_idx, UINT primitive_count)
1894 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1897 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, start_idx %u, primitive_count %u.\n",
1898 iface, primitive_type, min_vertex_idx, vertex_count, start_idx, primitive_count);
1900 wined3d_mutex_lock();
1901 wined3d_device_set_primitive_type(device->wined3d_device, primitive_type);
1902 hr = wined3d_device_draw_indexed_primitive(device->wined3d_device, start_idx,
1903 vertex_count_from_primitive_count(primitive_type, primitive_count));
1904 wined3d_mutex_unlock();
1909 static void STDMETHODCALLTYPE d3d8_null_wined3d_object_destroyed(void *parent) {}
1911 static const struct wined3d_parent_ops d3d8_null_wined3d_parent_ops =
1913 d3d8_null_wined3d_object_destroyed,
1916 /* The caller is responsible for wined3d locking */
1917 static HRESULT d3d8_device_prepare_vertex_buffer(struct d3d8_device *device, UINT min_size)
1921 if (device->vertex_buffer_size < min_size || !device->vertex_buffer)
1923 UINT size = max(device->vertex_buffer_size * 2, min_size);
1924 struct wined3d_buffer *buffer;
1926 TRACE("Growing vertex buffer to %u bytes\n", size);
1928 hr = wined3d_buffer_create_vb(device->wined3d_device, size, WINED3DUSAGE_DYNAMIC | WINED3DUSAGE_WRITEONLY,
1929 WINED3D_POOL_DEFAULT, NULL, &d3d8_null_wined3d_parent_ops, &buffer);
1932 ERR("(%p) wined3d_buffer_create_vb failed with hr = %08x\n", device, hr);
1936 if (device->vertex_buffer)
1937 wined3d_buffer_decref(device->vertex_buffer);
1939 device->vertex_buffer = buffer;
1940 device->vertex_buffer_size = size;
1941 device->vertex_buffer_pos = 0;
1946 static HRESULT WINAPI d3d8_device_DrawPrimitiveUP(IDirect3DDevice8 *iface,
1947 D3DPRIMITIVETYPE primitive_type, UINT primitive_count, const void *data,
1950 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
1952 UINT vtx_count = vertex_count_from_primitive_count(primitive_type, primitive_count);
1953 UINT size = vtx_count * stride;
1957 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
1958 iface, primitive_type, primitive_count, data, stride);
1960 if (!primitive_count)
1962 WARN("primitive_count is 0, returning D3D_OK\n");
1966 wined3d_mutex_lock();
1967 hr = d3d8_device_prepare_vertex_buffer(device, size);
1971 vb_pos = device->vertex_buffer_pos;
1972 align = vb_pos % stride;
1973 if (align) align = stride - align;
1974 if (vb_pos + size + align > device->vertex_buffer_size)
1979 hr = wined3d_buffer_map(device->vertex_buffer, vb_pos, size, &buffer_data,
1980 vb_pos ? WINED3D_MAP_NOOVERWRITE : WINED3D_MAP_DISCARD);
1983 memcpy(buffer_data, data, size);
1984 wined3d_buffer_unmap(device->vertex_buffer);
1985 device->vertex_buffer_pos = vb_pos + size;
1987 hr = wined3d_device_set_stream_source(device->wined3d_device, 0, device->vertex_buffer, 0, stride);
1991 wined3d_device_set_primitive_type(device->wined3d_device, primitive_type);
1992 hr = wined3d_device_draw_primitive(device->wined3d_device, vb_pos / stride, vtx_count);
1993 wined3d_device_set_stream_source(device->wined3d_device, 0, NULL, 0, 0);
1996 wined3d_mutex_unlock();
2000 /* The caller is responsible for wined3d locking */
2001 static HRESULT d3d8_device_prepare_index_buffer(struct d3d8_device *device, UINT min_size)
2005 if (device->index_buffer_size < min_size || !device->index_buffer)
2007 UINT size = max(device->index_buffer_size * 2, min_size);
2008 struct wined3d_buffer *buffer;
2010 TRACE("Growing index buffer to %u bytes\n", size);
2012 hr = wined3d_buffer_create_ib(device->wined3d_device, size, WINED3DUSAGE_DYNAMIC | WINED3DUSAGE_WRITEONLY,
2013 WINED3D_POOL_DEFAULT, NULL, &d3d8_null_wined3d_parent_ops, &buffer);
2016 ERR("(%p) wined3d_buffer_create_ib failed with hr = %08x\n", device, hr);
2020 if (device->index_buffer)
2021 wined3d_buffer_decref(device->index_buffer);
2023 device->index_buffer = buffer;
2024 device->index_buffer_size = size;
2025 device->index_buffer_pos = 0;
2030 static HRESULT WINAPI d3d8_device_DrawIndexedPrimitiveUP(IDirect3DDevice8 *iface,
2031 D3DPRIMITIVETYPE primitive_type, UINT min_vertex_idx, UINT vertex_count,
2032 UINT primitive_count, const void *index_data, D3DFORMAT index_format,
2033 const void *vertex_data, UINT vertex_stride)
2035 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2039 UINT idx_count = vertex_count_from_primitive_count(primitive_type, primitive_count);
2040 UINT idx_fmt_size = index_format == D3DFMT_INDEX16 ? 2 : 4;
2041 UINT idx_size = idx_count * idx_fmt_size;
2044 UINT vtx_size = vertex_count * vertex_stride;
2047 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, primitive_count %u,\n"
2048 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
2049 iface, primitive_type, min_vertex_idx, vertex_count, primitive_count,
2050 index_data, index_format, vertex_data, vertex_stride);
2052 if (!primitive_count)
2054 WARN("primitive_count is 0, returning D3D_OK\n");
2058 wined3d_mutex_lock();
2060 hr = d3d8_device_prepare_vertex_buffer(device, vtx_size);
2064 vb_pos = device->vertex_buffer_pos;
2065 align = vb_pos % vertex_stride;
2066 if (align) align = vertex_stride - align;
2067 if (vb_pos + vtx_size + align > device->vertex_buffer_size)
2072 hr = wined3d_buffer_map(device->vertex_buffer, vb_pos, vtx_size, &buffer_data,
2073 vb_pos ? WINED3D_MAP_NOOVERWRITE : WINED3D_MAP_DISCARD);
2076 memcpy(buffer_data, vertex_data, vtx_size);
2077 wined3d_buffer_unmap(device->vertex_buffer);
2078 device->vertex_buffer_pos = vb_pos + vtx_size;
2080 hr = d3d8_device_prepare_index_buffer(device, idx_size);
2084 ib_pos = device->index_buffer_pos;
2085 align = ib_pos % idx_fmt_size;
2086 if (align) align = idx_fmt_size - align;
2087 if (ib_pos + idx_size + align > device->index_buffer_size)
2092 hr = wined3d_buffer_map(device->index_buffer, ib_pos, idx_size, &buffer_data,
2093 ib_pos ? WINED3D_MAP_NOOVERWRITE : WINED3D_MAP_DISCARD);
2096 memcpy(buffer_data, index_data, idx_size);
2097 wined3d_buffer_unmap(device->index_buffer);
2098 device->index_buffer_pos = ib_pos + idx_size;
2100 hr = wined3d_device_set_stream_source(device->wined3d_device, 0, device->vertex_buffer, 0, vertex_stride);
2104 wined3d_device_set_index_buffer(device->wined3d_device, device->index_buffer,
2105 wined3dformat_from_d3dformat(index_format));
2106 wined3d_device_set_base_vertex_index(device->wined3d_device, vb_pos / vertex_stride);
2108 wined3d_device_set_primitive_type(device->wined3d_device, primitive_type);
2109 hr = wined3d_device_draw_indexed_primitive(device->wined3d_device, ib_pos / idx_fmt_size, idx_count);
2111 wined3d_device_set_stream_source(device->wined3d_device, 0, NULL, 0, 0);
2112 wined3d_device_set_index_buffer(device->wined3d_device, NULL, WINED3DFMT_UNKNOWN);
2113 wined3d_device_set_base_vertex_index(device->wined3d_device, 0);
2116 wined3d_mutex_unlock();
2120 static HRESULT WINAPI d3d8_device_ProcessVertices(IDirect3DDevice8 *iface, UINT src_start_idx,
2121 UINT dst_idx, UINT vertex_count, IDirect3DVertexBuffer8 *dst_buffer, DWORD flags)
2123 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2124 struct d3d8_vertexbuffer *dst = unsafe_impl_from_IDirect3DVertexBuffer8(dst_buffer);
2127 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, flags %#x.\n",
2128 iface, src_start_idx, dst_idx, vertex_count, dst_buffer, flags);
2130 wined3d_mutex_lock();
2131 hr = wined3d_device_process_vertices(device->wined3d_device, src_start_idx, dst_idx,
2132 vertex_count, dst->wined3d_buffer, NULL, flags, dst->fvf);
2133 wined3d_mutex_unlock();
2138 static HRESULT WINAPI d3d8_device_CreateVertexShader(IDirect3DDevice8 *iface,
2139 const DWORD *declaration, const DWORD *byte_code, DWORD *shader, DWORD usage)
2141 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2142 struct d3d8_vertex_shader *object;
2143 DWORD shader_handle;
2147 TRACE("iface %p, declaration %p, byte_code %p, shader %p, usage %#x.\n",
2148 iface, declaration, byte_code, shader, usage);
2150 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2153 ERR("Failed to allocate vertex shader memory.\n");
2155 return E_OUTOFMEMORY;
2158 wined3d_mutex_lock();
2159 handle = d3d8_allocate_handle(&device->handle_table, object, D3D8_HANDLE_VS);
2160 wined3d_mutex_unlock();
2161 if (handle == D3D8_INVALID_HANDLE)
2163 ERR("Failed to allocate vertex shader handle.\n");
2164 HeapFree(GetProcessHeap(), 0, object);
2166 return E_OUTOFMEMORY;
2169 shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
2171 hr = d3d8_vertex_shader_init(object, device, declaration, byte_code, shader_handle, usage);
2174 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
2175 wined3d_mutex_lock();
2176 d3d8_free_handle(&device->handle_table, handle, D3D8_HANDLE_VS);
2177 wined3d_mutex_unlock();
2178 HeapFree(GetProcessHeap(), 0, object);
2183 TRACE("Created vertex shader %p (handle %#x).\n", object, shader_handle);
2184 *shader = shader_handle;
2189 static struct d3d8_vertex_declaration *d3d8_device_get_fvf_declaration(struct d3d8_device *device, DWORD fvf)
2191 struct d3d8_vertex_declaration *d3d8_declaration;
2192 struct FvfToDecl *convertedDecls = device->decls;
2193 int p, low, high; /* deliberately signed */
2196 TRACE("Searching for declaration for fvf %08x... ", fvf);
2199 high = device->numConvertedDecls - 1;
2202 p = (low + high) >> 1;
2205 if (convertedDecls[p].fvf == fvf)
2207 TRACE("found %p\n", convertedDecls[p].declaration);
2208 return convertedDecls[p].declaration;
2211 if (convertedDecls[p].fvf < fvf)
2216 TRACE("not found. Creating and inserting at position %d.\n", low);
2218 if (!(d3d8_declaration = HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration))))
2220 ERR("Memory allocation failed.\n");
2224 if (FAILED(hr = d3d8_vertex_declaration_init_fvf(d3d8_declaration, device, fvf)))
2226 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
2227 HeapFree(GetProcessHeap(), 0, d3d8_declaration);
2231 if (device->declArraySize == device->numConvertedDecls)
2233 UINT grow = device->declArraySize / 2;
2235 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
2236 sizeof(*convertedDecls) * (device->numConvertedDecls + grow));
2237 if (!convertedDecls)
2239 d3d8_vertex_declaration_destroy(d3d8_declaration);
2242 device->decls = convertedDecls;
2243 device->declArraySize += grow;
2246 memmove(convertedDecls + low + 1, convertedDecls + low,
2247 sizeof(*convertedDecls) * (device->numConvertedDecls - low));
2248 convertedDecls[low].declaration = d3d8_declaration;
2249 convertedDecls[low].fvf = fvf;
2250 ++device->numConvertedDecls;
2252 TRACE("Returning %p. %u decls in array.\n", d3d8_declaration, device->numConvertedDecls);
2254 return d3d8_declaration;
2257 static HRESULT WINAPI d3d8_device_SetVertexShader(IDirect3DDevice8 *iface, DWORD shader)
2259 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2260 struct d3d8_vertex_shader *shader_impl;
2262 TRACE("iface %p, shader %#x.\n", iface, shader);
2264 if (VS_HIGHESTFIXEDFXF >= shader)
2266 TRACE("Setting FVF, %#x\n", shader);
2268 wined3d_mutex_lock();
2269 wined3d_device_set_vertex_declaration(device->wined3d_device,
2270 d3d8_device_get_fvf_declaration(device, shader)->wined3d_vertex_declaration);
2271 wined3d_device_set_vertex_shader(device->wined3d_device, NULL);
2272 wined3d_mutex_unlock();
2277 TRACE("Setting shader\n");
2279 wined3d_mutex_lock();
2280 if (!(shader_impl = d3d8_get_object(&device->handle_table, shader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS)))
2282 WARN("Invalid handle (%#x) passed.\n", shader);
2283 wined3d_mutex_unlock();
2285 return D3DERR_INVALIDCALL;
2288 wined3d_device_set_vertex_declaration(device->wined3d_device,
2289 shader_impl->vertex_declaration->wined3d_vertex_declaration);
2290 wined3d_device_set_vertex_shader(device->wined3d_device, shader_impl->wined3d_shader);
2291 wined3d_mutex_unlock();
2296 static HRESULT WINAPI d3d8_device_GetVertexShader(IDirect3DDevice8 *iface, DWORD *shader)
2298 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2299 struct wined3d_vertex_declaration *wined3d_declaration;
2300 struct d3d8_vertex_declaration *d3d8_declaration;
2302 TRACE("iface %p, shader %p.\n", iface, shader);
2304 wined3d_mutex_lock();
2305 if ((wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
2307 d3d8_declaration = wined3d_vertex_declaration_get_parent(wined3d_declaration);
2308 *shader = d3d8_declaration->shader_handle;
2314 wined3d_mutex_unlock();
2316 TRACE("Returning %#x.\n", *shader);
2321 static HRESULT WINAPI d3d8_device_DeleteVertexShader(IDirect3DDevice8 *iface, DWORD shader)
2323 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2324 struct d3d8_vertex_shader *shader_impl;
2326 TRACE("iface %p, shader %#x.\n", iface, shader);
2328 wined3d_mutex_lock();
2329 if (!(shader_impl = d3d8_free_handle(&device->handle_table, shader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS)))
2331 WARN("Invalid handle (%#x) passed.\n", shader);
2332 wined3d_mutex_unlock();
2334 return D3DERR_INVALIDCALL;
2337 if (shader_impl->wined3d_shader
2338 && wined3d_device_get_vertex_shader(device->wined3d_device) == shader_impl->wined3d_shader)
2339 IDirect3DDevice8_SetVertexShader(iface, 0);
2341 wined3d_mutex_unlock();
2343 d3d8_vertex_shader_destroy(shader_impl);
2348 static HRESULT WINAPI d3d8_device_SetVertexShaderConstant(IDirect3DDevice8 *iface,
2349 DWORD start_register, const void *data, DWORD count)
2351 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2354 TRACE("iface %p, start_register %u, data %p, count %u.\n",
2355 iface, start_register, data, count);
2357 if (start_register + count > D3D8_MAX_VERTEX_SHADER_CONSTANTF)
2359 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2360 start_register + count, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2361 return D3DERR_INVALIDCALL;
2364 wined3d_mutex_lock();
2365 hr = wined3d_device_set_vs_consts_f(device->wined3d_device, start_register, data, count);
2366 wined3d_mutex_unlock();
2371 static HRESULT WINAPI d3d8_device_GetVertexShaderConstant(IDirect3DDevice8 *iface,
2372 DWORD start_register, void *data, DWORD count)
2374 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2377 TRACE("iface %p, start_register %u, data %p, count %u.\n",
2378 iface, start_register, data, count);
2380 if (start_register + count > D3D8_MAX_VERTEX_SHADER_CONSTANTF)
2382 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2383 start_register + count, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2384 return D3DERR_INVALIDCALL;
2387 wined3d_mutex_lock();
2388 hr = wined3d_device_get_vs_consts_f(device->wined3d_device, start_register, data, count);
2389 wined3d_mutex_unlock();
2394 static HRESULT WINAPI d3d8_device_GetVertexShaderDeclaration(IDirect3DDevice8 *iface,
2395 DWORD shader, void *data, DWORD *data_size)
2397 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2398 struct d3d8_vertex_declaration *declaration;
2399 struct d3d8_vertex_shader *shader_impl;
2401 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2402 iface, shader, data, data_size);
2404 wined3d_mutex_lock();
2405 shader_impl = d3d8_get_object(&device->handle_table, shader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2406 wined3d_mutex_unlock();
2410 WARN("Invalid handle (%#x) passed.\n", shader);
2411 return D3DERR_INVALIDCALL;
2413 declaration = shader_impl->vertex_declaration;
2417 *data_size = declaration->elements_size;
2421 /* MSDN claims that if *data_size is smaller than the required size
2422 * we should write the required size and return D3DERR_MOREDATA.
2423 * That's not actually true. */
2424 if (*data_size < declaration->elements_size)
2425 return D3DERR_INVALIDCALL;
2427 memcpy(data, declaration->elements, declaration->elements_size);
2432 static HRESULT WINAPI d3d8_device_GetVertexShaderFunction(IDirect3DDevice8 *iface,
2433 DWORD shader, void *data, DWORD *data_size)
2435 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2436 struct d3d8_vertex_shader *shader_impl = NULL;
2439 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2440 iface, shader, data, data_size);
2442 wined3d_mutex_lock();
2443 if (!(shader_impl = d3d8_get_object(&device->handle_table, shader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS)))
2445 WARN("Invalid handle (%#x) passed.\n", shader);
2446 wined3d_mutex_unlock();
2448 return D3DERR_INVALIDCALL;
2451 if (!shader_impl->wined3d_shader)
2453 wined3d_mutex_unlock();
2458 hr = wined3d_shader_get_byte_code(shader_impl->wined3d_shader, data, data_size);
2459 wined3d_mutex_unlock();
2464 static HRESULT WINAPI d3d8_device_SetIndices(IDirect3DDevice8 *iface,
2465 IDirect3DIndexBuffer8 *buffer, UINT base_vertex_idx)
2467 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2468 struct d3d8_indexbuffer *ib = unsafe_impl_from_IDirect3DIndexBuffer8(buffer);
2470 TRACE("iface %p, buffer %p, base_vertex_idx %u.\n", iface, buffer, base_vertex_idx);
2472 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
2473 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
2474 * vertex buffers can't be created to address them with an index that requires the 32nd bit
2475 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
2478 wined3d_mutex_lock();
2479 wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_idx);
2480 wined3d_device_set_index_buffer(device->wined3d_device,
2481 ib ? ib->wined3d_buffer : NULL,
2482 ib ? ib->format : WINED3DFMT_UNKNOWN);
2483 wined3d_mutex_unlock();
2488 static HRESULT WINAPI d3d8_device_GetIndices(IDirect3DDevice8 *iface,
2489 IDirect3DIndexBuffer8 **buffer, UINT *base_vertex_index)
2491 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2492 enum wined3d_format_id wined3d_format;
2493 struct wined3d_buffer *wined3d_buffer;
2494 struct d3d8_indexbuffer *buffer_impl;
2496 TRACE("iface %p, buffer %p, base_vertex_index %p.\n", iface, buffer, base_vertex_index);
2499 return D3DERR_INVALIDCALL;
2501 /* The case from UINT to INT is safe because d3d8 will never set negative values */
2502 wined3d_mutex_lock();
2503 *base_vertex_index = wined3d_device_get_base_vertex_index(device->wined3d_device);
2504 if ((wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format)))
2506 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2507 *buffer = &buffer_impl->IDirect3DIndexBuffer8_iface;
2508 IDirect3DIndexBuffer8_AddRef(*buffer);
2514 wined3d_mutex_unlock();
2519 static HRESULT WINAPI d3d8_device_CreatePixelShader(IDirect3DDevice8 *iface,
2520 const DWORD *byte_code, DWORD *shader)
2522 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2523 struct d3d8_pixel_shader *object;
2524 DWORD shader_handle;
2528 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2531 return D3DERR_INVALIDCALL;
2533 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2536 ERR("Failed to allocate pixel shader memmory.\n");
2537 return E_OUTOFMEMORY;
2540 wined3d_mutex_lock();
2541 handle = d3d8_allocate_handle(&device->handle_table, object, D3D8_HANDLE_PS);
2542 wined3d_mutex_unlock();
2543 if (handle == D3D8_INVALID_HANDLE)
2545 ERR("Failed to allocate pixel shader handle.\n");
2546 HeapFree(GetProcessHeap(), 0, object);
2547 return E_OUTOFMEMORY;
2550 shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
2552 hr = d3d8_pixel_shader_init(object, device, byte_code, shader_handle);
2555 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
2556 wined3d_mutex_lock();
2557 d3d8_free_handle(&device->handle_table, handle, D3D8_HANDLE_PS);
2558 wined3d_mutex_unlock();
2559 HeapFree(GetProcessHeap(), 0, object);
2564 TRACE("Created pixel shader %p (handle %#x).\n", object, shader_handle);
2565 *shader = shader_handle;
2570 static HRESULT WINAPI d3d8_device_SetPixelShader(IDirect3DDevice8 *iface, DWORD shader)
2572 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2573 struct d3d8_pixel_shader *shader_impl;
2575 TRACE("iface %p, shader %#x.\n", iface, shader);
2577 wined3d_mutex_lock();
2581 wined3d_device_set_pixel_shader(device->wined3d_device, NULL);
2582 wined3d_mutex_unlock();
2586 if (!(shader_impl = d3d8_get_object(&device->handle_table, shader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS)))
2588 WARN("Invalid handle (%#x) passed.\n", shader);
2589 wined3d_mutex_unlock();
2590 return D3DERR_INVALIDCALL;
2593 TRACE("Setting shader %p.\n", shader_impl);
2594 wined3d_device_set_pixel_shader(device->wined3d_device, shader_impl->wined3d_shader);
2595 wined3d_mutex_unlock();
2600 static HRESULT WINAPI d3d8_device_GetPixelShader(IDirect3DDevice8 *iface, DWORD *shader)
2602 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2603 struct wined3d_shader *object;
2605 TRACE("iface %p, shader %p.\n", iface, shader);
2608 return D3DERR_INVALIDCALL;
2610 wined3d_mutex_lock();
2611 if ((object = wined3d_device_get_pixel_shader(device->wined3d_device)))
2613 struct d3d8_pixel_shader *d3d8_shader;
2614 d3d8_shader = wined3d_shader_get_parent(object);
2615 *shader = d3d8_shader->handle;
2621 wined3d_mutex_unlock();
2623 TRACE("Returning %#x.\n", *shader);
2628 static HRESULT WINAPI d3d8_device_DeletePixelShader(IDirect3DDevice8 *iface, DWORD shader)
2630 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2631 struct d3d8_pixel_shader *shader_impl;
2633 TRACE("iface %p, shader %#x.\n", iface, shader);
2635 wined3d_mutex_lock();
2637 if (!(shader_impl = d3d8_free_handle(&device->handle_table, shader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS)))
2639 WARN("Invalid handle (%#x) passed.\n", shader);
2640 wined3d_mutex_unlock();
2641 return D3DERR_INVALIDCALL;
2644 if (wined3d_device_get_pixel_shader(device->wined3d_device) == shader_impl->wined3d_shader)
2645 IDirect3DDevice8_SetPixelShader(iface, 0);
2647 wined3d_mutex_unlock();
2649 d3d8_pixel_shader_destroy(shader_impl);
2654 static HRESULT WINAPI d3d8_device_SetPixelShaderConstant(IDirect3DDevice8 *iface,
2655 DWORD start_register, const void *data, DWORD count)
2657 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2660 TRACE("iface %p, start_register %u, data %p, count %u.\n",
2661 iface, start_register, data, count);
2663 wined3d_mutex_lock();
2664 hr = wined3d_device_set_ps_consts_f(device->wined3d_device, start_register, data, count);
2665 wined3d_mutex_unlock();
2670 static HRESULT WINAPI d3d8_device_GetPixelShaderConstant(IDirect3DDevice8 *iface,
2671 DWORD start_register, void *data, DWORD count)
2673 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2676 TRACE("iface %p, start_register %u, data %p, count %u.\n",
2677 iface, start_register, data, count);
2679 wined3d_mutex_lock();
2680 hr = wined3d_device_get_ps_consts_f(device->wined3d_device, start_register, data, count);
2681 wined3d_mutex_unlock();
2686 static HRESULT WINAPI d3d8_device_GetPixelShaderFunction(IDirect3DDevice8 *iface,
2687 DWORD shader, void *data, DWORD *data_size)
2689 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2690 struct d3d8_pixel_shader *shader_impl = NULL;
2693 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2694 iface, shader, data, data_size);
2696 wined3d_mutex_lock();
2697 if (!(shader_impl = d3d8_get_object(&device->handle_table, shader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS)))
2699 WARN("Invalid handle (%#x) passed.\n", shader);
2700 wined3d_mutex_unlock();
2702 return D3DERR_INVALIDCALL;
2705 hr = wined3d_shader_get_byte_code(shader_impl->wined3d_shader, data, data_size);
2706 wined3d_mutex_unlock();
2711 static HRESULT WINAPI d3d8_device_DrawRectPatch(IDirect3DDevice8 *iface, UINT handle,
2712 const float *segment_count, const D3DRECTPATCH_INFO *patch_info)
2714 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2717 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2718 iface, handle, segment_count, patch_info);
2720 wined3d_mutex_lock();
2721 hr = wined3d_device_draw_rect_patch(device->wined3d_device, handle,
2722 segment_count, (const struct wined3d_rect_patch_info *)patch_info);
2723 wined3d_mutex_unlock();
2728 static HRESULT WINAPI d3d8_device_DrawTriPatch(IDirect3DDevice8 *iface, UINT handle,
2729 const float *segment_count, const D3DTRIPATCH_INFO *patch_info)
2731 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2734 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2735 iface, handle, segment_count, patch_info);
2737 wined3d_mutex_lock();
2738 hr = wined3d_device_draw_tri_patch(device->wined3d_device, handle,
2739 segment_count, (const struct wined3d_tri_patch_info *)patch_info);
2740 wined3d_mutex_unlock();
2745 static HRESULT WINAPI d3d8_device_DeletePatch(IDirect3DDevice8 *iface, UINT handle)
2747 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2750 TRACE("iface %p, handle %#x.\n", iface, handle);
2752 wined3d_mutex_lock();
2753 hr = wined3d_device_delete_patch(device->wined3d_device, handle);
2754 wined3d_mutex_unlock();
2759 static HRESULT WINAPI d3d8_device_SetStreamSource(IDirect3DDevice8 *iface,
2760 UINT stream_idx, IDirect3DVertexBuffer8 *buffer, UINT stride)
2762 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2763 struct d3d8_vertexbuffer *buffer_impl = unsafe_impl_from_IDirect3DVertexBuffer8(buffer);
2766 TRACE("iface %p, stream_idx %u, buffer %p, stride %u.\n",
2767 iface, stream_idx, buffer, stride);
2769 wined3d_mutex_lock();
2770 hr = wined3d_device_set_stream_source(device->wined3d_device, stream_idx,
2771 buffer_impl ? buffer_impl->wined3d_buffer : NULL, 0, stride);
2772 wined3d_mutex_unlock();
2777 static HRESULT WINAPI d3d8_device_GetStreamSource(IDirect3DDevice8 *iface,
2778 UINT stream_idx, IDirect3DVertexBuffer8 **buffer, UINT *stride)
2780 struct d3d8_device *device = impl_from_IDirect3DDevice8(iface);
2781 struct d3d8_vertexbuffer *buffer_impl;
2782 struct wined3d_buffer *wined3d_buffer = NULL;
2785 TRACE("iface %p, stream_idx %u, buffer %p, stride %p.\n",
2786 iface, stream_idx, buffer, stride);
2789 return D3DERR_INVALIDCALL;
2791 wined3d_mutex_lock();
2792 hr = wined3d_device_get_stream_source(device->wined3d_device, stream_idx, &wined3d_buffer, 0, stride);
2793 if (SUCCEEDED(hr) && wined3d_buffer)
2795 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2796 *buffer = &buffer_impl->IDirect3DVertexBuffer8_iface;
2797 IDirect3DVertexBuffer8_AddRef(*buffer);
2798 wined3d_buffer_decref(wined3d_buffer);
2803 ERR("Failed to get wined3d stream source, hr %#x.\n", hr);
2806 wined3d_mutex_unlock();
2811 static const struct IDirect3DDevice8Vtbl d3d8_device_vtbl =
2813 d3d8_device_QueryInterface,
2815 d3d8_device_Release,
2816 d3d8_device_TestCooperativeLevel,
2817 d3d8_device_GetAvailableTextureMem,
2818 d3d8_device_ResourceManagerDiscardBytes,
2819 d3d8_device_GetDirect3D,
2820 d3d8_device_GetDeviceCaps,
2821 d3d8_device_GetDisplayMode,
2822 d3d8_device_GetCreationParameters,
2823 d3d8_device_SetCursorProperties,
2824 d3d8_device_SetCursorPosition,
2825 d3d8_device_ShowCursor,
2826 d3d8_device_CreateAdditionalSwapChain,
2828 d3d8_device_Present,
2829 d3d8_device_GetBackBuffer,
2830 d3d8_device_GetRasterStatus,
2831 d3d8_device_SetGammaRamp,
2832 d3d8_device_GetGammaRamp,
2833 d3d8_device_CreateTexture,
2834 d3d8_device_CreateVolumeTexture,
2835 d3d8_device_CreateCubeTexture,
2836 d3d8_device_CreateVertexBuffer,
2837 d3d8_device_CreateIndexBuffer,
2838 d3d8_device_CreateRenderTarget,
2839 d3d8_device_CreateDepthStencilSurface,
2840 d3d8_device_CreateImageSurface,
2841 d3d8_device_CopyRects,
2842 d3d8_device_UpdateTexture,
2843 d3d8_device_GetFrontBuffer,
2844 d3d8_device_SetRenderTarget,
2845 d3d8_device_GetRenderTarget,
2846 d3d8_device_GetDepthStencilSurface,
2847 d3d8_device_BeginScene,
2848 d3d8_device_EndScene,
2850 d3d8_device_SetTransform,
2851 d3d8_device_GetTransform,
2852 d3d8_device_MultiplyTransform,
2853 d3d8_device_SetViewport,
2854 d3d8_device_GetViewport,
2855 d3d8_device_SetMaterial,
2856 d3d8_device_GetMaterial,
2857 d3d8_device_SetLight,
2858 d3d8_device_GetLight,
2859 d3d8_device_LightEnable,
2860 d3d8_device_GetLightEnable,
2861 d3d8_device_SetClipPlane,
2862 d3d8_device_GetClipPlane,
2863 d3d8_device_SetRenderState,
2864 d3d8_device_GetRenderState,
2865 d3d8_device_BeginStateBlock,
2866 d3d8_device_EndStateBlock,
2867 d3d8_device_ApplyStateBlock,
2868 d3d8_device_CaptureStateBlock,
2869 d3d8_device_DeleteStateBlock,
2870 d3d8_device_CreateStateBlock,
2871 d3d8_device_SetClipStatus,
2872 d3d8_device_GetClipStatus,
2873 d3d8_device_GetTexture,
2874 d3d8_device_SetTexture,
2875 d3d8_device_GetTextureStageState,
2876 d3d8_device_SetTextureStageState,
2877 d3d8_device_ValidateDevice,
2878 d3d8_device_GetInfo,
2879 d3d8_device_SetPaletteEntries,
2880 d3d8_device_GetPaletteEntries,
2881 d3d8_device_SetCurrentTexturePalette,
2882 d3d8_device_GetCurrentTexturePalette,
2883 d3d8_device_DrawPrimitive,
2884 d3d8_device_DrawIndexedPrimitive,
2885 d3d8_device_DrawPrimitiveUP,
2886 d3d8_device_DrawIndexedPrimitiveUP,
2887 d3d8_device_ProcessVertices,
2888 d3d8_device_CreateVertexShader,
2889 d3d8_device_SetVertexShader,
2890 d3d8_device_GetVertexShader,
2891 d3d8_device_DeleteVertexShader,
2892 d3d8_device_SetVertexShaderConstant,
2893 d3d8_device_GetVertexShaderConstant,
2894 d3d8_device_GetVertexShaderDeclaration,
2895 d3d8_device_GetVertexShaderFunction,
2896 d3d8_device_SetStreamSource,
2897 d3d8_device_GetStreamSource,
2898 d3d8_device_SetIndices,
2899 d3d8_device_GetIndices,
2900 d3d8_device_CreatePixelShader,
2901 d3d8_device_SetPixelShader,
2902 d3d8_device_GetPixelShader,
2903 d3d8_device_DeletePixelShader,
2904 d3d8_device_SetPixelShaderConstant,
2905 d3d8_device_GetPixelShaderConstant,
2906 d3d8_device_GetPixelShaderFunction,
2907 d3d8_device_DrawRectPatch,
2908 d3d8_device_DrawTriPatch,
2909 d3d8_device_DeletePatch,
2912 static inline struct d3d8_device *device_from_device_parent(struct wined3d_device_parent *device_parent)
2914 return CONTAINING_RECORD(device_parent, struct d3d8_device, device_parent);
2917 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
2918 struct wined3d_device *device)
2920 TRACE("device_parent %p, device %p\n", device_parent, device);
2923 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
2925 TRACE("device_parent %p.\n", device_parent);
2928 static HRESULT CDECL device_parent_create_texture_surface(struct wined3d_device_parent *device_parent,
2929 void *container_parent, UINT width, UINT height, enum wined3d_format_id format, DWORD usage,
2930 enum wined3d_pool pool, UINT sub_resource_idx, struct wined3d_surface **surface)
2932 struct d3d8_device *device = device_from_device_parent(device_parent);
2933 struct d3d8_surface *d3d_surface;
2934 BOOL lockable = TRUE;
2937 TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
2938 "\tpool %#x, sub_resource_idx %u, surface %p.\n",
2939 device_parent, container_parent, width, height, format, usage, pool, sub_resource_idx, surface);
2942 if (pool == WINED3D_POOL_DEFAULT && !(usage & WINED3DUSAGE_DYNAMIC))
2945 if (FAILED(hr = d3d8_device_create_surface(device, width, height, d3dformat_from_wined3dformat(format),
2946 lockable, FALSE, (IDirect3DSurface8 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0)))
2948 WARN("Failed to create surface, hr %#x.\n", hr);
2952 *surface = d3d_surface->wined3d_surface;
2953 wined3d_surface_incref(*surface);
2955 d3d_surface->container = container_parent;
2956 IDirect3DDevice8_Release(d3d_surface->parent_device);
2957 d3d_surface->parent_device = NULL;
2959 IDirect3DSurface8_Release(&d3d_surface->IDirect3DSurface8_iface);
2960 d3d_surface->forwardReference = container_parent;
2965 static HRESULT CDECL device_parent_create_swapchain_surface(struct wined3d_device_parent *device_parent,
2966 void *container_parent, UINT width, UINT height, enum wined3d_format_id format_id, DWORD usage,
2967 enum wined3d_multisample_type multisample_type, DWORD multisample_quality, struct wined3d_surface **surface)
2969 struct d3d8_device *device = device_from_device_parent(device_parent);
2970 struct d3d8_surface *d3d_surface;
2973 TRACE("device_parent %p, container_parent %p, width %u, height %u, format_id %#x, usage %#x,\n"
2974 "\tmultisample_type %#x, multisample_quality %u, surface %p.\n",
2975 device_parent, container_parent, width, height, format_id, usage,
2976 multisample_type, multisample_quality, surface);
2978 if (FAILED(hr = d3d8_device_create_surface(device, width, height, d3dformat_from_wined3dformat(format_id),
2979 TRUE, FALSE, (IDirect3DSurface8 **)&d3d_surface, usage, D3DPOOL_DEFAULT, multisample_type,
2980 multisample_quality)))
2982 WARN("Failed to create surface, hr %#x.\n", hr);
2986 *surface = d3d_surface->wined3d_surface;
2987 wined3d_surface_incref(*surface);
2989 d3d_surface->container = (IUnknown *)&device->IDirect3DDevice8_iface;
2990 /* Implicit surfaces are created with an refcount of 0 */
2991 IDirect3DSurface8_Release(&d3d_surface->IDirect3DSurface8_iface);
2996 static HRESULT CDECL device_parent_create_volume(struct wined3d_device_parent *device_parent,
2997 void *container_parent, UINT width, UINT height, UINT depth, enum wined3d_format_id format,
2998 enum wined3d_pool pool, DWORD usage, struct wined3d_volume **volume)
3000 struct d3d8_device *device = device_from_device_parent(device_parent);
3001 struct d3d8_volume *object;
3004 TRACE("device_parent %p, container_parent %p, width %u, height %u, depth %u, "
3005 "format %#x, pool %#x, usage %#x, volume %p.\n",
3006 device_parent, container_parent, width, height, depth,
3007 format, pool, usage, volume);
3009 /* Allocate the storage for the device */
3010 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
3013 FIXME("Allocation of memory failed\n");
3015 return D3DERR_OUTOFVIDEOMEMORY;
3018 hr = volume_init(object, device, width, height, depth, usage, format, pool);
3021 WARN("Failed to initialize volume, hr %#x.\n", hr);
3022 HeapFree(GetProcessHeap(), 0, object);
3026 *volume = object->wined3d_volume;
3027 wined3d_volume_incref(*volume);
3028 IDirect3DVolume8_Release(&object->IDirect3DVolume8_iface);
3030 object->container = container_parent;
3031 object->forwardReference = container_parent;
3033 TRACE("Created volume %p.\n", object);
3038 static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent *device_parent,
3039 struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain)
3041 struct d3d8_device *device = device_from_device_parent(device_parent);
3042 struct d3d8_swapchain *d3d_swapchain;
3045 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent, desc, swapchain);
3047 if (FAILED(hr = d3d8_swapchain_create(device, desc, &d3d_swapchain)))
3049 WARN("Failed to create swapchain, hr %#x.\n", hr);
3054 *swapchain = d3d_swapchain->wined3d_swapchain;
3055 wined3d_swapchain_incref(*swapchain);
3056 IDirect3DSwapChain8_Release(&d3d_swapchain->IDirect3DSwapChain8_iface);
3061 static const struct wined3d_device_parent_ops d3d8_wined3d_device_parent_ops =
3063 device_parent_wined3d_device_created,
3064 device_parent_mode_changed,
3065 device_parent_create_swapchain_surface,
3066 device_parent_create_texture_surface,
3067 device_parent_create_volume,
3068 device_parent_create_swapchain,
3071 static void setup_fpu(void)
3073 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3075 __asm__ volatile ("fnstcw %0" : "=m" (cw));
3076 cw = (cw & ~0xf3f) | 0x3f;
3077 __asm__ volatile ("fldcw %0" : : "m" (cw));
3078 #elif defined(__i386__) && defined(_MSC_VER)
3081 cw = (cw & ~0xf3f) | 0x3f;
3084 FIXME("FPU setup not implemented for this platform.\n");
3088 HRESULT device_init(struct d3d8_device *device, struct d3d8 *parent, struct wined3d *wined3d, UINT adapter,
3089 D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters)
3091 struct wined3d_swapchain_desc swapchain_desc;
3094 device->IDirect3DDevice8_iface.lpVtbl = &d3d8_device_vtbl;
3095 device->device_parent.ops = &d3d8_wined3d_device_parent_ops;
3097 device->handle_table.entries = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
3098 D3D8_INITIAL_HANDLE_TABLE_SIZE * sizeof(*device->handle_table.entries));
3099 if (!device->handle_table.entries)
3101 ERR("Failed to allocate handle table memory.\n");
3102 return E_OUTOFMEMORY;
3104 device->handle_table.table_size = D3D8_INITIAL_HANDLE_TABLE_SIZE;
3106 if (!(flags & D3DCREATE_FPU_PRESERVE)) setup_fpu();
3108 wined3d_mutex_lock();
3109 hr = wined3d_device_create(wined3d, adapter, device_type, focus_window, flags, 4,
3110 &device->device_parent, &device->wined3d_device);
3113 WARN("Failed to create wined3d device, hr %#x.\n", hr);
3114 wined3d_mutex_unlock();
3115 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
3119 if (!parameters->Windowed)
3121 HWND device_window = parameters->hDeviceWindow;
3124 focus_window = device_window;
3125 if (FAILED(hr = wined3d_device_acquire_focus_window(device->wined3d_device, focus_window)))
3127 ERR("Failed to acquire focus window, hr %#x.\n", hr);
3128 wined3d_device_decref(device->wined3d_device);
3129 wined3d_mutex_unlock();
3130 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
3135 device_window = focus_window;
3136 wined3d_device_setup_fullscreen_window(device->wined3d_device, device_window,
3137 parameters->BackBufferWidth,
3138 parameters->BackBufferHeight);
3141 if (flags & D3DCREATE_MULTITHREADED)
3142 wined3d_device_set_multithreaded(device->wined3d_device);
3144 wined3d_swapchain_desc_from_present_parameters(&swapchain_desc, parameters);
3146 hr = wined3d_device_init_3d(device->wined3d_device, &swapchain_desc);
3149 WARN("Failed to initialize 3D, hr %#x.\n", hr);
3150 wined3d_device_release_focus_window(device->wined3d_device);
3151 wined3d_device_decref(device->wined3d_device);
3152 wined3d_mutex_unlock();
3153 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
3157 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_POINTSIZE_MIN, 0);
3158 wined3d_mutex_unlock();
3160 present_parameters_from_wined3d_swapchain_desc(parameters, &swapchain_desc);
3162 device->declArraySize = 16;
3163 device->decls = HeapAlloc(GetProcessHeap(), 0, device->declArraySize * sizeof(*device->decls));
3166 ERR("Failed to allocate FVF vertex declaration map memory.\n");
3171 device->d3d_parent = &parent->IDirect3D8_iface;
3172 IDirect3D8_AddRef(device->d3d_parent);
3177 wined3d_mutex_lock();
3178 wined3d_device_uninit_3d(device->wined3d_device);
3179 wined3d_device_release_focus_window(device->wined3d_device);
3180 wined3d_device_decref(device->wined3d_device);
3181 wined3d_mutex_unlock();
3182 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);