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 /* IDirect3D IUnknown parts follow: */
268 static HRESULT WINAPI IDirect3DDevice8Impl_QueryInterface(LPDIRECT3DDEVICE8 iface,REFIID riid,LPVOID *ppobj)
270 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
272 TRACE("iface %p, riid %s, object %p.\n",
273 iface, debugstr_guid(riid), ppobj);
275 if (IsEqualGUID(riid, &IID_IUnknown)
276 || IsEqualGUID(riid, &IID_IDirect3DDevice8)) {
277 IUnknown_AddRef(iface);
282 if (IsEqualGUID(riid, &IID_IWineD3DDeviceParent))
284 IUnknown_AddRef((IUnknown *)&This->device_parent_vtbl);
285 *ppobj = &This->device_parent_vtbl;
289 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
291 return E_NOINTERFACE;
294 static ULONG WINAPI IDirect3DDevice8Impl_AddRef(LPDIRECT3DDEVICE8 iface) {
295 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
296 ULONG ref = InterlockedIncrement(&This->ref);
298 TRACE("%p increasing refcount to %u.\n", iface, ref);
303 static ULONG WINAPI IDirect3DDevice8Impl_Release(LPDIRECT3DDEVICE8 iface) {
304 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
307 if (This->inDestruction) return 0;
308 ref = InterlockedDecrement(&This->ref);
310 TRACE("%p decreasing refcount to %u.\n", iface, ref);
315 TRACE("Releasing wined3d device %p\n", This->WineD3DDevice);
317 wined3d_mutex_lock();
319 This->inDestruction = TRUE;
321 for(i = 0; i < This->numConvertedDecls; i++) {
322 IDirect3DVertexDeclaration8_Release(This->decls[i].decl);
324 HeapFree(GetProcessHeap(), 0, This->decls);
326 IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D8CB_DestroySwapChain);
327 IWineD3DDevice_ReleaseFocusWindow(This->WineD3DDevice);
328 IWineD3DDevice_Release(This->WineD3DDevice);
329 HeapFree(GetProcessHeap(), 0, This->handle_table.entries);
330 HeapFree(GetProcessHeap(), 0, This);
332 wined3d_mutex_unlock();
337 /* IDirect3DDevice Interface follow: */
338 static HRESULT WINAPI IDirect3DDevice8Impl_TestCooperativeLevel(IDirect3DDevice8 *iface)
340 TRACE("iface %p.\n", iface);
345 static UINT WINAPI IDirect3DDevice8Impl_GetAvailableTextureMem(LPDIRECT3DDEVICE8 iface) {
346 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
349 TRACE("iface %p.\n", iface);
351 wined3d_mutex_lock();
352 hr = IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
353 wined3d_mutex_unlock();
358 static HRESULT WINAPI IDirect3DDevice8Impl_ResourceManagerDiscardBytes(LPDIRECT3DDEVICE8 iface, DWORD Bytes) {
359 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
362 TRACE("iface %p, byte_count %u.\n", iface, Bytes);
363 FIXME("Byte count ignored.\n");
365 wined3d_mutex_lock();
366 hr = IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
367 wined3d_mutex_unlock();
372 static HRESULT WINAPI IDirect3DDevice8Impl_GetDirect3D(IDirect3DDevice8 *iface, IDirect3D8 **ppD3D8)
374 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
378 TRACE("iface %p, d3d8 %p.\n", iface, ppD3D8);
380 if (NULL == ppD3D8) {
381 return D3DERR_INVALIDCALL;
384 wined3d_mutex_lock();
385 hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &pWineD3D);
386 if (SUCCEEDED(hr) && pWineD3D)
388 *ppD3D8 = IWineD3D_GetParent(pWineD3D);
389 IDirect3D8_AddRef(*ppD3D8);
390 IWineD3D_Release(pWineD3D);
394 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
397 wined3d_mutex_unlock();
399 TRACE("(%p) returning %p\n",This , *ppD3D8);
404 static HRESULT WINAPI IDirect3DDevice8Impl_GetDeviceCaps(LPDIRECT3DDEVICE8 iface, D3DCAPS8* pCaps) {
405 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
406 HRESULT hrc = D3D_OK;
407 WINED3DCAPS *pWineCaps;
409 TRACE("iface %p, caps %p.\n", iface, pCaps);
412 return D3DERR_INVALIDCALL;
414 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
415 if(pWineCaps == NULL){
416 return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
419 wined3d_mutex_lock();
420 hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
421 wined3d_mutex_unlock();
423 fixup_caps(pWineCaps);
424 WINECAPSTOD3D8CAPS(pCaps, pWineCaps)
425 HeapFree(GetProcessHeap(), 0, pWineCaps);
427 TRACE("Returning %p %p\n", This, pCaps);
431 static HRESULT WINAPI IDirect3DDevice8Impl_GetDisplayMode(LPDIRECT3DDEVICE8 iface, D3DDISPLAYMODE* pMode) {
432 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
435 TRACE("iface %p, mode %p.\n", iface, pMode);
437 wined3d_mutex_lock();
438 hr = IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, 0, (WINED3DDISPLAYMODE *) pMode);
439 wined3d_mutex_unlock();
441 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
446 static HRESULT WINAPI IDirect3DDevice8Impl_GetCreationParameters(LPDIRECT3DDEVICE8 iface, D3DDEVICE_CREATION_PARAMETERS *pParameters) {
447 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
450 TRACE("iface %p, parameters %p.\n", iface, pParameters);
452 wined3d_mutex_lock();
453 hr = IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
454 wined3d_mutex_unlock();
459 static HRESULT WINAPI IDirect3DDevice8Impl_SetCursorProperties(LPDIRECT3DDEVICE8 iface, UINT XHotSpot, UINT YHotSpot, IDirect3DSurface8* pCursorBitmap) {
460 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
461 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl*)pCursorBitmap;
464 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
465 iface, XHotSpot, YHotSpot, pCursorBitmap);
469 WARN("No cursor bitmap, returning D3DERR_INVALIDCALL.\n");
470 return D3DERR_INVALIDCALL;
473 wined3d_mutex_lock();
474 hr = IWineD3DDevice_SetCursorProperties(This->WineD3DDevice,XHotSpot,YHotSpot,pSurface->wineD3DSurface);
475 wined3d_mutex_unlock();
480 static void WINAPI IDirect3DDevice8Impl_SetCursorPosition(LPDIRECT3DDEVICE8 iface, UINT XScreenSpace, UINT YScreenSpace, DWORD Flags) {
481 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
483 TRACE("iface %p, x %u, y %u, flags %#x.\n",
484 iface, XScreenSpace, YScreenSpace, Flags);
486 wined3d_mutex_lock();
487 IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
488 wined3d_mutex_unlock();
491 static BOOL WINAPI IDirect3DDevice8Impl_ShowCursor(LPDIRECT3DDEVICE8 iface, BOOL bShow) {
492 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
495 TRACE("iface %p, show %#x.\n", iface, bShow);
497 wined3d_mutex_lock();
498 ret = IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
499 wined3d_mutex_unlock();
504 static HRESULT WINAPI IDirect3DDevice8Impl_CreateAdditionalSwapChain(IDirect3DDevice8 *iface,
505 D3DPRESENT_PARAMETERS *present_parameters, IDirect3DSwapChain8 **swapchain)
507 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
508 IDirect3DSwapChain8Impl *object;
511 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
512 iface, present_parameters, swapchain);
514 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
517 ERR("Failed to allocate swapchain memory.\n");
518 return E_OUTOFMEMORY;
521 hr = swapchain_init(object, This, present_parameters);
524 WARN("Failed to initialize swapchain, hr %#x.\n", hr);
525 HeapFree(GetProcessHeap(), 0, object);
529 TRACE("Created swapchain %p.\n", object);
530 *swapchain = (IDirect3DSwapChain8 *)object;
535 static HRESULT WINAPI IDirect3DDevice8Impl_Reset(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
536 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
537 WINED3DPRESENT_PARAMETERS localParameters;
540 TRACE("iface %p, present_parameters %p.\n", iface, pPresentationParameters);
542 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
543 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
544 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
545 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
546 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
547 localParameters.MultiSampleQuality = 0; /* d3d9 only */
548 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
549 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
550 localParameters.Windowed = pPresentationParameters->Windowed;
551 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
552 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
553 localParameters.Flags = pPresentationParameters->Flags;
554 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
555 localParameters.PresentationInterval = pPresentationParameters->FullScreen_PresentationInterval;
556 localParameters.AutoRestoreDisplayMode = TRUE;
558 wined3d_mutex_lock();
559 hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
561 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, WINED3DRS_POINTSIZE_MIN, 0);
563 wined3d_mutex_unlock();
565 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
566 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
567 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
568 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
569 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
570 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
571 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
572 pPresentationParameters->Windowed = localParameters.Windowed;
573 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
574 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
575 pPresentationParameters->Flags = localParameters.Flags;
576 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
577 pPresentationParameters->FullScreen_PresentationInterval = localParameters.PresentationInterval;
582 static HRESULT WINAPI IDirect3DDevice8Impl_Present(LPDIRECT3DDEVICE8 iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion) {
583 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
586 TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
587 iface, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
589 wined3d_mutex_lock();
590 hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
591 wined3d_mutex_unlock();
596 static HRESULT WINAPI IDirect3DDevice8Impl_GetBackBuffer(IDirect3DDevice8 *iface,
597 UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8 **ppBackBuffer)
599 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
600 IWineD3DSurface *retSurface = NULL;
603 TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
604 iface, BackBuffer, Type, ppBackBuffer);
606 wined3d_mutex_lock();
607 hr = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, 0, BackBuffer, (WINED3DBACKBUFFER_TYPE)Type, &retSurface);
608 if (SUCCEEDED(hr) && retSurface && ppBackBuffer)
610 *ppBackBuffer = IWineD3DSurface_GetParent(retSurface);
611 IDirect3DSurface8_AddRef(*ppBackBuffer);
612 IWineD3DSurface_Release(retSurface);
614 wined3d_mutex_unlock();
619 static HRESULT WINAPI IDirect3DDevice8Impl_GetRasterStatus(LPDIRECT3DDEVICE8 iface, D3DRASTER_STATUS* pRasterStatus) {
620 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
623 TRACE("iface %p, raster_status %p.\n", iface, pRasterStatus);
625 wined3d_mutex_lock();
626 hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, 0, (WINED3DRASTER_STATUS *) pRasterStatus);
627 wined3d_mutex_unlock();
632 static void WINAPI IDirect3DDevice8Impl_SetGammaRamp(LPDIRECT3DDEVICE8 iface, DWORD Flags, CONST D3DGAMMARAMP* pRamp) {
633 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
635 TRACE("iface %p, flags %#x, ramp %p.\n", iface, Flags, pRamp);
637 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
638 wined3d_mutex_lock();
639 IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, 0, Flags, (CONST WINED3DGAMMARAMP *) pRamp);
640 wined3d_mutex_unlock();
643 static void WINAPI IDirect3DDevice8Impl_GetGammaRamp(LPDIRECT3DDEVICE8 iface, D3DGAMMARAMP* pRamp) {
644 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
646 TRACE("iface %p, ramp %p.\n", iface, pRamp);
648 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
649 wined3d_mutex_lock();
650 IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, 0, (WINED3DGAMMARAMP *) pRamp);
651 wined3d_mutex_unlock();
654 static HRESULT WINAPI IDirect3DDevice8Impl_CreateTexture(IDirect3DDevice8 *iface,
655 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
656 D3DPOOL pool, IDirect3DTexture8 **texture)
658 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
659 IDirect3DTexture8Impl *object;
662 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
663 iface, width, height, levels, usage, format, pool, texture);
665 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
668 ERR("Failed to allocate texture memory.\n");
669 return D3DERR_OUTOFVIDEOMEMORY;
672 hr = texture_init(object, This, width, height, levels, usage, format, pool);
675 WARN("Failed to initialize texture, hr %#x.\n", hr);
676 HeapFree(GetProcessHeap(), 0, object);
680 TRACE("Created texture %p.\n", object);
681 *texture = (IDirect3DTexture8 *)object;
686 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVolumeTexture(IDirect3DDevice8 *iface,
687 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
688 D3DPOOL pool, IDirect3DVolumeTexture8 **texture)
690 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
691 IDirect3DVolumeTexture8Impl *object;
694 TRACE("iface %p, width %u, height %u, depth %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
695 iface, width, height, depth, levels, usage, format, pool, texture);
697 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
700 ERR("Failed to allocate volume texture memory.\n");
701 return D3DERR_OUTOFVIDEOMEMORY;
704 hr = volumetexture_init(object, This, width, height, depth, levels, usage, format, pool);
707 WARN("Failed to initialize volume texture, hr %#x.\n", hr);
708 HeapFree(GetProcessHeap(), 0, object);
712 TRACE("Created volume texture %p.\n", object);
713 *texture = (IDirect3DVolumeTexture8 *)object;
718 static HRESULT WINAPI IDirect3DDevice8Impl_CreateCubeTexture(IDirect3DDevice8 *iface, UINT edge_length,
719 UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool, IDirect3DCubeTexture8 **texture)
721 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
722 IDirect3DCubeTexture8Impl *object;
725 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
726 iface, edge_length, levels, usage, format, pool, texture);
728 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
731 ERR("Failed to allocate cube texture memory.\n");
732 return D3DERR_OUTOFVIDEOMEMORY;
735 hr = cubetexture_init(object, This, edge_length, levels, usage, format, pool);
738 WARN("Failed to initialize cube texture, hr %#x.\n", hr);
739 HeapFree(GetProcessHeap(), 0, object);
743 TRACE("Created cube texture %p.\n", object);
744 *texture = (IDirect3DCubeTexture8 *)object;
749 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexBuffer(IDirect3DDevice8 *iface, UINT size, DWORD usage,
750 DWORD fvf, D3DPOOL pool, IDirect3DVertexBuffer8 **buffer)
752 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
753 IDirect3DVertexBuffer8Impl *object;
756 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p.\n",
757 iface, size, usage, fvf, pool, buffer);
759 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
762 ERR("Failed to allocate buffer memory.\n");
763 return D3DERR_OUTOFVIDEOMEMORY;
766 hr = vertexbuffer_init(object, This, size, usage, fvf, pool);
769 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr);
770 HeapFree(GetProcessHeap(), 0, object);
774 TRACE("Created vertex buffer %p.\n", object);
775 *buffer = (IDirect3DVertexBuffer8 *)object;
780 static HRESULT WINAPI IDirect3DDevice8Impl_CreateIndexBuffer(IDirect3DDevice8 *iface, UINT size, DWORD usage,
781 D3DFORMAT format, D3DPOOL pool, IDirect3DIndexBuffer8 **buffer)
783 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
784 IDirect3DIndexBuffer8Impl *object;
787 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p.\n",
788 iface, size, usage, format, pool, buffer);
790 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
793 ERR("Failed to allocate buffer memory.\n");
794 return D3DERR_OUTOFVIDEOMEMORY;
797 hr = indexbuffer_init(object, This, size, usage, format, pool);
800 WARN("Failed to initialize index buffer, hr %#x.\n", hr);
801 HeapFree(GetProcessHeap(), 0, object);
805 TRACE("Created index buffer %p.\n", object);
806 *buffer = (IDirect3DIndexBuffer8 *)object;
811 static HRESULT IDirect3DDevice8Impl_CreateSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height,
812 D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IDirect3DSurface8 **ppSurface,
813 UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality)
815 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
816 IDirect3DSurface8Impl *object;
819 TRACE("iface %p, width %u, height %u, format %#x, lockable %#x, discard %#x, level %u, surface %p,\n"
820 "\tusage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
821 iface, Width, Height, Format, Lockable, Discard, Level, ppSurface,
822 Usage, Pool, MultiSample, MultisampleQuality);
824 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface8Impl));
827 FIXME("Failed to allocate surface memory.\n");
828 return D3DERR_OUTOFVIDEOMEMORY;
831 hr = surface_init(object, This, Width, Height, Format, Lockable, Discard,
832 Level, Usage, Pool, MultiSample, MultisampleQuality);
835 WARN("Failed to initialize surface, hr %#x.\n", hr);
836 HeapFree(GetProcessHeap(), 0, object);
840 TRACE("Created surface %p.\n", object);
841 *ppSurface = (IDirect3DSurface8 *)object;
846 static HRESULT WINAPI IDirect3DDevice8Impl_CreateRenderTarget(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, BOOL Lockable, IDirect3DSurface8** ppSurface) {
849 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, lockable %#x, surface %p.\n",
850 iface, Width, Height, Format, MultiSample, Lockable, ppSurface);
852 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, Lockable, FALSE /* Discard */,
853 0 /* Level */, ppSurface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, MultiSample, 0);
858 static HRESULT WINAPI IDirect3DDevice8Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, IDirect3DSurface8** ppSurface) {
861 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, surface %p.\n",
862 iface, Width, Height, Format, MultiSample, ppSurface);
864 /* TODO: Verify that Discard is false */
865 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE,
866 0 /* Level */, ppSurface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, MultiSample, 0);
871 /* IDirect3DDevice8Impl::CreateImageSurface returns surface with pool type SYSTEMMEM */
872 static HRESULT WINAPI IDirect3DDevice8Impl_CreateImageSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, IDirect3DSurface8** ppSurface) {
875 TRACE("iface %p, width %u, height %u, format %#x, surface %p.\n",
876 iface, Width, Height, Format, ppSurface);
878 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE /* Discard */,
879 0 /* Level */, ppSurface, 0 /* Usage (undefined/none) */, D3DPOOL_SYSTEMMEM, D3DMULTISAMPLE_NONE,
880 0 /* MultisampleQuality */);
885 static HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8 *pSourceSurface, CONST RECT *pSourceRects, UINT cRects, IDirect3DSurface8 *pDestinationSurface, CONST POINT *pDestPoints) {
886 IDirect3DSurface8Impl *Source = (IDirect3DSurface8Impl *) pSourceSurface;
887 IDirect3DSurface8Impl *Dest = (IDirect3DSurface8Impl *) pDestinationSurface;
889 HRESULT hr = WINED3D_OK;
890 enum wined3d_format_id srcFormat, destFormat;
891 WINED3DSURFACE_DESC winedesc;
893 TRACE("iface %p, src_surface %p, src_rects %p, rect_count %u, dst_surface %p, dst_points %p.\n",
894 iface, pSourceSurface, pSourceRects, cRects, pDestinationSurface, pDestPoints);
896 /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the
897 * destination texture is in WINED3DPOOL_DEFAULT. */
899 wined3d_mutex_lock();
900 IWineD3DSurface_GetDesc(Source->wineD3DSurface, &winedesc);
901 srcFormat = winedesc.format;
903 IWineD3DSurface_GetDesc(Dest->wineD3DSurface, &winedesc);
904 destFormat = winedesc.format;
906 /* Check that the source and destination formats match */
907 if (srcFormat != destFormat && WINED3DFMT_UNKNOWN != destFormat)
909 WARN("Source %p format must match the dest %p format, returning D3DERR_INVALIDCALL.\n",
910 pSourceSurface, pDestinationSurface);
911 wined3d_mutex_unlock();
912 return D3DERR_INVALIDCALL;
914 else if (WINED3DFMT_UNKNOWN == destFormat)
916 TRACE("(%p) : Converting destination surface from WINED3DFMT_UNKNOWN to the source format\n", iface);
917 IWineD3DSurface_SetFormat(Dest->wineD3DSurface, srcFormat);
920 /* Quick if complete copy ... */
921 if (cRects == 0 && pSourceRects == NULL && pDestPoints == NULL) {
922 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
925 /* Copy rect by rect */
926 if (NULL != pSourceRects && NULL != pDestPoints) {
927 for (i = 0; i < cRects; ++i) {
928 IWineD3DSurface_BltFast(Dest->wineD3DSurface, pDestPoints[i].x, pDestPoints[i].y, Source->wineD3DSurface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
931 for (i = 0; i < cRects; ++i) {
932 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
936 wined3d_mutex_unlock();
941 static HRESULT WINAPI IDirect3DDevice8Impl_UpdateTexture(LPDIRECT3DDEVICE8 iface, IDirect3DBaseTexture8* pSourceTexture, IDirect3DBaseTexture8* pDestinationTexture) {
942 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
945 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface, pSourceTexture, pDestinationTexture);
947 wined3d_mutex_lock();
948 hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice, ((IDirect3DBaseTexture8Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture8Impl *)pDestinationTexture)->wineD3DBaseTexture);
949 wined3d_mutex_unlock();
954 static HRESULT WINAPI IDirect3DDevice8Impl_GetFrontBuffer(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pDestSurface) {
955 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
956 IDirect3DSurface8Impl *destSurface = (IDirect3DSurface8Impl *)pDestSurface;
959 TRACE("iface %p, dst_surface %p.\n", iface, pDestSurface);
961 if (pDestSurface == NULL) {
962 WARN("(%p) : Caller passed NULL as pDestSurface returning D3DERR_INVALIDCALL\n", This);
963 return D3DERR_INVALIDCALL;
966 wined3d_mutex_lock();
967 hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, 0, destSurface->wineD3DSurface);
968 wined3d_mutex_unlock();
973 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pRenderTarget, IDirect3DSurface8* pNewZStencil) {
974 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
975 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl *)pRenderTarget;
976 IDirect3DSurface8Impl *pZSurface = (IDirect3DSurface8Impl *)pNewZStencil;
977 IWineD3DSurface *original_ds = NULL;
980 TRACE("iface %p, render_target %p, depth_stencil %p.\n", iface, pRenderTarget, pNewZStencil);
982 wined3d_mutex_lock();
984 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice, &original_ds);
985 if (hr == WINED3D_OK || hr == WINED3DERR_NOTFOUND)
987 hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, pZSurface ? pZSurface->wineD3DSurface : NULL);
988 if (SUCCEEDED(hr) && pSurface)
989 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, 0, pSurface->wineD3DSurface, TRUE);
990 if (FAILED(hr)) IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, original_ds);
992 if (original_ds) IWineD3DSurface_Release(original_ds);
994 wined3d_mutex_unlock();
999 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderTarget(IDirect3DDevice8 *iface,
1000 IDirect3DSurface8 **ppRenderTarget)
1002 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1003 IWineD3DSurface *pRenderTarget;
1006 TRACE("iface %p, render_target %p.\n", iface, ppRenderTarget);
1008 if (ppRenderTarget == NULL) {
1009 return D3DERR_INVALIDCALL;
1012 wined3d_mutex_lock();
1013 hr = IWineD3DDevice_GetRenderTarget(This->WineD3DDevice, 0, &pRenderTarget);
1014 if (SUCCEEDED(hr) && pRenderTarget)
1016 *ppRenderTarget = IWineD3DSurface_GetParent(pRenderTarget);
1017 IDirect3DSurface8_AddRef(*ppRenderTarget);
1018 IWineD3DSurface_Release(pRenderTarget);
1022 FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
1023 *ppRenderTarget = NULL;
1025 wined3d_mutex_unlock();
1030 static HRESULT WINAPI IDirect3DDevice8Impl_GetDepthStencilSurface(IDirect3DDevice8 *iface,
1031 IDirect3DSurface8 **ppZStencilSurface)
1033 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1034 IWineD3DSurface *pZStencilSurface;
1037 TRACE("iface %p, depth_stencil %p.\n", iface, ppZStencilSurface);
1039 if(ppZStencilSurface == NULL){
1040 return D3DERR_INVALIDCALL;
1043 wined3d_mutex_lock();
1044 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice, &pZStencilSurface);
1047 *ppZStencilSurface = IWineD3DSurface_GetParent(pZStencilSurface);
1048 IDirect3DSurface8_AddRef(*ppZStencilSurface);
1049 IWineD3DSurface_Release(pZStencilSurface);
1053 if (hr != WINED3DERR_NOTFOUND)
1054 FIXME("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
1055 *ppZStencilSurface = NULL;
1057 wined3d_mutex_unlock();
1062 static HRESULT WINAPI IDirect3DDevice8Impl_BeginScene(LPDIRECT3DDEVICE8 iface) {
1063 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1066 TRACE("iface %p.\n", iface);
1068 wined3d_mutex_lock();
1069 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
1070 wined3d_mutex_unlock();
1075 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice8Impl_EndScene(LPDIRECT3DDEVICE8 iface) {
1076 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1079 TRACE("iface %p.\n", iface);
1081 wined3d_mutex_lock();
1082 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
1083 wined3d_mutex_unlock();
1088 static HRESULT WINAPI IDirect3DDevice8Impl_Clear(LPDIRECT3DDEVICE8 iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
1089 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1092 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1093 iface, Count, pRects, Flags, Color, Z, Stencil);
1095 wined3d_mutex_lock();
1096 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (const RECT *)pRects, Flags, Color, Z, Stencil);
1097 wined3d_mutex_unlock();
1102 static HRESULT WINAPI IDirect3DDevice8Impl_SetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
1103 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1106 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, lpMatrix);
1108 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1109 wined3d_mutex_lock();
1110 hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
1111 wined3d_mutex_unlock();
1116 static HRESULT WINAPI IDirect3DDevice8Impl_GetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State,D3DMATRIX* pMatrix) {
1117 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1120 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1122 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1123 wined3d_mutex_lock();
1124 hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
1125 wined3d_mutex_unlock();
1130 static HRESULT WINAPI IDirect3DDevice8Impl_MultiplyTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
1131 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1134 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1136 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1137 wined3d_mutex_lock();
1138 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
1139 wined3d_mutex_unlock();
1144 static HRESULT WINAPI IDirect3DDevice8Impl_SetViewport(LPDIRECT3DDEVICE8 iface, CONST D3DVIEWPORT8* pViewport) {
1145 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1148 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1150 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1151 wined3d_mutex_lock();
1152 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
1153 wined3d_mutex_unlock();
1158 static HRESULT WINAPI IDirect3DDevice8Impl_GetViewport(LPDIRECT3DDEVICE8 iface, D3DVIEWPORT8* pViewport) {
1159 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1162 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1164 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1165 wined3d_mutex_lock();
1166 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
1167 wined3d_mutex_unlock();
1172 static HRESULT WINAPI IDirect3DDevice8Impl_SetMaterial(LPDIRECT3DDEVICE8 iface, CONST D3DMATERIAL8* pMaterial) {
1173 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1176 TRACE("iface %p, material %p.\n", iface, pMaterial);
1178 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1179 wined3d_mutex_lock();
1180 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
1181 wined3d_mutex_unlock();
1186 static HRESULT WINAPI IDirect3DDevice8Impl_GetMaterial(LPDIRECT3DDEVICE8 iface, D3DMATERIAL8* pMaterial) {
1187 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1190 TRACE("iface %p, material %p.\n", iface, pMaterial);
1192 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1193 wined3d_mutex_lock();
1194 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
1195 wined3d_mutex_unlock();
1200 static HRESULT WINAPI IDirect3DDevice8Impl_SetLight(LPDIRECT3DDEVICE8 iface, DWORD Index, CONST D3DLIGHT8* pLight) {
1201 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1204 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1206 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1207 wined3d_mutex_lock();
1208 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
1209 wined3d_mutex_unlock();
1214 static HRESULT WINAPI IDirect3DDevice8Impl_GetLight(LPDIRECT3DDEVICE8 iface, DWORD Index,D3DLIGHT8* pLight) {
1215 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1218 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1220 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1221 wined3d_mutex_lock();
1222 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1223 wined3d_mutex_unlock();
1228 static HRESULT WINAPI IDirect3DDevice8Impl_LightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL Enable) {
1229 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1232 TRACE("iface %p, index %u, enable %#x.\n", iface, Index, Enable);
1234 wined3d_mutex_lock();
1235 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1236 wined3d_mutex_unlock();
1241 static HRESULT WINAPI IDirect3DDevice8Impl_GetLightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL* pEnable) {
1242 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1245 TRACE("iface %p, index %u, enable %p.\n", iface, Index, pEnable);
1247 wined3d_mutex_lock();
1248 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1249 wined3d_mutex_unlock();
1254 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,CONST float* pPlane) {
1255 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1258 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1260 wined3d_mutex_lock();
1261 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1262 wined3d_mutex_unlock();
1267 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,float* pPlane) {
1268 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1271 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1273 wined3d_mutex_lock();
1274 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1275 wined3d_mutex_unlock();
1280 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD Value) {
1281 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1284 TRACE("iface %p, state %#x, value %#x.\n", iface, State, Value);
1286 wined3d_mutex_lock();
1287 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1288 wined3d_mutex_unlock();
1293 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD* pValue) {
1294 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1297 TRACE("iface %p, state %#x, value %p.\n", iface, State, pValue);
1299 wined3d_mutex_lock();
1300 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1301 wined3d_mutex_unlock();
1306 static HRESULT WINAPI IDirect3DDevice8Impl_BeginStateBlock(LPDIRECT3DDEVICE8 iface) {
1307 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1310 TRACE("iface %p.\n", iface);
1312 wined3d_mutex_lock();
1313 hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
1314 wined3d_mutex_unlock();
1319 static HRESULT WINAPI IDirect3DDevice8Impl_EndStateBlock(LPDIRECT3DDEVICE8 iface, DWORD* pToken) {
1320 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1321 IWineD3DStateBlock *stateblock;
1324 TRACE("iface %p, token %p.\n", iface, pToken);
1326 /* Tell wineD3D to endstateblock before anything else (in case we run out
1327 * of memory later and cause locking problems)
1329 wined3d_mutex_lock();
1330 hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice , &stateblock);
1332 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
1333 wined3d_mutex_unlock();
1337 *pToken = d3d8_allocate_handle(&This->handle_table, stateblock, D3D8_HANDLE_SB);
1338 wined3d_mutex_unlock();
1340 if (*pToken == D3D8_INVALID_HANDLE)
1342 ERR("Failed to create a handle\n");
1343 wined3d_mutex_lock();
1344 IWineD3DStateBlock_Release(stateblock);
1345 wined3d_mutex_unlock();
1350 TRACE("Returning %#x (%p).\n", *pToken, stateblock);
1355 static HRESULT WINAPI IDirect3DDevice8Impl_ApplyStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1356 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1357 IWineD3DStateBlock *stateblock;
1360 TRACE("iface %p, token %#x.\n", iface, Token);
1362 if (!Token) return D3D_OK;
1364 wined3d_mutex_lock();
1365 stateblock = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1368 WARN("Invalid handle (%#x) passed.\n", Token);
1369 wined3d_mutex_unlock();
1370 return D3DERR_INVALIDCALL;
1372 hr = IWineD3DStateBlock_Apply(stateblock);
1373 wined3d_mutex_unlock();
1378 static HRESULT WINAPI IDirect3DDevice8Impl_CaptureStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1379 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1380 IWineD3DStateBlock *stateblock;
1383 TRACE("iface %p, token %#x.\n", iface, Token);
1385 wined3d_mutex_lock();
1386 stateblock = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1389 WARN("Invalid handle (%#x) passed.\n", Token);
1390 wined3d_mutex_unlock();
1391 return D3DERR_INVALIDCALL;
1393 hr = IWineD3DStateBlock_Capture(stateblock);
1394 wined3d_mutex_unlock();
1399 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1400 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1401 IWineD3DStateBlock *stateblock;
1403 TRACE("iface %p, token %#x.\n", iface, Token);
1405 wined3d_mutex_lock();
1406 stateblock = d3d8_free_handle(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1410 WARN("Invalid handle (%#x) passed.\n", Token);
1411 wined3d_mutex_unlock();
1412 return D3DERR_INVALIDCALL;
1415 if (IWineD3DStateBlock_Release((IUnknown *)stateblock))
1417 ERR("Stateblock %p has references left, this shouldn't happen.\n", stateblock);
1419 wined3d_mutex_unlock();
1424 static HRESULT WINAPI IDirect3DDevice8Impl_CreateStateBlock(IDirect3DDevice8 *iface,
1425 D3DSTATEBLOCKTYPE Type, DWORD *handle)
1427 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1428 IWineD3DStateBlock *stateblock;
1431 TRACE("iface %p, type %#x, handle %p.\n", iface, Type, handle);
1433 if (Type != D3DSBT_ALL
1434 && Type != D3DSBT_PIXELSTATE
1435 && Type != D3DSBT_VERTEXSTATE)
1437 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1438 return D3DERR_INVALIDCALL;
1441 wined3d_mutex_lock();
1442 hr = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type, &stateblock);
1445 wined3d_mutex_unlock();
1446 ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr);
1450 *handle = d3d8_allocate_handle(&This->handle_table, stateblock, D3D8_HANDLE_SB);
1451 wined3d_mutex_unlock();
1453 if (*handle == D3D8_INVALID_HANDLE)
1455 ERR("Failed to allocate a handle.\n");
1456 wined3d_mutex_lock();
1457 IWineD3DStateBlock_Release(stateblock);
1458 wined3d_mutex_unlock();
1463 TRACE("Returning %#x (%p).\n", *handle, stateblock);
1468 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipStatus(LPDIRECT3DDEVICE8 iface, CONST D3DCLIPSTATUS8* pClipStatus) {
1469 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1472 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1473 /* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
1475 wined3d_mutex_lock();
1476 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1477 wined3d_mutex_unlock();
1482 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipStatus(LPDIRECT3DDEVICE8 iface, D3DCLIPSTATUS8* pClipStatus) {
1483 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1486 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1488 wined3d_mutex_lock();
1489 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1490 wined3d_mutex_unlock();
1495 static HRESULT WINAPI IDirect3DDevice8Impl_GetTexture(IDirect3DDevice8 *iface,
1496 DWORD Stage, IDirect3DBaseTexture8 **ppTexture)
1498 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1499 IWineD3DBaseTexture *retTexture;
1502 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, ppTexture);
1504 if(ppTexture == NULL){
1505 return D3DERR_INVALIDCALL;
1508 wined3d_mutex_lock();
1509 hr = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
1512 WARN("Failed to get texture for stage %u, hr %#x.\n", Stage, hr);
1513 wined3d_mutex_unlock();
1520 *ppTexture = IWineD3DBaseTexture_GetParent(retTexture);
1521 IDirect3DBaseTexture8_AddRef(*ppTexture);
1522 IWineD3DBaseTexture_Release(retTexture);
1528 wined3d_mutex_unlock();
1533 static HRESULT WINAPI IDirect3DDevice8Impl_SetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage, IDirect3DBaseTexture8* pTexture) {
1534 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1537 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, pTexture);
1539 wined3d_mutex_lock();
1540 hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
1541 pTexture==NULL ? NULL : ((IDirect3DBaseTexture8Impl *)pTexture)->wineD3DBaseTexture);
1542 wined3d_mutex_unlock();
1547 static const struct tss_lookup
1554 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 0, unused */
1555 {FALSE, WINED3DTSS_COLOROP}, /* 1, D3DTSS_COLOROP */
1556 {FALSE, WINED3DTSS_COLORARG1}, /* 2, D3DTSS_COLORARG1 */
1557 {FALSE, WINED3DTSS_COLORARG2}, /* 3, D3DTSS_COLORARG2 */
1558 {FALSE, WINED3DTSS_ALPHAOP}, /* 4, D3DTSS_ALPHAOP */
1559 {FALSE, WINED3DTSS_ALPHAARG1}, /* 5, D3DTSS_ALPHAARG1 */
1560 {FALSE, WINED3DTSS_ALPHAARG2}, /* 6, D3DTSS_ALPHAARG2 */
1561 {FALSE, WINED3DTSS_BUMPENVMAT00}, /* 7, D3DTSS_BUMPENVMAT00 */
1562 {FALSE, WINED3DTSS_BUMPENVMAT01}, /* 8, D3DTSS_BUMPENVMAT01 */
1563 {FALSE, WINED3DTSS_BUMPENVMAT10}, /* 9, D3DTSS_BUMPENVMAT10 */
1564 {FALSE, WINED3DTSS_BUMPENVMAT11}, /* 10, D3DTSS_BUMPENVMAT11 */
1565 {FALSE, WINED3DTSS_TEXCOORDINDEX}, /* 11, D3DTSS_TEXCOORDINDEX */
1566 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 12, unused */
1567 {TRUE, WINED3DSAMP_ADDRESSU}, /* 13, D3DTSS_ADDRESSU */
1568 {TRUE, WINED3DSAMP_ADDRESSV}, /* 14, D3DTSS_ADDRESSV */
1569 {TRUE, WINED3DSAMP_BORDERCOLOR}, /* 15, D3DTSS_BORDERCOLOR */
1570 {TRUE, WINED3DSAMP_MAGFILTER}, /* 16, D3DTSS_MAGFILTER */
1571 {TRUE, WINED3DSAMP_MINFILTER}, /* 17, D3DTSS_MINFILTER */
1572 {TRUE, WINED3DSAMP_MIPFILTER}, /* 18, D3DTSS_MIPFILTER */
1573 {TRUE, WINED3DSAMP_MIPMAPLODBIAS}, /* 19, D3DTSS_MIPMAPLODBIAS */
1574 {TRUE, WINED3DSAMP_MAXMIPLEVEL}, /* 20, D3DTSS_MAXMIPLEVEL */
1575 {TRUE, WINED3DSAMP_MAXANISOTROPY}, /* 21, D3DTSS_MAXANISOTROPY */
1576 {FALSE, WINED3DTSS_BUMPENVLSCALE}, /* 22, D3DTSS_BUMPENVLSCALE */
1577 {FALSE, WINED3DTSS_BUMPENVLOFFSET}, /* 23, D3DTSS_BUMPENVLOFFSET */
1578 {FALSE, WINED3DTSS_TEXTURETRANSFORMFLAGS}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1579 {TRUE, WINED3DSAMP_ADDRESSW}, /* 25, D3DTSS_ADDRESSW */
1580 {FALSE, WINED3DTSS_COLORARG0}, /* 26, D3DTSS_COLORARG0 */
1581 {FALSE, WINED3DTSS_ALPHAARG0}, /* 27, D3DTSS_ALPHAARG0 */
1582 {FALSE, WINED3DTSS_RESULTARG}, /* 28, D3DTSS_RESULTARG */
1585 static HRESULT WINAPI IDirect3DDevice8Impl_GetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD *pValue)
1587 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1588 const struct tss_lookup *l;
1591 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface, Stage, Type, pValue);
1593 if (Type >= sizeof(tss_lookup) / sizeof(*tss_lookup))
1595 WARN("Invalid Type %#x passed.\n", Type);
1599 l = &tss_lookup[Type];
1601 wined3d_mutex_lock();
1602 if (l->sampler_state) hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Stage, l->state, pValue);
1603 else hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, l->state, pValue);
1604 wined3d_mutex_unlock();
1609 static HRESULT WINAPI IDirect3DDevice8Impl_SetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value)
1611 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1612 const struct tss_lookup *l;
1615 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface, Stage, Type, Value);
1617 if (Type >= sizeof(tss_lookup) / sizeof(*tss_lookup))
1619 WARN("Invalid Type %#x passed.\n", Type);
1623 l = &tss_lookup[Type];
1625 wined3d_mutex_lock();
1626 if (l->sampler_state) hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Stage, l->state, Value);
1627 else hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, l->state, Value);
1628 wined3d_mutex_unlock();
1633 static HRESULT WINAPI IDirect3DDevice8Impl_ValidateDevice(LPDIRECT3DDEVICE8 iface, DWORD* pNumPasses) {
1634 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1637 TRACE("iface %p, pass_count %p.\n", iface, pNumPasses);
1639 wined3d_mutex_lock();
1640 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1641 wined3d_mutex_unlock();
1646 static HRESULT WINAPI IDirect3DDevice8Impl_GetInfo(IDirect3DDevice8 *iface,
1647 DWORD info_id, void *info, DWORD info_size)
1649 FIXME("iface %p, info_id %#x, info %p, info_size %u stub!\n", iface, info_id, info, info_size);
1654 static HRESULT WINAPI IDirect3DDevice8Impl_SetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, CONST PALETTEENTRY* pEntries) {
1655 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1658 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1660 wined3d_mutex_lock();
1661 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1662 wined3d_mutex_unlock();
1667 static HRESULT WINAPI IDirect3DDevice8Impl_GetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
1668 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1671 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1673 wined3d_mutex_lock();
1674 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1675 wined3d_mutex_unlock();
1680 static HRESULT WINAPI IDirect3DDevice8Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber) {
1681 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1684 TRACE("iface %p, palette_idx %u.\n", iface, PaletteNumber);
1686 wined3d_mutex_lock();
1687 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1688 wined3d_mutex_unlock();
1693 static HRESULT WINAPI IDirect3DDevice8Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT *PaletteNumber) {
1694 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1697 TRACE("iface %p, palette_idx %p.\n", iface, PaletteNumber);
1699 wined3d_mutex_lock();
1700 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1701 wined3d_mutex_unlock();
1706 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitive(IDirect3DDevice8 *iface, D3DPRIMITIVETYPE PrimitiveType,
1707 UINT StartVertex, UINT PrimitiveCount)
1709 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1712 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1713 iface, PrimitiveType, StartVertex, PrimitiveCount);
1715 wined3d_mutex_lock();
1716 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1717 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
1718 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
1719 wined3d_mutex_unlock();
1724 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,
1725 UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount) {
1726 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1729 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, start_idx %u, primitive_count %u.\n",
1730 iface, PrimitiveType, MinVertexIndex, NumVertices, startIndex, primCount);
1732 wined3d_mutex_lock();
1733 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1734 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, startIndex,
1735 vertex_count_from_primitive_count(PrimitiveType, primCount));
1736 wined3d_mutex_unlock();
1741 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT PrimitiveCount,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride) {
1742 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1745 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
1746 iface, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
1748 wined3d_mutex_lock();
1749 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1750 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
1751 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
1752 pVertexStreamZeroData, VertexStreamZeroStride);
1753 wined3d_mutex_unlock();
1758 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,
1759 UINT NumVertexIndices,UINT PrimitiveCount,CONST void* pIndexData,
1760 D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,
1761 UINT VertexStreamZeroStride) {
1762 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1765 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
1766 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
1767 iface, PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount,
1768 pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
1770 wined3d_mutex_lock();
1771 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1772 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice,
1773 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
1774 wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
1775 wined3d_mutex_unlock();
1780 static HRESULT WINAPI IDirect3DDevice8Impl_ProcessVertices(LPDIRECT3DDEVICE8 iface, UINT SrcStartIndex,UINT DestIndex,UINT VertexCount,IDirect3DVertexBuffer8* pDestBuffer,DWORD Flags) {
1781 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1783 IDirect3DVertexBuffer8Impl *dest = (IDirect3DVertexBuffer8Impl *) pDestBuffer;
1785 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, flags %#x.\n",
1786 iface, SrcStartIndex, DestIndex, VertexCount, pDestBuffer, Flags);
1788 wined3d_mutex_lock();
1789 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, NULL, Flags, dest->fvf);
1790 wined3d_mutex_unlock();
1795 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(IDirect3DDevice8 *iface,
1796 const DWORD *declaration, const DWORD *byte_code, DWORD *shader, DWORD usage)
1798 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1799 IDirect3DVertexShader8Impl *object;
1800 DWORD shader_handle;
1804 TRACE("iface %p, declaration %p, byte_code %p, shader %p, usage %#x.\n",
1805 iface, declaration, byte_code, shader, usage);
1807 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1810 ERR("Failed to allocate vertex shader memory.\n");
1812 return E_OUTOFMEMORY;
1815 wined3d_mutex_lock();
1816 handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_VS);
1817 wined3d_mutex_unlock();
1818 if (handle == D3D8_INVALID_HANDLE)
1820 ERR("Failed to allocate vertex shader handle.\n");
1821 HeapFree(GetProcessHeap(), 0, object);
1823 return E_OUTOFMEMORY;
1826 shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
1828 hr = vertexshader_init(object, This, declaration, byte_code, shader_handle, usage);
1831 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
1832 wined3d_mutex_lock();
1833 d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_VS);
1834 wined3d_mutex_unlock();
1835 HeapFree(GetProcessHeap(), 0, object);
1840 TRACE("Created vertex shader %p (handle %#x).\n", object, shader_handle);
1841 *shader = shader_handle;
1846 static IDirect3DVertexDeclaration8Impl *IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl *This, DWORD fvf)
1848 IDirect3DVertexDeclaration8Impl *d3d8_declaration;
1850 int p, low, high; /* deliberately signed */
1851 struct FvfToDecl *convertedDecls = This->decls;
1853 TRACE("Searching for declaration for fvf %08x... ", fvf);
1856 high = This->numConvertedDecls - 1;
1857 while(low <= high) {
1858 p = (low + high) >> 1;
1860 if(convertedDecls[p].fvf == fvf) {
1861 TRACE("found %p\n", convertedDecls[p].decl);
1862 return (IDirect3DVertexDeclaration8Impl *)convertedDecls[p].decl;
1863 } else if(convertedDecls[p].fvf < fvf) {
1869 TRACE("not found. Creating and inserting at position %d.\n", low);
1871 d3d8_declaration = HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration));
1872 if (!d3d8_declaration)
1874 ERR("Memory allocation failed.\n");
1878 hr = vertexdeclaration_init_fvf(d3d8_declaration, This, fvf);
1881 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
1882 HeapFree(GetProcessHeap(), 0, d3d8_declaration);
1886 if(This->declArraySize == This->numConvertedDecls) {
1887 int grow = This->declArraySize / 2;
1888 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
1889 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
1890 if(!convertedDecls) {
1891 /* This will destroy it */
1892 IDirect3DVertexDeclaration8_Release((IDirect3DVertexDeclaration8 *)d3d8_declaration);
1895 This->decls = convertedDecls;
1896 This->declArraySize += grow;
1899 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(convertedDecls[0]) * (This->numConvertedDecls - low));
1900 convertedDecls[low].decl = (IDirect3DVertexDeclaration8 *)d3d8_declaration;
1901 convertedDecls[low].fvf = fvf;
1902 This->numConvertedDecls++;
1904 TRACE("Returning %p. %u decls in array\n", d3d8_declaration, This->numConvertedDecls);
1905 return d3d8_declaration;
1908 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1909 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1910 IDirect3DVertexShader8Impl *shader;
1913 TRACE("iface %p, shader %#x.\n", iface, pShader);
1915 if (VS_HIGHESTFIXEDFXF >= pShader) {
1916 TRACE("Setting FVF, %#x\n", pShader);
1918 wined3d_mutex_lock();
1919 IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
1920 IDirect3DDevice8Impl_FindDecl(This, pShader)->wined3d_vertex_declaration);
1921 IWineD3DDevice_SetVertexShader(This->WineD3DDevice, NULL);
1922 wined3d_mutex_unlock();
1927 TRACE("Setting shader\n");
1929 wined3d_mutex_lock();
1930 shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
1933 WARN("Invalid handle (%#x) passed.\n", pShader);
1934 wined3d_mutex_unlock();
1936 return D3DERR_INVALIDCALL;
1939 hr = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
1940 ((IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration)->wined3d_vertex_declaration);
1941 if (SUCCEEDED(hr)) hr = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, shader->wineD3DVertexShader);
1942 wined3d_mutex_unlock();
1944 TRACE("Returning hr %#x\n", hr);
1949 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShader(IDirect3DDevice8 *iface, DWORD *ppShader)
1951 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1952 IWineD3DVertexDeclaration *wined3d_declaration;
1953 IDirect3DVertexDeclaration8 *d3d8_declaration;
1956 TRACE("iface %p, shader %p.\n", iface, ppShader);
1958 wined3d_mutex_lock();
1959 hr = IWineD3DDevice_GetVertexDeclaration(This->WineD3DDevice, &wined3d_declaration);
1962 wined3d_mutex_unlock();
1963 WARN("(%p) : Call to IWineD3DDevice_GetVertexDeclaration failed %#x (device %p)\n",
1964 This, hr, This->WineD3DDevice);
1968 if (!wined3d_declaration)
1970 wined3d_mutex_unlock();
1975 d3d8_declaration = IWineD3DVertexDeclaration_GetParent(wined3d_declaration);
1976 IWineD3DVertexDeclaration_Release(wined3d_declaration);
1977 wined3d_mutex_unlock();
1978 *ppShader = ((IDirect3DVertexDeclaration8Impl *)d3d8_declaration)->shader_handle;
1980 TRACE("(%p) : returning %#x\n", This, *ppShader);
1985 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1986 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1987 IDirect3DVertexShader8Impl *shader;
1988 IWineD3DVertexShader *cur;
1990 TRACE("iface %p, shader %#x.\n", iface, pShader);
1992 wined3d_mutex_lock();
1993 shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
1996 WARN("Invalid handle (%#x) passed.\n", pShader);
1997 wined3d_mutex_unlock();
1999 return D3DERR_INVALIDCALL;
2002 cur = IWineD3DDevice_GetVertexShader(This->WineD3DDevice);
2005 if (cur == shader->wineD3DVertexShader) IDirect3DDevice8_SetVertexShader(iface, 0);
2006 IWineD3DVertexShader_Release(cur);
2009 wined3d_mutex_unlock();
2011 if (IUnknown_Release((IUnknown *)shader))
2013 ERR("Shader %p has references left, this shouldn't happen.\n", shader);
2019 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
2020 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2023 TRACE("iface %p, register %u, data %p, count %u.\n",
2024 iface, Register, pConstantData, ConstantCount);
2026 if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
2027 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2028 Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2029 return D3DERR_INVALIDCALL;
2032 wined3d_mutex_lock();
2033 hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2034 wined3d_mutex_unlock();
2039 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
2040 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2043 TRACE("iface %p, register %u, data %p, count %u.\n",
2044 iface, Register, pConstantData, ConstantCount);
2046 if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
2047 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2048 Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2049 return D3DERR_INVALIDCALL;
2052 wined3d_mutex_lock();
2053 hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2054 wined3d_mutex_unlock();
2059 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderDeclaration(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
2060 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2061 IDirect3DVertexDeclaration8Impl *declaration;
2062 IDirect3DVertexShader8Impl *shader;
2064 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2065 iface, pVertexShader, pData, pSizeOfData);
2067 wined3d_mutex_lock();
2068 shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2069 wined3d_mutex_unlock();
2073 WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2074 return D3DERR_INVALIDCALL;
2076 declaration = (IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration;
2078 /* If pData is NULL, we just return the required size of the buffer. */
2080 *pSizeOfData = declaration->elements_size;
2084 /* MSDN claims that if *pSizeOfData is smaller than the required size
2085 * we should write the required size and return D3DERR_MOREDATA.
2086 * That's not actually true. */
2087 if (*pSizeOfData < declaration->elements_size) {
2088 return D3DERR_INVALIDCALL;
2091 CopyMemory(pData, declaration->elements, declaration->elements_size);
2096 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
2097 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2098 IDirect3DVertexShader8Impl *shader = NULL;
2101 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2102 iface, pVertexShader, pData, pSizeOfData);
2104 wined3d_mutex_lock();
2105 shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2108 WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2109 wined3d_mutex_unlock();
2111 return D3DERR_INVALIDCALL;
2114 if (!shader->wineD3DVertexShader)
2116 wined3d_mutex_unlock();
2121 hr = IWineD3DVertexShader_GetFunction(shader->wineD3DVertexShader, pData, pSizeOfData);
2122 wined3d_mutex_unlock();
2127 static HRESULT WINAPI IDirect3DDevice8Impl_SetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8* pIndexData, UINT baseVertexIndex) {
2128 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2130 IDirect3DIndexBuffer8Impl *ib = (IDirect3DIndexBuffer8Impl *)pIndexData;
2132 TRACE("iface %p, buffer %p, base_vertex_idx %u.\n", iface, pIndexData, baseVertexIndex);
2134 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
2135 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
2136 * vertex buffers can't be created to address them with an index that requires the 32nd bit
2137 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
2140 wined3d_mutex_lock();
2141 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, baseVertexIndex);
2142 hr = IWineD3DDevice_SetIndexBuffer(This->WineD3DDevice,
2143 ib ? ib->wineD3DIndexBuffer : NULL,
2144 ib ? ib->format : WINED3DFMT_UNKNOWN);
2145 wined3d_mutex_unlock();
2150 static HRESULT WINAPI IDirect3DDevice8Impl_GetIndices(IDirect3DDevice8 *iface,
2151 IDirect3DIndexBuffer8 **ppIndexData, UINT *pBaseVertexIndex)
2153 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2154 IWineD3DBuffer *retIndexData = NULL;
2157 TRACE("iface %p, buffer %p, base_vertex_index %p.\n", iface, ppIndexData, pBaseVertexIndex);
2159 if(ppIndexData == NULL){
2160 return D3DERR_INVALIDCALL;
2163 /* The case from UINT to INT is safe because d3d8 will never set negative values */
2164 wined3d_mutex_lock();
2165 IWineD3DDevice_GetBaseVertexIndex(This->WineD3DDevice, (INT *) pBaseVertexIndex);
2166 hr = IWineD3DDevice_GetIndexBuffer(This->WineD3DDevice, &retIndexData);
2167 if (SUCCEEDED(hr) && retIndexData)
2169 *ppIndexData = IWineD3DBuffer_GetParent(retIndexData);
2170 IDirect3DIndexBuffer8_AddRef(*ppIndexData);
2171 IWineD3DBuffer_Release(retIndexData);
2173 if (FAILED(hr)) FIXME("Call to GetIndices failed\n");
2174 *ppIndexData = NULL;
2176 wined3d_mutex_unlock();
2181 static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(IDirect3DDevice8 *iface,
2182 const DWORD *byte_code, DWORD *shader)
2184 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2185 IDirect3DPixelShader8Impl *object;
2186 DWORD shader_handle;
2190 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2194 TRACE("(%p) Invalid call\n", This);
2195 return D3DERR_INVALIDCALL;
2198 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2201 ERR("Failed to allocate pixel shader memmory.\n");
2202 return E_OUTOFMEMORY;
2205 wined3d_mutex_lock();
2206 handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_PS);
2207 wined3d_mutex_unlock();
2208 if (handle == D3D8_INVALID_HANDLE)
2210 ERR("Failed to allocate pixel shader handle.\n");
2211 HeapFree(GetProcessHeap(), 0, object);
2212 return E_OUTOFMEMORY;
2215 shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
2217 hr = pixelshader_init(object, This, byte_code, shader_handle);
2220 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
2221 wined3d_mutex_lock();
2222 d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_PS);
2223 wined3d_mutex_unlock();
2224 HeapFree(GetProcessHeap(), 0, object);
2229 TRACE("Created pixel shader %p (handle %#x).\n", object, shader_handle);
2230 *shader = shader_handle;
2235 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
2236 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2237 IDirect3DPixelShader8Impl *shader;
2240 TRACE("iface %p, shader %#x.\n", iface, pShader);
2242 wined3d_mutex_lock();
2246 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, NULL);
2247 wined3d_mutex_unlock();
2251 shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2254 WARN("Invalid handle (%#x) passed.\n", pShader);
2255 wined3d_mutex_unlock();
2256 return D3DERR_INVALIDCALL;
2259 TRACE("(%p) : Setting shader %p\n", This, shader);
2260 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, shader->wineD3DPixelShader);
2261 wined3d_mutex_unlock();
2266 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShader(IDirect3DDevice8 *iface, DWORD *ppShader)
2268 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2269 IWineD3DPixelShader *object;
2271 TRACE("iface %p, shader %p.\n", iface, ppShader);
2273 if (NULL == ppShader) {
2274 TRACE("(%p) Invalid call\n", This);
2275 return D3DERR_INVALIDCALL;
2278 wined3d_mutex_lock();
2279 object = IWineD3DDevice_GetPixelShader(This->WineD3DDevice);
2282 IDirect3DPixelShader8Impl *d3d8_shader;
2283 d3d8_shader = IWineD3DPixelShader_GetParent(object);
2284 IWineD3DPixelShader_Release(object);
2285 *ppShader = d3d8_shader->handle;
2291 wined3d_mutex_unlock();
2293 TRACE("(%p) : returning %#x\n", This, *ppShader);
2298 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
2299 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2300 IDirect3DPixelShader8Impl *shader;
2301 IWineD3DPixelShader *cur;
2303 TRACE("iface %p, shader %#x.\n", iface, pShader);
2305 wined3d_mutex_lock();
2307 shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2310 WARN("Invalid handle (%#x) passed.\n", pShader);
2311 wined3d_mutex_unlock();
2312 return D3DERR_INVALIDCALL;
2315 cur = IWineD3DDevice_GetPixelShader(This->WineD3DDevice);
2318 if (cur == shader->wineD3DPixelShader) IDirect3DDevice8_SetPixelShader(iface, 0);
2319 IWineD3DPixelShader_Release(cur);
2322 wined3d_mutex_unlock();
2324 if (IUnknown_Release((IUnknown *)shader))
2326 ERR("Shader %p has references left, this shouldn't happen.\n", shader);
2332 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
2333 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2336 TRACE("iface %p, register %u, data %p, count %u.\n",
2337 iface, Register, pConstantData, ConstantCount);
2339 wined3d_mutex_lock();
2340 hr = IWineD3DDevice_SetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2341 wined3d_mutex_unlock();
2346 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
2347 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2350 TRACE("iface %p, register %u, data %p, count %u.\n",
2351 iface, Register, pConstantData, ConstantCount);
2353 wined3d_mutex_lock();
2354 hr = IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2355 wined3d_mutex_unlock();
2360 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pPixelShader, void* pData, DWORD* pSizeOfData) {
2361 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2362 IDirect3DPixelShader8Impl *shader = NULL;
2365 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2366 iface, pPixelShader, pData, pSizeOfData);
2368 wined3d_mutex_lock();
2369 shader = d3d8_get_object(&This->handle_table, pPixelShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2372 WARN("Invalid handle (%#x) passed.\n", pPixelShader);
2373 wined3d_mutex_unlock();
2375 return D3DERR_INVALIDCALL;
2378 hr = IWineD3DPixelShader_GetFunction(shader->wineD3DPixelShader, pData, pSizeOfData);
2379 wined3d_mutex_unlock();
2384 static HRESULT WINAPI IDirect3DDevice8Impl_DrawRectPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
2385 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2388 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2389 iface, Handle, pNumSegs, pRectPatchInfo);
2391 wined3d_mutex_lock();
2392 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
2393 wined3d_mutex_unlock();
2398 static HRESULT WINAPI IDirect3DDevice8Impl_DrawTriPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
2399 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2402 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2403 iface, Handle, pNumSegs, pTriPatchInfo);
2405 wined3d_mutex_lock();
2406 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
2407 wined3d_mutex_unlock();
2412 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePatch(LPDIRECT3DDEVICE8 iface, UINT Handle) {
2413 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2416 TRACE("iface %p, handle %#x.\n", iface, Handle);
2418 wined3d_mutex_lock();
2419 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
2420 wined3d_mutex_unlock();
2425 static HRESULT WINAPI IDirect3DDevice8Impl_SetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8* pStreamData,UINT Stride) {
2426 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2429 TRACE("iface %p, stream_idx %u, buffer %p, stride %u.\n",
2430 iface, StreamNumber, pStreamData, Stride);
2432 wined3d_mutex_lock();
2433 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
2434 NULL == pStreamData ? NULL : ((IDirect3DVertexBuffer8Impl *)pStreamData)->wineD3DVertexBuffer,
2435 0/* Offset in bytes */, Stride);
2436 wined3d_mutex_unlock();
2441 static HRESULT WINAPI IDirect3DDevice8Impl_GetStreamSource(IDirect3DDevice8 *iface,
2442 UINT StreamNumber, IDirect3DVertexBuffer8 **pStream, UINT *pStride)
2444 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2445 IWineD3DBuffer *retStream = NULL;
2448 TRACE("iface %p, stream_idx %u, buffer %p, stride %p.\n",
2449 iface, StreamNumber, pStream, pStride);
2451 if(pStream == NULL){
2452 return D3DERR_INVALIDCALL;
2455 wined3d_mutex_lock();
2456 hr = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber,
2457 &retStream, 0 /* Offset in bytes */, pStride);
2458 if (SUCCEEDED(hr) && retStream)
2460 *pStream = IWineD3DBuffer_GetParent(retStream);
2461 IDirect3DVertexBuffer8_AddRef(*pStream);
2462 IWineD3DBuffer_Release(retStream);
2466 if (FAILED(hr)) FIXME("Call to GetStreamSource failed, hr %#x.\n", hr);
2469 wined3d_mutex_unlock();
2474 static const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl =
2476 IDirect3DDevice8Impl_QueryInterface,
2477 IDirect3DDevice8Impl_AddRef,
2478 IDirect3DDevice8Impl_Release,
2479 IDirect3DDevice8Impl_TestCooperativeLevel,
2480 IDirect3DDevice8Impl_GetAvailableTextureMem,
2481 IDirect3DDevice8Impl_ResourceManagerDiscardBytes,
2482 IDirect3DDevice8Impl_GetDirect3D,
2483 IDirect3DDevice8Impl_GetDeviceCaps,
2484 IDirect3DDevice8Impl_GetDisplayMode,
2485 IDirect3DDevice8Impl_GetCreationParameters,
2486 IDirect3DDevice8Impl_SetCursorProperties,
2487 IDirect3DDevice8Impl_SetCursorPosition,
2488 IDirect3DDevice8Impl_ShowCursor,
2489 IDirect3DDevice8Impl_CreateAdditionalSwapChain,
2490 IDirect3DDevice8Impl_Reset,
2491 IDirect3DDevice8Impl_Present,
2492 IDirect3DDevice8Impl_GetBackBuffer,
2493 IDirect3DDevice8Impl_GetRasterStatus,
2494 IDirect3DDevice8Impl_SetGammaRamp,
2495 IDirect3DDevice8Impl_GetGammaRamp,
2496 IDirect3DDevice8Impl_CreateTexture,
2497 IDirect3DDevice8Impl_CreateVolumeTexture,
2498 IDirect3DDevice8Impl_CreateCubeTexture,
2499 IDirect3DDevice8Impl_CreateVertexBuffer,
2500 IDirect3DDevice8Impl_CreateIndexBuffer,
2501 IDirect3DDevice8Impl_CreateRenderTarget,
2502 IDirect3DDevice8Impl_CreateDepthStencilSurface,
2503 IDirect3DDevice8Impl_CreateImageSurface,
2504 IDirect3DDevice8Impl_CopyRects,
2505 IDirect3DDevice8Impl_UpdateTexture,
2506 IDirect3DDevice8Impl_GetFrontBuffer,
2507 IDirect3DDevice8Impl_SetRenderTarget,
2508 IDirect3DDevice8Impl_GetRenderTarget,
2509 IDirect3DDevice8Impl_GetDepthStencilSurface,
2510 IDirect3DDevice8Impl_BeginScene,
2511 IDirect3DDevice8Impl_EndScene,
2512 IDirect3DDevice8Impl_Clear,
2513 IDirect3DDevice8Impl_SetTransform,
2514 IDirect3DDevice8Impl_GetTransform,
2515 IDirect3DDevice8Impl_MultiplyTransform,
2516 IDirect3DDevice8Impl_SetViewport,
2517 IDirect3DDevice8Impl_GetViewport,
2518 IDirect3DDevice8Impl_SetMaterial,
2519 IDirect3DDevice8Impl_GetMaterial,
2520 IDirect3DDevice8Impl_SetLight,
2521 IDirect3DDevice8Impl_GetLight,
2522 IDirect3DDevice8Impl_LightEnable,
2523 IDirect3DDevice8Impl_GetLightEnable,
2524 IDirect3DDevice8Impl_SetClipPlane,
2525 IDirect3DDevice8Impl_GetClipPlane,
2526 IDirect3DDevice8Impl_SetRenderState,
2527 IDirect3DDevice8Impl_GetRenderState,
2528 IDirect3DDevice8Impl_BeginStateBlock,
2529 IDirect3DDevice8Impl_EndStateBlock,
2530 IDirect3DDevice8Impl_ApplyStateBlock,
2531 IDirect3DDevice8Impl_CaptureStateBlock,
2532 IDirect3DDevice8Impl_DeleteStateBlock,
2533 IDirect3DDevice8Impl_CreateStateBlock,
2534 IDirect3DDevice8Impl_SetClipStatus,
2535 IDirect3DDevice8Impl_GetClipStatus,
2536 IDirect3DDevice8Impl_GetTexture,
2537 IDirect3DDevice8Impl_SetTexture,
2538 IDirect3DDevice8Impl_GetTextureStageState,
2539 IDirect3DDevice8Impl_SetTextureStageState,
2540 IDirect3DDevice8Impl_ValidateDevice,
2541 IDirect3DDevice8Impl_GetInfo,
2542 IDirect3DDevice8Impl_SetPaletteEntries,
2543 IDirect3DDevice8Impl_GetPaletteEntries,
2544 IDirect3DDevice8Impl_SetCurrentTexturePalette,
2545 IDirect3DDevice8Impl_GetCurrentTexturePalette,
2546 IDirect3DDevice8Impl_DrawPrimitive,
2547 IDirect3DDevice8Impl_DrawIndexedPrimitive,
2548 IDirect3DDevice8Impl_DrawPrimitiveUP,
2549 IDirect3DDevice8Impl_DrawIndexedPrimitiveUP,
2550 IDirect3DDevice8Impl_ProcessVertices,
2551 IDirect3DDevice8Impl_CreateVertexShader,
2552 IDirect3DDevice8Impl_SetVertexShader,
2553 IDirect3DDevice8Impl_GetVertexShader,
2554 IDirect3DDevice8Impl_DeleteVertexShader,
2555 IDirect3DDevice8Impl_SetVertexShaderConstant,
2556 IDirect3DDevice8Impl_GetVertexShaderConstant,
2557 IDirect3DDevice8Impl_GetVertexShaderDeclaration,
2558 IDirect3DDevice8Impl_GetVertexShaderFunction,
2559 IDirect3DDevice8Impl_SetStreamSource,
2560 IDirect3DDevice8Impl_GetStreamSource,
2561 IDirect3DDevice8Impl_SetIndices,
2562 IDirect3DDevice8Impl_GetIndices,
2563 IDirect3DDevice8Impl_CreatePixelShader,
2564 IDirect3DDevice8Impl_SetPixelShader,
2565 IDirect3DDevice8Impl_GetPixelShader,
2566 IDirect3DDevice8Impl_DeletePixelShader,
2567 IDirect3DDevice8Impl_SetPixelShaderConstant,
2568 IDirect3DDevice8Impl_GetPixelShaderConstant,
2569 IDirect3DDevice8Impl_GetPixelShaderFunction,
2570 IDirect3DDevice8Impl_DrawRectPatch,
2571 IDirect3DDevice8Impl_DrawTriPatch,
2572 IDirect3DDevice8Impl_DeletePatch
2575 /* IWineD3DDeviceParent IUnknown methods */
2577 static inline struct IDirect3DDevice8Impl *device_from_device_parent(IWineD3DDeviceParent *iface)
2579 return (struct IDirect3DDevice8Impl *)((char*)iface
2580 - FIELD_OFFSET(struct IDirect3DDevice8Impl, device_parent_vtbl));
2583 static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface, REFIID riid, void **object)
2585 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2586 return IDirect3DDevice8Impl_QueryInterface((IDirect3DDevice8 *)This, riid, object);
2589 static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
2591 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2592 return IDirect3DDevice8Impl_AddRef((IDirect3DDevice8 *)This);
2595 static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
2597 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2598 return IDirect3DDevice8Impl_Release((IDirect3DDevice8 *)This);
2601 /* IWineD3DDeviceParent methods */
2603 static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
2605 TRACE("iface %p, device %p\n", iface, device);
2608 static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
2609 IUnknown *superior, UINT width, UINT height, enum wined3d_format_id format, DWORD usage,
2610 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface)
2612 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2613 IDirect3DSurface8Impl *d3d_surface;
2614 BOOL lockable = TRUE;
2617 TRACE("iface %p, superior %p, width %u, height %u, format %#x, usage %#x,\n"
2618 "\tpool %#x, level %u, face %u, surface %p\n",
2619 iface, superior, width, height, format, usage, pool, level, face, surface);
2622 if (pool == WINED3DPOOL_DEFAULT && !(usage & WINED3DUSAGE_DYNAMIC)) lockable = FALSE;
2624 hr = IDirect3DDevice8Impl_CreateSurface((IDirect3DDevice8 *)This, width, height,
2625 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
2626 (IDirect3DSurface8 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
2629 ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
2633 *surface = d3d_surface->wineD3DSurface;
2634 IWineD3DSurface_AddRef(*surface);
2636 d3d_surface->container = superior;
2637 IUnknown_Release(d3d_surface->parentDevice);
2638 d3d_surface->parentDevice = NULL;
2640 IDirect3DSurface8_Release((IDirect3DSurface8 *)d3d_surface);
2641 d3d_surface->forwardReference = superior;
2646 static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
2647 IUnknown *superior, UINT width, UINT height, enum wined3d_format_id format,
2648 WINED3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality, BOOL lockable,
2649 IWineD3DSurface **surface)
2651 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2652 IDirect3DSurface8Impl *d3d_surface;
2655 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2656 "\tmultisample_quality %u, lockable %u, surface %p\n",
2657 iface, superior, width, height, format, multisample_type, multisample_quality, lockable, surface);
2659 hr = IDirect3DDevice8_CreateRenderTarget((IDirect3DDevice8 *)This, width, height,
2660 d3dformat_from_wined3dformat(format), multisample_type, lockable, (IDirect3DSurface8 **)&d3d_surface);
2663 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
2667 *surface = d3d_surface->wineD3DSurface;
2668 IWineD3DSurface_AddRef(*surface);
2670 d3d_surface->container = (IUnknown *)This;
2671 /* Implicit surfaces are created with an refcount of 0 */
2672 IUnknown_Release((IUnknown *)d3d_surface);
2677 static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
2678 UINT width, UINT height, enum wined3d_format_id format, WINED3DMULTISAMPLE_TYPE multisample_type,
2679 DWORD multisample_quality, BOOL discard, IWineD3DSurface **surface)
2681 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2682 IDirect3DSurface8Impl *d3d_surface;
2685 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2686 "\tmultisample_quality %u, discard %u, surface %p\n",
2687 iface, width, height, format, multisample_type, multisample_quality, discard, surface);
2689 hr = IDirect3DDevice8_CreateDepthStencilSurface((IDirect3DDevice8 *)This, width, height,
2690 d3dformat_from_wined3dformat(format), multisample_type, (IDirect3DSurface8 **)&d3d_surface);
2693 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
2697 *surface = d3d_surface->wineD3DSurface;
2698 IWineD3DSurface_AddRef(*surface);
2700 d3d_surface->container = (IUnknown *)This;
2701 /* Implicit surfaces are created with an refcount of 0 */
2702 IUnknown_Release((IUnknown *)d3d_surface);
2707 static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
2708 IUnknown *superior, UINT width, UINT height, UINT depth, enum wined3d_format_id format,
2709 WINED3DPOOL pool, DWORD usage, IWineD3DVolume **volume)
2711 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2712 IDirect3DVolume8Impl *object;
2715 TRACE("iface %p, superior %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
2716 iface, superior, width, height, depth, format, pool, usage, volume);
2718 /* Allocate the storage for the device */
2719 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2722 FIXME("Allocation of memory failed\n");
2724 return D3DERR_OUTOFVIDEOMEMORY;
2727 hr = volume_init(object, This, width, height, depth, usage, format, pool);
2730 WARN("Failed to initialize volume, hr %#x.\n", hr);
2731 HeapFree(GetProcessHeap(), 0, object);
2735 *volume = object->wineD3DVolume;
2736 IWineD3DVolume_AddRef(*volume);
2737 IDirect3DVolume8_Release((IDirect3DVolume8 *)object);
2739 object->container = superior;
2740 object->forwardReference = superior;
2742 TRACE("(%p) Created volume %p\n", iface, object);
2747 static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
2748 WINED3DPRESENT_PARAMETERS *present_parameters, IWineD3DSwapChain **swapchain)
2750 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2751 IDirect3DSwapChain8Impl *d3d_swapchain;
2752 D3DPRESENT_PARAMETERS local_parameters;
2755 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
2757 /* Copy the presentation parameters */
2758 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
2759 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
2760 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
2761 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
2762 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
2763 local_parameters.SwapEffect = present_parameters->SwapEffect;
2764 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
2765 local_parameters.Windowed = present_parameters->Windowed;
2766 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
2767 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
2768 local_parameters.Flags = present_parameters->Flags;
2769 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
2770 local_parameters.FullScreen_PresentationInterval = present_parameters->PresentationInterval;
2772 hr = IDirect3DDevice8_CreateAdditionalSwapChain((IDirect3DDevice8 *)This,
2773 &local_parameters, (IDirect3DSwapChain8 **)&d3d_swapchain);
2776 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
2781 *swapchain = d3d_swapchain->wineD3DSwapChain;
2782 IUnknown_Release(d3d_swapchain->parentDevice);
2783 d3d_swapchain->parentDevice = NULL;
2785 /* Copy back the presentation parameters */
2786 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
2787 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
2788 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
2789 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
2790 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
2791 present_parameters->SwapEffect = local_parameters.SwapEffect;
2792 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
2793 present_parameters->Windowed = local_parameters.Windowed;
2794 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
2795 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
2796 present_parameters->Flags = local_parameters.Flags;
2797 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
2798 present_parameters->PresentationInterval = local_parameters.FullScreen_PresentationInterval;
2803 static const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl =
2805 /* IUnknown methods */
2806 device_parent_QueryInterface,
2807 device_parent_AddRef,
2808 device_parent_Release,
2809 /* IWineD3DDeviceParent methods */
2810 device_parent_WineD3DDeviceCreated,
2811 device_parent_CreateSurface,
2812 device_parent_CreateRenderTarget,
2813 device_parent_CreateDepthStencilSurface,
2814 device_parent_CreateVolume,
2815 device_parent_CreateSwapChain,
2818 static void setup_fpu(void)
2820 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
2822 __asm__ volatile ("fnstcw %0" : "=m" (cw));
2823 cw = (cw & ~0xf3f) | 0x3f;
2824 __asm__ volatile ("fldcw %0" : : "m" (cw));
2826 FIXME("FPU setup not implemented for this platform.\n");
2830 HRESULT device_init(IDirect3DDevice8Impl *device, IWineD3D *wined3d, UINT adapter,
2831 D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters)
2833 WINED3DPRESENT_PARAMETERS wined3d_parameters;
2836 device->lpVtbl = &Direct3DDevice8_Vtbl;
2837 device->device_parent_vtbl = &d3d8_wined3d_device_parent_vtbl;
2839 device->handle_table.entries = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2840 D3D8_INITIAL_HANDLE_TABLE_SIZE * sizeof(*device->handle_table.entries));
2841 if (!device->handle_table.entries)
2843 ERR("Failed to allocate handle table memory.\n");
2844 return E_OUTOFMEMORY;
2846 device->handle_table.table_size = D3D8_INITIAL_HANDLE_TABLE_SIZE;
2848 if (!(flags & D3DCREATE_FPU_PRESERVE)) setup_fpu();
2850 wined3d_mutex_lock();
2851 hr = IWineD3D_CreateDevice(wined3d, adapter, device_type, focus_window, flags,
2852 (IWineD3DDeviceParent *)&device->device_parent_vtbl, &device->WineD3DDevice);
2855 WARN("Failed to create wined3d device, hr %#x.\n", hr);
2856 wined3d_mutex_unlock();
2857 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
2861 if (!parameters->Windowed)
2863 HWND device_window = parameters->hDeviceWindow;
2865 if (!focus_window) focus_window = device_window;
2866 if (FAILED(hr = IWineD3DDevice_AcquireFocusWindow(device->WineD3DDevice, focus_window)))
2868 ERR("Failed to acquire focus window, hr %#x.\n", hr);
2869 IWineD3DDevice_Release(device->WineD3DDevice);
2870 wined3d_mutex_unlock();
2871 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
2875 if (!device_window) device_window = focus_window;
2876 IWineD3DDevice_SetupFullscreenWindow(device->WineD3DDevice, device_window,
2877 parameters->BackBufferWidth,
2878 parameters->BackBufferHeight);
2881 if (flags & D3DCREATE_MULTITHREADED) IWineD3DDevice_SetMultithreaded(device->WineD3DDevice);
2883 wined3d_parameters.BackBufferWidth = parameters->BackBufferWidth;
2884 wined3d_parameters.BackBufferHeight = parameters->BackBufferHeight;
2885 wined3d_parameters.BackBufferFormat = wined3dformat_from_d3dformat(parameters->BackBufferFormat);
2886 wined3d_parameters.BackBufferCount = parameters->BackBufferCount;
2887 wined3d_parameters.MultiSampleType = parameters->MultiSampleType;
2888 wined3d_parameters.MultiSampleQuality = 0; /* d3d9 only */
2889 wined3d_parameters.SwapEffect = parameters->SwapEffect;
2890 wined3d_parameters.hDeviceWindow = parameters->hDeviceWindow;
2891 wined3d_parameters.Windowed = parameters->Windowed;
2892 wined3d_parameters.EnableAutoDepthStencil = parameters->EnableAutoDepthStencil;
2893 wined3d_parameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(parameters->AutoDepthStencilFormat);
2894 wined3d_parameters.Flags = parameters->Flags;
2895 wined3d_parameters.FullScreen_RefreshRateInHz = parameters->FullScreen_RefreshRateInHz;
2896 wined3d_parameters.PresentationInterval = parameters->FullScreen_PresentationInterval;
2897 wined3d_parameters.AutoRestoreDisplayMode = TRUE;
2899 hr = IWineD3DDevice_Init3D(device->WineD3DDevice, &wined3d_parameters);
2902 WARN("Failed to initialize 3D, hr %#x.\n", hr);
2903 IWineD3DDevice_ReleaseFocusWindow(device->WineD3DDevice);
2904 IWineD3DDevice_Release(device->WineD3DDevice);
2905 wined3d_mutex_unlock();
2906 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
2910 hr = IWineD3DDevice_SetRenderState(device->WineD3DDevice, WINED3DRS_POINTSIZE_MIN, 0);
2911 wined3d_mutex_unlock();
2914 ERR("Failed to set minimum pointsize, hr %#x.\n", hr);
2918 parameters->BackBufferWidth = wined3d_parameters.BackBufferWidth;
2919 parameters->BackBufferHeight = wined3d_parameters.BackBufferHeight;
2920 parameters->BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters.BackBufferFormat);
2921 parameters->BackBufferCount = wined3d_parameters.BackBufferCount;
2922 parameters->MultiSampleType = wined3d_parameters.MultiSampleType;
2923 parameters->SwapEffect = wined3d_parameters.SwapEffect;
2924 parameters->hDeviceWindow = wined3d_parameters.hDeviceWindow;
2925 parameters->Windowed = wined3d_parameters.Windowed;
2926 parameters->EnableAutoDepthStencil = wined3d_parameters.EnableAutoDepthStencil;
2927 parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(wined3d_parameters.AutoDepthStencilFormat);
2928 parameters->Flags = wined3d_parameters.Flags;
2929 parameters->FullScreen_RefreshRateInHz = wined3d_parameters.FullScreen_RefreshRateInHz;
2930 parameters->FullScreen_PresentationInterval = wined3d_parameters.PresentationInterval;
2932 device->declArraySize = 16;
2933 device->decls = HeapAlloc(GetProcessHeap(), 0, device->declArraySize * sizeof(*device->decls));
2936 ERR("Failed to allocate FVF vertex delcaration map memory.\n");
2944 wined3d_mutex_lock();
2945 IWineD3DDevice_Uninit3D(device->WineD3DDevice, D3D8CB_DestroySwapChain);
2946 IWineD3DDevice_ReleaseFocusWindow(device->WineD3DDevice);
2947 IWineD3DDevice_Release(device->WineD3DDevice);
2948 wined3d_mutex_unlock();
2949 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);