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);
363 TRACE("Returning %p %p\n", This, pCaps);
367 static HRESULT WINAPI IDirect3DDevice8Impl_GetDisplayMode(LPDIRECT3DDEVICE8 iface, D3DDISPLAYMODE* pMode) {
368 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
370 TRACE("(%p) Relay\n", This);
372 EnterCriticalSection(&d3d8_cs);
373 hr = IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, 0, (WINED3DDISPLAYMODE *) pMode);
374 LeaveCriticalSection(&d3d8_cs);
376 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
381 static HRESULT WINAPI IDirect3DDevice8Impl_GetCreationParameters(LPDIRECT3DDEVICE8 iface, D3DDEVICE_CREATION_PARAMETERS *pParameters) {
382 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
384 TRACE("(%p) Relay\n", This);
386 EnterCriticalSection(&d3d8_cs);
387 hr = IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
388 LeaveCriticalSection(&d3d8_cs);
392 static HRESULT WINAPI IDirect3DDevice8Impl_SetCursorProperties(LPDIRECT3DDEVICE8 iface, UINT XHotSpot, UINT YHotSpot, IDirect3DSurface8* pCursorBitmap) {
393 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
394 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl*)pCursorBitmap;
396 TRACE("(%p) Relay\n", This);
398 WARN("No cursor bitmap, returning WINED3DERR_INVALIDCALL\n");
399 return WINED3DERR_INVALIDCALL;
402 EnterCriticalSection(&d3d8_cs);
403 hr = IWineD3DDevice_SetCursorProperties(This->WineD3DDevice,XHotSpot,YHotSpot,pSurface->wineD3DSurface);
404 LeaveCriticalSection(&d3d8_cs);
408 static void WINAPI IDirect3DDevice8Impl_SetCursorPosition(LPDIRECT3DDEVICE8 iface, UINT XScreenSpace, UINT YScreenSpace, DWORD Flags) {
409 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
410 TRACE("(%p) Relay\n", This);
412 EnterCriticalSection(&d3d8_cs);
413 IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
414 LeaveCriticalSection(&d3d8_cs);
417 static BOOL WINAPI IDirect3DDevice8Impl_ShowCursor(LPDIRECT3DDEVICE8 iface, BOOL bShow) {
418 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
420 TRACE("(%p) Relay\n", This);
422 EnterCriticalSection(&d3d8_cs);
423 ret = IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
424 LeaveCriticalSection(&d3d8_cs);
428 static HRESULT WINAPI IDirect3DDevice8Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain8** pSwapChain) {
429 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
430 IDirect3DSwapChain8Impl* object;
431 HRESULT hrc = D3D_OK;
432 WINED3DPRESENT_PARAMETERS localParameters;
434 TRACE("(%p) Relay\n", This);
436 /* Fix the back buffer count */
437 if(pPresentationParameters->BackBufferCount == 0) {
438 pPresentationParameters->BackBufferCount = 1;
441 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
442 if (NULL == object) {
443 FIXME("Allocation of memory failed\n");
445 return D3DERR_OUTOFVIDEOMEMORY;
448 object->lpVtbl = &Direct3DSwapChain8_Vtbl;
450 /* Allocate an associated WineD3DDevice object */
451 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
452 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
453 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
454 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
455 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
456 localParameters.MultiSampleQuality = 0; /* d3d9 only */
457 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
458 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
459 localParameters.Windowed = pPresentationParameters->Windowed;
460 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
461 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
462 localParameters.Flags = pPresentationParameters->Flags;
463 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
464 localParameters.PresentationInterval = pPresentationParameters->FullScreen_PresentationInterval;
465 localParameters.AutoRestoreDisplayMode = TRUE;
467 EnterCriticalSection(&d3d8_cs);
468 hrc = IWineD3DDevice_CreateSwapChain(This->WineD3DDevice, &localParameters,
469 &object->wineD3DSwapChain, (IUnknown *)object, SURFACE_OPENGL);
470 LeaveCriticalSection(&d3d8_cs);
472 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
473 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
474 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
475 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
476 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
477 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
478 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
479 pPresentationParameters->Windowed = localParameters.Windowed;
480 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
481 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
482 pPresentationParameters->Flags = localParameters.Flags;
483 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
484 pPresentationParameters->FullScreen_PresentationInterval = localParameters.PresentationInterval;
487 FIXME("(%p) call to IWineD3DDevice_CreateSwapChain failed\n", This);
488 HeapFree(GetProcessHeap(), 0 , object);
491 IUnknown_AddRef(iface);
492 object->parentDevice = iface;
493 *pSwapChain = (IDirect3DSwapChain8 *)object;
495 TRACE("(%p) returning %p\n", This, *pSwapChain);
499 static HRESULT WINAPI IDirect3DDevice8Impl_Reset(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
500 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
501 WINED3DPRESENT_PARAMETERS localParameters;
504 TRACE("(%p) Relay pPresentationParameters(%p)\n", This, pPresentationParameters);
506 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
507 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
508 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
509 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
510 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
511 localParameters.MultiSampleQuality = 0; /* d3d9 only */
512 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
513 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
514 localParameters.Windowed = pPresentationParameters->Windowed;
515 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
516 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
517 localParameters.Flags = pPresentationParameters->Flags;
518 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
519 localParameters.PresentationInterval = pPresentationParameters->FullScreen_PresentationInterval;
520 localParameters.AutoRestoreDisplayMode = TRUE;
522 EnterCriticalSection(&d3d8_cs);
523 hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
524 LeaveCriticalSection(&d3d8_cs);
526 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
527 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
528 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
529 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
530 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
531 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
532 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
533 pPresentationParameters->Windowed = localParameters.Windowed;
534 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
535 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
536 pPresentationParameters->Flags = localParameters.Flags;
537 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
538 pPresentationParameters->FullScreen_PresentationInterval = localParameters.PresentationInterval;
543 static HRESULT WINAPI IDirect3DDevice8Impl_Present(LPDIRECT3DDEVICE8 iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion) {
544 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
546 TRACE("(%p) Relay\n", This);
548 EnterCriticalSection(&d3d8_cs);
549 hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
550 LeaveCriticalSection(&d3d8_cs);
554 static HRESULT WINAPI IDirect3DDevice8Impl_GetBackBuffer(LPDIRECT3DDEVICE8 iface, UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8** ppBackBuffer) {
555 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
556 IWineD3DSurface *retSurface = NULL;
559 TRACE("(%p) Relay\n", This);
561 EnterCriticalSection(&d3d8_cs);
562 rc = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, 0, BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &retSurface);
563 if (rc == D3D_OK && NULL != retSurface && NULL != ppBackBuffer) {
564 IWineD3DSurface_GetParent(retSurface, (IUnknown **)ppBackBuffer);
565 IWineD3DSurface_Release(retSurface);
567 LeaveCriticalSection(&d3d8_cs);
571 static HRESULT WINAPI IDirect3DDevice8Impl_GetRasterStatus(LPDIRECT3DDEVICE8 iface, D3DRASTER_STATUS* pRasterStatus) {
572 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
574 TRACE("(%p) Relay\n", This);
576 EnterCriticalSection(&d3d8_cs);
577 hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, 0, (WINED3DRASTER_STATUS *) pRasterStatus);
578 LeaveCriticalSection(&d3d8_cs);
582 static void WINAPI IDirect3DDevice8Impl_SetGammaRamp(LPDIRECT3DDEVICE8 iface, DWORD Flags, CONST D3DGAMMARAMP* pRamp) {
583 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
584 TRACE("(%p) Relay\n", This);
586 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
587 EnterCriticalSection(&d3d8_cs);
588 IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, 0, Flags, (CONST WINED3DGAMMARAMP *) pRamp);
589 LeaveCriticalSection(&d3d8_cs);
592 static void WINAPI IDirect3DDevice8Impl_GetGammaRamp(LPDIRECT3DDEVICE8 iface, D3DGAMMARAMP* pRamp) {
593 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
594 TRACE("(%p) Relay\n", This);
596 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
597 EnterCriticalSection(&d3d8_cs);
598 IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, 0, (WINED3DGAMMARAMP *) pRamp);
599 LeaveCriticalSection(&d3d8_cs);
602 static HRESULT WINAPI IDirect3DDevice8Impl_CreateTexture(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, UINT Levels, DWORD Usage,
603 D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture8 **ppTexture) {
604 IDirect3DTexture8Impl *object;
605 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
606 HRESULT hrc = D3D_OK;
608 TRACE("(%p) : W(%d) H(%d), Lvl(%d) d(%d), Fmt(%u), Pool(%d)\n", This, Width, Height, Levels, Usage, Format, Pool);
610 /* Allocate the storage for the device */
611 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DTexture8Impl));
613 if (NULL == object) {
614 FIXME("Allocation of memory failed\n");
615 /* *ppTexture = NULL; */
616 return D3DERR_OUTOFVIDEOMEMORY;
619 object->lpVtbl = &Direct3DTexture8_Vtbl;
621 EnterCriticalSection(&d3d8_cs);
622 hrc = IWineD3DDevice_CreateTexture(This->WineD3DDevice, Width, Height, Levels, Usage & WINED3DUSAGE_MASK,
623 wined3dformat_from_d3dformat(Format), Pool, &object->wineD3DTexture, (IUnknown *)object);
624 LeaveCriticalSection(&d3d8_cs);
628 FIXME("(%p) call to IWineD3DDevice_CreateTexture failed\n", This);
629 HeapFree(GetProcessHeap(), 0, object);
630 /* *ppTexture = NULL; */
632 IUnknown_AddRef(iface);
633 object->parentDevice = iface;
634 *ppTexture = (LPDIRECT3DTEXTURE8) object;
635 TRACE("(%p) Created Texture %p, %p\n",This,object,object->wineD3DTexture);
641 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVolumeTexture(LPDIRECT3DDEVICE8 iface,
642 UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage,
643 D3DFORMAT Format, D3DPOOL Pool, IDirect3DVolumeTexture8** ppVolumeTexture) {
645 IDirect3DVolumeTexture8Impl *object;
646 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
647 HRESULT hrc = D3D_OK;
649 TRACE("(%p) Relay\n", This);
651 /* Allocate the storage for the device */
652 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVolumeTexture8Impl));
653 if (NULL == object) {
654 FIXME("(%p) allocation of memory failed\n", This);
655 *ppVolumeTexture = NULL;
656 return D3DERR_OUTOFVIDEOMEMORY;
659 object->lpVtbl = &Direct3DVolumeTexture8_Vtbl;
661 EnterCriticalSection(&d3d8_cs);
662 hrc = IWineD3DDevice_CreateVolumeTexture(This->WineD3DDevice, Width, Height, Depth, Levels,
663 Usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(Format),
664 Pool, &object->wineD3DVolumeTexture, (IUnknown *)object);
665 LeaveCriticalSection(&d3d8_cs);
670 FIXME("(%p) call to IWineD3DDevice_CreateVolumeTexture failed\n", This);
671 HeapFree(GetProcessHeap(), 0, object);
672 *ppVolumeTexture = NULL;
674 IUnknown_AddRef(iface);
675 object->parentDevice = iface;
676 *ppVolumeTexture = (LPDIRECT3DVOLUMETEXTURE8) object;
678 TRACE("(%p) returning %p\n", This , *ppVolumeTexture);
682 static HRESULT WINAPI IDirect3DDevice8Impl_CreateCubeTexture(LPDIRECT3DDEVICE8 iface, UINT EdgeLength, UINT Levels, DWORD Usage,
683 D3DFORMAT Format, D3DPOOL Pool, IDirect3DCubeTexture8** ppCubeTexture) {
685 IDirect3DCubeTexture8Impl *object;
686 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
689 TRACE("(%p) : ELen(%d) Lvl(%d) Usage(%d) fmt(%u), Pool(%d)\n" , This, EdgeLength, Levels, Usage, Format, Pool);
691 /* Allocate the storage for the device */
692 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
694 if (NULL == object) {
695 FIXME("(%p) allocation of CubeTexture failed\n", This);
696 *ppCubeTexture = NULL;
697 return D3DERR_OUTOFVIDEOMEMORY;
700 object->lpVtbl = &Direct3DCubeTexture8_Vtbl;
702 EnterCriticalSection(&d3d8_cs);
703 hr = IWineD3DDevice_CreateCubeTexture(This->WineD3DDevice, EdgeLength, Levels, Usage & WINED3DUSAGE_MASK,
704 wined3dformat_from_d3dformat(Format), Pool, &object->wineD3DCubeTexture, (IUnknown *)object);
705 LeaveCriticalSection(&d3d8_cs);
710 FIXME("(%p) call to IWineD3DDevice_CreateCubeTexture failed\n", This);
711 HeapFree(GetProcessHeap(), 0, object);
712 *ppCubeTexture = NULL;
714 IUnknown_AddRef(iface);
715 object->parentDevice = iface;
716 *ppCubeTexture = (LPDIRECT3DCUBETEXTURE8) object;
719 TRACE("(%p) returning %p\n",This, *ppCubeTexture);
723 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexBuffer(LPDIRECT3DDEVICE8 iface, UINT Size, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer8** ppVertexBuffer) {
724 IDirect3DVertexBuffer8Impl *object;
725 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
726 HRESULT hrc = D3D_OK;
728 TRACE("(%p) Relay\n", This);
729 /* Allocate the storage for the device */
730 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexBuffer8Impl));
731 if (NULL == object) {
732 FIXME("Allocation of memory failed\n");
733 *ppVertexBuffer = NULL;
734 return D3DERR_OUTOFVIDEOMEMORY;
737 object->lpVtbl = &Direct3DVertexBuffer8_Vtbl;
739 EnterCriticalSection(&d3d8_cs);
740 hrc = IWineD3DDevice_CreateVertexBuffer(This->WineD3DDevice, Size, Usage & WINED3DUSAGE_MASK,
741 0 /* fvf for ddraw only */, (WINED3DPOOL)Pool, &object->wineD3DVertexBuffer, (IUnknown *)object);
742 LeaveCriticalSection(&d3d8_cs);
748 FIXME("(%p) call to IWineD3DDevice_CreateVertexBuffer failed\n", This);
749 HeapFree(GetProcessHeap(), 0, object);
750 *ppVertexBuffer = NULL;
752 IUnknown_AddRef(iface);
753 object->parentDevice = iface;
754 *ppVertexBuffer = (LPDIRECT3DVERTEXBUFFER8) object;
759 static HRESULT WINAPI IDirect3DDevice8Impl_CreateIndexBuffer(LPDIRECT3DDEVICE8 iface, UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DIndexBuffer8** ppIndexBuffer) {
760 IDirect3DIndexBuffer8Impl *object;
761 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
762 HRESULT hrc = D3D_OK;
764 TRACE("(%p) Relay\n", This);
765 /* Allocate the storage for the device */
766 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
767 if (NULL == object) {
768 FIXME("Allocation of memory failed\n");
769 *ppIndexBuffer = NULL;
770 return D3DERR_OUTOFVIDEOMEMORY;
773 object->lpVtbl = &Direct3DIndexBuffer8_Vtbl;
775 object->format = wined3dformat_from_d3dformat(Format);
776 TRACE("Calling wined3d create index buffer\n");
777 EnterCriticalSection(&d3d8_cs);
778 hrc = IWineD3DDevice_CreateIndexBuffer(This->WineD3DDevice, Length, Usage & WINED3DUSAGE_MASK,
779 (WINED3DPOOL)Pool, &object->wineD3DIndexBuffer, (IUnknown *)object);
780 LeaveCriticalSection(&d3d8_cs);
785 FIXME("(%p) call to IWineD3DDevice_CreateIndexBuffer failed\n", This);
786 HeapFree(GetProcessHeap(), 0, object);
787 *ppIndexBuffer = NULL;
789 IUnknown_AddRef(iface);
790 object->parentDevice = iface;
791 *ppIndexBuffer = (LPDIRECT3DINDEXBUFFER8)object;
796 static HRESULT IDirect3DDevice8Impl_CreateSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IDirect3DSurface8 **ppSurface,D3DRESOURCETYPE Type, UINT Usage,D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality) {
798 IDirect3DSurface8Impl *object;
799 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
800 TRACE("(%p) Relay\n", This);
802 if(MultisampleQuality > 0){
803 FIXME("MultisampleQuality set to %d, substituting 0\n" , MultisampleQuality);
806 [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.
808 MultisampleQuality=0;
810 /*FIXME: Check MAX bounds of MultisampleQuality*/
812 /* Allocate the storage for the device */
813 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface8Impl));
814 if (NULL == object) {
815 FIXME("Allocation of memory failed\n");
817 return D3DERR_OUTOFVIDEOMEMORY;
820 object->lpVtbl = &Direct3DSurface8_Vtbl;
823 TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
825 EnterCriticalSection(&d3d8_cs);
826 hrc = IWineD3DDevice_CreateSurface(This->WineD3DDevice, Width, Height, wined3dformat_from_d3dformat(Format),
827 Lockable, Discard, Level, &object->wineD3DSurface, Type, Usage & WINED3DUSAGE_MASK,
828 (WINED3DPOOL)Pool, MultiSample, MultisampleQuality, SURFACE_OPENGL, (IUnknown *)object);
829 LeaveCriticalSection(&d3d8_cs);
830 if (hrc != D3D_OK || NULL == object->wineD3DSurface) {
832 FIXME("(%p) call to IWineD3DDevice_CreateSurface failed\n", This);
833 HeapFree(GetProcessHeap(), 0, object);
836 IUnknown_AddRef(iface);
837 object->parentDevice = iface;
838 *ppSurface = (LPDIRECT3DSURFACE8) object;
843 static HRESULT WINAPI IDirect3DDevice8Impl_CreateRenderTarget(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, BOOL Lockable, IDirect3DSurface8** ppSurface) {
847 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, Lockable, FALSE /* Discard */, 0 /* Level */ , ppSurface, D3DRTYPE_SURFACE, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, MultiSample, 0);
851 static HRESULT WINAPI IDirect3DDevice8Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, IDirect3DSurface8** ppSurface) {
855 /* TODO: Verify that Discard is false */
856 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE, 0 /* Level */
857 ,ppSurface, D3DRTYPE_SURFACE, D3DUSAGE_DEPTHSTENCIL,
858 D3DPOOL_DEFAULT, MultiSample, 0);
862 /* IDirect3DDevice8Impl::CreateImageSurface returns surface with pool type SYSTEMMEM */
863 static HRESULT WINAPI IDirect3DDevice8Impl_CreateImageSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, IDirect3DSurface8** ppSurface) {
867 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Loackable */ , FALSE /*Discard*/ , 0 /* Level */ , ppSurface,
868 D3DRTYPE_SURFACE, 0 /* Usage (undefined/none) */ , D3DPOOL_SYSTEMMEM, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
872 static HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8 *pSourceSurface, CONST RECT *pSourceRects, UINT cRects, IDirect3DSurface8 *pDestinationSurface, CONST POINT *pDestPoints) {
873 IDirect3DSurface8Impl *Source = (IDirect3DSurface8Impl *) pSourceSurface;
874 IDirect3DSurface8Impl *Dest = (IDirect3DSurface8Impl *) pDestinationSurface;
876 HRESULT hr = WINED3D_OK;
877 WINED3DFORMAT srcFormat, destFormat;
878 UINT srcWidth, destWidth;
879 UINT srcHeight, destHeight;
881 WINED3DSURFACE_DESC winedesc;
883 TRACE("(%p) pSrcSur=%p, pSourceRects=%p, cRects=%d, pDstSur=%p, pDestPtsArr=%p\n", iface,
884 pSourceSurface, pSourceRects, cRects, pDestinationSurface, pDestPoints);
887 /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the destination texture is in WINED3DPOOL_DEFAULT */
888 memset(&winedesc, 0, sizeof(winedesc));
890 winedesc.Format = &srcFormat;
891 winedesc.Width = &srcWidth;
892 winedesc.Height = &srcHeight;
893 winedesc.Size = &srcSize;
894 EnterCriticalSection(&d3d8_cs);
895 IWineD3DSurface_GetDesc(Source->wineD3DSurface, &winedesc);
897 winedesc.Format = &destFormat;
898 winedesc.Width = &destWidth;
899 winedesc.Height = &destHeight;
900 winedesc.Size = NULL;
901 IWineD3DSurface_GetDesc(Dest->wineD3DSurface, &winedesc);
903 /* Check that the source and destination formats match */
904 if (srcFormat != destFormat && WINED3DFMT_UNKNOWN != destFormat) {
905 WARN("(%p) source %p format must match the dest %p format, returning WINED3DERR_INVALIDCALL\n", iface, pSourceSurface, pDestinationSurface);
906 LeaveCriticalSection(&d3d8_cs);
907 return WINED3DERR_INVALIDCALL;
908 } else if (WINED3DFMT_UNKNOWN == destFormat) {
909 TRACE("(%p) : Converting destination surface from WINED3DFMT_UNKNOWN to the source format\n", iface);
910 IWineD3DSurface_SetFormat(Dest->wineD3DSurface, srcFormat);
911 destFormat = srcFormat;
914 /* Quick if complete copy ... */
915 if (cRects == 0 && pSourceRects == NULL && pDestPoints == NULL) {
916 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
919 /* Copy rect by rect */
920 if (NULL != pSourceRects && NULL != pDestPoints) {
921 for (i = 0; i < cRects; ++i) {
922 IWineD3DSurface_BltFast(Dest->wineD3DSurface, pDestPoints[i].x, pDestPoints[i].y, Source->wineD3DSurface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
925 for (i = 0; i < cRects; ++i) {
926 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
930 LeaveCriticalSection(&d3d8_cs);
935 static HRESULT WINAPI IDirect3DDevice8Impl_UpdateTexture(LPDIRECT3DDEVICE8 iface, IDirect3DBaseTexture8* pSourceTexture, IDirect3DBaseTexture8* pDestinationTexture) {
936 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
938 TRACE("(%p) Relay\n" , This);
940 EnterCriticalSection(&d3d8_cs);
941 hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice, ((IDirect3DBaseTexture8Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture8Impl *)pDestinationTexture)->wineD3DBaseTexture);
942 LeaveCriticalSection(&d3d8_cs);
946 static HRESULT WINAPI IDirect3DDevice8Impl_GetFrontBuffer(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pDestSurface) {
947 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
948 IDirect3DSurface8Impl *destSurface = (IDirect3DSurface8Impl *)pDestSurface;
951 TRACE("(%p) Relay\n" , This);
953 if (pDestSurface == NULL) {
954 WARN("(%p) : Caller passed NULL as pDestSurface returning D3DERR_INVALIDCALL\n", This);
955 return D3DERR_INVALIDCALL;
958 EnterCriticalSection(&d3d8_cs);
959 hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, 0, destSurface->wineD3DSurface);
960 LeaveCriticalSection(&d3d8_cs);
964 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pRenderTarget, IDirect3DSurface8* pNewZStencil) {
965 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
966 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl *)pRenderTarget;
967 IDirect3DSurface8Impl *pZSurface = (IDirect3DSurface8Impl *)pNewZStencil;
968 IWineD3DSurface *original_ds = NULL;
970 TRACE("(%p) Relay\n" , This);
972 EnterCriticalSection(&d3d8_cs);
974 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice, &original_ds);
975 if (hr == WINED3D_OK || hr == WINED3DERR_NOTFOUND)
977 hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, pZSurface ? pZSurface->wineD3DSurface : NULL);
978 if (SUCCEEDED(hr) && pSurface)
979 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, 0, pSurface->wineD3DSurface);
980 if (FAILED(hr)) IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, original_ds);
982 if (original_ds) IWineD3DSurface_Release(original_ds);
984 LeaveCriticalSection(&d3d8_cs);
988 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppRenderTarget) {
989 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
991 IWineD3DSurface *pRenderTarget;
993 TRACE("(%p) Relay\n" , This);
995 if (ppRenderTarget == NULL) {
996 return D3DERR_INVALIDCALL;
998 EnterCriticalSection(&d3d8_cs);
999 hr = IWineD3DDevice_GetRenderTarget(This->WineD3DDevice, 0, &pRenderTarget);
1001 if (hr == D3D_OK && pRenderTarget != NULL) {
1002 IWineD3DSurface_GetParent(pRenderTarget,(IUnknown**)ppRenderTarget);
1003 IWineD3DSurface_Release(pRenderTarget);
1005 FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
1006 *ppRenderTarget = NULL;
1008 LeaveCriticalSection(&d3d8_cs);
1013 static HRESULT WINAPI IDirect3DDevice8Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppZStencilSurface) {
1014 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1015 HRESULT hr = D3D_OK;
1016 IWineD3DSurface *pZStencilSurface;
1018 TRACE("(%p) Relay\n" , This);
1019 if(ppZStencilSurface == NULL){
1020 return D3DERR_INVALIDCALL;
1023 EnterCriticalSection(&d3d8_cs);
1024 hr=IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
1025 if (hr == WINED3D_OK) {
1026 IWineD3DSurface_GetParent(pZStencilSurface,(IUnknown**)ppZStencilSurface);
1027 IWineD3DSurface_Release(pZStencilSurface);
1029 if (hr != WINED3DERR_NOTFOUND)
1030 FIXME("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
1031 *ppZStencilSurface = NULL;
1033 LeaveCriticalSection(&d3d8_cs);
1038 static HRESULT WINAPI IDirect3DDevice8Impl_BeginScene(LPDIRECT3DDEVICE8 iface) {
1039 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1041 TRACE("(%p) Relay\n" , This);
1043 EnterCriticalSection(&d3d8_cs);
1044 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
1045 LeaveCriticalSection(&d3d8_cs);
1049 static HRESULT WINAPI IDirect3DDevice8Impl_EndScene(LPDIRECT3DDEVICE8 iface) {
1050 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1052 TRACE("(%p) Relay\n" , This);
1054 EnterCriticalSection(&d3d8_cs);
1055 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
1056 LeaveCriticalSection(&d3d8_cs);
1060 static HRESULT WINAPI IDirect3DDevice8Impl_Clear(LPDIRECT3DDEVICE8 iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
1061 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1063 TRACE("(%p) Relay\n" , This);
1065 /* Note: D3DRECT is compatible with WINED3DRECT */
1066 EnterCriticalSection(&d3d8_cs);
1067 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (CONST WINED3DRECT*) pRects, Flags, Color, Z, Stencil);
1068 LeaveCriticalSection(&d3d8_cs);
1072 static HRESULT WINAPI IDirect3DDevice8Impl_SetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
1073 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1075 TRACE("(%p) Relay\n" , This);
1077 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1078 EnterCriticalSection(&d3d8_cs);
1079 hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
1080 LeaveCriticalSection(&d3d8_cs);
1084 static HRESULT WINAPI IDirect3DDevice8Impl_GetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State,D3DMATRIX* pMatrix) {
1085 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1087 TRACE("(%p) Relay\n" , This);
1089 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1090 EnterCriticalSection(&d3d8_cs);
1091 hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
1092 LeaveCriticalSection(&d3d8_cs);
1096 static HRESULT WINAPI IDirect3DDevice8Impl_MultiplyTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
1097 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1099 TRACE("(%p) Relay\n" , This);
1101 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1102 EnterCriticalSection(&d3d8_cs);
1103 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
1104 LeaveCriticalSection(&d3d8_cs);
1108 static HRESULT WINAPI IDirect3DDevice8Impl_SetViewport(LPDIRECT3DDEVICE8 iface, CONST D3DVIEWPORT8* pViewport) {
1109 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1111 TRACE("(%p) Relay\n" , This);
1113 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1114 EnterCriticalSection(&d3d8_cs);
1115 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
1116 LeaveCriticalSection(&d3d8_cs);
1120 static HRESULT WINAPI IDirect3DDevice8Impl_GetViewport(LPDIRECT3DDEVICE8 iface, D3DVIEWPORT8* pViewport) {
1121 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1123 TRACE("(%p) Relay\n" , This);
1125 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1126 EnterCriticalSection(&d3d8_cs);
1127 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
1128 LeaveCriticalSection(&d3d8_cs);
1132 static HRESULT WINAPI IDirect3DDevice8Impl_SetMaterial(LPDIRECT3DDEVICE8 iface, CONST D3DMATERIAL8* pMaterial) {
1133 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1135 TRACE("(%p) Relay\n" , This);
1137 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1138 EnterCriticalSection(&d3d8_cs);
1139 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
1140 LeaveCriticalSection(&d3d8_cs);
1144 static HRESULT WINAPI IDirect3DDevice8Impl_GetMaterial(LPDIRECT3DDEVICE8 iface, D3DMATERIAL8* pMaterial) {
1145 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1147 TRACE("(%p) Relay\n" , This);
1149 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1150 EnterCriticalSection(&d3d8_cs);
1151 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
1152 LeaveCriticalSection(&d3d8_cs);
1156 static HRESULT WINAPI IDirect3DDevice8Impl_SetLight(LPDIRECT3DDEVICE8 iface, DWORD Index, CONST D3DLIGHT8* pLight) {
1157 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1159 TRACE("(%p) Relay\n" , This);
1161 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1162 EnterCriticalSection(&d3d8_cs);
1163 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
1164 LeaveCriticalSection(&d3d8_cs);
1168 static HRESULT WINAPI IDirect3DDevice8Impl_GetLight(LPDIRECT3DDEVICE8 iface, DWORD Index,D3DLIGHT8* pLight) {
1169 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1171 TRACE("(%p) Relay\n" , This);
1173 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1174 EnterCriticalSection(&d3d8_cs);
1175 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1176 LeaveCriticalSection(&d3d8_cs);
1180 static HRESULT WINAPI IDirect3DDevice8Impl_LightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL Enable) {
1181 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1183 TRACE("(%p) Relay\n" , This);
1185 EnterCriticalSection(&d3d8_cs);
1186 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1187 LeaveCriticalSection(&d3d8_cs);
1191 static HRESULT WINAPI IDirect3DDevice8Impl_GetLightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL* pEnable) {
1192 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1194 TRACE("(%p) Relay\n" , This);
1196 EnterCriticalSection(&d3d8_cs);
1197 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1198 LeaveCriticalSection(&d3d8_cs);
1202 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,CONST float* pPlane) {
1203 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1205 TRACE("(%p) Relay\n" , This);
1207 EnterCriticalSection(&d3d8_cs);
1208 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1209 LeaveCriticalSection(&d3d8_cs);
1213 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,float* pPlane) {
1214 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1216 TRACE("(%p) Relay\n" , This);
1218 EnterCriticalSection(&d3d8_cs);
1219 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1220 LeaveCriticalSection(&d3d8_cs);
1224 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD Value) {
1225 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1227 TRACE("(%p) Relay\n" , This);
1229 EnterCriticalSection(&d3d8_cs);
1230 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1231 LeaveCriticalSection(&d3d8_cs);
1235 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD* pValue) {
1236 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1238 TRACE("(%p) Relay\n" , This);
1240 EnterCriticalSection(&d3d8_cs);
1241 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1242 LeaveCriticalSection(&d3d8_cs);
1246 static HRESULT WINAPI IDirect3DDevice8Impl_BeginStateBlock(LPDIRECT3DDEVICE8 iface) {
1247 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1249 TRACE("(%p)\n", This);
1251 EnterCriticalSection(&d3d8_cs);
1252 hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
1253 LeaveCriticalSection(&d3d8_cs);
1257 static HRESULT WINAPI IDirect3DDevice8Impl_EndStateBlock(LPDIRECT3DDEVICE8 iface, DWORD* pToken) {
1258 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1260 IWineD3DStateBlock* wineD3DStateBlock;
1261 IDirect3DStateBlock8Impl* object;
1263 TRACE("(%p) Relay\n", This);
1265 /* Tell wineD3D to endstateblock before anything else (in case we run out
1266 * of memory later and cause locking problems)
1268 EnterCriticalSection(&d3d8_cs);
1269 hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice , &wineD3DStateBlock);
1271 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
1272 LeaveCriticalSection(&d3d8_cs);
1276 /* allocate a new IDirectD3DStateBlock */
1277 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY ,sizeof(IDirect3DStateBlock8Impl));
1279 object->lpVtbl = &Direct3DStateBlock8_Vtbl;
1281 object->wineD3DStateBlock = wineD3DStateBlock;
1283 *pToken = d3d8_allocate_handle(&This->handle_table, object);
1284 LeaveCriticalSection(&d3d8_cs);
1286 if (*pToken == D3D8_INVALID_HANDLE)
1288 ERR("Failed to create a handle\n");
1289 IDirect3DStateBlock8_Release((IDirect3DStateBlock8 *)object);
1294 TRACE("Returning %#x (%p).\n", *pToken, object);
1299 static HRESULT WINAPI IDirect3DDevice8Impl_ApplyStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1300 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1301 IDirect3DStateBlock8Impl *pSB;
1304 TRACE("(%p) %#x Relay\n", This, Token);
1306 EnterCriticalSection(&d3d8_cs);
1307 pSB = d3d8_get_object(&This->handle_table, Token - 1);
1310 WARN("Invalid handle (%#x) passed.\n", Token);
1311 LeaveCriticalSection(&d3d8_cs);
1312 return D3DERR_INVALIDCALL;
1314 hr = IWineD3DStateBlock_Apply(pSB->wineD3DStateBlock);
1315 LeaveCriticalSection(&d3d8_cs);
1319 static HRESULT WINAPI IDirect3DDevice8Impl_CaptureStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1320 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1321 IDirect3DStateBlock8Impl *pSB;
1324 TRACE("(%p) %#x Relay\n", This, Token);
1326 EnterCriticalSection(&d3d8_cs);
1327 pSB = d3d8_get_object(&This->handle_table, Token - 1);
1330 WARN("Invalid handle (%#x) passed.\n", Token);
1331 LeaveCriticalSection(&d3d8_cs);
1332 return D3DERR_INVALIDCALL;
1334 hr = IWineD3DStateBlock_Capture(pSB->wineD3DStateBlock);
1335 LeaveCriticalSection(&d3d8_cs);
1339 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1340 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1341 IDirect3DStateBlock8Impl *pSB;
1343 TRACE("(%p) Relay\n", This);
1345 EnterCriticalSection(&d3d8_cs);
1346 pSB = d3d8_free_handle(&This->handle_table, Token - 1);
1347 LeaveCriticalSection(&d3d8_cs);
1351 WARN("Invalid handle (%#x) passed.\n", Token);
1352 return D3DERR_INVALIDCALL;
1355 if (IUnknown_Release((IUnknown *)pSB))
1357 ERR("Stateblock %p has references left, this shouldn't happen.\n", pSB);
1363 static HRESULT WINAPI IDirect3DDevice8Impl_CreateStateBlock(IDirect3DDevice8 *iface,
1364 D3DSTATEBLOCKTYPE Type, DWORD *handle)
1366 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1367 IDirect3DStateBlock8Impl *object;
1370 TRACE("(%p) Relay\n", This);
1372 if (Type != D3DSBT_ALL
1373 && Type != D3DSBT_PIXELSTATE
1374 && Type != D3DSBT_VERTEXSTATE)
1376 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1377 return D3DERR_INVALIDCALL;
1380 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DStateBlock8Impl));
1383 ERR("Failed to allocate memory.\n");
1384 return E_OUTOFMEMORY;
1387 object->lpVtbl = &Direct3DStateBlock8_Vtbl;
1390 EnterCriticalSection(&d3d8_cs);
1391 hr = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type,
1392 &object->wineD3DStateBlock, (IUnknown *)object);
1395 LeaveCriticalSection(&d3d8_cs);
1396 ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr);
1397 HeapFree(GetProcessHeap(), 0, object);
1401 *handle = d3d8_allocate_handle(&This->handle_table, object);
1402 LeaveCriticalSection(&d3d8_cs);
1404 if (*handle == D3D8_INVALID_HANDLE)
1406 ERR("Failed to allocate a handle.\n");
1407 IDirect3DStateBlock8_Release((IDirect3DStateBlock8 *)object);
1412 TRACE("Returning %#x (%p).\n", *handle, object);
1417 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipStatus(LPDIRECT3DDEVICE8 iface, CONST D3DCLIPSTATUS8* pClipStatus) {
1418 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1420 TRACE("(%p) Relay\n" , This);
1421 /* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
1422 EnterCriticalSection(&d3d8_cs);
1423 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1424 LeaveCriticalSection(&d3d8_cs);
1428 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipStatus(LPDIRECT3DDEVICE8 iface, D3DCLIPSTATUS8* pClipStatus) {
1429 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1431 TRACE("(%p) Relay\n" , This);
1433 EnterCriticalSection(&d3d8_cs);
1434 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1435 LeaveCriticalSection(&d3d8_cs);
1439 static HRESULT WINAPI IDirect3DDevice8Impl_GetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage,IDirect3DBaseTexture8** ppTexture) {
1440 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1441 IWineD3DBaseTexture *retTexture = NULL;
1442 HRESULT rc = D3D_OK;
1444 TRACE("(%p) Relay\n" , This);
1446 if(ppTexture == NULL){
1447 return D3DERR_INVALIDCALL;
1450 EnterCriticalSection(&d3d8_cs);
1451 rc = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
1452 if (rc == D3D_OK && NULL != retTexture) {
1453 IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
1454 IWineD3DBaseTexture_Release(retTexture);
1456 FIXME("Call to get texture (%d) failed (%p)\n", Stage, retTexture);
1459 LeaveCriticalSection(&d3d8_cs);
1464 static HRESULT WINAPI IDirect3DDevice8Impl_SetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage, IDirect3DBaseTexture8* pTexture) {
1465 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1467 TRACE("(%p) Relay %d %p\n" , This, Stage, pTexture);
1469 EnterCriticalSection(&d3d8_cs);
1470 hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
1471 pTexture==NULL ? NULL : ((IDirect3DBaseTexture8Impl *)pTexture)->wineD3DBaseTexture);
1472 LeaveCriticalSection(&d3d8_cs);
1476 static const struct tss_lookup
1483 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 0, unused */
1484 {FALSE, WINED3DTSS_COLOROP}, /* 1, D3DTSS_COLOROP */
1485 {FALSE, WINED3DTSS_COLORARG1}, /* 2, D3DTSS_COLORARG1 */
1486 {FALSE, WINED3DTSS_COLORARG2}, /* 3, D3DTSS_COLORARG2 */
1487 {FALSE, WINED3DTSS_ALPHAOP}, /* 4, D3DTSS_ALPHAOP */
1488 {FALSE, WINED3DTSS_ALPHAARG1}, /* 5, D3DTSS_ALPHAARG1 */
1489 {FALSE, WINED3DTSS_ALPHAARG2}, /* 6, D3DTSS_ALPHAARG2 */
1490 {FALSE, WINED3DTSS_BUMPENVMAT00}, /* 7, D3DTSS_BUMPENVMAT00 */
1491 {FALSE, WINED3DTSS_BUMPENVMAT01}, /* 8, D3DTSS_BUMPENVMAT01 */
1492 {FALSE, WINED3DTSS_BUMPENVMAT10}, /* 9, D3DTSS_BUMPENVMAT10 */
1493 {FALSE, WINED3DTSS_BUMPENVMAT11}, /* 10, D3DTSS_BUMPENVMAT11 */
1494 {FALSE, WINED3DTSS_TEXCOORDINDEX}, /* 11, D3DTSS_TEXCOORDINDEX */
1495 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 12, unused */
1496 {TRUE, WINED3DSAMP_ADDRESSU}, /* 13, D3DTSS_ADDRESSU */
1497 {TRUE, WINED3DSAMP_ADDRESSV}, /* 14, D3DTSS_ADDRESSV */
1498 {TRUE, WINED3DSAMP_BORDERCOLOR}, /* 15, D3DTSS_BORDERCOLOR */
1499 {TRUE, WINED3DSAMP_MAGFILTER}, /* 16, D3DTSS_MAGFILTER */
1500 {TRUE, WINED3DSAMP_MINFILTER}, /* 17, D3DTSS_MINFILTER */
1501 {TRUE, WINED3DSAMP_MIPFILTER}, /* 18, D3DTSS_MIPFILTER */
1502 {TRUE, WINED3DSAMP_MIPMAPLODBIAS}, /* 19, D3DTSS_MIPMAPLODBIAS */
1503 {TRUE, WINED3DSAMP_MAXMIPLEVEL}, /* 20, D3DTSS_MAXMIPLEVEL */
1504 {TRUE, WINED3DSAMP_MAXANISOTROPY}, /* 21, D3DTSS_MAXANISOTROPY */
1505 {FALSE, WINED3DTSS_BUMPENVLSCALE}, /* 22, D3DTSS_BUMPENVLSCALE */
1506 {FALSE, WINED3DTSS_BUMPENVLOFFSET}, /* 23, D3DTSS_BUMPENVLOFFSET */
1507 {FALSE, WINED3DTSS_TEXTURETRANSFORMFLAGS}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1508 {TRUE, WINED3DSAMP_ADDRESSW}, /* 25, D3DTSS_ADDRESSW */
1509 {FALSE, WINED3DTSS_COLORARG0}, /* 26, D3DTSS_COLORARG0 */
1510 {FALSE, WINED3DTSS_ALPHAARG0}, /* 27, D3DTSS_ALPHAARG0 */
1511 {FALSE, WINED3DTSS_RESULTARG}, /* 28, D3DTSS_RESULTARG */
1514 static HRESULT WINAPI IDirect3DDevice8Impl_GetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD* pValue) {
1515 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1516 const struct tss_lookup *l = &tss_lookup[Type];
1518 TRACE("(%p) Relay\n" , This);
1520 EnterCriticalSection(&d3d8_cs);
1522 if (l->sampler_state) hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Stage, l->state, pValue);
1523 else hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, l->state, pValue);
1525 LeaveCriticalSection(&d3d8_cs);
1529 static HRESULT WINAPI IDirect3DDevice8Impl_SetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
1530 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1531 const struct tss_lookup *l = &tss_lookup[Type];
1533 TRACE("(%p) Relay\n" , This);
1535 EnterCriticalSection(&d3d8_cs);
1537 if (l->sampler_state) hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Stage, l->state, Value);
1538 else hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, l->state, Value);
1540 LeaveCriticalSection(&d3d8_cs);
1544 static HRESULT WINAPI IDirect3DDevice8Impl_ValidateDevice(LPDIRECT3DDEVICE8 iface, DWORD* pNumPasses) {
1545 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1547 TRACE("(%p) Relay\n" , This);
1549 EnterCriticalSection(&d3d8_cs);
1550 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1551 LeaveCriticalSection(&d3d8_cs);
1555 static HRESULT WINAPI IDirect3DDevice8Impl_GetInfo(LPDIRECT3DDEVICE8 iface, DWORD DevInfoID, void* pDevInfoStruct, DWORD DevInfoStructSize) {
1556 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1557 FIXME("(%p) : stub\n", This);
1561 static HRESULT WINAPI IDirect3DDevice8Impl_SetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, CONST PALETTEENTRY* pEntries) {
1562 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1564 TRACE("(%p) Relay\n" , This);
1566 EnterCriticalSection(&d3d8_cs);
1567 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1568 LeaveCriticalSection(&d3d8_cs);
1572 static HRESULT WINAPI IDirect3DDevice8Impl_GetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
1573 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1575 TRACE("(%p) Relay\n" , This);
1577 EnterCriticalSection(&d3d8_cs);
1578 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1579 LeaveCriticalSection(&d3d8_cs);
1583 static HRESULT WINAPI IDirect3DDevice8Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber) {
1584 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1586 TRACE("(%p) Relay\n" , This);
1588 EnterCriticalSection(&d3d8_cs);
1589 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1590 LeaveCriticalSection(&d3d8_cs);
1594 static HRESULT WINAPI IDirect3DDevice8Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT *PaletteNumber) {
1595 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1597 TRACE("(%p) Relay\n" , This);
1599 EnterCriticalSection(&d3d8_cs);
1600 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1601 LeaveCriticalSection(&d3d8_cs);
1605 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitive(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) {
1606 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1608 TRACE("(%p) Relay\n" , This);
1610 EnterCriticalSection(&d3d8_cs);
1611 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1612 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
1613 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
1614 LeaveCriticalSection(&d3d8_cs);
1618 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,
1619 UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount) {
1620 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1622 TRACE("(%p) Relay\n" , This);
1624 EnterCriticalSection(&d3d8_cs);
1625 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1626 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, MinVertexIndex, NumVertices,
1627 startIndex, vertex_count_from_primitive_count(PrimitiveType, primCount));
1628 LeaveCriticalSection(&d3d8_cs);
1632 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT PrimitiveCount,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride) {
1633 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1635 TRACE("(%p) Relay\n" , This);
1637 EnterCriticalSection(&d3d8_cs);
1638 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1639 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
1640 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
1641 pVertexStreamZeroData, VertexStreamZeroStride);
1642 LeaveCriticalSection(&d3d8_cs);
1646 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,
1647 UINT NumVertexIndices,UINT PrimitiveCount,CONST void* pIndexData,
1648 D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,
1649 UINT VertexStreamZeroStride) {
1650 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1652 TRACE("(%p) Relay\n" , This);
1654 EnterCriticalSection(&d3d8_cs);
1655 IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
1656 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice, MinVertexIndex, NumVertexIndices,
1657 vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
1658 wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
1659 LeaveCriticalSection(&d3d8_cs);
1663 static HRESULT WINAPI IDirect3DDevice8Impl_ProcessVertices(LPDIRECT3DDEVICE8 iface, UINT SrcStartIndex,UINT DestIndex,UINT VertexCount,IDirect3DVertexBuffer8* pDestBuffer,DWORD Flags) {
1664 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1666 IDirect3DVertexBuffer8Impl *dest = (IDirect3DVertexBuffer8Impl *) pDestBuffer;
1667 TRACE("(%p) Relay\n" , This);
1669 EnterCriticalSection(&d3d8_cs);
1670 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, NULL, Flags, dest->fvf);
1671 LeaveCriticalSection(&d3d8_cs);
1675 static HRESULT IDirect3DDevice8Impl_CreateVertexDeclaration(IDirect3DDevice8 *iface, CONST DWORD *declaration, IDirect3DVertexDeclaration8 **decl_ptr) {
1676 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1677 IDirect3DVertexDeclaration8Impl *object;
1678 WINED3DVERTEXELEMENT *wined3d_elements;
1679 UINT wined3d_element_count;
1680 HRESULT hr = D3D_OK;
1682 TRACE("(%p) : declaration %p\n", This, declaration);
1684 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1686 ERR("Memory allocation failed\n");
1688 return D3DERR_OUTOFVIDEOMEMORY;
1691 object->ref_count = 1;
1692 object->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
1694 wined3d_element_count = convert_to_wined3d_declaration(declaration, &object->elements_size, &wined3d_elements);
1695 object->elements = HeapAlloc(GetProcessHeap(), 0, object->elements_size);
1696 if (!object->elements) {
1697 ERR("Memory allocation failed\n");
1698 HeapFree(GetProcessHeap(), 0, wined3d_elements);
1699 HeapFree(GetProcessHeap(), 0, object);
1701 return D3DERR_OUTOFVIDEOMEMORY;
1704 CopyMemory(object->elements, declaration, object->elements_size);
1706 EnterCriticalSection(&d3d8_cs);
1707 hr = IWineD3DDevice_CreateVertexDeclaration(This->WineD3DDevice, &object->wined3d_vertex_declaration,
1708 (IUnknown *)object, wined3d_elements, wined3d_element_count);
1709 LeaveCriticalSection(&d3d8_cs);
1710 HeapFree(GetProcessHeap(), 0, wined3d_elements);
1713 ERR("(%p) : IWineD3DDevice_CreateVertexDeclaration call failed\n", This);
1714 HeapFree(GetProcessHeap(), 0, object->elements);
1715 HeapFree(GetProcessHeap(), 0, object);
1717 *decl_ptr = (IDirect3DVertexDeclaration8 *)object;
1718 TRACE("(%p) : Created vertex declaration %p\n", This, object);
1724 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pDeclaration, CONST DWORD* pFunction, DWORD* ppShader, DWORD Usage) {
1725 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1726 HRESULT hrc = D3D_OK;
1727 IDirect3DVertexShader8Impl *object;
1728 IWineD3DVertexDeclaration *wined3d_vertex_declaration;
1729 const DWORD *token = pDeclaration;
1732 /* Test if the vertex declaration is valid */
1733 while (D3DVSD_END() != *token) {
1734 D3DVSD_TOKENTYPE token_type = ((*token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT);
1736 if (token_type == D3DVSD_TOKEN_STREAMDATA && !(token_type & 0x10000000)) {
1737 DWORD type = ((*token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
1738 DWORD reg = ((*token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
1740 if(reg == D3DVSDE_NORMAL && type != D3DVSDT_FLOAT3 && !pFunction) {
1741 WARN("Attempt to use a non-FLOAT3 normal with the fixed function function\n");
1742 return D3DERR_INVALIDCALL;
1745 token += parse_token(token);
1748 /* Setup a stub object for now */
1749 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1750 TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
1751 if (NULL == object) {
1752 FIXME("Allocation of memory failed\n");
1754 return D3DERR_OUTOFVIDEOMEMORY;
1758 object->lpVtbl = &Direct3DVertexShader8_Vtbl;
1760 hrc = IDirect3DDevice8Impl_CreateVertexDeclaration(iface, pDeclaration, &object->vertex_declaration);
1762 ERR("(%p) : IDirect3DDeviceImpl_CreateVertexDeclaration call failed\n", This);
1763 HeapFree(GetProcessHeap(), 0, object);
1765 return D3DERR_INVALIDCALL;
1768 EnterCriticalSection(&d3d8_cs);
1769 handle = d3d8_allocate_handle(&This->handle_table, object);
1770 if (handle == D3D8_INVALID_HANDLE)
1772 ERR("Failed to allocate shader handle\n");
1773 LeaveCriticalSection(&d3d8_cs);
1774 IDirect3DVertexDeclaration8_Release(object->vertex_declaration);
1775 HeapFree(GetProcessHeap(), 0, object);
1777 return E_OUTOFMEMORY;
1781 DWORD shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
1782 *ppShader = ((IDirect3DVertexDeclaration8Impl *)object->vertex_declaration)->shader_handle = shader_handle;
1785 wined3d_vertex_declaration = ((IDirect3DVertexDeclaration8Impl *)object->vertex_declaration)->wined3d_vertex_declaration;
1789 /* Usage is missing ... Use SetRenderState to set the sw vp render state in SetVertexShader */
1790 hrc = IWineD3DDevice_CreateVertexShader(This->WineD3DDevice, wined3d_vertex_declaration,
1791 pFunction, &object->wineD3DVertexShader, (IUnknown *)object);
1795 /* free up object */
1796 FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n");
1797 d3d8_free_handle(&This->handle_table, handle);
1798 IDirect3DVertexDeclaration8_Release(object->vertex_declaration);
1799 HeapFree(GetProcessHeap(), 0, object);
1804 load_local_constants(pDeclaration, object->wineD3DVertexShader);
1805 TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
1809 LeaveCriticalSection(&d3d8_cs);
1814 static IDirect3DVertexDeclaration8Impl *IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl *This, DWORD fvf)
1816 IDirect3DVertexDeclaration8Impl *d3d8_declaration;
1818 int p, low, high; /* deliberately signed */
1819 struct FvfToDecl *convertedDecls = This->decls;
1821 TRACE("Searching for declaration for fvf %08x... ", fvf);
1824 high = This->numConvertedDecls - 1;
1825 while(low <= high) {
1826 p = (low + high) >> 1;
1828 if(convertedDecls[p].fvf == fvf) {
1829 TRACE("found %p\n", convertedDecls[p].decl);
1830 return (IDirect3DVertexDeclaration8Impl *)convertedDecls[p].decl;
1831 } else if(convertedDecls[p].fvf < fvf) {
1837 TRACE("not found. Creating and inserting at position %d.\n", low);
1839 d3d8_declaration = HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration));
1840 if (!d3d8_declaration)
1842 ERR("Memory allocation failed.\n");
1846 d3d8_declaration->ref_count = 1;
1847 d3d8_declaration->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
1848 d3d8_declaration->elements = NULL;
1849 d3d8_declaration->elements_size = 0;
1850 d3d8_declaration->shader_handle = fvf;
1852 hr = IWineD3DDevice_CreateVertexDeclarationFromFVF(This->WineD3DDevice,
1853 &d3d8_declaration->wined3d_vertex_declaration, (IUnknown *)d3d8_declaration, fvf);
1856 ERR("Failed to create wined3d vertex declaration.\n");
1857 HeapFree(GetProcessHeap(), 0, d3d8_declaration);
1861 if(This->declArraySize == This->numConvertedDecls) {
1862 int grow = This->declArraySize / 2;
1863 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
1864 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
1865 if(!convertedDecls) {
1866 /* This will destroy it */
1867 IDirect3DVertexDeclaration8_Release((IDirect3DVertexDeclaration8 *)d3d8_declaration);
1870 This->decls = convertedDecls;
1871 This->declArraySize += grow;
1874 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(convertedDecls[0]) * (This->numConvertedDecls - low));
1875 convertedDecls[low].decl = (IDirect3DVertexDeclaration8 *)d3d8_declaration;
1876 convertedDecls[low].fvf = fvf;
1877 This->numConvertedDecls++;
1879 TRACE("Returning %p. %u decls in array\n", d3d8_declaration, This->numConvertedDecls);
1880 return d3d8_declaration;
1883 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1884 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1885 IDirect3DVertexShader8Impl *shader;
1888 TRACE("(%p) : Relay\n", This);
1890 if (VS_HIGHESTFIXEDFXF >= pShader) {
1891 TRACE("Setting FVF, %#x\n", pShader);
1893 EnterCriticalSection(&d3d8_cs);
1894 IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
1895 IDirect3DDevice8Impl_FindDecl(This, pShader)->wined3d_vertex_declaration);
1896 IWineD3DDevice_SetVertexShader(This->WineD3DDevice, NULL);
1897 LeaveCriticalSection(&d3d8_cs);
1901 TRACE("Setting shader\n");
1903 EnterCriticalSection(&d3d8_cs);
1904 shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1));
1907 WARN("Invalid handle (%#x) passed.\n", pShader);
1908 LeaveCriticalSection(&d3d8_cs);
1909 return D3DERR_INVALIDCALL;
1912 hr = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
1913 ((IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration)->wined3d_vertex_declaration);
1914 if (SUCCEEDED(hr)) hr = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, shader->wineD3DVertexShader);
1915 LeaveCriticalSection(&d3d8_cs);
1917 TRACE("Returning hr %#x\n", hr);
1922 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
1923 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1924 IWineD3DVertexDeclaration *wined3d_declaration;
1925 IDirect3DVertexDeclaration8 *d3d8_declaration;
1928 TRACE("(%p) : Relay device@%p\n", This, This->WineD3DDevice);
1929 EnterCriticalSection(&d3d8_cs);
1931 hrc = IWineD3DDevice_GetVertexDeclaration(This->WineD3DDevice, &wined3d_declaration);
1934 LeaveCriticalSection(&d3d8_cs);
1935 WARN("(%p) : Call to IWineD3DDevice_GetVertexDeclaration failed %#x (device %p)\n",
1936 This, hrc, This->WineD3DDevice);
1940 if (!wined3d_declaration)
1942 LeaveCriticalSection(&d3d8_cs);
1947 hrc = IWineD3DVertexDeclaration_GetParent(wined3d_declaration, (IUnknown **)&d3d8_declaration);
1948 IWineD3DVertexDeclaration_Release(wined3d_declaration);
1949 LeaveCriticalSection(&d3d8_cs);
1952 *ppShader = ((IDirect3DVertexDeclaration8Impl *)d3d8_declaration)->shader_handle;
1953 IDirect3DVertexDeclaration8_Release(d3d8_declaration);
1956 TRACE("(%p) : returning %#x\n", This, *ppShader);
1961 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1962 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1963 IDirect3DVertexShader8Impl *shader;
1964 IWineD3DVertexShader *cur = NULL;
1966 TRACE("(%p) : pShader %#x\n", This, pShader);
1968 EnterCriticalSection(&d3d8_cs);
1970 shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1));
1973 WARN("Invalid handle (%#x) passed.\n", pShader);
1974 LeaveCriticalSection(&d3d8_cs);
1975 return D3DERR_INVALIDCALL;
1978 IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &cur);
1982 if (cur == shader->wineD3DVertexShader) IDirect3DDevice8_SetVertexShader(iface, 0);
1983 IWineD3DVertexShader_Release(cur);
1986 LeaveCriticalSection(&d3d8_cs);
1988 if (IUnknown_Release((IUnknown *)shader))
1990 ERR("Shader %p has references left, this shouldn't happen.\n", shader);
1996 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
1997 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1999 TRACE("(%p) : Relay\n", This);
2001 EnterCriticalSection(&d3d8_cs);
2002 hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2003 LeaveCriticalSection(&d3d8_cs);
2007 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
2008 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2010 TRACE("(%p) : Relay\n", This);
2012 EnterCriticalSection(&d3d8_cs);
2013 hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2014 LeaveCriticalSection(&d3d8_cs);
2018 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderDeclaration(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
2019 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2020 IDirect3DVertexDeclaration8Impl *declaration;
2021 IDirect3DVertexShader8Impl *shader;
2023 TRACE("(%p) : pVertexShader 0x%08x, pData %p, *pSizeOfData %u\n", This, pVertexShader, pData, *pSizeOfData);
2025 EnterCriticalSection(&d3d8_cs);
2027 shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1));
2028 LeaveCriticalSection(&d3d8_cs);
2031 WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2032 return D3DERR_INVALIDCALL;
2034 declaration = (IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration;
2036 /* If pData is NULL, we just return the required size of the buffer. */
2038 *pSizeOfData = declaration->elements_size;
2042 /* MSDN claims that if *pSizeOfData is smaller than the required size
2043 * we should write the required size and return D3DERR_MOREDATA.
2044 * That's not actually true. */
2045 if (*pSizeOfData < declaration->elements_size) {
2046 return D3DERR_INVALIDCALL;
2049 CopyMemory(pData, declaration->elements, declaration->elements_size);
2054 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
2055 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2056 IDirect3DVertexShader8Impl *shader = NULL;
2059 TRACE("(%p) : pVertexShader %#x, pData %p, pSizeOfData %p\n", This, pVertexShader, pData, pSizeOfData);
2061 EnterCriticalSection(&d3d8_cs);
2063 shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1));
2066 WARN("Invalid handle (%#x) passed.\n", pVertexShader);
2067 LeaveCriticalSection(&d3d8_cs);
2068 return D3DERR_INVALIDCALL;
2071 if (!shader->wineD3DVertexShader)
2073 LeaveCriticalSection(&d3d8_cs);
2078 hr = IWineD3DVertexShader_GetFunction(shader->wineD3DVertexShader, pData, pSizeOfData);
2080 LeaveCriticalSection(&d3d8_cs);
2084 static HRESULT WINAPI IDirect3DDevice8Impl_SetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8* pIndexData, UINT baseVertexIndex) {
2085 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2087 IDirect3DIndexBuffer8Impl *ib = (IDirect3DIndexBuffer8Impl *)pIndexData;
2088 TRACE("(%p) Relay\n", This);
2090 EnterCriticalSection(&d3d8_cs);
2091 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
2092 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
2093 * vertex buffers can't be created to address them with an index that requires the 32nd bit
2094 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
2097 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, baseVertexIndex);
2098 hr = IWineD3DDevice_SetIndices(This->WineD3DDevice,
2099 ib ? ib->wineD3DIndexBuffer : NULL,
2100 ib ? ib->format : WINED3DFMT_UNKNOWN);
2101 LeaveCriticalSection(&d3d8_cs);
2105 static HRESULT WINAPI IDirect3DDevice8Impl_GetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8** ppIndexData,UINT* pBaseVertexIndex) {
2106 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2107 IWineD3DBuffer *retIndexData = NULL;
2108 HRESULT rc = D3D_OK;
2110 TRACE("(%p) Relay\n", This);
2112 if(ppIndexData == NULL){
2113 return D3DERR_INVALIDCALL;
2116 EnterCriticalSection(&d3d8_cs);
2117 /* The case from UINT to INT is safe because d3d8 will never set negative values */
2118 IWineD3DDevice_GetBaseVertexIndex(This->WineD3DDevice, (INT *) pBaseVertexIndex);
2119 rc = IWineD3DDevice_GetIndices(This->WineD3DDevice, &retIndexData);
2120 if (SUCCEEDED(rc) && retIndexData) {
2121 IWineD3DBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
2122 IWineD3DBuffer_Release(retIndexData);
2124 if (FAILED(rc)) FIXME("Call to GetIndices failed\n");
2125 *ppIndexData = NULL;
2127 LeaveCriticalSection(&d3d8_cs);
2131 static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pFunction, DWORD* ppShader) {
2132 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2133 IDirect3DPixelShader8Impl *object;
2137 TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
2139 if (NULL == ppShader) {
2140 TRACE("(%p) Invalid call\n", This);
2141 return D3DERR_INVALIDCALL;
2144 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2147 ERR("Failed to allocate memmory.\n");
2148 return E_OUTOFMEMORY;
2152 object->lpVtbl = &Direct3DPixelShader8_Vtbl;
2154 EnterCriticalSection(&d3d8_cs);
2155 hr = IWineD3DDevice_CreatePixelShader(This->WineD3DDevice, pFunction,
2156 &object->wineD3DPixelShader, (IUnknown *)object);
2159 LeaveCriticalSection(&d3d8_cs);
2160 FIXME("(%p) call to IWineD3DDevice_CreatePixelShader failed\n", This);
2161 HeapFree(GetProcessHeap(), 0 , object);
2166 handle = d3d8_allocate_handle(&This->handle_table, object);
2167 LeaveCriticalSection(&d3d8_cs);
2168 if (handle == D3D8_INVALID_HANDLE)
2170 ERR("Failed to allocate shader handle\n");
2171 IDirect3DVertexShader8_Release((IUnknown *)object);
2172 return E_OUTOFMEMORY;
2175 *ppShader = object->handle = handle + VS_HIGHESTFIXEDFXF + 1;
2176 TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
2181 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
2182 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2183 IDirect3DPixelShader8Impl *shader;
2186 TRACE("(%p) : pShader %#x\n", This, pShader);
2188 EnterCriticalSection(&d3d8_cs);
2192 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, NULL);
2193 LeaveCriticalSection(&d3d8_cs);
2197 shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1));
2200 WARN("Invalid handle (%#x) passed.\n", pShader);
2201 LeaveCriticalSection(&d3d8_cs);
2202 return D3DERR_INVALIDCALL;
2205 TRACE("(%p) : Setting shader %p\n", This, shader);
2206 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, shader->wineD3DPixelShader);
2207 LeaveCriticalSection(&d3d8_cs);
2211 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
2212 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2213 IWineD3DPixelShader *object;
2215 HRESULT hrc = D3D_OK;
2216 TRACE("(%p) Relay\n", This);
2217 if (NULL == ppShader) {
2218 TRACE("(%p) Invalid call\n", This);
2219 return D3DERR_INVALIDCALL;
2222 EnterCriticalSection(&d3d8_cs);
2223 hrc = IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &object);
2224 if (D3D_OK == hrc && NULL != object) {
2225 IDirect3DPixelShader8Impl *d3d8_shader;
2226 hrc = IWineD3DPixelShader_GetParent(object, (IUnknown **)&d3d8_shader);
2227 IWineD3DPixelShader_Release(object);
2228 *ppShader = d3d8_shader->handle;
2229 IDirect3DPixelShader8_Release((IDirect3DPixelShader8 *)d3d8_shader);
2234 TRACE("(%p) : returning %#x\n", This, *ppShader);
2235 LeaveCriticalSection(&d3d8_cs);
2239 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
2240 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2241 IDirect3DPixelShader8Impl *shader;
2242 IWineD3DPixelShader *cur = NULL;
2244 TRACE("(%p) : pShader %#x\n", This, pShader);
2246 EnterCriticalSection(&d3d8_cs);
2248 shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1));
2251 WARN("Invalid handle (%#x) passed.\n", pShader);
2252 LeaveCriticalSection(&d3d8_cs);
2253 return D3DERR_INVALIDCALL;
2256 IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &cur);
2260 if (cur == shader->wineD3DPixelShader) IDirect3DDevice8_SetPixelShader(iface, 0);
2261 IWineD3DPixelShader_Release(cur);
2264 LeaveCriticalSection(&d3d8_cs);
2266 if (IUnknown_Release((IUnknown *)shader))
2268 ERR("Shader %p has references left, this shouldn't happen.\n", shader);
2274 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
2275 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2277 TRACE("(%p) Relay\n", This);
2279 EnterCriticalSection(&d3d8_cs);
2280 hr = IWineD3DDevice_SetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2281 LeaveCriticalSection(&d3d8_cs);
2285 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
2286 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2288 TRACE("(%p) Relay\n", This);
2290 EnterCriticalSection(&d3d8_cs);
2291 hr = IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2292 LeaveCriticalSection(&d3d8_cs);
2296 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pPixelShader, void* pData, DWORD* pSizeOfData) {
2297 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2298 IDirect3DPixelShader8Impl *shader = NULL;
2301 TRACE("(%p) : pPixelShader %#x, pData %p, pSizeOfData %p\n", This, pPixelShader, pData, pSizeOfData);
2303 EnterCriticalSection(&d3d8_cs);
2304 shader = d3d8_get_object(&This->handle_table, pPixelShader - (VS_HIGHESTFIXEDFXF + 1));
2307 WARN("Invalid handle (%#x) passed.\n", pPixelShader);
2308 LeaveCriticalSection(&d3d8_cs);
2309 return D3DERR_INVALIDCALL;
2312 hr = IWineD3DPixelShader_GetFunction(shader->wineD3DPixelShader, pData, pSizeOfData);
2313 LeaveCriticalSection(&d3d8_cs);
2317 static HRESULT WINAPI IDirect3DDevice8Impl_DrawRectPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
2318 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2320 TRACE("(%p) Relay\n", This);
2322 EnterCriticalSection(&d3d8_cs);
2323 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
2324 LeaveCriticalSection(&d3d8_cs);
2328 static HRESULT WINAPI IDirect3DDevice8Impl_DrawTriPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
2329 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2331 TRACE("(%p) Relay\n", This);
2333 EnterCriticalSection(&d3d8_cs);
2334 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
2335 LeaveCriticalSection(&d3d8_cs);
2339 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePatch(LPDIRECT3DDEVICE8 iface, UINT Handle) {
2340 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2342 TRACE("(%p) Relay\n", This);
2344 EnterCriticalSection(&d3d8_cs);
2345 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
2346 LeaveCriticalSection(&d3d8_cs);
2350 static HRESULT WINAPI IDirect3DDevice8Impl_SetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8* pStreamData,UINT Stride) {
2351 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2353 TRACE("(%p) Relay\n" , This);
2355 EnterCriticalSection(&d3d8_cs);
2356 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
2357 NULL == pStreamData ? NULL : ((IDirect3DVertexBuffer8Impl *)pStreamData)->wineD3DVertexBuffer,
2358 0/* Offset in bytes */, Stride);
2359 LeaveCriticalSection(&d3d8_cs);
2363 static HRESULT WINAPI IDirect3DDevice8Impl_GetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8** pStream,UINT* pStride) {
2364 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2365 IWineD3DBuffer *retStream = NULL;
2366 HRESULT rc = D3D_OK;
2368 TRACE("(%p) Relay\n" , This);
2370 if(pStream == NULL){
2371 return D3DERR_INVALIDCALL;
2374 EnterCriticalSection(&d3d8_cs);
2375 rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, 0 /* Offset in bytes */, pStride);
2376 if (rc == D3D_OK && NULL != retStream) {
2377 IWineD3DBuffer_GetParent(retStream, (IUnknown **)pStream);
2378 IWineD3DBuffer_Release(retStream);
2381 FIXME("Call to GetStreamSource failed %p\n", pStride);
2385 LeaveCriticalSection(&d3d8_cs);
2391 const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl =
2393 IDirect3DDevice8Impl_QueryInterface,
2394 IDirect3DDevice8Impl_AddRef,
2395 IDirect3DDevice8Impl_Release,
2396 IDirect3DDevice8Impl_TestCooperativeLevel,
2397 IDirect3DDevice8Impl_GetAvailableTextureMem,
2398 IDirect3DDevice8Impl_ResourceManagerDiscardBytes,
2399 IDirect3DDevice8Impl_GetDirect3D,
2400 IDirect3DDevice8Impl_GetDeviceCaps,
2401 IDirect3DDevice8Impl_GetDisplayMode,
2402 IDirect3DDevice8Impl_GetCreationParameters,
2403 IDirect3DDevice8Impl_SetCursorProperties,
2404 IDirect3DDevice8Impl_SetCursorPosition,
2405 IDirect3DDevice8Impl_ShowCursor,
2406 IDirect3DDevice8Impl_CreateAdditionalSwapChain,
2407 IDirect3DDevice8Impl_Reset,
2408 IDirect3DDevice8Impl_Present,
2409 IDirect3DDevice8Impl_GetBackBuffer,
2410 IDirect3DDevice8Impl_GetRasterStatus,
2411 IDirect3DDevice8Impl_SetGammaRamp,
2412 IDirect3DDevice8Impl_GetGammaRamp,
2413 IDirect3DDevice8Impl_CreateTexture,
2414 IDirect3DDevice8Impl_CreateVolumeTexture,
2415 IDirect3DDevice8Impl_CreateCubeTexture,
2416 IDirect3DDevice8Impl_CreateVertexBuffer,
2417 IDirect3DDevice8Impl_CreateIndexBuffer,
2418 IDirect3DDevice8Impl_CreateRenderTarget,
2419 IDirect3DDevice8Impl_CreateDepthStencilSurface,
2420 IDirect3DDevice8Impl_CreateImageSurface,
2421 IDirect3DDevice8Impl_CopyRects,
2422 IDirect3DDevice8Impl_UpdateTexture,
2423 IDirect3DDevice8Impl_GetFrontBuffer,
2424 IDirect3DDevice8Impl_SetRenderTarget,
2425 IDirect3DDevice8Impl_GetRenderTarget,
2426 IDirect3DDevice8Impl_GetDepthStencilSurface,
2427 IDirect3DDevice8Impl_BeginScene,
2428 IDirect3DDevice8Impl_EndScene,
2429 IDirect3DDevice8Impl_Clear,
2430 IDirect3DDevice8Impl_SetTransform,
2431 IDirect3DDevice8Impl_GetTransform,
2432 IDirect3DDevice8Impl_MultiplyTransform,
2433 IDirect3DDevice8Impl_SetViewport,
2434 IDirect3DDevice8Impl_GetViewport,
2435 IDirect3DDevice8Impl_SetMaterial,
2436 IDirect3DDevice8Impl_GetMaterial,
2437 IDirect3DDevice8Impl_SetLight,
2438 IDirect3DDevice8Impl_GetLight,
2439 IDirect3DDevice8Impl_LightEnable,
2440 IDirect3DDevice8Impl_GetLightEnable,
2441 IDirect3DDevice8Impl_SetClipPlane,
2442 IDirect3DDevice8Impl_GetClipPlane,
2443 IDirect3DDevice8Impl_SetRenderState,
2444 IDirect3DDevice8Impl_GetRenderState,
2445 IDirect3DDevice8Impl_BeginStateBlock,
2446 IDirect3DDevice8Impl_EndStateBlock,
2447 IDirect3DDevice8Impl_ApplyStateBlock,
2448 IDirect3DDevice8Impl_CaptureStateBlock,
2449 IDirect3DDevice8Impl_DeleteStateBlock,
2450 IDirect3DDevice8Impl_CreateStateBlock,
2451 IDirect3DDevice8Impl_SetClipStatus,
2452 IDirect3DDevice8Impl_GetClipStatus,
2453 IDirect3DDevice8Impl_GetTexture,
2454 IDirect3DDevice8Impl_SetTexture,
2455 IDirect3DDevice8Impl_GetTextureStageState,
2456 IDirect3DDevice8Impl_SetTextureStageState,
2457 IDirect3DDevice8Impl_ValidateDevice,
2458 IDirect3DDevice8Impl_GetInfo,
2459 IDirect3DDevice8Impl_SetPaletteEntries,
2460 IDirect3DDevice8Impl_GetPaletteEntries,
2461 IDirect3DDevice8Impl_SetCurrentTexturePalette,
2462 IDirect3DDevice8Impl_GetCurrentTexturePalette,
2463 IDirect3DDevice8Impl_DrawPrimitive,
2464 IDirect3DDevice8Impl_DrawIndexedPrimitive,
2465 IDirect3DDevice8Impl_DrawPrimitiveUP,
2466 IDirect3DDevice8Impl_DrawIndexedPrimitiveUP,
2467 IDirect3DDevice8Impl_ProcessVertices,
2468 IDirect3DDevice8Impl_CreateVertexShader,
2469 IDirect3DDevice8Impl_SetVertexShader,
2470 IDirect3DDevice8Impl_GetVertexShader,
2471 IDirect3DDevice8Impl_DeleteVertexShader,
2472 IDirect3DDevice8Impl_SetVertexShaderConstant,
2473 IDirect3DDevice8Impl_GetVertexShaderConstant,
2474 IDirect3DDevice8Impl_GetVertexShaderDeclaration,
2475 IDirect3DDevice8Impl_GetVertexShaderFunction,
2476 IDirect3DDevice8Impl_SetStreamSource,
2477 IDirect3DDevice8Impl_GetStreamSource,
2478 IDirect3DDevice8Impl_SetIndices,
2479 IDirect3DDevice8Impl_GetIndices,
2480 IDirect3DDevice8Impl_CreatePixelShader,
2481 IDirect3DDevice8Impl_SetPixelShader,
2482 IDirect3DDevice8Impl_GetPixelShader,
2483 IDirect3DDevice8Impl_DeletePixelShader,
2484 IDirect3DDevice8Impl_SetPixelShaderConstant,
2485 IDirect3DDevice8Impl_GetPixelShaderConstant,
2486 IDirect3DDevice8Impl_GetPixelShaderFunction,
2487 IDirect3DDevice8Impl_DrawRectPatch,
2488 IDirect3DDevice8Impl_DrawTriPatch,
2489 IDirect3DDevice8Impl_DeletePatch
2492 ULONG WINAPI D3D8CB_DestroySurface(IWineD3DSurface *pSurface) {
2493 IDirect3DSurface8Impl* surfaceParent;
2494 TRACE("(%p) call back\n", pSurface);
2496 IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
2497 /* GetParent's AddRef was forwarded to an object in destruction.
2498 * Releasing it here again would cause an endless recursion. */
2499 surfaceParent->forwardReference = NULL;
2500 return IDirect3DSurface8_Release((IDirect3DSurface8*) surfaceParent);
2503 /* IWineD3DDeviceParent IUnknown methods */
2505 static inline struct IDirect3DDevice8Impl *device_from_device_parent(IWineD3DDeviceParent *iface)
2507 return (struct IDirect3DDevice8Impl *)((char*)iface
2508 - FIELD_OFFSET(struct IDirect3DDevice8Impl, device_parent_vtbl));
2511 static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface, REFIID riid, void **object)
2513 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2514 return IDirect3DDevice8Impl_QueryInterface((IDirect3DDevice8 *)This, riid, object);
2517 static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
2519 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2520 return IDirect3DDevice8Impl_AddRef((IDirect3DDevice8 *)This);
2523 static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
2525 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2526 return IDirect3DDevice8Impl_Release((IDirect3DDevice8 *)This);
2529 /* IWineD3DDeviceParent methods */
2531 static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
2533 TRACE("iface %p, device %p\n", iface, device);
2536 static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
2537 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, DWORD usage,
2538 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface)
2540 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2541 IDirect3DSurface8Impl *d3d_surface;
2542 BOOL lockable = TRUE;
2545 TRACE("iface %p, superior %p, width %u, height %u, format %#x, usage %#x,\n"
2546 "\tpool %#x, level %u, face %u, surface %p\n",
2547 iface, superior, width, height, format, usage, pool, level, face, surface);
2550 if (pool == WINED3DPOOL_DEFAULT && !(usage & WINED3DUSAGE_DYNAMIC)) lockable = FALSE;
2552 hr = IDirect3DDevice8Impl_CreateSurface((IDirect3DDevice8 *)This, width, height,
2553 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
2554 (IDirect3DSurface8 **)&d3d_surface, D3DRTYPE_SURFACE, usage, pool,
2555 D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
2558 ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
2562 *surface = d3d_surface->wineD3DSurface;
2563 d3d_surface->container = superior;
2564 IUnknown_Release(d3d_surface->parentDevice);
2565 d3d_surface->parentDevice = NULL;
2566 d3d_surface->forwardReference = superior;
2571 static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
2572 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2573 DWORD multisample_quality, BOOL lockable, IWineD3DSurface **surface)
2575 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2576 IDirect3DSurface8Impl *d3d_surface;
2579 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2580 "\tmultisample_quality %u, lockable %u, surface %p\n",
2581 iface, superior, width, height, format, multisample_type, multisample_quality, lockable, surface);
2583 hr = IDirect3DDevice8_CreateRenderTarget((IDirect3DDevice8 *)This, width, height,
2584 d3dformat_from_wined3dformat(format), multisample_type, lockable, (IDirect3DSurface8 **)&d3d_surface);
2587 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
2591 *surface = d3d_surface->wineD3DSurface;
2592 d3d_surface->container = (IUnknown *)This;
2593 d3d_surface->isImplicit = TRUE;
2594 /* Implicit surfaces are created with an refcount of 0 */
2595 IUnknown_Release((IUnknown *)d3d_surface);
2600 static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
2601 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2602 DWORD multisample_quality, BOOL discard, IWineD3DSurface **surface)
2604 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2605 IDirect3DSurface8Impl *d3d_surface;
2608 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2609 "\tmultisample_quality %u, discard %u, surface %p\n",
2610 iface, superior, width, height, format, multisample_type, multisample_quality, discard, surface);
2612 hr = IDirect3DDevice8_CreateDepthStencilSurface((IDirect3DDevice8 *)This, width, height,
2613 d3dformat_from_wined3dformat(format), multisample_type, (IDirect3DSurface8 **)&d3d_surface);
2616 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
2620 *surface = d3d_surface->wineD3DSurface;
2621 d3d_surface->container = (IUnknown *)This;
2622 d3d_surface->isImplicit = TRUE;
2623 /* Implicit surfaces are created with an refcount of 0 */
2624 IUnknown_Release((IUnknown *)d3d_surface);
2629 static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
2630 IUnknown *superior, UINT width, UINT height, UINT depth, WINED3DFORMAT format,
2631 WINED3DPOOL pool, DWORD usage, IWineD3DVolume **volume)
2633 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2634 IDirect3DVolume8Impl *object;
2637 TRACE("iface %p, superior %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
2638 iface, superior, width, height, depth, format, pool, usage, volume);
2640 /* Allocate the storage for the device */
2641 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2644 FIXME("Allocation of memory failed\n");
2646 return D3DERR_OUTOFVIDEOMEMORY;
2649 object->lpVtbl = &Direct3DVolume8_Vtbl;
2651 hr = IWineD3DDevice_CreateVolume(This->WineD3DDevice, width, height, depth, usage,
2652 format, pool, &object->wineD3DVolume, (IUnknown *)object);
2655 ERR("(%p) CreateVolume failed, returning %#x\n", iface, hr);
2656 HeapFree(GetProcessHeap(), 0, object);
2661 *volume = object->wineD3DVolume;
2662 object->container = superior;
2663 object->forwardReference = superior;
2665 TRACE("(%p) Created volume %p\n", iface, *volume);
2670 static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
2671 WINED3DPRESENT_PARAMETERS *present_parameters, IWineD3DSwapChain **swapchain)
2673 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2674 IDirect3DSwapChain8Impl *d3d_swapchain;
2675 D3DPRESENT_PARAMETERS local_parameters;
2678 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
2680 /* Copy the presentation parameters */
2681 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
2682 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
2683 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
2684 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
2685 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
2686 local_parameters.SwapEffect = present_parameters->SwapEffect;
2687 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
2688 local_parameters.Windowed = present_parameters->Windowed;
2689 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
2690 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
2691 local_parameters.Flags = present_parameters->Flags;
2692 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
2693 local_parameters.FullScreen_PresentationInterval = present_parameters->PresentationInterval;
2695 hr = IDirect3DDevice8_CreateAdditionalSwapChain((IDirect3DDevice8 *)This,
2696 &local_parameters, (IDirect3DSwapChain8 **)&d3d_swapchain);
2699 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
2704 *swapchain = d3d_swapchain->wineD3DSwapChain;
2705 IUnknown_Release(d3d_swapchain->parentDevice);
2706 d3d_swapchain->parentDevice = NULL;
2708 /* Copy back the presentation parameters */
2709 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
2710 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
2711 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
2712 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
2713 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
2714 present_parameters->SwapEffect = local_parameters.SwapEffect;
2715 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
2716 present_parameters->Windowed = local_parameters.Windowed;
2717 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
2718 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
2719 present_parameters->Flags = local_parameters.Flags;
2720 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
2721 present_parameters->PresentationInterval = local_parameters.FullScreen_PresentationInterval;
2726 const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl =
2728 /* IUnknown methods */
2729 device_parent_QueryInterface,
2730 device_parent_AddRef,
2731 device_parent_Release,
2732 /* IWineD3DDeviceParent methods */
2733 device_parent_WineD3DDeviceCreated,
2734 device_parent_CreateSurface,
2735 device_parent_CreateRenderTarget,
2736 device_parent_CreateDepthStencilSurface,
2737 device_parent_CreateVolume,
2738 device_parent_CreateSwapChain,