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 /* Handle table functions */
168 static DWORD d3d8_allocate_handle(struct d3d8_handle_table *t, void *object, enum d3d8_handle_type type)
170 struct d3d8_handle_entry *entry;
174 DWORD index = t->free_entries - t->entries;
175 /* Use a free handle */
176 entry = t->free_entries;
177 if (entry->type != D3D8_HANDLE_FREE)
179 ERR("Handle %u(%p) is in the free list, but has type %#x.\n", index, entry, entry->type);
180 return D3D8_INVALID_HANDLE;
182 t->free_entries = entry->object;
183 entry->object = object;
189 if (!(t->entry_count < t->table_size))
192 UINT new_size = t->table_size + (t->table_size >> 1);
193 struct d3d8_handle_entry *new_entries = HeapReAlloc(GetProcessHeap(),
194 0, t->entries, new_size * sizeof(*t->entries));
197 ERR("Failed to grow the handle table.\n");
198 return D3D8_INVALID_HANDLE;
200 t->entries = new_entries;
201 t->table_size = new_size;
204 entry = &t->entries[t->entry_count];
205 entry->object = object;
208 return t->entry_count++;
211 static void *d3d8_free_handle(struct d3d8_handle_table *t, DWORD handle, enum d3d8_handle_type type)
213 struct d3d8_handle_entry *entry;
216 if (handle == D3D8_INVALID_HANDLE || handle >= t->entry_count)
218 WARN("Invalid handle %u passed.\n", handle);
222 entry = &t->entries[handle];
223 if (entry->type != type)
225 WARN("Handle %u(%p) is not of type %#x.\n", handle, entry, type);
229 object = entry->object;
230 entry->object = t->free_entries;
231 entry->type = D3D8_HANDLE_FREE;
232 t->free_entries = entry;
237 static void *d3d8_get_object(struct d3d8_handle_table *t, DWORD handle, enum d3d8_handle_type type)
239 struct d3d8_handle_entry *entry;
241 if (handle == D3D8_INVALID_HANDLE || handle >= t->entry_count)
243 WARN("Invalid handle %u passed.\n", handle);
247 entry = &t->entries[handle];
248 if (entry->type != type)
250 WARN("Handle %u(%p) is not of type %#x.\n", handle, entry, type);
254 return entry->object;
257 static inline IDirect3DDevice8Impl *impl_from_IDirect3DDevice8(IDirect3DDevice8 *iface)
259 return CONTAINING_RECORD(iface, IDirect3DDevice8Impl, IDirect3DDevice8_iface);
262 static HRESULT WINAPI IDirect3DDevice8Impl_QueryInterface(IDirect3DDevice8 *iface, REFIID riid,
265 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
267 TRACE("iface %p, riid %s, object %p.\n",
268 iface, debugstr_guid(riid), ppobj);
270 if (IsEqualGUID(riid, &IID_IUnknown)
271 || IsEqualGUID(riid, &IID_IDirect3DDevice8)) {
272 IUnknown_AddRef(iface);
277 if (IsEqualGUID(riid, &IID_IWineD3DDeviceParent))
279 IWineD3DDeviceParent_AddRef(&This->IWineD3DDeviceParent_iface);
280 *ppobj = &This->IWineD3DDeviceParent_iface;
284 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
286 return E_NOINTERFACE;
289 static ULONG WINAPI IDirect3DDevice8Impl_AddRef(IDirect3DDevice8 *iface)
291 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
292 ULONG ref = InterlockedIncrement(&This->ref);
294 TRACE("%p increasing refcount to %u.\n", iface, ref);
299 static ULONG WINAPI IDirect3DDevice8Impl_Release(IDirect3DDevice8 *iface)
301 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
304 if (This->inDestruction) return 0;
305 ref = InterlockedDecrement(&This->ref);
307 TRACE("%p decreasing refcount to %u.\n", iface, ref);
312 TRACE("Releasing wined3d device %p.\n", This->wined3d_device);
314 wined3d_mutex_lock();
316 This->inDestruction = TRUE;
318 for(i = 0; i < This->numConvertedDecls; i++) {
319 IDirect3DVertexDeclaration8_Release(This->decls[i].decl);
321 HeapFree(GetProcessHeap(), 0, This->decls);
323 wined3d_device_uninit_3d(This->wined3d_device);
324 wined3d_device_release_focus_window(This->wined3d_device);
325 wined3d_device_decref(This->wined3d_device);
326 HeapFree(GetProcessHeap(), 0, This->handle_table.entries);
327 HeapFree(GetProcessHeap(), 0, This);
329 wined3d_mutex_unlock();
334 /* IDirect3DDevice Interface follow: */
335 static HRESULT WINAPI IDirect3DDevice8Impl_TestCooperativeLevel(IDirect3DDevice8 *iface)
337 IDirect3DDevice8Impl *device = impl_from_IDirect3DDevice8(iface);
339 TRACE("iface %p.\n", iface);
343 TRACE("Device is lost.\n");
344 return D3DERR_DEVICENOTRESET;
350 static UINT WINAPI IDirect3DDevice8Impl_GetAvailableTextureMem(IDirect3DDevice8 *iface)
352 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
355 TRACE("iface %p.\n", iface);
357 wined3d_mutex_lock();
358 hr = wined3d_device_get_available_texture_mem(This->wined3d_device);
359 wined3d_mutex_unlock();
364 static HRESULT WINAPI IDirect3DDevice8Impl_ResourceManagerDiscardBytes(IDirect3DDevice8 *iface,
367 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
370 TRACE("iface %p, byte_count %u.\n", iface, Bytes);
371 FIXME("Byte count ignored.\n");
373 wined3d_mutex_lock();
374 hr = wined3d_device_evict_managed_resources(This->wined3d_device);
375 wined3d_mutex_unlock();
380 static HRESULT WINAPI IDirect3DDevice8Impl_GetDirect3D(IDirect3DDevice8 *iface, IDirect3D8 **ppD3D8)
382 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
383 struct wined3d *wined3d;
386 TRACE("iface %p, d3d8 %p.\n", iface, ppD3D8);
388 if (NULL == ppD3D8) {
389 return D3DERR_INVALIDCALL;
392 wined3d_mutex_lock();
393 hr = wined3d_device_get_wined3d(This->wined3d_device, &wined3d);
394 if (SUCCEEDED(hr) && wined3d)
396 *ppD3D8 = wined3d_get_parent(wined3d);
397 IDirect3D8_AddRef(*ppD3D8);
398 wined3d_decref(wined3d);
402 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
405 wined3d_mutex_unlock();
407 TRACE("(%p) returning %p\n",This , *ppD3D8);
412 static HRESULT WINAPI IDirect3DDevice8Impl_GetDeviceCaps(IDirect3DDevice8 *iface, D3DCAPS8 *pCaps)
414 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
415 HRESULT hrc = D3D_OK;
416 WINED3DCAPS *pWineCaps;
418 TRACE("iface %p, caps %p.\n", iface, pCaps);
421 return D3DERR_INVALIDCALL;
423 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
424 if(pWineCaps == NULL){
425 return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
428 wined3d_mutex_lock();
429 hrc = wined3d_device_get_device_caps(This->wined3d_device, pWineCaps);
430 wined3d_mutex_unlock();
432 fixup_caps(pWineCaps);
433 WINECAPSTOD3D8CAPS(pCaps, pWineCaps)
434 HeapFree(GetProcessHeap(), 0, pWineCaps);
436 TRACE("Returning %p %p\n", This, pCaps);
440 static HRESULT WINAPI IDirect3DDevice8Impl_GetDisplayMode(IDirect3DDevice8 *iface,
441 D3DDISPLAYMODE *pMode)
443 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
446 TRACE("iface %p, mode %p.\n", iface, pMode);
448 wined3d_mutex_lock();
449 hr = wined3d_device_get_display_mode(This->wined3d_device, 0, (WINED3DDISPLAYMODE *)pMode);
450 wined3d_mutex_unlock();
452 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
457 static HRESULT WINAPI IDirect3DDevice8Impl_GetCreationParameters(IDirect3DDevice8 *iface,
458 D3DDEVICE_CREATION_PARAMETERS *pParameters)
460 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
463 TRACE("iface %p, parameters %p.\n", iface, pParameters);
465 wined3d_mutex_lock();
466 hr = wined3d_device_get_creation_parameters(This->wined3d_device,
467 (WINED3DDEVICE_CREATION_PARAMETERS *)pParameters);
468 wined3d_mutex_unlock();
473 static HRESULT WINAPI IDirect3DDevice8Impl_SetCursorProperties(IDirect3DDevice8 *iface,
474 UINT XHotSpot, UINT YHotSpot, IDirect3DSurface8 *pCursorBitmap)
476 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
477 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl*)pCursorBitmap;
480 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
481 iface, XHotSpot, YHotSpot, pCursorBitmap);
485 WARN("No cursor bitmap, returning D3DERR_INVALIDCALL.\n");
486 return D3DERR_INVALIDCALL;
489 wined3d_mutex_lock();
490 hr = wined3d_device_set_cursor_properties(This->wined3d_device, XHotSpot, YHotSpot, pSurface->wined3d_surface);
491 wined3d_mutex_unlock();
496 static void WINAPI IDirect3DDevice8Impl_SetCursorPosition(IDirect3DDevice8 *iface,
497 UINT XScreenSpace, UINT YScreenSpace, DWORD Flags)
499 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
501 TRACE("iface %p, x %u, y %u, flags %#x.\n",
502 iface, XScreenSpace, YScreenSpace, Flags);
504 wined3d_mutex_lock();
505 wined3d_device_set_cursor_position(This->wined3d_device, XScreenSpace, YScreenSpace, Flags);
506 wined3d_mutex_unlock();
509 static BOOL WINAPI IDirect3DDevice8Impl_ShowCursor(IDirect3DDevice8 *iface, BOOL bShow)
511 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
514 TRACE("iface %p, show %#x.\n", iface, bShow);
516 wined3d_mutex_lock();
517 ret = wined3d_device_show_cursor(This->wined3d_device, bShow);
518 wined3d_mutex_unlock();
523 static HRESULT WINAPI IDirect3DDevice8Impl_CreateAdditionalSwapChain(IDirect3DDevice8 *iface,
524 D3DPRESENT_PARAMETERS *present_parameters, IDirect3DSwapChain8 **swapchain)
526 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
527 IDirect3DSwapChain8Impl *object;
530 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
531 iface, present_parameters, swapchain);
533 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
536 ERR("Failed to allocate swapchain memory.\n");
537 return E_OUTOFMEMORY;
540 hr = swapchain_init(object, This, present_parameters);
543 WARN("Failed to initialize swapchain, hr %#x.\n", hr);
544 HeapFree(GetProcessHeap(), 0, object);
548 TRACE("Created swapchain %p.\n", object);
549 *swapchain = &object->IDirect3DSwapChain8_iface;
554 static HRESULT WINAPI reset_enum_callback(struct wined3d_resource *resource, void *data)
556 struct wined3d_resource_desc desc;
557 BOOL *resources_ok = data;
559 wined3d_resource_get_desc(resource, &desc);
560 if (desc.pool == WINED3DPOOL_DEFAULT)
562 IDirect3DSurface8 *surface;
564 if (desc.resource_type != WINED3DRTYPE_SURFACE)
566 WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource);
567 *resources_ok = FALSE;
571 surface = wined3d_resource_get_parent(resource);
573 IDirect3DSurface8_AddRef(surface);
574 if (IDirect3DSurface8_Release(surface))
576 WARN("Surface %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface, resource);
577 *resources_ok = FALSE;
581 WARN("Surface %p (resource %p) is an implicit resource with ref 0.\n", surface, resource);
587 static HRESULT WINAPI IDirect3DDevice8Impl_Reset(IDirect3DDevice8 *iface,
588 D3DPRESENT_PARAMETERS *pPresentationParameters)
590 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
591 WINED3DPRESENT_PARAMETERS localParameters;
592 BOOL resources_ok = TRUE;
596 TRACE("iface %p, present_parameters %p.\n", iface, pPresentationParameters);
598 wined3d_mutex_lock();
599 wined3d_device_set_index_buffer(This->wined3d_device, NULL, WINED3DFMT_UNKNOWN);
600 for (i = 0; i < 16; ++i)
602 wined3d_device_set_stream_source(This->wined3d_device, i, NULL, 0, 0);
604 for (i = 0; i < 16; ++i)
606 wined3d_device_set_texture(This->wined3d_device, i, NULL);
609 wined3d_device_enum_resources(This->wined3d_device, reset_enum_callback, &resources_ok);
612 WARN("The application is holding D3DPOOL_DEFAULT resources, rejecting reset.\n");
614 wined3d_mutex_unlock();
616 return D3DERR_DEVICELOST;
619 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
620 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
621 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
622 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
623 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
624 localParameters.MultiSampleQuality = 0; /* d3d9 only */
625 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
626 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
627 localParameters.Windowed = pPresentationParameters->Windowed;
628 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
629 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
630 localParameters.Flags = pPresentationParameters->Flags;
631 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
632 localParameters.PresentationInterval = pPresentationParameters->FullScreen_PresentationInterval;
633 localParameters.AutoRestoreDisplayMode = TRUE;
635 hr = wined3d_device_reset(This->wined3d_device, &localParameters);
638 hr = wined3d_device_set_render_state(This->wined3d_device, WINED3DRS_POINTSIZE_MIN, 0);
645 wined3d_mutex_unlock();
647 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
648 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
649 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
650 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
651 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
652 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
653 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
654 pPresentationParameters->Windowed = localParameters.Windowed;
655 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
656 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
657 pPresentationParameters->Flags = localParameters.Flags;
658 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
659 pPresentationParameters->FullScreen_PresentationInterval = localParameters.PresentationInterval;
664 static HRESULT WINAPI IDirect3DDevice8Impl_Present(IDirect3DDevice8 *iface, const RECT *pSourceRect,
665 const RECT *pDestRect, HWND hDestWindowOverride, const RGNDATA *pDirtyRegion)
667 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
670 TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
671 iface, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
673 wined3d_mutex_lock();
674 hr = wined3d_device_present(This->wined3d_device, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
675 wined3d_mutex_unlock();
680 static HRESULT WINAPI IDirect3DDevice8Impl_GetBackBuffer(IDirect3DDevice8 *iface,
681 UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8 **ppBackBuffer)
683 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
684 struct wined3d_surface *wined3d_surface = NULL;
687 TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
688 iface, BackBuffer, Type, ppBackBuffer);
690 wined3d_mutex_lock();
691 hr = wined3d_device_get_back_buffer(This->wined3d_device, 0,
692 BackBuffer, (WINED3DBACKBUFFER_TYPE)Type, &wined3d_surface);
693 if (SUCCEEDED(hr) && wined3d_surface && ppBackBuffer)
695 *ppBackBuffer = wined3d_surface_get_parent(wined3d_surface);
696 IDirect3DSurface8_AddRef(*ppBackBuffer);
697 wined3d_surface_decref(wined3d_surface);
699 wined3d_mutex_unlock();
704 static HRESULT WINAPI IDirect3DDevice8Impl_GetRasterStatus(IDirect3DDevice8 *iface,
705 D3DRASTER_STATUS *pRasterStatus)
707 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
710 TRACE("iface %p, raster_status %p.\n", iface, pRasterStatus);
712 wined3d_mutex_lock();
713 hr = wined3d_device_get_raster_status(This->wined3d_device, 0, (WINED3DRASTER_STATUS *)pRasterStatus);
714 wined3d_mutex_unlock();
719 static void WINAPI IDirect3DDevice8Impl_SetGammaRamp(IDirect3DDevice8 *iface, DWORD Flags,
720 const D3DGAMMARAMP *pRamp)
722 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
724 TRACE("iface %p, flags %#x, ramp %p.\n", iface, Flags, pRamp);
726 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
727 wined3d_mutex_lock();
728 wined3d_device_set_gamma_ramp(This->wined3d_device, 0, Flags, (const WINED3DGAMMARAMP *)pRamp);
729 wined3d_mutex_unlock();
732 static void WINAPI IDirect3DDevice8Impl_GetGammaRamp(IDirect3DDevice8 *iface, D3DGAMMARAMP *pRamp)
734 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
736 TRACE("iface %p, ramp %p.\n", iface, pRamp);
738 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
739 wined3d_mutex_lock();
740 wined3d_device_get_gamma_ramp(This->wined3d_device, 0, (WINED3DGAMMARAMP *)pRamp);
741 wined3d_mutex_unlock();
744 static HRESULT WINAPI IDirect3DDevice8Impl_CreateTexture(IDirect3DDevice8 *iface,
745 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
746 D3DPOOL pool, IDirect3DTexture8 **texture)
748 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
749 IDirect3DTexture8Impl *object;
752 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
753 iface, width, height, levels, usage, format, pool, texture);
755 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
758 ERR("Failed to allocate texture memory.\n");
759 return D3DERR_OUTOFVIDEOMEMORY;
762 hr = texture_init(object, This, width, height, levels, usage, format, pool);
765 WARN("Failed to initialize texture, hr %#x.\n", hr);
766 HeapFree(GetProcessHeap(), 0, object);
770 TRACE("Created texture %p.\n", object);
771 *texture = &object->IDirect3DTexture8_iface;
776 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVolumeTexture(IDirect3DDevice8 *iface,
777 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
778 D3DPOOL pool, IDirect3DVolumeTexture8 **texture)
780 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
781 IDirect3DVolumeTexture8Impl *object;
784 TRACE("iface %p, width %u, height %u, depth %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
785 iface, width, height, depth, levels, usage, format, pool, texture);
787 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
790 ERR("Failed to allocate volume texture memory.\n");
791 return D3DERR_OUTOFVIDEOMEMORY;
794 hr = volumetexture_init(object, This, width, height, depth, levels, usage, format, pool);
797 WARN("Failed to initialize volume texture, hr %#x.\n", hr);
798 HeapFree(GetProcessHeap(), 0, object);
802 TRACE("Created volume texture %p.\n", object);
803 *texture = &object->IDirect3DVolumeTexture8_iface;
808 static HRESULT WINAPI IDirect3DDevice8Impl_CreateCubeTexture(IDirect3DDevice8 *iface, UINT edge_length,
809 UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool, IDirect3DCubeTexture8 **texture)
811 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
812 IDirect3DCubeTexture8Impl *object;
815 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
816 iface, edge_length, levels, usage, format, pool, texture);
818 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
821 ERR("Failed to allocate cube texture memory.\n");
822 return D3DERR_OUTOFVIDEOMEMORY;
825 hr = cubetexture_init(object, This, edge_length, levels, usage, format, pool);
828 WARN("Failed to initialize cube texture, hr %#x.\n", hr);
829 HeapFree(GetProcessHeap(), 0, object);
833 TRACE("Created cube texture %p.\n", object);
834 *texture = &object->IDirect3DCubeTexture8_iface;
839 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexBuffer(IDirect3DDevice8 *iface, UINT size,
840 DWORD usage, DWORD fvf, D3DPOOL pool, IDirect3DVertexBuffer8 **buffer)
842 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
843 IDirect3DVertexBuffer8Impl *object;
846 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p.\n",
847 iface, size, usage, fvf, 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 = vertexbuffer_init(object, This, size, usage, fvf, pool);
859 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr);
860 HeapFree(GetProcessHeap(), 0, object);
864 TRACE("Created vertex buffer %p.\n", object);
865 *buffer = (IDirect3DVertexBuffer8 *)object;
870 static HRESULT WINAPI IDirect3DDevice8Impl_CreateIndexBuffer(IDirect3DDevice8 *iface, UINT size,
871 DWORD usage, D3DFORMAT format, D3DPOOL pool, IDirect3DIndexBuffer8 **buffer)
873 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
874 IDirect3DIndexBuffer8Impl *object;
877 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p.\n",
878 iface, size, usage, format, pool, buffer);
880 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
883 ERR("Failed to allocate buffer memory.\n");
884 return D3DERR_OUTOFVIDEOMEMORY;
887 hr = indexbuffer_init(object, This, size, usage, format, pool);
890 WARN("Failed to initialize index buffer, hr %#x.\n", hr);
891 HeapFree(GetProcessHeap(), 0, object);
895 TRACE("Created index buffer %p.\n", object);
896 *buffer = (IDirect3DIndexBuffer8 *)object;
901 static HRESULT IDirect3DDevice8Impl_CreateSurface(IDirect3DDevice8Impl *device, UINT Width,
902 UINT Height, D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level,
903 IDirect3DSurface8 **ppSurface, UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample,
904 DWORD MultisampleQuality)
906 IDirect3DSurface8Impl *object;
909 TRACE("device %p, width %u, height %u, format %#x, lockable %#x, discard %#x, level %u, surface %p,\n"
910 "\tusage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
911 device, Width, Height, Format, Lockable, Discard, Level, ppSurface,
912 Usage, Pool, MultiSample, MultisampleQuality);
914 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface8Impl));
917 FIXME("Failed to allocate surface memory.\n");
918 return D3DERR_OUTOFVIDEOMEMORY;
921 hr = surface_init(object, device, Width, Height, Format, Lockable, Discard, Level, Usage,
922 Pool, MultiSample, MultisampleQuality);
925 WARN("Failed to initialize surface, hr %#x.\n", hr);
926 HeapFree(GetProcessHeap(), 0, object);
930 TRACE("Created surface %p.\n", object);
931 *ppSurface = (IDirect3DSurface8 *)object;
936 static HRESULT WINAPI IDirect3DDevice8Impl_CreateRenderTarget(IDirect3DDevice8 *iface, UINT Width,
937 UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, BOOL Lockable,
938 IDirect3DSurface8 **ppSurface)
940 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
943 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, lockable %#x, surface %p.\n",
944 iface, Width, Height, Format, MultiSample, Lockable, ppSurface);
946 hr = IDirect3DDevice8Impl_CreateSurface(This, Width, Height, Format, Lockable,
947 FALSE /* Discard */, 0 /* Level */, ppSurface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT,
953 static HRESULT WINAPI IDirect3DDevice8Impl_CreateDepthStencilSurface(IDirect3DDevice8 *iface,
954 UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample,
955 IDirect3DSurface8 **ppSurface)
957 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
960 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, surface %p.\n",
961 iface, Width, Height, Format, MultiSample, ppSurface);
963 /* TODO: Verify that Discard is false */
964 hr = IDirect3DDevice8Impl_CreateSurface(This, Width, Height, Format, TRUE /* Lockable */, FALSE,
965 0 /* Level */, ppSurface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, MultiSample, 0);
970 /* IDirect3DDevice8Impl::CreateImageSurface returns surface with pool type SYSTEMMEM */
971 static HRESULT WINAPI IDirect3DDevice8Impl_CreateImageSurface(IDirect3DDevice8 *iface, UINT Width,
972 UINT Height, D3DFORMAT Format, IDirect3DSurface8 **ppSurface)
974 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
977 TRACE("iface %p, width %u, height %u, format %#x, surface %p.\n",
978 iface, Width, Height, Format, ppSurface);
980 hr = IDirect3DDevice8Impl_CreateSurface(This, Width, Height, Format, TRUE /* Lockable */,
981 FALSE /* Discard */, 0 /* Level */, ppSurface, 0 /* Usage (undefined/none) */,
982 D3DPOOL_SYSTEMMEM, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
987 static HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(IDirect3DDevice8 *iface,
988 IDirect3DSurface8 *pSourceSurface, const RECT *pSourceRects, UINT cRects,
989 IDirect3DSurface8 *pDestinationSurface, const POINT *pDestPoints)
991 IDirect3DSurface8Impl *Source = (IDirect3DSurface8Impl *) pSourceSurface;
992 IDirect3DSurface8Impl *Dest = (IDirect3DSurface8Impl *) pDestinationSurface;
993 enum wined3d_format_id srcFormat, destFormat;
994 struct wined3d_resource_desc wined3d_desc;
995 struct wined3d_resource *wined3d_resource;
997 TRACE("iface %p, src_surface %p, src_rects %p, rect_count %u, dst_surface %p, dst_points %p.\n",
998 iface, pSourceSurface, pSourceRects, cRects, pDestinationSurface, pDestPoints);
1000 /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the
1001 * destination texture is in WINED3DPOOL_DEFAULT. */
1003 wined3d_mutex_lock();
1004 wined3d_resource = wined3d_surface_get_resource(Source->wined3d_surface);
1005 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
1006 srcFormat = wined3d_desc.format;
1008 wined3d_resource = wined3d_surface_get_resource(Dest->wined3d_surface);
1009 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
1010 destFormat = wined3d_desc.format;
1012 /* Check that the source and destination formats match */
1013 if (srcFormat != destFormat && WINED3DFMT_UNKNOWN != destFormat)
1015 WARN("Source %p format must match the dest %p format, returning D3DERR_INVALIDCALL.\n",
1016 pSourceSurface, pDestinationSurface);
1017 wined3d_mutex_unlock();
1018 return D3DERR_INVALIDCALL;
1020 else if (WINED3DFMT_UNKNOWN == destFormat)
1022 TRACE("(%p) : Converting destination surface from WINED3DFMT_UNKNOWN to the source format\n", iface);
1023 wined3d_surface_set_format(Dest->wined3d_surface, srcFormat);
1026 /* Quick if complete copy ... */
1027 if (!cRects && !pSourceRects && !pDestPoints)
1029 wined3d_surface_bltfast(Dest->wined3d_surface, 0, 0,
1030 Source->wined3d_surface, NULL, WINEDDBLTFAST_NOCOLORKEY);
1035 /* Copy rect by rect */
1036 if (pSourceRects && pDestPoints)
1038 for (i = 0; i < cRects; ++i)
1040 wined3d_surface_bltfast(Dest->wined3d_surface, pDestPoints[i].x, pDestPoints[i].y,
1041 Source->wined3d_surface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
1046 for (i = 0; i < cRects; ++i)
1048 wined3d_surface_bltfast(Dest->wined3d_surface, 0, 0,
1049 Source->wined3d_surface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
1053 wined3d_mutex_unlock();
1058 static HRESULT WINAPI IDirect3DDevice8Impl_UpdateTexture(IDirect3DDevice8 *iface,
1059 IDirect3DBaseTexture8 *src_texture, IDirect3DBaseTexture8 *dst_texture)
1061 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1064 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface, src_texture, dst_texture);
1066 wined3d_mutex_lock();
1067 hr = wined3d_device_update_texture(This->wined3d_device,
1068 ((IDirect3DBaseTexture8Impl *)src_texture)->wined3d_texture,
1069 ((IDirect3DBaseTexture8Impl *)dst_texture)->wined3d_texture);
1070 wined3d_mutex_unlock();
1075 static HRESULT WINAPI IDirect3DDevice8Impl_GetFrontBuffer(IDirect3DDevice8 *iface,
1076 IDirect3DSurface8 *pDestSurface)
1078 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1079 IDirect3DSurface8Impl *destSurface = (IDirect3DSurface8Impl *)pDestSurface;
1082 TRACE("iface %p, dst_surface %p.\n", iface, pDestSurface);
1084 if (pDestSurface == NULL) {
1085 WARN("(%p) : Caller passed NULL as pDestSurface returning D3DERR_INVALIDCALL\n", This);
1086 return D3DERR_INVALIDCALL;
1089 wined3d_mutex_lock();
1090 hr = wined3d_device_get_front_buffer_data(This->wined3d_device, 0, destSurface->wined3d_surface);
1091 wined3d_mutex_unlock();
1096 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderTarget(IDirect3DDevice8 *iface,
1097 IDirect3DSurface8 *pRenderTarget, IDirect3DSurface8 *pNewZStencil)
1099 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1100 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl *)pRenderTarget;
1101 IDirect3DSurface8Impl *pZSurface = (IDirect3DSurface8Impl *)pNewZStencil;
1102 struct wined3d_surface *original_ds = NULL;
1105 TRACE("iface %p, render_target %p, depth_stencil %p.\n", iface, pRenderTarget, pNewZStencil);
1107 wined3d_mutex_lock();
1111 struct wined3d_resource_desc ds_desc, rt_desc;
1112 struct wined3d_resource *wined3d_resource;
1113 IDirect3DSurface8 *orig_rt = NULL;
1115 /* If no render target is passed in check the size against the current RT */
1118 hr = IDirect3DDevice8_GetRenderTarget(iface, &orig_rt);
1121 wined3d_mutex_unlock();
1124 pSurface = (IDirect3DSurface8Impl *)orig_rt;
1127 wined3d_resource = wined3d_surface_get_resource(pZSurface->wined3d_surface);
1128 wined3d_resource_get_desc(wined3d_resource, &ds_desc);
1129 wined3d_resource = wined3d_surface_get_resource(pSurface->wined3d_surface);
1130 wined3d_resource_get_desc(wined3d_resource, &rt_desc);
1131 if (orig_rt) IDirect3DSurface8_Release(orig_rt);
1133 if (ds_desc.width < rt_desc.width || ds_desc.height < rt_desc.height)
1135 WARN("Depth stencil is smaller than the render target, returning D3DERR_INVALIDCALL\n");
1136 wined3d_mutex_unlock();
1137 return D3DERR_INVALIDCALL;
1141 hr = wined3d_device_get_depth_stencil(This->wined3d_device, &original_ds);
1142 if (hr == WINED3D_OK || hr == WINED3DERR_NOTFOUND)
1144 hr = wined3d_device_set_depth_stencil(This->wined3d_device, pZSurface ? pZSurface->wined3d_surface : NULL);
1145 if (SUCCEEDED(hr) && pRenderTarget)
1147 hr = wined3d_device_set_render_target(This->wined3d_device, 0, pSurface->wined3d_surface, TRUE);
1149 wined3d_device_set_depth_stencil(This->wined3d_device, original_ds);
1153 wined3d_surface_decref(original_ds);
1155 wined3d_mutex_unlock();
1160 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderTarget(IDirect3DDevice8 *iface,
1161 IDirect3DSurface8 **ppRenderTarget)
1163 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1164 struct wined3d_surface *wined3d_surface;
1167 TRACE("iface %p, render_target %p.\n", iface, ppRenderTarget);
1169 if (ppRenderTarget == NULL) {
1170 return D3DERR_INVALIDCALL;
1173 wined3d_mutex_lock();
1174 hr = wined3d_device_get_render_target(This->wined3d_device, 0, &wined3d_surface);
1175 if (SUCCEEDED(hr) && wined3d_surface)
1177 *ppRenderTarget = wined3d_surface_get_parent(wined3d_surface);
1178 IDirect3DSurface8_AddRef(*ppRenderTarget);
1179 wined3d_surface_decref(wined3d_surface);
1183 FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
1184 *ppRenderTarget = NULL;
1186 wined3d_mutex_unlock();
1191 static HRESULT WINAPI IDirect3DDevice8Impl_GetDepthStencilSurface(IDirect3DDevice8 *iface,
1192 IDirect3DSurface8 **ppZStencilSurface)
1194 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1195 struct wined3d_surface *wined3d_surface;
1198 TRACE("iface %p, depth_stencil %p.\n", iface, ppZStencilSurface);
1200 if(ppZStencilSurface == NULL){
1201 return D3DERR_INVALIDCALL;
1204 wined3d_mutex_lock();
1205 hr = wined3d_device_get_depth_stencil(This->wined3d_device, &wined3d_surface);
1208 *ppZStencilSurface = wined3d_surface_get_parent(wined3d_surface);
1209 IDirect3DSurface8_AddRef(*ppZStencilSurface);
1210 wined3d_surface_decref(wined3d_surface);
1214 if (hr != WINED3DERR_NOTFOUND)
1215 FIXME("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
1216 *ppZStencilSurface = NULL;
1218 wined3d_mutex_unlock();
1223 static HRESULT WINAPI IDirect3DDevice8Impl_BeginScene(IDirect3DDevice8 *iface)
1225 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1228 TRACE("iface %p.\n", iface);
1230 wined3d_mutex_lock();
1231 hr = wined3d_device_begin_scene(This->wined3d_device);
1232 wined3d_mutex_unlock();
1237 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice8Impl_EndScene(IDirect3DDevice8 *iface)
1239 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1242 TRACE("iface %p.\n", iface);
1244 wined3d_mutex_lock();
1245 hr = wined3d_device_end_scene(This->wined3d_device);
1246 wined3d_mutex_unlock();
1251 static HRESULT WINAPI IDirect3DDevice8Impl_Clear(IDirect3DDevice8 *iface, DWORD Count,
1252 const D3DRECT *pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil)
1254 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1257 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1258 iface, Count, pRects, Flags, Color, Z, Stencil);
1260 wined3d_mutex_lock();
1261 hr = wined3d_device_clear(This->wined3d_device, Count, (const RECT *)pRects, Flags, Color, Z, Stencil);
1262 wined3d_mutex_unlock();
1267 static HRESULT WINAPI IDirect3DDevice8Impl_SetTransform(IDirect3DDevice8 *iface,
1268 D3DTRANSFORMSTATETYPE State, const D3DMATRIX *lpMatrix)
1270 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1273 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, lpMatrix);
1275 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1276 wined3d_mutex_lock();
1277 hr = wined3d_device_set_transform(This->wined3d_device, State, (const WINED3DMATRIX *)lpMatrix);
1278 wined3d_mutex_unlock();
1283 static HRESULT WINAPI IDirect3DDevice8Impl_GetTransform(IDirect3DDevice8 *iface,
1284 D3DTRANSFORMSTATETYPE State, D3DMATRIX *pMatrix)
1286 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1289 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1291 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1292 wined3d_mutex_lock();
1293 hr = wined3d_device_get_transform(This->wined3d_device, State, (WINED3DMATRIX *)pMatrix);
1294 wined3d_mutex_unlock();
1299 static HRESULT WINAPI IDirect3DDevice8Impl_MultiplyTransform(IDirect3DDevice8 *iface,
1300 D3DTRANSFORMSTATETYPE State, const D3DMATRIX *pMatrix)
1302 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1305 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1307 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1308 wined3d_mutex_lock();
1309 hr = wined3d_device_multiply_transform(This->wined3d_device, State, (const WINED3DMATRIX *)pMatrix);
1310 wined3d_mutex_unlock();
1315 static HRESULT WINAPI IDirect3DDevice8Impl_SetViewport(IDirect3DDevice8 *iface,
1316 const D3DVIEWPORT8 *pViewport)
1318 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1321 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1323 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1324 wined3d_mutex_lock();
1325 hr = wined3d_device_set_viewport(This->wined3d_device, (const WINED3DVIEWPORT *)pViewport);
1326 wined3d_mutex_unlock();
1331 static HRESULT WINAPI IDirect3DDevice8Impl_GetViewport(IDirect3DDevice8 *iface,
1332 D3DVIEWPORT8 *pViewport)
1334 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1337 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1339 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1340 wined3d_mutex_lock();
1341 hr = wined3d_device_get_viewport(This->wined3d_device, (WINED3DVIEWPORT *)pViewport);
1342 wined3d_mutex_unlock();
1347 static HRESULT WINAPI IDirect3DDevice8Impl_SetMaterial(IDirect3DDevice8 *iface,
1348 const D3DMATERIAL8 *pMaterial)
1350 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1353 TRACE("iface %p, material %p.\n", iface, pMaterial);
1355 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1356 wined3d_mutex_lock();
1357 hr = wined3d_device_set_material(This->wined3d_device, (const WINED3DMATERIAL *)pMaterial);
1358 wined3d_mutex_unlock();
1363 static HRESULT WINAPI IDirect3DDevice8Impl_GetMaterial(IDirect3DDevice8 *iface,
1364 D3DMATERIAL8 *pMaterial)
1366 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1369 TRACE("iface %p, material %p.\n", iface, pMaterial);
1371 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1372 wined3d_mutex_lock();
1373 hr = wined3d_device_get_material(This->wined3d_device, (WINED3DMATERIAL *)pMaterial);
1374 wined3d_mutex_unlock();
1379 static HRESULT WINAPI IDirect3DDevice8Impl_SetLight(IDirect3DDevice8 *iface, DWORD Index,
1380 const D3DLIGHT8 *pLight)
1382 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1385 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1387 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1388 wined3d_mutex_lock();
1389 hr = wined3d_device_set_light(This->wined3d_device, Index, (const WINED3DLIGHT *)pLight);
1390 wined3d_mutex_unlock();
1395 static HRESULT WINAPI IDirect3DDevice8Impl_GetLight(IDirect3DDevice8 *iface, DWORD Index,
1398 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1401 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1403 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1404 wined3d_mutex_lock();
1405 hr = wined3d_device_get_light(This->wined3d_device, Index, (WINED3DLIGHT *)pLight);
1406 wined3d_mutex_unlock();
1411 static HRESULT WINAPI IDirect3DDevice8Impl_LightEnable(IDirect3DDevice8 *iface, DWORD Index,
1414 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1417 TRACE("iface %p, index %u, enable %#x.\n", iface, Index, Enable);
1419 wined3d_mutex_lock();
1420 hr = wined3d_device_set_light_enable(This->wined3d_device, Index, Enable);
1421 wined3d_mutex_unlock();
1426 static HRESULT WINAPI IDirect3DDevice8Impl_GetLightEnable(IDirect3DDevice8 *iface, DWORD Index,
1429 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1432 TRACE("iface %p, index %u, enable %p.\n", iface, Index, pEnable);
1434 wined3d_mutex_lock();
1435 hr = wined3d_device_get_light_enable(This->wined3d_device, Index, pEnable);
1436 wined3d_mutex_unlock();
1441 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipPlane(IDirect3DDevice8 *iface, DWORD Index,
1442 const float *pPlane)
1444 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1447 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1449 wined3d_mutex_lock();
1450 hr = wined3d_device_set_clip_plane(This->wined3d_device, Index, pPlane);
1451 wined3d_mutex_unlock();
1456 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipPlane(IDirect3DDevice8 *iface, DWORD Index,
1459 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1462 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1464 wined3d_mutex_lock();
1465 hr = wined3d_device_get_clip_plane(This->wined3d_device, Index, pPlane);
1466 wined3d_mutex_unlock();
1471 /* This factor is the result of a trial-and-error search. Both ZBIAS and DEPTHBIAS require
1472 * guesswork by design. d3d9 apps usually use a DEPTHBIAS of -0.00002(Mass Effect 2, WoW).
1473 * d3d8 apps(Final Fantasy XI) set ZBIAS to 15 and still expect the depth test to sort
1474 * objects properly. */
1475 static const float zbias_factor = -0.000005f;
1477 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(IDirect3DDevice8 *iface,
1478 D3DRENDERSTATETYPE State, DWORD Value)
1480 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1488 TRACE("iface %p, state %#x, value %#x.\n", iface, State, Value);
1490 wined3d_mutex_lock();
1494 wined3d_value.f = Value * zbias_factor;
1495 hr = wined3d_device_set_render_state(This->wined3d_device, WINED3DRS_DEPTHBIAS, wined3d_value.d);
1499 hr = wined3d_device_set_render_state(This->wined3d_device, State, Value);
1501 wined3d_mutex_unlock();
1506 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderState(IDirect3DDevice8 *iface,
1507 D3DRENDERSTATETYPE State, DWORD *pValue)
1509 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1517 TRACE("iface %p, state %#x, value %p.\n", iface, State, pValue);
1519 wined3d_mutex_lock();
1523 hr = wined3d_device_get_render_state(This->wined3d_device, WINED3DRS_DEPTHBIAS, &wined3d_value.d);
1524 if (SUCCEEDED(hr)) *pValue = wined3d_value.f / zbias_factor;
1528 hr = wined3d_device_get_render_state(This->wined3d_device, State, pValue);
1530 wined3d_mutex_unlock();
1535 static HRESULT WINAPI IDirect3DDevice8Impl_BeginStateBlock(IDirect3DDevice8 *iface)
1537 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1540 TRACE("iface %p.\n", iface);
1542 wined3d_mutex_lock();
1543 hr = wined3d_device_begin_stateblock(This->wined3d_device);
1544 wined3d_mutex_unlock();
1549 static HRESULT WINAPI IDirect3DDevice8Impl_EndStateBlock(IDirect3DDevice8 *iface, DWORD *pToken)
1551 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1552 struct wined3d_stateblock *stateblock;
1555 TRACE("iface %p, token %p.\n", iface, pToken);
1557 /* Tell wineD3D to endstateblock before anything else (in case we run out
1558 * of memory later and cause locking problems)
1560 wined3d_mutex_lock();
1561 hr = wined3d_device_end_stateblock(This->wined3d_device, &stateblock);
1564 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
1565 wined3d_mutex_unlock();
1569 *pToken = d3d8_allocate_handle(&This->handle_table, stateblock, D3D8_HANDLE_SB);
1570 wined3d_mutex_unlock();
1572 if (*pToken == D3D8_INVALID_HANDLE)
1574 ERR("Failed to create a handle\n");
1575 wined3d_mutex_lock();
1576 wined3d_stateblock_decref(stateblock);
1577 wined3d_mutex_unlock();
1582 TRACE("Returning %#x (%p).\n", *pToken, stateblock);
1587 static HRESULT WINAPI IDirect3DDevice8Impl_ApplyStateBlock(IDirect3DDevice8 *iface, DWORD Token)
1589 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1590 struct wined3d_stateblock *stateblock;
1593 TRACE("iface %p, token %#x.\n", iface, Token);
1595 if (!Token) return D3D_OK;
1597 wined3d_mutex_lock();
1598 stateblock = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1601 WARN("Invalid handle (%#x) passed.\n", Token);
1602 wined3d_mutex_unlock();
1603 return D3DERR_INVALIDCALL;
1605 hr = wined3d_stateblock_apply(stateblock);
1606 wined3d_mutex_unlock();
1611 static HRESULT WINAPI IDirect3DDevice8Impl_CaptureStateBlock(IDirect3DDevice8 *iface, DWORD Token)
1613 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1614 struct wined3d_stateblock *stateblock;
1617 TRACE("iface %p, token %#x.\n", iface, Token);
1619 wined3d_mutex_lock();
1620 stateblock = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1623 WARN("Invalid handle (%#x) passed.\n", Token);
1624 wined3d_mutex_unlock();
1625 return D3DERR_INVALIDCALL;
1627 hr = wined3d_stateblock_capture(stateblock);
1628 wined3d_mutex_unlock();
1633 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteStateBlock(IDirect3DDevice8 *iface, DWORD Token)
1635 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1636 struct wined3d_stateblock *stateblock;
1638 TRACE("iface %p, token %#x.\n", iface, Token);
1640 wined3d_mutex_lock();
1641 stateblock = d3d8_free_handle(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1645 WARN("Invalid handle (%#x) passed.\n", Token);
1646 wined3d_mutex_unlock();
1647 return D3DERR_INVALIDCALL;
1650 if (wined3d_stateblock_decref(stateblock))
1652 ERR("Stateblock %p has references left, this shouldn't happen.\n", stateblock);
1654 wined3d_mutex_unlock();
1659 static HRESULT WINAPI IDirect3DDevice8Impl_CreateStateBlock(IDirect3DDevice8 *iface,
1660 D3DSTATEBLOCKTYPE Type, DWORD *handle)
1662 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1663 struct wined3d_stateblock *stateblock;
1666 TRACE("iface %p, type %#x, handle %p.\n", iface, Type, handle);
1668 if (Type != D3DSBT_ALL
1669 && Type != D3DSBT_PIXELSTATE
1670 && Type != D3DSBT_VERTEXSTATE)
1672 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1673 return D3DERR_INVALIDCALL;
1676 wined3d_mutex_lock();
1677 hr = wined3d_stateblock_create(This->wined3d_device, (WINED3DSTATEBLOCKTYPE)Type, &stateblock);
1680 wined3d_mutex_unlock();
1681 ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr);
1685 *handle = d3d8_allocate_handle(&This->handle_table, stateblock, D3D8_HANDLE_SB);
1686 wined3d_mutex_unlock();
1688 if (*handle == D3D8_INVALID_HANDLE)
1690 ERR("Failed to allocate a handle.\n");
1691 wined3d_mutex_lock();
1692 wined3d_stateblock_decref(stateblock);
1693 wined3d_mutex_unlock();
1698 TRACE("Returning %#x (%p).\n", *handle, stateblock);
1703 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipStatus(IDirect3DDevice8 *iface,
1704 const D3DCLIPSTATUS8 *pClipStatus)
1706 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1709 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1710 /* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
1712 wined3d_mutex_lock();
1713 hr = wined3d_device_set_clip_status(This->wined3d_device, (const WINED3DCLIPSTATUS *)pClipStatus);
1714 wined3d_mutex_unlock();
1719 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipStatus(IDirect3DDevice8 *iface,
1720 D3DCLIPSTATUS8 *pClipStatus)
1722 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1725 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1727 wined3d_mutex_lock();
1728 hr = wined3d_device_get_clip_status(This->wined3d_device, (WINED3DCLIPSTATUS *)pClipStatus);
1729 wined3d_mutex_unlock();
1734 static HRESULT WINAPI IDirect3DDevice8Impl_GetTexture(IDirect3DDevice8 *iface,
1735 DWORD Stage, IDirect3DBaseTexture8 **ppTexture)
1737 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1738 struct wined3d_texture *wined3d_texture;
1741 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, ppTexture);
1743 if(ppTexture == NULL){
1744 return D3DERR_INVALIDCALL;
1747 wined3d_mutex_lock();
1748 hr = wined3d_device_get_texture(This->wined3d_device, Stage, &wined3d_texture);
1751 WARN("Failed to get texture for stage %u, hr %#x.\n", Stage, hr);
1752 wined3d_mutex_unlock();
1757 if (wined3d_texture)
1759 *ppTexture = wined3d_texture_get_parent(wined3d_texture);
1760 IDirect3DBaseTexture8_AddRef(*ppTexture);
1761 wined3d_texture_decref(wined3d_texture);
1767 wined3d_mutex_unlock();
1772 static HRESULT WINAPI IDirect3DDevice8Impl_SetTexture(IDirect3DDevice8 *iface, DWORD Stage,
1773 IDirect3DBaseTexture8 *pTexture)
1775 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1778 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, pTexture);
1780 wined3d_mutex_lock();
1781 hr = wined3d_device_set_texture(This->wined3d_device, Stage,
1782 pTexture ? ((IDirect3DBaseTexture8Impl *)pTexture)->wined3d_texture : NULL);
1783 wined3d_mutex_unlock();
1788 static const struct tss_lookup
1795 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 0, unused */
1796 {FALSE, WINED3DTSS_COLOROP}, /* 1, D3DTSS_COLOROP */
1797 {FALSE, WINED3DTSS_COLORARG1}, /* 2, D3DTSS_COLORARG1 */
1798 {FALSE, WINED3DTSS_COLORARG2}, /* 3, D3DTSS_COLORARG2 */
1799 {FALSE, WINED3DTSS_ALPHAOP}, /* 4, D3DTSS_ALPHAOP */
1800 {FALSE, WINED3DTSS_ALPHAARG1}, /* 5, D3DTSS_ALPHAARG1 */
1801 {FALSE, WINED3DTSS_ALPHAARG2}, /* 6, D3DTSS_ALPHAARG2 */
1802 {FALSE, WINED3DTSS_BUMPENVMAT00}, /* 7, D3DTSS_BUMPENVMAT00 */
1803 {FALSE, WINED3DTSS_BUMPENVMAT01}, /* 8, D3DTSS_BUMPENVMAT01 */
1804 {FALSE, WINED3DTSS_BUMPENVMAT10}, /* 9, D3DTSS_BUMPENVMAT10 */
1805 {FALSE, WINED3DTSS_BUMPENVMAT11}, /* 10, D3DTSS_BUMPENVMAT11 */
1806 {FALSE, WINED3DTSS_TEXCOORDINDEX}, /* 11, D3DTSS_TEXCOORDINDEX */
1807 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 12, unused */
1808 {TRUE, WINED3DSAMP_ADDRESSU}, /* 13, D3DTSS_ADDRESSU */
1809 {TRUE, WINED3DSAMP_ADDRESSV}, /* 14, D3DTSS_ADDRESSV */
1810 {TRUE, WINED3DSAMP_BORDERCOLOR}, /* 15, D3DTSS_BORDERCOLOR */
1811 {TRUE, WINED3DSAMP_MAGFILTER}, /* 16, D3DTSS_MAGFILTER */
1812 {TRUE, WINED3DSAMP_MINFILTER}, /* 17, D3DTSS_MINFILTER */
1813 {TRUE, WINED3DSAMP_MIPFILTER}, /* 18, D3DTSS_MIPFILTER */
1814 {TRUE, WINED3DSAMP_MIPMAPLODBIAS}, /* 19, D3DTSS_MIPMAPLODBIAS */
1815 {TRUE, WINED3DSAMP_MAXMIPLEVEL}, /* 20, D3DTSS_MAXMIPLEVEL */
1816 {TRUE, WINED3DSAMP_MAXANISOTROPY}, /* 21, D3DTSS_MAXANISOTROPY */
1817 {FALSE, WINED3DTSS_BUMPENVLSCALE}, /* 22, D3DTSS_BUMPENVLSCALE */
1818 {FALSE, WINED3DTSS_BUMPENVLOFFSET}, /* 23, D3DTSS_BUMPENVLOFFSET */
1819 {FALSE, WINED3DTSS_TEXTURETRANSFORMFLAGS}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1820 {TRUE, WINED3DSAMP_ADDRESSW}, /* 25, D3DTSS_ADDRESSW */
1821 {FALSE, WINED3DTSS_COLORARG0}, /* 26, D3DTSS_COLORARG0 */
1822 {FALSE, WINED3DTSS_ALPHAARG0}, /* 27, D3DTSS_ALPHAARG0 */
1823 {FALSE, WINED3DTSS_RESULTARG}, /* 28, D3DTSS_RESULTARG */
1826 static HRESULT WINAPI IDirect3DDevice8Impl_GetTextureStageState(IDirect3DDevice8 *iface,
1827 DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD *pValue)
1829 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1830 const struct tss_lookup *l;
1833 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface, Stage, Type, pValue);
1835 if (Type >= sizeof(tss_lookup) / sizeof(*tss_lookup))
1837 WARN("Invalid Type %#x passed.\n", Type);
1841 l = &tss_lookup[Type];
1843 wined3d_mutex_lock();
1844 if (l->sampler_state)
1845 hr = wined3d_device_get_sampler_state(This->wined3d_device, Stage, l->state, pValue);
1847 hr = wined3d_device_get_texture_stage_state(This->wined3d_device, Stage, l->state, pValue);
1848 wined3d_mutex_unlock();
1853 static HRESULT WINAPI IDirect3DDevice8Impl_SetTextureStageState(IDirect3DDevice8 *iface,
1854 DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value)
1856 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1857 const struct tss_lookup *l;
1860 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface, Stage, Type, Value);
1862 if (Type >= sizeof(tss_lookup) / sizeof(*tss_lookup))
1864 WARN("Invalid Type %#x passed.\n", Type);
1868 l = &tss_lookup[Type];
1870 wined3d_mutex_lock();
1871 if (l->sampler_state)
1872 hr = wined3d_device_set_sampler_state(This->wined3d_device, Stage, l->state, Value);
1874 hr = wined3d_device_set_texture_stage_state(This->wined3d_device, Stage, l->state, Value);
1875 wined3d_mutex_unlock();
1880 static HRESULT WINAPI IDirect3DDevice8Impl_ValidateDevice(IDirect3DDevice8 *iface,
1883 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1886 TRACE("iface %p, pass_count %p.\n", iface, pNumPasses);
1888 wined3d_mutex_lock();
1889 hr = wined3d_device_validate_device(This->wined3d_device, pNumPasses);
1890 wined3d_mutex_unlock();
1895 static HRESULT WINAPI IDirect3DDevice8Impl_GetInfo(IDirect3DDevice8 *iface,
1896 DWORD info_id, void *info, DWORD info_size)
1898 FIXME("iface %p, info_id %#x, info %p, info_size %u stub!\n", iface, info_id, info, info_size);
1903 static HRESULT WINAPI IDirect3DDevice8Impl_SetPaletteEntries(IDirect3DDevice8 *iface,
1904 UINT PaletteNumber, const PALETTEENTRY *pEntries)
1906 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1909 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1911 wined3d_mutex_lock();
1912 hr = wined3d_device_set_palette_entries(This->wined3d_device, PaletteNumber, pEntries);
1913 wined3d_mutex_unlock();
1918 static HRESULT WINAPI IDirect3DDevice8Impl_GetPaletteEntries(IDirect3DDevice8 *iface,
1919 UINT PaletteNumber, PALETTEENTRY *pEntries)
1921 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1924 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1926 wined3d_mutex_lock();
1927 hr = wined3d_device_get_palette_entries(This->wined3d_device, PaletteNumber, pEntries);
1928 wined3d_mutex_unlock();
1933 static HRESULT WINAPI IDirect3DDevice8Impl_SetCurrentTexturePalette(IDirect3DDevice8 *iface,
1936 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1939 TRACE("iface %p, palette_idx %u.\n", iface, PaletteNumber);
1941 wined3d_mutex_lock();
1942 hr = wined3d_device_set_current_texture_palette(This->wined3d_device, PaletteNumber);
1943 wined3d_mutex_unlock();
1948 static HRESULT WINAPI IDirect3DDevice8Impl_GetCurrentTexturePalette(IDirect3DDevice8 *iface,
1949 UINT *PaletteNumber)
1951 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1954 TRACE("iface %p, palette_idx %p.\n", iface, PaletteNumber);
1956 wined3d_mutex_lock();
1957 hr = wined3d_device_get_current_texture_palette(This->wined3d_device, PaletteNumber);
1958 wined3d_mutex_unlock();
1963 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitive(IDirect3DDevice8 *iface,
1964 D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount)
1966 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1969 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1970 iface, PrimitiveType, StartVertex, PrimitiveCount);
1972 wined3d_mutex_lock();
1973 wined3d_device_set_primitive_type(This->wined3d_device, PrimitiveType);
1974 hr = wined3d_device_draw_primitive(This->wined3d_device, StartVertex,
1975 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
1976 wined3d_mutex_unlock();
1981 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitive(IDirect3DDevice8 *iface,
1982 D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertices, UINT startIndex,
1985 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1988 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, start_idx %u, primitive_count %u.\n",
1989 iface, PrimitiveType, MinVertexIndex, NumVertices, startIndex, primCount);
1991 wined3d_mutex_lock();
1992 wined3d_device_set_primitive_type(This->wined3d_device, PrimitiveType);
1993 hr = wined3d_device_draw_indexed_primitive(This->wined3d_device, startIndex,
1994 vertex_count_from_primitive_count(PrimitiveType, primCount));
1995 wined3d_mutex_unlock();
2000 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitiveUP(IDirect3DDevice8 *iface,
2001 D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, const void *pVertexStreamZeroData,
2002 UINT VertexStreamZeroStride)
2004 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2007 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
2008 iface, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
2010 wined3d_mutex_lock();
2011 wined3d_device_set_primitive_type(This->wined3d_device, PrimitiveType);
2012 hr = wined3d_device_draw_primitive_up(This->wined3d_device,
2013 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
2014 pVertexStreamZeroData, VertexStreamZeroStride);
2015 wined3d_mutex_unlock();
2020 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(IDirect3DDevice8 *iface,
2021 D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertexIndices,
2022 UINT PrimitiveCount, const void *pIndexData, D3DFORMAT IndexDataFormat,
2023 const void *pVertexStreamZeroData, UINT VertexStreamZeroStride)
2025 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2028 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
2029 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
2030 iface, PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount,
2031 pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
2033 wined3d_mutex_lock();
2034 wined3d_device_set_primitive_type(This->wined3d_device, PrimitiveType);
2035 hr = wined3d_device_draw_indexed_primitive_up(This->wined3d_device,
2036 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
2037 wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
2038 wined3d_mutex_unlock();
2043 static HRESULT WINAPI IDirect3DDevice8Impl_ProcessVertices(IDirect3DDevice8 *iface,
2044 UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer8 *pDestBuffer,
2047 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2049 IDirect3DVertexBuffer8Impl *dest = (IDirect3DVertexBuffer8Impl *) pDestBuffer;
2051 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, flags %#x.\n",
2052 iface, SrcStartIndex, DestIndex, VertexCount, pDestBuffer, Flags);
2054 wined3d_mutex_lock();
2055 hr = wined3d_device_process_vertices(This->wined3d_device, SrcStartIndex, DestIndex,
2056 VertexCount, dest->wineD3DVertexBuffer, NULL, Flags, dest->fvf);
2057 wined3d_mutex_unlock();
2062 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(IDirect3DDevice8 *iface,
2063 const DWORD *declaration, const DWORD *byte_code, DWORD *shader, DWORD usage)
2065 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2066 IDirect3DVertexShader8Impl *object;
2067 DWORD shader_handle;
2071 TRACE("iface %p, declaration %p, byte_code %p, shader %p, usage %#x.\n",
2072 iface, declaration, byte_code, shader, usage);
2074 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2077 ERR("Failed to allocate vertex shader memory.\n");
2079 return E_OUTOFMEMORY;
2082 wined3d_mutex_lock();
2083 handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_VS);
2084 wined3d_mutex_unlock();
2085 if (handle == D3D8_INVALID_HANDLE)
2087 ERR("Failed to allocate vertex shader handle.\n");
2088 HeapFree(GetProcessHeap(), 0, object);
2090 return E_OUTOFMEMORY;
2093 shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
2095 hr = vertexshader_init(object, This, declaration, byte_code, shader_handle, usage);
2098 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
2099 wined3d_mutex_lock();
2100 d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_VS);
2101 wined3d_mutex_unlock();
2102 HeapFree(GetProcessHeap(), 0, object);
2107 TRACE("Created vertex shader %p (handle %#x).\n", object, shader_handle);
2108 *shader = shader_handle;
2113 static IDirect3DVertexDeclaration8Impl *IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl *This, DWORD fvf)
2115 IDirect3DVertexDeclaration8Impl *d3d8_declaration;
2117 int p, low, high; /* deliberately signed */
2118 struct FvfToDecl *convertedDecls = This->decls;
2120 TRACE("Searching for declaration for fvf %08x... ", fvf);
2123 high = This->numConvertedDecls - 1;
2124 while(low <= high) {
2125 p = (low + high) >> 1;
2127 if(convertedDecls[p].fvf == fvf) {
2128 TRACE("found %p\n", convertedDecls[p].decl);
2129 return (IDirect3DVertexDeclaration8Impl *)convertedDecls[p].decl;
2130 } else if(convertedDecls[p].fvf < fvf) {
2136 TRACE("not found. Creating and inserting at position %d.\n", low);
2138 d3d8_declaration = HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration));
2139 if (!d3d8_declaration)
2141 ERR("Memory allocation failed.\n");
2145 hr = vertexdeclaration_init_fvf(d3d8_declaration, This, fvf);
2148 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
2149 HeapFree(GetProcessHeap(), 0, d3d8_declaration);
2153 if(This->declArraySize == This->numConvertedDecls) {
2154 int grow = This->declArraySize / 2;
2155 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
2156 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
2157 if(!convertedDecls) {
2158 /* This will destroy it */
2159 IDirect3DVertexDeclaration8_Release((IDirect3DVertexDeclaration8 *)d3d8_declaration);
2162 This->decls = convertedDecls;
2163 This->declArraySize += grow;
2166 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(convertedDecls[0]) * (This->numConvertedDecls - low));
2167 convertedDecls[low].decl = (IDirect3DVertexDeclaration8 *)d3d8_declaration;
2168 convertedDecls[low].fvf = fvf;
2169 This->numConvertedDecls++;
2171 TRACE("Returning %p. %u decls in array\n", d3d8_declaration, This->numConvertedDecls);
2172 return d3d8_declaration;
2175 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShader(IDirect3DDevice8 *iface, DWORD pShader)
2177 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2178 IDirect3DVertexShader8Impl *shader;
2181 TRACE("iface %p, shader %#x.\n", iface, pShader);
2183 if (VS_HIGHESTFIXEDFXF >= pShader) {
2184 TRACE("Setting FVF, %#x\n", pShader);
2186 wined3d_mutex_lock();
2187 wined3d_device_set_vertex_declaration(This->wined3d_device,
2188 IDirect3DDevice8Impl_FindDecl(This, pShader)->wined3d_vertex_declaration);
2189 wined3d_device_set_vertex_shader(This->wined3d_device, NULL);
2190 wined3d_mutex_unlock();
2195 TRACE("Setting shader\n");
2197 wined3d_mutex_lock();
2198 shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2201 WARN("Invalid handle (%#x) passed.\n", pShader);
2202 wined3d_mutex_unlock();
2204 return D3DERR_INVALIDCALL;
2207 hr = wined3d_device_set_vertex_declaration(This->wined3d_device,
2208 ((IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration)->wined3d_vertex_declaration);
2210 hr = wined3d_device_set_vertex_shader(This->wined3d_device, shader->wined3d_shader);
2211 wined3d_mutex_unlock();
2213 TRACE("Returning hr %#x\n", hr);
2218 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShader(IDirect3DDevice8 *iface, DWORD *ppShader)
2220 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2221 struct wined3d_vertex_declaration *wined3d_declaration;
2222 IDirect3DVertexDeclaration8 *d3d8_declaration;
2225 TRACE("iface %p, shader %p.\n", iface, ppShader);
2227 wined3d_mutex_lock();
2228 hr = wined3d_device_get_vertex_declaration(This->wined3d_device, &wined3d_declaration);
2231 wined3d_mutex_unlock();
2232 WARN("(%p) : Call to IWineD3DDevice_GetVertexDeclaration failed %#x (device %p)\n",
2233 This, hr, This->wined3d_device);
2237 if (!wined3d_declaration)
2239 wined3d_mutex_unlock();
2244 d3d8_declaration = wined3d_vertex_declaration_get_parent(wined3d_declaration);
2245 wined3d_vertex_declaration_decref(wined3d_declaration);
2246 wined3d_mutex_unlock();
2247 *ppShader = ((IDirect3DVertexDeclaration8Impl *)d3d8_declaration)->shader_handle;
2249 TRACE("(%p) : returning %#x\n", This, *ppShader);
2254 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteVertexShader(IDirect3DDevice8 *iface, DWORD pShader)
2256 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2257 IDirect3DVertexShader8Impl *shader;
2258 struct wined3d_shader *cur;
2260 TRACE("iface %p, shader %#x.\n", iface, pShader);
2262 wined3d_mutex_lock();
2263 shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2266 WARN("Invalid handle (%#x) passed.\n", pShader);
2267 wined3d_mutex_unlock();
2269 return D3DERR_INVALIDCALL;
2272 cur = wined3d_device_get_vertex_shader(This->wined3d_device);
2275 if (cur == shader->wined3d_shader)
2276 IDirect3DDevice8_SetVertexShader(iface, 0);
2277 wined3d_shader_decref(cur);
2280 wined3d_mutex_unlock();
2282 if (IDirect3DVertexShader8_Release(&shader->IDirect3DVertexShader8_iface))
2284 ERR("Shader %p has references left, this shouldn't happen.\n", shader);
2290 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShaderConstant(IDirect3DDevice8 *iface,
2291 DWORD Register, const void *pConstantData, DWORD ConstantCount)
2293 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2296 TRACE("iface %p, register %u, data %p, count %u.\n",
2297 iface, Register, pConstantData, ConstantCount);
2299 if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
2300 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2301 Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2302 return D3DERR_INVALIDCALL;
2305 wined3d_mutex_lock();
2306 hr = wined3d_device_set_vs_consts_f(This->wined3d_device, Register, pConstantData, ConstantCount);
2307 wined3d_mutex_unlock();
2312 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderConstant(IDirect3DDevice8 *iface,
2313 DWORD Register, void *pConstantData, DWORD ConstantCount)
2315 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2318 TRACE("iface %p, register %u, data %p, count %u.\n",
2319 iface, Register, pConstantData, ConstantCount);
2321 if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
2322 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2323 Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2324 return D3DERR_INVALIDCALL;
2327 wined3d_mutex_lock();
2328 hr = wined3d_device_get_vs_consts_f(This->wined3d_device, Register, pConstantData, ConstantCount);
2329 wined3d_mutex_unlock();
2334 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderDeclaration(IDirect3DDevice8 *iface,
2335 DWORD pVertexShader, void *pData, DWORD *pSizeOfData)
2337 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2338 IDirect3DVertexDeclaration8Impl *declaration;
2339 IDirect3DVertexShader8Impl *shader;
2341 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2342 iface, pVertexShader, pData, pSizeOfData);
2344 wined3d_mutex_lock();
2345 shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2346 wined3d_mutex_unlock();
2350 WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2351 return D3DERR_INVALIDCALL;
2353 declaration = (IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration;
2355 /* If pData is NULL, we just return the required size of the buffer. */
2357 *pSizeOfData = declaration->elements_size;
2361 /* MSDN claims that if *pSizeOfData is smaller than the required size
2362 * we should write the required size and return D3DERR_MOREDATA.
2363 * That's not actually true. */
2364 if (*pSizeOfData < declaration->elements_size) {
2365 return D3DERR_INVALIDCALL;
2368 CopyMemory(pData, declaration->elements, declaration->elements_size);
2373 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderFunction(IDirect3DDevice8 *iface,
2374 DWORD pVertexShader, void *pData, DWORD *pSizeOfData)
2376 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2377 IDirect3DVertexShader8Impl *shader = NULL;
2380 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2381 iface, pVertexShader, pData, pSizeOfData);
2383 wined3d_mutex_lock();
2384 shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2387 WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2388 wined3d_mutex_unlock();
2390 return D3DERR_INVALIDCALL;
2393 if (!shader->wined3d_shader)
2395 wined3d_mutex_unlock();
2400 hr = wined3d_shader_get_byte_code(shader->wined3d_shader, pData, pSizeOfData);
2401 wined3d_mutex_unlock();
2406 static HRESULT WINAPI IDirect3DDevice8Impl_SetIndices(IDirect3DDevice8 *iface,
2407 IDirect3DIndexBuffer8 *pIndexData, UINT baseVertexIndex)
2409 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2411 IDirect3DIndexBuffer8Impl *ib = (IDirect3DIndexBuffer8Impl *)pIndexData;
2413 TRACE("iface %p, buffer %p, base_vertex_idx %u.\n", iface, pIndexData, baseVertexIndex);
2415 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
2416 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
2417 * vertex buffers can't be created to address them with an index that requires the 32nd bit
2418 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
2421 wined3d_mutex_lock();
2422 wined3d_device_set_base_vertex_index(This->wined3d_device, baseVertexIndex);
2423 hr = wined3d_device_set_index_buffer(This->wined3d_device,
2424 ib ? ib->wineD3DIndexBuffer : NULL,
2425 ib ? ib->format : WINED3DFMT_UNKNOWN);
2426 wined3d_mutex_unlock();
2431 static HRESULT WINAPI IDirect3DDevice8Impl_GetIndices(IDirect3DDevice8 *iface,
2432 IDirect3DIndexBuffer8 **ppIndexData, UINT *pBaseVertexIndex)
2434 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2435 struct wined3d_buffer *retIndexData = NULL;
2438 TRACE("iface %p, buffer %p, base_vertex_index %p.\n", iface, ppIndexData, pBaseVertexIndex);
2440 if(ppIndexData == NULL){
2441 return D3DERR_INVALIDCALL;
2444 /* The case from UINT to INT is safe because d3d8 will never set negative values */
2445 wined3d_mutex_lock();
2446 *pBaseVertexIndex = wined3d_device_get_base_vertex_index(This->wined3d_device);
2447 hr = wined3d_device_get_index_buffer(This->wined3d_device, &retIndexData);
2448 if (SUCCEEDED(hr) && retIndexData)
2450 *ppIndexData = wined3d_buffer_get_parent(retIndexData);
2451 IDirect3DIndexBuffer8_AddRef(*ppIndexData);
2452 wined3d_buffer_decref(retIndexData);
2454 if (FAILED(hr)) FIXME("Call to GetIndices failed\n");
2455 *ppIndexData = NULL;
2457 wined3d_mutex_unlock();
2462 static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(IDirect3DDevice8 *iface,
2463 const DWORD *byte_code, DWORD *shader)
2465 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2466 IDirect3DPixelShader8Impl *object;
2467 DWORD shader_handle;
2471 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2475 TRACE("(%p) Invalid call\n", This);
2476 return D3DERR_INVALIDCALL;
2479 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2482 ERR("Failed to allocate pixel shader memmory.\n");
2483 return E_OUTOFMEMORY;
2486 wined3d_mutex_lock();
2487 handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_PS);
2488 wined3d_mutex_unlock();
2489 if (handle == D3D8_INVALID_HANDLE)
2491 ERR("Failed to allocate pixel shader handle.\n");
2492 HeapFree(GetProcessHeap(), 0, object);
2493 return E_OUTOFMEMORY;
2496 shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
2498 hr = pixelshader_init(object, This, byte_code, shader_handle);
2501 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
2502 wined3d_mutex_lock();
2503 d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_PS);
2504 wined3d_mutex_unlock();
2505 HeapFree(GetProcessHeap(), 0, object);
2510 TRACE("Created pixel shader %p (handle %#x).\n", object, shader_handle);
2511 *shader = shader_handle;
2516 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShader(IDirect3DDevice8 *iface, DWORD pShader)
2518 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2519 IDirect3DPixelShader8Impl *shader;
2522 TRACE("iface %p, shader %#x.\n", iface, pShader);
2524 wined3d_mutex_lock();
2528 hr = wined3d_device_set_pixel_shader(This->wined3d_device, NULL);
2529 wined3d_mutex_unlock();
2533 shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2536 WARN("Invalid handle (%#x) passed.\n", pShader);
2537 wined3d_mutex_unlock();
2538 return D3DERR_INVALIDCALL;
2541 TRACE("(%p) : Setting shader %p\n", This, shader);
2542 hr = wined3d_device_set_pixel_shader(This->wined3d_device, shader->wined3d_shader);
2543 wined3d_mutex_unlock();
2548 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShader(IDirect3DDevice8 *iface, DWORD *ppShader)
2550 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2551 struct wined3d_shader *object;
2553 TRACE("iface %p, shader %p.\n", iface, ppShader);
2555 if (NULL == ppShader) {
2556 TRACE("(%p) Invalid call\n", This);
2557 return D3DERR_INVALIDCALL;
2560 wined3d_mutex_lock();
2561 object = wined3d_device_get_pixel_shader(This->wined3d_device);
2564 IDirect3DPixelShader8Impl *d3d8_shader;
2565 d3d8_shader = wined3d_shader_get_parent(object);
2566 wined3d_shader_decref(object);
2567 *ppShader = d3d8_shader->handle;
2573 wined3d_mutex_unlock();
2575 TRACE("(%p) : returning %#x\n", This, *ppShader);
2580 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePixelShader(IDirect3DDevice8 *iface, DWORD pShader)
2582 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2583 IDirect3DPixelShader8Impl *shader;
2584 struct wined3d_shader *cur;
2586 TRACE("iface %p, shader %#x.\n", iface, pShader);
2588 wined3d_mutex_lock();
2590 shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2593 WARN("Invalid handle (%#x) passed.\n", pShader);
2594 wined3d_mutex_unlock();
2595 return D3DERR_INVALIDCALL;
2598 cur = wined3d_device_get_pixel_shader(This->wined3d_device);
2601 if (cur == shader->wined3d_shader)
2602 IDirect3DDevice8_SetPixelShader(iface, 0);
2603 wined3d_shader_decref(cur);
2606 wined3d_mutex_unlock();
2608 if (IDirect3DPixelShader8_Release(&shader->IDirect3DPixelShader8_iface))
2610 ERR("Shader %p has references left, this shouldn't happen.\n", shader);
2616 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShaderConstant(IDirect3DDevice8 *iface,
2617 DWORD Register, const void *pConstantData, DWORD ConstantCount)
2619 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2622 TRACE("iface %p, register %u, data %p, count %u.\n",
2623 iface, Register, pConstantData, ConstantCount);
2625 wined3d_mutex_lock();
2626 hr = wined3d_device_set_ps_consts_f(This->wined3d_device, Register, pConstantData, ConstantCount);
2627 wined3d_mutex_unlock();
2632 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderConstant(IDirect3DDevice8 *iface,
2633 DWORD Register, void *pConstantData, DWORD ConstantCount)
2635 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2638 TRACE("iface %p, register %u, data %p, count %u.\n",
2639 iface, Register, pConstantData, ConstantCount);
2641 wined3d_mutex_lock();
2642 hr = wined3d_device_get_ps_consts_f(This->wined3d_device, Register, pConstantData, ConstantCount);
2643 wined3d_mutex_unlock();
2648 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderFunction(IDirect3DDevice8 *iface,
2649 DWORD pPixelShader, void *pData, DWORD *pSizeOfData)
2651 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2652 IDirect3DPixelShader8Impl *shader = NULL;
2655 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2656 iface, pPixelShader, pData, pSizeOfData);
2658 wined3d_mutex_lock();
2659 shader = d3d8_get_object(&This->handle_table, pPixelShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2662 WARN("Invalid handle (%#x) passed.\n", pPixelShader);
2663 wined3d_mutex_unlock();
2665 return D3DERR_INVALIDCALL;
2668 hr = wined3d_shader_get_byte_code(shader->wined3d_shader, pData, pSizeOfData);
2669 wined3d_mutex_unlock();
2674 static HRESULT WINAPI IDirect3DDevice8Impl_DrawRectPatch(IDirect3DDevice8 *iface, UINT Handle,
2675 const float *pNumSegs, const D3DRECTPATCH_INFO *pRectPatchInfo)
2677 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2680 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2681 iface, Handle, pNumSegs, pRectPatchInfo);
2683 wined3d_mutex_lock();
2684 hr = wined3d_device_draw_rect_patch(This->wined3d_device, Handle,
2685 pNumSegs, (const WINED3DRECTPATCH_INFO *)pRectPatchInfo);
2686 wined3d_mutex_unlock();
2691 static HRESULT WINAPI IDirect3DDevice8Impl_DrawTriPatch(IDirect3DDevice8 *iface, UINT Handle,
2692 const float *pNumSegs, const D3DTRIPATCH_INFO *pTriPatchInfo)
2694 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2697 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2698 iface, Handle, pNumSegs, pTriPatchInfo);
2700 wined3d_mutex_lock();
2701 hr = wined3d_device_draw_tri_patch(This->wined3d_device, Handle,
2702 pNumSegs, (const WINED3DTRIPATCH_INFO *)pTriPatchInfo);
2703 wined3d_mutex_unlock();
2708 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePatch(IDirect3DDevice8 *iface, UINT Handle)
2710 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2713 TRACE("iface %p, handle %#x.\n", iface, Handle);
2715 wined3d_mutex_lock();
2716 hr = wined3d_device_delete_patch(This->wined3d_device, Handle);
2717 wined3d_mutex_unlock();
2722 static HRESULT WINAPI IDirect3DDevice8Impl_SetStreamSource(IDirect3DDevice8 *iface,
2723 UINT StreamNumber, IDirect3DVertexBuffer8 *pStreamData, UINT Stride)
2725 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2728 TRACE("iface %p, stream_idx %u, buffer %p, stride %u.\n",
2729 iface, StreamNumber, pStreamData, Stride);
2731 wined3d_mutex_lock();
2732 hr = wined3d_device_set_stream_source(This->wined3d_device, StreamNumber,
2733 pStreamData ? ((IDirect3DVertexBuffer8Impl *)pStreamData)->wineD3DVertexBuffer : NULL,
2734 0/* Offset in bytes */, Stride);
2735 wined3d_mutex_unlock();
2740 static HRESULT WINAPI IDirect3DDevice8Impl_GetStreamSource(IDirect3DDevice8 *iface,
2741 UINT StreamNumber, IDirect3DVertexBuffer8 **pStream, UINT *pStride)
2743 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2744 struct wined3d_buffer *retStream = NULL;
2747 TRACE("iface %p, stream_idx %u, buffer %p, stride %p.\n",
2748 iface, StreamNumber, pStream, pStride);
2750 if(pStream == NULL){
2751 return D3DERR_INVALIDCALL;
2754 wined3d_mutex_lock();
2755 hr = wined3d_device_get_stream_source(This->wined3d_device, StreamNumber,
2756 &retStream, 0 /* Offset in bytes */, pStride);
2757 if (SUCCEEDED(hr) && retStream)
2759 *pStream = wined3d_buffer_get_parent(retStream);
2760 IDirect3DVertexBuffer8_AddRef(*pStream);
2761 wined3d_buffer_decref(retStream);
2765 if (FAILED(hr)) FIXME("Call to GetStreamSource failed, hr %#x.\n", hr);
2768 wined3d_mutex_unlock();
2773 static const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl =
2775 IDirect3DDevice8Impl_QueryInterface,
2776 IDirect3DDevice8Impl_AddRef,
2777 IDirect3DDevice8Impl_Release,
2778 IDirect3DDevice8Impl_TestCooperativeLevel,
2779 IDirect3DDevice8Impl_GetAvailableTextureMem,
2780 IDirect3DDevice8Impl_ResourceManagerDiscardBytes,
2781 IDirect3DDevice8Impl_GetDirect3D,
2782 IDirect3DDevice8Impl_GetDeviceCaps,
2783 IDirect3DDevice8Impl_GetDisplayMode,
2784 IDirect3DDevice8Impl_GetCreationParameters,
2785 IDirect3DDevice8Impl_SetCursorProperties,
2786 IDirect3DDevice8Impl_SetCursorPosition,
2787 IDirect3DDevice8Impl_ShowCursor,
2788 IDirect3DDevice8Impl_CreateAdditionalSwapChain,
2789 IDirect3DDevice8Impl_Reset,
2790 IDirect3DDevice8Impl_Present,
2791 IDirect3DDevice8Impl_GetBackBuffer,
2792 IDirect3DDevice8Impl_GetRasterStatus,
2793 IDirect3DDevice8Impl_SetGammaRamp,
2794 IDirect3DDevice8Impl_GetGammaRamp,
2795 IDirect3DDevice8Impl_CreateTexture,
2796 IDirect3DDevice8Impl_CreateVolumeTexture,
2797 IDirect3DDevice8Impl_CreateCubeTexture,
2798 IDirect3DDevice8Impl_CreateVertexBuffer,
2799 IDirect3DDevice8Impl_CreateIndexBuffer,
2800 IDirect3DDevice8Impl_CreateRenderTarget,
2801 IDirect3DDevice8Impl_CreateDepthStencilSurface,
2802 IDirect3DDevice8Impl_CreateImageSurface,
2803 IDirect3DDevice8Impl_CopyRects,
2804 IDirect3DDevice8Impl_UpdateTexture,
2805 IDirect3DDevice8Impl_GetFrontBuffer,
2806 IDirect3DDevice8Impl_SetRenderTarget,
2807 IDirect3DDevice8Impl_GetRenderTarget,
2808 IDirect3DDevice8Impl_GetDepthStencilSurface,
2809 IDirect3DDevice8Impl_BeginScene,
2810 IDirect3DDevice8Impl_EndScene,
2811 IDirect3DDevice8Impl_Clear,
2812 IDirect3DDevice8Impl_SetTransform,
2813 IDirect3DDevice8Impl_GetTransform,
2814 IDirect3DDevice8Impl_MultiplyTransform,
2815 IDirect3DDevice8Impl_SetViewport,
2816 IDirect3DDevice8Impl_GetViewport,
2817 IDirect3DDevice8Impl_SetMaterial,
2818 IDirect3DDevice8Impl_GetMaterial,
2819 IDirect3DDevice8Impl_SetLight,
2820 IDirect3DDevice8Impl_GetLight,
2821 IDirect3DDevice8Impl_LightEnable,
2822 IDirect3DDevice8Impl_GetLightEnable,
2823 IDirect3DDevice8Impl_SetClipPlane,
2824 IDirect3DDevice8Impl_GetClipPlane,
2825 IDirect3DDevice8Impl_SetRenderState,
2826 IDirect3DDevice8Impl_GetRenderState,
2827 IDirect3DDevice8Impl_BeginStateBlock,
2828 IDirect3DDevice8Impl_EndStateBlock,
2829 IDirect3DDevice8Impl_ApplyStateBlock,
2830 IDirect3DDevice8Impl_CaptureStateBlock,
2831 IDirect3DDevice8Impl_DeleteStateBlock,
2832 IDirect3DDevice8Impl_CreateStateBlock,
2833 IDirect3DDevice8Impl_SetClipStatus,
2834 IDirect3DDevice8Impl_GetClipStatus,
2835 IDirect3DDevice8Impl_GetTexture,
2836 IDirect3DDevice8Impl_SetTexture,
2837 IDirect3DDevice8Impl_GetTextureStageState,
2838 IDirect3DDevice8Impl_SetTextureStageState,
2839 IDirect3DDevice8Impl_ValidateDevice,
2840 IDirect3DDevice8Impl_GetInfo,
2841 IDirect3DDevice8Impl_SetPaletteEntries,
2842 IDirect3DDevice8Impl_GetPaletteEntries,
2843 IDirect3DDevice8Impl_SetCurrentTexturePalette,
2844 IDirect3DDevice8Impl_GetCurrentTexturePalette,
2845 IDirect3DDevice8Impl_DrawPrimitive,
2846 IDirect3DDevice8Impl_DrawIndexedPrimitive,
2847 IDirect3DDevice8Impl_DrawPrimitiveUP,
2848 IDirect3DDevice8Impl_DrawIndexedPrimitiveUP,
2849 IDirect3DDevice8Impl_ProcessVertices,
2850 IDirect3DDevice8Impl_CreateVertexShader,
2851 IDirect3DDevice8Impl_SetVertexShader,
2852 IDirect3DDevice8Impl_GetVertexShader,
2853 IDirect3DDevice8Impl_DeleteVertexShader,
2854 IDirect3DDevice8Impl_SetVertexShaderConstant,
2855 IDirect3DDevice8Impl_GetVertexShaderConstant,
2856 IDirect3DDevice8Impl_GetVertexShaderDeclaration,
2857 IDirect3DDevice8Impl_GetVertexShaderFunction,
2858 IDirect3DDevice8Impl_SetStreamSource,
2859 IDirect3DDevice8Impl_GetStreamSource,
2860 IDirect3DDevice8Impl_SetIndices,
2861 IDirect3DDevice8Impl_GetIndices,
2862 IDirect3DDevice8Impl_CreatePixelShader,
2863 IDirect3DDevice8Impl_SetPixelShader,
2864 IDirect3DDevice8Impl_GetPixelShader,
2865 IDirect3DDevice8Impl_DeletePixelShader,
2866 IDirect3DDevice8Impl_SetPixelShaderConstant,
2867 IDirect3DDevice8Impl_GetPixelShaderConstant,
2868 IDirect3DDevice8Impl_GetPixelShaderFunction,
2869 IDirect3DDevice8Impl_DrawRectPatch,
2870 IDirect3DDevice8Impl_DrawTriPatch,
2871 IDirect3DDevice8Impl_DeletePatch
2874 static inline IDirect3DDevice8Impl *impl_from_IWineD3DDeviceParent(IWineD3DDeviceParent *iface)
2876 return CONTAINING_RECORD(iface, IDirect3DDevice8Impl, IWineD3DDeviceParent_iface);
2879 static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface,
2880 REFIID riid, void **object)
2882 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
2883 return IDirect3DDevice8Impl_QueryInterface(&This->IDirect3DDevice8_iface, riid, object);
2886 static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
2888 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
2889 return IDirect3DDevice8Impl_AddRef(&This->IDirect3DDevice8_iface);
2892 static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
2894 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
2895 return IDirect3DDevice8Impl_Release(&This->IDirect3DDevice8_iface);
2898 /* IWineD3DDeviceParent methods */
2900 static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface,
2901 struct wined3d_device *device)
2903 TRACE("iface %p, device %p\n", iface, device);
2906 static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
2907 void *container_parent, UINT width, UINT height, enum wined3d_format_id format, DWORD usage,
2908 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, struct wined3d_surface **surface)
2910 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
2911 IDirect3DSurface8Impl *d3d_surface;
2912 BOOL lockable = TRUE;
2915 TRACE("iface %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
2916 "\tpool %#x, level %u, face %u, surface %p\n",
2917 iface, container_parent, width, height, format, usage, pool, level, face, surface);
2920 if (pool == WINED3DPOOL_DEFAULT && !(usage & WINED3DUSAGE_DYNAMIC)) lockable = FALSE;
2922 hr = IDirect3DDevice8Impl_CreateSurface(This, width, height,
2923 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
2924 (IDirect3DSurface8 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
2927 ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
2931 *surface = d3d_surface->wined3d_surface;
2932 wined3d_surface_incref(*surface);
2934 d3d_surface->container = container_parent;
2935 IUnknown_Release(d3d_surface->parentDevice);
2936 d3d_surface->parentDevice = NULL;
2938 IDirect3DSurface8_Release((IDirect3DSurface8 *)d3d_surface);
2939 d3d_surface->forwardReference = container_parent;
2944 static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
2945 void *container_parent, UINT width, UINT height, enum wined3d_format_id format,
2946 WINED3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality, BOOL lockable,
2947 struct wined3d_surface **surface)
2949 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
2950 IDirect3DSurface8Impl *d3d_surface;
2953 TRACE("iface %p, container_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2954 "\tmultisample_quality %u, lockable %u, surface %p\n",
2955 iface, container_parent, width, height, format, multisample_type, multisample_quality, lockable, surface);
2957 hr = IDirect3DDevice8_CreateRenderTarget(&This->IDirect3DDevice8_iface, width, height,
2958 d3dformat_from_wined3dformat(format), multisample_type, lockable, (IDirect3DSurface8 **)&d3d_surface);
2961 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
2965 *surface = d3d_surface->wined3d_surface;
2966 wined3d_surface_incref(*surface);
2968 d3d_surface->container = (IUnknown *)&This->IDirect3DDevice8_iface;
2969 /* Implicit surfaces are created with an refcount of 0 */
2970 IUnknown_Release((IUnknown *)d3d_surface);
2975 static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
2976 UINT width, UINT height, enum wined3d_format_id format, WINED3DMULTISAMPLE_TYPE multisample_type,
2977 DWORD multisample_quality, BOOL discard, struct wined3d_surface **surface)
2979 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
2980 IDirect3DSurface8Impl *d3d_surface;
2983 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2984 "\tmultisample_quality %u, discard %u, surface %p\n",
2985 iface, width, height, format, multisample_type, multisample_quality, discard, surface);
2987 hr = IDirect3DDevice8_CreateDepthStencilSurface(&This->IDirect3DDevice8_iface, width, height,
2988 d3dformat_from_wined3dformat(format), multisample_type, (IDirect3DSurface8 **)&d3d_surface);
2991 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
2995 *surface = d3d_surface->wined3d_surface;
2996 wined3d_surface_incref(*surface);
2998 d3d_surface->container = (IUnknown *)&This->IDirect3DDevice8_iface;
2999 /* Implicit surfaces are created with an refcount of 0 */
3000 IUnknown_Release((IUnknown *)d3d_surface);
3005 static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
3006 void *container_parent, UINT width, UINT height, UINT depth, enum wined3d_format_id format,
3007 WINED3DPOOL pool, DWORD usage, struct wined3d_volume **volume)
3009 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
3010 IDirect3DVolume8Impl *object;
3013 TRACE("iface %p, container_parent %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
3014 iface, container_parent, width, height, depth, format, pool, usage, volume);
3016 /* Allocate the storage for the device */
3017 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
3020 FIXME("Allocation of memory failed\n");
3022 return D3DERR_OUTOFVIDEOMEMORY;
3025 hr = volume_init(object, This, width, height, depth, usage, format, pool);
3028 WARN("Failed to initialize volume, hr %#x.\n", hr);
3029 HeapFree(GetProcessHeap(), 0, object);
3033 *volume = object->wined3d_volume;
3034 wined3d_volume_incref(*volume);
3035 IDirect3DVolume8_Release(&object->IDirect3DVolume8_iface);
3037 object->container = container_parent;
3038 object->forwardReference = container_parent;
3040 TRACE("(%p) Created volume %p\n", iface, object);
3045 static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
3046 WINED3DPRESENT_PARAMETERS *present_parameters, struct wined3d_swapchain **swapchain)
3048 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
3049 D3DPRESENT_PARAMETERS local_parameters;
3050 IDirect3DSwapChain8 *d3d_swapchain;
3053 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
3055 /* Copy the presentation parameters */
3056 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
3057 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
3058 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
3059 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
3060 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
3061 local_parameters.SwapEffect = present_parameters->SwapEffect;
3062 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
3063 local_parameters.Windowed = present_parameters->Windowed;
3064 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
3065 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
3066 local_parameters.Flags = present_parameters->Flags;
3067 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
3068 local_parameters.FullScreen_PresentationInterval = present_parameters->PresentationInterval;
3070 hr = IDirect3DDevice8_CreateAdditionalSwapChain(&This->IDirect3DDevice8_iface,
3071 &local_parameters, &d3d_swapchain);
3074 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
3079 *swapchain = ((IDirect3DSwapChain8Impl *)d3d_swapchain)->wined3d_swapchain;
3080 wined3d_swapchain_incref(*swapchain);
3081 IDirect3DSwapChain8_Release(d3d_swapchain);
3083 /* Copy back the presentation parameters */
3084 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
3085 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
3086 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
3087 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
3088 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
3089 present_parameters->SwapEffect = local_parameters.SwapEffect;
3090 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
3091 present_parameters->Windowed = local_parameters.Windowed;
3092 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
3093 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
3094 present_parameters->Flags = local_parameters.Flags;
3095 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
3096 present_parameters->PresentationInterval = local_parameters.FullScreen_PresentationInterval;
3101 static const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl =
3103 /* IUnknown methods */
3104 device_parent_QueryInterface,
3105 device_parent_AddRef,
3106 device_parent_Release,
3107 /* IWineD3DDeviceParent methods */
3108 device_parent_WineD3DDeviceCreated,
3109 device_parent_CreateSurface,
3110 device_parent_CreateRenderTarget,
3111 device_parent_CreateDepthStencilSurface,
3112 device_parent_CreateVolume,
3113 device_parent_CreateSwapChain,
3116 static void setup_fpu(void)
3118 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3120 __asm__ volatile ("fnstcw %0" : "=m" (cw));
3121 cw = (cw & ~0xf3f) | 0x3f;
3122 __asm__ volatile ("fldcw %0" : : "m" (cw));
3124 FIXME("FPU setup not implemented for this platform.\n");
3128 HRESULT device_init(IDirect3DDevice8Impl *device, struct wined3d *wined3d, UINT adapter,
3129 D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters)
3131 WINED3DPRESENT_PARAMETERS wined3d_parameters;
3134 device->IDirect3DDevice8_iface.lpVtbl = &Direct3DDevice8_Vtbl;
3135 device->IWineD3DDeviceParent_iface.lpVtbl = &d3d8_wined3d_device_parent_vtbl;
3137 device->handle_table.entries = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
3138 D3D8_INITIAL_HANDLE_TABLE_SIZE * sizeof(*device->handle_table.entries));
3139 if (!device->handle_table.entries)
3141 ERR("Failed to allocate handle table memory.\n");
3142 return E_OUTOFMEMORY;
3144 device->handle_table.table_size = D3D8_INITIAL_HANDLE_TABLE_SIZE;
3146 if (!(flags & D3DCREATE_FPU_PRESERVE)) setup_fpu();
3148 wined3d_mutex_lock();
3149 hr = wined3d_device_create(wined3d, adapter, device_type, focus_window, flags,
3150 &device->IWineD3DDeviceParent_iface, &device->wined3d_device);
3153 WARN("Failed to create wined3d device, hr %#x.\n", hr);
3154 wined3d_mutex_unlock();
3155 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
3159 if (!parameters->Windowed)
3161 HWND device_window = parameters->hDeviceWindow;
3164 focus_window = device_window;
3165 if (FAILED(hr = wined3d_device_acquire_focus_window(device->wined3d_device, focus_window)))
3167 ERR("Failed to acquire focus window, hr %#x.\n", hr);
3168 wined3d_device_decref(device->wined3d_device);
3169 wined3d_mutex_unlock();
3170 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
3175 device_window = focus_window;
3176 wined3d_device_setup_fullscreen_window(device->wined3d_device, device_window,
3177 parameters->BackBufferWidth,
3178 parameters->BackBufferHeight);
3181 if (flags & D3DCREATE_MULTITHREADED)
3182 wined3d_device_set_multithreaded(device->wined3d_device);
3184 wined3d_parameters.BackBufferWidth = parameters->BackBufferWidth;
3185 wined3d_parameters.BackBufferHeight = parameters->BackBufferHeight;
3186 wined3d_parameters.BackBufferFormat = wined3dformat_from_d3dformat(parameters->BackBufferFormat);
3187 wined3d_parameters.BackBufferCount = parameters->BackBufferCount;
3188 wined3d_parameters.MultiSampleType = parameters->MultiSampleType;
3189 wined3d_parameters.MultiSampleQuality = 0; /* d3d9 only */
3190 wined3d_parameters.SwapEffect = parameters->SwapEffect;
3191 wined3d_parameters.hDeviceWindow = parameters->hDeviceWindow;
3192 wined3d_parameters.Windowed = parameters->Windowed;
3193 wined3d_parameters.EnableAutoDepthStencil = parameters->EnableAutoDepthStencil;
3194 wined3d_parameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(parameters->AutoDepthStencilFormat);
3195 wined3d_parameters.Flags = parameters->Flags;
3196 wined3d_parameters.FullScreen_RefreshRateInHz = parameters->FullScreen_RefreshRateInHz;
3197 wined3d_parameters.PresentationInterval = parameters->FullScreen_PresentationInterval;
3198 wined3d_parameters.AutoRestoreDisplayMode = TRUE;
3200 hr = wined3d_device_init_3d(device->wined3d_device, &wined3d_parameters);
3203 WARN("Failed to initialize 3D, hr %#x.\n", hr);
3204 wined3d_device_release_focus_window(device->wined3d_device);
3205 wined3d_device_decref(device->wined3d_device);
3206 wined3d_mutex_unlock();
3207 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
3211 hr = wined3d_device_set_render_state(device->wined3d_device, WINED3DRS_POINTSIZE_MIN, 0);
3212 wined3d_mutex_unlock();
3215 ERR("Failed to set minimum pointsize, hr %#x.\n", hr);
3219 parameters->BackBufferWidth = wined3d_parameters.BackBufferWidth;
3220 parameters->BackBufferHeight = wined3d_parameters.BackBufferHeight;
3221 parameters->BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters.BackBufferFormat);
3222 parameters->BackBufferCount = wined3d_parameters.BackBufferCount;
3223 parameters->MultiSampleType = wined3d_parameters.MultiSampleType;
3224 parameters->SwapEffect = wined3d_parameters.SwapEffect;
3225 parameters->hDeviceWindow = wined3d_parameters.hDeviceWindow;
3226 parameters->Windowed = wined3d_parameters.Windowed;
3227 parameters->EnableAutoDepthStencil = wined3d_parameters.EnableAutoDepthStencil;
3228 parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(wined3d_parameters.AutoDepthStencilFormat);
3229 parameters->Flags = wined3d_parameters.Flags;
3230 parameters->FullScreen_RefreshRateInHz = wined3d_parameters.FullScreen_RefreshRateInHz;
3231 parameters->FullScreen_PresentationInterval = wined3d_parameters.PresentationInterval;
3233 device->declArraySize = 16;
3234 device->decls = HeapAlloc(GetProcessHeap(), 0, device->declArraySize * sizeof(*device->decls));
3237 ERR("Failed to allocate FVF vertex delcaration map memory.\n");
3245 wined3d_mutex_lock();
3246 wined3d_device_uninit_3d(device->wined3d_device);
3247 wined3d_device_release_focus_window(device->wined3d_device);
3248 wined3d_device_decref(device->wined3d_device);
3249 wined3d_mutex_unlock();
3250 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);