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 if(Type
!= D3DSBT_ALL
&& Type
!= D3DSBT_PIXELSTATE
&&
1169 Type
!= D3DSBT_VERTEXSTATE
) {
1170 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1171 return D3DERR_INVALIDCALL
;
1174 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirect3DStateBlock8Impl
));
1175 if (NULL
== object
) {
1177 return E_OUTOFMEMORY
;
1179 object
->lpVtbl
= &Direct3DStateBlock8_Vtbl
;
1182 EnterCriticalSection(&d3d8_cs
);
1183 hrc
= IWineD3DDevice_CreateStateBlock(This
->WineD3DDevice
, (WINED3DSTATEBLOCKTYPE
)Type
, &object
->wineD3DStateBlock
, (IUnknown
*)object
);
1184 LeaveCriticalSection(&d3d8_cs
);
1186 FIXME("(%p) Call to IWineD3DDevice_CreateStateBlock failed.\n", This
);
1187 HeapFree(GetProcessHeap(), 0, object
);
1190 *pToken
= (DWORD
)object
;
1192 TRACE("(%p) returning token (ptr to stateblock) of %p\n", This
, object
);
1197 static HRESULT WINAPI
IDirect3DDevice8Impl_SetClipStatus(LPDIRECT3DDEVICE8 iface
, CONST D3DCLIPSTATUS8
* pClipStatus
) {
1198 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1200 TRACE("(%p) Relay\n" , This
);
1201 /* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
1202 EnterCriticalSection(&d3d8_cs
);
1203 hr
= IWineD3DDevice_SetClipStatus(This
->WineD3DDevice
, (const WINED3DCLIPSTATUS
*)pClipStatus
);
1204 LeaveCriticalSection(&d3d8_cs
);
1208 static HRESULT WINAPI
IDirect3DDevice8Impl_GetClipStatus(LPDIRECT3DDEVICE8 iface
, D3DCLIPSTATUS8
* pClipStatus
) {
1209 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1211 TRACE("(%p) Relay\n" , This
);
1213 EnterCriticalSection(&d3d8_cs
);
1214 hr
= IWineD3DDevice_GetClipStatus(This
->WineD3DDevice
, (WINED3DCLIPSTATUS
*)pClipStatus
);
1215 LeaveCriticalSection(&d3d8_cs
);
1219 static HRESULT WINAPI
IDirect3DDevice8Impl_GetTexture(LPDIRECT3DDEVICE8 iface
, DWORD Stage
,IDirect3DBaseTexture8
** ppTexture
) {
1220 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1221 IWineD3DBaseTexture
*retTexture
= NULL
;
1222 HRESULT rc
= D3D_OK
;
1224 TRACE("(%p) Relay\n" , This
);
1226 if(ppTexture
== NULL
){
1227 return D3DERR_INVALIDCALL
;
1230 EnterCriticalSection(&d3d8_cs
);
1231 rc
= IWineD3DDevice_GetTexture(This
->WineD3DDevice
, Stage
, (IWineD3DBaseTexture
**)&retTexture
);
1232 if (rc
== D3D_OK
&& NULL
!= retTexture
) {
1233 IWineD3DBaseTexture_GetParent(retTexture
, (IUnknown
**)ppTexture
);
1234 IWineD3DBaseTexture_Release(retTexture
);
1236 FIXME("Call to get texture (%d) failed (%p)\n", Stage
, retTexture
);
1239 LeaveCriticalSection(&d3d8_cs
);
1244 static HRESULT WINAPI
IDirect3DDevice8Impl_SetTexture(LPDIRECT3DDEVICE8 iface
, DWORD Stage
, IDirect3DBaseTexture8
* pTexture
) {
1245 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1247 TRACE("(%p) Relay %d %p\n" , This
, Stage
, pTexture
);
1249 EnterCriticalSection(&d3d8_cs
);
1250 hr
= IWineD3DDevice_SetTexture(This
->WineD3DDevice
, Stage
,
1251 pTexture
==NULL
? NULL
: ((IDirect3DBaseTexture8Impl
*)pTexture
)->wineD3DBaseTexture
);
1252 LeaveCriticalSection(&d3d8_cs
);
1256 static HRESULT WINAPI
IDirect3DDevice8Impl_GetTextureStageState(LPDIRECT3DDEVICE8 iface
, DWORD Stage
,D3DTEXTURESTAGESTATETYPE Type
,DWORD
* pValue
) {
1257 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1259 TRACE("(%p) Relay\n" , This
);
1262 case D3DTSS_ADDRESSU
:
1263 Type
= WINED3DSAMP_ADDRESSU
;
1265 case D3DTSS_ADDRESSV
:
1266 Type
= WINED3DSAMP_ADDRESSV
;
1268 case D3DTSS_ADDRESSW
:
1269 Type
= WINED3DSAMP_ADDRESSW
;
1271 case D3DTSS_BORDERCOLOR
:
1272 Type
= WINED3DSAMP_BORDERCOLOR
;
1274 case D3DTSS_MAGFILTER
:
1275 Type
= WINED3DSAMP_MAGFILTER
;
1277 case D3DTSS_MAXANISOTROPY
:
1278 Type
= WINED3DSAMP_MAXANISOTROPY
;
1280 case D3DTSS_MAXMIPLEVEL
:
1281 Type
= WINED3DSAMP_MAXMIPLEVEL
;
1283 case D3DTSS_MINFILTER
:
1284 Type
= WINED3DSAMP_MINFILTER
;
1286 case D3DTSS_MIPFILTER
:
1287 Type
= WINED3DSAMP_MIPFILTER
;
1289 case D3DTSS_MIPMAPLODBIAS
:
1290 Type
= WINED3DSAMP_MIPMAPLODBIAS
;
1293 EnterCriticalSection(&d3d8_cs
);
1294 hr
= IWineD3DDevice_GetTextureStageState(This
->WineD3DDevice
, Stage
, Type
, pValue
);
1295 LeaveCriticalSection(&d3d8_cs
);
1299 EnterCriticalSection(&d3d8_cs
);
1300 hr
= IWineD3DDevice_GetSamplerState(This
->WineD3DDevice
, Stage
, Type
, pValue
);
1301 LeaveCriticalSection(&d3d8_cs
);
1305 static HRESULT WINAPI
IDirect3DDevice8Impl_SetTextureStageState(LPDIRECT3DDEVICE8 iface
, DWORD Stage
, D3DTEXTURESTAGESTATETYPE Type
, DWORD Value
) {
1306 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1308 TRACE("(%p) Relay\n" , This
);
1311 case D3DTSS_ADDRESSU
:
1312 Type
= WINED3DSAMP_ADDRESSU
;
1314 case D3DTSS_ADDRESSV
:
1315 Type
= WINED3DSAMP_ADDRESSV
;
1317 case D3DTSS_ADDRESSW
:
1318 Type
= WINED3DSAMP_ADDRESSW
;
1320 case D3DTSS_BORDERCOLOR
:
1321 Type
= WINED3DSAMP_BORDERCOLOR
;
1323 case D3DTSS_MAGFILTER
:
1324 Type
= WINED3DSAMP_MAGFILTER
;
1326 case D3DTSS_MAXANISOTROPY
:
1327 Type
= WINED3DSAMP_MAXANISOTROPY
;
1329 case D3DTSS_MAXMIPLEVEL
:
1330 Type
= WINED3DSAMP_MAXMIPLEVEL
;
1332 case D3DTSS_MINFILTER
:
1333 Type
= WINED3DSAMP_MINFILTER
;
1335 case D3DTSS_MIPFILTER
:
1336 Type
= WINED3DSAMP_MIPFILTER
;
1338 case D3DTSS_MIPMAPLODBIAS
:
1339 Type
= WINED3DSAMP_MIPMAPLODBIAS
;
1342 EnterCriticalSection(&d3d8_cs
);
1343 hr
= IWineD3DDevice_SetTextureStageState(This
->WineD3DDevice
, Stage
, Type
, Value
);
1344 LeaveCriticalSection(&d3d8_cs
);
1348 EnterCriticalSection(&d3d8_cs
);
1349 hr
= IWineD3DDevice_SetSamplerState(This
->WineD3DDevice
, Stage
, Type
, Value
);
1350 LeaveCriticalSection(&d3d8_cs
);
1354 static HRESULT WINAPI
IDirect3DDevice8Impl_ValidateDevice(LPDIRECT3DDEVICE8 iface
, DWORD
* pNumPasses
) {
1355 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1357 TRACE("(%p) Relay\n" , This
);
1359 EnterCriticalSection(&d3d8_cs
);
1360 hr
= IWineD3DDevice_ValidateDevice(This
->WineD3DDevice
, pNumPasses
);
1361 LeaveCriticalSection(&d3d8_cs
);
1365 static HRESULT WINAPI
IDirect3DDevice8Impl_GetInfo(LPDIRECT3DDEVICE8 iface
, DWORD DevInfoID
, void* pDevInfoStruct
, DWORD DevInfoStructSize
) {
1366 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1367 FIXME("(%p) : stub\n", This
);
1371 static HRESULT WINAPI
IDirect3DDevice8Impl_SetPaletteEntries(LPDIRECT3DDEVICE8 iface
, UINT PaletteNumber
, CONST PALETTEENTRY
* pEntries
) {
1372 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1374 TRACE("(%p) Relay\n" , This
);
1376 EnterCriticalSection(&d3d8_cs
);
1377 hr
= IWineD3DDevice_SetPaletteEntries(This
->WineD3DDevice
, PaletteNumber
, pEntries
);
1378 LeaveCriticalSection(&d3d8_cs
);
1382 static HRESULT WINAPI
IDirect3DDevice8Impl_GetPaletteEntries(LPDIRECT3DDEVICE8 iface
, UINT PaletteNumber
, PALETTEENTRY
* pEntries
) {
1383 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1385 TRACE("(%p) Relay\n" , This
);
1387 EnterCriticalSection(&d3d8_cs
);
1388 hr
= IWineD3DDevice_GetPaletteEntries(This
->WineD3DDevice
, PaletteNumber
, pEntries
);
1389 LeaveCriticalSection(&d3d8_cs
);
1393 static HRESULT WINAPI
IDirect3DDevice8Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface
, UINT PaletteNumber
) {
1394 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1396 TRACE("(%p) Relay\n" , This
);
1398 EnterCriticalSection(&d3d8_cs
);
1399 hr
= IWineD3DDevice_SetCurrentTexturePalette(This
->WineD3DDevice
, PaletteNumber
);
1400 LeaveCriticalSection(&d3d8_cs
);
1404 static HRESULT WINAPI
IDirect3DDevice8Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface
, UINT
*PaletteNumber
) {
1405 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1407 TRACE("(%p) Relay\n" , This
);
1409 EnterCriticalSection(&d3d8_cs
);
1410 hr
= IWineD3DDevice_GetCurrentTexturePalette(This
->WineD3DDevice
, PaletteNumber
);
1411 LeaveCriticalSection(&d3d8_cs
);
1415 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawPrimitive(LPDIRECT3DDEVICE8 iface
, D3DPRIMITIVETYPE PrimitiveType
, UINT StartVertex
, UINT PrimitiveCount
) {
1416 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1418 TRACE("(%p) Relay\n" , This
);
1420 EnterCriticalSection(&d3d8_cs
);
1421 hr
= IWineD3DDevice_DrawPrimitive(This
->WineD3DDevice
, PrimitiveType
, StartVertex
, PrimitiveCount
);
1422 LeaveCriticalSection(&d3d8_cs
);
1426 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE8 iface
, D3DPRIMITIVETYPE PrimitiveType
,
1427 UINT MinVertexIndex
,UINT NumVertices
,UINT startIndex
,UINT primCount
) {
1428 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1430 TRACE("(%p) Relay\n" , This
);
1432 EnterCriticalSection(&d3d8_cs
);
1433 hr
= IWineD3DDevice_DrawIndexedPrimitive(This
->WineD3DDevice
, PrimitiveType
, MinVertexIndex
, NumVertices
, startIndex
, primCount
);
1434 LeaveCriticalSection(&d3d8_cs
);
1438 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE8 iface
, D3DPRIMITIVETYPE PrimitiveType
,UINT PrimitiveCount
,CONST
void* pVertexStreamZeroData
,UINT VertexStreamZeroStride
) {
1439 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1441 TRACE("(%p) Relay\n" , This
);
1443 EnterCriticalSection(&d3d8_cs
);
1444 hr
= IWineD3DDevice_DrawPrimitiveUP(This
->WineD3DDevice
, PrimitiveType
, PrimitiveCount
, pVertexStreamZeroData
, VertexStreamZeroStride
);
1445 LeaveCriticalSection(&d3d8_cs
);
1449 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE8 iface
, D3DPRIMITIVETYPE PrimitiveType
,UINT MinVertexIndex
,
1450 UINT NumVertexIndices
,UINT PrimitiveCount
,CONST
void* pIndexData
,
1451 D3DFORMAT IndexDataFormat
,CONST
void* pVertexStreamZeroData
,
1452 UINT VertexStreamZeroStride
) {
1453 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1455 TRACE("(%p) Relay\n" , This
);
1457 EnterCriticalSection(&d3d8_cs
);
1458 hr
= IWineD3DDevice_DrawIndexedPrimitiveUP(This
->WineD3DDevice
, PrimitiveType
, MinVertexIndex
, NumVertexIndices
, PrimitiveCount
,
1459 pIndexData
, IndexDataFormat
, pVertexStreamZeroData
, VertexStreamZeroStride
);
1460 LeaveCriticalSection(&d3d8_cs
);
1464 static HRESULT WINAPI
IDirect3DDevice8Impl_ProcessVertices(LPDIRECT3DDEVICE8 iface
, UINT SrcStartIndex
,UINT DestIndex
,UINT VertexCount
,IDirect3DVertexBuffer8
* pDestBuffer
,DWORD Flags
) {
1465 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1467 TRACE("(%p) Relay\n" , This
);
1469 EnterCriticalSection(&d3d8_cs
);
1470 hr
= IWineD3DDevice_ProcessVertices(This
->WineD3DDevice
,SrcStartIndex
, DestIndex
, VertexCount
, ((IDirect3DVertexBuffer8Impl
*)pDestBuffer
)->wineD3DVertexBuffer
, NULL
, Flags
);
1471 LeaveCriticalSection(&d3d8_cs
);
1475 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateVertexDeclaration(IDirect3DDevice8
*iface
, CONST DWORD
*declaration
, IDirect3DVertexDeclaration8
**decl_ptr
) {
1476 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1477 IDirect3DVertexDeclaration8Impl
*object
;
1478 WINED3DVERTEXELEMENT
*wined3d_elements
;
1479 size_t wined3d_element_count
;
1480 HRESULT hr
= D3D_OK
;
1482 TRACE("(%p) : declaration %p\n", This
, declaration
);
1484 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1486 ERR("Memory allocation failed\n");
1488 return D3DERR_OUTOFVIDEOMEMORY
;
1491 object
->ref_count
= 1;
1492 object
->lpVtbl
= &Direct3DVertexDeclaration8_Vtbl
;
1494 wined3d_element_count
= convert_to_wined3d_declaration(declaration
, &object
->elements_size
, &wined3d_elements
);
1495 object
->elements
= HeapAlloc(GetProcessHeap(), 0, object
->elements_size
);
1496 if (!object
->elements
) {
1497 ERR("Memory allocation failed\n");
1498 HeapFree(GetProcessHeap(), 0, wined3d_elements
);
1499 HeapFree(GetProcessHeap(), 0, object
);
1501 return D3DERR_OUTOFVIDEOMEMORY
;
1504 CopyMemory(object
->elements
, declaration
, object
->elements_size
);
1506 EnterCriticalSection(&d3d8_cs
);
1507 hr
= IWineD3DDevice_CreateVertexDeclaration(This
->WineD3DDevice
, &object
->wined3d_vertex_declaration
,
1508 (IUnknown
*)object
, wined3d_elements
, wined3d_element_count
);
1509 LeaveCriticalSection(&d3d8_cs
);
1510 HeapFree(GetProcessHeap(), 0, wined3d_elements
);
1513 ERR("(%p) : IWineD3DDevice_CreateVertexDeclaration call failed\n", This
);
1514 HeapFree(GetProcessHeap(), 0, object
->elements
);
1515 HeapFree(GetProcessHeap(), 0, object
);
1517 *decl_ptr
= (IDirect3DVertexDeclaration8
*)object
;
1518 TRACE("(%p) : Created vertex declaration %p\n", This
, object
);
1524 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateVertexShader(LPDIRECT3DDEVICE8 iface
, CONST DWORD
* pDeclaration
, CONST DWORD
* pFunction
, DWORD
* ppShader
, DWORD Usage
) {
1525 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1526 HRESULT hrc
= D3D_OK
;
1527 IDirect3DVertexShader8Impl
*object
;
1528 IWineD3DVertexDeclaration
*wined3d_vertex_declaration
;
1530 /* Setup a stub object for now */
1531 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1532 TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This
, pFunction
, ppShader
);
1533 if (NULL
== object
) {
1534 FIXME("Allocation of memory failed\n");
1536 return D3DERR_OUTOFVIDEOMEMORY
;
1540 object
->lpVtbl
= &Direct3DVertexShader8_Vtbl
;
1542 EnterCriticalSection(&d3d8_cs
);
1543 hrc
= IDirect3DDevice8Impl_CreateVertexDeclaration(iface
, pDeclaration
, &object
->vertex_declaration
);
1545 ERR("(%p) : IDirect3DDeviceImpl_CreateVertexDeclaration call failed\n", This
);
1546 LeaveCriticalSection(&d3d8_cs
);
1547 HeapFree(GetProcessHeap(), 0, object
);
1549 return D3DERR_INVALIDCALL
;
1551 wined3d_vertex_declaration
= ((IDirect3DVertexDeclaration8Impl
*)object
->vertex_declaration
)->wined3d_vertex_declaration
;
1553 /* Usage is missing ... Use SetRenderState to set the sw vp render state in SetVertexShader */
1554 hrc
= IWineD3DDevice_CreateVertexShader(This
->WineD3DDevice
, wined3d_vertex_declaration
, pFunction
, &object
->wineD3DVertexShader
, (IUnknown
*)object
);
1557 /* free up object */
1558 FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n");
1559 HeapFree(GetProcessHeap(), 0, object
);
1562 /* TODO: Store the VS declarations locally so that they can be derefferenced with a value higher than VS_HIGHESTFIXEDFXF */
1563 shader_handle
*handle
= alloc_shader_handle(This
);
1565 ERR("Failed to allocate shader handle\n");
1566 IDirect3DVertexShader8_Release((IUnknown
*)object
);
1567 hrc
= E_OUTOFMEMORY
;
1569 object
->handle
= handle
;
1571 *ppShader
= (handle
- This
->shader_handles
) + VS_HIGHESTFIXEDFXF
+ 1;
1573 load_local_constants(pDeclaration
, object
->wineD3DVertexShader
);
1576 LeaveCriticalSection(&d3d8_cs
);
1577 TRACE("(%p) : returning %p (handle %#x)\n", This
, object
, *ppShader
);
1582 IWineD3DVertexDeclaration
*IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl
*This
, DWORD fvf
)
1585 IWineD3DVertexDeclaration
* pDecl
= NULL
;
1586 int p
, low
, high
; /* deliberately signed */
1587 struct FvfToDecl
*convertedDecls
= This
->decls
;
1589 TRACE("Searching for declaration for fvf %08x... ", fvf
);
1592 high
= This
->numConvertedDecls
- 1;
1593 while(low
<= high
) {
1594 p
= (low
+ high
) >> 1;
1596 if(convertedDecls
[p
].fvf
== fvf
) {
1597 TRACE("found %p\n", convertedDecls
[p
].decl
);
1598 return convertedDecls
[p
].decl
;
1599 } else if(convertedDecls
[p
].fvf
< fvf
) {
1605 TRACE("not found. Creating and inserting at position %d.\n", low
);
1607 hr
= IWineD3DDevice_CreateVertexDeclarationFromFVF(This
->WineD3DDevice
,
1611 if (FAILED(hr
)) return NULL
;
1613 if(This
->declArraySize
== This
->numConvertedDecls
) {
1614 int grow
= This
->declArraySize
/ 2;
1615 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
1616 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
1617 if(!convertedDecls
) {
1618 /* This will destroy it */
1619 IWineD3DVertexDeclaration_Release(pDecl
);
1622 This
->decls
= convertedDecls
;
1623 This
->declArraySize
+= grow
;
1626 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
1627 convertedDecls
[low
].decl
= pDecl
;
1628 convertedDecls
[low
].fvf
= fvf
;
1629 This
->numConvertedDecls
++;
1631 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);
1635 static HRESULT WINAPI
IDirect3DDevice8Impl_SetVertexShader(LPDIRECT3DDEVICE8 iface
, DWORD pShader
) {
1636 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1637 HRESULT hrc
= D3D_OK
;
1639 TRACE("(%p) : Relay\n", This
);
1640 EnterCriticalSection(&d3d8_cs
);
1641 if (VS_HIGHESTFIXEDFXF
>= pShader
) {
1642 TRACE("Setting FVF, %d %d\n", VS_HIGHESTFIXEDFXF
, pShader
);
1643 IWineD3DDevice_SetFVF(This
->WineD3DDevice
, pShader
);
1644 IWineD3DDevice_SetVertexDeclaration(This
->WineD3DDevice
, IDirect3DDevice8Impl_FindDecl(This
, pShader
));
1645 IWineD3DDevice_SetVertexShader(This
->WineD3DDevice
, NULL
);
1647 TRACE("Setting shader\n");
1648 if (This
->allocated_shader_handles
<= pShader
- (VS_HIGHESTFIXEDFXF
+ 1)) {
1649 FIXME("(%p) : Number of shaders exceeds the maximum number of possible shaders\n", This
);
1650 hrc
= D3DERR_INVALIDCALL
;
1652 IDirect3DVertexShader8Impl
*shader
= This
->shader_handles
[pShader
- (VS_HIGHESTFIXEDFXF
+ 1)];
1653 IWineD3DDevice_SetVertexDeclaration(This
->WineD3DDevice
,
1654 shader
? ((IDirect3DVertexDeclaration8Impl
*)shader
->vertex_declaration
)->wined3d_vertex_declaration
: NULL
);
1655 hrc
= IWineD3DDevice_SetVertexShader(This
->WineD3DDevice
, 0 == shader
? NULL
: shader
->wineD3DVertexShader
);
1658 TRACE("(%p) : returning hr(%u)\n", This
, hrc
);
1659 LeaveCriticalSection(&d3d8_cs
);
1664 static HRESULT WINAPI
IDirect3DDevice8Impl_GetVertexShader(LPDIRECT3DDEVICE8 iface
, DWORD
* ppShader
) {
1665 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1666 IWineD3DVertexShader
*pShader
;
1667 HRESULT hrc
= D3D_OK
;
1669 TRACE("(%p) : Relay device@%p\n", This
, This
->WineD3DDevice
);
1670 EnterCriticalSection(&d3d8_cs
);
1671 hrc
= IWineD3DDevice_GetVertexShader(This
->WineD3DDevice
, &pShader
);
1672 if (D3D_OK
== hrc
) {
1674 IDirect3DVertexShader8Impl
*d3d8_shader
;
1675 hrc
= IWineD3DVertexShader_GetParent(pShader
, (IUnknown
**)&d3d8_shader
);
1676 IWineD3DVertexShader_Release(pShader
);
1677 *ppShader
= (d3d8_shader
->handle
- This
->shader_handles
) + (VS_HIGHESTFIXEDFXF
+ 1);
1683 WARN("(%p) : Call to IWineD3DDevice_GetVertexShader failed %u (device %p)\n", This
, hrc
, This
->WineD3DDevice
);
1685 TRACE("(%p) : returning %#x\n", This
, *ppShader
);
1686 LeaveCriticalSection(&d3d8_cs
);
1691 static HRESULT WINAPI
IDirect3DDevice8Impl_DeleteVertexShader(LPDIRECT3DDEVICE8 iface
, DWORD pShader
) {
1692 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1694 TRACE("(%p) : pShader %#x\n", This
, pShader
);
1696 EnterCriticalSection(&d3d8_cs
);
1697 if (pShader
<= VS_HIGHESTFIXEDFXF
|| This
->allocated_shader_handles
<= pShader
- (VS_HIGHESTFIXEDFXF
+ 1)) {
1698 ERR("(%p) : Trying to delete an invalid handle\n", This
);
1699 LeaveCriticalSection(&d3d8_cs
);
1700 return D3DERR_INVALIDCALL
;
1702 IWineD3DVertexShader
*cur
= NULL
;
1703 shader_handle
*handle
= &This
->shader_handles
[pShader
- (VS_HIGHESTFIXEDFXF
+ 1)];
1704 IDirect3DVertexShader8Impl
*shader
= *handle
;
1706 IWineD3DDevice_GetVertexShader(This
->WineD3DDevice
, &cur
);
1708 if(cur
== shader
->wineD3DVertexShader
) IDirect3DDevice8_SetVertexShader(iface
, 0);
1709 IWineD3DVertexShader_Release(cur
);
1712 while(IUnknown_Release((IUnknown
*)shader
));
1713 free_shader_handle(This
, handle
);
1715 LeaveCriticalSection(&d3d8_cs
);
1720 static HRESULT WINAPI
IDirect3DDevice8Impl_SetVertexShaderConstant(LPDIRECT3DDEVICE8 iface
, DWORD Register
, CONST
void* pConstantData
, DWORD ConstantCount
) {
1721 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1723 TRACE("(%p) : Relay\n", This
);
1725 EnterCriticalSection(&d3d8_cs
);
1726 hr
= IWineD3DDevice_SetVertexShaderConstantF(This
->WineD3DDevice
, Register
, (CONST
float *)pConstantData
, ConstantCount
);
1727 LeaveCriticalSection(&d3d8_cs
);
1731 static HRESULT WINAPI
IDirect3DDevice8Impl_GetVertexShaderConstant(LPDIRECT3DDEVICE8 iface
, DWORD Register
, void* pConstantData
, DWORD ConstantCount
) {
1732 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1734 TRACE("(%p) : Relay\n", This
);
1736 EnterCriticalSection(&d3d8_cs
);
1737 hr
= IWineD3DDevice_GetVertexShaderConstantF(This
->WineD3DDevice
, Register
, (float *)pConstantData
, ConstantCount
);
1738 LeaveCriticalSection(&d3d8_cs
);
1742 static HRESULT WINAPI
IDirect3DDevice8Impl_GetVertexShaderDeclaration(LPDIRECT3DDEVICE8 iface
, DWORD pVertexShader
, void* pData
, DWORD
* pSizeOfData
) {
1743 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1744 IDirect3DVertexDeclaration8Impl
*declaration
;
1745 IDirect3DVertexShader8Impl
*shader
= NULL
;
1747 TRACE("(%p) : pVertexShader 0x%08x, pData %p, *pSizeOfData %u\n", This
, pVertexShader
, pData
, *pSizeOfData
);
1749 EnterCriticalSection(&d3d8_cs
);
1750 if (pVertexShader
<= VS_HIGHESTFIXEDFXF
|| This
->allocated_shader_handles
<= pVertexShader
- (VS_HIGHESTFIXEDFXF
+ 1)) {
1751 ERR("Passed an invalid shader handle.\n");
1752 LeaveCriticalSection(&d3d8_cs
);
1753 return D3DERR_INVALIDCALL
;
1756 shader
= This
->shader_handles
[pVertexShader
- (VS_HIGHESTFIXEDFXF
+ 1)];
1757 declaration
= (IDirect3DVertexDeclaration8Impl
*)shader
->vertex_declaration
;
1759 /* If pData is NULL, we just return the required size of the buffer. */
1761 *pSizeOfData
= declaration
->elements_size
;
1762 LeaveCriticalSection(&d3d8_cs
);
1766 /* MSDN claims that if *pSizeOfData is smaller than the required size
1767 * we should write the required size and return D3DERR_MOREDATA.
1768 * That's not actually true. */
1769 if (*pSizeOfData
< declaration
->elements_size
) {
1770 LeaveCriticalSection(&d3d8_cs
);
1771 return D3DERR_INVALIDCALL
;
1774 CopyMemory(pData
, declaration
->elements
, declaration
->elements_size
);
1775 LeaveCriticalSection(&d3d8_cs
);
1780 static HRESULT WINAPI
IDirect3DDevice8Impl_GetVertexShaderFunction(LPDIRECT3DDEVICE8 iface
, DWORD pVertexShader
, void* pData
, DWORD
* pSizeOfData
) {
1781 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1782 IDirect3DVertexShader8Impl
*shader
= NULL
;
1785 TRACE("(%p) : pVertexShader %#x, pData %p, pSizeOfData %p\n", This
, pVertexShader
, pData
, pSizeOfData
);
1787 EnterCriticalSection(&d3d8_cs
);
1788 if (pVertexShader
<= VS_HIGHESTFIXEDFXF
|| This
->allocated_shader_handles
<= pVertexShader
- (VS_HIGHESTFIXEDFXF
+ 1)) {
1789 ERR("Passed an invalid shader handle.\n");
1790 LeaveCriticalSection(&d3d8_cs
);
1791 return D3DERR_INVALIDCALL
;
1794 shader
= This
->shader_handles
[pVertexShader
- (VS_HIGHESTFIXEDFXF
+ 1)];
1795 hr
= IWineD3DVertexShader_GetFunction(shader
->wineD3DVertexShader
, pData
, (UINT
*)pSizeOfData
);
1796 LeaveCriticalSection(&d3d8_cs
);
1800 static HRESULT WINAPI
IDirect3DDevice8Impl_SetIndices(LPDIRECT3DDEVICE8 iface
, IDirect3DIndexBuffer8
* pIndexData
, UINT baseVertexIndex
) {
1801 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1803 TRACE("(%p) Relay\n", This
);
1805 EnterCriticalSection(&d3d8_cs
);
1806 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
1807 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
1808 * vertex buffers can't be created to address them with an index that requires the 32nd bit
1809 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
1812 IWineD3DDevice_SetBaseVertexIndex(This
->WineD3DDevice
, baseVertexIndex
);
1813 hr
= IWineD3DDevice_SetIndices(This
->WineD3DDevice
,
1814 pIndexData
? ((IDirect3DIndexBuffer8Impl
*)pIndexData
)->wineD3DIndexBuffer
: NULL
);
1815 LeaveCriticalSection(&d3d8_cs
);
1819 static HRESULT WINAPI
IDirect3DDevice8Impl_GetIndices(LPDIRECT3DDEVICE8 iface
, IDirect3DIndexBuffer8
** ppIndexData
,UINT
* pBaseVertexIndex
) {
1820 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1821 IWineD3DIndexBuffer
*retIndexData
= NULL
;
1822 HRESULT rc
= D3D_OK
;
1824 TRACE("(%p) Relay\n", This
);
1826 if(ppIndexData
== NULL
){
1827 return D3DERR_INVALIDCALL
;
1830 EnterCriticalSection(&d3d8_cs
);
1831 /* The case from UINT to INT is safe because d3d8 will never set negative values */
1832 IWineD3DDevice_GetBaseVertexIndex(This
->WineD3DDevice
, (INT
*) pBaseVertexIndex
);
1833 rc
= IWineD3DDevice_GetIndices(This
->WineD3DDevice
, &retIndexData
);
1834 if (SUCCEEDED(rc
) && retIndexData
) {
1835 IWineD3DIndexBuffer_GetParent(retIndexData
, (IUnknown
**)ppIndexData
);
1836 IWineD3DIndexBuffer_Release(retIndexData
);
1838 if (FAILED(rc
)) FIXME("Call to GetIndices failed\n");
1839 *ppIndexData
= NULL
;
1841 LeaveCriticalSection(&d3d8_cs
);
1845 static HRESULT WINAPI
IDirect3DDevice8Impl_CreatePixelShader(LPDIRECT3DDEVICE8 iface
, CONST DWORD
* pFunction
, DWORD
* ppShader
) {
1846 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1847 IDirect3DPixelShader8Impl
*object
;
1848 HRESULT hrc
= D3D_OK
;
1850 TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This
, pFunction
, ppShader
);
1852 if (NULL
== ppShader
) {
1853 TRACE("(%p) Invalid call\n", This
);
1854 return D3DERR_INVALIDCALL
;
1856 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1858 if (NULL
== object
) {
1859 return E_OUTOFMEMORY
;
1861 EnterCriticalSection(&d3d8_cs
);
1864 object
->lpVtbl
= &Direct3DPixelShader8_Vtbl
;
1865 hrc
= IWineD3DDevice_CreatePixelShader(This
->WineD3DDevice
, pFunction
, &object
->wineD3DPixelShader
, (IUnknown
*)object
);
1866 if (D3D_OK
!= hrc
) {
1867 FIXME("(%p) call to IWineD3DDevice_CreatePixelShader failed\n", This
);
1868 HeapFree(GetProcessHeap(), 0 , object
);
1871 shader_handle
*handle
= alloc_shader_handle(This
);
1873 ERR("Failed to allocate shader handle\n");
1874 IDirect3DVertexShader8_Release((IUnknown
*)object
);
1875 hrc
= E_OUTOFMEMORY
;
1877 object
->handle
= handle
;
1879 *ppShader
= (handle
- This
->shader_handles
) + VS_HIGHESTFIXEDFXF
+ 1;
1882 LeaveCriticalSection(&d3d8_cs
);
1885 TRACE("(%p) : returning %p (handle %#x)\n", This
, object
, *ppShader
);
1889 static HRESULT WINAPI
IDirect3DDevice8Impl_SetPixelShader(LPDIRECT3DDEVICE8 iface
, DWORD pShader
) {
1890 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1891 IDirect3DPixelShader8Impl
*shader
= NULL
;
1894 TRACE("(%p) : pShader %#x\n", This
, pShader
);
1896 EnterCriticalSection(&d3d8_cs
);
1897 if (pShader
> VS_HIGHESTFIXEDFXF
&& This
->allocated_shader_handles
> pShader
- (VS_HIGHESTFIXEDFXF
+ 1)) {
1898 shader
= This
->shader_handles
[pShader
- (VS_HIGHESTFIXEDFXF
+ 1)];
1899 } else if (pShader
) {
1900 ERR("Trying to set an invalid handle.\n");
1903 TRACE("(%p) : Setting shader %p\n", This
, shader
);
1904 hr
= IWineD3DDevice_SetPixelShader(This
->WineD3DDevice
, shader
== NULL
? NULL
:shader
->wineD3DPixelShader
);
1905 LeaveCriticalSection(&d3d8_cs
);
1909 static HRESULT WINAPI
IDirect3DDevice8Impl_GetPixelShader(LPDIRECT3DDEVICE8 iface
, DWORD
* ppShader
) {
1910 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1911 IWineD3DPixelShader
*object
;
1913 HRESULT hrc
= D3D_OK
;
1914 TRACE("(%p) Relay\n", This
);
1915 if (NULL
== ppShader
) {
1916 TRACE("(%p) Invalid call\n", This
);
1917 return D3DERR_INVALIDCALL
;
1920 EnterCriticalSection(&d3d8_cs
);
1921 hrc
= IWineD3DDevice_GetPixelShader(This
->WineD3DDevice
, &object
);
1922 if (D3D_OK
== hrc
&& NULL
!= object
) {
1923 IDirect3DPixelShader8Impl
*d3d8_shader
;
1924 hrc
= IWineD3DPixelShader_GetParent(object
, (IUnknown
**)&d3d8_shader
);
1925 IWineD3DPixelShader_Release(object
);
1926 *ppShader
= (d3d8_shader
->handle
- This
->shader_handles
) + (VS_HIGHESTFIXEDFXF
+ 1);
1928 *ppShader
= (DWORD
)NULL
;
1931 TRACE("(%p) : returning %#x\n", This
, *ppShader
);
1932 LeaveCriticalSection(&d3d8_cs
);
1936 static HRESULT WINAPI
IDirect3DDevice8Impl_DeletePixelShader(LPDIRECT3DDEVICE8 iface
, DWORD pShader
) {
1937 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1939 TRACE("(%p) : pShader %#x\n", This
, pShader
);
1941 EnterCriticalSection(&d3d8_cs
);
1942 if (pShader
<= VS_HIGHESTFIXEDFXF
|| This
->allocated_shader_handles
<= pShader
- (VS_HIGHESTFIXEDFXF
+ 1)) {
1943 ERR("(%p) : Trying to delete an invalid handle\n", This
);
1944 LeaveCriticalSection(&d3d8_cs
);
1945 return D3DERR_INVALIDCALL
;
1947 IWineD3DPixelShader
*cur
= NULL
;
1948 shader_handle
*handle
= &This
->shader_handles
[pShader
- (VS_HIGHESTFIXEDFXF
+ 1)];
1949 IDirect3DPixelShader8Impl
*shader
= *handle
;
1951 IWineD3DDevice_GetPixelShader(This
->WineD3DDevice
, &cur
);
1953 if(cur
== shader
->wineD3DPixelShader
) IDirect3DDevice8_SetPixelShader(iface
, 0);
1954 IWineD3DPixelShader_Release(cur
);
1957 while(IUnknown_Release((IUnknown
*)shader
));
1958 free_shader_handle(This
, handle
);
1960 LeaveCriticalSection(&d3d8_cs
);
1965 static HRESULT WINAPI
IDirect3DDevice8Impl_SetPixelShaderConstant(LPDIRECT3DDEVICE8 iface
, DWORD Register
, CONST
void* pConstantData
, DWORD ConstantCount
) {
1966 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1968 TRACE("(%p) Relay\n", This
);
1970 EnterCriticalSection(&d3d8_cs
);
1971 hr
= IWineD3DDevice_SetPixelShaderConstantF(This
->WineD3DDevice
, Register
, (CONST
float *)pConstantData
, ConstantCount
);
1972 LeaveCriticalSection(&d3d8_cs
);
1976 static HRESULT WINAPI
IDirect3DDevice8Impl_GetPixelShaderConstant(LPDIRECT3DDEVICE8 iface
, DWORD Register
, void* pConstantData
, DWORD ConstantCount
) {
1977 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1979 TRACE("(%p) Relay\n", This
);
1981 EnterCriticalSection(&d3d8_cs
);
1982 hr
= IWineD3DDevice_GetPixelShaderConstantF(This
->WineD3DDevice
, Register
, (float *)pConstantData
, ConstantCount
);
1983 LeaveCriticalSection(&d3d8_cs
);
1987 static HRESULT WINAPI
IDirect3DDevice8Impl_GetPixelShaderFunction(LPDIRECT3DDEVICE8 iface
, DWORD pPixelShader
, void* pData
, DWORD
* pSizeOfData
) {
1988 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1989 IDirect3DPixelShader8Impl
*shader
= NULL
;
1992 TRACE("(%p) : pPixelShader %#x, pData %p, pSizeOfData %p\n", This
, pPixelShader
, pData
, pSizeOfData
);
1994 EnterCriticalSection(&d3d8_cs
);
1995 if (pPixelShader
<= VS_HIGHESTFIXEDFXF
|| This
->allocated_shader_handles
<= pPixelShader
- (VS_HIGHESTFIXEDFXF
+ 1)) {
1996 ERR("Passed an invalid shader handle.\n");
1997 LeaveCriticalSection(&d3d8_cs
);
1998 return D3DERR_INVALIDCALL
;
2001 shader
= This
->shader_handles
[pPixelShader
- (VS_HIGHESTFIXEDFXF
+ 1)];
2002 hr
= IWineD3DPixelShader_GetFunction(shader
->wineD3DPixelShader
, pData
, (UINT
*)pSizeOfData
);
2003 LeaveCriticalSection(&d3d8_cs
);
2007 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawRectPatch(LPDIRECT3DDEVICE8 iface
, UINT Handle
,CONST
float* pNumSegs
,CONST D3DRECTPATCH_INFO
* pRectPatchInfo
) {
2008 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2010 TRACE("(%p) Relay\n", This
);
2012 EnterCriticalSection(&d3d8_cs
);
2013 hr
= IWineD3DDevice_DrawRectPatch(This
->WineD3DDevice
, Handle
, pNumSegs
, (CONST WINED3DRECTPATCH_INFO
*)pRectPatchInfo
);
2014 LeaveCriticalSection(&d3d8_cs
);
2018 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawTriPatch(LPDIRECT3DDEVICE8 iface
, UINT Handle
,CONST
float* pNumSegs
,CONST D3DTRIPATCH_INFO
* pTriPatchInfo
) {
2019 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2021 TRACE("(%p) Relay\n", This
);
2023 EnterCriticalSection(&d3d8_cs
);
2024 hr
= IWineD3DDevice_DrawTriPatch(This
->WineD3DDevice
, Handle
, pNumSegs
, (CONST WINED3DTRIPATCH_INFO
*)pTriPatchInfo
);
2025 LeaveCriticalSection(&d3d8_cs
);
2029 static HRESULT WINAPI
IDirect3DDevice8Impl_DeletePatch(LPDIRECT3DDEVICE8 iface
, UINT Handle
) {
2030 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2032 TRACE("(%p) Relay\n", This
);
2034 EnterCriticalSection(&d3d8_cs
);
2035 hr
= IWineD3DDevice_DeletePatch(This
->WineD3DDevice
, Handle
);
2036 LeaveCriticalSection(&d3d8_cs
);
2040 static HRESULT WINAPI
IDirect3DDevice8Impl_SetStreamSource(LPDIRECT3DDEVICE8 iface
, UINT StreamNumber
,IDirect3DVertexBuffer8
* pStreamData
,UINT Stride
) {
2041 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2043 TRACE("(%p) Relay\n" , This
);
2045 EnterCriticalSection(&d3d8_cs
);
2046 hr
= IWineD3DDevice_SetStreamSource(This
->WineD3DDevice
, StreamNumber
,
2047 NULL
== pStreamData
? NULL
: ((IDirect3DVertexBuffer8Impl
*)pStreamData
)->wineD3DVertexBuffer
,
2048 0/* Offset in bytes */, Stride
);
2049 LeaveCriticalSection(&d3d8_cs
);
2053 static HRESULT WINAPI
IDirect3DDevice8Impl_GetStreamSource(LPDIRECT3DDEVICE8 iface
, UINT StreamNumber
,IDirect3DVertexBuffer8
** pStream
,UINT
* pStride
) {
2054 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2055 IWineD3DVertexBuffer
*retStream
= NULL
;
2056 HRESULT rc
= D3D_OK
;
2058 TRACE("(%p) Relay\n" , This
);
2060 if(pStream
== NULL
){
2061 return D3DERR_INVALIDCALL
;
2064 EnterCriticalSection(&d3d8_cs
);
2065 rc
= IWineD3DDevice_GetStreamSource(This
->WineD3DDevice
, StreamNumber
, (IWineD3DVertexBuffer
**)&retStream
, 0 /* Offset in bytes */, pStride
);
2066 if (rc
== D3D_OK
&& NULL
!= retStream
) {
2067 IWineD3DVertexBuffer_GetParent(retStream
, (IUnknown
**)pStream
);
2068 IWineD3DVertexBuffer_Release(retStream
);
2071 FIXME("Call to GetStreamSource failed %p\n", pStride
);
2075 LeaveCriticalSection(&d3d8_cs
);
2081 const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl
=
2083 IDirect3DDevice8Impl_QueryInterface
,
2084 IDirect3DDevice8Impl_AddRef
,
2085 IDirect3DDevice8Impl_Release
,
2086 IDirect3DDevice8Impl_TestCooperativeLevel
,
2087 IDirect3DDevice8Impl_GetAvailableTextureMem
,
2088 IDirect3DDevice8Impl_ResourceManagerDiscardBytes
,
2089 IDirect3DDevice8Impl_GetDirect3D
,
2090 IDirect3DDevice8Impl_GetDeviceCaps
,
2091 IDirect3DDevice8Impl_GetDisplayMode
,
2092 IDirect3DDevice8Impl_GetCreationParameters
,
2093 IDirect3DDevice8Impl_SetCursorProperties
,
2094 IDirect3DDevice8Impl_SetCursorPosition
,
2095 IDirect3DDevice8Impl_ShowCursor
,
2096 IDirect3DDevice8Impl_CreateAdditionalSwapChain
,
2097 IDirect3DDevice8Impl_Reset
,
2098 IDirect3DDevice8Impl_Present
,
2099 IDirect3DDevice8Impl_GetBackBuffer
,
2100 IDirect3DDevice8Impl_GetRasterStatus
,
2101 IDirect3DDevice8Impl_SetGammaRamp
,
2102 IDirect3DDevice8Impl_GetGammaRamp
,
2103 IDirect3DDevice8Impl_CreateTexture
,
2104 IDirect3DDevice8Impl_CreateVolumeTexture
,
2105 IDirect3DDevice8Impl_CreateCubeTexture
,
2106 IDirect3DDevice8Impl_CreateVertexBuffer
,
2107 IDirect3DDevice8Impl_CreateIndexBuffer
,
2108 IDirect3DDevice8Impl_CreateRenderTarget
,
2109 IDirect3DDevice8Impl_CreateDepthStencilSurface
,
2110 IDirect3DDevice8Impl_CreateImageSurface
,
2111 IDirect3DDevice8Impl_CopyRects
,
2112 IDirect3DDevice8Impl_UpdateTexture
,
2113 IDirect3DDevice8Impl_GetFrontBuffer
,
2114 IDirect3DDevice8Impl_SetRenderTarget
,
2115 IDirect3DDevice8Impl_GetRenderTarget
,
2116 IDirect3DDevice8Impl_GetDepthStencilSurface
,
2117 IDirect3DDevice8Impl_BeginScene
,
2118 IDirect3DDevice8Impl_EndScene
,
2119 IDirect3DDevice8Impl_Clear
,
2120 IDirect3DDevice8Impl_SetTransform
,
2121 IDirect3DDevice8Impl_GetTransform
,
2122 IDirect3DDevice8Impl_MultiplyTransform
,
2123 IDirect3DDevice8Impl_SetViewport
,
2124 IDirect3DDevice8Impl_GetViewport
,
2125 IDirect3DDevice8Impl_SetMaterial
,
2126 IDirect3DDevice8Impl_GetMaterial
,
2127 IDirect3DDevice8Impl_SetLight
,
2128 IDirect3DDevice8Impl_GetLight
,
2129 IDirect3DDevice8Impl_LightEnable
,
2130 IDirect3DDevice8Impl_GetLightEnable
,
2131 IDirect3DDevice8Impl_SetClipPlane
,
2132 IDirect3DDevice8Impl_GetClipPlane
,
2133 IDirect3DDevice8Impl_SetRenderState
,
2134 IDirect3DDevice8Impl_GetRenderState
,
2135 IDirect3DDevice8Impl_BeginStateBlock
,
2136 IDirect3DDevice8Impl_EndStateBlock
,
2137 IDirect3DDevice8Impl_ApplyStateBlock
,
2138 IDirect3DDevice8Impl_CaptureStateBlock
,
2139 IDirect3DDevice8Impl_DeleteStateBlock
,
2140 IDirect3DDevice8Impl_CreateStateBlock
,
2141 IDirect3DDevice8Impl_SetClipStatus
,
2142 IDirect3DDevice8Impl_GetClipStatus
,
2143 IDirect3DDevice8Impl_GetTexture
,
2144 IDirect3DDevice8Impl_SetTexture
,
2145 IDirect3DDevice8Impl_GetTextureStageState
,
2146 IDirect3DDevice8Impl_SetTextureStageState
,
2147 IDirect3DDevice8Impl_ValidateDevice
,
2148 IDirect3DDevice8Impl_GetInfo
,
2149 IDirect3DDevice8Impl_SetPaletteEntries
,
2150 IDirect3DDevice8Impl_GetPaletteEntries
,
2151 IDirect3DDevice8Impl_SetCurrentTexturePalette
,
2152 IDirect3DDevice8Impl_GetCurrentTexturePalette
,
2153 IDirect3DDevice8Impl_DrawPrimitive
,
2154 IDirect3DDevice8Impl_DrawIndexedPrimitive
,
2155 IDirect3DDevice8Impl_DrawPrimitiveUP
,
2156 IDirect3DDevice8Impl_DrawIndexedPrimitiveUP
,
2157 IDirect3DDevice8Impl_ProcessVertices
,
2158 IDirect3DDevice8Impl_CreateVertexShader
,
2159 IDirect3DDevice8Impl_SetVertexShader
,
2160 IDirect3DDevice8Impl_GetVertexShader
,
2161 IDirect3DDevice8Impl_DeleteVertexShader
,
2162 IDirect3DDevice8Impl_SetVertexShaderConstant
,
2163 IDirect3DDevice8Impl_GetVertexShaderConstant
,
2164 IDirect3DDevice8Impl_GetVertexShaderDeclaration
,
2165 IDirect3DDevice8Impl_GetVertexShaderFunction
,
2166 IDirect3DDevice8Impl_SetStreamSource
,
2167 IDirect3DDevice8Impl_GetStreamSource
,
2168 IDirect3DDevice8Impl_SetIndices
,
2169 IDirect3DDevice8Impl_GetIndices
,
2170 IDirect3DDevice8Impl_CreatePixelShader
,
2171 IDirect3DDevice8Impl_SetPixelShader
,
2172 IDirect3DDevice8Impl_GetPixelShader
,
2173 IDirect3DDevice8Impl_DeletePixelShader
,
2174 IDirect3DDevice8Impl_SetPixelShaderConstant
,
2175 IDirect3DDevice8Impl_GetPixelShaderConstant
,
2176 IDirect3DDevice8Impl_GetPixelShaderFunction
,
2177 IDirect3DDevice8Impl_DrawRectPatch
,
2178 IDirect3DDevice8Impl_DrawTriPatch
,
2179 IDirect3DDevice8Impl_DeletePatch
2182 /* Internal function called back during the CreateDevice to create a render target */
2183 HRESULT WINAPI
D3D8CB_CreateSurface(IUnknown
*device
, IUnknown
*pSuperior
, UINT Width
, UINT Height
,
2184 WINED3DFORMAT Format
, DWORD Usage
, WINED3DPOOL Pool
, UINT Level
,
2185 WINED3DCUBEMAP_FACES Face
, IWineD3DSurface
**ppSurface
,
2186 HANDLE
*pSharedHandle
) {
2188 HRESULT res
= D3D_OK
;
2189 IDirect3DSurface8Impl
*d3dSurface
= NULL
;
2190 BOOL Lockable
= TRUE
;
2192 if((WINED3DPOOL_DEFAULT
== Pool
&& WINED3DUSAGE_DYNAMIC
!= Usage
))
2196 res
= IDirect3DDevice8Impl_CreateSurface((IDirect3DDevice8
*)device
, Width
, Height
, (D3DFORMAT
)Format
, Lockable
, FALSE
/*Discard*/, Level
, (IDirect3DSurface8
**)&d3dSurface
, D3DRTYPE_SURFACE
, Usage
, Pool
, D3DMULTISAMPLE_NONE
, 0 /* MultisampleQuality */);
2198 if (SUCCEEDED(res
)) {
2199 *ppSurface
= d3dSurface
->wineD3DSurface
;
2200 d3dSurface
->container
= pSuperior
;
2201 IUnknown_Release(d3dSurface
->parentDevice
);
2202 d3dSurface
->parentDevice
= NULL
;
2203 d3dSurface
->forwardReference
= pSuperior
;
2205 FIXME("(%p) IDirect3DDevice8_CreateSurface failed\n", device
);
2210 ULONG WINAPI
D3D8CB_DestroySurface(IWineD3DSurface
*pSurface
) {
2211 IDirect3DSurface8Impl
* surfaceParent
;
2212 TRACE("(%p) call back\n", pSurface
);
2214 IWineD3DSurface_GetParent(pSurface
, (IUnknown
**) &surfaceParent
);
2215 /* GetParent's AddRef was forwarded to an object in destruction.
2216 * Releasing it here again would cause an endless recursion. */
2217 surfaceParent
->forwardReference
= NULL
;
2218 return IDirect3DSurface8_Release((IDirect3DSurface8
*) surfaceParent
);