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
);
110 IWineD3DDevice_Uninit3D(This
->WineD3DDevice
, D3D8CB_DestroyDepthStencilSurface
, D3D8CB_DestroySwapChain
);
111 IWineD3DDevice_Release(This
->WineD3DDevice
);
112 HeapFree(GetProcessHeap(), 0, This
->shader_handles
);
113 HeapFree(GetProcessHeap(), 0, This
);
114 LeaveCriticalSection(&d3d8_cs
);
119 /* IDirect3DDevice Interface follow: */
120 static HRESULT WINAPI
IDirect3DDevice8Impl_TestCooperativeLevel(LPDIRECT3DDEVICE8 iface
) {
121 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
124 TRACE("(%p) : Relay\n", This
);
125 EnterCriticalSection(&d3d8_cs
);
126 hr
= IWineD3DDevice_TestCooperativeLevel(This
->WineD3DDevice
);
127 LeaveCriticalSection(&d3d8_cs
);
131 static UINT WINAPI
IDirect3DDevice8Impl_GetAvailableTextureMem(LPDIRECT3DDEVICE8 iface
) {
132 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
135 TRACE("(%p) Relay\n", This
);
136 EnterCriticalSection(&d3d8_cs
);
137 hr
= IWineD3DDevice_GetAvailableTextureMem(This
->WineD3DDevice
);
138 LeaveCriticalSection(&d3d8_cs
);
142 static HRESULT WINAPI
IDirect3DDevice8Impl_ResourceManagerDiscardBytes(LPDIRECT3DDEVICE8 iface
, DWORD Bytes
) {
143 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
146 TRACE("(%p) : Relay bytes(%d)\n", This
, Bytes
);
147 EnterCriticalSection(&d3d8_cs
);
148 hr
= IWineD3DDevice_EvictManagedResources(This
->WineD3DDevice
);
149 LeaveCriticalSection(&d3d8_cs
);
153 static HRESULT WINAPI
IDirect3DDevice8Impl_GetDirect3D(LPDIRECT3DDEVICE8 iface
, IDirect3D8
** ppD3D8
) {
154 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
158 TRACE("(%p) Relay\n", This
);
160 if (NULL
== ppD3D8
) {
161 return D3DERR_INVALIDCALL
;
164 EnterCriticalSection(&d3d8_cs
);
165 hr
= IWineD3DDevice_GetDirect3D(This
->WineD3DDevice
, &pWineD3D
);
166 if (hr
== D3D_OK
&& pWineD3D
!= NULL
)
168 IWineD3D_GetParent(pWineD3D
,(IUnknown
**)ppD3D8
);
169 IWineD3D_Release(pWineD3D
);
171 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
174 TRACE("(%p) returning %p\n",This
, *ppD3D8
);
175 LeaveCriticalSection(&d3d8_cs
);
180 static HRESULT WINAPI
IDirect3DDevice8Impl_GetDeviceCaps(LPDIRECT3DDEVICE8 iface
, D3DCAPS8
* pCaps
) {
181 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
182 HRESULT hrc
= D3D_OK
;
183 WINED3DCAPS
*pWineCaps
;
185 TRACE("(%p) : Relay pCaps %p\n", This
, pCaps
);
187 return D3DERR_INVALIDCALL
;
189 pWineCaps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WINED3DCAPS
));
190 if(pWineCaps
== NULL
){
191 return D3DERR_INVALIDCALL
; /* well this is what MSDN says to return */
194 D3D8CAPSTOWINECAPS(pCaps
, pWineCaps
)
195 EnterCriticalSection(&d3d8_cs
);
196 hrc
= IWineD3DDevice_GetDeviceCaps(This
->WineD3DDevice
, pWineCaps
);
197 LeaveCriticalSection(&d3d8_cs
);
198 HeapFree(GetProcessHeap(), 0, pWineCaps
);
200 /* D3D8 doesn't support SM 2.0 or higher, so clamp to 1.x */
201 if(pCaps
->PixelShaderVersion
> D3DPS_VERSION(1,4)){
202 pCaps
->PixelShaderVersion
= D3DPS_VERSION(1,4);
204 if(pCaps
->VertexShaderVersion
> D3DVS_VERSION(1,1)){
205 pCaps
->VertexShaderVersion
= D3DVS_VERSION(1,1);
208 TRACE("Returning %p %p\n", This
, pCaps
);
212 static HRESULT WINAPI
IDirect3DDevice8Impl_GetDisplayMode(LPDIRECT3DDEVICE8 iface
, D3DDISPLAYMODE
* pMode
) {
213 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
215 TRACE("(%p) Relay\n", This
);
217 EnterCriticalSection(&d3d8_cs
);
218 hr
= IWineD3DDevice_GetDisplayMode(This
->WineD3DDevice
, 0, (WINED3DDISPLAYMODE
*) pMode
);
219 LeaveCriticalSection(&d3d8_cs
);
223 static HRESULT WINAPI
IDirect3DDevice8Impl_GetCreationParameters(LPDIRECT3DDEVICE8 iface
, D3DDEVICE_CREATION_PARAMETERS
*pParameters
) {
224 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
226 TRACE("(%p) Relay\n", This
);
228 EnterCriticalSection(&d3d8_cs
);
229 hr
= IWineD3DDevice_GetCreationParameters(This
->WineD3DDevice
, (WINED3DDEVICE_CREATION_PARAMETERS
*) pParameters
);
230 LeaveCriticalSection(&d3d8_cs
);
234 static HRESULT WINAPI
IDirect3DDevice8Impl_SetCursorProperties(LPDIRECT3DDEVICE8 iface
, UINT XHotSpot
, UINT YHotSpot
, IDirect3DSurface8
* pCursorBitmap
) {
235 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
236 IDirect3DSurface8Impl
*pSurface
= (IDirect3DSurface8Impl
*)pCursorBitmap
;
238 TRACE("(%p) Relay\n", This
);
240 WARN("No cursor bitmap, returning WINED3DERR_INVALIDCALL\n");
241 return WINED3DERR_INVALIDCALL
;
244 EnterCriticalSection(&d3d8_cs
);
245 hr
= IWineD3DDevice_SetCursorProperties(This
->WineD3DDevice
,XHotSpot
,YHotSpot
,(IWineD3DSurface
*)pSurface
->wineD3DSurface
);
246 LeaveCriticalSection(&d3d8_cs
);
250 static void WINAPI
IDirect3DDevice8Impl_SetCursorPosition(LPDIRECT3DDEVICE8 iface
, UINT XScreenSpace
, UINT YScreenSpace
, DWORD Flags
) {
251 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
252 TRACE("(%p) Relay\n", This
);
254 EnterCriticalSection(&d3d8_cs
);
255 IWineD3DDevice_SetCursorPosition(This
->WineD3DDevice
, XScreenSpace
, YScreenSpace
, Flags
);
256 LeaveCriticalSection(&d3d8_cs
);
259 static BOOL WINAPI
IDirect3DDevice8Impl_ShowCursor(LPDIRECT3DDEVICE8 iface
, BOOL bShow
) {
260 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
262 TRACE("(%p) Relay\n", This
);
264 EnterCriticalSection(&d3d8_cs
);
265 ret
= IWineD3DDevice_ShowCursor(This
->WineD3DDevice
, bShow
);
266 LeaveCriticalSection(&d3d8_cs
);
270 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE8 iface
, D3DPRESENT_PARAMETERS
* pPresentationParameters
, IDirect3DSwapChain8
** pSwapChain
) {
271 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
272 IDirect3DSwapChain8Impl
* object
;
273 HRESULT hrc
= D3D_OK
;
274 WINED3DPRESENT_PARAMETERS localParameters
;
276 TRACE("(%p) Relay\n", This
);
278 /* Fix the back buffer count */
279 if(pPresentationParameters
->BackBufferCount
== 0) {
280 pPresentationParameters
->BackBufferCount
= 1;
283 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
284 if (NULL
== object
) {
285 FIXME("Allocation of memory failed\n");
287 return D3DERR_OUTOFVIDEOMEMORY
;
290 object
->lpVtbl
= &Direct3DSwapChain8_Vtbl
;
292 /* Allocate an associated WineD3DDevice object */
293 localParameters
.BackBufferWidth
= pPresentationParameters
->BackBufferWidth
;
294 localParameters
.BackBufferHeight
= pPresentationParameters
->BackBufferHeight
;
295 localParameters
.BackBufferFormat
= pPresentationParameters
->BackBufferFormat
;
296 localParameters
.BackBufferCount
= pPresentationParameters
->BackBufferCount
;
297 localParameters
.MultiSampleType
= pPresentationParameters
->MultiSampleType
;
298 localParameters
.MultiSampleQuality
= 0; /* d3d9 only */
299 localParameters
.SwapEffect
= pPresentationParameters
->SwapEffect
;
300 localParameters
.hDeviceWindow
= pPresentationParameters
->hDeviceWindow
;
301 localParameters
.Windowed
= pPresentationParameters
->Windowed
;
302 localParameters
.EnableAutoDepthStencil
= pPresentationParameters
->EnableAutoDepthStencil
;
303 localParameters
.AutoDepthStencilFormat
= pPresentationParameters
->AutoDepthStencilFormat
;
304 localParameters
.Flags
= pPresentationParameters
->Flags
;
305 localParameters
.FullScreen_RefreshRateInHz
= pPresentationParameters
->FullScreen_RefreshRateInHz
;
306 localParameters
.PresentationInterval
= pPresentationParameters
->FullScreen_PresentationInterval
;
308 EnterCriticalSection(&d3d8_cs
);
309 hrc
= IWineD3DDevice_CreateAdditionalSwapChain(This
->WineD3DDevice
, &localParameters
, &object
->wineD3DSwapChain
, (IUnknown
*)object
, D3D8CB_CreateRenderTarget
, D3D8CB_CreateDepthStencilSurface
);
310 LeaveCriticalSection(&d3d8_cs
);
312 pPresentationParameters
->BackBufferWidth
= localParameters
.BackBufferWidth
;
313 pPresentationParameters
->BackBufferHeight
= localParameters
.BackBufferHeight
;
314 pPresentationParameters
->BackBufferFormat
= localParameters
.BackBufferFormat
;
315 pPresentationParameters
->BackBufferCount
= localParameters
.BackBufferCount
;
316 pPresentationParameters
->MultiSampleType
= localParameters
.MultiSampleType
;
317 pPresentationParameters
->SwapEffect
= localParameters
.SwapEffect
;
318 pPresentationParameters
->hDeviceWindow
= localParameters
.hDeviceWindow
;
319 pPresentationParameters
->Windowed
= localParameters
.Windowed
;
320 pPresentationParameters
->EnableAutoDepthStencil
= localParameters
.EnableAutoDepthStencil
;
321 pPresentationParameters
->AutoDepthStencilFormat
= localParameters
.AutoDepthStencilFormat
;
322 pPresentationParameters
->Flags
= localParameters
.Flags
;
323 pPresentationParameters
->FullScreen_RefreshRateInHz
= localParameters
.FullScreen_RefreshRateInHz
;
324 pPresentationParameters
->FullScreen_PresentationInterval
= localParameters
.PresentationInterval
;
327 FIXME("(%p) call to IWineD3DDevice_CreateAdditionalSwapChain failed\n", This
);
328 HeapFree(GetProcessHeap(), 0 , object
);
331 IUnknown_AddRef(iface
);
332 object
->parentDevice
= iface
;
333 *pSwapChain
= (IDirect3DSwapChain8
*)object
;
335 TRACE("(%p) returning %p\n", This
, *pSwapChain
);
339 static HRESULT WINAPI
IDirect3DDevice8Impl_Reset(LPDIRECT3DDEVICE8 iface
, D3DPRESENT_PARAMETERS
* pPresentationParameters
) {
340 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
341 WINED3DPRESENT_PARAMETERS localParameters
;
344 TRACE("(%p) Relay pPresentationParameters(%p)\n", This
, pPresentationParameters
);
346 localParameters
.BackBufferWidth
= pPresentationParameters
->BackBufferWidth
;
347 localParameters
.BackBufferHeight
= pPresentationParameters
->BackBufferHeight
;
348 localParameters
.BackBufferFormat
= pPresentationParameters
->BackBufferFormat
;
349 localParameters
.BackBufferCount
= pPresentationParameters
->BackBufferCount
;
350 localParameters
.MultiSampleType
= pPresentationParameters
->MultiSampleType
;
351 localParameters
.MultiSampleQuality
= 0; /* d3d9 only */
352 localParameters
.SwapEffect
= pPresentationParameters
->SwapEffect
;
353 localParameters
.hDeviceWindow
= pPresentationParameters
->hDeviceWindow
;
354 localParameters
.Windowed
= pPresentationParameters
->Windowed
;
355 localParameters
.EnableAutoDepthStencil
= pPresentationParameters
->EnableAutoDepthStencil
;
356 localParameters
.AutoDepthStencilFormat
= pPresentationParameters
->AutoDepthStencilFormat
;
357 localParameters
.Flags
= pPresentationParameters
->Flags
;
358 localParameters
.FullScreen_RefreshRateInHz
= pPresentationParameters
->FullScreen_RefreshRateInHz
;
359 localParameters
.PresentationInterval
= pPresentationParameters
->FullScreen_PresentationInterval
;
361 EnterCriticalSection(&d3d8_cs
);
362 hr
= IWineD3DDevice_Reset(This
->WineD3DDevice
, &localParameters
);
363 LeaveCriticalSection(&d3d8_cs
);
365 pPresentationParameters
->BackBufferWidth
= localParameters
.BackBufferWidth
;
366 pPresentationParameters
->BackBufferHeight
= localParameters
.BackBufferHeight
;
367 pPresentationParameters
->BackBufferFormat
= localParameters
.BackBufferFormat
;
368 pPresentationParameters
->BackBufferCount
= localParameters
.BackBufferCount
;
369 pPresentationParameters
->MultiSampleType
= localParameters
.MultiSampleType
;
370 pPresentationParameters
->SwapEffect
= localParameters
.SwapEffect
;
371 pPresentationParameters
->hDeviceWindow
= localParameters
.hDeviceWindow
;
372 pPresentationParameters
->Windowed
= localParameters
.Windowed
;
373 pPresentationParameters
->EnableAutoDepthStencil
= localParameters
.EnableAutoDepthStencil
;
374 pPresentationParameters
->AutoDepthStencilFormat
= localParameters
.AutoDepthStencilFormat
;
375 pPresentationParameters
->Flags
= localParameters
.Flags
;
376 pPresentationParameters
->FullScreen_RefreshRateInHz
= localParameters
.FullScreen_RefreshRateInHz
;
377 pPresentationParameters
->FullScreen_PresentationInterval
= localParameters
.PresentationInterval
;
382 static HRESULT WINAPI
IDirect3DDevice8Impl_Present(LPDIRECT3DDEVICE8 iface
, CONST RECT
* pSourceRect
,CONST RECT
* pDestRect
,HWND hDestWindowOverride
,CONST RGNDATA
* pDirtyRegion
) {
383 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
385 TRACE("(%p) Relay\n", This
);
387 EnterCriticalSection(&d3d8_cs
);
388 hr
= IWineD3DDevice_Present(This
->WineD3DDevice
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
389 LeaveCriticalSection(&d3d8_cs
);
393 static HRESULT WINAPI
IDirect3DDevice8Impl_GetBackBuffer(LPDIRECT3DDEVICE8 iface
, UINT BackBuffer
, D3DBACKBUFFER_TYPE Type
, IDirect3DSurface8
** ppBackBuffer
) {
394 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
395 IWineD3DSurface
*retSurface
= NULL
;
398 TRACE("(%p) Relay\n", This
);
400 EnterCriticalSection(&d3d8_cs
);
401 rc
= IWineD3DDevice_GetBackBuffer(This
->WineD3DDevice
, 0, BackBuffer
, (WINED3DBACKBUFFER_TYPE
) Type
, (IWineD3DSurface
**)&retSurface
);
402 if (rc
== D3D_OK
&& NULL
!= retSurface
&& NULL
!= ppBackBuffer
) {
403 IWineD3DSurface_GetParent(retSurface
, (IUnknown
**)ppBackBuffer
);
404 IWineD3DSurface_Release(retSurface
);
406 LeaveCriticalSection(&d3d8_cs
);
410 static HRESULT WINAPI
IDirect3DDevice8Impl_GetRasterStatus(LPDIRECT3DDEVICE8 iface
, D3DRASTER_STATUS
* pRasterStatus
) {
411 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
413 TRACE("(%p) Relay\n", This
);
415 EnterCriticalSection(&d3d8_cs
);
416 hr
= IWineD3DDevice_GetRasterStatus(This
->WineD3DDevice
, 0, (WINED3DRASTER_STATUS
*) pRasterStatus
);
417 LeaveCriticalSection(&d3d8_cs
);
421 static void WINAPI
IDirect3DDevice8Impl_SetGammaRamp(LPDIRECT3DDEVICE8 iface
, DWORD Flags
, CONST D3DGAMMARAMP
* pRamp
) {
422 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
423 TRACE("(%p) Relay\n", This
);
425 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
426 EnterCriticalSection(&d3d8_cs
);
427 IWineD3DDevice_SetGammaRamp(This
->WineD3DDevice
, 0, Flags
, (CONST WINED3DGAMMARAMP
*) pRamp
);
428 LeaveCriticalSection(&d3d8_cs
);
431 static void WINAPI
IDirect3DDevice8Impl_GetGammaRamp(LPDIRECT3DDEVICE8 iface
, D3DGAMMARAMP
* pRamp
) {
432 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
433 TRACE("(%p) Relay\n", This
);
435 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
436 EnterCriticalSection(&d3d8_cs
);
437 IWineD3DDevice_GetGammaRamp(This
->WineD3DDevice
, 0, (WINED3DGAMMARAMP
*) pRamp
);
438 LeaveCriticalSection(&d3d8_cs
);
441 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateTexture(LPDIRECT3DDEVICE8 iface
, UINT Width
, UINT Height
, UINT Levels
, DWORD Usage
,
442 D3DFORMAT Format
, D3DPOOL Pool
, IDirect3DTexture8
**ppTexture
) {
443 IDirect3DTexture8Impl
*object
;
444 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
445 HRESULT hrc
= D3D_OK
;
447 TRACE("(%p) : W(%d) H(%d), Lvl(%d) d(%d), Fmt(%u), Pool(%d)\n", This
, Width
, Height
, Levels
, Usage
, Format
, Pool
);
449 /* Allocate the storage for the device */
450 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirect3DTexture8Impl
));
452 if (NULL
== object
) {
453 FIXME("Allocation of memory failed\n");
454 /* *ppTexture = NULL; */
455 return D3DERR_OUTOFVIDEOMEMORY
;
458 object
->lpVtbl
= &Direct3DTexture8_Vtbl
;
460 EnterCriticalSection(&d3d8_cs
);
461 hrc
= IWineD3DDevice_CreateTexture(This
->WineD3DDevice
, Width
, Height
, Levels
, Usage
& WINED3DUSAGE_MASK
,
462 (WINED3DFORMAT
)Format
, (WINED3DPOOL
) Pool
, &object
->wineD3DTexture
, NULL
, (IUnknown
*)object
, D3D8CB_CreateSurface
);
463 LeaveCriticalSection(&d3d8_cs
);
467 FIXME("(%p) call to IWineD3DDevice_CreateTexture failed\n", This
);
468 HeapFree(GetProcessHeap(), 0, object
);
469 /* *ppTexture = NULL; */
471 IUnknown_AddRef(iface
);
472 object
->parentDevice
= iface
;
473 *ppTexture
= (LPDIRECT3DTEXTURE8
) object
;
476 TRACE("(%p) Created Texture %p, %p\n",This
,object
,object
->wineD3DTexture
);
480 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateVolumeTexture(LPDIRECT3DDEVICE8 iface
,
481 UINT Width
, UINT Height
, UINT Depth
, UINT Levels
, DWORD Usage
,
482 D3DFORMAT Format
, D3DPOOL Pool
, IDirect3DVolumeTexture8
** ppVolumeTexture
) {
484 IDirect3DVolumeTexture8Impl
*object
;
485 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
486 HRESULT hrc
= D3D_OK
;
488 TRACE("(%p) Relay\n", This
);
490 /* Allocate the storage for the device */
491 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirect3DVolumeTexture8Impl
));
492 if (NULL
== object
) {
493 FIXME("(%p) allocation of memory failed\n", This
);
494 *ppVolumeTexture
= NULL
;
495 return D3DERR_OUTOFVIDEOMEMORY
;
498 object
->lpVtbl
= &Direct3DVolumeTexture8_Vtbl
;
500 EnterCriticalSection(&d3d8_cs
);
501 hrc
= IWineD3DDevice_CreateVolumeTexture(This
->WineD3DDevice
, Width
, Height
, Depth
, Levels
, Usage
& WINED3DUSAGE_MASK
,
502 (WINED3DFORMAT
)Format
, (WINED3DPOOL
) Pool
, &object
->wineD3DVolumeTexture
, NULL
,
503 (IUnknown
*)object
, D3D8CB_CreateVolume
);
504 LeaveCriticalSection(&d3d8_cs
);
509 FIXME("(%p) call to IWineD3DDevice_CreateVolumeTexture failed\n", This
);
510 HeapFree(GetProcessHeap(), 0, object
);
511 *ppVolumeTexture
= NULL
;
513 IUnknown_AddRef(iface
);
514 object
->parentDevice
= iface
;
515 *ppVolumeTexture
= (LPDIRECT3DVOLUMETEXTURE8
) object
;
517 TRACE("(%p) returning %p\n", This
, *ppVolumeTexture
);
521 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateCubeTexture(LPDIRECT3DDEVICE8 iface
, UINT EdgeLength
, UINT Levels
, DWORD Usage
,
522 D3DFORMAT Format
, D3DPOOL Pool
, IDirect3DCubeTexture8
** ppCubeTexture
) {
524 IDirect3DCubeTexture8Impl
*object
;
525 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
528 TRACE("(%p) : ELen(%d) Lvl(%d) Usage(%d) fmt(%u), Pool(%d)\n" , This
, EdgeLength
, Levels
, Usage
, Format
, Pool
);
530 /* Allocate the storage for the device */
531 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
533 if (NULL
== object
) {
534 FIXME("(%p) allocation of CubeTexture failed\n", This
);
535 *ppCubeTexture
= NULL
;
536 return D3DERR_OUTOFVIDEOMEMORY
;
539 object
->lpVtbl
= &Direct3DCubeTexture8_Vtbl
;
541 EnterCriticalSection(&d3d8_cs
);
542 hr
= IWineD3DDevice_CreateCubeTexture(This
->WineD3DDevice
, EdgeLength
, Levels
, Usage
& WINED3DUSAGE_MASK
,
543 (WINED3DFORMAT
)Format
, (WINED3DPOOL
) Pool
, &object
->wineD3DCubeTexture
, NULL
, (IUnknown
*)object
,
544 D3D8CB_CreateSurface
);
545 LeaveCriticalSection(&d3d8_cs
);
550 FIXME("(%p) call to IWineD3DDevice_CreateCubeTexture failed\n", This
);
551 HeapFree(GetProcessHeap(), 0, object
);
552 *ppCubeTexture
= NULL
;
554 IUnknown_AddRef(iface
);
555 object
->parentDevice
= iface
;
556 *ppCubeTexture
= (LPDIRECT3DCUBETEXTURE8
) object
;
559 TRACE("(%p) returning %p\n",This
, *ppCubeTexture
);
563 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateVertexBuffer(LPDIRECT3DDEVICE8 iface
, UINT Size
, DWORD Usage
, DWORD FVF
, D3DPOOL Pool
, IDirect3DVertexBuffer8
** ppVertexBuffer
) {
564 IDirect3DVertexBuffer8Impl
*object
;
565 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
566 HRESULT hrc
= D3D_OK
;
568 TRACE("(%p) Relay\n", This
);
569 /* Allocate the storage for the device */
570 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirect3DVertexBuffer8Impl
));
571 if (NULL
== object
) {
572 FIXME("Allocation of memory failed\n");
573 *ppVertexBuffer
= NULL
;
574 return D3DERR_OUTOFVIDEOMEMORY
;
577 object
->lpVtbl
= &Direct3DVertexBuffer8_Vtbl
;
579 EnterCriticalSection(&d3d8_cs
);
580 hrc
= IWineD3DDevice_CreateVertexBuffer(This
->WineD3DDevice
, Size
, Usage
& WINED3DUSAGE_MASK
, FVF
, (WINED3DPOOL
) Pool
, &(object
->wineD3DVertexBuffer
), NULL
, (IUnknown
*)object
);
581 LeaveCriticalSection(&d3d8_cs
);
586 FIXME("(%p) call to IWineD3DDevice_CreateVertexBuffer failed\n", This
);
587 HeapFree(GetProcessHeap(), 0, object
);
588 *ppVertexBuffer
= NULL
;
590 IUnknown_AddRef(iface
);
591 object
->parentDevice
= iface
;
592 *ppVertexBuffer
= (LPDIRECT3DVERTEXBUFFER8
) object
;
597 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateIndexBuffer(LPDIRECT3DDEVICE8 iface
, UINT Length
, DWORD Usage
, D3DFORMAT Format
, D3DPOOL Pool
, IDirect3DIndexBuffer8
** ppIndexBuffer
) {
598 IDirect3DIndexBuffer8Impl
*object
;
599 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
600 HRESULT hrc
= D3D_OK
;
602 TRACE("(%p) Relay\n", This
);
603 /* Allocate the storage for the device */
604 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
605 if (NULL
== object
) {
606 FIXME("Allocation of memory failed\n");
607 *ppIndexBuffer
= NULL
;
608 return D3DERR_OUTOFVIDEOMEMORY
;
611 object
->lpVtbl
= &Direct3DIndexBuffer8_Vtbl
;
613 TRACE("Calling wined3d create index buffer\n");
614 EnterCriticalSection(&d3d8_cs
);
615 hrc
= IWineD3DDevice_CreateIndexBuffer(This
->WineD3DDevice
, Length
, Usage
& WINED3DUSAGE_MASK
, Format
, (WINED3DPOOL
) Pool
, &object
->wineD3DIndexBuffer
, NULL
, (IUnknown
*)object
);
616 LeaveCriticalSection(&d3d8_cs
);
621 FIXME("(%p) call to IWineD3DDevice_CreateIndexBuffer failed\n", This
);
622 HeapFree(GetProcessHeap(), 0, object
);
623 *ppIndexBuffer
= NULL
;
625 IUnknown_AddRef(iface
);
626 object
->parentDevice
= iface
;
627 *ppIndexBuffer
= (LPDIRECT3DINDEXBUFFER8
)object
;
632 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
) {
634 IDirect3DSurface8Impl
*object
;
635 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
636 TRACE("(%p) Relay\n", This
);
637 if(MultisampleQuality
< 0) {
638 FIXME("MultisampleQuality out of range %d, substituting 0\n", MultisampleQuality
);
639 /*FIXME: Find out what windows does with a MultisampleQuality < 0 */
640 MultisampleQuality
=0;
643 if(MultisampleQuality
> 0){
644 FIXME("MultisampleQuality set to %d, substituting 0\n" , MultisampleQuality
);
647 [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.
649 MultisampleQuality
=0;
651 /*FIXME: Check MAX bounds of MultisampleQuality*/
653 /* Allocate the storage for the device */
654 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirect3DSurface8Impl
));
655 if (NULL
== object
) {
656 FIXME("Allocation of memory failed\n");
658 return D3DERR_OUTOFVIDEOMEMORY
;
661 object
->lpVtbl
= &Direct3DSurface8_Vtbl
;
664 TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This
, Width
, Height
, Format
, *ppSurface
);
666 /* Not called from the VTable, no locking needed */
667 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
);
668 if (hrc
!= D3D_OK
|| NULL
== object
->wineD3DSurface
) {
670 FIXME("(%p) call to IWineD3DDevice_CreateSurface failed\n", This
);
671 HeapFree(GetProcessHeap(), 0, object
);
674 IUnknown_AddRef(iface
);
675 object
->parentDevice
= iface
;
676 *ppSurface
= (LPDIRECT3DSURFACE8
) object
;
681 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateRenderTarget(LPDIRECT3DDEVICE8 iface
, UINT Width
, UINT Height
, D3DFORMAT Format
, D3DMULTISAMPLE_TYPE MultiSample
, BOOL Lockable
, IDirect3DSurface8
** ppSurface
) {
685 EnterCriticalSection(&d3d8_cs
);
686 hr
= IDirect3DDevice8Impl_CreateSurface(iface
, Width
, Height
, Format
, Lockable
, FALSE
/* Discard */, 0 /* Level */ , ppSurface
, D3DRTYPE_SURFACE
, D3DUSAGE_RENDERTARGET
, D3DPOOL_DEFAULT
, MultiSample
, 0);
687 LeaveCriticalSection(&d3d8_cs
);
691 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE8 iface
, UINT Width
, UINT Height
, D3DFORMAT Format
, D3DMULTISAMPLE_TYPE MultiSample
, IDirect3DSurface8
** ppSurface
) {
695 /* TODO: Verify that Discard is false */
696 EnterCriticalSection(&d3d8_cs
);
697 hr
= IDirect3DDevice8Impl_CreateSurface(iface
, Width
, Height
, Format
, TRUE
/* Lockable */, FALSE
, 0 /* Level */
698 ,ppSurface
, D3DRTYPE_SURFACE
, D3DUSAGE_DEPTHSTENCIL
,
699 D3DPOOL_DEFAULT
, MultiSample
, 0);
700 LeaveCriticalSection(&d3d8_cs
);
704 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateImageSurface(LPDIRECT3DDEVICE8 iface
, UINT Width
, UINT Height
, D3DFORMAT Format
, IDirect3DSurface8
** ppSurface
) {
708 EnterCriticalSection(&d3d8_cs
);
709 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 */);
710 LeaveCriticalSection(&d3d8_cs
);
714 static HRESULT WINAPI
IDirect3DDevice8Impl_CopyRects(LPDIRECT3DDEVICE8 iface
, IDirect3DSurface8
*pSourceSurface
, CONST RECT
*pSourceRects
, UINT cRects
, IDirect3DSurface8
*pDestinationSurface
, CONST POINT
*pDestPoints
) {
715 IDirect3DSurface8Impl
*Source
= (IDirect3DSurface8Impl
*) pSourceSurface
;
716 IDirect3DSurface8Impl
*Dest
= (IDirect3DSurface8Impl
*) pDestinationSurface
;
718 HRESULT hr
= WINED3D_OK
;
719 WINED3DFORMAT srcFormat
, destFormat
;
720 UINT srcWidth
, destWidth
;
721 UINT srcHeight
, destHeight
;
723 WINED3DSURFACE_DESC winedesc
;
725 TRACE("(%p) pSrcSur=%p, pSourceRects=%p, cRects=%d, pDstSur=%p, pDestPtsArr=%p\n", iface
,
726 pSourceSurface
, pSourceRects
, cRects
, pDestinationSurface
, pDestPoints
);
729 /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the destination texture is in WINED3DPOOL_DEFAULT */
730 memset(&winedesc
, 0, sizeof(winedesc
));
732 winedesc
.Format
= &srcFormat
;
733 winedesc
.Width
= &srcWidth
;
734 winedesc
.Height
= &srcHeight
;
735 winedesc
.Size
= &srcSize
;
736 IWineD3DSurface_GetDesc(Source
->wineD3DSurface
, &winedesc
);
738 winedesc
.Format
= &destFormat
;
739 winedesc
.Width
= &destWidth
;
740 winedesc
.Height
= &destHeight
;
741 winedesc
.Size
= NULL
;
742 EnterCriticalSection(&d3d8_cs
);
743 IWineD3DSurface_GetDesc(Dest
->wineD3DSurface
, &winedesc
);
745 /* Check that the source and destination formats match */
746 if (srcFormat
!= destFormat
&& WINED3DFMT_UNKNOWN
!= destFormat
) {
747 WARN("(%p) source %p format must match the dest %p format, returning WINED3DERR_INVALIDCALL\n", iface
, pSourceSurface
, pDestinationSurface
);
748 LeaveCriticalSection(&d3d8_cs
);
749 return WINED3DERR_INVALIDCALL
;
750 } else if (WINED3DFMT_UNKNOWN
== destFormat
) {
751 TRACE("(%p) : Converting destination surface from WINED3DFMT_UNKNOWN to the source format\n", iface
);
752 IWineD3DSurface_SetFormat(Dest
->wineD3DSurface
, srcFormat
);
753 destFormat
= srcFormat
;
756 /* Quick if complete copy ... */
757 if (cRects
== 0 && pSourceRects
== NULL
&& pDestPoints
== NULL
) {
758 IWineD3DSurface_BltFast(Dest
->wineD3DSurface
, 0, 0, Source
->wineD3DSurface
, NULL
, WINEDDBLTFAST_NOCOLORKEY
);
761 /* Copy rect by rect */
762 if (NULL
!= pSourceRects
&& NULL
!= pDestPoints
) {
763 for (i
= 0; i
< cRects
; ++i
) {
764 IWineD3DSurface_BltFast(Dest
->wineD3DSurface
, pDestPoints
[i
].x
, pDestPoints
[i
].y
, Source
->wineD3DSurface
, (RECT
*) &pSourceRects
[i
], WINEDDBLTFAST_NOCOLORKEY
);
767 for (i
= 0; i
< cRects
; ++i
) {
768 IWineD3DSurface_BltFast(Dest
->wineD3DSurface
, 0, 0, Source
->wineD3DSurface
, (RECT
*) &pSourceRects
[i
], WINEDDBLTFAST_NOCOLORKEY
);
772 LeaveCriticalSection(&d3d8_cs
);
777 static HRESULT WINAPI
IDirect3DDevice8Impl_UpdateTexture(LPDIRECT3DDEVICE8 iface
, IDirect3DBaseTexture8
* pSourceTexture
, IDirect3DBaseTexture8
* pDestinationTexture
) {
778 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
780 TRACE("(%p) Relay\n" , This
);
782 EnterCriticalSection(&d3d8_cs
);
783 hr
= IWineD3DDevice_UpdateTexture(This
->WineD3DDevice
, ((IDirect3DBaseTexture8Impl
*)pSourceTexture
)->wineD3DBaseTexture
, ((IDirect3DBaseTexture8Impl
*)pDestinationTexture
)->wineD3DBaseTexture
);
784 LeaveCriticalSection(&d3d8_cs
);
788 static HRESULT WINAPI
IDirect3DDevice8Impl_GetFrontBuffer(LPDIRECT3DDEVICE8 iface
, IDirect3DSurface8
* pDestSurface
) {
789 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
790 IDirect3DSurface8Impl
*destSurface
= (IDirect3DSurface8Impl
*)pDestSurface
;
793 TRACE("(%p) Relay\n" , This
);
795 if (pDestSurface
== NULL
) {
796 WARN("(%p) : Caller passed NULL as pDestSurface returning D3DERR_INVALIDCALL\n", This
);
797 return D3DERR_INVALIDCALL
;
800 EnterCriticalSection(&d3d8_cs
);
801 hr
= IWineD3DDevice_GetFrontBufferData(This
->WineD3DDevice
, 0, destSurface
->wineD3DSurface
);
802 LeaveCriticalSection(&d3d8_cs
);
806 static HRESULT WINAPI
IDirect3DDevice8Impl_SetRenderTarget(LPDIRECT3DDEVICE8 iface
, IDirect3DSurface8
* pRenderTarget
, IDirect3DSurface8
* pNewZStencil
) {
807 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
808 IDirect3DSurface8Impl
*pSurface
= (IDirect3DSurface8Impl
*)pRenderTarget
;
809 IDirect3DSurface8Impl
*pZSurface
= (IDirect3DSurface8Impl
*)pNewZStencil
;
811 TRACE("(%p) Relay\n" , This
);
813 IWineD3DDevice_SetDepthStencilSurface(This
->WineD3DDevice
, NULL
== pZSurface
? NULL
: (IWineD3DSurface
*)pZSurface
->wineD3DSurface
);
815 EnterCriticalSection(&d3d8_cs
);
816 hr
= IWineD3DDevice_SetRenderTarget(This
->WineD3DDevice
, 0, pSurface
? (IWineD3DSurface
*)pSurface
->wineD3DSurface
: NULL
);
817 LeaveCriticalSection(&d3d8_cs
);
821 static HRESULT WINAPI
IDirect3DDevice8Impl_GetRenderTarget(LPDIRECT3DDEVICE8 iface
, IDirect3DSurface8
** ppRenderTarget
) {
822 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
824 IWineD3DSurface
*pRenderTarget
;
826 TRACE("(%p) Relay\n" , This
);
828 if (ppRenderTarget
== NULL
) {
829 return D3DERR_INVALIDCALL
;
831 EnterCriticalSection(&d3d8_cs
);
832 hr
= IWineD3DDevice_GetRenderTarget(This
->WineD3DDevice
, 0, &pRenderTarget
);
834 if (hr
== D3D_OK
&& pRenderTarget
!= NULL
) {
835 IWineD3DSurface_GetParent(pRenderTarget
,(IUnknown
**)ppRenderTarget
);
836 IWineD3DSurface_Release(pRenderTarget
);
838 FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
839 *ppRenderTarget
= NULL
;
841 LeaveCriticalSection(&d3d8_cs
);
846 static HRESULT WINAPI
IDirect3DDevice8Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE8 iface
, IDirect3DSurface8
** ppZStencilSurface
) {
847 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
849 IWineD3DSurface
*pZStencilSurface
;
851 TRACE("(%p) Relay\n" , This
);
852 if(ppZStencilSurface
== NULL
){
853 return D3DERR_INVALIDCALL
;
856 EnterCriticalSection(&d3d8_cs
);
857 hr
=IWineD3DDevice_GetDepthStencilSurface(This
->WineD3DDevice
,&pZStencilSurface
);
858 if(hr
== D3D_OK
&& pZStencilSurface
!= NULL
){
859 IWineD3DSurface_GetParent(pZStencilSurface
,(IUnknown
**)ppZStencilSurface
);
860 IWineD3DSurface_Release(pZStencilSurface
);
862 FIXME("Call to IWineD3DDevice_GetDepthStencilSurface failed\n");
863 *ppZStencilSurface
= NULL
;
865 LeaveCriticalSection(&d3d8_cs
);
870 static HRESULT WINAPI
IDirect3DDevice8Impl_BeginScene(LPDIRECT3DDEVICE8 iface
) {
871 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
873 TRACE("(%p) Relay\n" , This
);
875 EnterCriticalSection(&d3d8_cs
);
876 hr
= IWineD3DDevice_BeginScene(This
->WineD3DDevice
);
877 LeaveCriticalSection(&d3d8_cs
);
881 static HRESULT WINAPI
IDirect3DDevice8Impl_EndScene(LPDIRECT3DDEVICE8 iface
) {
882 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
884 TRACE("(%p) Relay\n" , This
);
886 EnterCriticalSection(&d3d8_cs
);
887 hr
= IWineD3DDevice_EndScene(This
->WineD3DDevice
);
888 LeaveCriticalSection(&d3d8_cs
);
892 static HRESULT WINAPI
IDirect3DDevice8Impl_Clear(LPDIRECT3DDEVICE8 iface
, DWORD Count
, CONST D3DRECT
* pRects
, DWORD Flags
, D3DCOLOR Color
, float Z
, DWORD Stencil
) {
893 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
895 TRACE("(%p) Relay\n" , This
);
897 /* Note: D3DRECT is compatible with WINED3DRECT */
898 EnterCriticalSection(&d3d8_cs
);
899 hr
= IWineD3DDevice_Clear(This
->WineD3DDevice
, Count
, (CONST WINED3DRECT
*) pRects
, Flags
, Color
, Z
, Stencil
);
900 LeaveCriticalSection(&d3d8_cs
);
904 static HRESULT WINAPI
IDirect3DDevice8Impl_SetTransform(LPDIRECT3DDEVICE8 iface
, D3DTRANSFORMSTATETYPE State
, CONST D3DMATRIX
* lpMatrix
) {
905 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
907 TRACE("(%p) Relay\n" , This
);
909 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
910 EnterCriticalSection(&d3d8_cs
);
911 hr
= IWineD3DDevice_SetTransform(This
->WineD3DDevice
, State
, (CONST WINED3DMATRIX
*) lpMatrix
);
912 LeaveCriticalSection(&d3d8_cs
);
916 static HRESULT WINAPI
IDirect3DDevice8Impl_GetTransform(LPDIRECT3DDEVICE8 iface
, D3DTRANSFORMSTATETYPE State
,D3DMATRIX
* pMatrix
) {
917 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
919 TRACE("(%p) Relay\n" , This
);
921 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
922 EnterCriticalSection(&d3d8_cs
);
923 hr
= IWineD3DDevice_GetTransform(This
->WineD3DDevice
, State
, (WINED3DMATRIX
*) pMatrix
);
924 LeaveCriticalSection(&d3d8_cs
);
928 static HRESULT WINAPI
IDirect3DDevice8Impl_MultiplyTransform(LPDIRECT3DDEVICE8 iface
, D3DTRANSFORMSTATETYPE State
, CONST D3DMATRIX
* pMatrix
) {
929 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
931 TRACE("(%p) Relay\n" , This
);
933 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
934 EnterCriticalSection(&d3d8_cs
);
935 hr
= IWineD3DDevice_MultiplyTransform(This
->WineD3DDevice
, State
, (CONST WINED3DMATRIX
*) pMatrix
);
936 LeaveCriticalSection(&d3d8_cs
);
940 static HRESULT WINAPI
IDirect3DDevice8Impl_SetViewport(LPDIRECT3DDEVICE8 iface
, CONST D3DVIEWPORT8
* pViewport
) {
941 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
943 TRACE("(%p) Relay\n" , This
);
945 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
946 EnterCriticalSection(&d3d8_cs
);
947 hr
= IWineD3DDevice_SetViewport(This
->WineD3DDevice
, (const WINED3DVIEWPORT
*)pViewport
);
948 LeaveCriticalSection(&d3d8_cs
);
952 static HRESULT WINAPI
IDirect3DDevice8Impl_GetViewport(LPDIRECT3DDEVICE8 iface
, D3DVIEWPORT8
* pViewport
) {
953 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
955 TRACE("(%p) Relay\n" , This
);
957 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
958 EnterCriticalSection(&d3d8_cs
);
959 hr
= IWineD3DDevice_GetViewport(This
->WineD3DDevice
, (WINED3DVIEWPORT
*)pViewport
);
960 LeaveCriticalSection(&d3d8_cs
);
964 static HRESULT WINAPI
IDirect3DDevice8Impl_SetMaterial(LPDIRECT3DDEVICE8 iface
, CONST D3DMATERIAL8
* pMaterial
) {
965 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
967 TRACE("(%p) Relay\n" , This
);
969 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
970 EnterCriticalSection(&d3d8_cs
);
971 hr
= IWineD3DDevice_SetMaterial(This
->WineD3DDevice
, (const WINED3DMATERIAL
*)pMaterial
);
972 LeaveCriticalSection(&d3d8_cs
);
976 static HRESULT WINAPI
IDirect3DDevice8Impl_GetMaterial(LPDIRECT3DDEVICE8 iface
, D3DMATERIAL8
* pMaterial
) {
977 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
979 TRACE("(%p) Relay\n" , This
);
981 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
982 EnterCriticalSection(&d3d8_cs
);
983 hr
= IWineD3DDevice_GetMaterial(This
->WineD3DDevice
, (WINED3DMATERIAL
*)pMaterial
);
984 LeaveCriticalSection(&d3d8_cs
);
988 static HRESULT WINAPI
IDirect3DDevice8Impl_SetLight(LPDIRECT3DDEVICE8 iface
, DWORD Index
, CONST D3DLIGHT8
* pLight
) {
989 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
991 TRACE("(%p) Relay\n" , This
);
993 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
994 EnterCriticalSection(&d3d8_cs
);
995 hr
= IWineD3DDevice_SetLight(This
->WineD3DDevice
, Index
, (const WINED3DLIGHT
*)pLight
);
996 LeaveCriticalSection(&d3d8_cs
);
1000 static HRESULT WINAPI
IDirect3DDevice8Impl_GetLight(LPDIRECT3DDEVICE8 iface
, DWORD Index
,D3DLIGHT8
* pLight
) {
1001 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1003 TRACE("(%p) Relay\n" , This
);
1005 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1006 EnterCriticalSection(&d3d8_cs
);
1007 hr
= IWineD3DDevice_GetLight(This
->WineD3DDevice
, Index
, (WINED3DLIGHT
*)pLight
);
1008 LeaveCriticalSection(&d3d8_cs
);
1012 static HRESULT WINAPI
IDirect3DDevice8Impl_LightEnable(LPDIRECT3DDEVICE8 iface
, DWORD Index
,BOOL Enable
) {
1013 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1015 TRACE("(%p) Relay\n" , This
);
1017 EnterCriticalSection(&d3d8_cs
);
1018 hr
= IWineD3DDevice_SetLightEnable(This
->WineD3DDevice
, Index
, Enable
);
1019 LeaveCriticalSection(&d3d8_cs
);
1023 static HRESULT WINAPI
IDirect3DDevice8Impl_GetLightEnable(LPDIRECT3DDEVICE8 iface
, DWORD Index
,BOOL
* pEnable
) {
1024 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1026 TRACE("(%p) Relay\n" , This
);
1028 EnterCriticalSection(&d3d8_cs
);
1029 hr
= IWineD3DDevice_GetLightEnable(This
->WineD3DDevice
, Index
, pEnable
);
1030 LeaveCriticalSection(&d3d8_cs
);
1034 static HRESULT WINAPI
IDirect3DDevice8Impl_SetClipPlane(LPDIRECT3DDEVICE8 iface
, DWORD Index
,CONST
float* pPlane
) {
1035 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1037 TRACE("(%p) Relay\n" , This
);
1039 EnterCriticalSection(&d3d8_cs
);
1040 hr
= IWineD3DDevice_SetClipPlane(This
->WineD3DDevice
, Index
, pPlane
);
1041 LeaveCriticalSection(&d3d8_cs
);
1045 static HRESULT WINAPI
IDirect3DDevice8Impl_GetClipPlane(LPDIRECT3DDEVICE8 iface
, DWORD Index
,float* pPlane
) {
1046 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1048 TRACE("(%p) Relay\n" , This
);
1050 EnterCriticalSection(&d3d8_cs
);
1051 hr
= IWineD3DDevice_GetClipPlane(This
->WineD3DDevice
, Index
, pPlane
);
1052 LeaveCriticalSection(&d3d8_cs
);
1056 static HRESULT WINAPI
IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface
, D3DRENDERSTATETYPE State
,DWORD Value
) {
1057 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1059 TRACE("(%p) Relay\n" , This
);
1061 EnterCriticalSection(&d3d8_cs
);
1062 hr
= IWineD3DDevice_SetRenderState(This
->WineD3DDevice
, State
, Value
);
1063 LeaveCriticalSection(&d3d8_cs
);
1067 static HRESULT WINAPI
IDirect3DDevice8Impl_GetRenderState(LPDIRECT3DDEVICE8 iface
, D3DRENDERSTATETYPE State
,DWORD
* pValue
) {
1068 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1070 TRACE("(%p) Relay\n" , This
);
1072 EnterCriticalSection(&d3d8_cs
);
1073 hr
= IWineD3DDevice_GetRenderState(This
->WineD3DDevice
, State
, pValue
);
1074 LeaveCriticalSection(&d3d8_cs
);
1078 static HRESULT WINAPI
IDirect3DDevice8Impl_BeginStateBlock(LPDIRECT3DDEVICE8 iface
) {
1079 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1081 TRACE("(%p)\n", This
);
1083 EnterCriticalSection(&d3d8_cs
);
1084 hr
= IWineD3DDevice_BeginStateBlock(This
->WineD3DDevice
);
1085 LeaveCriticalSection(&d3d8_cs
);
1089 static HRESULT WINAPI
IDirect3DDevice8Impl_EndStateBlock(LPDIRECT3DDEVICE8 iface
, DWORD
* pToken
) {
1090 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1092 IWineD3DStateBlock
* wineD3DStateBlock
;
1093 IDirect3DStateBlock8Impl
* object
;
1095 TRACE("(%p) Relay\n", This
);
1097 /* Tell wineD3D to endstatablock before anything else (in case we run out
1098 * of memory later and cause locking problems)
1100 EnterCriticalSection(&d3d8_cs
);
1101 hr
= IWineD3DDevice_EndStateBlock(This
->WineD3DDevice
, &wineD3DStateBlock
);
1103 FIXME("IWineD3DDevice_EndStateBlock returned an error\n");
1104 LeaveCriticalSection(&d3d8_cs
);
1108 /* allocate a new IDirectD3DStateBlock */
1109 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,sizeof(IDirect3DStateBlock8Impl
));
1111 object
->lpVtbl
= &Direct3DStateBlock8_Vtbl
;
1113 object
->wineD3DStateBlock
= wineD3DStateBlock
;
1115 *pToken
= (DWORD
)object
;
1116 TRACE("(%p)Returning %p %p\n", This
, object
, wineD3DStateBlock
);
1118 LeaveCriticalSection(&d3d8_cs
);
1122 static HRESULT WINAPI
IDirect3DDevice8Impl_ApplyStateBlock(LPDIRECT3DDEVICE8 iface
, DWORD Token
) {
1123 IDirect3DStateBlock8Impl
*pSB
= (IDirect3DStateBlock8Impl
*) Token
;
1124 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1127 TRACE("(%p) %p Relay\n", This
, pSB
);
1129 EnterCriticalSection(&d3d8_cs
);
1130 hr
= IWineD3DStateBlock_Apply(pSB
->wineD3DStateBlock
);
1131 LeaveCriticalSection(&d3d8_cs
);
1135 static HRESULT WINAPI
IDirect3DDevice8Impl_CaptureStateBlock(LPDIRECT3DDEVICE8 iface
, DWORD Token
) {
1136 IDirect3DStateBlock8Impl
* pSB
= (IDirect3DStateBlock8Impl
*)Token
;
1137 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1140 TRACE("(%p) %p Relay\n", This
, pSB
);
1142 EnterCriticalSection(&d3d8_cs
);
1143 hr
= IWineD3DStateBlock_Capture(pSB
->wineD3DStateBlock
);
1144 LeaveCriticalSection(&d3d8_cs
);
1148 static HRESULT WINAPI
IDirect3DDevice8Impl_DeleteStateBlock(LPDIRECT3DDEVICE8 iface
, DWORD Token
) {
1149 IDirect3DStateBlock8Impl
* pSB
= (IDirect3DStateBlock8Impl
*)Token
;
1150 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1152 TRACE("(%p) Relay\n", This
);
1154 EnterCriticalSection(&d3d8_cs
);
1155 while(IUnknown_Release((IUnknown
*)pSB
));
1156 LeaveCriticalSection(&d3d8_cs
);
1161 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateStateBlock(LPDIRECT3DDEVICE8 iface
, D3DSTATEBLOCKTYPE Type
, DWORD
* pToken
) {
1162 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1163 IDirect3DStateBlock8Impl
*object
;
1164 HRESULT hrc
= D3D_OK
;
1166 TRACE("(%p) Relay\n", This
);
1168 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirect3DStateBlock8Impl
));
1169 if (NULL
== object
) {
1171 return E_OUTOFMEMORY
;
1173 object
->lpVtbl
= &Direct3DStateBlock8_Vtbl
;
1176 EnterCriticalSection(&d3d8_cs
);
1177 hrc
= IWineD3DDevice_CreateStateBlock(This
->WineD3DDevice
, (WINED3DSTATEBLOCKTYPE
)Type
, &object
->wineD3DStateBlock
, (IUnknown
*)object
);
1178 LeaveCriticalSection(&d3d8_cs
);
1180 FIXME("(%p) Call to IWineD3DDevice_CreateStateBlock failed.\n", This
);
1181 HeapFree(GetProcessHeap(), 0, object
);
1184 *pToken
= (DWORD
)object
;
1186 TRACE("(%p) returning token (ptr to stateblock) of %p\n", This
, object
);
1191 static HRESULT WINAPI
IDirect3DDevice8Impl_SetClipStatus(LPDIRECT3DDEVICE8 iface
, CONST D3DCLIPSTATUS8
* pClipStatus
) {
1192 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1194 TRACE("(%p) Relay\n" , This
);
1195 /* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
1196 EnterCriticalSection(&d3d8_cs
);
1197 hr
= IWineD3DDevice_SetClipStatus(This
->WineD3DDevice
, (const WINED3DCLIPSTATUS
*)pClipStatus
);
1198 LeaveCriticalSection(&d3d8_cs
);
1202 static HRESULT WINAPI
IDirect3DDevice8Impl_GetClipStatus(LPDIRECT3DDEVICE8 iface
, D3DCLIPSTATUS8
* pClipStatus
) {
1203 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1205 TRACE("(%p) Relay\n" , This
);
1207 EnterCriticalSection(&d3d8_cs
);
1208 hr
= IWineD3DDevice_GetClipStatus(This
->WineD3DDevice
, (WINED3DCLIPSTATUS
*)pClipStatus
);
1209 LeaveCriticalSection(&d3d8_cs
);
1213 static HRESULT WINAPI
IDirect3DDevice8Impl_GetTexture(LPDIRECT3DDEVICE8 iface
, DWORD Stage
,IDirect3DBaseTexture8
** ppTexture
) {
1214 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1215 IWineD3DBaseTexture
*retTexture
= NULL
;
1216 HRESULT rc
= D3D_OK
;
1218 TRACE("(%p) Relay\n" , This
);
1220 if(ppTexture
== NULL
){
1221 return D3DERR_INVALIDCALL
;
1224 EnterCriticalSection(&d3d8_cs
);
1225 rc
= IWineD3DDevice_GetTexture(This
->WineD3DDevice
, Stage
, (IWineD3DBaseTexture
**)&retTexture
);
1226 if (rc
== D3D_OK
&& NULL
!= retTexture
) {
1227 IWineD3DBaseTexture_GetParent(retTexture
, (IUnknown
**)ppTexture
);
1228 IWineD3DBaseTexture_Release(retTexture
);
1230 FIXME("Call to get texture (%d) failed (%p)\n", Stage
, retTexture
);
1233 LeaveCriticalSection(&d3d8_cs
);
1238 static HRESULT WINAPI
IDirect3DDevice8Impl_SetTexture(LPDIRECT3DDEVICE8 iface
, DWORD Stage
, IDirect3DBaseTexture8
* pTexture
) {
1239 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1241 TRACE("(%p) Relay %d %p\n" , This
, Stage
, pTexture
);
1243 EnterCriticalSection(&d3d8_cs
);
1244 hr
= IWineD3DDevice_SetTexture(This
->WineD3DDevice
, Stage
,
1245 pTexture
==NULL
? NULL
: ((IDirect3DBaseTexture8Impl
*)pTexture
)->wineD3DBaseTexture
);
1246 LeaveCriticalSection(&d3d8_cs
);
1250 static HRESULT WINAPI
IDirect3DDevice8Impl_GetTextureStageState(LPDIRECT3DDEVICE8 iface
, DWORD Stage
,D3DTEXTURESTAGESTATETYPE Type
,DWORD
* pValue
) {
1251 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1253 TRACE("(%p) Relay\n" , This
);
1256 case D3DTSS_ADDRESSU
:
1257 Type
= WINED3DSAMP_ADDRESSU
;
1259 case D3DTSS_ADDRESSV
:
1260 Type
= WINED3DSAMP_ADDRESSV
;
1262 case D3DTSS_ADDRESSW
:
1263 Type
= WINED3DSAMP_ADDRESSW
;
1265 case D3DTSS_BORDERCOLOR
:
1266 Type
= WINED3DSAMP_BORDERCOLOR
;
1268 case D3DTSS_MAGFILTER
:
1269 Type
= WINED3DSAMP_MAGFILTER
;
1271 case D3DTSS_MAXANISOTROPY
:
1272 Type
= WINED3DSAMP_MAXANISOTROPY
;
1274 case D3DTSS_MAXMIPLEVEL
:
1275 Type
= WINED3DSAMP_MAXMIPLEVEL
;
1277 case D3DTSS_MINFILTER
:
1278 Type
= WINED3DSAMP_MINFILTER
;
1280 case D3DTSS_MIPFILTER
:
1281 Type
= WINED3DSAMP_MIPFILTER
;
1283 case D3DTSS_MIPMAPLODBIAS
:
1284 Type
= WINED3DSAMP_MIPMAPLODBIAS
;
1287 EnterCriticalSection(&d3d8_cs
);
1288 hr
= IWineD3DDevice_GetTextureStageState(This
->WineD3DDevice
, Stage
, Type
, pValue
);
1289 LeaveCriticalSection(&d3d8_cs
);
1293 EnterCriticalSection(&d3d8_cs
);
1294 hr
= IWineD3DDevice_GetSamplerState(This
->WineD3DDevice
, Stage
, Type
, pValue
);
1295 LeaveCriticalSection(&d3d8_cs
);
1299 static HRESULT WINAPI
IDirect3DDevice8Impl_SetTextureStageState(LPDIRECT3DDEVICE8 iface
, DWORD Stage
, D3DTEXTURESTAGESTATETYPE Type
, DWORD Value
) {
1300 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1302 TRACE("(%p) Relay\n" , This
);
1305 case D3DTSS_ADDRESSU
:
1306 Type
= WINED3DSAMP_ADDRESSU
;
1308 case D3DTSS_ADDRESSV
:
1309 Type
= WINED3DSAMP_ADDRESSV
;
1311 case D3DTSS_ADDRESSW
:
1312 Type
= WINED3DSAMP_ADDRESSW
;
1314 case D3DTSS_BORDERCOLOR
:
1315 Type
= WINED3DSAMP_BORDERCOLOR
;
1317 case D3DTSS_MAGFILTER
:
1318 Type
= WINED3DSAMP_MAGFILTER
;
1320 case D3DTSS_MAXANISOTROPY
:
1321 Type
= WINED3DSAMP_MAXANISOTROPY
;
1323 case D3DTSS_MAXMIPLEVEL
:
1324 Type
= WINED3DSAMP_MAXMIPLEVEL
;
1326 case D3DTSS_MINFILTER
:
1327 Type
= WINED3DSAMP_MINFILTER
;
1329 case D3DTSS_MIPFILTER
:
1330 Type
= WINED3DSAMP_MIPFILTER
;
1332 case D3DTSS_MIPMAPLODBIAS
:
1333 Type
= WINED3DSAMP_MIPMAPLODBIAS
;
1336 EnterCriticalSection(&d3d8_cs
);
1337 hr
= IWineD3DDevice_SetTextureStageState(This
->WineD3DDevice
, Stage
, Type
, Value
);
1338 LeaveCriticalSection(&d3d8_cs
);
1342 EnterCriticalSection(&d3d8_cs
);
1343 hr
= IWineD3DDevice_SetSamplerState(This
->WineD3DDevice
, Stage
, Type
, Value
);
1344 LeaveCriticalSection(&d3d8_cs
);
1348 static HRESULT WINAPI
IDirect3DDevice8Impl_ValidateDevice(LPDIRECT3DDEVICE8 iface
, DWORD
* pNumPasses
) {
1349 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1351 TRACE("(%p) Relay\n" , This
);
1353 EnterCriticalSection(&d3d8_cs
);
1354 hr
= IWineD3DDevice_ValidateDevice(This
->WineD3DDevice
, pNumPasses
);
1355 LeaveCriticalSection(&d3d8_cs
);
1359 static HRESULT WINAPI
IDirect3DDevice8Impl_GetInfo(LPDIRECT3DDEVICE8 iface
, DWORD DevInfoID
, void* pDevInfoStruct
, DWORD DevInfoStructSize
) {
1360 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1361 FIXME("(%p) : stub\n", This
);
1365 static HRESULT WINAPI
IDirect3DDevice8Impl_SetPaletteEntries(LPDIRECT3DDEVICE8 iface
, UINT PaletteNumber
, CONST PALETTEENTRY
* pEntries
) {
1366 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1368 TRACE("(%p) Relay\n" , This
);
1370 EnterCriticalSection(&d3d8_cs
);
1371 hr
= IWineD3DDevice_SetPaletteEntries(This
->WineD3DDevice
, PaletteNumber
, pEntries
);
1372 LeaveCriticalSection(&d3d8_cs
);
1376 static HRESULT WINAPI
IDirect3DDevice8Impl_GetPaletteEntries(LPDIRECT3DDEVICE8 iface
, UINT PaletteNumber
, PALETTEENTRY
* pEntries
) {
1377 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1379 TRACE("(%p) Relay\n" , This
);
1381 EnterCriticalSection(&d3d8_cs
);
1382 hr
= IWineD3DDevice_GetPaletteEntries(This
->WineD3DDevice
, PaletteNumber
, pEntries
);
1383 LeaveCriticalSection(&d3d8_cs
);
1387 static HRESULT WINAPI
IDirect3DDevice8Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface
, UINT PaletteNumber
) {
1388 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1390 TRACE("(%p) Relay\n" , This
);
1392 EnterCriticalSection(&d3d8_cs
);
1393 hr
= IWineD3DDevice_SetCurrentTexturePalette(This
->WineD3DDevice
, PaletteNumber
);
1394 LeaveCriticalSection(&d3d8_cs
);
1398 static HRESULT WINAPI
IDirect3DDevice8Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface
, UINT
*PaletteNumber
) {
1399 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1401 TRACE("(%p) Relay\n" , This
);
1403 EnterCriticalSection(&d3d8_cs
);
1404 hr
= IWineD3DDevice_GetCurrentTexturePalette(This
->WineD3DDevice
, PaletteNumber
);
1405 LeaveCriticalSection(&d3d8_cs
);
1409 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawPrimitive(LPDIRECT3DDEVICE8 iface
, D3DPRIMITIVETYPE PrimitiveType
, UINT StartVertex
, UINT PrimitiveCount
) {
1410 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1412 TRACE("(%p) Relay\n" , This
);
1414 EnterCriticalSection(&d3d8_cs
);
1415 hr
= IWineD3DDevice_DrawPrimitive(This
->WineD3DDevice
, PrimitiveType
, StartVertex
, PrimitiveCount
);
1416 LeaveCriticalSection(&d3d8_cs
);
1420 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE8 iface
, D3DPRIMITIVETYPE PrimitiveType
,
1421 UINT MinVertexIndex
,UINT NumVertices
,UINT startIndex
,UINT primCount
) {
1422 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1424 TRACE("(%p) Relay\n" , This
);
1426 EnterCriticalSection(&d3d8_cs
);
1427 hr
= IWineD3DDevice_DrawIndexedPrimitive(This
->WineD3DDevice
, PrimitiveType
, MinVertexIndex
, NumVertices
, startIndex
, primCount
);
1428 LeaveCriticalSection(&d3d8_cs
);
1432 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE8 iface
, D3DPRIMITIVETYPE PrimitiveType
,UINT PrimitiveCount
,CONST
void* pVertexStreamZeroData
,UINT VertexStreamZeroStride
) {
1433 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1435 TRACE("(%p) Relay\n" , This
);
1437 EnterCriticalSection(&d3d8_cs
);
1438 hr
= IWineD3DDevice_DrawPrimitiveUP(This
->WineD3DDevice
, PrimitiveType
, PrimitiveCount
, pVertexStreamZeroData
, VertexStreamZeroStride
);
1439 LeaveCriticalSection(&d3d8_cs
);
1443 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE8 iface
, D3DPRIMITIVETYPE PrimitiveType
,UINT MinVertexIndex
,
1444 UINT NumVertexIndices
,UINT PrimitiveCount
,CONST
void* pIndexData
,
1445 D3DFORMAT IndexDataFormat
,CONST
void* pVertexStreamZeroData
,
1446 UINT VertexStreamZeroStride
) {
1447 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1449 TRACE("(%p) Relay\n" , This
);
1451 EnterCriticalSection(&d3d8_cs
);
1452 hr
= IWineD3DDevice_DrawIndexedPrimitiveUP(This
->WineD3DDevice
, PrimitiveType
, MinVertexIndex
, NumVertexIndices
, PrimitiveCount
,
1453 pIndexData
, IndexDataFormat
, pVertexStreamZeroData
, VertexStreamZeroStride
);
1454 LeaveCriticalSection(&d3d8_cs
);
1458 static HRESULT WINAPI
IDirect3DDevice8Impl_ProcessVertices(LPDIRECT3DDEVICE8 iface
, UINT SrcStartIndex
,UINT DestIndex
,UINT VertexCount
,IDirect3DVertexBuffer8
* pDestBuffer
,DWORD Flags
) {
1459 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1461 TRACE("(%p) Relay\n" , This
);
1463 EnterCriticalSection(&d3d8_cs
);
1464 hr
= IWineD3DDevice_ProcessVertices(This
->WineD3DDevice
,SrcStartIndex
, DestIndex
, VertexCount
, ((IDirect3DVertexBuffer8Impl
*)pDestBuffer
)->wineD3DVertexBuffer
, NULL
, Flags
);
1465 LeaveCriticalSection(&d3d8_cs
);
1469 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateVertexDeclaration(IDirect3DDevice8
*iface
, CONST DWORD
*declaration
, IDirect3DVertexDeclaration8
**decl_ptr
) {
1470 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1471 IDirect3DVertexDeclaration8Impl
*object
;
1472 WINED3DVERTEXELEMENT
*wined3d_elements
;
1473 size_t wined3d_element_count
;
1474 HRESULT hr
= D3D_OK
;
1476 TRACE("(%p) : declaration %p\n", This
, declaration
);
1478 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1480 ERR("Memory allocation failed\n");
1482 return D3DERR_OUTOFVIDEOMEMORY
;
1485 object
->ref_count
= 1;
1486 object
->lpVtbl
= &Direct3DVertexDeclaration8_Vtbl
;
1488 wined3d_element_count
= convert_to_wined3d_declaration(declaration
, &object
->elements_size
, &wined3d_elements
);
1489 object
->elements
= HeapAlloc(GetProcessHeap(), 0, object
->elements_size
);
1490 if (!object
->elements
) {
1491 ERR("Memory allocation failed\n");
1492 HeapFree(GetProcessHeap(), 0, wined3d_elements
);
1493 HeapFree(GetProcessHeap(), 0, object
);
1495 return D3DERR_OUTOFVIDEOMEMORY
;
1498 CopyMemory(object
->elements
, declaration
, object
->elements_size
);
1500 EnterCriticalSection(&d3d8_cs
);
1501 hr
= IWineD3DDevice_CreateVertexDeclaration(This
->WineD3DDevice
, &object
->wined3d_vertex_declaration
,
1502 (IUnknown
*)object
, wined3d_elements
, wined3d_element_count
);
1503 LeaveCriticalSection(&d3d8_cs
);
1504 HeapFree(GetProcessHeap(), 0, wined3d_elements
);
1507 ERR("(%p) : IWineD3DDevice_CreateVertexDeclaration call failed\n", This
);
1508 HeapFree(GetProcessHeap(), 0, object
->elements
);
1509 HeapFree(GetProcessHeap(), 0, object
);
1511 *decl_ptr
= (IDirect3DVertexDeclaration8
*)object
;
1512 TRACE("(%p) : Created vertex declaration %p\n", This
, object
);
1518 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateVertexShader(LPDIRECT3DDEVICE8 iface
, CONST DWORD
* pDeclaration
, CONST DWORD
* pFunction
, DWORD
* ppShader
, DWORD Usage
) {
1519 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1520 HRESULT hrc
= D3D_OK
;
1521 IDirect3DVertexShader8Impl
*object
;
1522 IWineD3DVertexDeclaration
*wined3d_vertex_declaration
;
1524 /* Setup a stub object for now */
1525 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1526 TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This
, pFunction
, ppShader
);
1527 if (NULL
== object
) {
1528 FIXME("Allocation of memory failed\n");
1530 return D3DERR_OUTOFVIDEOMEMORY
;
1534 object
->lpVtbl
= &Direct3DVertexShader8_Vtbl
;
1536 EnterCriticalSection(&d3d8_cs
);
1537 hrc
= IDirect3DDevice8Impl_CreateVertexDeclaration(iface
, pDeclaration
, &object
->vertex_declaration
);
1539 ERR("(%p) : IDirect3DDeviceImpl_CreateVertexDeclaration call failed\n", This
);
1540 LeaveCriticalSection(&d3d8_cs
);
1541 HeapFree(GetProcessHeap(), 0, object
);
1543 return D3DERR_INVALIDCALL
;
1545 wined3d_vertex_declaration
= ((IDirect3DVertexDeclaration8Impl
*)object
->vertex_declaration
)->wined3d_vertex_declaration
;
1547 /* Usage is missing ... Use SetRenderState to set the sw vp render state in SetVertexShader */
1548 hrc
= IWineD3DDevice_CreateVertexShader(This
->WineD3DDevice
, wined3d_vertex_declaration
, pFunction
, &object
->wineD3DVertexShader
, (IUnknown
*)object
);
1551 /* free up object */
1552 FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n");
1553 HeapFree(GetProcessHeap(), 0, object
);
1556 /* TODO: Store the VS declarations locally so that they can be derefferenced with a value higher than VS_HIGHESTFIXEDFXF */
1557 shader_handle
*handle
= alloc_shader_handle(This
);
1559 ERR("Failed to allocate shader handle\n");
1560 IDirect3DVertexShader8_Release((IUnknown
*)object
);
1561 hrc
= E_OUTOFMEMORY
;
1563 object
->handle
= handle
;
1565 *ppShader
= (handle
- This
->shader_handles
) + VS_HIGHESTFIXEDFXF
+ 1;
1567 load_local_constants(pDeclaration
, object
->wineD3DVertexShader
);
1570 LeaveCriticalSection(&d3d8_cs
);
1571 TRACE("(%p) : returning %p (handle %#x)\n", This
, object
, *ppShader
);
1576 IWineD3DVertexDeclaration
*IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl
*This
, DWORD fvf
)
1579 IWineD3DVertexDeclaration
* pDecl
= NULL
;
1580 int p
, low
, high
; /* deliberately signed */
1581 struct FvfToDecl
*convertedDecls
= This
->decls
;
1583 TRACE("Searching for declaration for fvf %08x... ", fvf
);
1586 high
= This
->numConvertedDecls
- 1;
1587 while(low
<= high
) {
1588 p
= (low
+ high
) >> 1;
1590 if(convertedDecls
[p
].fvf
== fvf
) {
1591 TRACE("found %p\n", convertedDecls
[p
].decl
);
1592 return convertedDecls
[p
].decl
;
1593 } else if(convertedDecls
[p
].fvf
< fvf
) {
1599 TRACE("not found. Creating and inserting at position %d.\n", low
);
1601 hr
= IWineD3DDevice_CreateVertexDeclarationFromFVF(This
->WineD3DDevice
,
1605 if (FAILED(hr
)) return NULL
;
1607 if(This
->declArraySize
== This
->numConvertedDecls
) {
1608 int grow
= This
->declArraySize
/ 2;
1609 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
1610 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
1611 if(!convertedDecls
) {
1612 /* This will destroy it */
1613 IWineD3DVertexDeclaration_Release(pDecl
);
1616 This
->decls
= convertedDecls
;
1617 This
->declArraySize
+= grow
;
1620 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
1621 convertedDecls
[low
].decl
= pDecl
;
1622 convertedDecls
[low
].fvf
= fvf
;
1623 This
->numConvertedDecls
++;
1625 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);
1629 static HRESULT WINAPI
IDirect3DDevice8Impl_SetVertexShader(LPDIRECT3DDEVICE8 iface
, DWORD pShader
) {
1630 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1631 HRESULT hrc
= D3D_OK
;
1633 TRACE("(%p) : Relay\n", This
);
1634 EnterCriticalSection(&d3d8_cs
);
1635 if (VS_HIGHESTFIXEDFXF
>= pShader
) {
1636 TRACE("Setting FVF, %d %d\n", VS_HIGHESTFIXEDFXF
, pShader
);
1637 IWineD3DDevice_SetFVF(This
->WineD3DDevice
, pShader
);
1638 IWineD3DDevice_SetVertexDeclaration(This
->WineD3DDevice
, IDirect3DDevice8Impl_FindDecl(This
, pShader
));
1639 IWineD3DDevice_SetVertexShader(This
->WineD3DDevice
, NULL
);
1641 TRACE("Setting shader\n");
1642 if (This
->allocated_shader_handles
<= pShader
- (VS_HIGHESTFIXEDFXF
+ 1)) {
1643 FIXME("(%p) : Number of shaders exceeds the maximum number of possible shaders\n", This
);
1644 hrc
= D3DERR_INVALIDCALL
;
1646 IDirect3DVertexShader8Impl
*shader
= This
->shader_handles
[pShader
- (VS_HIGHESTFIXEDFXF
+ 1)];
1647 IWineD3DDevice_SetVertexDeclaration(This
->WineD3DDevice
,
1648 shader
? ((IDirect3DVertexDeclaration8Impl
*)shader
->vertex_declaration
)->wined3d_vertex_declaration
: NULL
);
1649 hrc
= IWineD3DDevice_SetVertexShader(This
->WineD3DDevice
, 0 == shader
? NULL
: shader
->wineD3DVertexShader
);
1652 TRACE("(%p) : returning hr(%u)\n", This
, hrc
);
1653 LeaveCriticalSection(&d3d8_cs
);
1658 static HRESULT WINAPI
IDirect3DDevice8Impl_GetVertexShader(LPDIRECT3DDEVICE8 iface
, DWORD
* ppShader
) {
1659 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1660 IWineD3DVertexShader
*pShader
;
1661 HRESULT hrc
= D3D_OK
;
1663 TRACE("(%p) : Relay device@%p\n", This
, This
->WineD3DDevice
);
1664 EnterCriticalSection(&d3d8_cs
);
1665 hrc
= IWineD3DDevice_GetVertexShader(This
->WineD3DDevice
, &pShader
);
1666 if (D3D_OK
== hrc
) {
1668 IDirect3DVertexShader8Impl
*d3d8_shader
;
1669 hrc
= IWineD3DVertexShader_GetParent(pShader
, (IUnknown
**)&d3d8_shader
);
1670 IWineD3DVertexShader_Release(pShader
);
1671 *ppShader
= (d3d8_shader
->handle
- This
->shader_handles
) + (VS_HIGHESTFIXEDFXF
+ 1);
1677 WARN("(%p) : Call to IWineD3DDevice_GetVertexShader failed %u (device %p)\n", This
, hrc
, This
->WineD3DDevice
);
1679 TRACE("(%p) : returning %#x\n", This
, *ppShader
);
1680 LeaveCriticalSection(&d3d8_cs
);
1685 static HRESULT WINAPI
IDirect3DDevice8Impl_DeleteVertexShader(LPDIRECT3DDEVICE8 iface
, DWORD pShader
) {
1686 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1688 TRACE("(%p) : pShader %#x\n", This
, pShader
);
1690 EnterCriticalSection(&d3d8_cs
);
1691 if (pShader
<= VS_HIGHESTFIXEDFXF
|| This
->allocated_shader_handles
<= pShader
- (VS_HIGHESTFIXEDFXF
+ 1)) {
1692 ERR("(%p) : Trying to delete an invalid handle\n", This
);
1693 LeaveCriticalSection(&d3d8_cs
);
1694 return D3DERR_INVALIDCALL
;
1696 IWineD3DVertexShader
*cur
= NULL
;
1697 shader_handle
*handle
= &This
->shader_handles
[pShader
- (VS_HIGHESTFIXEDFXF
+ 1)];
1698 IDirect3DVertexShader8Impl
*shader
= *handle
;
1700 IWineD3DDevice_GetVertexShader(This
->WineD3DDevice
, &cur
);
1702 if(cur
== shader
->wineD3DVertexShader
) IDirect3DDevice8_SetVertexShader(iface
, 0);
1703 IWineD3DVertexShader_Release(cur
);
1706 while(IUnknown_Release((IUnknown
*)shader
));
1707 free_shader_handle(This
, handle
);
1709 LeaveCriticalSection(&d3d8_cs
);
1714 static HRESULT WINAPI
IDirect3DDevice8Impl_SetVertexShaderConstant(LPDIRECT3DDEVICE8 iface
, DWORD Register
, CONST
void* pConstantData
, DWORD ConstantCount
) {
1715 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1717 TRACE("(%p) : Relay\n", This
);
1719 EnterCriticalSection(&d3d8_cs
);
1720 hr
= IWineD3DDevice_SetVertexShaderConstantF(This
->WineD3DDevice
, Register
, (CONST
float *)pConstantData
, ConstantCount
);
1721 LeaveCriticalSection(&d3d8_cs
);
1725 static HRESULT WINAPI
IDirect3DDevice8Impl_GetVertexShaderConstant(LPDIRECT3DDEVICE8 iface
, DWORD Register
, void* pConstantData
, DWORD ConstantCount
) {
1726 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1728 TRACE("(%p) : Relay\n", This
);
1730 EnterCriticalSection(&d3d8_cs
);
1731 hr
= IWineD3DDevice_GetVertexShaderConstantF(This
->WineD3DDevice
, Register
, (float *)pConstantData
, ConstantCount
);
1732 LeaveCriticalSection(&d3d8_cs
);
1736 static HRESULT WINAPI
IDirect3DDevice8Impl_GetVertexShaderDeclaration(LPDIRECT3DDEVICE8 iface
, DWORD pVertexShader
, void* pData
, DWORD
* pSizeOfData
) {
1737 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1738 IDirect3DVertexDeclaration8Impl
*declaration
;
1739 IDirect3DVertexShader8Impl
*shader
= NULL
;
1741 TRACE("(%p) : pVertexShader 0x%08x, pData %p, *pSizeOfData %u\n", This
, pVertexShader
, pData
, *pSizeOfData
);
1743 EnterCriticalSection(&d3d8_cs
);
1744 if (pVertexShader
<= VS_HIGHESTFIXEDFXF
|| This
->allocated_shader_handles
<= pVertexShader
- (VS_HIGHESTFIXEDFXF
+ 1)) {
1745 ERR("Passed an invalid shader handle.\n");
1746 LeaveCriticalSection(&d3d8_cs
);
1747 return D3DERR_INVALIDCALL
;
1750 shader
= This
->shader_handles
[pVertexShader
- (VS_HIGHESTFIXEDFXF
+ 1)];
1751 declaration
= (IDirect3DVertexDeclaration8Impl
*)shader
->vertex_declaration
;
1753 /* If pData is NULL, we just return the required size of the buffer. */
1755 *pSizeOfData
= declaration
->elements_size
;
1756 LeaveCriticalSection(&d3d8_cs
);
1760 /* MSDN claims that if *pSizeOfData is smaller than the required size
1761 * we should write the required size and return D3DERR_MOREDATA.
1762 * That's not actually true. */
1763 if (*pSizeOfData
< declaration
->elements_size
) {
1764 LeaveCriticalSection(&d3d8_cs
);
1765 return D3DERR_INVALIDCALL
;
1768 CopyMemory(pData
, declaration
->elements
, declaration
->elements_size
);
1769 LeaveCriticalSection(&d3d8_cs
);
1774 static HRESULT WINAPI
IDirect3DDevice8Impl_GetVertexShaderFunction(LPDIRECT3DDEVICE8 iface
, DWORD pVertexShader
, void* pData
, DWORD
* pSizeOfData
) {
1775 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1776 IDirect3DVertexShader8Impl
*shader
= NULL
;
1779 TRACE("(%p) : pVertexShader %#x, pData %p, pSizeOfData %p\n", This
, pVertexShader
, pData
, pSizeOfData
);
1781 EnterCriticalSection(&d3d8_cs
);
1782 if (pVertexShader
<= VS_HIGHESTFIXEDFXF
|| This
->allocated_shader_handles
<= pVertexShader
- (VS_HIGHESTFIXEDFXF
+ 1)) {
1783 ERR("Passed an invalid shader handle.\n");
1784 LeaveCriticalSection(&d3d8_cs
);
1785 return D3DERR_INVALIDCALL
;
1788 shader
= This
->shader_handles
[pVertexShader
- (VS_HIGHESTFIXEDFXF
+ 1)];
1789 hr
= IWineD3DVertexShader_GetFunction(shader
->wineD3DVertexShader
, pData
, (UINT
*)pSizeOfData
);
1790 LeaveCriticalSection(&d3d8_cs
);
1794 static HRESULT WINAPI
IDirect3DDevice8Impl_SetIndices(LPDIRECT3DDEVICE8 iface
, IDirect3DIndexBuffer8
* pIndexData
, UINT baseVertexIndex
) {
1795 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1797 TRACE("(%p) Relay\n", This
);
1799 EnterCriticalSection(&d3d8_cs
);
1800 IWineD3DDevice_SetBaseVertexIndex(This
->WineD3DDevice
, baseVertexIndex
);
1801 hr
= IWineD3DDevice_SetIndices(This
->WineD3DDevice
,
1802 pIndexData
? ((IDirect3DIndexBuffer8Impl
*)pIndexData
)->wineD3DIndexBuffer
: NULL
);
1803 LeaveCriticalSection(&d3d8_cs
);
1807 static HRESULT WINAPI
IDirect3DDevice8Impl_GetIndices(LPDIRECT3DDEVICE8 iface
, IDirect3DIndexBuffer8
** ppIndexData
,UINT
* pBaseVertexIndex
) {
1808 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1809 IWineD3DIndexBuffer
*retIndexData
= NULL
;
1810 HRESULT rc
= D3D_OK
;
1812 TRACE("(%p) Relay\n", This
);
1814 if(ppIndexData
== NULL
){
1815 return D3DERR_INVALIDCALL
;
1818 EnterCriticalSection(&d3d8_cs
);
1819 IWineD3DDevice_GetBaseVertexIndex(This
->WineD3DDevice
, pBaseVertexIndex
);
1820 rc
= IWineD3DDevice_GetIndices(This
->WineD3DDevice
, &retIndexData
);
1821 if (SUCCEEDED(rc
) && retIndexData
) {
1822 IWineD3DIndexBuffer_GetParent(retIndexData
, (IUnknown
**)ppIndexData
);
1823 IWineD3DIndexBuffer_Release(retIndexData
);
1825 if (FAILED(rc
)) FIXME("Call to GetIndices failed\n");
1826 *ppIndexData
= NULL
;
1828 LeaveCriticalSection(&d3d8_cs
);
1832 static HRESULT WINAPI
IDirect3DDevice8Impl_CreatePixelShader(LPDIRECT3DDEVICE8 iface
, CONST DWORD
* pFunction
, DWORD
* ppShader
) {
1833 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1834 IDirect3DPixelShader8Impl
*object
;
1835 HRESULT hrc
= D3D_OK
;
1837 TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This
, pFunction
, ppShader
);
1839 if (NULL
== ppShader
) {
1840 TRACE("(%p) Invalid call\n", This
);
1841 return D3DERR_INVALIDCALL
;
1843 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1845 if (NULL
== object
) {
1846 return E_OUTOFMEMORY
;
1848 EnterCriticalSection(&d3d8_cs
);
1851 object
->lpVtbl
= &Direct3DPixelShader8_Vtbl
;
1852 hrc
= IWineD3DDevice_CreatePixelShader(This
->WineD3DDevice
, pFunction
, &object
->wineD3DPixelShader
, (IUnknown
*)object
);
1853 if (D3D_OK
!= hrc
) {
1854 FIXME("(%p) call to IWineD3DDevice_CreatePixelShader failed\n", This
);
1855 HeapFree(GetProcessHeap(), 0 , object
);
1858 shader_handle
*handle
= alloc_shader_handle(This
);
1860 ERR("Failed to allocate shader handle\n");
1861 IDirect3DVertexShader8_Release((IUnknown
*)object
);
1862 hrc
= E_OUTOFMEMORY
;
1864 object
->handle
= handle
;
1866 *ppShader
= (handle
- This
->shader_handles
) + VS_HIGHESTFIXEDFXF
+ 1;
1869 LeaveCriticalSection(&d3d8_cs
);
1872 TRACE("(%p) : returning %p (handle %#x)\n", This
, object
, *ppShader
);
1876 static HRESULT WINAPI
IDirect3DDevice8Impl_SetPixelShader(LPDIRECT3DDEVICE8 iface
, DWORD pShader
) {
1877 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1878 IDirect3DPixelShader8Impl
*shader
= NULL
;
1881 TRACE("(%p) : pShader %#x\n", This
, pShader
);
1883 EnterCriticalSection(&d3d8_cs
);
1884 if (pShader
> VS_HIGHESTFIXEDFXF
&& This
->allocated_shader_handles
> pShader
- (VS_HIGHESTFIXEDFXF
+ 1)) {
1885 shader
= This
->shader_handles
[pShader
- (VS_HIGHESTFIXEDFXF
+ 1)];
1886 } else if (pShader
) {
1887 ERR("Trying to set an invalid handle.\n");
1890 TRACE("(%p) : Setting shader %p\n", This
, shader
);
1891 hr
= IWineD3DDevice_SetPixelShader(This
->WineD3DDevice
, shader
== NULL
? NULL
:shader
->wineD3DPixelShader
);
1892 LeaveCriticalSection(&d3d8_cs
);
1896 static HRESULT WINAPI
IDirect3DDevice8Impl_GetPixelShader(LPDIRECT3DDEVICE8 iface
, DWORD
* ppShader
) {
1897 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1898 IWineD3DPixelShader
*object
;
1900 HRESULT hrc
= D3D_OK
;
1901 TRACE("(%p) Relay\n", This
);
1902 if (NULL
== ppShader
) {
1903 TRACE("(%p) Invalid call\n", This
);
1904 return D3DERR_INVALIDCALL
;
1907 EnterCriticalSection(&d3d8_cs
);
1908 hrc
= IWineD3DDevice_GetPixelShader(This
->WineD3DDevice
, &object
);
1909 if (D3D_OK
== hrc
&& NULL
!= object
) {
1910 IDirect3DPixelShader8Impl
*d3d8_shader
;
1911 hrc
= IWineD3DPixelShader_GetParent(object
, (IUnknown
**)&d3d8_shader
);
1912 IWineD3DPixelShader_Release(object
);
1913 *ppShader
= (d3d8_shader
->handle
- This
->shader_handles
) + (VS_HIGHESTFIXEDFXF
+ 1);
1915 *ppShader
= (DWORD
)NULL
;
1918 TRACE("(%p) : returning %#x\n", This
, *ppShader
);
1919 LeaveCriticalSection(&d3d8_cs
);
1923 static HRESULT WINAPI
IDirect3DDevice8Impl_DeletePixelShader(LPDIRECT3DDEVICE8 iface
, DWORD pShader
) {
1924 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1926 TRACE("(%p) : pShader %#x\n", This
, pShader
);
1928 EnterCriticalSection(&d3d8_cs
);
1929 if (pShader
<= VS_HIGHESTFIXEDFXF
|| This
->allocated_shader_handles
<= pShader
- (VS_HIGHESTFIXEDFXF
+ 1)) {
1930 ERR("(%p) : Trying to delete an invalid handle\n", This
);
1931 LeaveCriticalSection(&d3d8_cs
);
1932 return D3DERR_INVALIDCALL
;
1934 IWineD3DPixelShader
*cur
= NULL
;
1935 shader_handle
*handle
= &This
->shader_handles
[pShader
- (VS_HIGHESTFIXEDFXF
+ 1)];
1936 IDirect3DPixelShader8Impl
*shader
= *handle
;
1938 IWineD3DDevice_GetPixelShader(This
->WineD3DDevice
, &cur
);
1940 if(cur
== shader
->wineD3DPixelShader
) IDirect3DDevice8_SetPixelShader(iface
, 0);
1941 IWineD3DPixelShader_Release(cur
);
1944 while(IUnknown_Release((IUnknown
*)shader
));
1945 free_shader_handle(This
, handle
);
1947 LeaveCriticalSection(&d3d8_cs
);
1952 static HRESULT WINAPI
IDirect3DDevice8Impl_SetPixelShaderConstant(LPDIRECT3DDEVICE8 iface
, DWORD Register
, CONST
void* pConstantData
, DWORD ConstantCount
) {
1953 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1955 TRACE("(%p) Relay\n", This
);
1957 EnterCriticalSection(&d3d8_cs
);
1958 hr
= IWineD3DDevice_SetPixelShaderConstantF(This
->WineD3DDevice
, Register
, (CONST
float *)pConstantData
, ConstantCount
);
1959 LeaveCriticalSection(&d3d8_cs
);
1963 static HRESULT WINAPI
IDirect3DDevice8Impl_GetPixelShaderConstant(LPDIRECT3DDEVICE8 iface
, DWORD Register
, void* pConstantData
, DWORD ConstantCount
) {
1964 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1966 TRACE("(%p) Relay\n", This
);
1968 EnterCriticalSection(&d3d8_cs
);
1969 hr
= IWineD3DDevice_GetPixelShaderConstantF(This
->WineD3DDevice
, Register
, (float *)pConstantData
, ConstantCount
);
1970 LeaveCriticalSection(&d3d8_cs
);
1974 static HRESULT WINAPI
IDirect3DDevice8Impl_GetPixelShaderFunction(LPDIRECT3DDEVICE8 iface
, DWORD pPixelShader
, void* pData
, DWORD
* pSizeOfData
) {
1975 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1976 IDirect3DPixelShader8Impl
*shader
= NULL
;
1979 TRACE("(%p) : pPixelShader %#x, pData %p, pSizeOfData %p\n", This
, pPixelShader
, pData
, pSizeOfData
);
1981 EnterCriticalSection(&d3d8_cs
);
1982 if (pPixelShader
<= VS_HIGHESTFIXEDFXF
|| This
->allocated_shader_handles
<= pPixelShader
- (VS_HIGHESTFIXEDFXF
+ 1)) {
1983 ERR("Passed an invalid shader handle.\n");
1984 LeaveCriticalSection(&d3d8_cs
);
1985 return D3DERR_INVALIDCALL
;
1988 shader
= This
->shader_handles
[pPixelShader
- (VS_HIGHESTFIXEDFXF
+ 1)];
1989 hr
= IWineD3DPixelShader_GetFunction(shader
->wineD3DPixelShader
, pData
, (UINT
*)pSizeOfData
);
1990 LeaveCriticalSection(&d3d8_cs
);
1994 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawRectPatch(LPDIRECT3DDEVICE8 iface
, UINT Handle
,CONST
float* pNumSegs
,CONST D3DRECTPATCH_INFO
* pRectPatchInfo
) {
1995 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1997 TRACE("(%p) Relay\n", This
);
1999 EnterCriticalSection(&d3d8_cs
);
2000 hr
= IWineD3DDevice_DrawRectPatch(This
->WineD3DDevice
, Handle
, pNumSegs
, (CONST WINED3DRECTPATCH_INFO
*)pRectPatchInfo
);
2001 LeaveCriticalSection(&d3d8_cs
);
2005 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawTriPatch(LPDIRECT3DDEVICE8 iface
, UINT Handle
,CONST
float* pNumSegs
,CONST D3DTRIPATCH_INFO
* pTriPatchInfo
) {
2006 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2008 TRACE("(%p) Relay\n", This
);
2010 EnterCriticalSection(&d3d8_cs
);
2011 hr
= IWineD3DDevice_DrawTriPatch(This
->WineD3DDevice
, Handle
, pNumSegs
, (CONST WINED3DTRIPATCH_INFO
*)pTriPatchInfo
);
2012 LeaveCriticalSection(&d3d8_cs
);
2016 static HRESULT WINAPI
IDirect3DDevice8Impl_DeletePatch(LPDIRECT3DDEVICE8 iface
, UINT Handle
) {
2017 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2019 TRACE("(%p) Relay\n", This
);
2021 EnterCriticalSection(&d3d8_cs
);
2022 hr
= IWineD3DDevice_DeletePatch(This
->WineD3DDevice
, Handle
);
2023 LeaveCriticalSection(&d3d8_cs
);
2027 static HRESULT WINAPI
IDirect3DDevice8Impl_SetStreamSource(LPDIRECT3DDEVICE8 iface
, UINT StreamNumber
,IDirect3DVertexBuffer8
* pStreamData
,UINT Stride
) {
2028 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2030 TRACE("(%p) Relay\n" , This
);
2032 EnterCriticalSection(&d3d8_cs
);
2033 hr
= IWineD3DDevice_SetStreamSource(This
->WineD3DDevice
, StreamNumber
,
2034 NULL
== pStreamData
? NULL
: ((IDirect3DVertexBuffer8Impl
*)pStreamData
)->wineD3DVertexBuffer
,
2035 0/* Offset in bytes */, Stride
);
2036 LeaveCriticalSection(&d3d8_cs
);
2040 static HRESULT WINAPI
IDirect3DDevice8Impl_GetStreamSource(LPDIRECT3DDEVICE8 iface
, UINT StreamNumber
,IDirect3DVertexBuffer8
** pStream
,UINT
* pStride
) {
2041 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2042 IWineD3DVertexBuffer
*retStream
= NULL
;
2043 HRESULT rc
= D3D_OK
;
2045 TRACE("(%p) Relay\n" , This
);
2047 if(pStream
== NULL
){
2048 return D3DERR_INVALIDCALL
;
2051 EnterCriticalSection(&d3d8_cs
);
2052 rc
= IWineD3DDevice_GetStreamSource(This
->WineD3DDevice
, StreamNumber
, (IWineD3DVertexBuffer
**)&retStream
, 0 /* Offset in bytes */, pStride
);
2053 if (rc
== D3D_OK
&& NULL
!= retStream
) {
2054 IWineD3DVertexBuffer_GetParent(retStream
, (IUnknown
**)pStream
);
2055 IWineD3DVertexBuffer_Release(retStream
);
2058 FIXME("Call to GetStreamSource failed %p\n", pStride
);
2062 LeaveCriticalSection(&d3d8_cs
);
2068 const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl
=
2070 IDirect3DDevice8Impl_QueryInterface
,
2071 IDirect3DDevice8Impl_AddRef
,
2072 IDirect3DDevice8Impl_Release
,
2073 IDirect3DDevice8Impl_TestCooperativeLevel
,
2074 IDirect3DDevice8Impl_GetAvailableTextureMem
,
2075 IDirect3DDevice8Impl_ResourceManagerDiscardBytes
,
2076 IDirect3DDevice8Impl_GetDirect3D
,
2077 IDirect3DDevice8Impl_GetDeviceCaps
,
2078 IDirect3DDevice8Impl_GetDisplayMode
,
2079 IDirect3DDevice8Impl_GetCreationParameters
,
2080 IDirect3DDevice8Impl_SetCursorProperties
,
2081 IDirect3DDevice8Impl_SetCursorPosition
,
2082 IDirect3DDevice8Impl_ShowCursor
,
2083 IDirect3DDevice8Impl_CreateAdditionalSwapChain
,
2084 IDirect3DDevice8Impl_Reset
,
2085 IDirect3DDevice8Impl_Present
,
2086 IDirect3DDevice8Impl_GetBackBuffer
,
2087 IDirect3DDevice8Impl_GetRasterStatus
,
2088 IDirect3DDevice8Impl_SetGammaRamp
,
2089 IDirect3DDevice8Impl_GetGammaRamp
,
2090 IDirect3DDevice8Impl_CreateTexture
,
2091 IDirect3DDevice8Impl_CreateVolumeTexture
,
2092 IDirect3DDevice8Impl_CreateCubeTexture
,
2093 IDirect3DDevice8Impl_CreateVertexBuffer
,
2094 IDirect3DDevice8Impl_CreateIndexBuffer
,
2095 IDirect3DDevice8Impl_CreateRenderTarget
,
2096 IDirect3DDevice8Impl_CreateDepthStencilSurface
,
2097 IDirect3DDevice8Impl_CreateImageSurface
,
2098 IDirect3DDevice8Impl_CopyRects
,
2099 IDirect3DDevice8Impl_UpdateTexture
,
2100 IDirect3DDevice8Impl_GetFrontBuffer
,
2101 IDirect3DDevice8Impl_SetRenderTarget
,
2102 IDirect3DDevice8Impl_GetRenderTarget
,
2103 IDirect3DDevice8Impl_GetDepthStencilSurface
,
2104 IDirect3DDevice8Impl_BeginScene
,
2105 IDirect3DDevice8Impl_EndScene
,
2106 IDirect3DDevice8Impl_Clear
,
2107 IDirect3DDevice8Impl_SetTransform
,
2108 IDirect3DDevice8Impl_GetTransform
,
2109 IDirect3DDevice8Impl_MultiplyTransform
,
2110 IDirect3DDevice8Impl_SetViewport
,
2111 IDirect3DDevice8Impl_GetViewport
,
2112 IDirect3DDevice8Impl_SetMaterial
,
2113 IDirect3DDevice8Impl_GetMaterial
,
2114 IDirect3DDevice8Impl_SetLight
,
2115 IDirect3DDevice8Impl_GetLight
,
2116 IDirect3DDevice8Impl_LightEnable
,
2117 IDirect3DDevice8Impl_GetLightEnable
,
2118 IDirect3DDevice8Impl_SetClipPlane
,
2119 IDirect3DDevice8Impl_GetClipPlane
,
2120 IDirect3DDevice8Impl_SetRenderState
,
2121 IDirect3DDevice8Impl_GetRenderState
,
2122 IDirect3DDevice8Impl_BeginStateBlock
,
2123 IDirect3DDevice8Impl_EndStateBlock
,
2124 IDirect3DDevice8Impl_ApplyStateBlock
,
2125 IDirect3DDevice8Impl_CaptureStateBlock
,
2126 IDirect3DDevice8Impl_DeleteStateBlock
,
2127 IDirect3DDevice8Impl_CreateStateBlock
,
2128 IDirect3DDevice8Impl_SetClipStatus
,
2129 IDirect3DDevice8Impl_GetClipStatus
,
2130 IDirect3DDevice8Impl_GetTexture
,
2131 IDirect3DDevice8Impl_SetTexture
,
2132 IDirect3DDevice8Impl_GetTextureStageState
,
2133 IDirect3DDevice8Impl_SetTextureStageState
,
2134 IDirect3DDevice8Impl_ValidateDevice
,
2135 IDirect3DDevice8Impl_GetInfo
,
2136 IDirect3DDevice8Impl_SetPaletteEntries
,
2137 IDirect3DDevice8Impl_GetPaletteEntries
,
2138 IDirect3DDevice8Impl_SetCurrentTexturePalette
,
2139 IDirect3DDevice8Impl_GetCurrentTexturePalette
,
2140 IDirect3DDevice8Impl_DrawPrimitive
,
2141 IDirect3DDevice8Impl_DrawIndexedPrimitive
,
2142 IDirect3DDevice8Impl_DrawPrimitiveUP
,
2143 IDirect3DDevice8Impl_DrawIndexedPrimitiveUP
,
2144 IDirect3DDevice8Impl_ProcessVertices
,
2145 IDirect3DDevice8Impl_CreateVertexShader
,
2146 IDirect3DDevice8Impl_SetVertexShader
,
2147 IDirect3DDevice8Impl_GetVertexShader
,
2148 IDirect3DDevice8Impl_DeleteVertexShader
,
2149 IDirect3DDevice8Impl_SetVertexShaderConstant
,
2150 IDirect3DDevice8Impl_GetVertexShaderConstant
,
2151 IDirect3DDevice8Impl_GetVertexShaderDeclaration
,
2152 IDirect3DDevice8Impl_GetVertexShaderFunction
,
2153 IDirect3DDevice8Impl_SetStreamSource
,
2154 IDirect3DDevice8Impl_GetStreamSource
,
2155 IDirect3DDevice8Impl_SetIndices
,
2156 IDirect3DDevice8Impl_GetIndices
,
2157 IDirect3DDevice8Impl_CreatePixelShader
,
2158 IDirect3DDevice8Impl_SetPixelShader
,
2159 IDirect3DDevice8Impl_GetPixelShader
,
2160 IDirect3DDevice8Impl_DeletePixelShader
,
2161 IDirect3DDevice8Impl_SetPixelShaderConstant
,
2162 IDirect3DDevice8Impl_GetPixelShaderConstant
,
2163 IDirect3DDevice8Impl_GetPixelShaderFunction
,
2164 IDirect3DDevice8Impl_DrawRectPatch
,
2165 IDirect3DDevice8Impl_DrawTriPatch
,
2166 IDirect3DDevice8Impl_DeletePatch
2169 /* Internal function called back during the CreateDevice to create a render target */
2170 HRESULT WINAPI
D3D8CB_CreateSurface(IUnknown
*device
, IUnknown
*pSuperior
, UINT Width
, UINT Height
,
2171 WINED3DFORMAT Format
, DWORD Usage
, WINED3DPOOL Pool
, UINT Level
,
2172 WINED3DCUBEMAP_FACES Face
, IWineD3DSurface
**ppSurface
,
2173 HANDLE
*pSharedHandle
) {
2175 HRESULT res
= D3D_OK
;
2176 IDirect3DSurface8Impl
*d3dSurface
= NULL
;
2177 BOOL Lockable
= TRUE
;
2179 if((WINED3DPOOL_DEFAULT
== Pool
&& WINED3DUSAGE_DYNAMIC
!= Usage
))
2183 res
= IDirect3DDevice8Impl_CreateSurface((IDirect3DDevice8
*)device
, Width
, Height
, (D3DFORMAT
)Format
, Lockable
, FALSE
/*Discard*/, Level
, (IDirect3DSurface8
**)&d3dSurface
, D3DRTYPE_SURFACE
, Usage
, Pool
, D3DMULTISAMPLE_NONE
, 0 /* MultisampleQuality */);
2185 if (SUCCEEDED(res
)) {
2186 *ppSurface
= d3dSurface
->wineD3DSurface
;
2187 d3dSurface
->container
= pSuperior
;
2188 IUnknown_Release(d3dSurface
->parentDevice
);
2189 d3dSurface
->parentDevice
= NULL
;
2190 d3dSurface
->forwardReference
= pSuperior
;
2192 FIXME("(%p) IDirect3DDevice8_CreateSurface failed\n", device
);
2197 ULONG WINAPI
D3D8CB_DestroySurface(IWineD3DSurface
*pSurface
) {
2198 IDirect3DSurface8Impl
* surfaceParent
;
2199 TRACE("(%p) call back\n", pSurface
);
2201 IWineD3DSurface_GetParent(pSurface
, (IUnknown
**) &surfaceParent
);
2202 /* GetParent's AddRef was forwarded to an object in destruction.
2203 * Releasing it here again would cause an endless recursion. */
2204 surfaceParent
->forwardReference
= NULL
;
2205 return IDirect3DSurface8_Release((IDirect3DSurface8
*) surfaceParent
);