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(WINED3DFORMAT 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 WINED3DFORMAT %#x\n", format);
86 return D3DFMT_UNKNOWN;
90 WINED3DFORMAT 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 /* Use a free handle */
175 entry = t->free_entries;
176 if (entry->type != D3D8_HANDLE_FREE)
178 ERR("Handle %u(%p) is in the free list, but has type %#x.\n", (entry - t->entries), entry, entry->type);
179 return D3D8_INVALID_HANDLE;
181 t->free_entries = entry->object;
182 entry->object = object;
185 return entry - t->entries;
188 if (!(t->entry_count < t->table_size))
191 UINT new_size = t->table_size + (t->table_size >> 1);
192 struct d3d8_handle_entry *new_entries = HeapReAlloc(GetProcessHeap(),
193 0, t->entries, new_size * sizeof(*t->entries));
196 ERR("Failed to grow the handle table.\n");
197 return D3D8_INVALID_HANDLE;
199 t->entries = new_entries;
200 t->table_size = new_size;
203 entry = &t->entries[t->entry_count];
204 entry->object = object;
207 return t->entry_count++;
210 static void *d3d8_free_handle(struct d3d8_handle_table *t, DWORD handle, enum d3d8_handle_type type)
212 struct d3d8_handle_entry *entry;
215 if (handle == D3D8_INVALID_HANDLE || handle >= t->entry_count)
217 WARN("Invalid handle %u passed.\n", handle);
221 entry = &t->entries[handle];
222 if (entry->type != type)
224 WARN("Handle %u(%p) is not of type %#x.\n", handle, entry, type);
228 object = entry->object;
229 entry->object = t->free_entries;
230 entry->type = D3D8_HANDLE_FREE;
231 t->free_entries = entry;
236 static void *d3d8_get_object(struct d3d8_handle_table *t, DWORD handle, enum d3d8_handle_type type)
238 struct d3d8_handle_entry *entry;
240 if (handle == D3D8_INVALID_HANDLE || handle >= t->entry_count)
242 WARN("Invalid handle %u passed.\n", handle);
246 entry = &t->entries[handle];
247 if (entry->type != type)
249 WARN("Handle %u(%p) is not of type %#x.\n", handle, entry, type);
253 return entry->object;
256 static ULONG WINAPI D3D8CB_DestroySwapChain(IWineD3DSwapChain *swapchain)
260 TRACE("swapchain %p.\n", swapchain);
262 IWineD3DSwapChain_GetParent(swapchain, &parent);
263 IUnknown_Release(parent);
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_Release(This->WineD3DDevice);
328 HeapFree(GetProcessHeap(), 0, This->handle_table.entries);
329 HeapFree(GetProcessHeap(), 0, This);
331 wined3d_mutex_unlock();
336 /* IDirect3DDevice Interface follow: */
337 static HRESULT WINAPI IDirect3DDevice8Impl_TestCooperativeLevel(IDirect3DDevice8 *iface)
339 TRACE("iface %p.\n", iface);
344 static UINT WINAPI IDirect3DDevice8Impl_GetAvailableTextureMem(LPDIRECT3DDEVICE8 iface) {
345 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
348 TRACE("iface %p.\n", iface);
350 wined3d_mutex_lock();
351 hr = IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
352 wined3d_mutex_unlock();
357 static HRESULT WINAPI IDirect3DDevice8Impl_ResourceManagerDiscardBytes(LPDIRECT3DDEVICE8 iface, DWORD Bytes) {
358 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
361 TRACE("iface %p, byte_count %u.\n", iface, Bytes);
362 FIXME("Byte count ignored.\n");
364 wined3d_mutex_lock();
365 hr = IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
366 wined3d_mutex_unlock();
371 static HRESULT WINAPI IDirect3DDevice8Impl_GetDirect3D(LPDIRECT3DDEVICE8 iface, IDirect3D8** ppD3D8) {
372 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
376 TRACE("iface %p, d3d8 %p.\n", iface, ppD3D8);
378 if (NULL == ppD3D8) {
379 return D3DERR_INVALIDCALL;
382 wined3d_mutex_lock();
383 hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &pWineD3D);
384 if (hr == D3D_OK && pWineD3D != NULL)
386 IWineD3D_GetParent(pWineD3D,(IUnknown **)ppD3D8);
387 IWineD3D_Release(pWineD3D);
389 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
392 wined3d_mutex_unlock();
394 TRACE("(%p) returning %p\n",This , *ppD3D8);
399 static HRESULT WINAPI IDirect3DDevice8Impl_GetDeviceCaps(LPDIRECT3DDEVICE8 iface, D3DCAPS8* pCaps) {
400 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
401 HRESULT hrc = D3D_OK;
402 WINED3DCAPS *pWineCaps;
404 TRACE("iface %p, caps %p.\n", iface, pCaps);
407 return D3DERR_INVALIDCALL;
409 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
410 if(pWineCaps == NULL){
411 return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
414 wined3d_mutex_lock();
415 hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
416 wined3d_mutex_unlock();
418 fixup_caps(pWineCaps);
419 WINECAPSTOD3D8CAPS(pCaps, pWineCaps)
420 HeapFree(GetProcessHeap(), 0, pWineCaps);
422 TRACE("Returning %p %p\n", This, pCaps);
426 static HRESULT WINAPI IDirect3DDevice8Impl_GetDisplayMode(LPDIRECT3DDEVICE8 iface, D3DDISPLAYMODE* pMode) {
427 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
430 TRACE("iface %p, mode %p.\n", iface, pMode);
432 wined3d_mutex_lock();
433 hr = IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, 0, (WINED3DDISPLAYMODE *) pMode);
434 wined3d_mutex_unlock();
436 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
441 static HRESULT WINAPI IDirect3DDevice8Impl_GetCreationParameters(LPDIRECT3DDEVICE8 iface, D3DDEVICE_CREATION_PARAMETERS *pParameters) {
442 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
445 TRACE("iface %p, parameters %p.\n", iface, pParameters);
447 wined3d_mutex_lock();
448 hr = IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
449 wined3d_mutex_unlock();
454 static HRESULT WINAPI IDirect3DDevice8Impl_SetCursorProperties(LPDIRECT3DDEVICE8 iface, UINT XHotSpot, UINT YHotSpot, IDirect3DSurface8* pCursorBitmap) {
455 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
456 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl*)pCursorBitmap;
459 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
460 iface, XHotSpot, YHotSpot, pCursorBitmap);
463 WARN("No cursor bitmap, returning WINED3DERR_INVALIDCALL\n");
464 return WINED3DERR_INVALIDCALL;
467 wined3d_mutex_lock();
468 hr = IWineD3DDevice_SetCursorProperties(This->WineD3DDevice,XHotSpot,YHotSpot,pSurface->wineD3DSurface);
469 wined3d_mutex_unlock();
474 static void WINAPI IDirect3DDevice8Impl_SetCursorPosition(LPDIRECT3DDEVICE8 iface, UINT XScreenSpace, UINT YScreenSpace, DWORD Flags) {
475 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
477 TRACE("iface %p, x %u, y %u, flags %#x.\n",
478 iface, XScreenSpace, YScreenSpace, Flags);
480 wined3d_mutex_lock();
481 IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
482 wined3d_mutex_unlock();
485 static BOOL WINAPI IDirect3DDevice8Impl_ShowCursor(LPDIRECT3DDEVICE8 iface, BOOL bShow) {
486 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
489 TRACE("iface %p, show %#x.\n", iface, bShow);
491 wined3d_mutex_lock();
492 ret = IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
493 wined3d_mutex_unlock();
498 static HRESULT WINAPI IDirect3DDevice8Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain8** pSwapChain) {
499 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
500 IDirect3DSwapChain8Impl* object;
501 HRESULT hrc = D3D_OK;
502 WINED3DPRESENT_PARAMETERS localParameters;
504 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
505 iface, pPresentationParameters, pSwapChain);
507 /* Fix the back buffer count */
508 if(pPresentationParameters->BackBufferCount == 0) {
509 pPresentationParameters->BackBufferCount = 1;
512 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
513 if (NULL == object) {
514 FIXME("Allocation of memory failed\n");
516 return D3DERR_OUTOFVIDEOMEMORY;
519 object->lpVtbl = &Direct3DSwapChain8_Vtbl;
521 /* Allocate an associated WineD3DDevice object */
522 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
523 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
524 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
525 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
526 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
527 localParameters.MultiSampleQuality = 0; /* d3d9 only */
528 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
529 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
530 localParameters.Windowed = pPresentationParameters->Windowed;
531 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
532 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
533 localParameters.Flags = pPresentationParameters->Flags;
534 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
535 localParameters.PresentationInterval = pPresentationParameters->FullScreen_PresentationInterval;
536 localParameters.AutoRestoreDisplayMode = TRUE;
538 wined3d_mutex_lock();
539 hrc = IWineD3DDevice_CreateSwapChain(This->WineD3DDevice, &localParameters,
540 &object->wineD3DSwapChain, (IUnknown *)object, SURFACE_OPENGL);
541 wined3d_mutex_unlock();
543 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
544 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
545 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
546 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
547 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
548 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
549 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
550 pPresentationParameters->Windowed = localParameters.Windowed;
551 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
552 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
553 pPresentationParameters->Flags = localParameters.Flags;
554 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
555 pPresentationParameters->FullScreen_PresentationInterval = localParameters.PresentationInterval;
558 FIXME("(%p) call to IWineD3DDevice_CreateSwapChain failed\n", This);
559 HeapFree(GetProcessHeap(), 0 , object);
562 IUnknown_AddRef(iface);
563 object->parentDevice = iface;
564 *pSwapChain = (IDirect3DSwapChain8 *)object;
566 TRACE("(%p) returning %p\n", This, *pSwapChain);
570 static HRESULT WINAPI IDirect3DDevice8Impl_Reset(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
571 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
572 WINED3DPRESENT_PARAMETERS localParameters;
575 TRACE("iface %p, present_parameters %p.\n", iface, pPresentationParameters);
577 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
578 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
579 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
580 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
581 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
582 localParameters.MultiSampleQuality = 0; /* d3d9 only */
583 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
584 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
585 localParameters.Windowed = pPresentationParameters->Windowed;
586 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
587 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
588 localParameters.Flags = pPresentationParameters->Flags;
589 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
590 localParameters.PresentationInterval = pPresentationParameters->FullScreen_PresentationInterval;
591 localParameters.AutoRestoreDisplayMode = TRUE;
593 wined3d_mutex_lock();
594 hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
596 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, WINED3DRS_POINTSIZE_MIN, 0);
598 wined3d_mutex_unlock();
600 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
601 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
602 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
603 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
604 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
605 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
606 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
607 pPresentationParameters->Windowed = localParameters.Windowed;
608 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
609 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
610 pPresentationParameters->Flags = localParameters.Flags;
611 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
612 pPresentationParameters->FullScreen_PresentationInterval = localParameters.PresentationInterval;
617 static HRESULT WINAPI IDirect3DDevice8Impl_Present(LPDIRECT3DDEVICE8 iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion) {
618 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
621 TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
622 iface, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
624 wined3d_mutex_lock();
625 hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
626 wined3d_mutex_unlock();
631 static HRESULT WINAPI IDirect3DDevice8Impl_GetBackBuffer(LPDIRECT3DDEVICE8 iface, UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8** ppBackBuffer) {
632 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
633 IWineD3DSurface *retSurface = NULL;
636 TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
637 iface, BackBuffer, Type, ppBackBuffer);
639 wined3d_mutex_lock();
640 rc = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, 0, BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &retSurface);
641 if (rc == D3D_OK && NULL != retSurface && NULL != ppBackBuffer) {
642 IWineD3DSurface_GetParent(retSurface, (IUnknown **)ppBackBuffer);
643 IWineD3DSurface_Release(retSurface);
645 wined3d_mutex_unlock();
650 static HRESULT WINAPI IDirect3DDevice8Impl_GetRasterStatus(LPDIRECT3DDEVICE8 iface, D3DRASTER_STATUS* pRasterStatus) {
651 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
654 TRACE("iface %p, raster_status %p.\n", iface, pRasterStatus);
656 wined3d_mutex_lock();
657 hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, 0, (WINED3DRASTER_STATUS *) pRasterStatus);
658 wined3d_mutex_unlock();
663 static void WINAPI IDirect3DDevice8Impl_SetGammaRamp(LPDIRECT3DDEVICE8 iface, DWORD Flags, CONST D3DGAMMARAMP* pRamp) {
664 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
666 TRACE("iface %p, flags %#x, ramp %p.\n", iface, Flags, pRamp);
668 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
669 wined3d_mutex_lock();
670 IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, 0, Flags, (CONST WINED3DGAMMARAMP *) pRamp);
671 wined3d_mutex_unlock();
674 static void WINAPI IDirect3DDevice8Impl_GetGammaRamp(LPDIRECT3DDEVICE8 iface, D3DGAMMARAMP* pRamp) {
675 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
677 TRACE("iface %p, ramp %p.\n", iface, pRamp);
679 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
680 wined3d_mutex_lock();
681 IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, 0, (WINED3DGAMMARAMP *) pRamp);
682 wined3d_mutex_unlock();
685 static HRESULT WINAPI IDirect3DDevice8Impl_CreateTexture(IDirect3DDevice8 *iface,
686 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
687 D3DPOOL pool, IDirect3DTexture8 **texture)
689 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
690 IDirect3DTexture8Impl *object;
693 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
694 iface, width, height, levels, usage, format, pool, texture);
696 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
699 ERR("Failed to allocate texture memory.\n");
700 return D3DERR_OUTOFVIDEOMEMORY;
703 hr = texture_init(object, This, width, height, levels, usage, format, pool);
706 WARN("Failed to initialize texture, hr %#x.\n", hr);
707 HeapFree(GetProcessHeap(), 0, object);
711 TRACE("Created texture %p.\n", object);
712 *texture = (IDirect3DTexture8 *)object;
717 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVolumeTexture(IDirect3DDevice8 *iface,
718 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
719 D3DPOOL pool, IDirect3DVolumeTexture8 **texture)
721 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
722 IDirect3DVolumeTexture8Impl *object;
725 TRACE("iface %p, width %u, height %u, depth %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
726 iface, width, height, depth, levels, usage, format, pool, texture);
728 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
731 ERR("Failed to allocate volume texture memory.\n");
732 return D3DERR_OUTOFVIDEOMEMORY;
735 hr = volumetexture_init(object, This, width, height, depth, levels, usage, format, pool);
738 WARN("Failed to initialize volume texture, hr %#x.\n", hr);
739 HeapFree(GetProcessHeap(), 0, object);
743 TRACE("Created volume texture %p.\n", object);
744 *texture = (IDirect3DVolumeTexture8 *)object;
749 static HRESULT WINAPI IDirect3DDevice8Impl_CreateCubeTexture(IDirect3DDevice8 *iface, UINT edge_length,
750 UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool, IDirect3DCubeTexture8 **texture)
752 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
753 IDirect3DCubeTexture8Impl *object;
756 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
757 iface, edge_length, levels, usage, format, pool, texture);
759 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
762 ERR("Failed to allocate cube texture memory.\n");
763 return D3DERR_OUTOFVIDEOMEMORY;
766 hr = cubetexture_init(object, This, edge_length, levels, usage, format, pool);
769 WARN("Failed to initialize cube texture, hr %#x.\n", hr);
770 HeapFree(GetProcessHeap(), 0, object);
774 TRACE("Created cube texture %p.\n", object);
775 *texture = (IDirect3DCubeTexture8 *)object;
780 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexBuffer(IDirect3DDevice8 *iface, UINT size, DWORD usage,
781 DWORD fvf, D3DPOOL pool, IDirect3DVertexBuffer8 **buffer)
783 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
784 IDirect3DVertexBuffer8Impl *object;
787 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p.\n",
788 iface, size, usage, fvf, 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 = vertexbuffer_init(object, This, size, usage, fvf, pool);
800 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr);
801 HeapFree(GetProcessHeap(), 0, object);
805 TRACE("Created vertex buffer %p.\n", object);
806 *buffer = (IDirect3DVertexBuffer8 *)object;
811 static HRESULT WINAPI IDirect3DDevice8Impl_CreateIndexBuffer(IDirect3DDevice8 *iface, UINT size, DWORD usage,
812 D3DFORMAT format, D3DPOOL pool, IDirect3DIndexBuffer8 **buffer)
814 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
815 IDirect3DIndexBuffer8Impl *object;
818 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p.\n",
819 iface, size, usage, format, pool, buffer);
821 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
824 ERR("Failed to allocate buffer memory.\n");
825 return D3DERR_OUTOFVIDEOMEMORY;
828 hr = indexbuffer_init(object, This, size, usage, format, pool);
831 WARN("Failed to initialize index buffer, hr %#x.\n", hr);
832 HeapFree(GetProcessHeap(), 0, object);
836 TRACE("Created index buffer %p.\n", object);
837 *buffer = (IDirect3DIndexBuffer8 *)object;
842 static HRESULT IDirect3DDevice8Impl_CreateSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height,
843 D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IDirect3DSurface8 **ppSurface,
844 UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality)
846 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
847 IDirect3DSurface8Impl *object;
850 TRACE("iface %p, width %u, height %u, format %#x, lockable %#x, discard %#x, level %u, surface %p,\n"
851 "\tusage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
852 iface, Width, Height, Format, Lockable, Discard, Level, ppSurface,
853 Usage, Pool, MultiSample, MultisampleQuality);
855 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface8Impl));
858 FIXME("Failed to allocate surface memory.\n");
859 return D3DERR_OUTOFVIDEOMEMORY;
862 hr = surface_init(object, This, Width, Height, Format, Lockable, Discard,
863 Level, Usage, Pool, MultiSample, MultisampleQuality);
866 WARN("Failed to initialize surface, hr %#x.\n", hr);
867 HeapFree(GetProcessHeap(), 0, object);
871 TRACE("Created surface %p.\n", object);
872 *ppSurface = (IDirect3DSurface8 *)object;
877 static HRESULT WINAPI IDirect3DDevice8Impl_CreateRenderTarget(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, BOOL Lockable, IDirect3DSurface8** ppSurface) {
880 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, lockable %#x, surface %p.\n",
881 iface, Width, Height, Format, MultiSample, Lockable, ppSurface);
883 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, Lockable, FALSE /* Discard */,
884 0 /* Level */, ppSurface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, MultiSample, 0);
889 static HRESULT WINAPI IDirect3DDevice8Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, IDirect3DSurface8** ppSurface) {
892 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, surface %p.\n",
893 iface, Width, Height, Format, MultiSample, ppSurface);
895 /* TODO: Verify that Discard is false */
896 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE,
897 0 /* Level */, ppSurface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, MultiSample, 0);
902 /* IDirect3DDevice8Impl::CreateImageSurface returns surface with pool type SYSTEMMEM */
903 static HRESULT WINAPI IDirect3DDevice8Impl_CreateImageSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, IDirect3DSurface8** ppSurface) {
906 TRACE("iface %p, width %u, height %u, format %#x, surface %p.\n",
907 iface, Width, Height, Format, ppSurface);
909 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE /* Discard */,
910 0 /* Level */, ppSurface, 0 /* Usage (undefined/none) */, D3DPOOL_SYSTEMMEM, D3DMULTISAMPLE_NONE,
911 0 /* MultisampleQuality */);
916 static HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8 *pSourceSurface, CONST RECT *pSourceRects, UINT cRects, IDirect3DSurface8 *pDestinationSurface, CONST POINT *pDestPoints) {
917 IDirect3DSurface8Impl *Source = (IDirect3DSurface8Impl *) pSourceSurface;
918 IDirect3DSurface8Impl *Dest = (IDirect3DSurface8Impl *) pDestinationSurface;
920 HRESULT hr = WINED3D_OK;
921 WINED3DFORMAT srcFormat, destFormat;
922 WINED3DSURFACE_DESC winedesc;
924 TRACE("iface %p, src_surface %p, src_rects %p, rect_count %u, dst_surface %p, dst_points %p.\n",
925 iface, pSourceSurface, pSourceRects, cRects, pDestinationSurface, pDestPoints);
927 /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the
928 * destination texture is in WINED3DPOOL_DEFAULT. */
930 wined3d_mutex_lock();
931 IWineD3DSurface_GetDesc(Source->wineD3DSurface, &winedesc);
932 srcFormat = winedesc.format;
934 IWineD3DSurface_GetDesc(Dest->wineD3DSurface, &winedesc);
935 destFormat = winedesc.format;
937 /* Check that the source and destination formats match */
938 if (srcFormat != destFormat && WINED3DFMT_UNKNOWN != destFormat) {
939 WARN("(%p) source %p format must match the dest %p format, returning WINED3DERR_INVALIDCALL\n", iface, pSourceSurface, pDestinationSurface);
940 wined3d_mutex_unlock();
941 return WINED3DERR_INVALIDCALL;
942 } else if (WINED3DFMT_UNKNOWN == destFormat) {
943 TRACE("(%p) : Converting destination surface from WINED3DFMT_UNKNOWN to the source format\n", iface);
944 IWineD3DSurface_SetFormat(Dest->wineD3DSurface, srcFormat);
947 /* Quick if complete copy ... */
948 if (cRects == 0 && pSourceRects == NULL && pDestPoints == NULL) {
949 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
952 /* Copy rect by rect */
953 if (NULL != pSourceRects && NULL != pDestPoints) {
954 for (i = 0; i < cRects; ++i) {
955 IWineD3DSurface_BltFast(Dest->wineD3DSurface, pDestPoints[i].x, pDestPoints[i].y, Source->wineD3DSurface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
958 for (i = 0; i < cRects; ++i) {
959 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
963 wined3d_mutex_unlock();
968 static HRESULT WINAPI IDirect3DDevice8Impl_UpdateTexture(LPDIRECT3DDEVICE8 iface, IDirect3DBaseTexture8* pSourceTexture, IDirect3DBaseTexture8* pDestinationTexture) {
969 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
972 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface, pSourceTexture, pDestinationTexture);
974 wined3d_mutex_lock();
975 hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice, ((IDirect3DBaseTexture8Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture8Impl *)pDestinationTexture)->wineD3DBaseTexture);
976 wined3d_mutex_unlock();
981 static HRESULT WINAPI IDirect3DDevice8Impl_GetFrontBuffer(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pDestSurface) {
982 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
983 IDirect3DSurface8Impl *destSurface = (IDirect3DSurface8Impl *)pDestSurface;
986 TRACE("iface %p, dst_surface %p.\n", iface, pDestSurface);
988 if (pDestSurface == NULL) {
989 WARN("(%p) : Caller passed NULL as pDestSurface returning D3DERR_INVALIDCALL\n", This);
990 return D3DERR_INVALIDCALL;
993 wined3d_mutex_lock();
994 hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, 0, destSurface->wineD3DSurface);
995 wined3d_mutex_unlock();
1000 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pRenderTarget, IDirect3DSurface8* pNewZStencil) {
1001 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1002 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl *)pRenderTarget;
1003 IDirect3DSurface8Impl *pZSurface = (IDirect3DSurface8Impl *)pNewZStencil;
1004 IWineD3DSurface *original_ds = NULL;
1007 TRACE("iface %p, render_target %p, depth_stencil %p.\n", iface, pRenderTarget, pNewZStencil);
1009 wined3d_mutex_lock();
1011 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice, &original_ds);
1012 if (hr == WINED3D_OK || hr == WINED3DERR_NOTFOUND)
1014 hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, pZSurface ? pZSurface->wineD3DSurface : NULL);
1015 if (SUCCEEDED(hr) && pSurface)
1016 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, 0, pSurface->wineD3DSurface, TRUE);
1017 if (FAILED(hr)) IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, original_ds);
1019 if (original_ds) IWineD3DSurface_Release(original_ds);
1021 wined3d_mutex_unlock();
1026 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppRenderTarget) {
1027 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1028 HRESULT hr = D3D_OK;
1029 IWineD3DSurface *pRenderTarget;
1031 TRACE("iface %p, render_target %p.\n", iface, ppRenderTarget);
1033 if (ppRenderTarget == NULL) {
1034 return D3DERR_INVALIDCALL;
1037 wined3d_mutex_lock();
1038 hr = IWineD3DDevice_GetRenderTarget(This->WineD3DDevice, 0, &pRenderTarget);
1040 if (hr == D3D_OK && pRenderTarget != NULL) {
1041 IWineD3DSurface_GetParent(pRenderTarget,(IUnknown**)ppRenderTarget);
1042 IWineD3DSurface_Release(pRenderTarget);
1044 FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
1045 *ppRenderTarget = NULL;
1047 wined3d_mutex_unlock();
1052 static HRESULT WINAPI IDirect3DDevice8Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppZStencilSurface) {
1053 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1054 HRESULT hr = D3D_OK;
1055 IWineD3DSurface *pZStencilSurface;
1057 TRACE("iface %p, depth_stencil %p.\n", iface, ppZStencilSurface);
1059 if(ppZStencilSurface == NULL){
1060 return D3DERR_INVALIDCALL;
1063 wined3d_mutex_lock();
1064 hr=IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
1065 if (hr == WINED3D_OK) {
1066 IWineD3DSurface_GetParent(pZStencilSurface,(IUnknown**)ppZStencilSurface);
1067 IWineD3DSurface_Release(pZStencilSurface);
1069 if (hr != WINED3DERR_NOTFOUND)
1070 FIXME("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
1071 *ppZStencilSurface = NULL;
1073 wined3d_mutex_unlock();
1078 static HRESULT WINAPI IDirect3DDevice8Impl_BeginScene(LPDIRECT3DDEVICE8 iface) {
1079 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1082 TRACE("iface %p.\n", iface);
1084 wined3d_mutex_lock();
1085 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
1086 wined3d_mutex_unlock();
1091 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice8Impl_EndScene(LPDIRECT3DDEVICE8 iface) {
1092 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1095 TRACE("iface %p.\n", iface);
1097 wined3d_mutex_lock();
1098 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
1099 wined3d_mutex_unlock();
1104 static HRESULT WINAPI IDirect3DDevice8Impl_Clear(LPDIRECT3DDEVICE8 iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
1105 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1108 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1109 iface, Count, pRects, Flags, Color, Z, Stencil);
1111 /* Note: D3DRECT is compatible with WINED3DRECT */
1112 wined3d_mutex_lock();
1113 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (CONST WINED3DRECT*) pRects, Flags, Color, Z, Stencil);
1114 wined3d_mutex_unlock();
1119 static HRESULT WINAPI IDirect3DDevice8Impl_SetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
1120 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1123 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, lpMatrix);
1125 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1126 wined3d_mutex_lock();
1127 hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
1128 wined3d_mutex_unlock();
1133 static HRESULT WINAPI IDirect3DDevice8Impl_GetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State,D3DMATRIX* pMatrix) {
1134 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1137 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1139 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1140 wined3d_mutex_lock();
1141 hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
1142 wined3d_mutex_unlock();
1147 static HRESULT WINAPI IDirect3DDevice8Impl_MultiplyTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
1148 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1151 TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
1153 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1154 wined3d_mutex_lock();
1155 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
1156 wined3d_mutex_unlock();
1161 static HRESULT WINAPI IDirect3DDevice8Impl_SetViewport(LPDIRECT3DDEVICE8 iface, CONST D3DVIEWPORT8* pViewport) {
1162 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1165 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1167 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1168 wined3d_mutex_lock();
1169 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
1170 wined3d_mutex_unlock();
1175 static HRESULT WINAPI IDirect3DDevice8Impl_GetViewport(LPDIRECT3DDEVICE8 iface, D3DVIEWPORT8* pViewport) {
1176 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1179 TRACE("iface %p, viewport %p.\n", iface, pViewport);
1181 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1182 wined3d_mutex_lock();
1183 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
1184 wined3d_mutex_unlock();
1189 static HRESULT WINAPI IDirect3DDevice8Impl_SetMaterial(LPDIRECT3DDEVICE8 iface, CONST D3DMATERIAL8* pMaterial) {
1190 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1193 TRACE("iface %p, material %p.\n", iface, pMaterial);
1195 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1196 wined3d_mutex_lock();
1197 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
1198 wined3d_mutex_unlock();
1203 static HRESULT WINAPI IDirect3DDevice8Impl_GetMaterial(LPDIRECT3DDEVICE8 iface, D3DMATERIAL8* pMaterial) {
1204 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1207 TRACE("iface %p, material %p.\n", iface, pMaterial);
1209 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1210 wined3d_mutex_lock();
1211 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
1212 wined3d_mutex_unlock();
1217 static HRESULT WINAPI IDirect3DDevice8Impl_SetLight(LPDIRECT3DDEVICE8 iface, DWORD Index, CONST D3DLIGHT8* pLight) {
1218 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1221 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1223 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1224 wined3d_mutex_lock();
1225 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
1226 wined3d_mutex_unlock();
1231 static HRESULT WINAPI IDirect3DDevice8Impl_GetLight(LPDIRECT3DDEVICE8 iface, DWORD Index,D3DLIGHT8* pLight) {
1232 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1235 TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
1237 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1238 wined3d_mutex_lock();
1239 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1240 wined3d_mutex_unlock();
1245 static HRESULT WINAPI IDirect3DDevice8Impl_LightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL Enable) {
1246 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1249 TRACE("iface %p, index %u, enable %#x.\n", iface, Index, Enable);
1251 wined3d_mutex_lock();
1252 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1253 wined3d_mutex_unlock();
1258 static HRESULT WINAPI IDirect3DDevice8Impl_GetLightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL* pEnable) {
1259 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1262 TRACE("iface %p, index %u, enable %p.\n", iface, Index, pEnable);
1264 wined3d_mutex_lock();
1265 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1266 wined3d_mutex_unlock();
1271 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,CONST float* pPlane) {
1272 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1275 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1277 wined3d_mutex_lock();
1278 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1279 wined3d_mutex_unlock();
1284 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,float* pPlane) {
1285 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1288 TRACE("iface %p, index %u, plane %p.\n", iface, Index, pPlane);
1290 wined3d_mutex_lock();
1291 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1292 wined3d_mutex_unlock();
1297 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD Value) {
1298 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1301 TRACE("iface %p, state %#x, value %#x.\n", iface, State, Value);
1303 wined3d_mutex_lock();
1304 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1305 wined3d_mutex_unlock();
1310 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD* pValue) {
1311 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1314 TRACE("iface %p, state %#x, value %p.\n", iface, State, pValue);
1316 wined3d_mutex_lock();
1317 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1318 wined3d_mutex_unlock();
1323 static HRESULT WINAPI IDirect3DDevice8Impl_BeginStateBlock(LPDIRECT3DDEVICE8 iface) {
1324 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1327 TRACE("iface %p.\n", iface);
1329 wined3d_mutex_lock();
1330 hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
1331 wined3d_mutex_unlock();
1336 static HRESULT WINAPI IDirect3DDevice8Impl_EndStateBlock(LPDIRECT3DDEVICE8 iface, DWORD* pToken) {
1337 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1338 IWineD3DStateBlock *stateblock;
1341 TRACE("iface %p, token %p.\n", iface, pToken);
1343 /* Tell wineD3D to endstateblock before anything else (in case we run out
1344 * of memory later and cause locking problems)
1346 wined3d_mutex_lock();
1347 hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice , &stateblock);
1349 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
1350 wined3d_mutex_unlock();
1354 *pToken = d3d8_allocate_handle(&This->handle_table, stateblock, D3D8_HANDLE_SB);
1355 wined3d_mutex_unlock();
1357 if (*pToken == D3D8_INVALID_HANDLE)
1359 ERR("Failed to create a handle\n");
1360 wined3d_mutex_lock();
1361 IWineD3DStateBlock_Release(stateblock);
1362 wined3d_mutex_unlock();
1367 TRACE("Returning %#x (%p).\n", *pToken, stateblock);
1372 static HRESULT WINAPI IDirect3DDevice8Impl_ApplyStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1373 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1374 IWineD3DStateBlock *stateblock;
1377 TRACE("iface %p, token %#x.\n", iface, Token);
1379 wined3d_mutex_lock();
1380 stateblock = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1383 WARN("Invalid handle (%#x) passed.\n", Token);
1384 wined3d_mutex_unlock();
1385 return D3DERR_INVALIDCALL;
1387 hr = IWineD3DStateBlock_Apply(stateblock);
1388 wined3d_mutex_unlock();
1393 static HRESULT WINAPI IDirect3DDevice8Impl_CaptureStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1394 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1395 IWineD3DStateBlock *stateblock;
1398 TRACE("iface %p, token %#x.\n", iface, Token);
1400 wined3d_mutex_lock();
1401 stateblock = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1404 WARN("Invalid handle (%#x) passed.\n", Token);
1405 wined3d_mutex_unlock();
1406 return D3DERR_INVALIDCALL;
1408 hr = IWineD3DStateBlock_Capture(stateblock);
1409 wined3d_mutex_unlock();
1414 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1415 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1416 IWineD3DStateBlock *stateblock;
1418 TRACE("iface %p, token %#x.\n", iface, Token);
1420 wined3d_mutex_lock();
1421 stateblock = d3d8_free_handle(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1425 WARN("Invalid handle (%#x) passed.\n", Token);
1426 wined3d_mutex_unlock();
1427 return D3DERR_INVALIDCALL;
1430 if (IWineD3DStateBlock_Release((IUnknown *)stateblock))
1432 ERR("Stateblock %p has references left, this shouldn't happen.\n", stateblock);
1434 wined3d_mutex_unlock();
1439 static HRESULT WINAPI IDirect3DDevice8Impl_CreateStateBlock(IDirect3DDevice8 *iface,
1440 D3DSTATEBLOCKTYPE Type, DWORD *handle)
1442 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1443 IWineD3DStateBlock *stateblock;
1446 TRACE("iface %p, type %#x, handle %p.\n", iface, Type, handle);
1448 if (Type != D3DSBT_ALL
1449 && Type != D3DSBT_PIXELSTATE
1450 && Type != D3DSBT_VERTEXSTATE)
1452 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1453 return D3DERR_INVALIDCALL;
1456 wined3d_mutex_lock();
1457 hr = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type,
1461 wined3d_mutex_unlock();
1462 ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr);
1466 *handle = d3d8_allocate_handle(&This->handle_table, stateblock, D3D8_HANDLE_SB);
1467 wined3d_mutex_unlock();
1469 if (*handle == D3D8_INVALID_HANDLE)
1471 ERR("Failed to allocate a handle.\n");
1472 wined3d_mutex_lock();
1473 IWineD3DStateBlock_Release(stateblock);
1474 wined3d_mutex_unlock();
1479 TRACE("Returning %#x (%p).\n", *handle, stateblock);
1484 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipStatus(LPDIRECT3DDEVICE8 iface, CONST D3DCLIPSTATUS8* pClipStatus) {
1485 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1488 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1489 /* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
1491 wined3d_mutex_lock();
1492 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1493 wined3d_mutex_unlock();
1498 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipStatus(LPDIRECT3DDEVICE8 iface, D3DCLIPSTATUS8* pClipStatus) {
1499 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1502 TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
1504 wined3d_mutex_lock();
1505 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1506 wined3d_mutex_unlock();
1511 static HRESULT WINAPI IDirect3DDevice8Impl_GetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage,IDirect3DBaseTexture8** ppTexture) {
1512 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1513 IWineD3DBaseTexture *retTexture;
1516 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, ppTexture);
1518 if(ppTexture == NULL){
1519 return D3DERR_INVALIDCALL;
1522 wined3d_mutex_lock();
1523 hr = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
1526 WARN("Failed to get texture for stage %u, hr %#x.\n", Stage, hr);
1527 wined3d_mutex_unlock();
1534 IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
1535 IWineD3DBaseTexture_Release(retTexture);
1541 wined3d_mutex_unlock();
1546 static HRESULT WINAPI IDirect3DDevice8Impl_SetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage, IDirect3DBaseTexture8* pTexture) {
1547 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1550 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, pTexture);
1552 wined3d_mutex_lock();
1553 hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
1554 pTexture==NULL ? NULL : ((IDirect3DBaseTexture8Impl *)pTexture)->wineD3DBaseTexture);
1555 wined3d_mutex_unlock();
1560 static const struct tss_lookup
1567 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 0, unused */
1568 {FALSE, WINED3DTSS_COLOROP}, /* 1, D3DTSS_COLOROP */
1569 {FALSE, WINED3DTSS_COLORARG1}, /* 2, D3DTSS_COLORARG1 */
1570 {FALSE, WINED3DTSS_COLORARG2}, /* 3, D3DTSS_COLORARG2 */
1571 {FALSE, WINED3DTSS_ALPHAOP}, /* 4, D3DTSS_ALPHAOP */
1572 {FALSE, WINED3DTSS_ALPHAARG1}, /* 5, D3DTSS_ALPHAARG1 */
1573 {FALSE, WINED3DTSS_ALPHAARG2}, /* 6, D3DTSS_ALPHAARG2 */
1574 {FALSE, WINED3DTSS_BUMPENVMAT00}, /* 7, D3DTSS_BUMPENVMAT00 */
1575 {FALSE, WINED3DTSS_BUMPENVMAT01}, /* 8, D3DTSS_BUMPENVMAT01 */
1576 {FALSE, WINED3DTSS_BUMPENVMAT10}, /* 9, D3DTSS_BUMPENVMAT10 */
1577 {FALSE, WINED3DTSS_BUMPENVMAT11}, /* 10, D3DTSS_BUMPENVMAT11 */
1578 {FALSE, WINED3DTSS_TEXCOORDINDEX}, /* 11, D3DTSS_TEXCOORDINDEX */
1579 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 12, unused */
1580 {TRUE, WINED3DSAMP_ADDRESSU}, /* 13, D3DTSS_ADDRESSU */
1581 {TRUE, WINED3DSAMP_ADDRESSV}, /* 14, D3DTSS_ADDRESSV */
1582 {TRUE, WINED3DSAMP_BORDERCOLOR}, /* 15, D3DTSS_BORDERCOLOR */
1583 {TRUE, WINED3DSAMP_MAGFILTER}, /* 16, D3DTSS_MAGFILTER */
1584 {TRUE, WINED3DSAMP_MINFILTER}, /* 17, D3DTSS_MINFILTER */
1585 {TRUE, WINED3DSAMP_MIPFILTER}, /* 18, D3DTSS_MIPFILTER */
1586 {TRUE, WINED3DSAMP_MIPMAPLODBIAS}, /* 19, D3DTSS_MIPMAPLODBIAS */
1587 {TRUE, WINED3DSAMP_MAXMIPLEVEL}, /* 20, D3DTSS_MAXMIPLEVEL */
1588 {TRUE, WINED3DSAMP_MAXANISOTROPY}, /* 21, D3DTSS_MAXANISOTROPY */
1589 {FALSE, WINED3DTSS_BUMPENVLSCALE}, /* 22, D3DTSS_BUMPENVLSCALE */
1590 {FALSE, WINED3DTSS_BUMPENVLOFFSET}, /* 23, D3DTSS_BUMPENVLOFFSET */
1591 {FALSE, WINED3DTSS_TEXTURETRANSFORMFLAGS}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1592 {TRUE, WINED3DSAMP_ADDRESSW}, /* 25, D3DTSS_ADDRESSW */
1593 {FALSE, WINED3DTSS_COLORARG0}, /* 26, D3DTSS_COLORARG0 */
1594 {FALSE, WINED3DTSS_ALPHAARG0}, /* 27, D3DTSS_ALPHAARG0 */
1595 {FALSE, WINED3DTSS_RESULTARG}, /* 28, D3DTSS_RESULTARG */
1598 static HRESULT WINAPI IDirect3DDevice8Impl_GetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD* pValue) {
1599 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1600 const struct tss_lookup *l = &tss_lookup[Type];
1603 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface, Stage, Type, pValue);
1605 wined3d_mutex_lock();
1606 if (l->sampler_state) hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Stage, l->state, pValue);
1607 else hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, l->state, pValue);
1608 wined3d_mutex_unlock();
1613 static HRESULT WINAPI IDirect3DDevice8Impl_SetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
1614 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1615 const struct tss_lookup *l = &tss_lookup[Type];
1618 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface, Stage, Type, Value);
1620 wined3d_mutex_lock();
1621 if (l->sampler_state) hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Stage, l->state, Value);
1622 else hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, l->state, Value);
1623 wined3d_mutex_unlock();
1628 static HRESULT WINAPI IDirect3DDevice8Impl_ValidateDevice(LPDIRECT3DDEVICE8 iface, DWORD* pNumPasses) {
1629 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1632 TRACE("iface %p, pass_count %p.\n", iface, pNumPasses);
1634 wined3d_mutex_lock();
1635 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1636 wined3d_mutex_unlock();
1641 static HRESULT WINAPI IDirect3DDevice8Impl_GetInfo(IDirect3DDevice8 *iface,
1642 DWORD info_id, void *info, DWORD info_size)
1644 FIXME("iface %p, info_id %#x, info %p, info_size %u stub!\n", iface, info_id, info, info_size);
1649 static HRESULT WINAPI IDirect3DDevice8Impl_SetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, CONST PALETTEENTRY* pEntries) {
1650 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1653 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1655 wined3d_mutex_lock();
1656 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1657 wined3d_mutex_unlock();
1662 static HRESULT WINAPI IDirect3DDevice8Impl_GetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
1663 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1666 TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
1668 wined3d_mutex_lock();
1669 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1670 wined3d_mutex_unlock();
1675 static HRESULT WINAPI IDirect3DDevice8Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber) {
1676 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1679 TRACE("iface %p, palette_idx %u.\n", iface, PaletteNumber);
1681 wined3d_mutex_lock();
1682 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1683 wined3d_mutex_unlock();
1688 static HRESULT WINAPI IDirect3DDevice8Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT *PaletteNumber) {
1689 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1692 TRACE("iface %p, palette_idx %p.\n", iface, PaletteNumber);
1694 wined3d_mutex_lock();
1695 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1696 wined3d_mutex_unlock();
1701 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitive(IDirect3DDevice8 *iface, D3DPRIMITIVETYPE PrimitiveType,
1702 UINT StartVertex, UINT PrimitiveCount)
1704 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1707 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1708 iface, PrimitiveType, StartVertex, PrimitiveCount);
1710 wined3d_mutex_lock();
1711 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1712 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
1713 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
1714 wined3d_mutex_unlock();
1719 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,
1720 UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount) {
1721 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1724 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, start_idx %u, primitive_count %u.\n",
1725 iface, PrimitiveType, MinVertexIndex, NumVertices, startIndex, primCount);
1727 wined3d_mutex_lock();
1728 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1729 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, startIndex,
1730 vertex_count_from_primitive_count(PrimitiveType, primCount));
1731 wined3d_mutex_unlock();
1736 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT PrimitiveCount,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride) {
1737 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1740 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
1741 iface, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
1743 wined3d_mutex_lock();
1744 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1745 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
1746 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
1747 pVertexStreamZeroData, VertexStreamZeroStride);
1748 wined3d_mutex_unlock();
1753 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,
1754 UINT NumVertexIndices,UINT PrimitiveCount,CONST void* pIndexData,
1755 D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,
1756 UINT VertexStreamZeroStride) {
1757 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1760 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
1761 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
1762 iface, PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount,
1763 pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
1765 wined3d_mutex_lock();
1766 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1767 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice,
1768 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
1769 wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
1770 wined3d_mutex_unlock();
1775 static HRESULT WINAPI IDirect3DDevice8Impl_ProcessVertices(LPDIRECT3DDEVICE8 iface, UINT SrcStartIndex,UINT DestIndex,UINT VertexCount,IDirect3DVertexBuffer8* pDestBuffer,DWORD Flags) {
1776 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1778 IDirect3DVertexBuffer8Impl *dest = (IDirect3DVertexBuffer8Impl *) pDestBuffer;
1780 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, flags %#x.\n",
1781 iface, SrcStartIndex, DestIndex, VertexCount, pDestBuffer, Flags);
1783 wined3d_mutex_lock();
1784 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, NULL, Flags, dest->fvf);
1785 wined3d_mutex_unlock();
1790 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(IDirect3DDevice8 *iface,
1791 const DWORD *declaration, const DWORD *byte_code, DWORD *shader, DWORD usage)
1793 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1794 IDirect3DVertexShader8Impl *object;
1795 DWORD shader_handle;
1799 TRACE("iface %p, declaration %p, byte_code %p, shader %p, usage %#x.\n",
1800 iface, declaration, byte_code, shader, usage);
1802 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1805 ERR("Failed to allocate vertex shader memory.\n");
1807 return E_OUTOFMEMORY;
1810 wined3d_mutex_lock();
1811 handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_VS);
1812 wined3d_mutex_unlock();
1813 if (handle == D3D8_INVALID_HANDLE)
1815 ERR("Failed to allocate vertex shader handle.\n");
1816 HeapFree(GetProcessHeap(), 0, object);
1818 return E_OUTOFMEMORY;
1821 shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
1823 hr = vertexshader_init(object, This, declaration, byte_code, shader_handle, usage);
1826 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
1827 wined3d_mutex_lock();
1828 d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_VS);
1829 wined3d_mutex_unlock();
1830 HeapFree(GetProcessHeap(), 0, object);
1835 TRACE("Created vertex shader %p (handle %#x).\n", object, shader_handle);
1836 *shader = shader_handle;
1841 static IDirect3DVertexDeclaration8Impl *IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl *This, DWORD fvf)
1843 IDirect3DVertexDeclaration8Impl *d3d8_declaration;
1845 int p, low, high; /* deliberately signed */
1846 struct FvfToDecl *convertedDecls = This->decls;
1848 TRACE("Searching for declaration for fvf %08x... ", fvf);
1851 high = This->numConvertedDecls - 1;
1852 while(low <= high) {
1853 p = (low + high) >> 1;
1855 if(convertedDecls[p].fvf == fvf) {
1856 TRACE("found %p\n", convertedDecls[p].decl);
1857 return (IDirect3DVertexDeclaration8Impl *)convertedDecls[p].decl;
1858 } else if(convertedDecls[p].fvf < fvf) {
1864 TRACE("not found. Creating and inserting at position %d.\n", low);
1866 d3d8_declaration = HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration));
1867 if (!d3d8_declaration)
1869 ERR("Memory allocation failed.\n");
1873 hr = vertexdeclaration_init_fvf(d3d8_declaration, This, fvf);
1876 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
1877 HeapFree(GetProcessHeap(), 0, d3d8_declaration);
1881 if(This->declArraySize == This->numConvertedDecls) {
1882 int grow = This->declArraySize / 2;
1883 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
1884 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
1885 if(!convertedDecls) {
1886 /* This will destroy it */
1887 IDirect3DVertexDeclaration8_Release((IDirect3DVertexDeclaration8 *)d3d8_declaration);
1890 This->decls = convertedDecls;
1891 This->declArraySize += grow;
1894 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(convertedDecls[0]) * (This->numConvertedDecls - low));
1895 convertedDecls[low].decl = (IDirect3DVertexDeclaration8 *)d3d8_declaration;
1896 convertedDecls[low].fvf = fvf;
1897 This->numConvertedDecls++;
1899 TRACE("Returning %p. %u decls in array\n", d3d8_declaration, This->numConvertedDecls);
1900 return d3d8_declaration;
1903 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1904 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1905 IDirect3DVertexShader8Impl *shader;
1908 TRACE("iface %p, shader %#x.\n", iface, pShader);
1910 if (VS_HIGHESTFIXEDFXF >= pShader) {
1911 TRACE("Setting FVF, %#x\n", pShader);
1913 wined3d_mutex_lock();
1914 IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
1915 IDirect3DDevice8Impl_FindDecl(This, pShader)->wined3d_vertex_declaration);
1916 IWineD3DDevice_SetVertexShader(This->WineD3DDevice, NULL);
1917 wined3d_mutex_unlock();
1922 TRACE("Setting shader\n");
1924 wined3d_mutex_lock();
1925 shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
1928 WARN("Invalid handle (%#x) passed.\n", pShader);
1929 wined3d_mutex_unlock();
1931 return D3DERR_INVALIDCALL;
1934 hr = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
1935 ((IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration)->wined3d_vertex_declaration);
1936 if (SUCCEEDED(hr)) hr = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, shader->wineD3DVertexShader);
1937 wined3d_mutex_unlock();
1939 TRACE("Returning hr %#x\n", hr);
1944 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
1945 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1946 IWineD3DVertexDeclaration *wined3d_declaration;
1947 IDirect3DVertexDeclaration8 *d3d8_declaration;
1950 TRACE("iface %p, shader %p.\n", iface, ppShader);
1952 wined3d_mutex_lock();
1953 hrc = IWineD3DDevice_GetVertexDeclaration(This->WineD3DDevice, &wined3d_declaration);
1956 wined3d_mutex_unlock();
1957 WARN("(%p) : Call to IWineD3DDevice_GetVertexDeclaration failed %#x (device %p)\n",
1958 This, hrc, This->WineD3DDevice);
1962 if (!wined3d_declaration)
1964 wined3d_mutex_unlock();
1969 hrc = IWineD3DVertexDeclaration_GetParent(wined3d_declaration, (IUnknown **)&d3d8_declaration);
1970 IWineD3DVertexDeclaration_Release(wined3d_declaration);
1971 wined3d_mutex_unlock();
1974 *ppShader = ((IDirect3DVertexDeclaration8Impl *)d3d8_declaration)->shader_handle;
1975 IDirect3DVertexDeclaration8_Release(d3d8_declaration);
1978 TRACE("(%p) : returning %#x\n", This, *ppShader);
1983 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1984 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1985 IDirect3DVertexShader8Impl *shader;
1986 IWineD3DVertexShader *cur = NULL;
1988 TRACE("iface %p, shader %#x.\n", iface, pShader);
1990 wined3d_mutex_lock();
1991 shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
1994 WARN("Invalid handle (%#x) passed.\n", pShader);
1995 wined3d_mutex_unlock();
1997 return D3DERR_INVALIDCALL;
2000 IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &cur);
2004 if (cur == shader->wineD3DVertexShader) IDirect3DDevice8_SetVertexShader(iface, 0);
2005 IWineD3DVertexShader_Release(cur);
2008 wined3d_mutex_unlock();
2010 if (IUnknown_Release((IUnknown *)shader))
2012 ERR("Shader %p has references left, this shouldn't happen.\n", shader);
2018 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
2019 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2022 TRACE("iface %p, register %u, data %p, count %u.\n",
2023 iface, Register, pConstantData, ConstantCount);
2025 if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
2026 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2027 Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2028 return D3DERR_INVALIDCALL;
2031 wined3d_mutex_lock();
2032 hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2033 wined3d_mutex_unlock();
2038 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
2039 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2042 TRACE("iface %p, register %u, data %p, count %u.\n",
2043 iface, Register, pConstantData, ConstantCount);
2045 if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
2046 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2047 Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2048 return D3DERR_INVALIDCALL;
2051 wined3d_mutex_lock();
2052 hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2053 wined3d_mutex_unlock();
2058 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderDeclaration(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
2059 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2060 IDirect3DVertexDeclaration8Impl *declaration;
2061 IDirect3DVertexShader8Impl *shader;
2063 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2064 iface, pVertexShader, pData, pSizeOfData);
2066 wined3d_mutex_lock();
2067 shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2068 wined3d_mutex_unlock();
2072 WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2073 return D3DERR_INVALIDCALL;
2075 declaration = (IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration;
2077 /* If pData is NULL, we just return the required size of the buffer. */
2079 *pSizeOfData = declaration->elements_size;
2083 /* MSDN claims that if *pSizeOfData is smaller than the required size
2084 * we should write the required size and return D3DERR_MOREDATA.
2085 * That's not actually true. */
2086 if (*pSizeOfData < declaration->elements_size) {
2087 return D3DERR_INVALIDCALL;
2090 CopyMemory(pData, declaration->elements, declaration->elements_size);
2095 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
2096 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2097 IDirect3DVertexShader8Impl *shader = NULL;
2100 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2101 iface, pVertexShader, pData, pSizeOfData);
2103 wined3d_mutex_lock();
2104 shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2107 WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2108 wined3d_mutex_unlock();
2110 return D3DERR_INVALIDCALL;
2113 if (!shader->wineD3DVertexShader)
2115 wined3d_mutex_unlock();
2120 hr = IWineD3DVertexShader_GetFunction(shader->wineD3DVertexShader, pData, pSizeOfData);
2121 wined3d_mutex_unlock();
2126 static HRESULT WINAPI IDirect3DDevice8Impl_SetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8* pIndexData, UINT baseVertexIndex) {
2127 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2129 IDirect3DIndexBuffer8Impl *ib = (IDirect3DIndexBuffer8Impl *)pIndexData;
2131 TRACE("iface %p, buffer %p, base_vertex_idx %u.\n", iface, pIndexData, baseVertexIndex);
2133 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
2134 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
2135 * vertex buffers can't be created to address them with an index that requires the 32nd bit
2136 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
2139 wined3d_mutex_lock();
2140 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, baseVertexIndex);
2141 hr = IWineD3DDevice_SetIndexBuffer(This->WineD3DDevice,
2142 ib ? ib->wineD3DIndexBuffer : NULL,
2143 ib ? ib->format : WINED3DFMT_UNKNOWN);
2144 wined3d_mutex_unlock();
2149 static HRESULT WINAPI IDirect3DDevice8Impl_GetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8** ppIndexData,UINT* pBaseVertexIndex) {
2150 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2151 IWineD3DBuffer *retIndexData = NULL;
2152 HRESULT rc = D3D_OK;
2154 TRACE("iface %p, buffer %p, base_vertex_index %p.\n", iface, ppIndexData, pBaseVertexIndex);
2156 if(ppIndexData == NULL){
2157 return D3DERR_INVALIDCALL;
2160 /* The case from UINT to INT is safe because d3d8 will never set negative values */
2161 wined3d_mutex_lock();
2162 IWineD3DDevice_GetBaseVertexIndex(This->WineD3DDevice, (INT *) pBaseVertexIndex);
2163 rc = IWineD3DDevice_GetIndexBuffer(This->WineD3DDevice, &retIndexData);
2164 if (SUCCEEDED(rc) && retIndexData) {
2165 IWineD3DBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
2166 IWineD3DBuffer_Release(retIndexData);
2168 if (FAILED(rc)) FIXME("Call to GetIndices failed\n");
2169 *ppIndexData = NULL;
2171 wined3d_mutex_unlock();
2176 static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(IDirect3DDevice8 *iface,
2177 const DWORD *byte_code, DWORD *shader)
2179 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2180 IDirect3DPixelShader8Impl *object;
2181 DWORD shader_handle;
2185 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2189 TRACE("(%p) Invalid call\n", This);
2190 return D3DERR_INVALIDCALL;
2193 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2196 ERR("Failed to allocate pixel shader memmory.\n");
2197 return E_OUTOFMEMORY;
2200 wined3d_mutex_lock();
2201 handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_PS);
2202 wined3d_mutex_unlock();
2203 if (handle == D3D8_INVALID_HANDLE)
2205 ERR("Failed to allocate pixel shader handle.\n");
2206 HeapFree(GetProcessHeap(), 0, object);
2207 return E_OUTOFMEMORY;
2210 shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
2212 hr = pixelshader_init(object, This, byte_code, shader_handle);
2215 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
2216 wined3d_mutex_lock();
2217 d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_PS);
2218 wined3d_mutex_unlock();
2219 HeapFree(GetProcessHeap(), 0, object);
2224 TRACE("Created pixel shader %p (handle %#x).\n", object, shader_handle);
2225 *shader = shader_handle;
2230 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
2231 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2232 IDirect3DPixelShader8Impl *shader;
2235 TRACE("iface %p, shader %#x.\n", iface, pShader);
2237 wined3d_mutex_lock();
2241 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, NULL);
2242 wined3d_mutex_unlock();
2246 shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2249 WARN("Invalid handle (%#x) passed.\n", pShader);
2250 wined3d_mutex_unlock();
2251 return D3DERR_INVALIDCALL;
2254 TRACE("(%p) : Setting shader %p\n", This, shader);
2255 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, shader->wineD3DPixelShader);
2256 wined3d_mutex_unlock();
2261 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
2262 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2263 IWineD3DPixelShader *object;
2264 HRESULT hrc = D3D_OK;
2266 TRACE("iface %p, shader %p.\n", iface, ppShader);
2268 if (NULL == ppShader) {
2269 TRACE("(%p) Invalid call\n", This);
2270 return D3DERR_INVALIDCALL;
2273 wined3d_mutex_lock();
2274 hrc = IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &object);
2275 if (D3D_OK == hrc && NULL != object) {
2276 IDirect3DPixelShader8Impl *d3d8_shader;
2277 hrc = IWineD3DPixelShader_GetParent(object, (IUnknown **)&d3d8_shader);
2278 IWineD3DPixelShader_Release(object);
2279 *ppShader = d3d8_shader->handle;
2280 IDirect3DPixelShader8_Release((IDirect3DPixelShader8 *)d3d8_shader);
2284 wined3d_mutex_unlock();
2286 TRACE("(%p) : returning %#x\n", This, *ppShader);
2291 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
2292 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2293 IDirect3DPixelShader8Impl *shader;
2294 IWineD3DPixelShader *cur = NULL;
2296 TRACE("iface %p, shader %#x.\n", iface, pShader);
2298 wined3d_mutex_lock();
2300 shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2303 WARN("Invalid handle (%#x) passed.\n", pShader);
2304 wined3d_mutex_unlock();
2305 return D3DERR_INVALIDCALL;
2308 IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &cur);
2312 if (cur == shader->wineD3DPixelShader) IDirect3DDevice8_SetPixelShader(iface, 0);
2313 IWineD3DPixelShader_Release(cur);
2316 wined3d_mutex_unlock();
2318 if (IUnknown_Release((IUnknown *)shader))
2320 ERR("Shader %p has references left, this shouldn't happen.\n", shader);
2326 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
2327 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2330 TRACE("iface %p, register %u, data %p, count %u.\n",
2331 iface, Register, pConstantData, ConstantCount);
2333 wined3d_mutex_lock();
2334 hr = IWineD3DDevice_SetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2335 wined3d_mutex_unlock();
2340 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
2341 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2344 TRACE("iface %p, register %u, data %p, count %u.\n",
2345 iface, Register, pConstantData, ConstantCount);
2347 wined3d_mutex_lock();
2348 hr = IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2349 wined3d_mutex_unlock();
2354 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pPixelShader, void* pData, DWORD* pSizeOfData) {
2355 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2356 IDirect3DPixelShader8Impl *shader = NULL;
2359 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2360 iface, pPixelShader, pData, pSizeOfData);
2362 wined3d_mutex_lock();
2363 shader = d3d8_get_object(&This->handle_table, pPixelShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2366 WARN("Invalid handle (%#x) passed.\n", pPixelShader);
2367 wined3d_mutex_unlock();
2369 return D3DERR_INVALIDCALL;
2372 hr = IWineD3DPixelShader_GetFunction(shader->wineD3DPixelShader, pData, pSizeOfData);
2373 wined3d_mutex_unlock();
2378 static HRESULT WINAPI IDirect3DDevice8Impl_DrawRectPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
2379 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2382 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2383 iface, Handle, pNumSegs, pRectPatchInfo);
2385 wined3d_mutex_lock();
2386 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
2387 wined3d_mutex_unlock();
2392 static HRESULT WINAPI IDirect3DDevice8Impl_DrawTriPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
2393 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2396 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2397 iface, Handle, pNumSegs, pTriPatchInfo);
2399 wined3d_mutex_lock();
2400 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
2401 wined3d_mutex_unlock();
2406 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePatch(LPDIRECT3DDEVICE8 iface, UINT Handle) {
2407 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2410 TRACE("iface %p, handle %#x.\n", iface, Handle);
2412 wined3d_mutex_lock();
2413 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
2414 wined3d_mutex_unlock();
2419 static HRESULT WINAPI IDirect3DDevice8Impl_SetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8* pStreamData,UINT Stride) {
2420 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2423 TRACE("iface %p, stream_idx %u, buffer %p, stride %u.\n",
2424 iface, StreamNumber, pStreamData, Stride);
2426 wined3d_mutex_lock();
2427 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
2428 NULL == pStreamData ? NULL : ((IDirect3DVertexBuffer8Impl *)pStreamData)->wineD3DVertexBuffer,
2429 0/* Offset in bytes */, Stride);
2430 wined3d_mutex_unlock();
2435 static HRESULT WINAPI IDirect3DDevice8Impl_GetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8** pStream,UINT* pStride) {
2436 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2437 IWineD3DBuffer *retStream = NULL;
2438 HRESULT rc = D3D_OK;
2440 TRACE("iface %p, stream_idx %u, buffer %p, stride %p.\n",
2441 iface, StreamNumber, pStream, pStride);
2443 if(pStream == NULL){
2444 return D3DERR_INVALIDCALL;
2447 wined3d_mutex_lock();
2448 rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, 0 /* Offset in bytes */, pStride);
2449 if (rc == D3D_OK && NULL != retStream) {
2450 IWineD3DBuffer_GetParent(retStream, (IUnknown **)pStream);
2451 IWineD3DBuffer_Release(retStream);
2454 FIXME("Call to GetStreamSource failed %p\n", pStride);
2458 wined3d_mutex_unlock();
2463 static const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl =
2465 IDirect3DDevice8Impl_QueryInterface,
2466 IDirect3DDevice8Impl_AddRef,
2467 IDirect3DDevice8Impl_Release,
2468 IDirect3DDevice8Impl_TestCooperativeLevel,
2469 IDirect3DDevice8Impl_GetAvailableTextureMem,
2470 IDirect3DDevice8Impl_ResourceManagerDiscardBytes,
2471 IDirect3DDevice8Impl_GetDirect3D,
2472 IDirect3DDevice8Impl_GetDeviceCaps,
2473 IDirect3DDevice8Impl_GetDisplayMode,
2474 IDirect3DDevice8Impl_GetCreationParameters,
2475 IDirect3DDevice8Impl_SetCursorProperties,
2476 IDirect3DDevice8Impl_SetCursorPosition,
2477 IDirect3DDevice8Impl_ShowCursor,
2478 IDirect3DDevice8Impl_CreateAdditionalSwapChain,
2479 IDirect3DDevice8Impl_Reset,
2480 IDirect3DDevice8Impl_Present,
2481 IDirect3DDevice8Impl_GetBackBuffer,
2482 IDirect3DDevice8Impl_GetRasterStatus,
2483 IDirect3DDevice8Impl_SetGammaRamp,
2484 IDirect3DDevice8Impl_GetGammaRamp,
2485 IDirect3DDevice8Impl_CreateTexture,
2486 IDirect3DDevice8Impl_CreateVolumeTexture,
2487 IDirect3DDevice8Impl_CreateCubeTexture,
2488 IDirect3DDevice8Impl_CreateVertexBuffer,
2489 IDirect3DDevice8Impl_CreateIndexBuffer,
2490 IDirect3DDevice8Impl_CreateRenderTarget,
2491 IDirect3DDevice8Impl_CreateDepthStencilSurface,
2492 IDirect3DDevice8Impl_CreateImageSurface,
2493 IDirect3DDevice8Impl_CopyRects,
2494 IDirect3DDevice8Impl_UpdateTexture,
2495 IDirect3DDevice8Impl_GetFrontBuffer,
2496 IDirect3DDevice8Impl_SetRenderTarget,
2497 IDirect3DDevice8Impl_GetRenderTarget,
2498 IDirect3DDevice8Impl_GetDepthStencilSurface,
2499 IDirect3DDevice8Impl_BeginScene,
2500 IDirect3DDevice8Impl_EndScene,
2501 IDirect3DDevice8Impl_Clear,
2502 IDirect3DDevice8Impl_SetTransform,
2503 IDirect3DDevice8Impl_GetTransform,
2504 IDirect3DDevice8Impl_MultiplyTransform,
2505 IDirect3DDevice8Impl_SetViewport,
2506 IDirect3DDevice8Impl_GetViewport,
2507 IDirect3DDevice8Impl_SetMaterial,
2508 IDirect3DDevice8Impl_GetMaterial,
2509 IDirect3DDevice8Impl_SetLight,
2510 IDirect3DDevice8Impl_GetLight,
2511 IDirect3DDevice8Impl_LightEnable,
2512 IDirect3DDevice8Impl_GetLightEnable,
2513 IDirect3DDevice8Impl_SetClipPlane,
2514 IDirect3DDevice8Impl_GetClipPlane,
2515 IDirect3DDevice8Impl_SetRenderState,
2516 IDirect3DDevice8Impl_GetRenderState,
2517 IDirect3DDevice8Impl_BeginStateBlock,
2518 IDirect3DDevice8Impl_EndStateBlock,
2519 IDirect3DDevice8Impl_ApplyStateBlock,
2520 IDirect3DDevice8Impl_CaptureStateBlock,
2521 IDirect3DDevice8Impl_DeleteStateBlock,
2522 IDirect3DDevice8Impl_CreateStateBlock,
2523 IDirect3DDevice8Impl_SetClipStatus,
2524 IDirect3DDevice8Impl_GetClipStatus,
2525 IDirect3DDevice8Impl_GetTexture,
2526 IDirect3DDevice8Impl_SetTexture,
2527 IDirect3DDevice8Impl_GetTextureStageState,
2528 IDirect3DDevice8Impl_SetTextureStageState,
2529 IDirect3DDevice8Impl_ValidateDevice,
2530 IDirect3DDevice8Impl_GetInfo,
2531 IDirect3DDevice8Impl_SetPaletteEntries,
2532 IDirect3DDevice8Impl_GetPaletteEntries,
2533 IDirect3DDevice8Impl_SetCurrentTexturePalette,
2534 IDirect3DDevice8Impl_GetCurrentTexturePalette,
2535 IDirect3DDevice8Impl_DrawPrimitive,
2536 IDirect3DDevice8Impl_DrawIndexedPrimitive,
2537 IDirect3DDevice8Impl_DrawPrimitiveUP,
2538 IDirect3DDevice8Impl_DrawIndexedPrimitiveUP,
2539 IDirect3DDevice8Impl_ProcessVertices,
2540 IDirect3DDevice8Impl_CreateVertexShader,
2541 IDirect3DDevice8Impl_SetVertexShader,
2542 IDirect3DDevice8Impl_GetVertexShader,
2543 IDirect3DDevice8Impl_DeleteVertexShader,
2544 IDirect3DDevice8Impl_SetVertexShaderConstant,
2545 IDirect3DDevice8Impl_GetVertexShaderConstant,
2546 IDirect3DDevice8Impl_GetVertexShaderDeclaration,
2547 IDirect3DDevice8Impl_GetVertexShaderFunction,
2548 IDirect3DDevice8Impl_SetStreamSource,
2549 IDirect3DDevice8Impl_GetStreamSource,
2550 IDirect3DDevice8Impl_SetIndices,
2551 IDirect3DDevice8Impl_GetIndices,
2552 IDirect3DDevice8Impl_CreatePixelShader,
2553 IDirect3DDevice8Impl_SetPixelShader,
2554 IDirect3DDevice8Impl_GetPixelShader,
2555 IDirect3DDevice8Impl_DeletePixelShader,
2556 IDirect3DDevice8Impl_SetPixelShaderConstant,
2557 IDirect3DDevice8Impl_GetPixelShaderConstant,
2558 IDirect3DDevice8Impl_GetPixelShaderFunction,
2559 IDirect3DDevice8Impl_DrawRectPatch,
2560 IDirect3DDevice8Impl_DrawTriPatch,
2561 IDirect3DDevice8Impl_DeletePatch
2564 /* IWineD3DDeviceParent IUnknown methods */
2566 static inline struct IDirect3DDevice8Impl *device_from_device_parent(IWineD3DDeviceParent *iface)
2568 return (struct IDirect3DDevice8Impl *)((char*)iface
2569 - FIELD_OFFSET(struct IDirect3DDevice8Impl, device_parent_vtbl));
2572 static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface, REFIID riid, void **object)
2574 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2575 return IDirect3DDevice8Impl_QueryInterface((IDirect3DDevice8 *)This, riid, object);
2578 static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
2580 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2581 return IDirect3DDevice8Impl_AddRef((IDirect3DDevice8 *)This);
2584 static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
2586 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2587 return IDirect3DDevice8Impl_Release((IDirect3DDevice8 *)This);
2590 /* IWineD3DDeviceParent methods */
2592 static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
2594 TRACE("iface %p, device %p\n", iface, device);
2597 static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
2598 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, DWORD usage,
2599 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface)
2601 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2602 IDirect3DSurface8Impl *d3d_surface;
2603 BOOL lockable = TRUE;
2606 TRACE("iface %p, superior %p, width %u, height %u, format %#x, usage %#x,\n"
2607 "\tpool %#x, level %u, face %u, surface %p\n",
2608 iface, superior, width, height, format, usage, pool, level, face, surface);
2611 if (pool == WINED3DPOOL_DEFAULT && !(usage & WINED3DUSAGE_DYNAMIC)) lockable = FALSE;
2613 hr = IDirect3DDevice8Impl_CreateSurface((IDirect3DDevice8 *)This, width, height,
2614 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
2615 (IDirect3DSurface8 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
2618 ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
2622 *surface = d3d_surface->wineD3DSurface;
2623 IWineD3DSurface_AddRef(*surface);
2625 d3d_surface->container = superior;
2626 IUnknown_Release(d3d_surface->parentDevice);
2627 d3d_surface->parentDevice = NULL;
2629 IDirect3DSurface8_Release((IDirect3DSurface8 *)d3d_surface);
2630 d3d_surface->forwardReference = superior;
2635 static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
2636 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2637 DWORD multisample_quality, BOOL lockable, IWineD3DSurface **surface)
2639 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2640 IDirect3DSurface8Impl *d3d_surface;
2643 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2644 "\tmultisample_quality %u, lockable %u, surface %p\n",
2645 iface, superior, width, height, format, multisample_type, multisample_quality, lockable, surface);
2647 hr = IDirect3DDevice8_CreateRenderTarget((IDirect3DDevice8 *)This, width, height,
2648 d3dformat_from_wined3dformat(format), multisample_type, lockable, (IDirect3DSurface8 **)&d3d_surface);
2651 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
2655 *surface = d3d_surface->wineD3DSurface;
2656 IWineD3DSurface_AddRef(*surface);
2658 d3d_surface->container = (IUnknown *)This;
2659 /* Implicit surfaces are created with an refcount of 0 */
2660 IUnknown_Release((IUnknown *)d3d_surface);
2665 static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
2666 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2667 DWORD multisample_quality, BOOL discard, IWineD3DSurface **surface)
2669 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2670 IDirect3DSurface8Impl *d3d_surface;
2673 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2674 "\tmultisample_quality %u, discard %u, surface %p\n",
2675 iface, superior, width, height, format, multisample_type, multisample_quality, discard, surface);
2677 hr = IDirect3DDevice8_CreateDepthStencilSurface((IDirect3DDevice8 *)This, width, height,
2678 d3dformat_from_wined3dformat(format), multisample_type, (IDirect3DSurface8 **)&d3d_surface);
2681 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
2685 *surface = d3d_surface->wineD3DSurface;
2686 IWineD3DSurface_AddRef(*surface);
2688 d3d_surface->container = (IUnknown *)This;
2689 /* Implicit surfaces are created with an refcount of 0 */
2690 IUnknown_Release((IUnknown *)d3d_surface);
2695 static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
2696 IUnknown *superior, UINT width, UINT height, UINT depth, WINED3DFORMAT format,
2697 WINED3DPOOL pool, DWORD usage, IWineD3DVolume **volume)
2699 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2700 IDirect3DVolume8Impl *object;
2703 TRACE("iface %p, superior %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
2704 iface, superior, width, height, depth, format, pool, usage, volume);
2706 /* Allocate the storage for the device */
2707 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2710 FIXME("Allocation of memory failed\n");
2712 return D3DERR_OUTOFVIDEOMEMORY;
2715 hr = volume_init(object, This, width, height, depth, usage, format, pool);
2718 WARN("Failed to initialize volume, hr %#x.\n", hr);
2719 HeapFree(GetProcessHeap(), 0, object);
2723 *volume = object->wineD3DVolume;
2724 IWineD3DVolume_AddRef(*volume);
2725 IDirect3DVolume8_Release((IDirect3DVolume8 *)object);
2727 object->container = superior;
2728 object->forwardReference = superior;
2730 TRACE("(%p) Created volume %p\n", iface, object);
2735 static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
2736 WINED3DPRESENT_PARAMETERS *present_parameters, IWineD3DSwapChain **swapchain)
2738 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2739 IDirect3DSwapChain8Impl *d3d_swapchain;
2740 D3DPRESENT_PARAMETERS local_parameters;
2743 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
2745 /* Copy the presentation parameters */
2746 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
2747 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
2748 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
2749 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
2750 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
2751 local_parameters.SwapEffect = present_parameters->SwapEffect;
2752 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
2753 local_parameters.Windowed = present_parameters->Windowed;
2754 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
2755 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
2756 local_parameters.Flags = present_parameters->Flags;
2757 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
2758 local_parameters.FullScreen_PresentationInterval = present_parameters->PresentationInterval;
2760 hr = IDirect3DDevice8_CreateAdditionalSwapChain((IDirect3DDevice8 *)This,
2761 &local_parameters, (IDirect3DSwapChain8 **)&d3d_swapchain);
2764 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
2769 *swapchain = d3d_swapchain->wineD3DSwapChain;
2770 IUnknown_Release(d3d_swapchain->parentDevice);
2771 d3d_swapchain->parentDevice = NULL;
2773 /* Copy back the presentation parameters */
2774 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
2775 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
2776 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
2777 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
2778 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
2779 present_parameters->SwapEffect = local_parameters.SwapEffect;
2780 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
2781 present_parameters->Windowed = local_parameters.Windowed;
2782 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
2783 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
2784 present_parameters->Flags = local_parameters.Flags;
2785 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
2786 present_parameters->PresentationInterval = local_parameters.FullScreen_PresentationInterval;
2791 static const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl =
2793 /* IUnknown methods */
2794 device_parent_QueryInterface,
2795 device_parent_AddRef,
2796 device_parent_Release,
2797 /* IWineD3DDeviceParent methods */
2798 device_parent_WineD3DDeviceCreated,
2799 device_parent_CreateSurface,
2800 device_parent_CreateRenderTarget,
2801 device_parent_CreateDepthStencilSurface,
2802 device_parent_CreateVolume,
2803 device_parent_CreateSwapChain,
2806 HRESULT device_init(IDirect3DDevice8Impl *device, IWineD3D *wined3d, UINT adapter,
2807 D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters)
2809 WINED3DPRESENT_PARAMETERS wined3d_parameters;
2812 device->lpVtbl = &Direct3DDevice8_Vtbl;
2813 device->device_parent_vtbl = &d3d8_wined3d_device_parent_vtbl;
2815 device->handle_table.entries = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2816 D3D8_INITIAL_HANDLE_TABLE_SIZE * sizeof(*device->handle_table.entries));
2817 if (!device->handle_table.entries)
2819 ERR("Failed to allocate handle table memory.\n");
2820 return E_OUTOFMEMORY;
2822 device->handle_table.table_size = D3D8_INITIAL_HANDLE_TABLE_SIZE;
2824 wined3d_mutex_lock();
2825 hr = IWineD3D_CreateDevice(wined3d, adapter, device_type, focus_window, flags, (IUnknown *)device,
2826 (IWineD3DDeviceParent *)&device->device_parent_vtbl, &device->WineD3DDevice);
2829 WARN("Failed to create wined3d device, hr %#x.\n", hr);
2830 wined3d_mutex_unlock();
2831 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
2835 if (flags & D3DCREATE_MULTITHREADED) IWineD3DDevice_SetMultithreaded(device->WineD3DDevice);
2837 wined3d_parameters.BackBufferWidth = parameters->BackBufferWidth;
2838 wined3d_parameters.BackBufferHeight = parameters->BackBufferHeight;
2839 wined3d_parameters.BackBufferFormat = wined3dformat_from_d3dformat(parameters->BackBufferFormat);
2840 wined3d_parameters.BackBufferCount = parameters->BackBufferCount;
2841 wined3d_parameters.MultiSampleType = parameters->MultiSampleType;
2842 wined3d_parameters.MultiSampleQuality = 0; /* d3d9 only */
2843 wined3d_parameters.SwapEffect = parameters->SwapEffect;
2844 wined3d_parameters.hDeviceWindow = parameters->hDeviceWindow;
2845 wined3d_parameters.Windowed = parameters->Windowed;
2846 wined3d_parameters.EnableAutoDepthStencil = parameters->EnableAutoDepthStencil;
2847 wined3d_parameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(parameters->AutoDepthStencilFormat);
2848 wined3d_parameters.Flags = parameters->Flags;
2849 wined3d_parameters.FullScreen_RefreshRateInHz = parameters->FullScreen_RefreshRateInHz;
2850 wined3d_parameters.PresentationInterval = parameters->FullScreen_PresentationInterval;
2851 wined3d_parameters.AutoRestoreDisplayMode = TRUE;
2853 hr = IWineD3DDevice_Init3D(device->WineD3DDevice, &wined3d_parameters);
2856 WARN("Failed to initialize 3D, hr %#x.\n", hr);
2857 IWineD3DDevice_Release(device->WineD3DDevice);
2858 wined3d_mutex_unlock();
2859 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);
2863 hr = IWineD3DDevice_SetRenderState(device->WineD3DDevice, WINED3DRS_POINTSIZE_MIN, 0);
2864 wined3d_mutex_unlock();
2867 ERR("Failed to set minimum pointsize, hr %#x.\n", hr);
2871 parameters->BackBufferWidth = wined3d_parameters.BackBufferWidth;
2872 parameters->BackBufferHeight = wined3d_parameters.BackBufferHeight;
2873 parameters->BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters.BackBufferFormat);
2874 parameters->BackBufferCount = wined3d_parameters.BackBufferCount;
2875 parameters->MultiSampleType = wined3d_parameters.MultiSampleType;
2876 parameters->SwapEffect = wined3d_parameters.SwapEffect;
2877 parameters->hDeviceWindow = wined3d_parameters.hDeviceWindow;
2878 parameters->Windowed = wined3d_parameters.Windowed;
2879 parameters->EnableAutoDepthStencil = wined3d_parameters.EnableAutoDepthStencil;
2880 parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(wined3d_parameters.AutoDepthStencilFormat);
2881 parameters->Flags = wined3d_parameters.Flags;
2882 parameters->FullScreen_RefreshRateInHz = wined3d_parameters.FullScreen_RefreshRateInHz;
2883 parameters->FullScreen_PresentationInterval = wined3d_parameters.PresentationInterval;
2885 device->declArraySize = 16;
2886 device->decls = HeapAlloc(GetProcessHeap(), 0, device->declArraySize * sizeof(*device->decls));
2889 ERR("Failed to allocate FVF vertex delcaration map memory.\n");
2897 wined3d_mutex_lock();
2898 IWineD3DDevice_Uninit3D(device->WineD3DDevice, D3D8CB_DestroySwapChain);
2899 IWineD3DDevice_Release(device->WineD3DDevice);
2900 wined3d_mutex_unlock();
2901 HeapFree(GetProcessHeap(), 0, device->handle_table.entries);