d3d10core: Keep a reference to the wined3d device in the d3d10 device.
[wine/hacks.git] / dlls / d3d8 / device.c
blob643cdbce3007835350536e4a6a8a44e7ae080e1c
1 /*
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
22 #include "config.h"
24 #include <math.h>
25 #include <stdarg.h>
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winuser.h"
32 #include "wingdi.h"
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;
46 switch(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;
83 default:
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;
96 switch(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;
133 default:
134 FIXME("Unhandled D3DFORMAT %#x\n", format);
135 return WINED3DFMT_UNKNOWN;
139 /* Shader handle functions */
140 static shader_handle *alloc_shader_handle(IDirect3DDevice8Impl *This) {
141 if (This->free_shader_handles) {
142 /* Use a free handle */
143 shader_handle *handle = This->free_shader_handles;
144 This->free_shader_handles = *handle;
145 return handle;
147 if (!(This->allocated_shader_handles < This->shader_handle_table_size)) {
148 /* Grow the table */
149 DWORD new_size = This->shader_handle_table_size + (This->shader_handle_table_size >> 1);
150 shader_handle *new_handles = HeapReAlloc(GetProcessHeap(), 0, This->shader_handles, new_size * sizeof(shader_handle));
151 if (!new_handles) return NULL;
152 This->shader_handles = new_handles;
153 This->shader_handle_table_size = new_size;
156 return &This->shader_handles[This->allocated_shader_handles++];
159 static void free_shader_handle(IDirect3DDevice8Impl *This, shader_handle *handle) {
160 *handle = This->free_shader_handles;
161 This->free_shader_handles = handle;
164 /* IDirect3D IUnknown parts follow: */
165 static HRESULT WINAPI IDirect3DDevice8Impl_QueryInterface(LPDIRECT3DDEVICE8 iface,REFIID riid,LPVOID *ppobj)
167 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
169 if (IsEqualGUID(riid, &IID_IUnknown)
170 || IsEqualGUID(riid, &IID_IDirect3DDevice8)) {
171 IUnknown_AddRef(iface);
172 *ppobj = This;
173 return S_OK;
176 if (IsEqualGUID(riid, &IID_IWineD3DDeviceParent))
178 IUnknown_AddRef((IUnknown *)&This->device_parent_vtbl);
179 *ppobj = &This->device_parent_vtbl;
180 return S_OK;
183 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
184 *ppobj = NULL;
185 return E_NOINTERFACE;
188 static ULONG WINAPI IDirect3DDevice8Impl_AddRef(LPDIRECT3DDEVICE8 iface) {
189 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
190 ULONG ref = InterlockedIncrement(&This->ref);
192 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
194 return ref;
197 static ULONG WINAPI IDirect3DDevice8Impl_Release(LPDIRECT3DDEVICE8 iface) {
198 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
199 ULONG ref;
201 if (This->inDestruction) return 0;
202 ref = InterlockedDecrement(&This->ref);
204 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
206 if (ref == 0) {
207 unsigned i;
209 TRACE("Releasing wined3d device %p\n", This->WineD3DDevice);
210 EnterCriticalSection(&d3d8_cs);
211 This->inDestruction = TRUE;
213 for(i = 0; i < This->numConvertedDecls; i++) {
214 IDirect3DVertexDeclaration8_Release(This->decls[i].decl);
216 HeapFree(GetProcessHeap(), 0, This->decls);
218 IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D8CB_DestroyDepthStencilSurface, D3D8CB_DestroySwapChain);
219 IWineD3DDevice_Release(This->WineD3DDevice);
220 HeapFree(GetProcessHeap(), 0, This->shader_handles);
221 HeapFree(GetProcessHeap(), 0, This);
222 LeaveCriticalSection(&d3d8_cs);
224 return ref;
227 /* IDirect3DDevice Interface follow: */
228 static HRESULT WINAPI IDirect3DDevice8Impl_TestCooperativeLevel(LPDIRECT3DDEVICE8 iface) {
229 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
230 HRESULT hr;
232 TRACE("(%p) : Relay\n", This);
233 EnterCriticalSection(&d3d8_cs);
234 hr = IWineD3DDevice_TestCooperativeLevel(This->WineD3DDevice);
235 LeaveCriticalSection(&d3d8_cs);
236 return hr;
239 static UINT WINAPI IDirect3DDevice8Impl_GetAvailableTextureMem(LPDIRECT3DDEVICE8 iface) {
240 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
241 HRESULT hr;
243 TRACE("(%p) Relay\n", This);
244 EnterCriticalSection(&d3d8_cs);
245 hr = IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
246 LeaveCriticalSection(&d3d8_cs);
247 return hr;
250 static HRESULT WINAPI IDirect3DDevice8Impl_ResourceManagerDiscardBytes(LPDIRECT3DDEVICE8 iface, DWORD Bytes) {
251 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
252 HRESULT hr;
254 TRACE("(%p) : Relay bytes(%d)\n", This, Bytes);
255 EnterCriticalSection(&d3d8_cs);
256 hr = IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
257 LeaveCriticalSection(&d3d8_cs);
258 return hr;
261 static HRESULT WINAPI IDirect3DDevice8Impl_GetDirect3D(LPDIRECT3DDEVICE8 iface, IDirect3D8** ppD3D8) {
262 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
263 HRESULT hr = D3D_OK;
264 IWineD3D* pWineD3D;
266 TRACE("(%p) Relay\n", This);
268 if (NULL == ppD3D8) {
269 return D3DERR_INVALIDCALL;
272 EnterCriticalSection(&d3d8_cs);
273 hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &pWineD3D);
274 if (hr == D3D_OK && pWineD3D != NULL)
276 IWineD3D_GetParent(pWineD3D,(IUnknown **)ppD3D8);
277 IWineD3D_Release(pWineD3D);
278 } else {
279 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
280 *ppD3D8 = NULL;
282 TRACE("(%p) returning %p\n",This , *ppD3D8);
283 LeaveCriticalSection(&d3d8_cs);
285 return hr;
288 static HRESULT WINAPI IDirect3DDevice8Impl_GetDeviceCaps(LPDIRECT3DDEVICE8 iface, D3DCAPS8* pCaps) {
289 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
290 HRESULT hrc = D3D_OK;
291 WINED3DCAPS *pWineCaps;
293 TRACE("(%p) : Relay pCaps %p\n", This, pCaps);
294 if(NULL == pCaps){
295 return D3DERR_INVALIDCALL;
297 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
298 if(pWineCaps == NULL){
299 return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
302 EnterCriticalSection(&d3d8_cs);
303 hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
304 LeaveCriticalSection(&d3d8_cs);
305 WINECAPSTOD3D8CAPS(pCaps, pWineCaps)
306 HeapFree(GetProcessHeap(), 0, pWineCaps);
308 /* D3D8 doesn't support SM 2.0 or higher, so clamp to 1.x */
309 if(pCaps->PixelShaderVersion > D3DPS_VERSION(1,4)){
310 pCaps->PixelShaderVersion = D3DPS_VERSION(1,4);
312 if(pCaps->VertexShaderVersion > D3DVS_VERSION(1,1)){
313 pCaps->VertexShaderVersion = D3DVS_VERSION(1,1);
316 TRACE("Returning %p %p\n", This, pCaps);
317 return hrc;
320 static HRESULT WINAPI IDirect3DDevice8Impl_GetDisplayMode(LPDIRECT3DDEVICE8 iface, D3DDISPLAYMODE* pMode) {
321 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
322 HRESULT hr;
323 TRACE("(%p) Relay\n", This);
325 EnterCriticalSection(&d3d8_cs);
326 hr = IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, 0, (WINED3DDISPLAYMODE *) pMode);
327 LeaveCriticalSection(&d3d8_cs);
329 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
331 return hr;
334 static HRESULT WINAPI IDirect3DDevice8Impl_GetCreationParameters(LPDIRECT3DDEVICE8 iface, D3DDEVICE_CREATION_PARAMETERS *pParameters) {
335 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
336 HRESULT hr;
337 TRACE("(%p) Relay\n", This);
339 EnterCriticalSection(&d3d8_cs);
340 hr = IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
341 LeaveCriticalSection(&d3d8_cs);
342 return hr;
345 static HRESULT WINAPI IDirect3DDevice8Impl_SetCursorProperties(LPDIRECT3DDEVICE8 iface, UINT XHotSpot, UINT YHotSpot, IDirect3DSurface8* pCursorBitmap) {
346 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
347 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl*)pCursorBitmap;
348 HRESULT hr;
349 TRACE("(%p) Relay\n", This);
350 if(!pCursorBitmap) {
351 WARN("No cursor bitmap, returning WINED3DERR_INVALIDCALL\n");
352 return WINED3DERR_INVALIDCALL;
355 EnterCriticalSection(&d3d8_cs);
356 hr = IWineD3DDevice_SetCursorProperties(This->WineD3DDevice,XHotSpot,YHotSpot,pSurface->wineD3DSurface);
357 LeaveCriticalSection(&d3d8_cs);
358 return hr;
361 static void WINAPI IDirect3DDevice8Impl_SetCursorPosition(LPDIRECT3DDEVICE8 iface, UINT XScreenSpace, UINT YScreenSpace, DWORD Flags) {
362 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
363 TRACE("(%p) Relay\n", This);
365 EnterCriticalSection(&d3d8_cs);
366 IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
367 LeaveCriticalSection(&d3d8_cs);
370 static BOOL WINAPI IDirect3DDevice8Impl_ShowCursor(LPDIRECT3DDEVICE8 iface, BOOL bShow) {
371 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
372 BOOL ret;
373 TRACE("(%p) Relay\n", This);
375 EnterCriticalSection(&d3d8_cs);
376 ret = IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
377 LeaveCriticalSection(&d3d8_cs);
378 return ret;
381 static HRESULT WINAPI IDirect3DDevice8Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain8** pSwapChain) {
382 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
383 IDirect3DSwapChain8Impl* object;
384 HRESULT hrc = D3D_OK;
385 WINED3DPRESENT_PARAMETERS localParameters;
387 TRACE("(%p) Relay\n", This);
389 /* Fix the back buffer count */
390 if(pPresentationParameters->BackBufferCount == 0) {
391 pPresentationParameters->BackBufferCount = 1;
394 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
395 if (NULL == object) {
396 FIXME("Allocation of memory failed\n");
397 *pSwapChain = NULL;
398 return D3DERR_OUTOFVIDEOMEMORY;
400 object->ref = 1;
401 object->lpVtbl = &Direct3DSwapChain8_Vtbl;
403 /* Allocate an associated WineD3DDevice object */
404 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
405 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
406 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
407 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
408 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
409 localParameters.MultiSampleQuality = 0; /* d3d9 only */
410 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
411 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
412 localParameters.Windowed = pPresentationParameters->Windowed;
413 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
414 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
415 localParameters.Flags = pPresentationParameters->Flags;
416 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
417 localParameters.PresentationInterval = pPresentationParameters->FullScreen_PresentationInterval;
418 localParameters.AutoRestoreDisplayMode = TRUE;
420 EnterCriticalSection(&d3d8_cs);
421 hrc = IWineD3DDevice_CreateSwapChain(This->WineD3DDevice, &localParameters,
422 &object->wineD3DSwapChain, (IUnknown *)object, SURFACE_OPENGL);
423 LeaveCriticalSection(&d3d8_cs);
425 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
426 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
427 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
428 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
429 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
430 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
431 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
432 pPresentationParameters->Windowed = localParameters.Windowed;
433 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
434 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
435 pPresentationParameters->Flags = localParameters.Flags;
436 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
437 pPresentationParameters->FullScreen_PresentationInterval = localParameters.PresentationInterval;
439 if (hrc != D3D_OK) {
440 FIXME("(%p) call to IWineD3DDevice_CreateSwapChain failed\n", This);
441 HeapFree(GetProcessHeap(), 0 , object);
442 *pSwapChain = NULL;
443 }else{
444 IUnknown_AddRef(iface);
445 object->parentDevice = iface;
446 *pSwapChain = (IDirect3DSwapChain8 *)object;
448 TRACE("(%p) returning %p\n", This, *pSwapChain);
449 return hrc;
452 static HRESULT WINAPI IDirect3DDevice8Impl_Reset(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
453 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
454 WINED3DPRESENT_PARAMETERS localParameters;
455 HRESULT hr;
457 TRACE("(%p) Relay pPresentationParameters(%p)\n", This, pPresentationParameters);
459 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
460 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
461 localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
462 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
463 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
464 localParameters.MultiSampleQuality = 0; /* d3d9 only */
465 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
466 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
467 localParameters.Windowed = pPresentationParameters->Windowed;
468 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
469 localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
470 localParameters.Flags = pPresentationParameters->Flags;
471 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
472 localParameters.PresentationInterval = pPresentationParameters->FullScreen_PresentationInterval;
473 localParameters.AutoRestoreDisplayMode = TRUE;
475 EnterCriticalSection(&d3d8_cs);
476 hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
477 LeaveCriticalSection(&d3d8_cs);
479 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
480 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
481 pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
482 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
483 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
484 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
485 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
486 pPresentationParameters->Windowed = localParameters.Windowed;
487 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
488 pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
489 pPresentationParameters->Flags = localParameters.Flags;
490 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
491 pPresentationParameters->FullScreen_PresentationInterval = localParameters.PresentationInterval;
493 return hr;
496 static HRESULT WINAPI IDirect3DDevice8Impl_Present(LPDIRECT3DDEVICE8 iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion) {
497 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
498 HRESULT hr;
499 TRACE("(%p) Relay\n", This);
501 EnterCriticalSection(&d3d8_cs);
502 hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
503 LeaveCriticalSection(&d3d8_cs);
504 return hr;
507 static HRESULT WINAPI IDirect3DDevice8Impl_GetBackBuffer(LPDIRECT3DDEVICE8 iface, UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8** ppBackBuffer) {
508 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
509 IWineD3DSurface *retSurface = NULL;
510 HRESULT rc = D3D_OK;
512 TRACE("(%p) Relay\n", This);
514 EnterCriticalSection(&d3d8_cs);
515 rc = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, 0, BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &retSurface);
516 if (rc == D3D_OK && NULL != retSurface && NULL != ppBackBuffer) {
517 IWineD3DSurface_GetParent(retSurface, (IUnknown **)ppBackBuffer);
518 IWineD3DSurface_Release(retSurface);
520 LeaveCriticalSection(&d3d8_cs);
521 return rc;
524 static HRESULT WINAPI IDirect3DDevice8Impl_GetRasterStatus(LPDIRECT3DDEVICE8 iface, D3DRASTER_STATUS* pRasterStatus) {
525 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
526 HRESULT hr;
527 TRACE("(%p) Relay\n", This);
529 EnterCriticalSection(&d3d8_cs);
530 hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, 0, (WINED3DRASTER_STATUS *) pRasterStatus);
531 LeaveCriticalSection(&d3d8_cs);
532 return hr;
535 static void WINAPI IDirect3DDevice8Impl_SetGammaRamp(LPDIRECT3DDEVICE8 iface, DWORD Flags, CONST D3DGAMMARAMP* pRamp) {
536 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
537 TRACE("(%p) Relay\n", This);
539 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
540 EnterCriticalSection(&d3d8_cs);
541 IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, 0, Flags, (CONST WINED3DGAMMARAMP *) pRamp);
542 LeaveCriticalSection(&d3d8_cs);
545 static void WINAPI IDirect3DDevice8Impl_GetGammaRamp(LPDIRECT3DDEVICE8 iface, D3DGAMMARAMP* pRamp) {
546 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
547 TRACE("(%p) Relay\n", This);
549 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
550 EnterCriticalSection(&d3d8_cs);
551 IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, 0, (WINED3DGAMMARAMP *) pRamp);
552 LeaveCriticalSection(&d3d8_cs);
555 static HRESULT WINAPI IDirect3DDevice8Impl_CreateTexture(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, UINT Levels, DWORD Usage,
556 D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture8 **ppTexture) {
557 IDirect3DTexture8Impl *object;
558 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
559 HRESULT hrc = D3D_OK;
561 TRACE("(%p) : W(%d) H(%d), Lvl(%d) d(%d), Fmt(%u), Pool(%d)\n", This, Width, Height, Levels, Usage, Format, Pool);
563 /* Allocate the storage for the device */
564 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DTexture8Impl));
566 if (NULL == object) {
567 FIXME("Allocation of memory failed\n");
568 /* *ppTexture = NULL; */
569 return D3DERR_OUTOFVIDEOMEMORY;
572 object->lpVtbl = &Direct3DTexture8_Vtbl;
573 object->ref = 1;
574 EnterCriticalSection(&d3d8_cs);
575 hrc = IWineD3DDevice_CreateTexture(This->WineD3DDevice, Width, Height, Levels, Usage & WINED3DUSAGE_MASK,
576 wined3dformat_from_d3dformat(Format), Pool, &object->wineD3DTexture, NULL, (IUnknown *)object);
577 LeaveCriticalSection(&d3d8_cs);
579 if (FAILED(hrc)) {
580 /* free up object */
581 FIXME("(%p) call to IWineD3DDevice_CreateTexture failed\n", This);
582 HeapFree(GetProcessHeap(), 0, object);
583 /* *ppTexture = NULL; */
584 } else {
585 IUnknown_AddRef(iface);
586 object->parentDevice = iface;
587 *ppTexture = (LPDIRECT3DTEXTURE8) object;
588 TRACE("(%p) Created Texture %p, %p\n",This,object,object->wineD3DTexture);
591 return hrc;
594 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVolumeTexture(LPDIRECT3DDEVICE8 iface,
595 UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage,
596 D3DFORMAT Format, D3DPOOL Pool, IDirect3DVolumeTexture8** ppVolumeTexture) {
598 IDirect3DVolumeTexture8Impl *object;
599 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
600 HRESULT hrc = D3D_OK;
602 TRACE("(%p) Relay\n", This);
604 /* Allocate the storage for the device */
605 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVolumeTexture8Impl));
606 if (NULL == object) {
607 FIXME("(%p) allocation of memory failed\n", This);
608 *ppVolumeTexture = NULL;
609 return D3DERR_OUTOFVIDEOMEMORY;
612 object->lpVtbl = &Direct3DVolumeTexture8_Vtbl;
613 object->ref = 1;
614 EnterCriticalSection(&d3d8_cs);
615 hrc = IWineD3DDevice_CreateVolumeTexture(This->WineD3DDevice, Width, Height, Depth, Levels,
616 Usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(Format), Pool,
617 &object->wineD3DVolumeTexture, NULL, (IUnknown *)object);
618 LeaveCriticalSection(&d3d8_cs);
620 if (hrc != D3D_OK) {
622 /* free up object */
623 FIXME("(%p) call to IWineD3DDevice_CreateVolumeTexture failed\n", This);
624 HeapFree(GetProcessHeap(), 0, object);
625 *ppVolumeTexture = NULL;
626 } else {
627 IUnknown_AddRef(iface);
628 object->parentDevice = iface;
629 *ppVolumeTexture = (LPDIRECT3DVOLUMETEXTURE8) object;
631 TRACE("(%p) returning %p\n", This , *ppVolumeTexture);
632 return hrc;
635 static HRESULT WINAPI IDirect3DDevice8Impl_CreateCubeTexture(LPDIRECT3DDEVICE8 iface, UINT EdgeLength, UINT Levels, DWORD Usage,
636 D3DFORMAT Format, D3DPOOL Pool, IDirect3DCubeTexture8** ppCubeTexture) {
638 IDirect3DCubeTexture8Impl *object;
639 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
640 HRESULT hr = D3D_OK;
642 TRACE("(%p) : ELen(%d) Lvl(%d) Usage(%d) fmt(%u), Pool(%d)\n" , This, EdgeLength, Levels, Usage, Format, Pool);
644 /* Allocate the storage for the device */
645 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
647 if (NULL == object) {
648 FIXME("(%p) allocation of CubeTexture failed\n", This);
649 *ppCubeTexture = NULL;
650 return D3DERR_OUTOFVIDEOMEMORY;
653 object->lpVtbl = &Direct3DCubeTexture8_Vtbl;
654 object->ref = 1;
655 EnterCriticalSection(&d3d8_cs);
656 hr = IWineD3DDevice_CreateCubeTexture(This->WineD3DDevice, EdgeLength, Levels, Usage & WINED3DUSAGE_MASK,
657 wined3dformat_from_d3dformat(Format), Pool, &object->wineD3DCubeTexture, NULL, (IUnknown *)object);
658 LeaveCriticalSection(&d3d8_cs);
660 if (hr != D3D_OK){
662 /* free up object */
663 FIXME("(%p) call to IWineD3DDevice_CreateCubeTexture failed\n", This);
664 HeapFree(GetProcessHeap(), 0, object);
665 *ppCubeTexture = NULL;
666 } else {
667 IUnknown_AddRef(iface);
668 object->parentDevice = iface;
669 *ppCubeTexture = (LPDIRECT3DCUBETEXTURE8) object;
672 TRACE("(%p) returning %p\n",This, *ppCubeTexture);
673 return hr;
676 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexBuffer(LPDIRECT3DDEVICE8 iface, UINT Size, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer8** ppVertexBuffer) {
677 IDirect3DVertexBuffer8Impl *object;
678 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
679 HRESULT hrc = D3D_OK;
681 TRACE("(%p) Relay\n", This);
682 /* Allocate the storage for the device */
683 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexBuffer8Impl));
684 if (NULL == object) {
685 FIXME("Allocation of memory failed\n");
686 *ppVertexBuffer = NULL;
687 return D3DERR_OUTOFVIDEOMEMORY;
690 object->lpVtbl = &Direct3DVertexBuffer8_Vtbl;
691 object->ref = 1;
692 EnterCriticalSection(&d3d8_cs);
693 hrc = IWineD3DDevice_CreateVertexBuffer(This->WineD3DDevice, Size, Usage & WINED3DUSAGE_MASK, FVF, (WINED3DPOOL) Pool, &(object->wineD3DVertexBuffer), NULL, (IUnknown *)object);
694 LeaveCriticalSection(&d3d8_cs);
696 if (D3D_OK != hrc) {
698 /* free up object */
699 FIXME("(%p) call to IWineD3DDevice_CreateVertexBuffer failed\n", This);
700 HeapFree(GetProcessHeap(), 0, object);
701 *ppVertexBuffer = NULL;
702 } else {
703 IUnknown_AddRef(iface);
704 object->parentDevice = iface;
705 *ppVertexBuffer = (LPDIRECT3DVERTEXBUFFER8) object;
707 return hrc;
710 static HRESULT WINAPI IDirect3DDevice8Impl_CreateIndexBuffer(LPDIRECT3DDEVICE8 iface, UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DIndexBuffer8** ppIndexBuffer) {
711 IDirect3DIndexBuffer8Impl *object;
712 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
713 HRESULT hrc = D3D_OK;
715 TRACE("(%p) Relay\n", This);
716 /* Allocate the storage for the device */
717 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
718 if (NULL == object) {
719 FIXME("Allocation of memory failed\n");
720 *ppIndexBuffer = NULL;
721 return D3DERR_OUTOFVIDEOMEMORY;
724 object->lpVtbl = &Direct3DIndexBuffer8_Vtbl;
725 object->ref = 1;
726 TRACE("Calling wined3d create index buffer\n");
727 EnterCriticalSection(&d3d8_cs);
728 hrc = IWineD3DDevice_CreateIndexBuffer(This->WineD3DDevice, Length, Usage & WINED3DUSAGE_MASK,
729 wined3dformat_from_d3dformat(Format), (WINED3DPOOL) Pool, &object->wineD3DIndexBuffer,
730 NULL, (IUnknown *)object);
731 LeaveCriticalSection(&d3d8_cs);
733 if (D3D_OK != hrc) {
735 /* free up object */
736 FIXME("(%p) call to IWineD3DDevice_CreateIndexBuffer failed\n", This);
737 HeapFree(GetProcessHeap(), 0, object);
738 *ppIndexBuffer = NULL;
739 } else {
740 IUnknown_AddRef(iface);
741 object->parentDevice = iface;
742 *ppIndexBuffer = (LPDIRECT3DINDEXBUFFER8)object;
744 return hrc;
747 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) {
748 HRESULT hrc;
749 IDirect3DSurface8Impl *object;
750 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
751 TRACE("(%p) Relay\n", This);
753 if(MultisampleQuality > 0){
754 FIXME("MultisampleQuality set to %d, substituting 0\n" , MultisampleQuality);
756 MultisampleQuality
757 [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.
759 MultisampleQuality=0;
761 /*FIXME: Check MAX bounds of MultisampleQuality*/
763 /* Allocate the storage for the device */
764 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface8Impl));
765 if (NULL == object) {
766 FIXME("Allocation of memory failed\n");
767 *ppSurface = NULL;
768 return D3DERR_OUTOFVIDEOMEMORY;
771 object->lpVtbl = &Direct3DSurface8_Vtbl;
772 object->ref = 1;
774 TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
776 /* Not called from the VTable, no locking needed */
777 hrc = IWineD3DDevice_CreateSurface(This->WineD3DDevice, Width, Height, wined3dformat_from_d3dformat(Format),
778 Lockable, Discard, Level, &object->wineD3DSurface, Type, Usage & WINED3DUSAGE_MASK,
779 (WINED3DPOOL)Pool, MultiSample,MultisampleQuality, NULL, SURFACE_OPENGL, (IUnknown *)object);
780 if (hrc != D3D_OK || NULL == object->wineD3DSurface) {
781 /* free up object */
782 FIXME("(%p) call to IWineD3DDevice_CreateSurface failed\n", This);
783 HeapFree(GetProcessHeap(), 0, object);
784 *ppSurface = NULL;
785 } else {
786 IUnknown_AddRef(iface);
787 object->parentDevice = iface;
788 *ppSurface = (LPDIRECT3DSURFACE8) object;
790 return hrc;
793 static HRESULT WINAPI IDirect3DDevice8Impl_CreateRenderTarget(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, BOOL Lockable, IDirect3DSurface8** ppSurface) {
794 HRESULT hr;
795 TRACE("Relay\n");
797 EnterCriticalSection(&d3d8_cs);
798 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, Lockable, FALSE /* Discard */, 0 /* Level */ , ppSurface, D3DRTYPE_SURFACE, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, MultiSample, 0);
799 LeaveCriticalSection(&d3d8_cs);
800 return hr;
803 static HRESULT WINAPI IDirect3DDevice8Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, IDirect3DSurface8** ppSurface) {
804 HRESULT hr;
805 TRACE("Relay\n");
807 /* TODO: Verify that Discard is false */
808 EnterCriticalSection(&d3d8_cs);
809 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE, 0 /* Level */
810 ,ppSurface, D3DRTYPE_SURFACE, D3DUSAGE_DEPTHSTENCIL,
811 D3DPOOL_DEFAULT, MultiSample, 0);
812 LeaveCriticalSection(&d3d8_cs);
813 return hr;
816 /* IDirect3DDevice8Impl::CreateImageSurface returns surface with pool type SYSTEMMEM */
817 static HRESULT WINAPI IDirect3DDevice8Impl_CreateImageSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, IDirect3DSurface8** ppSurface) {
818 HRESULT hr;
819 TRACE("Relay\n");
821 EnterCriticalSection(&d3d8_cs);
822 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Loackable */ , FALSE /*Discard*/ , 0 /* Level */ , ppSurface,
823 D3DRTYPE_SURFACE, 0 /* Usage (undefined/none) */ , D3DPOOL_SYSTEMMEM, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
824 LeaveCriticalSection(&d3d8_cs);
825 return hr;
828 static HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8 *pSourceSurface, CONST RECT *pSourceRects, UINT cRects, IDirect3DSurface8 *pDestinationSurface, CONST POINT *pDestPoints) {
829 IDirect3DSurface8Impl *Source = (IDirect3DSurface8Impl *) pSourceSurface;
830 IDirect3DSurface8Impl *Dest = (IDirect3DSurface8Impl *) pDestinationSurface;
832 HRESULT hr = WINED3D_OK;
833 WINED3DFORMAT srcFormat, destFormat;
834 UINT srcWidth, destWidth;
835 UINT srcHeight, destHeight;
836 UINT srcSize;
837 WINED3DSURFACE_DESC winedesc;
839 TRACE("(%p) pSrcSur=%p, pSourceRects=%p, cRects=%d, pDstSur=%p, pDestPtsArr=%p\n", iface,
840 pSourceSurface, pSourceRects, cRects, pDestinationSurface, pDestPoints);
843 /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the destination texture is in WINED3DPOOL_DEFAULT */
844 memset(&winedesc, 0, sizeof(winedesc));
846 winedesc.Format = &srcFormat;
847 winedesc.Width = &srcWidth;
848 winedesc.Height = &srcHeight;
849 winedesc.Size = &srcSize;
850 IWineD3DSurface_GetDesc(Source->wineD3DSurface, &winedesc);
852 winedesc.Format = &destFormat;
853 winedesc.Width = &destWidth;
854 winedesc.Height = &destHeight;
855 winedesc.Size = NULL;
856 EnterCriticalSection(&d3d8_cs);
857 IWineD3DSurface_GetDesc(Dest->wineD3DSurface, &winedesc);
859 /* Check that the source and destination formats match */
860 if (srcFormat != destFormat && WINED3DFMT_UNKNOWN != destFormat) {
861 WARN("(%p) source %p format must match the dest %p format, returning WINED3DERR_INVALIDCALL\n", iface, pSourceSurface, pDestinationSurface);
862 LeaveCriticalSection(&d3d8_cs);
863 return WINED3DERR_INVALIDCALL;
864 } else if (WINED3DFMT_UNKNOWN == destFormat) {
865 TRACE("(%p) : Converting destination surface from WINED3DFMT_UNKNOWN to the source format\n", iface);
866 IWineD3DSurface_SetFormat(Dest->wineD3DSurface, srcFormat);
867 destFormat = srcFormat;
870 /* Quick if complete copy ... */
871 if (cRects == 0 && pSourceRects == NULL && pDestPoints == NULL) {
872 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
873 } else {
874 unsigned int i;
875 /* Copy rect by rect */
876 if (NULL != pSourceRects && NULL != pDestPoints) {
877 for (i = 0; i < cRects; ++i) {
878 IWineD3DSurface_BltFast(Dest->wineD3DSurface, pDestPoints[i].x, pDestPoints[i].y, Source->wineD3DSurface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
880 } else {
881 for (i = 0; i < cRects; ++i) {
882 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
886 LeaveCriticalSection(&d3d8_cs);
888 return hr;
891 static HRESULT WINAPI IDirect3DDevice8Impl_UpdateTexture(LPDIRECT3DDEVICE8 iface, IDirect3DBaseTexture8* pSourceTexture, IDirect3DBaseTexture8* pDestinationTexture) {
892 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
893 HRESULT hr;
894 TRACE("(%p) Relay\n" , This);
896 EnterCriticalSection(&d3d8_cs);
897 hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice, ((IDirect3DBaseTexture8Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture8Impl *)pDestinationTexture)->wineD3DBaseTexture);
898 LeaveCriticalSection(&d3d8_cs);
899 return hr;
902 static HRESULT WINAPI IDirect3DDevice8Impl_GetFrontBuffer(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pDestSurface) {
903 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
904 IDirect3DSurface8Impl *destSurface = (IDirect3DSurface8Impl *)pDestSurface;
905 HRESULT hr;
907 TRACE("(%p) Relay\n" , This);
909 if (pDestSurface == NULL) {
910 WARN("(%p) : Caller passed NULL as pDestSurface returning D3DERR_INVALIDCALL\n", This);
911 return D3DERR_INVALIDCALL;
914 EnterCriticalSection(&d3d8_cs);
915 hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, 0, destSurface->wineD3DSurface);
916 LeaveCriticalSection(&d3d8_cs);
917 return hr;
920 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pRenderTarget, IDirect3DSurface8* pNewZStencil) {
921 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
922 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl *)pRenderTarget;
923 IDirect3DSurface8Impl *pZSurface = (IDirect3DSurface8Impl *)pNewZStencil;
924 IWineD3DSurface *original_ds = NULL;
925 HRESULT hr;
926 TRACE("(%p) Relay\n" , This);
928 EnterCriticalSection(&d3d8_cs);
930 hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice, &original_ds);
931 if (hr == WINED3D_OK || hr == WINED3DERR_NOTFOUND)
933 hr = IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, pZSurface ? pZSurface->wineD3DSurface : NULL);
934 if (SUCCEEDED(hr) && pSurface)
935 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, 0, pSurface->wineD3DSurface);
936 if (FAILED(hr)) IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, original_ds);
938 if (original_ds) IWineD3DSurface_Release(original_ds);
940 LeaveCriticalSection(&d3d8_cs);
941 return hr;
944 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppRenderTarget) {
945 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
946 HRESULT hr = D3D_OK;
947 IWineD3DSurface *pRenderTarget;
949 TRACE("(%p) Relay\n" , This);
951 if (ppRenderTarget == NULL) {
952 return D3DERR_INVALIDCALL;
954 EnterCriticalSection(&d3d8_cs);
955 hr = IWineD3DDevice_GetRenderTarget(This->WineD3DDevice, 0, &pRenderTarget);
957 if (hr == D3D_OK && pRenderTarget != NULL) {
958 IWineD3DSurface_GetParent(pRenderTarget,(IUnknown**)ppRenderTarget);
959 IWineD3DSurface_Release(pRenderTarget);
960 } else {
961 FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
962 *ppRenderTarget = NULL;
964 LeaveCriticalSection(&d3d8_cs);
966 return hr;
969 static HRESULT WINAPI IDirect3DDevice8Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppZStencilSurface) {
970 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
971 HRESULT hr = D3D_OK;
972 IWineD3DSurface *pZStencilSurface;
974 TRACE("(%p) Relay\n" , This);
975 if(ppZStencilSurface == NULL){
976 return D3DERR_INVALIDCALL;
979 EnterCriticalSection(&d3d8_cs);
980 hr=IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
981 if (hr == WINED3D_OK) {
982 IWineD3DSurface_GetParent(pZStencilSurface,(IUnknown**)ppZStencilSurface);
983 IWineD3DSurface_Release(pZStencilSurface);
984 }else{
985 if (hr != WINED3DERR_NOTFOUND)
986 FIXME("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
987 *ppZStencilSurface = NULL;
989 LeaveCriticalSection(&d3d8_cs);
991 return hr;
994 static HRESULT WINAPI IDirect3DDevice8Impl_BeginScene(LPDIRECT3DDEVICE8 iface) {
995 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
996 HRESULT hr;
997 TRACE("(%p) Relay\n" , This);
999 EnterCriticalSection(&d3d8_cs);
1000 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
1001 LeaveCriticalSection(&d3d8_cs);
1002 return hr;
1005 static HRESULT WINAPI IDirect3DDevice8Impl_EndScene(LPDIRECT3DDEVICE8 iface) {
1006 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1007 HRESULT hr;
1008 TRACE("(%p) Relay\n" , This);
1010 EnterCriticalSection(&d3d8_cs);
1011 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
1012 LeaveCriticalSection(&d3d8_cs);
1013 return hr;
1016 static HRESULT WINAPI IDirect3DDevice8Impl_Clear(LPDIRECT3DDEVICE8 iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
1017 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1018 HRESULT hr;
1019 TRACE("(%p) Relay\n" , This);
1021 /* Note: D3DRECT is compatible with WINED3DRECT */
1022 EnterCriticalSection(&d3d8_cs);
1023 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (CONST WINED3DRECT*) pRects, Flags, Color, Z, Stencil);
1024 LeaveCriticalSection(&d3d8_cs);
1025 return hr;
1028 static HRESULT WINAPI IDirect3DDevice8Impl_SetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
1029 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1030 HRESULT hr;
1031 TRACE("(%p) Relay\n" , This);
1033 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1034 EnterCriticalSection(&d3d8_cs);
1035 hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
1036 LeaveCriticalSection(&d3d8_cs);
1037 return hr;
1040 static HRESULT WINAPI IDirect3DDevice8Impl_GetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State,D3DMATRIX* pMatrix) {
1041 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1042 HRESULT hr;
1043 TRACE("(%p) Relay\n" , This);
1045 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1046 EnterCriticalSection(&d3d8_cs);
1047 hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
1048 LeaveCriticalSection(&d3d8_cs);
1049 return hr;
1052 static HRESULT WINAPI IDirect3DDevice8Impl_MultiplyTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
1053 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1054 HRESULT hr;
1055 TRACE("(%p) Relay\n" , This);
1057 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1058 EnterCriticalSection(&d3d8_cs);
1059 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
1060 LeaveCriticalSection(&d3d8_cs);
1061 return hr;
1064 static HRESULT WINAPI IDirect3DDevice8Impl_SetViewport(LPDIRECT3DDEVICE8 iface, CONST D3DVIEWPORT8* pViewport) {
1065 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1066 HRESULT hr;
1067 TRACE("(%p) Relay\n" , This);
1069 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1070 EnterCriticalSection(&d3d8_cs);
1071 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
1072 LeaveCriticalSection(&d3d8_cs);
1073 return hr;
1076 static HRESULT WINAPI IDirect3DDevice8Impl_GetViewport(LPDIRECT3DDEVICE8 iface, D3DVIEWPORT8* pViewport) {
1077 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1078 HRESULT hr;
1079 TRACE("(%p) Relay\n" , This);
1081 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1082 EnterCriticalSection(&d3d8_cs);
1083 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
1084 LeaveCriticalSection(&d3d8_cs);
1085 return hr;
1088 static HRESULT WINAPI IDirect3DDevice8Impl_SetMaterial(LPDIRECT3DDEVICE8 iface, CONST D3DMATERIAL8* pMaterial) {
1089 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1090 HRESULT hr;
1091 TRACE("(%p) Relay\n" , This);
1093 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1094 EnterCriticalSection(&d3d8_cs);
1095 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
1096 LeaveCriticalSection(&d3d8_cs);
1097 return hr;
1100 static HRESULT WINAPI IDirect3DDevice8Impl_GetMaterial(LPDIRECT3DDEVICE8 iface, D3DMATERIAL8* pMaterial) {
1101 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1102 HRESULT hr;
1103 TRACE("(%p) Relay\n" , This);
1105 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1106 EnterCriticalSection(&d3d8_cs);
1107 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
1108 LeaveCriticalSection(&d3d8_cs);
1109 return hr;
1112 static HRESULT WINAPI IDirect3DDevice8Impl_SetLight(LPDIRECT3DDEVICE8 iface, DWORD Index, CONST D3DLIGHT8* pLight) {
1113 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1114 HRESULT hr;
1115 TRACE("(%p) Relay\n" , This);
1117 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1118 EnterCriticalSection(&d3d8_cs);
1119 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
1120 LeaveCriticalSection(&d3d8_cs);
1121 return hr;
1124 static HRESULT WINAPI IDirect3DDevice8Impl_GetLight(LPDIRECT3DDEVICE8 iface, DWORD Index,D3DLIGHT8* pLight) {
1125 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1126 HRESULT hr;
1127 TRACE("(%p) Relay\n" , This);
1129 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1130 EnterCriticalSection(&d3d8_cs);
1131 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1132 LeaveCriticalSection(&d3d8_cs);
1133 return hr;
1136 static HRESULT WINAPI IDirect3DDevice8Impl_LightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL Enable) {
1137 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1138 HRESULT hr;
1139 TRACE("(%p) Relay\n" , This);
1141 EnterCriticalSection(&d3d8_cs);
1142 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1143 LeaveCriticalSection(&d3d8_cs);
1144 return hr;
1147 static HRESULT WINAPI IDirect3DDevice8Impl_GetLightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL* pEnable) {
1148 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1149 HRESULT hr;
1150 TRACE("(%p) Relay\n" , This);
1152 EnterCriticalSection(&d3d8_cs);
1153 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1154 LeaveCriticalSection(&d3d8_cs);
1155 return hr;
1158 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,CONST float* pPlane) {
1159 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1160 HRESULT hr;
1161 TRACE("(%p) Relay\n" , This);
1163 EnterCriticalSection(&d3d8_cs);
1164 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1165 LeaveCriticalSection(&d3d8_cs);
1166 return hr;
1169 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,float* pPlane) {
1170 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1171 HRESULT hr;
1172 TRACE("(%p) Relay\n" , This);
1174 EnterCriticalSection(&d3d8_cs);
1175 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1176 LeaveCriticalSection(&d3d8_cs);
1177 return hr;
1180 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD Value) {
1181 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1182 HRESULT hr;
1183 TRACE("(%p) Relay\n" , This);
1185 EnterCriticalSection(&d3d8_cs);
1186 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1187 LeaveCriticalSection(&d3d8_cs);
1188 return hr;
1191 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD* pValue) {
1192 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1193 HRESULT hr;
1194 TRACE("(%p) Relay\n" , This);
1196 EnterCriticalSection(&d3d8_cs);
1197 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1198 LeaveCriticalSection(&d3d8_cs);
1199 return hr;
1202 static HRESULT WINAPI IDirect3DDevice8Impl_BeginStateBlock(LPDIRECT3DDEVICE8 iface) {
1203 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1204 HRESULT hr;
1205 TRACE("(%p)\n", This);
1207 EnterCriticalSection(&d3d8_cs);
1208 hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
1209 LeaveCriticalSection(&d3d8_cs);
1210 return hr;
1213 static HRESULT WINAPI IDirect3DDevice8Impl_EndStateBlock(LPDIRECT3DDEVICE8 iface, DWORD* pToken) {
1214 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1215 HRESULT hr;
1216 IWineD3DStateBlock* wineD3DStateBlock;
1217 IDirect3DStateBlock8Impl* object;
1219 TRACE("(%p) Relay\n", This);
1221 /* Tell wineD3D to endstateblock before anything else (in case we run out
1222 * of memory later and cause locking problems)
1224 EnterCriticalSection(&d3d8_cs);
1225 hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice , &wineD3DStateBlock);
1226 if (hr != D3D_OK) {
1227 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
1228 LeaveCriticalSection(&d3d8_cs);
1229 return hr;
1232 /* allocate a new IDirectD3DStateBlock */
1233 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY ,sizeof(IDirect3DStateBlock8Impl));
1234 object->ref = 1;
1235 object->lpVtbl = &Direct3DStateBlock8_Vtbl;
1237 object->wineD3DStateBlock = wineD3DStateBlock;
1239 *pToken = (DWORD)object;
1240 TRACE("(%p)Returning %p %p\n", This, object, wineD3DStateBlock);
1242 LeaveCriticalSection(&d3d8_cs);
1243 return hr;
1246 static HRESULT WINAPI IDirect3DDevice8Impl_ApplyStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1247 IDirect3DStateBlock8Impl *pSB = (IDirect3DStateBlock8Impl*) Token;
1248 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1249 HRESULT hr;
1251 TRACE("(%p) %p Relay\n", This, pSB);
1253 EnterCriticalSection(&d3d8_cs);
1254 hr = IWineD3DStateBlock_Apply(pSB->wineD3DStateBlock);
1255 LeaveCriticalSection(&d3d8_cs);
1256 return hr;
1259 static HRESULT WINAPI IDirect3DDevice8Impl_CaptureStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1260 IDirect3DStateBlock8Impl* pSB = (IDirect3DStateBlock8Impl *)Token;
1261 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1262 HRESULT hr;
1264 TRACE("(%p) %p Relay\n", This, pSB);
1266 EnterCriticalSection(&d3d8_cs);
1267 hr = IWineD3DStateBlock_Capture(pSB->wineD3DStateBlock);
1268 LeaveCriticalSection(&d3d8_cs);
1269 return hr;
1272 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1273 IDirect3DStateBlock8Impl* pSB = (IDirect3DStateBlock8Impl *)Token;
1274 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1276 TRACE("(%p) Relay\n", This);
1278 EnterCriticalSection(&d3d8_cs);
1279 while(IUnknown_Release((IUnknown *)pSB));
1280 LeaveCriticalSection(&d3d8_cs);
1282 return D3D_OK;
1285 static HRESULT WINAPI IDirect3DDevice8Impl_CreateStateBlock(LPDIRECT3DDEVICE8 iface, D3DSTATEBLOCKTYPE Type, DWORD* pToken) {
1286 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1287 IDirect3DStateBlock8Impl *object;
1288 HRESULT hrc = D3D_OK;
1290 TRACE("(%p) Relay\n", This);
1292 if(Type != D3DSBT_ALL && Type != D3DSBT_PIXELSTATE &&
1293 Type != D3DSBT_VERTEXSTATE ) {
1294 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1295 return D3DERR_INVALIDCALL;
1298 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DStateBlock8Impl));
1299 if (NULL == object) {
1300 *pToken = 0;
1301 return E_OUTOFMEMORY;
1303 object->lpVtbl = &Direct3DStateBlock8_Vtbl;
1304 object->ref = 1;
1306 EnterCriticalSection(&d3d8_cs);
1307 hrc = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type, &object->wineD3DStateBlock, (IUnknown *)object);
1308 LeaveCriticalSection(&d3d8_cs);
1309 if(D3D_OK != hrc){
1310 FIXME("(%p) Call to IWineD3DDevice_CreateStateBlock failed.\n", This);
1311 HeapFree(GetProcessHeap(), 0, object);
1312 *pToken = 0;
1313 } else {
1314 *pToken = (DWORD)object;
1315 TRACE("(%p) returning token (ptr to stateblock) of %p\n", This, object);
1318 return hrc;
1321 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipStatus(LPDIRECT3DDEVICE8 iface, CONST D3DCLIPSTATUS8* pClipStatus) {
1322 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1323 HRESULT hr;
1324 TRACE("(%p) Relay\n" , This);
1325 /* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
1326 EnterCriticalSection(&d3d8_cs);
1327 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1328 LeaveCriticalSection(&d3d8_cs);
1329 return hr;
1332 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipStatus(LPDIRECT3DDEVICE8 iface, D3DCLIPSTATUS8* pClipStatus) {
1333 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1334 HRESULT hr;
1335 TRACE("(%p) Relay\n" , This);
1337 EnterCriticalSection(&d3d8_cs);
1338 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1339 LeaveCriticalSection(&d3d8_cs);
1340 return hr;
1343 static HRESULT WINAPI IDirect3DDevice8Impl_GetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage,IDirect3DBaseTexture8** ppTexture) {
1344 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1345 IWineD3DBaseTexture *retTexture = NULL;
1346 HRESULT rc = D3D_OK;
1348 TRACE("(%p) Relay\n" , This);
1350 if(ppTexture == NULL){
1351 return D3DERR_INVALIDCALL;
1354 EnterCriticalSection(&d3d8_cs);
1355 rc = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
1356 if (rc == D3D_OK && NULL != retTexture) {
1357 IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
1358 IWineD3DBaseTexture_Release(retTexture);
1359 } else {
1360 FIXME("Call to get texture (%d) failed (%p)\n", Stage, retTexture);
1361 *ppTexture = NULL;
1363 LeaveCriticalSection(&d3d8_cs);
1365 return rc;
1368 static HRESULT WINAPI IDirect3DDevice8Impl_SetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage, IDirect3DBaseTexture8* pTexture) {
1369 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1370 HRESULT hr;
1371 TRACE("(%p) Relay %d %p\n" , This, Stage, pTexture);
1373 EnterCriticalSection(&d3d8_cs);
1374 hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
1375 pTexture==NULL ? NULL : ((IDirect3DBaseTexture8Impl *)pTexture)->wineD3DBaseTexture);
1376 LeaveCriticalSection(&d3d8_cs);
1377 return hr;
1380 static const struct tss_lookup
1382 BOOL sampler_state;
1383 DWORD state;
1385 tss_lookup[] =
1387 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 0, unused */
1388 {FALSE, WINED3DTSS_COLOROP}, /* 1, D3DTSS_COLOROP */
1389 {FALSE, WINED3DTSS_COLORARG1}, /* 2, D3DTSS_COLORARG1 */
1390 {FALSE, WINED3DTSS_COLORARG2}, /* 3, D3DTSS_COLORARG2 */
1391 {FALSE, WINED3DTSS_ALPHAOP}, /* 4, D3DTSS_ALPHAOP */
1392 {FALSE, WINED3DTSS_ALPHAARG1}, /* 5, D3DTSS_ALPHAARG1 */
1393 {FALSE, WINED3DTSS_ALPHAARG2}, /* 6, D3DTSS_ALPHAARG2 */
1394 {FALSE, WINED3DTSS_BUMPENVMAT00}, /* 7, D3DTSS_BUMPENVMAT00 */
1395 {FALSE, WINED3DTSS_BUMPENVMAT01}, /* 8, D3DTSS_BUMPENVMAT01 */
1396 {FALSE, WINED3DTSS_BUMPENVMAT10}, /* 9, D3DTSS_BUMPENVMAT10 */
1397 {FALSE, WINED3DTSS_BUMPENVMAT11}, /* 10, D3DTSS_BUMPENVMAT11 */
1398 {FALSE, WINED3DTSS_TEXCOORDINDEX}, /* 11, D3DTSS_TEXCOORDINDEX */
1399 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 12, unused */
1400 {TRUE, WINED3DSAMP_ADDRESSU}, /* 13, D3DTSS_ADDRESSU */
1401 {TRUE, WINED3DSAMP_ADDRESSV}, /* 14, D3DTSS_ADDRESSV */
1402 {TRUE, WINED3DSAMP_BORDERCOLOR}, /* 15, D3DTSS_BORDERCOLOR */
1403 {TRUE, WINED3DSAMP_MAGFILTER}, /* 16, D3DTSS_MAGFILTER */
1404 {TRUE, WINED3DSAMP_MINFILTER}, /* 17, D3DTSS_MINFILTER */
1405 {TRUE, WINED3DSAMP_MIPFILTER}, /* 18, D3DTSS_MIPFILTER */
1406 {TRUE, WINED3DSAMP_MIPMAPLODBIAS}, /* 19, D3DTSS_MIPMAPLODBIAS */
1407 {TRUE, WINED3DSAMP_MAXMIPLEVEL}, /* 20, D3DTSS_MAXMIPLEVEL */
1408 {TRUE, WINED3DSAMP_MAXANISOTROPY}, /* 21, D3DTSS_MAXANISOTROPY */
1409 {FALSE, WINED3DTSS_BUMPENVLSCALE}, /* 22, D3DTSS_BUMPENVLSCALE */
1410 {FALSE, WINED3DTSS_BUMPENVLOFFSET}, /* 23, D3DTSS_BUMPENVLOFFSET */
1411 {FALSE, WINED3DTSS_TEXTURETRANSFORMFLAGS}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1412 {TRUE, WINED3DSAMP_ADDRESSW}, /* 25, D3DTSS_ADDRESSW */
1413 {FALSE, WINED3DTSS_COLORARG0}, /* 26, D3DTSS_COLORARG0 */
1414 {FALSE, WINED3DTSS_ALPHAARG0}, /* 27, D3DTSS_ALPHAARG0 */
1415 {FALSE, WINED3DTSS_RESULTARG}, /* 28, D3DTSS_RESULTARG */
1418 static HRESULT WINAPI IDirect3DDevice8Impl_GetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD* pValue) {
1419 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1420 const struct tss_lookup *l = &tss_lookup[Type];
1421 HRESULT hr;
1422 TRACE("(%p) Relay\n" , This);
1424 EnterCriticalSection(&d3d8_cs);
1426 if (l->sampler_state) hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Stage, l->state, pValue);
1427 else hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, l->state, pValue);
1429 LeaveCriticalSection(&d3d8_cs);
1430 return hr;
1433 static HRESULT WINAPI IDirect3DDevice8Impl_SetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
1434 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1435 const struct tss_lookup *l = &tss_lookup[Type];
1436 HRESULT hr;
1437 TRACE("(%p) Relay\n" , This);
1439 EnterCriticalSection(&d3d8_cs);
1441 if (l->sampler_state) hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Stage, l->state, Value);
1442 else hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, l->state, Value);
1444 LeaveCriticalSection(&d3d8_cs);
1445 return hr;
1448 static HRESULT WINAPI IDirect3DDevice8Impl_ValidateDevice(LPDIRECT3DDEVICE8 iface, DWORD* pNumPasses) {
1449 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1450 HRESULT hr;
1451 TRACE("(%p) Relay\n" , This);
1453 EnterCriticalSection(&d3d8_cs);
1454 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1455 LeaveCriticalSection(&d3d8_cs);
1456 return hr;
1459 static HRESULT WINAPI IDirect3DDevice8Impl_GetInfo(LPDIRECT3DDEVICE8 iface, DWORD DevInfoID, void* pDevInfoStruct, DWORD DevInfoStructSize) {
1460 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1461 FIXME("(%p) : stub\n", This);
1462 return D3D_OK;
1465 static HRESULT WINAPI IDirect3DDevice8Impl_SetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, CONST PALETTEENTRY* pEntries) {
1466 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1467 HRESULT hr;
1468 TRACE("(%p) Relay\n" , This);
1470 EnterCriticalSection(&d3d8_cs);
1471 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1472 LeaveCriticalSection(&d3d8_cs);
1473 return hr;
1476 static HRESULT WINAPI IDirect3DDevice8Impl_GetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
1477 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1478 HRESULT hr;
1479 TRACE("(%p) Relay\n" , This);
1481 EnterCriticalSection(&d3d8_cs);
1482 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1483 LeaveCriticalSection(&d3d8_cs);
1484 return hr;
1487 static HRESULT WINAPI IDirect3DDevice8Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber) {
1488 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1489 HRESULT hr;
1490 TRACE("(%p) Relay\n" , This);
1492 EnterCriticalSection(&d3d8_cs);
1493 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1494 LeaveCriticalSection(&d3d8_cs);
1495 return hr;
1498 static HRESULT WINAPI IDirect3DDevice8Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT *PaletteNumber) {
1499 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1500 HRESULT hr;
1501 TRACE("(%p) Relay\n" , This);
1503 EnterCriticalSection(&d3d8_cs);
1504 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1505 LeaveCriticalSection(&d3d8_cs);
1506 return hr;
1509 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitive(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) {
1510 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1511 HRESULT hr;
1512 TRACE("(%p) Relay\n" , This);
1514 EnterCriticalSection(&d3d8_cs);
1515 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, PrimitiveType, StartVertex, PrimitiveCount);
1516 LeaveCriticalSection(&d3d8_cs);
1517 return hr;
1520 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,
1521 UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount) {
1522 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1523 HRESULT hr;
1524 TRACE("(%p) Relay\n" , This);
1526 EnterCriticalSection(&d3d8_cs);
1527 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, PrimitiveType, MinVertexIndex, NumVertices, startIndex, primCount);
1528 LeaveCriticalSection(&d3d8_cs);
1529 return hr;
1532 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT PrimitiveCount,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride) {
1533 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1534 HRESULT hr;
1535 TRACE("(%p) Relay\n" , This);
1537 EnterCriticalSection(&d3d8_cs);
1538 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
1539 LeaveCriticalSection(&d3d8_cs);
1540 return hr;
1543 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,
1544 UINT NumVertexIndices,UINT PrimitiveCount,CONST void* pIndexData,
1545 D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,
1546 UINT VertexStreamZeroStride) {
1547 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1548 HRESULT hr;
1549 TRACE("(%p) Relay\n" , This);
1551 EnterCriticalSection(&d3d8_cs);
1552 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice, PrimitiveType, MinVertexIndex,
1553 NumVertexIndices, PrimitiveCount, pIndexData, wined3dformat_from_d3dformat(IndexDataFormat),
1554 pVertexStreamZeroData, VertexStreamZeroStride);
1555 LeaveCriticalSection(&d3d8_cs);
1556 return hr;
1559 static HRESULT WINAPI IDirect3DDevice8Impl_ProcessVertices(LPDIRECT3DDEVICE8 iface, UINT SrcStartIndex,UINT DestIndex,UINT VertexCount,IDirect3DVertexBuffer8* pDestBuffer,DWORD Flags) {
1560 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1561 HRESULT hr;
1562 TRACE("(%p) Relay\n" , This);
1564 EnterCriticalSection(&d3d8_cs);
1565 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, ((IDirect3DVertexBuffer8Impl *)pDestBuffer)->wineD3DVertexBuffer, NULL, Flags);
1566 LeaveCriticalSection(&d3d8_cs);
1567 return hr;
1570 static HRESULT IDirect3DDevice8Impl_CreateVertexDeclaration(IDirect3DDevice8 *iface, CONST DWORD *declaration, IDirect3DVertexDeclaration8 **decl_ptr) {
1571 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1572 IDirect3DVertexDeclaration8Impl *object;
1573 WINED3DVERTEXELEMENT *wined3d_elements;
1574 UINT wined3d_element_count;
1575 HRESULT hr = D3D_OK;
1577 TRACE("(%p) : declaration %p\n", This, declaration);
1579 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1580 if (!object) {
1581 ERR("Memory allocation failed\n");
1582 *decl_ptr = NULL;
1583 return D3DERR_OUTOFVIDEOMEMORY;
1586 object->ref_count = 1;
1587 object->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
1589 wined3d_element_count = convert_to_wined3d_declaration(declaration, &object->elements_size, &wined3d_elements);
1590 object->elements = HeapAlloc(GetProcessHeap(), 0, object->elements_size);
1591 if (!object->elements) {
1592 ERR("Memory allocation failed\n");
1593 HeapFree(GetProcessHeap(), 0, wined3d_elements);
1594 HeapFree(GetProcessHeap(), 0, object);
1595 *decl_ptr = NULL;
1596 return D3DERR_OUTOFVIDEOMEMORY;
1599 CopyMemory(object->elements, declaration, object->elements_size);
1601 EnterCriticalSection(&d3d8_cs);
1602 hr = IWineD3DDevice_CreateVertexDeclaration(This->WineD3DDevice, &object->wined3d_vertex_declaration,
1603 (IUnknown *)object, wined3d_elements, wined3d_element_count);
1604 LeaveCriticalSection(&d3d8_cs);
1605 HeapFree(GetProcessHeap(), 0, wined3d_elements);
1607 if (FAILED(hr)) {
1608 ERR("(%p) : IWineD3DDevice_CreateVertexDeclaration call failed\n", This);
1609 HeapFree(GetProcessHeap(), 0, object->elements);
1610 HeapFree(GetProcessHeap(), 0, object);
1611 } else {
1612 *decl_ptr = (IDirect3DVertexDeclaration8 *)object;
1613 TRACE("(%p) : Created vertex declaration %p\n", This, object);
1616 return hr;
1619 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pDeclaration, CONST DWORD* pFunction, DWORD* ppShader, DWORD Usage) {
1620 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1621 HRESULT hrc = D3D_OK;
1622 IDirect3DVertexShader8Impl *object;
1623 IWineD3DVertexDeclaration *wined3d_vertex_declaration;
1624 const DWORD *token = pDeclaration;
1625 shader_handle *handle;
1627 /* Test if the vertex declaration is valid */
1628 while (D3DVSD_END() != *token) {
1629 D3DVSD_TOKENTYPE token_type = ((*token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT);
1631 if (token_type == D3DVSD_TOKEN_STREAMDATA && !(token_type & 0x10000000)) {
1632 DWORD type = ((*token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
1633 DWORD reg = ((*token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
1635 if(reg == D3DVSDE_NORMAL && type != D3DVSDT_FLOAT3 && !pFunction) {
1636 WARN("Attempt to use a non-FLOAT3 normal with the fixed function function\n");
1637 return D3DERR_INVALIDCALL;
1640 token += parse_token(token);
1643 /* Setup a stub object for now */
1644 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1645 TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
1646 if (NULL == object) {
1647 FIXME("Allocation of memory failed\n");
1648 *ppShader = 0;
1649 return D3DERR_OUTOFVIDEOMEMORY;
1652 object->ref = 1;
1653 object->lpVtbl = &Direct3DVertexShader8_Vtbl;
1655 EnterCriticalSection(&d3d8_cs);
1656 hrc = IDirect3DDevice8Impl_CreateVertexDeclaration(iface, pDeclaration, &object->vertex_declaration);
1657 if (FAILED(hrc)) {
1658 ERR("(%p) : IDirect3DDeviceImpl_CreateVertexDeclaration call failed\n", This);
1659 LeaveCriticalSection(&d3d8_cs);
1660 HeapFree(GetProcessHeap(), 0, object);
1661 *ppShader = 0;
1662 return D3DERR_INVALIDCALL;
1665 handle = alloc_shader_handle(This);
1666 if (!handle)
1668 ERR("Failed to allocate shader handle\n");
1669 LeaveCriticalSection(&d3d8_cs);
1670 IDirect3DVertexDeclaration8_Release(object->vertex_declaration);
1671 HeapFree(GetProcessHeap(), 0, object);
1672 *ppShader = 0;
1673 return E_OUTOFMEMORY;
1675 else
1677 DWORD shader_handle = (handle - This->shader_handles) + VS_HIGHESTFIXEDFXF + 1;
1678 *handle = object;
1679 *ppShader = ((IDirect3DVertexDeclaration8Impl *)object->vertex_declaration)->shader_handle = shader_handle;
1682 wined3d_vertex_declaration = ((IDirect3DVertexDeclaration8Impl *)object->vertex_declaration)->wined3d_vertex_declaration;
1684 if (pFunction)
1686 /* Usage is missing ... Use SetRenderState to set the sw vp render state in SetVertexShader */
1687 hrc = IWineD3DDevice_CreateVertexShader(This->WineD3DDevice, wined3d_vertex_declaration,
1688 pFunction, &object->wineD3DVertexShader, (IUnknown *)object);
1690 if (FAILED(hrc))
1692 /* free up object */
1693 FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n");
1694 free_shader_handle(This, handle);
1695 IDirect3DVertexDeclaration8_Release(object->vertex_declaration);
1696 HeapFree(GetProcessHeap(), 0, object);
1697 *ppShader = 0;
1699 else
1701 load_local_constants(pDeclaration, object->wineD3DVertexShader);
1702 TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
1706 LeaveCriticalSection(&d3d8_cs);
1708 return hrc;
1711 static IDirect3DVertexDeclaration8Impl *IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl *This, DWORD fvf)
1713 IDirect3DVertexDeclaration8Impl *d3d8_declaration;
1714 HRESULT hr;
1715 int p, low, high; /* deliberately signed */
1716 struct FvfToDecl *convertedDecls = This->decls;
1718 TRACE("Searching for declaration for fvf %08x... ", fvf);
1720 low = 0;
1721 high = This->numConvertedDecls - 1;
1722 while(low <= high) {
1723 p = (low + high) >> 1;
1724 TRACE("%d ", p);
1725 if(convertedDecls[p].fvf == fvf) {
1726 TRACE("found %p\n", convertedDecls[p].decl);
1727 return (IDirect3DVertexDeclaration8Impl *)convertedDecls[p].decl;
1728 } else if(convertedDecls[p].fvf < fvf) {
1729 low = p + 1;
1730 } else {
1731 high = p - 1;
1734 TRACE("not found. Creating and inserting at position %d.\n", low);
1736 d3d8_declaration = HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration));
1737 if (!d3d8_declaration)
1739 ERR("Memory allocation failed.\n");
1740 return NULL;
1743 d3d8_declaration->ref_count = 1;
1744 d3d8_declaration->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
1745 d3d8_declaration->elements = NULL;
1746 d3d8_declaration->elements_size = 0;
1747 d3d8_declaration->shader_handle = fvf;
1749 hr = IWineD3DDevice_CreateVertexDeclarationFromFVF(This->WineD3DDevice,
1750 &d3d8_declaration->wined3d_vertex_declaration, (IUnknown *)d3d8_declaration, fvf);
1751 if (FAILED(hr))
1753 ERR("Failed to create wined3d vertex declaration.\n");
1754 HeapFree(GetProcessHeap(), 0, d3d8_declaration);
1755 return NULL;
1758 if(This->declArraySize == This->numConvertedDecls) {
1759 int grow = This->declArraySize / 2;
1760 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
1761 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
1762 if(!convertedDecls) {
1763 /* This will destroy it */
1764 IDirect3DVertexDeclaration8_Release((IDirect3DVertexDeclaration8 *)d3d8_declaration);
1765 return NULL;
1767 This->decls = convertedDecls;
1768 This->declArraySize += grow;
1771 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(convertedDecls[0]) * (This->numConvertedDecls - low));
1772 convertedDecls[low].decl = (IDirect3DVertexDeclaration8 *)d3d8_declaration;
1773 convertedDecls[low].fvf = fvf;
1774 This->numConvertedDecls++;
1776 TRACE("Returning %p. %u decls in array\n", d3d8_declaration, This->numConvertedDecls);
1777 return d3d8_declaration;
1780 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1781 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1782 HRESULT hrc = D3D_OK;
1784 TRACE("(%p) : Relay\n", This);
1785 EnterCriticalSection(&d3d8_cs);
1786 if (VS_HIGHESTFIXEDFXF >= pShader) {
1787 TRACE("Setting FVF, %#x\n", pShader);
1788 IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
1789 IDirect3DDevice8Impl_FindDecl(This, pShader)->wined3d_vertex_declaration);
1790 IWineD3DDevice_SetVertexShader(This->WineD3DDevice, NULL);
1791 } else {
1792 TRACE("Setting shader\n");
1793 if (This->allocated_shader_handles <= pShader - (VS_HIGHESTFIXEDFXF + 1)) {
1794 FIXME("(%p) : Number of shaders exceeds the maximum number of possible shaders\n", This);
1795 hrc = D3DERR_INVALIDCALL;
1796 } else {
1797 IDirect3DVertexShader8Impl *shader = This->shader_handles[pShader - (VS_HIGHESTFIXEDFXF + 1)];
1799 if (shader)
1801 hrc = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
1802 ((IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration)->wined3d_vertex_declaration);
1803 if (SUCCEEDED(hrc))
1804 hrc = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, shader->wineD3DVertexShader);
1806 else
1808 hrc = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice, NULL);
1809 if (SUCCEEDED(hrc)) hrc = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, NULL);
1813 TRACE("(%p) : returning hr(%u)\n", This, hrc);
1814 LeaveCriticalSection(&d3d8_cs);
1816 return hrc;
1819 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
1820 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1821 IWineD3DVertexDeclaration *wined3d_declaration;
1822 HRESULT hrc;
1824 TRACE("(%p) : Relay device@%p\n", This, This->WineD3DDevice);
1825 EnterCriticalSection(&d3d8_cs);
1827 hrc = IWineD3DDevice_GetVertexDeclaration(This->WineD3DDevice, &wined3d_declaration);
1828 if (SUCCEEDED(hrc))
1830 if (wined3d_declaration)
1832 IDirect3DVertexDeclaration8 *d3d8_declaration;
1833 hrc = IWineD3DVertexDeclaration_GetParent(wined3d_declaration, (IUnknown **)&d3d8_declaration);
1834 IWineD3DVertexDeclaration_Release(wined3d_declaration);
1835 if (SUCCEEDED(hrc))
1837 *ppShader = ((IDirect3DVertexDeclaration8Impl *)d3d8_declaration)->shader_handle;
1838 IDirect3DVertexDeclaration8_Release(d3d8_declaration);
1841 else
1843 *ppShader = 0;
1844 hrc = D3D_OK;
1847 else
1849 WARN("(%p) : Call to IWineD3DDevice_GetVertexDeclaration failed %#x (device %p)\n",
1850 This, hrc, This->WineD3DDevice);
1852 TRACE("(%p) : returning %#x\n", This, *ppShader);
1853 LeaveCriticalSection(&d3d8_cs);
1855 return hrc;
1858 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1859 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1861 TRACE("(%p) : pShader %#x\n", This, pShader);
1863 EnterCriticalSection(&d3d8_cs);
1864 if (pShader <= VS_HIGHESTFIXEDFXF || This->allocated_shader_handles <= pShader - (VS_HIGHESTFIXEDFXF + 1)) {
1865 ERR("(%p) : Trying to delete an invalid handle\n", This);
1866 LeaveCriticalSection(&d3d8_cs);
1867 return D3DERR_INVALIDCALL;
1868 } else {
1869 IWineD3DVertexShader *cur = NULL;
1870 shader_handle *handle = &This->shader_handles[pShader - (VS_HIGHESTFIXEDFXF + 1)];
1871 IDirect3DVertexShader8Impl *shader = *handle;
1873 IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &cur);
1874 if(cur) {
1875 if(cur == shader->wineD3DVertexShader) IDirect3DDevice8_SetVertexShader(iface, 0);
1876 IWineD3DVertexShader_Release(cur);
1879 while(IUnknown_Release((IUnknown *)shader));
1880 free_shader_handle(This, handle);
1882 LeaveCriticalSection(&d3d8_cs);
1884 return D3D_OK;
1887 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
1888 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1889 HRESULT hr;
1890 TRACE("(%p) : Relay\n", This);
1892 EnterCriticalSection(&d3d8_cs);
1893 hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
1894 LeaveCriticalSection(&d3d8_cs);
1895 return hr;
1898 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
1899 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1900 HRESULT hr;
1901 TRACE("(%p) : Relay\n", This);
1903 EnterCriticalSection(&d3d8_cs);
1904 hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
1905 LeaveCriticalSection(&d3d8_cs);
1906 return hr;
1909 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderDeclaration(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
1910 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1911 IDirect3DVertexDeclaration8Impl *declaration;
1912 IDirect3DVertexShader8Impl *shader = NULL;
1914 TRACE("(%p) : pVertexShader 0x%08x, pData %p, *pSizeOfData %u\n", This, pVertexShader, pData, *pSizeOfData);
1916 EnterCriticalSection(&d3d8_cs);
1917 if (pVertexShader <= VS_HIGHESTFIXEDFXF || This->allocated_shader_handles <= pVertexShader - (VS_HIGHESTFIXEDFXF + 1)) {
1918 ERR("Passed an invalid shader handle.\n");
1919 LeaveCriticalSection(&d3d8_cs);
1920 return D3DERR_INVALIDCALL;
1923 shader = This->shader_handles[pVertexShader - (VS_HIGHESTFIXEDFXF + 1)];
1924 declaration = (IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration;
1926 /* If pData is NULL, we just return the required size of the buffer. */
1927 if (!pData) {
1928 *pSizeOfData = declaration->elements_size;
1929 LeaveCriticalSection(&d3d8_cs);
1930 return D3D_OK;
1933 /* MSDN claims that if *pSizeOfData is smaller than the required size
1934 * we should write the required size and return D3DERR_MOREDATA.
1935 * That's not actually true. */
1936 if (*pSizeOfData < declaration->elements_size) {
1937 LeaveCriticalSection(&d3d8_cs);
1938 return D3DERR_INVALIDCALL;
1941 CopyMemory(pData, declaration->elements, declaration->elements_size);
1942 LeaveCriticalSection(&d3d8_cs);
1944 return D3D_OK;
1947 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
1948 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1949 IDirect3DVertexShader8Impl *shader = NULL;
1950 HRESULT hr;
1952 TRACE("(%p) : pVertexShader %#x, pData %p, pSizeOfData %p\n", This, pVertexShader, pData, pSizeOfData);
1954 EnterCriticalSection(&d3d8_cs);
1955 if (pVertexShader <= VS_HIGHESTFIXEDFXF || This->allocated_shader_handles <= pVertexShader - (VS_HIGHESTFIXEDFXF + 1)) {
1956 ERR("Passed an invalid shader handle.\n");
1957 LeaveCriticalSection(&d3d8_cs);
1958 return D3DERR_INVALIDCALL;
1961 shader = This->shader_handles[pVertexShader - (VS_HIGHESTFIXEDFXF + 1)];
1962 if (shader->wineD3DVertexShader)
1964 hr = IWineD3DVertexShader_GetFunction(shader->wineD3DVertexShader, pData, pSizeOfData);
1966 else
1968 *pSizeOfData = 0;
1969 hr = D3D_OK;
1972 LeaveCriticalSection(&d3d8_cs);
1973 return hr;
1976 static HRESULT WINAPI IDirect3DDevice8Impl_SetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8* pIndexData, UINT baseVertexIndex) {
1977 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1978 HRESULT hr;
1979 TRACE("(%p) Relay\n", This);
1981 EnterCriticalSection(&d3d8_cs);
1982 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
1983 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
1984 * vertex buffers can't be created to address them with an index that requires the 32nd bit
1985 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
1986 * problem)
1988 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, baseVertexIndex);
1989 hr = IWineD3DDevice_SetIndices(This->WineD3DDevice,
1990 pIndexData ? ((IDirect3DIndexBuffer8Impl *)pIndexData)->wineD3DIndexBuffer : NULL);
1991 LeaveCriticalSection(&d3d8_cs);
1992 return hr;
1995 static HRESULT WINAPI IDirect3DDevice8Impl_GetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8** ppIndexData,UINT* pBaseVertexIndex) {
1996 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1997 IWineD3DIndexBuffer *retIndexData = NULL;
1998 HRESULT rc = D3D_OK;
2000 TRACE("(%p) Relay\n", This);
2002 if(ppIndexData == NULL){
2003 return D3DERR_INVALIDCALL;
2006 EnterCriticalSection(&d3d8_cs);
2007 /* The case from UINT to INT is safe because d3d8 will never set negative values */
2008 IWineD3DDevice_GetBaseVertexIndex(This->WineD3DDevice, (INT *) pBaseVertexIndex);
2009 rc = IWineD3DDevice_GetIndices(This->WineD3DDevice, &retIndexData);
2010 if (SUCCEEDED(rc) && retIndexData) {
2011 IWineD3DIndexBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
2012 IWineD3DIndexBuffer_Release(retIndexData);
2013 } else {
2014 if (FAILED(rc)) FIXME("Call to GetIndices failed\n");
2015 *ppIndexData = NULL;
2017 LeaveCriticalSection(&d3d8_cs);
2019 return rc;
2021 static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pFunction, DWORD* ppShader) {
2022 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2023 IDirect3DPixelShader8Impl *object;
2024 HRESULT hrc = D3D_OK;
2026 TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
2028 if (NULL == ppShader) {
2029 TRACE("(%p) Invalid call\n", This);
2030 return D3DERR_INVALIDCALL;
2032 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2034 if (NULL == object) {
2035 return E_OUTOFMEMORY;
2036 } else {
2037 EnterCriticalSection(&d3d8_cs);
2039 object->ref = 1;
2040 object->lpVtbl = &Direct3DPixelShader8_Vtbl;
2041 hrc = IWineD3DDevice_CreatePixelShader(This->WineD3DDevice, pFunction, &object->wineD3DPixelShader , (IUnknown *)object);
2042 if (D3D_OK != hrc) {
2043 FIXME("(%p) call to IWineD3DDevice_CreatePixelShader failed\n", This);
2044 HeapFree(GetProcessHeap(), 0 , object);
2045 *ppShader = 0;
2046 } else {
2047 shader_handle *handle = alloc_shader_handle(This);
2048 if (!handle) {
2049 ERR("Failed to allocate shader handle\n");
2050 IDirect3DVertexShader8_Release((IUnknown *)object);
2051 hrc = E_OUTOFMEMORY;
2052 } else {
2053 *handle = object;
2054 object->handle = (handle - This->shader_handles) + VS_HIGHESTFIXEDFXF + 1;
2055 *ppShader = object->handle;
2056 TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
2059 LeaveCriticalSection(&d3d8_cs);
2062 return hrc;
2065 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
2066 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2067 IDirect3DPixelShader8Impl *shader = NULL;
2068 HRESULT hr;
2070 TRACE("(%p) : pShader %#x\n", This, pShader);
2072 EnterCriticalSection(&d3d8_cs);
2073 if (pShader > VS_HIGHESTFIXEDFXF && This->allocated_shader_handles > pShader - (VS_HIGHESTFIXEDFXF + 1)) {
2074 shader = This->shader_handles[pShader - (VS_HIGHESTFIXEDFXF + 1)];
2075 } else if (pShader) {
2076 ERR("Trying to set an invalid handle.\n");
2079 TRACE("(%p) : Setting shader %p\n", This, shader);
2080 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, shader == NULL ? NULL :shader->wineD3DPixelShader);
2081 LeaveCriticalSection(&d3d8_cs);
2082 return hr;
2085 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
2086 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2087 IWineD3DPixelShader *object;
2089 HRESULT hrc = D3D_OK;
2090 TRACE("(%p) Relay\n", This);
2091 if (NULL == ppShader) {
2092 TRACE("(%p) Invalid call\n", This);
2093 return D3DERR_INVALIDCALL;
2096 EnterCriticalSection(&d3d8_cs);
2097 hrc = IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &object);
2098 if (D3D_OK == hrc && NULL != object) {
2099 IDirect3DPixelShader8Impl *d3d8_shader;
2100 hrc = IWineD3DPixelShader_GetParent(object, (IUnknown **)&d3d8_shader);
2101 IWineD3DPixelShader_Release(object);
2102 *ppShader = d3d8_shader->handle;
2103 } else {
2104 *ppShader = 0;
2107 TRACE("(%p) : returning %#x\n", This, *ppShader);
2108 LeaveCriticalSection(&d3d8_cs);
2109 return hrc;
2112 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
2113 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2115 TRACE("(%p) : pShader %#x\n", This, pShader);
2117 EnterCriticalSection(&d3d8_cs);
2118 if (pShader <= VS_HIGHESTFIXEDFXF || This->allocated_shader_handles <= pShader - (VS_HIGHESTFIXEDFXF + 1)) {
2119 ERR("(%p) : Trying to delete an invalid handle\n", This);
2120 LeaveCriticalSection(&d3d8_cs);
2121 return D3DERR_INVALIDCALL;
2122 } else {
2123 IWineD3DPixelShader *cur = NULL;
2124 shader_handle *handle = &This->shader_handles[pShader - (VS_HIGHESTFIXEDFXF + 1)];
2125 IDirect3DPixelShader8Impl *shader = *handle;
2127 IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &cur);
2128 if(cur) {
2129 if(cur == shader->wineD3DPixelShader) IDirect3DDevice8_SetPixelShader(iface, 0);
2130 IWineD3DPixelShader_Release(cur);
2133 while(IUnknown_Release((IUnknown *)shader));
2134 free_shader_handle(This, handle);
2136 LeaveCriticalSection(&d3d8_cs);
2138 return D3D_OK;
2141 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
2142 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2143 HRESULT hr;
2144 TRACE("(%p) Relay\n", This);
2146 EnterCriticalSection(&d3d8_cs);
2147 hr = IWineD3DDevice_SetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2148 LeaveCriticalSection(&d3d8_cs);
2149 return hr;
2152 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
2153 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2154 HRESULT hr;
2155 TRACE("(%p) Relay\n", This);
2157 EnterCriticalSection(&d3d8_cs);
2158 hr = IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
2159 LeaveCriticalSection(&d3d8_cs);
2160 return hr;
2163 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pPixelShader, void* pData, DWORD* pSizeOfData) {
2164 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2165 IDirect3DPixelShader8Impl *shader = NULL;
2166 HRESULT hr;
2168 TRACE("(%p) : pPixelShader %#x, pData %p, pSizeOfData %p\n", This, pPixelShader, pData, pSizeOfData);
2170 EnterCriticalSection(&d3d8_cs);
2171 if (pPixelShader <= VS_HIGHESTFIXEDFXF || This->allocated_shader_handles <= pPixelShader - (VS_HIGHESTFIXEDFXF + 1)) {
2172 ERR("Passed an invalid shader handle.\n");
2173 LeaveCriticalSection(&d3d8_cs);
2174 return D3DERR_INVALIDCALL;
2177 shader = This->shader_handles[pPixelShader - (VS_HIGHESTFIXEDFXF + 1)];
2178 hr = IWineD3DPixelShader_GetFunction(shader->wineD3DPixelShader, pData, pSizeOfData);
2179 LeaveCriticalSection(&d3d8_cs);
2180 return hr;
2183 static HRESULT WINAPI IDirect3DDevice8Impl_DrawRectPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
2184 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2185 HRESULT hr;
2186 TRACE("(%p) Relay\n", This);
2188 EnterCriticalSection(&d3d8_cs);
2189 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
2190 LeaveCriticalSection(&d3d8_cs);
2191 return hr;
2194 static HRESULT WINAPI IDirect3DDevice8Impl_DrawTriPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
2195 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2196 HRESULT hr;
2197 TRACE("(%p) Relay\n", This);
2199 EnterCriticalSection(&d3d8_cs);
2200 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
2201 LeaveCriticalSection(&d3d8_cs);
2202 return hr;
2205 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePatch(LPDIRECT3DDEVICE8 iface, UINT Handle) {
2206 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2207 HRESULT hr;
2208 TRACE("(%p) Relay\n", This);
2210 EnterCriticalSection(&d3d8_cs);
2211 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
2212 LeaveCriticalSection(&d3d8_cs);
2213 return hr;
2216 static HRESULT WINAPI IDirect3DDevice8Impl_SetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8* pStreamData,UINT Stride) {
2217 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2218 HRESULT hr;
2219 TRACE("(%p) Relay\n" , This);
2221 EnterCriticalSection(&d3d8_cs);
2222 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
2223 NULL == pStreamData ? NULL : ((IDirect3DVertexBuffer8Impl *)pStreamData)->wineD3DVertexBuffer,
2224 0/* Offset in bytes */, Stride);
2225 LeaveCriticalSection(&d3d8_cs);
2226 return hr;
2229 static HRESULT WINAPI IDirect3DDevice8Impl_GetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8** pStream,UINT* pStride) {
2230 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2231 IWineD3DVertexBuffer *retStream = NULL;
2232 HRESULT rc = D3D_OK;
2234 TRACE("(%p) Relay\n" , This);
2236 if(pStream == NULL){
2237 return D3DERR_INVALIDCALL;
2240 EnterCriticalSection(&d3d8_cs);
2241 rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, 0 /* Offset in bytes */, pStride);
2242 if (rc == D3D_OK && NULL != retStream) {
2243 IWineD3DVertexBuffer_GetParent(retStream, (IUnknown **)pStream);
2244 IWineD3DVertexBuffer_Release(retStream);
2245 }else{
2246 if (rc != D3D_OK){
2247 FIXME("Call to GetStreamSource failed %p\n", pStride);
2249 *pStream = NULL;
2251 LeaveCriticalSection(&d3d8_cs);
2253 return rc;
2257 const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl =
2259 IDirect3DDevice8Impl_QueryInterface,
2260 IDirect3DDevice8Impl_AddRef,
2261 IDirect3DDevice8Impl_Release,
2262 IDirect3DDevice8Impl_TestCooperativeLevel,
2263 IDirect3DDevice8Impl_GetAvailableTextureMem,
2264 IDirect3DDevice8Impl_ResourceManagerDiscardBytes,
2265 IDirect3DDevice8Impl_GetDirect3D,
2266 IDirect3DDevice8Impl_GetDeviceCaps,
2267 IDirect3DDevice8Impl_GetDisplayMode,
2268 IDirect3DDevice8Impl_GetCreationParameters,
2269 IDirect3DDevice8Impl_SetCursorProperties,
2270 IDirect3DDevice8Impl_SetCursorPosition,
2271 IDirect3DDevice8Impl_ShowCursor,
2272 IDirect3DDevice8Impl_CreateAdditionalSwapChain,
2273 IDirect3DDevice8Impl_Reset,
2274 IDirect3DDevice8Impl_Present,
2275 IDirect3DDevice8Impl_GetBackBuffer,
2276 IDirect3DDevice8Impl_GetRasterStatus,
2277 IDirect3DDevice8Impl_SetGammaRamp,
2278 IDirect3DDevice8Impl_GetGammaRamp,
2279 IDirect3DDevice8Impl_CreateTexture,
2280 IDirect3DDevice8Impl_CreateVolumeTexture,
2281 IDirect3DDevice8Impl_CreateCubeTexture,
2282 IDirect3DDevice8Impl_CreateVertexBuffer,
2283 IDirect3DDevice8Impl_CreateIndexBuffer,
2284 IDirect3DDevice8Impl_CreateRenderTarget,
2285 IDirect3DDevice8Impl_CreateDepthStencilSurface,
2286 IDirect3DDevice8Impl_CreateImageSurface,
2287 IDirect3DDevice8Impl_CopyRects,
2288 IDirect3DDevice8Impl_UpdateTexture,
2289 IDirect3DDevice8Impl_GetFrontBuffer,
2290 IDirect3DDevice8Impl_SetRenderTarget,
2291 IDirect3DDevice8Impl_GetRenderTarget,
2292 IDirect3DDevice8Impl_GetDepthStencilSurface,
2293 IDirect3DDevice8Impl_BeginScene,
2294 IDirect3DDevice8Impl_EndScene,
2295 IDirect3DDevice8Impl_Clear,
2296 IDirect3DDevice8Impl_SetTransform,
2297 IDirect3DDevice8Impl_GetTransform,
2298 IDirect3DDevice8Impl_MultiplyTransform,
2299 IDirect3DDevice8Impl_SetViewport,
2300 IDirect3DDevice8Impl_GetViewport,
2301 IDirect3DDevice8Impl_SetMaterial,
2302 IDirect3DDevice8Impl_GetMaterial,
2303 IDirect3DDevice8Impl_SetLight,
2304 IDirect3DDevice8Impl_GetLight,
2305 IDirect3DDevice8Impl_LightEnable,
2306 IDirect3DDevice8Impl_GetLightEnable,
2307 IDirect3DDevice8Impl_SetClipPlane,
2308 IDirect3DDevice8Impl_GetClipPlane,
2309 IDirect3DDevice8Impl_SetRenderState,
2310 IDirect3DDevice8Impl_GetRenderState,
2311 IDirect3DDevice8Impl_BeginStateBlock,
2312 IDirect3DDevice8Impl_EndStateBlock,
2313 IDirect3DDevice8Impl_ApplyStateBlock,
2314 IDirect3DDevice8Impl_CaptureStateBlock,
2315 IDirect3DDevice8Impl_DeleteStateBlock,
2316 IDirect3DDevice8Impl_CreateStateBlock,
2317 IDirect3DDevice8Impl_SetClipStatus,
2318 IDirect3DDevice8Impl_GetClipStatus,
2319 IDirect3DDevice8Impl_GetTexture,
2320 IDirect3DDevice8Impl_SetTexture,
2321 IDirect3DDevice8Impl_GetTextureStageState,
2322 IDirect3DDevice8Impl_SetTextureStageState,
2323 IDirect3DDevice8Impl_ValidateDevice,
2324 IDirect3DDevice8Impl_GetInfo,
2325 IDirect3DDevice8Impl_SetPaletteEntries,
2326 IDirect3DDevice8Impl_GetPaletteEntries,
2327 IDirect3DDevice8Impl_SetCurrentTexturePalette,
2328 IDirect3DDevice8Impl_GetCurrentTexturePalette,
2329 IDirect3DDevice8Impl_DrawPrimitive,
2330 IDirect3DDevice8Impl_DrawIndexedPrimitive,
2331 IDirect3DDevice8Impl_DrawPrimitiveUP,
2332 IDirect3DDevice8Impl_DrawIndexedPrimitiveUP,
2333 IDirect3DDevice8Impl_ProcessVertices,
2334 IDirect3DDevice8Impl_CreateVertexShader,
2335 IDirect3DDevice8Impl_SetVertexShader,
2336 IDirect3DDevice8Impl_GetVertexShader,
2337 IDirect3DDevice8Impl_DeleteVertexShader,
2338 IDirect3DDevice8Impl_SetVertexShaderConstant,
2339 IDirect3DDevice8Impl_GetVertexShaderConstant,
2340 IDirect3DDevice8Impl_GetVertexShaderDeclaration,
2341 IDirect3DDevice8Impl_GetVertexShaderFunction,
2342 IDirect3DDevice8Impl_SetStreamSource,
2343 IDirect3DDevice8Impl_GetStreamSource,
2344 IDirect3DDevice8Impl_SetIndices,
2345 IDirect3DDevice8Impl_GetIndices,
2346 IDirect3DDevice8Impl_CreatePixelShader,
2347 IDirect3DDevice8Impl_SetPixelShader,
2348 IDirect3DDevice8Impl_GetPixelShader,
2349 IDirect3DDevice8Impl_DeletePixelShader,
2350 IDirect3DDevice8Impl_SetPixelShaderConstant,
2351 IDirect3DDevice8Impl_GetPixelShaderConstant,
2352 IDirect3DDevice8Impl_GetPixelShaderFunction,
2353 IDirect3DDevice8Impl_DrawRectPatch,
2354 IDirect3DDevice8Impl_DrawTriPatch,
2355 IDirect3DDevice8Impl_DeletePatch
2358 ULONG WINAPI D3D8CB_DestroySurface(IWineD3DSurface *pSurface) {
2359 IDirect3DSurface8Impl* surfaceParent;
2360 TRACE("(%p) call back\n", pSurface);
2362 IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
2363 /* GetParent's AddRef was forwarded to an object in destruction.
2364 * Releasing it here again would cause an endless recursion. */
2365 surfaceParent->forwardReference = NULL;
2366 return IDirect3DSurface8_Release((IDirect3DSurface8*) surfaceParent);
2369 /* IWineD3DDeviceParent IUnknown methods */
2371 static inline struct IDirect3DDevice8Impl *device_from_device_parent(IWineD3DDeviceParent *iface)
2373 return (struct IDirect3DDevice8Impl *)((char*)iface
2374 - FIELD_OFFSET(struct IDirect3DDevice8Impl, device_parent_vtbl));
2377 static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface, REFIID riid, void **object)
2379 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2380 return IDirect3DDevice8Impl_QueryInterface((IDirect3DDevice8 *)This, riid, object);
2383 static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
2385 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2386 return IDirect3DDevice8Impl_AddRef((IDirect3DDevice8 *)This);
2389 static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
2391 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2392 return IDirect3DDevice8Impl_Release((IDirect3DDevice8 *)This);
2395 /* IWineD3DDeviceParent methods */
2397 static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
2399 TRACE("iface %p, device %p\n", iface, device);
2402 static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
2403 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, DWORD usage,
2404 WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface)
2406 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2407 IDirect3DSurface8Impl *d3d_surface;
2408 BOOL lockable = TRUE;
2409 HRESULT hr;
2411 TRACE("iface %p, superior %p, width %u, height %u, format %#x, usage %#x,\n"
2412 "\tpool %#x, level %u, face %u, surface %p\n",
2413 iface, superior, width, height, format, usage, pool, level, face, surface);
2416 if (pool == WINED3DPOOL_DEFAULT && !(usage & WINED3DUSAGE_DYNAMIC)) lockable = FALSE;
2418 hr = IDirect3DDevice8Impl_CreateSurface((IDirect3DDevice8 *)This, width, height,
2419 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
2420 (IDirect3DSurface8 **)&d3d_surface, D3DRTYPE_SURFACE, usage, pool,
2421 D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
2422 if (FAILED(hr))
2424 ERR("(%p) CreateSurface failed, returning %#x\n", iface, hr);
2425 return hr;
2428 *surface = d3d_surface->wineD3DSurface;
2429 d3d_surface->container = superior;
2430 IUnknown_Release(d3d_surface->parentDevice);
2431 d3d_surface->parentDevice = NULL;
2432 d3d_surface->forwardReference = superior;
2434 return hr;
2437 static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
2438 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2439 DWORD multisample_quality, BOOL lockable, IWineD3DSurface **surface)
2441 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2442 IDirect3DSurface8Impl *d3d_surface;
2443 HRESULT hr;
2445 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2446 "\tmultisample_quality %u, lockable %u, surface %p\n",
2447 iface, superior, width, height, format, multisample_type, multisample_quality, lockable, surface);
2449 hr = IDirect3DDevice8_CreateRenderTarget((IDirect3DDevice8 *)This, width, height,
2450 d3dformat_from_wined3dformat(format), multisample_type, lockable, (IDirect3DSurface8 **)&d3d_surface);
2451 if (FAILED(hr))
2453 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface, hr);
2454 return hr;
2457 *surface = d3d_surface->wineD3DSurface;
2458 d3d_surface->container = (IUnknown *)This;
2459 d3d_surface->isImplicit = TRUE;
2460 /* Implicit surfaces are created with an refcount of 0 */
2461 IUnknown_Release((IUnknown *)d3d_surface);
2463 return hr;
2466 static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
2467 IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
2468 DWORD multisample_quality, BOOL discard, IWineD3DSurface **surface)
2470 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2471 IDirect3DSurface8Impl *d3d_surface;
2472 HRESULT hr;
2474 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2475 "\tmultisample_quality %u, discard %u, surface %p\n",
2476 iface, superior, width, height, format, multisample_type, multisample_quality, discard, surface);
2478 hr = IDirect3DDevice8_CreateDepthStencilSurface((IDirect3DDevice8 *)This, width, height,
2479 d3dformat_from_wined3dformat(format), multisample_type, (IDirect3DSurface8 **)&d3d_surface);
2480 if (FAILED(hr))
2482 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface, hr);
2483 return hr;
2486 *surface = d3d_surface->wineD3DSurface;
2487 d3d_surface->container = (IUnknown *)This;
2488 d3d_surface->isImplicit = TRUE;
2489 /* Implicit surfaces are created with an refcount of 0 */
2490 IUnknown_Release((IUnknown *)d3d_surface);
2492 return hr;
2495 static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
2496 IUnknown *superior, UINT width, UINT height, UINT depth, WINED3DFORMAT format,
2497 WINED3DPOOL pool, DWORD usage, IWineD3DVolume **volume)
2499 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2500 IDirect3DVolume8Impl *object;
2501 HRESULT hr;
2503 TRACE("iface %p, superior %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
2504 iface, superior, width, height, depth, format, pool, usage, volume);
2506 /* Allocate the storage for the device */
2507 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2508 if (!object)
2510 FIXME("Allocation of memory failed\n");
2511 *volume = NULL;
2512 return D3DERR_OUTOFVIDEOMEMORY;
2515 object->lpVtbl = &Direct3DVolume8_Vtbl;
2516 object->ref = 1;
2517 hr = IWineD3DDevice_CreateVolume(This->WineD3DDevice, width, height, depth, usage,
2518 format, pool, &object->wineD3DVolume, NULL, (IUnknown *)object);
2519 if (FAILED(hr))
2521 ERR("(%p) CreateVolume failed, returning %#x\n", iface, hr);
2522 HeapFree(GetProcessHeap(), 0, object);
2523 *volume = NULL;
2524 return hr;
2527 *volume = object->wineD3DVolume;
2528 object->container = superior;
2529 object->forwardReference = superior;
2531 TRACE("(%p) Created volume %p\n", iface, *volume);
2533 return hr;
2536 static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
2537 WINED3DPRESENT_PARAMETERS *present_parameters, IWineD3DSwapChain **swapchain)
2539 struct IDirect3DDevice8Impl *This = device_from_device_parent(iface);
2540 IDirect3DSwapChain8Impl *d3d_swapchain;
2541 D3DPRESENT_PARAMETERS local_parameters;
2542 HRESULT hr;
2544 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
2546 /* Copy the presentation parameters */
2547 local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
2548 local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
2549 local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
2550 local_parameters.BackBufferCount = present_parameters->BackBufferCount;
2551 local_parameters.MultiSampleType = present_parameters->MultiSampleType;
2552 local_parameters.SwapEffect = present_parameters->SwapEffect;
2553 local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
2554 local_parameters.Windowed = present_parameters->Windowed;
2555 local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
2556 local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
2557 local_parameters.Flags = present_parameters->Flags;
2558 local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
2559 local_parameters.FullScreen_PresentationInterval = present_parameters->PresentationInterval;
2561 hr = IDirect3DDevice8_CreateAdditionalSwapChain((IDirect3DDevice8 *)This,
2562 &local_parameters, (IDirect3DSwapChain8 **)&d3d_swapchain);
2563 if (FAILED(hr))
2565 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface, hr);
2566 *swapchain = NULL;
2567 return hr;
2570 *swapchain = d3d_swapchain->wineD3DSwapChain;
2571 IUnknown_Release(d3d_swapchain->parentDevice);
2572 d3d_swapchain->parentDevice = NULL;
2574 /* Copy back the presentation parameters */
2575 present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
2576 present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
2577 present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
2578 present_parameters->BackBufferCount = local_parameters.BackBufferCount;
2579 present_parameters->MultiSampleType = local_parameters.MultiSampleType;
2580 present_parameters->SwapEffect = local_parameters.SwapEffect;
2581 present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
2582 present_parameters->Windowed = local_parameters.Windowed;
2583 present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
2584 present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
2585 present_parameters->Flags = local_parameters.Flags;
2586 present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
2587 present_parameters->PresentationInterval = local_parameters.FullScreen_PresentationInterval;
2589 return hr;
2592 const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl =
2594 /* IUnknown methods */
2595 device_parent_QueryInterface,
2596 device_parent_AddRef,
2597 device_parent_Release,
2598 /* IWineD3DDeviceParent methods */
2599 device_parent_WineD3DDeviceCreated,
2600 device_parent_CreateSurface,
2601 device_parent_CreateRenderTarget,
2602 device_parent_CreateDepthStencilSurface,
2603 device_parent_CreateVolume,
2604 device_parent_CreateSwapChain,