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_A2W10V10U10: return D3DFMT_A2W10V10U10;
73 case WINED3DFMT_D16_LOCKABLE: return D3DFMT_D16_LOCKABLE;
74 case WINED3DFMT_D32: return D3DFMT_D32;
75 case WINED3DFMT_D15S1: return D3DFMT_D15S1;
76 case WINED3DFMT_D24S8: return D3DFMT_D24S8;
77 case WINED3DFMT_D24X8: return D3DFMT_D24X8;
78 case WINED3DFMT_D24X4S4: return D3DFMT_D24X4S4;
79 case WINED3DFMT_D16_UNORM: return D3DFMT_D16;
80 case WINED3DFMT_VERTEXDATA: return D3DFMT_VERTEXDATA;
81 case WINED3DFMT_R16_UINT: return D3DFMT_INDEX16;
82 case WINED3DFMT_R32_UINT: return D3DFMT_INDEX32;
84 FIXME("Unhandled WINED3DFORMAT %#x\n", format);
85 return D3DFMT_UNKNOWN;
89 WINED3DFORMAT wined3dformat_from_d3dformat(D3DFORMAT format)
91 BYTE *c = (BYTE *)&format;
93 /* Don't translate FOURCC formats */
94 if (isprint(c[0]) && isprint(c[1]) && isprint(c[2]) && isprint(c[3])) return format;
98 case D3DFMT_UNKNOWN: return WINED3DFMT_UNKNOWN;
99 case D3DFMT_R8G8B8: return WINED3DFMT_R8G8B8;
100 case D3DFMT_A8R8G8B8: return WINED3DFMT_A8R8G8B8;
101 case D3DFMT_X8R8G8B8: return WINED3DFMT_X8R8G8B8;
102 case D3DFMT_R5G6B5: return WINED3DFMT_R5G6B5;
103 case D3DFMT_X1R5G5B5: return WINED3DFMT_X1R5G5B5;
104 case D3DFMT_A1R5G5B5: return WINED3DFMT_A1R5G5B5;
105 case D3DFMT_A4R4G4B4: return WINED3DFMT_A4R4G4B4;
106 case D3DFMT_R3G3B2: return WINED3DFMT_R3G3B2;
107 case D3DFMT_A8: return WINED3DFMT_A8_UNORM;
108 case D3DFMT_A8R3G3B2: return WINED3DFMT_A8R3G3B2;
109 case D3DFMT_X4R4G4B4: return WINED3DFMT_X4R4G4B4;
110 case D3DFMT_A2B10G10R10: return WINED3DFMT_R10G10B10A2_UNORM;
111 case D3DFMT_G16R16: return WINED3DFMT_R16G16_UNORM;
112 case D3DFMT_A8P8: return WINED3DFMT_A8P8;
113 case D3DFMT_P8: return WINED3DFMT_P8;
114 case D3DFMT_L8: return WINED3DFMT_L8;
115 case D3DFMT_A8L8: return WINED3DFMT_A8L8;
116 case D3DFMT_A4L4: return WINED3DFMT_A4L4;
117 case D3DFMT_V8U8: return WINED3DFMT_R8G8_SNORM;
118 case D3DFMT_L6V5U5: return WINED3DFMT_L6V5U5;
119 case D3DFMT_X8L8V8U8: return WINED3DFMT_X8L8V8U8;
120 case D3DFMT_Q8W8V8U8: return WINED3DFMT_R8G8B8A8_SNORM;
121 case D3DFMT_V16U16: return WINED3DFMT_R16G16_SNORM;
122 case D3DFMT_A2W10V10U10: return WINED3DFMT_A2W10V10U10;
123 case D3DFMT_D16_LOCKABLE: return WINED3DFMT_D16_LOCKABLE;
124 case D3DFMT_D32: return WINED3DFMT_D32;
125 case D3DFMT_D15S1: return WINED3DFMT_D15S1;
126 case D3DFMT_D24S8: return WINED3DFMT_D24S8;
127 case D3DFMT_D24X8: return WINED3DFMT_D24X8;
128 case D3DFMT_D24X4S4: return WINED3DFMT_D24X4S4;
129 case D3DFMT_D16: return WINED3DFMT_D16_UNORM;
130 case D3DFMT_VERTEXDATA: return WINED3DFMT_VERTEXDATA;
131 case D3DFMT_INDEX16: return WINED3DFMT_R16_UINT;
132 case D3DFMT_INDEX32: return WINED3DFMT_R32_UINT;
134 FIXME("Unhandled D3DFORMAT %#x\n", format);
135 return WINED3DFMT_UNKNOWN;
139 static UINT vertex_count_from_primitive_count(D3DPRIMITIVETYPE primitive_type, UINT primitive_count)
141 switch(primitive_type)
143 case D3DPT_POINTLIST:
144 return primitive_count;
147 return primitive_count * 2;
149 case D3DPT_LINESTRIP:
150 return primitive_count + 1;
152 case D3DPT_TRIANGLELIST:
153 return primitive_count * 3;
155 case D3DPT_TRIANGLESTRIP:
156 case D3DPT_TRIANGLEFAN:
157 return primitive_count + 2;
160 FIXME("Unhandled primitive type %#x\n", primitive_type);
165 /* Handle table functions */
166 static DWORD d3d8_allocate_handle(struct d3d8_handle_table *t, void *object)
170 /* Use a free handle */
171 void **entry = t->free_entries;
172 t->free_entries = *entry;
174 return entry - t->entries;
177 if (!(t->entry_count < t->table_size))
180 UINT new_size = t->table_size + (t->table_size >> 1);
181 void **new_entries = HeapReAlloc(GetProcessHeap(), 0, t->entries, new_size * sizeof(void *));
182 if (!new_entries) return D3D8_INVALID_HANDLE;
183 t->entries = new_entries;
184 t->table_size = new_size;
187 t->entries[t->entry_count] = object;
188 return t->entry_count++;
191 static void *d3d8_free_handle(struct d3d8_handle_table *t, DWORD handle)
193 void **entry, *object;
195 if (handle >= t->entry_count) return NULL;
197 entry = &t->entries[handle];
199 *entry = t->free_entries;
200 t->free_entries = entry;
205 static void *d3d8_get_object(struct d3d8_handle_table *t, DWORD handle)
207 if (handle >= t->entry_count) return NULL;
208 return t->entries[handle];
211 /* IDirect3D IUnknown parts follow: */
212 static HRESULT WINAPI IDirect3DDevice8Impl_QueryInterface(LPDIRECT3DDEVICE8 iface,REFIID riid,LPVOID *ppobj)
214 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
216 if (IsEqualGUID(riid, &IID_IUnknown)
217 || IsEqualGUID(riid, &IID_IDirect3DDevice8)) {
218 IUnknown_AddRef(iface);
223 if (IsEqualGUID(riid, &IID_IWineD3DDeviceParent))
225 IUnknown_AddRef((IUnknown *)&This->device_parent_vtbl);
226 *ppobj = &This->device_parent_vtbl;
230 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
232 return E_NOINTERFACE;
235 static ULONG WINAPI IDirect3DDevice8Impl_AddRef(LPDIRECT3DDEVICE8 iface) {
236 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
237 ULONG ref = InterlockedIncrement(&This->ref);
239 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
244 static ULONG WINAPI IDirect3DDevice8Impl_Release(LPDIRECT3DDEVICE8 iface) {
245 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
248 if (This->inDestruction) return 0;
249 ref = InterlockedDecrement(&This->ref);
251 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
256 TRACE("Releasing wined3d device %p\n", This->WineD3DDevice);
257 EnterCriticalSection(&d3d8_cs);
258 This->inDestruction = TRUE;
260 for(i = 0; i < This->numConvertedDecls; i++) {
261 IDirect3DVertexDeclaration8_Release(This->decls[i].decl);
263 HeapFree(GetProcessHeap(), 0, This->decls);
265 IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D8CB_DestroyDepthStencilSurface, D3D8CB_DestroySwapChain);
266 IWineD3DDevice_Release(This->WineD3DDevice);
267 HeapFree(GetProcessHeap(), 0, This->handle_table.entries);
268 HeapFree(GetProcessHeap(), 0, This);
269 LeaveCriticalSection(&d3d8_cs);
274 /* IDirect3DDevice Interface follow: */
275 static HRESULT WINAPI IDirect3DDevice8Impl_TestCooperativeLevel(LPDIRECT3DDEVICE8 iface) {
276 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
279 TRACE("(%p) : Relay\n", This);
280 EnterCriticalSection(&d3d8_cs);
281 hr = IWineD3DDevice_TestCooperativeLevel(This->WineD3DDevice);
282 LeaveCriticalSection(&d3d8_cs);
286 static UINT WINAPI IDirect3DDevice8Impl_GetAvailableTextureMem(LPDIRECT3DDEVICE8 iface) {
287 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
290 TRACE("(%p) Relay\n", This);
291 EnterCriticalSection(&d3d8_cs);
292 hr = IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
293 LeaveCriticalSection(&d3d8_cs);
297 static HRESULT WINAPI IDirect3DDevice8Impl_ResourceManagerDiscardBytes(LPDIRECT3DDEVICE8 iface, DWORD Bytes) {
298 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
301 TRACE("(%p) : Relay bytes(%d)\n", This, Bytes);
302 EnterCriticalSection(&d3d8_cs);
303 hr = IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
304 LeaveCriticalSection(&d3d8_cs);
308 static HRESULT WINAPI IDirect3DDevice8Impl_GetDirect3D(LPDIRECT3DDEVICE8 iface, IDirect3D8** ppD3D8) {
309 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
313 TRACE("(%p) Relay\n", This);
315 if (NULL == ppD3D8) {
316 return D3DERR_INVALIDCALL;
319 EnterCriticalSection(&d3d8_cs);
320 hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &pWineD3D);
321 if (hr == D3D_OK && pWineD3D != NULL)
323 IWineD3D_GetParent(pWineD3D,(IUnknown **)ppD3D8);
324 IWineD3D_Release(pWineD3D);
326 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
329 TRACE("(%p) returning %p\n",This , *ppD3D8);
330 LeaveCriticalSection(&d3d8_cs);
335 static HRESULT WINAPI IDirect3DDevice8Impl_GetDeviceCaps(LPDIRECT3DDEVICE8 iface, D3DCAPS8* pCaps) {
336 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
337 HRESULT hrc = D3D_OK;
338 WINED3DCAPS *pWineCaps;
340 TRACE("(%p) : Relay pCaps %p\n", This, pCaps);
342 return D3DERR_INVALIDCALL;
344 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
345 if(pWineCaps == NULL){
346 return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
349 EnterCriticalSection(&d3d8_cs);
350 hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
351 LeaveCriticalSection(&d3d8_cs);
352 WINECAPSTOD3D8CAPS(pCaps, pWineCaps)
353 HeapFree(GetProcessHeap(), 0, pWineCaps);
355 /* D3D8 doesn't support SM 2.0 or higher, so clamp to 1.x */
356 if(pCaps->PixelShaderVersion > D3DPS_VERSION(1,4)){
357 pCaps->PixelShaderVersion = D3DPS_VERSION(1,4);
359 if(pCaps->VertexShaderVersion > D3DVS_VERSION(1,1)){
360 pCaps->VertexShaderVersion = D3DVS_VERSION(1,1);
362 pCaps->MaxVertexShaderConst = min(D3D8_MAX_VERTEX_SHADER_CONSTANTF, pCaps->MaxVertexShaderConst);
364 TRACE("Returning %p %p\n", This, pCaps);
368 static HRESULT WINAPI IDirect3DDevice8Impl_GetDisplayMode(LPDIRECT3DDEVICE8 iface, D3DDISPLAYMODE* pMode) {
369 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
371 TRACE("(%p) Relay\n", This);
373 EnterCriticalSection(&d3d8_cs);
374 hr = IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, 0, (WINED3DDISPLAYMODE *) pMode);
375 LeaveCriticalSection(&d3d8_cs);
377 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
382 static HRESULT WINAPI IDirect3DDevice8Impl_GetCreationParameters(LPDIRECT3DDEVICE8 iface, D3DDEVICE_CREATION_PARAMETERS *pParameters) {
383 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
385 TRACE("(%p) Relay\n", This);
387 EnterCriticalSection(&d3d8_cs);
388 hr = IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
389 LeaveCriticalSection(&d3d8_cs);
393 static HRESULT WINAPI IDirect3DDevice8Impl_SetCursorProperties(LPDIRECT3DDEVICE8 iface, UINT XHotSpot, UINT YHotSpot, IDirect3DSurface8* pCursorBitmap) {
394 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
395 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl*)pCursorBitmap;
397 TRACE("(%p) Relay\n", This);
399 WARN("No cursor bitmap, returning WINED3DERR_INVALIDCALL\n");
400 return WINED3DERR_INVALIDCALL;
403 EnterCriticalSection(&d3d8_cs);
404 hr = IWineD3DDevice_SetCursorProperties(This->WineD3DDevice,XHotSpot,YHotSpot,pSurface->wineD3DSurface);
405 LeaveCriticalSection(&d3d8_cs);
409 static void WINAPI IDirect3DDevice8Impl_SetCursorPosition(LPDIRECT3DDEVICE8 iface, UINT XScreenSpace, UINT YScreenSpace, DWORD Flags) {
410 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
411 TRACE("(%p) Relay\n", This);
413 EnterCriticalSection(&d3d8_cs);
414 IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
415 LeaveCriticalSection(&d3d8_cs);
418 static BOOL WINAPI IDirect3DDevice8Impl_ShowCursor(LPDIRECT3DDEVICE8 iface, BOOL bShow) {
419 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
421 TRACE("(%p) Relay\n", This);
423 EnterCriticalSection(&d3d8_cs);
424 ret = IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
425 LeaveCriticalSection(&d3d8_cs);
429 static HRESULT WINAPI IDirect3DDevice8Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain8** pSwapChain) {
430 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
431 IDirect3DSwapChain8Impl* object;
432 HRESULT hrc = D3D_OK;
433 WINED3DPRESENT_PARAMETERS localParameters;
435 TRACE("(%p) Relay\n", This);
437 /* Fix the back buffer count */
438 if(pPresentationParameters->BackBufferCount == 0) {
439 pPresentationParameters->BackBufferCount = 1;
442 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
443 if (NULL == object) {
444 FIXME("Allocation of memory failed\n");
446 return D3DERR_OUTOFVIDEOMEMORY;
449 object->lpVtbl = &Direct3DSwapChain8_Vtbl;
451 /* Allocate an associated WineD3DDevice object */
452 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
453 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
454 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
455 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
456 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
457 localParameters.MultiSampleQuality = 0; /* d3d9 only */
458 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
459 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
460 localParameters.Windowed = pPresentationParameters->Windowed;
461 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
462 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
463 localParameters.Flags = pPresentationParameters->Flags;
464 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
465 localParameters.PresentationInterval = pPresentationParameters->FullScreen_PresentationInterval;
466 localParameters.AutoRestoreDisplayMode = TRUE;
468 EnterCriticalSection(&d3d8_cs);
469 hrc = IWineD3DDevice_CreateSwapChain(This->WineD3DDevice, &localParameters,
470 &object->wineD3DSwapChain, (IUnknown *)object, SURFACE_OPENGL);
471 LeaveCriticalSection(&d3d8_cs);
473 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
474 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
475 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
476 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
477 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
478 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
479 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
480 pPresentationParameters->Windowed = localParameters.Windowed;
481 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
482 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
483 pPresentationParameters->Flags = localParameters.Flags;
484 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
485 pPresentationParameters->FullScreen_PresentationInterval = localParameters.PresentationInterval;
488 FIXME("(%p) call to IWineD3DDevice_CreateSwapChain failed\n", This);
489 HeapFree(GetProcessHeap(), 0 , object);
492 IUnknown_AddRef(iface);
493 object->parentDevice = iface;
494 *pSwapChain = (IDirect3DSwapChain8 *)object;
496 TRACE("(%p) returning %p\n", This, *pSwapChain);
500 static HRESULT WINAPI IDirect3DDevice8Impl_Reset(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
501 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
502 WINED3DPRESENT_PARAMETERS localParameters;
505 TRACE("(%p) Relay pPresentationParameters(%p)\n", This, pPresentationParameters);
507 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
508 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
509 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
510 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
511 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
512 localParameters.MultiSampleQuality = 0; /* d3d9 only */
513 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
514 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
515 localParameters.Windowed = pPresentationParameters->Windowed;
516 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
517 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
518 localParameters.Flags = pPresentationParameters->Flags;
519 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
520 localParameters.PresentationInterval = pPresentationParameters->FullScreen_PresentationInterval;
521 localParameters.AutoRestoreDisplayMode = TRUE;
523 EnterCriticalSection(&d3d8_cs);
524 hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
525 LeaveCriticalSection(&d3d8_cs);
527 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
528 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
529 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
530 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
531 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
532 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
533 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
534 pPresentationParameters->Windowed = localParameters.Windowed;
535 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
536 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
537 pPresentationParameters->Flags = localParameters.Flags;
538 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
539 pPresentationParameters->FullScreen_PresentationInterval = localParameters.PresentationInterval;
544 static HRESULT WINAPI IDirect3DDevice8Impl_Present(LPDIRECT3DDEVICE8 iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion) {
545 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
547 TRACE("(%p) Relay\n", This);
549 EnterCriticalSection(&d3d8_cs);
550 hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
551 LeaveCriticalSection(&d3d8_cs);
555 static HRESULT WINAPI IDirect3DDevice8Impl_GetBackBuffer(LPDIRECT3DDEVICE8 iface, UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8** ppBackBuffer) {
556 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
557 IWineD3DSurface *retSurface = NULL;
560 TRACE("(%p) Relay\n", This);
562 EnterCriticalSection(&d3d8_cs);
563 rc = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, 0, BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &retSurface);
564 if (rc == D3D_OK && NULL != retSurface && NULL != ppBackBuffer) {
565 IWineD3DSurface_GetParent(retSurface, (IUnknown **)ppBackBuffer);
566 IWineD3DSurface_Release(retSurface);
568 LeaveCriticalSection(&d3d8_cs);
572 static HRESULT WINAPI IDirect3DDevice8Impl_GetRasterStatus(LPDIRECT3DDEVICE8 iface, D3DRASTER_STATUS* pRasterStatus) {
573 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
575 TRACE("(%p) Relay\n", This);
577 EnterCriticalSection(&d3d8_cs);
578 hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, 0, (WINED3DRASTER_STATUS *) pRasterStatus);
579 LeaveCriticalSection(&d3d8_cs);
583 static void WINAPI IDirect3DDevice8Impl_SetGammaRamp(LPDIRECT3DDEVICE8 iface, DWORD Flags, CONST D3DGAMMARAMP* pRamp) {
584 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
585 TRACE("(%p) Relay\n", This);
587 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
588 EnterCriticalSection(&d3d8_cs);
589 IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, 0, Flags, (CONST WINED3DGAMMARAMP *) pRamp);
590 LeaveCriticalSection(&d3d8_cs);
593 static void WINAPI IDirect3DDevice8Impl_GetGammaRamp(LPDIRECT3DDEVICE8 iface, D3DGAMMARAMP* pRamp) {
594 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
595 TRACE("(%p) Relay\n", This);
597 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
598 EnterCriticalSection(&d3d8_cs);
599 IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, 0, (WINED3DGAMMARAMP *) pRamp);
600 LeaveCriticalSection(&d3d8_cs);
603 static HRESULT WINAPI IDirect3DDevice8Impl_CreateTexture(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, UINT Levels, DWORD Usage,
604 D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture8 **ppTexture) {
605 IDirect3DTexture8Impl *object;
606 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
607 HRESULT hrc = D3D_OK;
609 TRACE("(%p) : W(%d) H(%d), Lvl(%d) d(%d), Fmt(%u), Pool(%d)\n", This, Width, Height, Levels, Usage, Format, Pool);
611 /* Allocate the storage for the device */
612 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DTexture8Impl));
614 if (NULL == object) {
615 FIXME("Allocation of memory failed\n");
616 /* *ppTexture = NULL; */
617 return D3DERR_OUTOFVIDEOMEMORY;
620 object->lpVtbl = &Direct3DTexture8_Vtbl;
622 EnterCriticalSection(&d3d8_cs);
623 hrc = IWineD3DDevice_CreateTexture(This->WineD3DDevice, Width, Height, Levels, Usage & WINED3DUSAGE_MASK,
624 wined3dformat_from_d3dformat(Format), Pool, &object->wineD3DTexture, (IUnknown *)object);
625 LeaveCriticalSection(&d3d8_cs);
629 FIXME("(%p) call to IWineD3DDevice_CreateTexture failed\n", This);
630 HeapFree(GetProcessHeap(), 0, object);
631 /* *ppTexture = NULL; */
633 IUnknown_AddRef(iface);
634 object->parentDevice = iface;
635 *ppTexture = (LPDIRECT3DTEXTURE8) object;
636 TRACE("(%p) Created Texture %p, %p\n",This,object,object->wineD3DTexture);
642 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVolumeTexture(LPDIRECT3DDEVICE8 iface,
643 UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage,
644 D3DFORMAT Format, D3DPOOL Pool, IDirect3DVolumeTexture8** ppVolumeTexture) {
646 IDirect3DVolumeTexture8Impl *object;
647 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
648 HRESULT hrc = D3D_OK;
650 TRACE("(%p) Relay\n", This);
652 /* Allocate the storage for the device */
653 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVolumeTexture8Impl));
654 if (NULL == object) {
655 FIXME("(%p) allocation of memory failed\n", This);
656 *ppVolumeTexture = NULL;
657 return D3DERR_OUTOFVIDEOMEMORY;
660 object->lpVtbl = &Direct3DVolumeTexture8_Vtbl;
662 EnterCriticalSection(&d3d8_cs);
663 hrc = IWineD3DDevice_CreateVolumeTexture(This->WineD3DDevice, Width, Height, Depth, Levels,
664 Usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(Format),
665 Pool, &object->wineD3DVolumeTexture, (IUnknown *)object);
666 LeaveCriticalSection(&d3d8_cs);
671 FIXME("(%p) call to IWineD3DDevice_CreateVolumeTexture failed\n", This);
672 HeapFree(GetProcessHeap(), 0, object);
673 *ppVolumeTexture = NULL;
675 IUnknown_AddRef(iface);
676 object->parentDevice = iface;
677 *ppVolumeTexture = (LPDIRECT3DVOLUMETEXTURE8) object;
679 TRACE("(%p) returning %p\n", This , *ppVolumeTexture);
683 static HRESULT WINAPI IDirect3DDevice8Impl_CreateCubeTexture(LPDIRECT3DDEVICE8 iface, UINT EdgeLength, UINT Levels, DWORD Usage,
684 D3DFORMAT Format, D3DPOOL Pool, IDirect3DCubeTexture8** ppCubeTexture) {
686 IDirect3DCubeTexture8Impl *object;
687 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
690 TRACE("(%p) : ELen(%d) Lvl(%d) Usage(%d) fmt(%u), Pool(%d)\n" , This, EdgeLength, Levels, Usage, Format, Pool);
692 /* Allocate the storage for the device */
693 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
695 if (NULL == object) {
696 FIXME("(%p) allocation of CubeTexture failed\n", This);
697 *ppCubeTexture = NULL;
698 return D3DERR_OUTOFVIDEOMEMORY;
701 object->lpVtbl = &Direct3DCubeTexture8_Vtbl;
703 EnterCriticalSection(&d3d8_cs);
704 hr = IWineD3DDevice_CreateCubeTexture(This->WineD3DDevice, EdgeLength, Levels, Usage & WINED3DUSAGE_MASK,
705 wined3dformat_from_d3dformat(Format), Pool, &object->wineD3DCubeTexture, (IUnknown *)object);
706 LeaveCriticalSection(&d3d8_cs);
711 FIXME("(%p) call to IWineD3DDevice_CreateCubeTexture failed\n", This);
712 HeapFree(GetProcessHeap(), 0, object);
713 *ppCubeTexture = NULL;
715 IUnknown_AddRef(iface);
716 object->parentDevice = iface;
717 *ppCubeTexture = (LPDIRECT3DCUBETEXTURE8) object;
720 TRACE("(%p) returning %p\n",This, *ppCubeTexture);
724 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexBuffer(LPDIRECT3DDEVICE8 iface, UINT Size, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer8** ppVertexBuffer) {
725 IDirect3DVertexBuffer8Impl *object;
726 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
727 HRESULT hrc = D3D_OK;
729 TRACE("(%p) Relay\n", This);
730 /* Allocate the storage for the device */
731 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexBuffer8Impl));
732 if (NULL == object) {
733 FIXME("Allocation of memory failed\n");
734 *ppVertexBuffer = NULL;
735 return D3DERR_OUTOFVIDEOMEMORY;
738 object->lpVtbl = &Direct3DVertexBuffer8_Vtbl;
740 EnterCriticalSection(&d3d8_cs);
741 hrc = IWineD3DDevice_CreateVertexBuffer(This->WineD3DDevice, Size, Usage & WINED3DUSAGE_MASK,
742 0 /* fvf for ddraw only */, (WINED3DPOOL)Pool, &object->wineD3DVertexBuffer, (IUnknown *)object);
743 LeaveCriticalSection(&d3d8_cs);
749 FIXME("(%p) call to IWineD3DDevice_CreateVertexBuffer failed\n", This);
750 HeapFree(GetProcessHeap(), 0, object);
751 *ppVertexBuffer = NULL;
753 IUnknown_AddRef(iface);
754 object->parentDevice = iface;
755 *ppVertexBuffer = (LPDIRECT3DVERTEXBUFFER8) object;
760 static HRESULT WINAPI IDirect3DDevice8Impl_CreateIndexBuffer(LPDIRECT3DDEVICE8 iface, UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DIndexBuffer8** ppIndexBuffer) {
761 IDirect3DIndexBuffer8Impl *object;
762 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
763 HRESULT hrc = D3D_OK;
765 TRACE("(%p) Relay\n", This);
766 /* Allocate the storage for the device */
767 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
768 if (NULL == object) {
769 FIXME("Allocation of memory failed\n");
770 *ppIndexBuffer = NULL;
771 return D3DERR_OUTOFVIDEOMEMORY;
774 object->lpVtbl = &Direct3DIndexBuffer8_Vtbl;
776 object->format = wined3dformat_from_d3dformat(Format);
777 TRACE("Calling wined3d create index buffer\n");
778 EnterCriticalSection(&d3d8_cs);
779 hrc = IWineD3DDevice_CreateIndexBuffer(This->WineD3DDevice, Length, Usage & WINED3DUSAGE_MASK,
780 (WINED3DPOOL)Pool, &object->wineD3DIndexBuffer, (IUnknown *)object);
781 LeaveCriticalSection(&d3d8_cs);
786 FIXME("(%p) call to IWineD3DDevice_CreateIndexBuffer failed\n", This);
787 HeapFree(GetProcessHeap(), 0, object);
788 *ppIndexBuffer = NULL;
790 IUnknown_AddRef(iface);
791 object->parentDevice = iface;
792 *ppIndexBuffer = (LPDIRECT3DINDEXBUFFER8)object;
797 static HRESULT IDirect3DDevice8Impl_CreateSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height,
798 D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IDirect3DSurface8 **ppSurface,
799 UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality)
802 IDirect3DSurface8Impl *object;
803 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
804 TRACE("(%p) Relay\n", This);
806 if(MultisampleQuality > 0){
807 FIXME("MultisampleQuality set to %d, substituting 0\n" , MultisampleQuality);
810 [in] Quality level. The valid range is between zero and one less than the level returned by pQualityLevels used by IDirect3D8::CheckDeviceMultiSampleType. Passing a larger value returns the error D3DERR_INVALIDCALL. The MultisampleQuality values of paired render targets, depth stencil surfaces, and the MultiSample type must all match.
812 MultisampleQuality=0;
814 /*FIXME: Check MAX bounds of MultisampleQuality*/
816 /* Allocate the storage for the device */
817 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface8Impl));
818 if (NULL == object) {
819 FIXME("Allocation of memory failed\n");
821 return D3DERR_OUTOFVIDEOMEMORY;
824 object->lpVtbl = &Direct3DSurface8_Vtbl;
827 TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
829 EnterCriticalSection(&d3d8_cs);
830 hrc = IWineD3DDevice_CreateSurface(This->WineD3DDevice, Width, Height, wined3dformat_from_d3dformat(Format),
831 Lockable, Discard, Level, &object->wineD3DSurface, Usage & WINED3DUSAGE_MASK, (WINED3DPOOL)Pool,
832 MultiSample, MultisampleQuality, SURFACE_OPENGL, (IUnknown *)object);
833 LeaveCriticalSection(&d3d8_cs);
834 if (hrc != D3D_OK || NULL == object->wineD3DSurface) {
836 FIXME("(%p) call to IWineD3DDevice_CreateSurface failed\n", This);
837 HeapFree(GetProcessHeap(), 0, object);
840 IUnknown_AddRef(iface);
841 object->parentDevice = iface;
842 *ppSurface = (LPDIRECT3DSURFACE8) object;
847 static HRESULT WINAPI IDirect3DDevice8Impl_CreateRenderTarget(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, BOOL Lockable, IDirect3DSurface8** ppSurface) {
851 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, Lockable, FALSE /* Discard */,
852 0 /* Level */, ppSurface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, MultiSample, 0);
857 static HRESULT WINAPI IDirect3DDevice8Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, IDirect3DSurface8** ppSurface) {
861 /* TODO: Verify that Discard is false */
862 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE,
863 0 /* Level */, ppSurface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, MultiSample, 0);
868 /* IDirect3DDevice8Impl::CreateImageSurface returns surface with pool type SYSTEMMEM */
869 static HRESULT WINAPI IDirect3DDevice8Impl_CreateImageSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, IDirect3DSurface8** ppSurface) {
873 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE /* Discard */,
874 0 /* Level */, ppSurface, 0 /* Usage (undefined/none) */, D3DPOOL_SYSTEMMEM, D3DMULTISAMPLE_NONE,
875 0 /* MultisampleQuality */);
880 static HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8 *pSourceSurface, CONST RECT *pSourceRects, UINT cRects, IDirect3DSurface8 *pDestinationSurface, CONST POINT *pDestPoints) {
881 IDirect3DSurface8Impl *Source = (IDirect3DSurface8Impl *) pSourceSurface;
882 IDirect3DSurface8Impl *Dest = (IDirect3DSurface8Impl *) pDestinationSurface;
884 HRESULT hr = WINED3D_OK;
885 WINED3DFORMAT srcFormat, destFormat;
886 UINT srcWidth, destWidth;
887 UINT srcHeight, destHeight;
889 WINED3DSURFACE_DESC winedesc;
891 TRACE("(%p) pSrcSur=%p, pSourceRects=%p, cRects=%d, pDstSur=%p, pDestPtsArr=%p\n", iface,
892 pSourceSurface, pSourceRects, cRects, pDestinationSurface, pDestPoints);
895 /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the destination texture is in WINED3DPOOL_DEFAULT */
897 EnterCriticalSection(&d3d8_cs);
898 IWineD3DSurface_GetDesc(Source->wineD3DSurface, &winedesc);
899 srcFormat = winedesc.format;
900 srcWidth = winedesc.width;
901 srcHeight = winedesc.height;
902 srcSize = winedesc.size;
904 IWineD3DSurface_GetDesc(Dest->wineD3DSurface, &winedesc);
905 destFormat = winedesc.format;
906 destWidth = winedesc.width;
907 destHeight = winedesc.height;
909 /* Check that the source and destination formats match */
910 if (srcFormat != destFormat && WINED3DFMT_UNKNOWN != destFormat) {
911 WARN("(%p) source %p format must match the dest %p format, returning WINED3DERR_INVALIDCALL\n", iface, pSourceSurface, pDestinationSurface);
912 LeaveCriticalSection(&d3d8_cs);
913 return WINED3DERR_INVALIDCALL;
914 } else if (WINED3DFMT_UNKNOWN == destFormat) {
915 TRACE("(%p) : Converting destination surface from WINED3DFMT_UNKNOWN to the source format\n", iface);
916 IWineD3DSurface_SetFormat(Dest->wineD3DSurface, srcFormat);
917 destFormat = srcFormat;
920 /* Quick if complete copy ... */
921 if (cRects == 0 && pSourceRects == NULL && pDestPoints == NULL) {
922 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
925 /* Copy rect by rect */
926 if (NULL != pSourceRects && NULL != pDestPoints) {
927 for (i = 0; i < cRects; ++i) {
928 IWineD3DSurface_BltFast(Dest->wineD3DSurface, pDestPoints[i].x, pDestPoints[i].y, Source->wineD3DSurface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
931 for (i = 0; i < cRects; ++i) {
932 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
936 LeaveCriticalSection(&d3d8_cs);
941 static HRESULT WINAPI IDirect3DDevice8Impl_UpdateTexture(LPDIRECT3DDEVICE8 iface, IDirect3DBaseTexture8* pSourceTexture, IDirect3DBaseTexture8* pDestinationTexture) {
942 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
944 TRACE("(%p) Relay\n" , This);
946 EnterCriticalSection(&d3d8_cs);
947 hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice, ((IDirect3DBaseTexture8Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture8Impl *)pDestinationTexture)->wineD3DBaseTexture);
948 LeaveCriticalSection(&d3d8_cs);
952 static HRESULT WINAPI IDirect3DDevice8Impl_GetFrontBuffer(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pDestSurface) {
953 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
954 IDirect3DSurface8Impl *destSurface = (IDirect3DSurface8Impl *)pDestSurface;
957 TRACE("(%p) Relay\n" , This);
959 if (pDestSurface == NULL) {
960 WARN("(%p) : Caller passed NULL as pDestSurface returning D3DERR_INVALIDCALL\n", This);
961 return D3DERR_INVALIDCALL;
964 EnterCriticalSection(&d3d8_cs);
965 hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, 0, destSurface->wineD3DSurface);
966 LeaveCriticalSection(&d3d8_cs);
970 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pRenderTarget, IDirect3DSurface8* pNewZStencil) {
971 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
972 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl *)pRenderTarget;
973 IDirect3DSurface8Impl *pZSurface = (IDirect3DSurface8Impl *)pNewZStencil;
974 IWineD3DSurface *original_ds = NULL;
976 TRACE("(%p) Relay\n" , This);
978 EnterCriticalSection(&d3d8_cs);
980 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice, &original_ds);
981 if (hr == WINED3D_OK || hr == WINED3DERR_NOTFOUND)
983 hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, pZSurface ? pZSurface->wineD3DSurface : NULL);
984 if (SUCCEEDED(hr) && pSurface)
985 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, 0, pSurface->wineD3DSurface);
986 if (FAILED(hr)) IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, original_ds);
988 if (original_ds) IWineD3DSurface_Release(original_ds);
990 LeaveCriticalSection(&d3d8_cs);
994 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppRenderTarget) {
995 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
997 IWineD3DSurface *pRenderTarget;
999 TRACE("(%p) Relay\n" , This);
1001 if (ppRenderTarget == NULL) {
1002 return D3DERR_INVALIDCALL;
1004 EnterCriticalSection(&d3d8_cs);
1005 hr = IWineD3DDevice_GetRenderTarget(This->WineD3DDevice, 0, &pRenderTarget);
1007 if (hr == D3D_OK && pRenderTarget != NULL) {
1008 IWineD3DSurface_GetParent(pRenderTarget,(IUnknown**)ppRenderTarget);
1009 IWineD3DSurface_Release(pRenderTarget);
1011 FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
1012 *ppRenderTarget = NULL;
1014 LeaveCriticalSection(&d3d8_cs);
1019 static HRESULT WINAPI IDirect3DDevice8Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppZStencilSurface) {
1020 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1021 HRESULT hr = D3D_OK;
1022 IWineD3DSurface *pZStencilSurface;
1024 TRACE("(%p) Relay\n" , This);
1025 if(ppZStencilSurface == NULL){
1026 return D3DERR_INVALIDCALL;
1029 EnterCriticalSection(&d3d8_cs);
1030 hr=IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
1031 if (hr == WINED3D_OK) {
1032 IWineD3DSurface_GetParent(pZStencilSurface,(IUnknown**)ppZStencilSurface);
1033 IWineD3DSurface_Release(pZStencilSurface);
1035 if (hr != WINED3DERR_NOTFOUND)
1036 FIXME("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
1037 *ppZStencilSurface = NULL;
1039 LeaveCriticalSection(&d3d8_cs);
1044 static HRESULT WINAPI IDirect3DDevice8Impl_BeginScene(LPDIRECT3DDEVICE8 iface) {
1045 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1047 TRACE("(%p) Relay\n" , This);
1049 EnterCriticalSection(&d3d8_cs);
1050 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
1051 LeaveCriticalSection(&d3d8_cs);
1055 static HRESULT WINAPI IDirect3DDevice8Impl_EndScene(LPDIRECT3DDEVICE8 iface) {
1056 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1058 TRACE("(%p) Relay\n" , This);
1060 EnterCriticalSection(&d3d8_cs);
1061 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
1062 LeaveCriticalSection(&d3d8_cs);
1066 static HRESULT WINAPI IDirect3DDevice8Impl_Clear(LPDIRECT3DDEVICE8 iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
1067 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1069 TRACE("(%p) Relay\n" , This);
1071 /* Note: D3DRECT is compatible with WINED3DRECT */
1072 EnterCriticalSection(&d3d8_cs);
1073 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (CONST WINED3DRECT*) pRects, Flags, Color, Z, Stencil);
1074 LeaveCriticalSection(&d3d8_cs);
1078 static HRESULT WINAPI IDirect3DDevice8Impl_SetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
1079 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1081 TRACE("(%p) Relay\n" , This);
1083 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1084 EnterCriticalSection(&d3d8_cs);
1085 hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
1086 LeaveCriticalSection(&d3d8_cs);
1090 static HRESULT WINAPI IDirect3DDevice8Impl_GetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State,D3DMATRIX* pMatrix) {
1091 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1093 TRACE("(%p) Relay\n" , This);
1095 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1096 EnterCriticalSection(&d3d8_cs);
1097 hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
1098 LeaveCriticalSection(&d3d8_cs);
1102 static HRESULT WINAPI IDirect3DDevice8Impl_MultiplyTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
1103 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1105 TRACE("(%p) Relay\n" , This);
1107 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1108 EnterCriticalSection(&d3d8_cs);
1109 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
1110 LeaveCriticalSection(&d3d8_cs);
1114 static HRESULT WINAPI IDirect3DDevice8Impl_SetViewport(LPDIRECT3DDEVICE8 iface, CONST D3DVIEWPORT8* pViewport) {
1115 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1117 TRACE("(%p) Relay\n" , This);
1119 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1120 EnterCriticalSection(&d3d8_cs);
1121 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
1122 LeaveCriticalSection(&d3d8_cs);
1126 static HRESULT WINAPI IDirect3DDevice8Impl_GetViewport(LPDIRECT3DDEVICE8 iface, D3DVIEWPORT8* pViewport) {
1127 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1129 TRACE("(%p) Relay\n" , This);
1131 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1132 EnterCriticalSection(&d3d8_cs);
1133 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
1134 LeaveCriticalSection(&d3d8_cs);
1138 static HRESULT WINAPI IDirect3DDevice8Impl_SetMaterial(LPDIRECT3DDEVICE8 iface, CONST D3DMATERIAL8* pMaterial) {
1139 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1141 TRACE("(%p) Relay\n" , This);
1143 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1144 EnterCriticalSection(&d3d8_cs);
1145 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
1146 LeaveCriticalSection(&d3d8_cs);
1150 static HRESULT WINAPI IDirect3DDevice8Impl_GetMaterial(LPDIRECT3DDEVICE8 iface, D3DMATERIAL8* pMaterial) {
1151 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1153 TRACE("(%p) Relay\n" , This);
1155 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1156 EnterCriticalSection(&d3d8_cs);
1157 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
1158 LeaveCriticalSection(&d3d8_cs);
1162 static HRESULT WINAPI IDirect3DDevice8Impl_SetLight(LPDIRECT3DDEVICE8 iface, DWORD Index, CONST D3DLIGHT8* pLight) {
1163 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1165 TRACE("(%p) Relay\n" , This);
1167 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1168 EnterCriticalSection(&d3d8_cs);
1169 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
1170 LeaveCriticalSection(&d3d8_cs);
1174 static HRESULT WINAPI IDirect3DDevice8Impl_GetLight(LPDIRECT3DDEVICE8 iface, DWORD Index,D3DLIGHT8* pLight) {
1175 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1177 TRACE("(%p) Relay\n" , This);
1179 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1180 EnterCriticalSection(&d3d8_cs);
1181 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1182 LeaveCriticalSection(&d3d8_cs);
1186 static HRESULT WINAPI IDirect3DDevice8Impl_LightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL Enable) {
1187 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1189 TRACE("(%p) Relay\n" , This);
1191 EnterCriticalSection(&d3d8_cs);
1192 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1193 LeaveCriticalSection(&d3d8_cs);
1197 static HRESULT WINAPI IDirect3DDevice8Impl_GetLightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL* pEnable) {
1198 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1200 TRACE("(%p) Relay\n" , This);
1202 EnterCriticalSection(&d3d8_cs);
1203 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1204 LeaveCriticalSection(&d3d8_cs);
1208 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,CONST float* pPlane) {
1209 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1211 TRACE("(%p) Relay\n" , This);
1213 EnterCriticalSection(&d3d8_cs);
1214 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1215 LeaveCriticalSection(&d3d8_cs);
1219 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,float* pPlane) {
1220 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1222 TRACE("(%p) Relay\n" , This);
1224 EnterCriticalSection(&d3d8_cs);
1225 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1226 LeaveCriticalSection(&d3d8_cs);
1230 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD Value) {
1231 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1233 TRACE("(%p) Relay\n" , This);
1235 EnterCriticalSection(&d3d8_cs);
1236 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1237 LeaveCriticalSection(&d3d8_cs);
1241 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD* pValue) {
1242 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1244 TRACE("(%p) Relay\n" , This);
1246 EnterCriticalSection(&d3d8_cs);
1247 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1248 LeaveCriticalSection(&d3d8_cs);
1252 static HRESULT WINAPI IDirect3DDevice8Impl_BeginStateBlock(LPDIRECT3DDEVICE8 iface) {
1253 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1255 TRACE("(%p)\n", This);
1257 EnterCriticalSection(&d3d8_cs);
1258 hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
1259 LeaveCriticalSection(&d3d8_cs);
1263 static HRESULT WINAPI IDirect3DDevice8Impl_EndStateBlock(LPDIRECT3DDEVICE8 iface, DWORD* pToken) {
1264 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1266 IWineD3DStateBlock* wineD3DStateBlock;
1267 IDirect3DStateBlock8Impl* object;
1269 TRACE("(%p) Relay\n", This);
1271 /* Tell wineD3D to endstateblock before anything else (in case we run out
1272 * of memory later and cause locking problems)
1274 EnterCriticalSection(&d3d8_cs);
1275 hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice , &wineD3DStateBlock);
1277 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
1278 LeaveCriticalSection(&d3d8_cs);
1282 /* allocate a new IDirectD3DStateBlock */
1283 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY ,sizeof(IDirect3DStateBlock8Impl));
1285 object->lpVtbl = &Direct3DStateBlock8_Vtbl;
1287 object->wineD3DStateBlock = wineD3DStateBlock;
1289 *pToken = d3d8_allocate_handle(&This->handle_table, object);
1290 LeaveCriticalSection(&d3d8_cs);
1292 if (*pToken == D3D8_INVALID_HANDLE)
1294 ERR("Failed to create a handle\n");
1295 IDirect3DStateBlock8_Release((IDirect3DStateBlock8 *)object);
1300 TRACE("Returning %#x (%p).\n", *pToken, object);
1305 static HRESULT WINAPI IDirect3DDevice8Impl_ApplyStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1306 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1307 IDirect3DStateBlock8Impl *pSB;
1310 TRACE("(%p) %#x Relay\n", This, Token);
1312 EnterCriticalSection(&d3d8_cs);
1313 pSB = d3d8_get_object(&This->handle_table, Token - 1);
1316 WARN("Invalid handle (%#x) passed.\n", Token);
1317 LeaveCriticalSection(&d3d8_cs);
1318 return D3DERR_INVALIDCALL;
1320 hr = IWineD3DStateBlock_Apply(pSB->wineD3DStateBlock);
1321 LeaveCriticalSection(&d3d8_cs);
1325 static HRESULT WINAPI IDirect3DDevice8Impl_CaptureStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1326 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1327 IDirect3DStateBlock8Impl *pSB;
1330 TRACE("(%p) %#x Relay\n", This, Token);
1332 EnterCriticalSection(&d3d8_cs);
1333 pSB = d3d8_get_object(&This->handle_table, Token - 1);
1336 WARN("Invalid handle (%#x) passed.\n", Token);
1337 LeaveCriticalSection(&d3d8_cs);
1338 return D3DERR_INVALIDCALL;
1340 hr = IWineD3DStateBlock_Capture(pSB->wineD3DStateBlock);
1341 LeaveCriticalSection(&d3d8_cs);
1345 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1346 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1347 IDirect3DStateBlock8Impl *pSB;
1349 TRACE("(%p) Relay\n", This);
1351 EnterCriticalSection(&d3d8_cs);
1352 pSB = d3d8_free_handle(&This->handle_table, Token - 1);
1353 LeaveCriticalSection(&d3d8_cs);
1357 WARN("Invalid handle (%#x) passed.\n", Token);
1358 return D3DERR_INVALIDCALL;
1361 if (IUnknown_Release((IUnknown *)pSB))
1363 ERR("Stateblock %p has references left, this shouldn't happen.\n", pSB);
1369 static HRESULT WINAPI IDirect3DDevice8Impl_CreateStateBlock(IDirect3DDevice8 *iface,
1370 D3DSTATEBLOCKTYPE Type, DWORD *handle)
1372 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1373 IDirect3DStateBlock8Impl *object;
1376 TRACE("(%p) Relay\n", This);
1378 if (Type != D3DSBT_ALL
1379 && Type != D3DSBT_PIXELSTATE
1380 && Type != D3DSBT_VERTEXSTATE)
1382 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1383 return D3DERR_INVALIDCALL;
1386 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DStateBlock8Impl));
1389 ERR("Failed to allocate memory.\n");
1390 return E_OUTOFMEMORY;
1393 object->lpVtbl = &Direct3DStateBlock8_Vtbl;
1396 EnterCriticalSection(&d3d8_cs);
1397 hr = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type,
1398 &object->wineD3DStateBlock, (IUnknown *)object);
1401 LeaveCriticalSection(&d3d8_cs);
1402 ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr);
1403 HeapFree(GetProcessHeap(), 0, object);
1407 *handle = d3d8_allocate_handle(&This->handle_table, object);
1408 LeaveCriticalSection(&d3d8_cs);
1410 if (*handle == D3D8_INVALID_HANDLE)
1412 ERR("Failed to allocate a handle.\n");
1413 IDirect3DStateBlock8_Release((IDirect3DStateBlock8 *)object);
1418 TRACE("Returning %#x (%p).\n", *handle, object);
1423 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipStatus(LPDIRECT3DDEVICE8 iface, CONST D3DCLIPSTATUS8* pClipStatus) {
1424 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1426 TRACE("(%p) Relay\n" , This);
1427 /* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
1428 EnterCriticalSection(&d3d8_cs);
1429 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1430 LeaveCriticalSection(&d3d8_cs);
1434 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipStatus(LPDIRECT3DDEVICE8 iface, D3DCLIPSTATUS8* pClipStatus) {
1435 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1437 TRACE("(%p) Relay\n" , This);
1439 EnterCriticalSection(&d3d8_cs);
1440 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1441 LeaveCriticalSection(&d3d8_cs);
1445 static HRESULT WINAPI IDirect3DDevice8Impl_GetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage,IDirect3DBaseTexture8** ppTexture) {
1446 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1447 IWineD3DBaseTexture *retTexture = NULL;
1448 HRESULT rc = D3D_OK;
1450 TRACE("(%p) Relay\n" , This);
1452 if(ppTexture == NULL){
1453 return D3DERR_INVALIDCALL;
1456 EnterCriticalSection(&d3d8_cs);
1457 rc = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
1458 if (rc == D3D_OK && NULL != retTexture) {
1459 IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
1460 IWineD3DBaseTexture_Release(retTexture);
1462 FIXME("Call to get texture (%d) failed (%p)\n", Stage, retTexture);
1465 LeaveCriticalSection(&d3d8_cs);
1470 static HRESULT WINAPI IDirect3DDevice8Impl_SetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage, IDirect3DBaseTexture8* pTexture) {
1471 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1473 TRACE("(%p) Relay %d %p\n" , This, Stage, pTexture);
1475 EnterCriticalSection(&d3d8_cs);
1476 hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
1477 pTexture==NULL ? NULL : ((IDirect3DBaseTexture8Impl *)pTexture)->wineD3DBaseTexture);
1478 LeaveCriticalSection(&d3d8_cs);
1482 static const struct tss_lookup
1489 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 0, unused */
1490 {FALSE, WINED3DTSS_COLOROP}, /* 1, D3DTSS_COLOROP */
1491 {FALSE, WINED3DTSS_COLORARG1}, /* 2, D3DTSS_COLORARG1 */
1492 {FALSE, WINED3DTSS_COLORARG2}, /* 3, D3DTSS_COLORARG2 */
1493 {FALSE, WINED3DTSS_ALPHAOP}, /* 4, D3DTSS_ALPHAOP */
1494 {FALSE, WINED3DTSS_ALPHAARG1}, /* 5, D3DTSS_ALPHAARG1 */
1495 {FALSE, WINED3DTSS_ALPHAARG2}, /* 6, D3DTSS_ALPHAARG2 */
1496 {FALSE, WINED3DTSS_BUMPENVMAT00}, /* 7, D3DTSS_BUMPENVMAT00 */
1497 {FALSE, WINED3DTSS_BUMPENVMAT01}, /* 8, D3DTSS_BUMPENVMAT01 */
1498 {FALSE, WINED3DTSS_BUMPENVMAT10}, /* 9, D3DTSS_BUMPENVMAT10 */
1499 {FALSE, WINED3DTSS_BUMPENVMAT11}, /* 10, D3DTSS_BUMPENVMAT11 */
1500 {FALSE, WINED3DTSS_TEXCOORDINDEX}, /* 11, D3DTSS_TEXCOORDINDEX */
1501 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 12, unused */
1502 {TRUE, WINED3DSAMP_ADDRESSU}, /* 13, D3DTSS_ADDRESSU */
1503 {TRUE, WINED3DSAMP_ADDRESSV}, /* 14, D3DTSS_ADDRESSV */
1504 {TRUE, WINED3DSAMP_BORDERCOLOR}, /* 15, D3DTSS_BORDERCOLOR */
1505 {TRUE, WINED3DSAMP_MAGFILTER}, /* 16, D3DTSS_MAGFILTER */
1506 {TRUE, WINED3DSAMP_MINFILTER}, /* 17, D3DTSS_MINFILTER */
1507 {TRUE, WINED3DSAMP_MIPFILTER}, /* 18, D3DTSS_MIPFILTER */
1508 {TRUE, WINED3DSAMP_MIPMAPLODBIAS}, /* 19, D3DTSS_MIPMAPLODBIAS */
1509 {TRUE, WINED3DSAMP_MAXMIPLEVEL}, /* 20, D3DTSS_MAXMIPLEVEL */
1510 {TRUE, WINED3DSAMP_MAXANISOTROPY}, /* 21, D3DTSS_MAXANISOTROPY */
1511 {FALSE, WINED3DTSS_BUMPENVLSCALE}, /* 22, D3DTSS_BUMPENVLSCALE */
1512 {FALSE, WINED3DTSS_BUMPENVLOFFSET}, /* 23, D3DTSS_BUMPENVLOFFSET */
1513 {FALSE, WINED3DTSS_TEXTURETRANSFORMFLAGS}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1514 {TRUE, WINED3DSAMP_ADDRESSW}, /* 25, D3DTSS_ADDRESSW */
1515 {FALSE, WINED3DTSS_COLORARG0}, /* 26, D3DTSS_COLORARG0 */
1516 {FALSE, WINED3DTSS_ALPHAARG0}, /* 27, D3DTSS_ALPHAARG0 */
1517 {FALSE, WINED3DTSS_RESULTARG}, /* 28, D3DTSS_RESULTARG */
1520 static HRESULT WINAPI IDirect3DDevice8Impl_GetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD* pValue) {
1521 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1522 const struct tss_lookup *l = &tss_lookup[Type];
1524 TRACE("(%p) Relay\n" , This);
1526 EnterCriticalSection(&d3d8_cs);
1528 if (l->sampler_state) hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Stage, l->state, pValue);
1529 else hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, l->state, pValue);
1531 LeaveCriticalSection(&d3d8_cs);
1535 static HRESULT WINAPI IDirect3DDevice8Impl_SetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
1536 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1537 const struct tss_lookup *l = &tss_lookup[Type];
1539 TRACE("(%p) Relay\n" , This);
1541 EnterCriticalSection(&d3d8_cs);
1543 if (l->sampler_state) hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Stage, l->state, Value);
1544 else hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, l->state, Value);
1546 LeaveCriticalSection(&d3d8_cs);
1550 static HRESULT WINAPI IDirect3DDevice8Impl_ValidateDevice(LPDIRECT3DDEVICE8 iface, DWORD* pNumPasses) {
1551 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1553 TRACE("(%p) Relay\n" , This);
1555 EnterCriticalSection(&d3d8_cs);
1556 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1557 LeaveCriticalSection(&d3d8_cs);
1561 static HRESULT WINAPI IDirect3DDevice8Impl_GetInfo(LPDIRECT3DDEVICE8 iface, DWORD DevInfoID, void* pDevInfoStruct, DWORD DevInfoStructSize) {
1562 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1563 FIXME("(%p) : stub\n", This);
1567 static HRESULT WINAPI IDirect3DDevice8Impl_SetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, CONST PALETTEENTRY* pEntries) {
1568 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1570 TRACE("(%p) Relay\n" , This);
1572 EnterCriticalSection(&d3d8_cs);
1573 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1574 LeaveCriticalSection(&d3d8_cs);
1578 static HRESULT WINAPI IDirect3DDevice8Impl_GetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
1579 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1581 TRACE("(%p) Relay\n" , This);
1583 EnterCriticalSection(&d3d8_cs);
1584 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1585 LeaveCriticalSection(&d3d8_cs);
1589 static HRESULT WINAPI IDirect3DDevice8Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber) {
1590 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1592 TRACE("(%p) Relay\n" , This);
1594 EnterCriticalSection(&d3d8_cs);
1595 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1596 LeaveCriticalSection(&d3d8_cs);
1600 static HRESULT WINAPI IDirect3DDevice8Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT *PaletteNumber) {
1601 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1603 TRACE("(%p) Relay\n" , This);
1605 EnterCriticalSection(&d3d8_cs);
1606 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1607 LeaveCriticalSection(&d3d8_cs);
1611 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitive(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) {
1612 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1614 TRACE("(%p) Relay\n" , This);
1616 EnterCriticalSection(&d3d8_cs);
1617 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1618 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
1619 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
1620 LeaveCriticalSection(&d3d8_cs);
1624 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,
1625 UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount) {
1626 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1628 TRACE("(%p) Relay\n" , This);
1630 EnterCriticalSection(&d3d8_cs);
1631 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1632 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, MinVertexIndex, NumVertices,
1633 startIndex, vertex_count_from_primitive_count(PrimitiveType, primCount));
1634 LeaveCriticalSection(&d3d8_cs);
1638 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT PrimitiveCount,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride) {
1639 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1641 TRACE("(%p) Relay\n" , This);
1643 EnterCriticalSection(&d3d8_cs);
1644 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1645 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
1646 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
1647 pVertexStreamZeroData, VertexStreamZeroStride);
1648 LeaveCriticalSection(&d3d8_cs);
1652 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,
1653 UINT NumVertexIndices,UINT PrimitiveCount,CONST void* pIndexData,
1654 D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,
1655 UINT VertexStreamZeroStride) {
1656 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1658 TRACE("(%p) Relay\n" , This);
1660 EnterCriticalSection(&d3d8_cs);
1661 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1662 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice, MinVertexIndex, NumVertexIndices,
1663 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
1664 wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
1665 LeaveCriticalSection(&d3d8_cs);
1669 static HRESULT WINAPI IDirect3DDevice8Impl_ProcessVertices(LPDIRECT3DDEVICE8 iface, UINT SrcStartIndex,UINT DestIndex,UINT VertexCount,IDirect3DVertexBuffer8* pDestBuffer,DWORD Flags) {
1670 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1672 IDirect3DVertexBuffer8Impl *dest = (IDirect3DVertexBuffer8Impl *) pDestBuffer;
1673 TRACE("(%p) Relay\n" , This);
1675 EnterCriticalSection(&d3d8_cs);
1676 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, NULL, Flags, dest->fvf);
1677 LeaveCriticalSection(&d3d8_cs);
1681 static HRESULT IDirect3DDevice8Impl_CreateVertexDeclaration(IDirect3DDevice8 *iface, CONST DWORD *declaration, IDirect3DVertexDeclaration8 **decl_ptr) {
1682 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1683 IDirect3DVertexDeclaration8Impl *object;
1684 WINED3DVERTEXELEMENT *wined3d_elements;
1685 UINT wined3d_element_count;
1686 HRESULT hr = D3D_OK;
1688 TRACE("(%p) : declaration %p\n", This, declaration);
1690 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1692 ERR("Memory allocation failed\n");
1694 return D3DERR_OUTOFVIDEOMEMORY;
1697 object->ref_count = 1;
1698 object->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
1700 wined3d_element_count = convert_to_wined3d_declaration(declaration, &object->elements_size, &wined3d_elements);
1701 object->elements = HeapAlloc(GetProcessHeap(), 0, object->elements_size);
1702 if (!object->elements) {
1703 ERR("Memory allocation failed\n");
1704 HeapFree(GetProcessHeap(), 0, wined3d_elements);
1705 HeapFree(GetProcessHeap(), 0, object);
1707 return D3DERR_OUTOFVIDEOMEMORY;
1710 CopyMemory(object->elements, declaration, object->elements_size);
1712 EnterCriticalSection(&d3d8_cs);
1713 hr = IWineD3DDevice_CreateVertexDeclaration(This->WineD3DDevice, &object->wined3d_vertex_declaration,
1714 (IUnknown *)object, wined3d_elements, wined3d_element_count);
1715 LeaveCriticalSection(&d3d8_cs);
1716 HeapFree(GetProcessHeap(), 0, wined3d_elements);
1719 ERR("(%p) : IWineD3DDevice_CreateVertexDeclaration call failed\n", This);
1720 HeapFree(GetProcessHeap(), 0, object->elements);
1721 HeapFree(GetProcessHeap(), 0, object);
1723 *decl_ptr = (IDirect3DVertexDeclaration8 *)object;
1724 TRACE("(%p) : Created vertex declaration %p\n", This, object);
1730 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pDeclaration, CONST DWORD* pFunction, DWORD* ppShader, DWORD Usage) {
1731 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1732 HRESULT hrc = D3D_OK;
1733 IDirect3DVertexShader8Impl *object;
1734 const DWORD *token = pDeclaration;
1737 /* Test if the vertex declaration is valid */
1738 while (D3DVSD_END() != *token) {
1739 D3DVSD_TOKENTYPE token_type = ((*token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT);
1741 if (token_type == D3DVSD_TOKEN_STREAMDATA && !(token_type & 0x10000000)) {
1742 DWORD type = ((*token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
1743 DWORD reg = ((*token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
1745 if(reg == D3DVSDE_NORMAL && type != D3DVSDT_FLOAT3 && !pFunction) {
1746 WARN("Attempt to use a non-FLOAT3 normal with the fixed function function\n");
1747 return D3DERR_INVALIDCALL;
1750 token += parse_token(token);
1753 /* Setup a stub object for now */
1754 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1755 TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
1756 if (NULL == object) {
1757 FIXME("Allocation of memory failed\n");
1759 return D3DERR_OUTOFVIDEOMEMORY;
1763 object->lpVtbl = &Direct3DVertexShader8_Vtbl;
1765 hrc = IDirect3DDevice8Impl_CreateVertexDeclaration(iface, pDeclaration, &object->vertex_declaration);
1767 ERR("(%p) : IDirect3DDeviceImpl_CreateVertexDeclaration call failed\n", This);
1768 HeapFree(GetProcessHeap(), 0, object);
1770 return D3DERR_INVALIDCALL;
1773 EnterCriticalSection(&d3d8_cs);
1774 handle = d3d8_allocate_handle(&This->handle_table, object);
1775 if (handle == D3D8_INVALID_HANDLE)
1777 ERR("Failed to allocate shader handle\n");
1778 LeaveCriticalSection(&d3d8_cs);
1779 IDirect3DVertexDeclaration8_Release(object->vertex_declaration);
1780 HeapFree(GetProcessHeap(), 0, object);
1782 return E_OUTOFMEMORY;
1786 DWORD shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
1787 *ppShader = ((IDirect3DVertexDeclaration8Impl *)object->vertex_declaration)->shader_handle = shader_handle;
1792 /* Usage is missing ... Use SetRenderState to set the sw vp render state in SetVertexShader */
1793 hrc = IWineD3DDevice_CreateVertexShader(This->WineD3DDevice, pFunction,
1794 NULL /* output signature */, &object->wineD3DVertexShader, (IUnknown *)object);
1798 /* free up object */
1799 FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n");
1800 d3d8_free_handle(&This->handle_table, handle);
1801 IDirect3DVertexDeclaration8_Release(object->vertex_declaration);
1802 HeapFree(GetProcessHeap(), 0, object);
1807 load_local_constants(pDeclaration, object->wineD3DVertexShader);
1808 TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
1812 LeaveCriticalSection(&d3d8_cs);
1817 static IDirect3DVertexDeclaration8Impl *IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl *This, DWORD fvf)
1819 IDirect3DVertexDeclaration8Impl *d3d8_declaration;
1821 int p, low, high; /* deliberately signed */
1822 struct FvfToDecl *convertedDecls = This->decls;
1824 TRACE("Searching for declaration for fvf %08x... ", fvf);
1827 high = This->numConvertedDecls - 1;
1828 while(low <= high) {
1829 p = (low + high) >> 1;
1831 if(convertedDecls[p].fvf == fvf) {
1832 TRACE("found %p\n", convertedDecls[p].decl);
1833 return (IDirect3DVertexDeclaration8Impl *)convertedDecls[p].decl;
1834 } else if(convertedDecls[p].fvf < fvf) {
1840 TRACE("not found. Creating and inserting at position %d.\n", low);
1842 d3d8_declaration = HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration));
1843 if (!d3d8_declaration)
1845 ERR("Memory allocation failed.\n");
1849 d3d8_declaration->ref_count = 1;
1850 d3d8_declaration->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
1851 d3d8_declaration->elements = NULL;
1852 d3d8_declaration->elements_size = 0;
1853 d3d8_declaration->shader_handle = fvf;
1855 hr = IWineD3DDevice_CreateVertexDeclarationFromFVF(This->WineD3DDevice,
1856 &d3d8_declaration->wined3d_vertex_declaration, (IUnknown *)d3d8_declaration, fvf);
1859 ERR("Failed to create wined3d vertex declaration.\n");
1860 HeapFree(GetProcessHeap(), 0, d3d8_declaration);
1864 if(This->declArraySize == This->numConvertedDecls) {
1865 int grow = This->declArraySize / 2;
1866 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
1867 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
1868 if(!convertedDecls) {
1869 /* This will destroy it */
1870 IDirect3DVertexDeclaration8_Release((IDirect3DVertexDeclaration8 *)d3d8_declaration);
1873 This->decls = convertedDecls;
1874 This->declArraySize += grow;
1877 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(convertedDecls[0]) * (This->numConvertedDecls - low));
1878 convertedDecls[low].decl = (IDirect3DVertexDeclaration8 *)d3d8_declaration;
1879 convertedDecls[low].fvf = fvf;
1880 This->numConvertedDecls++;
1882 TRACE("Returning %p. %u decls in array\n", d3d8_declaration, This->numConvertedDecls);
1883 return d3d8_declaration;
1886 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1887 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1888 IDirect3DVertexShader8Impl *shader;
1891 TRACE("(%p) : Relay\n", This);
1893 if (VS_HIGHESTFIXEDFXF >= pShader) {
1894 TRACE("Setting FVF, %#x\n", pShader);
1896 EnterCriticalSection(&d3d8_cs);
1897 IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
1898 IDirect3DDevice8Impl_FindDecl(This, pShader)->wined3d_vertex_declaration);
1899 IWineD3DDevice_SetVertexShader(This->WineD3DDevice, NULL);
1900 LeaveCriticalSection(&d3d8_cs);
1904 TRACE("Setting shader\n");
1906 EnterCriticalSection(&d3d8_cs);
1907 shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1));
1910 WARN("Invalid handle (%#x) passed.\n", pShader);
1911 LeaveCriticalSection(&d3d8_cs);
1912 return D3DERR_INVALIDCALL;
1915 hr = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
1916 ((IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration)->wined3d_vertex_declaration);
1917 if (SUCCEEDED(hr)) hr = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, shader->wineD3DVertexShader);
1918 LeaveCriticalSection(&d3d8_cs);
1920 TRACE("Returning hr %#x\n", hr);
1925 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
1926 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1927 IWineD3DVertexDeclaration *wined3d_declaration;
1928 IDirect3DVertexDeclaration8 *d3d8_declaration;
1931 TRACE("(%p) : Relay device@%p\n", This, This->WineD3DDevice);
1932 EnterCriticalSection(&d3d8_cs);
1934 hrc = IWineD3DDevice_GetVertexDeclaration(This->WineD3DDevice, &wined3d_declaration);
1937 LeaveCriticalSection(&d3d8_cs);
1938 WARN("(%p) : Call to IWineD3DDevice_GetVertexDeclaration failed %#x (device %p)\n",
1939 This, hrc, This->WineD3DDevice);
1943 if (!wined3d_declaration)
1945 LeaveCriticalSection(&d3d8_cs);
1950 hrc = IWineD3DVertexDeclaration_GetParent(wined3d_declaration, (IUnknown **)&d3d8_declaration);
1951 IWineD3DVertexDeclaration_Release(wined3d_declaration);
1952 LeaveCriticalSection(&d3d8_cs);
1955 *ppShader = ((IDirect3DVertexDeclaration8Impl *)d3d8_declaration)->shader_handle;
1956 IDirect3DVertexDeclaration8_Release(d3d8_declaration);
1959 TRACE("(%p) : returning %#x\n", This, *ppShader);
1964 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1965 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1966 IDirect3DVertexShader8Impl *shader;
1967 IWineD3DVertexShader *cur = NULL;
1969 TRACE("(%p) : pShader %#x\n", This, pShader);
1971 EnterCriticalSection(&d3d8_cs);
1973 shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1));
1976 WARN("Invalid handle (%#x) passed.\n", pShader);
1977 LeaveCriticalSection(&d3d8_cs);
1978 return D3DERR_INVALIDCALL;
1981 IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &cur);
1985 if (cur == shader->wineD3DVertexShader) IDirect3DDevice8_SetVertexShader(iface, 0);
1986 IWineD3DVertexShader_Release(cur);
1989 LeaveCriticalSection(&d3d8_cs);
1991 if (IUnknown_Release((IUnknown *)shader))
1993 ERR("Shader %p has references left, this shouldn't happen.\n", shader);
1999 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
2000 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2002 TRACE("(%p) : Relay\n", This);
2004 if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
2005 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2006 Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2007 return D3DERR_INVALIDCALL;
2010 EnterCriticalSection(&d3d8_cs);
2011 hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2012 LeaveCriticalSection(&d3d8_cs);
2016 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
2017 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2019 TRACE("(%p) : Relay\n", This);
2021 if(Register + ConstantCount > D3D8_MAX_VERTEX_SHADER_CONSTANTF) {
2022 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2023 Register + ConstantCount, D3D8_MAX_VERTEX_SHADER_CONSTANTF);
2024 return D3DERR_INVALIDCALL;
2027 EnterCriticalSection(&d3d8_cs);
2028 hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2029 LeaveCriticalSection(&d3d8_cs);
2033 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderDeclaration(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
2034 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2035 IDirect3DVertexDeclaration8Impl *declaration;
2036 IDirect3DVertexShader8Impl *shader;
2038 TRACE("(%p) : pVertexShader 0x%08x, pData %p, *pSizeOfData %u\n", This, pVertexShader, pData, *pSizeOfData);
2040 EnterCriticalSection(&d3d8_cs);
2042 shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1));
2043 LeaveCriticalSection(&d3d8_cs);
2046 WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2047 return D3DERR_INVALIDCALL;
2049 declaration = (IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration;
2051 /* If pData is NULL, we just return the required size of the buffer. */
2053 *pSizeOfData = declaration->elements_size;
2057 /* MSDN claims that if *pSizeOfData is smaller than the required size
2058 * we should write the required size and return D3DERR_MOREDATA.
2059 * That's not actually true. */
2060 if (*pSizeOfData < declaration->elements_size) {
2061 return D3DERR_INVALIDCALL;
2064 CopyMemory(pData, declaration->elements, declaration->elements_size);
2069 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
2070 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2071 IDirect3DVertexShader8Impl *shader = NULL;
2074 TRACE("(%p) : pVertexShader %#x, pData %p, pSizeOfData %p\n", This, pVertexShader, pData, pSizeOfData);
2076 EnterCriticalSection(&d3d8_cs);
2078 shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1));
2081 WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2082 LeaveCriticalSection(&d3d8_cs);
2083 return D3DERR_INVALIDCALL;
2086 if (!shader->wineD3DVertexShader)
2088 LeaveCriticalSection(&d3d8_cs);
2093 hr = IWineD3DVertexShader_GetFunction(shader->wineD3DVertexShader, pData, pSizeOfData);
2095 LeaveCriticalSection(&d3d8_cs);
2099 static HRESULT WINAPI IDirect3DDevice8Impl_SetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8* pIndexData, UINT baseVertexIndex) {
2100 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2102 IDirect3DIndexBuffer8Impl *ib = (IDirect3DIndexBuffer8Impl *)pIndexData;
2103 TRACE("(%p) Relay\n", This);
2105 EnterCriticalSection(&d3d8_cs);
2106 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
2107 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
2108 * vertex buffers can't be created to address them with an index that requires the 32nd bit
2109 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
2112 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, baseVertexIndex);
2113 hr = IWineD3DDevice_SetIndices(This->WineD3DDevice,
2114 ib ? ib->wineD3DIndexBuffer : NULL,
2115 ib ? ib->format : WINED3DFMT_UNKNOWN);
2116 LeaveCriticalSection(&d3d8_cs);
2120 static HRESULT WINAPI IDirect3DDevice8Impl_GetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8** ppIndexData,UINT* pBaseVertexIndex) {
2121 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2122 IWineD3DBuffer *retIndexData = NULL;
2123 HRESULT rc = D3D_OK;
2125 TRACE("(%p) Relay\n", This);
2127 if(ppIndexData == NULL){
2128 return D3DERR_INVALIDCALL;
2131 EnterCriticalSection(&d3d8_cs);
2132 /* The case from UINT to INT is safe because d3d8 will never set negative values */
2133 IWineD3DDevice_GetBaseVertexIndex(This->WineD3DDevice, (INT *) pBaseVertexIndex);
2134 rc = IWineD3DDevice_GetIndices(This->WineD3DDevice, &retIndexData);
2135 if (SUCCEEDED(rc) && retIndexData) {
2136 IWineD3DBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
2137 IWineD3DBuffer_Release(retIndexData);
2139 if (FAILED(rc)) FIXME("Call to GetIndices failed\n");
2140 *ppIndexData = NULL;
2142 LeaveCriticalSection(&d3d8_cs);
2146 static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pFunction, DWORD* ppShader) {
2147 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2148 IDirect3DPixelShader8Impl *object;
2152 TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
2154 if (NULL == ppShader) {
2155 TRACE("(%p) Invalid call\n", This);
2156 return D3DERR_INVALIDCALL;
2159 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2162 ERR("Failed to allocate memmory.\n");
2163 return E_OUTOFMEMORY;
2167 object->lpVtbl = &Direct3DPixelShader8_Vtbl;
2169 EnterCriticalSection(&d3d8_cs);
2170 hr = IWineD3DDevice_CreatePixelShader(This->WineD3DDevice, pFunction,
2171 NULL, &object->wineD3DPixelShader, (IUnknown *)object);
2174 LeaveCriticalSection(&d3d8_cs);
2175 FIXME("(%p) call to IWineD3DDevice_CreatePixelShader failed\n", This);
2176 HeapFree(GetProcessHeap(), 0 , object);
2181 handle = d3d8_allocate_handle(&This->handle_table, object);
2182 LeaveCriticalSection(&d3d8_cs);
2183 if (handle == D3D8_INVALID_HANDLE)
2185 ERR("Failed to allocate shader handle\n");
2186 IDirect3DVertexShader8_Release((IUnknown *)object);
2187 return E_OUTOFMEMORY;
2190 *ppShader = object->handle = handle + VS_HIGHESTFIXEDFXF + 1;
2191 TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
2196 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
2197 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2198 IDirect3DPixelShader8Impl *shader;
2201 TRACE("(%p) : pShader %#x\n", This, pShader);
2203 EnterCriticalSection(&d3d8_cs);
2207 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, NULL);
2208 LeaveCriticalSection(&d3d8_cs);
2212 shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1));
2215 WARN("Invalid handle (%#x) passed.\n", pShader);
2216 LeaveCriticalSection(&d3d8_cs);
2217 return D3DERR_INVALIDCALL;
2220 TRACE("(%p) : Setting shader %p\n", This, shader);
2221 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, shader->wineD3DPixelShader);
2222 LeaveCriticalSection(&d3d8_cs);
2226 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
2227 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2228 IWineD3DPixelShader *object;
2230 HRESULT hrc = D3D_OK;
2231 TRACE("(%p) Relay\n", This);
2232 if (NULL == ppShader) {
2233 TRACE("(%p) Invalid call\n", This);
2234 return D3DERR_INVALIDCALL;
2237 EnterCriticalSection(&d3d8_cs);
2238 hrc = IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &object);
2239 if (D3D_OK == hrc && NULL != object) {
2240 IDirect3DPixelShader8Impl *d3d8_shader;
2241 hrc = IWineD3DPixelShader_GetParent(object, (IUnknown **)&d3d8_shader);
2242 IWineD3DPixelShader_Release(object);
2243 *ppShader = d3d8_shader->handle;
2244 IDirect3DPixelShader8_Release((IDirect3DPixelShader8 *)d3d8_shader);
2249 TRACE("(%p) : returning %#x\n", This, *ppShader);
2250 LeaveCriticalSection(&d3d8_cs);
2254 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
2255 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2256 IDirect3DPixelShader8Impl *shader;
2257 IWineD3DPixelShader *cur = NULL;
2259 TRACE("(%p) : pShader %#x\n", This, pShader);
2261 EnterCriticalSection(&d3d8_cs);
2263 shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1));
2266 WARN("Invalid handle (%#x) passed.\n", pShader);
2267 LeaveCriticalSection(&d3d8_cs);
2268 return D3DERR_INVALIDCALL;
2271 IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &cur);
2275 if (cur == shader->wineD3DPixelShader) IDirect3DDevice8_SetPixelShader(iface, 0);
2276 IWineD3DPixelShader_Release(cur);
2279 LeaveCriticalSection(&d3d8_cs);
2281 if (IUnknown_Release((IUnknown *)shader))
2283 ERR("Shader %p has references left, this shouldn't happen.\n", shader);
2289 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
2290 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2292 TRACE("(%p) Relay\n", This);
2294 EnterCriticalSection(&d3d8_cs);
2295 hr = IWineD3DDevice_SetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2296 LeaveCriticalSection(&d3d8_cs);
2300 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
2301 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2303 TRACE("(%p) Relay\n", This);
2305 EnterCriticalSection(&d3d8_cs);
2306 hr = IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2307 LeaveCriticalSection(&d3d8_cs);
2311 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pPixelShader, void* pData, DWORD* pSizeOfData) {
2312 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2313 IDirect3DPixelShader8Impl *shader = NULL;
2316 TRACE("(%p) : pPixelShader %#x, pData %p, pSizeOfData %p\n", This, pPixelShader, pData, pSizeOfData);
2318 EnterCriticalSection(&d3d8_cs);
2319 shader = d3d8_get_object(&This->handle_table, pPixelShader - (VS_HIGHESTFIXEDFXF + 1));
2322 WARN("Invalid handle (%#x) passed.\n", pPixelShader);
2323 LeaveCriticalSection(&d3d8_cs);
2324 return D3DERR_INVALIDCALL;
2327 hr = IWineD3DPixelShader_GetFunction(shader->wineD3DPixelShader, pData, pSizeOfData);
2328 LeaveCriticalSection(&d3d8_cs);
2332 static HRESULT WINAPI IDirect3DDevice8Impl_DrawRectPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
2333 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2335 TRACE("(%p) Relay\n", This);
2337 EnterCriticalSection(&d3d8_cs);
2338 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
2339 LeaveCriticalSection(&d3d8_cs);
2343 static HRESULT WINAPI IDirect3DDevice8Impl_DrawTriPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
2344 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2346 TRACE("(%p) Relay\n", This);
2348 EnterCriticalSection(&d3d8_cs);
2349 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
2350 LeaveCriticalSection(&d3d8_cs);
2354 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePatch(LPDIRECT3DDEVICE8 iface, UINT Handle) {
2355 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2357 TRACE("(%p) Relay\n", This);
2359 EnterCriticalSection(&d3d8_cs);
2360 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
2361 LeaveCriticalSection(&d3d8_cs);
2365 static HRESULT WINAPI IDirect3DDevice8Impl_SetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8* pStreamData,UINT Stride) {
2366 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2368 TRACE("(%p) Relay\n" , This);
2370 EnterCriticalSection(&d3d8_cs);
2371 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
2372 NULL == pStreamData ? NULL : ((IDirect3DVertexBuffer8Impl *)pStreamData)->wineD3DVertexBuffer,
2373 0/* Offset in bytes */, Stride);
2374 LeaveCriticalSection(&d3d8_cs);
2378 static HRESULT WINAPI IDirect3DDevice8Impl_GetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8** pStream,UINT* pStride) {
2379 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2380 IWineD3DBuffer *retStream = NULL;
2381 HRESULT rc = D3D_OK;
2383 TRACE("(%p) Relay\n" , This);
2385 if(pStream == NULL){
2386 return D3DERR_INVALIDCALL;
2389 EnterCriticalSection(&d3d8_cs);
2390 rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, 0 /* Offset in bytes */, pStride);
2391 if (rc == D3D_OK && NULL != retStream) {
2392 IWineD3DBuffer_GetParent(retStream, (IUnknown **)pStream);
2393 IWineD3DBuffer_Release(retStream);
2396 FIXME("Call to GetStreamSource failed %p\n", pStride);
2400 LeaveCriticalSection(&d3d8_cs);
2406 const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl =
2408 IDirect3DDevice8Impl_QueryInterface,
2409 IDirect3DDevice8Impl_AddRef,
2410 IDirect3DDevice8Impl_Release,
2411 IDirect3DDevice8Impl_TestCooperativeLevel,
2412 IDirect3DDevice8Impl_GetAvailableTextureMem,
2413 IDirect3DDevice8Impl_ResourceManagerDiscardBytes,
2414 IDirect3DDevice8Impl_GetDirect3D,
2415 IDirect3DDevice8Impl_GetDeviceCaps,
2416 IDirect3DDevice8Impl_GetDisplayMode,
2417 IDirect3DDevice8Impl_GetCreationParameters,
2418 IDirect3DDevice8Impl_SetCursorProperties,
2419 IDirect3DDevice8Impl_SetCursorPosition,
2420 IDirect3DDevice8Impl_ShowCursor,
2421 IDirect3DDevice8Impl_CreateAdditionalSwapChain,
2422 IDirect3DDevice8Impl_Reset,
2423 IDirect3DDevice8Impl_Present,
2424 IDirect3DDevice8Impl_GetBackBuffer,
2425 IDirect3DDevice8Impl_GetRasterStatus,
2426 IDirect3DDevice8Impl_SetGammaRamp,
2427 IDirect3DDevice8Impl_GetGammaRamp,
2428 IDirect3DDevice8Impl_CreateTexture,
2429 IDirect3DDevice8Impl_CreateVolumeTexture,
2430 IDirect3DDevice8Impl_CreateCubeTexture,
2431 IDirect3DDevice8Impl_CreateVertexBuffer,
2432 IDirect3DDevice8Impl_CreateIndexBuffer,
2433 IDirect3DDevice8Impl_CreateRenderTarget,
2434 IDirect3DDevice8Impl_CreateDepthStencilSurface,
2435 IDirect3DDevice8Impl_CreateImageSurface,
2436 IDirect3DDevice8Impl_CopyRects,
2437 IDirect3DDevice8Impl_UpdateTexture,
2438 IDirect3DDevice8Impl_GetFrontBuffer,
2439 IDirect3DDevice8Impl_SetRenderTarget,
2440 IDirect3DDevice8Impl_GetRenderTarget,
2441 IDirect3DDevice8Impl_GetDepthStencilSurface,
2442 IDirect3DDevice8Impl_BeginScene,
2443 IDirect3DDevice8Impl_EndScene,
2444 IDirect3DDevice8Impl_Clear,
2445 IDirect3DDevice8Impl_SetTransform,
2446 IDirect3DDevice8Impl_GetTransform,
2447 IDirect3DDevice8Impl_MultiplyTransform,
2448 IDirect3DDevice8Impl_SetViewport,
2449 IDirect3DDevice8Impl_GetViewport,
2450 IDirect3DDevice8Impl_SetMaterial,
2451 IDirect3DDevice8Impl_GetMaterial,
2452 IDirect3DDevice8Impl_SetLight,
2453 IDirect3DDevice8Impl_GetLight,
2454 IDirect3DDevice8Impl_LightEnable,
2455 IDirect3DDevice8Impl_GetLightEnable,
2456 IDirect3DDevice8Impl_SetClipPlane,
2457 IDirect3DDevice8Impl_GetClipPlane,
2458 IDirect3DDevice8Impl_SetRenderState,
2459 IDirect3DDevice8Impl_GetRenderState,
2460 IDirect3DDevice8Impl_BeginStateBlock,
2461 IDirect3DDevice8Impl_EndStateBlock,
2462 IDirect3DDevice8Impl_ApplyStateBlock,
2463 IDirect3DDevice8Impl_CaptureStateBlock,
2464 IDirect3DDevice8Impl_DeleteStateBlock,
2465 IDirect3DDevice8Impl_CreateStateBlock,
2466 IDirect3DDevice8Impl_SetClipStatus,
2467 IDirect3DDevice8Impl_GetClipStatus,
2468 IDirect3DDevice8Impl_GetTexture,
2469 IDirect3DDevice8Impl_SetTexture,
2470 IDirect3DDevice8Impl_GetTextureStageState,
2471 IDirect3DDevice8Impl_SetTextureStageState,
2472 IDirect3DDevice8Impl_ValidateDevice,
2473 IDirect3DDevice8Impl_GetInfo,
2474 IDirect3DDevice8Impl_SetPaletteEntries,
2475 IDirect3DDevice8Impl_GetPaletteEntries,
2476 IDirect3DDevice8Impl_SetCurrentTexturePalette,
2477 IDirect3DDevice8Impl_GetCurrentTexturePalette,
2478 IDirect3DDevice8Impl_DrawPrimitive,
2479 IDirect3DDevice8Impl_DrawIndexedPrimitive,
2480 IDirect3DDevice8Impl_DrawPrimitiveUP,
2481 IDirect3DDevice8Impl_DrawIndexedPrimitiveUP,
2482 IDirect3DDevice8Impl_ProcessVertices,
2483 IDirect3DDevice8Impl_CreateVertexShader,
2484 IDirect3DDevice8Impl_SetVertexShader,
2485 IDirect3DDevice8Impl_GetVertexShader,
2486 IDirect3DDevice8Impl_DeleteVertexShader,
2487 IDirect3DDevice8Impl_SetVertexShaderConstant,
2488 IDirect3DDevice8Impl_GetVertexShaderConstant,
2489 IDirect3DDevice8Impl_GetVertexShaderDeclaration,
2490 IDirect3DDevice8Impl_GetVertexShaderFunction,
2491 IDirect3DDevice8Impl_SetStreamSource,
2492 IDirect3DDevice8Impl_GetStreamSource,
2493 IDirect3DDevice8Impl_SetIndices,
2494 IDirect3DDevice8Impl_GetIndices,
2495 IDirect3DDevice8Impl_CreatePixelShader,
2496 IDirect3DDevice8Impl_SetPixelShader,
2497 IDirect3DDevice8Impl_GetPixelShader,
2498 IDirect3DDevice8Impl_DeletePixelShader,
2499 IDirect3DDevice8Impl_SetPixelShaderConstant,
2500 IDirect3DDevice8Impl_GetPixelShaderConstant,
2501 IDirect3DDevice8Impl_GetPixelShaderFunction,
2502 IDirect3DDevice8Impl_DrawRectPatch,
2503 IDirect3DDevice8Impl_DrawTriPatch,
2504 IDirect3DDevice8Impl_DeletePatch
2507 ULONG WINAPI D3D8CB_DestroySurface(IWineD3DSurface *pSurface) {
2508 IDirect3DSurface8Impl* surfaceParent;
2509 TRACE("(%p) call back\n", pSurface);
2511 IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
2512 /* GetParent's AddRef was forwarded to an object in destruction.
2513 * Releasing it here again would cause an endless recursion. */
2514 surfaceParent->forwardReference = NULL;
2515 return IDirect3DSurface8_Release((IDirect3DSurface8*) surfaceParent);
2518 /* IWineD3DDeviceParent IUnknown methods */
2520 static inline struct IDirect3DDevice8Impl *device_from_device_parent(IWineD3DDeviceParent *iface)
2522 return (struct IDirect3DDevice8Impl *)((char*)iface
2523 - FIELD_OFFSET(struct IDirect3DDevice8Impl, device_parent_vtbl));
2526 static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface, REFIID riid, void **object)
2528 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2529 return IDirect3DDevice8Impl_QueryInterface((IDirect3DDevice8 *)This, riid, object);
2532 static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
2534 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2535 return IDirect3DDevice8Impl_AddRef((IDirect3DDevice8 *)This);
2538 static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
2540 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2541 return IDirect3DDevice8Impl_Release((IDirect3DDevice8 *)This);
2544 /* IWineD3DDeviceParent methods */
2546 static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
2548 TRACE("iface %p, device %p\n", iface, device);
2551 static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
2552 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, DWORD usage,
2553 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface)
2555 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2556 IDirect3DSurface8Impl *d3d_surface;
2557 BOOL lockable = TRUE;
2560 TRACE("iface %p, superior %p, width %u, height %u, format %#x, usage %#x,\n"
2561 "\tpool %#x, level %u, face %u, surface %p\n",
2562 iface, superior, width, height, format, usage, pool, level, face, surface);
2565 if (pool == WINED3DPOOL_DEFAULT && !(usage & WINED3DUSAGE_DYNAMIC)) lockable = FALSE;
2567 hr = IDirect3DDevice8Impl_CreateSurface((IDirect3DDevice8 *)This, width, height,
2568 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
2569 (IDirect3DSurface8 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
2572 ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
2576 *surface = d3d_surface->wineD3DSurface;
2577 d3d_surface->container = superior;
2578 IUnknown_Release(d3d_surface->parentDevice);
2579 d3d_surface->parentDevice = NULL;
2580 d3d_surface->forwardReference = superior;
2585 static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
2586 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2587 DWORD multisample_quality, BOOL lockable, IWineD3DSurface **surface)
2589 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2590 IDirect3DSurface8Impl *d3d_surface;
2593 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2594 "\tmultisample_quality %u, lockable %u, surface %p\n",
2595 iface, superior, width, height, format, multisample_type, multisample_quality, lockable, surface);
2597 hr = IDirect3DDevice8_CreateRenderTarget((IDirect3DDevice8 *)This, width, height,
2598 d3dformat_from_wined3dformat(format), multisample_type, lockable, (IDirect3DSurface8 **)&d3d_surface);
2601 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
2605 *surface = d3d_surface->wineD3DSurface;
2606 d3d_surface->container = (IUnknown *)This;
2607 d3d_surface->isImplicit = TRUE;
2608 /* Implicit surfaces are created with an refcount of 0 */
2609 IUnknown_Release((IUnknown *)d3d_surface);
2614 static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
2615 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2616 DWORD multisample_quality, BOOL discard, IWineD3DSurface **surface)
2618 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2619 IDirect3DSurface8Impl *d3d_surface;
2622 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2623 "\tmultisample_quality %u, discard %u, surface %p\n",
2624 iface, superior, width, height, format, multisample_type, multisample_quality, discard, surface);
2626 hr = IDirect3DDevice8_CreateDepthStencilSurface((IDirect3DDevice8 *)This, width, height,
2627 d3dformat_from_wined3dformat(format), multisample_type, (IDirect3DSurface8 **)&d3d_surface);
2630 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
2634 *surface = d3d_surface->wineD3DSurface;
2635 d3d_surface->container = (IUnknown *)This;
2636 d3d_surface->isImplicit = TRUE;
2637 /* Implicit surfaces are created with an refcount of 0 */
2638 IUnknown_Release((IUnknown *)d3d_surface);
2643 static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
2644 IUnknown *superior, UINT width, UINT height, UINT depth, WINED3DFORMAT format,
2645 WINED3DPOOL pool, DWORD usage, IWineD3DVolume **volume)
2647 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2648 IDirect3DVolume8Impl *object;
2651 TRACE("iface %p, superior %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
2652 iface, superior, width, height, depth, format, pool, usage, volume);
2654 /* Allocate the storage for the device */
2655 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2658 FIXME("Allocation of memory failed\n");
2660 return D3DERR_OUTOFVIDEOMEMORY;
2663 object->lpVtbl = &Direct3DVolume8_Vtbl;
2665 hr = IWineD3DDevice_CreateVolume(This->WineD3DDevice, width, height, depth, usage,
2666 format, pool, &object->wineD3DVolume, (IUnknown *)object);
2669 ERR("(%p) CreateVolume failed, returning %#x\n", iface, hr);
2670 HeapFree(GetProcessHeap(), 0, object);
2675 *volume = object->wineD3DVolume;
2676 object->container = superior;
2677 object->forwardReference = superior;
2679 TRACE("(%p) Created volume %p\n", iface, *volume);
2684 static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
2685 WINED3DPRESENT_PARAMETERS *present_parameters, IWineD3DSwapChain **swapchain)
2687 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2688 IDirect3DSwapChain8Impl *d3d_swapchain;
2689 D3DPRESENT_PARAMETERS local_parameters;
2692 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
2694 /* Copy the presentation parameters */
2695 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
2696 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
2697 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
2698 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
2699 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
2700 local_parameters.SwapEffect = present_parameters->SwapEffect;
2701 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
2702 local_parameters.Windowed = present_parameters->Windowed;
2703 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
2704 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
2705 local_parameters.Flags = present_parameters->Flags;
2706 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
2707 local_parameters.FullScreen_PresentationInterval = present_parameters->PresentationInterval;
2709 hr = IDirect3DDevice8_CreateAdditionalSwapChain((IDirect3DDevice8 *)This,
2710 &local_parameters, (IDirect3DSwapChain8 **)&d3d_swapchain);
2713 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
2718 *swapchain = d3d_swapchain->wineD3DSwapChain;
2719 IUnknown_Release(d3d_swapchain->parentDevice);
2720 d3d_swapchain->parentDevice = NULL;
2722 /* Copy back the presentation parameters */
2723 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
2724 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
2725 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
2726 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
2727 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
2728 present_parameters->SwapEffect = local_parameters.SwapEffect;
2729 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
2730 present_parameters->Windowed = local_parameters.Windowed;
2731 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
2732 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
2733 present_parameters->Flags = local_parameters.Flags;
2734 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
2735 present_parameters->PresentationInterval = local_parameters.FullScreen_PresentationInterval;
2740 const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl =
2742 /* IUnknown methods */
2743 device_parent_QueryInterface,
2744 device_parent_AddRef,
2745 device_parent_Release,
2746 /* IWineD3DDeviceParent methods */
2747 device_parent_WineD3DDeviceCreated,
2748 device_parent_CreateSurface,
2749 device_parent_CreateRenderTarget,
2750 device_parent_CreateDepthStencilSurface,
2751 device_parent_CreateVolume,
2752 device_parent_CreateSwapChain,