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 D3DFORMAT
d3dformat_from_wined3dformat(WINED3DFORMAT format
)
41 BYTE
*c
= (BYTE
*)&format
;
43 /* Don't translate FOURCC formats */
44 if (isprint(c
[0]) && isprint(c
[1]) && isprint(c
[2]) && isprint(c
[3])) return format
;
48 case WINED3DFMT_UNKNOWN
: return D3DFMT_UNKNOWN
;
49 case WINED3DFMT_B8G8R8_UNORM
: return D3DFMT_R8G8B8
;
50 case WINED3DFMT_B8G8R8A8_UNORM
: return D3DFMT_A8R8G8B8
;
51 case WINED3DFMT_B8G8R8X8_UNORM
: return D3DFMT_X8R8G8B8
;
52 case WINED3DFMT_B5G6R5_UNORM
: return D3DFMT_R5G6B5
;
53 case WINED3DFMT_B5G5R5X1_UNORM
: return D3DFMT_X1R5G5B5
;
54 case WINED3DFMT_B5G5R5A1_UNORM
: return D3DFMT_A1R5G5B5
;
55 case WINED3DFMT_B4G4R4A4_UNORM
: return D3DFMT_A4R4G4B4
;
56 case WINED3DFMT_B2G3R3_UNORM
: return D3DFMT_R3G3B2
;
57 case WINED3DFMT_A8_UNORM
: return D3DFMT_A8
;
58 case WINED3DFMT_B2G3R3A8_UNORM
: return D3DFMT_A8R3G3B2
;
59 case WINED3DFMT_B4G4R4X4_UNORM
: return D3DFMT_X4R4G4B4
;
60 case WINED3DFMT_R10G10B10A2_UNORM
: return D3DFMT_A2B10G10R10
;
61 case WINED3DFMT_R16G16_UNORM
: return D3DFMT_G16R16
;
62 case WINED3DFMT_P8_UINT_A8_UNORM
: return D3DFMT_A8P8
;
63 case WINED3DFMT_P8_UINT
: return D3DFMT_P8
;
64 case WINED3DFMT_L8_UNORM
: return D3DFMT_L8
;
65 case WINED3DFMT_L8A8_UNORM
: return D3DFMT_A8L8
;
66 case WINED3DFMT_L4A4_UNORM
: return D3DFMT_A4L4
;
67 case WINED3DFMT_R8G8_SNORM
: return D3DFMT_V8U8
;
68 case WINED3DFMT_R5G5_SNORM_L6_UNORM
: return D3DFMT_L6V5U5
;
69 case WINED3DFMT_R8G8_SNORM_L8X8_UNORM
: return D3DFMT_X8L8V8U8
;
70 case WINED3DFMT_R8G8B8A8_SNORM
: return D3DFMT_Q8W8V8U8
;
71 case WINED3DFMT_R16G16_SNORM
: return D3DFMT_V16U16
;
72 case WINED3DFMT_R10G11B11_SNORM
: return D3DFMT_W11V11U10
;
73 case WINED3DFMT_R10G10B10_SNORM_A2_UNORM
: return D3DFMT_A2W10V10U10
;
74 case WINED3DFMT_D16_LOCKABLE
: return D3DFMT_D16_LOCKABLE
;
75 case WINED3DFMT_D32_UNORM
: return D3DFMT_D32
;
76 case WINED3DFMT_S1_UINT_D15_UNORM
: return D3DFMT_D15S1
;
77 case WINED3DFMT_S8_UINT_D24_UNORM
: return D3DFMT_D24S8
;
78 case WINED3DFMT_X8D24_UNORM
: return D3DFMT_D24X8
;
79 case WINED3DFMT_S4X4_UINT_D24_UNORM
: return D3DFMT_D24X4S4
;
80 case WINED3DFMT_D16_UNORM
: return D3DFMT_D16
;
81 case WINED3DFMT_VERTEXDATA
: return D3DFMT_VERTEXDATA
;
82 case WINED3DFMT_R16_UINT
: return D3DFMT_INDEX16
;
83 case WINED3DFMT_R32_UINT
: return D3DFMT_INDEX32
;
85 FIXME("Unhandled WINED3DFORMAT %#x\n", format
);
86 return D3DFMT_UNKNOWN
;
90 WINED3DFORMAT
wined3dformat_from_d3dformat(D3DFORMAT format
)
92 BYTE
*c
= (BYTE
*)&format
;
94 /* Don't translate FOURCC formats */
95 if (isprint(c
[0]) && isprint(c
[1]) && isprint(c
[2]) && isprint(c
[3])) return format
;
99 case D3DFMT_UNKNOWN
: return WINED3DFMT_UNKNOWN
;
100 case D3DFMT_R8G8B8
: return WINED3DFMT_B8G8R8_UNORM
;
101 case D3DFMT_A8R8G8B8
: return WINED3DFMT_B8G8R8A8_UNORM
;
102 case D3DFMT_X8R8G8B8
: return WINED3DFMT_B8G8R8X8_UNORM
;
103 case D3DFMT_R5G6B5
: return WINED3DFMT_B5G6R5_UNORM
;
104 case D3DFMT_X1R5G5B5
: return WINED3DFMT_B5G5R5X1_UNORM
;
105 case D3DFMT_A1R5G5B5
: return WINED3DFMT_B5G5R5A1_UNORM
;
106 case D3DFMT_A4R4G4B4
: return WINED3DFMT_B4G4R4A4_UNORM
;
107 case D3DFMT_R3G3B2
: return WINED3DFMT_B2G3R3_UNORM
;
108 case D3DFMT_A8
: return WINED3DFMT_A8_UNORM
;
109 case D3DFMT_A8R3G3B2
: return WINED3DFMT_B2G3R3A8_UNORM
;
110 case D3DFMT_X4R4G4B4
: return WINED3DFMT_B4G4R4X4_UNORM
;
111 case D3DFMT_A2B10G10R10
: return WINED3DFMT_R10G10B10A2_UNORM
;
112 case D3DFMT_G16R16
: return WINED3DFMT_R16G16_UNORM
;
113 case D3DFMT_A8P8
: return WINED3DFMT_P8_UINT_A8_UNORM
;
114 case D3DFMT_P8
: return WINED3DFMT_P8_UINT
;
115 case D3DFMT_L8
: return WINED3DFMT_L8_UNORM
;
116 case D3DFMT_A8L8
: return WINED3DFMT_L8A8_UNORM
;
117 case D3DFMT_A4L4
: return WINED3DFMT_L4A4_UNORM
;
118 case D3DFMT_V8U8
: return WINED3DFMT_R8G8_SNORM
;
119 case D3DFMT_L6V5U5
: return WINED3DFMT_R5G5_SNORM_L6_UNORM
;
120 case D3DFMT_X8L8V8U8
: return WINED3DFMT_R8G8_SNORM_L8X8_UNORM
;
121 case D3DFMT_Q8W8V8U8
: return WINED3DFMT_R8G8B8A8_SNORM
;
122 case D3DFMT_V16U16
: return WINED3DFMT_R16G16_SNORM
;
123 case D3DFMT_W11V11U10
: return WINED3DFMT_R10G11B11_SNORM
;
124 case D3DFMT_A2W10V10U10
: return WINED3DFMT_R10G10B10_SNORM_A2_UNORM
;
125 case D3DFMT_D16_LOCKABLE
: return WINED3DFMT_D16_LOCKABLE
;
126 case D3DFMT_D32
: return WINED3DFMT_D32_UNORM
;
127 case D3DFMT_D15S1
: return WINED3DFMT_S1_UINT_D15_UNORM
;
128 case D3DFMT_D24S8
: return WINED3DFMT_S8_UINT_D24_UNORM
;
129 case D3DFMT_D24X8
: return WINED3DFMT_X8D24_UNORM
;
130 case D3DFMT_D24X4S4
: return WINED3DFMT_S4X4_UINT_D24_UNORM
;
131 case D3DFMT_D16
: return WINED3DFMT_D16_UNORM
;
132 case D3DFMT_VERTEXDATA
: return WINED3DFMT_VERTEXDATA
;
133 case D3DFMT_INDEX16
: return WINED3DFMT_R16_UINT
;
134 case D3DFMT_INDEX32
: return WINED3DFMT_R32_UINT
;
136 FIXME("Unhandled D3DFORMAT %#x\n", format
);
137 return WINED3DFMT_UNKNOWN
;
141 static UINT
vertex_count_from_primitive_count(D3DPRIMITIVETYPE primitive_type
, UINT primitive_count
)
143 switch(primitive_type
)
145 case D3DPT_POINTLIST
:
146 return primitive_count
;
149 return primitive_count
* 2;
151 case D3DPT_LINESTRIP
:
152 return primitive_count
+ 1;
154 case D3DPT_TRIANGLELIST
:
155 return primitive_count
* 3;
157 case D3DPT_TRIANGLESTRIP
:
158 case D3DPT_TRIANGLEFAN
:
159 return primitive_count
+ 2;
162 FIXME("Unhandled primitive type %#x\n", primitive_type
);
167 /* Handle table functions */
168 static DWORD
d3d8_allocate_handle(struct d3d8_handle_table
*t
, void *object
, enum d3d8_handle_type type
)
170 struct d3d8_handle_entry
*entry
;
174 /* Use a free handle */
175 entry
= t
->free_entries
;
176 if (entry
->type
!= D3D8_HANDLE_FREE
)
178 ERR("Handle %u(%p) is in the free list, but has type %#x.\n", (entry
- t
->entries
), entry
, entry
->type
);
179 return D3D8_INVALID_HANDLE
;
181 t
->free_entries
= entry
->object
;
182 entry
->object
= object
;
185 return entry
- t
->entries
;
188 if (!(t
->entry_count
< t
->table_size
))
191 UINT new_size
= t
->table_size
+ (t
->table_size
>> 1);
192 struct d3d8_handle_entry
*new_entries
= HeapReAlloc(GetProcessHeap(),
193 0, t
->entries
, new_size
* sizeof(*t
->entries
));
196 ERR("Failed to grow the handle table.\n");
197 return D3D8_INVALID_HANDLE
;
199 t
->entries
= new_entries
;
200 t
->table_size
= new_size
;
203 entry
= &t
->entries
[t
->entry_count
];
204 entry
->object
= object
;
207 return t
->entry_count
++;
210 static void *d3d8_free_handle(struct d3d8_handle_table
*t
, DWORD handle
, enum d3d8_handle_type type
)
212 struct d3d8_handle_entry
*entry
;
215 if (handle
== D3D8_INVALID_HANDLE
|| handle
>= t
->entry_count
)
217 WARN("Invalid handle %u passed.\n", handle
);
221 entry
= &t
->entries
[handle
];
222 if (entry
->type
!= type
)
224 WARN("Handle %u(%p) is not of type %#x.\n", handle
, entry
, type
);
228 object
= entry
->object
;
229 entry
->object
= t
->free_entries
;
230 entry
->type
= D3D8_HANDLE_FREE
;
231 t
->free_entries
= entry
;
236 static void *d3d8_get_object(struct d3d8_handle_table
*t
, DWORD handle
, enum d3d8_handle_type type
)
238 struct d3d8_handle_entry
*entry
;
240 if (handle
== D3D8_INVALID_HANDLE
|| handle
>= t
->entry_count
)
242 WARN("Invalid handle %u passed.\n", handle
);
246 entry
= &t
->entries
[handle
];
247 if (entry
->type
!= type
)
249 WARN("Handle %u(%p) is not of type %#x.\n", handle
, entry
, type
);
253 return entry
->object
;
256 /* IDirect3D IUnknown parts follow: */
257 static HRESULT WINAPI
IDirect3DDevice8Impl_QueryInterface(LPDIRECT3DDEVICE8 iface
,REFIID riid
,LPVOID
*ppobj
)
259 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
261 if (IsEqualGUID(riid
, &IID_IUnknown
)
262 || IsEqualGUID(riid
, &IID_IDirect3DDevice8
)) {
263 IUnknown_AddRef(iface
);
268 if (IsEqualGUID(riid
, &IID_IWineD3DDeviceParent
))
270 IUnknown_AddRef((IUnknown
*)&This
->device_parent_vtbl
);
271 *ppobj
= &This
->device_parent_vtbl
;
275 WARN("(%p)->(%s,%p),not found\n", This
, debugstr_guid(riid
), ppobj
);
277 return E_NOINTERFACE
;
280 static ULONG WINAPI
IDirect3DDevice8Impl_AddRef(LPDIRECT3DDEVICE8 iface
) {
281 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
282 ULONG ref
= InterlockedIncrement(&This
->ref
);
284 TRACE("(%p) : AddRef from %d\n", This
, ref
- 1);
289 static ULONG WINAPI
IDirect3DDevice8Impl_Release(LPDIRECT3DDEVICE8 iface
) {
290 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
293 if (This
->inDestruction
) return 0;
294 ref
= InterlockedDecrement(&This
->ref
);
296 TRACE("(%p) : ReleaseRef to %d\n", This
, ref
);
301 TRACE("Releasing wined3d device %p\n", This
->WineD3DDevice
);
303 wined3d_mutex_lock();
305 This
->inDestruction
= TRUE
;
307 for(i
= 0; i
< This
->numConvertedDecls
; i
++) {
308 IDirect3DVertexDeclaration8_Release(This
->decls
[i
].decl
);
310 HeapFree(GetProcessHeap(), 0, This
->decls
);
312 IWineD3DDevice_Uninit3D(This
->WineD3DDevice
, D3D8CB_DestroySwapChain
);
313 IWineD3DDevice_Release(This
->WineD3DDevice
);
314 HeapFree(GetProcessHeap(), 0, This
->handle_table
.entries
);
315 HeapFree(GetProcessHeap(), 0, This
);
317 wined3d_mutex_unlock();
322 /* IDirect3DDevice Interface follow: */
323 static HRESULT WINAPI
IDirect3DDevice8Impl_TestCooperativeLevel(LPDIRECT3DDEVICE8 iface
) {
324 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
327 TRACE("(%p) : Relay\n", This
);
329 wined3d_mutex_lock();
330 hr
= IWineD3DDevice_TestCooperativeLevel(This
->WineD3DDevice
);
331 wined3d_mutex_unlock();
336 static UINT WINAPI
IDirect3DDevice8Impl_GetAvailableTextureMem(LPDIRECT3DDEVICE8 iface
) {
337 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
340 TRACE("(%p) Relay\n", This
);
342 wined3d_mutex_lock();
343 hr
= IWineD3DDevice_GetAvailableTextureMem(This
->WineD3DDevice
);
344 wined3d_mutex_unlock();
349 static HRESULT WINAPI
IDirect3DDevice8Impl_ResourceManagerDiscardBytes(LPDIRECT3DDEVICE8 iface
, DWORD Bytes
) {
350 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
353 TRACE("(%p) : Relay bytes(%d)\n", This
, Bytes
);
355 wined3d_mutex_lock();
356 hr
= IWineD3DDevice_EvictManagedResources(This
->WineD3DDevice
);
357 wined3d_mutex_unlock();
362 static HRESULT WINAPI
IDirect3DDevice8Impl_GetDirect3D(LPDIRECT3DDEVICE8 iface
, IDirect3D8
** ppD3D8
) {
363 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
367 TRACE("(%p) Relay\n", This
);
369 if (NULL
== ppD3D8
) {
370 return D3DERR_INVALIDCALL
;
373 wined3d_mutex_lock();
374 hr
= IWineD3DDevice_GetDirect3D(This
->WineD3DDevice
, &pWineD3D
);
375 if (hr
== D3D_OK
&& pWineD3D
!= NULL
)
377 IWineD3D_GetParent(pWineD3D
,(IUnknown
**)ppD3D8
);
378 IWineD3D_Release(pWineD3D
);
380 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
383 wined3d_mutex_unlock();
385 TRACE("(%p) returning %p\n",This
, *ppD3D8
);
390 static HRESULT WINAPI
IDirect3DDevice8Impl_GetDeviceCaps(LPDIRECT3DDEVICE8 iface
, D3DCAPS8
* pCaps
) {
391 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
392 HRESULT hrc
= D3D_OK
;
393 WINED3DCAPS
*pWineCaps
;
395 TRACE("(%p) : Relay pCaps %p\n", This
, pCaps
);
397 return D3DERR_INVALIDCALL
;
399 pWineCaps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WINED3DCAPS
));
400 if(pWineCaps
== NULL
){
401 return D3DERR_INVALIDCALL
; /* well this is what MSDN says to return */
404 wined3d_mutex_lock();
405 hrc
= IWineD3DDevice_GetDeviceCaps(This
->WineD3DDevice
, pWineCaps
);
406 wined3d_mutex_unlock();
408 fixup_caps(pWineCaps
);
409 WINECAPSTOD3D8CAPS(pCaps
, pWineCaps
)
410 HeapFree(GetProcessHeap(), 0, pWineCaps
);
412 TRACE("Returning %p %p\n", This
, pCaps
);
416 static HRESULT WINAPI
IDirect3DDevice8Impl_GetDisplayMode(LPDIRECT3DDEVICE8 iface
, D3DDISPLAYMODE
* pMode
) {
417 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
419 TRACE("(%p) Relay\n", This
);
421 wined3d_mutex_lock();
422 hr
= IWineD3DDevice_GetDisplayMode(This
->WineD3DDevice
, 0, (WINED3DDISPLAYMODE
*) pMode
);
423 wined3d_mutex_unlock();
425 if (SUCCEEDED(hr
)) pMode
->Format
= d3dformat_from_wined3dformat(pMode
->Format
);
430 static HRESULT WINAPI
IDirect3DDevice8Impl_GetCreationParameters(LPDIRECT3DDEVICE8 iface
, D3DDEVICE_CREATION_PARAMETERS
*pParameters
) {
431 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
433 TRACE("(%p) Relay\n", This
);
435 wined3d_mutex_lock();
436 hr
= IWineD3DDevice_GetCreationParameters(This
->WineD3DDevice
, (WINED3DDEVICE_CREATION_PARAMETERS
*) pParameters
);
437 wined3d_mutex_unlock();
442 static HRESULT WINAPI
IDirect3DDevice8Impl_SetCursorProperties(LPDIRECT3DDEVICE8 iface
, UINT XHotSpot
, UINT YHotSpot
, IDirect3DSurface8
* pCursorBitmap
) {
443 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
444 IDirect3DSurface8Impl
*pSurface
= (IDirect3DSurface8Impl
*)pCursorBitmap
;
446 TRACE("(%p) Relay\n", This
);
448 WARN("No cursor bitmap, returning WINED3DERR_INVALIDCALL\n");
449 return WINED3DERR_INVALIDCALL
;
452 wined3d_mutex_lock();
453 hr
= IWineD3DDevice_SetCursorProperties(This
->WineD3DDevice
,XHotSpot
,YHotSpot
,pSurface
->wineD3DSurface
);
454 wined3d_mutex_unlock();
459 static void WINAPI
IDirect3DDevice8Impl_SetCursorPosition(LPDIRECT3DDEVICE8 iface
, UINT XScreenSpace
, UINT YScreenSpace
, DWORD Flags
) {
460 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
461 TRACE("(%p) Relay\n", This
);
463 wined3d_mutex_lock();
464 IWineD3DDevice_SetCursorPosition(This
->WineD3DDevice
, XScreenSpace
, YScreenSpace
, Flags
);
465 wined3d_mutex_unlock();
468 static BOOL WINAPI
IDirect3DDevice8Impl_ShowCursor(LPDIRECT3DDEVICE8 iface
, BOOL bShow
) {
469 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
471 TRACE("(%p) Relay\n", This
);
473 wined3d_mutex_lock();
474 ret
= IWineD3DDevice_ShowCursor(This
->WineD3DDevice
, bShow
);
475 wined3d_mutex_unlock();
480 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE8 iface
, D3DPRESENT_PARAMETERS
* pPresentationParameters
, IDirect3DSwapChain8
** pSwapChain
) {
481 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
482 IDirect3DSwapChain8Impl
* object
;
483 HRESULT hrc
= D3D_OK
;
484 WINED3DPRESENT_PARAMETERS localParameters
;
486 TRACE("(%p) Relay\n", This
);
488 /* Fix the back buffer count */
489 if(pPresentationParameters
->BackBufferCount
== 0) {
490 pPresentationParameters
->BackBufferCount
= 1;
493 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
494 if (NULL
== object
) {
495 FIXME("Allocation of memory failed\n");
497 return D3DERR_OUTOFVIDEOMEMORY
;
500 object
->lpVtbl
= &Direct3DSwapChain8_Vtbl
;
502 /* Allocate an associated WineD3DDevice object */
503 localParameters
.BackBufferWidth
= pPresentationParameters
->BackBufferWidth
;
504 localParameters
.BackBufferHeight
= pPresentationParameters
->BackBufferHeight
;
505 localParameters
.BackBufferFormat
= wined3dformat_from_d3dformat(pPresentationParameters
->BackBufferFormat
);
506 localParameters
.BackBufferCount
= pPresentationParameters
->BackBufferCount
;
507 localParameters
.MultiSampleType
= pPresentationParameters
->MultiSampleType
;
508 localParameters
.MultiSampleQuality
= 0; /* d3d9 only */
509 localParameters
.SwapEffect
= pPresentationParameters
->SwapEffect
;
510 localParameters
.hDeviceWindow
= pPresentationParameters
->hDeviceWindow
;
511 localParameters
.Windowed
= pPresentationParameters
->Windowed
;
512 localParameters
.EnableAutoDepthStencil
= pPresentationParameters
->EnableAutoDepthStencil
;
513 localParameters
.AutoDepthStencilFormat
= wined3dformat_from_d3dformat(pPresentationParameters
->AutoDepthStencilFormat
);
514 localParameters
.Flags
= pPresentationParameters
->Flags
;
515 localParameters
.FullScreen_RefreshRateInHz
= pPresentationParameters
->FullScreen_RefreshRateInHz
;
516 localParameters
.PresentationInterval
= pPresentationParameters
->FullScreen_PresentationInterval
;
517 localParameters
.AutoRestoreDisplayMode
= TRUE
;
519 wined3d_mutex_lock();
520 hrc
= IWineD3DDevice_CreateSwapChain(This
->WineD3DDevice
, &localParameters
,
521 &object
->wineD3DSwapChain
, (IUnknown
*)object
, SURFACE_OPENGL
);
522 wined3d_mutex_unlock();
524 pPresentationParameters
->BackBufferWidth
= localParameters
.BackBufferWidth
;
525 pPresentationParameters
->BackBufferHeight
= localParameters
.BackBufferHeight
;
526 pPresentationParameters
->BackBufferFormat
= d3dformat_from_wined3dformat(localParameters
.BackBufferFormat
);
527 pPresentationParameters
->BackBufferCount
= localParameters
.BackBufferCount
;
528 pPresentationParameters
->MultiSampleType
= localParameters
.MultiSampleType
;
529 pPresentationParameters
->SwapEffect
= localParameters
.SwapEffect
;
530 pPresentationParameters
->hDeviceWindow
= localParameters
.hDeviceWindow
;
531 pPresentationParameters
->Windowed
= localParameters
.Windowed
;
532 pPresentationParameters
->EnableAutoDepthStencil
= localParameters
.EnableAutoDepthStencil
;
533 pPresentationParameters
->AutoDepthStencilFormat
= d3dformat_from_wined3dformat(localParameters
.AutoDepthStencilFormat
);
534 pPresentationParameters
->Flags
= localParameters
.Flags
;
535 pPresentationParameters
->FullScreen_RefreshRateInHz
= localParameters
.FullScreen_RefreshRateInHz
;
536 pPresentationParameters
->FullScreen_PresentationInterval
= localParameters
.PresentationInterval
;
539 FIXME("(%p) call to IWineD3DDevice_CreateSwapChain failed\n", This
);
540 HeapFree(GetProcessHeap(), 0 , object
);
543 IUnknown_AddRef(iface
);
544 object
->parentDevice
= iface
;
545 *pSwapChain
= (IDirect3DSwapChain8
*)object
;
547 TRACE("(%p) returning %p\n", This
, *pSwapChain
);
551 static HRESULT WINAPI
IDirect3DDevice8Impl_Reset(LPDIRECT3DDEVICE8 iface
, D3DPRESENT_PARAMETERS
* pPresentationParameters
) {
552 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
553 WINED3DPRESENT_PARAMETERS localParameters
;
556 TRACE("(%p) Relay pPresentationParameters(%p)\n", This
, pPresentationParameters
);
558 localParameters
.BackBufferWidth
= pPresentationParameters
->BackBufferWidth
;
559 localParameters
.BackBufferHeight
= pPresentationParameters
->BackBufferHeight
;
560 localParameters
.BackBufferFormat
= wined3dformat_from_d3dformat(pPresentationParameters
->BackBufferFormat
);
561 localParameters
.BackBufferCount
= pPresentationParameters
->BackBufferCount
;
562 localParameters
.MultiSampleType
= pPresentationParameters
->MultiSampleType
;
563 localParameters
.MultiSampleQuality
= 0; /* d3d9 only */
564 localParameters
.SwapEffect
= pPresentationParameters
->SwapEffect
;
565 localParameters
.hDeviceWindow
= pPresentationParameters
->hDeviceWindow
;
566 localParameters
.Windowed
= pPresentationParameters
->Windowed
;
567 localParameters
.EnableAutoDepthStencil
= pPresentationParameters
->EnableAutoDepthStencil
;
568 localParameters
.AutoDepthStencilFormat
= wined3dformat_from_d3dformat(pPresentationParameters
->AutoDepthStencilFormat
);
569 localParameters
.Flags
= pPresentationParameters
->Flags
;
570 localParameters
.FullScreen_RefreshRateInHz
= pPresentationParameters
->FullScreen_RefreshRateInHz
;
571 localParameters
.PresentationInterval
= pPresentationParameters
->FullScreen_PresentationInterval
;
572 localParameters
.AutoRestoreDisplayMode
= TRUE
;
574 wined3d_mutex_lock();
575 hr
= IWineD3DDevice_Reset(This
->WineD3DDevice
, &localParameters
);
576 wined3d_mutex_unlock();
578 pPresentationParameters
->BackBufferWidth
= localParameters
.BackBufferWidth
;
579 pPresentationParameters
->BackBufferHeight
= localParameters
.BackBufferHeight
;
580 pPresentationParameters
->BackBufferFormat
= d3dformat_from_wined3dformat(localParameters
.BackBufferFormat
);
581 pPresentationParameters
->BackBufferCount
= localParameters
.BackBufferCount
;
582 pPresentationParameters
->MultiSampleType
= localParameters
.MultiSampleType
;
583 pPresentationParameters
->SwapEffect
= localParameters
.SwapEffect
;
584 pPresentationParameters
->hDeviceWindow
= localParameters
.hDeviceWindow
;
585 pPresentationParameters
->Windowed
= localParameters
.Windowed
;
586 pPresentationParameters
->EnableAutoDepthStencil
= localParameters
.EnableAutoDepthStencil
;
587 pPresentationParameters
->AutoDepthStencilFormat
= d3dformat_from_wined3dformat(localParameters
.AutoDepthStencilFormat
);
588 pPresentationParameters
->Flags
= localParameters
.Flags
;
589 pPresentationParameters
->FullScreen_RefreshRateInHz
= localParameters
.FullScreen_RefreshRateInHz
;
590 pPresentationParameters
->FullScreen_PresentationInterval
= localParameters
.PresentationInterval
;
595 static HRESULT WINAPI
IDirect3DDevice8Impl_Present(LPDIRECT3DDEVICE8 iface
, CONST RECT
* pSourceRect
,CONST RECT
* pDestRect
,HWND hDestWindowOverride
,CONST RGNDATA
* pDirtyRegion
) {
596 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
598 TRACE("(%p) Relay\n", This
);
600 wined3d_mutex_lock();
601 hr
= IWineD3DDevice_Present(This
->WineD3DDevice
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
602 wined3d_mutex_unlock();
607 static HRESULT WINAPI
IDirect3DDevice8Impl_GetBackBuffer(LPDIRECT3DDEVICE8 iface
, UINT BackBuffer
, D3DBACKBUFFER_TYPE Type
, IDirect3DSurface8
** ppBackBuffer
) {
608 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
609 IWineD3DSurface
*retSurface
= NULL
;
612 TRACE("(%p) Relay\n", This
);
614 wined3d_mutex_lock();
615 rc
= IWineD3DDevice_GetBackBuffer(This
->WineD3DDevice
, 0, BackBuffer
, (WINED3DBACKBUFFER_TYPE
) Type
, &retSurface
);
616 if (rc
== D3D_OK
&& NULL
!= retSurface
&& NULL
!= ppBackBuffer
) {
617 IWineD3DSurface_GetParent(retSurface
, (IUnknown
**)ppBackBuffer
);
618 IWineD3DSurface_Release(retSurface
);
620 wined3d_mutex_unlock();
625 static HRESULT WINAPI
IDirect3DDevice8Impl_GetRasterStatus(LPDIRECT3DDEVICE8 iface
, D3DRASTER_STATUS
* pRasterStatus
) {
626 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
628 TRACE("(%p) Relay\n", This
);
630 wined3d_mutex_lock();
631 hr
= IWineD3DDevice_GetRasterStatus(This
->WineD3DDevice
, 0, (WINED3DRASTER_STATUS
*) pRasterStatus
);
632 wined3d_mutex_unlock();
637 static void WINAPI
IDirect3DDevice8Impl_SetGammaRamp(LPDIRECT3DDEVICE8 iface
, DWORD Flags
, CONST D3DGAMMARAMP
* pRamp
) {
638 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
639 TRACE("(%p) Relay\n", This
);
641 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
642 wined3d_mutex_lock();
643 IWineD3DDevice_SetGammaRamp(This
->WineD3DDevice
, 0, Flags
, (CONST WINED3DGAMMARAMP
*) pRamp
);
644 wined3d_mutex_unlock();
647 static void WINAPI
IDirect3DDevice8Impl_GetGammaRamp(LPDIRECT3DDEVICE8 iface
, D3DGAMMARAMP
* pRamp
) {
648 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
649 TRACE("(%p) Relay\n", This
);
651 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
652 wined3d_mutex_lock();
653 IWineD3DDevice_GetGammaRamp(This
->WineD3DDevice
, 0, (WINED3DGAMMARAMP
*) pRamp
);
654 wined3d_mutex_unlock();
657 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateTexture(IDirect3DDevice8
*iface
,
658 UINT width
, UINT height
, UINT levels
, DWORD usage
, D3DFORMAT format
,
659 D3DPOOL pool
, IDirect3DTexture8
**texture
)
661 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
662 IDirect3DTexture8Impl
*object
;
665 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
666 iface
, width
, height
, levels
, usage
, format
, pool
, texture
);
668 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
671 ERR("Failed to allocate texture memory.\n");
672 return D3DERR_OUTOFVIDEOMEMORY
;
675 hr
= texture_init(object
, This
, width
, height
, levels
, usage
, format
, pool
);
678 WARN("Failed to initialize texture, hr %#x.\n", hr
);
679 HeapFree(GetProcessHeap(), 0, object
);
683 TRACE("Created texture %p.\n", object
);
684 *texture
= (IDirect3DTexture8
*)object
;
689 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateVolumeTexture(IDirect3DDevice8
*iface
,
690 UINT width
, UINT height
, UINT depth
, UINT levels
, DWORD usage
, D3DFORMAT format
,
691 D3DPOOL pool
, IDirect3DVolumeTexture8
**texture
)
693 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
694 IDirect3DVolumeTexture8Impl
*object
;
697 TRACE("iface %p, width %u, height %u, depth %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
698 iface
, width
, height
, depth
, levels
, usage
, format
, pool
, texture
);
700 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
703 ERR("Failed to allocate volume texture memory.\n");
704 return D3DERR_OUTOFVIDEOMEMORY
;
707 hr
= volumetexture_init(object
, This
, width
, height
, depth
, levels
, usage
, format
, pool
);
710 WARN("Failed to initialize volume texture, hr %#x.\n", hr
);
711 HeapFree(GetProcessHeap(), 0, object
);
715 TRACE("Created volume texture %p.\n", object
);
716 *texture
= (IDirect3DVolumeTexture8
*)object
;
721 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateCubeTexture(IDirect3DDevice8
*iface
, UINT edge_length
,
722 UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DCubeTexture8
**texture
)
724 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
725 IDirect3DCubeTexture8Impl
*object
;
728 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
729 iface
, edge_length
, levels
, usage
, format
, pool
, texture
);
731 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
734 ERR("Failed to allocate cube texture memory.\n");
735 return D3DERR_OUTOFVIDEOMEMORY
;
738 hr
= cubetexture_init(object
, This
, edge_length
, levels
, usage
, format
, pool
);
741 WARN("Failed to initialize cube texture, hr %#x.\n", hr
);
742 HeapFree(GetProcessHeap(), 0, object
);
746 TRACE("Created cube texture %p.\n", object
);
747 *texture
= (IDirect3DCubeTexture8
*)object
;
752 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateVertexBuffer(IDirect3DDevice8
*iface
, UINT size
, DWORD usage
,
753 DWORD fvf
, D3DPOOL pool
, IDirect3DVertexBuffer8
**buffer
)
755 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
756 IDirect3DVertexBuffer8Impl
*object
;
759 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p.\n",
760 iface
, size
, usage
, fvf
, pool
, buffer
);
762 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
765 ERR("Failed to allocate buffer memory.\n");
766 return D3DERR_OUTOFVIDEOMEMORY
;
769 hr
= vertexbuffer_init(object
, This
, size
, usage
, fvf
, pool
);
772 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr
);
773 HeapFree(GetProcessHeap(), 0, object
);
777 TRACE("Created vertex buffer %p.\n", object
);
778 *buffer
= (IDirect3DVertexBuffer8
*)object
;
783 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateIndexBuffer(IDirect3DDevice8
*iface
, UINT size
, DWORD usage
,
784 D3DFORMAT format
, D3DPOOL pool
, IDirect3DIndexBuffer8
**buffer
)
786 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
787 IDirect3DIndexBuffer8Impl
*object
;
790 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p.\n",
791 iface
, size
, usage
, format
, pool
, buffer
);
793 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
796 ERR("Failed to allocate buffer memory.\n");
797 return D3DERR_OUTOFVIDEOMEMORY
;
800 hr
= indexbuffer_init(object
, This
, size
, usage
, format
, pool
);
803 WARN("Failed to initialize index buffer, hr %#x.\n", hr
);
804 HeapFree(GetProcessHeap(), 0, object
);
808 TRACE("Created index buffer %p.\n", object
);
809 *buffer
= (IDirect3DIndexBuffer8
*)object
;
814 static HRESULT
IDirect3DDevice8Impl_CreateSurface(LPDIRECT3DDEVICE8 iface
, UINT Width
, UINT Height
,
815 D3DFORMAT Format
, BOOL Lockable
, BOOL Discard
, UINT Level
, IDirect3DSurface8
**ppSurface
,
816 UINT Usage
, D3DPOOL Pool
, D3DMULTISAMPLE_TYPE MultiSample
, DWORD MultisampleQuality
)
818 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
819 IDirect3DSurface8Impl
*object
;
822 TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This
, Width
, Height
, Format
, *ppSurface
);
824 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirect3DSurface8Impl
));
827 FIXME("Failed to allocate surface memory.\n");
828 return D3DERR_OUTOFVIDEOMEMORY
;
831 hr
= surface_init(object
, This
, Width
, Height
, Format
, Lockable
, Discard
,
832 Level
, Usage
, Pool
, MultiSample
, MultisampleQuality
);
835 WARN("Failed to initialize surface, hr %#x.\n", hr
);
836 HeapFree(GetProcessHeap(), 0, object
);
840 TRACE("Created surface %p.\n", object
);
841 *ppSurface
= (IDirect3DSurface8
*)object
;
846 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateRenderTarget(LPDIRECT3DDEVICE8 iface
, UINT Width
, UINT Height
, D3DFORMAT Format
, D3DMULTISAMPLE_TYPE MultiSample
, BOOL Lockable
, IDirect3DSurface8
** ppSurface
) {
850 hr
= IDirect3DDevice8Impl_CreateSurface(iface
, Width
, Height
, Format
, Lockable
, FALSE
/* Discard */,
851 0 /* Level */, ppSurface
, D3DUSAGE_RENDERTARGET
, D3DPOOL_DEFAULT
, MultiSample
, 0);
856 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE8 iface
, UINT Width
, UINT Height
, D3DFORMAT Format
, D3DMULTISAMPLE_TYPE MultiSample
, IDirect3DSurface8
** ppSurface
) {
860 /* TODO: Verify that Discard is false */
861 hr
= IDirect3DDevice8Impl_CreateSurface(iface
, Width
, Height
, Format
, TRUE
/* Lockable */, FALSE
,
862 0 /* Level */, ppSurface
, D3DUSAGE_DEPTHSTENCIL
, D3DPOOL_DEFAULT
, MultiSample
, 0);
867 /* IDirect3DDevice8Impl::CreateImageSurface returns surface with pool type SYSTEMMEM */
868 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateImageSurface(LPDIRECT3DDEVICE8 iface
, UINT Width
, UINT Height
, D3DFORMAT Format
, IDirect3DSurface8
** ppSurface
) {
872 hr
= IDirect3DDevice8Impl_CreateSurface(iface
, Width
, Height
, Format
, TRUE
/* Lockable */, FALSE
/* Discard */,
873 0 /* Level */, ppSurface
, 0 /* Usage (undefined/none) */, D3DPOOL_SYSTEMMEM
, D3DMULTISAMPLE_NONE
,
874 0 /* MultisampleQuality */);
879 static HRESULT WINAPI
IDirect3DDevice8Impl_CopyRects(LPDIRECT3DDEVICE8 iface
, IDirect3DSurface8
*pSourceSurface
, CONST RECT
*pSourceRects
, UINT cRects
, IDirect3DSurface8
*pDestinationSurface
, CONST POINT
*pDestPoints
) {
880 IDirect3DSurface8Impl
*Source
= (IDirect3DSurface8Impl
*) pSourceSurface
;
881 IDirect3DSurface8Impl
*Dest
= (IDirect3DSurface8Impl
*) pDestinationSurface
;
883 HRESULT hr
= WINED3D_OK
;
884 WINED3DFORMAT srcFormat
, destFormat
;
885 UINT srcWidth
, destWidth
;
886 UINT srcHeight
, destHeight
;
888 WINED3DSURFACE_DESC winedesc
;
890 TRACE("(%p) pSrcSur=%p, pSourceRects=%p, cRects=%d, pDstSur=%p, pDestPtsArr=%p\n", iface
,
891 pSourceSurface
, pSourceRects
, cRects
, pDestinationSurface
, pDestPoints
);
894 /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the destination texture is in WINED3DPOOL_DEFAULT */
896 wined3d_mutex_lock();
897 IWineD3DSurface_GetDesc(Source
->wineD3DSurface
, &winedesc
);
898 srcFormat
= winedesc
.format
;
899 srcWidth
= winedesc
.width
;
900 srcHeight
= winedesc
.height
;
901 srcSize
= winedesc
.size
;
903 IWineD3DSurface_GetDesc(Dest
->wineD3DSurface
, &winedesc
);
904 destFormat
= winedesc
.format
;
905 destWidth
= winedesc
.width
;
906 destHeight
= winedesc
.height
;
908 /* Check that the source and destination formats match */
909 if (srcFormat
!= destFormat
&& WINED3DFMT_UNKNOWN
!= destFormat
) {
910 WARN("(%p) source %p format must match the dest %p format, returning WINED3DERR_INVALIDCALL\n", iface
, pSourceSurface
, pDestinationSurface
);
911 wined3d_mutex_unlock();
912 return WINED3DERR_INVALIDCALL
;
913 } else if (WINED3DFMT_UNKNOWN
== destFormat
) {
914 TRACE("(%p) : Converting destination surface from WINED3DFMT_UNKNOWN to the source format\n", iface
);
915 IWineD3DSurface_SetFormat(Dest
->wineD3DSurface
, srcFormat
);
916 destFormat
= srcFormat
;
919 /* Quick if complete copy ... */
920 if (cRects
== 0 && pSourceRects
== NULL
&& pDestPoints
== NULL
) {
921 IWineD3DSurface_BltFast(Dest
->wineD3DSurface
, 0, 0, Source
->wineD3DSurface
, NULL
, WINEDDBLTFAST_NOCOLORKEY
);
924 /* Copy rect by rect */
925 if (NULL
!= pSourceRects
&& NULL
!= pDestPoints
) {
926 for (i
= 0; i
< cRects
; ++i
) {
927 IWineD3DSurface_BltFast(Dest
->wineD3DSurface
, pDestPoints
[i
].x
, pDestPoints
[i
].y
, Source
->wineD3DSurface
, &pSourceRects
[i
], WINEDDBLTFAST_NOCOLORKEY
);
930 for (i
= 0; i
< cRects
; ++i
) {
931 IWineD3DSurface_BltFast(Dest
->wineD3DSurface
, 0, 0, Source
->wineD3DSurface
, &pSourceRects
[i
], WINEDDBLTFAST_NOCOLORKEY
);
935 wined3d_mutex_unlock();
940 static HRESULT WINAPI
IDirect3DDevice8Impl_UpdateTexture(LPDIRECT3DDEVICE8 iface
, IDirect3DBaseTexture8
* pSourceTexture
, IDirect3DBaseTexture8
* pDestinationTexture
) {
941 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
943 TRACE("(%p) Relay\n" , This
);
945 wined3d_mutex_lock();
946 hr
= IWineD3DDevice_UpdateTexture(This
->WineD3DDevice
, ((IDirect3DBaseTexture8Impl
*)pSourceTexture
)->wineD3DBaseTexture
, ((IDirect3DBaseTexture8Impl
*)pDestinationTexture
)->wineD3DBaseTexture
);
947 wined3d_mutex_unlock();
952 static HRESULT WINAPI
IDirect3DDevice8Impl_GetFrontBuffer(LPDIRECT3DDEVICE8 iface
, IDirect3DSurface8
* pDestSurface
) {
953 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
954 IDirect3DSurface8Impl
*destSurface
= (IDirect3DSurface8Impl
*)pDestSurface
;
957 TRACE("(%p) Relay\n" , This
);
959 if (pDestSurface
== NULL
) {
960 WARN("(%p) : Caller passed NULL as pDestSurface returning D3DERR_INVALIDCALL\n", This
);
961 return D3DERR_INVALIDCALL
;
964 wined3d_mutex_lock();
965 hr
= IWineD3DDevice_GetFrontBufferData(This
->WineD3DDevice
, 0, destSurface
->wineD3DSurface
);
966 wined3d_mutex_unlock();
971 static HRESULT WINAPI
IDirect3DDevice8Impl_SetRenderTarget(LPDIRECT3DDEVICE8 iface
, IDirect3DSurface8
* pRenderTarget
, IDirect3DSurface8
* pNewZStencil
) {
972 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
973 IDirect3DSurface8Impl
*pSurface
= (IDirect3DSurface8Impl
*)pRenderTarget
;
974 IDirect3DSurface8Impl
*pZSurface
= (IDirect3DSurface8Impl
*)pNewZStencil
;
975 IWineD3DSurface
*original_ds
= NULL
;
977 TRACE("(%p) Relay\n" , This
);
979 wined3d_mutex_lock();
981 hr
= IWineD3DDevice_GetDepthStencilSurface(This
->WineD3DDevice
, &original_ds
);
982 if (hr
== WINED3D_OK
|| hr
== WINED3DERR_NOTFOUND
)
984 hr
= IWineD3DDevice_SetDepthStencilSurface(This
->WineD3DDevice
, pZSurface
? pZSurface
->wineD3DSurface
: NULL
);
985 if (SUCCEEDED(hr
) && pSurface
)
986 hr
= IWineD3DDevice_SetRenderTarget(This
->WineD3DDevice
, 0, pSurface
->wineD3DSurface
);
987 if (FAILED(hr
)) IWineD3DDevice_SetDepthStencilSurface(This
->WineD3DDevice
, original_ds
);
989 if (original_ds
) IWineD3DSurface_Release(original_ds
);
991 wined3d_mutex_unlock();
996 static HRESULT WINAPI
IDirect3DDevice8Impl_GetRenderTarget(LPDIRECT3DDEVICE8 iface
, IDirect3DSurface8
** ppRenderTarget
) {
997 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
999 IWineD3DSurface
*pRenderTarget
;
1001 TRACE("(%p) Relay\n" , This
);
1003 if (ppRenderTarget
== NULL
) {
1004 return D3DERR_INVALIDCALL
;
1007 wined3d_mutex_lock();
1008 hr
= IWineD3DDevice_GetRenderTarget(This
->WineD3DDevice
, 0, &pRenderTarget
);
1010 if (hr
== D3D_OK
&& pRenderTarget
!= NULL
) {
1011 IWineD3DSurface_GetParent(pRenderTarget
,(IUnknown
**)ppRenderTarget
);
1012 IWineD3DSurface_Release(pRenderTarget
);
1014 FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
1015 *ppRenderTarget
= NULL
;
1017 wined3d_mutex_unlock();
1022 static HRESULT WINAPI
IDirect3DDevice8Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE8 iface
, IDirect3DSurface8
** ppZStencilSurface
) {
1023 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1024 HRESULT hr
= D3D_OK
;
1025 IWineD3DSurface
*pZStencilSurface
;
1027 TRACE("(%p) Relay\n" , This
);
1028 if(ppZStencilSurface
== NULL
){
1029 return D3DERR_INVALIDCALL
;
1032 wined3d_mutex_lock();
1033 hr
=IWineD3DDevice_GetDepthStencilSurface(This
->WineD3DDevice
,&pZStencilSurface
);
1034 if (hr
== WINED3D_OK
) {
1035 IWineD3DSurface_GetParent(pZStencilSurface
,(IUnknown
**)ppZStencilSurface
);
1036 IWineD3DSurface_Release(pZStencilSurface
);
1038 if (hr
!= WINED3DERR_NOTFOUND
)
1039 FIXME("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr
);
1040 *ppZStencilSurface
= NULL
;
1042 wined3d_mutex_unlock();
1047 static HRESULT WINAPI
IDirect3DDevice8Impl_BeginScene(LPDIRECT3DDEVICE8 iface
) {
1048 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1050 TRACE("(%p) Relay\n" , This
);
1052 wined3d_mutex_lock();
1053 hr
= IWineD3DDevice_BeginScene(This
->WineD3DDevice
);
1054 wined3d_mutex_unlock();
1059 static HRESULT WINAPI
IDirect3DDevice8Impl_EndScene(LPDIRECT3DDEVICE8 iface
) {
1060 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1062 TRACE("(%p) Relay\n" , This
);
1064 wined3d_mutex_lock();
1065 hr
= IWineD3DDevice_EndScene(This
->WineD3DDevice
);
1066 wined3d_mutex_unlock();
1071 static HRESULT WINAPI
IDirect3DDevice8Impl_Clear(LPDIRECT3DDEVICE8 iface
, DWORD Count
, CONST D3DRECT
* pRects
, DWORD Flags
, D3DCOLOR Color
, float Z
, DWORD Stencil
) {
1072 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1074 TRACE("(%p) Relay\n" , This
);
1076 /* Note: D3DRECT is compatible with WINED3DRECT */
1077 wined3d_mutex_lock();
1078 hr
= IWineD3DDevice_Clear(This
->WineD3DDevice
, Count
, (CONST WINED3DRECT
*) pRects
, Flags
, Color
, Z
, Stencil
);
1079 wined3d_mutex_unlock();
1084 static HRESULT WINAPI
IDirect3DDevice8Impl_SetTransform(LPDIRECT3DDEVICE8 iface
, D3DTRANSFORMSTATETYPE State
, CONST D3DMATRIX
* lpMatrix
) {
1085 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1087 TRACE("(%p) Relay\n" , This
);
1089 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1090 wined3d_mutex_lock();
1091 hr
= IWineD3DDevice_SetTransform(This
->WineD3DDevice
, State
, (CONST WINED3DMATRIX
*) lpMatrix
);
1092 wined3d_mutex_unlock();
1097 static HRESULT WINAPI
IDirect3DDevice8Impl_GetTransform(LPDIRECT3DDEVICE8 iface
, D3DTRANSFORMSTATETYPE State
,D3DMATRIX
* pMatrix
) {
1098 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1100 TRACE("(%p) Relay\n" , This
);
1102 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1103 wined3d_mutex_lock();
1104 hr
= IWineD3DDevice_GetTransform(This
->WineD3DDevice
, State
, (WINED3DMATRIX
*) pMatrix
);
1105 wined3d_mutex_unlock();
1110 static HRESULT WINAPI
IDirect3DDevice8Impl_MultiplyTransform(LPDIRECT3DDEVICE8 iface
, D3DTRANSFORMSTATETYPE State
, CONST D3DMATRIX
* pMatrix
) {
1111 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1113 TRACE("(%p) Relay\n" , This
);
1115 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1116 wined3d_mutex_lock();
1117 hr
= IWineD3DDevice_MultiplyTransform(This
->WineD3DDevice
, State
, (CONST WINED3DMATRIX
*) pMatrix
);
1118 wined3d_mutex_unlock();
1123 static HRESULT WINAPI
IDirect3DDevice8Impl_SetViewport(LPDIRECT3DDEVICE8 iface
, CONST D3DVIEWPORT8
* pViewport
) {
1124 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1126 TRACE("(%p) Relay\n" , This
);
1128 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1129 wined3d_mutex_lock();
1130 hr
= IWineD3DDevice_SetViewport(This
->WineD3DDevice
, (const WINED3DVIEWPORT
*)pViewport
);
1131 wined3d_mutex_unlock();
1136 static HRESULT WINAPI
IDirect3DDevice8Impl_GetViewport(LPDIRECT3DDEVICE8 iface
, D3DVIEWPORT8
* pViewport
) {
1137 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1139 TRACE("(%p) Relay\n" , This
);
1141 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1142 wined3d_mutex_lock();
1143 hr
= IWineD3DDevice_GetViewport(This
->WineD3DDevice
, (WINED3DVIEWPORT
*)pViewport
);
1144 wined3d_mutex_unlock();
1149 static HRESULT WINAPI
IDirect3DDevice8Impl_SetMaterial(LPDIRECT3DDEVICE8 iface
, CONST D3DMATERIAL8
* pMaterial
) {
1150 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1152 TRACE("(%p) Relay\n" , This
);
1154 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1155 wined3d_mutex_lock();
1156 hr
= IWineD3DDevice_SetMaterial(This
->WineD3DDevice
, (const WINED3DMATERIAL
*)pMaterial
);
1157 wined3d_mutex_unlock();
1162 static HRESULT WINAPI
IDirect3DDevice8Impl_GetMaterial(LPDIRECT3DDEVICE8 iface
, D3DMATERIAL8
* pMaterial
) {
1163 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1165 TRACE("(%p) Relay\n" , This
);
1167 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1168 wined3d_mutex_lock();
1169 hr
= IWineD3DDevice_GetMaterial(This
->WineD3DDevice
, (WINED3DMATERIAL
*)pMaterial
);
1170 wined3d_mutex_unlock();
1175 static HRESULT WINAPI
IDirect3DDevice8Impl_SetLight(LPDIRECT3DDEVICE8 iface
, DWORD Index
, CONST D3DLIGHT8
* pLight
) {
1176 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1178 TRACE("(%p) Relay\n" , This
);
1180 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1181 wined3d_mutex_lock();
1182 hr
= IWineD3DDevice_SetLight(This
->WineD3DDevice
, Index
, (const WINED3DLIGHT
*)pLight
);
1183 wined3d_mutex_unlock();
1188 static HRESULT WINAPI
IDirect3DDevice8Impl_GetLight(LPDIRECT3DDEVICE8 iface
, DWORD Index
,D3DLIGHT8
* pLight
) {
1189 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1191 TRACE("(%p) Relay\n" , This
);
1193 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1194 wined3d_mutex_lock();
1195 hr
= IWineD3DDevice_GetLight(This
->WineD3DDevice
, Index
, (WINED3DLIGHT
*)pLight
);
1196 wined3d_mutex_unlock();
1201 static HRESULT WINAPI
IDirect3DDevice8Impl_LightEnable(LPDIRECT3DDEVICE8 iface
, DWORD Index
,BOOL Enable
) {
1202 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1204 TRACE("(%p) Relay\n" , This
);
1206 wined3d_mutex_lock();
1207 hr
= IWineD3DDevice_SetLightEnable(This
->WineD3DDevice
, Index
, Enable
);
1208 wined3d_mutex_unlock();
1213 static HRESULT WINAPI
IDirect3DDevice8Impl_GetLightEnable(LPDIRECT3DDEVICE8 iface
, DWORD Index
,BOOL
* pEnable
) {
1214 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1216 TRACE("(%p) Relay\n" , This
);
1218 wined3d_mutex_lock();
1219 hr
= IWineD3DDevice_GetLightEnable(This
->WineD3DDevice
, Index
, pEnable
);
1220 wined3d_mutex_unlock();
1225 static HRESULT WINAPI
IDirect3DDevice8Impl_SetClipPlane(LPDIRECT3DDEVICE8 iface
, DWORD Index
,CONST
float* pPlane
) {
1226 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1228 TRACE("(%p) Relay\n" , This
);
1230 wined3d_mutex_lock();
1231 hr
= IWineD3DDevice_SetClipPlane(This
->WineD3DDevice
, Index
, pPlane
);
1232 wined3d_mutex_unlock();
1237 static HRESULT WINAPI
IDirect3DDevice8Impl_GetClipPlane(LPDIRECT3DDEVICE8 iface
, DWORD Index
,float* pPlane
) {
1238 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1240 TRACE("(%p) Relay\n" , This
);
1242 wined3d_mutex_lock();
1243 hr
= IWineD3DDevice_GetClipPlane(This
->WineD3DDevice
, Index
, pPlane
);
1244 wined3d_mutex_unlock();
1249 static HRESULT WINAPI
IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface
, D3DRENDERSTATETYPE State
,DWORD Value
) {
1250 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1252 TRACE("(%p) Relay\n" , This
);
1254 wined3d_mutex_lock();
1255 hr
= IWineD3DDevice_SetRenderState(This
->WineD3DDevice
, State
, Value
);
1256 wined3d_mutex_unlock();
1261 static HRESULT WINAPI
IDirect3DDevice8Impl_GetRenderState(LPDIRECT3DDEVICE8 iface
, D3DRENDERSTATETYPE State
,DWORD
* pValue
) {
1262 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1264 TRACE("(%p) Relay\n" , This
);
1266 wined3d_mutex_lock();
1267 hr
= IWineD3DDevice_GetRenderState(This
->WineD3DDevice
, State
, pValue
);
1268 wined3d_mutex_unlock();
1273 static HRESULT WINAPI
IDirect3DDevice8Impl_BeginStateBlock(LPDIRECT3DDEVICE8 iface
) {
1274 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1276 TRACE("(%p)\n", This
);
1278 wined3d_mutex_lock();
1279 hr
= IWineD3DDevice_BeginStateBlock(This
->WineD3DDevice
);
1280 wined3d_mutex_unlock();
1285 static HRESULT WINAPI
IDirect3DDevice8Impl_EndStateBlock(LPDIRECT3DDEVICE8 iface
, DWORD
* pToken
) {
1286 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1288 IWineD3DStateBlock
* wineD3DStateBlock
;
1289 IDirect3DStateBlock8Impl
* object
;
1291 TRACE("(%p) Relay\n", This
);
1293 /* Tell wineD3D to endstateblock before anything else (in case we run out
1294 * of memory later and cause locking problems)
1296 wined3d_mutex_lock();
1297 hr
= IWineD3DDevice_EndStateBlock(This
->WineD3DDevice
, &wineD3DStateBlock
);
1299 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
1300 wined3d_mutex_unlock();
1304 /* allocate a new IDirectD3DStateBlock */
1305 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,sizeof(IDirect3DStateBlock8Impl
));
1307 object
->lpVtbl
= &Direct3DStateBlock8_Vtbl
;
1309 object
->wineD3DStateBlock
= wineD3DStateBlock
;
1311 *pToken
= d3d8_allocate_handle(&This
->handle_table
, object
, D3D8_HANDLE_SB
);
1312 wined3d_mutex_unlock();
1314 if (*pToken
== D3D8_INVALID_HANDLE
)
1316 ERR("Failed to create a handle\n");
1317 IDirect3DStateBlock8_Release((IDirect3DStateBlock8
*)object
);
1322 TRACE("Returning %#x (%p).\n", *pToken
, object
);
1327 static HRESULT WINAPI
IDirect3DDevice8Impl_ApplyStateBlock(LPDIRECT3DDEVICE8 iface
, DWORD Token
) {
1328 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1329 IDirect3DStateBlock8Impl
*pSB
;
1332 TRACE("(%p) %#x Relay\n", This
, Token
);
1334 wined3d_mutex_lock();
1335 pSB
= d3d8_get_object(&This
->handle_table
, Token
- 1, D3D8_HANDLE_SB
);
1338 WARN("Invalid handle (%#x) passed.\n", Token
);
1339 wined3d_mutex_unlock();
1340 return D3DERR_INVALIDCALL
;
1342 hr
= IWineD3DStateBlock_Apply(pSB
->wineD3DStateBlock
);
1343 wined3d_mutex_unlock();
1348 static HRESULT WINAPI
IDirect3DDevice8Impl_CaptureStateBlock(LPDIRECT3DDEVICE8 iface
, DWORD Token
) {
1349 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1350 IDirect3DStateBlock8Impl
*pSB
;
1353 TRACE("(%p) %#x Relay\n", This
, Token
);
1355 wined3d_mutex_lock();
1356 pSB
= d3d8_get_object(&This
->handle_table
, Token
- 1, D3D8_HANDLE_SB
);
1359 WARN("Invalid handle (%#x) passed.\n", Token
);
1360 wined3d_mutex_unlock();
1361 return D3DERR_INVALIDCALL
;
1363 hr
= IWineD3DStateBlock_Capture(pSB
->wineD3DStateBlock
);
1364 wined3d_mutex_unlock();
1369 static HRESULT WINAPI
IDirect3DDevice8Impl_DeleteStateBlock(LPDIRECT3DDEVICE8 iface
, DWORD Token
) {
1370 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1371 IDirect3DStateBlock8Impl
*pSB
;
1373 TRACE("(%p) Relay\n", This
);
1375 wined3d_mutex_lock();
1376 pSB
= d3d8_free_handle(&This
->handle_table
, Token
- 1, D3D8_HANDLE_SB
);
1377 wined3d_mutex_unlock();
1381 WARN("Invalid handle (%#x) passed.\n", Token
);
1382 return D3DERR_INVALIDCALL
;
1385 if (IUnknown_Release((IUnknown
*)pSB
))
1387 ERR("Stateblock %p has references left, this shouldn't happen.\n", pSB
);
1393 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateStateBlock(IDirect3DDevice8
*iface
,
1394 D3DSTATEBLOCKTYPE Type
, DWORD
*handle
)
1396 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1397 IDirect3DStateBlock8Impl
*object
;
1400 TRACE("(%p) Relay\n", This
);
1402 if (Type
!= D3DSBT_ALL
1403 && Type
!= D3DSBT_PIXELSTATE
1404 && Type
!= D3DSBT_VERTEXSTATE
)
1406 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1407 return D3DERR_INVALIDCALL
;
1410 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirect3DStateBlock8Impl
));
1413 ERR("Failed to allocate memory.\n");
1414 return E_OUTOFMEMORY
;
1417 object
->lpVtbl
= &Direct3DStateBlock8_Vtbl
;
1420 wined3d_mutex_lock();
1421 hr
= IWineD3DDevice_CreateStateBlock(This
->WineD3DDevice
, (WINED3DSTATEBLOCKTYPE
)Type
,
1422 &object
->wineD3DStateBlock
, (IUnknown
*)object
);
1425 wined3d_mutex_unlock();
1426 ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr
);
1427 HeapFree(GetProcessHeap(), 0, object
);
1431 *handle
= d3d8_allocate_handle(&This
->handle_table
, object
, D3D8_HANDLE_SB
);
1432 wined3d_mutex_unlock();
1434 if (*handle
== D3D8_INVALID_HANDLE
)
1436 ERR("Failed to allocate a handle.\n");
1437 IDirect3DStateBlock8_Release((IDirect3DStateBlock8
*)object
);
1442 TRACE("Returning %#x (%p).\n", *handle
, object
);
1447 static HRESULT WINAPI
IDirect3DDevice8Impl_SetClipStatus(LPDIRECT3DDEVICE8 iface
, CONST D3DCLIPSTATUS8
* pClipStatus
) {
1448 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1450 TRACE("(%p) Relay\n" , This
);
1451 /* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
1453 wined3d_mutex_lock();
1454 hr
= IWineD3DDevice_SetClipStatus(This
->WineD3DDevice
, (const WINED3DCLIPSTATUS
*)pClipStatus
);
1455 wined3d_mutex_unlock();
1460 static HRESULT WINAPI
IDirect3DDevice8Impl_GetClipStatus(LPDIRECT3DDEVICE8 iface
, D3DCLIPSTATUS8
* pClipStatus
) {
1461 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1463 TRACE("(%p) Relay\n" , This
);
1465 wined3d_mutex_lock();
1466 hr
= IWineD3DDevice_GetClipStatus(This
->WineD3DDevice
, (WINED3DCLIPSTATUS
*)pClipStatus
);
1467 wined3d_mutex_unlock();
1472 static HRESULT WINAPI
IDirect3DDevice8Impl_GetTexture(LPDIRECT3DDEVICE8 iface
, DWORD Stage
,IDirect3DBaseTexture8
** ppTexture
) {
1473 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1474 IWineD3DBaseTexture
*retTexture
;
1477 TRACE("(%p) Relay\n" , This
);
1479 if(ppTexture
== NULL
){
1480 return D3DERR_INVALIDCALL
;
1483 wined3d_mutex_lock();
1484 hr
= IWineD3DDevice_GetTexture(This
->WineD3DDevice
, Stage
, &retTexture
);
1487 WARN("Failed to get texture for stage %u, hr %#x.\n", Stage
, hr
);
1488 wined3d_mutex_unlock();
1495 IWineD3DBaseTexture_GetParent(retTexture
, (IUnknown
**)ppTexture
);
1496 IWineD3DBaseTexture_Release(retTexture
);
1502 wined3d_mutex_unlock();
1507 static HRESULT WINAPI
IDirect3DDevice8Impl_SetTexture(LPDIRECT3DDEVICE8 iface
, DWORD Stage
, IDirect3DBaseTexture8
* pTexture
) {
1508 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1510 TRACE("(%p) Relay %d %p\n" , This
, Stage
, pTexture
);
1512 wined3d_mutex_lock();
1513 hr
= IWineD3DDevice_SetTexture(This
->WineD3DDevice
, Stage
,
1514 pTexture
==NULL
? NULL
: ((IDirect3DBaseTexture8Impl
*)pTexture
)->wineD3DBaseTexture
);
1515 wined3d_mutex_unlock();
1520 static const struct tss_lookup
1527 {FALSE
, WINED3DTSS_FORCE_DWORD
}, /* 0, unused */
1528 {FALSE
, WINED3DTSS_COLOROP
}, /* 1, D3DTSS_COLOROP */
1529 {FALSE
, WINED3DTSS_COLORARG1
}, /* 2, D3DTSS_COLORARG1 */
1530 {FALSE
, WINED3DTSS_COLORARG2
}, /* 3, D3DTSS_COLORARG2 */
1531 {FALSE
, WINED3DTSS_ALPHAOP
}, /* 4, D3DTSS_ALPHAOP */
1532 {FALSE
, WINED3DTSS_ALPHAARG1
}, /* 5, D3DTSS_ALPHAARG1 */
1533 {FALSE
, WINED3DTSS_ALPHAARG2
}, /* 6, D3DTSS_ALPHAARG2 */
1534 {FALSE
, WINED3DTSS_BUMPENVMAT00
}, /* 7, D3DTSS_BUMPENVMAT00 */
1535 {FALSE
, WINED3DTSS_BUMPENVMAT01
}, /* 8, D3DTSS_BUMPENVMAT01 */
1536 {FALSE
, WINED3DTSS_BUMPENVMAT10
}, /* 9, D3DTSS_BUMPENVMAT10 */
1537 {FALSE
, WINED3DTSS_BUMPENVMAT11
}, /* 10, D3DTSS_BUMPENVMAT11 */
1538 {FALSE
, WINED3DTSS_TEXCOORDINDEX
}, /* 11, D3DTSS_TEXCOORDINDEX */
1539 {FALSE
, WINED3DTSS_FORCE_DWORD
}, /* 12, unused */
1540 {TRUE
, WINED3DSAMP_ADDRESSU
}, /* 13, D3DTSS_ADDRESSU */
1541 {TRUE
, WINED3DSAMP_ADDRESSV
}, /* 14, D3DTSS_ADDRESSV */
1542 {TRUE
, WINED3DSAMP_BORDERCOLOR
}, /* 15, D3DTSS_BORDERCOLOR */
1543 {TRUE
, WINED3DSAMP_MAGFILTER
}, /* 16, D3DTSS_MAGFILTER */
1544 {TRUE
, WINED3DSAMP_MINFILTER
}, /* 17, D3DTSS_MINFILTER */
1545 {TRUE
, WINED3DSAMP_MIPFILTER
}, /* 18, D3DTSS_MIPFILTER */
1546 {TRUE
, WINED3DSAMP_MIPMAPLODBIAS
}, /* 19, D3DTSS_MIPMAPLODBIAS */
1547 {TRUE
, WINED3DSAMP_MAXMIPLEVEL
}, /* 20, D3DTSS_MAXMIPLEVEL */
1548 {TRUE
, WINED3DSAMP_MAXANISOTROPY
}, /* 21, D3DTSS_MAXANISOTROPY */
1549 {FALSE
, WINED3DTSS_BUMPENVLSCALE
}, /* 22, D3DTSS_BUMPENVLSCALE */
1550 {FALSE
, WINED3DTSS_BUMPENVLOFFSET
}, /* 23, D3DTSS_BUMPENVLOFFSET */
1551 {FALSE
, WINED3DTSS_TEXTURETRANSFORMFLAGS
}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1552 {TRUE
, WINED3DSAMP_ADDRESSW
}, /* 25, D3DTSS_ADDRESSW */
1553 {FALSE
, WINED3DTSS_COLORARG0
}, /* 26, D3DTSS_COLORARG0 */
1554 {FALSE
, WINED3DTSS_ALPHAARG0
}, /* 27, D3DTSS_ALPHAARG0 */
1555 {FALSE
, WINED3DTSS_RESULTARG
}, /* 28, D3DTSS_RESULTARG */
1558 static HRESULT WINAPI
IDirect3DDevice8Impl_GetTextureStageState(LPDIRECT3DDEVICE8 iface
, DWORD Stage
,D3DTEXTURESTAGESTATETYPE Type
,DWORD
* pValue
) {
1559 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1560 const struct tss_lookup
*l
= &tss_lookup
[Type
];
1562 TRACE("(%p) Relay\n" , This
);
1564 wined3d_mutex_lock();
1565 if (l
->sampler_state
) hr
= IWineD3DDevice_GetSamplerState(This
->WineD3DDevice
, Stage
, l
->state
, pValue
);
1566 else hr
= IWineD3DDevice_GetTextureStageState(This
->WineD3DDevice
, Stage
, l
->state
, pValue
);
1567 wined3d_mutex_unlock();
1572 static HRESULT WINAPI
IDirect3DDevice8Impl_SetTextureStageState(LPDIRECT3DDEVICE8 iface
, DWORD Stage
, D3DTEXTURESTAGESTATETYPE Type
, DWORD Value
) {
1573 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1574 const struct tss_lookup
*l
= &tss_lookup
[Type
];
1576 TRACE("(%p) Relay\n" , This
);
1578 wined3d_mutex_lock();
1579 if (l
->sampler_state
) hr
= IWineD3DDevice_SetSamplerState(This
->WineD3DDevice
, Stage
, l
->state
, Value
);
1580 else hr
= IWineD3DDevice_SetTextureStageState(This
->WineD3DDevice
, Stage
, l
->state
, Value
);
1581 wined3d_mutex_unlock();
1586 static HRESULT WINAPI
IDirect3DDevice8Impl_ValidateDevice(LPDIRECT3DDEVICE8 iface
, DWORD
* pNumPasses
) {
1587 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1589 TRACE("(%p) Relay\n" , This
);
1591 wined3d_mutex_lock();
1592 hr
= IWineD3DDevice_ValidateDevice(This
->WineD3DDevice
, pNumPasses
);
1593 wined3d_mutex_unlock();
1598 static HRESULT WINAPI
IDirect3DDevice8Impl_GetInfo(LPDIRECT3DDEVICE8 iface
, DWORD DevInfoID
, void* pDevInfoStruct
, DWORD DevInfoStructSize
) {
1599 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1600 FIXME("(%p) : stub\n", This
);
1604 static HRESULT WINAPI
IDirect3DDevice8Impl_SetPaletteEntries(LPDIRECT3DDEVICE8 iface
, UINT PaletteNumber
, CONST PALETTEENTRY
* pEntries
) {
1605 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1607 TRACE("(%p) Relay\n" , This
);
1609 wined3d_mutex_lock();
1610 hr
= IWineD3DDevice_SetPaletteEntries(This
->WineD3DDevice
, PaletteNumber
, pEntries
);
1611 wined3d_mutex_unlock();
1616 static HRESULT WINAPI
IDirect3DDevice8Impl_GetPaletteEntries(LPDIRECT3DDEVICE8 iface
, UINT PaletteNumber
, PALETTEENTRY
* pEntries
) {
1617 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1619 TRACE("(%p) Relay\n" , This
);
1621 wined3d_mutex_lock();
1622 hr
= IWineD3DDevice_GetPaletteEntries(This
->WineD3DDevice
, PaletteNumber
, pEntries
);
1623 wined3d_mutex_unlock();
1628 static HRESULT WINAPI
IDirect3DDevice8Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface
, UINT PaletteNumber
) {
1629 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1631 TRACE("(%p) Relay\n" , This
);
1633 wined3d_mutex_lock();
1634 hr
= IWineD3DDevice_SetCurrentTexturePalette(This
->WineD3DDevice
, PaletteNumber
);
1635 wined3d_mutex_unlock();
1640 static HRESULT WINAPI
IDirect3DDevice8Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface
, UINT
*PaletteNumber
) {
1641 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1643 TRACE("(%p) Relay\n" , This
);
1645 wined3d_mutex_lock();
1646 hr
= IWineD3DDevice_GetCurrentTexturePalette(This
->WineD3DDevice
, PaletteNumber
);
1647 wined3d_mutex_unlock();
1652 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawPrimitive(IDirect3DDevice8
*iface
, D3DPRIMITIVETYPE PrimitiveType
,
1653 UINT StartVertex
, UINT PrimitiveCount
)
1655 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1657 TRACE("(%p) Relay\n" , This
);
1659 wined3d_mutex_lock();
1660 IWineD3DDevice_SetPrimitiveType(This
->WineD3DDevice
, PrimitiveType
);
1661 hr
= IWineD3DDevice_DrawPrimitive(This
->WineD3DDevice
, StartVertex
,
1662 vertex_count_from_primitive_count(PrimitiveType
, PrimitiveCount
));
1663 wined3d_mutex_unlock();
1668 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE8 iface
, D3DPRIMITIVETYPE PrimitiveType
,
1669 UINT MinVertexIndex
,UINT NumVertices
,UINT startIndex
,UINT primCount
) {
1670 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1672 TRACE("(%p) Relay\n" , This
);
1674 wined3d_mutex_lock();
1675 IWineD3DDevice_SetPrimitiveType(This
->WineD3DDevice
, PrimitiveType
);
1676 hr
= IWineD3DDevice_DrawIndexedPrimitive(This
->WineD3DDevice
, startIndex
,
1677 vertex_count_from_primitive_count(PrimitiveType
, primCount
));
1678 wined3d_mutex_unlock();
1683 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE8 iface
, D3DPRIMITIVETYPE PrimitiveType
,UINT PrimitiveCount
,CONST
void* pVertexStreamZeroData
,UINT VertexStreamZeroStride
) {
1684 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1686 TRACE("(%p) Relay\n" , This
);
1688 wined3d_mutex_lock();
1689 IWineD3DDevice_SetPrimitiveType(This
->WineD3DDevice
, PrimitiveType
);
1690 hr
= IWineD3DDevice_DrawPrimitiveUP(This
->WineD3DDevice
,
1691 vertex_count_from_primitive_count(PrimitiveType
, PrimitiveCount
),
1692 pVertexStreamZeroData
, VertexStreamZeroStride
);
1693 wined3d_mutex_unlock();
1698 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE8 iface
, D3DPRIMITIVETYPE PrimitiveType
,UINT MinVertexIndex
,
1699 UINT NumVertexIndices
,UINT PrimitiveCount
,CONST
void* pIndexData
,
1700 D3DFORMAT IndexDataFormat
,CONST
void* pVertexStreamZeroData
,
1701 UINT VertexStreamZeroStride
) {
1702 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1704 TRACE("(%p) Relay\n" , This
);
1706 wined3d_mutex_lock();
1707 IWineD3DDevice_SetPrimitiveType(This
->WineD3DDevice
, PrimitiveType
);
1708 hr
= IWineD3DDevice_DrawIndexedPrimitiveUP(This
->WineD3DDevice
,
1709 vertex_count_from_primitive_count(PrimitiveType
, PrimitiveCount
), pIndexData
,
1710 wined3dformat_from_d3dformat(IndexDataFormat
), pVertexStreamZeroData
, VertexStreamZeroStride
);
1711 wined3d_mutex_unlock();
1716 static HRESULT WINAPI
IDirect3DDevice8Impl_ProcessVertices(LPDIRECT3DDEVICE8 iface
, UINT SrcStartIndex
,UINT DestIndex
,UINT VertexCount
,IDirect3DVertexBuffer8
* pDestBuffer
,DWORD Flags
) {
1717 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1719 IDirect3DVertexBuffer8Impl
*dest
= (IDirect3DVertexBuffer8Impl
*) pDestBuffer
;
1720 TRACE("(%p) Relay\n" , This
);
1722 wined3d_mutex_lock();
1723 hr
= IWineD3DDevice_ProcessVertices(This
->WineD3DDevice
,SrcStartIndex
, DestIndex
, VertexCount
, dest
->wineD3DVertexBuffer
, NULL
, Flags
, dest
->fvf
);
1724 wined3d_mutex_unlock();
1729 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateVertexShader(IDirect3DDevice8
*iface
,
1730 const DWORD
*declaration
, const DWORD
*byte_code
, DWORD
*shader
, DWORD usage
)
1732 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1733 IDirect3DVertexShader8Impl
*object
;
1734 DWORD shader_handle
;
1738 TRACE("iface %p, declaration %p, byte_code %p, shader %p, usage %#x.\n",
1739 iface
, declaration
, byte_code
, shader
, usage
);
1741 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1744 ERR("Failed to allocate vertex shader memory.\n");
1746 return E_OUTOFMEMORY
;
1749 wined3d_mutex_lock();
1750 handle
= d3d8_allocate_handle(&This
->handle_table
, object
, D3D8_HANDLE_VS
);
1751 wined3d_mutex_unlock();
1752 if (handle
== D3D8_INVALID_HANDLE
)
1754 ERR("Failed to allocate vertex shader handle.\n");
1755 HeapFree(GetProcessHeap(), 0, object
);
1757 return E_OUTOFMEMORY
;
1760 shader_handle
= handle
+ VS_HIGHESTFIXEDFXF
+ 1;
1762 hr
= vertexshader_init(object
, This
, declaration
, byte_code
, shader_handle
, usage
);
1765 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
1766 wined3d_mutex_lock();
1767 d3d8_free_handle(&This
->handle_table
, handle
, D3D8_HANDLE_VS
);
1768 wined3d_mutex_unlock();
1769 HeapFree(GetProcessHeap(), 0, object
);
1774 TRACE("Created vertex shader %p (handle %#x).\n", object
, shader_handle
);
1775 *shader
= shader_handle
;
1780 static IDirect3DVertexDeclaration8Impl
*IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl
*This
, DWORD fvf
)
1782 IDirect3DVertexDeclaration8Impl
*d3d8_declaration
;
1784 int p
, low
, high
; /* deliberately signed */
1785 struct FvfToDecl
*convertedDecls
= This
->decls
;
1787 TRACE("Searching for declaration for fvf %08x... ", fvf
);
1790 high
= This
->numConvertedDecls
- 1;
1791 while(low
<= high
) {
1792 p
= (low
+ high
) >> 1;
1794 if(convertedDecls
[p
].fvf
== fvf
) {
1795 TRACE("found %p\n", convertedDecls
[p
].decl
);
1796 return (IDirect3DVertexDeclaration8Impl
*)convertedDecls
[p
].decl
;
1797 } else if(convertedDecls
[p
].fvf
< fvf
) {
1803 TRACE("not found. Creating and inserting at position %d.\n", low
);
1805 d3d8_declaration
= HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration
));
1806 if (!d3d8_declaration
)
1808 ERR("Memory allocation failed.\n");
1812 hr
= vertexdeclaration_init_fvf(d3d8_declaration
, This
, fvf
);
1815 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr
);
1816 HeapFree(GetProcessHeap(), 0, d3d8_declaration
);
1820 if(This
->declArraySize
== This
->numConvertedDecls
) {
1821 int grow
= This
->declArraySize
/ 2;
1822 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
1823 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
1824 if(!convertedDecls
) {
1825 /* This will destroy it */
1826 IDirect3DVertexDeclaration8_Release((IDirect3DVertexDeclaration8
*)d3d8_declaration
);
1829 This
->decls
= convertedDecls
;
1830 This
->declArraySize
+= grow
;
1833 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
1834 convertedDecls
[low
].decl
= (IDirect3DVertexDeclaration8
*)d3d8_declaration
;
1835 convertedDecls
[low
].fvf
= fvf
;
1836 This
->numConvertedDecls
++;
1838 TRACE("Returning %p. %u decls in array\n", d3d8_declaration
, This
->numConvertedDecls
);
1839 return d3d8_declaration
;
1842 static HRESULT WINAPI
IDirect3DDevice8Impl_SetVertexShader(LPDIRECT3DDEVICE8 iface
, DWORD pShader
) {
1843 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1844 IDirect3DVertexShader8Impl
*shader
;
1847 TRACE("(%p) : Relay\n", This
);
1849 if (VS_HIGHESTFIXEDFXF
>= pShader
) {
1850 TRACE("Setting FVF, %#x\n", pShader
);
1852 wined3d_mutex_lock();
1853 IWineD3DDevice_SetVertexDeclaration(This
->WineD3DDevice
,
1854 IDirect3DDevice8Impl_FindDecl(This
, pShader
)->wined3d_vertex_declaration
);
1855 IWineD3DDevice_SetVertexShader(This
->WineD3DDevice
, NULL
);
1856 wined3d_mutex_unlock();
1861 TRACE("Setting shader\n");
1863 wined3d_mutex_lock();
1864 shader
= d3d8_get_object(&This
->handle_table
, pShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
);
1867 WARN("Invalid handle (%#x) passed.\n", pShader
);
1868 wined3d_mutex_unlock();
1870 return D3DERR_INVALIDCALL
;
1873 hr
= IWineD3DDevice_SetVertexDeclaration(This
->WineD3DDevice
,
1874 ((IDirect3DVertexDeclaration8Impl
*)shader
->vertex_declaration
)->wined3d_vertex_declaration
);
1875 if (SUCCEEDED(hr
)) hr
= IWineD3DDevice_SetVertexShader(This
->WineD3DDevice
, shader
->wineD3DVertexShader
);
1876 wined3d_mutex_unlock();
1878 TRACE("Returning hr %#x\n", hr
);
1883 static HRESULT WINAPI
IDirect3DDevice8Impl_GetVertexShader(LPDIRECT3DDEVICE8 iface
, DWORD
* ppShader
) {
1884 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1885 IWineD3DVertexDeclaration
*wined3d_declaration
;
1886 IDirect3DVertexDeclaration8
*d3d8_declaration
;
1889 TRACE("(%p) : Relay device@%p\n", This
, This
->WineD3DDevice
);
1891 wined3d_mutex_lock();
1892 hrc
= IWineD3DDevice_GetVertexDeclaration(This
->WineD3DDevice
, &wined3d_declaration
);
1895 wined3d_mutex_unlock();
1896 WARN("(%p) : Call to IWineD3DDevice_GetVertexDeclaration failed %#x (device %p)\n",
1897 This
, hrc
, This
->WineD3DDevice
);
1901 if (!wined3d_declaration
)
1903 wined3d_mutex_unlock();
1908 hrc
= IWineD3DVertexDeclaration_GetParent(wined3d_declaration
, (IUnknown
**)&d3d8_declaration
);
1909 IWineD3DVertexDeclaration_Release(wined3d_declaration
);
1910 wined3d_mutex_unlock();
1913 *ppShader
= ((IDirect3DVertexDeclaration8Impl
*)d3d8_declaration
)->shader_handle
;
1914 IDirect3DVertexDeclaration8_Release(d3d8_declaration
);
1917 TRACE("(%p) : returning %#x\n", This
, *ppShader
);
1922 static HRESULT WINAPI
IDirect3DDevice8Impl_DeleteVertexShader(LPDIRECT3DDEVICE8 iface
, DWORD pShader
) {
1923 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1924 IDirect3DVertexShader8Impl
*shader
;
1925 IWineD3DVertexShader
*cur
= NULL
;
1927 TRACE("(%p) : pShader %#x\n", This
, pShader
);
1929 wined3d_mutex_lock();
1930 shader
= d3d8_free_handle(&This
->handle_table
, pShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
);
1933 WARN("Invalid handle (%#x) passed.\n", pShader
);
1934 wined3d_mutex_unlock();
1936 return D3DERR_INVALIDCALL
;
1939 IWineD3DDevice_GetVertexShader(This
->WineD3DDevice
, &cur
);
1943 if (cur
== shader
->wineD3DVertexShader
) IDirect3DDevice8_SetVertexShader(iface
, 0);
1944 IWineD3DVertexShader_Release(cur
);
1947 wined3d_mutex_unlock();
1949 if (IUnknown_Release((IUnknown
*)shader
))
1951 ERR("Shader %p has references left, this shouldn't happen.\n", shader
);
1957 static HRESULT WINAPI
IDirect3DDevice8Impl_SetVertexShaderConstant(LPDIRECT3DDEVICE8 iface
, DWORD Register
, CONST
void* pConstantData
, DWORD ConstantCount
) {
1958 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1960 TRACE("(%p) : Relay\n", This
);
1962 if(Register
+ ConstantCount
> D3D8_MAX_VERTEX_SHADER_CONSTANTF
) {
1963 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
1964 Register
+ ConstantCount
, D3D8_MAX_VERTEX_SHADER_CONSTANTF
);
1965 return D3DERR_INVALIDCALL
;
1968 wined3d_mutex_lock();
1969 hr
= IWineD3DDevice_SetVertexShaderConstantF(This
->WineD3DDevice
, Register
, pConstantData
, ConstantCount
);
1970 wined3d_mutex_unlock();
1975 static HRESULT WINAPI
IDirect3DDevice8Impl_GetVertexShaderConstant(LPDIRECT3DDEVICE8 iface
, DWORD Register
, void* pConstantData
, DWORD ConstantCount
) {
1976 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1978 TRACE("(%p) : Relay\n", This
);
1980 if(Register
+ ConstantCount
> D3D8_MAX_VERTEX_SHADER_CONSTANTF
) {
1981 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
1982 Register
+ ConstantCount
, D3D8_MAX_VERTEX_SHADER_CONSTANTF
);
1983 return D3DERR_INVALIDCALL
;
1986 wined3d_mutex_lock();
1987 hr
= IWineD3DDevice_GetVertexShaderConstantF(This
->WineD3DDevice
, Register
, pConstantData
, ConstantCount
);
1988 wined3d_mutex_unlock();
1993 static HRESULT WINAPI
IDirect3DDevice8Impl_GetVertexShaderDeclaration(LPDIRECT3DDEVICE8 iface
, DWORD pVertexShader
, void* pData
, DWORD
* pSizeOfData
) {
1994 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1995 IDirect3DVertexDeclaration8Impl
*declaration
;
1996 IDirect3DVertexShader8Impl
*shader
;
1998 TRACE("(%p) : pVertexShader 0x%08x, pData %p, *pSizeOfData %u\n", This
, pVertexShader
, pData
, *pSizeOfData
);
2000 wined3d_mutex_lock();
2001 shader
= d3d8_get_object(&This
->handle_table
, pVertexShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
);
2002 wined3d_mutex_unlock();
2006 WARN("Invalid handle (%#x) passed.\n", pVertexShader
);
2007 return D3DERR_INVALIDCALL
;
2009 declaration
= (IDirect3DVertexDeclaration8Impl
*)shader
->vertex_declaration
;
2011 /* If pData is NULL, we just return the required size of the buffer. */
2013 *pSizeOfData
= declaration
->elements_size
;
2017 /* MSDN claims that if *pSizeOfData is smaller than the required size
2018 * we should write the required size and return D3DERR_MOREDATA.
2019 * That's not actually true. */
2020 if (*pSizeOfData
< declaration
->elements_size
) {
2021 return D3DERR_INVALIDCALL
;
2024 CopyMemory(pData
, declaration
->elements
, declaration
->elements_size
);
2029 static HRESULT WINAPI
IDirect3DDevice8Impl_GetVertexShaderFunction(LPDIRECT3DDEVICE8 iface
, DWORD pVertexShader
, void* pData
, DWORD
* pSizeOfData
) {
2030 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2031 IDirect3DVertexShader8Impl
*shader
= NULL
;
2034 TRACE("(%p) : pVertexShader %#x, pData %p, pSizeOfData %p\n", This
, pVertexShader
, pData
, pSizeOfData
);
2036 wined3d_mutex_lock();
2037 shader
= d3d8_get_object(&This
->handle_table
, pVertexShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
);
2040 WARN("Invalid handle (%#x) passed.\n", pVertexShader
);
2041 wined3d_mutex_unlock();
2043 return D3DERR_INVALIDCALL
;
2046 if (!shader
->wineD3DVertexShader
)
2048 wined3d_mutex_unlock();
2053 hr
= IWineD3DVertexShader_GetFunction(shader
->wineD3DVertexShader
, pData
, pSizeOfData
);
2054 wined3d_mutex_unlock();
2059 static HRESULT WINAPI
IDirect3DDevice8Impl_SetIndices(LPDIRECT3DDEVICE8 iface
, IDirect3DIndexBuffer8
* pIndexData
, UINT baseVertexIndex
) {
2060 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2062 IDirect3DIndexBuffer8Impl
*ib
= (IDirect3DIndexBuffer8Impl
*)pIndexData
;
2063 TRACE("(%p) Relay\n", This
);
2065 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
2066 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
2067 * vertex buffers can't be created to address them with an index that requires the 32nd bit
2068 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
2071 wined3d_mutex_lock();
2072 IWineD3DDevice_SetBaseVertexIndex(This
->WineD3DDevice
, baseVertexIndex
);
2073 hr
= IWineD3DDevice_SetIndexBuffer(This
->WineD3DDevice
,
2074 ib
? ib
->wineD3DIndexBuffer
: NULL
,
2075 ib
? ib
->format
: WINED3DFMT_UNKNOWN
);
2076 wined3d_mutex_unlock();
2081 static HRESULT WINAPI
IDirect3DDevice8Impl_GetIndices(LPDIRECT3DDEVICE8 iface
, IDirect3DIndexBuffer8
** ppIndexData
,UINT
* pBaseVertexIndex
) {
2082 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2083 IWineD3DBuffer
*retIndexData
= NULL
;
2084 HRESULT rc
= D3D_OK
;
2086 TRACE("(%p) Relay\n", This
);
2088 if(ppIndexData
== NULL
){
2089 return D3DERR_INVALIDCALL
;
2092 /* The case from UINT to INT is safe because d3d8 will never set negative values */
2093 wined3d_mutex_lock();
2094 IWineD3DDevice_GetBaseVertexIndex(This
->WineD3DDevice
, (INT
*) pBaseVertexIndex
);
2095 rc
= IWineD3DDevice_GetIndexBuffer(This
->WineD3DDevice
, &retIndexData
);
2096 if (SUCCEEDED(rc
) && retIndexData
) {
2097 IWineD3DBuffer_GetParent(retIndexData
, (IUnknown
**)ppIndexData
);
2098 IWineD3DBuffer_Release(retIndexData
);
2100 if (FAILED(rc
)) FIXME("Call to GetIndices failed\n");
2101 *ppIndexData
= NULL
;
2103 wined3d_mutex_unlock();
2108 static HRESULT WINAPI
IDirect3DDevice8Impl_CreatePixelShader(IDirect3DDevice8
*iface
,
2109 const DWORD
*byte_code
, DWORD
*shader
)
2111 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2112 IDirect3DPixelShader8Impl
*object
;
2113 DWORD shader_handle
;
2117 TRACE("iface %p, byte_code %p, shader %p.\n", iface
, byte_code
, shader
);
2121 TRACE("(%p) Invalid call\n", This
);
2122 return D3DERR_INVALIDCALL
;
2125 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2128 ERR("Failed to allocate pixel shader memmory.\n");
2129 return E_OUTOFMEMORY
;
2132 wined3d_mutex_lock();
2133 handle
= d3d8_allocate_handle(&This
->handle_table
, object
, D3D8_HANDLE_PS
);
2134 wined3d_mutex_unlock();
2135 if (handle
== D3D8_INVALID_HANDLE
)
2137 ERR("Failed to allocate pixel shader handle.\n");
2138 HeapFree(GetProcessHeap(), 0, object
);
2139 return E_OUTOFMEMORY
;
2142 shader_handle
= handle
+ VS_HIGHESTFIXEDFXF
+ 1;
2144 hr
= pixelshader_init(object
, This
, byte_code
, shader_handle
);
2147 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
2148 wined3d_mutex_lock();
2149 d3d8_free_handle(&This
->handle_table
, handle
, D3D8_HANDLE_PS
);
2150 wined3d_mutex_unlock();
2151 HeapFree(GetProcessHeap(), 0, object
);
2156 TRACE("Created pixel shader %p (handle %#x).\n", object
, shader_handle
);
2157 *shader
= shader_handle
;
2162 static HRESULT WINAPI
IDirect3DDevice8Impl_SetPixelShader(LPDIRECT3DDEVICE8 iface
, DWORD pShader
) {
2163 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2164 IDirect3DPixelShader8Impl
*shader
;
2167 TRACE("(%p) : pShader %#x\n", This
, pShader
);
2169 wined3d_mutex_lock();
2173 hr
= IWineD3DDevice_SetPixelShader(This
->WineD3DDevice
, NULL
);
2174 wined3d_mutex_unlock();
2178 shader
= d3d8_get_object(&This
->handle_table
, pShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
);
2181 WARN("Invalid handle (%#x) passed.\n", pShader
);
2182 wined3d_mutex_unlock();
2183 return D3DERR_INVALIDCALL
;
2186 TRACE("(%p) : Setting shader %p\n", This
, shader
);
2187 hr
= IWineD3DDevice_SetPixelShader(This
->WineD3DDevice
, shader
->wineD3DPixelShader
);
2188 wined3d_mutex_unlock();
2193 static HRESULT WINAPI
IDirect3DDevice8Impl_GetPixelShader(LPDIRECT3DDEVICE8 iface
, DWORD
* ppShader
) {
2194 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2195 IWineD3DPixelShader
*object
;
2197 HRESULT hrc
= D3D_OK
;
2198 TRACE("(%p) Relay\n", This
);
2199 if (NULL
== ppShader
) {
2200 TRACE("(%p) Invalid call\n", This
);
2201 return D3DERR_INVALIDCALL
;
2204 wined3d_mutex_lock();
2205 hrc
= IWineD3DDevice_GetPixelShader(This
->WineD3DDevice
, &object
);
2206 if (D3D_OK
== hrc
&& NULL
!= object
) {
2207 IDirect3DPixelShader8Impl
*d3d8_shader
;
2208 hrc
= IWineD3DPixelShader_GetParent(object
, (IUnknown
**)&d3d8_shader
);
2209 IWineD3DPixelShader_Release(object
);
2210 *ppShader
= d3d8_shader
->handle
;
2211 IDirect3DPixelShader8_Release((IDirect3DPixelShader8
*)d3d8_shader
);
2215 wined3d_mutex_unlock();
2217 TRACE("(%p) : returning %#x\n", This
, *ppShader
);
2222 static HRESULT WINAPI
IDirect3DDevice8Impl_DeletePixelShader(LPDIRECT3DDEVICE8 iface
, DWORD pShader
) {
2223 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2224 IDirect3DPixelShader8Impl
*shader
;
2225 IWineD3DPixelShader
*cur
= NULL
;
2227 TRACE("(%p) : pShader %#x\n", This
, pShader
);
2229 wined3d_mutex_lock();
2231 shader
= d3d8_free_handle(&This
->handle_table
, pShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
);
2234 WARN("Invalid handle (%#x) passed.\n", pShader
);
2235 wined3d_mutex_unlock();
2239 IWineD3DDevice_GetPixelShader(This
->WineD3DDevice
, &cur
);
2243 if (cur
== shader
->wineD3DPixelShader
) IDirect3DDevice8_SetPixelShader(iface
, 0);
2244 IWineD3DPixelShader_Release(cur
);
2247 wined3d_mutex_unlock();
2249 if (IUnknown_Release((IUnknown
*)shader
))
2251 ERR("Shader %p has references left, this shouldn't happen.\n", shader
);
2257 static HRESULT WINAPI
IDirect3DDevice8Impl_SetPixelShaderConstant(LPDIRECT3DDEVICE8 iface
, DWORD Register
, CONST
void* pConstantData
, DWORD ConstantCount
) {
2258 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2260 TRACE("(%p) Relay\n", This
);
2262 wined3d_mutex_lock();
2263 hr
= IWineD3DDevice_SetPixelShaderConstantF(This
->WineD3DDevice
, Register
, pConstantData
, ConstantCount
);
2264 wined3d_mutex_unlock();
2269 static HRESULT WINAPI
IDirect3DDevice8Impl_GetPixelShaderConstant(LPDIRECT3DDEVICE8 iface
, DWORD Register
, void* pConstantData
, DWORD ConstantCount
) {
2270 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2272 TRACE("(%p) Relay\n", This
);
2274 wined3d_mutex_lock();
2275 hr
= IWineD3DDevice_GetPixelShaderConstantF(This
->WineD3DDevice
, Register
, pConstantData
, ConstantCount
);
2276 wined3d_mutex_unlock();
2281 static HRESULT WINAPI
IDirect3DDevice8Impl_GetPixelShaderFunction(LPDIRECT3DDEVICE8 iface
, DWORD pPixelShader
, void* pData
, DWORD
* pSizeOfData
) {
2282 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2283 IDirect3DPixelShader8Impl
*shader
= NULL
;
2286 TRACE("(%p) : pPixelShader %#x, pData %p, pSizeOfData %p\n", This
, pPixelShader
, pData
, pSizeOfData
);
2288 wined3d_mutex_lock();
2289 shader
= d3d8_get_object(&This
->handle_table
, pPixelShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
);
2292 WARN("Invalid handle (%#x) passed.\n", pPixelShader
);
2293 wined3d_mutex_unlock();
2295 return D3DERR_INVALIDCALL
;
2298 hr
= IWineD3DPixelShader_GetFunction(shader
->wineD3DPixelShader
, pData
, pSizeOfData
);
2299 wined3d_mutex_unlock();
2304 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawRectPatch(LPDIRECT3DDEVICE8 iface
, UINT Handle
,CONST
float* pNumSegs
,CONST D3DRECTPATCH_INFO
* pRectPatchInfo
) {
2305 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2307 TRACE("(%p) Relay\n", This
);
2309 wined3d_mutex_lock();
2310 hr
= IWineD3DDevice_DrawRectPatch(This
->WineD3DDevice
, Handle
, pNumSegs
, (CONST WINED3DRECTPATCH_INFO
*)pRectPatchInfo
);
2311 wined3d_mutex_unlock();
2316 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawTriPatch(LPDIRECT3DDEVICE8 iface
, UINT Handle
,CONST
float* pNumSegs
,CONST D3DTRIPATCH_INFO
* pTriPatchInfo
) {
2317 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2319 TRACE("(%p) Relay\n", This
);
2321 wined3d_mutex_lock();
2322 hr
= IWineD3DDevice_DrawTriPatch(This
->WineD3DDevice
, Handle
, pNumSegs
, (CONST WINED3DTRIPATCH_INFO
*)pTriPatchInfo
);
2323 wined3d_mutex_unlock();
2328 static HRESULT WINAPI
IDirect3DDevice8Impl_DeletePatch(LPDIRECT3DDEVICE8 iface
, UINT Handle
) {
2329 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2331 TRACE("(%p) Relay\n", This
);
2333 wined3d_mutex_lock();
2334 hr
= IWineD3DDevice_DeletePatch(This
->WineD3DDevice
, Handle
);
2335 wined3d_mutex_unlock();
2340 static HRESULT WINAPI
IDirect3DDevice8Impl_SetStreamSource(LPDIRECT3DDEVICE8 iface
, UINT StreamNumber
,IDirect3DVertexBuffer8
* pStreamData
,UINT Stride
) {
2341 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2343 TRACE("(%p) Relay\n" , This
);
2345 wined3d_mutex_lock();
2346 hr
= IWineD3DDevice_SetStreamSource(This
->WineD3DDevice
, StreamNumber
,
2347 NULL
== pStreamData
? NULL
: ((IDirect3DVertexBuffer8Impl
*)pStreamData
)->wineD3DVertexBuffer
,
2348 0/* Offset in bytes */, Stride
);
2349 wined3d_mutex_unlock();
2354 static HRESULT WINAPI
IDirect3DDevice8Impl_GetStreamSource(LPDIRECT3DDEVICE8 iface
, UINT StreamNumber
,IDirect3DVertexBuffer8
** pStream
,UINT
* pStride
) {
2355 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2356 IWineD3DBuffer
*retStream
= NULL
;
2357 HRESULT rc
= D3D_OK
;
2359 TRACE("(%p) Relay\n" , This
);
2361 if(pStream
== NULL
){
2362 return D3DERR_INVALIDCALL
;
2365 wined3d_mutex_lock();
2366 rc
= IWineD3DDevice_GetStreamSource(This
->WineD3DDevice
, StreamNumber
, &retStream
, 0 /* Offset in bytes */, pStride
);
2367 if (rc
== D3D_OK
&& NULL
!= retStream
) {
2368 IWineD3DBuffer_GetParent(retStream
, (IUnknown
**)pStream
);
2369 IWineD3DBuffer_Release(retStream
);
2372 FIXME("Call to GetStreamSource failed %p\n", pStride
);
2376 wined3d_mutex_unlock();
2382 const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl
=
2384 IDirect3DDevice8Impl_QueryInterface
,
2385 IDirect3DDevice8Impl_AddRef
,
2386 IDirect3DDevice8Impl_Release
,
2387 IDirect3DDevice8Impl_TestCooperativeLevel
,
2388 IDirect3DDevice8Impl_GetAvailableTextureMem
,
2389 IDirect3DDevice8Impl_ResourceManagerDiscardBytes
,
2390 IDirect3DDevice8Impl_GetDirect3D
,
2391 IDirect3DDevice8Impl_GetDeviceCaps
,
2392 IDirect3DDevice8Impl_GetDisplayMode
,
2393 IDirect3DDevice8Impl_GetCreationParameters
,
2394 IDirect3DDevice8Impl_SetCursorProperties
,
2395 IDirect3DDevice8Impl_SetCursorPosition
,
2396 IDirect3DDevice8Impl_ShowCursor
,
2397 IDirect3DDevice8Impl_CreateAdditionalSwapChain
,
2398 IDirect3DDevice8Impl_Reset
,
2399 IDirect3DDevice8Impl_Present
,
2400 IDirect3DDevice8Impl_GetBackBuffer
,
2401 IDirect3DDevice8Impl_GetRasterStatus
,
2402 IDirect3DDevice8Impl_SetGammaRamp
,
2403 IDirect3DDevice8Impl_GetGammaRamp
,
2404 IDirect3DDevice8Impl_CreateTexture
,
2405 IDirect3DDevice8Impl_CreateVolumeTexture
,
2406 IDirect3DDevice8Impl_CreateCubeTexture
,
2407 IDirect3DDevice8Impl_CreateVertexBuffer
,
2408 IDirect3DDevice8Impl_CreateIndexBuffer
,
2409 IDirect3DDevice8Impl_CreateRenderTarget
,
2410 IDirect3DDevice8Impl_CreateDepthStencilSurface
,
2411 IDirect3DDevice8Impl_CreateImageSurface
,
2412 IDirect3DDevice8Impl_CopyRects
,
2413 IDirect3DDevice8Impl_UpdateTexture
,
2414 IDirect3DDevice8Impl_GetFrontBuffer
,
2415 IDirect3DDevice8Impl_SetRenderTarget
,
2416 IDirect3DDevice8Impl_GetRenderTarget
,
2417 IDirect3DDevice8Impl_GetDepthStencilSurface
,
2418 IDirect3DDevice8Impl_BeginScene
,
2419 IDirect3DDevice8Impl_EndScene
,
2420 IDirect3DDevice8Impl_Clear
,
2421 IDirect3DDevice8Impl_SetTransform
,
2422 IDirect3DDevice8Impl_GetTransform
,
2423 IDirect3DDevice8Impl_MultiplyTransform
,
2424 IDirect3DDevice8Impl_SetViewport
,
2425 IDirect3DDevice8Impl_GetViewport
,
2426 IDirect3DDevice8Impl_SetMaterial
,
2427 IDirect3DDevice8Impl_GetMaterial
,
2428 IDirect3DDevice8Impl_SetLight
,
2429 IDirect3DDevice8Impl_GetLight
,
2430 IDirect3DDevice8Impl_LightEnable
,
2431 IDirect3DDevice8Impl_GetLightEnable
,
2432 IDirect3DDevice8Impl_SetClipPlane
,
2433 IDirect3DDevice8Impl_GetClipPlane
,
2434 IDirect3DDevice8Impl_SetRenderState
,
2435 IDirect3DDevice8Impl_GetRenderState
,
2436 IDirect3DDevice8Impl_BeginStateBlock
,
2437 IDirect3DDevice8Impl_EndStateBlock
,
2438 IDirect3DDevice8Impl_ApplyStateBlock
,
2439 IDirect3DDevice8Impl_CaptureStateBlock
,
2440 IDirect3DDevice8Impl_DeleteStateBlock
,
2441 IDirect3DDevice8Impl_CreateStateBlock
,
2442 IDirect3DDevice8Impl_SetClipStatus
,
2443 IDirect3DDevice8Impl_GetClipStatus
,
2444 IDirect3DDevice8Impl_GetTexture
,
2445 IDirect3DDevice8Impl_SetTexture
,
2446 IDirect3DDevice8Impl_GetTextureStageState
,
2447 IDirect3DDevice8Impl_SetTextureStageState
,
2448 IDirect3DDevice8Impl_ValidateDevice
,
2449 IDirect3DDevice8Impl_GetInfo
,
2450 IDirect3DDevice8Impl_SetPaletteEntries
,
2451 IDirect3DDevice8Impl_GetPaletteEntries
,
2452 IDirect3DDevice8Impl_SetCurrentTexturePalette
,
2453 IDirect3DDevice8Impl_GetCurrentTexturePalette
,
2454 IDirect3DDevice8Impl_DrawPrimitive
,
2455 IDirect3DDevice8Impl_DrawIndexedPrimitive
,
2456 IDirect3DDevice8Impl_DrawPrimitiveUP
,
2457 IDirect3DDevice8Impl_DrawIndexedPrimitiveUP
,
2458 IDirect3DDevice8Impl_ProcessVertices
,
2459 IDirect3DDevice8Impl_CreateVertexShader
,
2460 IDirect3DDevice8Impl_SetVertexShader
,
2461 IDirect3DDevice8Impl_GetVertexShader
,
2462 IDirect3DDevice8Impl_DeleteVertexShader
,
2463 IDirect3DDevice8Impl_SetVertexShaderConstant
,
2464 IDirect3DDevice8Impl_GetVertexShaderConstant
,
2465 IDirect3DDevice8Impl_GetVertexShaderDeclaration
,
2466 IDirect3DDevice8Impl_GetVertexShaderFunction
,
2467 IDirect3DDevice8Impl_SetStreamSource
,
2468 IDirect3DDevice8Impl_GetStreamSource
,
2469 IDirect3DDevice8Impl_SetIndices
,
2470 IDirect3DDevice8Impl_GetIndices
,
2471 IDirect3DDevice8Impl_CreatePixelShader
,
2472 IDirect3DDevice8Impl_SetPixelShader
,
2473 IDirect3DDevice8Impl_GetPixelShader
,
2474 IDirect3DDevice8Impl_DeletePixelShader
,
2475 IDirect3DDevice8Impl_SetPixelShaderConstant
,
2476 IDirect3DDevice8Impl_GetPixelShaderConstant
,
2477 IDirect3DDevice8Impl_GetPixelShaderFunction
,
2478 IDirect3DDevice8Impl_DrawRectPatch
,
2479 IDirect3DDevice8Impl_DrawTriPatch
,
2480 IDirect3DDevice8Impl_DeletePatch
2483 /* IWineD3DDeviceParent IUnknown methods */
2485 static inline struct IDirect3DDevice8Impl
*device_from_device_parent(IWineD3DDeviceParent
*iface
)
2487 return (struct IDirect3DDevice8Impl
*)((char*)iface
2488 - FIELD_OFFSET(struct IDirect3DDevice8Impl
, device_parent_vtbl
));
2491 static HRESULT STDMETHODCALLTYPE
device_parent_QueryInterface(IWineD3DDeviceParent
*iface
, REFIID riid
, void **object
)
2493 struct IDirect3DDevice8Impl
*This
= device_from_device_parent(iface
);
2494 return IDirect3DDevice8Impl_QueryInterface((IDirect3DDevice8
*)This
, riid
, object
);
2497 static ULONG STDMETHODCALLTYPE
device_parent_AddRef(IWineD3DDeviceParent
*iface
)
2499 struct IDirect3DDevice8Impl
*This
= device_from_device_parent(iface
);
2500 return IDirect3DDevice8Impl_AddRef((IDirect3DDevice8
*)This
);
2503 static ULONG STDMETHODCALLTYPE
device_parent_Release(IWineD3DDeviceParent
*iface
)
2505 struct IDirect3DDevice8Impl
*This
= device_from_device_parent(iface
);
2506 return IDirect3DDevice8Impl_Release((IDirect3DDevice8
*)This
);
2509 /* IWineD3DDeviceParent methods */
2511 static void STDMETHODCALLTYPE
device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent
*iface
, IWineD3DDevice
*device
)
2513 TRACE("iface %p, device %p\n", iface
, device
);
2516 static HRESULT STDMETHODCALLTYPE
device_parent_CreateSurface(IWineD3DDeviceParent
*iface
,
2517 IUnknown
*superior
, UINT width
, UINT height
, WINED3DFORMAT format
, DWORD usage
,
2518 WINED3DPOOL pool
, UINT level
, WINED3DCUBEMAP_FACES face
, IWineD3DSurface
**surface
)
2520 struct IDirect3DDevice8Impl
*This
= device_from_device_parent(iface
);
2521 IDirect3DSurface8Impl
*d3d_surface
;
2522 BOOL lockable
= TRUE
;
2525 TRACE("iface %p, superior %p, width %u, height %u, format %#x, usage %#x,\n"
2526 "\tpool %#x, level %u, face %u, surface %p\n",
2527 iface
, superior
, width
, height
, format
, usage
, pool
, level
, face
, surface
);
2530 if (pool
== WINED3DPOOL_DEFAULT
&& !(usage
& WINED3DUSAGE_DYNAMIC
)) lockable
= FALSE
;
2532 hr
= IDirect3DDevice8Impl_CreateSurface((IDirect3DDevice8
*)This
, width
, height
,
2533 d3dformat_from_wined3dformat(format
), lockable
, FALSE
/* Discard */, level
,
2534 (IDirect3DSurface8
**)&d3d_surface
, usage
, pool
, D3DMULTISAMPLE_NONE
, 0 /* MultisampleQuality */);
2537 ERR("(%p) CreateSurface failed, returning %#x\n", iface
, hr
);
2541 *surface
= d3d_surface
->wineD3DSurface
;
2542 IWineD3DSurface_AddRef(*surface
);
2544 d3d_surface
->container
= superior
;
2545 IUnknown_Release(d3d_surface
->parentDevice
);
2546 d3d_surface
->parentDevice
= NULL
;
2548 IDirect3DSurface8_Release((IDirect3DSurface8
*)d3d_surface
);
2549 d3d_surface
->forwardReference
= superior
;
2554 static HRESULT STDMETHODCALLTYPE
device_parent_CreateRenderTarget(IWineD3DDeviceParent
*iface
,
2555 IUnknown
*superior
, UINT width
, UINT height
, WINED3DFORMAT format
, WINED3DMULTISAMPLE_TYPE multisample_type
,
2556 DWORD multisample_quality
, BOOL lockable
, IWineD3DSurface
**surface
)
2558 struct IDirect3DDevice8Impl
*This
= device_from_device_parent(iface
);
2559 IDirect3DSurface8Impl
*d3d_surface
;
2562 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2563 "\tmultisample_quality %u, lockable %u, surface %p\n",
2564 iface
, superior
, width
, height
, format
, multisample_type
, multisample_quality
, lockable
, surface
);
2566 hr
= IDirect3DDevice8_CreateRenderTarget((IDirect3DDevice8
*)This
, width
, height
,
2567 d3dformat_from_wined3dformat(format
), multisample_type
, lockable
, (IDirect3DSurface8
**)&d3d_surface
);
2570 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface
, hr
);
2574 *surface
= d3d_surface
->wineD3DSurface
;
2575 IWineD3DSurface_AddRef(*surface
);
2577 d3d_surface
->container
= (IUnknown
*)This
;
2578 /* Implicit surfaces are created with an refcount of 0 */
2579 IUnknown_Release((IUnknown
*)d3d_surface
);
2584 static HRESULT STDMETHODCALLTYPE
device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent
*iface
,
2585 IUnknown
*superior
, UINT width
, UINT height
, WINED3DFORMAT format
, WINED3DMULTISAMPLE_TYPE multisample_type
,
2586 DWORD multisample_quality
, BOOL discard
, IWineD3DSurface
**surface
)
2588 struct IDirect3DDevice8Impl
*This
= device_from_device_parent(iface
);
2589 IDirect3DSurface8Impl
*d3d_surface
;
2592 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2593 "\tmultisample_quality %u, discard %u, surface %p\n",
2594 iface
, superior
, width
, height
, format
, multisample_type
, multisample_quality
, discard
, surface
);
2596 hr
= IDirect3DDevice8_CreateDepthStencilSurface((IDirect3DDevice8
*)This
, width
, height
,
2597 d3dformat_from_wined3dformat(format
), multisample_type
, (IDirect3DSurface8
**)&d3d_surface
);
2600 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface
, hr
);
2604 *surface
= d3d_surface
->wineD3DSurface
;
2605 IWineD3DSurface_AddRef(*surface
);
2607 d3d_surface
->container
= (IUnknown
*)This
;
2608 /* Implicit surfaces are created with an refcount of 0 */
2609 IUnknown_Release((IUnknown
*)d3d_surface
);
2614 static HRESULT STDMETHODCALLTYPE
device_parent_CreateVolume(IWineD3DDeviceParent
*iface
,
2615 IUnknown
*superior
, UINT width
, UINT height
, UINT depth
, WINED3DFORMAT format
,
2616 WINED3DPOOL pool
, DWORD usage
, IWineD3DVolume
**volume
)
2618 struct IDirect3DDevice8Impl
*This
= device_from_device_parent(iface
);
2619 IDirect3DVolume8Impl
*object
;
2622 TRACE("iface %p, superior %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
2623 iface
, superior
, width
, height
, depth
, format
, pool
, usage
, volume
);
2625 /* Allocate the storage for the device */
2626 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2629 FIXME("Allocation of memory failed\n");
2631 return D3DERR_OUTOFVIDEOMEMORY
;
2634 hr
= volume_init(object
, This
, width
, height
, depth
, usage
, format
, pool
);
2637 WARN("Failed to initialize volume, hr %#x.\n", hr
);
2638 HeapFree(GetProcessHeap(), 0, object
);
2642 *volume
= object
->wineD3DVolume
;
2643 IWineD3DVolume_AddRef(*volume
);
2644 IDirect3DVolume8_Release((IDirect3DVolume8
*)object
);
2646 object
->container
= superior
;
2647 object
->forwardReference
= superior
;
2649 TRACE("(%p) Created volume %p\n", iface
, object
);
2654 static HRESULT STDMETHODCALLTYPE
device_parent_CreateSwapChain(IWineD3DDeviceParent
*iface
,
2655 WINED3DPRESENT_PARAMETERS
*present_parameters
, IWineD3DSwapChain
**swapchain
)
2657 struct IDirect3DDevice8Impl
*This
= device_from_device_parent(iface
);
2658 IDirect3DSwapChain8Impl
*d3d_swapchain
;
2659 D3DPRESENT_PARAMETERS local_parameters
;
2662 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface
, present_parameters
, swapchain
);
2664 /* Copy the presentation parameters */
2665 local_parameters
.BackBufferWidth
= present_parameters
->BackBufferWidth
;
2666 local_parameters
.BackBufferHeight
= present_parameters
->BackBufferHeight
;
2667 local_parameters
.BackBufferFormat
= d3dformat_from_wined3dformat(present_parameters
->BackBufferFormat
);
2668 local_parameters
.BackBufferCount
= present_parameters
->BackBufferCount
;
2669 local_parameters
.MultiSampleType
= present_parameters
->MultiSampleType
;
2670 local_parameters
.SwapEffect
= present_parameters
->SwapEffect
;
2671 local_parameters
.hDeviceWindow
= present_parameters
->hDeviceWindow
;
2672 local_parameters
.Windowed
= present_parameters
->Windowed
;
2673 local_parameters
.EnableAutoDepthStencil
= present_parameters
->EnableAutoDepthStencil
;
2674 local_parameters
.AutoDepthStencilFormat
= d3dformat_from_wined3dformat(present_parameters
->AutoDepthStencilFormat
);
2675 local_parameters
.Flags
= present_parameters
->Flags
;
2676 local_parameters
.FullScreen_RefreshRateInHz
= present_parameters
->FullScreen_RefreshRateInHz
;
2677 local_parameters
.FullScreen_PresentationInterval
= present_parameters
->PresentationInterval
;
2679 hr
= IDirect3DDevice8_CreateAdditionalSwapChain((IDirect3DDevice8
*)This
,
2680 &local_parameters
, (IDirect3DSwapChain8
**)&d3d_swapchain
);
2683 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface
, hr
);
2688 *swapchain
= d3d_swapchain
->wineD3DSwapChain
;
2689 IUnknown_Release(d3d_swapchain
->parentDevice
);
2690 d3d_swapchain
->parentDevice
= NULL
;
2692 /* Copy back the presentation parameters */
2693 present_parameters
->BackBufferWidth
= local_parameters
.BackBufferWidth
;
2694 present_parameters
->BackBufferHeight
= local_parameters
.BackBufferHeight
;
2695 present_parameters
->BackBufferFormat
= wined3dformat_from_d3dformat(local_parameters
.BackBufferFormat
);
2696 present_parameters
->BackBufferCount
= local_parameters
.BackBufferCount
;
2697 present_parameters
->MultiSampleType
= local_parameters
.MultiSampleType
;
2698 present_parameters
->SwapEffect
= local_parameters
.SwapEffect
;
2699 present_parameters
->hDeviceWindow
= local_parameters
.hDeviceWindow
;
2700 present_parameters
->Windowed
= local_parameters
.Windowed
;
2701 present_parameters
->EnableAutoDepthStencil
= local_parameters
.EnableAutoDepthStencil
;
2702 present_parameters
->AutoDepthStencilFormat
= wined3dformat_from_d3dformat(local_parameters
.AutoDepthStencilFormat
);
2703 present_parameters
->Flags
= local_parameters
.Flags
;
2704 present_parameters
->FullScreen_RefreshRateInHz
= local_parameters
.FullScreen_RefreshRateInHz
;
2705 present_parameters
->PresentationInterval
= local_parameters
.FullScreen_PresentationInterval
;
2710 const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl
=
2712 /* IUnknown methods */
2713 device_parent_QueryInterface
,
2714 device_parent_AddRef
,
2715 device_parent_Release
,
2716 /* IWineD3DDeviceParent methods */
2717 device_parent_WineD3DDeviceCreated
,
2718 device_parent_CreateSurface
,
2719 device_parent_CreateRenderTarget
,
2720 device_parent_CreateDepthStencilSurface
,
2721 device_parent_CreateVolume
,
2722 device_parent_CreateSwapChain
,