d3d8: Hold the lock in IDirect3DDevice8 methods.
[wine.git] / dlls / d3d8 / device.c
blobf7bc68faa667fe3d83c49df859a2c976e6f77269
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 /* 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;
45 return handle;
47 if (!(This->allocated_shader_handles < This->shader_handle_table_size)) {
48 /* Grow the table */
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);
72 *ppobj = This;
73 return S_OK;
76 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
77 *ppobj = NULL;
78 return E_NOINTERFACE;
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);
87 return ref;
90 static ULONG WINAPI IDirect3DDevice8Impl_Release(LPDIRECT3DDEVICE8 iface) {
91 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
92 ULONG ref;
94 if (This->inDestruction) return 0;
95 ref = InterlockedDecrement(&This->ref);
97 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
99 if (ref == 0) {
100 TRACE("Releasing wined3d device %p\n", This->WineD3DDevice);
101 EnterCriticalSection(&d3d8_cs);
102 This->inDestruction = TRUE;
103 IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D8CB_DestroyDepthStencilSurface, D3D8CB_DestroySwapChain);
104 IWineD3DDevice_Release(This->WineD3DDevice);
105 HeapFree(GetProcessHeap(), 0, This->shader_handles);
106 HeapFree(GetProcessHeap(), 0, This);
107 LeaveCriticalSection(&d3d8_cs);
109 return ref;
112 /* IDirect3DDevice Interface follow: */
113 static HRESULT WINAPI IDirect3DDevice8Impl_TestCooperativeLevel(LPDIRECT3DDEVICE8 iface) {
114 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
115 HRESULT hr;
117 TRACE("(%p) : Relay\n", This);
118 EnterCriticalSection(&d3d8_cs);
119 hr = IWineD3DDevice_TestCooperativeLevel(This->WineD3DDevice);
120 LeaveCriticalSection(&d3d8_cs);
121 return hr;
124 static UINT WINAPI IDirect3DDevice8Impl_GetAvailableTextureMem(LPDIRECT3DDEVICE8 iface) {
125 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
126 HRESULT hr;
128 TRACE("(%p) Relay\n", This);
129 EnterCriticalSection(&d3d8_cs);
130 hr = IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
131 LeaveCriticalSection(&d3d8_cs);
132 return hr;
135 static HRESULT WINAPI IDirect3DDevice8Impl_ResourceManagerDiscardBytes(LPDIRECT3DDEVICE8 iface, DWORD Bytes) {
136 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
137 HRESULT hr;
139 TRACE("(%p) : Relay bytes(%d)\n", This, Bytes);
140 EnterCriticalSection(&d3d8_cs);
141 hr = IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
142 LeaveCriticalSection(&d3d8_cs);
143 return hr;
146 static HRESULT WINAPI IDirect3DDevice8Impl_GetDirect3D(LPDIRECT3DDEVICE8 iface, IDirect3D8** ppD3D8) {
147 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
148 HRESULT hr = D3D_OK;
149 IWineD3D* pWineD3D;
151 TRACE("(%p) Relay\n", This);
153 if (NULL == ppD3D8) {
154 return D3DERR_INVALIDCALL;
157 EnterCriticalSection(&d3d8_cs);
158 hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &pWineD3D);
159 if (hr == D3D_OK && pWineD3D != NULL)
161 IWineD3D_GetParent(pWineD3D,(IUnknown **)ppD3D8);
162 IWineD3D_Release(pWineD3D);
163 } else {
164 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
165 *ppD3D8 = NULL;
167 TRACE("(%p) returning %p\n",This , *ppD3D8);
168 LeaveCriticalSection(&d3d8_cs);
170 return hr;
173 static HRESULT WINAPI IDirect3DDevice8Impl_GetDeviceCaps(LPDIRECT3DDEVICE8 iface, D3DCAPS8* pCaps) {
174 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
175 HRESULT hrc = D3D_OK;
176 WINED3DCAPS *pWineCaps;
178 TRACE("(%p) : Relay pCaps %p\n", This, pCaps);
179 if(NULL == pCaps){
180 return D3DERR_INVALIDCALL;
182 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
183 if(pWineCaps == NULL){
184 return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
187 D3D8CAPSTOWINECAPS(pCaps, pWineCaps)
188 EnterCriticalSection(&d3d8_cs);
189 hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
190 LeaveCriticalSection(&d3d8_cs);
191 HeapFree(GetProcessHeap(), 0, pWineCaps);
193 /* D3D8 doesn't support SM 2.0 or higher, so clamp to 1.x */
194 if(pCaps->PixelShaderVersion > D3DPS_VERSION(1,4)){
195 pCaps->PixelShaderVersion = D3DPS_VERSION(1,4);
197 if(pCaps->VertexShaderVersion > D3DVS_VERSION(1,1)){
198 pCaps->VertexShaderVersion = D3DVS_VERSION(1,1);
201 TRACE("Returning %p %p\n", This, pCaps);
202 return hrc;
205 static HRESULT WINAPI IDirect3DDevice8Impl_GetDisplayMode(LPDIRECT3DDEVICE8 iface, D3DDISPLAYMODE* pMode) {
206 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
207 HRESULT hr;
208 TRACE("(%p) Relay\n", This);
210 EnterCriticalSection(&d3d8_cs);
211 hr = IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, 0, (WINED3DDISPLAYMODE *) pMode);
212 LeaveCriticalSection(&d3d8_cs);
213 return hr;
216 static HRESULT WINAPI IDirect3DDevice8Impl_GetCreationParameters(LPDIRECT3DDEVICE8 iface, D3DDEVICE_CREATION_PARAMETERS *pParameters) {
217 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
218 HRESULT hr;
219 TRACE("(%p) Relay\n", This);
221 EnterCriticalSection(&d3d8_cs);
222 hr = IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
223 LeaveCriticalSection(&d3d8_cs);
224 return hr;
227 static HRESULT WINAPI IDirect3DDevice8Impl_SetCursorProperties(LPDIRECT3DDEVICE8 iface, UINT XHotSpot, UINT YHotSpot, IDirect3DSurface8* pCursorBitmap) {
228 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
229 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl*)pCursorBitmap;
230 HRESULT hr;
231 TRACE("(%p) Relay\n", This);
232 if(!pCursorBitmap) {
233 WARN("No cursor bitmap, returning WINED3DERR_INVALIDCALL\n");
234 return WINED3DERR_INVALIDCALL;
237 EnterCriticalSection(&d3d8_cs);
238 hr = IWineD3DDevice_SetCursorProperties(This->WineD3DDevice,XHotSpot,YHotSpot,(IWineD3DSurface*)pSurface->wineD3DSurface);
239 LeaveCriticalSection(&d3d8_cs);
240 return hr;
243 static void WINAPI IDirect3DDevice8Impl_SetCursorPosition(LPDIRECT3DDEVICE8 iface, UINT XScreenSpace, UINT YScreenSpace, DWORD Flags) {
244 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
245 TRACE("(%p) Relay\n", This);
247 EnterCriticalSection(&d3d8_cs);
248 IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
249 LeaveCriticalSection(&d3d8_cs);
252 static BOOL WINAPI IDirect3DDevice8Impl_ShowCursor(LPDIRECT3DDEVICE8 iface, BOOL bShow) {
253 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
254 BOOL ret;
255 TRACE("(%p) Relay\n", This);
257 EnterCriticalSection(&d3d8_cs);
258 ret = IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
259 LeaveCriticalSection(&d3d8_cs);
260 return ret;
263 static HRESULT WINAPI IDirect3DDevice8Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain8** pSwapChain) {
264 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
265 IDirect3DSwapChain8Impl* object;
266 HRESULT hrc = D3D_OK;
267 WINED3DPRESENT_PARAMETERS localParameters;
269 TRACE("(%p) Relay\n", This);
271 /* Fix the back buffer count */
272 if(pPresentationParameters->BackBufferCount == 0) {
273 pPresentationParameters->BackBufferCount = 1;
276 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
277 if (NULL == object) {
278 FIXME("Allocation of memory failed\n");
279 *pSwapChain = NULL;
280 return D3DERR_OUTOFVIDEOMEMORY;
282 object->ref = 1;
283 object->lpVtbl = &Direct3DSwapChain8_Vtbl;
285 /* Allocate an associated WineD3DDevice object */
286 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
287 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
288 localParameters.BackBufferFormat = pPresentationParameters->BackBufferFormat;
289 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
290 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
291 localParameters.MultiSampleQuality = 0; /* d3d9 only */
292 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
293 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
294 localParameters.Windowed = pPresentationParameters->Windowed;
295 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
296 localParameters.AutoDepthStencilFormat = pPresentationParameters->AutoDepthStencilFormat;
297 localParameters.Flags = pPresentationParameters->Flags;
298 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
299 localParameters.PresentationInterval = pPresentationParameters->FullScreen_PresentationInterval;
301 EnterCriticalSection(&d3d8_cs);
302 hrc = IWineD3DDevice_CreateAdditionalSwapChain(This->WineD3DDevice, &localParameters, &object->wineD3DSwapChain, (IUnknown*)object, D3D8CB_CreateRenderTarget, D3D8CB_CreateDepthStencilSurface);
303 LeaveCriticalSection(&d3d8_cs);
305 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
306 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
307 pPresentationParameters->BackBufferFormat = localParameters.BackBufferFormat;
308 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
309 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
310 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
311 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
312 pPresentationParameters->Windowed = localParameters.Windowed;
313 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
314 pPresentationParameters->AutoDepthStencilFormat = localParameters.AutoDepthStencilFormat;
315 pPresentationParameters->Flags = localParameters.Flags;
316 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
317 pPresentationParameters->FullScreen_PresentationInterval = localParameters.PresentationInterval;
319 if (hrc != D3D_OK) {
320 FIXME("(%p) call to IWineD3DDevice_CreateAdditionalSwapChain failed\n", This);
321 HeapFree(GetProcessHeap(), 0 , object);
322 *pSwapChain = NULL;
323 }else{
324 IUnknown_AddRef(iface);
325 object->parentDevice = iface;
326 *pSwapChain = (IDirect3DSwapChain8 *)object;
328 TRACE("(%p) returning %p\n", This, *pSwapChain);
329 return hrc;
332 static HRESULT WINAPI IDirect3DDevice8Impl_Reset(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
333 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
334 WINED3DPRESENT_PARAMETERS localParameters;
335 HRESULT hr;
337 TRACE("(%p) Relay pPresentationParameters(%p)\n", This, pPresentationParameters);
339 localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
340 localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
341 localParameters.BackBufferFormat = pPresentationParameters->BackBufferFormat;
342 localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
343 localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
344 localParameters.MultiSampleQuality = 0; /* d3d9 only */
345 localParameters.SwapEffect = pPresentationParameters->SwapEffect;
346 localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
347 localParameters.Windowed = pPresentationParameters->Windowed;
348 localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
349 localParameters.AutoDepthStencilFormat = pPresentationParameters->AutoDepthStencilFormat;
350 localParameters.Flags = pPresentationParameters->Flags;
351 localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
352 localParameters.PresentationInterval = pPresentationParameters->FullScreen_PresentationInterval;
354 EnterCriticalSection(&d3d8_cs);
355 hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
356 LeaveCriticalSection(&d3d8_cs);
358 pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
359 pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
360 pPresentationParameters->BackBufferFormat = localParameters.BackBufferFormat;
361 pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
362 pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
363 pPresentationParameters->SwapEffect = localParameters.SwapEffect;
364 pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
365 pPresentationParameters->Windowed = localParameters.Windowed;
366 pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
367 pPresentationParameters->AutoDepthStencilFormat = localParameters.AutoDepthStencilFormat;
368 pPresentationParameters->Flags = localParameters.Flags;
369 pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
370 pPresentationParameters->FullScreen_PresentationInterval = localParameters.PresentationInterval;
372 return hr;
375 static HRESULT WINAPI IDirect3DDevice8Impl_Present(LPDIRECT3DDEVICE8 iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion) {
376 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
377 HRESULT hr;
378 TRACE("(%p) Relay\n", This);
380 EnterCriticalSection(&d3d8_cs);
381 hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
382 LeaveCriticalSection(&d3d8_cs);
383 return hr;
386 static HRESULT WINAPI IDirect3DDevice8Impl_GetBackBuffer(LPDIRECT3DDEVICE8 iface, UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8** ppBackBuffer) {
387 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
388 IWineD3DSurface *retSurface = NULL;
389 HRESULT rc = D3D_OK;
391 TRACE("(%p) Relay\n", This);
393 EnterCriticalSection(&d3d8_cs);
394 rc = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, 0, BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, (IWineD3DSurface **)&retSurface);
395 if (rc == D3D_OK && NULL != retSurface && NULL != ppBackBuffer) {
396 IWineD3DSurface_GetParent(retSurface, (IUnknown **)ppBackBuffer);
397 IWineD3DSurface_Release(retSurface);
399 LeaveCriticalSection(&d3d8_cs);
400 return rc;
403 static HRESULT WINAPI IDirect3DDevice8Impl_GetRasterStatus(LPDIRECT3DDEVICE8 iface, D3DRASTER_STATUS* pRasterStatus) {
404 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
405 HRESULT hr;
406 TRACE("(%p) Relay\n", This);
408 EnterCriticalSection(&d3d8_cs);
409 hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, 0, (WINED3DRASTER_STATUS *) pRasterStatus);
410 LeaveCriticalSection(&d3d8_cs);
411 return hr;
414 static void WINAPI IDirect3DDevice8Impl_SetGammaRamp(LPDIRECT3DDEVICE8 iface, DWORD Flags, CONST D3DGAMMARAMP* pRamp) {
415 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
416 TRACE("(%p) Relay\n", This);
418 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
419 EnterCriticalSection(&d3d8_cs);
420 IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, 0, Flags, (CONST WINED3DGAMMARAMP *) pRamp);
421 LeaveCriticalSection(&d3d8_cs);
424 static void WINAPI IDirect3DDevice8Impl_GetGammaRamp(LPDIRECT3DDEVICE8 iface, D3DGAMMARAMP* pRamp) {
425 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
426 TRACE("(%p) Relay\n", This);
428 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
429 EnterCriticalSection(&d3d8_cs);
430 IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, 0, (WINED3DGAMMARAMP *) pRamp);
431 LeaveCriticalSection(&d3d8_cs);
434 static HRESULT WINAPI IDirect3DDevice8Impl_CreateTexture(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, UINT Levels, DWORD Usage,
435 D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture8 **ppTexture) {
436 IDirect3DTexture8Impl *object;
437 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
438 HRESULT hrc = D3D_OK;
440 TRACE("(%p) : W(%d) H(%d), Lvl(%d) d(%d), Fmt(%u), Pool(%d)\n", This, Width, Height, Levels, Usage, Format, Pool);
442 /* Allocate the storage for the device */
443 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DTexture8Impl));
445 if (NULL == object) {
446 FIXME("Allocation of memory failed\n");
447 /* *ppTexture = NULL; */
448 return D3DERR_OUTOFVIDEOMEMORY;
451 object->lpVtbl = &Direct3DTexture8_Vtbl;
452 object->ref = 1;
453 EnterCriticalSection(&d3d8_cs);
454 hrc = IWineD3DDevice_CreateTexture(This->WineD3DDevice, Width, Height, Levels, Usage & WINED3DUSAGE_MASK,
455 (WINED3DFORMAT)Format, (WINED3DPOOL) Pool, &object->wineD3DTexture, NULL, (IUnknown *)object, D3D8CB_CreateSurface);
456 LeaveCriticalSection(&d3d8_cs);
458 if (FAILED(hrc)) {
459 /* free up object */
460 FIXME("(%p) call to IWineD3DDevice_CreateTexture failed\n", This);
461 HeapFree(GetProcessHeap(), 0, object);
462 /* *ppTexture = NULL; */
463 } else {
464 IUnknown_AddRef(iface);
465 object->parentDevice = iface;
466 *ppTexture = (LPDIRECT3DTEXTURE8) object;
469 TRACE("(%p) Created Texture %p, %p\n",This,object,object->wineD3DTexture);
470 return hrc;
473 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVolumeTexture(LPDIRECT3DDEVICE8 iface,
474 UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage,
475 D3DFORMAT Format, D3DPOOL Pool, IDirect3DVolumeTexture8** ppVolumeTexture) {
477 IDirect3DVolumeTexture8Impl *object;
478 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
479 HRESULT hrc = D3D_OK;
481 TRACE("(%p) Relay\n", This);
483 /* Allocate the storage for the device */
484 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVolumeTexture8Impl));
485 if (NULL == object) {
486 FIXME("(%p) allocation of memory failed\n", This);
487 *ppVolumeTexture = NULL;
488 return D3DERR_OUTOFVIDEOMEMORY;
491 object->lpVtbl = &Direct3DVolumeTexture8_Vtbl;
492 object->ref = 1;
493 EnterCriticalSection(&d3d8_cs);
494 hrc = IWineD3DDevice_CreateVolumeTexture(This->WineD3DDevice, Width, Height, Depth, Levels, Usage & WINED3DUSAGE_MASK,
495 (WINED3DFORMAT)Format, (WINED3DPOOL) Pool, &object->wineD3DVolumeTexture, NULL,
496 (IUnknown *)object, D3D8CB_CreateVolume);
497 LeaveCriticalSection(&d3d8_cs);
499 if (hrc != D3D_OK) {
501 /* free up object */
502 FIXME("(%p) call to IWineD3DDevice_CreateVolumeTexture failed\n", This);
503 HeapFree(GetProcessHeap(), 0, object);
504 *ppVolumeTexture = NULL;
505 } else {
506 IUnknown_AddRef(iface);
507 object->parentDevice = iface;
508 *ppVolumeTexture = (LPDIRECT3DVOLUMETEXTURE8) object;
510 TRACE("(%p) returning %p\n", This , *ppVolumeTexture);
511 return hrc;
514 static HRESULT WINAPI IDirect3DDevice8Impl_CreateCubeTexture(LPDIRECT3DDEVICE8 iface, UINT EdgeLength, UINT Levels, DWORD Usage,
515 D3DFORMAT Format, D3DPOOL Pool, IDirect3DCubeTexture8** ppCubeTexture) {
517 IDirect3DCubeTexture8Impl *object;
518 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
519 HRESULT hr = D3D_OK;
521 TRACE("(%p) : ELen(%d) Lvl(%d) Usage(%d) fmt(%u), Pool(%d)\n" , This, EdgeLength, Levels, Usage, Format, Pool);
523 /* Allocate the storage for the device */
524 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
526 if (NULL == object) {
527 FIXME("(%p) allocation of CubeTexture failed\n", This);
528 *ppCubeTexture = NULL;
529 return D3DERR_OUTOFVIDEOMEMORY;
532 object->lpVtbl = &Direct3DCubeTexture8_Vtbl;
533 object->ref = 1;
534 EnterCriticalSection(&d3d8_cs);
535 hr = IWineD3DDevice_CreateCubeTexture(This->WineD3DDevice, EdgeLength, Levels, Usage & WINED3DUSAGE_MASK,
536 (WINED3DFORMAT)Format, (WINED3DPOOL) Pool, &object->wineD3DCubeTexture, NULL, (IUnknown*)object,
537 D3D8CB_CreateSurface);
538 LeaveCriticalSection(&d3d8_cs);
540 if (hr != D3D_OK){
542 /* free up object */
543 FIXME("(%p) call to IWineD3DDevice_CreateCubeTexture failed\n", This);
544 HeapFree(GetProcessHeap(), 0, object);
545 *ppCubeTexture = NULL;
546 } else {
547 IUnknown_AddRef(iface);
548 object->parentDevice = iface;
549 *ppCubeTexture = (LPDIRECT3DCUBETEXTURE8) object;
552 TRACE("(%p) returning %p\n",This, *ppCubeTexture);
553 return hr;
556 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexBuffer(LPDIRECT3DDEVICE8 iface, UINT Size, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer8** ppVertexBuffer) {
557 IDirect3DVertexBuffer8Impl *object;
558 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
559 HRESULT hrc = D3D_OK;
561 TRACE("(%p) Relay\n", This);
562 /* Allocate the storage for the device */
563 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexBuffer8Impl));
564 if (NULL == object) {
565 FIXME("Allocation of memory failed\n");
566 *ppVertexBuffer = NULL;
567 return D3DERR_OUTOFVIDEOMEMORY;
570 object->lpVtbl = &Direct3DVertexBuffer8_Vtbl;
571 object->ref = 1;
572 EnterCriticalSection(&d3d8_cs);
573 hrc = IWineD3DDevice_CreateVertexBuffer(This->WineD3DDevice, Size, Usage & WINED3DUSAGE_MASK, FVF, (WINED3DPOOL) Pool, &(object->wineD3DVertexBuffer), NULL, (IUnknown *)object);
574 LeaveCriticalSection(&d3d8_cs);
576 if (D3D_OK != hrc) {
578 /* free up object */
579 FIXME("(%p) call to IWineD3DDevice_CreateVertexBuffer failed\n", This);
580 HeapFree(GetProcessHeap(), 0, object);
581 *ppVertexBuffer = NULL;
582 } else {
583 IUnknown_AddRef(iface);
584 object->parentDevice = iface;
585 *ppVertexBuffer = (LPDIRECT3DVERTEXBUFFER8) object;
587 return hrc;
590 static HRESULT WINAPI IDirect3DDevice8Impl_CreateIndexBuffer(LPDIRECT3DDEVICE8 iface, UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DIndexBuffer8** ppIndexBuffer) {
591 IDirect3DIndexBuffer8Impl *object;
592 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
593 HRESULT hrc = D3D_OK;
595 TRACE("(%p) Relay\n", This);
596 /* Allocate the storage for the device */
597 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
598 if (NULL == object) {
599 FIXME("Allocation of memory failed\n");
600 *ppIndexBuffer = NULL;
601 return D3DERR_OUTOFVIDEOMEMORY;
604 object->lpVtbl = &Direct3DIndexBuffer8_Vtbl;
605 object->ref = 1;
606 TRACE("Calling wined3d create index buffer\n");
607 EnterCriticalSection(&d3d8_cs);
608 hrc = IWineD3DDevice_CreateIndexBuffer(This->WineD3DDevice, Length, Usage & WINED3DUSAGE_MASK, Format, (WINED3DPOOL) Pool, &object->wineD3DIndexBuffer, NULL, (IUnknown *)object);
609 LeaveCriticalSection(&d3d8_cs);
611 if (D3D_OK != hrc) {
613 /* free up object */
614 FIXME("(%p) call to IWineD3DDevice_CreateIndexBuffer failed\n", This);
615 HeapFree(GetProcessHeap(), 0, object);
616 *ppIndexBuffer = NULL;
617 } else {
618 IUnknown_AddRef(iface);
619 object->parentDevice = iface;
620 *ppIndexBuffer = (LPDIRECT3DINDEXBUFFER8)object;
622 return hrc;
625 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) {
626 HRESULT hrc;
627 IDirect3DSurface8Impl *object;
628 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
629 TRACE("(%p) Relay\n", This);
630 if(MultisampleQuality < 0) {
631 FIXME("MultisampleQuality out of range %d, substituting 0\n", MultisampleQuality);
632 /*FIXME: Find out what windows does with a MultisampleQuality < 0 */
633 MultisampleQuality=0;
636 if(MultisampleQuality > 0){
637 FIXME("MultisampleQuality set to %d, substituting 0\n" , MultisampleQuality);
639 MultisampleQuality
640 [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.
642 MultisampleQuality=0;
644 /*FIXME: Check MAX bounds of MultisampleQuality*/
646 /* Allocate the storage for the device */
647 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface8Impl));
648 if (NULL == object) {
649 FIXME("Allocation of memory failed\n");
650 *ppSurface = NULL;
651 return D3DERR_OUTOFVIDEOMEMORY;
654 object->lpVtbl = &Direct3DSurface8_Vtbl;
655 object->ref = 1;
657 TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
659 /* Not called from the VTable, no locking needed */
660 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);
661 if (hrc != D3D_OK || NULL == object->wineD3DSurface) {
662 /* free up object */
663 FIXME("(%p) call to IWineD3DDevice_CreateSurface failed\n", This);
664 HeapFree(GetProcessHeap(), 0, object);
665 *ppSurface = NULL;
666 } else {
667 IUnknown_AddRef(iface);
668 object->parentDevice = iface;
669 *ppSurface = (LPDIRECT3DSURFACE8) object;
671 return hrc;
674 static HRESULT WINAPI IDirect3DDevice8Impl_CreateRenderTarget(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, BOOL Lockable, IDirect3DSurface8** ppSurface) {
675 HRESULT hr;
676 TRACE("Relay\n");
678 EnterCriticalSection(&d3d8_cs);
679 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, Lockable, FALSE /* Discard */, 0 /* Level */ , ppSurface, D3DRTYPE_SURFACE, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, MultiSample, 0);
680 LeaveCriticalSection(&d3d8_cs);
681 return hr;
684 static HRESULT WINAPI IDirect3DDevice8Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, IDirect3DSurface8** ppSurface) {
685 HRESULT hr;
686 TRACE("Relay\n");
688 /* TODO: Verify that Discard is false */
689 EnterCriticalSection(&d3d8_cs);
690 hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE, 0 /* Level */
691 ,ppSurface, D3DRTYPE_SURFACE, D3DUSAGE_DEPTHSTENCIL,
692 D3DPOOL_DEFAULT, MultiSample, 0);
693 LeaveCriticalSection(&d3d8_cs);
694 return hr;
697 static HRESULT WINAPI IDirect3DDevice8Impl_CreateImageSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, IDirect3DSurface8** ppSurface) {
698 HRESULT hr;
699 TRACE("Relay\n");
701 EnterCriticalSection(&d3d8_cs);
702 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 */);
703 LeaveCriticalSection(&d3d8_cs);
704 return hr;
707 static HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8 *pSourceSurface, CONST RECT *pSourceRects, UINT cRects, IDirect3DSurface8 *pDestinationSurface, CONST POINT *pDestPoints) {
708 IDirect3DSurface8Impl *Source = (IDirect3DSurface8Impl *) pSourceSurface;
709 IDirect3DSurface8Impl *Dest = (IDirect3DSurface8Impl *) pDestinationSurface;
711 HRESULT hr = WINED3D_OK;
712 WINED3DFORMAT srcFormat, destFormat;
713 UINT srcWidth, destWidth;
714 UINT srcHeight, destHeight;
715 UINT srcSize;
716 WINED3DSURFACE_DESC winedesc;
718 TRACE("(%p) pSrcSur=%p, pSourceRects=%p, cRects=%d, pDstSur=%p, pDestPtsArr=%p\n", iface,
719 pSourceSurface, pSourceRects, cRects, pDestinationSurface, pDestPoints);
722 /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the destination texture is in WINED3DPOOL_DEFAULT */
723 memset(&winedesc, 0, sizeof(winedesc));
725 winedesc.Format = &srcFormat;
726 winedesc.Width = &srcWidth;
727 winedesc.Height = &srcHeight;
728 winedesc.Size = &srcSize;
729 IWineD3DSurface_GetDesc(Source->wineD3DSurface, &winedesc);
731 winedesc.Format = &destFormat;
732 winedesc.Width = &destWidth;
733 winedesc.Height = &destHeight;
734 winedesc.Size = NULL;
735 EnterCriticalSection(&d3d8_cs);
736 IWineD3DSurface_GetDesc(Dest->wineD3DSurface, &winedesc);
738 /* Check that the source and destination formats match */
739 if (srcFormat != destFormat && WINED3DFMT_UNKNOWN != destFormat) {
740 WARN("(%p) source %p format must match the dest %p format, returning WINED3DERR_INVALIDCALL\n", iface, pSourceSurface, pDestinationSurface);
741 LeaveCriticalSection(&d3d8_cs);
742 return WINED3DERR_INVALIDCALL;
743 } else if (WINED3DFMT_UNKNOWN == destFormat) {
744 TRACE("(%p) : Converting destination surface from WINED3DFMT_UNKNOWN to the source format\n", iface);
745 IWineD3DSurface_SetFormat(Dest->wineD3DSurface, srcFormat);
746 destFormat = srcFormat;
749 /* Quick if complete copy ... */
750 if (cRects == 0 && pSourceRects == NULL && pDestPoints == NULL) {
751 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
752 } else {
753 unsigned int i;
754 /* Copy rect by rect */
755 if (NULL != pSourceRects && NULL != pDestPoints) {
756 for (i = 0; i < cRects; ++i) {
757 IWineD3DSurface_BltFast(Dest->wineD3DSurface, pDestPoints[i].x, pDestPoints[i].y, Source->wineD3DSurface, (RECT *) &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
759 } else {
760 for (i = 0; i < cRects; ++i) {
761 IWineD3DSurface_BltFast(Dest->wineD3DSurface, 0, 0, Source->wineD3DSurface, (RECT *) &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
765 LeaveCriticalSection(&d3d8_cs);
767 return hr;
770 static HRESULT WINAPI IDirect3DDevice8Impl_UpdateTexture(LPDIRECT3DDEVICE8 iface, IDirect3DBaseTexture8* pSourceTexture, IDirect3DBaseTexture8* pDestinationTexture) {
771 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
772 HRESULT hr;
773 TRACE("(%p) Relay\n" , This);
775 EnterCriticalSection(&d3d8_cs);
776 hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice, ((IDirect3DBaseTexture8Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture8Impl *)pDestinationTexture)->wineD3DBaseTexture);
777 LeaveCriticalSection(&d3d8_cs);
778 return hr;
781 static HRESULT WINAPI IDirect3DDevice8Impl_GetFrontBuffer(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pDestSurface) {
782 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
783 IDirect3DSurface8Impl *destSurface = (IDirect3DSurface8Impl *)pDestSurface;
784 HRESULT hr;
786 TRACE("(%p) Relay\n" , This);
788 if (pDestSurface == NULL) {
789 WARN("(%p) : Caller passed NULL as pDestSurface returning D3DERR_INVALIDCALL\n", This);
790 return D3DERR_INVALIDCALL;
793 EnterCriticalSection(&d3d8_cs);
794 hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, 0, destSurface->wineD3DSurface);
795 LeaveCriticalSection(&d3d8_cs);
796 return hr;
799 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pRenderTarget, IDirect3DSurface8* pNewZStencil) {
800 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
801 IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl *)pRenderTarget;
802 IDirect3DSurface8Impl *pZSurface = (IDirect3DSurface8Impl *)pNewZStencil;
803 HRESULT hr;
804 TRACE("(%p) Relay\n" , This);
806 IWineD3DDevice_SetDepthStencilSurface(This->WineD3DDevice, NULL == pZSurface ? NULL : (IWineD3DSurface *)pZSurface->wineD3DSurface);
808 EnterCriticalSection(&d3d8_cs);
809 hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, 0, pSurface ? (IWineD3DSurface *)pSurface->wineD3DSurface : NULL);
810 LeaveCriticalSection(&d3d8_cs);
811 return hr;
814 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppRenderTarget) {
815 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
816 HRESULT hr = D3D_OK;
817 IWineD3DSurface *pRenderTarget;
819 TRACE("(%p) Relay\n" , This);
821 if (ppRenderTarget == NULL) {
822 return D3DERR_INVALIDCALL;
824 EnterCriticalSection(&d3d8_cs);
825 hr = IWineD3DDevice_GetRenderTarget(This->WineD3DDevice, 0, &pRenderTarget);
827 if (hr == D3D_OK && pRenderTarget != NULL) {
828 IWineD3DSurface_GetParent(pRenderTarget,(IUnknown**)ppRenderTarget);
829 IWineD3DSurface_Release(pRenderTarget);
830 } else {
831 FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
832 *ppRenderTarget = NULL;
834 LeaveCriticalSection(&d3d8_cs);
836 return hr;
839 static HRESULT WINAPI IDirect3DDevice8Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppZStencilSurface) {
840 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
841 HRESULT hr = D3D_OK;
842 IWineD3DSurface *pZStencilSurface;
844 TRACE("(%p) Relay\n" , This);
845 if(ppZStencilSurface == NULL){
846 return D3DERR_INVALIDCALL;
849 EnterCriticalSection(&d3d8_cs);
850 hr=IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
851 if(hr == D3D_OK && pZStencilSurface != NULL){
852 IWineD3DSurface_GetParent(pZStencilSurface,(IUnknown**)ppZStencilSurface);
853 IWineD3DSurface_Release(pZStencilSurface);
854 }else{
855 FIXME("Call to IWineD3DDevice_GetDepthStencilSurface failed\n");
856 *ppZStencilSurface = NULL;
858 LeaveCriticalSection(&d3d8_cs);
860 return D3D_OK;
863 static HRESULT WINAPI IDirect3DDevice8Impl_BeginScene(LPDIRECT3DDEVICE8 iface) {
864 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
865 HRESULT hr;
866 TRACE("(%p) Relay\n" , This);
868 EnterCriticalSection(&d3d8_cs);
869 hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
870 LeaveCriticalSection(&d3d8_cs);
871 return hr;
874 static HRESULT WINAPI IDirect3DDevice8Impl_EndScene(LPDIRECT3DDEVICE8 iface) {
875 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
876 HRESULT hr;
877 TRACE("(%p) Relay\n" , This);
879 EnterCriticalSection(&d3d8_cs);
880 hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
881 LeaveCriticalSection(&d3d8_cs);
882 return hr;
885 static HRESULT WINAPI IDirect3DDevice8Impl_Clear(LPDIRECT3DDEVICE8 iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil) {
886 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
887 HRESULT hr;
888 TRACE("(%p) Relay\n" , This);
890 /* Note: D3DRECT is compatible with WINED3DRECT */
891 EnterCriticalSection(&d3d8_cs);
892 hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (CONST WINED3DRECT*) pRects, Flags, Color, Z, Stencil);
893 LeaveCriticalSection(&d3d8_cs);
894 return hr;
897 static HRESULT WINAPI IDirect3DDevice8Impl_SetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* lpMatrix) {
898 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
899 HRESULT hr;
900 TRACE("(%p) Relay\n" , This);
902 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
903 EnterCriticalSection(&d3d8_cs);
904 hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
905 LeaveCriticalSection(&d3d8_cs);
906 return hr;
909 static HRESULT WINAPI IDirect3DDevice8Impl_GetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State,D3DMATRIX* pMatrix) {
910 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
911 HRESULT hr;
912 TRACE("(%p) Relay\n" , This);
914 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
915 EnterCriticalSection(&d3d8_cs);
916 hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
917 LeaveCriticalSection(&d3d8_cs);
918 return hr;
921 static HRESULT WINAPI IDirect3DDevice8Impl_MultiplyTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
922 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
923 HRESULT hr;
924 TRACE("(%p) Relay\n" , This);
926 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
927 EnterCriticalSection(&d3d8_cs);
928 hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
929 LeaveCriticalSection(&d3d8_cs);
930 return hr;
933 static HRESULT WINAPI IDirect3DDevice8Impl_SetViewport(LPDIRECT3DDEVICE8 iface, CONST D3DVIEWPORT8* pViewport) {
934 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
935 HRESULT hr;
936 TRACE("(%p) Relay\n" , This);
938 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
939 EnterCriticalSection(&d3d8_cs);
940 hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
941 LeaveCriticalSection(&d3d8_cs);
942 return hr;
945 static HRESULT WINAPI IDirect3DDevice8Impl_GetViewport(LPDIRECT3DDEVICE8 iface, D3DVIEWPORT8* pViewport) {
946 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
947 HRESULT hr;
948 TRACE("(%p) Relay\n" , This);
950 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
951 EnterCriticalSection(&d3d8_cs);
952 hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
953 LeaveCriticalSection(&d3d8_cs);
954 return hr;
957 static HRESULT WINAPI IDirect3DDevice8Impl_SetMaterial(LPDIRECT3DDEVICE8 iface, CONST D3DMATERIAL8* pMaterial) {
958 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
959 HRESULT hr;
960 TRACE("(%p) Relay\n" , This);
962 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
963 EnterCriticalSection(&d3d8_cs);
964 hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
965 LeaveCriticalSection(&d3d8_cs);
966 return hr;
969 static HRESULT WINAPI IDirect3DDevice8Impl_GetMaterial(LPDIRECT3DDEVICE8 iface, D3DMATERIAL8* pMaterial) {
970 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
971 HRESULT hr;
972 TRACE("(%p) Relay\n" , This);
974 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
975 EnterCriticalSection(&d3d8_cs);
976 hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
977 LeaveCriticalSection(&d3d8_cs);
978 return hr;
981 static HRESULT WINAPI IDirect3DDevice8Impl_SetLight(LPDIRECT3DDEVICE8 iface, DWORD Index, CONST D3DLIGHT8* pLight) {
982 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
983 HRESULT hr;
984 TRACE("(%p) Relay\n" , This);
986 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
987 EnterCriticalSection(&d3d8_cs);
988 hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
989 LeaveCriticalSection(&d3d8_cs);
990 return hr;
993 static HRESULT WINAPI IDirect3DDevice8Impl_GetLight(LPDIRECT3DDEVICE8 iface, DWORD Index,D3DLIGHT8* pLight) {
994 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
995 HRESULT hr;
996 TRACE("(%p) Relay\n" , This);
998 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
999 EnterCriticalSection(&d3d8_cs);
1000 hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
1001 LeaveCriticalSection(&d3d8_cs);
1002 return hr;
1005 static HRESULT WINAPI IDirect3DDevice8Impl_LightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL Enable) {
1006 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1007 HRESULT hr;
1008 TRACE("(%p) Relay\n" , This);
1010 EnterCriticalSection(&d3d8_cs);
1011 hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
1012 LeaveCriticalSection(&d3d8_cs);
1013 return hr;
1016 static HRESULT WINAPI IDirect3DDevice8Impl_GetLightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL* pEnable) {
1017 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1018 HRESULT hr;
1019 TRACE("(%p) Relay\n" , This);
1021 EnterCriticalSection(&d3d8_cs);
1022 hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
1023 LeaveCriticalSection(&d3d8_cs);
1024 return hr;
1027 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,CONST float* pPlane) {
1028 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1029 HRESULT hr;
1030 TRACE("(%p) Relay\n" , This);
1032 EnterCriticalSection(&d3d8_cs);
1033 hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
1034 LeaveCriticalSection(&d3d8_cs);
1035 return hr;
1038 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,float* pPlane) {
1039 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1040 HRESULT hr;
1041 TRACE("(%p) Relay\n" , This);
1043 EnterCriticalSection(&d3d8_cs);
1044 hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
1045 LeaveCriticalSection(&d3d8_cs);
1046 return hr;
1049 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD Value) {
1050 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1051 HRESULT hr;
1052 TRACE("(%p) Relay\n" , This);
1054 EnterCriticalSection(&d3d8_cs);
1055 hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
1056 LeaveCriticalSection(&d3d8_cs);
1057 return hr;
1060 static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD* pValue) {
1061 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1062 HRESULT hr;
1063 TRACE("(%p) Relay\n" , This);
1065 EnterCriticalSection(&d3d8_cs);
1066 hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
1067 LeaveCriticalSection(&d3d8_cs);
1068 return hr;
1071 static HRESULT WINAPI IDirect3DDevice8Impl_BeginStateBlock(LPDIRECT3DDEVICE8 iface) {
1072 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1073 HRESULT hr;
1074 TRACE("(%p)\n", This);
1076 EnterCriticalSection(&d3d8_cs);
1077 hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
1078 LeaveCriticalSection(&d3d8_cs);
1079 return hr;
1082 static HRESULT WINAPI IDirect3DDevice8Impl_EndStateBlock(LPDIRECT3DDEVICE8 iface, DWORD* pToken) {
1083 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1084 HRESULT hr;
1085 IWineD3DStateBlock* wineD3DStateBlock;
1086 IDirect3DStateBlock8Impl* object;
1088 TRACE("(%p) Relay\n", This);
1090 /* Tell wineD3D to endstatablock before anything else (in case we run out
1091 * of memory later and cause locking problems)
1093 EnterCriticalSection(&d3d8_cs);
1094 hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice , &wineD3DStateBlock);
1095 if (hr != D3D_OK) {
1096 FIXME("IWineD3DDevice_EndStateBlock returned an error\n");
1097 LeaveCriticalSection(&d3d8_cs);
1098 return hr;
1101 /* allocate a new IDirectD3DStateBlock */
1102 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY ,sizeof(IDirect3DStateBlock8Impl));
1103 object->ref = 1;
1104 object->lpVtbl = &Direct3DStateBlock8_Vtbl;
1106 object->wineD3DStateBlock = wineD3DStateBlock;
1108 *pToken = (DWORD)object;
1109 TRACE("(%p)Returning %p %p\n", This, object, wineD3DStateBlock);
1111 LeaveCriticalSection(&d3d8_cs);
1112 return hr;
1115 static HRESULT WINAPI IDirect3DDevice8Impl_ApplyStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1116 IDirect3DStateBlock8Impl *pSB = (IDirect3DStateBlock8Impl*) Token;
1117 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1118 HRESULT hr;
1120 TRACE("(%p) %p Relay\n", This, pSB);
1122 EnterCriticalSection(&d3d8_cs);
1123 hr = IWineD3DStateBlock_Apply(pSB->wineD3DStateBlock);
1124 LeaveCriticalSection(&d3d8_cs);
1125 return hr;
1128 static HRESULT WINAPI IDirect3DDevice8Impl_CaptureStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1129 IDirect3DStateBlock8Impl* pSB = (IDirect3DStateBlock8Impl *)Token;
1130 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1131 HRESULT hr;
1133 TRACE("(%p) %p Relay\n", This, pSB);
1135 EnterCriticalSection(&d3d8_cs);
1136 hr = IWineD3DStateBlock_Capture(pSB->wineD3DStateBlock);
1137 LeaveCriticalSection(&d3d8_cs);
1138 return hr;
1141 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token) {
1142 IDirect3DStateBlock8Impl* pSB = (IDirect3DStateBlock8Impl *)Token;
1143 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1145 TRACE("(%p) Relay\n", This);
1147 EnterCriticalSection(&d3d8_cs);
1148 while(IUnknown_Release((IUnknown *)pSB));
1149 LeaveCriticalSection(&d3d8_cs);
1151 return D3D_OK;
1154 static HRESULT WINAPI IDirect3DDevice8Impl_CreateStateBlock(LPDIRECT3DDEVICE8 iface, D3DSTATEBLOCKTYPE Type, DWORD* pToken) {
1155 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1156 IDirect3DStateBlock8Impl *object;
1157 HRESULT hrc = D3D_OK;
1159 TRACE("(%p) Relay\n", This);
1161 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DStateBlock8Impl));
1162 if (NULL == object) {
1163 *pToken = 0;
1164 return E_OUTOFMEMORY;
1166 object->lpVtbl = &Direct3DStateBlock8_Vtbl;
1167 object->ref = 1;
1169 EnterCriticalSection(&d3d8_cs);
1170 hrc = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type, &object->wineD3DStateBlock, (IUnknown *)object);
1171 LeaveCriticalSection(&d3d8_cs);
1172 if(D3D_OK != hrc){
1173 FIXME("(%p) Call to IWineD3DDevice_CreateStateBlock failed.\n", This);
1174 HeapFree(GetProcessHeap(), 0, object);
1175 *pToken = 0;
1176 } else {
1177 *pToken = (DWORD)object;
1179 TRACE("(%p) returning token (ptr to stateblock) of %p\n", This, object);
1181 return hrc;
1184 static HRESULT WINAPI IDirect3DDevice8Impl_SetClipStatus(LPDIRECT3DDEVICE8 iface, CONST D3DCLIPSTATUS8* pClipStatus) {
1185 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1186 HRESULT hr;
1187 TRACE("(%p) Relay\n" , This);
1188 /* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
1189 EnterCriticalSection(&d3d8_cs);
1190 hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
1191 LeaveCriticalSection(&d3d8_cs);
1192 return hr;
1195 static HRESULT WINAPI IDirect3DDevice8Impl_GetClipStatus(LPDIRECT3DDEVICE8 iface, D3DCLIPSTATUS8* pClipStatus) {
1196 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1197 HRESULT hr;
1198 TRACE("(%p) Relay\n" , This);
1200 EnterCriticalSection(&d3d8_cs);
1201 hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
1202 LeaveCriticalSection(&d3d8_cs);
1203 return hr;
1206 static HRESULT WINAPI IDirect3DDevice8Impl_GetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage,IDirect3DBaseTexture8** ppTexture) {
1207 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1208 IWineD3DBaseTexture *retTexture = NULL;
1209 HRESULT rc = D3D_OK;
1211 TRACE("(%p) Relay\n" , This);
1213 if(ppTexture == NULL){
1214 return D3DERR_INVALIDCALL;
1217 EnterCriticalSection(&d3d8_cs);
1218 rc = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, (IWineD3DBaseTexture **)&retTexture);
1219 if (rc == D3D_OK && NULL != retTexture) {
1220 IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
1221 IWineD3DBaseTexture_Release(retTexture);
1222 } else {
1223 FIXME("Call to get texture (%d) failed (%p)\n", Stage, retTexture);
1224 *ppTexture = NULL;
1226 LeaveCriticalSection(&d3d8_cs);
1228 return rc;
1231 static HRESULT WINAPI IDirect3DDevice8Impl_SetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage, IDirect3DBaseTexture8* pTexture) {
1232 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1233 HRESULT hr;
1234 TRACE("(%p) Relay %d %p\n" , This, Stage, pTexture);
1236 EnterCriticalSection(&d3d8_cs);
1237 hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
1238 pTexture==NULL ? NULL : ((IDirect3DBaseTexture8Impl *)pTexture)->wineD3DBaseTexture);
1239 LeaveCriticalSection(&d3d8_cs);
1240 return hr;
1243 static HRESULT WINAPI IDirect3DDevice8Impl_GetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD* pValue) {
1244 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1245 HRESULT hr;
1246 TRACE("(%p) Relay\n" , This);
1248 switch(Type) {
1249 case D3DTSS_ADDRESSU:
1250 Type = WINED3DSAMP_ADDRESSU;
1251 break;
1252 case D3DTSS_ADDRESSV:
1253 Type = WINED3DSAMP_ADDRESSV;
1254 break;
1255 case D3DTSS_ADDRESSW:
1256 Type = WINED3DSAMP_ADDRESSW;
1257 break;
1258 case D3DTSS_BORDERCOLOR:
1259 Type = WINED3DSAMP_BORDERCOLOR;
1260 break;
1261 case D3DTSS_MAGFILTER:
1262 Type = WINED3DSAMP_MAGFILTER;
1263 break;
1264 case D3DTSS_MAXANISOTROPY:
1265 Type = WINED3DSAMP_MAXANISOTROPY;
1266 break;
1267 case D3DTSS_MAXMIPLEVEL:
1268 Type = WINED3DSAMP_MAXMIPLEVEL;
1269 break;
1270 case D3DTSS_MINFILTER:
1271 Type = WINED3DSAMP_MINFILTER;
1272 break;
1273 case D3DTSS_MIPFILTER:
1274 Type = WINED3DSAMP_MIPFILTER;
1275 break;
1276 case D3DTSS_MIPMAPLODBIAS:
1277 Type = WINED3DSAMP_MIPMAPLODBIAS;
1278 break;
1279 default:
1280 EnterCriticalSection(&d3d8_cs);
1281 hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, Type, pValue);
1282 LeaveCriticalSection(&d3d8_cs);
1283 return hr;
1286 EnterCriticalSection(&d3d8_cs);
1287 hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Stage, Type, pValue);
1288 LeaveCriticalSection(&d3d8_cs);
1289 return hr;
1292 static HRESULT WINAPI IDirect3DDevice8Impl_SetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) {
1293 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1294 HRESULT hr;
1295 TRACE("(%p) Relay\n" , This);
1297 switch(Type) {
1298 case D3DTSS_ADDRESSU:
1299 Type = WINED3DSAMP_ADDRESSU;
1300 break;
1301 case D3DTSS_ADDRESSV:
1302 Type = WINED3DSAMP_ADDRESSV;
1303 break;
1304 case D3DTSS_ADDRESSW:
1305 Type = WINED3DSAMP_ADDRESSW;
1306 break;
1307 case D3DTSS_BORDERCOLOR:
1308 Type = WINED3DSAMP_BORDERCOLOR;
1309 break;
1310 case D3DTSS_MAGFILTER:
1311 Type = WINED3DSAMP_MAGFILTER;
1312 break;
1313 case D3DTSS_MAXANISOTROPY:
1314 Type = WINED3DSAMP_MAXANISOTROPY;
1315 break;
1316 case D3DTSS_MAXMIPLEVEL:
1317 Type = WINED3DSAMP_MAXMIPLEVEL;
1318 break;
1319 case D3DTSS_MINFILTER:
1320 Type = WINED3DSAMP_MINFILTER;
1321 break;
1322 case D3DTSS_MIPFILTER:
1323 Type = WINED3DSAMP_MIPFILTER;
1324 break;
1325 case D3DTSS_MIPMAPLODBIAS:
1326 Type = WINED3DSAMP_MIPMAPLODBIAS;
1327 break;
1328 default:
1329 EnterCriticalSection(&d3d8_cs);
1330 hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, Type, Value);
1331 LeaveCriticalSection(&d3d8_cs);
1332 return hr;
1335 EnterCriticalSection(&d3d8_cs);
1336 hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Stage, Type, Value);
1337 LeaveCriticalSection(&d3d8_cs);
1338 return hr;
1341 static HRESULT WINAPI IDirect3DDevice8Impl_ValidateDevice(LPDIRECT3DDEVICE8 iface, DWORD* pNumPasses) {
1342 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1343 HRESULT hr;
1344 TRACE("(%p) Relay\n" , This);
1346 EnterCriticalSection(&d3d8_cs);
1347 hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
1348 LeaveCriticalSection(&d3d8_cs);
1349 return hr;
1352 static HRESULT WINAPI IDirect3DDevice8Impl_GetInfo(LPDIRECT3DDEVICE8 iface, DWORD DevInfoID, void* pDevInfoStruct, DWORD DevInfoStructSize) {
1353 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1354 FIXME("(%p) : stub\n", This);
1355 return D3D_OK;
1358 static HRESULT WINAPI IDirect3DDevice8Impl_SetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, CONST PALETTEENTRY* pEntries) {
1359 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1360 HRESULT hr;
1361 TRACE("(%p) Relay\n" , This);
1363 EnterCriticalSection(&d3d8_cs);
1364 hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1365 LeaveCriticalSection(&d3d8_cs);
1366 return hr;
1369 static HRESULT WINAPI IDirect3DDevice8Impl_GetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, PALETTEENTRY* pEntries) {
1370 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1371 HRESULT hr;
1372 TRACE("(%p) Relay\n" , This);
1374 EnterCriticalSection(&d3d8_cs);
1375 hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
1376 LeaveCriticalSection(&d3d8_cs);
1377 return hr;
1380 static HRESULT WINAPI IDirect3DDevice8Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber) {
1381 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1382 HRESULT hr;
1383 TRACE("(%p) Relay\n" , This);
1385 EnterCriticalSection(&d3d8_cs);
1386 hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1387 LeaveCriticalSection(&d3d8_cs);
1388 return hr;
1391 static HRESULT WINAPI IDirect3DDevice8Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT *PaletteNumber) {
1392 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1393 HRESULT hr;
1394 TRACE("(%p) Relay\n" , This);
1396 EnterCriticalSection(&d3d8_cs);
1397 hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
1398 LeaveCriticalSection(&d3d8_cs);
1399 return hr;
1402 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitive(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) {
1403 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1404 HRESULT hr;
1405 TRACE("(%p) Relay\n" , This);
1407 EnterCriticalSection(&d3d8_cs);
1408 hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, PrimitiveType, StartVertex, PrimitiveCount);
1409 LeaveCriticalSection(&d3d8_cs);
1410 return hr;
1413 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,
1414 UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount) {
1415 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1416 HRESULT hr;
1417 TRACE("(%p) Relay\n" , This);
1419 EnterCriticalSection(&d3d8_cs);
1420 hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, PrimitiveType, MinVertexIndex, NumVertices, startIndex, primCount);
1421 LeaveCriticalSection(&d3d8_cs);
1422 return hr;
1425 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT PrimitiveCount,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride) {
1426 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1427 HRESULT hr;
1428 TRACE("(%p) Relay\n" , This);
1430 EnterCriticalSection(&d3d8_cs);
1431 hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
1432 LeaveCriticalSection(&d3d8_cs);
1433 return hr;
1436 static HRESULT WINAPI IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,
1437 UINT NumVertexIndices,UINT PrimitiveCount,CONST void* pIndexData,
1438 D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,
1439 UINT VertexStreamZeroStride) {
1440 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1441 HRESULT hr;
1442 TRACE("(%p) Relay\n" , This);
1444 EnterCriticalSection(&d3d8_cs);
1445 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice, PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount,
1446 pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
1447 LeaveCriticalSection(&d3d8_cs);
1448 return hr;
1451 static HRESULT WINAPI IDirect3DDevice8Impl_ProcessVertices(LPDIRECT3DDEVICE8 iface, UINT SrcStartIndex,UINT DestIndex,UINT VertexCount,IDirect3DVertexBuffer8* pDestBuffer,DWORD Flags) {
1452 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1453 HRESULT hr;
1454 TRACE("(%p) Relay\n" , This);
1456 EnterCriticalSection(&d3d8_cs);
1457 hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, ((IDirect3DVertexBuffer8Impl *)pDestBuffer)->wineD3DVertexBuffer, NULL, Flags);
1458 LeaveCriticalSection(&d3d8_cs);
1459 return hr;
1462 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexDeclaration(IDirect3DDevice8 *iface, CONST DWORD *declaration, IDirect3DVertexDeclaration8 **decl_ptr) {
1463 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1464 IDirect3DVertexDeclaration8Impl *object;
1465 WINED3DVERTEXELEMENT *wined3d_elements;
1466 size_t wined3d_element_count;
1467 HRESULT hr = D3D_OK;
1469 TRACE("(%p) : declaration %p\n", This, declaration);
1471 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1472 if (!object) {
1473 ERR("Memory allocation failed\n");
1474 *decl_ptr = NULL;
1475 return D3DERR_OUTOFVIDEOMEMORY;
1478 object->ref_count = 1;
1479 object->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
1481 wined3d_element_count = convert_to_wined3d_declaration(declaration, &object->elements_size, &wined3d_elements);
1482 object->elements = HeapAlloc(GetProcessHeap(), 0, object->elements_size);
1483 if (!object->elements) {
1484 ERR("Memory allocation failed\n");
1485 HeapFree(GetProcessHeap(), 0, wined3d_elements);
1486 HeapFree(GetProcessHeap(), 0, object);
1487 *decl_ptr = NULL;
1488 return D3DERR_OUTOFVIDEOMEMORY;
1491 CopyMemory(object->elements, declaration, object->elements_size);
1493 EnterCriticalSection(&d3d8_cs);
1494 hr = IWineD3DDevice_CreateVertexDeclaration(This->WineD3DDevice, &object->wined3d_vertex_declaration,
1495 (IUnknown *)object, wined3d_elements, wined3d_element_count);
1496 LeaveCriticalSection(&d3d8_cs);
1497 HeapFree(GetProcessHeap(), 0, wined3d_elements);
1499 if (FAILED(hr)) {
1500 ERR("(%p) : IWineD3DDevice_CreateVertexDeclaration call failed\n", This);
1501 HeapFree(GetProcessHeap(), 0, object->elements);
1502 HeapFree(GetProcessHeap(), 0, object);
1503 } else {
1504 *decl_ptr = (IDirect3DVertexDeclaration8 *)object;
1505 TRACE("(%p) : Created vertex declaration %p\n", This, object);
1508 return hr;
1511 static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pDeclaration, CONST DWORD* pFunction, DWORD* ppShader, DWORD Usage) {
1512 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1513 HRESULT hrc = D3D_OK;
1514 IDirect3DVertexShader8Impl *object;
1515 IWineD3DVertexDeclaration *wined3d_vertex_declaration;
1517 /* Setup a stub object for now */
1518 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1519 TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
1520 if (NULL == object) {
1521 FIXME("Allocation of memory failed\n");
1522 *ppShader = 0;
1523 return D3DERR_OUTOFVIDEOMEMORY;
1526 object->ref = 1;
1527 object->lpVtbl = &Direct3DVertexShader8_Vtbl;
1529 EnterCriticalSection(&d3d8_cs);
1530 hrc = IDirect3DDevice8Impl_CreateVertexDeclaration(iface, pDeclaration, &object->vertex_declaration);
1531 if (FAILED(hrc)) {
1532 ERR("(%p) : IDirect3DDeviceImpl_CreateVertexDeclaration call failed\n", This);
1533 LeaveCriticalSection(&d3d8_cs);
1534 HeapFree(GetProcessHeap(), 0, object);
1535 *ppShader = 0;
1536 return D3DERR_INVALIDCALL;
1538 wined3d_vertex_declaration = ((IDirect3DVertexDeclaration8Impl *)object->vertex_declaration)->wined3d_vertex_declaration;
1540 /* Usage is missing ... Use SetRenderState to set the sw vp render state in SetVertexShader */
1541 hrc = IWineD3DDevice_CreateVertexShader(This->WineD3DDevice, wined3d_vertex_declaration, pFunction, &object->wineD3DVertexShader, (IUnknown *)object);
1543 if (FAILED(hrc)) {
1544 /* free up object */
1545 FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n");
1546 HeapFree(GetProcessHeap(), 0, object);
1547 *ppShader = 0;
1548 } else {
1549 /* TODO: Store the VS declarations locally so that they can be derefferenced with a value higher than VS_HIGHESTFIXEDFXF */
1550 shader_handle *handle = alloc_shader_handle(This);
1551 if (!handle) {
1552 ERR("Failed to allocate shader handle\n");
1553 IDirect3DVertexShader8_Release((IUnknown *)object);
1554 hrc = E_OUTOFMEMORY;
1555 } else {
1556 object->handle = handle;
1557 *handle = object;
1558 *ppShader = (handle - This->shader_handles) + VS_HIGHESTFIXEDFXF + 1;
1560 load_local_constants(pDeclaration, object->wineD3DVertexShader);
1563 LeaveCriticalSection(&d3d8_cs);
1564 TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
1566 return hrc;
1569 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1570 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1571 HRESULT hrc = D3D_OK;
1573 TRACE("(%p) : Relay\n", This);
1574 EnterCriticalSection(&d3d8_cs);
1575 if (VS_HIGHESTFIXEDFXF >= pShader) {
1576 TRACE("Setting FVF, %d %d\n", VS_HIGHESTFIXEDFXF, pShader);
1577 IWineD3DDevice_SetFVF(This->WineD3DDevice, pShader);
1579 /* Call SetVertexShader with a NULL shader to set the vertexshader in the stateblock to NULL. */
1580 IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice, NULL);
1581 IWineD3DDevice_SetVertexShader(This->WineD3DDevice, NULL);
1582 } else {
1583 TRACE("Setting shader\n");
1584 if (This->allocated_shader_handles <= pShader - (VS_HIGHESTFIXEDFXF + 1)) {
1585 FIXME("(%p) : Number of shaders exceeds the maximum number of possible shaders\n", This);
1586 hrc = D3DERR_INVALIDCALL;
1587 } else {
1588 IDirect3DVertexShader8Impl *shader = This->shader_handles[pShader - (VS_HIGHESTFIXEDFXF + 1)];
1589 IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
1590 shader ? ((IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration)->wined3d_vertex_declaration : NULL);
1591 hrc = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, 0 == shader ? NULL : shader->wineD3DVertexShader);
1594 TRACE("(%p) : returning hr(%u)\n", This, hrc);
1595 LeaveCriticalSection(&d3d8_cs);
1597 return hrc;
1600 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
1601 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1602 IWineD3DVertexShader *pShader;
1603 HRESULT hrc = D3D_OK;
1605 TRACE("(%p) : Relay device@%p\n", This, This->WineD3DDevice);
1606 EnterCriticalSection(&d3d8_cs);
1607 hrc = IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &pShader);
1608 if (D3D_OK == hrc) {
1609 if(0 != pShader) {
1610 IDirect3DVertexShader8Impl *d3d8_shader;
1611 hrc = IWineD3DVertexShader_GetParent(pShader, (IUnknown **)&d3d8_shader);
1612 IWineD3DVertexShader_Release(pShader);
1613 *ppShader = (d3d8_shader->handle - This->shader_handles) + (VS_HIGHESTFIXEDFXF + 1);
1614 } else {
1615 *ppShader = 0;
1616 hrc = D3D_OK;
1618 } else {
1619 WARN("(%p) : Call to IWineD3DDevice_GetVertexShader failed %u (device %p)\n", This, hrc, This->WineD3DDevice);
1621 TRACE("(%p) : returning %#x\n", This, *ppShader);
1622 LeaveCriticalSection(&d3d8_cs);
1624 return hrc;
1627 static HRESULT WINAPI IDirect3DDevice8Impl_DeleteVertexShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1628 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1630 TRACE("(%p) : pShader %#x\n", This, pShader);
1632 EnterCriticalSection(&d3d8_cs);
1633 if (pShader <= VS_HIGHESTFIXEDFXF || This->allocated_shader_handles <= pShader - (VS_HIGHESTFIXEDFXF + 1)) {
1634 ERR("(%p) : Trying to delete an invalid handle\n", This);
1635 LeaveCriticalSection(&d3d8_cs);
1636 return D3DERR_INVALIDCALL;
1637 } else {
1638 IWineD3DVertexShader *cur = NULL;
1639 shader_handle *handle = &This->shader_handles[pShader - (VS_HIGHESTFIXEDFXF + 1)];
1640 IDirect3DVertexShader8Impl *shader = *handle;
1642 IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &cur);
1643 if(cur) {
1644 if(cur == shader->wineD3DVertexShader) IDirect3DDevice8_SetVertexShader(iface, 0);
1645 IWineD3DVertexShader_Release(cur);
1648 while(IUnknown_Release((IUnknown *)shader));
1649 free_shader_handle(This, handle);
1651 LeaveCriticalSection(&d3d8_cs);
1653 return D3D_OK;
1656 static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
1657 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1658 HRESULT hr;
1659 TRACE("(%p) : Relay\n", This);
1661 EnterCriticalSection(&d3d8_cs);
1662 hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, (CONST float *)pConstantData, ConstantCount);
1663 LeaveCriticalSection(&d3d8_cs);
1664 return hr;
1667 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
1668 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1669 HRESULT hr;
1670 TRACE("(%p) : Relay\n", This);
1672 EnterCriticalSection(&d3d8_cs);
1673 hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, (float *)pConstantData, ConstantCount);
1674 LeaveCriticalSection(&d3d8_cs);
1675 return hr;
1678 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderDeclaration(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
1679 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1680 IDirect3DVertexDeclaration8Impl *declaration;
1681 IDirect3DVertexShader8Impl *shader = NULL;
1683 TRACE("(%p) : pVertexShader 0x%08x, pData %p, *pSizeOfData %u\n", This, pVertexShader, pData, *pSizeOfData);
1685 EnterCriticalSection(&d3d8_cs);
1686 if (pVertexShader <= VS_HIGHESTFIXEDFXF || This->allocated_shader_handles <= pVertexShader - (VS_HIGHESTFIXEDFXF + 1)) {
1687 ERR("Passed an invalid shader handle.\n");
1688 LeaveCriticalSection(&d3d8_cs);
1689 return D3DERR_INVALIDCALL;
1692 shader = This->shader_handles[pVertexShader - (VS_HIGHESTFIXEDFXF + 1)];
1693 declaration = (IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration;
1695 /* If pData is NULL, we just return the required size of the buffer. */
1696 if (!pData) {
1697 *pSizeOfData = declaration->elements_size;
1698 LeaveCriticalSection(&d3d8_cs);
1699 return D3D_OK;
1702 /* MSDN claims that if *pSizeOfData is smaller than the required size
1703 * we should write the required size and return D3DERR_MOREDATA.
1704 * That's not actually true. */
1705 if (*pSizeOfData < declaration->elements_size) {
1706 LeaveCriticalSection(&d3d8_cs);
1707 return D3DERR_INVALIDCALL;
1710 CopyMemory(pData, declaration->elements, declaration->elements_size);
1711 LeaveCriticalSection(&d3d8_cs);
1713 return D3D_OK;
1716 static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pVertexShader, void* pData, DWORD* pSizeOfData) {
1717 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1718 IDirect3DVertexShader8Impl *shader = NULL;
1719 HRESULT hr;
1721 TRACE("(%p) : pVertexShader %#x, pData %p, pSizeOfData %p\n", This, pVertexShader, pData, pSizeOfData);
1723 EnterCriticalSection(&d3d8_cs);
1724 if (pVertexShader <= VS_HIGHESTFIXEDFXF || This->allocated_shader_handles <= pVertexShader - (VS_HIGHESTFIXEDFXF + 1)) {
1725 ERR("Passed an invalid shader handle.\n");
1726 LeaveCriticalSection(&d3d8_cs);
1727 return D3DERR_INVALIDCALL;
1730 shader = This->shader_handles[pVertexShader - (VS_HIGHESTFIXEDFXF + 1)];
1731 hr = IWineD3DVertexShader_GetFunction(shader->wineD3DVertexShader, pData, (UINT *)pSizeOfData);
1732 LeaveCriticalSection(&d3d8_cs);
1733 return hr;
1736 static HRESULT WINAPI IDirect3DDevice8Impl_SetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8* pIndexData, UINT baseVertexIndex) {
1737 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1738 HRESULT hr;
1739 TRACE("(%p) Relay\n", This);
1741 EnterCriticalSection(&d3d8_cs);
1742 IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, baseVertexIndex);
1743 hr = IWineD3DDevice_SetIndices(This->WineD3DDevice,
1744 pIndexData ? ((IDirect3DIndexBuffer8Impl *)pIndexData)->wineD3DIndexBuffer : NULL);
1745 LeaveCriticalSection(&d3d8_cs);
1746 return hr;
1749 static HRESULT WINAPI IDirect3DDevice8Impl_GetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8** ppIndexData,UINT* pBaseVertexIndex) {
1750 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1751 IWineD3DIndexBuffer *retIndexData = NULL;
1752 HRESULT rc = D3D_OK;
1754 TRACE("(%p) Relay\n", This);
1756 if(ppIndexData == NULL){
1757 return D3DERR_INVALIDCALL;
1760 EnterCriticalSection(&d3d8_cs);
1761 IWineD3DDevice_GetBaseVertexIndex(This->WineD3DDevice, pBaseVertexIndex);
1762 rc = IWineD3DDevice_GetIndices(This->WineD3DDevice, &retIndexData);
1763 if (SUCCEEDED(rc) && retIndexData) {
1764 IWineD3DIndexBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
1765 IWineD3DIndexBuffer_Release(retIndexData);
1766 } else {
1767 if (FAILED(rc)) FIXME("Call to GetIndices failed\n");
1768 *ppIndexData = NULL;
1770 LeaveCriticalSection(&d3d8_cs);
1772 return rc;
1774 static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pFunction, DWORD* ppShader) {
1775 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1776 IDirect3DPixelShader8Impl *object;
1777 HRESULT hrc = D3D_OK;
1779 TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
1781 if (NULL == ppShader) {
1782 TRACE("(%p) Invalid call\n", This);
1783 return D3DERR_INVALIDCALL;
1785 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1787 if (NULL == object) {
1788 return E_OUTOFMEMORY;
1789 } else {
1790 EnterCriticalSection(&d3d8_cs);
1792 object->ref = 1;
1793 object->lpVtbl = &Direct3DPixelShader8_Vtbl;
1794 hrc = IWineD3DDevice_CreatePixelShader(This->WineD3DDevice, pFunction, &object->wineD3DPixelShader , (IUnknown *)object);
1795 if (D3D_OK != hrc) {
1796 FIXME("(%p) call to IWineD3DDevice_CreatePixelShader failed\n", This);
1797 HeapFree(GetProcessHeap(), 0 , object);
1798 *ppShader = 0;
1799 } else {
1800 shader_handle *handle = alloc_shader_handle(This);
1801 if (!handle) {
1802 ERR("Failed to allocate shader handle\n");
1803 IDirect3DVertexShader8_Release((IUnknown *)object);
1804 hrc = E_OUTOFMEMORY;
1805 } else {
1806 object->handle = handle;
1807 *handle = object;
1808 *ppShader = (handle - This->shader_handles) + VS_HIGHESTFIXEDFXF + 1;
1811 LeaveCriticalSection(&d3d8_cs);
1814 TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
1815 return hrc;
1818 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1819 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1820 IDirect3DPixelShader8Impl *shader = NULL;
1821 HRESULT hr;
1823 TRACE("(%p) : pShader %#x\n", This, pShader);
1825 EnterCriticalSection(&d3d8_cs);
1826 if (pShader > VS_HIGHESTFIXEDFXF && This->allocated_shader_handles > pShader - (VS_HIGHESTFIXEDFXF + 1)) {
1827 shader = This->shader_handles[pShader - (VS_HIGHESTFIXEDFXF + 1)];
1828 } else if (pShader) {
1829 ERR("Trying to set an invalid handle.\n");
1832 TRACE("(%p) : Setting shader %p\n", This, shader);
1833 hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, shader == NULL ? NULL :shader->wineD3DPixelShader);
1834 LeaveCriticalSection(&d3d8_cs);
1835 return hr;
1838 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD* ppShader) {
1839 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1840 IWineD3DPixelShader *object;
1842 HRESULT hrc = D3D_OK;
1843 TRACE("(%p) Relay\n", This);
1844 if (NULL == ppShader) {
1845 TRACE("(%p) Invalid call\n", This);
1846 return D3DERR_INVALIDCALL;
1849 EnterCriticalSection(&d3d8_cs);
1850 hrc = IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &object);
1851 if (D3D_OK == hrc && NULL != object) {
1852 IDirect3DPixelShader8Impl *d3d8_shader;
1853 hrc = IWineD3DPixelShader_GetParent(object, (IUnknown **)&d3d8_shader);
1854 IWineD3DPixelShader_Release(object);
1855 *ppShader = (d3d8_shader->handle - This->shader_handles) + (VS_HIGHESTFIXEDFXF + 1);
1856 } else {
1857 *ppShader = (DWORD)NULL;
1860 TRACE("(%p) : returning %#x\n", This, *ppShader);
1861 LeaveCriticalSection(&d3d8_cs);
1862 return hrc;
1865 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
1866 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1868 TRACE("(%p) : pShader %#x\n", This, pShader);
1870 EnterCriticalSection(&d3d8_cs);
1871 if (pShader <= VS_HIGHESTFIXEDFXF || This->allocated_shader_handles <= pShader - (VS_HIGHESTFIXEDFXF + 1)) {
1872 ERR("(%p) : Trying to delete an invalid handle\n", This);
1873 LeaveCriticalSection(&d3d8_cs);
1874 return D3DERR_INVALIDCALL;
1875 } else {
1876 IWineD3DPixelShader *cur = NULL;
1877 shader_handle *handle = &This->shader_handles[pShader - (VS_HIGHESTFIXEDFXF + 1)];
1878 IDirect3DPixelShader8Impl *shader = *handle;
1880 IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &cur);
1881 if(cur) {
1882 if(cur == shader->wineD3DPixelShader) IDirect3DDevice8_SetPixelShader(iface, 0);
1883 IWineD3DPixelShader_Release(cur);
1886 while(IUnknown_Release((IUnknown *)shader));
1887 free_shader_handle(This, handle);
1889 LeaveCriticalSection(&d3d8_cs);
1891 return D3D_OK;
1894 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
1895 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1896 HRESULT hr;
1897 TRACE("(%p) Relay\n", This);
1899 EnterCriticalSection(&d3d8_cs);
1900 hr = IWineD3DDevice_SetPixelShaderConstantF(This->WineD3DDevice, Register, (CONST float *)pConstantData, ConstantCount);
1901 LeaveCriticalSection(&d3d8_cs);
1902 return hr;
1905 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, void* pConstantData, DWORD ConstantCount) {
1906 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1907 HRESULT hr;
1908 TRACE("(%p) Relay\n", This);
1910 EnterCriticalSection(&d3d8_cs);
1911 hr = IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, Register, (float *)pConstantData, ConstantCount);
1912 LeaveCriticalSection(&d3d8_cs);
1913 return hr;
1916 static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShaderFunction(LPDIRECT3DDEVICE8 iface, DWORD pPixelShader, void* pData, DWORD* pSizeOfData) {
1917 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1918 IDirect3DPixelShader8Impl *shader = NULL;
1919 HRESULT hr;
1921 TRACE("(%p) : pPixelShader %#x, pData %p, pSizeOfData %p\n", This, pPixelShader, pData, pSizeOfData);
1923 EnterCriticalSection(&d3d8_cs);
1924 if (pPixelShader <= VS_HIGHESTFIXEDFXF || This->allocated_shader_handles <= pPixelShader - (VS_HIGHESTFIXEDFXF + 1)) {
1925 ERR("Passed an invalid shader handle.\n");
1926 LeaveCriticalSection(&d3d8_cs);
1927 return D3DERR_INVALIDCALL;
1930 shader = This->shader_handles[pPixelShader - (VS_HIGHESTFIXEDFXF + 1)];
1931 hr = IWineD3DPixelShader_GetFunction(shader->wineD3DPixelShader, pData, (UINT *)pSizeOfData);
1932 LeaveCriticalSection(&d3d8_cs);
1933 return hr;
1936 static HRESULT WINAPI IDirect3DDevice8Impl_DrawRectPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
1937 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1938 HRESULT hr;
1939 TRACE("(%p) Relay\n", This);
1941 EnterCriticalSection(&d3d8_cs);
1942 hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
1943 LeaveCriticalSection(&d3d8_cs);
1944 return hr;
1947 static HRESULT WINAPI IDirect3DDevice8Impl_DrawTriPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo) {
1948 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1949 HRESULT hr;
1950 TRACE("(%p) Relay\n", This);
1952 EnterCriticalSection(&d3d8_cs);
1953 hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
1954 LeaveCriticalSection(&d3d8_cs);
1955 return hr;
1958 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePatch(LPDIRECT3DDEVICE8 iface, UINT Handle) {
1959 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1960 HRESULT hr;
1961 TRACE("(%p) Relay\n", This);
1963 EnterCriticalSection(&d3d8_cs);
1964 hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
1965 LeaveCriticalSection(&d3d8_cs);
1966 return hr;
1969 static HRESULT WINAPI IDirect3DDevice8Impl_SetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8* pStreamData,UINT Stride) {
1970 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1971 HRESULT hr;
1972 TRACE("(%p) Relay\n" , This);
1974 EnterCriticalSection(&d3d8_cs);
1975 hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
1976 NULL == pStreamData ? NULL : ((IDirect3DVertexBuffer8Impl *)pStreamData)->wineD3DVertexBuffer,
1977 0/* Offset in bytes */, Stride);
1978 LeaveCriticalSection(&d3d8_cs);
1979 return hr;
1982 static HRESULT WINAPI IDirect3DDevice8Impl_GetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8** pStream,UINT* pStride) {
1983 IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
1984 IWineD3DVertexBuffer *retStream = NULL;
1985 HRESULT rc = D3D_OK;
1987 TRACE("(%p) Relay\n" , This);
1989 if(pStream == NULL){
1990 return D3DERR_INVALIDCALL;
1993 EnterCriticalSection(&d3d8_cs);
1994 rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, (IWineD3DVertexBuffer **)&retStream, 0 /* Offset in bytes */, pStride);
1995 if (rc == D3D_OK && NULL != retStream) {
1996 IWineD3DVertexBuffer_GetParent(retStream, (IUnknown **)pStream);
1997 IWineD3DVertexBuffer_Release(retStream);
1998 }else{
1999 if (rc != D3D_OK){
2000 FIXME("Call to GetStreamSource failed %p\n", pStride);
2002 *pStream = NULL;
2004 LeaveCriticalSection(&d3d8_cs);
2006 return rc;
2010 const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl =
2012 IDirect3DDevice8Impl_QueryInterface,
2013 IDirect3DDevice8Impl_AddRef,
2014 IDirect3DDevice8Impl_Release,
2015 IDirect3DDevice8Impl_TestCooperativeLevel,
2016 IDirect3DDevice8Impl_GetAvailableTextureMem,
2017 IDirect3DDevice8Impl_ResourceManagerDiscardBytes,
2018 IDirect3DDevice8Impl_GetDirect3D,
2019 IDirect3DDevice8Impl_GetDeviceCaps,
2020 IDirect3DDevice8Impl_GetDisplayMode,
2021 IDirect3DDevice8Impl_GetCreationParameters,
2022 IDirect3DDevice8Impl_SetCursorProperties,
2023 IDirect3DDevice8Impl_SetCursorPosition,
2024 IDirect3DDevice8Impl_ShowCursor,
2025 IDirect3DDevice8Impl_CreateAdditionalSwapChain,
2026 IDirect3DDevice8Impl_Reset,
2027 IDirect3DDevice8Impl_Present,
2028 IDirect3DDevice8Impl_GetBackBuffer,
2029 IDirect3DDevice8Impl_GetRasterStatus,
2030 IDirect3DDevice8Impl_SetGammaRamp,
2031 IDirect3DDevice8Impl_GetGammaRamp,
2032 IDirect3DDevice8Impl_CreateTexture,
2033 IDirect3DDevice8Impl_CreateVolumeTexture,
2034 IDirect3DDevice8Impl_CreateCubeTexture,
2035 IDirect3DDevice8Impl_CreateVertexBuffer,
2036 IDirect3DDevice8Impl_CreateIndexBuffer,
2037 IDirect3DDevice8Impl_CreateRenderTarget,
2038 IDirect3DDevice8Impl_CreateDepthStencilSurface,
2039 IDirect3DDevice8Impl_CreateImageSurface,
2040 IDirect3DDevice8Impl_CopyRects,
2041 IDirect3DDevice8Impl_UpdateTexture,
2042 IDirect3DDevice8Impl_GetFrontBuffer,
2043 IDirect3DDevice8Impl_SetRenderTarget,
2044 IDirect3DDevice8Impl_GetRenderTarget,
2045 IDirect3DDevice8Impl_GetDepthStencilSurface,
2046 IDirect3DDevice8Impl_BeginScene,
2047 IDirect3DDevice8Impl_EndScene,
2048 IDirect3DDevice8Impl_Clear,
2049 IDirect3DDevice8Impl_SetTransform,
2050 IDirect3DDevice8Impl_GetTransform,
2051 IDirect3DDevice8Impl_MultiplyTransform,
2052 IDirect3DDevice8Impl_SetViewport,
2053 IDirect3DDevice8Impl_GetViewport,
2054 IDirect3DDevice8Impl_SetMaterial,
2055 IDirect3DDevice8Impl_GetMaterial,
2056 IDirect3DDevice8Impl_SetLight,
2057 IDirect3DDevice8Impl_GetLight,
2058 IDirect3DDevice8Impl_LightEnable,
2059 IDirect3DDevice8Impl_GetLightEnable,
2060 IDirect3DDevice8Impl_SetClipPlane,
2061 IDirect3DDevice8Impl_GetClipPlane,
2062 IDirect3DDevice8Impl_SetRenderState,
2063 IDirect3DDevice8Impl_GetRenderState,
2064 IDirect3DDevice8Impl_BeginStateBlock,
2065 IDirect3DDevice8Impl_EndStateBlock,
2066 IDirect3DDevice8Impl_ApplyStateBlock,
2067 IDirect3DDevice8Impl_CaptureStateBlock,
2068 IDirect3DDevice8Impl_DeleteStateBlock,
2069 IDirect3DDevice8Impl_CreateStateBlock,
2070 IDirect3DDevice8Impl_SetClipStatus,
2071 IDirect3DDevice8Impl_GetClipStatus,
2072 IDirect3DDevice8Impl_GetTexture,
2073 IDirect3DDevice8Impl_SetTexture,
2074 IDirect3DDevice8Impl_GetTextureStageState,
2075 IDirect3DDevice8Impl_SetTextureStageState,
2076 IDirect3DDevice8Impl_ValidateDevice,
2077 IDirect3DDevice8Impl_GetInfo,
2078 IDirect3DDevice8Impl_SetPaletteEntries,
2079 IDirect3DDevice8Impl_GetPaletteEntries,
2080 IDirect3DDevice8Impl_SetCurrentTexturePalette,
2081 IDirect3DDevice8Impl_GetCurrentTexturePalette,
2082 IDirect3DDevice8Impl_DrawPrimitive,
2083 IDirect3DDevice8Impl_DrawIndexedPrimitive,
2084 IDirect3DDevice8Impl_DrawPrimitiveUP,
2085 IDirect3DDevice8Impl_DrawIndexedPrimitiveUP,
2086 IDirect3DDevice8Impl_ProcessVertices,
2087 IDirect3DDevice8Impl_CreateVertexShader,
2088 IDirect3DDevice8Impl_SetVertexShader,
2089 IDirect3DDevice8Impl_GetVertexShader,
2090 IDirect3DDevice8Impl_DeleteVertexShader,
2091 IDirect3DDevice8Impl_SetVertexShaderConstant,
2092 IDirect3DDevice8Impl_GetVertexShaderConstant,
2093 IDirect3DDevice8Impl_GetVertexShaderDeclaration,
2094 IDirect3DDevice8Impl_GetVertexShaderFunction,
2095 IDirect3DDevice8Impl_SetStreamSource,
2096 IDirect3DDevice8Impl_GetStreamSource,
2097 IDirect3DDevice8Impl_SetIndices,
2098 IDirect3DDevice8Impl_GetIndices,
2099 IDirect3DDevice8Impl_CreatePixelShader,
2100 IDirect3DDevice8Impl_SetPixelShader,
2101 IDirect3DDevice8Impl_GetPixelShader,
2102 IDirect3DDevice8Impl_DeletePixelShader,
2103 IDirect3DDevice8Impl_SetPixelShaderConstant,
2104 IDirect3DDevice8Impl_GetPixelShaderConstant,
2105 IDirect3DDevice8Impl_GetPixelShaderFunction,
2106 IDirect3DDevice8Impl_DrawRectPatch,
2107 IDirect3DDevice8Impl_DrawTriPatch,
2108 IDirect3DDevice8Impl_DeletePatch
2111 /* Internal function called back during the CreateDevice to create a render target */
2112 HRESULT WINAPI D3D8CB_CreateSurface(IUnknown *device, IUnknown *pSuperior, UINT Width, UINT Height,
2113 WINED3DFORMAT Format, DWORD Usage, WINED3DPOOL Pool, UINT Level,
2114 WINED3DCUBEMAP_FACES Face, IWineD3DSurface **ppSurface,
2115 HANDLE *pSharedHandle) {
2117 HRESULT res = D3D_OK;
2118 IDirect3DSurface8Impl *d3dSurface = NULL;
2119 BOOL Lockable = TRUE;
2121 if((WINED3DPOOL_DEFAULT == Pool && WINED3DUSAGE_DYNAMIC != Usage))
2122 Lockable = FALSE;
2124 TRACE("relay\n");
2125 res = IDirect3DDevice8Impl_CreateSurface((IDirect3DDevice8 *)device, Width, Height, (D3DFORMAT)Format, Lockable, FALSE/*Discard*/, Level, (IDirect3DSurface8 **)&d3dSurface, D3DRTYPE_SURFACE, Usage, Pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
2127 if (SUCCEEDED(res)) {
2128 *ppSurface = d3dSurface->wineD3DSurface;
2129 d3dSurface->container = pSuperior;
2130 IUnknown_Release(d3dSurface->parentDevice);
2131 d3dSurface->parentDevice = NULL;
2132 d3dSurface->forwardReference = pSuperior;
2133 } else {
2134 FIXME("(%p) IDirect3DDevice8_CreateSurface failed\n", device);
2136 return res;
2139 ULONG WINAPI D3D8CB_DestroySurface(IWineD3DSurface *pSurface) {
2140 IDirect3DSurface8Impl* surfaceParent;
2141 TRACE("(%p) call back\n", pSurface);
2143 IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
2144 /* GetParent's AddRef was forwarded to an object in destruction.
2145 * Releasing it here again would cause an endless recursion. */
2146 surfaceParent->forwardReference = NULL;
2147 return IDirect3DSurface8_Release((IDirect3DSurface8*) surfaceParent);