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(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, UINT Levels, DWORD Usage,
658 D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture8 **ppTexture) {
659 IDirect3DTexture8Impl *object;
660 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
661 HRESULT hrc = D3D_OK;
663 TRACE("(%p) : W(%d) H(%d), Lvl(%d) d(%d), Fmt(%u), Pool(%d)\n", This, Width, Height, Levels, Usage, Format, Pool);
665 /* Allocate the storage for the device */
666 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DTexture8Impl));
668 if (NULL == object) {
669 FIXME("Allocation of memory failed\n");
670 /* *ppTexture = NULL; */
671 return D3DERR_OUTOFVIDEOMEMORY;
674 object->lpVtbl = &Direct3DTexture8_Vtbl;
677 wined3d_mutex_lock();
678 hrc = IWineD3DDevice_CreateTexture(This->WineD3DDevice, Width, Height, Levels, Usage & WINED3DUSAGE_MASK,
679 wined3dformat_from_d3dformat(Format), Pool, &object->wineD3DTexture, (IUnknown *)object);
680 wined3d_mutex_unlock();
684 FIXME("(%p) call to IWineD3DDevice_CreateTexture failed\n", This);
685 HeapFree(GetProcessHeap(), 0, object);
686 /* *ppTexture = NULL; */
688 IUnknown_AddRef(iface);
689 object->parentDevice = iface;
690 *ppTexture = (LPDIRECT3DTEXTURE8) object;
691 TRACE("(%p) Created Texture %p, %p\n",This,object,object->wineD3DTexture);
697 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVolumeTexture(IDirect3DDevice8 *iface,
698 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
699 D3DPOOL pool, IDirect3DVolumeTexture8 **texture)
701 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
702 IDirect3DVolumeTexture8Impl *object;
705 TRACE("iface %p, width %u, height %u, depth %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
706 iface, width, height, depth, levels, usage, format, pool, texture);
708 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
711 ERR("Failed to allocate volume texture memory.\n");
712 return D3DERR_OUTOFVIDEOMEMORY;
715 hr = volumetexture_init(object, This, width, height, depth, levels, usage, format, pool);
718 WARN("Failed to initialize volume texture, hr %#x.\n", hr);
719 HeapFree(GetProcessHeap(), 0, object);
723 TRACE("Created volume texture %p.\n", object);
724 *texture = (IDirect3DVolumeTexture8 *)object;
729 static HRESULT WINAPI IDirect3DDevice8Impl_CreateCubeTexture(IDirect3DDevice8 *iface, UINT EdgeLength,
730 UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DCubeTexture8 **ppCubeTexture)
732 IDirect3DCubeTexture8Impl *object;
733 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
736 TRACE("(%p) : ELen(%d) Lvl(%d) Usage(%d) fmt(%u), Pool(%d)\n" , This, EdgeLength, Levels, Usage, Format, Pool);
738 /* Allocate the storage for the device */
739 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
741 if (NULL == object) {
742 FIXME("(%p) allocation of CubeTexture failed\n", This);
743 *ppCubeTexture = NULL;
744 return D3DERR_OUTOFVIDEOMEMORY;
747 object->lpVtbl = &Direct3DCubeTexture8_Vtbl;
750 wined3d_mutex_lock();
751 hr = IWineD3DDevice_CreateCubeTexture(This->WineD3DDevice, EdgeLength, Levels, Usage & WINED3DUSAGE_MASK,
752 wined3dformat_from_d3dformat(Format), Pool, &object->wineD3DCubeTexture, (IUnknown *)object);
753 wined3d_mutex_unlock();
758 FIXME("(%p) call to IWineD3DDevice_CreateCubeTexture failed\n", This);
759 HeapFree(GetProcessHeap(), 0, object);
760 *ppCubeTexture = NULL;
762 IUnknown_AddRef(iface);
763 object->parentDevice = iface;
764 *ppCubeTexture = (LPDIRECT3DCUBETEXTURE8) object;
767 TRACE("(%p) returning %p\n",This, *ppCubeTexture);
771 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexBuffer(LPDIRECT3DDEVICE8 iface, UINT Size, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer8** ppVertexBuffer) {
772 IDirect3DVertexBuffer8Impl *object;
773 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
774 HRESULT hrc = D3D_OK;
776 TRACE("(%p) Relay\n", This);
777 /* Allocate the storage for the device */
778 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexBuffer8Impl));
779 if (NULL == object) {
780 FIXME("Allocation of memory failed\n");
781 *ppVertexBuffer = NULL;
782 return D3DERR_OUTOFVIDEOMEMORY;
785 object->lpVtbl = &Direct3DVertexBuffer8_Vtbl;
788 wined3d_mutex_lock();
789 hrc = IWineD3DDevice_CreateVertexBuffer(This->WineD3DDevice, Size, Usage & WINED3DUSAGE_MASK,
790 0 /* fvf for ddraw only */, (WINED3DPOOL)Pool, &object->wineD3DVertexBuffer, (IUnknown *)object);
791 wined3d_mutex_unlock();
798 FIXME("(%p) call to IWineD3DDevice_CreateVertexBuffer failed\n", This);
799 HeapFree(GetProcessHeap(), 0, object);
800 *ppVertexBuffer = NULL;
802 IUnknown_AddRef(iface);
803 object->parentDevice = iface;
804 *ppVertexBuffer = (LPDIRECT3DVERTEXBUFFER8) object;
809 static HRESULT WINAPI IDirect3DDevice8Impl_CreateIndexBuffer(LPDIRECT3DDEVICE8 iface, UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DIndexBuffer8** ppIndexBuffer) {
810 IDirect3DIndexBuffer8Impl *object;
811 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
812 HRESULT hrc = D3D_OK;
814 TRACE("(%p) Relay\n", This);
815 /* Allocate the storage for the device */
816 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
817 if (NULL == object) {
818 FIXME("Allocation of memory failed\n");
819 *ppIndexBuffer = NULL;
820 return D3DERR_OUTOFVIDEOMEMORY;
823 object->lpVtbl = &Direct3DIndexBuffer8_Vtbl;
825 object->format = wined3dformat_from_d3dformat(Format);
826 TRACE("Calling wined3d create index buffer\n");
828 wined3d_mutex_lock();
829 hrc = IWineD3DDevice_CreateIndexBuffer(This->WineD3DDevice, Length, Usage & WINED3DUSAGE_MASK,
830 (WINED3DPOOL)Pool, &object->wineD3DIndexBuffer, (IUnknown *)object);
831 wined3d_mutex_unlock();
836 FIXME("(%p) call to IWineD3DDevice_CreateIndexBuffer failed\n", This);
837 HeapFree(GetProcessHeap(), 0, object);
838 *ppIndexBuffer = NULL;
840 IUnknown_AddRef(iface);
841 object->parentDevice = iface;
842 *ppIndexBuffer = (LPDIRECT3DINDEXBUFFER8)object;
847 static HRESULT IDirect3DDevice8Impl_CreateSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height,
848 D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IDirect3DSurface8 **ppSurface,
849 UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality)
851 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
852 IDirect3DSurface8Impl *object;
855 TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
857 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface8Impl));
860 FIXME("Failed to allocate surface memory.\n");
861 return D3DERR_OUTOFVIDEOMEMORY;
864 hr = surface_init(object, This, Width, Height, Format, Lockable, Discard,
865 Level, Usage, Pool, MultiSample, MultisampleQuality);
868 WARN("Failed to initialize surface, hr %#x.\n", hr);
869 HeapFree(GetProcessHeap(), 0, object);
873 TRACE("Created surface %p.\n", object);
874 *ppSurface = (IDirect3DSurface8 *)object;
879 static HRESULT WINAPI IDirect3DDevice8Impl_CreateRenderTarget(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, BOOL Lockable, IDirect3DSurface8** ppSurface) {
883 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, Lockable, FALSE /* Discard */,
884 0 /* Level */, ppSurface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, MultiSample, 0);
889 static HRESULT WINAPI IDirect3DDevice8Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, IDirect3DSurface8** ppSurface) {
893 /* TODO: Verify that Discard is false */
894 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE,
895 0 /* Level */, ppSurface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, MultiSample, 0);
900 /* IDirect3DDevice8Impl::CreateImageSurface returns surface with pool type SYSTEMMEM */
901 static HRESULT WINAPI IDirect3DDevice8Impl_CreateImageSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, IDirect3DSurface8** ppSurface) {
905 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE /* Discard */,
906 0 /* Level */, ppSurface, 0 /* Usage (undefined/none) */, D3DPOOL_SYSTEMMEM, D3DMULTISAMPLE_NONE,
907 0 /* MultisampleQuality */);
912 static HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8 *pSourceSurface, CONST RECT *pSourceRects, UINT cRects, IDirect3DSurface8 *pDestinationSurface, CONST POINT *pDestPoints) {
913 IDirect3DSurface8Impl *Source = (IDirect3DSurface8Impl *) pSourceSurface;
914 IDirect3DSurface8Impl *Dest = (IDirect3DSurface8Impl *) pDestinationSurface;
916 HRESULT hr = WINED3D_OK;
917 WINED3DFORMAT srcFormat, destFormat;
918 UINT srcWidth, destWidth;
919 UINT srcHeight, destHeight;
921 WINED3DSURFACE_DESC winedesc;
923 TRACE("(%p) pSrcSur=%p, pSourceRects=%p, cRects=%d, pDstSur=%p, pDestPtsArr=%p\n", iface,
924 pSourceSurface, pSourceRects, cRects, pDestinationSurface, pDestPoints);
927 /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the destination texture is in WINED3DPOOL_DEFAULT */
929 wined3d_mutex_lock();
930 IWineD3DSurface_GetDesc(Source->wineD3DSurface, &winedesc);
931 srcFormat = winedesc.format;
932 srcWidth = winedesc.width;
933 srcHeight = winedesc.height;
934 srcSize = winedesc.size;
936 IWineD3DSurface_GetDesc(Dest->wineD3DSurface, &winedesc);
937 destFormat = winedesc.format;
938 destWidth = winedesc.width;
939 destHeight = winedesc.height;
941 /* Check that the source and destination formats match */
942 if (srcFormat != destFormat && WINED3DFMT_UNKNOWN != destFormat) {
943 WARN("(%p) source %p format must match the dest %p format, returning WINED3DERR_INVALIDCALL\n", iface, pSourceSurface, pDestinationSurface);
944 wined3d_mutex_unlock();
945 return WINED3DERR_INVALIDCALL;
946 } else if (WINED3DFMT_UNKNOWN == destFormat) {
947 TRACE("(%p) : Converting destination surface from WINED3DFMT_UNKNOWN to the source format\n", iface);
948 IWineD3DSurface_SetFormat(Dest->wineD3DSurface, srcFormat);
949 destFormat = srcFormat;
952 /* Quick if complete copy ... */
953 if (cRects == 0 && pSourceRects == NULL && pDestPoints == NULL) {
954 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
957 /* Copy rect by rect */
958 if (NULL != pSourceRects && NULL != pDestPoints) {
959 for (i = 0; i < cRects; ++i) {
960 IWineD3DSurface_BltFast(Dest->wineD3DSurface, pDestPoints[i].x, pDestPoints[i].y, Source->wineD3DSurface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
963 for (i = 0; i < cRects; ++i) {
964 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
968 wined3d_mutex_unlock();
973 static HRESULT WINAPI IDirect3DDevice8Impl_UpdateTexture(LPDIRECT3DDEVICE8 iface, IDirect3DBaseTexture8* pSourceTexture, IDirect3DBaseTexture8* pDestinationTexture) {
974 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
976 TRACE("(%p) Relay\n" , This);
978 wined3d_mutex_lock();
979 hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice, ((IDirect3DBaseTexture8Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture8Impl *)pDestinationTexture)->wineD3DBaseTexture);
980 wined3d_mutex_unlock();
985 static HRESULT WINAPI IDirect3DDevice8Impl_GetFrontBuffer(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pDestSurface) {
986 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
987 IDirect3DSurface8Impl *destSurface = (IDirect3DSurface8Impl *)pDestSurface;
990 TRACE("(%p) Relay\n" , This);
992 if (pDestSurface == NULL) {
993 WARN("(%p) : Caller passed NULL as pDestSurface returning D3DERR_INVALIDCALL\n", This);
994 return D3DERR_INVALIDCALL;
997 wined3d_mutex_lock();
998 hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, 0, destSurface->wineD3DSurface);
999 wined3d_mutex_unlock();
1004 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pRenderTarget, IDirect3DSurface8* pNewZStencil) {
1005 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1006 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl *)pRenderTarget;
1007 IDirect3DSurface8Impl *pZSurface = (IDirect3DSurface8Impl *)pNewZStencil;
1008 IWineD3DSurface *original_ds = NULL;
1010 TRACE("(%p) Relay\n" , This);
1012 wined3d_mutex_lock();
1014 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice, &original_ds);
1015 if (hr == WINED3D_OK || hr == WINED3DERR_NOTFOUND)
1017 hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, pZSurface ? pZSurface->wineD3DSurface : NULL);
1018 if (SUCCEEDED(hr) && pSurface)
1019 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, 0, pSurface->wineD3DSurface);
1020 if (FAILED(hr)) IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, original_ds);
1022 if (original_ds) IWineD3DSurface_Release(original_ds);
1024 wined3d_mutex_unlock();
1029 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppRenderTarget) {
1030 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1031 HRESULT hr = D3D_OK;
1032 IWineD3DSurface *pRenderTarget;
1034 TRACE("(%p) Relay\n" , This);
1036 if (ppRenderTarget == NULL) {
1037 return D3DERR_INVALIDCALL;
1040 wined3d_mutex_lock();
1041 hr = IWineD3DDevice_GetRenderTarget(This->WineD3DDevice, 0, &pRenderTarget);
1043 if (hr == D3D_OK && pRenderTarget != NULL) {
1044 IWineD3DSurface_GetParent(pRenderTarget,(IUnknown**)ppRenderTarget);
1045 IWineD3DSurface_Release(pRenderTarget);
1047 FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
1048 *ppRenderTarget = NULL;
1050 wined3d_mutex_unlock();
1055 static HRESULT WINAPI IDirect3DDevice8Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppZStencilSurface) {
1056 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1057 HRESULT hr = D3D_OK;
1058 IWineD3DSurface *pZStencilSurface;
1060 TRACE("(%p) Relay\n" , This);
1061 if(ppZStencilSurface == NULL){
1062 return D3DERR_INVALIDCALL;
1065 wined3d_mutex_lock();
1066 hr=IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
1067 if (hr == WINED3D_OK) {
1068 IWineD3DSurface_GetParent(pZStencilSurface,(IUnknown**)ppZStencilSurface);
1069 IWineD3DSurface_Release(pZStencilSurface);
1071 if (hr != WINED3DERR_NOTFOUND)
1072 FIXME("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
1073 *ppZStencilSurface = NULL;
1075 wined3d_mutex_unlock();
1080 static HRESULT WINAPI IDirect3DDevice8Impl_BeginScene(LPDIRECT3DDEVICE8 iface) {
1081 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1083 TRACE("(%p) Relay\n" , This);
1085 wined3d_mutex_lock();
1086 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
1087 wined3d_mutex_unlock();
1092 static HRESULT WINAPI IDirect3DDevice8Impl_EndScene(LPDIRECT3DDEVICE8 iface) {
1093 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1095 TRACE("(%p) Relay\n" , This);
1097 wined3d_mutex_lock();
1098 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
1099 wined3d_mutex_unlock();
1104 static HRESULT WINAPI IDirect3DDevice8Impl_Clear(LPDIRECT3DDEVICE8 iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
1105 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1107 TRACE("(%p) Relay\n" , This);
1109 /* Note: D3DRECT is compatible with WINED3DRECT */
1110 wined3d_mutex_lock();
1111 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (CONST WINED3DRECT*) pRects, Flags, Color, Z, Stencil);
1112 wined3d_mutex_unlock();
1117 static HRESULT WINAPI IDirect3DDevice8Impl_SetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
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_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
1125 wined3d_mutex_unlock();
1130 static HRESULT WINAPI IDirect3DDevice8Impl_GetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State,D3DMATRIX* pMatrix) {
1131 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1133 TRACE("(%p) Relay\n" , This);
1135 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1136 wined3d_mutex_lock();
1137 hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
1138 wined3d_mutex_unlock();
1143 static HRESULT WINAPI IDirect3DDevice8Impl_MultiplyTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
1144 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1146 TRACE("(%p) Relay\n" , This);
1148 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1149 wined3d_mutex_lock();
1150 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
1151 wined3d_mutex_unlock();
1156 static HRESULT WINAPI IDirect3DDevice8Impl_SetViewport(LPDIRECT3DDEVICE8 iface, CONST D3DVIEWPORT8* pViewport) {
1157 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1159 TRACE("(%p) Relay\n" , This);
1161 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1162 wined3d_mutex_lock();
1163 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
1164 wined3d_mutex_unlock();
1169 static HRESULT WINAPI IDirect3DDevice8Impl_GetViewport(LPDIRECT3DDEVICE8 iface, D3DVIEWPORT8* pViewport) {
1170 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1172 TRACE("(%p) Relay\n" , This);
1174 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1175 wined3d_mutex_lock();
1176 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
1177 wined3d_mutex_unlock();
1182 static HRESULT WINAPI IDirect3DDevice8Impl_SetMaterial(LPDIRECT3DDEVICE8 iface, CONST D3DMATERIAL8* pMaterial) {
1183 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1185 TRACE("(%p) Relay\n" , This);
1187 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1188 wined3d_mutex_lock();
1189 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
1190 wined3d_mutex_unlock();
1195 static HRESULT WINAPI IDirect3DDevice8Impl_GetMaterial(LPDIRECT3DDEVICE8 iface, D3DMATERIAL8* pMaterial) {
1196 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1198 TRACE("(%p) Relay\n" , This);
1200 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1201 wined3d_mutex_lock();
1202 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
1203 wined3d_mutex_unlock();
1208 static HRESULT WINAPI IDirect3DDevice8Impl_SetLight(LPDIRECT3DDEVICE8 iface, DWORD Index, CONST D3DLIGHT8* pLight) {
1209 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1211 TRACE("(%p) Relay\n" , This);
1213 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1214 wined3d_mutex_lock();
1215 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
1216 wined3d_mutex_unlock();
1221 static HRESULT WINAPI IDirect3DDevice8Impl_GetLight(LPDIRECT3DDEVICE8 iface, DWORD Index,D3DLIGHT8* pLight) {
1222 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1224 TRACE("(%p) Relay\n" , This);
1226 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1227 wined3d_mutex_lock();
1228 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1229 wined3d_mutex_unlock();
1234 static HRESULT WINAPI IDirect3DDevice8Impl_LightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL Enable) {
1235 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1237 TRACE("(%p) Relay\n" , This);
1239 wined3d_mutex_lock();
1240 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1241 wined3d_mutex_unlock();
1246 static HRESULT WINAPI IDirect3DDevice8Impl_GetLightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL* pEnable) {
1247 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1249 TRACE("(%p) Relay\n" , This);
1251 wined3d_mutex_lock();
1252 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1253 wined3d_mutex_unlock();
1258 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,CONST float* pPlane) {
1259 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1261 TRACE("(%p) Relay\n" , This);
1263 wined3d_mutex_lock();
1264 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1265 wined3d_mutex_unlock();
1270 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,float* pPlane) {
1271 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1273 TRACE("(%p) Relay\n" , This);
1275 wined3d_mutex_lock();
1276 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1277 wined3d_mutex_unlock();
1282 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD Value) {
1283 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1285 TRACE("(%p) Relay\n" , This);
1287 wined3d_mutex_lock();
1288 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1289 wined3d_mutex_unlock();
1294 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD* pValue) {
1295 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1297 TRACE("(%p) Relay\n" , This);
1299 wined3d_mutex_lock();
1300 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1301 wined3d_mutex_unlock();
1306 static HRESULT WINAPI IDirect3DDevice8Impl_BeginStateBlock(LPDIRECT3DDEVICE8 iface) {
1307 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1309 TRACE("(%p)\n", This);
1311 wined3d_mutex_lock();
1312 hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
1313 wined3d_mutex_unlock();
1318 static HRESULT WINAPI IDirect3DDevice8Impl_EndStateBlock(LPDIRECT3DDEVICE8 iface, DWORD* pToken) {
1319 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1321 IWineD3DStateBlock* wineD3DStateBlock;
1322 IDirect3DStateBlock8Impl* object;
1324 TRACE("(%p) Relay\n", This);
1326 /* Tell wineD3D to endstateblock before anything else (in case we run out
1327 * of memory later and cause locking problems)
1329 wined3d_mutex_lock();
1330 hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice , &wineD3DStateBlock);
1332 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
1333 wined3d_mutex_unlock();
1337 /* allocate a new IDirectD3DStateBlock */
1338 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY ,sizeof(IDirect3DStateBlock8Impl));
1340 object->lpVtbl = &Direct3DStateBlock8_Vtbl;
1342 object->wineD3DStateBlock = wineD3DStateBlock;
1344 *pToken = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_SB);
1345 wined3d_mutex_unlock();
1347 if (*pToken == D3D8_INVALID_HANDLE)
1349 ERR("Failed to create a handle\n");
1350 IDirect3DStateBlock8_Release((IDirect3DStateBlock8 *)object);
1355 TRACE("Returning %#x (%p).\n", *pToken, object);
1360 static HRESULT WINAPI IDirect3DDevice8Impl_ApplyStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1361 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1362 IDirect3DStateBlock8Impl *pSB;
1365 TRACE("(%p) %#x Relay\n", This, Token);
1367 wined3d_mutex_lock();
1368 pSB = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1371 WARN("Invalid handle (%#x) passed.\n", Token);
1372 wined3d_mutex_unlock();
1373 return D3DERR_INVALIDCALL;
1375 hr = IWineD3DStateBlock_Apply(pSB->wineD3DStateBlock);
1376 wined3d_mutex_unlock();
1381 static HRESULT WINAPI IDirect3DDevice8Impl_CaptureStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1382 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1383 IDirect3DStateBlock8Impl *pSB;
1386 TRACE("(%p) %#x Relay\n", This, Token);
1388 wined3d_mutex_lock();
1389 pSB = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1392 WARN("Invalid handle (%#x) passed.\n", Token);
1393 wined3d_mutex_unlock();
1394 return D3DERR_INVALIDCALL;
1396 hr = IWineD3DStateBlock_Capture(pSB->wineD3DStateBlock);
1397 wined3d_mutex_unlock();
1402 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1403 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1404 IDirect3DStateBlock8Impl *pSB;
1406 TRACE("(%p) Relay\n", This);
1408 wined3d_mutex_lock();
1409 pSB = d3d8_free_handle(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1410 wined3d_mutex_unlock();
1414 WARN("Invalid handle (%#x) passed.\n", Token);
1415 return D3DERR_INVALIDCALL;
1418 if (IUnknown_Release((IUnknown *)pSB))
1420 ERR("Stateblock %p has references left, this shouldn't happen.\n", pSB);
1426 static HRESULT WINAPI IDirect3DDevice8Impl_CreateStateBlock(IDirect3DDevice8 *iface,
1427 D3DSTATEBLOCKTYPE Type, DWORD *handle)
1429 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1430 IDirect3DStateBlock8Impl *object;
1433 TRACE("(%p) Relay\n", This);
1435 if (Type != D3DSBT_ALL
1436 && Type != D3DSBT_PIXELSTATE
1437 && Type != D3DSBT_VERTEXSTATE)
1439 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1440 return D3DERR_INVALIDCALL;
1443 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DStateBlock8Impl));
1446 ERR("Failed to allocate memory.\n");
1447 return E_OUTOFMEMORY;
1450 object->lpVtbl = &Direct3DStateBlock8_Vtbl;
1453 wined3d_mutex_lock();
1454 hr = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type,
1455 &object->wineD3DStateBlock, (IUnknown *)object);
1458 wined3d_mutex_unlock();
1459 ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr);
1460 HeapFree(GetProcessHeap(), 0, object);
1464 *handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_SB);
1465 wined3d_mutex_unlock();
1467 if (*handle == D3D8_INVALID_HANDLE)
1469 ERR("Failed to allocate a handle.\n");
1470 IDirect3DStateBlock8_Release((IDirect3DStateBlock8 *)object);
1475 TRACE("Returning %#x (%p).\n", *handle, object);
1480 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipStatus(LPDIRECT3DDEVICE8 iface, CONST D3DCLIPSTATUS8* pClipStatus) {
1481 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1483 TRACE("(%p) Relay\n" , This);
1484 /* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
1486 wined3d_mutex_lock();
1487 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1488 wined3d_mutex_unlock();
1493 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipStatus(LPDIRECT3DDEVICE8 iface, D3DCLIPSTATUS8* pClipStatus) {
1494 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1496 TRACE("(%p) Relay\n" , This);
1498 wined3d_mutex_lock();
1499 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1500 wined3d_mutex_unlock();
1505 static HRESULT WINAPI IDirect3DDevice8Impl_GetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage,IDirect3DBaseTexture8** ppTexture) {
1506 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1507 IWineD3DBaseTexture *retTexture = NULL;
1508 HRESULT rc = D3D_OK;
1510 TRACE("(%p) Relay\n" , This);
1512 if(ppTexture == NULL){
1513 return D3DERR_INVALIDCALL;
1516 wined3d_mutex_lock();
1517 rc = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
1518 if (rc == D3D_OK && NULL != retTexture) {
1519 IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
1520 IWineD3DBaseTexture_Release(retTexture);
1522 FIXME("Call to get texture (%d) failed (%p)\n", Stage, retTexture);
1525 wined3d_mutex_unlock();
1530 static HRESULT WINAPI IDirect3DDevice8Impl_SetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage, IDirect3DBaseTexture8* pTexture) {
1531 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1533 TRACE("(%p) Relay %d %p\n" , This, Stage, pTexture);
1535 wined3d_mutex_lock();
1536 hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
1537 pTexture==NULL ? NULL : ((IDirect3DBaseTexture8Impl *)pTexture)->wineD3DBaseTexture);
1538 wined3d_mutex_unlock();
1543 static const struct tss_lookup
1550 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 0, unused */
1551 {FALSE, WINED3DTSS_COLOROP}, /* 1, D3DTSS_COLOROP */
1552 {FALSE, WINED3DTSS_COLORARG1}, /* 2, D3DTSS_COLORARG1 */
1553 {FALSE, WINED3DTSS_COLORARG2}, /* 3, D3DTSS_COLORARG2 */
1554 {FALSE, WINED3DTSS_ALPHAOP}, /* 4, D3DTSS_ALPHAOP */
1555 {FALSE, WINED3DTSS_ALPHAARG1}, /* 5, D3DTSS_ALPHAARG1 */
1556 {FALSE, WINED3DTSS_ALPHAARG2}, /* 6, D3DTSS_ALPHAARG2 */
1557 {FALSE, WINED3DTSS_BUMPENVMAT00}, /* 7, D3DTSS_BUMPENVMAT00 */
1558 {FALSE, WINED3DTSS_BUMPENVMAT01}, /* 8, D3DTSS_BUMPENVMAT01 */
1559 {FALSE, WINED3DTSS_BUMPENVMAT10}, /* 9, D3DTSS_BUMPENVMAT10 */
1560 {FALSE, WINED3DTSS_BUMPENVMAT11}, /* 10, D3DTSS_BUMPENVMAT11 */
1561 {FALSE, WINED3DTSS_TEXCOORDINDEX}, /* 11, D3DTSS_TEXCOORDINDEX */
1562 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 12, unused */
1563 {TRUE, WINED3DSAMP_ADDRESSU}, /* 13, D3DTSS_ADDRESSU */
1564 {TRUE, WINED3DSAMP_ADDRESSV}, /* 14, D3DTSS_ADDRESSV */
1565 {TRUE, WINED3DSAMP_BORDERCOLOR}, /* 15, D3DTSS_BORDERCOLOR */
1566 {TRUE, WINED3DSAMP_MAGFILTER}, /* 16, D3DTSS_MAGFILTER */
1567 {TRUE, WINED3DSAMP_MINFILTER}, /* 17, D3DTSS_MINFILTER */
1568 {TRUE, WINED3DSAMP_MIPFILTER}, /* 18, D3DTSS_MIPFILTER */
1569 {TRUE, WINED3DSAMP_MIPMAPLODBIAS}, /* 19, D3DTSS_MIPMAPLODBIAS */
1570 {TRUE, WINED3DSAMP_MAXMIPLEVEL}, /* 20, D3DTSS_MAXMIPLEVEL */
1571 {TRUE, WINED3DSAMP_MAXANISOTROPY}, /* 21, D3DTSS_MAXANISOTROPY */
1572 {FALSE, WINED3DTSS_BUMPENVLSCALE}, /* 22, D3DTSS_BUMPENVLSCALE */
1573 {FALSE, WINED3DTSS_BUMPENVLOFFSET}, /* 23, D3DTSS_BUMPENVLOFFSET */
1574 {FALSE, WINED3DTSS_TEXTURETRANSFORMFLAGS}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1575 {TRUE, WINED3DSAMP_ADDRESSW}, /* 25, D3DTSS_ADDRESSW */
1576 {FALSE, WINED3DTSS_COLORARG0}, /* 26, D3DTSS_COLORARG0 */
1577 {FALSE, WINED3DTSS_ALPHAARG0}, /* 27, D3DTSS_ALPHAARG0 */
1578 {FALSE, WINED3DTSS_RESULTARG}, /* 28, D3DTSS_RESULTARG */
1581 static HRESULT WINAPI IDirect3DDevice8Impl_GetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD* pValue) {
1582 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1583 const struct tss_lookup *l = &tss_lookup[Type];
1585 TRACE("(%p) Relay\n" , This);
1587 wined3d_mutex_lock();
1588 if (l->sampler_state) hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Stage, l->state, pValue);
1589 else hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, l->state, pValue);
1590 wined3d_mutex_unlock();
1595 static HRESULT WINAPI IDirect3DDevice8Impl_SetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
1596 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1597 const struct tss_lookup *l = &tss_lookup[Type];
1599 TRACE("(%p) Relay\n" , This);
1601 wined3d_mutex_lock();
1602 if (l->sampler_state) hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Stage, l->state, Value);
1603 else hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, l->state, Value);
1604 wined3d_mutex_unlock();
1609 static HRESULT WINAPI IDirect3DDevice8Impl_ValidateDevice(LPDIRECT3DDEVICE8 iface, DWORD* pNumPasses) {
1610 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1612 TRACE("(%p) Relay\n" , This);
1614 wined3d_mutex_lock();
1615 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1616 wined3d_mutex_unlock();
1621 static HRESULT WINAPI IDirect3DDevice8Impl_GetInfo(LPDIRECT3DDEVICE8 iface, DWORD DevInfoID, void* pDevInfoStruct, DWORD DevInfoStructSize) {
1622 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1623 FIXME("(%p) : stub\n", This);
1627 static HRESULT WINAPI IDirect3DDevice8Impl_SetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, CONST PALETTEENTRY* pEntries) {
1628 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1630 TRACE("(%p) Relay\n" , This);
1632 wined3d_mutex_lock();
1633 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1634 wined3d_mutex_unlock();
1639 static HRESULT WINAPI IDirect3DDevice8Impl_GetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
1640 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1642 TRACE("(%p) Relay\n" , This);
1644 wined3d_mutex_lock();
1645 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1646 wined3d_mutex_unlock();
1651 static HRESULT WINAPI IDirect3DDevice8Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber) {
1652 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1654 TRACE("(%p) Relay\n" , This);
1656 wined3d_mutex_lock();
1657 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1658 wined3d_mutex_unlock();
1663 static HRESULT WINAPI IDirect3DDevice8Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT *PaletteNumber) {
1664 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1666 TRACE("(%p) Relay\n" , This);
1668 wined3d_mutex_lock();
1669 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1670 wined3d_mutex_unlock();
1675 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitive(IDirect3DDevice8 *iface, D3DPRIMITIVETYPE PrimitiveType,
1676 UINT StartVertex, UINT PrimitiveCount)
1678 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1680 TRACE("(%p) Relay\n" , This);
1682 wined3d_mutex_lock();
1683 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1684 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
1685 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
1686 wined3d_mutex_unlock();
1691 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,
1692 UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount) {
1693 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1695 TRACE("(%p) Relay\n" , This);
1697 wined3d_mutex_lock();
1698 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1699 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, startIndex,
1700 vertex_count_from_primitive_count(PrimitiveType, primCount));
1701 wined3d_mutex_unlock();
1706 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT PrimitiveCount,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride) {
1707 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1709 TRACE("(%p) Relay\n" , This);
1711 wined3d_mutex_lock();
1712 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1713 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
1714 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
1715 pVertexStreamZeroData, VertexStreamZeroStride);
1716 wined3d_mutex_unlock();
1721 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,
1722 UINT NumVertexIndices,UINT PrimitiveCount,CONST void* pIndexData,
1723 D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,
1724 UINT VertexStreamZeroStride) {
1725 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1727 TRACE("(%p) Relay\n" , This);
1729 wined3d_mutex_lock();
1730 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1731 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice,
1732 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
1733 wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
1734 wined3d_mutex_unlock();
1739 static HRESULT WINAPI IDirect3DDevice8Impl_ProcessVertices(LPDIRECT3DDEVICE8 iface, UINT SrcStartIndex,UINT DestIndex,UINT VertexCount,IDirect3DVertexBuffer8* pDestBuffer,DWORD Flags) {
1740 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1742 IDirect3DVertexBuffer8Impl *dest = (IDirect3DVertexBuffer8Impl *) pDestBuffer;
1743 TRACE("(%p) Relay\n" , This);
1745 wined3d_mutex_lock();
1746 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, NULL, Flags, dest->fvf);
1747 wined3d_mutex_unlock();
1752 static HRESULT IDirect3DDevice8Impl_CreateVertexDeclaration(IDirect3DDevice8 *iface, CONST DWORD *declaration, IDirect3DVertexDeclaration8 **decl_ptr) {
1753 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1754 IDirect3DVertexDeclaration8Impl *object;
1755 WINED3DVERTEXELEMENT *wined3d_elements;
1756 UINT wined3d_element_count;
1757 HRESULT hr = D3D_OK;
1759 TRACE("(%p) : declaration %p\n", This, declaration);
1761 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1763 ERR("Memory allocation failed\n");
1765 return D3DERR_OUTOFVIDEOMEMORY;
1768 object->ref_count = 1;
1769 object->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
1771 wined3d_element_count = convert_to_wined3d_declaration(declaration, &object->elements_size, &wined3d_elements);
1772 object->elements = HeapAlloc(GetProcessHeap(), 0, object->elements_size);
1773 if (!object->elements) {
1774 ERR("Memory allocation failed\n");
1775 HeapFree(GetProcessHeap(), 0, wined3d_elements);
1776 HeapFree(GetProcessHeap(), 0, object);
1778 return D3DERR_OUTOFVIDEOMEMORY;
1781 CopyMemory(object->elements, declaration, object->elements_size);
1783 wined3d_mutex_lock();
1784 hr = IWineD3DDevice_CreateVertexDeclaration(This->WineD3DDevice, &object->wined3d_vertex_declaration,
1785 (IUnknown *)object, wined3d_elements, wined3d_element_count);
1786 wined3d_mutex_unlock();
1788 HeapFree(GetProcessHeap(), 0, wined3d_elements);
1791 ERR("(%p) : IWineD3DDevice_CreateVertexDeclaration call failed\n", This);
1792 HeapFree(GetProcessHeap(), 0, object->elements);
1793 HeapFree(GetProcessHeap(), 0, object);
1795 *decl_ptr = (IDirect3DVertexDeclaration8 *)object;
1796 TRACE("(%p) : Created vertex declaration %p\n", This, object);
1802 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pDeclaration, CONST DWORD* pFunction, DWORD* ppShader, DWORD Usage) {
1803 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1804 HRESULT hrc = D3D_OK;
1805 IDirect3DVertexShader8Impl *object;
1806 const DWORD *token = pDeclaration;
1809 /* Test if the vertex declaration is valid */
1810 while (D3DVSD_END() != *token) {
1811 D3DVSD_TOKENTYPE token_type = ((*token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT);
1813 if (token_type == D3DVSD_TOKEN_STREAMDATA && !(token_type & 0x10000000)) {
1814 DWORD type = ((*token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
1815 DWORD reg = ((*token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
1817 if(reg == D3DVSDE_NORMAL && type != D3DVSDT_FLOAT3 && !pFunction) {
1818 WARN("Attempt to use a non-FLOAT3 normal with the fixed function function\n");
1819 return D3DERR_INVALIDCALL;
1822 token += parse_token(token);
1825 /* Setup a stub object for now */
1826 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1827 TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
1828 if (NULL == object) {
1829 FIXME("Allocation of memory failed\n");
1831 return D3DERR_OUTOFVIDEOMEMORY;
1835 object->lpVtbl = &Direct3DVertexShader8_Vtbl;
1837 hrc = IDirect3DDevice8Impl_CreateVertexDeclaration(iface, pDeclaration, &object->vertex_declaration);
1839 ERR("(%p) : IDirect3DDeviceImpl_CreateVertexDeclaration call failed\n", This);
1840 HeapFree(GetProcessHeap(), 0, object);
1842 return D3DERR_INVALIDCALL;
1845 wined3d_mutex_lock();
1846 handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_VS);
1847 if (handle == D3D8_INVALID_HANDLE)
1849 ERR("Failed to allocate shader handle\n");
1850 wined3d_mutex_unlock();
1851 IDirect3DVertexDeclaration8_Release(object->vertex_declaration);
1852 HeapFree(GetProcessHeap(), 0, object);
1854 return E_OUTOFMEMORY;
1858 DWORD shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
1859 *ppShader = ((IDirect3DVertexDeclaration8Impl *)object->vertex_declaration)->shader_handle = shader_handle;
1864 /* Usage is missing ... Use SetRenderState to set the sw vp render state in SetVertexShader */
1865 hrc = IWineD3DDevice_CreateVertexShader(This->WineD3DDevice, pFunction,
1866 NULL /* output signature */, &object->wineD3DVertexShader, (IUnknown *)object);
1870 /* free up object */
1871 FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n");
1872 d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_VS);
1873 IDirect3DVertexDeclaration8_Release(object->vertex_declaration);
1874 HeapFree(GetProcessHeap(), 0, object);
1879 load_local_constants(pDeclaration, object->wineD3DVertexShader);
1880 TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
1884 wined3d_mutex_unlock();
1889 static IDirect3DVertexDeclaration8Impl *IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl *This, DWORD fvf)
1891 IDirect3DVertexDeclaration8Impl *d3d8_declaration;
1893 int p, low, high; /* deliberately signed */
1894 struct FvfToDecl *convertedDecls = This->decls;
1896 TRACE("Searching for declaration for fvf %08x... ", fvf);
1899 high = This->numConvertedDecls - 1;
1900 while(low <= high) {
1901 p = (low + high) >> 1;
1903 if(convertedDecls[p].fvf == fvf) {
1904 TRACE("found %p\n", convertedDecls[p].decl);
1905 return (IDirect3DVertexDeclaration8Impl *)convertedDecls[p].decl;
1906 } else if(convertedDecls[p].fvf < fvf) {
1912 TRACE("not found. Creating and inserting at position %d.\n", low);
1914 d3d8_declaration = HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration));
1915 if (!d3d8_declaration)
1917 ERR("Memory allocation failed.\n");
1921 d3d8_declaration->ref_count = 1;
1922 d3d8_declaration->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
1923 d3d8_declaration->elements = NULL;
1924 d3d8_declaration->elements_size = 0;
1925 d3d8_declaration->shader_handle = fvf;
1927 hr = IWineD3DDevice_CreateVertexDeclarationFromFVF(This->WineD3DDevice,
1928 &d3d8_declaration->wined3d_vertex_declaration, (IUnknown *)d3d8_declaration, fvf);
1931 ERR("Failed to create wined3d vertex declaration.\n");
1932 HeapFree(GetProcessHeap(), 0, d3d8_declaration);
1936 if(This->declArraySize == This->numConvertedDecls) {
1937 int grow = This->declArraySize / 2;
1938 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
1939 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
1940 if(!convertedDecls) {
1941 /* This will destroy it */
1942 IDirect3DVertexDeclaration8_Release((IDirect3DVertexDeclaration8 *)d3d8_declaration);
1945 This->decls = convertedDecls;
1946 This->declArraySize += grow;
1949 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(convertedDecls[0]) * (This->numConvertedDecls - low));
1950 convertedDecls[low].decl = (IDirect3DVertexDeclaration8 *)d3d8_declaration;
1951 convertedDecls[low].fvf = fvf;
1952 This->numConvertedDecls++;
1954 TRACE("Returning %p. %u decls in array\n", d3d8_declaration, This->numConvertedDecls);
1955 return d3d8_declaration;
1958 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1959 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1960 IDirect3DVertexShader8Impl *shader;
1963 TRACE("(%p) : Relay\n", This);
1965 if (VS_HIGHESTFIXEDFXF >= pShader) {
1966 TRACE("Setting FVF, %#x\n", pShader);
1968 wined3d_mutex_lock();
1969 IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
1970 IDirect3DDevice8Impl_FindDecl(This, pShader)->wined3d_vertex_declaration);
1971 IWineD3DDevice_SetVertexShader(This->WineD3DDevice, NULL);
1972 wined3d_mutex_unlock();
1977 TRACE("Setting shader\n");
1979 wined3d_mutex_lock();
1980 shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
1983 WARN("Invalid handle (%#x) passed.\n", pShader);
1984 wined3d_mutex_unlock();
1986 return D3DERR_INVALIDCALL;
1989 hr = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
1990 ((IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration)->wined3d_vertex_declaration);
1991 if (SUCCEEDED(hr)) hr = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, shader->wineD3DVertexShader);
1992 wined3d_mutex_unlock();
1994 TRACE("Returning hr %#x\n", hr);
1999 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
2000 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2001 IWineD3DVertexDeclaration *wined3d_declaration;
2002 IDirect3DVertexDeclaration8 *d3d8_declaration;
2005 TRACE("(%p) : Relay device@%p\n", This, This->WineD3DDevice);
2007 wined3d_mutex_lock();
2008 hrc = IWineD3DDevice_GetVertexDeclaration(This->WineD3DDevice, &wined3d_declaration);
2011 wined3d_mutex_unlock();
2012 WARN("(%p) : Call to IWineD3DDevice_GetVertexDeclaration failed %#x (device %p)\n",
2013 This, hrc, This->WineD3DDevice);
2017 if (!wined3d_declaration)
2019 wined3d_mutex_unlock();
2024 hrc = IWineD3DVertexDeclaration_GetParent(wined3d_declaration, (IUnknown **)&d3d8_declaration);
2025 IWineD3DVertexDeclaration_Release(wined3d_declaration);
2026 wined3d_mutex_unlock();
2029 *ppShader = ((IDirect3DVertexDeclaration8Impl *)d3d8_declaration)->shader_handle;
2030 IDirect3DVertexDeclaration8_Release(d3d8_declaration);
2033 TRACE("(%p) : returning %#x\n", This, *ppShader);
2038 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
2039 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2040 IDirect3DVertexShader8Impl *shader;
2041 IWineD3DVertexShader *cur = NULL;
2043 TRACE("(%p) : pShader %#x\n", This, pShader);
2045 wined3d_mutex_lock();
2046 shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2049 WARN("Invalid handle (%#x) passed.\n", pShader);
2050 wined3d_mutex_unlock();
2052 return D3DERR_INVALIDCALL;
2055 IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &cur);
2059 if (cur == shader->wineD3DVertexShader) IDirect3DDevice8_SetVertexShader(iface, 0);
2060 IWineD3DVertexShader_Release(cur);
2063 wined3d_mutex_unlock();
2065 if (IUnknown_Release((IUnknown *)shader))
2067 ERR("Shader %p has references left, this shouldn't happen.\n", shader);
2073 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
2074 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2076 TRACE("(%p) : Relay\n", This);
2078 if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
2079 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2080 Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2081 return D3DERR_INVALIDCALL;
2084 wined3d_mutex_lock();
2085 hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2086 wined3d_mutex_unlock();
2091 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
2092 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2094 TRACE("(%p) : Relay\n", This);
2096 if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
2097 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2098 Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2099 return D3DERR_INVALIDCALL;
2102 wined3d_mutex_lock();
2103 hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2104 wined3d_mutex_unlock();
2109 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderDeclaration(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
2110 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2111 IDirect3DVertexDeclaration8Impl *declaration;
2112 IDirect3DVertexShader8Impl *shader;
2114 TRACE("(%p) : pVertexShader 0x%08x, pData %p, *pSizeOfData %u\n", This, pVertexShader, pData, *pSizeOfData);
2116 wined3d_mutex_lock();
2117 shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2118 wined3d_mutex_unlock();
2122 WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2123 return D3DERR_INVALIDCALL;
2125 declaration = (IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration;
2127 /* If pData is NULL, we just return the required size of the buffer. */
2129 *pSizeOfData = declaration->elements_size;
2133 /* MSDN claims that if *pSizeOfData is smaller than the required size
2134 * we should write the required size and return D3DERR_MOREDATA.
2135 * That's not actually true. */
2136 if (*pSizeOfData < declaration->elements_size) {
2137 return D3DERR_INVALIDCALL;
2140 CopyMemory(pData, declaration->elements, declaration->elements_size);
2145 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
2146 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2147 IDirect3DVertexShader8Impl *shader = NULL;
2150 TRACE("(%p) : pVertexShader %#x, pData %p, pSizeOfData %p\n", This, pVertexShader, pData, pSizeOfData);
2152 wined3d_mutex_lock();
2153 shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2156 WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2157 wined3d_mutex_unlock();
2159 return D3DERR_INVALIDCALL;
2162 if (!shader->wineD3DVertexShader)
2164 wined3d_mutex_unlock();
2169 hr = IWineD3DVertexShader_GetFunction(shader->wineD3DVertexShader, pData, pSizeOfData);
2170 wined3d_mutex_unlock();
2175 static HRESULT WINAPI IDirect3DDevice8Impl_SetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8* pIndexData, UINT baseVertexIndex) {
2176 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2178 IDirect3DIndexBuffer8Impl *ib = (IDirect3DIndexBuffer8Impl *)pIndexData;
2179 TRACE("(%p) Relay\n", This);
2181 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
2182 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
2183 * vertex buffers can't be created to address them with an index that requires the 32nd bit
2184 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
2187 wined3d_mutex_lock();
2188 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, baseVertexIndex);
2189 hr = IWineD3DDevice_SetIndices(This->WineD3DDevice,
2190 ib ? ib->wineD3DIndexBuffer : NULL,
2191 ib ? ib->format : WINED3DFMT_UNKNOWN);
2192 wined3d_mutex_unlock();
2197 static HRESULT WINAPI IDirect3DDevice8Impl_GetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8** ppIndexData,UINT* pBaseVertexIndex) {
2198 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2199 IWineD3DBuffer *retIndexData = NULL;
2200 HRESULT rc = D3D_OK;
2202 TRACE("(%p) Relay\n", This);
2204 if(ppIndexData == NULL){
2205 return D3DERR_INVALIDCALL;
2208 /* The case from UINT to INT is safe because d3d8 will never set negative values */
2209 wined3d_mutex_lock();
2210 IWineD3DDevice_GetBaseVertexIndex(This->WineD3DDevice, (INT *) pBaseVertexIndex);
2211 rc = IWineD3DDevice_GetIndices(This->WineD3DDevice, &retIndexData);
2212 if (SUCCEEDED(rc) && retIndexData) {
2213 IWineD3DBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
2214 IWineD3DBuffer_Release(retIndexData);
2216 if (FAILED(rc)) FIXME("Call to GetIndices failed\n");
2217 *ppIndexData = NULL;
2219 wined3d_mutex_unlock();
2223 static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pFunction, DWORD* ppShader) {
2224 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2225 IDirect3DPixelShader8Impl *object;
2229 TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
2231 if (NULL == ppShader) {
2232 TRACE("(%p) Invalid call\n", This);
2233 return D3DERR_INVALIDCALL;
2236 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2239 ERR("Failed to allocate memmory.\n");
2240 return E_OUTOFMEMORY;
2244 object->lpVtbl = &Direct3DPixelShader8_Vtbl;
2246 wined3d_mutex_lock();
2247 hr = IWineD3DDevice_CreatePixelShader(This->WineD3DDevice, pFunction,
2248 NULL, &object->wineD3DPixelShader, (IUnknown *)object);
2251 wined3d_mutex_unlock();
2252 FIXME("(%p) call to IWineD3DDevice_CreatePixelShader failed\n", This);
2253 HeapFree(GetProcessHeap(), 0 , object);
2258 handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_PS);
2259 wined3d_mutex_unlock();
2261 if (handle == D3D8_INVALID_HANDLE)
2263 ERR("Failed to allocate shader handle\n");
2264 IDirect3DVertexShader8_Release((IUnknown *)object);
2265 return E_OUTOFMEMORY;
2268 *ppShader = object->handle = handle + VS_HIGHESTFIXEDFXF + 1;
2269 TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
2274 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
2275 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2276 IDirect3DPixelShader8Impl *shader;
2279 TRACE("(%p) : pShader %#x\n", This, pShader);
2281 wined3d_mutex_lock();
2285 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, NULL);
2286 wined3d_mutex_unlock();
2290 shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2293 WARN("Invalid handle (%#x) passed.\n", pShader);
2294 wined3d_mutex_unlock();
2295 return D3DERR_INVALIDCALL;
2298 TRACE("(%p) : Setting shader %p\n", This, shader);
2299 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, shader->wineD3DPixelShader);
2300 wined3d_mutex_unlock();
2305 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
2306 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2307 IWineD3DPixelShader *object;
2309 HRESULT hrc = D3D_OK;
2310 TRACE("(%p) Relay\n", This);
2311 if (NULL == ppShader) {
2312 TRACE("(%p) Invalid call\n", This);
2313 return D3DERR_INVALIDCALL;
2316 wined3d_mutex_lock();
2317 hrc = IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &object);
2318 if (D3D_OK == hrc && NULL != object) {
2319 IDirect3DPixelShader8Impl *d3d8_shader;
2320 hrc = IWineD3DPixelShader_GetParent(object, (IUnknown **)&d3d8_shader);
2321 IWineD3DPixelShader_Release(object);
2322 *ppShader = d3d8_shader->handle;
2323 IDirect3DPixelShader8_Release((IDirect3DPixelShader8 *)d3d8_shader);
2327 wined3d_mutex_unlock();
2329 TRACE("(%p) : returning %#x\n", This, *ppShader);
2334 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
2335 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2336 IDirect3DPixelShader8Impl *shader;
2337 IWineD3DPixelShader *cur = NULL;
2339 TRACE("(%p) : pShader %#x\n", This, pShader);
2341 wined3d_mutex_lock();
2343 shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2346 WARN("Invalid handle (%#x) passed.\n", pShader);
2347 wined3d_mutex_unlock();
2351 IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &cur);
2355 if (cur == shader->wineD3DPixelShader) IDirect3DDevice8_SetPixelShader(iface, 0);
2356 IWineD3DPixelShader_Release(cur);
2359 wined3d_mutex_unlock();
2361 if (IUnknown_Release((IUnknown *)shader))
2363 ERR("Shader %p has references left, this shouldn't happen.\n", shader);
2369 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
2370 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2372 TRACE("(%p) Relay\n", This);
2374 wined3d_mutex_lock();
2375 hr = IWineD3DDevice_SetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2376 wined3d_mutex_unlock();
2381 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
2382 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2384 TRACE("(%p) Relay\n", This);
2386 wined3d_mutex_lock();
2387 hr = IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2388 wined3d_mutex_unlock();
2393 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pPixelShader, void* pData, DWORD* pSizeOfData) {
2394 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2395 IDirect3DPixelShader8Impl *shader = NULL;
2398 TRACE("(%p) : pPixelShader %#x, pData %p, pSizeOfData %p\n", This, pPixelShader, pData, pSizeOfData);
2400 wined3d_mutex_lock();
2401 shader = d3d8_get_object(&This->handle_table, pPixelShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2404 WARN("Invalid handle (%#x) passed.\n", pPixelShader);
2405 wined3d_mutex_unlock();
2407 return D3DERR_INVALIDCALL;
2410 hr = IWineD3DPixelShader_GetFunction(shader->wineD3DPixelShader, pData, pSizeOfData);
2411 wined3d_mutex_unlock();
2416 static HRESULT WINAPI IDirect3DDevice8Impl_DrawRectPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
2417 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2419 TRACE("(%p) Relay\n", This);
2421 wined3d_mutex_lock();
2422 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
2423 wined3d_mutex_unlock();
2428 static HRESULT WINAPI IDirect3DDevice8Impl_DrawTriPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
2429 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2431 TRACE("(%p) Relay\n", This);
2433 wined3d_mutex_lock();
2434 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
2435 wined3d_mutex_unlock();
2440 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePatch(LPDIRECT3DDEVICE8 iface, UINT Handle) {
2441 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2443 TRACE("(%p) Relay\n", This);
2445 wined3d_mutex_lock();
2446 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
2447 wined3d_mutex_unlock();
2452 static HRESULT WINAPI IDirect3DDevice8Impl_SetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8* pStreamData,UINT Stride) {
2453 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2455 TRACE("(%p) Relay\n" , This);
2457 wined3d_mutex_lock();
2458 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
2459 NULL == pStreamData ? NULL : ((IDirect3DVertexBuffer8Impl *)pStreamData)->wineD3DVertexBuffer,
2460 0/* Offset in bytes */, Stride);
2461 wined3d_mutex_unlock();
2466 static HRESULT WINAPI IDirect3DDevice8Impl_GetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8** pStream,UINT* pStride) {
2467 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2468 IWineD3DBuffer *retStream = NULL;
2469 HRESULT rc = D3D_OK;
2471 TRACE("(%p) Relay\n" , This);
2473 if(pStream == NULL){
2474 return D3DERR_INVALIDCALL;
2477 wined3d_mutex_lock();
2478 rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, 0 /* Offset in bytes */, pStride);
2479 if (rc == D3D_OK && NULL != retStream) {
2480 IWineD3DBuffer_GetParent(retStream, (IUnknown **)pStream);
2481 IWineD3DBuffer_Release(retStream);
2484 FIXME("Call to GetStreamSource failed %p\n", pStride);
2488 wined3d_mutex_unlock();
2494 const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl =
2496 IDirect3DDevice8Impl_QueryInterface,
2497 IDirect3DDevice8Impl_AddRef,
2498 IDirect3DDevice8Impl_Release,
2499 IDirect3DDevice8Impl_TestCooperativeLevel,
2500 IDirect3DDevice8Impl_GetAvailableTextureMem,
2501 IDirect3DDevice8Impl_ResourceManagerDiscardBytes,
2502 IDirect3DDevice8Impl_GetDirect3D,
2503 IDirect3DDevice8Impl_GetDeviceCaps,
2504 IDirect3DDevice8Impl_GetDisplayMode,
2505 IDirect3DDevice8Impl_GetCreationParameters,
2506 IDirect3DDevice8Impl_SetCursorProperties,
2507 IDirect3DDevice8Impl_SetCursorPosition,
2508 IDirect3DDevice8Impl_ShowCursor,
2509 IDirect3DDevice8Impl_CreateAdditionalSwapChain,
2510 IDirect3DDevice8Impl_Reset,
2511 IDirect3DDevice8Impl_Present,
2512 IDirect3DDevice8Impl_GetBackBuffer,
2513 IDirect3DDevice8Impl_GetRasterStatus,
2514 IDirect3DDevice8Impl_SetGammaRamp,
2515 IDirect3DDevice8Impl_GetGammaRamp,
2516 IDirect3DDevice8Impl_CreateTexture,
2517 IDirect3DDevice8Impl_CreateVolumeTexture,
2518 IDirect3DDevice8Impl_CreateCubeTexture,
2519 IDirect3DDevice8Impl_CreateVertexBuffer,
2520 IDirect3DDevice8Impl_CreateIndexBuffer,
2521 IDirect3DDevice8Impl_CreateRenderTarget,
2522 IDirect3DDevice8Impl_CreateDepthStencilSurface,
2523 IDirect3DDevice8Impl_CreateImageSurface,
2524 IDirect3DDevice8Impl_CopyRects,
2525 IDirect3DDevice8Impl_UpdateTexture,
2526 IDirect3DDevice8Impl_GetFrontBuffer,
2527 IDirect3DDevice8Impl_SetRenderTarget,
2528 IDirect3DDevice8Impl_GetRenderTarget,
2529 IDirect3DDevice8Impl_GetDepthStencilSurface,
2530 IDirect3DDevice8Impl_BeginScene,
2531 IDirect3DDevice8Impl_EndScene,
2532 IDirect3DDevice8Impl_Clear,
2533 IDirect3DDevice8Impl_SetTransform,
2534 IDirect3DDevice8Impl_GetTransform,
2535 IDirect3DDevice8Impl_MultiplyTransform,
2536 IDirect3DDevice8Impl_SetViewport,
2537 IDirect3DDevice8Impl_GetViewport,
2538 IDirect3DDevice8Impl_SetMaterial,
2539 IDirect3DDevice8Impl_GetMaterial,
2540 IDirect3DDevice8Impl_SetLight,
2541 IDirect3DDevice8Impl_GetLight,
2542 IDirect3DDevice8Impl_LightEnable,
2543 IDirect3DDevice8Impl_GetLightEnable,
2544 IDirect3DDevice8Impl_SetClipPlane,
2545 IDirect3DDevice8Impl_GetClipPlane,
2546 IDirect3DDevice8Impl_SetRenderState,
2547 IDirect3DDevice8Impl_GetRenderState,
2548 IDirect3DDevice8Impl_BeginStateBlock,
2549 IDirect3DDevice8Impl_EndStateBlock,
2550 IDirect3DDevice8Impl_ApplyStateBlock,
2551 IDirect3DDevice8Impl_CaptureStateBlock,
2552 IDirect3DDevice8Impl_DeleteStateBlock,
2553 IDirect3DDevice8Impl_CreateStateBlock,
2554 IDirect3DDevice8Impl_SetClipStatus,
2555 IDirect3DDevice8Impl_GetClipStatus,
2556 IDirect3DDevice8Impl_GetTexture,
2557 IDirect3DDevice8Impl_SetTexture,
2558 IDirect3DDevice8Impl_GetTextureStageState,
2559 IDirect3DDevice8Impl_SetTextureStageState,
2560 IDirect3DDevice8Impl_ValidateDevice,
2561 IDirect3DDevice8Impl_GetInfo,
2562 IDirect3DDevice8Impl_SetPaletteEntries,
2563 IDirect3DDevice8Impl_GetPaletteEntries,
2564 IDirect3DDevice8Impl_SetCurrentTexturePalette,
2565 IDirect3DDevice8Impl_GetCurrentTexturePalette,
2566 IDirect3DDevice8Impl_DrawPrimitive,
2567 IDirect3DDevice8Impl_DrawIndexedPrimitive,
2568 IDirect3DDevice8Impl_DrawPrimitiveUP,
2569 IDirect3DDevice8Impl_DrawIndexedPrimitiveUP,
2570 IDirect3DDevice8Impl_ProcessVertices,
2571 IDirect3DDevice8Impl_CreateVertexShader,
2572 IDirect3DDevice8Impl_SetVertexShader,
2573 IDirect3DDevice8Impl_GetVertexShader,
2574 IDirect3DDevice8Impl_DeleteVertexShader,
2575 IDirect3DDevice8Impl_SetVertexShaderConstant,
2576 IDirect3DDevice8Impl_GetVertexShaderConstant,
2577 IDirect3DDevice8Impl_GetVertexShaderDeclaration,
2578 IDirect3DDevice8Impl_GetVertexShaderFunction,
2579 IDirect3DDevice8Impl_SetStreamSource,
2580 IDirect3DDevice8Impl_GetStreamSource,
2581 IDirect3DDevice8Impl_SetIndices,
2582 IDirect3DDevice8Impl_GetIndices,
2583 IDirect3DDevice8Impl_CreatePixelShader,
2584 IDirect3DDevice8Impl_SetPixelShader,
2585 IDirect3DDevice8Impl_GetPixelShader,
2586 IDirect3DDevice8Impl_DeletePixelShader,
2587 IDirect3DDevice8Impl_SetPixelShaderConstant,
2588 IDirect3DDevice8Impl_GetPixelShaderConstant,
2589 IDirect3DDevice8Impl_GetPixelShaderFunction,
2590 IDirect3DDevice8Impl_DrawRectPatch,
2591 IDirect3DDevice8Impl_DrawTriPatch,
2592 IDirect3DDevice8Impl_DeletePatch
2595 /* IWineD3DDeviceParent IUnknown methods */
2597 static inline struct IDirect3DDevice8Impl *device_from_device_parent(IWineD3DDeviceParent *iface)
2599 return (struct IDirect3DDevice8Impl *)((char*)iface
2600 - FIELD_OFFSET(struct IDirect3DDevice8Impl, device_parent_vtbl));
2603 static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface, REFIID riid, void **object)
2605 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2606 return IDirect3DDevice8Impl_QueryInterface((IDirect3DDevice8 *)This, riid, object);
2609 static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
2611 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2612 return IDirect3DDevice8Impl_AddRef((IDirect3DDevice8 *)This);
2615 static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
2617 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2618 return IDirect3DDevice8Impl_Release((IDirect3DDevice8 *)This);
2621 /* IWineD3DDeviceParent methods */
2623 static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
2625 TRACE("iface %p, device %p\n", iface, device);
2628 static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
2629 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, DWORD usage,
2630 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface)
2632 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2633 IDirect3DSurface8Impl *d3d_surface;
2634 BOOL lockable = TRUE;
2637 TRACE("iface %p, superior %p, width %u, height %u, format %#x, usage %#x,\n"
2638 "\tpool %#x, level %u, face %u, surface %p\n",
2639 iface, superior, width, height, format, usage, pool, level, face, surface);
2642 if (pool == WINED3DPOOL_DEFAULT && !(usage & WINED3DUSAGE_DYNAMIC)) lockable = FALSE;
2644 hr = IDirect3DDevice8Impl_CreateSurface((IDirect3DDevice8 *)This, width, height,
2645 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
2646 (IDirect3DSurface8 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
2649 ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
2653 *surface = d3d_surface->wineD3DSurface;
2654 IWineD3DSurface_AddRef(*surface);
2656 d3d_surface->container = superior;
2657 IUnknown_Release(d3d_surface->parentDevice);
2658 d3d_surface->parentDevice = NULL;
2660 IDirect3DSurface8_Release((IDirect3DSurface8 *)d3d_surface);
2661 d3d_surface->forwardReference = superior;
2666 static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
2667 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2668 DWORD multisample_quality, BOOL lockable, IWineD3DSurface **surface)
2670 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2671 IDirect3DSurface8Impl *d3d_surface;
2674 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2675 "\tmultisample_quality %u, lockable %u, surface %p\n",
2676 iface, superior, width, height, format, multisample_type, multisample_quality, lockable, surface);
2678 hr = IDirect3DDevice8_CreateRenderTarget((IDirect3DDevice8 *)This, width, height,
2679 d3dformat_from_wined3dformat(format), multisample_type, lockable, (IDirect3DSurface8 **)&d3d_surface);
2682 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
2686 *surface = d3d_surface->wineD3DSurface;
2687 IWineD3DSurface_AddRef(*surface);
2689 d3d_surface->container = (IUnknown *)This;
2690 /* Implicit surfaces are created with an refcount of 0 */
2691 IUnknown_Release((IUnknown *)d3d_surface);
2696 static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
2697 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2698 DWORD multisample_quality, BOOL discard, IWineD3DSurface **surface)
2700 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2701 IDirect3DSurface8Impl *d3d_surface;
2704 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2705 "\tmultisample_quality %u, discard %u, surface %p\n",
2706 iface, superior, width, height, format, multisample_type, multisample_quality, discard, surface);
2708 hr = IDirect3DDevice8_CreateDepthStencilSurface((IDirect3DDevice8 *)This, width, height,
2709 d3dformat_from_wined3dformat(format), multisample_type, (IDirect3DSurface8 **)&d3d_surface);
2712 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
2716 *surface = d3d_surface->wineD3DSurface;
2717 IWineD3DSurface_AddRef(*surface);
2719 d3d_surface->container = (IUnknown *)This;
2720 /* Implicit surfaces are created with an refcount of 0 */
2721 IUnknown_Release((IUnknown *)d3d_surface);
2726 static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
2727 IUnknown *superior, UINT width, UINT height, UINT depth, WINED3DFORMAT format,
2728 WINED3DPOOL pool, DWORD usage, IWineD3DVolume **volume)
2730 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2731 IDirect3DVolume8Impl *object;
2734 TRACE("iface %p, superior %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
2735 iface, superior, width, height, depth, format, pool, usage, volume);
2737 /* Allocate the storage for the device */
2738 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2741 FIXME("Allocation of memory failed\n");
2743 return D3DERR_OUTOFVIDEOMEMORY;
2746 hr = volume_init(object, This, width, height, depth, usage, format, pool);
2749 WARN("Failed to initialize volume, hr %#x.\n", hr);
2750 HeapFree(GetProcessHeap(), 0, object);
2754 *volume = object->wineD3DVolume;
2755 IWineD3DVolume_AddRef(*volume);
2756 IDirect3DVolume8_Release((IDirect3DVolume8 *)object);
2758 object->container = superior;
2759 object->forwardReference = superior;
2761 TRACE("(%p) Created volume %p\n", iface, object);
2766 static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
2767 WINED3DPRESENT_PARAMETERS *present_parameters, IWineD3DSwapChain **swapchain)
2769 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2770 IDirect3DSwapChain8Impl *d3d_swapchain;
2771 D3DPRESENT_PARAMETERS local_parameters;
2774 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
2776 /* Copy the presentation parameters */
2777 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
2778 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
2779 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
2780 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
2781 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
2782 local_parameters.SwapEffect = present_parameters->SwapEffect;
2783 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
2784 local_parameters.Windowed = present_parameters->Windowed;
2785 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
2786 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
2787 local_parameters.Flags = present_parameters->Flags;
2788 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
2789 local_parameters.FullScreen_PresentationInterval = present_parameters->PresentationInterval;
2791 hr = IDirect3DDevice8_CreateAdditionalSwapChain((IDirect3DDevice8 *)This,
2792 &local_parameters, (IDirect3DSwapChain8 **)&d3d_swapchain);
2795 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
2800 *swapchain = d3d_swapchain->wineD3DSwapChain;
2801 IUnknown_Release(d3d_swapchain->parentDevice);
2802 d3d_swapchain->parentDevice = NULL;
2804 /* Copy back the presentation parameters */
2805 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
2806 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
2807 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
2808 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
2809 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
2810 present_parameters->SwapEffect = local_parameters.SwapEffect;
2811 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
2812 present_parameters->Windowed = local_parameters.Windowed;
2813 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
2814 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
2815 present_parameters->Flags = local_parameters.Flags;
2816 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
2817 present_parameters->PresentationInterval = local_parameters.FullScreen_PresentationInterval;
2822 const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl =
2824 /* IUnknown methods */
2825 device_parent_QueryInterface,
2826 device_parent_AddRef,
2827 device_parent_Release,
2828 /* IWineD3DDeviceParent methods */
2829 device_parent_WineD3DDeviceCreated,
2830 device_parent_CreateSurface,
2831 device_parent_CreateRenderTarget,
2832 device_parent_CreateDepthStencilSurface,
2833 device_parent_CreateVolume,
2834 device_parent_CreateSwapChain,