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 **ppVolumeTexture)
701 IDirect3DVolumeTexture8Impl *object;
702 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
703 HRESULT hrc = D3D_OK;
705 TRACE("(%p) Relay\n", This);
707 /* Allocate the storage for the device */
708 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVolumeTexture8Impl));
709 if (NULL == object) {
710 FIXME("(%p) allocation of memory failed\n", This);
711 *ppVolumeTexture = NULL;
712 return D3DERR_OUTOFVIDEOMEMORY;
715 object->lpVtbl = &Direct3DVolumeTexture8_Vtbl;
718 wined3d_mutex_lock();
719 hrc = IWineD3DDevice_CreateVolumeTexture(This->WineD3DDevice, Width, Height, Depth, Levels,
720 Usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(Format),
721 Pool, &object->wineD3DVolumeTexture, (IUnknown *)object);
722 wined3d_mutex_unlock();
727 FIXME("(%p) call to IWineD3DDevice_CreateVolumeTexture failed\n", This);
728 HeapFree(GetProcessHeap(), 0, object);
729 *ppVolumeTexture = NULL;
731 IUnknown_AddRef(iface);
732 object->parentDevice = iface;
733 *ppVolumeTexture = (LPDIRECT3DVOLUMETEXTURE8) object;
735 TRACE("(%p) returning %p\n", This , *ppVolumeTexture);
739 static HRESULT WINAPI IDirect3DDevice8Impl_CreateCubeTexture(IDirect3DDevice8 *iface, UINT EdgeLength,
740 UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DCubeTexture8 **ppCubeTexture)
742 IDirect3DCubeTexture8Impl *object;
743 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
746 TRACE("(%p) : ELen(%d) Lvl(%d) Usage(%d) fmt(%u), Pool(%d)\n" , This, EdgeLength, Levels, Usage, Format, Pool);
748 /* Allocate the storage for the device */
749 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
751 if (NULL == object) {
752 FIXME("(%p) allocation of CubeTexture failed\n", This);
753 *ppCubeTexture = NULL;
754 return D3DERR_OUTOFVIDEOMEMORY;
757 object->lpVtbl = &Direct3DCubeTexture8_Vtbl;
760 wined3d_mutex_lock();
761 hr = IWineD3DDevice_CreateCubeTexture(This->WineD3DDevice, EdgeLength, Levels, Usage & WINED3DUSAGE_MASK,
762 wined3dformat_from_d3dformat(Format), Pool, &object->wineD3DCubeTexture, (IUnknown *)object);
763 wined3d_mutex_unlock();
768 FIXME("(%p) call to IWineD3DDevice_CreateCubeTexture failed\n", This);
769 HeapFree(GetProcessHeap(), 0, object);
770 *ppCubeTexture = NULL;
772 IUnknown_AddRef(iface);
773 object->parentDevice = iface;
774 *ppCubeTexture = (LPDIRECT3DCUBETEXTURE8) object;
777 TRACE("(%p) returning %p\n",This, *ppCubeTexture);
781 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexBuffer(LPDIRECT3DDEVICE8 iface, UINT Size, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer8** ppVertexBuffer) {
782 IDirect3DVertexBuffer8Impl *object;
783 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
784 HRESULT hrc = D3D_OK;
786 TRACE("(%p) Relay\n", This);
787 /* Allocate the storage for the device */
788 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexBuffer8Impl));
789 if (NULL == object) {
790 FIXME("Allocation of memory failed\n");
791 *ppVertexBuffer = NULL;
792 return D3DERR_OUTOFVIDEOMEMORY;
795 object->lpVtbl = &Direct3DVertexBuffer8_Vtbl;
798 wined3d_mutex_lock();
799 hrc = IWineD3DDevice_CreateVertexBuffer(This->WineD3DDevice, Size, Usage & WINED3DUSAGE_MASK,
800 0 /* fvf for ddraw only */, (WINED3DPOOL)Pool, &object->wineD3DVertexBuffer, (IUnknown *)object);
801 wined3d_mutex_unlock();
808 FIXME("(%p) call to IWineD3DDevice_CreateVertexBuffer failed\n", This);
809 HeapFree(GetProcessHeap(), 0, object);
810 *ppVertexBuffer = NULL;
812 IUnknown_AddRef(iface);
813 object->parentDevice = iface;
814 *ppVertexBuffer = (LPDIRECT3DVERTEXBUFFER8) object;
819 static HRESULT WINAPI IDirect3DDevice8Impl_CreateIndexBuffer(LPDIRECT3DDEVICE8 iface, UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DIndexBuffer8** ppIndexBuffer) {
820 IDirect3DIndexBuffer8Impl *object;
821 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
822 HRESULT hrc = D3D_OK;
824 TRACE("(%p) Relay\n", This);
825 /* Allocate the storage for the device */
826 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
827 if (NULL == object) {
828 FIXME("Allocation of memory failed\n");
829 *ppIndexBuffer = NULL;
830 return D3DERR_OUTOFVIDEOMEMORY;
833 object->lpVtbl = &Direct3DIndexBuffer8_Vtbl;
835 object->format = wined3dformat_from_d3dformat(Format);
836 TRACE("Calling wined3d create index buffer\n");
838 wined3d_mutex_lock();
839 hrc = IWineD3DDevice_CreateIndexBuffer(This->WineD3DDevice, Length, Usage & WINED3DUSAGE_MASK,
840 (WINED3DPOOL)Pool, &object->wineD3DIndexBuffer, (IUnknown *)object);
841 wined3d_mutex_unlock();
846 FIXME("(%p) call to IWineD3DDevice_CreateIndexBuffer failed\n", This);
847 HeapFree(GetProcessHeap(), 0, object);
848 *ppIndexBuffer = NULL;
850 IUnknown_AddRef(iface);
851 object->parentDevice = iface;
852 *ppIndexBuffer = (LPDIRECT3DINDEXBUFFER8)object;
857 static HRESULT IDirect3DDevice8Impl_CreateSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height,
858 D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IDirect3DSurface8 **ppSurface,
859 UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality)
861 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
862 IDirect3DSurface8Impl *object;
865 TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
867 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface8Impl));
870 FIXME("Failed to allocate surface memory.\n");
871 return D3DERR_OUTOFVIDEOMEMORY;
874 hr = surface_init(object, This, Width, Height, Format, Lockable, Discard,
875 Level, Usage, Pool, MultiSample, MultisampleQuality);
878 WARN("Failed to initialize surface, hr %#x.\n", hr);
879 HeapFree(GetProcessHeap(), 0, object);
883 TRACE("Created surface %p.\n", object);
884 *ppSurface = (IDirect3DSurface8 *)object;
889 static HRESULT WINAPI IDirect3DDevice8Impl_CreateRenderTarget(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, BOOL Lockable, IDirect3DSurface8** ppSurface) {
893 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, Lockable, FALSE /* Discard */,
894 0 /* Level */, ppSurface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, MultiSample, 0);
899 static HRESULT WINAPI IDirect3DDevice8Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, IDirect3DSurface8** ppSurface) {
903 /* TODO: Verify that Discard is false */
904 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE,
905 0 /* Level */, ppSurface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, MultiSample, 0);
910 /* IDirect3DDevice8Impl::CreateImageSurface returns surface with pool type SYSTEMMEM */
911 static HRESULT WINAPI IDirect3DDevice8Impl_CreateImageSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, IDirect3DSurface8** ppSurface) {
915 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE /* Discard */,
916 0 /* Level */, ppSurface, 0 /* Usage (undefined/none) */, D3DPOOL_SYSTEMMEM, D3DMULTISAMPLE_NONE,
917 0 /* MultisampleQuality */);
922 static HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8 *pSourceSurface, CONST RECT *pSourceRects, UINT cRects, IDirect3DSurface8 *pDestinationSurface, CONST POINT *pDestPoints) {
923 IDirect3DSurface8Impl *Source = (IDirect3DSurface8Impl *) pSourceSurface;
924 IDirect3DSurface8Impl *Dest = (IDirect3DSurface8Impl *) pDestinationSurface;
926 HRESULT hr = WINED3D_OK;
927 WINED3DFORMAT srcFormat, destFormat;
928 UINT srcWidth, destWidth;
929 UINT srcHeight, destHeight;
931 WINED3DSURFACE_DESC winedesc;
933 TRACE("(%p) pSrcSur=%p, pSourceRects=%p, cRects=%d, pDstSur=%p, pDestPtsArr=%p\n", iface,
934 pSourceSurface, pSourceRects, cRects, pDestinationSurface, pDestPoints);
937 /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the destination texture is in WINED3DPOOL_DEFAULT */
939 wined3d_mutex_lock();
940 IWineD3DSurface_GetDesc(Source->wineD3DSurface, &winedesc);
941 srcFormat = winedesc.format;
942 srcWidth = winedesc.width;
943 srcHeight = winedesc.height;
944 srcSize = winedesc.size;
946 IWineD3DSurface_GetDesc(Dest->wineD3DSurface, &winedesc);
947 destFormat = winedesc.format;
948 destWidth = winedesc.width;
949 destHeight = winedesc.height;
951 /* Check that the source and destination formats match */
952 if (srcFormat != destFormat && WINED3DFMT_UNKNOWN != destFormat) {
953 WARN("(%p) source %p format must match the dest %p format, returning WINED3DERR_INVALIDCALL\n", iface, pSourceSurface, pDestinationSurface);
954 wined3d_mutex_unlock();
955 return WINED3DERR_INVALIDCALL;
956 } else if (WINED3DFMT_UNKNOWN == destFormat) {
957 TRACE("(%p) : Converting destination surface from WINED3DFMT_UNKNOWN to the source format\n", iface);
958 IWineD3DSurface_SetFormat(Dest->wineD3DSurface, srcFormat);
959 destFormat = srcFormat;
962 /* Quick if complete copy ... */
963 if (cRects == 0 && pSourceRects == NULL && pDestPoints == NULL) {
964 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
967 /* Copy rect by rect */
968 if (NULL != pSourceRects && NULL != pDestPoints) {
969 for (i = 0; i < cRects; ++i) {
970 IWineD3DSurface_BltFast(Dest->wineD3DSurface, pDestPoints[i].x, pDestPoints[i].y, Source->wineD3DSurface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
973 for (i = 0; i < cRects; ++i) {
974 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
978 wined3d_mutex_unlock();
983 static HRESULT WINAPI IDirect3DDevice8Impl_UpdateTexture(LPDIRECT3DDEVICE8 iface, IDirect3DBaseTexture8* pSourceTexture, IDirect3DBaseTexture8* pDestinationTexture) {
984 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
986 TRACE("(%p) Relay\n" , This);
988 wined3d_mutex_lock();
989 hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice, ((IDirect3DBaseTexture8Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture8Impl *)pDestinationTexture)->wineD3DBaseTexture);
990 wined3d_mutex_unlock();
995 static HRESULT WINAPI IDirect3DDevice8Impl_GetFrontBuffer(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pDestSurface) {
996 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
997 IDirect3DSurface8Impl *destSurface = (IDirect3DSurface8Impl *)pDestSurface;
1000 TRACE("(%p) Relay\n" , This);
1002 if (pDestSurface == NULL) {
1003 WARN("(%p) : Caller passed NULL as pDestSurface returning D3DERR_INVALIDCALL\n", This);
1004 return D3DERR_INVALIDCALL;
1007 wined3d_mutex_lock();
1008 hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, 0, destSurface->wineD3DSurface);
1009 wined3d_mutex_unlock();
1014 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pRenderTarget, IDirect3DSurface8* pNewZStencil) {
1015 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1016 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl *)pRenderTarget;
1017 IDirect3DSurface8Impl *pZSurface = (IDirect3DSurface8Impl *)pNewZStencil;
1018 IWineD3DSurface *original_ds = NULL;
1020 TRACE("(%p) Relay\n" , This);
1022 wined3d_mutex_lock();
1024 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice, &original_ds);
1025 if (hr == WINED3D_OK || hr == WINED3DERR_NOTFOUND)
1027 hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, pZSurface ? pZSurface->wineD3DSurface : NULL);
1028 if (SUCCEEDED(hr) && pSurface)
1029 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, 0, pSurface->wineD3DSurface);
1030 if (FAILED(hr)) IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, original_ds);
1032 if (original_ds) IWineD3DSurface_Release(original_ds);
1034 wined3d_mutex_unlock();
1039 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppRenderTarget) {
1040 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1041 HRESULT hr = D3D_OK;
1042 IWineD3DSurface *pRenderTarget;
1044 TRACE("(%p) Relay\n" , This);
1046 if (ppRenderTarget == NULL) {
1047 return D3DERR_INVALIDCALL;
1050 wined3d_mutex_lock();
1051 hr = IWineD3DDevice_GetRenderTarget(This->WineD3DDevice, 0, &pRenderTarget);
1053 if (hr == D3D_OK && pRenderTarget != NULL) {
1054 IWineD3DSurface_GetParent(pRenderTarget,(IUnknown**)ppRenderTarget);
1055 IWineD3DSurface_Release(pRenderTarget);
1057 FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
1058 *ppRenderTarget = NULL;
1060 wined3d_mutex_unlock();
1065 static HRESULT WINAPI IDirect3DDevice8Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppZStencilSurface) {
1066 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1067 HRESULT hr = D3D_OK;
1068 IWineD3DSurface *pZStencilSurface;
1070 TRACE("(%p) Relay\n" , This);
1071 if(ppZStencilSurface == NULL){
1072 return D3DERR_INVALIDCALL;
1075 wined3d_mutex_lock();
1076 hr=IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
1077 if (hr == WINED3D_OK) {
1078 IWineD3DSurface_GetParent(pZStencilSurface,(IUnknown**)ppZStencilSurface);
1079 IWineD3DSurface_Release(pZStencilSurface);
1081 if (hr != WINED3DERR_NOTFOUND)
1082 FIXME("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
1083 *ppZStencilSurface = NULL;
1085 wined3d_mutex_unlock();
1090 static HRESULT WINAPI IDirect3DDevice8Impl_BeginScene(LPDIRECT3DDEVICE8 iface) {
1091 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1093 TRACE("(%p) Relay\n" , This);
1095 wined3d_mutex_lock();
1096 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
1097 wined3d_mutex_unlock();
1102 static HRESULT WINAPI IDirect3DDevice8Impl_EndScene(LPDIRECT3DDEVICE8 iface) {
1103 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1105 TRACE("(%p) Relay\n" , This);
1107 wined3d_mutex_lock();
1108 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
1109 wined3d_mutex_unlock();
1114 static HRESULT WINAPI IDirect3DDevice8Impl_Clear(LPDIRECT3DDEVICE8 iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
1115 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1117 TRACE("(%p) Relay\n" , This);
1119 /* Note: D3DRECT is compatible with WINED3DRECT */
1120 wined3d_mutex_lock();
1121 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (CONST WINED3DRECT*) pRects, Flags, Color, Z, Stencil);
1122 wined3d_mutex_unlock();
1127 static HRESULT WINAPI IDirect3DDevice8Impl_SetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
1128 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1130 TRACE("(%p) Relay\n" , This);
1132 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1133 wined3d_mutex_lock();
1134 hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
1135 wined3d_mutex_unlock();
1140 static HRESULT WINAPI IDirect3DDevice8Impl_GetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State,D3DMATRIX* pMatrix) {
1141 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1143 TRACE("(%p) Relay\n" , This);
1145 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1146 wined3d_mutex_lock();
1147 hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
1148 wined3d_mutex_unlock();
1153 static HRESULT WINAPI IDirect3DDevice8Impl_MultiplyTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
1154 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1156 TRACE("(%p) Relay\n" , This);
1158 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1159 wined3d_mutex_lock();
1160 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
1161 wined3d_mutex_unlock();
1166 static HRESULT WINAPI IDirect3DDevice8Impl_SetViewport(LPDIRECT3DDEVICE8 iface, CONST D3DVIEWPORT8* pViewport) {
1167 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1169 TRACE("(%p) Relay\n" , This);
1171 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1172 wined3d_mutex_lock();
1173 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
1174 wined3d_mutex_unlock();
1179 static HRESULT WINAPI IDirect3DDevice8Impl_GetViewport(LPDIRECT3DDEVICE8 iface, D3DVIEWPORT8* pViewport) {
1180 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1182 TRACE("(%p) Relay\n" , This);
1184 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1185 wined3d_mutex_lock();
1186 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
1187 wined3d_mutex_unlock();
1192 static HRESULT WINAPI IDirect3DDevice8Impl_SetMaterial(LPDIRECT3DDEVICE8 iface, CONST D3DMATERIAL8* pMaterial) {
1193 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1195 TRACE("(%p) Relay\n" , This);
1197 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1198 wined3d_mutex_lock();
1199 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
1200 wined3d_mutex_unlock();
1205 static HRESULT WINAPI IDirect3DDevice8Impl_GetMaterial(LPDIRECT3DDEVICE8 iface, D3DMATERIAL8* pMaterial) {
1206 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1208 TRACE("(%p) Relay\n" , This);
1210 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1211 wined3d_mutex_lock();
1212 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
1213 wined3d_mutex_unlock();
1218 static HRESULT WINAPI IDirect3DDevice8Impl_SetLight(LPDIRECT3DDEVICE8 iface, DWORD Index, CONST D3DLIGHT8* pLight) {
1219 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1221 TRACE("(%p) Relay\n" , This);
1223 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1224 wined3d_mutex_lock();
1225 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
1226 wined3d_mutex_unlock();
1231 static HRESULT WINAPI IDirect3DDevice8Impl_GetLight(LPDIRECT3DDEVICE8 iface, DWORD Index,D3DLIGHT8* pLight) {
1232 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1234 TRACE("(%p) Relay\n" , This);
1236 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1237 wined3d_mutex_lock();
1238 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1239 wined3d_mutex_unlock();
1244 static HRESULT WINAPI IDirect3DDevice8Impl_LightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL Enable) {
1245 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1247 TRACE("(%p) Relay\n" , This);
1249 wined3d_mutex_lock();
1250 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1251 wined3d_mutex_unlock();
1256 static HRESULT WINAPI IDirect3DDevice8Impl_GetLightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL* pEnable) {
1257 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1259 TRACE("(%p) Relay\n" , This);
1261 wined3d_mutex_lock();
1262 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1263 wined3d_mutex_unlock();
1268 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,CONST float* pPlane) {
1269 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1271 TRACE("(%p) Relay\n" , This);
1273 wined3d_mutex_lock();
1274 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1275 wined3d_mutex_unlock();
1280 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,float* pPlane) {
1281 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1283 TRACE("(%p) Relay\n" , This);
1285 wined3d_mutex_lock();
1286 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1287 wined3d_mutex_unlock();
1292 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD Value) {
1293 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1295 TRACE("(%p) Relay\n" , This);
1297 wined3d_mutex_lock();
1298 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1299 wined3d_mutex_unlock();
1304 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD* pValue) {
1305 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1307 TRACE("(%p) Relay\n" , This);
1309 wined3d_mutex_lock();
1310 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1311 wined3d_mutex_unlock();
1316 static HRESULT WINAPI IDirect3DDevice8Impl_BeginStateBlock(LPDIRECT3DDEVICE8 iface) {
1317 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1319 TRACE("(%p)\n", This);
1321 wined3d_mutex_lock();
1322 hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
1323 wined3d_mutex_unlock();
1328 static HRESULT WINAPI IDirect3DDevice8Impl_EndStateBlock(LPDIRECT3DDEVICE8 iface, DWORD* pToken) {
1329 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1331 IWineD3DStateBlock* wineD3DStateBlock;
1332 IDirect3DStateBlock8Impl* object;
1334 TRACE("(%p) Relay\n", This);
1336 /* Tell wineD3D to endstateblock before anything else (in case we run out
1337 * of memory later and cause locking problems)
1339 wined3d_mutex_lock();
1340 hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice , &wineD3DStateBlock);
1342 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
1343 wined3d_mutex_unlock();
1347 /* allocate a new IDirectD3DStateBlock */
1348 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY ,sizeof(IDirect3DStateBlock8Impl));
1350 object->lpVtbl = &Direct3DStateBlock8_Vtbl;
1352 object->wineD3DStateBlock = wineD3DStateBlock;
1354 *pToken = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_SB);
1355 wined3d_mutex_unlock();
1357 if (*pToken == D3D8_INVALID_HANDLE)
1359 ERR("Failed to create a handle\n");
1360 IDirect3DStateBlock8_Release((IDirect3DStateBlock8 *)object);
1365 TRACE("Returning %#x (%p).\n", *pToken, object);
1370 static HRESULT WINAPI IDirect3DDevice8Impl_ApplyStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1371 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1372 IDirect3DStateBlock8Impl *pSB;
1375 TRACE("(%p) %#x Relay\n", This, Token);
1377 wined3d_mutex_lock();
1378 pSB = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1381 WARN("Invalid handle (%#x) passed.\n", Token);
1382 wined3d_mutex_unlock();
1383 return D3DERR_INVALIDCALL;
1385 hr = IWineD3DStateBlock_Apply(pSB->wineD3DStateBlock);
1386 wined3d_mutex_unlock();
1391 static HRESULT WINAPI IDirect3DDevice8Impl_CaptureStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1392 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1393 IDirect3DStateBlock8Impl *pSB;
1396 TRACE("(%p) %#x Relay\n", This, Token);
1398 wined3d_mutex_lock();
1399 pSB = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1402 WARN("Invalid handle (%#x) passed.\n", Token);
1403 wined3d_mutex_unlock();
1404 return D3DERR_INVALIDCALL;
1406 hr = IWineD3DStateBlock_Capture(pSB->wineD3DStateBlock);
1407 wined3d_mutex_unlock();
1412 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1413 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1414 IDirect3DStateBlock8Impl *pSB;
1416 TRACE("(%p) Relay\n", This);
1418 wined3d_mutex_lock();
1419 pSB = d3d8_free_handle(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
1420 wined3d_mutex_unlock();
1424 WARN("Invalid handle (%#x) passed.\n", Token);
1425 return D3DERR_INVALIDCALL;
1428 if (IUnknown_Release((IUnknown *)pSB))
1430 ERR("Stateblock %p has references left, this shouldn't happen.\n", pSB);
1436 static HRESULT WINAPI IDirect3DDevice8Impl_CreateStateBlock(IDirect3DDevice8 *iface,
1437 D3DSTATEBLOCKTYPE Type, DWORD *handle)
1439 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1440 IDirect3DStateBlock8Impl *object;
1443 TRACE("(%p) Relay\n", This);
1445 if (Type != D3DSBT_ALL
1446 && Type != D3DSBT_PIXELSTATE
1447 && Type != D3DSBT_VERTEXSTATE)
1449 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1450 return D3DERR_INVALIDCALL;
1453 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DStateBlock8Impl));
1456 ERR("Failed to allocate memory.\n");
1457 return E_OUTOFMEMORY;
1460 object->lpVtbl = &Direct3DStateBlock8_Vtbl;
1463 wined3d_mutex_lock();
1464 hr = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type,
1465 &object->wineD3DStateBlock, (IUnknown *)object);
1468 wined3d_mutex_unlock();
1469 ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr);
1470 HeapFree(GetProcessHeap(), 0, object);
1474 *handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_SB);
1475 wined3d_mutex_unlock();
1477 if (*handle == D3D8_INVALID_HANDLE)
1479 ERR("Failed to allocate a handle.\n");
1480 IDirect3DStateBlock8_Release((IDirect3DStateBlock8 *)object);
1485 TRACE("Returning %#x (%p).\n", *handle, object);
1490 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipStatus(LPDIRECT3DDEVICE8 iface, CONST D3DCLIPSTATUS8* pClipStatus) {
1491 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1493 TRACE("(%p) Relay\n" , This);
1494 /* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
1496 wined3d_mutex_lock();
1497 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1498 wined3d_mutex_unlock();
1503 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipStatus(LPDIRECT3DDEVICE8 iface, D3DCLIPSTATUS8* pClipStatus) {
1504 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1506 TRACE("(%p) Relay\n" , This);
1508 wined3d_mutex_lock();
1509 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1510 wined3d_mutex_unlock();
1515 static HRESULT WINAPI IDirect3DDevice8Impl_GetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage,IDirect3DBaseTexture8** ppTexture) {
1516 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1517 IWineD3DBaseTexture *retTexture = NULL;
1518 HRESULT rc = D3D_OK;
1520 TRACE("(%p) Relay\n" , This);
1522 if(ppTexture == NULL){
1523 return D3DERR_INVALIDCALL;
1526 wined3d_mutex_lock();
1527 rc = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
1528 if (rc == D3D_OK && NULL != retTexture) {
1529 IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
1530 IWineD3DBaseTexture_Release(retTexture);
1532 FIXME("Call to get texture (%d) failed (%p)\n", Stage, retTexture);
1535 wined3d_mutex_unlock();
1540 static HRESULT WINAPI IDirect3DDevice8Impl_SetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage, IDirect3DBaseTexture8* pTexture) {
1541 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1543 TRACE("(%p) Relay %d %p\n" , This, Stage, pTexture);
1545 wined3d_mutex_lock();
1546 hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
1547 pTexture==NULL ? NULL : ((IDirect3DBaseTexture8Impl *)pTexture)->wineD3DBaseTexture);
1548 wined3d_mutex_unlock();
1553 static const struct tss_lookup
1560 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 0, unused */
1561 {FALSE, WINED3DTSS_COLOROP}, /* 1, D3DTSS_COLOROP */
1562 {FALSE, WINED3DTSS_COLORARG1}, /* 2, D3DTSS_COLORARG1 */
1563 {FALSE, WINED3DTSS_COLORARG2}, /* 3, D3DTSS_COLORARG2 */
1564 {FALSE, WINED3DTSS_ALPHAOP}, /* 4, D3DTSS_ALPHAOP */
1565 {FALSE, WINED3DTSS_ALPHAARG1}, /* 5, D3DTSS_ALPHAARG1 */
1566 {FALSE, WINED3DTSS_ALPHAARG2}, /* 6, D3DTSS_ALPHAARG2 */
1567 {FALSE, WINED3DTSS_BUMPENVMAT00}, /* 7, D3DTSS_BUMPENVMAT00 */
1568 {FALSE, WINED3DTSS_BUMPENVMAT01}, /* 8, D3DTSS_BUMPENVMAT01 */
1569 {FALSE, WINED3DTSS_BUMPENVMAT10}, /* 9, D3DTSS_BUMPENVMAT10 */
1570 {FALSE, WINED3DTSS_BUMPENVMAT11}, /* 10, D3DTSS_BUMPENVMAT11 */
1571 {FALSE, WINED3DTSS_TEXCOORDINDEX}, /* 11, D3DTSS_TEXCOORDINDEX */
1572 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 12, unused */
1573 {TRUE, WINED3DSAMP_ADDRESSU}, /* 13, D3DTSS_ADDRESSU */
1574 {TRUE, WINED3DSAMP_ADDRESSV}, /* 14, D3DTSS_ADDRESSV */
1575 {TRUE, WINED3DSAMP_BORDERCOLOR}, /* 15, D3DTSS_BORDERCOLOR */
1576 {TRUE, WINED3DSAMP_MAGFILTER}, /* 16, D3DTSS_MAGFILTER */
1577 {TRUE, WINED3DSAMP_MINFILTER}, /* 17, D3DTSS_MINFILTER */
1578 {TRUE, WINED3DSAMP_MIPFILTER}, /* 18, D3DTSS_MIPFILTER */
1579 {TRUE, WINED3DSAMP_MIPMAPLODBIAS}, /* 19, D3DTSS_MIPMAPLODBIAS */
1580 {TRUE, WINED3DSAMP_MAXMIPLEVEL}, /* 20, D3DTSS_MAXMIPLEVEL */
1581 {TRUE, WINED3DSAMP_MAXANISOTROPY}, /* 21, D3DTSS_MAXANISOTROPY */
1582 {FALSE, WINED3DTSS_BUMPENVLSCALE}, /* 22, D3DTSS_BUMPENVLSCALE */
1583 {FALSE, WINED3DTSS_BUMPENVLOFFSET}, /* 23, D3DTSS_BUMPENVLOFFSET */
1584 {FALSE, WINED3DTSS_TEXTURETRANSFORMFLAGS}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1585 {TRUE, WINED3DSAMP_ADDRESSW}, /* 25, D3DTSS_ADDRESSW */
1586 {FALSE, WINED3DTSS_COLORARG0}, /* 26, D3DTSS_COLORARG0 */
1587 {FALSE, WINED3DTSS_ALPHAARG0}, /* 27, D3DTSS_ALPHAARG0 */
1588 {FALSE, WINED3DTSS_RESULTARG}, /* 28, D3DTSS_RESULTARG */
1591 static HRESULT WINAPI IDirect3DDevice8Impl_GetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD* pValue) {
1592 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1593 const struct tss_lookup *l = &tss_lookup[Type];
1595 TRACE("(%p) Relay\n" , This);
1597 wined3d_mutex_lock();
1598 if (l->sampler_state) hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Stage, l->state, pValue);
1599 else hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, l->state, pValue);
1600 wined3d_mutex_unlock();
1605 static HRESULT WINAPI IDirect3DDevice8Impl_SetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
1606 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1607 const struct tss_lookup *l = &tss_lookup[Type];
1609 TRACE("(%p) Relay\n" , This);
1611 wined3d_mutex_lock();
1612 if (l->sampler_state) hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Stage, l->state, Value);
1613 else hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, l->state, Value);
1614 wined3d_mutex_unlock();
1619 static HRESULT WINAPI IDirect3DDevice8Impl_ValidateDevice(LPDIRECT3DDEVICE8 iface, DWORD* pNumPasses) {
1620 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1622 TRACE("(%p) Relay\n" , This);
1624 wined3d_mutex_lock();
1625 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1626 wined3d_mutex_unlock();
1631 static HRESULT WINAPI IDirect3DDevice8Impl_GetInfo(LPDIRECT3DDEVICE8 iface, DWORD DevInfoID, void* pDevInfoStruct, DWORD DevInfoStructSize) {
1632 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1633 FIXME("(%p) : stub\n", This);
1637 static HRESULT WINAPI IDirect3DDevice8Impl_SetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, CONST PALETTEENTRY* pEntries) {
1638 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1640 TRACE("(%p) Relay\n" , This);
1642 wined3d_mutex_lock();
1643 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1644 wined3d_mutex_unlock();
1649 static HRESULT WINAPI IDirect3DDevice8Impl_GetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
1650 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1652 TRACE("(%p) Relay\n" , This);
1654 wined3d_mutex_lock();
1655 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1656 wined3d_mutex_unlock();
1661 static HRESULT WINAPI IDirect3DDevice8Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber) {
1662 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1664 TRACE("(%p) Relay\n" , This);
1666 wined3d_mutex_lock();
1667 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1668 wined3d_mutex_unlock();
1673 static HRESULT WINAPI IDirect3DDevice8Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT *PaletteNumber) {
1674 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1676 TRACE("(%p) Relay\n" , This);
1678 wined3d_mutex_lock();
1679 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1680 wined3d_mutex_unlock();
1685 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitive(IDirect3DDevice8 *iface, D3DPRIMITIVETYPE PrimitiveType,
1686 UINT StartVertex, UINT PrimitiveCount)
1688 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1690 TRACE("(%p) Relay\n" , This);
1692 wined3d_mutex_lock();
1693 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1694 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
1695 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
1696 wined3d_mutex_unlock();
1701 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,
1702 UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount) {
1703 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1705 TRACE("(%p) Relay\n" , This);
1707 wined3d_mutex_lock();
1708 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1709 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, startIndex,
1710 vertex_count_from_primitive_count(PrimitiveType, primCount));
1711 wined3d_mutex_unlock();
1716 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT PrimitiveCount,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride) {
1717 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1719 TRACE("(%p) Relay\n" , This);
1721 wined3d_mutex_lock();
1722 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1723 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
1724 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
1725 pVertexStreamZeroData, VertexStreamZeroStride);
1726 wined3d_mutex_unlock();
1731 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,
1732 UINT NumVertexIndices,UINT PrimitiveCount,CONST void* pIndexData,
1733 D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,
1734 UINT VertexStreamZeroStride) {
1735 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1737 TRACE("(%p) Relay\n" , This);
1739 wined3d_mutex_lock();
1740 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1741 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice,
1742 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
1743 wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
1744 wined3d_mutex_unlock();
1749 static HRESULT WINAPI IDirect3DDevice8Impl_ProcessVertices(LPDIRECT3DDEVICE8 iface, UINT SrcStartIndex,UINT DestIndex,UINT VertexCount,IDirect3DVertexBuffer8* pDestBuffer,DWORD Flags) {
1750 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1752 IDirect3DVertexBuffer8Impl *dest = (IDirect3DVertexBuffer8Impl *) pDestBuffer;
1753 TRACE("(%p) Relay\n" , This);
1755 wined3d_mutex_lock();
1756 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, NULL, Flags, dest->fvf);
1757 wined3d_mutex_unlock();
1762 static HRESULT IDirect3DDevice8Impl_CreateVertexDeclaration(IDirect3DDevice8 *iface, CONST DWORD *declaration, IDirect3DVertexDeclaration8 **decl_ptr) {
1763 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1764 IDirect3DVertexDeclaration8Impl *object;
1765 WINED3DVERTEXELEMENT *wined3d_elements;
1766 UINT wined3d_element_count;
1767 HRESULT hr = D3D_OK;
1769 TRACE("(%p) : declaration %p\n", This, declaration);
1771 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1773 ERR("Memory allocation failed\n");
1775 return D3DERR_OUTOFVIDEOMEMORY;
1778 object->ref_count = 1;
1779 object->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
1781 wined3d_element_count = convert_to_wined3d_declaration(declaration, &object->elements_size, &wined3d_elements);
1782 object->elements = HeapAlloc(GetProcessHeap(), 0, object->elements_size);
1783 if (!object->elements) {
1784 ERR("Memory allocation failed\n");
1785 HeapFree(GetProcessHeap(), 0, wined3d_elements);
1786 HeapFree(GetProcessHeap(), 0, object);
1788 return D3DERR_OUTOFVIDEOMEMORY;
1791 CopyMemory(object->elements, declaration, object->elements_size);
1793 wined3d_mutex_lock();
1794 hr = IWineD3DDevice_CreateVertexDeclaration(This->WineD3DDevice, &object->wined3d_vertex_declaration,
1795 (IUnknown *)object, wined3d_elements, wined3d_element_count);
1796 wined3d_mutex_unlock();
1798 HeapFree(GetProcessHeap(), 0, wined3d_elements);
1801 ERR("(%p) : IWineD3DDevice_CreateVertexDeclaration call failed\n", This);
1802 HeapFree(GetProcessHeap(), 0, object->elements);
1803 HeapFree(GetProcessHeap(), 0, object);
1805 *decl_ptr = (IDirect3DVertexDeclaration8 *)object;
1806 TRACE("(%p) : Created vertex declaration %p\n", This, object);
1812 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pDeclaration, CONST DWORD* pFunction, DWORD* ppShader, DWORD Usage) {
1813 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1814 HRESULT hrc = D3D_OK;
1815 IDirect3DVertexShader8Impl *object;
1816 const DWORD *token = pDeclaration;
1819 /* Test if the vertex declaration is valid */
1820 while (D3DVSD_END() != *token) {
1821 D3DVSD_TOKENTYPE token_type = ((*token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT);
1823 if (token_type == D3DVSD_TOKEN_STREAMDATA && !(token_type & 0x10000000)) {
1824 DWORD type = ((*token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
1825 DWORD reg = ((*token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
1827 if(reg == D3DVSDE_NORMAL && type != D3DVSDT_FLOAT3 && !pFunction) {
1828 WARN("Attempt to use a non-FLOAT3 normal with the fixed function function\n");
1829 return D3DERR_INVALIDCALL;
1832 token += parse_token(token);
1835 /* Setup a stub object for now */
1836 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1837 TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
1838 if (NULL == object) {
1839 FIXME("Allocation of memory failed\n");
1841 return D3DERR_OUTOFVIDEOMEMORY;
1845 object->lpVtbl = &Direct3DVertexShader8_Vtbl;
1847 hrc = IDirect3DDevice8Impl_CreateVertexDeclaration(iface, pDeclaration, &object->vertex_declaration);
1849 ERR("(%p) : IDirect3DDeviceImpl_CreateVertexDeclaration call failed\n", This);
1850 HeapFree(GetProcessHeap(), 0, object);
1852 return D3DERR_INVALIDCALL;
1855 wined3d_mutex_lock();
1856 handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_VS);
1857 if (handle == D3D8_INVALID_HANDLE)
1859 ERR("Failed to allocate shader handle\n");
1860 wined3d_mutex_unlock();
1861 IDirect3DVertexDeclaration8_Release(object->vertex_declaration);
1862 HeapFree(GetProcessHeap(), 0, object);
1864 return E_OUTOFMEMORY;
1868 DWORD shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
1869 *ppShader = ((IDirect3DVertexDeclaration8Impl *)object->vertex_declaration)->shader_handle = shader_handle;
1874 /* Usage is missing ... Use SetRenderState to set the sw vp render state in SetVertexShader */
1875 hrc = IWineD3DDevice_CreateVertexShader(This->WineD3DDevice, pFunction,
1876 NULL /* output signature */, &object->wineD3DVertexShader, (IUnknown *)object);
1880 /* free up object */
1881 FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n");
1882 d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_VS);
1883 IDirect3DVertexDeclaration8_Release(object->vertex_declaration);
1884 HeapFree(GetProcessHeap(), 0, object);
1889 load_local_constants(pDeclaration, object->wineD3DVertexShader);
1890 TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
1894 wined3d_mutex_unlock();
1899 static IDirect3DVertexDeclaration8Impl *IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl *This, DWORD fvf)
1901 IDirect3DVertexDeclaration8Impl *d3d8_declaration;
1903 int p, low, high; /* deliberately signed */
1904 struct FvfToDecl *convertedDecls = This->decls;
1906 TRACE("Searching for declaration for fvf %08x... ", fvf);
1909 high = This->numConvertedDecls - 1;
1910 while(low <= high) {
1911 p = (low + high) >> 1;
1913 if(convertedDecls[p].fvf == fvf) {
1914 TRACE("found %p\n", convertedDecls[p].decl);
1915 return (IDirect3DVertexDeclaration8Impl *)convertedDecls[p].decl;
1916 } else if(convertedDecls[p].fvf < fvf) {
1922 TRACE("not found. Creating and inserting at position %d.\n", low);
1924 d3d8_declaration = HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration));
1925 if (!d3d8_declaration)
1927 ERR("Memory allocation failed.\n");
1931 d3d8_declaration->ref_count = 1;
1932 d3d8_declaration->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
1933 d3d8_declaration->elements = NULL;
1934 d3d8_declaration->elements_size = 0;
1935 d3d8_declaration->shader_handle = fvf;
1937 hr = IWineD3DDevice_CreateVertexDeclarationFromFVF(This->WineD3DDevice,
1938 &d3d8_declaration->wined3d_vertex_declaration, (IUnknown *)d3d8_declaration, fvf);
1941 ERR("Failed to create wined3d vertex declaration.\n");
1942 HeapFree(GetProcessHeap(), 0, d3d8_declaration);
1946 if(This->declArraySize == This->numConvertedDecls) {
1947 int grow = This->declArraySize / 2;
1948 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
1949 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
1950 if(!convertedDecls) {
1951 /* This will destroy it */
1952 IDirect3DVertexDeclaration8_Release((IDirect3DVertexDeclaration8 *)d3d8_declaration);
1955 This->decls = convertedDecls;
1956 This->declArraySize += grow;
1959 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(convertedDecls[0]) * (This->numConvertedDecls - low));
1960 convertedDecls[low].decl = (IDirect3DVertexDeclaration8 *)d3d8_declaration;
1961 convertedDecls[low].fvf = fvf;
1962 This->numConvertedDecls++;
1964 TRACE("Returning %p. %u decls in array\n", d3d8_declaration, This->numConvertedDecls);
1965 return d3d8_declaration;
1968 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1969 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1970 IDirect3DVertexShader8Impl *shader;
1973 TRACE("(%p) : Relay\n", This);
1975 if (VS_HIGHESTFIXEDFXF >= pShader) {
1976 TRACE("Setting FVF, %#x\n", pShader);
1978 wined3d_mutex_lock();
1979 IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
1980 IDirect3DDevice8Impl_FindDecl(This, pShader)->wined3d_vertex_declaration);
1981 IWineD3DDevice_SetVertexShader(This->WineD3DDevice, NULL);
1982 wined3d_mutex_unlock();
1987 TRACE("Setting shader\n");
1989 wined3d_mutex_lock();
1990 shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
1993 WARN("Invalid handle (%#x) passed.\n", pShader);
1994 wined3d_mutex_unlock();
1996 return D3DERR_INVALIDCALL;
1999 hr = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
2000 ((IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration)->wined3d_vertex_declaration);
2001 if (SUCCEEDED(hr)) hr = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, shader->wineD3DVertexShader);
2002 wined3d_mutex_unlock();
2004 TRACE("Returning hr %#x\n", hr);
2009 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
2010 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2011 IWineD3DVertexDeclaration *wined3d_declaration;
2012 IDirect3DVertexDeclaration8 *d3d8_declaration;
2015 TRACE("(%p) : Relay device@%p\n", This, This->WineD3DDevice);
2017 wined3d_mutex_lock();
2018 hrc = IWineD3DDevice_GetVertexDeclaration(This->WineD3DDevice, &wined3d_declaration);
2021 wined3d_mutex_unlock();
2022 WARN("(%p) : Call to IWineD3DDevice_GetVertexDeclaration failed %#x (device %p)\n",
2023 This, hrc, This->WineD3DDevice);
2027 if (!wined3d_declaration)
2029 wined3d_mutex_unlock();
2034 hrc = IWineD3DVertexDeclaration_GetParent(wined3d_declaration, (IUnknown **)&d3d8_declaration);
2035 IWineD3DVertexDeclaration_Release(wined3d_declaration);
2036 wined3d_mutex_unlock();
2039 *ppShader = ((IDirect3DVertexDeclaration8Impl *)d3d8_declaration)->shader_handle;
2040 IDirect3DVertexDeclaration8_Release(d3d8_declaration);
2043 TRACE("(%p) : returning %#x\n", This, *ppShader);
2048 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
2049 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2050 IDirect3DVertexShader8Impl *shader;
2051 IWineD3DVertexShader *cur = NULL;
2053 TRACE("(%p) : pShader %#x\n", This, pShader);
2055 wined3d_mutex_lock();
2056 shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2059 WARN("Invalid handle (%#x) passed.\n", pShader);
2060 wined3d_mutex_unlock();
2062 return D3DERR_INVALIDCALL;
2065 IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &cur);
2069 if (cur == shader->wineD3DVertexShader) IDirect3DDevice8_SetVertexShader(iface, 0);
2070 IWineD3DVertexShader_Release(cur);
2073 wined3d_mutex_unlock();
2075 if (IUnknown_Release((IUnknown *)shader))
2077 ERR("Shader %p has references left, this shouldn't happen.\n", shader);
2083 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
2084 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2086 TRACE("(%p) : Relay\n", This);
2088 if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
2089 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2090 Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2091 return D3DERR_INVALIDCALL;
2094 wined3d_mutex_lock();
2095 hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2096 wined3d_mutex_unlock();
2101 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
2102 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2104 TRACE("(%p) : Relay\n", This);
2106 if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
2107 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2108 Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2109 return D3DERR_INVALIDCALL;
2112 wined3d_mutex_lock();
2113 hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2114 wined3d_mutex_unlock();
2119 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderDeclaration(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
2120 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2121 IDirect3DVertexDeclaration8Impl *declaration;
2122 IDirect3DVertexShader8Impl *shader;
2124 TRACE("(%p) : pVertexShader 0x%08x, pData %p, *pSizeOfData %u\n", This, pVertexShader, pData, *pSizeOfData);
2126 wined3d_mutex_lock();
2127 shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2128 wined3d_mutex_unlock();
2132 WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2133 return D3DERR_INVALIDCALL;
2135 declaration = (IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration;
2137 /* If pData is NULL, we just return the required size of the buffer. */
2139 *pSizeOfData = declaration->elements_size;
2143 /* MSDN claims that if *pSizeOfData is smaller than the required size
2144 * we should write the required size and return D3DERR_MOREDATA.
2145 * That's not actually true. */
2146 if (*pSizeOfData < declaration->elements_size) {
2147 return D3DERR_INVALIDCALL;
2150 CopyMemory(pData, declaration->elements, declaration->elements_size);
2155 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
2156 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2157 IDirect3DVertexShader8Impl *shader = NULL;
2160 TRACE("(%p) : pVertexShader %#x, pData %p, pSizeOfData %p\n", This, pVertexShader, pData, pSizeOfData);
2162 wined3d_mutex_lock();
2163 shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
2166 WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2167 wined3d_mutex_unlock();
2169 return D3DERR_INVALIDCALL;
2172 if (!shader->wineD3DVertexShader)
2174 wined3d_mutex_unlock();
2179 hr = IWineD3DVertexShader_GetFunction(shader->wineD3DVertexShader, pData, pSizeOfData);
2180 wined3d_mutex_unlock();
2185 static HRESULT WINAPI IDirect3DDevice8Impl_SetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8* pIndexData, UINT baseVertexIndex) {
2186 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2188 IDirect3DIndexBuffer8Impl *ib = (IDirect3DIndexBuffer8Impl *)pIndexData;
2189 TRACE("(%p) Relay\n", This);
2191 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
2192 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
2193 * vertex buffers can't be created to address them with an index that requires the 32nd bit
2194 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
2197 wined3d_mutex_lock();
2198 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, baseVertexIndex);
2199 hr = IWineD3DDevice_SetIndices(This->WineD3DDevice,
2200 ib ? ib->wineD3DIndexBuffer : NULL,
2201 ib ? ib->format : WINED3DFMT_UNKNOWN);
2202 wined3d_mutex_unlock();
2207 static HRESULT WINAPI IDirect3DDevice8Impl_GetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8** ppIndexData,UINT* pBaseVertexIndex) {
2208 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2209 IWineD3DBuffer *retIndexData = NULL;
2210 HRESULT rc = D3D_OK;
2212 TRACE("(%p) Relay\n", This);
2214 if(ppIndexData == NULL){
2215 return D3DERR_INVALIDCALL;
2218 /* The case from UINT to INT is safe because d3d8 will never set negative values */
2219 wined3d_mutex_lock();
2220 IWineD3DDevice_GetBaseVertexIndex(This->WineD3DDevice, (INT *) pBaseVertexIndex);
2221 rc = IWineD3DDevice_GetIndices(This->WineD3DDevice, &retIndexData);
2222 if (SUCCEEDED(rc) && retIndexData) {
2223 IWineD3DBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
2224 IWineD3DBuffer_Release(retIndexData);
2226 if (FAILED(rc)) FIXME("Call to GetIndices failed\n");
2227 *ppIndexData = NULL;
2229 wined3d_mutex_unlock();
2233 static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pFunction, DWORD* ppShader) {
2234 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2235 IDirect3DPixelShader8Impl *object;
2239 TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
2241 if (NULL == ppShader) {
2242 TRACE("(%p) Invalid call\n", This);
2243 return D3DERR_INVALIDCALL;
2246 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2249 ERR("Failed to allocate memmory.\n");
2250 return E_OUTOFMEMORY;
2254 object->lpVtbl = &Direct3DPixelShader8_Vtbl;
2256 wined3d_mutex_lock();
2257 hr = IWineD3DDevice_CreatePixelShader(This->WineD3DDevice, pFunction,
2258 NULL, &object->wineD3DPixelShader, (IUnknown *)object);
2261 wined3d_mutex_unlock();
2262 FIXME("(%p) call to IWineD3DDevice_CreatePixelShader failed\n", This);
2263 HeapFree(GetProcessHeap(), 0 , object);
2268 handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_PS);
2269 wined3d_mutex_unlock();
2271 if (handle == D3D8_INVALID_HANDLE)
2273 ERR("Failed to allocate shader handle\n");
2274 IDirect3DVertexShader8_Release((IUnknown *)object);
2275 return E_OUTOFMEMORY;
2278 *ppShader = object->handle = handle + VS_HIGHESTFIXEDFXF + 1;
2279 TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
2284 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
2285 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2286 IDirect3DPixelShader8Impl *shader;
2289 TRACE("(%p) : pShader %#x\n", This, pShader);
2291 wined3d_mutex_lock();
2295 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, NULL);
2296 wined3d_mutex_unlock();
2300 shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2303 WARN("Invalid handle (%#x) passed.\n", pShader);
2304 wined3d_mutex_unlock();
2305 return D3DERR_INVALIDCALL;
2308 TRACE("(%p) : Setting shader %p\n", This, shader);
2309 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, shader->wineD3DPixelShader);
2310 wined3d_mutex_unlock();
2315 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
2316 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2317 IWineD3DPixelShader *object;
2319 HRESULT hrc = D3D_OK;
2320 TRACE("(%p) Relay\n", This);
2321 if (NULL == ppShader) {
2322 TRACE("(%p) Invalid call\n", This);
2323 return D3DERR_INVALIDCALL;
2326 wined3d_mutex_lock();
2327 hrc = IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &object);
2328 if (D3D_OK == hrc && NULL != object) {
2329 IDirect3DPixelShader8Impl *d3d8_shader;
2330 hrc = IWineD3DPixelShader_GetParent(object, (IUnknown **)&d3d8_shader);
2331 IWineD3DPixelShader_Release(object);
2332 *ppShader = d3d8_shader->handle;
2333 IDirect3DPixelShader8_Release((IDirect3DPixelShader8 *)d3d8_shader);
2337 wined3d_mutex_unlock();
2339 TRACE("(%p) : returning %#x\n", This, *ppShader);
2344 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
2345 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2346 IDirect3DPixelShader8Impl *shader;
2347 IWineD3DPixelShader *cur = NULL;
2349 TRACE("(%p) : pShader %#x\n", This, pShader);
2351 wined3d_mutex_lock();
2353 shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2356 WARN("Invalid handle (%#x) passed.\n", pShader);
2357 wined3d_mutex_unlock();
2361 IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &cur);
2365 if (cur == shader->wineD3DPixelShader) IDirect3DDevice8_SetPixelShader(iface, 0);
2366 IWineD3DPixelShader_Release(cur);
2369 wined3d_mutex_unlock();
2371 if (IUnknown_Release((IUnknown *)shader))
2373 ERR("Shader %p has references left, this shouldn't happen.\n", shader);
2379 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
2380 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2382 TRACE("(%p) Relay\n", This);
2384 wined3d_mutex_lock();
2385 hr = IWineD3DDevice_SetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2386 wined3d_mutex_unlock();
2391 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
2392 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2394 TRACE("(%p) Relay\n", This);
2396 wined3d_mutex_lock();
2397 hr = IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2398 wined3d_mutex_unlock();
2403 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pPixelShader, void* pData, DWORD* pSizeOfData) {
2404 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2405 IDirect3DPixelShader8Impl *shader = NULL;
2408 TRACE("(%p) : pPixelShader %#x, pData %p, pSizeOfData %p\n", This, pPixelShader, pData, pSizeOfData);
2410 wined3d_mutex_lock();
2411 shader = d3d8_get_object(&This->handle_table, pPixelShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
2414 WARN("Invalid handle (%#x) passed.\n", pPixelShader);
2415 wined3d_mutex_unlock();
2417 return D3DERR_INVALIDCALL;
2420 hr = IWineD3DPixelShader_GetFunction(shader->wineD3DPixelShader, pData, pSizeOfData);
2421 wined3d_mutex_unlock();
2426 static HRESULT WINAPI IDirect3DDevice8Impl_DrawRectPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
2427 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2429 TRACE("(%p) Relay\n", This);
2431 wined3d_mutex_lock();
2432 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
2433 wined3d_mutex_unlock();
2438 static HRESULT WINAPI IDirect3DDevice8Impl_DrawTriPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
2439 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2441 TRACE("(%p) Relay\n", This);
2443 wined3d_mutex_lock();
2444 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
2445 wined3d_mutex_unlock();
2450 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePatch(LPDIRECT3DDEVICE8 iface, UINT Handle) {
2451 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2453 TRACE("(%p) Relay\n", This);
2455 wined3d_mutex_lock();
2456 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
2457 wined3d_mutex_unlock();
2462 static HRESULT WINAPI IDirect3DDevice8Impl_SetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8* pStreamData,UINT Stride) {
2463 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2465 TRACE("(%p) Relay\n" , This);
2467 wined3d_mutex_lock();
2468 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
2469 NULL == pStreamData ? NULL : ((IDirect3DVertexBuffer8Impl *)pStreamData)->wineD3DVertexBuffer,
2470 0/* Offset in bytes */, Stride);
2471 wined3d_mutex_unlock();
2476 static HRESULT WINAPI IDirect3DDevice8Impl_GetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8** pStream,UINT* pStride) {
2477 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2478 IWineD3DBuffer *retStream = NULL;
2479 HRESULT rc = D3D_OK;
2481 TRACE("(%p) Relay\n" , This);
2483 if(pStream == NULL){
2484 return D3DERR_INVALIDCALL;
2487 wined3d_mutex_lock();
2488 rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, 0 /* Offset in bytes */, pStride);
2489 if (rc == D3D_OK && NULL != retStream) {
2490 IWineD3DBuffer_GetParent(retStream, (IUnknown **)pStream);
2491 IWineD3DBuffer_Release(retStream);
2494 FIXME("Call to GetStreamSource failed %p\n", pStride);
2498 wined3d_mutex_unlock();
2504 const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl =
2506 IDirect3DDevice8Impl_QueryInterface,
2507 IDirect3DDevice8Impl_AddRef,
2508 IDirect3DDevice8Impl_Release,
2509 IDirect3DDevice8Impl_TestCooperativeLevel,
2510 IDirect3DDevice8Impl_GetAvailableTextureMem,
2511 IDirect3DDevice8Impl_ResourceManagerDiscardBytes,
2512 IDirect3DDevice8Impl_GetDirect3D,
2513 IDirect3DDevice8Impl_GetDeviceCaps,
2514 IDirect3DDevice8Impl_GetDisplayMode,
2515 IDirect3DDevice8Impl_GetCreationParameters,
2516 IDirect3DDevice8Impl_SetCursorProperties,
2517 IDirect3DDevice8Impl_SetCursorPosition,
2518 IDirect3DDevice8Impl_ShowCursor,
2519 IDirect3DDevice8Impl_CreateAdditionalSwapChain,
2520 IDirect3DDevice8Impl_Reset,
2521 IDirect3DDevice8Impl_Present,
2522 IDirect3DDevice8Impl_GetBackBuffer,
2523 IDirect3DDevice8Impl_GetRasterStatus,
2524 IDirect3DDevice8Impl_SetGammaRamp,
2525 IDirect3DDevice8Impl_GetGammaRamp,
2526 IDirect3DDevice8Impl_CreateTexture,
2527 IDirect3DDevice8Impl_CreateVolumeTexture,
2528 IDirect3DDevice8Impl_CreateCubeTexture,
2529 IDirect3DDevice8Impl_CreateVertexBuffer,
2530 IDirect3DDevice8Impl_CreateIndexBuffer,
2531 IDirect3DDevice8Impl_CreateRenderTarget,
2532 IDirect3DDevice8Impl_CreateDepthStencilSurface,
2533 IDirect3DDevice8Impl_CreateImageSurface,
2534 IDirect3DDevice8Impl_CopyRects,
2535 IDirect3DDevice8Impl_UpdateTexture,
2536 IDirect3DDevice8Impl_GetFrontBuffer,
2537 IDirect3DDevice8Impl_SetRenderTarget,
2538 IDirect3DDevice8Impl_GetRenderTarget,
2539 IDirect3DDevice8Impl_GetDepthStencilSurface,
2540 IDirect3DDevice8Impl_BeginScene,
2541 IDirect3DDevice8Impl_EndScene,
2542 IDirect3DDevice8Impl_Clear,
2543 IDirect3DDevice8Impl_SetTransform,
2544 IDirect3DDevice8Impl_GetTransform,
2545 IDirect3DDevice8Impl_MultiplyTransform,
2546 IDirect3DDevice8Impl_SetViewport,
2547 IDirect3DDevice8Impl_GetViewport,
2548 IDirect3DDevice8Impl_SetMaterial,
2549 IDirect3DDevice8Impl_GetMaterial,
2550 IDirect3DDevice8Impl_SetLight,
2551 IDirect3DDevice8Impl_GetLight,
2552 IDirect3DDevice8Impl_LightEnable,
2553 IDirect3DDevice8Impl_GetLightEnable,
2554 IDirect3DDevice8Impl_SetClipPlane,
2555 IDirect3DDevice8Impl_GetClipPlane,
2556 IDirect3DDevice8Impl_SetRenderState,
2557 IDirect3DDevice8Impl_GetRenderState,
2558 IDirect3DDevice8Impl_BeginStateBlock,
2559 IDirect3DDevice8Impl_EndStateBlock,
2560 IDirect3DDevice8Impl_ApplyStateBlock,
2561 IDirect3DDevice8Impl_CaptureStateBlock,
2562 IDirect3DDevice8Impl_DeleteStateBlock,
2563 IDirect3DDevice8Impl_CreateStateBlock,
2564 IDirect3DDevice8Impl_SetClipStatus,
2565 IDirect3DDevice8Impl_GetClipStatus,
2566 IDirect3DDevice8Impl_GetTexture,
2567 IDirect3DDevice8Impl_SetTexture,
2568 IDirect3DDevice8Impl_GetTextureStageState,
2569 IDirect3DDevice8Impl_SetTextureStageState,
2570 IDirect3DDevice8Impl_ValidateDevice,
2571 IDirect3DDevice8Impl_GetInfo,
2572 IDirect3DDevice8Impl_SetPaletteEntries,
2573 IDirect3DDevice8Impl_GetPaletteEntries,
2574 IDirect3DDevice8Impl_SetCurrentTexturePalette,
2575 IDirect3DDevice8Impl_GetCurrentTexturePalette,
2576 IDirect3DDevice8Impl_DrawPrimitive,
2577 IDirect3DDevice8Impl_DrawIndexedPrimitive,
2578 IDirect3DDevice8Impl_DrawPrimitiveUP,
2579 IDirect3DDevice8Impl_DrawIndexedPrimitiveUP,
2580 IDirect3DDevice8Impl_ProcessVertices,
2581 IDirect3DDevice8Impl_CreateVertexShader,
2582 IDirect3DDevice8Impl_SetVertexShader,
2583 IDirect3DDevice8Impl_GetVertexShader,
2584 IDirect3DDevice8Impl_DeleteVertexShader,
2585 IDirect3DDevice8Impl_SetVertexShaderConstant,
2586 IDirect3DDevice8Impl_GetVertexShaderConstant,
2587 IDirect3DDevice8Impl_GetVertexShaderDeclaration,
2588 IDirect3DDevice8Impl_GetVertexShaderFunction,
2589 IDirect3DDevice8Impl_SetStreamSource,
2590 IDirect3DDevice8Impl_GetStreamSource,
2591 IDirect3DDevice8Impl_SetIndices,
2592 IDirect3DDevice8Impl_GetIndices,
2593 IDirect3DDevice8Impl_CreatePixelShader,
2594 IDirect3DDevice8Impl_SetPixelShader,
2595 IDirect3DDevice8Impl_GetPixelShader,
2596 IDirect3DDevice8Impl_DeletePixelShader,
2597 IDirect3DDevice8Impl_SetPixelShaderConstant,
2598 IDirect3DDevice8Impl_GetPixelShaderConstant,
2599 IDirect3DDevice8Impl_GetPixelShaderFunction,
2600 IDirect3DDevice8Impl_DrawRectPatch,
2601 IDirect3DDevice8Impl_DrawTriPatch,
2602 IDirect3DDevice8Impl_DeletePatch
2605 /* IWineD3DDeviceParent IUnknown methods */
2607 static inline struct IDirect3DDevice8Impl *device_from_device_parent(IWineD3DDeviceParent *iface)
2609 return (struct IDirect3DDevice8Impl *)((char*)iface
2610 - FIELD_OFFSET(struct IDirect3DDevice8Impl, device_parent_vtbl));
2613 static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface, REFIID riid, void **object)
2615 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2616 return IDirect3DDevice8Impl_QueryInterface((IDirect3DDevice8 *)This, riid, object);
2619 static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
2621 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2622 return IDirect3DDevice8Impl_AddRef((IDirect3DDevice8 *)This);
2625 static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
2627 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2628 return IDirect3DDevice8Impl_Release((IDirect3DDevice8 *)This);
2631 /* IWineD3DDeviceParent methods */
2633 static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
2635 TRACE("iface %p, device %p\n", iface, device);
2638 static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
2639 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, DWORD usage,
2640 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface)
2642 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2643 IDirect3DSurface8Impl *d3d_surface;
2644 BOOL lockable = TRUE;
2647 TRACE("iface %p, superior %p, width %u, height %u, format %#x, usage %#x,\n"
2648 "\tpool %#x, level %u, face %u, surface %p\n",
2649 iface, superior, width, height, format, usage, pool, level, face, surface);
2652 if (pool == WINED3DPOOL_DEFAULT && !(usage & WINED3DUSAGE_DYNAMIC)) lockable = FALSE;
2654 hr = IDirect3DDevice8Impl_CreateSurface((IDirect3DDevice8 *)This, width, height,
2655 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
2656 (IDirect3DSurface8 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
2659 ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
2663 *surface = d3d_surface->wineD3DSurface;
2664 IWineD3DSurface_AddRef(*surface);
2666 d3d_surface->container = superior;
2667 IUnknown_Release(d3d_surface->parentDevice);
2668 d3d_surface->parentDevice = NULL;
2670 IDirect3DSurface8_Release((IDirect3DSurface8 *)d3d_surface);
2671 d3d_surface->forwardReference = superior;
2676 static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
2677 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2678 DWORD multisample_quality, BOOL lockable, IWineD3DSurface **surface)
2680 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2681 IDirect3DSurface8Impl *d3d_surface;
2684 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2685 "\tmultisample_quality %u, lockable %u, surface %p\n",
2686 iface, superior, width, height, format, multisample_type, multisample_quality, lockable, surface);
2688 hr = IDirect3DDevice8_CreateRenderTarget((IDirect3DDevice8 *)This, width, height,
2689 d3dformat_from_wined3dformat(format), multisample_type, lockable, (IDirect3DSurface8 **)&d3d_surface);
2692 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
2696 *surface = d3d_surface->wineD3DSurface;
2697 IWineD3DSurface_AddRef(*surface);
2699 d3d_surface->container = (IUnknown *)This;
2700 /* Implicit surfaces are created with an refcount of 0 */
2701 IUnknown_Release((IUnknown *)d3d_surface);
2706 static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
2707 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2708 DWORD multisample_quality, BOOL discard, IWineD3DSurface **surface)
2710 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2711 IDirect3DSurface8Impl *d3d_surface;
2714 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2715 "\tmultisample_quality %u, discard %u, surface %p\n",
2716 iface, superior, width, height, format, multisample_type, multisample_quality, discard, surface);
2718 hr = IDirect3DDevice8_CreateDepthStencilSurface((IDirect3DDevice8 *)This, width, height,
2719 d3dformat_from_wined3dformat(format), multisample_type, (IDirect3DSurface8 **)&d3d_surface);
2722 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
2726 *surface = d3d_surface->wineD3DSurface;
2727 IWineD3DSurface_AddRef(*surface);
2729 d3d_surface->container = (IUnknown *)This;
2730 /* Implicit surfaces are created with an refcount of 0 */
2731 IUnknown_Release((IUnknown *)d3d_surface);
2736 static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
2737 IUnknown *superior, UINT width, UINT height, UINT depth, WINED3DFORMAT format,
2738 WINED3DPOOL pool, DWORD usage, IWineD3DVolume **volume)
2740 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2741 IDirect3DVolume8Impl *object;
2744 TRACE("iface %p, superior %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
2745 iface, superior, width, height, depth, format, pool, usage, volume);
2747 /* Allocate the storage for the device */
2748 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2751 FIXME("Allocation of memory failed\n");
2753 return D3DERR_OUTOFVIDEOMEMORY;
2756 object->lpVtbl = &Direct3DVolume8_Vtbl;
2758 hr = IWineD3DDevice_CreateVolume(This->WineD3DDevice, width, height, depth, usage,
2759 format, pool, &object->wineD3DVolume, (IUnknown *)object);
2762 ERR("(%p) CreateVolume failed, returning %#x\n", iface, hr);
2763 HeapFree(GetProcessHeap(), 0, object);
2768 *volume = object->wineD3DVolume;
2769 object->container = superior;
2770 object->forwardReference = superior;
2772 TRACE("(%p) Created volume %p\n", iface, *volume);
2777 static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
2778 WINED3DPRESENT_PARAMETERS *present_parameters, IWineD3DSwapChain **swapchain)
2780 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2781 IDirect3DSwapChain8Impl *d3d_swapchain;
2782 D3DPRESENT_PARAMETERS local_parameters;
2785 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
2787 /* Copy the presentation parameters */
2788 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
2789 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
2790 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
2791 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
2792 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
2793 local_parameters.SwapEffect = present_parameters->SwapEffect;
2794 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
2795 local_parameters.Windowed = present_parameters->Windowed;
2796 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
2797 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
2798 local_parameters.Flags = present_parameters->Flags;
2799 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
2800 local_parameters.FullScreen_PresentationInterval = present_parameters->PresentationInterval;
2802 hr = IDirect3DDevice8_CreateAdditionalSwapChain((IDirect3DDevice8 *)This,
2803 &local_parameters, (IDirect3DSwapChain8 **)&d3d_swapchain);
2806 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
2811 *swapchain = d3d_swapchain->wineD3DSwapChain;
2812 IUnknown_Release(d3d_swapchain->parentDevice);
2813 d3d_swapchain->parentDevice = NULL;
2815 /* Copy back the presentation parameters */
2816 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
2817 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
2818 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
2819 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
2820 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
2821 present_parameters->SwapEffect = local_parameters.SwapEffect;
2822 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
2823 present_parameters->Windowed = local_parameters.Windowed;
2824 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
2825 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
2826 present_parameters->Flags = local_parameters.Flags;
2827 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
2828 present_parameters->PresentationInterval = local_parameters.FullScreen_PresentationInterval;
2833 const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl =
2835 /* IUnknown methods */
2836 device_parent_QueryInterface,
2837 device_parent_AddRef,
2838 device_parent_Release,
2839 /* IWineD3DDeviceParent methods */
2840 device_parent_WineD3DDeviceCreated,
2841 device_parent_CreateSurface,
2842 device_parent_CreateRenderTarget,
2843 device_parent_CreateDepthStencilSurface,
2844 device_parent_CreateVolume,
2845 device_parent_CreateSwapChain,