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(enum wined3d_format_id 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_D24_UNORM_S8_UINT
: 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 wined3d format %#x.\n", format
);
86 return D3DFMT_UNKNOWN
;
90 enum wined3d_format_id
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_D24_UNORM_S8_UINT
;
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 DWORD index
= t
->free_entries
- t
->entries
;
175 /* Use a free handle */
176 entry
= t
->free_entries
;
177 if (entry
->type
!= D3D8_HANDLE_FREE
)
179 ERR("Handle %u(%p) is in the free list, but has type %#x.\n", index
, entry
, entry
->type
);
180 return D3D8_INVALID_HANDLE
;
182 t
->free_entries
= entry
->object
;
183 entry
->object
= object
;
189 if (!(t
->entry_count
< t
->table_size
))
192 UINT new_size
= t
->table_size
+ (t
->table_size
>> 1);
193 struct d3d8_handle_entry
*new_entries
= HeapReAlloc(GetProcessHeap(),
194 0, t
->entries
, new_size
* sizeof(*t
->entries
));
197 ERR("Failed to grow the handle table.\n");
198 return D3D8_INVALID_HANDLE
;
200 t
->entries
= new_entries
;
201 t
->table_size
= new_size
;
204 entry
= &t
->entries
[t
->entry_count
];
205 entry
->object
= object
;
208 return t
->entry_count
++;
211 static void *d3d8_free_handle(struct d3d8_handle_table
*t
, DWORD handle
, enum d3d8_handle_type type
)
213 struct d3d8_handle_entry
*entry
;
216 if (handle
== D3D8_INVALID_HANDLE
|| handle
>= t
->entry_count
)
218 WARN("Invalid handle %u passed.\n", handle
);
222 entry
= &t
->entries
[handle
];
223 if (entry
->type
!= type
)
225 WARN("Handle %u(%p) is not of type %#x.\n", handle
, entry
, type
);
229 object
= entry
->object
;
230 entry
->object
= t
->free_entries
;
231 entry
->type
= D3D8_HANDLE_FREE
;
232 t
->free_entries
= entry
;
237 static void *d3d8_get_object(struct d3d8_handle_table
*t
, DWORD handle
, enum d3d8_handle_type type
)
239 struct d3d8_handle_entry
*entry
;
241 if (handle
== D3D8_INVALID_HANDLE
|| handle
>= t
->entry_count
)
243 WARN("Invalid handle %u passed.\n", handle
);
247 entry
= &t
->entries
[handle
];
248 if (entry
->type
!= type
)
250 WARN("Handle %u(%p) is not of type %#x.\n", handle
, entry
, type
);
254 return entry
->object
;
257 static inline IDirect3DDevice8Impl
*impl_from_IDirect3DDevice8(IDirect3DDevice8
*iface
)
259 return CONTAINING_RECORD(iface
, IDirect3DDevice8Impl
, IDirect3DDevice8_iface
);
262 static HRESULT WINAPI
IDirect3DDevice8Impl_QueryInterface(IDirect3DDevice8
*iface
, REFIID riid
,
265 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
267 TRACE("iface %p, riid %s, object %p.\n",
268 iface
, debugstr_guid(riid
), ppobj
);
270 if (IsEqualGUID(riid
, &IID_IUnknown
)
271 || IsEqualGUID(riid
, &IID_IDirect3DDevice8
)) {
272 IUnknown_AddRef(iface
);
277 if (IsEqualGUID(riid
, &IID_IWineD3DDeviceParent
))
279 IWineD3DDeviceParent_AddRef(&This
->IWineD3DDeviceParent_iface
);
280 *ppobj
= &This
->IWineD3DDeviceParent_iface
;
284 WARN("(%p)->(%s,%p),not found\n", This
, debugstr_guid(riid
), ppobj
);
286 return E_NOINTERFACE
;
289 static ULONG WINAPI
IDirect3DDevice8Impl_AddRef(IDirect3DDevice8
*iface
)
291 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
292 ULONG ref
= InterlockedIncrement(&This
->ref
);
294 TRACE("%p increasing refcount to %u.\n", iface
, ref
);
299 static ULONG WINAPI
IDirect3DDevice8Impl_Release(IDirect3DDevice8
*iface
)
301 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
304 if (This
->inDestruction
) return 0;
305 ref
= InterlockedDecrement(&This
->ref
);
307 TRACE("%p decreasing refcount to %u.\n", iface
, ref
);
312 TRACE("Releasing wined3d device %p\n", This
->WineD3DDevice
);
314 wined3d_mutex_lock();
316 This
->inDestruction
= TRUE
;
318 for(i
= 0; i
< This
->numConvertedDecls
; i
++) {
319 IDirect3DVertexDeclaration8_Release(This
->decls
[i
].decl
);
321 HeapFree(GetProcessHeap(), 0, This
->decls
);
323 IWineD3DDevice_Uninit3D(This
->WineD3DDevice
);
324 IWineD3DDevice_ReleaseFocusWindow(This
->WineD3DDevice
);
325 IWineD3DDevice_Release(This
->WineD3DDevice
);
326 HeapFree(GetProcessHeap(), 0, This
->handle_table
.entries
);
327 HeapFree(GetProcessHeap(), 0, This
);
329 wined3d_mutex_unlock();
334 /* IDirect3DDevice Interface follow: */
335 static HRESULT WINAPI
IDirect3DDevice8Impl_TestCooperativeLevel(IDirect3DDevice8
*iface
)
337 TRACE("iface %p.\n", iface
);
342 static UINT WINAPI
IDirect3DDevice8Impl_GetAvailableTextureMem(IDirect3DDevice8
*iface
)
344 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
347 TRACE("iface %p.\n", iface
);
349 wined3d_mutex_lock();
350 hr
= IWineD3DDevice_GetAvailableTextureMem(This
->WineD3DDevice
);
351 wined3d_mutex_unlock();
356 static HRESULT WINAPI
IDirect3DDevice8Impl_ResourceManagerDiscardBytes(IDirect3DDevice8
*iface
,
359 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
362 TRACE("iface %p, byte_count %u.\n", iface
, Bytes
);
363 FIXME("Byte count ignored.\n");
365 wined3d_mutex_lock();
366 hr
= IWineD3DDevice_EvictManagedResources(This
->WineD3DDevice
);
367 wined3d_mutex_unlock();
372 static HRESULT WINAPI
IDirect3DDevice8Impl_GetDirect3D(IDirect3DDevice8
*iface
, IDirect3D8
**ppD3D8
)
374 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
375 struct wined3d
*wined3d
;
378 TRACE("iface %p, d3d8 %p.\n", iface
, ppD3D8
);
380 if (NULL
== ppD3D8
) {
381 return D3DERR_INVALIDCALL
;
384 wined3d_mutex_lock();
385 hr
= IWineD3DDevice_GetDirect3D(This
->WineD3DDevice
, &wined3d
);
386 if (SUCCEEDED(hr
) && wined3d
)
388 *ppD3D8
= wined3d_get_parent(wined3d
);
389 IDirect3D8_AddRef(*ppD3D8
);
390 wined3d_decref(wined3d
);
394 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
397 wined3d_mutex_unlock();
399 TRACE("(%p) returning %p\n",This
, *ppD3D8
);
404 static HRESULT WINAPI
IDirect3DDevice8Impl_GetDeviceCaps(IDirect3DDevice8
*iface
, D3DCAPS8
*pCaps
)
406 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
407 HRESULT hrc
= D3D_OK
;
408 WINED3DCAPS
*pWineCaps
;
410 TRACE("iface %p, caps %p.\n", iface
, pCaps
);
413 return D3DERR_INVALIDCALL
;
415 pWineCaps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WINED3DCAPS
));
416 if(pWineCaps
== NULL
){
417 return D3DERR_INVALIDCALL
; /* well this is what MSDN says to return */
420 wined3d_mutex_lock();
421 hrc
= IWineD3DDevice_GetDeviceCaps(This
->WineD3DDevice
, pWineCaps
);
422 wined3d_mutex_unlock();
424 fixup_caps(pWineCaps
);
425 WINECAPSTOD3D8CAPS(pCaps
, pWineCaps
)
426 HeapFree(GetProcessHeap(), 0, pWineCaps
);
428 TRACE("Returning %p %p\n", This
, pCaps
);
432 static HRESULT WINAPI
IDirect3DDevice8Impl_GetDisplayMode(IDirect3DDevice8
*iface
,
433 D3DDISPLAYMODE
*pMode
)
435 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
438 TRACE("iface %p, mode %p.\n", iface
, pMode
);
440 wined3d_mutex_lock();
441 hr
= IWineD3DDevice_GetDisplayMode(This
->WineD3DDevice
, 0, (WINED3DDISPLAYMODE
*) pMode
);
442 wined3d_mutex_unlock();
444 if (SUCCEEDED(hr
)) pMode
->Format
= d3dformat_from_wined3dformat(pMode
->Format
);
449 static HRESULT WINAPI
IDirect3DDevice8Impl_GetCreationParameters(IDirect3DDevice8
*iface
,
450 D3DDEVICE_CREATION_PARAMETERS
*pParameters
)
452 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
455 TRACE("iface %p, parameters %p.\n", iface
, pParameters
);
457 wined3d_mutex_lock();
458 hr
= IWineD3DDevice_GetCreationParameters(This
->WineD3DDevice
, (WINED3DDEVICE_CREATION_PARAMETERS
*) pParameters
);
459 wined3d_mutex_unlock();
464 static HRESULT WINAPI
IDirect3DDevice8Impl_SetCursorProperties(IDirect3DDevice8
*iface
,
465 UINT XHotSpot
, UINT YHotSpot
, IDirect3DSurface8
*pCursorBitmap
)
467 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
468 IDirect3DSurface8Impl
*pSurface
= (IDirect3DSurface8Impl
*)pCursorBitmap
;
471 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
472 iface
, XHotSpot
, YHotSpot
, pCursorBitmap
);
476 WARN("No cursor bitmap, returning D3DERR_INVALIDCALL.\n");
477 return D3DERR_INVALIDCALL
;
480 wined3d_mutex_lock();
481 hr
= IWineD3DDevice_SetCursorProperties(This
->WineD3DDevice
,XHotSpot
,YHotSpot
,pSurface
->wineD3DSurface
);
482 wined3d_mutex_unlock();
487 static void WINAPI
IDirect3DDevice8Impl_SetCursorPosition(IDirect3DDevice8
*iface
,
488 UINT XScreenSpace
, UINT YScreenSpace
, DWORD Flags
)
490 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
492 TRACE("iface %p, x %u, y %u, flags %#x.\n",
493 iface
, XScreenSpace
, YScreenSpace
, Flags
);
495 wined3d_mutex_lock();
496 IWineD3DDevice_SetCursorPosition(This
->WineD3DDevice
, XScreenSpace
, YScreenSpace
, Flags
);
497 wined3d_mutex_unlock();
500 static BOOL WINAPI
IDirect3DDevice8Impl_ShowCursor(IDirect3DDevice8
*iface
, BOOL bShow
)
502 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
505 TRACE("iface %p, show %#x.\n", iface
, bShow
);
507 wined3d_mutex_lock();
508 ret
= IWineD3DDevice_ShowCursor(This
->WineD3DDevice
, bShow
);
509 wined3d_mutex_unlock();
514 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateAdditionalSwapChain(IDirect3DDevice8
*iface
,
515 D3DPRESENT_PARAMETERS
*present_parameters
, IDirect3DSwapChain8
**swapchain
)
517 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
518 IDirect3DSwapChain8Impl
*object
;
521 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
522 iface
, present_parameters
, swapchain
);
524 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
527 ERR("Failed to allocate swapchain memory.\n");
528 return E_OUTOFMEMORY
;
531 hr
= swapchain_init(object
, This
, present_parameters
);
534 WARN("Failed to initialize swapchain, hr %#x.\n", hr
);
535 HeapFree(GetProcessHeap(), 0, object
);
539 TRACE("Created swapchain %p.\n", object
);
540 *swapchain
= &object
->IDirect3DSwapChain8_iface
;
545 static HRESULT WINAPI
IDirect3DDevice8Impl_Reset(IDirect3DDevice8
*iface
,
546 D3DPRESENT_PARAMETERS
*pPresentationParameters
)
548 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
549 WINED3DPRESENT_PARAMETERS localParameters
;
552 TRACE("iface %p, present_parameters %p.\n", iface
, pPresentationParameters
);
554 localParameters
.BackBufferWidth
= pPresentationParameters
->BackBufferWidth
;
555 localParameters
.BackBufferHeight
= pPresentationParameters
->BackBufferHeight
;
556 localParameters
.BackBufferFormat
= wined3dformat_from_d3dformat(pPresentationParameters
->BackBufferFormat
);
557 localParameters
.BackBufferCount
= pPresentationParameters
->BackBufferCount
;
558 localParameters
.MultiSampleType
= pPresentationParameters
->MultiSampleType
;
559 localParameters
.MultiSampleQuality
= 0; /* d3d9 only */
560 localParameters
.SwapEffect
= pPresentationParameters
->SwapEffect
;
561 localParameters
.hDeviceWindow
= pPresentationParameters
->hDeviceWindow
;
562 localParameters
.Windowed
= pPresentationParameters
->Windowed
;
563 localParameters
.EnableAutoDepthStencil
= pPresentationParameters
->EnableAutoDepthStencil
;
564 localParameters
.AutoDepthStencilFormat
= wined3dformat_from_d3dformat(pPresentationParameters
->AutoDepthStencilFormat
);
565 localParameters
.Flags
= pPresentationParameters
->Flags
;
566 localParameters
.FullScreen_RefreshRateInHz
= pPresentationParameters
->FullScreen_RefreshRateInHz
;
567 localParameters
.PresentationInterval
= pPresentationParameters
->FullScreen_PresentationInterval
;
568 localParameters
.AutoRestoreDisplayMode
= TRUE
;
570 wined3d_mutex_lock();
571 hr
= IWineD3DDevice_Reset(This
->WineD3DDevice
, &localParameters
);
573 hr
= IWineD3DDevice_SetRenderState(This
->WineD3DDevice
, WINED3DRS_POINTSIZE_MIN
, 0);
575 wined3d_mutex_unlock();
577 pPresentationParameters
->BackBufferWidth
= localParameters
.BackBufferWidth
;
578 pPresentationParameters
->BackBufferHeight
= localParameters
.BackBufferHeight
;
579 pPresentationParameters
->BackBufferFormat
= d3dformat_from_wined3dformat(localParameters
.BackBufferFormat
);
580 pPresentationParameters
->BackBufferCount
= localParameters
.BackBufferCount
;
581 pPresentationParameters
->MultiSampleType
= localParameters
.MultiSampleType
;
582 pPresentationParameters
->SwapEffect
= localParameters
.SwapEffect
;
583 pPresentationParameters
->hDeviceWindow
= localParameters
.hDeviceWindow
;
584 pPresentationParameters
->Windowed
= localParameters
.Windowed
;
585 pPresentationParameters
->EnableAutoDepthStencil
= localParameters
.EnableAutoDepthStencil
;
586 pPresentationParameters
->AutoDepthStencilFormat
= d3dformat_from_wined3dformat(localParameters
.AutoDepthStencilFormat
);
587 pPresentationParameters
->Flags
= localParameters
.Flags
;
588 pPresentationParameters
->FullScreen_RefreshRateInHz
= localParameters
.FullScreen_RefreshRateInHz
;
589 pPresentationParameters
->FullScreen_PresentationInterval
= localParameters
.PresentationInterval
;
594 static HRESULT WINAPI
IDirect3DDevice8Impl_Present(IDirect3DDevice8
*iface
, const RECT
*pSourceRect
,
595 const RECT
*pDestRect
, HWND hDestWindowOverride
, const RGNDATA
*pDirtyRegion
)
597 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
600 TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
601 iface
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
603 wined3d_mutex_lock();
604 hr
= IWineD3DDevice_Present(This
->WineD3DDevice
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
605 wined3d_mutex_unlock();
610 static HRESULT WINAPI
IDirect3DDevice8Impl_GetBackBuffer(IDirect3DDevice8
*iface
,
611 UINT BackBuffer
, D3DBACKBUFFER_TYPE Type
, IDirect3DSurface8
**ppBackBuffer
)
613 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
614 IWineD3DSurface
*retSurface
= NULL
;
617 TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
618 iface
, BackBuffer
, Type
, ppBackBuffer
);
620 wined3d_mutex_lock();
621 hr
= IWineD3DDevice_GetBackBuffer(This
->WineD3DDevice
, 0, BackBuffer
, (WINED3DBACKBUFFER_TYPE
)Type
, &retSurface
);
622 if (SUCCEEDED(hr
) && retSurface
&& ppBackBuffer
)
624 *ppBackBuffer
= IWineD3DSurface_GetParent(retSurface
);
625 IDirect3DSurface8_AddRef(*ppBackBuffer
);
626 IWineD3DSurface_Release(retSurface
);
628 wined3d_mutex_unlock();
633 static HRESULT WINAPI
IDirect3DDevice8Impl_GetRasterStatus(IDirect3DDevice8
*iface
,
634 D3DRASTER_STATUS
*pRasterStatus
)
636 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
639 TRACE("iface %p, raster_status %p.\n", iface
, pRasterStatus
);
641 wined3d_mutex_lock();
642 hr
= IWineD3DDevice_GetRasterStatus(This
->WineD3DDevice
, 0, (WINED3DRASTER_STATUS
*) pRasterStatus
);
643 wined3d_mutex_unlock();
648 static void WINAPI
IDirect3DDevice8Impl_SetGammaRamp(IDirect3DDevice8
*iface
, DWORD Flags
,
649 const D3DGAMMARAMP
*pRamp
)
651 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
653 TRACE("iface %p, flags %#x, ramp %p.\n", iface
, Flags
, pRamp
);
655 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
656 wined3d_mutex_lock();
657 IWineD3DDevice_SetGammaRamp(This
->WineD3DDevice
, 0, Flags
, (CONST WINED3DGAMMARAMP
*) pRamp
);
658 wined3d_mutex_unlock();
661 static void WINAPI
IDirect3DDevice8Impl_GetGammaRamp(IDirect3DDevice8
*iface
, D3DGAMMARAMP
*pRamp
)
663 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
665 TRACE("iface %p, ramp %p.\n", iface
, pRamp
);
667 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
668 wined3d_mutex_lock();
669 IWineD3DDevice_GetGammaRamp(This
->WineD3DDevice
, 0, (WINED3DGAMMARAMP
*) pRamp
);
670 wined3d_mutex_unlock();
673 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateTexture(IDirect3DDevice8
*iface
,
674 UINT width
, UINT height
, UINT levels
, DWORD usage
, D3DFORMAT format
,
675 D3DPOOL pool
, IDirect3DTexture8
**texture
)
677 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
678 IDirect3DTexture8Impl
*object
;
681 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
682 iface
, width
, height
, levels
, usage
, format
, pool
, texture
);
684 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
687 ERR("Failed to allocate texture memory.\n");
688 return D3DERR_OUTOFVIDEOMEMORY
;
691 hr
= texture_init(object
, This
, width
, height
, levels
, usage
, format
, pool
);
694 WARN("Failed to initialize texture, hr %#x.\n", hr
);
695 HeapFree(GetProcessHeap(), 0, object
);
699 TRACE("Created texture %p.\n", object
);
700 *texture
= &object
->IDirect3DTexture8_iface
;
705 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateVolumeTexture(IDirect3DDevice8
*iface
,
706 UINT width
, UINT height
, UINT depth
, UINT levels
, DWORD usage
, D3DFORMAT format
,
707 D3DPOOL pool
, IDirect3DVolumeTexture8
**texture
)
709 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
710 IDirect3DVolumeTexture8Impl
*object
;
713 TRACE("iface %p, width %u, height %u, depth %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
714 iface
, width
, height
, depth
, levels
, usage
, format
, pool
, texture
);
716 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
719 ERR("Failed to allocate volume texture memory.\n");
720 return D3DERR_OUTOFVIDEOMEMORY
;
723 hr
= volumetexture_init(object
, This
, width
, height
, depth
, levels
, usage
, format
, pool
);
726 WARN("Failed to initialize volume texture, hr %#x.\n", hr
);
727 HeapFree(GetProcessHeap(), 0, object
);
731 TRACE("Created volume texture %p.\n", object
);
732 *texture
= &object
->IDirect3DVolumeTexture8_iface
;
737 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateCubeTexture(IDirect3DDevice8
*iface
, UINT edge_length
,
738 UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DCubeTexture8
**texture
)
740 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
741 IDirect3DCubeTexture8Impl
*object
;
744 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
745 iface
, edge_length
, levels
, usage
, format
, pool
, texture
);
747 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
750 ERR("Failed to allocate cube texture memory.\n");
751 return D3DERR_OUTOFVIDEOMEMORY
;
754 hr
= cubetexture_init(object
, This
, edge_length
, levels
, usage
, format
, pool
);
757 WARN("Failed to initialize cube texture, hr %#x.\n", hr
);
758 HeapFree(GetProcessHeap(), 0, object
);
762 TRACE("Created cube texture %p.\n", object
);
763 *texture
= &object
->IDirect3DCubeTexture8_iface
;
768 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateVertexBuffer(IDirect3DDevice8
*iface
, UINT size
,
769 DWORD usage
, DWORD fvf
, D3DPOOL pool
, IDirect3DVertexBuffer8
**buffer
)
771 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
772 IDirect3DVertexBuffer8Impl
*object
;
775 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p.\n",
776 iface
, size
, usage
, fvf
, pool
, buffer
);
778 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
781 ERR("Failed to allocate buffer memory.\n");
782 return D3DERR_OUTOFVIDEOMEMORY
;
785 hr
= vertexbuffer_init(object
, This
, size
, usage
, fvf
, pool
);
788 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr
);
789 HeapFree(GetProcessHeap(), 0, object
);
793 TRACE("Created vertex buffer %p.\n", object
);
794 *buffer
= (IDirect3DVertexBuffer8
*)object
;
799 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateIndexBuffer(IDirect3DDevice8
*iface
, UINT size
,
800 DWORD usage
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DIndexBuffer8
**buffer
)
802 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
803 IDirect3DIndexBuffer8Impl
*object
;
806 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p.\n",
807 iface
, size
, usage
, format
, pool
, buffer
);
809 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
812 ERR("Failed to allocate buffer memory.\n");
813 return D3DERR_OUTOFVIDEOMEMORY
;
816 hr
= indexbuffer_init(object
, This
, size
, usage
, format
, pool
);
819 WARN("Failed to initialize index buffer, hr %#x.\n", hr
);
820 HeapFree(GetProcessHeap(), 0, object
);
824 TRACE("Created index buffer %p.\n", object
);
825 *buffer
= (IDirect3DIndexBuffer8
*)object
;
830 static HRESULT
IDirect3DDevice8Impl_CreateSurface(IDirect3DDevice8Impl
*device
, UINT Width
,
831 UINT Height
, D3DFORMAT Format
, BOOL Lockable
, BOOL Discard
, UINT Level
,
832 IDirect3DSurface8
**ppSurface
, UINT Usage
, D3DPOOL Pool
, D3DMULTISAMPLE_TYPE MultiSample
,
833 DWORD MultisampleQuality
)
835 IDirect3DSurface8Impl
*object
;
838 TRACE("device %p, width %u, height %u, format %#x, lockable %#x, discard %#x, level %u, surface %p,\n"
839 "\tusage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
840 device
, Width
, Height
, Format
, Lockable
, Discard
, Level
, ppSurface
,
841 Usage
, Pool
, MultiSample
, MultisampleQuality
);
843 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirect3DSurface8Impl
));
846 FIXME("Failed to allocate surface memory.\n");
847 return D3DERR_OUTOFVIDEOMEMORY
;
850 hr
= surface_init(object
, device
, Width
, Height
, Format
, Lockable
, Discard
, Level
, Usage
,
851 Pool
, MultiSample
, MultisampleQuality
);
854 WARN("Failed to initialize surface, hr %#x.\n", hr
);
855 HeapFree(GetProcessHeap(), 0, object
);
859 TRACE("Created surface %p.\n", object
);
860 *ppSurface
= (IDirect3DSurface8
*)object
;
865 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateRenderTarget(IDirect3DDevice8
*iface
, UINT Width
,
866 UINT Height
, D3DFORMAT Format
, D3DMULTISAMPLE_TYPE MultiSample
, BOOL Lockable
,
867 IDirect3DSurface8
**ppSurface
)
869 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
872 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, lockable %#x, surface %p.\n",
873 iface
, Width
, Height
, Format
, MultiSample
, Lockable
, ppSurface
);
875 hr
= IDirect3DDevice8Impl_CreateSurface(This
, Width
, Height
, Format
, Lockable
,
876 FALSE
/* Discard */, 0 /* Level */, ppSurface
, D3DUSAGE_RENDERTARGET
, D3DPOOL_DEFAULT
,
882 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateDepthStencilSurface(IDirect3DDevice8
*iface
,
883 UINT Width
, UINT Height
, D3DFORMAT Format
, D3DMULTISAMPLE_TYPE MultiSample
,
884 IDirect3DSurface8
**ppSurface
)
886 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
889 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, surface %p.\n",
890 iface
, Width
, Height
, Format
, MultiSample
, ppSurface
);
892 /* TODO: Verify that Discard is false */
893 hr
= IDirect3DDevice8Impl_CreateSurface(This
, Width
, Height
, Format
, TRUE
/* Lockable */, FALSE
,
894 0 /* Level */, ppSurface
, D3DUSAGE_DEPTHSTENCIL
, D3DPOOL_DEFAULT
, MultiSample
, 0);
899 /* IDirect3DDevice8Impl::CreateImageSurface returns surface with pool type SYSTEMMEM */
900 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateImageSurface(IDirect3DDevice8
*iface
, UINT Width
,
901 UINT Height
, D3DFORMAT Format
, IDirect3DSurface8
**ppSurface
)
903 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
906 TRACE("iface %p, width %u, height %u, format %#x, surface %p.\n",
907 iface
, Width
, Height
, Format
, ppSurface
);
909 hr
= IDirect3DDevice8Impl_CreateSurface(This
, Width
, Height
, Format
, TRUE
/* Lockable */,
910 FALSE
/* Discard */, 0 /* Level */, ppSurface
, 0 /* Usage (undefined/none) */,
911 D3DPOOL_SYSTEMMEM
, D3DMULTISAMPLE_NONE
, 0 /* MultisampleQuality */);
916 static HRESULT WINAPI
IDirect3DDevice8Impl_CopyRects(IDirect3DDevice8
*iface
,
917 IDirect3DSurface8
*pSourceSurface
, const RECT
*pSourceRects
, UINT cRects
,
918 IDirect3DSurface8
*pDestinationSurface
, const POINT
*pDestPoints
)
920 IDirect3DSurface8Impl
*Source
= (IDirect3DSurface8Impl
*) pSourceSurface
;
921 IDirect3DSurface8Impl
*Dest
= (IDirect3DSurface8Impl
*) pDestinationSurface
;
922 enum wined3d_format_id srcFormat
, destFormat
;
923 struct wined3d_resource_desc wined3d_desc
;
924 struct wined3d_resource
*wined3d_resource
;
926 TRACE("iface %p, src_surface %p, src_rects %p, rect_count %u, dst_surface %p, dst_points %p.\n",
927 iface
, pSourceSurface
, pSourceRects
, cRects
, pDestinationSurface
, pDestPoints
);
929 /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the
930 * destination texture is in WINED3DPOOL_DEFAULT. */
932 wined3d_mutex_lock();
933 wined3d_resource
= IWineD3DSurface_GetResource(Source
->wineD3DSurface
);
934 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
935 srcFormat
= wined3d_desc
.format
;
937 wined3d_resource
= IWineD3DSurface_GetResource(Dest
->wineD3DSurface
);
938 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
939 destFormat
= wined3d_desc
.format
;
941 /* Check that the source and destination formats match */
942 if (srcFormat
!= destFormat
&& WINED3DFMT_UNKNOWN
!= destFormat
)
944 WARN("Source %p format must match the dest %p format, returning D3DERR_INVALIDCALL.\n",
945 pSourceSurface
, pDestinationSurface
);
946 wined3d_mutex_unlock();
947 return D3DERR_INVALIDCALL
;
949 else if (WINED3DFMT_UNKNOWN
== destFormat
)
951 TRACE("(%p) : Converting destination surface from WINED3DFMT_UNKNOWN to the source format\n", iface
);
952 IWineD3DSurface_SetFormat(Dest
->wineD3DSurface
, srcFormat
);
955 /* Quick if complete copy ... */
956 if (cRects
== 0 && pSourceRects
== NULL
&& pDestPoints
== NULL
) {
957 IWineD3DSurface_BltFast(Dest
->wineD3DSurface
, 0, 0, Source
->wineD3DSurface
, NULL
, WINEDDBLTFAST_NOCOLORKEY
);
960 /* Copy rect by rect */
961 if (NULL
!= pSourceRects
&& NULL
!= pDestPoints
) {
962 for (i
= 0; i
< cRects
; ++i
) {
963 IWineD3DSurface_BltFast(Dest
->wineD3DSurface
, pDestPoints
[i
].x
, pDestPoints
[i
].y
, Source
->wineD3DSurface
, &pSourceRects
[i
], WINEDDBLTFAST_NOCOLORKEY
);
966 for (i
= 0; i
< cRects
; ++i
) {
967 IWineD3DSurface_BltFast(Dest
->wineD3DSurface
, 0, 0, Source
->wineD3DSurface
, &pSourceRects
[i
], WINEDDBLTFAST_NOCOLORKEY
);
971 wined3d_mutex_unlock();
976 static HRESULT WINAPI
IDirect3DDevice8Impl_UpdateTexture(IDirect3DDevice8
*iface
,
977 IDirect3DBaseTexture8
*src_texture
, IDirect3DBaseTexture8
*dst_texture
)
979 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
982 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface
, src_texture
, dst_texture
);
984 wined3d_mutex_lock();
985 hr
= IWineD3DDevice_UpdateTexture(This
->WineD3DDevice
,
986 ((IDirect3DBaseTexture8Impl
*)src_texture
)->wined3d_texture
,
987 ((IDirect3DBaseTexture8Impl
*)dst_texture
)->wined3d_texture
);
988 wined3d_mutex_unlock();
993 static HRESULT WINAPI
IDirect3DDevice8Impl_GetFrontBuffer(IDirect3DDevice8
*iface
,
994 IDirect3DSurface8
*pDestSurface
)
996 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
997 IDirect3DSurface8Impl
*destSurface
= (IDirect3DSurface8Impl
*)pDestSurface
;
1000 TRACE("iface %p, dst_surface %p.\n", iface
, pDestSurface
);
1002 if (pDestSurface
== NULL
) {
1003 WARN("(%p) : Caller passed NULL as pDestSurface returning D3DERR_INVALIDCALL\n", This
);
1004 return D3DERR_INVALIDCALL
;
1007 wined3d_mutex_lock();
1008 hr
= IWineD3DDevice_GetFrontBufferData(This
->WineD3DDevice
, 0, destSurface
->wineD3DSurface
);
1009 wined3d_mutex_unlock();
1014 static HRESULT WINAPI
IDirect3DDevice8Impl_SetRenderTarget(IDirect3DDevice8
*iface
,
1015 IDirect3DSurface8
*pRenderTarget
, IDirect3DSurface8
*pNewZStencil
)
1017 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1018 IDirect3DSurface8Impl
*pSurface
= (IDirect3DSurface8Impl
*)pRenderTarget
;
1019 IDirect3DSurface8Impl
*pZSurface
= (IDirect3DSurface8Impl
*)pNewZStencil
;
1020 IWineD3DSurface
*original_ds
= NULL
;
1023 TRACE("iface %p, render_target %p, depth_stencil %p.\n", iface
, pRenderTarget
, pNewZStencil
);
1025 wined3d_mutex_lock();
1029 struct wined3d_resource_desc ds_desc
, rt_desc
;
1030 struct wined3d_resource
*wined3d_resource
;
1032 wined3d_resource
= IWineD3DSurface_GetResource(pZSurface
->wineD3DSurface
);
1033 wined3d_resource_get_desc(wined3d_resource
, &ds_desc
);
1034 wined3d_resource
= IWineD3DSurface_GetResource(pSurface
->wineD3DSurface
);
1035 wined3d_resource_get_desc(wined3d_resource
, &rt_desc
);
1037 if (ds_desc
.width
< rt_desc
.width
|| ds_desc
.height
< rt_desc
.height
)
1039 WARN("Depth stencil is smaller than the render target, returning D3DERR_INVALIDCALL\n");
1040 wined3d_mutex_unlock();
1041 return D3DERR_INVALIDCALL
;
1045 hr
= IWineD3DDevice_GetDepthStencilSurface(This
->WineD3DDevice
, &original_ds
);
1046 if (hr
== WINED3D_OK
|| hr
== WINED3DERR_NOTFOUND
)
1048 hr
= IWineD3DDevice_SetDepthStencilSurface(This
->WineD3DDevice
, pZSurface
? pZSurface
->wineD3DSurface
: NULL
);
1049 if (SUCCEEDED(hr
) && pSurface
)
1050 hr
= IWineD3DDevice_SetRenderTarget(This
->WineD3DDevice
, 0, pSurface
->wineD3DSurface
, TRUE
);
1051 if (FAILED(hr
)) IWineD3DDevice_SetDepthStencilSurface(This
->WineD3DDevice
, original_ds
);
1053 if (original_ds
) IWineD3DSurface_Release(original_ds
);
1055 wined3d_mutex_unlock();
1060 static HRESULT WINAPI
IDirect3DDevice8Impl_GetRenderTarget(IDirect3DDevice8
*iface
,
1061 IDirect3DSurface8
**ppRenderTarget
)
1063 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1064 IWineD3DSurface
*pRenderTarget
;
1067 TRACE("iface %p, render_target %p.\n", iface
, ppRenderTarget
);
1069 if (ppRenderTarget
== NULL
) {
1070 return D3DERR_INVALIDCALL
;
1073 wined3d_mutex_lock();
1074 hr
= IWineD3DDevice_GetRenderTarget(This
->WineD3DDevice
, 0, &pRenderTarget
);
1075 if (SUCCEEDED(hr
) && pRenderTarget
)
1077 *ppRenderTarget
= IWineD3DSurface_GetParent(pRenderTarget
);
1078 IDirect3DSurface8_AddRef(*ppRenderTarget
);
1079 IWineD3DSurface_Release(pRenderTarget
);
1083 FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
1084 *ppRenderTarget
= NULL
;
1086 wined3d_mutex_unlock();
1091 static HRESULT WINAPI
IDirect3DDevice8Impl_GetDepthStencilSurface(IDirect3DDevice8
*iface
,
1092 IDirect3DSurface8
**ppZStencilSurface
)
1094 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1095 IWineD3DSurface
*pZStencilSurface
;
1098 TRACE("iface %p, depth_stencil %p.\n", iface
, ppZStencilSurface
);
1100 if(ppZStencilSurface
== NULL
){
1101 return D3DERR_INVALIDCALL
;
1104 wined3d_mutex_lock();
1105 hr
= IWineD3DDevice_GetDepthStencilSurface(This
->WineD3DDevice
, &pZStencilSurface
);
1108 *ppZStencilSurface
= IWineD3DSurface_GetParent(pZStencilSurface
);
1109 IDirect3DSurface8_AddRef(*ppZStencilSurface
);
1110 IWineD3DSurface_Release(pZStencilSurface
);
1114 if (hr
!= WINED3DERR_NOTFOUND
)
1115 FIXME("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr
);
1116 *ppZStencilSurface
= NULL
;
1118 wined3d_mutex_unlock();
1123 static HRESULT WINAPI
IDirect3DDevice8Impl_BeginScene(IDirect3DDevice8
*iface
)
1125 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1128 TRACE("iface %p.\n", iface
);
1130 wined3d_mutex_lock();
1131 hr
= IWineD3DDevice_BeginScene(This
->WineD3DDevice
);
1132 wined3d_mutex_unlock();
1137 static HRESULT WINAPI DECLSPEC_HOTPATCH
IDirect3DDevice8Impl_EndScene(IDirect3DDevice8
*iface
)
1139 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1142 TRACE("iface %p.\n", iface
);
1144 wined3d_mutex_lock();
1145 hr
= IWineD3DDevice_EndScene(This
->WineD3DDevice
);
1146 wined3d_mutex_unlock();
1151 static HRESULT WINAPI
IDirect3DDevice8Impl_Clear(IDirect3DDevice8
*iface
, DWORD Count
,
1152 const D3DRECT
*pRects
, DWORD Flags
, D3DCOLOR Color
, float Z
, DWORD Stencil
)
1154 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1157 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1158 iface
, Count
, pRects
, Flags
, Color
, Z
, Stencil
);
1160 wined3d_mutex_lock();
1161 hr
= IWineD3DDevice_Clear(This
->WineD3DDevice
, Count
, (const RECT
*)pRects
, Flags
, Color
, Z
, Stencil
);
1162 wined3d_mutex_unlock();
1167 static HRESULT WINAPI
IDirect3DDevice8Impl_SetTransform(IDirect3DDevice8
*iface
,
1168 D3DTRANSFORMSTATETYPE State
, const D3DMATRIX
*lpMatrix
)
1170 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1173 TRACE("iface %p, state %#x, matrix %p.\n", iface
, State
, lpMatrix
);
1175 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1176 wined3d_mutex_lock();
1177 hr
= IWineD3DDevice_SetTransform(This
->WineD3DDevice
, State
, (CONST WINED3DMATRIX
*) lpMatrix
);
1178 wined3d_mutex_unlock();
1183 static HRESULT WINAPI
IDirect3DDevice8Impl_GetTransform(IDirect3DDevice8
*iface
,
1184 D3DTRANSFORMSTATETYPE State
, D3DMATRIX
*pMatrix
)
1186 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1189 TRACE("iface %p, state %#x, matrix %p.\n", iface
, State
, pMatrix
);
1191 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1192 wined3d_mutex_lock();
1193 hr
= IWineD3DDevice_GetTransform(This
->WineD3DDevice
, State
, (WINED3DMATRIX
*) pMatrix
);
1194 wined3d_mutex_unlock();
1199 static HRESULT WINAPI
IDirect3DDevice8Impl_MultiplyTransform(IDirect3DDevice8
*iface
,
1200 D3DTRANSFORMSTATETYPE State
, const D3DMATRIX
*pMatrix
)
1202 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1205 TRACE("iface %p, state %#x, matrix %p.\n", iface
, State
, pMatrix
);
1207 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1208 wined3d_mutex_lock();
1209 hr
= IWineD3DDevice_MultiplyTransform(This
->WineD3DDevice
, State
, (CONST WINED3DMATRIX
*) pMatrix
);
1210 wined3d_mutex_unlock();
1215 static HRESULT WINAPI
IDirect3DDevice8Impl_SetViewport(IDirect3DDevice8
*iface
,
1216 const D3DVIEWPORT8
*pViewport
)
1218 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1221 TRACE("iface %p, viewport %p.\n", iface
, pViewport
);
1223 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1224 wined3d_mutex_lock();
1225 hr
= IWineD3DDevice_SetViewport(This
->WineD3DDevice
, (const WINED3DVIEWPORT
*)pViewport
);
1226 wined3d_mutex_unlock();
1231 static HRESULT WINAPI
IDirect3DDevice8Impl_GetViewport(IDirect3DDevice8
*iface
,
1232 D3DVIEWPORT8
*pViewport
)
1234 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1237 TRACE("iface %p, viewport %p.\n", iface
, pViewport
);
1239 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1240 wined3d_mutex_lock();
1241 hr
= IWineD3DDevice_GetViewport(This
->WineD3DDevice
, (WINED3DVIEWPORT
*)pViewport
);
1242 wined3d_mutex_unlock();
1247 static HRESULT WINAPI
IDirect3DDevice8Impl_SetMaterial(IDirect3DDevice8
*iface
,
1248 const D3DMATERIAL8
*pMaterial
)
1250 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1253 TRACE("iface %p, material %p.\n", iface
, pMaterial
);
1255 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1256 wined3d_mutex_lock();
1257 hr
= IWineD3DDevice_SetMaterial(This
->WineD3DDevice
, (const WINED3DMATERIAL
*)pMaterial
);
1258 wined3d_mutex_unlock();
1263 static HRESULT WINAPI
IDirect3DDevice8Impl_GetMaterial(IDirect3DDevice8
*iface
,
1264 D3DMATERIAL8
*pMaterial
)
1266 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1269 TRACE("iface %p, material %p.\n", iface
, pMaterial
);
1271 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1272 wined3d_mutex_lock();
1273 hr
= IWineD3DDevice_GetMaterial(This
->WineD3DDevice
, (WINED3DMATERIAL
*)pMaterial
);
1274 wined3d_mutex_unlock();
1279 static HRESULT WINAPI
IDirect3DDevice8Impl_SetLight(IDirect3DDevice8
*iface
, DWORD Index
,
1280 const D3DLIGHT8
*pLight
)
1282 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1285 TRACE("iface %p, index %u, light %p.\n", iface
, Index
, pLight
);
1287 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1288 wined3d_mutex_lock();
1289 hr
= IWineD3DDevice_SetLight(This
->WineD3DDevice
, Index
, (const WINED3DLIGHT
*)pLight
);
1290 wined3d_mutex_unlock();
1295 static HRESULT WINAPI
IDirect3DDevice8Impl_GetLight(IDirect3DDevice8
*iface
, DWORD Index
,
1298 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1301 TRACE("iface %p, index %u, light %p.\n", iface
, Index
, pLight
);
1303 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1304 wined3d_mutex_lock();
1305 hr
= IWineD3DDevice_GetLight(This
->WineD3DDevice
, Index
, (WINED3DLIGHT
*)pLight
);
1306 wined3d_mutex_unlock();
1311 static HRESULT WINAPI
IDirect3DDevice8Impl_LightEnable(IDirect3DDevice8
*iface
, DWORD Index
,
1314 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1317 TRACE("iface %p, index %u, enable %#x.\n", iface
, Index
, Enable
);
1319 wined3d_mutex_lock();
1320 hr
= IWineD3DDevice_SetLightEnable(This
->WineD3DDevice
, Index
, Enable
);
1321 wined3d_mutex_unlock();
1326 static HRESULT WINAPI
IDirect3DDevice8Impl_GetLightEnable(IDirect3DDevice8
*iface
, DWORD Index
,
1329 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1332 TRACE("iface %p, index %u, enable %p.\n", iface
, Index
, pEnable
);
1334 wined3d_mutex_lock();
1335 hr
= IWineD3DDevice_GetLightEnable(This
->WineD3DDevice
, Index
, pEnable
);
1336 wined3d_mutex_unlock();
1341 static HRESULT WINAPI
IDirect3DDevice8Impl_SetClipPlane(IDirect3DDevice8
*iface
, DWORD Index
,
1342 const float *pPlane
)
1344 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1347 TRACE("iface %p, index %u, plane %p.\n", iface
, Index
, pPlane
);
1349 wined3d_mutex_lock();
1350 hr
= IWineD3DDevice_SetClipPlane(This
->WineD3DDevice
, Index
, pPlane
);
1351 wined3d_mutex_unlock();
1356 static HRESULT WINAPI
IDirect3DDevice8Impl_GetClipPlane(IDirect3DDevice8
*iface
, DWORD Index
,
1359 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1362 TRACE("iface %p, index %u, plane %p.\n", iface
, Index
, pPlane
);
1364 wined3d_mutex_lock();
1365 hr
= IWineD3DDevice_GetClipPlane(This
->WineD3DDevice
, Index
, pPlane
);
1366 wined3d_mutex_unlock();
1371 static HRESULT WINAPI
IDirect3DDevice8Impl_SetRenderState(IDirect3DDevice8
*iface
,
1372 D3DRENDERSTATETYPE State
, DWORD Value
)
1374 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1377 TRACE("iface %p, state %#x, value %#x.\n", iface
, State
, Value
);
1379 wined3d_mutex_lock();
1380 hr
= IWineD3DDevice_SetRenderState(This
->WineD3DDevice
, State
, Value
);
1381 wined3d_mutex_unlock();
1386 static HRESULT WINAPI
IDirect3DDevice8Impl_GetRenderState(IDirect3DDevice8
*iface
,
1387 D3DRENDERSTATETYPE State
, DWORD
*pValue
)
1389 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1392 TRACE("iface %p, state %#x, value %p.\n", iface
, State
, pValue
);
1394 wined3d_mutex_lock();
1395 hr
= IWineD3DDevice_GetRenderState(This
->WineD3DDevice
, State
, pValue
);
1396 wined3d_mutex_unlock();
1401 static HRESULT WINAPI
IDirect3DDevice8Impl_BeginStateBlock(IDirect3DDevice8
*iface
)
1403 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1406 TRACE("iface %p.\n", iface
);
1408 wined3d_mutex_lock();
1409 hr
= IWineD3DDevice_BeginStateBlock(This
->WineD3DDevice
);
1410 wined3d_mutex_unlock();
1415 static HRESULT WINAPI
IDirect3DDevice8Impl_EndStateBlock(IDirect3DDevice8
*iface
, DWORD
*pToken
)
1417 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1418 struct wined3d_stateblock
*stateblock
;
1421 TRACE("iface %p, token %p.\n", iface
, pToken
);
1423 /* Tell wineD3D to endstateblock before anything else (in case we run out
1424 * of memory later and cause locking problems)
1426 wined3d_mutex_lock();
1427 hr
= IWineD3DDevice_EndStateBlock(This
->WineD3DDevice
, &stateblock
);
1429 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
1430 wined3d_mutex_unlock();
1434 *pToken
= d3d8_allocate_handle(&This
->handle_table
, stateblock
, D3D8_HANDLE_SB
);
1435 wined3d_mutex_unlock();
1437 if (*pToken
== D3D8_INVALID_HANDLE
)
1439 ERR("Failed to create a handle\n");
1440 wined3d_mutex_lock();
1441 wined3d_stateblock_decref(stateblock
);
1442 wined3d_mutex_unlock();
1447 TRACE("Returning %#x (%p).\n", *pToken
, stateblock
);
1452 static HRESULT WINAPI
IDirect3DDevice8Impl_ApplyStateBlock(IDirect3DDevice8
*iface
, DWORD Token
)
1454 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1455 struct wined3d_stateblock
*stateblock
;
1458 TRACE("iface %p, token %#x.\n", iface
, Token
);
1460 if (!Token
) return D3D_OK
;
1462 wined3d_mutex_lock();
1463 stateblock
= d3d8_get_object(&This
->handle_table
, Token
- 1, D3D8_HANDLE_SB
);
1466 WARN("Invalid handle (%#x) passed.\n", Token
);
1467 wined3d_mutex_unlock();
1468 return D3DERR_INVALIDCALL
;
1470 hr
= wined3d_stateblock_apply(stateblock
);
1471 wined3d_mutex_unlock();
1476 static HRESULT WINAPI
IDirect3DDevice8Impl_CaptureStateBlock(IDirect3DDevice8
*iface
, DWORD Token
)
1478 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1479 struct wined3d_stateblock
*stateblock
;
1482 TRACE("iface %p, token %#x.\n", iface
, Token
);
1484 wined3d_mutex_lock();
1485 stateblock
= d3d8_get_object(&This
->handle_table
, Token
- 1, D3D8_HANDLE_SB
);
1488 WARN("Invalid handle (%#x) passed.\n", Token
);
1489 wined3d_mutex_unlock();
1490 return D3DERR_INVALIDCALL
;
1492 hr
= wined3d_stateblock_capture(stateblock
);
1493 wined3d_mutex_unlock();
1498 static HRESULT WINAPI
IDirect3DDevice8Impl_DeleteStateBlock(IDirect3DDevice8
*iface
, DWORD Token
)
1500 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1501 struct wined3d_stateblock
*stateblock
;
1503 TRACE("iface %p, token %#x.\n", iface
, Token
);
1505 wined3d_mutex_lock();
1506 stateblock
= d3d8_free_handle(&This
->handle_table
, Token
- 1, D3D8_HANDLE_SB
);
1510 WARN("Invalid handle (%#x) passed.\n", Token
);
1511 wined3d_mutex_unlock();
1512 return D3DERR_INVALIDCALL
;
1515 if (wined3d_stateblock_decref(stateblock
))
1517 ERR("Stateblock %p has references left, this shouldn't happen.\n", stateblock
);
1519 wined3d_mutex_unlock();
1524 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateStateBlock(IDirect3DDevice8
*iface
,
1525 D3DSTATEBLOCKTYPE Type
, DWORD
*handle
)
1527 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1528 struct wined3d_stateblock
*stateblock
;
1531 TRACE("iface %p, type %#x, handle %p.\n", iface
, Type
, handle
);
1533 if (Type
!= D3DSBT_ALL
1534 && Type
!= D3DSBT_PIXELSTATE
1535 && Type
!= D3DSBT_VERTEXSTATE
)
1537 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1538 return D3DERR_INVALIDCALL
;
1541 wined3d_mutex_lock();
1542 hr
= IWineD3DDevice_CreateStateBlock(This
->WineD3DDevice
, (WINED3DSTATEBLOCKTYPE
)Type
, &stateblock
);
1545 wined3d_mutex_unlock();
1546 ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr
);
1550 *handle
= d3d8_allocate_handle(&This
->handle_table
, stateblock
, D3D8_HANDLE_SB
);
1551 wined3d_mutex_unlock();
1553 if (*handle
== D3D8_INVALID_HANDLE
)
1555 ERR("Failed to allocate a handle.\n");
1556 wined3d_mutex_lock();
1557 wined3d_stateblock_decref(stateblock
);
1558 wined3d_mutex_unlock();
1563 TRACE("Returning %#x (%p).\n", *handle
, stateblock
);
1568 static HRESULT WINAPI
IDirect3DDevice8Impl_SetClipStatus(IDirect3DDevice8
*iface
,
1569 const D3DCLIPSTATUS8
*pClipStatus
)
1571 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1574 TRACE("iface %p, clip_status %p.\n", iface
, pClipStatus
);
1575 /* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
1577 wined3d_mutex_lock();
1578 hr
= IWineD3DDevice_SetClipStatus(This
->WineD3DDevice
, (const WINED3DCLIPSTATUS
*)pClipStatus
);
1579 wined3d_mutex_unlock();
1584 static HRESULT WINAPI
IDirect3DDevice8Impl_GetClipStatus(IDirect3DDevice8
*iface
,
1585 D3DCLIPSTATUS8
*pClipStatus
)
1587 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1590 TRACE("iface %p, clip_status %p.\n", iface
, pClipStatus
);
1592 wined3d_mutex_lock();
1593 hr
= IWineD3DDevice_GetClipStatus(This
->WineD3DDevice
, (WINED3DCLIPSTATUS
*)pClipStatus
);
1594 wined3d_mutex_unlock();
1599 static HRESULT WINAPI
IDirect3DDevice8Impl_GetTexture(IDirect3DDevice8
*iface
,
1600 DWORD Stage
, IDirect3DBaseTexture8
**ppTexture
)
1602 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1603 struct wined3d_texture
*wined3d_texture
;
1606 TRACE("iface %p, stage %u, texture %p.\n", iface
, Stage
, ppTexture
);
1608 if(ppTexture
== NULL
){
1609 return D3DERR_INVALIDCALL
;
1612 wined3d_mutex_lock();
1613 hr
= IWineD3DDevice_GetTexture(This
->WineD3DDevice
, Stage
, &wined3d_texture
);
1616 WARN("Failed to get texture for stage %u, hr %#x.\n", Stage
, hr
);
1617 wined3d_mutex_unlock();
1622 if (wined3d_texture
)
1624 *ppTexture
= wined3d_texture_get_parent(wined3d_texture
);
1625 IDirect3DBaseTexture8_AddRef(*ppTexture
);
1626 wined3d_texture_decref(wined3d_texture
);
1632 wined3d_mutex_unlock();
1637 static HRESULT WINAPI
IDirect3DDevice8Impl_SetTexture(IDirect3DDevice8
*iface
, DWORD Stage
,
1638 IDirect3DBaseTexture8
*pTexture
)
1640 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1643 TRACE("iface %p, stage %u, texture %p.\n", iface
, Stage
, pTexture
);
1645 wined3d_mutex_lock();
1646 hr
= IWineD3DDevice_SetTexture(This
->WineD3DDevice
, Stage
,
1647 pTexture
? ((IDirect3DBaseTexture8Impl
*)pTexture
)->wined3d_texture
: NULL
);
1648 wined3d_mutex_unlock();
1653 static const struct tss_lookup
1660 {FALSE
, WINED3DTSS_FORCE_DWORD
}, /* 0, unused */
1661 {FALSE
, WINED3DTSS_COLOROP
}, /* 1, D3DTSS_COLOROP */
1662 {FALSE
, WINED3DTSS_COLORARG1
}, /* 2, D3DTSS_COLORARG1 */
1663 {FALSE
, WINED3DTSS_COLORARG2
}, /* 3, D3DTSS_COLORARG2 */
1664 {FALSE
, WINED3DTSS_ALPHAOP
}, /* 4, D3DTSS_ALPHAOP */
1665 {FALSE
, WINED3DTSS_ALPHAARG1
}, /* 5, D3DTSS_ALPHAARG1 */
1666 {FALSE
, WINED3DTSS_ALPHAARG2
}, /* 6, D3DTSS_ALPHAARG2 */
1667 {FALSE
, WINED3DTSS_BUMPENVMAT00
}, /* 7, D3DTSS_BUMPENVMAT00 */
1668 {FALSE
, WINED3DTSS_BUMPENVMAT01
}, /* 8, D3DTSS_BUMPENVMAT01 */
1669 {FALSE
, WINED3DTSS_BUMPENVMAT10
}, /* 9, D3DTSS_BUMPENVMAT10 */
1670 {FALSE
, WINED3DTSS_BUMPENVMAT11
}, /* 10, D3DTSS_BUMPENVMAT11 */
1671 {FALSE
, WINED3DTSS_TEXCOORDINDEX
}, /* 11, D3DTSS_TEXCOORDINDEX */
1672 {FALSE
, WINED3DTSS_FORCE_DWORD
}, /* 12, unused */
1673 {TRUE
, WINED3DSAMP_ADDRESSU
}, /* 13, D3DTSS_ADDRESSU */
1674 {TRUE
, WINED3DSAMP_ADDRESSV
}, /* 14, D3DTSS_ADDRESSV */
1675 {TRUE
, WINED3DSAMP_BORDERCOLOR
}, /* 15, D3DTSS_BORDERCOLOR */
1676 {TRUE
, WINED3DSAMP_MAGFILTER
}, /* 16, D3DTSS_MAGFILTER */
1677 {TRUE
, WINED3DSAMP_MINFILTER
}, /* 17, D3DTSS_MINFILTER */
1678 {TRUE
, WINED3DSAMP_MIPFILTER
}, /* 18, D3DTSS_MIPFILTER */
1679 {TRUE
, WINED3DSAMP_MIPMAPLODBIAS
}, /* 19, D3DTSS_MIPMAPLODBIAS */
1680 {TRUE
, WINED3DSAMP_MAXMIPLEVEL
}, /* 20, D3DTSS_MAXMIPLEVEL */
1681 {TRUE
, WINED3DSAMP_MAXANISOTROPY
}, /* 21, D3DTSS_MAXANISOTROPY */
1682 {FALSE
, WINED3DTSS_BUMPENVLSCALE
}, /* 22, D3DTSS_BUMPENVLSCALE */
1683 {FALSE
, WINED3DTSS_BUMPENVLOFFSET
}, /* 23, D3DTSS_BUMPENVLOFFSET */
1684 {FALSE
, WINED3DTSS_TEXTURETRANSFORMFLAGS
}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1685 {TRUE
, WINED3DSAMP_ADDRESSW
}, /* 25, D3DTSS_ADDRESSW */
1686 {FALSE
, WINED3DTSS_COLORARG0
}, /* 26, D3DTSS_COLORARG0 */
1687 {FALSE
, WINED3DTSS_ALPHAARG0
}, /* 27, D3DTSS_ALPHAARG0 */
1688 {FALSE
, WINED3DTSS_RESULTARG
}, /* 28, D3DTSS_RESULTARG */
1691 static HRESULT WINAPI
IDirect3DDevice8Impl_GetTextureStageState(IDirect3DDevice8
*iface
,
1692 DWORD Stage
, D3DTEXTURESTAGESTATETYPE Type
, DWORD
*pValue
)
1694 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1695 const struct tss_lookup
*l
;
1698 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface
, Stage
, Type
, pValue
);
1700 if (Type
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
1702 WARN("Invalid Type %#x passed.\n", Type
);
1706 l
= &tss_lookup
[Type
];
1708 wined3d_mutex_lock();
1709 if (l
->sampler_state
) hr
= IWineD3DDevice_GetSamplerState(This
->WineD3DDevice
, Stage
, l
->state
, pValue
);
1710 else hr
= IWineD3DDevice_GetTextureStageState(This
->WineD3DDevice
, Stage
, l
->state
, pValue
);
1711 wined3d_mutex_unlock();
1716 static HRESULT WINAPI
IDirect3DDevice8Impl_SetTextureStageState(IDirect3DDevice8
*iface
,
1717 DWORD Stage
, D3DTEXTURESTAGESTATETYPE Type
, DWORD Value
)
1719 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1720 const struct tss_lookup
*l
;
1723 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface
, Stage
, Type
, Value
);
1725 if (Type
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
1727 WARN("Invalid Type %#x passed.\n", Type
);
1731 l
= &tss_lookup
[Type
];
1733 wined3d_mutex_lock();
1734 if (l
->sampler_state
) hr
= IWineD3DDevice_SetSamplerState(This
->WineD3DDevice
, Stage
, l
->state
, Value
);
1735 else hr
= IWineD3DDevice_SetTextureStageState(This
->WineD3DDevice
, Stage
, l
->state
, Value
);
1736 wined3d_mutex_unlock();
1741 static HRESULT WINAPI
IDirect3DDevice8Impl_ValidateDevice(IDirect3DDevice8
*iface
,
1744 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1747 TRACE("iface %p, pass_count %p.\n", iface
, pNumPasses
);
1749 wined3d_mutex_lock();
1750 hr
= IWineD3DDevice_ValidateDevice(This
->WineD3DDevice
, pNumPasses
);
1751 wined3d_mutex_unlock();
1756 static HRESULT WINAPI
IDirect3DDevice8Impl_GetInfo(IDirect3DDevice8
*iface
,
1757 DWORD info_id
, void *info
, DWORD info_size
)
1759 FIXME("iface %p, info_id %#x, info %p, info_size %u stub!\n", iface
, info_id
, info
, info_size
);
1764 static HRESULT WINAPI
IDirect3DDevice8Impl_SetPaletteEntries(IDirect3DDevice8
*iface
,
1765 UINT PaletteNumber
, const PALETTEENTRY
*pEntries
)
1767 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1770 TRACE("iface %p, palette_idx %u, entries %p.\n", iface
, PaletteNumber
, pEntries
);
1772 wined3d_mutex_lock();
1773 hr
= IWineD3DDevice_SetPaletteEntries(This
->WineD3DDevice
, PaletteNumber
, pEntries
);
1774 wined3d_mutex_unlock();
1779 static HRESULT WINAPI
IDirect3DDevice8Impl_GetPaletteEntries(IDirect3DDevice8
*iface
,
1780 UINT PaletteNumber
, PALETTEENTRY
*pEntries
)
1782 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1785 TRACE("iface %p, palette_idx %u, entries %p.\n", iface
, PaletteNumber
, pEntries
);
1787 wined3d_mutex_lock();
1788 hr
= IWineD3DDevice_GetPaletteEntries(This
->WineD3DDevice
, PaletteNumber
, pEntries
);
1789 wined3d_mutex_unlock();
1794 static HRESULT WINAPI
IDirect3DDevice8Impl_SetCurrentTexturePalette(IDirect3DDevice8
*iface
,
1797 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1800 TRACE("iface %p, palette_idx %u.\n", iface
, PaletteNumber
);
1802 wined3d_mutex_lock();
1803 hr
= IWineD3DDevice_SetCurrentTexturePalette(This
->WineD3DDevice
, PaletteNumber
);
1804 wined3d_mutex_unlock();
1809 static HRESULT WINAPI
IDirect3DDevice8Impl_GetCurrentTexturePalette(IDirect3DDevice8
*iface
,
1810 UINT
*PaletteNumber
)
1812 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1815 TRACE("iface %p, palette_idx %p.\n", iface
, PaletteNumber
);
1817 wined3d_mutex_lock();
1818 hr
= IWineD3DDevice_GetCurrentTexturePalette(This
->WineD3DDevice
, PaletteNumber
);
1819 wined3d_mutex_unlock();
1824 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawPrimitive(IDirect3DDevice8
*iface
,
1825 D3DPRIMITIVETYPE PrimitiveType
, UINT StartVertex
, UINT PrimitiveCount
)
1827 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1830 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1831 iface
, PrimitiveType
, StartVertex
, PrimitiveCount
);
1833 wined3d_mutex_lock();
1834 IWineD3DDevice_SetPrimitiveType(This
->WineD3DDevice
, PrimitiveType
);
1835 hr
= IWineD3DDevice_DrawPrimitive(This
->WineD3DDevice
, StartVertex
,
1836 vertex_count_from_primitive_count(PrimitiveType
, PrimitiveCount
));
1837 wined3d_mutex_unlock();
1842 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawIndexedPrimitive(IDirect3DDevice8
*iface
,
1843 D3DPRIMITIVETYPE PrimitiveType
, UINT MinVertexIndex
, UINT NumVertices
, UINT startIndex
,
1846 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1849 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, start_idx %u, primitive_count %u.\n",
1850 iface
, PrimitiveType
, MinVertexIndex
, NumVertices
, startIndex
, primCount
);
1852 wined3d_mutex_lock();
1853 IWineD3DDevice_SetPrimitiveType(This
->WineD3DDevice
, PrimitiveType
);
1854 hr
= IWineD3DDevice_DrawIndexedPrimitive(This
->WineD3DDevice
, startIndex
,
1855 vertex_count_from_primitive_count(PrimitiveType
, primCount
));
1856 wined3d_mutex_unlock();
1861 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawPrimitiveUP(IDirect3DDevice8
*iface
,
1862 D3DPRIMITIVETYPE PrimitiveType
, UINT PrimitiveCount
, const void *pVertexStreamZeroData
,
1863 UINT VertexStreamZeroStride
)
1865 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1868 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
1869 iface
, PrimitiveType
, PrimitiveCount
, pVertexStreamZeroData
, VertexStreamZeroStride
);
1871 wined3d_mutex_lock();
1872 IWineD3DDevice_SetPrimitiveType(This
->WineD3DDevice
, PrimitiveType
);
1873 hr
= IWineD3DDevice_DrawPrimitiveUP(This
->WineD3DDevice
,
1874 vertex_count_from_primitive_count(PrimitiveType
, PrimitiveCount
),
1875 pVertexStreamZeroData
, VertexStreamZeroStride
);
1876 wined3d_mutex_unlock();
1881 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(IDirect3DDevice8
*iface
,
1882 D3DPRIMITIVETYPE PrimitiveType
, UINT MinVertexIndex
, UINT NumVertexIndices
,
1883 UINT PrimitiveCount
, const void *pIndexData
, D3DFORMAT IndexDataFormat
,
1884 const void *pVertexStreamZeroData
, UINT VertexStreamZeroStride
)
1886 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1889 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
1890 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
1891 iface
, PrimitiveType
, MinVertexIndex
, NumVertexIndices
, PrimitiveCount
,
1892 pIndexData
, IndexDataFormat
, pVertexStreamZeroData
, VertexStreamZeroStride
);
1894 wined3d_mutex_lock();
1895 IWineD3DDevice_SetPrimitiveType(This
->WineD3DDevice
, PrimitiveType
);
1896 hr
= IWineD3DDevice_DrawIndexedPrimitiveUP(This
->WineD3DDevice
,
1897 vertex_count_from_primitive_count(PrimitiveType
, PrimitiveCount
), pIndexData
,
1898 wined3dformat_from_d3dformat(IndexDataFormat
), pVertexStreamZeroData
, VertexStreamZeroStride
);
1899 wined3d_mutex_unlock();
1904 static HRESULT WINAPI
IDirect3DDevice8Impl_ProcessVertices(IDirect3DDevice8
*iface
,
1905 UINT SrcStartIndex
, UINT DestIndex
, UINT VertexCount
, IDirect3DVertexBuffer8
*pDestBuffer
,
1908 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1910 IDirect3DVertexBuffer8Impl
*dest
= (IDirect3DVertexBuffer8Impl
*) pDestBuffer
;
1912 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, flags %#x.\n",
1913 iface
, SrcStartIndex
, DestIndex
, VertexCount
, pDestBuffer
, Flags
);
1915 wined3d_mutex_lock();
1916 hr
= IWineD3DDevice_ProcessVertices(This
->WineD3DDevice
,SrcStartIndex
, DestIndex
, VertexCount
, dest
->wineD3DVertexBuffer
, NULL
, Flags
, dest
->fvf
);
1917 wined3d_mutex_unlock();
1922 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateVertexShader(IDirect3DDevice8
*iface
,
1923 const DWORD
*declaration
, const DWORD
*byte_code
, DWORD
*shader
, DWORD usage
)
1925 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1926 IDirect3DVertexShader8Impl
*object
;
1927 DWORD shader_handle
;
1931 TRACE("iface %p, declaration %p, byte_code %p, shader %p, usage %#x.\n",
1932 iface
, declaration
, byte_code
, shader
, usage
);
1934 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1937 ERR("Failed to allocate vertex shader memory.\n");
1939 return E_OUTOFMEMORY
;
1942 wined3d_mutex_lock();
1943 handle
= d3d8_allocate_handle(&This
->handle_table
, object
, D3D8_HANDLE_VS
);
1944 wined3d_mutex_unlock();
1945 if (handle
== D3D8_INVALID_HANDLE
)
1947 ERR("Failed to allocate vertex shader handle.\n");
1948 HeapFree(GetProcessHeap(), 0, object
);
1950 return E_OUTOFMEMORY
;
1953 shader_handle
= handle
+ VS_HIGHESTFIXEDFXF
+ 1;
1955 hr
= vertexshader_init(object
, This
, declaration
, byte_code
, shader_handle
, usage
);
1958 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
1959 wined3d_mutex_lock();
1960 d3d8_free_handle(&This
->handle_table
, handle
, D3D8_HANDLE_VS
);
1961 wined3d_mutex_unlock();
1962 HeapFree(GetProcessHeap(), 0, object
);
1967 TRACE("Created vertex shader %p (handle %#x).\n", object
, shader_handle
);
1968 *shader
= shader_handle
;
1973 static IDirect3DVertexDeclaration8Impl
*IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl
*This
, DWORD fvf
)
1975 IDirect3DVertexDeclaration8Impl
*d3d8_declaration
;
1977 int p
, low
, high
; /* deliberately signed */
1978 struct FvfToDecl
*convertedDecls
= This
->decls
;
1980 TRACE("Searching for declaration for fvf %08x... ", fvf
);
1983 high
= This
->numConvertedDecls
- 1;
1984 while(low
<= high
) {
1985 p
= (low
+ high
) >> 1;
1987 if(convertedDecls
[p
].fvf
== fvf
) {
1988 TRACE("found %p\n", convertedDecls
[p
].decl
);
1989 return (IDirect3DVertexDeclaration8Impl
*)convertedDecls
[p
].decl
;
1990 } else if(convertedDecls
[p
].fvf
< fvf
) {
1996 TRACE("not found. Creating and inserting at position %d.\n", low
);
1998 d3d8_declaration
= HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration
));
1999 if (!d3d8_declaration
)
2001 ERR("Memory allocation failed.\n");
2005 hr
= vertexdeclaration_init_fvf(d3d8_declaration
, This
, fvf
);
2008 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr
);
2009 HeapFree(GetProcessHeap(), 0, d3d8_declaration
);
2013 if(This
->declArraySize
== This
->numConvertedDecls
) {
2014 int grow
= This
->declArraySize
/ 2;
2015 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
2016 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
2017 if(!convertedDecls
) {
2018 /* This will destroy it */
2019 IDirect3DVertexDeclaration8_Release((IDirect3DVertexDeclaration8
*)d3d8_declaration
);
2022 This
->decls
= convertedDecls
;
2023 This
->declArraySize
+= grow
;
2026 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
2027 convertedDecls
[low
].decl
= (IDirect3DVertexDeclaration8
*)d3d8_declaration
;
2028 convertedDecls
[low
].fvf
= fvf
;
2029 This
->numConvertedDecls
++;
2031 TRACE("Returning %p. %u decls in array\n", d3d8_declaration
, This
->numConvertedDecls
);
2032 return d3d8_declaration
;
2035 static HRESULT WINAPI
IDirect3DDevice8Impl_SetVertexShader(IDirect3DDevice8
*iface
, DWORD pShader
)
2037 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2038 IDirect3DVertexShader8Impl
*shader
;
2041 TRACE("iface %p, shader %#x.\n", iface
, pShader
);
2043 if (VS_HIGHESTFIXEDFXF
>= pShader
) {
2044 TRACE("Setting FVF, %#x\n", pShader
);
2046 wined3d_mutex_lock();
2047 IWineD3DDevice_SetVertexDeclaration(This
->WineD3DDevice
,
2048 IDirect3DDevice8Impl_FindDecl(This
, pShader
)->wined3d_vertex_declaration
);
2049 IWineD3DDevice_SetVertexShader(This
->WineD3DDevice
, NULL
);
2050 wined3d_mutex_unlock();
2055 TRACE("Setting shader\n");
2057 wined3d_mutex_lock();
2058 shader
= d3d8_get_object(&This
->handle_table
, pShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
);
2061 WARN("Invalid handle (%#x) passed.\n", pShader
);
2062 wined3d_mutex_unlock();
2064 return D3DERR_INVALIDCALL
;
2067 hr
= IWineD3DDevice_SetVertexDeclaration(This
->WineD3DDevice
,
2068 ((IDirect3DVertexDeclaration8Impl
*)shader
->vertex_declaration
)->wined3d_vertex_declaration
);
2070 hr
= IWineD3DDevice_SetVertexShader(This
->WineD3DDevice
, shader
->wined3d_shader
);
2071 wined3d_mutex_unlock();
2073 TRACE("Returning hr %#x\n", hr
);
2078 static HRESULT WINAPI
IDirect3DDevice8Impl_GetVertexShader(IDirect3DDevice8
*iface
, DWORD
*ppShader
)
2080 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2081 struct wined3d_vertex_declaration
*wined3d_declaration
;
2082 IDirect3DVertexDeclaration8
*d3d8_declaration
;
2085 TRACE("iface %p, shader %p.\n", iface
, ppShader
);
2087 wined3d_mutex_lock();
2088 hr
= IWineD3DDevice_GetVertexDeclaration(This
->WineD3DDevice
, &wined3d_declaration
);
2091 wined3d_mutex_unlock();
2092 WARN("(%p) : Call to IWineD3DDevice_GetVertexDeclaration failed %#x (device %p)\n",
2093 This
, hr
, This
->WineD3DDevice
);
2097 if (!wined3d_declaration
)
2099 wined3d_mutex_unlock();
2104 d3d8_declaration
= wined3d_vertex_declaration_get_parent(wined3d_declaration
);
2105 wined3d_vertex_declaration_decref(wined3d_declaration
);
2106 wined3d_mutex_unlock();
2107 *ppShader
= ((IDirect3DVertexDeclaration8Impl
*)d3d8_declaration
)->shader_handle
;
2109 TRACE("(%p) : returning %#x\n", This
, *ppShader
);
2114 static HRESULT WINAPI
IDirect3DDevice8Impl_DeleteVertexShader(IDirect3DDevice8
*iface
, DWORD pShader
)
2116 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2117 IDirect3DVertexShader8Impl
*shader
;
2118 struct wined3d_shader
*cur
;
2120 TRACE("iface %p, shader %#x.\n", iface
, pShader
);
2122 wined3d_mutex_lock();
2123 shader
= d3d8_free_handle(&This
->handle_table
, pShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
);
2126 WARN("Invalid handle (%#x) passed.\n", pShader
);
2127 wined3d_mutex_unlock();
2129 return D3DERR_INVALIDCALL
;
2132 cur
= IWineD3DDevice_GetVertexShader(This
->WineD3DDevice
);
2135 if (cur
== shader
->wined3d_shader
)
2136 IDirect3DDevice8_SetVertexShader(iface
, 0);
2137 wined3d_shader_decref(cur
);
2140 wined3d_mutex_unlock();
2142 if (IDirect3DVertexShader8_Release(&shader
->IDirect3DVertexShader8_iface
))
2144 ERR("Shader %p has references left, this shouldn't happen.\n", shader
);
2150 static HRESULT WINAPI
IDirect3DDevice8Impl_SetVertexShaderConstant(IDirect3DDevice8
*iface
,
2151 DWORD Register
, const void *pConstantData
, DWORD ConstantCount
)
2153 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2156 TRACE("iface %p, register %u, data %p, count %u.\n",
2157 iface
, Register
, pConstantData
, ConstantCount
);
2159 if(Register
+ ConstantCount
> D3D8_MAX_VERTEX_SHADER_CONSTANTF
) {
2160 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2161 Register
+ ConstantCount
, D3D8_MAX_VERTEX_SHADER_CONSTANTF
);
2162 return D3DERR_INVALIDCALL
;
2165 wined3d_mutex_lock();
2166 hr
= IWineD3DDevice_SetVertexShaderConstantF(This
->WineD3DDevice
, Register
, pConstantData
, ConstantCount
);
2167 wined3d_mutex_unlock();
2172 static HRESULT WINAPI
IDirect3DDevice8Impl_GetVertexShaderConstant(IDirect3DDevice8
*iface
,
2173 DWORD Register
, void *pConstantData
, DWORD ConstantCount
)
2175 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2178 TRACE("iface %p, register %u, data %p, count %u.\n",
2179 iface
, Register
, pConstantData
, ConstantCount
);
2181 if(Register
+ ConstantCount
> D3D8_MAX_VERTEX_SHADER_CONSTANTF
) {
2182 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2183 Register
+ ConstantCount
, D3D8_MAX_VERTEX_SHADER_CONSTANTF
);
2184 return D3DERR_INVALIDCALL
;
2187 wined3d_mutex_lock();
2188 hr
= IWineD3DDevice_GetVertexShaderConstantF(This
->WineD3DDevice
, Register
, pConstantData
, ConstantCount
);
2189 wined3d_mutex_unlock();
2194 static HRESULT WINAPI
IDirect3DDevice8Impl_GetVertexShaderDeclaration(IDirect3DDevice8
*iface
,
2195 DWORD pVertexShader
, void *pData
, DWORD
*pSizeOfData
)
2197 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2198 IDirect3DVertexDeclaration8Impl
*declaration
;
2199 IDirect3DVertexShader8Impl
*shader
;
2201 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2202 iface
, pVertexShader
, pData
, pSizeOfData
);
2204 wined3d_mutex_lock();
2205 shader
= d3d8_get_object(&This
->handle_table
, pVertexShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
);
2206 wined3d_mutex_unlock();
2210 WARN("Invalid handle (%#x) passed.\n", pVertexShader
);
2211 return D3DERR_INVALIDCALL
;
2213 declaration
= (IDirect3DVertexDeclaration8Impl
*)shader
->vertex_declaration
;
2215 /* If pData is NULL, we just return the required size of the buffer. */
2217 *pSizeOfData
= declaration
->elements_size
;
2221 /* MSDN claims that if *pSizeOfData is smaller than the required size
2222 * we should write the required size and return D3DERR_MOREDATA.
2223 * That's not actually true. */
2224 if (*pSizeOfData
< declaration
->elements_size
) {
2225 return D3DERR_INVALIDCALL
;
2228 CopyMemory(pData
, declaration
->elements
, declaration
->elements_size
);
2233 static HRESULT WINAPI
IDirect3DDevice8Impl_GetVertexShaderFunction(IDirect3DDevice8
*iface
,
2234 DWORD pVertexShader
, void *pData
, DWORD
*pSizeOfData
)
2236 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2237 IDirect3DVertexShader8Impl
*shader
= NULL
;
2240 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2241 iface
, pVertexShader
, pData
, pSizeOfData
);
2243 wined3d_mutex_lock();
2244 shader
= d3d8_get_object(&This
->handle_table
, pVertexShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
);
2247 WARN("Invalid handle (%#x) passed.\n", pVertexShader
);
2248 wined3d_mutex_unlock();
2250 return D3DERR_INVALIDCALL
;
2253 if (!shader
->wined3d_shader
)
2255 wined3d_mutex_unlock();
2260 hr
= wined3d_shader_get_byte_code(shader
->wined3d_shader
, pData
, pSizeOfData
);
2261 wined3d_mutex_unlock();
2266 static HRESULT WINAPI
IDirect3DDevice8Impl_SetIndices(IDirect3DDevice8
*iface
,
2267 IDirect3DIndexBuffer8
*pIndexData
, UINT baseVertexIndex
)
2269 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2271 IDirect3DIndexBuffer8Impl
*ib
= (IDirect3DIndexBuffer8Impl
*)pIndexData
;
2273 TRACE("iface %p, buffer %p, base_vertex_idx %u.\n", iface
, pIndexData
, baseVertexIndex
);
2275 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
2276 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
2277 * vertex buffers can't be created to address them with an index that requires the 32nd bit
2278 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
2281 wined3d_mutex_lock();
2282 IWineD3DDevice_SetBaseVertexIndex(This
->WineD3DDevice
, baseVertexIndex
);
2283 hr
= IWineD3DDevice_SetIndexBuffer(This
->WineD3DDevice
,
2284 ib
? ib
->wineD3DIndexBuffer
: NULL
,
2285 ib
? ib
->format
: WINED3DFMT_UNKNOWN
);
2286 wined3d_mutex_unlock();
2291 static HRESULT WINAPI
IDirect3DDevice8Impl_GetIndices(IDirect3DDevice8
*iface
,
2292 IDirect3DIndexBuffer8
**ppIndexData
, UINT
*pBaseVertexIndex
)
2294 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2295 struct wined3d_buffer
*retIndexData
= NULL
;
2298 TRACE("iface %p, buffer %p, base_vertex_index %p.\n", iface
, ppIndexData
, pBaseVertexIndex
);
2300 if(ppIndexData
== NULL
){
2301 return D3DERR_INVALIDCALL
;
2304 /* The case from UINT to INT is safe because d3d8 will never set negative values */
2305 wined3d_mutex_lock();
2306 IWineD3DDevice_GetBaseVertexIndex(This
->WineD3DDevice
, (INT
*) pBaseVertexIndex
);
2307 hr
= IWineD3DDevice_GetIndexBuffer(This
->WineD3DDevice
, &retIndexData
);
2308 if (SUCCEEDED(hr
) && retIndexData
)
2310 *ppIndexData
= wined3d_buffer_get_parent(retIndexData
);
2311 IDirect3DIndexBuffer8_AddRef(*ppIndexData
);
2312 wined3d_buffer_decref(retIndexData
);
2314 if (FAILED(hr
)) FIXME("Call to GetIndices failed\n");
2315 *ppIndexData
= NULL
;
2317 wined3d_mutex_unlock();
2322 static HRESULT WINAPI
IDirect3DDevice8Impl_CreatePixelShader(IDirect3DDevice8
*iface
,
2323 const DWORD
*byte_code
, DWORD
*shader
)
2325 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2326 IDirect3DPixelShader8Impl
*object
;
2327 DWORD shader_handle
;
2331 TRACE("iface %p, byte_code %p, shader %p.\n", iface
, byte_code
, shader
);
2335 TRACE("(%p) Invalid call\n", This
);
2336 return D3DERR_INVALIDCALL
;
2339 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2342 ERR("Failed to allocate pixel shader memmory.\n");
2343 return E_OUTOFMEMORY
;
2346 wined3d_mutex_lock();
2347 handle
= d3d8_allocate_handle(&This
->handle_table
, object
, D3D8_HANDLE_PS
);
2348 wined3d_mutex_unlock();
2349 if (handle
== D3D8_INVALID_HANDLE
)
2351 ERR("Failed to allocate pixel shader handle.\n");
2352 HeapFree(GetProcessHeap(), 0, object
);
2353 return E_OUTOFMEMORY
;
2356 shader_handle
= handle
+ VS_HIGHESTFIXEDFXF
+ 1;
2358 hr
= pixelshader_init(object
, This
, byte_code
, shader_handle
);
2361 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
2362 wined3d_mutex_lock();
2363 d3d8_free_handle(&This
->handle_table
, handle
, D3D8_HANDLE_PS
);
2364 wined3d_mutex_unlock();
2365 HeapFree(GetProcessHeap(), 0, object
);
2370 TRACE("Created pixel shader %p (handle %#x).\n", object
, shader_handle
);
2371 *shader
= shader_handle
;
2376 static HRESULT WINAPI
IDirect3DDevice8Impl_SetPixelShader(IDirect3DDevice8
*iface
, DWORD pShader
)
2378 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2379 IDirect3DPixelShader8Impl
*shader
;
2382 TRACE("iface %p, shader %#x.\n", iface
, pShader
);
2384 wined3d_mutex_lock();
2388 hr
= IWineD3DDevice_SetPixelShader(This
->WineD3DDevice
, NULL
);
2389 wined3d_mutex_unlock();
2393 shader
= d3d8_get_object(&This
->handle_table
, pShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
);
2396 WARN("Invalid handle (%#x) passed.\n", pShader
);
2397 wined3d_mutex_unlock();
2398 return D3DERR_INVALIDCALL
;
2401 TRACE("(%p) : Setting shader %p\n", This
, shader
);
2402 hr
= IWineD3DDevice_SetPixelShader(This
->WineD3DDevice
, shader
->wined3d_shader
);
2403 wined3d_mutex_unlock();
2408 static HRESULT WINAPI
IDirect3DDevice8Impl_GetPixelShader(IDirect3DDevice8
*iface
, DWORD
*ppShader
)
2410 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2411 struct wined3d_shader
*object
;
2413 TRACE("iface %p, shader %p.\n", iface
, ppShader
);
2415 if (NULL
== ppShader
) {
2416 TRACE("(%p) Invalid call\n", This
);
2417 return D3DERR_INVALIDCALL
;
2420 wined3d_mutex_lock();
2421 object
= IWineD3DDevice_GetPixelShader(This
->WineD3DDevice
);
2424 IDirect3DPixelShader8Impl
*d3d8_shader
;
2425 d3d8_shader
= wined3d_shader_get_parent(object
);
2426 wined3d_shader_decref(object
);
2427 *ppShader
= d3d8_shader
->handle
;
2433 wined3d_mutex_unlock();
2435 TRACE("(%p) : returning %#x\n", This
, *ppShader
);
2440 static HRESULT WINAPI
IDirect3DDevice8Impl_DeletePixelShader(IDirect3DDevice8
*iface
, DWORD pShader
)
2442 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2443 IDirect3DPixelShader8Impl
*shader
;
2444 struct wined3d_shader
*cur
;
2446 TRACE("iface %p, shader %#x.\n", iface
, pShader
);
2448 wined3d_mutex_lock();
2450 shader
= d3d8_free_handle(&This
->handle_table
, pShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
);
2453 WARN("Invalid handle (%#x) passed.\n", pShader
);
2454 wined3d_mutex_unlock();
2455 return D3DERR_INVALIDCALL
;
2458 cur
= IWineD3DDevice_GetPixelShader(This
->WineD3DDevice
);
2461 if (cur
== shader
->wined3d_shader
)
2462 IDirect3DDevice8_SetPixelShader(iface
, 0);
2463 wined3d_shader_decref(cur
);
2466 wined3d_mutex_unlock();
2468 if (IDirect3DPixelShader8_Release(&shader
->IDirect3DPixelShader8_iface
))
2470 ERR("Shader %p has references left, this shouldn't happen.\n", shader
);
2476 static HRESULT WINAPI
IDirect3DDevice8Impl_SetPixelShaderConstant(IDirect3DDevice8
*iface
,
2477 DWORD Register
, const void *pConstantData
, DWORD ConstantCount
)
2479 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2482 TRACE("iface %p, register %u, data %p, count %u.\n",
2483 iface
, Register
, pConstantData
, ConstantCount
);
2485 wined3d_mutex_lock();
2486 hr
= IWineD3DDevice_SetPixelShaderConstantF(This
->WineD3DDevice
, Register
, pConstantData
, ConstantCount
);
2487 wined3d_mutex_unlock();
2492 static HRESULT WINAPI
IDirect3DDevice8Impl_GetPixelShaderConstant(IDirect3DDevice8
*iface
,
2493 DWORD Register
, void *pConstantData
, DWORD ConstantCount
)
2495 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2498 TRACE("iface %p, register %u, data %p, count %u.\n",
2499 iface
, Register
, pConstantData
, ConstantCount
);
2501 wined3d_mutex_lock();
2502 hr
= IWineD3DDevice_GetPixelShaderConstantF(This
->WineD3DDevice
, Register
, pConstantData
, ConstantCount
);
2503 wined3d_mutex_unlock();
2508 static HRESULT WINAPI
IDirect3DDevice8Impl_GetPixelShaderFunction(IDirect3DDevice8
*iface
,
2509 DWORD pPixelShader
, void *pData
, DWORD
*pSizeOfData
)
2511 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2512 IDirect3DPixelShader8Impl
*shader
= NULL
;
2515 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2516 iface
, pPixelShader
, pData
, pSizeOfData
);
2518 wined3d_mutex_lock();
2519 shader
= d3d8_get_object(&This
->handle_table
, pPixelShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
);
2522 WARN("Invalid handle (%#x) passed.\n", pPixelShader
);
2523 wined3d_mutex_unlock();
2525 return D3DERR_INVALIDCALL
;
2528 hr
= wined3d_shader_get_byte_code(shader
->wined3d_shader
, pData
, pSizeOfData
);
2529 wined3d_mutex_unlock();
2534 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawRectPatch(IDirect3DDevice8
*iface
, UINT Handle
,
2535 const float *pNumSegs
, const D3DRECTPATCH_INFO
*pRectPatchInfo
)
2537 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2540 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2541 iface
, Handle
, pNumSegs
, pRectPatchInfo
);
2543 wined3d_mutex_lock();
2544 hr
= IWineD3DDevice_DrawRectPatch(This
->WineD3DDevice
, Handle
, pNumSegs
, (CONST WINED3DRECTPATCH_INFO
*)pRectPatchInfo
);
2545 wined3d_mutex_unlock();
2550 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawTriPatch(IDirect3DDevice8
*iface
, UINT Handle
,
2551 const float *pNumSegs
, const D3DTRIPATCH_INFO
*pTriPatchInfo
)
2553 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2556 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2557 iface
, Handle
, pNumSegs
, pTriPatchInfo
);
2559 wined3d_mutex_lock();
2560 hr
= IWineD3DDevice_DrawTriPatch(This
->WineD3DDevice
, Handle
, pNumSegs
, (CONST WINED3DTRIPATCH_INFO
*)pTriPatchInfo
);
2561 wined3d_mutex_unlock();
2566 static HRESULT WINAPI
IDirect3DDevice8Impl_DeletePatch(IDirect3DDevice8
*iface
, UINT Handle
)
2568 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2571 TRACE("iface %p, handle %#x.\n", iface
, Handle
);
2573 wined3d_mutex_lock();
2574 hr
= IWineD3DDevice_DeletePatch(This
->WineD3DDevice
, Handle
);
2575 wined3d_mutex_unlock();
2580 static HRESULT WINAPI
IDirect3DDevice8Impl_SetStreamSource(IDirect3DDevice8
*iface
,
2581 UINT StreamNumber
, IDirect3DVertexBuffer8
*pStreamData
, UINT Stride
)
2583 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2586 TRACE("iface %p, stream_idx %u, buffer %p, stride %u.\n",
2587 iface
, StreamNumber
, pStreamData
, Stride
);
2589 wined3d_mutex_lock();
2590 hr
= IWineD3DDevice_SetStreamSource(This
->WineD3DDevice
, StreamNumber
,
2591 NULL
== pStreamData
? NULL
: ((IDirect3DVertexBuffer8Impl
*)pStreamData
)->wineD3DVertexBuffer
,
2592 0/* Offset in bytes */, Stride
);
2593 wined3d_mutex_unlock();
2598 static HRESULT WINAPI
IDirect3DDevice8Impl_GetStreamSource(IDirect3DDevice8
*iface
,
2599 UINT StreamNumber
, IDirect3DVertexBuffer8
**pStream
, UINT
*pStride
)
2601 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2602 struct wined3d_buffer
*retStream
= NULL
;
2605 TRACE("iface %p, stream_idx %u, buffer %p, stride %p.\n",
2606 iface
, StreamNumber
, pStream
, pStride
);
2608 if(pStream
== NULL
){
2609 return D3DERR_INVALIDCALL
;
2612 wined3d_mutex_lock();
2613 hr
= IWineD3DDevice_GetStreamSource(This
->WineD3DDevice
, StreamNumber
,
2614 &retStream
, 0 /* Offset in bytes */, pStride
);
2615 if (SUCCEEDED(hr
) && retStream
)
2617 *pStream
= wined3d_buffer_get_parent(retStream
);
2618 IDirect3DVertexBuffer8_AddRef(*pStream
);
2619 wined3d_buffer_decref(retStream
);
2623 if (FAILED(hr
)) FIXME("Call to GetStreamSource failed, hr %#x.\n", hr
);
2626 wined3d_mutex_unlock();
2631 static const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl
=
2633 IDirect3DDevice8Impl_QueryInterface
,
2634 IDirect3DDevice8Impl_AddRef
,
2635 IDirect3DDevice8Impl_Release
,
2636 IDirect3DDevice8Impl_TestCooperativeLevel
,
2637 IDirect3DDevice8Impl_GetAvailableTextureMem
,
2638 IDirect3DDevice8Impl_ResourceManagerDiscardBytes
,
2639 IDirect3DDevice8Impl_GetDirect3D
,
2640 IDirect3DDevice8Impl_GetDeviceCaps
,
2641 IDirect3DDevice8Impl_GetDisplayMode
,
2642 IDirect3DDevice8Impl_GetCreationParameters
,
2643 IDirect3DDevice8Impl_SetCursorProperties
,
2644 IDirect3DDevice8Impl_SetCursorPosition
,
2645 IDirect3DDevice8Impl_ShowCursor
,
2646 IDirect3DDevice8Impl_CreateAdditionalSwapChain
,
2647 IDirect3DDevice8Impl_Reset
,
2648 IDirect3DDevice8Impl_Present
,
2649 IDirect3DDevice8Impl_GetBackBuffer
,
2650 IDirect3DDevice8Impl_GetRasterStatus
,
2651 IDirect3DDevice8Impl_SetGammaRamp
,
2652 IDirect3DDevice8Impl_GetGammaRamp
,
2653 IDirect3DDevice8Impl_CreateTexture
,
2654 IDirect3DDevice8Impl_CreateVolumeTexture
,
2655 IDirect3DDevice8Impl_CreateCubeTexture
,
2656 IDirect3DDevice8Impl_CreateVertexBuffer
,
2657 IDirect3DDevice8Impl_CreateIndexBuffer
,
2658 IDirect3DDevice8Impl_CreateRenderTarget
,
2659 IDirect3DDevice8Impl_CreateDepthStencilSurface
,
2660 IDirect3DDevice8Impl_CreateImageSurface
,
2661 IDirect3DDevice8Impl_CopyRects
,
2662 IDirect3DDevice8Impl_UpdateTexture
,
2663 IDirect3DDevice8Impl_GetFrontBuffer
,
2664 IDirect3DDevice8Impl_SetRenderTarget
,
2665 IDirect3DDevice8Impl_GetRenderTarget
,
2666 IDirect3DDevice8Impl_GetDepthStencilSurface
,
2667 IDirect3DDevice8Impl_BeginScene
,
2668 IDirect3DDevice8Impl_EndScene
,
2669 IDirect3DDevice8Impl_Clear
,
2670 IDirect3DDevice8Impl_SetTransform
,
2671 IDirect3DDevice8Impl_GetTransform
,
2672 IDirect3DDevice8Impl_MultiplyTransform
,
2673 IDirect3DDevice8Impl_SetViewport
,
2674 IDirect3DDevice8Impl_GetViewport
,
2675 IDirect3DDevice8Impl_SetMaterial
,
2676 IDirect3DDevice8Impl_GetMaterial
,
2677 IDirect3DDevice8Impl_SetLight
,
2678 IDirect3DDevice8Impl_GetLight
,
2679 IDirect3DDevice8Impl_LightEnable
,
2680 IDirect3DDevice8Impl_GetLightEnable
,
2681 IDirect3DDevice8Impl_SetClipPlane
,
2682 IDirect3DDevice8Impl_GetClipPlane
,
2683 IDirect3DDevice8Impl_SetRenderState
,
2684 IDirect3DDevice8Impl_GetRenderState
,
2685 IDirect3DDevice8Impl_BeginStateBlock
,
2686 IDirect3DDevice8Impl_EndStateBlock
,
2687 IDirect3DDevice8Impl_ApplyStateBlock
,
2688 IDirect3DDevice8Impl_CaptureStateBlock
,
2689 IDirect3DDevice8Impl_DeleteStateBlock
,
2690 IDirect3DDevice8Impl_CreateStateBlock
,
2691 IDirect3DDevice8Impl_SetClipStatus
,
2692 IDirect3DDevice8Impl_GetClipStatus
,
2693 IDirect3DDevice8Impl_GetTexture
,
2694 IDirect3DDevice8Impl_SetTexture
,
2695 IDirect3DDevice8Impl_GetTextureStageState
,
2696 IDirect3DDevice8Impl_SetTextureStageState
,
2697 IDirect3DDevice8Impl_ValidateDevice
,
2698 IDirect3DDevice8Impl_GetInfo
,
2699 IDirect3DDevice8Impl_SetPaletteEntries
,
2700 IDirect3DDevice8Impl_GetPaletteEntries
,
2701 IDirect3DDevice8Impl_SetCurrentTexturePalette
,
2702 IDirect3DDevice8Impl_GetCurrentTexturePalette
,
2703 IDirect3DDevice8Impl_DrawPrimitive
,
2704 IDirect3DDevice8Impl_DrawIndexedPrimitive
,
2705 IDirect3DDevice8Impl_DrawPrimitiveUP
,
2706 IDirect3DDevice8Impl_DrawIndexedPrimitiveUP
,
2707 IDirect3DDevice8Impl_ProcessVertices
,
2708 IDirect3DDevice8Impl_CreateVertexShader
,
2709 IDirect3DDevice8Impl_SetVertexShader
,
2710 IDirect3DDevice8Impl_GetVertexShader
,
2711 IDirect3DDevice8Impl_DeleteVertexShader
,
2712 IDirect3DDevice8Impl_SetVertexShaderConstant
,
2713 IDirect3DDevice8Impl_GetVertexShaderConstant
,
2714 IDirect3DDevice8Impl_GetVertexShaderDeclaration
,
2715 IDirect3DDevice8Impl_GetVertexShaderFunction
,
2716 IDirect3DDevice8Impl_SetStreamSource
,
2717 IDirect3DDevice8Impl_GetStreamSource
,
2718 IDirect3DDevice8Impl_SetIndices
,
2719 IDirect3DDevice8Impl_GetIndices
,
2720 IDirect3DDevice8Impl_CreatePixelShader
,
2721 IDirect3DDevice8Impl_SetPixelShader
,
2722 IDirect3DDevice8Impl_GetPixelShader
,
2723 IDirect3DDevice8Impl_DeletePixelShader
,
2724 IDirect3DDevice8Impl_SetPixelShaderConstant
,
2725 IDirect3DDevice8Impl_GetPixelShaderConstant
,
2726 IDirect3DDevice8Impl_GetPixelShaderFunction
,
2727 IDirect3DDevice8Impl_DrawRectPatch
,
2728 IDirect3DDevice8Impl_DrawTriPatch
,
2729 IDirect3DDevice8Impl_DeletePatch
2732 static inline IDirect3DDevice8Impl
*impl_from_IWineD3DDeviceParent(IWineD3DDeviceParent
*iface
)
2734 return CONTAINING_RECORD(iface
, IDirect3DDevice8Impl
, IWineD3DDeviceParent_iface
);
2737 static HRESULT STDMETHODCALLTYPE
device_parent_QueryInterface(IWineD3DDeviceParent
*iface
,
2738 REFIID riid
, void **object
)
2740 IDirect3DDevice8Impl
*This
= impl_from_IWineD3DDeviceParent(iface
);
2741 return IDirect3DDevice8Impl_QueryInterface(&This
->IDirect3DDevice8_iface
, riid
, object
);
2744 static ULONG STDMETHODCALLTYPE
device_parent_AddRef(IWineD3DDeviceParent
*iface
)
2746 IDirect3DDevice8Impl
*This
= impl_from_IWineD3DDeviceParent(iface
);
2747 return IDirect3DDevice8Impl_AddRef(&This
->IDirect3DDevice8_iface
);
2750 static ULONG STDMETHODCALLTYPE
device_parent_Release(IWineD3DDeviceParent
*iface
)
2752 IDirect3DDevice8Impl
*This
= impl_from_IWineD3DDeviceParent(iface
);
2753 return IDirect3DDevice8Impl_Release(&This
->IDirect3DDevice8_iface
);
2756 /* IWineD3DDeviceParent methods */
2758 static void STDMETHODCALLTYPE
device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent
*iface
, IWineD3DDevice
*device
)
2760 TRACE("iface %p, device %p\n", iface
, device
);
2763 static HRESULT STDMETHODCALLTYPE
device_parent_CreateSurface(IWineD3DDeviceParent
*iface
,
2764 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
, DWORD usage
,
2765 WINED3DPOOL pool
, UINT level
, WINED3DCUBEMAP_FACES face
, IWineD3DSurface
**surface
)
2767 IDirect3DDevice8Impl
*This
= impl_from_IWineD3DDeviceParent(iface
);
2768 IDirect3DSurface8Impl
*d3d_surface
;
2769 BOOL lockable
= TRUE
;
2772 TRACE("iface %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
2773 "\tpool %#x, level %u, face %u, surface %p\n",
2774 iface
, container_parent
, width
, height
, format
, usage
, pool
, level
, face
, surface
);
2777 if (pool
== WINED3DPOOL_DEFAULT
&& !(usage
& WINED3DUSAGE_DYNAMIC
)) lockable
= FALSE
;
2779 hr
= IDirect3DDevice8Impl_CreateSurface(This
, width
, height
,
2780 d3dformat_from_wined3dformat(format
), lockable
, FALSE
/* Discard */, level
,
2781 (IDirect3DSurface8
**)&d3d_surface
, usage
, pool
, D3DMULTISAMPLE_NONE
, 0 /* MultisampleQuality */);
2784 ERR("(%p) CreateSurface failed, returning %#x\n", iface
, hr
);
2788 *surface
= d3d_surface
->wineD3DSurface
;
2789 IWineD3DSurface_AddRef(*surface
);
2791 d3d_surface
->container
= container_parent
;
2792 IUnknown_Release(d3d_surface
->parentDevice
);
2793 d3d_surface
->parentDevice
= NULL
;
2795 IDirect3DSurface8_Release((IDirect3DSurface8
*)d3d_surface
);
2796 d3d_surface
->forwardReference
= container_parent
;
2801 static HRESULT STDMETHODCALLTYPE
device_parent_CreateRenderTarget(IWineD3DDeviceParent
*iface
,
2802 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
,
2803 WINED3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
, BOOL lockable
,
2804 IWineD3DSurface
**surface
)
2806 IDirect3DDevice8Impl
*This
= impl_from_IWineD3DDeviceParent(iface
);
2807 IDirect3DSurface8Impl
*d3d_surface
;
2810 TRACE("iface %p, container_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2811 "\tmultisample_quality %u, lockable %u, surface %p\n",
2812 iface
, container_parent
, width
, height
, format
, multisample_type
, multisample_quality
, lockable
, surface
);
2814 hr
= IDirect3DDevice8_CreateRenderTarget(&This
->IDirect3DDevice8_iface
, width
, height
,
2815 d3dformat_from_wined3dformat(format
), multisample_type
, lockable
, (IDirect3DSurface8
**)&d3d_surface
);
2818 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface
, hr
);
2822 *surface
= d3d_surface
->wineD3DSurface
;
2823 IWineD3DSurface_AddRef(*surface
);
2825 d3d_surface
->container
= (IUnknown
*)&This
->IDirect3DDevice8_iface
;
2826 /* Implicit surfaces are created with an refcount of 0 */
2827 IUnknown_Release((IUnknown
*)d3d_surface
);
2832 static HRESULT STDMETHODCALLTYPE
device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent
*iface
,
2833 UINT width
, UINT height
, enum wined3d_format_id format
, WINED3DMULTISAMPLE_TYPE multisample_type
,
2834 DWORD multisample_quality
, BOOL discard
, IWineD3DSurface
**surface
)
2836 IDirect3DDevice8Impl
*This
= impl_from_IWineD3DDeviceParent(iface
);
2837 IDirect3DSurface8Impl
*d3d_surface
;
2840 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2841 "\tmultisample_quality %u, discard %u, surface %p\n",
2842 iface
, width
, height
, format
, multisample_type
, multisample_quality
, discard
, surface
);
2844 hr
= IDirect3DDevice8_CreateDepthStencilSurface(&This
->IDirect3DDevice8_iface
, width
, height
,
2845 d3dformat_from_wined3dformat(format
), multisample_type
, (IDirect3DSurface8
**)&d3d_surface
);
2848 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface
, hr
);
2852 *surface
= d3d_surface
->wineD3DSurface
;
2853 IWineD3DSurface_AddRef(*surface
);
2855 d3d_surface
->container
= (IUnknown
*)&This
->IDirect3DDevice8_iface
;
2856 /* Implicit surfaces are created with an refcount of 0 */
2857 IUnknown_Release((IUnknown
*)d3d_surface
);
2862 static HRESULT STDMETHODCALLTYPE
device_parent_CreateVolume(IWineD3DDeviceParent
*iface
,
2863 void *container_parent
, UINT width
, UINT height
, UINT depth
, enum wined3d_format_id format
,
2864 WINED3DPOOL pool
, DWORD usage
, IWineD3DVolume
**volume
)
2866 IDirect3DDevice8Impl
*This
= impl_from_IWineD3DDeviceParent(iface
);
2867 IDirect3DVolume8Impl
*object
;
2870 TRACE("iface %p, container_parent %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
2871 iface
, container_parent
, width
, height
, depth
, format
, pool
, usage
, volume
);
2873 /* Allocate the storage for the device */
2874 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2877 FIXME("Allocation of memory failed\n");
2879 return D3DERR_OUTOFVIDEOMEMORY
;
2882 hr
= volume_init(object
, This
, width
, height
, depth
, usage
, format
, pool
);
2885 WARN("Failed to initialize volume, hr %#x.\n", hr
);
2886 HeapFree(GetProcessHeap(), 0, object
);
2890 *volume
= object
->wineD3DVolume
;
2891 IWineD3DVolume_AddRef(*volume
);
2892 IDirect3DVolume8_Release(&object
->IDirect3DVolume8_iface
);
2894 object
->container
= container_parent
;
2895 object
->forwardReference
= container_parent
;
2897 TRACE("(%p) Created volume %p\n", iface
, object
);
2902 static HRESULT STDMETHODCALLTYPE
device_parent_CreateSwapChain(IWineD3DDeviceParent
*iface
,
2903 WINED3DPRESENT_PARAMETERS
*present_parameters
, IWineD3DSwapChain
**swapchain
)
2905 IDirect3DDevice8Impl
*This
= impl_from_IWineD3DDeviceParent(iface
);
2906 D3DPRESENT_PARAMETERS local_parameters
;
2907 IDirect3DSwapChain8
*d3d_swapchain
;
2910 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface
, present_parameters
, swapchain
);
2912 /* Copy the presentation parameters */
2913 local_parameters
.BackBufferWidth
= present_parameters
->BackBufferWidth
;
2914 local_parameters
.BackBufferHeight
= present_parameters
->BackBufferHeight
;
2915 local_parameters
.BackBufferFormat
= d3dformat_from_wined3dformat(present_parameters
->BackBufferFormat
);
2916 local_parameters
.BackBufferCount
= present_parameters
->BackBufferCount
;
2917 local_parameters
.MultiSampleType
= present_parameters
->MultiSampleType
;
2918 local_parameters
.SwapEffect
= present_parameters
->SwapEffect
;
2919 local_parameters
.hDeviceWindow
= present_parameters
->hDeviceWindow
;
2920 local_parameters
.Windowed
= present_parameters
->Windowed
;
2921 local_parameters
.EnableAutoDepthStencil
= present_parameters
->EnableAutoDepthStencil
;
2922 local_parameters
.AutoDepthStencilFormat
= d3dformat_from_wined3dformat(present_parameters
->AutoDepthStencilFormat
);
2923 local_parameters
.Flags
= present_parameters
->Flags
;
2924 local_parameters
.FullScreen_RefreshRateInHz
= present_parameters
->FullScreen_RefreshRateInHz
;
2925 local_parameters
.FullScreen_PresentationInterval
= present_parameters
->PresentationInterval
;
2927 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(&This
->IDirect3DDevice8_iface
,
2928 &local_parameters
, &d3d_swapchain
);
2931 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface
, hr
);
2936 *swapchain
= ((IDirect3DSwapChain8Impl
*)d3d_swapchain
)->wineD3DSwapChain
;
2937 IWineD3DSwapChain_AddRef(*swapchain
);
2938 IDirect3DSwapChain8_Release(d3d_swapchain
);
2940 /* Copy back the presentation parameters */
2941 present_parameters
->BackBufferWidth
= local_parameters
.BackBufferWidth
;
2942 present_parameters
->BackBufferHeight
= local_parameters
.BackBufferHeight
;
2943 present_parameters
->BackBufferFormat
= wined3dformat_from_d3dformat(local_parameters
.BackBufferFormat
);
2944 present_parameters
->BackBufferCount
= local_parameters
.BackBufferCount
;
2945 present_parameters
->MultiSampleType
= local_parameters
.MultiSampleType
;
2946 present_parameters
->SwapEffect
= local_parameters
.SwapEffect
;
2947 present_parameters
->hDeviceWindow
= local_parameters
.hDeviceWindow
;
2948 present_parameters
->Windowed
= local_parameters
.Windowed
;
2949 present_parameters
->EnableAutoDepthStencil
= local_parameters
.EnableAutoDepthStencil
;
2950 present_parameters
->AutoDepthStencilFormat
= wined3dformat_from_d3dformat(local_parameters
.AutoDepthStencilFormat
);
2951 present_parameters
->Flags
= local_parameters
.Flags
;
2952 present_parameters
->FullScreen_RefreshRateInHz
= local_parameters
.FullScreen_RefreshRateInHz
;
2953 present_parameters
->PresentationInterval
= local_parameters
.FullScreen_PresentationInterval
;
2958 static const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl
=
2960 /* IUnknown methods */
2961 device_parent_QueryInterface
,
2962 device_parent_AddRef
,
2963 device_parent_Release
,
2964 /* IWineD3DDeviceParent methods */
2965 device_parent_WineD3DDeviceCreated
,
2966 device_parent_CreateSurface
,
2967 device_parent_CreateRenderTarget
,
2968 device_parent_CreateDepthStencilSurface
,
2969 device_parent_CreateVolume
,
2970 device_parent_CreateSwapChain
,
2973 static void setup_fpu(void)
2975 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
2977 __asm__
volatile ("fnstcw %0" : "=m" (cw
));
2978 cw
= (cw
& ~0xf3f) | 0x3f;
2979 __asm__
volatile ("fldcw %0" : : "m" (cw
));
2981 FIXME("FPU setup not implemented for this platform.\n");
2985 HRESULT
device_init(IDirect3DDevice8Impl
*device
, struct wined3d
*wined3d
, UINT adapter
,
2986 D3DDEVTYPE device_type
, HWND focus_window
, DWORD flags
, D3DPRESENT_PARAMETERS
*parameters
)
2988 WINED3DPRESENT_PARAMETERS wined3d_parameters
;
2991 device
->IDirect3DDevice8_iface
.lpVtbl
= &Direct3DDevice8_Vtbl
;
2992 device
->IWineD3DDeviceParent_iface
.lpVtbl
= &d3d8_wined3d_device_parent_vtbl
;
2994 device
->handle_table
.entries
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2995 D3D8_INITIAL_HANDLE_TABLE_SIZE
* sizeof(*device
->handle_table
.entries
));
2996 if (!device
->handle_table
.entries
)
2998 ERR("Failed to allocate handle table memory.\n");
2999 return E_OUTOFMEMORY
;
3001 device
->handle_table
.table_size
= D3D8_INITIAL_HANDLE_TABLE_SIZE
;
3003 if (!(flags
& D3DCREATE_FPU_PRESERVE
)) setup_fpu();
3005 wined3d_mutex_lock();
3006 hr
= wined3d_device_create(wined3d
, adapter
, device_type
, focus_window
, flags
,
3007 &device
->IWineD3DDeviceParent_iface
, &device
->WineD3DDevice
);
3010 WARN("Failed to create wined3d device, hr %#x.\n", hr
);
3011 wined3d_mutex_unlock();
3012 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
3016 if (!parameters
->Windowed
)
3018 HWND device_window
= parameters
->hDeviceWindow
;
3020 if (!focus_window
) focus_window
= device_window
;
3021 if (FAILED(hr
= IWineD3DDevice_AcquireFocusWindow(device
->WineD3DDevice
, focus_window
)))
3023 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
3024 IWineD3DDevice_Release(device
->WineD3DDevice
);
3025 wined3d_mutex_unlock();
3026 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
3030 if (!device_window
) device_window
= focus_window
;
3031 IWineD3DDevice_SetupFullscreenWindow(device
->WineD3DDevice
, device_window
,
3032 parameters
->BackBufferWidth
,
3033 parameters
->BackBufferHeight
);
3036 if (flags
& D3DCREATE_MULTITHREADED
) IWineD3DDevice_SetMultithreaded(device
->WineD3DDevice
);
3038 wined3d_parameters
.BackBufferWidth
= parameters
->BackBufferWidth
;
3039 wined3d_parameters
.BackBufferHeight
= parameters
->BackBufferHeight
;
3040 wined3d_parameters
.BackBufferFormat
= wined3dformat_from_d3dformat(parameters
->BackBufferFormat
);
3041 wined3d_parameters
.BackBufferCount
= parameters
->BackBufferCount
;
3042 wined3d_parameters
.MultiSampleType
= parameters
->MultiSampleType
;
3043 wined3d_parameters
.MultiSampleQuality
= 0; /* d3d9 only */
3044 wined3d_parameters
.SwapEffect
= parameters
->SwapEffect
;
3045 wined3d_parameters
.hDeviceWindow
= parameters
->hDeviceWindow
;
3046 wined3d_parameters
.Windowed
= parameters
->Windowed
;
3047 wined3d_parameters
.EnableAutoDepthStencil
= parameters
->EnableAutoDepthStencil
;
3048 wined3d_parameters
.AutoDepthStencilFormat
= wined3dformat_from_d3dformat(parameters
->AutoDepthStencilFormat
);
3049 wined3d_parameters
.Flags
= parameters
->Flags
;
3050 wined3d_parameters
.FullScreen_RefreshRateInHz
= parameters
->FullScreen_RefreshRateInHz
;
3051 wined3d_parameters
.PresentationInterval
= parameters
->FullScreen_PresentationInterval
;
3052 wined3d_parameters
.AutoRestoreDisplayMode
= TRUE
;
3054 hr
= IWineD3DDevice_Init3D(device
->WineD3DDevice
, &wined3d_parameters
);
3057 WARN("Failed to initialize 3D, hr %#x.\n", hr
);
3058 IWineD3DDevice_ReleaseFocusWindow(device
->WineD3DDevice
);
3059 IWineD3DDevice_Release(device
->WineD3DDevice
);
3060 wined3d_mutex_unlock();
3061 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
3065 hr
= IWineD3DDevice_SetRenderState(device
->WineD3DDevice
, WINED3DRS_POINTSIZE_MIN
, 0);
3066 wined3d_mutex_unlock();
3069 ERR("Failed to set minimum pointsize, hr %#x.\n", hr
);
3073 parameters
->BackBufferWidth
= wined3d_parameters
.BackBufferWidth
;
3074 parameters
->BackBufferHeight
= wined3d_parameters
.BackBufferHeight
;
3075 parameters
->BackBufferFormat
= d3dformat_from_wined3dformat(wined3d_parameters
.BackBufferFormat
);
3076 parameters
->BackBufferCount
= wined3d_parameters
.BackBufferCount
;
3077 parameters
->MultiSampleType
= wined3d_parameters
.MultiSampleType
;
3078 parameters
->SwapEffect
= wined3d_parameters
.SwapEffect
;
3079 parameters
->hDeviceWindow
= wined3d_parameters
.hDeviceWindow
;
3080 parameters
->Windowed
= wined3d_parameters
.Windowed
;
3081 parameters
->EnableAutoDepthStencil
= wined3d_parameters
.EnableAutoDepthStencil
;
3082 parameters
->AutoDepthStencilFormat
= d3dformat_from_wined3dformat(wined3d_parameters
.AutoDepthStencilFormat
);
3083 parameters
->Flags
= wined3d_parameters
.Flags
;
3084 parameters
->FullScreen_RefreshRateInHz
= wined3d_parameters
.FullScreen_RefreshRateInHz
;
3085 parameters
->FullScreen_PresentationInterval
= wined3d_parameters
.PresentationInterval
;
3087 device
->declArraySize
= 16;
3088 device
->decls
= HeapAlloc(GetProcessHeap(), 0, device
->declArraySize
* sizeof(*device
->decls
));
3091 ERR("Failed to allocate FVF vertex delcaration map memory.\n");
3099 wined3d_mutex_lock();
3100 IWineD3DDevice_Uninit3D(device
->WineD3DDevice
);
3101 IWineD3DDevice_ReleaseFocusWindow(device
->WineD3DDevice
);
3102 IWineD3DDevice_Release(device
->WineD3DDevice
);
3103 wined3d_mutex_unlock();
3104 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);