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 ULONG WINAPI D3D8CB_DestroySwapChain(IWineD3DSwapChain *swapchain)
261 TRACE("swapchain %p.\n", swapchain);
263 parent = IWineD3DSwapChain_GetParent(swapchain);
264 return IUnknown_Release(parent);
267 static inline IDirect3DDevice8Impl *impl_from_IDirect3DDevice8(IDirect3DDevice8 *iface)
269 return CONTAINING_RECORD(iface, IDirect3DDevice8Impl, IDirect3DDevice8_iface);
272 static HRESULT WINAPI IDirect3DDevice8Impl_QueryInterface(IDirect3DDevice8 *iface, REFIID riid,
275 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
277 TRACE("iface %p, riid %s, object %p.\n",
278 iface, debugstr_guid(riid), ppobj);
280 if (IsEqualGUID(riid, &IID_IUnknown)
281 || IsEqualGUID(riid, &IID_IDirect3DDevice8)) {
282 IUnknown_AddRef(iface);
287 if (IsEqualGUID(riid, &IID_IWineD3DDeviceParent))
289 IWineD3DDeviceParent_AddRef(&This->IWineD3DDeviceParent_iface);
290 *ppobj = &This->IWineD3DDeviceParent_iface;
294 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
296 return E_NOINTERFACE;
299 static ULONG WINAPI IDirect3DDevice8Impl_AddRef(IDirect3DDevice8 *iface)
301 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
302 ULONG ref = InterlockedIncrement(&This->ref);
304 TRACE("%p increasing refcount to %u.\n", iface, ref);
309 static ULONG WINAPI IDirect3DDevice8Impl_Release(IDirect3DDevice8 *iface)
311 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
314 if (This->inDestruction) return 0;
315 ref = InterlockedDecrement(&This->ref);
317 TRACE("%p decreasing refcount to %u.\n", iface, ref);
322 TRACE("Releasing wined3d device %p\n", This->WineD3DDevice);
324 wined3d_mutex_lock();
326 This->inDestruction = TRUE;
328 for(i = 0; i < This->numConvertedDecls; i++) {
329 IDirect3DVertexDeclaration8_Release(This->decls[i].decl);
331 HeapFree(GetProcessHeap(), 0, This->decls);
333 IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D8CB_DestroySwapChain);
334 IWineD3DDevice_ReleaseFocusWindow(This->WineD3DDevice);
335 IWineD3DDevice_Release(This->WineD3DDevice);
336 HeapFree(GetProcessHeap(), 0, This->handle_table.entries);
337 HeapFree(GetProcessHeap(), 0, This);
339 wined3d_mutex_unlock();
344 /* IDirect3DDevice Interface follow: */
345 static HRESULT WINAPI IDirect3DDevice8Impl_TestCooperativeLevel(IDirect3DDevice8 *iface)
347 TRACE("iface %p.\n", iface);
352 static UINT WINAPI IDirect3DDevice8Impl_GetAvailableTextureMem(IDirect3DDevice8 *iface)
354 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
357 TRACE("iface %p.\n", iface);
359 wined3d_mutex_lock();
360 hr = IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
361 wined3d_mutex_unlock();
366 static HRESULT WINAPI IDirect3DDevice8Impl_ResourceManagerDiscardBytes(IDirect3DDevice8 *iface,
369 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
372 TRACE("iface %p, byte_count %u.\n", iface, Bytes);
373 FIXME("Byte count ignored.\n");
375 wined3d_mutex_lock();
376 hr = IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
377 wined3d_mutex_unlock();
382 static HRESULT WINAPI IDirect3DDevice8Impl_GetDirect3D(IDirect3DDevice8 *iface, IDirect3D8 **ppD3D8)
384 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
385 struct wined3d *wined3d;
388 TRACE("iface %p, d3d8 %p.\n", iface, ppD3D8);
390 if (NULL == ppD3D8) {
391 return D3DERR_INVALIDCALL;
394 wined3d_mutex_lock();
395 hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &wined3d);
396 if (SUCCEEDED(hr) && wined3d)
398 *ppD3D8 = wined3d_get_parent(wined3d);
399 IDirect3D8_AddRef(*ppD3D8);
400 wined3d_decref(wined3d);
404 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
407 wined3d_mutex_unlock();
409 TRACE("(%p) returning %p\n",This , *ppD3D8);
414 static HRESULT WINAPI IDirect3DDevice8Impl_GetDeviceCaps(IDirect3DDevice8 *iface, D3DCAPS8 *pCaps)
416 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
417 HRESULT hrc = D3D_OK;
418 WINED3DCAPS *pWineCaps;
420 TRACE("iface %p, caps %p.\n", iface, pCaps);
423 return D3DERR_INVALIDCALL;
425 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
426 if(pWineCaps == NULL){
427 return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
430 wined3d_mutex_lock();
431 hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
432 wined3d_mutex_unlock();
434 fixup_caps(pWineCaps);
435 WINECAPSTOD3D8CAPS(pCaps, pWineCaps)
436 HeapFree(GetProcessHeap(), 0, pWineCaps);
438 TRACE("Returning %p %p\n", This, pCaps);
442 static HRESULT WINAPI IDirect3DDevice8Impl_GetDisplayMode(IDirect3DDevice8 *iface,
443 D3DDISPLAYMODE *pMode)
445 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
448 TRACE("iface %p, mode %p.\n", iface, pMode);
450 wined3d_mutex_lock();
451 hr = IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, 0, (WINED3DDISPLAYMODE *) pMode);
452 wined3d_mutex_unlock();
454 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
459 static HRESULT WINAPI IDirect3DDevice8Impl_GetCreationParameters(IDirect3DDevice8 *iface,
460 D3DDEVICE_CREATION_PARAMETERS *pParameters)
462 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
465 TRACE("iface %p, parameters %p.\n", iface, pParameters);
467 wined3d_mutex_lock();
468 hr = IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
469 wined3d_mutex_unlock();
474 static HRESULT WINAPI IDirect3DDevice8Impl_SetCursorProperties(IDirect3DDevice8 *iface,
475 UINT XHotSpot, UINT YHotSpot, IDirect3DSurface8 *pCursorBitmap)
477 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
478 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl*)pCursorBitmap;
481 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
482 iface, XHotSpot, YHotSpot, pCursorBitmap);
486 WARN("No cursor bitmap, returning D3DERR_INVALIDCALL.\n");
487 return D3DERR_INVALIDCALL;
490 wined3d_mutex_lock();
491 hr = IWineD3DDevice_SetCursorProperties(This->WineD3DDevice,XHotSpot,YHotSpot,pSurface->wineD3DSurface);
492 wined3d_mutex_unlock();
497 static void WINAPI IDirect3DDevice8Impl_SetCursorPosition(IDirect3DDevice8 *iface,
498 UINT XScreenSpace, UINT YScreenSpace, DWORD Flags)
500 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
502 TRACE("iface %p, x %u, y %u, flags %#x.\n",
503 iface, XScreenSpace, YScreenSpace, Flags);
505 wined3d_mutex_lock();
506 IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
507 wined3d_mutex_unlock();
510 static BOOL WINAPI IDirect3DDevice8Impl_ShowCursor(IDirect3DDevice8 *iface, BOOL bShow)
512 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
515 TRACE("iface %p, show %#x.\n", iface, bShow);
517 wined3d_mutex_lock();
518 ret = IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
519 wined3d_mutex_unlock();
524 static HRESULT WINAPI IDirect3DDevice8Impl_CreateAdditionalSwapChain(IDirect3DDevice8 *iface,
525 D3DPRESENT_PARAMETERS *present_parameters, IDirect3DSwapChain8 **swapchain)
527 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
528 IDirect3DSwapChain8Impl *object;
531 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
532 iface, present_parameters, swapchain);
534 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
537 ERR("Failed to allocate swapchain memory.\n");
538 return E_OUTOFMEMORY;
541 hr = swapchain_init(object, This, present_parameters);
544 WARN("Failed to initialize swapchain, hr %#x.\n", hr);
545 HeapFree(GetProcessHeap(), 0, object);
549 TRACE("Created swapchain %p.\n", object);
550 *swapchain = &object->IDirect3DSwapChain8_iface;
555 static HRESULT WINAPI IDirect3DDevice8Impl_Reset(IDirect3DDevice8 *iface,
556 D3DPRESENT_PARAMETERS *pPresentationParameters)
558 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
559 WINED3DPRESENT_PARAMETERS localParameters;
562 TRACE("iface %p, present_parameters %p.\n", iface, pPresentationParameters);
564 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
565 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
566 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
567 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
568 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
569 localParameters.MultiSampleQuality = 0; /* d3d9 only */
570 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
571 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
572 localParameters.Windowed = pPresentationParameters->Windowed;
573 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
574 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
575 localParameters.Flags = pPresentationParameters->Flags;
576 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
577 localParameters.PresentationInterval = pPresentationParameters->FullScreen_PresentationInterval;
578 localParameters.AutoRestoreDisplayMode = TRUE;
580 wined3d_mutex_lock();
581 hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
583 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, WINED3DRS_POINTSIZE_MIN, 0);
585 wined3d_mutex_unlock();
587 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
588 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
589 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
590 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
591 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
592 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
593 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
594 pPresentationParameters->Windowed = localParameters.Windowed;
595 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
596 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
597 pPresentationParameters->Flags = localParameters.Flags;
598 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
599 pPresentationParameters->FullScreen_PresentationInterval = localParameters.PresentationInterval;
604 static HRESULT WINAPI IDirect3DDevice8Impl_Present(IDirect3DDevice8 *iface, const RECT *pSourceRect,
605 const RECT *pDestRect, HWND hDestWindowOverride, const RGNDATA *pDirtyRegion)
607 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
610 TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
611 iface, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
613 wined3d_mutex_lock();
614 hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
615 wined3d_mutex_unlock();
620 static HRESULT WINAPI IDirect3DDevice8Impl_GetBackBuffer(IDirect3DDevice8 *iface,
621 UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8 **ppBackBuffer)
623 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
624 IWineD3DSurface *retSurface = NULL;
627 TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
628 iface, BackBuffer, Type, ppBackBuffer);
630 wined3d_mutex_lock();
631 hr = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, 0, BackBuffer, (WINED3DBACKBUFFER_TYPE)Type, &retSurface);
632 if (SUCCEEDED(hr) && retSurface && ppBackBuffer)
634 *ppBackBuffer = IWineD3DSurface_GetParent(retSurface);
635 IDirect3DSurface8_AddRef(*ppBackBuffer);
636 IWineD3DSurface_Release(retSurface);
638 wined3d_mutex_unlock();
643 static HRESULT WINAPI IDirect3DDevice8Impl_GetRasterStatus(IDirect3DDevice8 *iface,
644 D3DRASTER_STATUS *pRasterStatus)
646 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
649 TRACE("iface %p, raster_status %p.\n", iface, pRasterStatus);
651 wined3d_mutex_lock();
652 hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, 0, (WINED3DRASTER_STATUS *) pRasterStatus);
653 wined3d_mutex_unlock();
658 static void WINAPI IDirect3DDevice8Impl_SetGammaRamp(IDirect3DDevice8 *iface, DWORD Flags,
659 const D3DGAMMARAMP *pRamp)
661 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
663 TRACE("iface %p, flags %#x, ramp %p.\n", iface, Flags, pRamp);
665 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
666 wined3d_mutex_lock();
667 IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, 0, Flags, (CONST WINED3DGAMMARAMP *) pRamp);
668 wined3d_mutex_unlock();
671 static void WINAPI IDirect3DDevice8Impl_GetGammaRamp(IDirect3DDevice8 *iface, D3DGAMMARAMP *pRamp)
673 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
675 TRACE("iface %p, ramp %p.\n", iface, pRamp);
677 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
678 wined3d_mutex_lock();
679 IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, 0, (WINED3DGAMMARAMP *) pRamp);
680 wined3d_mutex_unlock();
683 static HRESULT WINAPI IDirect3DDevice8Impl_CreateTexture(IDirect3DDevice8 *iface,
684 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
685 D3DPOOL pool, IDirect3DTexture8 **texture)
687 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
688 IDirect3DTexture8Impl *object;
691 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
692 iface, width, height, levels, usage, format, pool, texture);
694 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
697 ERR("Failed to allocate texture memory.\n");
698 return D3DERR_OUTOFVIDEOMEMORY;
701 hr = texture_init(object, This, width, height, levels, usage, format, pool);
704 WARN("Failed to initialize texture, hr %#x.\n", hr);
705 HeapFree(GetProcessHeap(), 0, object);
709 TRACE("Created texture %p.\n", object);
710 *texture = &object->IDirect3DTexture8_iface;
715 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVolumeTexture(IDirect3DDevice8 *iface,
716 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
717 D3DPOOL pool, IDirect3DVolumeTexture8 **texture)
719 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
720 IDirect3DVolumeTexture8Impl *object;
723 TRACE("iface %p, width %u, height %u, depth %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
724 iface, width, height, depth, levels, usage, format, pool, texture);
726 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
729 ERR("Failed to allocate volume texture memory.\n");
730 return D3DERR_OUTOFVIDEOMEMORY;
733 hr = volumetexture_init(object, This, width, height, depth, levels, usage, format, pool);
736 WARN("Failed to initialize volume texture, hr %#x.\n", hr);
737 HeapFree(GetProcessHeap(), 0, object);
741 TRACE("Created volume texture %p.\n", object);
742 *texture = &object->IDirect3DVolumeTexture8_iface;
747 static HRESULT WINAPI IDirect3DDevice8Impl_CreateCubeTexture(IDirect3DDevice8 *iface, UINT edge_length,
748 UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool, IDirect3DCubeTexture8 **texture)
750 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
751 IDirect3DCubeTexture8Impl *object;
754 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
755 iface, edge_length, levels, usage, format, pool, texture);
757 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
760 ERR("Failed to allocate cube texture memory.\n");
761 return D3DERR_OUTOFVIDEOMEMORY;
764 hr = cubetexture_init(object, This, edge_length, levels, usage, format, pool);
767 WARN("Failed to initialize cube texture, hr %#x.\n", hr);
768 HeapFree(GetProcessHeap(), 0, object);
772 TRACE("Created cube texture %p.\n", object);
773 *texture = &object->IDirect3DCubeTexture8_iface;
778 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexBuffer(IDirect3DDevice8 *iface, UINT size,
779 DWORD usage, DWORD fvf, D3DPOOL pool, IDirect3DVertexBuffer8 **buffer)
781 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
782 IDirect3DVertexBuffer8Impl *object;
785 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p.\n",
786 iface, size, usage, fvf, pool, buffer);
788 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
791 ERR("Failed to allocate buffer memory.\n");
792 return D3DERR_OUTOFVIDEOMEMORY;
795 hr = vertexbuffer_init(object, This, size, usage, fvf, pool);
798 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr);
799 HeapFree(GetProcessHeap(), 0, object);
803 TRACE("Created vertex buffer %p.\n", object);
804 *buffer = (IDirect3DVertexBuffer8 *)object;
809 static HRESULT WINAPI IDirect3DDevice8Impl_CreateIndexBuffer(IDirect3DDevice8 *iface, UINT size,
810 DWORD usage, D3DFORMAT format, D3DPOOL pool, IDirect3DIndexBuffer8 **buffer)
812 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
813 IDirect3DIndexBuffer8Impl *object;
816 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p.\n",
817 iface, size, usage, format, pool, buffer);
819 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
822 ERR("Failed to allocate buffer memory.\n");
823 return D3DERR_OUTOFVIDEOMEMORY;
826 hr = indexbuffer_init(object, This, size, usage, format, pool);
829 WARN("Failed to initialize index buffer, hr %#x.\n", hr);
830 HeapFree(GetProcessHeap(), 0, object);
834 TRACE("Created index buffer %p.\n", object);
835 *buffer = (IDirect3DIndexBuffer8 *)object;
840 static HRESULT IDirect3DDevice8Impl_CreateSurface(IDirect3DDevice8Impl *device, UINT Width,
841 UINT Height, D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level,
842 IDirect3DSurface8 **ppSurface, UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample,
843 DWORD MultisampleQuality)
845 IDirect3DSurface8Impl *object;
848 TRACE("device %p, width %u, height %u, format %#x, lockable %#x, discard %#x, level %u, surface %p,\n"
849 "\tusage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
850 device, Width, Height, Format, Lockable, Discard, Level, ppSurface,
851 Usage, Pool, MultiSample, MultisampleQuality);
853 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface8Impl));
856 FIXME("Failed to allocate surface memory.\n");
857 return D3DERR_OUTOFVIDEOMEMORY;
860 hr = surface_init(object, device, Width, Height, Format, Lockable, Discard, Level, Usage,
861 Pool, MultiSample, MultisampleQuality);
864 WARN("Failed to initialize surface, hr %#x.\n", hr);
865 HeapFree(GetProcessHeap(), 0, object);
869 TRACE("Created surface %p.\n", object);
870 *ppSurface = (IDirect3DSurface8 *)object;
875 static HRESULT WINAPI IDirect3DDevice8Impl_CreateRenderTarget(IDirect3DDevice8 *iface, UINT Width,
876 UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, BOOL Lockable,
877 IDirect3DSurface8 **ppSurface)
879 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
882 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, lockable %#x, surface %p.\n",
883 iface, Width, Height, Format, MultiSample, Lockable, ppSurface);
885 hr = IDirect3DDevice8Impl_CreateSurface(This, Width, Height, Format, Lockable,
886 FALSE /* Discard */, 0 /* Level */, ppSurface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT,
892 static HRESULT WINAPI IDirect3DDevice8Impl_CreateDepthStencilSurface(IDirect3DDevice8 *iface,
893 UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample,
894 IDirect3DSurface8 **ppSurface)
896 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
899 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, surface %p.\n",
900 iface, Width, Height, Format, MultiSample, ppSurface);
902 /* TODO: Verify that Discard is false */
903 hr = IDirect3DDevice8Impl_CreateSurface(This, Width, Height, Format, TRUE /* Lockable */, FALSE,
904 0 /* Level */, ppSurface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, MultiSample, 0);
909 /* IDirect3DDevice8Impl::CreateImageSurface returns surface with pool type SYSTEMMEM */
910 static HRESULT WINAPI IDirect3DDevice8Impl_CreateImageSurface(IDirect3DDevice8 *iface, UINT Width,
911 UINT Height, D3DFORMAT Format, IDirect3DSurface8 **ppSurface)
913 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
916 TRACE("iface %p, width %u, height %u, format %#x, surface %p.\n",
917 iface, Width, Height, Format, ppSurface);
919 hr = IDirect3DDevice8Impl_CreateSurface(This, Width, Height, Format, TRUE /* Lockable */,
920 FALSE /* Discard */, 0 /* Level */, ppSurface, 0 /* Usage (undefined/none) */,
921 D3DPOOL_SYSTEMMEM, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
926 static HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(IDirect3DDevice8 *iface,
927 IDirect3DSurface8 *pSourceSurface, const RECT *pSourceRects, UINT cRects,
928 IDirect3DSurface8 *pDestinationSurface, const POINT *pDestPoints)
930 IDirect3DSurface8Impl *Source = (IDirect3DSurface8Impl *) pSourceSurface;
931 IDirect3DSurface8Impl *Dest = (IDirect3DSurface8Impl *) pDestinationSurface;
932 enum wined3d_format_id srcFormat, destFormat;
933 struct wined3d_resource_desc wined3d_desc;
934 struct wined3d_resource *wined3d_resource;
936 TRACE("iface %p, src_surface %p, src_rects %p, rect_count %u, dst_surface %p, dst_points %p.\n",
937 iface, pSourceSurface, pSourceRects, cRects, pDestinationSurface, pDestPoints);
939 /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the
940 * destination texture is in WINED3DPOOL_DEFAULT. */
942 wined3d_mutex_lock();
943 wined3d_resource = IWineD3DSurface_GetResource(Source->wineD3DSurface);
944 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
945 srcFormat = wined3d_desc.format;
947 wined3d_resource = IWineD3DSurface_GetResource(Dest->wineD3DSurface);
948 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
949 destFormat = wined3d_desc.format;
951 /* Check that the source and destination formats match */
952 if (srcFormat != destFormat && WINED3DFMT_UNKNOWN != destFormat)
954 WARN("Source %p format must match the dest %p format, returning D3DERR_INVALIDCALL.\n",
955 pSourceSurface, pDestinationSurface);
956 wined3d_mutex_unlock();
957 return D3DERR_INVALIDCALL;
959 else if (WINED3DFMT_UNKNOWN == destFormat)
961 TRACE("(%p) : Converting destination surface from WINED3DFMT_UNKNOWN to the source format\n", iface);
962 IWineD3DSurface_SetFormat(Dest->wineD3DSurface, srcFormat);
965 /* Quick if complete copy ... */
966 if (cRects == 0 && pSourceRects == NULL && pDestPoints == NULL) {
967 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
970 /* Copy rect by rect */
971 if (NULL != pSourceRects && NULL != pDestPoints) {
972 for (i = 0; i < cRects; ++i) {
973 IWineD3DSurface_BltFast(Dest->wineD3DSurface, pDestPoints[i].x, pDestPoints[i].y, Source->wineD3DSurface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
976 for (i = 0; i < cRects; ++i) {
977 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
981 wined3d_mutex_unlock();
986 static HRESULT WINAPI IDirect3DDevice8Impl_UpdateTexture(IDirect3DDevice8 *iface,
987 IDirect3DBaseTexture8 *pSourceTexture, IDirect3DBaseTexture8 *pDestinationTexture)
989 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
992 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface, pSourceTexture, pDestinationTexture);
994 wined3d_mutex_lock();
995 hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice, ((IDirect3DBaseTexture8Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture8Impl *)pDestinationTexture)->wineD3DBaseTexture);
996 wined3d_mutex_unlock();
1001 static HRESULT WINAPI IDirect3DDevice8Impl_GetFrontBuffer(IDirect3DDevice8 *iface,
1002 IDirect3DSurface8 *pDestSurface)
1004 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1005 IDirect3DSurface8Impl *destSurface = (IDirect3DSurface8Impl *)pDestSurface;
1008 TRACE("iface %p, dst_surface %p.\n", iface, pDestSurface);
1010 if (pDestSurface == NULL) {
1011 WARN("(%p) : Caller passed NULL as pDestSurface returning D3DERR_INVALIDCALL\n", This);
1012 return D3DERR_INVALIDCALL;
1015 wined3d_mutex_lock();
1016 hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, 0, destSurface->wineD3DSurface);
1017 wined3d_mutex_unlock();
1022 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderTarget(IDirect3DDevice8 *iface,
1023 IDirect3DSurface8 *pRenderTarget, IDirect3DSurface8 *pNewZStencil)
1025 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1026 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl *)pRenderTarget;
1027 IDirect3DSurface8Impl *pZSurface = (IDirect3DSurface8Impl *)pNewZStencil;
1028 IWineD3DSurface *original_ds = NULL;
1031 TRACE("iface %p, render_target %p, depth_stencil %p.\n", iface, pRenderTarget, pNewZStencil);
1033 wined3d_mutex_lock();
1037 struct wined3d_resource_desc ds_desc, rt_desc;
1038 struct wined3d_resource *wined3d_resource;
1040 wined3d_resource = IWineD3DSurface_GetResource(pZSurface->wineD3DSurface);
1041 wined3d_resource_get_desc(wined3d_resource, &ds_desc);
1042 wined3d_resource = IWineD3DSurface_GetResource(pSurface->wineD3DSurface);
1043 wined3d_resource_get_desc(wined3d_resource, &rt_desc);
1045 if (ds_desc.width < rt_desc.width || ds_desc.height < rt_desc.height)
1047 WARN("Depth stencil is smaller than the render target, returning D3DERR_INVALIDCALL\n");
1048 wined3d_mutex_unlock();
1049 return D3DERR_INVALIDCALL;
1053 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice, &original_ds);
1054 if (hr == WINED3D_OK || hr == WINED3DERR_NOTFOUND)
1056 hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, pZSurface ? pZSurface->wineD3DSurface : NULL);
1057 if (SUCCEEDED(hr) && pSurface)
1058 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, 0, pSurface->wineD3DSurface, TRUE);
1059 if (FAILED(hr)) IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, original_ds);
1061 if (original_ds) IWineD3DSurface_Release(original_ds);
1063 wined3d_mutex_unlock();
1068 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderTarget(IDirect3DDevice8 *iface,
1069 IDirect3DSurface8 **ppRenderTarget)
1071 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1072 IWineD3DSurface *pRenderTarget;
1075 TRACE("iface %p, render_target %p.\n", iface, ppRenderTarget);
1077 if (ppRenderTarget == NULL) {
1078 return D3DERR_INVALIDCALL;
1081 wined3d_mutex_lock();
1082 hr = IWineD3DDevice_GetRenderTarget(This->WineD3DDevice, 0, &pRenderTarget);
1083 if (SUCCEEDED(hr) && pRenderTarget)
1085 *ppRenderTarget = IWineD3DSurface_GetParent(pRenderTarget);
1086 IDirect3DSurface8_AddRef(*ppRenderTarget);
1087 IWineD3DSurface_Release(pRenderTarget);
1091 FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
1092 *ppRenderTarget = NULL;
1094 wined3d_mutex_unlock();
1099 static HRESULT WINAPI IDirect3DDevice8Impl_GetDepthStencilSurface(IDirect3DDevice8 *iface,
1100 IDirect3DSurface8 **ppZStencilSurface)
1102 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1103 IWineD3DSurface *pZStencilSurface;
1106 TRACE("iface %p, depth_stencil %p.\n", iface, ppZStencilSurface);
1108 if(ppZStencilSurface == NULL){
1109 return D3DERR_INVALIDCALL;
1112 wined3d_mutex_lock();
1113 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice, &pZStencilSurface);
1116 *ppZStencilSurface = IWineD3DSurface_GetParent(pZStencilSurface);
1117 IDirect3DSurface8_AddRef(*ppZStencilSurface);
1118 IWineD3DSurface_Release(pZStencilSurface);
1122 if (hr != WINED3DERR_NOTFOUND)
1123 FIXME("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
1124 *ppZStencilSurface = NULL;
1126 wined3d_mutex_unlock();
1131 static HRESULT WINAPI IDirect3DDevice8Impl_BeginScene(IDirect3DDevice8 *iface)
1133 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1136 TRACE("iface %p.\n", iface);
1138 wined3d_mutex_lock();
1139 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
1140 wined3d_mutex_unlock();
1145 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice8Impl_EndScene(IDirect3DDevice8 *iface)
1147 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1150 TRACE("iface %p.\n", iface);
1152 wined3d_mutex_lock();
1153 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
1154 wined3d_mutex_unlock();
1159 static HRESULT WINAPI IDirect3DDevice8Impl_Clear(IDirect3DDevice8 *iface, DWORD Count,
1160 const D3DRECT *pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil)
1162 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1165 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1166 iface, Count, pRects, Flags, Color, Z, Stencil);
1168 wined3d_mutex_lock();
1169 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (const RECT *)pRects, Flags, Color, Z, Stencil);
1170 wined3d_mutex_unlock();
1175 static HRESULT WINAPI IDirect3DDevice8Impl_SetTransform(IDirect3DDevice8 *iface,
1176 D3DTRANSFORMSTATETYPE State, const D3DMATRIX *lpMatrix)
1178 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1181 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, lpMatrix);
1183 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1184 wined3d_mutex_lock();
1185 hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
1186 wined3d_mutex_unlock();
1191 static HRESULT WINAPI IDirect3DDevice8Impl_GetTransform(IDirect3DDevice8 *iface,
1192 D3DTRANSFORMSTATETYPE State, D3DMATRIX *pMatrix)
1194 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1197 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1199 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1200 wined3d_mutex_lock();
1201 hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
1202 wined3d_mutex_unlock();
1207 static HRESULT WINAPI IDirect3DDevice8Impl_MultiplyTransform(IDirect3DDevice8 *iface,
1208 D3DTRANSFORMSTATETYPE State, const D3DMATRIX *pMatrix)
1210 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1213 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1215 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1216 wined3d_mutex_lock();
1217 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
1218 wined3d_mutex_unlock();
1223 static HRESULT WINAPI IDirect3DDevice8Impl_SetViewport(IDirect3DDevice8 *iface,
1224 const D3DVIEWPORT8 *pViewport)
1226 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1229 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1231 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1232 wined3d_mutex_lock();
1233 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
1234 wined3d_mutex_unlock();
1239 static HRESULT WINAPI IDirect3DDevice8Impl_GetViewport(IDirect3DDevice8 *iface,
1240 D3DVIEWPORT8 *pViewport)
1242 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1245 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1247 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1248 wined3d_mutex_lock();
1249 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
1250 wined3d_mutex_unlock();
1255 static HRESULT WINAPI IDirect3DDevice8Impl_SetMaterial(IDirect3DDevice8 *iface,
1256 const D3DMATERIAL8 *pMaterial)
1258 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1261 TRACE("iface %p, material %p.\n", iface, pMaterial);
1263 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1264 wined3d_mutex_lock();
1265 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
1266 wined3d_mutex_unlock();
1271 static HRESULT WINAPI IDirect3DDevice8Impl_GetMaterial(IDirect3DDevice8 *iface,
1272 D3DMATERIAL8 *pMaterial)
1274 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1277 TRACE("iface %p, material %p.\n", iface, pMaterial);
1279 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1280 wined3d_mutex_lock();
1281 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
1282 wined3d_mutex_unlock();
1287 static HRESULT WINAPI IDirect3DDevice8Impl_SetLight(IDirect3DDevice8 *iface, DWORD Index,
1288 const D3DLIGHT8 *pLight)
1290 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1293 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1295 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1296 wined3d_mutex_lock();
1297 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
1298 wined3d_mutex_unlock();
1303 static HRESULT WINAPI IDirect3DDevice8Impl_GetLight(IDirect3DDevice8 *iface, DWORD Index,
1306 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1309 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1311 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1312 wined3d_mutex_lock();
1313 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1314 wined3d_mutex_unlock();
1319 static HRESULT WINAPI IDirect3DDevice8Impl_LightEnable(IDirect3DDevice8 *iface, DWORD Index,
1322 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1325 TRACE("iface %p, index %u, enable %#x.\n", iface, Index, Enable);
1327 wined3d_mutex_lock();
1328 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1329 wined3d_mutex_unlock();
1334 static HRESULT WINAPI IDirect3DDevice8Impl_GetLightEnable(IDirect3DDevice8 *iface, DWORD Index,
1337 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1340 TRACE("iface %p, index %u, enable %p.\n", iface, Index, pEnable);
1342 wined3d_mutex_lock();
1343 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1344 wined3d_mutex_unlock();
1349 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipPlane(IDirect3DDevice8 *iface, DWORD Index,
1350 const float *pPlane)
1352 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1355 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1357 wined3d_mutex_lock();
1358 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1359 wined3d_mutex_unlock();
1364 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipPlane(IDirect3DDevice8 *iface, DWORD Index,
1367 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1370 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1372 wined3d_mutex_lock();
1373 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1374 wined3d_mutex_unlock();
1379 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(IDirect3DDevice8 *iface,
1380 D3DRENDERSTATETYPE State, DWORD Value)
1382 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1385 TRACE("iface %p, state %#x, value %#x.\n", iface, State, Value);
1387 wined3d_mutex_lock();
1388 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1389 wined3d_mutex_unlock();
1394 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderState(IDirect3DDevice8 *iface,
1395 D3DRENDERSTATETYPE State, DWORD *pValue)
1397 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1400 TRACE("iface %p, state %#x, value %p.\n", iface, State, pValue);
1402 wined3d_mutex_lock();
1403 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1404 wined3d_mutex_unlock();
1409 static HRESULT WINAPI IDirect3DDevice8Impl_BeginStateBlock(IDirect3DDevice8 *iface)
1411 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1414 TRACE("iface %p.\n", iface);
1416 wined3d_mutex_lock();
1417 hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
1418 wined3d_mutex_unlock();
1423 static HRESULT WINAPI IDirect3DDevice8Impl_EndStateBlock(IDirect3DDevice8 *iface, DWORD *pToken)
1425 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1426 struct wined3d_stateblock *stateblock;
1429 TRACE("iface %p, token %p.\n", iface, pToken);
1431 /* Tell wineD3D to endstateblock before anything else (in case we run out
1432 * of memory later and cause locking problems)
1434 wined3d_mutex_lock();
1435 hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice , &stateblock);
1437 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
1438 wined3d_mutex_unlock();
1442 *pToken = d3d8_allocate_handle(&This->handle_table, stateblock, D3D8_HANDLE_SB);
1443 wined3d_mutex_unlock();
1445 if (*pToken == D3D8_INVALID_HANDLE)
1447 ERR("Failed to create a handle\n");
1448 wined3d_mutex_lock();
1449 wined3d_stateblock_decref(stateblock);
1450 wined3d_mutex_unlock();
1455 TRACE("Returning %#x (%p).\n", *pToken, stateblock);
1460 static HRESULT WINAPI IDirect3DDevice8Impl_ApplyStateBlock(IDirect3DDevice8 *iface, DWORD Token)
1462 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1463 struct wined3d_stateblock *stateblock;
1466 TRACE("iface %p, token %#x.\n", iface, Token);
1468 if (!Token) return D3D_OK;
1470 wined3d_mutex_lock();
1471 stateblock = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1474 WARN("Invalid handle (%#x) passed.\n", Token);
1475 wined3d_mutex_unlock();
1476 return D3DERR_INVALIDCALL;
1478 hr = wined3d_stateblock_apply(stateblock);
1479 wined3d_mutex_unlock();
1484 static HRESULT WINAPI IDirect3DDevice8Impl_CaptureStateBlock(IDirect3DDevice8 *iface, DWORD Token)
1486 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1487 struct wined3d_stateblock *stateblock;
1490 TRACE("iface %p, token %#x.\n", iface, Token);
1492 wined3d_mutex_lock();
1493 stateblock = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1496 WARN("Invalid handle (%#x) passed.\n", Token);
1497 wined3d_mutex_unlock();
1498 return D3DERR_INVALIDCALL;
1500 hr = wined3d_stateblock_capture(stateblock);
1501 wined3d_mutex_unlock();
1506 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteStateBlock(IDirect3DDevice8 *iface, DWORD Token)
1508 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1509 struct wined3d_stateblock *stateblock;
1511 TRACE("iface %p, token %#x.\n", iface, Token);
1513 wined3d_mutex_lock();
1514 stateblock = d3d8_free_handle(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1518 WARN("Invalid handle (%#x) passed.\n", Token);
1519 wined3d_mutex_unlock();
1520 return D3DERR_INVALIDCALL;
1523 if (wined3d_stateblock_decref(stateblock))
1525 ERR("Stateblock %p has references left, this shouldn't happen.\n", stateblock);
1527 wined3d_mutex_unlock();
1532 static HRESULT WINAPI IDirect3DDevice8Impl_CreateStateBlock(IDirect3DDevice8 *iface,
1533 D3DSTATEBLOCKTYPE Type, DWORD *handle)
1535 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1536 struct wined3d_stateblock *stateblock;
1539 TRACE("iface %p, type %#x, handle %p.\n", iface, Type, handle);
1541 if (Type != D3DSBT_ALL
1542 && Type != D3DSBT_PIXELSTATE
1543 && Type != D3DSBT_VERTEXSTATE)
1545 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1546 return D3DERR_INVALIDCALL;
1549 wined3d_mutex_lock();
1550 hr = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type, &stateblock);
1553 wined3d_mutex_unlock();
1554 ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr);
1558 *handle = d3d8_allocate_handle(&This->handle_table, stateblock, D3D8_HANDLE_SB);
1559 wined3d_mutex_unlock();
1561 if (*handle == D3D8_INVALID_HANDLE)
1563 ERR("Failed to allocate a handle.\n");
1564 wined3d_mutex_lock();
1565 wined3d_stateblock_decref(stateblock);
1566 wined3d_mutex_unlock();
1571 TRACE("Returning %#x (%p).\n", *handle, stateblock);
1576 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipStatus(IDirect3DDevice8 *iface,
1577 const D3DCLIPSTATUS8 *pClipStatus)
1579 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1582 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1583 /* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
1585 wined3d_mutex_lock();
1586 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1587 wined3d_mutex_unlock();
1592 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipStatus(IDirect3DDevice8 *iface,
1593 D3DCLIPSTATUS8 *pClipStatus)
1595 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1598 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1600 wined3d_mutex_lock();
1601 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1602 wined3d_mutex_unlock();
1607 static HRESULT WINAPI IDirect3DDevice8Impl_GetTexture(IDirect3DDevice8 *iface,
1608 DWORD Stage, IDirect3DBaseTexture8 **ppTexture)
1610 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1611 IWineD3DBaseTexture *retTexture;
1614 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, ppTexture);
1616 if(ppTexture == NULL){
1617 return D3DERR_INVALIDCALL;
1620 wined3d_mutex_lock();
1621 hr = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
1624 WARN("Failed to get texture for stage %u, hr %#x.\n", Stage, hr);
1625 wined3d_mutex_unlock();
1632 *ppTexture = IWineD3DBaseTexture_GetParent(retTexture);
1633 IDirect3DBaseTexture8_AddRef(*ppTexture);
1634 IWineD3DBaseTexture_Release(retTexture);
1640 wined3d_mutex_unlock();
1645 static HRESULT WINAPI IDirect3DDevice8Impl_SetTexture(IDirect3DDevice8 *iface, DWORD Stage,
1646 IDirect3DBaseTexture8 *pTexture)
1648 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1651 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, pTexture);
1653 wined3d_mutex_lock();
1654 hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
1655 pTexture==NULL ? NULL : ((IDirect3DBaseTexture8Impl *)pTexture)->wineD3DBaseTexture);
1656 wined3d_mutex_unlock();
1661 static const struct tss_lookup
1668 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 0, unused */
1669 {FALSE, WINED3DTSS_COLOROP}, /* 1, D3DTSS_COLOROP */
1670 {FALSE, WINED3DTSS_COLORARG1}, /* 2, D3DTSS_COLORARG1 */
1671 {FALSE, WINED3DTSS_COLORARG2}, /* 3, D3DTSS_COLORARG2 */
1672 {FALSE, WINED3DTSS_ALPHAOP}, /* 4, D3DTSS_ALPHAOP */
1673 {FALSE, WINED3DTSS_ALPHAARG1}, /* 5, D3DTSS_ALPHAARG1 */
1674 {FALSE, WINED3DTSS_ALPHAARG2}, /* 6, D3DTSS_ALPHAARG2 */
1675 {FALSE, WINED3DTSS_BUMPENVMAT00}, /* 7, D3DTSS_BUMPENVMAT00 */
1676 {FALSE, WINED3DTSS_BUMPENVMAT01}, /* 8, D3DTSS_BUMPENVMAT01 */
1677 {FALSE, WINED3DTSS_BUMPENVMAT10}, /* 9, D3DTSS_BUMPENVMAT10 */
1678 {FALSE, WINED3DTSS_BUMPENVMAT11}, /* 10, D3DTSS_BUMPENVMAT11 */
1679 {FALSE, WINED3DTSS_TEXCOORDINDEX}, /* 11, D3DTSS_TEXCOORDINDEX */
1680 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 12, unused */
1681 {TRUE, WINED3DSAMP_ADDRESSU}, /* 13, D3DTSS_ADDRESSU */
1682 {TRUE, WINED3DSAMP_ADDRESSV}, /* 14, D3DTSS_ADDRESSV */
1683 {TRUE, WINED3DSAMP_BORDERCOLOR}, /* 15, D3DTSS_BORDERCOLOR */
1684 {TRUE, WINED3DSAMP_MAGFILTER}, /* 16, D3DTSS_MAGFILTER */
1685 {TRUE, WINED3DSAMP_MINFILTER}, /* 17, D3DTSS_MINFILTER */
1686 {TRUE, WINED3DSAMP_MIPFILTER}, /* 18, D3DTSS_MIPFILTER */
1687 {TRUE, WINED3DSAMP_MIPMAPLODBIAS}, /* 19, D3DTSS_MIPMAPLODBIAS */
1688 {TRUE, WINED3DSAMP_MAXMIPLEVEL}, /* 20, D3DTSS_MAXMIPLEVEL */
1689 {TRUE, WINED3DSAMP_MAXANISOTROPY}, /* 21, D3DTSS_MAXANISOTROPY */
1690 {FALSE, WINED3DTSS_BUMPENVLSCALE}, /* 22, D3DTSS_BUMPENVLSCALE */
1691 {FALSE, WINED3DTSS_BUMPENVLOFFSET}, /* 23, D3DTSS_BUMPENVLOFFSET */
1692 {FALSE, WINED3DTSS_TEXTURETRANSFORMFLAGS}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1693 {TRUE, WINED3DSAMP_ADDRESSW}, /* 25, D3DTSS_ADDRESSW */
1694 {FALSE, WINED3DTSS_COLORARG0}, /* 26, D3DTSS_COLORARG0 */
1695 {FALSE, WINED3DTSS_ALPHAARG0}, /* 27, D3DTSS_ALPHAARG0 */
1696 {FALSE, WINED3DTSS_RESULTARG}, /* 28, D3DTSS_RESULTARG */
1699 static HRESULT WINAPI IDirect3DDevice8Impl_GetTextureStageState(IDirect3DDevice8 *iface,
1700 DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD *pValue)
1702 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1703 const struct tss_lookup *l;
1706 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface, Stage, Type, pValue);
1708 if (Type >= sizeof(tss_lookup) / sizeof(*tss_lookup))
1710 WARN("Invalid Type %#x passed.\n", Type);
1714 l = &tss_lookup[Type];
1716 wined3d_mutex_lock();
1717 if (l->sampler_state) hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Stage, l->state, pValue);
1718 else hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, l->state, pValue);
1719 wined3d_mutex_unlock();
1724 static HRESULT WINAPI IDirect3DDevice8Impl_SetTextureStageState(IDirect3DDevice8 *iface,
1725 DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value)
1727 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1728 const struct tss_lookup *l;
1731 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface, Stage, Type, Value);
1733 if (Type >= sizeof(tss_lookup) / sizeof(*tss_lookup))
1735 WARN("Invalid Type %#x passed.\n", Type);
1739 l = &tss_lookup[Type];
1741 wined3d_mutex_lock();
1742 if (l->sampler_state) hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Stage, l->state, Value);
1743 else hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, l->state, Value);
1744 wined3d_mutex_unlock();
1749 static HRESULT WINAPI IDirect3DDevice8Impl_ValidateDevice(IDirect3DDevice8 *iface,
1752 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1755 TRACE("iface %p, pass_count %p.\n", iface, pNumPasses);
1757 wined3d_mutex_lock();
1758 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1759 wined3d_mutex_unlock();
1764 static HRESULT WINAPI IDirect3DDevice8Impl_GetInfo(IDirect3DDevice8 *iface,
1765 DWORD info_id, void *info, DWORD info_size)
1767 FIXME("iface %p, info_id %#x, info %p, info_size %u stub!\n", iface, info_id, info, info_size);
1772 static HRESULT WINAPI IDirect3DDevice8Impl_SetPaletteEntries(IDirect3DDevice8 *iface,
1773 UINT PaletteNumber, const PALETTEENTRY *pEntries)
1775 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1778 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1780 wined3d_mutex_lock();
1781 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1782 wined3d_mutex_unlock();
1787 static HRESULT WINAPI IDirect3DDevice8Impl_GetPaletteEntries(IDirect3DDevice8 *iface,
1788 UINT PaletteNumber, PALETTEENTRY *pEntries)
1790 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1793 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1795 wined3d_mutex_lock();
1796 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1797 wined3d_mutex_unlock();
1802 static HRESULT WINAPI IDirect3DDevice8Impl_SetCurrentTexturePalette(IDirect3DDevice8 *iface,
1805 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1808 TRACE("iface %p, palette_idx %u.\n", iface, PaletteNumber);
1810 wined3d_mutex_lock();
1811 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1812 wined3d_mutex_unlock();
1817 static HRESULT WINAPI IDirect3DDevice8Impl_GetCurrentTexturePalette(IDirect3DDevice8 *iface,
1818 UINT *PaletteNumber)
1820 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1823 TRACE("iface %p, palette_idx %p.\n", iface, PaletteNumber);
1825 wined3d_mutex_lock();
1826 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1827 wined3d_mutex_unlock();
1832 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitive(IDirect3DDevice8 *iface,
1833 D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount)
1835 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1838 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1839 iface, PrimitiveType, StartVertex, PrimitiveCount);
1841 wined3d_mutex_lock();
1842 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1843 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
1844 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
1845 wined3d_mutex_unlock();
1850 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitive(IDirect3DDevice8 *iface,
1851 D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertices, UINT startIndex,
1854 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1857 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, start_idx %u, primitive_count %u.\n",
1858 iface, PrimitiveType, MinVertexIndex, NumVertices, startIndex, primCount);
1860 wined3d_mutex_lock();
1861 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1862 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, startIndex,
1863 vertex_count_from_primitive_count(PrimitiveType, primCount));
1864 wined3d_mutex_unlock();
1869 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitiveUP(IDirect3DDevice8 *iface,
1870 D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, const void *pVertexStreamZeroData,
1871 UINT VertexStreamZeroStride)
1873 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1876 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
1877 iface, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
1879 wined3d_mutex_lock();
1880 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1881 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
1882 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
1883 pVertexStreamZeroData, VertexStreamZeroStride);
1884 wined3d_mutex_unlock();
1889 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(IDirect3DDevice8 *iface,
1890 D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertexIndices,
1891 UINT PrimitiveCount, const void *pIndexData, D3DFORMAT IndexDataFormat,
1892 const void *pVertexStreamZeroData, UINT VertexStreamZeroStride)
1894 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1897 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
1898 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
1899 iface, PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount,
1900 pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
1902 wined3d_mutex_lock();
1903 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1904 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice,
1905 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
1906 wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
1907 wined3d_mutex_unlock();
1912 static HRESULT WINAPI IDirect3DDevice8Impl_ProcessVertices(IDirect3DDevice8 *iface,
1913 UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer8 *pDestBuffer,
1916 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1918 IDirect3DVertexBuffer8Impl *dest = (IDirect3DVertexBuffer8Impl *) pDestBuffer;
1920 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, flags %#x.\n",
1921 iface, SrcStartIndex, DestIndex, VertexCount, pDestBuffer, Flags);
1923 wined3d_mutex_lock();
1924 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, NULL, Flags, dest->fvf);
1925 wined3d_mutex_unlock();
1930 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(IDirect3DDevice8 *iface,
1931 const DWORD *declaration, const DWORD *byte_code, DWORD *shader, DWORD usage)
1933 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
1934 IDirect3DVertexShader8Impl *object;
1935 DWORD shader_handle;
1939 TRACE("iface %p, declaration %p, byte_code %p, shader %p, usage %#x.\n",
1940 iface, declaration, byte_code, shader, usage);
1942 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1945 ERR("Failed to allocate vertex shader memory.\n");
1947 return E_OUTOFMEMORY;
1950 wined3d_mutex_lock();
1951 handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_VS);
1952 wined3d_mutex_unlock();
1953 if (handle == D3D8_INVALID_HANDLE)
1955 ERR("Failed to allocate vertex shader handle.\n");
1956 HeapFree(GetProcessHeap(), 0, object);
1958 return E_OUTOFMEMORY;
1961 shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
1963 hr = vertexshader_init(object, This, declaration, byte_code, shader_handle, usage);
1966 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
1967 wined3d_mutex_lock();
1968 d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_VS);
1969 wined3d_mutex_unlock();
1970 HeapFree(GetProcessHeap(), 0, object);
1975 TRACE("Created vertex shader %p (handle %#x).\n", object, shader_handle);
1976 *shader = shader_handle;
1981 static IDirect3DVertexDeclaration8Impl *IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl *This, DWORD fvf)
1983 IDirect3DVertexDeclaration8Impl *d3d8_declaration;
1985 int p, low, high; /* deliberately signed */
1986 struct FvfToDecl *convertedDecls = This->decls;
1988 TRACE("Searching for declaration for fvf %08x... ", fvf);
1991 high = This->numConvertedDecls - 1;
1992 while(low <= high) {
1993 p = (low + high) >> 1;
1995 if(convertedDecls[p].fvf == fvf) {
1996 TRACE("found %p\n", convertedDecls[p].decl);
1997 return (IDirect3DVertexDeclaration8Impl *)convertedDecls[p].decl;
1998 } else if(convertedDecls[p].fvf < fvf) {
2004 TRACE("not found. Creating and inserting at position %d.\n", low);
2006 d3d8_declaration = HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration));
2007 if (!d3d8_declaration)
2009 ERR("Memory allocation failed.\n");
2013 hr = vertexdeclaration_init_fvf(d3d8_declaration, This, fvf);
2016 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
2017 HeapFree(GetProcessHeap(), 0, d3d8_declaration);
2021 if(This->declArraySize == This->numConvertedDecls) {
2022 int grow = This->declArraySize / 2;
2023 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
2024 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
2025 if(!convertedDecls) {
2026 /* This will destroy it */
2027 IDirect3DVertexDeclaration8_Release((IDirect3DVertexDeclaration8 *)d3d8_declaration);
2030 This->decls = convertedDecls;
2031 This->declArraySize += grow;
2034 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(convertedDecls[0]) * (This->numConvertedDecls - low));
2035 convertedDecls[low].decl = (IDirect3DVertexDeclaration8 *)d3d8_declaration;
2036 convertedDecls[low].fvf = fvf;
2037 This->numConvertedDecls++;
2039 TRACE("Returning %p. %u decls in array\n", d3d8_declaration, This->numConvertedDecls);
2040 return d3d8_declaration;
2043 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShader(IDirect3DDevice8 *iface, DWORD pShader)
2045 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2046 IDirect3DVertexShader8Impl *shader;
2049 TRACE("iface %p, shader %#x.\n", iface, pShader);
2051 if (VS_HIGHESTFIXEDFXF >= pShader) {
2052 TRACE("Setting FVF, %#x\n", pShader);
2054 wined3d_mutex_lock();
2055 IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
2056 IDirect3DDevice8Impl_FindDecl(This, pShader)->wined3d_vertex_declaration);
2057 IWineD3DDevice_SetVertexShader(This->WineD3DDevice, NULL);
2058 wined3d_mutex_unlock();
2063 TRACE("Setting shader\n");
2065 wined3d_mutex_lock();
2066 shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2069 WARN("Invalid handle (%#x) passed.\n", pShader);
2070 wined3d_mutex_unlock();
2072 return D3DERR_INVALIDCALL;
2075 hr = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
2076 ((IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration)->wined3d_vertex_declaration);
2077 if (SUCCEEDED(hr)) hr = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, shader->wineD3DVertexShader);
2078 wined3d_mutex_unlock();
2080 TRACE("Returning hr %#x\n", hr);
2085 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShader(IDirect3DDevice8 *iface, DWORD *ppShader)
2087 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2088 struct wined3d_vertex_declaration *wined3d_declaration;
2089 IDirect3DVertexDeclaration8 *d3d8_declaration;
2092 TRACE("iface %p, shader %p.\n", iface, ppShader);
2094 wined3d_mutex_lock();
2095 hr = IWineD3DDevice_GetVertexDeclaration(This->WineD3DDevice, &wined3d_declaration);
2098 wined3d_mutex_unlock();
2099 WARN("(%p) : Call to IWineD3DDevice_GetVertexDeclaration failed %#x (device %p)\n",
2100 This, hr, This->WineD3DDevice);
2104 if (!wined3d_declaration)
2106 wined3d_mutex_unlock();
2111 d3d8_declaration = wined3d_vertex_declaration_get_parent(wined3d_declaration);
2112 wined3d_vertex_declaration_decref(wined3d_declaration);
2113 wined3d_mutex_unlock();
2114 *ppShader = ((IDirect3DVertexDeclaration8Impl *)d3d8_declaration)->shader_handle;
2116 TRACE("(%p) : returning %#x\n", This, *ppShader);
2121 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteVertexShader(IDirect3DDevice8 *iface,
2124 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2125 IDirect3DVertexShader8Impl *shader;
2126 IWineD3DVertexShader *cur;
2128 TRACE("iface %p, shader %#x.\n", iface, pShader);
2130 wined3d_mutex_lock();
2131 shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2134 WARN("Invalid handle (%#x) passed.\n", pShader);
2135 wined3d_mutex_unlock();
2137 return D3DERR_INVALIDCALL;
2140 cur = IWineD3DDevice_GetVertexShader(This->WineD3DDevice);
2143 if (cur == shader->wineD3DVertexShader) IDirect3DDevice8_SetVertexShader(iface, 0);
2144 IWineD3DVertexShader_Release(cur);
2147 wined3d_mutex_unlock();
2149 if (IDirect3DVertexShader8_Release(&shader->IDirect3DVertexShader8_iface))
2151 ERR("Shader %p has references left, this shouldn't happen.\n", shader);
2157 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShaderConstant(IDirect3DDevice8 *iface,
2158 DWORD Register, const void *pConstantData, DWORD ConstantCount)
2160 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2163 TRACE("iface %p, register %u, data %p, count %u.\n",
2164 iface, Register, pConstantData, ConstantCount);
2166 if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
2167 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2168 Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2169 return D3DERR_INVALIDCALL;
2172 wined3d_mutex_lock();
2173 hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2174 wined3d_mutex_unlock();
2179 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderConstant(IDirect3DDevice8 *iface,
2180 DWORD Register, void *pConstantData, DWORD ConstantCount)
2182 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2185 TRACE("iface %p, register %u, data %p, count %u.\n",
2186 iface, Register, pConstantData, ConstantCount);
2188 if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
2189 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2190 Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2191 return D3DERR_INVALIDCALL;
2194 wined3d_mutex_lock();
2195 hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2196 wined3d_mutex_unlock();
2201 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderDeclaration(IDirect3DDevice8 *iface,
2202 DWORD pVertexShader, void *pData, DWORD *pSizeOfData)
2204 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2205 IDirect3DVertexDeclaration8Impl *declaration;
2206 IDirect3DVertexShader8Impl *shader;
2208 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2209 iface, pVertexShader, pData, pSizeOfData);
2211 wined3d_mutex_lock();
2212 shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2213 wined3d_mutex_unlock();
2217 WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2218 return D3DERR_INVALIDCALL;
2220 declaration = (IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration;
2222 /* If pData is NULL, we just return the required size of the buffer. */
2224 *pSizeOfData = declaration->elements_size;
2228 /* MSDN claims that if *pSizeOfData is smaller than the required size
2229 * we should write the required size and return D3DERR_MOREDATA.
2230 * That's not actually true. */
2231 if (*pSizeOfData < declaration->elements_size) {
2232 return D3DERR_INVALIDCALL;
2235 CopyMemory(pData, declaration->elements, declaration->elements_size);
2240 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderFunction(IDirect3DDevice8 *iface,
2241 DWORD pVertexShader, void *pData, DWORD *pSizeOfData)
2243 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2244 IDirect3DVertexShader8Impl *shader = NULL;
2247 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2248 iface, pVertexShader, pData, pSizeOfData);
2250 wined3d_mutex_lock();
2251 shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2254 WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2255 wined3d_mutex_unlock();
2257 return D3DERR_INVALIDCALL;
2260 if (!shader->wineD3DVertexShader)
2262 wined3d_mutex_unlock();
2267 hr = IWineD3DVertexShader_GetFunction(shader->wineD3DVertexShader, pData, pSizeOfData);
2268 wined3d_mutex_unlock();
2273 static HRESULT WINAPI IDirect3DDevice8Impl_SetIndices(IDirect3DDevice8 *iface,
2274 IDirect3DIndexBuffer8 *pIndexData, UINT baseVertexIndex)
2276 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2278 IDirect3DIndexBuffer8Impl *ib = (IDirect3DIndexBuffer8Impl *)pIndexData;
2280 TRACE("iface %p, buffer %p, base_vertex_idx %u.\n", iface, pIndexData, baseVertexIndex);
2282 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
2283 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
2284 * vertex buffers can't be created to address them with an index that requires the 32nd bit
2285 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
2288 wined3d_mutex_lock();
2289 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, baseVertexIndex);
2290 hr = IWineD3DDevice_SetIndexBuffer(This->WineD3DDevice,
2291 ib ? ib->wineD3DIndexBuffer : NULL,
2292 ib ? ib->format : WINED3DFMT_UNKNOWN);
2293 wined3d_mutex_unlock();
2298 static HRESULT WINAPI IDirect3DDevice8Impl_GetIndices(IDirect3DDevice8 *iface,
2299 IDirect3DIndexBuffer8 **ppIndexData, UINT *pBaseVertexIndex)
2301 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2302 struct wined3d_buffer *retIndexData = NULL;
2305 TRACE("iface %p, buffer %p, base_vertex_index %p.\n", iface, ppIndexData, pBaseVertexIndex);
2307 if(ppIndexData == NULL){
2308 return D3DERR_INVALIDCALL;
2311 /* The case from UINT to INT is safe because d3d8 will never set negative values */
2312 wined3d_mutex_lock();
2313 IWineD3DDevice_GetBaseVertexIndex(This->WineD3DDevice, (INT *) pBaseVertexIndex);
2314 hr = IWineD3DDevice_GetIndexBuffer(This->WineD3DDevice, &retIndexData);
2315 if (SUCCEEDED(hr) && retIndexData)
2317 *ppIndexData = wined3d_buffer_get_parent(retIndexData);
2318 IDirect3DIndexBuffer8_AddRef(*ppIndexData);
2319 wined3d_buffer_decref(retIndexData);
2321 if (FAILED(hr)) FIXME("Call to GetIndices failed\n");
2322 *ppIndexData = NULL;
2324 wined3d_mutex_unlock();
2329 static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(IDirect3DDevice8 *iface,
2330 const DWORD *byte_code, DWORD *shader)
2332 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2333 IDirect3DPixelShader8Impl *object;
2334 DWORD shader_handle;
2338 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2342 TRACE("(%p) Invalid call\n", This);
2343 return D3DERR_INVALIDCALL;
2346 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2349 ERR("Failed to allocate pixel shader memmory.\n");
2350 return E_OUTOFMEMORY;
2353 wined3d_mutex_lock();
2354 handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_PS);
2355 wined3d_mutex_unlock();
2356 if (handle == D3D8_INVALID_HANDLE)
2358 ERR("Failed to allocate pixel shader handle.\n");
2359 HeapFree(GetProcessHeap(), 0, object);
2360 return E_OUTOFMEMORY;
2363 shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
2365 hr = pixelshader_init(object, This, byte_code, shader_handle);
2368 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
2369 wined3d_mutex_lock();
2370 d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_PS);
2371 wined3d_mutex_unlock();
2372 HeapFree(GetProcessHeap(), 0, object);
2377 TRACE("Created pixel shader %p (handle %#x).\n", object, shader_handle);
2378 *shader = shader_handle;
2383 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShader(IDirect3DDevice8 *iface, DWORD pShader)
2385 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2386 IDirect3DPixelShader8Impl *shader;
2389 TRACE("iface %p, shader %#x.\n", iface, pShader);
2391 wined3d_mutex_lock();
2395 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, NULL);
2396 wined3d_mutex_unlock();
2400 shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2403 WARN("Invalid handle (%#x) passed.\n", pShader);
2404 wined3d_mutex_unlock();
2405 return D3DERR_INVALIDCALL;
2408 TRACE("(%p) : Setting shader %p\n", This, shader);
2409 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, shader->wineD3DPixelShader);
2410 wined3d_mutex_unlock();
2415 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShader(IDirect3DDevice8 *iface, DWORD *ppShader)
2417 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2418 IWineD3DPixelShader *object;
2420 TRACE("iface %p, shader %p.\n", iface, ppShader);
2422 if (NULL == ppShader) {
2423 TRACE("(%p) Invalid call\n", This);
2424 return D3DERR_INVALIDCALL;
2427 wined3d_mutex_lock();
2428 object = IWineD3DDevice_GetPixelShader(This->WineD3DDevice);
2431 IDirect3DPixelShader8Impl *d3d8_shader;
2432 d3d8_shader = IWineD3DPixelShader_GetParent(object);
2433 IWineD3DPixelShader_Release(object);
2434 *ppShader = d3d8_shader->handle;
2440 wined3d_mutex_unlock();
2442 TRACE("(%p) : returning %#x\n", This, *ppShader);
2447 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePixelShader(IDirect3DDevice8 *iface, DWORD pShader)
2449 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2450 IDirect3DPixelShader8Impl *shader;
2451 IWineD3DPixelShader *cur;
2453 TRACE("iface %p, shader %#x.\n", iface, pShader);
2455 wined3d_mutex_lock();
2457 shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2460 WARN("Invalid handle (%#x) passed.\n", pShader);
2461 wined3d_mutex_unlock();
2462 return D3DERR_INVALIDCALL;
2465 cur = IWineD3DDevice_GetPixelShader(This->WineD3DDevice);
2468 if (cur == shader->wineD3DPixelShader) IDirect3DDevice8_SetPixelShader(iface, 0);
2469 IWineD3DPixelShader_Release(cur);
2472 wined3d_mutex_unlock();
2474 if (IDirect3DPixelShader8_Release(&shader->IDirect3DPixelShader8_iface))
2476 ERR("Shader %p has references left, this shouldn't happen.\n", shader);
2482 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShaderConstant(IDirect3DDevice8 *iface,
2483 DWORD Register, const void *pConstantData, DWORD ConstantCount)
2485 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2488 TRACE("iface %p, register %u, data %p, count %u.\n",
2489 iface, Register, pConstantData, ConstantCount);
2491 wined3d_mutex_lock();
2492 hr = IWineD3DDevice_SetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2493 wined3d_mutex_unlock();
2498 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderConstant(IDirect3DDevice8 *iface,
2499 DWORD Register, void *pConstantData, DWORD ConstantCount)
2501 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2504 TRACE("iface %p, register %u, data %p, count %u.\n",
2505 iface, Register, pConstantData, ConstantCount);
2507 wined3d_mutex_lock();
2508 hr = IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2509 wined3d_mutex_unlock();
2514 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderFunction(IDirect3DDevice8 *iface,
2515 DWORD pPixelShader, void *pData, DWORD *pSizeOfData)
2517 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2518 IDirect3DPixelShader8Impl *shader = NULL;
2521 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2522 iface, pPixelShader, pData, pSizeOfData);
2524 wined3d_mutex_lock();
2525 shader = d3d8_get_object(&This->handle_table, pPixelShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2528 WARN("Invalid handle (%#x) passed.\n", pPixelShader);
2529 wined3d_mutex_unlock();
2531 return D3DERR_INVALIDCALL;
2534 hr = IWineD3DPixelShader_GetFunction(shader->wineD3DPixelShader, pData, pSizeOfData);
2535 wined3d_mutex_unlock();
2540 static HRESULT WINAPI IDirect3DDevice8Impl_DrawRectPatch(IDirect3DDevice8 *iface, UINT Handle,
2541 const float *pNumSegs, const D3DRECTPATCH_INFO *pRectPatchInfo)
2543 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2546 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2547 iface, Handle, pNumSegs, pRectPatchInfo);
2549 wined3d_mutex_lock();
2550 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
2551 wined3d_mutex_unlock();
2556 static HRESULT WINAPI IDirect3DDevice8Impl_DrawTriPatch(IDirect3DDevice8 *iface, UINT Handle,
2557 const float *pNumSegs, const D3DTRIPATCH_INFO *pTriPatchInfo)
2559 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2562 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2563 iface, Handle, pNumSegs, pTriPatchInfo);
2565 wined3d_mutex_lock();
2566 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
2567 wined3d_mutex_unlock();
2572 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePatch(IDirect3DDevice8 *iface, UINT Handle)
2574 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2577 TRACE("iface %p, handle %#x.\n", iface, Handle);
2579 wined3d_mutex_lock();
2580 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
2581 wined3d_mutex_unlock();
2586 static HRESULT WINAPI IDirect3DDevice8Impl_SetStreamSource(IDirect3DDevice8 *iface,
2587 UINT StreamNumber, IDirect3DVertexBuffer8 *pStreamData, UINT Stride)
2589 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2592 TRACE("iface %p, stream_idx %u, buffer %p, stride %u.\n",
2593 iface, StreamNumber, pStreamData, Stride);
2595 wined3d_mutex_lock();
2596 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
2597 NULL == pStreamData ? NULL : ((IDirect3DVertexBuffer8Impl *)pStreamData)->wineD3DVertexBuffer,
2598 0/* Offset in bytes */, Stride);
2599 wined3d_mutex_unlock();
2604 static HRESULT WINAPI IDirect3DDevice8Impl_GetStreamSource(IDirect3DDevice8 *iface,
2605 UINT StreamNumber, IDirect3DVertexBuffer8 **pStream, UINT *pStride)
2607 IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
2608 struct wined3d_buffer *retStream = NULL;
2611 TRACE("iface %p, stream_idx %u, buffer %p, stride %p.\n",
2612 iface, StreamNumber, pStream, pStride);
2614 if(pStream == NULL){
2615 return D3DERR_INVALIDCALL;
2618 wined3d_mutex_lock();
2619 hr = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber,
2620 &retStream, 0 /* Offset in bytes */, pStride);
2621 if (SUCCEEDED(hr) && retStream)
2623 *pStream = wined3d_buffer_get_parent(retStream);
2624 IDirect3DVertexBuffer8_AddRef(*pStream);
2625 wined3d_buffer_decref(retStream);
2629 if (FAILED(hr)) FIXME("Call to GetStreamSource failed, hr %#x.\n", hr);
2632 wined3d_mutex_unlock();
2637 static const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl =
2639 IDirect3DDevice8Impl_QueryInterface,
2640 IDirect3DDevice8Impl_AddRef,
2641 IDirect3DDevice8Impl_Release,
2642 IDirect3DDevice8Impl_TestCooperativeLevel,
2643 IDirect3DDevice8Impl_GetAvailableTextureMem,
2644 IDirect3DDevice8Impl_ResourceManagerDiscardBytes,
2645 IDirect3DDevice8Impl_GetDirect3D,
2646 IDirect3DDevice8Impl_GetDeviceCaps,
2647 IDirect3DDevice8Impl_GetDisplayMode,
2648 IDirect3DDevice8Impl_GetCreationParameters,
2649 IDirect3DDevice8Impl_SetCursorProperties,
2650 IDirect3DDevice8Impl_SetCursorPosition,
2651 IDirect3DDevice8Impl_ShowCursor,
2652 IDirect3DDevice8Impl_CreateAdditionalSwapChain,
2653 IDirect3DDevice8Impl_Reset,
2654 IDirect3DDevice8Impl_Present,
2655 IDirect3DDevice8Impl_GetBackBuffer,
2656 IDirect3DDevice8Impl_GetRasterStatus,
2657 IDirect3DDevice8Impl_SetGammaRamp,
2658 IDirect3DDevice8Impl_GetGammaRamp,
2659 IDirect3DDevice8Impl_CreateTexture,
2660 IDirect3DDevice8Impl_CreateVolumeTexture,
2661 IDirect3DDevice8Impl_CreateCubeTexture,
2662 IDirect3DDevice8Impl_CreateVertexBuffer,
2663 IDirect3DDevice8Impl_CreateIndexBuffer,
2664 IDirect3DDevice8Impl_CreateRenderTarget,
2665 IDirect3DDevice8Impl_CreateDepthStencilSurface,
2666 IDirect3DDevice8Impl_CreateImageSurface,
2667 IDirect3DDevice8Impl_CopyRects,
2668 IDirect3DDevice8Impl_UpdateTexture,
2669 IDirect3DDevice8Impl_GetFrontBuffer,
2670 IDirect3DDevice8Impl_SetRenderTarget,
2671 IDirect3DDevice8Impl_GetRenderTarget,
2672 IDirect3DDevice8Impl_GetDepthStencilSurface,
2673 IDirect3DDevice8Impl_BeginScene,
2674 IDirect3DDevice8Impl_EndScene,
2675 IDirect3DDevice8Impl_Clear,
2676 IDirect3DDevice8Impl_SetTransform,
2677 IDirect3DDevice8Impl_GetTransform,
2678 IDirect3DDevice8Impl_MultiplyTransform,
2679 IDirect3DDevice8Impl_SetViewport,
2680 IDirect3DDevice8Impl_GetViewport,
2681 IDirect3DDevice8Impl_SetMaterial,
2682 IDirect3DDevice8Impl_GetMaterial,
2683 IDirect3DDevice8Impl_SetLight,
2684 IDirect3DDevice8Impl_GetLight,
2685 IDirect3DDevice8Impl_LightEnable,
2686 IDirect3DDevice8Impl_GetLightEnable,
2687 IDirect3DDevice8Impl_SetClipPlane,
2688 IDirect3DDevice8Impl_GetClipPlane,
2689 IDirect3DDevice8Impl_SetRenderState,
2690 IDirect3DDevice8Impl_GetRenderState,
2691 IDirect3DDevice8Impl_BeginStateBlock,
2692 IDirect3DDevice8Impl_EndStateBlock,
2693 IDirect3DDevice8Impl_ApplyStateBlock,
2694 IDirect3DDevice8Impl_CaptureStateBlock,
2695 IDirect3DDevice8Impl_DeleteStateBlock,
2696 IDirect3DDevice8Impl_CreateStateBlock,
2697 IDirect3DDevice8Impl_SetClipStatus,
2698 IDirect3DDevice8Impl_GetClipStatus,
2699 IDirect3DDevice8Impl_GetTexture,
2700 IDirect3DDevice8Impl_SetTexture,
2701 IDirect3DDevice8Impl_GetTextureStageState,
2702 IDirect3DDevice8Impl_SetTextureStageState,
2703 IDirect3DDevice8Impl_ValidateDevice,
2704 IDirect3DDevice8Impl_GetInfo,
2705 IDirect3DDevice8Impl_SetPaletteEntries,
2706 IDirect3DDevice8Impl_GetPaletteEntries,
2707 IDirect3DDevice8Impl_SetCurrentTexturePalette,
2708 IDirect3DDevice8Impl_GetCurrentTexturePalette,
2709 IDirect3DDevice8Impl_DrawPrimitive,
2710 IDirect3DDevice8Impl_DrawIndexedPrimitive,
2711 IDirect3DDevice8Impl_DrawPrimitiveUP,
2712 IDirect3DDevice8Impl_DrawIndexedPrimitiveUP,
2713 IDirect3DDevice8Impl_ProcessVertices,
2714 IDirect3DDevice8Impl_CreateVertexShader,
2715 IDirect3DDevice8Impl_SetVertexShader,
2716 IDirect3DDevice8Impl_GetVertexShader,
2717 IDirect3DDevice8Impl_DeleteVertexShader,
2718 IDirect3DDevice8Impl_SetVertexShaderConstant,
2719 IDirect3DDevice8Impl_GetVertexShaderConstant,
2720 IDirect3DDevice8Impl_GetVertexShaderDeclaration,
2721 IDirect3DDevice8Impl_GetVertexShaderFunction,
2722 IDirect3DDevice8Impl_SetStreamSource,
2723 IDirect3DDevice8Impl_GetStreamSource,
2724 IDirect3DDevice8Impl_SetIndices,
2725 IDirect3DDevice8Impl_GetIndices,
2726 IDirect3DDevice8Impl_CreatePixelShader,
2727 IDirect3DDevice8Impl_SetPixelShader,
2728 IDirect3DDevice8Impl_GetPixelShader,
2729 IDirect3DDevice8Impl_DeletePixelShader,
2730 IDirect3DDevice8Impl_SetPixelShaderConstant,
2731 IDirect3DDevice8Impl_GetPixelShaderConstant,
2732 IDirect3DDevice8Impl_GetPixelShaderFunction,
2733 IDirect3DDevice8Impl_DrawRectPatch,
2734 IDirect3DDevice8Impl_DrawTriPatch,
2735 IDirect3DDevice8Impl_DeletePatch
2738 static inline IDirect3DDevice8Impl *impl_from_IWineD3DDeviceParent(IWineD3DDeviceParent *iface)
2740 return CONTAINING_RECORD(iface, IDirect3DDevice8Impl, IWineD3DDeviceParent_iface);
2743 static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface,
2744 REFIID riid, void **object)
2746 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
2747 return IDirect3DDevice8Impl_QueryInterface(&This->IDirect3DDevice8_iface, riid, object);
2750 static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
2752 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
2753 return IDirect3DDevice8Impl_AddRef(&This->IDirect3DDevice8_iface);
2756 static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
2758 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
2759 return IDirect3DDevice8Impl_Release(&This->IDirect3DDevice8_iface);
2762 /* IWineD3DDeviceParent methods */
2764 static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
2766 TRACE("iface %p, device %p\n", iface, device);
2769 static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
2770 void *container_parent, UINT width, UINT height, enum wined3d_format_id format, DWORD usage,
2771 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface)
2773 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
2774 IDirect3DSurface8Impl *d3d_surface;
2775 BOOL lockable = TRUE;
2778 TRACE("iface %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
2779 "\tpool %#x, level %u, face %u, surface %p\n",
2780 iface, container_parent, width, height, format, usage, pool, level, face, surface);
2783 if (pool == WINED3DPOOL_DEFAULT && !(usage & WINED3DUSAGE_DYNAMIC)) lockable = FALSE;
2785 hr = IDirect3DDevice8Impl_CreateSurface(This, width, height,
2786 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
2787 (IDirect3DSurface8 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
2790 ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
2794 *surface = d3d_surface->wineD3DSurface;
2795 IWineD3DSurface_AddRef(*surface);
2797 d3d_surface->container = container_parent;
2798 IUnknown_Release(d3d_surface->parentDevice);
2799 d3d_surface->parentDevice = NULL;
2801 IDirect3DSurface8_Release((IDirect3DSurface8 *)d3d_surface);
2802 d3d_surface->forwardReference = container_parent;
2807 static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
2808 void *container_parent, UINT width, UINT height, enum wined3d_format_id format,
2809 WINED3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality, BOOL lockable,
2810 IWineD3DSurface **surface)
2812 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
2813 IDirect3DSurface8Impl *d3d_surface;
2816 TRACE("iface %p, container_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2817 "\tmultisample_quality %u, lockable %u, surface %p\n",
2818 iface, container_parent, width, height, format, multisample_type, multisample_quality, lockable, surface);
2820 hr = IDirect3DDevice8_CreateRenderTarget(&This->IDirect3DDevice8_iface, width, height,
2821 d3dformat_from_wined3dformat(format), multisample_type, lockable, (IDirect3DSurface8 **)&d3d_surface);
2824 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
2828 *surface = d3d_surface->wineD3DSurface;
2829 IWineD3DSurface_AddRef(*surface);
2831 d3d_surface->container = (IUnknown *)&This->IDirect3DDevice8_iface;
2832 /* Implicit surfaces are created with an refcount of 0 */
2833 IUnknown_Release((IUnknown *)d3d_surface);
2838 static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
2839 UINT width, UINT height, enum wined3d_format_id format, WINED3DMULTISAMPLE_TYPE multisample_type,
2840 DWORD multisample_quality, BOOL discard, IWineD3DSurface **surface)
2842 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
2843 IDirect3DSurface8Impl *d3d_surface;
2846 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2847 "\tmultisample_quality %u, discard %u, surface %p\n",
2848 iface, width, height, format, multisample_type, multisample_quality, discard, surface);
2850 hr = IDirect3DDevice8_CreateDepthStencilSurface(&This->IDirect3DDevice8_iface, width, height,
2851 d3dformat_from_wined3dformat(format), multisample_type, (IDirect3DSurface8 **)&d3d_surface);
2854 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
2858 *surface = d3d_surface->wineD3DSurface;
2859 IWineD3DSurface_AddRef(*surface);
2861 d3d_surface->container = (IUnknown *)&This->IDirect3DDevice8_iface;
2862 /* Implicit surfaces are created with an refcount of 0 */
2863 IUnknown_Release((IUnknown *)d3d_surface);
2868 static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
2869 void *container_parent, UINT width, UINT height, UINT depth, enum wined3d_format_id format,
2870 WINED3DPOOL pool, DWORD usage, IWineD3DVolume **volume)
2872 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
2873 IDirect3DVolume8Impl *object;
2876 TRACE("iface %p, container_parent %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
2877 iface, container_parent, width, height, depth, format, pool, usage, volume);
2879 /* Allocate the storage for the device */
2880 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2883 FIXME("Allocation of memory failed\n");
2885 return D3DERR_OUTOFVIDEOMEMORY;
2888 hr = volume_init(object, This, width, height, depth, usage, format, pool);
2891 WARN("Failed to initialize volume, hr %#x.\n", hr);
2892 HeapFree(GetProcessHeap(), 0, object);
2896 *volume = object->wineD3DVolume;
2897 IWineD3DVolume_AddRef(*volume);
2898 IDirect3DVolume8_Release(&object->IDirect3DVolume8_iface);
2900 object->container = container_parent;
2901 object->forwardReference = container_parent;
2903 TRACE("(%p) Created volume %p\n", iface, object);
2908 static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
2909 WINED3DPRESENT_PARAMETERS *present_parameters, IWineD3DSwapChain **swapchain)
2911 IDirect3DDevice8Impl *This = impl_from_IWineD3DDeviceParent(iface);
2912 IDirect3DSwapChain8Impl *d3d_swapchain;
2913 D3DPRESENT_PARAMETERS local_parameters;
2916 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
2918 /* Copy the presentation parameters */
2919 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
2920 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
2921 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
2922 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
2923 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
2924 local_parameters.SwapEffect = present_parameters->SwapEffect;
2925 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
2926 local_parameters.Windowed = present_parameters->Windowed;
2927 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
2928 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
2929 local_parameters.Flags = present_parameters->Flags;
2930 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
2931 local_parameters.FullScreen_PresentationInterval = present_parameters->PresentationInterval;
2933 hr = IDirect3DDevice8_CreateAdditionalSwapChain(&This->IDirect3DDevice8_iface,
2934 &local_parameters, (IDirect3DSwapChain8 **)&d3d_swapchain);
2937 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
2942 *swapchain = d3d_swapchain->wineD3DSwapChain;
2943 IUnknown_Release(d3d_swapchain->parentDevice);
2944 d3d_swapchain->parentDevice = NULL;
2946 /* Copy back the presentation parameters */
2947 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
2948 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
2949 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
2950 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
2951 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
2952 present_parameters->SwapEffect = local_parameters.SwapEffect;
2953 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
2954 present_parameters->Windowed = local_parameters.Windowed;
2955 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
2956 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
2957 present_parameters->Flags = local_parameters.Flags;
2958 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
2959 present_parameters->PresentationInterval = local_parameters.FullScreen_PresentationInterval;
2964 static const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl =
2966 /* IUnknown methods */
2967 device_parent_QueryInterface,
2968 device_parent_AddRef,
2969 device_parent_Release,
2970 /* IWineD3DDeviceParent methods */
2971 device_parent_WineD3DDeviceCreated,
2972 device_parent_CreateSurface,
2973 device_parent_CreateRenderTarget,
2974 device_parent_CreateDepthStencilSurface,
2975 device_parent_CreateVolume,
2976 device_parent_CreateSwapChain,
2979 static void setup_fpu(void)
2981 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
2983 __asm__ volatile ("fnstcw %0" : "=m" (cw));
2984 cw = (cw & ~0xf3f) | 0x3f;
2985 __asm__ volatile ("fldcw %0" : : "m" (cw));
2987 FIXME("FPU setup not implemented for this platform.\n");
2991 HRESULT device_init(IDirect3DDevice8Impl *device, struct wined3d *wined3d, UINT adapter,
2992 D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters)
2994 WINED3DPRESENT_PARAMETERS wined3d_parameters;
2997 device->IDirect3DDevice8_iface.lpVtbl = &Direct3DDevice8_Vtbl;
2998 device->IWineD3DDeviceParent_iface.lpVtbl = &d3d8_wined3d_device_parent_vtbl;
3000 device->handle_table.entries = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
3001 D3D8_INITIAL_HANDLE_TABLE_SIZE * sizeof(*device->handle_table.entries));
3002 if (!device->handle_table.entries)
3004 ERR("Failed to allocate handle table memory.\n");
3005 return E_OUTOFMEMORY;
3007 device->handle_table.table_size = D3D8_INITIAL_HANDLE_TABLE_SIZE;
3009 if (!(flags & D3DCREATE_FPU_PRESERVE)) setup_fpu();
3011 wined3d_mutex_lock();
3012 hr = wined3d_device_create(wined3d, adapter, device_type, focus_window, flags,
3013 &device->IWineD3DDeviceParent_iface, &device->WineD3DDevice);
3016 WARN("Failed to create wined3d device, hr %#x.\n", hr);
3017 wined3d_mutex_unlock();
3018 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
3022 if (!parameters->Windowed)
3024 HWND device_window = parameters->hDeviceWindow;
3026 if (!focus_window) focus_window = device_window;
3027 if (FAILED(hr = IWineD3DDevice_AcquireFocusWindow(device->WineD3DDevice, focus_window)))
3029 ERR("Failed to acquire focus window, hr %#x.\n", hr);
3030 IWineD3DDevice_Release(device->WineD3DDevice);
3031 wined3d_mutex_unlock();
3032 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
3036 if (!device_window) device_window = focus_window;
3037 IWineD3DDevice_SetupFullscreenWindow(device->WineD3DDevice, device_window,
3038 parameters->BackBufferWidth,
3039 parameters->BackBufferHeight);
3042 if (flags & D3DCREATE_MULTITHREADED) IWineD3DDevice_SetMultithreaded(device->WineD3DDevice);
3044 wined3d_parameters.BackBufferWidth = parameters->BackBufferWidth;
3045 wined3d_parameters.BackBufferHeight = parameters->BackBufferHeight;
3046 wined3d_parameters.BackBufferFormat = wined3dformat_from_d3dformat(parameters->BackBufferFormat);
3047 wined3d_parameters.BackBufferCount = parameters->BackBufferCount;
3048 wined3d_parameters.MultiSampleType = parameters->MultiSampleType;
3049 wined3d_parameters.MultiSampleQuality = 0; /* d3d9 only */
3050 wined3d_parameters.SwapEffect = parameters->SwapEffect;
3051 wined3d_parameters.hDeviceWindow = parameters->hDeviceWindow;
3052 wined3d_parameters.Windowed = parameters->Windowed;
3053 wined3d_parameters.EnableAutoDepthStencil = parameters->EnableAutoDepthStencil;
3054 wined3d_parameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(parameters->AutoDepthStencilFormat);
3055 wined3d_parameters.Flags = parameters->Flags;
3056 wined3d_parameters.FullScreen_RefreshRateInHz = parameters->FullScreen_RefreshRateInHz;
3057 wined3d_parameters.PresentationInterval = parameters->FullScreen_PresentationInterval;
3058 wined3d_parameters.AutoRestoreDisplayMode = TRUE;
3060 hr = IWineD3DDevice_Init3D(device->WineD3DDevice, &wined3d_parameters);
3063 WARN("Failed to initialize 3D, hr %#x.\n", hr);
3064 IWineD3DDevice_ReleaseFocusWindow(device->WineD3DDevice);
3065 IWineD3DDevice_Release(device->WineD3DDevice);
3066 wined3d_mutex_unlock();
3067 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
3071 hr = IWineD3DDevice_SetRenderState(device->WineD3DDevice, WINED3DRS_POINTSIZE_MIN, 0);
3072 wined3d_mutex_unlock();
3075 ERR("Failed to set minimum pointsize, hr %#x.\n", hr);
3079 parameters->BackBufferWidth = wined3d_parameters.BackBufferWidth;
3080 parameters->BackBufferHeight = wined3d_parameters.BackBufferHeight;
3081 parameters->BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters.BackBufferFormat);
3082 parameters->BackBufferCount = wined3d_parameters.BackBufferCount;
3083 parameters->MultiSampleType = wined3d_parameters.MultiSampleType;
3084 parameters->SwapEffect = wined3d_parameters.SwapEffect;
3085 parameters->hDeviceWindow = wined3d_parameters.hDeviceWindow;
3086 parameters->Windowed = wined3d_parameters.Windowed;
3087 parameters->EnableAutoDepthStencil = wined3d_parameters.EnableAutoDepthStencil;
3088 parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(wined3d_parameters.AutoDepthStencilFormat);
3089 parameters->Flags = wined3d_parameters.Flags;
3090 parameters->FullScreen_RefreshRateInHz = wined3d_parameters.FullScreen_RefreshRateInHz;
3091 parameters->FullScreen_PresentationInterval = wined3d_parameters.PresentationInterval;
3093 device->declArraySize = 16;
3094 device->decls = HeapAlloc(GetProcessHeap(), 0, device->declArraySize * sizeof(*device->decls));
3097 ERR("Failed to allocate FVF vertex delcaration map memory.\n");
3105 wined3d_mutex_lock();
3106 IWineD3DDevice_Uninit3D(device->WineD3DDevice, D3D8CB_DestroySwapChain);
3107 IWineD3DDevice_ReleaseFocusWindow(device->WineD3DDevice);
3108 IWineD3DDevice_Release(device->WineD3DDevice);
3109 wined3d_mutex_unlock();
3110 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);