2 * IDirect3DDevice8 implementation
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2004 Christian Costa
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
33 #include "wine/debug.h"
35 #include "d3d8_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
39 /* Shader handle functions */
40 static shader_handle *alloc_shader_handle(IDirect3DDevice8Impl *This) {
41 if (This->free_shader_handles) {
42 /* Use a free handle */
43 shader_handle *handle = This->free_shader_handles;
44 This->free_shader_handles = *handle;
47 if (!(This->allocated_shader_handles < This->shader_handle_table_size)) {
49 DWORD new_size = This->shader_handle_table_size + (This->shader_handle_table_size >> 1);
50 shader_handle *new_handles = HeapReAlloc(GetProcessHeap(), 0, This->shader_handles, new_size * sizeof(shader_handle));
51 if (!new_handles) return NULL;
52 This->shader_handles = new_handles;
53 This->shader_handle_table_size = new_size;
56 return &This->shader_handles[This->allocated_shader_handles++];
59 static void free_shader_handle(IDirect3DDevice8Impl *This, shader_handle *handle) {
60 *handle = This->free_shader_handles;
61 This->free_shader_handles = handle;
64 /* IDirect3D IUnknown parts follow: */
65 static HRESULT WINAPI IDirect3DDevice8Impl_QueryInterface(LPDIRECT3DDEVICE8 iface,REFIID riid,LPVOID *ppobj)
67 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
69 if (IsEqualGUID(riid, &IID_IUnknown)
70 || IsEqualGUID(riid, &IID_IDirect3DDevice8)) {
71 IUnknown_AddRef(iface);
76 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
81 static ULONG WINAPI IDirect3DDevice8Impl_AddRef(LPDIRECT3DDEVICE8 iface) {
82 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
83 ULONG ref = InterlockedIncrement(&This->ref);
85 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
90 static ULONG WINAPI IDirect3DDevice8Impl_Release(LPDIRECT3DDEVICE8 iface) {
91 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
94 if (This->inDestruction) return 0;
95 ref = InterlockedDecrement(&This->ref);
97 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
102 TRACE("Releasing wined3d device %p\n", This->WineD3DDevice);
103 EnterCriticalSection(&d3d8_cs);
104 This->inDestruction = TRUE;
106 for(i = 0; i < This->numConvertedDecls; i++) {
107 IWineD3DVertexDeclaration_Release(This->decls[i].decl);
109 HeapFree(GetProcessHeap(), 0, This->decls);
111 IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D8CB_DestroyDepthStencilSurface, D3D8CB_DestroySwapChain);
112 IWineD3DDevice_Release(This->WineD3DDevice);
113 HeapFree(GetProcessHeap(), 0, This->shader_handles);
114 HeapFree(GetProcessHeap(), 0, This);
115 LeaveCriticalSection(&d3d8_cs);
120 /* IDirect3DDevice Interface follow: */
121 static HRESULT WINAPI IDirect3DDevice8Impl_TestCooperativeLevel(LPDIRECT3DDEVICE8 iface) {
122 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
125 TRACE("(%p) : Relay\n", This);
126 EnterCriticalSection(&d3d8_cs);
127 hr = IWineD3DDevice_TestCooperativeLevel(This->WineD3DDevice);
128 LeaveCriticalSection(&d3d8_cs);
132 static UINT WINAPI IDirect3DDevice8Impl_GetAvailableTextureMem(LPDIRECT3DDEVICE8 iface) {
133 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
136 TRACE("(%p) Relay\n", This);
137 EnterCriticalSection(&d3d8_cs);
138 hr = IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
139 LeaveCriticalSection(&d3d8_cs);
143 static HRESULT WINAPI IDirect3DDevice8Impl_ResourceManagerDiscardBytes(LPDIRECT3DDEVICE8 iface, DWORD Bytes) {
144 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
147 TRACE("(%p) : Relay bytes(%d)\n", This, Bytes);
148 EnterCriticalSection(&d3d8_cs);
149 hr = IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
150 LeaveCriticalSection(&d3d8_cs);
154 static HRESULT WINAPI IDirect3DDevice8Impl_GetDirect3D(LPDIRECT3DDEVICE8 iface, IDirect3D8** ppD3D8) {
155 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
159 TRACE("(%p) Relay\n", This);
161 if (NULL == ppD3D8) {
162 return D3DERR_INVALIDCALL;
165 EnterCriticalSection(&d3d8_cs);
166 hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &pWineD3D);
167 if (hr == D3D_OK && pWineD3D != NULL)
169 IWineD3D_GetParent(pWineD3D,(IUnknown **)ppD3D8);
170 IWineD3D_Release(pWineD3D);
172 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
175 TRACE("(%p) returning %p\n",This , *ppD3D8);
176 LeaveCriticalSection(&d3d8_cs);
181 static HRESULT WINAPI IDirect3DDevice8Impl_GetDeviceCaps(LPDIRECT3DDEVICE8 iface, D3DCAPS8* pCaps) {
182 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
183 HRESULT hrc = D3D_OK;
184 WINED3DCAPS *pWineCaps;
186 TRACE("(%p) : Relay pCaps %p\n", This, pCaps);
188 return D3DERR_INVALIDCALL;
190 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
191 if(pWineCaps == NULL){
192 return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
195 D3D8CAPSTOWINECAPS(pCaps, pWineCaps)
196 EnterCriticalSection(&d3d8_cs);
197 hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
198 LeaveCriticalSection(&d3d8_cs);
199 HeapFree(GetProcessHeap(), 0, pWineCaps);
201 /* D3D8 doesn't support SM 2.0 or higher, so clamp to 1.x */
202 if(pCaps->PixelShaderVersion > D3DPS_VERSION(1,4)){
203 pCaps->PixelShaderVersion = D3DPS_VERSION(1,4);
205 if(pCaps->VertexShaderVersion > D3DVS_VERSION(1,1)){
206 pCaps->VertexShaderVersion = D3DVS_VERSION(1,1);
209 TRACE("Returning %p %p\n", This, pCaps);
213 static HRESULT WINAPI IDirect3DDevice8Impl_GetDisplayMode(LPDIRECT3DDEVICE8 iface, D3DDISPLAYMODE* pMode) {
214 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
216 TRACE("(%p) Relay\n", This);
218 EnterCriticalSection(&d3d8_cs);
219 hr = IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, 0, (WINED3DDISPLAYMODE *) pMode);
220 LeaveCriticalSection(&d3d8_cs);
224 static HRESULT WINAPI IDirect3DDevice8Impl_GetCreationParameters(LPDIRECT3DDEVICE8 iface, D3DDEVICE_CREATION_PARAMETERS *pParameters) {
225 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
227 TRACE("(%p) Relay\n", This);
229 EnterCriticalSection(&d3d8_cs);
230 hr = IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
231 LeaveCriticalSection(&d3d8_cs);
235 static HRESULT WINAPI IDirect3DDevice8Impl_SetCursorProperties(LPDIRECT3DDEVICE8 iface, UINT XHotSpot, UINT YHotSpot, IDirect3DSurface8* pCursorBitmap) {
236 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
237 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl*)pCursorBitmap;
239 TRACE("(%p) Relay\n", This);
241 WARN("No cursor bitmap, returning WINED3DERR_INVALIDCALL\n");
242 return WINED3DERR_INVALIDCALL;
245 EnterCriticalSection(&d3d8_cs);
246 hr = IWineD3DDevice_SetCursorProperties(This->WineD3DDevice,XHotSpot,YHotSpot,pSurface->wineD3DSurface);
247 LeaveCriticalSection(&d3d8_cs);
251 static void WINAPI IDirect3DDevice8Impl_SetCursorPosition(LPDIRECT3DDEVICE8 iface, UINT XScreenSpace, UINT YScreenSpace, DWORD Flags) {
252 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
253 TRACE("(%p) Relay\n", This);
255 EnterCriticalSection(&d3d8_cs);
256 IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
257 LeaveCriticalSection(&d3d8_cs);
260 static BOOL WINAPI IDirect3DDevice8Impl_ShowCursor(LPDIRECT3DDEVICE8 iface, BOOL bShow) {
261 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
263 TRACE("(%p) Relay\n", This);
265 EnterCriticalSection(&d3d8_cs);
266 ret = IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
267 LeaveCriticalSection(&d3d8_cs);
271 static HRESULT WINAPI IDirect3DDevice8Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain8** pSwapChain) {
272 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
273 IDirect3DSwapChain8Impl* object;
274 HRESULT hrc = D3D_OK;
275 WINED3DPRESENT_PARAMETERS localParameters;
277 TRACE("(%p) Relay\n", This);
279 /* Fix the back buffer count */
280 if(pPresentationParameters->BackBufferCount == 0) {
281 pPresentationParameters->BackBufferCount = 1;
284 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
285 if (NULL == object) {
286 FIXME("Allocation of memory failed\n");
288 return D3DERR_OUTOFVIDEOMEMORY;
291 object->lpVtbl = &Direct3DSwapChain8_Vtbl;
293 /* Allocate an associated WineD3DDevice object */
294 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
295 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
296 localParameters.BackBufferFormat = pPresentationParameters->BackBufferFormat;
297 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
298 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
299 localParameters.MultiSampleQuality = 0; /* d3d9 only */
300 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
301 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
302 localParameters.Windowed = pPresentationParameters->Windowed;
303 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
304 localParameters.AutoDepthStencilFormat = pPresentationParameters->AutoDepthStencilFormat;
305 localParameters.Flags = pPresentationParameters->Flags;
306 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
307 localParameters.PresentationInterval = pPresentationParameters->FullScreen_PresentationInterval;
309 EnterCriticalSection(&d3d8_cs);
310 hrc = IWineD3DDevice_CreateAdditionalSwapChain(This->WineD3DDevice, &localParameters, &object->wineD3DSwapChain, (IUnknown*)object, D3D8CB_CreateRenderTarget, D3D8CB_CreateDepthStencilSurface);
311 LeaveCriticalSection(&d3d8_cs);
313 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
314 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
315 pPresentationParameters->BackBufferFormat = localParameters.BackBufferFormat;
316 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
317 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
318 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
319 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
320 pPresentationParameters->Windowed = localParameters.Windowed;
321 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
322 pPresentationParameters->AutoDepthStencilFormat = localParameters.AutoDepthStencilFormat;
323 pPresentationParameters->Flags = localParameters.Flags;
324 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
325 pPresentationParameters->FullScreen_PresentationInterval = localParameters.PresentationInterval;
328 FIXME("(%p) call to IWineD3DDevice_CreateAdditionalSwapChain failed\n", This);
329 HeapFree(GetProcessHeap(), 0 , object);
332 IUnknown_AddRef(iface);
333 object->parentDevice = iface;
334 *pSwapChain = (IDirect3DSwapChain8 *)object;
336 TRACE("(%p) returning %p\n", This, *pSwapChain);
340 static HRESULT WINAPI IDirect3DDevice8Impl_Reset(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
341 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
342 WINED3DPRESENT_PARAMETERS localParameters;
345 TRACE("(%p) Relay pPresentationParameters(%p)\n", This, pPresentationParameters);
347 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
348 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
349 localParameters.BackBufferFormat = pPresentationParameters->BackBufferFormat;
350 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
351 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
352 localParameters.MultiSampleQuality = 0; /* d3d9 only */
353 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
354 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
355 localParameters.Windowed = pPresentationParameters->Windowed;
356 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
357 localParameters.AutoDepthStencilFormat = pPresentationParameters->AutoDepthStencilFormat;
358 localParameters.Flags = pPresentationParameters->Flags;
359 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
360 localParameters.PresentationInterval = pPresentationParameters->FullScreen_PresentationInterval;
362 EnterCriticalSection(&d3d8_cs);
363 hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
364 LeaveCriticalSection(&d3d8_cs);
366 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
367 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
368 pPresentationParameters->BackBufferFormat = localParameters.BackBufferFormat;
369 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
370 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
371 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
372 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
373 pPresentationParameters->Windowed = localParameters.Windowed;
374 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
375 pPresentationParameters->AutoDepthStencilFormat = localParameters.AutoDepthStencilFormat;
376 pPresentationParameters->Flags = localParameters.Flags;
377 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
378 pPresentationParameters->FullScreen_PresentationInterval = localParameters.PresentationInterval;
383 static HRESULT WINAPI IDirect3DDevice8Impl_Present(LPDIRECT3DDEVICE8 iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion) {
384 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
386 TRACE("(%p) Relay\n", This);
388 EnterCriticalSection(&d3d8_cs);
389 hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
390 LeaveCriticalSection(&d3d8_cs);
394 static HRESULT WINAPI IDirect3DDevice8Impl_GetBackBuffer(LPDIRECT3DDEVICE8 iface, UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8** ppBackBuffer) {
395 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
396 IWineD3DSurface *retSurface = NULL;
399 TRACE("(%p) Relay\n", This);
401 EnterCriticalSection(&d3d8_cs);
402 rc = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, 0, BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &retSurface);
403 if (rc == D3D_OK && NULL != retSurface && NULL != ppBackBuffer) {
404 IWineD3DSurface_GetParent(retSurface, (IUnknown **)ppBackBuffer);
405 IWineD3DSurface_Release(retSurface);
407 LeaveCriticalSection(&d3d8_cs);
411 static HRESULT WINAPI IDirect3DDevice8Impl_GetRasterStatus(LPDIRECT3DDEVICE8 iface, D3DRASTER_STATUS* pRasterStatus) {
412 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
414 TRACE("(%p) Relay\n", This);
416 EnterCriticalSection(&d3d8_cs);
417 hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, 0, (WINED3DRASTER_STATUS *) pRasterStatus);
418 LeaveCriticalSection(&d3d8_cs);
422 static void WINAPI IDirect3DDevice8Impl_SetGammaRamp(LPDIRECT3DDEVICE8 iface, DWORD Flags, CONST D3DGAMMARAMP* pRamp) {
423 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
424 TRACE("(%p) Relay\n", This);
426 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
427 EnterCriticalSection(&d3d8_cs);
428 IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, 0, Flags, (CONST WINED3DGAMMARAMP *) pRamp);
429 LeaveCriticalSection(&d3d8_cs);
432 static void WINAPI IDirect3DDevice8Impl_GetGammaRamp(LPDIRECT3DDEVICE8 iface, D3DGAMMARAMP* pRamp) {
433 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
434 TRACE("(%p) Relay\n", This);
436 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
437 EnterCriticalSection(&d3d8_cs);
438 IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, 0, (WINED3DGAMMARAMP *) pRamp);
439 LeaveCriticalSection(&d3d8_cs);
442 static HRESULT WINAPI IDirect3DDevice8Impl_CreateTexture(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, UINT Levels, DWORD Usage,
443 D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture8 **ppTexture) {
444 IDirect3DTexture8Impl *object;
445 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
446 HRESULT hrc = D3D_OK;
448 TRACE("(%p) : W(%d) H(%d), Lvl(%d) d(%d), Fmt(%u), Pool(%d)\n", This, Width, Height, Levels, Usage, Format, Pool);
450 /* Allocate the storage for the device */
451 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DTexture8Impl));
453 if (NULL == object) {
454 FIXME("Allocation of memory failed\n");
455 /* *ppTexture = NULL; */
456 return D3DERR_OUTOFVIDEOMEMORY;
459 object->lpVtbl = &Direct3DTexture8_Vtbl;
461 EnterCriticalSection(&d3d8_cs);
462 hrc = IWineD3DDevice_CreateTexture(This->WineD3DDevice, Width, Height, Levels, Usage & WINED3DUSAGE_MASK,
463 (WINED3DFORMAT)Format, (WINED3DPOOL) Pool, &object->wineD3DTexture, NULL, (IUnknown *)object, D3D8CB_CreateSurface);
464 LeaveCriticalSection(&d3d8_cs);
468 FIXME("(%p) call to IWineD3DDevice_CreateTexture failed\n", This);
469 HeapFree(GetProcessHeap(), 0, object);
470 /* *ppTexture = NULL; */
472 IUnknown_AddRef(iface);
473 object->parentDevice = iface;
474 *ppTexture = (LPDIRECT3DTEXTURE8) object;
477 TRACE("(%p) Created Texture %p, %p\n",This,object,object->wineD3DTexture);
481 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVolumeTexture(LPDIRECT3DDEVICE8 iface,
482 UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage,
483 D3DFORMAT Format, D3DPOOL Pool, IDirect3DVolumeTexture8** ppVolumeTexture) {
485 IDirect3DVolumeTexture8Impl *object;
486 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
487 HRESULT hrc = D3D_OK;
489 TRACE("(%p) Relay\n", This);
491 /* Allocate the storage for the device */
492 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVolumeTexture8Impl));
493 if (NULL == object) {
494 FIXME("(%p) allocation of memory failed\n", This);
495 *ppVolumeTexture = NULL;
496 return D3DERR_OUTOFVIDEOMEMORY;
499 object->lpVtbl = &Direct3DVolumeTexture8_Vtbl;
501 EnterCriticalSection(&d3d8_cs);
502 hrc = IWineD3DDevice_CreateVolumeTexture(This->WineD3DDevice, Width, Height, Depth, Levels, Usage & WINED3DUSAGE_MASK,
503 (WINED3DFORMAT)Format, (WINED3DPOOL) Pool, &object->wineD3DVolumeTexture, NULL,
504 (IUnknown *)object, D3D8CB_CreateVolume);
505 LeaveCriticalSection(&d3d8_cs);
510 FIXME("(%p) call to IWineD3DDevice_CreateVolumeTexture failed\n", This);
511 HeapFree(GetProcessHeap(), 0, object);
512 *ppVolumeTexture = NULL;
514 IUnknown_AddRef(iface);
515 object->parentDevice = iface;
516 *ppVolumeTexture = (LPDIRECT3DVOLUMETEXTURE8) object;
518 TRACE("(%p) returning %p\n", This , *ppVolumeTexture);
522 static HRESULT WINAPI IDirect3DDevice8Impl_CreateCubeTexture(LPDIRECT3DDEVICE8 iface, UINT EdgeLength, UINT Levels, DWORD Usage,
523 D3DFORMAT Format, D3DPOOL Pool, IDirect3DCubeTexture8** ppCubeTexture) {
525 IDirect3DCubeTexture8Impl *object;
526 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
529 TRACE("(%p) : ELen(%d) Lvl(%d) Usage(%d) fmt(%u), Pool(%d)\n" , This, EdgeLength, Levels, Usage, Format, Pool);
531 /* Allocate the storage for the device */
532 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
534 if (NULL == object) {
535 FIXME("(%p) allocation of CubeTexture failed\n", This);
536 *ppCubeTexture = NULL;
537 return D3DERR_OUTOFVIDEOMEMORY;
540 object->lpVtbl = &Direct3DCubeTexture8_Vtbl;
542 EnterCriticalSection(&d3d8_cs);
543 hr = IWineD3DDevice_CreateCubeTexture(This->WineD3DDevice, EdgeLength, Levels, Usage & WINED3DUSAGE_MASK,
544 (WINED3DFORMAT)Format, (WINED3DPOOL) Pool, &object->wineD3DCubeTexture, NULL, (IUnknown*)object,
545 D3D8CB_CreateSurface);
546 LeaveCriticalSection(&d3d8_cs);
551 FIXME("(%p) call to IWineD3DDevice_CreateCubeTexture failed\n", This);
552 HeapFree(GetProcessHeap(), 0, object);
553 *ppCubeTexture = NULL;
555 IUnknown_AddRef(iface);
556 object->parentDevice = iface;
557 *ppCubeTexture = (LPDIRECT3DCUBETEXTURE8) object;
560 TRACE("(%p) returning %p\n",This, *ppCubeTexture);
564 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexBuffer(LPDIRECT3DDEVICE8 iface, UINT Size, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer8** ppVertexBuffer) {
565 IDirect3DVertexBuffer8Impl *object;
566 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
567 HRESULT hrc = D3D_OK;
569 TRACE("(%p) Relay\n", This);
570 /* Allocate the storage for the device */
571 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexBuffer8Impl));
572 if (NULL == object) {
573 FIXME("Allocation of memory failed\n");
574 *ppVertexBuffer = NULL;
575 return D3DERR_OUTOFVIDEOMEMORY;
578 object->lpVtbl = &Direct3DVertexBuffer8_Vtbl;
580 EnterCriticalSection(&d3d8_cs);
581 hrc = IWineD3DDevice_CreateVertexBuffer(This->WineD3DDevice, Size, Usage & WINED3DUSAGE_MASK, FVF, (WINED3DPOOL) Pool, &(object->wineD3DVertexBuffer), NULL, (IUnknown *)object);
582 LeaveCriticalSection(&d3d8_cs);
587 FIXME("(%p) call to IWineD3DDevice_CreateVertexBuffer failed\n", This);
588 HeapFree(GetProcessHeap(), 0, object);
589 *ppVertexBuffer = NULL;
591 IUnknown_AddRef(iface);
592 object->parentDevice = iface;
593 *ppVertexBuffer = (LPDIRECT3DVERTEXBUFFER8) object;
598 static HRESULT WINAPI IDirect3DDevice8Impl_CreateIndexBuffer(LPDIRECT3DDEVICE8 iface, UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DIndexBuffer8** ppIndexBuffer) {
599 IDirect3DIndexBuffer8Impl *object;
600 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
601 HRESULT hrc = D3D_OK;
603 TRACE("(%p) Relay\n", This);
604 /* Allocate the storage for the device */
605 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
606 if (NULL == object) {
607 FIXME("Allocation of memory failed\n");
608 *ppIndexBuffer = NULL;
609 return D3DERR_OUTOFVIDEOMEMORY;
612 object->lpVtbl = &Direct3DIndexBuffer8_Vtbl;
614 TRACE("Calling wined3d create index buffer\n");
615 EnterCriticalSection(&d3d8_cs);
616 hrc = IWineD3DDevice_CreateIndexBuffer(This->WineD3DDevice, Length, Usage & WINED3DUSAGE_MASK, Format, (WINED3DPOOL) Pool, &object->wineD3DIndexBuffer, NULL, (IUnknown *)object);
617 LeaveCriticalSection(&d3d8_cs);
622 FIXME("(%p) call to IWineD3DDevice_CreateIndexBuffer failed\n", This);
623 HeapFree(GetProcessHeap(), 0, object);
624 *ppIndexBuffer = NULL;
626 IUnknown_AddRef(iface);
627 object->parentDevice = iface;
628 *ppIndexBuffer = (LPDIRECT3DINDEXBUFFER8)object;
633 static HRESULT WINAPI 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) {
635 IDirect3DSurface8Impl *object;
636 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
637 TRACE("(%p) Relay\n", This);
638 if(MultisampleQuality < 0) {
639 FIXME("MultisampleQuality out of range %d, substituting 0\n", MultisampleQuality);
640 /*FIXME: Find out what windows does with a MultisampleQuality < 0 */
641 MultisampleQuality=0;
644 if(MultisampleQuality > 0){
645 FIXME("MultisampleQuality set to %d, substituting 0\n" , MultisampleQuality);
648 [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.
650 MultisampleQuality=0;
652 /*FIXME: Check MAX bounds of MultisampleQuality*/
654 /* Allocate the storage for the device */
655 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface8Impl));
656 if (NULL == object) {
657 FIXME("Allocation of memory failed\n");
659 return D3DERR_OUTOFVIDEOMEMORY;
662 object->lpVtbl = &Direct3DSurface8_Vtbl;
665 TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
667 /* Not called from the VTable, no locking needed */
668 hrc = IWineD3DDevice_CreateSurface(This->WineD3DDevice, Width, Height, Format, Lockable, Discard, Level, &object->wineD3DSurface, Type, Usage & WINED3DUSAGE_MASK, (WINED3DPOOL) Pool,MultiSample,MultisampleQuality, NULL, SURFACE_OPENGL, (IUnknown *)object);
669 if (hrc != D3D_OK || NULL == object->wineD3DSurface) {
671 FIXME("(%p) call to IWineD3DDevice_CreateSurface failed\n", This);
672 HeapFree(GetProcessHeap(), 0, object);
675 IUnknown_AddRef(iface);
676 object->parentDevice = iface;
677 *ppSurface = (LPDIRECT3DSURFACE8) object;
682 static HRESULT WINAPI IDirect3DDevice8Impl_CreateRenderTarget(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, BOOL Lockable, IDirect3DSurface8** ppSurface) {
686 EnterCriticalSection(&d3d8_cs);
687 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, Lockable, FALSE /* Discard */, 0 /* Level */ , ppSurface, D3DRTYPE_SURFACE, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, MultiSample, 0);
688 LeaveCriticalSection(&d3d8_cs);
692 static HRESULT WINAPI IDirect3DDevice8Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, IDirect3DSurface8** ppSurface) {
696 /* TODO: Verify that Discard is false */
697 EnterCriticalSection(&d3d8_cs);
698 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE, 0 /* Level */
699 ,ppSurface, D3DRTYPE_SURFACE, D3DUSAGE_DEPTHSTENCIL,
700 D3DPOOL_DEFAULT, MultiSample, 0);
701 LeaveCriticalSection(&d3d8_cs);
705 static HRESULT WINAPI IDirect3DDevice8Impl_CreateImageSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, IDirect3DSurface8** ppSurface) {
709 EnterCriticalSection(&d3d8_cs);
710 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Loackable */ , FALSE /*Discard*/ , 0 /* Level */ , ppSurface, D3DRTYPE_SURFACE, 0 /* Usage (undefined/none) */ , D3DPOOL_SCRATCH, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
711 LeaveCriticalSection(&d3d8_cs);
715 static HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8 *pSourceSurface, CONST RECT *pSourceRects, UINT cRects, IDirect3DSurface8 *pDestinationSurface, CONST POINT *pDestPoints) {
716 IDirect3DSurface8Impl *Source = (IDirect3DSurface8Impl *) pSourceSurface;
717 IDirect3DSurface8Impl *Dest = (IDirect3DSurface8Impl *) pDestinationSurface;
719 HRESULT hr = WINED3D_OK;
720 WINED3DFORMAT srcFormat, destFormat;
721 UINT srcWidth, destWidth;
722 UINT srcHeight, destHeight;
724 WINED3DSURFACE_DESC winedesc;
726 TRACE("(%p) pSrcSur=%p, pSourceRects=%p, cRects=%d, pDstSur=%p, pDestPtsArr=%p\n", iface,
727 pSourceSurface, pSourceRects, cRects, pDestinationSurface, pDestPoints);
730 /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the destination texture is in WINED3DPOOL_DEFAULT */
731 memset(&winedesc, 0, sizeof(winedesc));
733 winedesc.Format = &srcFormat;
734 winedesc.Width = &srcWidth;
735 winedesc.Height = &srcHeight;
736 winedesc.Size = &srcSize;
737 IWineD3DSurface_GetDesc(Source->wineD3DSurface, &winedesc);
739 winedesc.Format = &destFormat;
740 winedesc.Width = &destWidth;
741 winedesc.Height = &destHeight;
742 winedesc.Size = NULL;
743 EnterCriticalSection(&d3d8_cs);
744 IWineD3DSurface_GetDesc(Dest->wineD3DSurface, &winedesc);
746 /* Check that the source and destination formats match */
747 if (srcFormat != destFormat && WINED3DFMT_UNKNOWN != destFormat) {
748 WARN("(%p) source %p format must match the dest %p format, returning WINED3DERR_INVALIDCALL\n", iface, pSourceSurface, pDestinationSurface);
749 LeaveCriticalSection(&d3d8_cs);
750 return WINED3DERR_INVALIDCALL;
751 } else if (WINED3DFMT_UNKNOWN == destFormat) {
752 TRACE("(%p) : Converting destination surface from WINED3DFMT_UNKNOWN to the source format\n", iface);
753 IWineD3DSurface_SetFormat(Dest->wineD3DSurface, srcFormat);
754 destFormat = srcFormat;
757 /* Quick if complete copy ... */
758 if (cRects == 0 && pSourceRects == NULL && pDestPoints == NULL) {
759 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
762 /* Copy rect by rect */
763 if (NULL != pSourceRects && NULL != pDestPoints) {
764 for (i = 0; i < cRects; ++i) {
765 IWineD3DSurface_BltFast(Dest->wineD3DSurface, pDestPoints[i].x, pDestPoints[i].y, Source->wineD3DSurface, (RECT *) &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
768 for (i = 0; i < cRects; ++i) {
769 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, (RECT *) &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
773 LeaveCriticalSection(&d3d8_cs);
778 static HRESULT WINAPI IDirect3DDevice8Impl_UpdateTexture(LPDIRECT3DDEVICE8 iface, IDirect3DBaseTexture8* pSourceTexture, IDirect3DBaseTexture8* pDestinationTexture) {
779 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
781 TRACE("(%p) Relay\n" , This);
783 EnterCriticalSection(&d3d8_cs);
784 hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice, ((IDirect3DBaseTexture8Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture8Impl *)pDestinationTexture)->wineD3DBaseTexture);
785 LeaveCriticalSection(&d3d8_cs);
789 static HRESULT WINAPI IDirect3DDevice8Impl_GetFrontBuffer(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pDestSurface) {
790 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
791 IDirect3DSurface8Impl *destSurface = (IDirect3DSurface8Impl *)pDestSurface;
794 TRACE("(%p) Relay\n" , This);
796 if (pDestSurface == NULL) {
797 WARN("(%p) : Caller passed NULL as pDestSurface returning D3DERR_INVALIDCALL\n", This);
798 return D3DERR_INVALIDCALL;
801 EnterCriticalSection(&d3d8_cs);
802 hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, 0, destSurface->wineD3DSurface);
803 LeaveCriticalSection(&d3d8_cs);
807 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pRenderTarget, IDirect3DSurface8* pNewZStencil) {
808 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
809 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl *)pRenderTarget;
810 IDirect3DSurface8Impl *pZSurface = (IDirect3DSurface8Impl *)pNewZStencil;
812 TRACE("(%p) Relay\n" , This);
814 IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, NULL == pZSurface ? NULL : pZSurface->wineD3DSurface);
816 EnterCriticalSection(&d3d8_cs);
817 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, 0, pSurface ? pSurface->wineD3DSurface : NULL);
818 LeaveCriticalSection(&d3d8_cs);
822 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppRenderTarget) {
823 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
825 IWineD3DSurface *pRenderTarget;
827 TRACE("(%p) Relay\n" , This);
829 if (ppRenderTarget == NULL) {
830 return D3DERR_INVALIDCALL;
832 EnterCriticalSection(&d3d8_cs);
833 hr = IWineD3DDevice_GetRenderTarget(This->WineD3DDevice, 0, &pRenderTarget);
835 if (hr == D3D_OK && pRenderTarget != NULL) {
836 IWineD3DSurface_GetParent(pRenderTarget,(IUnknown**)ppRenderTarget);
837 IWineD3DSurface_Release(pRenderTarget);
839 FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
840 *ppRenderTarget = NULL;
842 LeaveCriticalSection(&d3d8_cs);
847 static HRESULT WINAPI IDirect3DDevice8Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppZStencilSurface) {
848 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
850 IWineD3DSurface *pZStencilSurface;
852 TRACE("(%p) Relay\n" , This);
853 if(ppZStencilSurface == NULL){
854 return D3DERR_INVALIDCALL;
857 EnterCriticalSection(&d3d8_cs);
858 hr=IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
859 if(hr == D3D_OK && pZStencilSurface != NULL){
860 IWineD3DSurface_GetParent(pZStencilSurface,(IUnknown**)ppZStencilSurface);
861 IWineD3DSurface_Release(pZStencilSurface);
863 FIXME("Call to IWineD3DDevice_GetDepthStencilSurface failed\n");
864 *ppZStencilSurface = NULL;
866 LeaveCriticalSection(&d3d8_cs);
871 static HRESULT WINAPI IDirect3DDevice8Impl_BeginScene(LPDIRECT3DDEVICE8 iface) {
872 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
874 TRACE("(%p) Relay\n" , This);
876 EnterCriticalSection(&d3d8_cs);
877 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
878 LeaveCriticalSection(&d3d8_cs);
882 static HRESULT WINAPI IDirect3DDevice8Impl_EndScene(LPDIRECT3DDEVICE8 iface) {
883 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
885 TRACE("(%p) Relay\n" , This);
887 EnterCriticalSection(&d3d8_cs);
888 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
889 LeaveCriticalSection(&d3d8_cs);
893 static HRESULT WINAPI IDirect3DDevice8Impl_Clear(LPDIRECT3DDEVICE8 iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
894 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
896 TRACE("(%p) Relay\n" , This);
898 /* Note: D3DRECT is compatible with WINED3DRECT */
899 EnterCriticalSection(&d3d8_cs);
900 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (CONST WINED3DRECT*) pRects, Flags, Color, Z, Stencil);
901 LeaveCriticalSection(&d3d8_cs);
905 static HRESULT WINAPI IDirect3DDevice8Impl_SetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
906 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
908 TRACE("(%p) Relay\n" , This);
910 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
911 EnterCriticalSection(&d3d8_cs);
912 hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
913 LeaveCriticalSection(&d3d8_cs);
917 static HRESULT WINAPI IDirect3DDevice8Impl_GetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State,D3DMATRIX* pMatrix) {
918 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
920 TRACE("(%p) Relay\n" , This);
922 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
923 EnterCriticalSection(&d3d8_cs);
924 hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
925 LeaveCriticalSection(&d3d8_cs);
929 static HRESULT WINAPI IDirect3DDevice8Impl_MultiplyTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
930 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
932 TRACE("(%p) Relay\n" , This);
934 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
935 EnterCriticalSection(&d3d8_cs);
936 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
937 LeaveCriticalSection(&d3d8_cs);
941 static HRESULT WINAPI IDirect3DDevice8Impl_SetViewport(LPDIRECT3DDEVICE8 iface, CONST D3DVIEWPORT8* pViewport) {
942 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
944 TRACE("(%p) Relay\n" , This);
946 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
947 EnterCriticalSection(&d3d8_cs);
948 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
949 LeaveCriticalSection(&d3d8_cs);
953 static HRESULT WINAPI IDirect3DDevice8Impl_GetViewport(LPDIRECT3DDEVICE8 iface, D3DVIEWPORT8* pViewport) {
954 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
956 TRACE("(%p) Relay\n" , This);
958 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
959 EnterCriticalSection(&d3d8_cs);
960 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
961 LeaveCriticalSection(&d3d8_cs);
965 static HRESULT WINAPI IDirect3DDevice8Impl_SetMaterial(LPDIRECT3DDEVICE8 iface, CONST D3DMATERIAL8* pMaterial) {
966 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
968 TRACE("(%p) Relay\n" , This);
970 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
971 EnterCriticalSection(&d3d8_cs);
972 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
973 LeaveCriticalSection(&d3d8_cs);
977 static HRESULT WINAPI IDirect3DDevice8Impl_GetMaterial(LPDIRECT3DDEVICE8 iface, D3DMATERIAL8* pMaterial) {
978 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
980 TRACE("(%p) Relay\n" , This);
982 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
983 EnterCriticalSection(&d3d8_cs);
984 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
985 LeaveCriticalSection(&d3d8_cs);
989 static HRESULT WINAPI IDirect3DDevice8Impl_SetLight(LPDIRECT3DDEVICE8 iface, DWORD Index, CONST D3DLIGHT8* pLight) {
990 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
992 TRACE("(%p) Relay\n" , This);
994 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
995 EnterCriticalSection(&d3d8_cs);
996 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
997 LeaveCriticalSection(&d3d8_cs);
1001 static HRESULT WINAPI IDirect3DDevice8Impl_GetLight(LPDIRECT3DDEVICE8 iface, DWORD Index,D3DLIGHT8* pLight) {
1002 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1004 TRACE("(%p) Relay\n" , This);
1006 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1007 EnterCriticalSection(&d3d8_cs);
1008 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1009 LeaveCriticalSection(&d3d8_cs);
1013 static HRESULT WINAPI IDirect3DDevice8Impl_LightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL Enable) {
1014 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1016 TRACE("(%p) Relay\n" , This);
1018 EnterCriticalSection(&d3d8_cs);
1019 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1020 LeaveCriticalSection(&d3d8_cs);
1024 static HRESULT WINAPI IDirect3DDevice8Impl_GetLightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL* pEnable) {
1025 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1027 TRACE("(%p) Relay\n" , This);
1029 EnterCriticalSection(&d3d8_cs);
1030 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1031 LeaveCriticalSection(&d3d8_cs);
1035 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,CONST float* pPlane) {
1036 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1038 TRACE("(%p) Relay\n" , This);
1040 EnterCriticalSection(&d3d8_cs);
1041 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1042 LeaveCriticalSection(&d3d8_cs);
1046 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,float* pPlane) {
1047 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1049 TRACE("(%p) Relay\n" , This);
1051 EnterCriticalSection(&d3d8_cs);
1052 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1053 LeaveCriticalSection(&d3d8_cs);
1057 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD Value) {
1058 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1060 TRACE("(%p) Relay\n" , This);
1062 EnterCriticalSection(&d3d8_cs);
1063 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1064 LeaveCriticalSection(&d3d8_cs);
1068 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD* pValue) {
1069 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1071 TRACE("(%p) Relay\n" , This);
1073 EnterCriticalSection(&d3d8_cs);
1074 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1075 LeaveCriticalSection(&d3d8_cs);
1079 static HRESULT WINAPI IDirect3DDevice8Impl_BeginStateBlock(LPDIRECT3DDEVICE8 iface) {
1080 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1082 TRACE("(%p)\n", This);
1084 EnterCriticalSection(&d3d8_cs);
1085 hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
1086 LeaveCriticalSection(&d3d8_cs);
1090 static HRESULT WINAPI IDirect3DDevice8Impl_EndStateBlock(LPDIRECT3DDEVICE8 iface, DWORD* pToken) {
1091 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1093 IWineD3DStateBlock* wineD3DStateBlock;
1094 IDirect3DStateBlock8Impl* object;
1096 TRACE("(%p) Relay\n", This);
1098 /* Tell wineD3D to endstatablock before anything else (in case we run out
1099 * of memory later and cause locking problems)
1101 EnterCriticalSection(&d3d8_cs);
1102 hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice , &wineD3DStateBlock);
1104 FIXME("IWineD3DDevice_EndStateBlock returned an error\n");
1105 LeaveCriticalSection(&d3d8_cs);
1109 /* allocate a new IDirectD3DStateBlock */
1110 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY ,sizeof(IDirect3DStateBlock8Impl));
1112 object->lpVtbl = &Direct3DStateBlock8_Vtbl;
1114 object->wineD3DStateBlock = wineD3DStateBlock;
1116 *pToken = (DWORD)object;
1117 TRACE("(%p)Returning %p %p\n", This, object, wineD3DStateBlock);
1119 LeaveCriticalSection(&d3d8_cs);
1123 static HRESULT WINAPI IDirect3DDevice8Impl_ApplyStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1124 IDirect3DStateBlock8Impl *pSB = (IDirect3DStateBlock8Impl*) Token;
1125 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1128 TRACE("(%p) %p Relay\n", This, pSB);
1130 EnterCriticalSection(&d3d8_cs);
1131 hr = IWineD3DStateBlock_Apply(pSB->wineD3DStateBlock);
1132 LeaveCriticalSection(&d3d8_cs);
1136 static HRESULT WINAPI IDirect3DDevice8Impl_CaptureStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1137 IDirect3DStateBlock8Impl* pSB = (IDirect3DStateBlock8Impl *)Token;
1138 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1141 TRACE("(%p) %p Relay\n", This, pSB);
1143 EnterCriticalSection(&d3d8_cs);
1144 hr = IWineD3DStateBlock_Capture(pSB->wineD3DStateBlock);
1145 LeaveCriticalSection(&d3d8_cs);
1149 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1150 IDirect3DStateBlock8Impl* pSB = (IDirect3DStateBlock8Impl *)Token;
1151 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1153 TRACE("(%p) Relay\n", This);
1155 EnterCriticalSection(&d3d8_cs);
1156 while(IUnknown_Release((IUnknown *)pSB));
1157 LeaveCriticalSection(&d3d8_cs);
1162 static HRESULT WINAPI IDirect3DDevice8Impl_CreateStateBlock(LPDIRECT3DDEVICE8 iface, D3DSTATEBLOCKTYPE Type, DWORD* pToken) {
1163 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1164 IDirect3DStateBlock8Impl *object;
1165 HRESULT hrc = D3D_OK;
1167 TRACE("(%p) Relay\n", This);
1169 if(Type != D3DSBT_ALL && Type != D3DSBT_PIXELSTATE &&
1170 Type != D3DSBT_VERTEXSTATE ) {
1171 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1172 return D3DERR_INVALIDCALL;
1175 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DStateBlock8Impl));
1176 if (NULL == object) {
1178 return E_OUTOFMEMORY;
1180 object->lpVtbl = &Direct3DStateBlock8_Vtbl;
1183 EnterCriticalSection(&d3d8_cs);
1184 hrc = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type, &object->wineD3DStateBlock, (IUnknown *)object);
1185 LeaveCriticalSection(&d3d8_cs);
1187 FIXME("(%p) Call to IWineD3DDevice_CreateStateBlock failed.\n", This);
1188 HeapFree(GetProcessHeap(), 0, object);
1191 *pToken = (DWORD)object;
1193 TRACE("(%p) returning token (ptr to stateblock) of %p\n", This, object);
1198 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipStatus(LPDIRECT3DDEVICE8 iface, CONST D3DCLIPSTATUS8* pClipStatus) {
1199 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1201 TRACE("(%p) Relay\n" , This);
1202 /* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
1203 EnterCriticalSection(&d3d8_cs);
1204 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1205 LeaveCriticalSection(&d3d8_cs);
1209 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipStatus(LPDIRECT3DDEVICE8 iface, D3DCLIPSTATUS8* pClipStatus) {
1210 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1212 TRACE("(%p) Relay\n" , This);
1214 EnterCriticalSection(&d3d8_cs);
1215 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1216 LeaveCriticalSection(&d3d8_cs);
1220 static HRESULT WINAPI IDirect3DDevice8Impl_GetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage,IDirect3DBaseTexture8** ppTexture) {
1221 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1222 IWineD3DBaseTexture *retTexture = NULL;
1223 HRESULT rc = D3D_OK;
1225 TRACE("(%p) Relay\n" , This);
1227 if(ppTexture == NULL){
1228 return D3DERR_INVALIDCALL;
1231 EnterCriticalSection(&d3d8_cs);
1232 rc = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
1233 if (rc == D3D_OK && NULL != retTexture) {
1234 IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
1235 IWineD3DBaseTexture_Release(retTexture);
1237 FIXME("Call to get texture (%d) failed (%p)\n", Stage, retTexture);
1240 LeaveCriticalSection(&d3d8_cs);
1245 static HRESULT WINAPI IDirect3DDevice8Impl_SetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage, IDirect3DBaseTexture8* pTexture) {
1246 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1248 TRACE("(%p) Relay %d %p\n" , This, Stage, pTexture);
1250 EnterCriticalSection(&d3d8_cs);
1251 hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
1252 pTexture==NULL ? NULL : ((IDirect3DBaseTexture8Impl *)pTexture)->wineD3DBaseTexture);
1253 LeaveCriticalSection(&d3d8_cs);
1257 static HRESULT WINAPI IDirect3DDevice8Impl_GetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD* pValue) {
1258 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1260 TRACE("(%p) Relay\n" , This);
1263 case D3DTSS_ADDRESSU:
1264 Type = WINED3DSAMP_ADDRESSU;
1266 case D3DTSS_ADDRESSV:
1267 Type = WINED3DSAMP_ADDRESSV;
1269 case D3DTSS_ADDRESSW:
1270 Type = WINED3DSAMP_ADDRESSW;
1272 case D3DTSS_BORDERCOLOR:
1273 Type = WINED3DSAMP_BORDERCOLOR;
1275 case D3DTSS_MAGFILTER:
1276 Type = WINED3DSAMP_MAGFILTER;
1278 case D3DTSS_MAXANISOTROPY:
1279 Type = WINED3DSAMP_MAXANISOTROPY;
1281 case D3DTSS_MAXMIPLEVEL:
1282 Type = WINED3DSAMP_MAXMIPLEVEL;
1284 case D3DTSS_MINFILTER:
1285 Type = WINED3DSAMP_MINFILTER;
1287 case D3DTSS_MIPFILTER:
1288 Type = WINED3DSAMP_MIPFILTER;
1290 case D3DTSS_MIPMAPLODBIAS:
1291 Type = WINED3DSAMP_MIPMAPLODBIAS;
1294 EnterCriticalSection(&d3d8_cs);
1295 hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, Type, pValue);
1296 LeaveCriticalSection(&d3d8_cs);
1300 EnterCriticalSection(&d3d8_cs);
1301 hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Stage, Type, pValue);
1302 LeaveCriticalSection(&d3d8_cs);
1306 static HRESULT WINAPI IDirect3DDevice8Impl_SetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
1307 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1309 TRACE("(%p) Relay\n" , This);
1312 case D3DTSS_ADDRESSU:
1313 Type = WINED3DSAMP_ADDRESSU;
1315 case D3DTSS_ADDRESSV:
1316 Type = WINED3DSAMP_ADDRESSV;
1318 case D3DTSS_ADDRESSW:
1319 Type = WINED3DSAMP_ADDRESSW;
1321 case D3DTSS_BORDERCOLOR:
1322 Type = WINED3DSAMP_BORDERCOLOR;
1324 case D3DTSS_MAGFILTER:
1325 Type = WINED3DSAMP_MAGFILTER;
1327 case D3DTSS_MAXANISOTROPY:
1328 Type = WINED3DSAMP_MAXANISOTROPY;
1330 case D3DTSS_MAXMIPLEVEL:
1331 Type = WINED3DSAMP_MAXMIPLEVEL;
1333 case D3DTSS_MINFILTER:
1334 Type = WINED3DSAMP_MINFILTER;
1336 case D3DTSS_MIPFILTER:
1337 Type = WINED3DSAMP_MIPFILTER;
1339 case D3DTSS_MIPMAPLODBIAS:
1340 Type = WINED3DSAMP_MIPMAPLODBIAS;
1343 EnterCriticalSection(&d3d8_cs);
1344 hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, Type, Value);
1345 LeaveCriticalSection(&d3d8_cs);
1349 EnterCriticalSection(&d3d8_cs);
1350 hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Stage, Type, Value);
1351 LeaveCriticalSection(&d3d8_cs);
1355 static HRESULT WINAPI IDirect3DDevice8Impl_ValidateDevice(LPDIRECT3DDEVICE8 iface, DWORD* pNumPasses) {
1356 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1358 TRACE("(%p) Relay\n" , This);
1360 EnterCriticalSection(&d3d8_cs);
1361 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1362 LeaveCriticalSection(&d3d8_cs);
1366 static HRESULT WINAPI IDirect3DDevice8Impl_GetInfo(LPDIRECT3DDEVICE8 iface, DWORD DevInfoID, void* pDevInfoStruct, DWORD DevInfoStructSize) {
1367 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1368 FIXME("(%p) : stub\n", This);
1372 static HRESULT WINAPI IDirect3DDevice8Impl_SetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, CONST PALETTEENTRY* pEntries) {
1373 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1375 TRACE("(%p) Relay\n" , This);
1377 EnterCriticalSection(&d3d8_cs);
1378 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1379 LeaveCriticalSection(&d3d8_cs);
1383 static HRESULT WINAPI IDirect3DDevice8Impl_GetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
1384 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1386 TRACE("(%p) Relay\n" , This);
1388 EnterCriticalSection(&d3d8_cs);
1389 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1390 LeaveCriticalSection(&d3d8_cs);
1394 static HRESULT WINAPI IDirect3DDevice8Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber) {
1395 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1397 TRACE("(%p) Relay\n" , This);
1399 EnterCriticalSection(&d3d8_cs);
1400 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1401 LeaveCriticalSection(&d3d8_cs);
1405 static HRESULT WINAPI IDirect3DDevice8Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT *PaletteNumber) {
1406 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1408 TRACE("(%p) Relay\n" , This);
1410 EnterCriticalSection(&d3d8_cs);
1411 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1412 LeaveCriticalSection(&d3d8_cs);
1416 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitive(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) {
1417 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1419 TRACE("(%p) Relay\n" , This);
1421 EnterCriticalSection(&d3d8_cs);
1422 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, PrimitiveType, StartVertex, PrimitiveCount);
1423 LeaveCriticalSection(&d3d8_cs);
1427 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,
1428 UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount) {
1429 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1431 TRACE("(%p) Relay\n" , This);
1433 EnterCriticalSection(&d3d8_cs);
1434 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, PrimitiveType, MinVertexIndex, NumVertices, startIndex, primCount);
1435 LeaveCriticalSection(&d3d8_cs);
1439 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT PrimitiveCount,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride) {
1440 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1442 TRACE("(%p) Relay\n" , This);
1444 EnterCriticalSection(&d3d8_cs);
1445 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
1446 LeaveCriticalSection(&d3d8_cs);
1450 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,
1451 UINT NumVertexIndices,UINT PrimitiveCount,CONST void* pIndexData,
1452 D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,
1453 UINT VertexStreamZeroStride) {
1454 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1456 TRACE("(%p) Relay\n" , This);
1458 EnterCriticalSection(&d3d8_cs);
1459 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice, PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount,
1460 pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
1461 LeaveCriticalSection(&d3d8_cs);
1465 static HRESULT WINAPI IDirect3DDevice8Impl_ProcessVertices(LPDIRECT3DDEVICE8 iface, UINT SrcStartIndex,UINT DestIndex,UINT VertexCount,IDirect3DVertexBuffer8* pDestBuffer,DWORD Flags) {
1466 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1468 TRACE("(%p) Relay\n" , This);
1470 EnterCriticalSection(&d3d8_cs);
1471 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, ((IDirect3DVertexBuffer8Impl *)pDestBuffer)->wineD3DVertexBuffer, NULL, Flags);
1472 LeaveCriticalSection(&d3d8_cs);
1476 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexDeclaration(IDirect3DDevice8 *iface, CONST DWORD *declaration, IDirect3DVertexDeclaration8 **decl_ptr) {
1477 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1478 IDirect3DVertexDeclaration8Impl *object;
1479 WINED3DVERTEXELEMENT *wined3d_elements;
1480 size_t wined3d_element_count;
1481 HRESULT hr = D3D_OK;
1483 TRACE("(%p) : declaration %p\n", This, declaration);
1485 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1487 ERR("Memory allocation failed\n");
1489 return D3DERR_OUTOFVIDEOMEMORY;
1492 object->ref_count = 1;
1493 object->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
1495 wined3d_element_count = convert_to_wined3d_declaration(declaration, &object->elements_size, &wined3d_elements);
1496 object->elements = HeapAlloc(GetProcessHeap(), 0, object->elements_size);
1497 if (!object->elements) {
1498 ERR("Memory allocation failed\n");
1499 HeapFree(GetProcessHeap(), 0, wined3d_elements);
1500 HeapFree(GetProcessHeap(), 0, object);
1502 return D3DERR_OUTOFVIDEOMEMORY;
1505 CopyMemory(object->elements, declaration, object->elements_size);
1507 EnterCriticalSection(&d3d8_cs);
1508 hr = IWineD3DDevice_CreateVertexDeclaration(This->WineD3DDevice, &object->wined3d_vertex_declaration,
1509 (IUnknown *)object, wined3d_elements, wined3d_element_count);
1510 LeaveCriticalSection(&d3d8_cs);
1511 HeapFree(GetProcessHeap(), 0, wined3d_elements);
1514 ERR("(%p) : IWineD3DDevice_CreateVertexDeclaration call failed\n", This);
1515 HeapFree(GetProcessHeap(), 0, object->elements);
1516 HeapFree(GetProcessHeap(), 0, object);
1518 *decl_ptr = (IDirect3DVertexDeclaration8 *)object;
1519 TRACE("(%p) : Created vertex declaration %p\n", This, object);
1525 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pDeclaration, CONST DWORD* pFunction, DWORD* ppShader, DWORD Usage) {
1526 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1527 HRESULT hrc = D3D_OK;
1528 IDirect3DVertexShader8Impl *object;
1529 IWineD3DVertexDeclaration *wined3d_vertex_declaration;
1531 /* Setup a stub object for now */
1532 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1533 TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
1534 if (NULL == object) {
1535 FIXME("Allocation of memory failed\n");
1537 return D3DERR_OUTOFVIDEOMEMORY;
1541 object->lpVtbl = &Direct3DVertexShader8_Vtbl;
1543 EnterCriticalSection(&d3d8_cs);
1544 hrc = IDirect3DDevice8Impl_CreateVertexDeclaration(iface, pDeclaration, &object->vertex_declaration);
1546 ERR("(%p) : IDirect3DDeviceImpl_CreateVertexDeclaration call failed\n", This);
1547 LeaveCriticalSection(&d3d8_cs);
1548 HeapFree(GetProcessHeap(), 0, object);
1550 return D3DERR_INVALIDCALL;
1552 wined3d_vertex_declaration = ((IDirect3DVertexDeclaration8Impl *)object->vertex_declaration)->wined3d_vertex_declaration;
1554 /* Usage is missing ... Use SetRenderState to set the sw vp render state in SetVertexShader */
1555 hrc = IWineD3DDevice_CreateVertexShader(This->WineD3DDevice, wined3d_vertex_declaration, pFunction, &object->wineD3DVertexShader, (IUnknown *)object);
1558 /* free up object */
1559 FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n");
1560 HeapFree(GetProcessHeap(), 0, object);
1563 /* TODO: Store the VS declarations locally so that they can be derefferenced with a value higher than VS_HIGHESTFIXEDFXF */
1564 shader_handle *handle = alloc_shader_handle(This);
1566 ERR("Failed to allocate shader handle\n");
1567 IDirect3DVertexShader8_Release((IUnknown *)object);
1568 hrc = E_OUTOFMEMORY;
1570 object->handle = handle;
1572 *ppShader = (handle - This->shader_handles) + VS_HIGHESTFIXEDFXF + 1;
1574 load_local_constants(pDeclaration, object->wineD3DVertexShader);
1577 LeaveCriticalSection(&d3d8_cs);
1578 TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
1583 IWineD3DVertexDeclaration *IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl *This, DWORD fvf)
1586 IWineD3DVertexDeclaration* pDecl = NULL;
1587 int p, low, high; /* deliberately signed */
1588 struct FvfToDecl *convertedDecls = This->decls;
1590 TRACE("Searching for declaration for fvf %08x... ", fvf);
1593 high = This->numConvertedDecls - 1;
1594 while(low <= high) {
1595 p = (low + high) >> 1;
1597 if(convertedDecls[p].fvf == fvf) {
1598 TRACE("found %p\n", convertedDecls[p].decl);
1599 return convertedDecls[p].decl;
1600 } else if(convertedDecls[p].fvf < fvf) {
1606 TRACE("not found. Creating and inserting at position %d.\n", low);
1608 hr = IWineD3DDevice_CreateVertexDeclarationFromFVF(This->WineD3DDevice,
1612 if (FAILED(hr)) return NULL;
1614 if(This->declArraySize == This->numConvertedDecls) {
1615 int grow = This->declArraySize / 2;
1616 convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
1617 sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
1618 if(!convertedDecls) {
1619 /* This will destroy it */
1620 IWineD3DVertexDeclaration_Release(pDecl);
1623 This->decls = convertedDecls;
1624 This->declArraySize += grow;
1627 memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(convertedDecls[0]) * (This->numConvertedDecls - low));
1628 convertedDecls[low].decl = pDecl;
1629 convertedDecls[low].fvf = fvf;
1630 This->numConvertedDecls++;
1632 TRACE("Returning %p. %d decls in array\n", pDecl, This->numConvertedDecls);
1636 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1637 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1638 HRESULT hrc = D3D_OK;
1640 TRACE("(%p) : Relay\n", This);
1641 EnterCriticalSection(&d3d8_cs);
1642 if (VS_HIGHESTFIXEDFXF >= pShader) {
1643 TRACE("Setting FVF, %d %d\n", VS_HIGHESTFIXEDFXF, pShader);
1644 IWineD3DDevice_SetFVF(This->WineD3DDevice, pShader);
1645 IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice, IDirect3DDevice8Impl_FindDecl(This, pShader));
1646 IWineD3DDevice_SetVertexShader(This->WineD3DDevice, NULL);
1648 TRACE("Setting shader\n");
1649 if (This->allocated_shader_handles <= pShader - (VS_HIGHESTFIXEDFXF + 1)) {
1650 FIXME("(%p) : Number of shaders exceeds the maximum number of possible shaders\n", This);
1651 hrc = D3DERR_INVALIDCALL;
1653 IDirect3DVertexShader8Impl *shader = This->shader_handles[pShader - (VS_HIGHESTFIXEDFXF + 1)];
1654 IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
1655 shader ? ((IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration)->wined3d_vertex_declaration : NULL);
1656 hrc = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, 0 == shader ? NULL : shader->wineD3DVertexShader);
1659 TRACE("(%p) : returning hr(%u)\n", This, hrc);
1660 LeaveCriticalSection(&d3d8_cs);
1665 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
1666 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1667 IWineD3DVertexShader *pShader;
1668 HRESULT hrc = D3D_OK;
1670 TRACE("(%p) : Relay device@%p\n", This, This->WineD3DDevice);
1671 EnterCriticalSection(&d3d8_cs);
1672 hrc = IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &pShader);
1673 if (D3D_OK == hrc) {
1675 IDirect3DVertexShader8Impl *d3d8_shader;
1676 hrc = IWineD3DVertexShader_GetParent(pShader, (IUnknown **)&d3d8_shader);
1677 IWineD3DVertexShader_Release(pShader);
1678 *ppShader = (d3d8_shader->handle - This->shader_handles) + (VS_HIGHESTFIXEDFXF + 1);
1684 WARN("(%p) : Call to IWineD3DDevice_GetVertexShader failed %u (device %p)\n", This, hrc, This->WineD3DDevice);
1686 TRACE("(%p) : returning %#x\n", This, *ppShader);
1687 LeaveCriticalSection(&d3d8_cs);
1692 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1693 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1695 TRACE("(%p) : pShader %#x\n", This, pShader);
1697 EnterCriticalSection(&d3d8_cs);
1698 if (pShader <= VS_HIGHESTFIXEDFXF || This->allocated_shader_handles <= pShader - (VS_HIGHESTFIXEDFXF + 1)) {
1699 ERR("(%p) : Trying to delete an invalid handle\n", This);
1700 LeaveCriticalSection(&d3d8_cs);
1701 return D3DERR_INVALIDCALL;
1703 IWineD3DVertexShader *cur = NULL;
1704 shader_handle *handle = &This->shader_handles[pShader - (VS_HIGHESTFIXEDFXF + 1)];
1705 IDirect3DVertexShader8Impl *shader = *handle;
1707 IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &cur);
1709 if(cur == shader->wineD3DVertexShader) IDirect3DDevice8_SetVertexShader(iface, 0);
1710 IWineD3DVertexShader_Release(cur);
1713 while(IUnknown_Release((IUnknown *)shader));
1714 free_shader_handle(This, handle);
1716 LeaveCriticalSection(&d3d8_cs);
1721 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
1722 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1724 TRACE("(%p) : Relay\n", This);
1726 EnterCriticalSection(&d3d8_cs);
1727 hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, (CONST float *)pConstantData, ConstantCount);
1728 LeaveCriticalSection(&d3d8_cs);
1732 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
1733 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1735 TRACE("(%p) : Relay\n", This);
1737 EnterCriticalSection(&d3d8_cs);
1738 hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, (float *)pConstantData, ConstantCount);
1739 LeaveCriticalSection(&d3d8_cs);
1743 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderDeclaration(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
1744 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1745 IDirect3DVertexDeclaration8Impl *declaration;
1746 IDirect3DVertexShader8Impl *shader = NULL;
1748 TRACE("(%p) : pVertexShader 0x%08x, pData %p, *pSizeOfData %u\n", This, pVertexShader, pData, *pSizeOfData);
1750 EnterCriticalSection(&d3d8_cs);
1751 if (pVertexShader <= VS_HIGHESTFIXEDFXF || This->allocated_shader_handles <= pVertexShader - (VS_HIGHESTFIXEDFXF + 1)) {
1752 ERR("Passed an invalid shader handle.\n");
1753 LeaveCriticalSection(&d3d8_cs);
1754 return D3DERR_INVALIDCALL;
1757 shader = This->shader_handles[pVertexShader - (VS_HIGHESTFIXEDFXF + 1)];
1758 declaration = (IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration;
1760 /* If pData is NULL, we just return the required size of the buffer. */
1762 *pSizeOfData = declaration->elements_size;
1763 LeaveCriticalSection(&d3d8_cs);
1767 /* MSDN claims that if *pSizeOfData is smaller than the required size
1768 * we should write the required size and return D3DERR_MOREDATA.
1769 * That's not actually true. */
1770 if (*pSizeOfData < declaration->elements_size) {
1771 LeaveCriticalSection(&d3d8_cs);
1772 return D3DERR_INVALIDCALL;
1775 CopyMemory(pData, declaration->elements, declaration->elements_size);
1776 LeaveCriticalSection(&d3d8_cs);
1781 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
1782 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1783 IDirect3DVertexShader8Impl *shader = NULL;
1786 TRACE("(%p) : pVertexShader %#x, pData %p, pSizeOfData %p\n", This, pVertexShader, pData, pSizeOfData);
1788 EnterCriticalSection(&d3d8_cs);
1789 if (pVertexShader <= VS_HIGHESTFIXEDFXF || This->allocated_shader_handles <= pVertexShader - (VS_HIGHESTFIXEDFXF + 1)) {
1790 ERR("Passed an invalid shader handle.\n");
1791 LeaveCriticalSection(&d3d8_cs);
1792 return D3DERR_INVALIDCALL;
1795 shader = This->shader_handles[pVertexShader - (VS_HIGHESTFIXEDFXF + 1)];
1796 hr = IWineD3DVertexShader_GetFunction(shader->wineD3DVertexShader, pData, (UINT *)pSizeOfData);
1797 LeaveCriticalSection(&d3d8_cs);
1801 static HRESULT WINAPI IDirect3DDevice8Impl_SetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8* pIndexData, UINT baseVertexIndex) {
1802 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1804 TRACE("(%p) Relay\n", This);
1806 EnterCriticalSection(&d3d8_cs);
1807 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
1808 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
1809 * vertex buffers can't be created to address them with an index that requires the 32nd bit
1810 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
1813 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, baseVertexIndex);
1814 hr = IWineD3DDevice_SetIndices(This->WineD3DDevice,
1815 pIndexData ? ((IDirect3DIndexBuffer8Impl *)pIndexData)->wineD3DIndexBuffer : NULL);
1816 LeaveCriticalSection(&d3d8_cs);
1820 static HRESULT WINAPI IDirect3DDevice8Impl_GetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8** ppIndexData,UINT* pBaseVertexIndex) {
1821 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1822 IWineD3DIndexBuffer *retIndexData = NULL;
1823 HRESULT rc = D3D_OK;
1825 TRACE("(%p) Relay\n", This);
1827 if(ppIndexData == NULL){
1828 return D3DERR_INVALIDCALL;
1831 EnterCriticalSection(&d3d8_cs);
1832 /* The case from UINT to INT is safe because d3d8 will never set negative values */
1833 IWineD3DDevice_GetBaseVertexIndex(This->WineD3DDevice, (INT *) pBaseVertexIndex);
1834 rc = IWineD3DDevice_GetIndices(This->WineD3DDevice, &retIndexData);
1835 if (SUCCEEDED(rc) && retIndexData) {
1836 IWineD3DIndexBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
1837 IWineD3DIndexBuffer_Release(retIndexData);
1839 if (FAILED(rc)) FIXME("Call to GetIndices failed\n");
1840 *ppIndexData = NULL;
1842 LeaveCriticalSection(&d3d8_cs);
1846 static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pFunction, DWORD* ppShader) {
1847 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1848 IDirect3DPixelShader8Impl *object;
1849 HRESULT hrc = D3D_OK;
1851 TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
1853 if (NULL == ppShader) {
1854 TRACE("(%p) Invalid call\n", This);
1855 return D3DERR_INVALIDCALL;
1857 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1859 if (NULL == object) {
1860 return E_OUTOFMEMORY;
1862 EnterCriticalSection(&d3d8_cs);
1865 object->lpVtbl = &Direct3DPixelShader8_Vtbl;
1866 hrc = IWineD3DDevice_CreatePixelShader(This->WineD3DDevice, pFunction, &object->wineD3DPixelShader , (IUnknown *)object);
1867 if (D3D_OK != hrc) {
1868 FIXME("(%p) call to IWineD3DDevice_CreatePixelShader failed\n", This);
1869 HeapFree(GetProcessHeap(), 0 , object);
1872 shader_handle *handle = alloc_shader_handle(This);
1874 ERR("Failed to allocate shader handle\n");
1875 IDirect3DVertexShader8_Release((IUnknown *)object);
1876 hrc = E_OUTOFMEMORY;
1878 object->handle = handle;
1880 *ppShader = (handle - This->shader_handles) + VS_HIGHESTFIXEDFXF + 1;
1883 LeaveCriticalSection(&d3d8_cs);
1886 TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
1890 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1891 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1892 IDirect3DPixelShader8Impl *shader = NULL;
1895 TRACE("(%p) : pShader %#x\n", This, pShader);
1897 EnterCriticalSection(&d3d8_cs);
1898 if (pShader > VS_HIGHESTFIXEDFXF && This->allocated_shader_handles > pShader - (VS_HIGHESTFIXEDFXF + 1)) {
1899 shader = This->shader_handles[pShader - (VS_HIGHESTFIXEDFXF + 1)];
1900 } else if (pShader) {
1901 ERR("Trying to set an invalid handle.\n");
1904 TRACE("(%p) : Setting shader %p\n", This, shader);
1905 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, shader == NULL ? NULL :shader->wineD3DPixelShader);
1906 LeaveCriticalSection(&d3d8_cs);
1910 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
1911 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1912 IWineD3DPixelShader *object;
1914 HRESULT hrc = D3D_OK;
1915 TRACE("(%p) Relay\n", This);
1916 if (NULL == ppShader) {
1917 TRACE("(%p) Invalid call\n", This);
1918 return D3DERR_INVALIDCALL;
1921 EnterCriticalSection(&d3d8_cs);
1922 hrc = IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &object);
1923 if (D3D_OK == hrc && NULL != object) {
1924 IDirect3DPixelShader8Impl *d3d8_shader;
1925 hrc = IWineD3DPixelShader_GetParent(object, (IUnknown **)&d3d8_shader);
1926 IWineD3DPixelShader_Release(object);
1927 *ppShader = (d3d8_shader->handle - This->shader_handles) + (VS_HIGHESTFIXEDFXF + 1);
1929 *ppShader = (DWORD)NULL;
1932 TRACE("(%p) : returning %#x\n", This, *ppShader);
1933 LeaveCriticalSection(&d3d8_cs);
1937 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1938 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1940 TRACE("(%p) : pShader %#x\n", This, pShader);
1942 EnterCriticalSection(&d3d8_cs);
1943 if (pShader <= VS_HIGHESTFIXEDFXF || This->allocated_shader_handles <= pShader - (VS_HIGHESTFIXEDFXF + 1)) {
1944 ERR("(%p) : Trying to delete an invalid handle\n", This);
1945 LeaveCriticalSection(&d3d8_cs);
1946 return D3DERR_INVALIDCALL;
1948 IWineD3DPixelShader *cur = NULL;
1949 shader_handle *handle = &This->shader_handles[pShader - (VS_HIGHESTFIXEDFXF + 1)];
1950 IDirect3DPixelShader8Impl *shader = *handle;
1952 IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &cur);
1954 if(cur == shader->wineD3DPixelShader) IDirect3DDevice8_SetPixelShader(iface, 0);
1955 IWineD3DPixelShader_Release(cur);
1958 while(IUnknown_Release((IUnknown *)shader));
1959 free_shader_handle(This, handle);
1961 LeaveCriticalSection(&d3d8_cs);
1966 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
1967 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1969 TRACE("(%p) Relay\n", This);
1971 EnterCriticalSection(&d3d8_cs);
1972 hr = IWineD3DDevice_SetPixelShaderConstantF(This->WineD3DDevice, Register, (CONST float *)pConstantData, ConstantCount);
1973 LeaveCriticalSection(&d3d8_cs);
1977 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
1978 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1980 TRACE("(%p) Relay\n", This);
1982 EnterCriticalSection(&d3d8_cs);
1983 hr = IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, Register, (float *)pConstantData, ConstantCount);
1984 LeaveCriticalSection(&d3d8_cs);
1988 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pPixelShader, void* pData, DWORD* pSizeOfData) {
1989 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1990 IDirect3DPixelShader8Impl *shader = NULL;
1993 TRACE("(%p) : pPixelShader %#x, pData %p, pSizeOfData %p\n", This, pPixelShader, pData, pSizeOfData);
1995 EnterCriticalSection(&d3d8_cs);
1996 if (pPixelShader <= VS_HIGHESTFIXEDFXF || This->allocated_shader_handles <= pPixelShader - (VS_HIGHESTFIXEDFXF + 1)) {
1997 ERR("Passed an invalid shader handle.\n");
1998 LeaveCriticalSection(&d3d8_cs);
1999 return D3DERR_INVALIDCALL;
2002 shader = This->shader_handles[pPixelShader - (VS_HIGHESTFIXEDFXF + 1)];
2003 hr = IWineD3DPixelShader_GetFunction(shader->wineD3DPixelShader, pData, (UINT *)pSizeOfData);
2004 LeaveCriticalSection(&d3d8_cs);
2008 static HRESULT WINAPI IDirect3DDevice8Impl_DrawRectPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
2009 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2011 TRACE("(%p) Relay\n", This);
2013 EnterCriticalSection(&d3d8_cs);
2014 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
2015 LeaveCriticalSection(&d3d8_cs);
2019 static HRESULT WINAPI IDirect3DDevice8Impl_DrawTriPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
2020 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2022 TRACE("(%p) Relay\n", This);
2024 EnterCriticalSection(&d3d8_cs);
2025 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
2026 LeaveCriticalSection(&d3d8_cs);
2030 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePatch(LPDIRECT3DDEVICE8 iface, UINT Handle) {
2031 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2033 TRACE("(%p) Relay\n", This);
2035 EnterCriticalSection(&d3d8_cs);
2036 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
2037 LeaveCriticalSection(&d3d8_cs);
2041 static HRESULT WINAPI IDirect3DDevice8Impl_SetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8* pStreamData,UINT Stride) {
2042 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2044 TRACE("(%p) Relay\n" , This);
2046 EnterCriticalSection(&d3d8_cs);
2047 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
2048 NULL == pStreamData ? NULL : ((IDirect3DVertexBuffer8Impl *)pStreamData)->wineD3DVertexBuffer,
2049 0/* Offset in bytes */, Stride);
2050 LeaveCriticalSection(&d3d8_cs);
2054 static HRESULT WINAPI IDirect3DDevice8Impl_GetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8** pStream,UINT* pStride) {
2055 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
2056 IWineD3DVertexBuffer *retStream = NULL;
2057 HRESULT rc = D3D_OK;
2059 TRACE("(%p) Relay\n" , This);
2061 if(pStream == NULL){
2062 return D3DERR_INVALIDCALL;
2065 EnterCriticalSection(&d3d8_cs);
2066 rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, 0 /* Offset in bytes */, pStride);
2067 if (rc == D3D_OK && NULL != retStream) {
2068 IWineD3DVertexBuffer_GetParent(retStream, (IUnknown **)pStream);
2069 IWineD3DVertexBuffer_Release(retStream);
2072 FIXME("Call to GetStreamSource failed %p\n", pStride);
2076 LeaveCriticalSection(&d3d8_cs);
2082 const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl =
2084 IDirect3DDevice8Impl_QueryInterface,
2085 IDirect3DDevice8Impl_AddRef,
2086 IDirect3DDevice8Impl_Release,
2087 IDirect3DDevice8Impl_TestCooperativeLevel,
2088 IDirect3DDevice8Impl_GetAvailableTextureMem,
2089 IDirect3DDevice8Impl_ResourceManagerDiscardBytes,
2090 IDirect3DDevice8Impl_GetDirect3D,
2091 IDirect3DDevice8Impl_GetDeviceCaps,
2092 IDirect3DDevice8Impl_GetDisplayMode,
2093 IDirect3DDevice8Impl_GetCreationParameters,
2094 IDirect3DDevice8Impl_SetCursorProperties,
2095 IDirect3DDevice8Impl_SetCursorPosition,
2096 IDirect3DDevice8Impl_ShowCursor,
2097 IDirect3DDevice8Impl_CreateAdditionalSwapChain,
2098 IDirect3DDevice8Impl_Reset,
2099 IDirect3DDevice8Impl_Present,
2100 IDirect3DDevice8Impl_GetBackBuffer,
2101 IDirect3DDevice8Impl_GetRasterStatus,
2102 IDirect3DDevice8Impl_SetGammaRamp,
2103 IDirect3DDevice8Impl_GetGammaRamp,
2104 IDirect3DDevice8Impl_CreateTexture,
2105 IDirect3DDevice8Impl_CreateVolumeTexture,
2106 IDirect3DDevice8Impl_CreateCubeTexture,
2107 IDirect3DDevice8Impl_CreateVertexBuffer,
2108 IDirect3DDevice8Impl_CreateIndexBuffer,
2109 IDirect3DDevice8Impl_CreateRenderTarget,
2110 IDirect3DDevice8Impl_CreateDepthStencilSurface,
2111 IDirect3DDevice8Impl_CreateImageSurface,
2112 IDirect3DDevice8Impl_CopyRects,
2113 IDirect3DDevice8Impl_UpdateTexture,
2114 IDirect3DDevice8Impl_GetFrontBuffer,
2115 IDirect3DDevice8Impl_SetRenderTarget,
2116 IDirect3DDevice8Impl_GetRenderTarget,
2117 IDirect3DDevice8Impl_GetDepthStencilSurface,
2118 IDirect3DDevice8Impl_BeginScene,
2119 IDirect3DDevice8Impl_EndScene,
2120 IDirect3DDevice8Impl_Clear,
2121 IDirect3DDevice8Impl_SetTransform,
2122 IDirect3DDevice8Impl_GetTransform,
2123 IDirect3DDevice8Impl_MultiplyTransform,
2124 IDirect3DDevice8Impl_SetViewport,
2125 IDirect3DDevice8Impl_GetViewport,
2126 IDirect3DDevice8Impl_SetMaterial,
2127 IDirect3DDevice8Impl_GetMaterial,
2128 IDirect3DDevice8Impl_SetLight,
2129 IDirect3DDevice8Impl_GetLight,
2130 IDirect3DDevice8Impl_LightEnable,
2131 IDirect3DDevice8Impl_GetLightEnable,
2132 IDirect3DDevice8Impl_SetClipPlane,
2133 IDirect3DDevice8Impl_GetClipPlane,
2134 IDirect3DDevice8Impl_SetRenderState,
2135 IDirect3DDevice8Impl_GetRenderState,
2136 IDirect3DDevice8Impl_BeginStateBlock,
2137 IDirect3DDevice8Impl_EndStateBlock,
2138 IDirect3DDevice8Impl_ApplyStateBlock,
2139 IDirect3DDevice8Impl_CaptureStateBlock,
2140 IDirect3DDevice8Impl_DeleteStateBlock,
2141 IDirect3DDevice8Impl_CreateStateBlock,
2142 IDirect3DDevice8Impl_SetClipStatus,
2143 IDirect3DDevice8Impl_GetClipStatus,
2144 IDirect3DDevice8Impl_GetTexture,
2145 IDirect3DDevice8Impl_SetTexture,
2146 IDirect3DDevice8Impl_GetTextureStageState,
2147 IDirect3DDevice8Impl_SetTextureStageState,
2148 IDirect3DDevice8Impl_ValidateDevice,
2149 IDirect3DDevice8Impl_GetInfo,
2150 IDirect3DDevice8Impl_SetPaletteEntries,
2151 IDirect3DDevice8Impl_GetPaletteEntries,
2152 IDirect3DDevice8Impl_SetCurrentTexturePalette,
2153 IDirect3DDevice8Impl_GetCurrentTexturePalette,
2154 IDirect3DDevice8Impl_DrawPrimitive,
2155 IDirect3DDevice8Impl_DrawIndexedPrimitive,
2156 IDirect3DDevice8Impl_DrawPrimitiveUP,
2157 IDirect3DDevice8Impl_DrawIndexedPrimitiveUP,
2158 IDirect3DDevice8Impl_ProcessVertices,
2159 IDirect3DDevice8Impl_CreateVertexShader,
2160 IDirect3DDevice8Impl_SetVertexShader,
2161 IDirect3DDevice8Impl_GetVertexShader,
2162 IDirect3DDevice8Impl_DeleteVertexShader,
2163 IDirect3DDevice8Impl_SetVertexShaderConstant,
2164 IDirect3DDevice8Impl_GetVertexShaderConstant,
2165 IDirect3DDevice8Impl_GetVertexShaderDeclaration,
2166 IDirect3DDevice8Impl_GetVertexShaderFunction,
2167 IDirect3DDevice8Impl_SetStreamSource,
2168 IDirect3DDevice8Impl_GetStreamSource,
2169 IDirect3DDevice8Impl_SetIndices,
2170 IDirect3DDevice8Impl_GetIndices,
2171 IDirect3DDevice8Impl_CreatePixelShader,
2172 IDirect3DDevice8Impl_SetPixelShader,
2173 IDirect3DDevice8Impl_GetPixelShader,
2174 IDirect3DDevice8Impl_DeletePixelShader,
2175 IDirect3DDevice8Impl_SetPixelShaderConstant,
2176 IDirect3DDevice8Impl_GetPixelShaderConstant,
2177 IDirect3DDevice8Impl_GetPixelShaderFunction,
2178 IDirect3DDevice8Impl_DrawRectPatch,
2179 IDirect3DDevice8Impl_DrawTriPatch,
2180 IDirect3DDevice8Impl_DeletePatch
2183 /* Internal function called back during the CreateDevice to create a render target */
2184 HRESULT WINAPI D3D8CB_CreateSurface(IUnknown *device, IUnknown *pSuperior, UINT Width, UINT Height,
2185 WINED3DFORMAT Format, DWORD Usage, WINED3DPOOL Pool, UINT Level,
2186 WINED3DCUBEMAP_FACES Face, IWineD3DSurface **ppSurface,
2187 HANDLE *pSharedHandle) {
2189 HRESULT res = D3D_OK;
2190 IDirect3DSurface8Impl *d3dSurface = NULL;
2191 BOOL Lockable = TRUE;
2193 if((WINED3DPOOL_DEFAULT == Pool && WINED3DUSAGE_DYNAMIC != Usage))
2197 res = IDirect3DDevice8Impl_CreateSurface((IDirect3DDevice8 *)device, Width, Height, (D3DFORMAT)Format, Lockable, FALSE/*Discard*/, Level, (IDirect3DSurface8 **)&d3dSurface, D3DRTYPE_SURFACE, Usage, Pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
2199 if (SUCCEEDED(res)) {
2200 *ppSurface = d3dSurface->wineD3DSurface;
2201 d3dSurface->container = pSuperior;
2202 IUnknown_Release(d3dSurface->parentDevice);
2203 d3dSurface->parentDevice = NULL;
2204 d3dSurface->forwardReference = pSuperior;
2206 FIXME("(%p) IDirect3DDevice8_CreateSurface failed\n", device);
2211 ULONG WINAPI D3D8CB_DestroySurface(IWineD3DSurface *pSurface) {
2212 IDirect3DSurface8Impl* surfaceParent;
2213 TRACE("(%p) call back\n", pSurface);
2215 IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
2216 /* GetParent's AddRef was forwarded to an object in destruction.
2217 * Releasing it here again would cause an endless recursion. */
2218 surfaceParent->forwardReference = NULL;
2219 return IDirect3DSurface8_Release((IDirect3DSurface8*) surfaceParent);