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_R8G8B8: return D3DFMT_R8G8B8;
50 case WINED3DFMT_A8R8G8B8: return D3DFMT_A8R8G8B8;
51 case WINED3DFMT_X8R8G8B8: return D3DFMT_X8R8G8B8;
52 case WINED3DFMT_R5G6B5: return D3DFMT_R5G6B5;
53 case WINED3DFMT_X1R5G5B5: return D3DFMT_X1R5G5B5;
54 case WINED3DFMT_A1R5G5B5: return D3DFMT_A1R5G5B5;
55 case WINED3DFMT_A4R4G4B4: return D3DFMT_A4R4G4B4;
56 case WINED3DFMT_R3G3B2: return D3DFMT_R3G3B2;
57 case WINED3DFMT_A8_UNORM: return D3DFMT_A8;
58 case WINED3DFMT_A8R3G3B2: return D3DFMT_A8R3G3B2;
59 case WINED3DFMT_X4R4G4B4: return D3DFMT_X4R4G4B4;
60 case WINED3DFMT_R10G10B10A2_UNORM: return D3DFMT_A2B10G10R10;
61 case WINED3DFMT_R16G16_UNORM: return D3DFMT_G16R16;
62 case WINED3DFMT_A8P8: return D3DFMT_A8P8;
63 case WINED3DFMT_P8: return D3DFMT_P8;
64 case WINED3DFMT_L8: return D3DFMT_L8;
65 case WINED3DFMT_A8L8: return D3DFMT_A8L8;
66 case WINED3DFMT_A4L4: return D3DFMT_A4L4;
67 case WINED3DFMT_R8G8_SNORM: return D3DFMT_V8U8;
68 case WINED3DFMT_L6V5U5: return D3DFMT_L6V5U5;
69 case WINED3DFMT_X8L8V8U8: return D3DFMT_X8L8V8U8;
70 case WINED3DFMT_R8G8B8A8_SNORM: return D3DFMT_Q8W8V8U8;
71 case WINED3DFMT_R16G16_SNORM: return D3DFMT_V16U16;
72 case WINED3DFMT_W11V11U10: return D3DFMT_W11V11U10;
73 case WINED3DFMT_A2W10V10U10: return D3DFMT_A2W10V10U10;
74 case WINED3DFMT_D16_LOCKABLE: return D3DFMT_D16_LOCKABLE;
75 case WINED3DFMT_D32: return D3DFMT_D32;
76 case WINED3DFMT_D15S1: return D3DFMT_D15S1;
77 case WINED3DFMT_D24S8: return D3DFMT_D24S8;
78 case WINED3DFMT_D24X8: return D3DFMT_D24X8;
79 case WINED3DFMT_D24X4S4: 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_R8G8B8;
101 case D3DFMT_A8R8G8B8: return WINED3DFMT_A8R8G8B8;
102 case D3DFMT_X8R8G8B8: return WINED3DFMT_X8R8G8B8;
103 case D3DFMT_R5G6B5: return WINED3DFMT_R5G6B5;
104 case D3DFMT_X1R5G5B5: return WINED3DFMT_X1R5G5B5;
105 case D3DFMT_A1R5G5B5: return WINED3DFMT_A1R5G5B5;
106 case D3DFMT_A4R4G4B4: return WINED3DFMT_A4R4G4B4;
107 case D3DFMT_R3G3B2: return WINED3DFMT_R3G3B2;
108 case D3DFMT_A8: return WINED3DFMT_A8_UNORM;
109 case D3DFMT_A8R3G3B2: return WINED3DFMT_A8R3G3B2;
110 case D3DFMT_X4R4G4B4: return WINED3DFMT_X4R4G4B4;
111 case D3DFMT_A2B10G10R10: return WINED3DFMT_R10G10B10A2_UNORM;
112 case D3DFMT_G16R16: return WINED3DFMT_R16G16_UNORM;
113 case D3DFMT_A8P8: return WINED3DFMT_A8P8;
114 case D3DFMT_P8: return WINED3DFMT_P8;
115 case D3DFMT_L8: return WINED3DFMT_L8;
116 case D3DFMT_A8L8: return WINED3DFMT_A8L8;
117 case D3DFMT_A4L4: return WINED3DFMT_A4L4;
118 case D3DFMT_V8U8: return WINED3DFMT_R8G8_SNORM;
119 case D3DFMT_L6V5U5: return WINED3DFMT_L6V5U5;
120 case D3DFMT_X8L8V8U8: return WINED3DFMT_X8L8V8U8;
121 case D3DFMT_Q8W8V8U8: return WINED3DFMT_R8G8B8A8_SNORM;
122 case D3DFMT_V16U16: return WINED3DFMT_R16G16_SNORM;
123 case D3DFMT_W11V11U10: return WINED3DFMT_W11V11U10;
124 case D3DFMT_A2W10V10U10: return WINED3DFMT_A2W10V10U10;
125 case D3DFMT_D16_LOCKABLE: return WINED3DFMT_D16_LOCKABLE;
126 case D3DFMT_D32: return WINED3DFMT_D32;
127 case D3DFMT_D15S1: return WINED3DFMT_D15S1;
128 case D3DFMT_D24S8: return WINED3DFMT_D24S8;
129 case D3DFMT_D24X8: return WINED3DFMT_D24X8;
130 case D3DFMT_D24X4S4: return WINED3DFMT_D24X4S4;
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 /* IDirect3D IUnknown parts follow: */
257 static HRESULT WINAPI IDirect3DDevice8Impl_QueryInterface(LPDIRECT3DDEVICE8 iface,REFIID riid,LPVOID *ppobj)
259 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
261 if (IsEqualGUID(riid, &IID_IUnknown)
262 || IsEqualGUID(riid, &IID_IDirect3DDevice8)) {
263 IUnknown_AddRef(iface);
268 if (IsEqualGUID(riid, &IID_IWineD3DDeviceParent))
270 IUnknown_AddRef((IUnknown *)&This->device_parent_vtbl);
271 *ppobj = &This->device_parent_vtbl;
275 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
277 return E_NOINTERFACE;
280 static ULONG WINAPI IDirect3DDevice8Impl_AddRef(LPDIRECT3DDEVICE8 iface) {
281 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
282 ULONG ref = InterlockedIncrement(&This->ref);
284 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
289 static ULONG WINAPI IDirect3DDevice8Impl_Release(LPDIRECT3DDEVICE8 iface) {
290 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
293 if (This->inDestruction) return 0;
294 ref = InterlockedDecrement(&This->ref);
296 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
301 TRACE("Releasing wined3d device %p\n", This->WineD3DDevice);
303 wined3d_mutex_lock();
305 This->inDestruction = TRUE;
307 for(i = 0; i < This->numConvertedDecls; i++) {
308 IDirect3DVertexDeclaration8_Release(This->decls[i].decl);
310 HeapFree(GetProcessHeap(), 0, This->decls);
312 IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D8CB_DestroySwapChain);
313 IWineD3DDevice_Release(This->WineD3DDevice);
314 HeapFree(GetProcessHeap(), 0, This->handle_table.entries);
315 HeapFree(GetProcessHeap(), 0, This);
317 wined3d_mutex_unlock();
322 /* IDirect3DDevice Interface follow: */
323 static HRESULT WINAPI IDirect3DDevice8Impl_TestCooperativeLevel(LPDIRECT3DDEVICE8 iface) {
324 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
327 TRACE("(%p) : Relay\n", This);
329 wined3d_mutex_lock();
330 hr = IWineD3DDevice_TestCooperativeLevel(This->WineD3DDevice);
331 wined3d_mutex_unlock();
336 static UINT WINAPI IDirect3DDevice8Impl_GetAvailableTextureMem(LPDIRECT3DDEVICE8 iface) {
337 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
340 TRACE("(%p) Relay\n", This);
342 wined3d_mutex_lock();
343 hr = IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
344 wined3d_mutex_unlock();
349 static HRESULT WINAPI IDirect3DDevice8Impl_ResourceManagerDiscardBytes(LPDIRECT3DDEVICE8 iface, DWORD Bytes) {
350 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
353 TRACE("(%p) : Relay bytes(%d)\n", This, Bytes);
355 wined3d_mutex_lock();
356 hr = IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
357 wined3d_mutex_unlock();
362 static HRESULT WINAPI IDirect3DDevice8Impl_GetDirect3D(LPDIRECT3DDEVICE8 iface, IDirect3D8** ppD3D8) {
363 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
367 TRACE("(%p) Relay\n", This);
369 if (NULL == ppD3D8) {
370 return D3DERR_INVALIDCALL;
373 wined3d_mutex_lock();
374 hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &pWineD3D);
375 if (hr == D3D_OK && pWineD3D != NULL)
377 IWineD3D_GetParent(pWineD3D,(IUnknown **)ppD3D8);
378 IWineD3D_Release(pWineD3D);
380 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
383 wined3d_mutex_unlock();
385 TRACE("(%p) returning %p\n",This , *ppD3D8);
390 static HRESULT WINAPI IDirect3DDevice8Impl_GetDeviceCaps(LPDIRECT3DDEVICE8 iface, D3DCAPS8* pCaps) {
391 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
392 HRESULT hrc = D3D_OK;
393 WINED3DCAPS *pWineCaps;
395 TRACE("(%p) : Relay pCaps %p\n", This, pCaps);
397 return D3DERR_INVALIDCALL;
399 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
400 if(pWineCaps == NULL){
401 return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
404 wined3d_mutex_lock();
405 hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
406 wined3d_mutex_unlock();
408 fixup_caps(pWineCaps);
409 WINECAPSTOD3D8CAPS(pCaps, pWineCaps)
410 HeapFree(GetProcessHeap(), 0, pWineCaps);
412 TRACE("Returning %p %p\n", This, pCaps);
416 static HRESULT WINAPI IDirect3DDevice8Impl_GetDisplayMode(LPDIRECT3DDEVICE8 iface, D3DDISPLAYMODE* pMode) {
417 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
419 TRACE("(%p) Relay\n", This);
421 wined3d_mutex_lock();
422 hr = IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, 0, (WINED3DDISPLAYMODE *) pMode);
423 wined3d_mutex_unlock();
425 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
430 static HRESULT WINAPI IDirect3DDevice8Impl_GetCreationParameters(LPDIRECT3DDEVICE8 iface, D3DDEVICE_CREATION_PARAMETERS *pParameters) {
431 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
433 TRACE("(%p) Relay\n", This);
435 wined3d_mutex_lock();
436 hr = IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
437 wined3d_mutex_unlock();
442 static HRESULT WINAPI IDirect3DDevice8Impl_SetCursorProperties(LPDIRECT3DDEVICE8 iface, UINT XHotSpot, UINT YHotSpot, IDirect3DSurface8* pCursorBitmap) {
443 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
444 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl*)pCursorBitmap;
446 TRACE("(%p) Relay\n", This);
448 WARN("No cursor bitmap, returning WINED3DERR_INVALIDCALL\n");
449 return WINED3DERR_INVALIDCALL;
452 wined3d_mutex_lock();
453 hr = IWineD3DDevice_SetCursorProperties(This->WineD3DDevice,XHotSpot,YHotSpot,pSurface->wineD3DSurface);
454 wined3d_mutex_unlock();
459 static void WINAPI IDirect3DDevice8Impl_SetCursorPosition(LPDIRECT3DDEVICE8 iface, UINT XScreenSpace, UINT YScreenSpace, DWORD Flags) {
460 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
461 TRACE("(%p) Relay\n", This);
463 wined3d_mutex_lock();
464 IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
465 wined3d_mutex_unlock();
468 static BOOL WINAPI IDirect3DDevice8Impl_ShowCursor(LPDIRECT3DDEVICE8 iface, BOOL bShow) {
469 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
471 TRACE("(%p) Relay\n", This);
473 wined3d_mutex_lock();
474 ret = IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
475 wined3d_mutex_unlock();
480 static HRESULT WINAPI IDirect3DDevice8Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain8** pSwapChain) {
481 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
482 IDirect3DSwapChain8Impl* object;
483 HRESULT hrc = D3D_OK;
484 WINED3DPRESENT_PARAMETERS localParameters;
486 TRACE("(%p) Relay\n", This);
488 /* Fix the back buffer count */
489 if(pPresentationParameters->BackBufferCount == 0) {
490 pPresentationParameters->BackBufferCount = 1;
493 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
494 if (NULL == object) {
495 FIXME("Allocation of memory failed\n");
497 return D3DERR_OUTOFVIDEOMEMORY;
500 object->lpVtbl = &Direct3DSwapChain8_Vtbl;
502 /* Allocate an associated WineD3DDevice object */
503 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
504 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
505 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
506 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
507 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
508 localParameters.MultiSampleQuality = 0; /* d3d9 only */
509 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
510 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
511 localParameters.Windowed = pPresentationParameters->Windowed;
512 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
513 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
514 localParameters.Flags = pPresentationParameters->Flags;
515 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
516 localParameters.PresentationInterval = pPresentationParameters->FullScreen_PresentationInterval;
517 localParameters.AutoRestoreDisplayMode = TRUE;
519 wined3d_mutex_lock();
520 hrc = IWineD3DDevice_CreateSwapChain(This->WineD3DDevice, &localParameters,
521 &object->wineD3DSwapChain, (IUnknown *)object, SURFACE_OPENGL);
522 wined3d_mutex_unlock();
524 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
525 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
526 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
527 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
528 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
529 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
530 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
531 pPresentationParameters->Windowed = localParameters.Windowed;
532 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
533 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
534 pPresentationParameters->Flags = localParameters.Flags;
535 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
536 pPresentationParameters->FullScreen_PresentationInterval = localParameters.PresentationInterval;
539 FIXME("(%p) call to IWineD3DDevice_CreateSwapChain failed\n", This);
540 HeapFree(GetProcessHeap(), 0 , object);
543 IUnknown_AddRef(iface);
544 object->parentDevice = iface;
545 *pSwapChain = (IDirect3DSwapChain8 *)object;
547 TRACE("(%p) returning %p\n", This, *pSwapChain);
551 static HRESULT WINAPI IDirect3DDevice8Impl_Reset(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
552 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
553 WINED3DPRESENT_PARAMETERS localParameters;
556 TRACE("(%p) Relay pPresentationParameters(%p)\n", This, pPresentationParameters);
558 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
559 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
560 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
561 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
562 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
563 localParameters.MultiSampleQuality = 0; /* d3d9 only */
564 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
565 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
566 localParameters.Windowed = pPresentationParameters->Windowed;
567 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
568 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
569 localParameters.Flags = pPresentationParameters->Flags;
570 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
571 localParameters.PresentationInterval = pPresentationParameters->FullScreen_PresentationInterval;
572 localParameters.AutoRestoreDisplayMode = TRUE;
574 wined3d_mutex_lock();
575 hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
576 wined3d_mutex_unlock();
578 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
579 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
580 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
581 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
582 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
583 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
584 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
585 pPresentationParameters->Windowed = localParameters.Windowed;
586 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
587 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
588 pPresentationParameters->Flags = localParameters.Flags;
589 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
590 pPresentationParameters->FullScreen_PresentationInterval = localParameters.PresentationInterval;
595 static HRESULT WINAPI IDirect3DDevice8Impl_Present(LPDIRECT3DDEVICE8 iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion) {
596 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
598 TRACE("(%p) Relay\n", This);
600 wined3d_mutex_lock();
601 hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
602 wined3d_mutex_unlock();
607 static HRESULT WINAPI IDirect3DDevice8Impl_GetBackBuffer(LPDIRECT3DDEVICE8 iface, UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8** ppBackBuffer) {
608 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
609 IWineD3DSurface *retSurface = NULL;
612 TRACE("(%p) Relay\n", This);
614 wined3d_mutex_lock();
615 rc = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, 0, BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &retSurface);
616 if (rc == D3D_OK && NULL != retSurface && NULL != ppBackBuffer) {
617 IWineD3DSurface_GetParent(retSurface, (IUnknown **)ppBackBuffer);
618 IWineD3DSurface_Release(retSurface);
620 wined3d_mutex_unlock();
625 static HRESULT WINAPI IDirect3DDevice8Impl_GetRasterStatus(LPDIRECT3DDEVICE8 iface, D3DRASTER_STATUS* pRasterStatus) {
626 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
628 TRACE("(%p) Relay\n", This);
630 wined3d_mutex_lock();
631 hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, 0, (WINED3DRASTER_STATUS *) pRasterStatus);
632 wined3d_mutex_unlock();
637 static void WINAPI IDirect3DDevice8Impl_SetGammaRamp(LPDIRECT3DDEVICE8 iface, DWORD Flags, CONST D3DGAMMARAMP* pRamp) {
638 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
639 TRACE("(%p) Relay\n", This);
641 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
642 wined3d_mutex_lock();
643 IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, 0, Flags, (CONST WINED3DGAMMARAMP *) pRamp);
644 wined3d_mutex_unlock();
647 static void WINAPI IDirect3DDevice8Impl_GetGammaRamp(LPDIRECT3DDEVICE8 iface, D3DGAMMARAMP* pRamp) {
648 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
649 TRACE("(%p) Relay\n", This);
651 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
652 wined3d_mutex_lock();
653 IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, 0, (WINED3DGAMMARAMP *) pRamp);
654 wined3d_mutex_unlock();
657 static HRESULT WINAPI IDirect3DDevice8Impl_CreateTexture(IDirect3DDevice8 *iface,
658 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
659 D3DPOOL pool, IDirect3DTexture8 **texture)
661 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
662 IDirect3DTexture8Impl *object;
665 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
666 iface, width, height, levels, usage, format, pool, texture);
668 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
671 ERR("Failed to allocate texture memory.\n");
672 return D3DERR_OUTOFVIDEOMEMORY;
675 hr = texture_init(object, This, width, height, levels, usage, format, pool);
678 WARN("Failed to initialize texture, hr %#x.\n", hr);
679 HeapFree(GetProcessHeap(), 0, object);
683 TRACE("Created texture %p.\n", object);
684 *texture = (IDirect3DTexture8 *)object;
689 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVolumeTexture(IDirect3DDevice8 *iface,
690 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
691 D3DPOOL pool, IDirect3DVolumeTexture8 **texture)
693 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
694 IDirect3DVolumeTexture8Impl *object;
697 TRACE("iface %p, width %u, height %u, depth %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
698 iface, width, height, depth, levels, usage, format, pool, texture);
700 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
703 ERR("Failed to allocate volume texture memory.\n");
704 return D3DERR_OUTOFVIDEOMEMORY;
707 hr = volumetexture_init(object, This, width, height, depth, levels, usage, format, pool);
710 WARN("Failed to initialize volume texture, hr %#x.\n", hr);
711 HeapFree(GetProcessHeap(), 0, object);
715 TRACE("Created volume texture %p.\n", object);
716 *texture = (IDirect3DVolumeTexture8 *)object;
721 static HRESULT WINAPI IDirect3DDevice8Impl_CreateCubeTexture(IDirect3DDevice8 *iface, UINT edge_length,
722 UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool, IDirect3DCubeTexture8 **texture)
724 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
725 IDirect3DCubeTexture8Impl *object;
728 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
729 iface, edge_length, levels, usage, format, pool, texture);
731 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
734 ERR("Failed to allocate cube texture memory.\n");
735 return D3DERR_OUTOFVIDEOMEMORY;
738 hr = cubetexture_init(object, This, edge_length, levels, usage, format, pool);
741 WARN("Failed to initialize cube texture, hr %#x.\n", hr);
742 HeapFree(GetProcessHeap(), 0, object);
746 TRACE("Created cube texture %p.\n", object);
747 *texture = (IDirect3DCubeTexture8 *)object;
752 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexBuffer(LPDIRECT3DDEVICE8 iface, UINT Size, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer8** ppVertexBuffer) {
753 IDirect3DVertexBuffer8Impl *object;
754 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
755 HRESULT hrc = D3D_OK;
757 TRACE("(%p) Relay\n", This);
758 /* Allocate the storage for the device */
759 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexBuffer8Impl));
760 if (NULL == object) {
761 FIXME("Allocation of memory failed\n");
762 *ppVertexBuffer = NULL;
763 return D3DERR_OUTOFVIDEOMEMORY;
766 object->lpVtbl = &Direct3DVertexBuffer8_Vtbl;
769 wined3d_mutex_lock();
770 hrc = IWineD3DDevice_CreateVertexBuffer(This->WineD3DDevice, Size, Usage & WINED3DUSAGE_MASK,
771 0 /* fvf for ddraw only */, (WINED3DPOOL)Pool, &object->wineD3DVertexBuffer, (IUnknown *)object);
772 wined3d_mutex_unlock();
779 FIXME("(%p) call to IWineD3DDevice_CreateVertexBuffer failed\n", This);
780 HeapFree(GetProcessHeap(), 0, object);
781 *ppVertexBuffer = NULL;
783 IUnknown_AddRef(iface);
784 object->parentDevice = iface;
785 *ppVertexBuffer = (LPDIRECT3DVERTEXBUFFER8) object;
790 static HRESULT WINAPI IDirect3DDevice8Impl_CreateIndexBuffer(IDirect3DDevice8 *iface, UINT size, DWORD usage,
791 D3DFORMAT format, D3DPOOL pool, IDirect3DIndexBuffer8 **buffer)
793 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
794 IDirect3DIndexBuffer8Impl *object;
797 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p.\n",
798 iface, size, usage, format, pool, buffer);
800 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
803 ERR("Failed to allocate buffer memory.\n");
804 return D3DERR_OUTOFVIDEOMEMORY;
807 hr = indexbuffer_init(object, This, size, usage, format, pool);
810 WARN("Failed to initialize index buffer, hr %#x.\n", hr);
811 HeapFree(GetProcessHeap(), 0, object);
815 TRACE("Created index buffer %p.\n", object);
816 *buffer = (IDirect3DIndexBuffer8 *)object;
821 static HRESULT IDirect3DDevice8Impl_CreateSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height,
822 D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IDirect3DSurface8 **ppSurface,
823 UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality)
825 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
826 IDirect3DSurface8Impl *object;
829 TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
831 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface8Impl));
834 FIXME("Failed to allocate surface memory.\n");
835 return D3DERR_OUTOFVIDEOMEMORY;
838 hr = surface_init(object, This, Width, Height, Format, Lockable, Discard,
839 Level, Usage, Pool, MultiSample, MultisampleQuality);
842 WARN("Failed to initialize surface, hr %#x.\n", hr);
843 HeapFree(GetProcessHeap(), 0, object);
847 TRACE("Created surface %p.\n", object);
848 *ppSurface = (IDirect3DSurface8 *)object;
853 static HRESULT WINAPI IDirect3DDevice8Impl_CreateRenderTarget(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, BOOL Lockable, IDirect3DSurface8** ppSurface) {
857 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, Lockable, FALSE /* Discard */,
858 0 /* Level */, ppSurface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, MultiSample, 0);
863 static HRESULT WINAPI IDirect3DDevice8Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, IDirect3DSurface8** ppSurface) {
867 /* TODO: Verify that Discard is false */
868 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE,
869 0 /* Level */, ppSurface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, MultiSample, 0);
874 /* IDirect3DDevice8Impl::CreateImageSurface returns surface with pool type SYSTEMMEM */
875 static HRESULT WINAPI IDirect3DDevice8Impl_CreateImageSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, IDirect3DSurface8** ppSurface) {
879 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE /* Discard */,
880 0 /* Level */, ppSurface, 0 /* Usage (undefined/none) */, D3DPOOL_SYSTEMMEM, D3DMULTISAMPLE_NONE,
881 0 /* MultisampleQuality */);
886 static HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8 *pSourceSurface, CONST RECT *pSourceRects, UINT cRects, IDirect3DSurface8 *pDestinationSurface, CONST POINT *pDestPoints) {
887 IDirect3DSurface8Impl *Source = (IDirect3DSurface8Impl *) pSourceSurface;
888 IDirect3DSurface8Impl *Dest = (IDirect3DSurface8Impl *) pDestinationSurface;
890 HRESULT hr = WINED3D_OK;
891 WINED3DFORMAT srcFormat, destFormat;
892 UINT srcWidth, destWidth;
893 UINT srcHeight, destHeight;
895 WINED3DSURFACE_DESC winedesc;
897 TRACE("(%p) pSrcSur=%p, pSourceRects=%p, cRects=%d, pDstSur=%p, pDestPtsArr=%p\n", iface,
898 pSourceSurface, pSourceRects, cRects, pDestinationSurface, pDestPoints);
901 /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the destination texture is in WINED3DPOOL_DEFAULT */
903 wined3d_mutex_lock();
904 IWineD3DSurface_GetDesc(Source->wineD3DSurface, &winedesc);
905 srcFormat = winedesc.format;
906 srcWidth = winedesc.width;
907 srcHeight = winedesc.height;
908 srcSize = winedesc.size;
910 IWineD3DSurface_GetDesc(Dest->wineD3DSurface, &winedesc);
911 destFormat = winedesc.format;
912 destWidth = winedesc.width;
913 destHeight = winedesc.height;
915 /* Check that the source and destination formats match */
916 if (srcFormat != destFormat && WINED3DFMT_UNKNOWN != destFormat) {
917 WARN("(%p) source %p format must match the dest %p format, returning WINED3DERR_INVALIDCALL\n", iface, pSourceSurface, pDestinationSurface);
918 wined3d_mutex_unlock();
919 return WINED3DERR_INVALIDCALL;
920 } else if (WINED3DFMT_UNKNOWN == destFormat) {
921 TRACE("(%p) : Converting destination surface from WINED3DFMT_UNKNOWN to the source format\n", iface);
922 IWineD3DSurface_SetFormat(Dest->wineD3DSurface, srcFormat);
923 destFormat = srcFormat;
926 /* Quick if complete copy ... */
927 if (cRects == 0 && pSourceRects == NULL && pDestPoints == NULL) {
928 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
931 /* Copy rect by rect */
932 if (NULL != pSourceRects && NULL != pDestPoints) {
933 for (i = 0; i < cRects; ++i) {
934 IWineD3DSurface_BltFast(Dest->wineD3DSurface, pDestPoints[i].x, pDestPoints[i].y, Source->wineD3DSurface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
937 for (i = 0; i < cRects; ++i) {
938 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
942 wined3d_mutex_unlock();
947 static HRESULT WINAPI IDirect3DDevice8Impl_UpdateTexture(LPDIRECT3DDEVICE8 iface, IDirect3DBaseTexture8* pSourceTexture, IDirect3DBaseTexture8* pDestinationTexture) {
948 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
950 TRACE("(%p) Relay\n" , This);
952 wined3d_mutex_lock();
953 hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice, ((IDirect3DBaseTexture8Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture8Impl *)pDestinationTexture)->wineD3DBaseTexture);
954 wined3d_mutex_unlock();
959 static HRESULT WINAPI IDirect3DDevice8Impl_GetFrontBuffer(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pDestSurface) {
960 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
961 IDirect3DSurface8Impl *destSurface = (IDirect3DSurface8Impl *)pDestSurface;
964 TRACE("(%p) Relay\n" , This);
966 if (pDestSurface == NULL) {
967 WARN("(%p) : Caller passed NULL as pDestSurface returning D3DERR_INVALIDCALL\n", This);
968 return D3DERR_INVALIDCALL;
971 wined3d_mutex_lock();
972 hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, 0, destSurface->wineD3DSurface);
973 wined3d_mutex_unlock();
978 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pRenderTarget, IDirect3DSurface8* pNewZStencil) {
979 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
980 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl *)pRenderTarget;
981 IDirect3DSurface8Impl *pZSurface = (IDirect3DSurface8Impl *)pNewZStencil;
982 IWineD3DSurface *original_ds = NULL;
984 TRACE("(%p) Relay\n" , This);
986 wined3d_mutex_lock();
988 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice, &original_ds);
989 if (hr == WINED3D_OK || hr == WINED3DERR_NOTFOUND)
991 hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, pZSurface ? pZSurface->wineD3DSurface : NULL);
992 if (SUCCEEDED(hr) && pSurface)
993 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, 0, pSurface->wineD3DSurface);
994 if (FAILED(hr)) IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, original_ds);
996 if (original_ds) IWineD3DSurface_Release(original_ds);
998 wined3d_mutex_unlock();
1003 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppRenderTarget) {
1004 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1005 HRESULT hr = D3D_OK;
1006 IWineD3DSurface *pRenderTarget;
1008 TRACE("(%p) Relay\n" , This);
1010 if (ppRenderTarget == NULL) {
1011 return D3DERR_INVALIDCALL;
1014 wined3d_mutex_lock();
1015 hr = IWineD3DDevice_GetRenderTarget(This->WineD3DDevice, 0, &pRenderTarget);
1017 if (hr == D3D_OK && pRenderTarget != NULL) {
1018 IWineD3DSurface_GetParent(pRenderTarget,(IUnknown**)ppRenderTarget);
1019 IWineD3DSurface_Release(pRenderTarget);
1021 FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
1022 *ppRenderTarget = NULL;
1024 wined3d_mutex_unlock();
1029 static HRESULT WINAPI IDirect3DDevice8Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppZStencilSurface) {
1030 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1031 HRESULT hr = D3D_OK;
1032 IWineD3DSurface *pZStencilSurface;
1034 TRACE("(%p) Relay\n" , This);
1035 if(ppZStencilSurface == NULL){
1036 return D3DERR_INVALIDCALL;
1039 wined3d_mutex_lock();
1040 hr=IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
1041 if (hr == WINED3D_OK) {
1042 IWineD3DSurface_GetParent(pZStencilSurface,(IUnknown**)ppZStencilSurface);
1043 IWineD3DSurface_Release(pZStencilSurface);
1045 if (hr != WINED3DERR_NOTFOUND)
1046 FIXME("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
1047 *ppZStencilSurface = NULL;
1049 wined3d_mutex_unlock();
1054 static HRESULT WINAPI IDirect3DDevice8Impl_BeginScene(LPDIRECT3DDEVICE8 iface) {
1055 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1057 TRACE("(%p) Relay\n" , This);
1059 wined3d_mutex_lock();
1060 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
1061 wined3d_mutex_unlock();
1066 static HRESULT WINAPI IDirect3DDevice8Impl_EndScene(LPDIRECT3DDEVICE8 iface) {
1067 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1069 TRACE("(%p) Relay\n" , This);
1071 wined3d_mutex_lock();
1072 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
1073 wined3d_mutex_unlock();
1078 static HRESULT WINAPI IDirect3DDevice8Impl_Clear(LPDIRECT3DDEVICE8 iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
1079 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1081 TRACE("(%p) Relay\n" , This);
1083 /* Note: D3DRECT is compatible with WINED3DRECT */
1084 wined3d_mutex_lock();
1085 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (CONST WINED3DRECT*) pRects, Flags, Color, Z, Stencil);
1086 wined3d_mutex_unlock();
1091 static HRESULT WINAPI IDirect3DDevice8Impl_SetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
1092 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1094 TRACE("(%p) Relay\n" , This);
1096 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1097 wined3d_mutex_lock();
1098 hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
1099 wined3d_mutex_unlock();
1104 static HRESULT WINAPI IDirect3DDevice8Impl_GetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State,D3DMATRIX* pMatrix) {
1105 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1107 TRACE("(%p) Relay\n" , This);
1109 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1110 wined3d_mutex_lock();
1111 hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
1112 wined3d_mutex_unlock();
1117 static HRESULT WINAPI IDirect3DDevice8Impl_MultiplyTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
1118 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1120 TRACE("(%p) Relay\n" , This);
1122 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1123 wined3d_mutex_lock();
1124 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
1125 wined3d_mutex_unlock();
1130 static HRESULT WINAPI IDirect3DDevice8Impl_SetViewport(LPDIRECT3DDEVICE8 iface, CONST D3DVIEWPORT8* pViewport) {
1131 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1133 TRACE("(%p) Relay\n" , This);
1135 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1136 wined3d_mutex_lock();
1137 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
1138 wined3d_mutex_unlock();
1143 static HRESULT WINAPI IDirect3DDevice8Impl_GetViewport(LPDIRECT3DDEVICE8 iface, D3DVIEWPORT8* pViewport) {
1144 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1146 TRACE("(%p) Relay\n" , This);
1148 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1149 wined3d_mutex_lock();
1150 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
1151 wined3d_mutex_unlock();
1156 static HRESULT WINAPI IDirect3DDevice8Impl_SetMaterial(LPDIRECT3DDEVICE8 iface, CONST D3DMATERIAL8* pMaterial) {
1157 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1159 TRACE("(%p) Relay\n" , This);
1161 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1162 wined3d_mutex_lock();
1163 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
1164 wined3d_mutex_unlock();
1169 static HRESULT WINAPI IDirect3DDevice8Impl_GetMaterial(LPDIRECT3DDEVICE8 iface, D3DMATERIAL8* pMaterial) {
1170 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1172 TRACE("(%p) Relay\n" , This);
1174 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1175 wined3d_mutex_lock();
1176 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
1177 wined3d_mutex_unlock();
1182 static HRESULT WINAPI IDirect3DDevice8Impl_SetLight(LPDIRECT3DDEVICE8 iface, DWORD Index, CONST D3DLIGHT8* pLight) {
1183 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1185 TRACE("(%p) Relay\n" , This);
1187 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1188 wined3d_mutex_lock();
1189 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
1190 wined3d_mutex_unlock();
1195 static HRESULT WINAPI IDirect3DDevice8Impl_GetLight(LPDIRECT3DDEVICE8 iface, DWORD Index,D3DLIGHT8* pLight) {
1196 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1198 TRACE("(%p) Relay\n" , This);
1200 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1201 wined3d_mutex_lock();
1202 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1203 wined3d_mutex_unlock();
1208 static HRESULT WINAPI IDirect3DDevice8Impl_LightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL Enable) {
1209 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1211 TRACE("(%p) Relay\n" , This);
1213 wined3d_mutex_lock();
1214 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1215 wined3d_mutex_unlock();
1220 static HRESULT WINAPI IDirect3DDevice8Impl_GetLightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL* pEnable) {
1221 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1223 TRACE("(%p) Relay\n" , This);
1225 wined3d_mutex_lock();
1226 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1227 wined3d_mutex_unlock();
1232 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,CONST float* pPlane) {
1233 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1235 TRACE("(%p) Relay\n" , This);
1237 wined3d_mutex_lock();
1238 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1239 wined3d_mutex_unlock();
1244 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,float* pPlane) {
1245 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1247 TRACE("(%p) Relay\n" , This);
1249 wined3d_mutex_lock();
1250 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1251 wined3d_mutex_unlock();
1256 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD Value) {
1257 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1259 TRACE("(%p) Relay\n" , This);
1261 wined3d_mutex_lock();
1262 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1263 wined3d_mutex_unlock();
1268 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD* pValue) {
1269 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1271 TRACE("(%p) Relay\n" , This);
1273 wined3d_mutex_lock();
1274 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1275 wined3d_mutex_unlock();
1280 static HRESULT WINAPI IDirect3DDevice8Impl_BeginStateBlock(LPDIRECT3DDEVICE8 iface) {
1281 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1283 TRACE("(%p)\n", This);
1285 wined3d_mutex_lock();
1286 hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
1287 wined3d_mutex_unlock();
1292 static HRESULT WINAPI IDirect3DDevice8Impl_EndStateBlock(LPDIRECT3DDEVICE8 iface, DWORD* pToken) {
1293 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1295 IWineD3DStateBlock* wineD3DStateBlock;
1296 IDirect3DStateBlock8Impl* object;
1298 TRACE("(%p) Relay\n", This);
1300 /* Tell wineD3D to endstateblock before anything else (in case we run out
1301 * of memory later and cause locking problems)
1303 wined3d_mutex_lock();
1304 hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice , &wineD3DStateBlock);
1306 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
1307 wined3d_mutex_unlock();
1311 /* allocate a new IDirectD3DStateBlock */
1312 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY ,sizeof(IDirect3DStateBlock8Impl));
1314 object->lpVtbl = &Direct3DStateBlock8_Vtbl;
1316 object->wineD3DStateBlock = wineD3DStateBlock;
1318 *pToken = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_SB);
1319 wined3d_mutex_unlock();
1321 if (*pToken == D3D8_INVALID_HANDLE)
1323 ERR("Failed to create a handle\n");
1324 IDirect3DStateBlock8_Release((IDirect3DStateBlock8 *)object);
1329 TRACE("Returning %#x (%p).\n", *pToken, object);
1334 static HRESULT WINAPI IDirect3DDevice8Impl_ApplyStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1335 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1336 IDirect3DStateBlock8Impl *pSB;
1339 TRACE("(%p) %#x Relay\n", This, Token);
1341 wined3d_mutex_lock();
1342 pSB = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1345 WARN("Invalid handle (%#x) passed.\n", Token);
1346 wined3d_mutex_unlock();
1347 return D3DERR_INVALIDCALL;
1349 hr = IWineD3DStateBlock_Apply(pSB->wineD3DStateBlock);
1350 wined3d_mutex_unlock();
1355 static HRESULT WINAPI IDirect3DDevice8Impl_CaptureStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1356 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1357 IDirect3DStateBlock8Impl *pSB;
1360 TRACE("(%p) %#x Relay\n", This, Token);
1362 wined3d_mutex_lock();
1363 pSB = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1366 WARN("Invalid handle (%#x) passed.\n", Token);
1367 wined3d_mutex_unlock();
1368 return D3DERR_INVALIDCALL;
1370 hr = IWineD3DStateBlock_Capture(pSB->wineD3DStateBlock);
1371 wined3d_mutex_unlock();
1376 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1377 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1378 IDirect3DStateBlock8Impl *pSB;
1380 TRACE("(%p) Relay\n", This);
1382 wined3d_mutex_lock();
1383 pSB = d3d8_free_handle(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1384 wined3d_mutex_unlock();
1388 WARN("Invalid handle (%#x) passed.\n", Token);
1389 return D3DERR_INVALIDCALL;
1392 if (IUnknown_Release((IUnknown *)pSB))
1394 ERR("Stateblock %p has references left, this shouldn't happen.\n", pSB);
1400 static HRESULT WINAPI IDirect3DDevice8Impl_CreateStateBlock(IDirect3DDevice8 *iface,
1401 D3DSTATEBLOCKTYPE Type, DWORD *handle)
1403 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1404 IDirect3DStateBlock8Impl *object;
1407 TRACE("(%p) Relay\n", This);
1409 if (Type != D3DSBT_ALL
1410 && Type != D3DSBT_PIXELSTATE
1411 && Type != D3DSBT_VERTEXSTATE)
1413 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1414 return D3DERR_INVALIDCALL;
1417 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DStateBlock8Impl));
1420 ERR("Failed to allocate memory.\n");
1421 return E_OUTOFMEMORY;
1424 object->lpVtbl = &Direct3DStateBlock8_Vtbl;
1427 wined3d_mutex_lock();
1428 hr = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type,
1429 &object->wineD3DStateBlock, (IUnknown *)object);
1432 wined3d_mutex_unlock();
1433 ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr);
1434 HeapFree(GetProcessHeap(), 0, object);
1438 *handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_SB);
1439 wined3d_mutex_unlock();
1441 if (*handle == D3D8_INVALID_HANDLE)
1443 ERR("Failed to allocate a handle.\n");
1444 IDirect3DStateBlock8_Release((IDirect3DStateBlock8 *)object);
1449 TRACE("Returning %#x (%p).\n", *handle, object);
1454 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipStatus(LPDIRECT3DDEVICE8 iface, CONST D3DCLIPSTATUS8* pClipStatus) {
1455 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1457 TRACE("(%p) Relay\n" , This);
1458 /* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
1460 wined3d_mutex_lock();
1461 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1462 wined3d_mutex_unlock();
1467 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipStatus(LPDIRECT3DDEVICE8 iface, D3DCLIPSTATUS8* pClipStatus) {
1468 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1470 TRACE("(%p) Relay\n" , This);
1472 wined3d_mutex_lock();
1473 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1474 wined3d_mutex_unlock();
1479 static HRESULT WINAPI IDirect3DDevice8Impl_GetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage,IDirect3DBaseTexture8** ppTexture) {
1480 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1481 IWineD3DBaseTexture *retTexture = NULL;
1482 HRESULT rc = D3D_OK;
1484 TRACE("(%p) Relay\n" , This);
1486 if(ppTexture == NULL){
1487 return D3DERR_INVALIDCALL;
1490 wined3d_mutex_lock();
1491 rc = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
1492 if (rc == D3D_OK && NULL != retTexture) {
1493 IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
1494 IWineD3DBaseTexture_Release(retTexture);
1496 FIXME("Call to get texture (%d) failed (%p)\n", Stage, retTexture);
1499 wined3d_mutex_unlock();
1504 static HRESULT WINAPI IDirect3DDevice8Impl_SetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage, IDirect3DBaseTexture8* pTexture) {
1505 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1507 TRACE("(%p) Relay %d %p\n" , This, Stage, pTexture);
1509 wined3d_mutex_lock();
1510 hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
1511 pTexture==NULL ? NULL : ((IDirect3DBaseTexture8Impl *)pTexture)->wineD3DBaseTexture);
1512 wined3d_mutex_unlock();
1517 static const struct tss_lookup
1524 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 0, unused */
1525 {FALSE, WINED3DTSS_COLOROP}, /* 1, D3DTSS_COLOROP */
1526 {FALSE, WINED3DTSS_COLORARG1}, /* 2, D3DTSS_COLORARG1 */
1527 {FALSE, WINED3DTSS_COLORARG2}, /* 3, D3DTSS_COLORARG2 */
1528 {FALSE, WINED3DTSS_ALPHAOP}, /* 4, D3DTSS_ALPHAOP */
1529 {FALSE, WINED3DTSS_ALPHAARG1}, /* 5, D3DTSS_ALPHAARG1 */
1530 {FALSE, WINED3DTSS_ALPHAARG2}, /* 6, D3DTSS_ALPHAARG2 */
1531 {FALSE, WINED3DTSS_BUMPENVMAT00}, /* 7, D3DTSS_BUMPENVMAT00 */
1532 {FALSE, WINED3DTSS_BUMPENVMAT01}, /* 8, D3DTSS_BUMPENVMAT01 */
1533 {FALSE, WINED3DTSS_BUMPENVMAT10}, /* 9, D3DTSS_BUMPENVMAT10 */
1534 {FALSE, WINED3DTSS_BUMPENVMAT11}, /* 10, D3DTSS_BUMPENVMAT11 */
1535 {FALSE, WINED3DTSS_TEXCOORDINDEX}, /* 11, D3DTSS_TEXCOORDINDEX */
1536 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 12, unused */
1537 {TRUE, WINED3DSAMP_ADDRESSU}, /* 13, D3DTSS_ADDRESSU */
1538 {TRUE, WINED3DSAMP_ADDRESSV}, /* 14, D3DTSS_ADDRESSV */
1539 {TRUE, WINED3DSAMP_BORDERCOLOR}, /* 15, D3DTSS_BORDERCOLOR */
1540 {TRUE, WINED3DSAMP_MAGFILTER}, /* 16, D3DTSS_MAGFILTER */
1541 {TRUE, WINED3DSAMP_MINFILTER}, /* 17, D3DTSS_MINFILTER */
1542 {TRUE, WINED3DSAMP_MIPFILTER}, /* 18, D3DTSS_MIPFILTER */
1543 {TRUE, WINED3DSAMP_MIPMAPLODBIAS}, /* 19, D3DTSS_MIPMAPLODBIAS */
1544 {TRUE, WINED3DSAMP_MAXMIPLEVEL}, /* 20, D3DTSS_MAXMIPLEVEL */
1545 {TRUE, WINED3DSAMP_MAXANISOTROPY}, /* 21, D3DTSS_MAXANISOTROPY */
1546 {FALSE, WINED3DTSS_BUMPENVLSCALE}, /* 22, D3DTSS_BUMPENVLSCALE */
1547 {FALSE, WINED3DTSS_BUMPENVLOFFSET}, /* 23, D3DTSS_BUMPENVLOFFSET */
1548 {FALSE, WINED3DTSS_TEXTURETRANSFORMFLAGS}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1549 {TRUE, WINED3DSAMP_ADDRESSW}, /* 25, D3DTSS_ADDRESSW */
1550 {FALSE, WINED3DTSS_COLORARG0}, /* 26, D3DTSS_COLORARG0 */
1551 {FALSE, WINED3DTSS_ALPHAARG0}, /* 27, D3DTSS_ALPHAARG0 */
1552 {FALSE, WINED3DTSS_RESULTARG}, /* 28, D3DTSS_RESULTARG */
1555 static HRESULT WINAPI IDirect3DDevice8Impl_GetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD* pValue) {
1556 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1557 const struct tss_lookup *l = &tss_lookup[Type];
1559 TRACE("(%p) Relay\n" , This);
1561 wined3d_mutex_lock();
1562 if (l->sampler_state) hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Stage, l->state, pValue);
1563 else hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, l->state, pValue);
1564 wined3d_mutex_unlock();
1569 static HRESULT WINAPI IDirect3DDevice8Impl_SetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
1570 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1571 const struct tss_lookup *l = &tss_lookup[Type];
1573 TRACE("(%p) Relay\n" , This);
1575 wined3d_mutex_lock();
1576 if (l->sampler_state) hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Stage, l->state, Value);
1577 else hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, l->state, Value);
1578 wined3d_mutex_unlock();
1583 static HRESULT WINAPI IDirect3DDevice8Impl_ValidateDevice(LPDIRECT3DDEVICE8 iface, DWORD* pNumPasses) {
1584 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1586 TRACE("(%p) Relay\n" , This);
1588 wined3d_mutex_lock();
1589 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1590 wined3d_mutex_unlock();
1595 static HRESULT WINAPI IDirect3DDevice8Impl_GetInfo(LPDIRECT3DDEVICE8 iface, DWORD DevInfoID, void* pDevInfoStruct, DWORD DevInfoStructSize) {
1596 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1597 FIXME("(%p) : stub\n", This);
1601 static HRESULT WINAPI IDirect3DDevice8Impl_SetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, CONST PALETTEENTRY* pEntries) {
1602 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1604 TRACE("(%p) Relay\n" , This);
1606 wined3d_mutex_lock();
1607 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1608 wined3d_mutex_unlock();
1613 static HRESULT WINAPI IDirect3DDevice8Impl_GetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
1614 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1616 TRACE("(%p) Relay\n" , This);
1618 wined3d_mutex_lock();
1619 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1620 wined3d_mutex_unlock();
1625 static HRESULT WINAPI IDirect3DDevice8Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber) {
1626 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1628 TRACE("(%p) Relay\n" , This);
1630 wined3d_mutex_lock();
1631 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1632 wined3d_mutex_unlock();
1637 static HRESULT WINAPI IDirect3DDevice8Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT *PaletteNumber) {
1638 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1640 TRACE("(%p) Relay\n" , This);
1642 wined3d_mutex_lock();
1643 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1644 wined3d_mutex_unlock();
1649 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitive(IDirect3DDevice8 *iface, D3DPRIMITIVETYPE PrimitiveType,
1650 UINT StartVertex, UINT PrimitiveCount)
1652 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1654 TRACE("(%p) Relay\n" , This);
1656 wined3d_mutex_lock();
1657 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1658 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
1659 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
1660 wined3d_mutex_unlock();
1665 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,
1666 UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount) {
1667 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1669 TRACE("(%p) Relay\n" , This);
1671 wined3d_mutex_lock();
1672 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1673 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, startIndex,
1674 vertex_count_from_primitive_count(PrimitiveType, primCount));
1675 wined3d_mutex_unlock();
1680 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT PrimitiveCount,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride) {
1681 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1683 TRACE("(%p) Relay\n" , This);
1685 wined3d_mutex_lock();
1686 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1687 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
1688 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
1689 pVertexStreamZeroData, VertexStreamZeroStride);
1690 wined3d_mutex_unlock();
1695 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,
1696 UINT NumVertexIndices,UINT PrimitiveCount,CONST void* pIndexData,
1697 D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,
1698 UINT VertexStreamZeroStride) {
1699 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1701 TRACE("(%p) Relay\n" , This);
1703 wined3d_mutex_lock();
1704 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1705 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice,
1706 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
1707 wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
1708 wined3d_mutex_unlock();
1713 static HRESULT WINAPI IDirect3DDevice8Impl_ProcessVertices(LPDIRECT3DDEVICE8 iface, UINT SrcStartIndex,UINT DestIndex,UINT VertexCount,IDirect3DVertexBuffer8* pDestBuffer,DWORD Flags) {
1714 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1716 IDirect3DVertexBuffer8Impl *dest = (IDirect3DVertexBuffer8Impl *) pDestBuffer;
1717 TRACE("(%p) Relay\n" , This);
1719 wined3d_mutex_lock();
1720 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, NULL, Flags, dest->fvf);
1721 wined3d_mutex_unlock();
1726 static HRESULT IDirect3DDevice8Impl_CreateVertexDeclaration(IDirect3DDevice8 *iface, CONST DWORD *declaration, IDirect3DVertexDeclaration8 **decl_ptr) {
1727 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1728 IDirect3DVertexDeclaration8Impl *object;
1729 WINED3DVERTEXELEMENT *wined3d_elements;
1730 UINT wined3d_element_count;
1731 HRESULT hr = D3D_OK;
1733 TRACE("(%p) : declaration %p\n", This, declaration);
1735 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1737 ERR("Memory allocation failed\n");
1739 return D3DERR_OUTOFVIDEOMEMORY;
1742 object->ref_count = 1;
1743 object->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
1745 wined3d_element_count = convert_to_wined3d_declaration(declaration, &object->elements_size, &wined3d_elements);
1746 object->elements = HeapAlloc(GetProcessHeap(), 0, object->elements_size);
1747 if (!object->elements) {
1748 ERR("Memory allocation failed\n");
1749 HeapFree(GetProcessHeap(), 0, wined3d_elements);
1750 HeapFree(GetProcessHeap(), 0, object);
1752 return D3DERR_OUTOFVIDEOMEMORY;
1755 CopyMemory(object->elements, declaration, object->elements_size);
1757 wined3d_mutex_lock();
1758 hr = IWineD3DDevice_CreateVertexDeclaration(This->WineD3DDevice, &object->wined3d_vertex_declaration,
1759 (IUnknown *)object, wined3d_elements, wined3d_element_count);
1760 wined3d_mutex_unlock();
1762 HeapFree(GetProcessHeap(), 0, wined3d_elements);
1765 ERR("(%p) : IWineD3DDevice_CreateVertexDeclaration call failed\n", This);
1766 HeapFree(GetProcessHeap(), 0, object->elements);
1767 HeapFree(GetProcessHeap(), 0, object);
1769 *decl_ptr = (IDirect3DVertexDeclaration8 *)object;
1770 TRACE("(%p) : Created vertex declaration %p\n", This, object);
1776 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pDeclaration, CONST DWORD* pFunction, DWORD* ppShader, DWORD Usage) {
1777 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1778 HRESULT hrc = D3D_OK;
1779 IDirect3DVertexShader8Impl *object;
1780 const DWORD *token = pDeclaration;
1783 /* Test if the vertex declaration is valid */
1784 while (D3DVSD_END() != *token) {
1785 D3DVSD_TOKENTYPE token_type = ((*token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT);
1787 if (token_type == D3DVSD_TOKEN_STREAMDATA && !(token_type & 0x10000000)) {
1788 DWORD type = ((*token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
1789 DWORD reg = ((*token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
1791 if(reg == D3DVSDE_NORMAL && type != D3DVSDT_FLOAT3 && !pFunction) {
1792 WARN("Attempt to use a non-FLOAT3 normal with the fixed function function\n");
1793 return D3DERR_INVALIDCALL;
1796 token += parse_token(token);
1799 /* Setup a stub object for now */
1800 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1801 TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
1802 if (NULL == object) {
1803 FIXME("Allocation of memory failed\n");
1805 return D3DERR_OUTOFVIDEOMEMORY;
1809 object->lpVtbl = &Direct3DVertexShader8_Vtbl;
1811 hrc = IDirect3DDevice8Impl_CreateVertexDeclaration(iface, pDeclaration, &object->vertex_declaration);
1813 ERR("(%p) : IDirect3DDeviceImpl_CreateVertexDeclaration call failed\n", This);
1814 HeapFree(GetProcessHeap(), 0, object);
1816 return D3DERR_INVALIDCALL;
1819 wined3d_mutex_lock();
1820 handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_VS);
1821 if (handle == D3D8_INVALID_HANDLE)
1823 ERR("Failed to allocate shader handle\n");
1824 wined3d_mutex_unlock();
1825 IDirect3DVertexDeclaration8_Release(object->vertex_declaration);
1826 HeapFree(GetProcessHeap(), 0, object);
1828 return E_OUTOFMEMORY;
1832 DWORD shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
1833 *ppShader = ((IDirect3DVertexDeclaration8Impl *)object->vertex_declaration)->shader_handle = shader_handle;
1838 /* Usage is missing ... Use SetRenderState to set the sw vp render state in SetVertexShader */
1839 hrc = IWineD3DDevice_CreateVertexShader(This->WineD3DDevice, pFunction,
1840 NULL /* output signature */, &object->wineD3DVertexShader, (IUnknown *)object);
1844 /* free up object */
1845 FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n");
1846 d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_VS);
1847 IDirect3DVertexDeclaration8_Release(object->vertex_declaration);
1848 HeapFree(GetProcessHeap(), 0, object);
1853 load_local_constants(pDeclaration, object->wineD3DVertexShader);
1854 TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
1858 wined3d_mutex_unlock();
1863 static IDirect3DVertexDeclaration8Impl *IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl *This, DWORD fvf)
1865 IDirect3DVertexDeclaration8Impl *d3d8_declaration;
1867 int p, low, high; /* deliberately signed */
1868 struct FvfToDecl *convertedDecls = This->decls;
1870 TRACE("Searching for declaration for fvf %08x... ", fvf);
1873 high = This->numConvertedDecls - 1;
1874 while(low <= high) {
1875 p = (low + high) >> 1;
1877 if(convertedDecls[p].fvf == fvf) {
1878 TRACE("found %p\n", convertedDecls[p].decl);
1879 return (IDirect3DVertexDeclaration8Impl *)convertedDecls[p].decl;
1880 } else if(convertedDecls[p].fvf < fvf) {
1886 TRACE("not found. Creating and inserting at position %d.\n", low);
1888 d3d8_declaration = HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration));
1889 if (!d3d8_declaration)
1891 ERR("Memory allocation failed.\n");
1895 d3d8_declaration->ref_count = 1;
1896 d3d8_declaration->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
1897 d3d8_declaration->elements = NULL;
1898 d3d8_declaration->elements_size = 0;
1899 d3d8_declaration->shader_handle = fvf;
1901 hr = IWineD3DDevice_CreateVertexDeclarationFromFVF(This->WineD3DDevice,
1902 &d3d8_declaration->wined3d_vertex_declaration, (IUnknown *)d3d8_declaration, fvf);
1905 ERR("Failed to create wined3d vertex declaration.\n");
1906 HeapFree(GetProcessHeap(), 0, d3d8_declaration);
1910 if(This->declArraySize == This->numConvertedDecls) {
1911 int grow = This->declArraySize / 2;
1912 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
1913 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
1914 if(!convertedDecls) {
1915 /* This will destroy it */
1916 IDirect3DVertexDeclaration8_Release((IDirect3DVertexDeclaration8 *)d3d8_declaration);
1919 This->decls = convertedDecls;
1920 This->declArraySize += grow;
1923 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(convertedDecls[0]) * (This->numConvertedDecls - low));
1924 convertedDecls[low].decl = (IDirect3DVertexDeclaration8 *)d3d8_declaration;
1925 convertedDecls[low].fvf = fvf;
1926 This->numConvertedDecls++;
1928 TRACE("Returning %p. %u decls in array\n", d3d8_declaration, This->numConvertedDecls);
1929 return d3d8_declaration;
1932 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1933 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1934 IDirect3DVertexShader8Impl *shader;
1937 TRACE("(%p) : Relay\n", This);
1939 if (VS_HIGHESTFIXEDFXF >= pShader) {
1940 TRACE("Setting FVF, %#x\n", pShader);
1942 wined3d_mutex_lock();
1943 IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
1944 IDirect3DDevice8Impl_FindDecl(This, pShader)->wined3d_vertex_declaration);
1945 IWineD3DDevice_SetVertexShader(This->WineD3DDevice, NULL);
1946 wined3d_mutex_unlock();
1951 TRACE("Setting shader\n");
1953 wined3d_mutex_lock();
1954 shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
1957 WARN("Invalid handle (%#x) passed.\n", pShader);
1958 wined3d_mutex_unlock();
1960 return D3DERR_INVALIDCALL;
1963 hr = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
1964 ((IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration)->wined3d_vertex_declaration);
1965 if (SUCCEEDED(hr)) hr = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, shader->wineD3DVertexShader);
1966 wined3d_mutex_unlock();
1968 TRACE("Returning hr %#x\n", hr);
1973 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
1974 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1975 IWineD3DVertexDeclaration *wined3d_declaration;
1976 IDirect3DVertexDeclaration8 *d3d8_declaration;
1979 TRACE("(%p) : Relay device@%p\n", This, This->WineD3DDevice);
1981 wined3d_mutex_lock();
1982 hrc = IWineD3DDevice_GetVertexDeclaration(This->WineD3DDevice, &wined3d_declaration);
1985 wined3d_mutex_unlock();
1986 WARN("(%p) : Call to IWineD3DDevice_GetVertexDeclaration failed %#x (device %p)\n",
1987 This, hrc, This->WineD3DDevice);
1991 if (!wined3d_declaration)
1993 wined3d_mutex_unlock();
1998 hrc = IWineD3DVertexDeclaration_GetParent(wined3d_declaration, (IUnknown **)&d3d8_declaration);
1999 IWineD3DVertexDeclaration_Release(wined3d_declaration);
2000 wined3d_mutex_unlock();
2003 *ppShader = ((IDirect3DVertexDeclaration8Impl *)d3d8_declaration)->shader_handle;
2004 IDirect3DVertexDeclaration8_Release(d3d8_declaration);
2007 TRACE("(%p) : returning %#x\n", This, *ppShader);
2012 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
2013 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2014 IDirect3DVertexShader8Impl *shader;
2015 IWineD3DVertexShader *cur = NULL;
2017 TRACE("(%p) : pShader %#x\n", This, pShader);
2019 wined3d_mutex_lock();
2020 shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2023 WARN("Invalid handle (%#x) passed.\n", pShader);
2024 wined3d_mutex_unlock();
2026 return D3DERR_INVALIDCALL;
2029 IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &cur);
2033 if (cur == shader->wineD3DVertexShader) IDirect3DDevice8_SetVertexShader(iface, 0);
2034 IWineD3DVertexShader_Release(cur);
2037 wined3d_mutex_unlock();
2039 if (IUnknown_Release((IUnknown *)shader))
2041 ERR("Shader %p has references left, this shouldn't happen.\n", shader);
2047 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
2048 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2050 TRACE("(%p) : Relay\n", This);
2052 if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
2053 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2054 Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2055 return D3DERR_INVALIDCALL;
2058 wined3d_mutex_lock();
2059 hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2060 wined3d_mutex_unlock();
2065 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
2066 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2068 TRACE("(%p) : Relay\n", This);
2070 if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
2071 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2072 Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2073 return D3DERR_INVALIDCALL;
2076 wined3d_mutex_lock();
2077 hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2078 wined3d_mutex_unlock();
2083 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderDeclaration(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
2084 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2085 IDirect3DVertexDeclaration8Impl *declaration;
2086 IDirect3DVertexShader8Impl *shader;
2088 TRACE("(%p) : pVertexShader 0x%08x, pData %p, *pSizeOfData %u\n", This, pVertexShader, pData, *pSizeOfData);
2090 wined3d_mutex_lock();
2091 shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2092 wined3d_mutex_unlock();
2096 WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2097 return D3DERR_INVALIDCALL;
2099 declaration = (IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration;
2101 /* If pData is NULL, we just return the required size of the buffer. */
2103 *pSizeOfData = declaration->elements_size;
2107 /* MSDN claims that if *pSizeOfData is smaller than the required size
2108 * we should write the required size and return D3DERR_MOREDATA.
2109 * That's not actually true. */
2110 if (*pSizeOfData < declaration->elements_size) {
2111 return D3DERR_INVALIDCALL;
2114 CopyMemory(pData, declaration->elements, declaration->elements_size);
2119 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
2120 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2121 IDirect3DVertexShader8Impl *shader = NULL;
2124 TRACE("(%p) : pVertexShader %#x, pData %p, pSizeOfData %p\n", This, pVertexShader, pData, pSizeOfData);
2126 wined3d_mutex_lock();
2127 shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2130 WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2131 wined3d_mutex_unlock();
2133 return D3DERR_INVALIDCALL;
2136 if (!shader->wineD3DVertexShader)
2138 wined3d_mutex_unlock();
2143 hr = IWineD3DVertexShader_GetFunction(shader->wineD3DVertexShader, pData, pSizeOfData);
2144 wined3d_mutex_unlock();
2149 static HRESULT WINAPI IDirect3DDevice8Impl_SetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8* pIndexData, UINT baseVertexIndex) {
2150 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2152 IDirect3DIndexBuffer8Impl *ib = (IDirect3DIndexBuffer8Impl *)pIndexData;
2153 TRACE("(%p) Relay\n", This);
2155 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
2156 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
2157 * vertex buffers can't be created to address them with an index that requires the 32nd bit
2158 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
2161 wined3d_mutex_lock();
2162 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, baseVertexIndex);
2163 hr = IWineD3DDevice_SetIndices(This->WineD3DDevice,
2164 ib ? ib->wineD3DIndexBuffer : NULL,
2165 ib ? ib->format : WINED3DFMT_UNKNOWN);
2166 wined3d_mutex_unlock();
2171 static HRESULT WINAPI IDirect3DDevice8Impl_GetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8** ppIndexData,UINT* pBaseVertexIndex) {
2172 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2173 IWineD3DBuffer *retIndexData = NULL;
2174 HRESULT rc = D3D_OK;
2176 TRACE("(%p) Relay\n", This);
2178 if(ppIndexData == NULL){
2179 return D3DERR_INVALIDCALL;
2182 /* The case from UINT to INT is safe because d3d8 will never set negative values */
2183 wined3d_mutex_lock();
2184 IWineD3DDevice_GetBaseVertexIndex(This->WineD3DDevice, (INT *) pBaseVertexIndex);
2185 rc = IWineD3DDevice_GetIndices(This->WineD3DDevice, &retIndexData);
2186 if (SUCCEEDED(rc) && retIndexData) {
2187 IWineD3DBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
2188 IWineD3DBuffer_Release(retIndexData);
2190 if (FAILED(rc)) FIXME("Call to GetIndices failed\n");
2191 *ppIndexData = NULL;
2193 wined3d_mutex_unlock();
2197 static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pFunction, DWORD* ppShader) {
2198 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2199 IDirect3DPixelShader8Impl *object;
2203 TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
2205 if (NULL == ppShader) {
2206 TRACE("(%p) Invalid call\n", This);
2207 return D3DERR_INVALIDCALL;
2210 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2213 ERR("Failed to allocate memmory.\n");
2214 return E_OUTOFMEMORY;
2218 object->lpVtbl = &Direct3DPixelShader8_Vtbl;
2220 wined3d_mutex_lock();
2221 hr = IWineD3DDevice_CreatePixelShader(This->WineD3DDevice, pFunction,
2222 NULL, &object->wineD3DPixelShader, (IUnknown *)object);
2225 wined3d_mutex_unlock();
2226 FIXME("(%p) call to IWineD3DDevice_CreatePixelShader failed\n", This);
2227 HeapFree(GetProcessHeap(), 0 , object);
2232 handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_PS);
2233 wined3d_mutex_unlock();
2235 if (handle == D3D8_INVALID_HANDLE)
2237 ERR("Failed to allocate shader handle\n");
2238 IDirect3DVertexShader8_Release((IUnknown *)object);
2239 return E_OUTOFMEMORY;
2242 *ppShader = object->handle = handle + VS_HIGHESTFIXEDFXF + 1;
2243 TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
2248 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
2249 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2250 IDirect3DPixelShader8Impl *shader;
2253 TRACE("(%p) : pShader %#x\n", This, pShader);
2255 wined3d_mutex_lock();
2259 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, NULL);
2260 wined3d_mutex_unlock();
2264 shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2267 WARN("Invalid handle (%#x) passed.\n", pShader);
2268 wined3d_mutex_unlock();
2269 return D3DERR_INVALIDCALL;
2272 TRACE("(%p) : Setting shader %p\n", This, shader);
2273 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, shader->wineD3DPixelShader);
2274 wined3d_mutex_unlock();
2279 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
2280 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2281 IWineD3DPixelShader *object;
2283 HRESULT hrc = D3D_OK;
2284 TRACE("(%p) Relay\n", This);
2285 if (NULL == ppShader) {
2286 TRACE("(%p) Invalid call\n", This);
2287 return D3DERR_INVALIDCALL;
2290 wined3d_mutex_lock();
2291 hrc = IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &object);
2292 if (D3D_OK == hrc && NULL != object) {
2293 IDirect3DPixelShader8Impl *d3d8_shader;
2294 hrc = IWineD3DPixelShader_GetParent(object, (IUnknown **)&d3d8_shader);
2295 IWineD3DPixelShader_Release(object);
2296 *ppShader = d3d8_shader->handle;
2297 IDirect3DPixelShader8_Release((IDirect3DPixelShader8 *)d3d8_shader);
2301 wined3d_mutex_unlock();
2303 TRACE("(%p) : returning %#x\n", This, *ppShader);
2308 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
2309 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2310 IDirect3DPixelShader8Impl *shader;
2311 IWineD3DPixelShader *cur = NULL;
2313 TRACE("(%p) : pShader %#x\n", This, pShader);
2315 wined3d_mutex_lock();
2317 shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2320 WARN("Invalid handle (%#x) passed.\n", pShader);
2321 wined3d_mutex_unlock();
2325 IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &cur);
2329 if (cur == shader->wineD3DPixelShader) IDirect3DDevice8_SetPixelShader(iface, 0);
2330 IWineD3DPixelShader_Release(cur);
2333 wined3d_mutex_unlock();
2335 if (IUnknown_Release((IUnknown *)shader))
2337 ERR("Shader %p has references left, this shouldn't happen.\n", shader);
2343 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
2344 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2346 TRACE("(%p) Relay\n", This);
2348 wined3d_mutex_lock();
2349 hr = IWineD3DDevice_SetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2350 wined3d_mutex_unlock();
2355 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
2356 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2358 TRACE("(%p) Relay\n", This);
2360 wined3d_mutex_lock();
2361 hr = IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2362 wined3d_mutex_unlock();
2367 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pPixelShader, void* pData, DWORD* pSizeOfData) {
2368 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2369 IDirect3DPixelShader8Impl *shader = NULL;
2372 TRACE("(%p) : pPixelShader %#x, pData %p, pSizeOfData %p\n", This, pPixelShader, pData, pSizeOfData);
2374 wined3d_mutex_lock();
2375 shader = d3d8_get_object(&This->handle_table, pPixelShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2378 WARN("Invalid handle (%#x) passed.\n", pPixelShader);
2379 wined3d_mutex_unlock();
2381 return D3DERR_INVALIDCALL;
2384 hr = IWineD3DPixelShader_GetFunction(shader->wineD3DPixelShader, pData, pSizeOfData);
2385 wined3d_mutex_unlock();
2390 static HRESULT WINAPI IDirect3DDevice8Impl_DrawRectPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
2391 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2393 TRACE("(%p) Relay\n", This);
2395 wined3d_mutex_lock();
2396 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
2397 wined3d_mutex_unlock();
2402 static HRESULT WINAPI IDirect3DDevice8Impl_DrawTriPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
2403 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2405 TRACE("(%p) Relay\n", This);
2407 wined3d_mutex_lock();
2408 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
2409 wined3d_mutex_unlock();
2414 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePatch(LPDIRECT3DDEVICE8 iface, UINT Handle) {
2415 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2417 TRACE("(%p) Relay\n", This);
2419 wined3d_mutex_lock();
2420 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
2421 wined3d_mutex_unlock();
2426 static HRESULT WINAPI IDirect3DDevice8Impl_SetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8* pStreamData,UINT Stride) {
2427 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2429 TRACE("(%p) Relay\n" , This);
2431 wined3d_mutex_lock();
2432 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
2433 NULL == pStreamData ? NULL : ((IDirect3DVertexBuffer8Impl *)pStreamData)->wineD3DVertexBuffer,
2434 0/* Offset in bytes */, Stride);
2435 wined3d_mutex_unlock();
2440 static HRESULT WINAPI IDirect3DDevice8Impl_GetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8** pStream,UINT* pStride) {
2441 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2442 IWineD3DBuffer *retStream = NULL;
2443 HRESULT rc = D3D_OK;
2445 TRACE("(%p) Relay\n" , This);
2447 if(pStream == NULL){
2448 return D3DERR_INVALIDCALL;
2451 wined3d_mutex_lock();
2452 rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, 0 /* Offset in bytes */, pStride);
2453 if (rc == D3D_OK && NULL != retStream) {
2454 IWineD3DBuffer_GetParent(retStream, (IUnknown **)pStream);
2455 IWineD3DBuffer_Release(retStream);
2458 FIXME("Call to GetStreamSource failed %p\n", pStride);
2462 wined3d_mutex_unlock();
2468 const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl =
2470 IDirect3DDevice8Impl_QueryInterface,
2471 IDirect3DDevice8Impl_AddRef,
2472 IDirect3DDevice8Impl_Release,
2473 IDirect3DDevice8Impl_TestCooperativeLevel,
2474 IDirect3DDevice8Impl_GetAvailableTextureMem,
2475 IDirect3DDevice8Impl_ResourceManagerDiscardBytes,
2476 IDirect3DDevice8Impl_GetDirect3D,
2477 IDirect3DDevice8Impl_GetDeviceCaps,
2478 IDirect3DDevice8Impl_GetDisplayMode,
2479 IDirect3DDevice8Impl_GetCreationParameters,
2480 IDirect3DDevice8Impl_SetCursorProperties,
2481 IDirect3DDevice8Impl_SetCursorPosition,
2482 IDirect3DDevice8Impl_ShowCursor,
2483 IDirect3DDevice8Impl_CreateAdditionalSwapChain,
2484 IDirect3DDevice8Impl_Reset,
2485 IDirect3DDevice8Impl_Present,
2486 IDirect3DDevice8Impl_GetBackBuffer,
2487 IDirect3DDevice8Impl_GetRasterStatus,
2488 IDirect3DDevice8Impl_SetGammaRamp,
2489 IDirect3DDevice8Impl_GetGammaRamp,
2490 IDirect3DDevice8Impl_CreateTexture,
2491 IDirect3DDevice8Impl_CreateVolumeTexture,
2492 IDirect3DDevice8Impl_CreateCubeTexture,
2493 IDirect3DDevice8Impl_CreateVertexBuffer,
2494 IDirect3DDevice8Impl_CreateIndexBuffer,
2495 IDirect3DDevice8Impl_CreateRenderTarget,
2496 IDirect3DDevice8Impl_CreateDepthStencilSurface,
2497 IDirect3DDevice8Impl_CreateImageSurface,
2498 IDirect3DDevice8Impl_CopyRects,
2499 IDirect3DDevice8Impl_UpdateTexture,
2500 IDirect3DDevice8Impl_GetFrontBuffer,
2501 IDirect3DDevice8Impl_SetRenderTarget,
2502 IDirect3DDevice8Impl_GetRenderTarget,
2503 IDirect3DDevice8Impl_GetDepthStencilSurface,
2504 IDirect3DDevice8Impl_BeginScene,
2505 IDirect3DDevice8Impl_EndScene,
2506 IDirect3DDevice8Impl_Clear,
2507 IDirect3DDevice8Impl_SetTransform,
2508 IDirect3DDevice8Impl_GetTransform,
2509 IDirect3DDevice8Impl_MultiplyTransform,
2510 IDirect3DDevice8Impl_SetViewport,
2511 IDirect3DDevice8Impl_GetViewport,
2512 IDirect3DDevice8Impl_SetMaterial,
2513 IDirect3DDevice8Impl_GetMaterial,
2514 IDirect3DDevice8Impl_SetLight,
2515 IDirect3DDevice8Impl_GetLight,
2516 IDirect3DDevice8Impl_LightEnable,
2517 IDirect3DDevice8Impl_GetLightEnable,
2518 IDirect3DDevice8Impl_SetClipPlane,
2519 IDirect3DDevice8Impl_GetClipPlane,
2520 IDirect3DDevice8Impl_SetRenderState,
2521 IDirect3DDevice8Impl_GetRenderState,
2522 IDirect3DDevice8Impl_BeginStateBlock,
2523 IDirect3DDevice8Impl_EndStateBlock,
2524 IDirect3DDevice8Impl_ApplyStateBlock,
2525 IDirect3DDevice8Impl_CaptureStateBlock,
2526 IDirect3DDevice8Impl_DeleteStateBlock,
2527 IDirect3DDevice8Impl_CreateStateBlock,
2528 IDirect3DDevice8Impl_SetClipStatus,
2529 IDirect3DDevice8Impl_GetClipStatus,
2530 IDirect3DDevice8Impl_GetTexture,
2531 IDirect3DDevice8Impl_SetTexture,
2532 IDirect3DDevice8Impl_GetTextureStageState,
2533 IDirect3DDevice8Impl_SetTextureStageState,
2534 IDirect3DDevice8Impl_ValidateDevice,
2535 IDirect3DDevice8Impl_GetInfo,
2536 IDirect3DDevice8Impl_SetPaletteEntries,
2537 IDirect3DDevice8Impl_GetPaletteEntries,
2538 IDirect3DDevice8Impl_SetCurrentTexturePalette,
2539 IDirect3DDevice8Impl_GetCurrentTexturePalette,
2540 IDirect3DDevice8Impl_DrawPrimitive,
2541 IDirect3DDevice8Impl_DrawIndexedPrimitive,
2542 IDirect3DDevice8Impl_DrawPrimitiveUP,
2543 IDirect3DDevice8Impl_DrawIndexedPrimitiveUP,
2544 IDirect3DDevice8Impl_ProcessVertices,
2545 IDirect3DDevice8Impl_CreateVertexShader,
2546 IDirect3DDevice8Impl_SetVertexShader,
2547 IDirect3DDevice8Impl_GetVertexShader,
2548 IDirect3DDevice8Impl_DeleteVertexShader,
2549 IDirect3DDevice8Impl_SetVertexShaderConstant,
2550 IDirect3DDevice8Impl_GetVertexShaderConstant,
2551 IDirect3DDevice8Impl_GetVertexShaderDeclaration,
2552 IDirect3DDevice8Impl_GetVertexShaderFunction,
2553 IDirect3DDevice8Impl_SetStreamSource,
2554 IDirect3DDevice8Impl_GetStreamSource,
2555 IDirect3DDevice8Impl_SetIndices,
2556 IDirect3DDevice8Impl_GetIndices,
2557 IDirect3DDevice8Impl_CreatePixelShader,
2558 IDirect3DDevice8Impl_SetPixelShader,
2559 IDirect3DDevice8Impl_GetPixelShader,
2560 IDirect3DDevice8Impl_DeletePixelShader,
2561 IDirect3DDevice8Impl_SetPixelShaderConstant,
2562 IDirect3DDevice8Impl_GetPixelShaderConstant,
2563 IDirect3DDevice8Impl_GetPixelShaderFunction,
2564 IDirect3DDevice8Impl_DrawRectPatch,
2565 IDirect3DDevice8Impl_DrawTriPatch,
2566 IDirect3DDevice8Impl_DeletePatch
2569 /* IWineD3DDeviceParent IUnknown methods */
2571 static inline struct IDirect3DDevice8Impl *device_from_device_parent(IWineD3DDeviceParent *iface)
2573 return (struct IDirect3DDevice8Impl *)((char*)iface
2574 - FIELD_OFFSET(struct IDirect3DDevice8Impl, device_parent_vtbl));
2577 static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface, REFIID riid, void **object)
2579 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2580 return IDirect3DDevice8Impl_QueryInterface((IDirect3DDevice8 *)This, riid, object);
2583 static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
2585 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2586 return IDirect3DDevice8Impl_AddRef((IDirect3DDevice8 *)This);
2589 static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
2591 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2592 return IDirect3DDevice8Impl_Release((IDirect3DDevice8 *)This);
2595 /* IWineD3DDeviceParent methods */
2597 static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
2599 TRACE("iface %p, device %p\n", iface, device);
2602 static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
2603 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, DWORD usage,
2604 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface)
2606 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2607 IDirect3DSurface8Impl *d3d_surface;
2608 BOOL lockable = TRUE;
2611 TRACE("iface %p, superior %p, width %u, height %u, format %#x, usage %#x,\n"
2612 "\tpool %#x, level %u, face %u, surface %p\n",
2613 iface, superior, width, height, format, usage, pool, level, face, surface);
2616 if (pool == WINED3DPOOL_DEFAULT && !(usage & WINED3DUSAGE_DYNAMIC)) lockable = FALSE;
2618 hr = IDirect3DDevice8Impl_CreateSurface((IDirect3DDevice8 *)This, width, height,
2619 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
2620 (IDirect3DSurface8 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
2623 ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
2627 *surface = d3d_surface->wineD3DSurface;
2628 IWineD3DSurface_AddRef(*surface);
2630 d3d_surface->container = superior;
2631 IUnknown_Release(d3d_surface->parentDevice);
2632 d3d_surface->parentDevice = NULL;
2634 IDirect3DSurface8_Release((IDirect3DSurface8 *)d3d_surface);
2635 d3d_surface->forwardReference = superior;
2640 static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
2641 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2642 DWORD multisample_quality, BOOL lockable, IWineD3DSurface **surface)
2644 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2645 IDirect3DSurface8Impl *d3d_surface;
2648 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2649 "\tmultisample_quality %u, lockable %u, surface %p\n",
2650 iface, superior, width, height, format, multisample_type, multisample_quality, lockable, surface);
2652 hr = IDirect3DDevice8_CreateRenderTarget((IDirect3DDevice8 *)This, width, height,
2653 d3dformat_from_wined3dformat(format), multisample_type, lockable, (IDirect3DSurface8 **)&d3d_surface);
2656 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
2660 *surface = d3d_surface->wineD3DSurface;
2661 IWineD3DSurface_AddRef(*surface);
2663 d3d_surface->container = (IUnknown *)This;
2664 /* Implicit surfaces are created with an refcount of 0 */
2665 IUnknown_Release((IUnknown *)d3d_surface);
2670 static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
2671 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2672 DWORD multisample_quality, BOOL discard, IWineD3DSurface **surface)
2674 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2675 IDirect3DSurface8Impl *d3d_surface;
2678 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2679 "\tmultisample_quality %u, discard %u, surface %p\n",
2680 iface, superior, width, height, format, multisample_type, multisample_quality, discard, surface);
2682 hr = IDirect3DDevice8_CreateDepthStencilSurface((IDirect3DDevice8 *)This, width, height,
2683 d3dformat_from_wined3dformat(format), multisample_type, (IDirect3DSurface8 **)&d3d_surface);
2686 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
2690 *surface = d3d_surface->wineD3DSurface;
2691 IWineD3DSurface_AddRef(*surface);
2693 d3d_surface->container = (IUnknown *)This;
2694 /* Implicit surfaces are created with an refcount of 0 */
2695 IUnknown_Release((IUnknown *)d3d_surface);
2700 static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
2701 IUnknown *superior, UINT width, UINT height, UINT depth, WINED3DFORMAT format,
2702 WINED3DPOOL pool, DWORD usage, IWineD3DVolume **volume)
2704 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2705 IDirect3DVolume8Impl *object;
2708 TRACE("iface %p, superior %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
2709 iface, superior, width, height, depth, format, pool, usage, volume);
2711 /* Allocate the storage for the device */
2712 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2715 FIXME("Allocation of memory failed\n");
2717 return D3DERR_OUTOFVIDEOMEMORY;
2720 hr = volume_init(object, This, width, height, depth, usage, format, pool);
2723 WARN("Failed to initialize volume, hr %#x.\n", hr);
2724 HeapFree(GetProcessHeap(), 0, object);
2728 *volume = object->wineD3DVolume;
2729 IWineD3DVolume_AddRef(*volume);
2730 IDirect3DVolume8_Release((IDirect3DVolume8 *)object);
2732 object->container = superior;
2733 object->forwardReference = superior;
2735 TRACE("(%p) Created volume %p\n", iface, object);
2740 static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
2741 WINED3DPRESENT_PARAMETERS *present_parameters, IWineD3DSwapChain **swapchain)
2743 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2744 IDirect3DSwapChain8Impl *d3d_swapchain;
2745 D3DPRESENT_PARAMETERS local_parameters;
2748 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
2750 /* Copy the presentation parameters */
2751 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
2752 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
2753 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
2754 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
2755 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
2756 local_parameters.SwapEffect = present_parameters->SwapEffect;
2757 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
2758 local_parameters.Windowed = present_parameters->Windowed;
2759 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
2760 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
2761 local_parameters.Flags = present_parameters->Flags;
2762 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
2763 local_parameters.FullScreen_PresentationInterval = present_parameters->PresentationInterval;
2765 hr = IDirect3DDevice8_CreateAdditionalSwapChain((IDirect3DDevice8 *)This,
2766 &local_parameters, (IDirect3DSwapChain8 **)&d3d_swapchain);
2769 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
2774 *swapchain = d3d_swapchain->wineD3DSwapChain;
2775 IUnknown_Release(d3d_swapchain->parentDevice);
2776 d3d_swapchain->parentDevice = NULL;
2778 /* Copy back the presentation parameters */
2779 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
2780 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
2781 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
2782 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
2783 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
2784 present_parameters->SwapEffect = local_parameters.SwapEffect;
2785 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
2786 present_parameters->Windowed = local_parameters.Windowed;
2787 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
2788 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
2789 present_parameters->Flags = local_parameters.Flags;
2790 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
2791 present_parameters->PresentationInterval = local_parameters.FullScreen_PresentationInterval;
2796 const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl =
2798 /* IUnknown methods */
2799 device_parent_QueryInterface,
2800 device_parent_AddRef,
2801 device_parent_Release,
2802 /* IWineD3DDeviceParent methods */
2803 device_parent_WineD3DDeviceCreated,
2804 device_parent_CreateSurface,
2805 device_parent_CreateRenderTarget,
2806 device_parent_CreateDepthStencilSurface,
2807 device_parent_CreateVolume,
2808 device_parent_CreateSwapChain,