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
);
1382 TRACE("iface %p, state %#x, value %#x.\n", iface
, State
, Value
);
1384 wined3d_mutex_lock();
1388 wined3d_value
.f
= Value
/ -16.0f
;
1389 hr
= IWineD3DDevice_SetRenderState(This
->WineD3DDevice
, WINED3DRS_DEPTHBIAS
, wined3d_value
.d
);
1393 hr
= IWineD3DDevice_SetRenderState(This
->WineD3DDevice
, State
, Value
);
1395 wined3d_mutex_unlock();
1400 static HRESULT WINAPI
IDirect3DDevice8Impl_GetRenderState(IDirect3DDevice8
*iface
,
1401 D3DRENDERSTATETYPE State
, DWORD
*pValue
)
1403 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1411 TRACE("iface %p, state %#x, value %p.\n", iface
, State
, pValue
);
1413 wined3d_mutex_lock();
1417 hr
= IWineD3DDevice_GetRenderState(This
->WineD3DDevice
, WINED3DRS_DEPTHBIAS
, &wined3d_value
.d
);
1418 if (SUCCEEDED(hr
)) *pValue
= -wined3d_value
.f
* 16.0f
;
1422 hr
= IWineD3DDevice_GetRenderState(This
->WineD3DDevice
, State
, pValue
);
1424 wined3d_mutex_unlock();
1429 static HRESULT WINAPI
IDirect3DDevice8Impl_BeginStateBlock(IDirect3DDevice8
*iface
)
1431 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1434 TRACE("iface %p.\n", iface
);
1436 wined3d_mutex_lock();
1437 hr
= IWineD3DDevice_BeginStateBlock(This
->WineD3DDevice
);
1438 wined3d_mutex_unlock();
1443 static HRESULT WINAPI
IDirect3DDevice8Impl_EndStateBlock(IDirect3DDevice8
*iface
, DWORD
*pToken
)
1445 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1446 struct wined3d_stateblock
*stateblock
;
1449 TRACE("iface %p, token %p.\n", iface
, pToken
);
1451 /* Tell wineD3D to endstateblock before anything else (in case we run out
1452 * of memory later and cause locking problems)
1454 wined3d_mutex_lock();
1455 hr
= IWineD3DDevice_EndStateBlock(This
->WineD3DDevice
, &stateblock
);
1457 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
1458 wined3d_mutex_unlock();
1462 *pToken
= d3d8_allocate_handle(&This
->handle_table
, stateblock
, D3D8_HANDLE_SB
);
1463 wined3d_mutex_unlock();
1465 if (*pToken
== D3D8_INVALID_HANDLE
)
1467 ERR("Failed to create a handle\n");
1468 wined3d_mutex_lock();
1469 wined3d_stateblock_decref(stateblock
);
1470 wined3d_mutex_unlock();
1475 TRACE("Returning %#x (%p).\n", *pToken
, stateblock
);
1480 static HRESULT WINAPI
IDirect3DDevice8Impl_ApplyStateBlock(IDirect3DDevice8
*iface
, DWORD Token
)
1482 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1483 struct wined3d_stateblock
*stateblock
;
1486 TRACE("iface %p, token %#x.\n", iface
, Token
);
1488 if (!Token
) return D3D_OK
;
1490 wined3d_mutex_lock();
1491 stateblock
= d3d8_get_object(&This
->handle_table
, Token
- 1, D3D8_HANDLE_SB
);
1494 WARN("Invalid handle (%#x) passed.\n", Token
);
1495 wined3d_mutex_unlock();
1496 return D3DERR_INVALIDCALL
;
1498 hr
= wined3d_stateblock_apply(stateblock
);
1499 wined3d_mutex_unlock();
1504 static HRESULT WINAPI
IDirect3DDevice8Impl_CaptureStateBlock(IDirect3DDevice8
*iface
, DWORD Token
)
1506 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1507 struct wined3d_stateblock
*stateblock
;
1510 TRACE("iface %p, token %#x.\n", iface
, Token
);
1512 wined3d_mutex_lock();
1513 stateblock
= d3d8_get_object(&This
->handle_table
, Token
- 1, D3D8_HANDLE_SB
);
1516 WARN("Invalid handle (%#x) passed.\n", Token
);
1517 wined3d_mutex_unlock();
1518 return D3DERR_INVALIDCALL
;
1520 hr
= wined3d_stateblock_capture(stateblock
);
1521 wined3d_mutex_unlock();
1526 static HRESULT WINAPI
IDirect3DDevice8Impl_DeleteStateBlock(IDirect3DDevice8
*iface
, DWORD Token
)
1528 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1529 struct wined3d_stateblock
*stateblock
;
1531 TRACE("iface %p, token %#x.\n", iface
, Token
);
1533 wined3d_mutex_lock();
1534 stateblock
= d3d8_free_handle(&This
->handle_table
, Token
- 1, D3D8_HANDLE_SB
);
1538 WARN("Invalid handle (%#x) passed.\n", Token
);
1539 wined3d_mutex_unlock();
1540 return D3DERR_INVALIDCALL
;
1543 if (wined3d_stateblock_decref(stateblock
))
1545 ERR("Stateblock %p has references left, this shouldn't happen.\n", stateblock
);
1547 wined3d_mutex_unlock();
1552 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateStateBlock(IDirect3DDevice8
*iface
,
1553 D3DSTATEBLOCKTYPE Type
, DWORD
*handle
)
1555 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1556 struct wined3d_stateblock
*stateblock
;
1559 TRACE("iface %p, type %#x, handle %p.\n", iface
, Type
, handle
);
1561 if (Type
!= D3DSBT_ALL
1562 && Type
!= D3DSBT_PIXELSTATE
1563 && Type
!= D3DSBT_VERTEXSTATE
)
1565 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1566 return D3DERR_INVALIDCALL
;
1569 wined3d_mutex_lock();
1570 hr
= IWineD3DDevice_CreateStateBlock(This
->WineD3DDevice
, (WINED3DSTATEBLOCKTYPE
)Type
, &stateblock
);
1573 wined3d_mutex_unlock();
1574 ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr
);
1578 *handle
= d3d8_allocate_handle(&This
->handle_table
, stateblock
, D3D8_HANDLE_SB
);
1579 wined3d_mutex_unlock();
1581 if (*handle
== D3D8_INVALID_HANDLE
)
1583 ERR("Failed to allocate a handle.\n");
1584 wined3d_mutex_lock();
1585 wined3d_stateblock_decref(stateblock
);
1586 wined3d_mutex_unlock();
1591 TRACE("Returning %#x (%p).\n", *handle
, stateblock
);
1596 static HRESULT WINAPI
IDirect3DDevice8Impl_SetClipStatus(IDirect3DDevice8
*iface
,
1597 const D3DCLIPSTATUS8
*pClipStatus
)
1599 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1602 TRACE("iface %p, clip_status %p.\n", iface
, pClipStatus
);
1603 /* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
1605 wined3d_mutex_lock();
1606 hr
= IWineD3DDevice_SetClipStatus(This
->WineD3DDevice
, (const WINED3DCLIPSTATUS
*)pClipStatus
);
1607 wined3d_mutex_unlock();
1612 static HRESULT WINAPI
IDirect3DDevice8Impl_GetClipStatus(IDirect3DDevice8
*iface
,
1613 D3DCLIPSTATUS8
*pClipStatus
)
1615 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1618 TRACE("iface %p, clip_status %p.\n", iface
, pClipStatus
);
1620 wined3d_mutex_lock();
1621 hr
= IWineD3DDevice_GetClipStatus(This
->WineD3DDevice
, (WINED3DCLIPSTATUS
*)pClipStatus
);
1622 wined3d_mutex_unlock();
1627 static HRESULT WINAPI
IDirect3DDevice8Impl_GetTexture(IDirect3DDevice8
*iface
,
1628 DWORD Stage
, IDirect3DBaseTexture8
**ppTexture
)
1630 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1631 struct wined3d_texture
*wined3d_texture
;
1634 TRACE("iface %p, stage %u, texture %p.\n", iface
, Stage
, ppTexture
);
1636 if(ppTexture
== NULL
){
1637 return D3DERR_INVALIDCALL
;
1640 wined3d_mutex_lock();
1641 hr
= IWineD3DDevice_GetTexture(This
->WineD3DDevice
, Stage
, &wined3d_texture
);
1644 WARN("Failed to get texture for stage %u, hr %#x.\n", Stage
, hr
);
1645 wined3d_mutex_unlock();
1650 if (wined3d_texture
)
1652 *ppTexture
= wined3d_texture_get_parent(wined3d_texture
);
1653 IDirect3DBaseTexture8_AddRef(*ppTexture
);
1654 wined3d_texture_decref(wined3d_texture
);
1660 wined3d_mutex_unlock();
1665 static HRESULT WINAPI
IDirect3DDevice8Impl_SetTexture(IDirect3DDevice8
*iface
, DWORD Stage
,
1666 IDirect3DBaseTexture8
*pTexture
)
1668 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1671 TRACE("iface %p, stage %u, texture %p.\n", iface
, Stage
, pTexture
);
1673 wined3d_mutex_lock();
1674 hr
= IWineD3DDevice_SetTexture(This
->WineD3DDevice
, Stage
,
1675 pTexture
? ((IDirect3DBaseTexture8Impl
*)pTexture
)->wined3d_texture
: NULL
);
1676 wined3d_mutex_unlock();
1681 static const struct tss_lookup
1688 {FALSE
, WINED3DTSS_FORCE_DWORD
}, /* 0, unused */
1689 {FALSE
, WINED3DTSS_COLOROP
}, /* 1, D3DTSS_COLOROP */
1690 {FALSE
, WINED3DTSS_COLORARG1
}, /* 2, D3DTSS_COLORARG1 */
1691 {FALSE
, WINED3DTSS_COLORARG2
}, /* 3, D3DTSS_COLORARG2 */
1692 {FALSE
, WINED3DTSS_ALPHAOP
}, /* 4, D3DTSS_ALPHAOP */
1693 {FALSE
, WINED3DTSS_ALPHAARG1
}, /* 5, D3DTSS_ALPHAARG1 */
1694 {FALSE
, WINED3DTSS_ALPHAARG2
}, /* 6, D3DTSS_ALPHAARG2 */
1695 {FALSE
, WINED3DTSS_BUMPENVMAT00
}, /* 7, D3DTSS_BUMPENVMAT00 */
1696 {FALSE
, WINED3DTSS_BUMPENVMAT01
}, /* 8, D3DTSS_BUMPENVMAT01 */
1697 {FALSE
, WINED3DTSS_BUMPENVMAT10
}, /* 9, D3DTSS_BUMPENVMAT10 */
1698 {FALSE
, WINED3DTSS_BUMPENVMAT11
}, /* 10, D3DTSS_BUMPENVMAT11 */
1699 {FALSE
, WINED3DTSS_TEXCOORDINDEX
}, /* 11, D3DTSS_TEXCOORDINDEX */
1700 {FALSE
, WINED3DTSS_FORCE_DWORD
}, /* 12, unused */
1701 {TRUE
, WINED3DSAMP_ADDRESSU
}, /* 13, D3DTSS_ADDRESSU */
1702 {TRUE
, WINED3DSAMP_ADDRESSV
}, /* 14, D3DTSS_ADDRESSV */
1703 {TRUE
, WINED3DSAMP_BORDERCOLOR
}, /* 15, D3DTSS_BORDERCOLOR */
1704 {TRUE
, WINED3DSAMP_MAGFILTER
}, /* 16, D3DTSS_MAGFILTER */
1705 {TRUE
, WINED3DSAMP_MINFILTER
}, /* 17, D3DTSS_MINFILTER */
1706 {TRUE
, WINED3DSAMP_MIPFILTER
}, /* 18, D3DTSS_MIPFILTER */
1707 {TRUE
, WINED3DSAMP_MIPMAPLODBIAS
}, /* 19, D3DTSS_MIPMAPLODBIAS */
1708 {TRUE
, WINED3DSAMP_MAXMIPLEVEL
}, /* 20, D3DTSS_MAXMIPLEVEL */
1709 {TRUE
, WINED3DSAMP_MAXANISOTROPY
}, /* 21, D3DTSS_MAXANISOTROPY */
1710 {FALSE
, WINED3DTSS_BUMPENVLSCALE
}, /* 22, D3DTSS_BUMPENVLSCALE */
1711 {FALSE
, WINED3DTSS_BUMPENVLOFFSET
}, /* 23, D3DTSS_BUMPENVLOFFSET */
1712 {FALSE
, WINED3DTSS_TEXTURETRANSFORMFLAGS
}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1713 {TRUE
, WINED3DSAMP_ADDRESSW
}, /* 25, D3DTSS_ADDRESSW */
1714 {FALSE
, WINED3DTSS_COLORARG0
}, /* 26, D3DTSS_COLORARG0 */
1715 {FALSE
, WINED3DTSS_ALPHAARG0
}, /* 27, D3DTSS_ALPHAARG0 */
1716 {FALSE
, WINED3DTSS_RESULTARG
}, /* 28, D3DTSS_RESULTARG */
1719 static HRESULT WINAPI
IDirect3DDevice8Impl_GetTextureStageState(IDirect3DDevice8
*iface
,
1720 DWORD Stage
, D3DTEXTURESTAGESTATETYPE Type
, DWORD
*pValue
)
1722 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1723 const struct tss_lookup
*l
;
1726 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface
, Stage
, Type
, pValue
);
1728 if (Type
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
1730 WARN("Invalid Type %#x passed.\n", Type
);
1734 l
= &tss_lookup
[Type
];
1736 wined3d_mutex_lock();
1737 if (l
->sampler_state
) hr
= IWineD3DDevice_GetSamplerState(This
->WineD3DDevice
, Stage
, l
->state
, pValue
);
1738 else hr
= IWineD3DDevice_GetTextureStageState(This
->WineD3DDevice
, Stage
, l
->state
, pValue
);
1739 wined3d_mutex_unlock();
1744 static HRESULT WINAPI
IDirect3DDevice8Impl_SetTextureStageState(IDirect3DDevice8
*iface
,
1745 DWORD Stage
, D3DTEXTURESTAGESTATETYPE Type
, DWORD Value
)
1747 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1748 const struct tss_lookup
*l
;
1751 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface
, Stage
, Type
, Value
);
1753 if (Type
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
1755 WARN("Invalid Type %#x passed.\n", Type
);
1759 l
= &tss_lookup
[Type
];
1761 wined3d_mutex_lock();
1762 if (l
->sampler_state
) hr
= IWineD3DDevice_SetSamplerState(This
->WineD3DDevice
, Stage
, l
->state
, Value
);
1763 else hr
= IWineD3DDevice_SetTextureStageState(This
->WineD3DDevice
, Stage
, l
->state
, Value
);
1764 wined3d_mutex_unlock();
1769 static HRESULT WINAPI
IDirect3DDevice8Impl_ValidateDevice(IDirect3DDevice8
*iface
,
1772 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1775 TRACE("iface %p, pass_count %p.\n", iface
, pNumPasses
);
1777 wined3d_mutex_lock();
1778 hr
= IWineD3DDevice_ValidateDevice(This
->WineD3DDevice
, pNumPasses
);
1779 wined3d_mutex_unlock();
1784 static HRESULT WINAPI
IDirect3DDevice8Impl_GetInfo(IDirect3DDevice8
*iface
,
1785 DWORD info_id
, void *info
, DWORD info_size
)
1787 FIXME("iface %p, info_id %#x, info %p, info_size %u stub!\n", iface
, info_id
, info
, info_size
);
1792 static HRESULT WINAPI
IDirect3DDevice8Impl_SetPaletteEntries(IDirect3DDevice8
*iface
,
1793 UINT PaletteNumber
, const PALETTEENTRY
*pEntries
)
1795 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1798 TRACE("iface %p, palette_idx %u, entries %p.\n", iface
, PaletteNumber
, pEntries
);
1800 wined3d_mutex_lock();
1801 hr
= IWineD3DDevice_SetPaletteEntries(This
->WineD3DDevice
, PaletteNumber
, pEntries
);
1802 wined3d_mutex_unlock();
1807 static HRESULT WINAPI
IDirect3DDevice8Impl_GetPaletteEntries(IDirect3DDevice8
*iface
,
1808 UINT PaletteNumber
, PALETTEENTRY
*pEntries
)
1810 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1813 TRACE("iface %p, palette_idx %u, entries %p.\n", iface
, PaletteNumber
, pEntries
);
1815 wined3d_mutex_lock();
1816 hr
= IWineD3DDevice_GetPaletteEntries(This
->WineD3DDevice
, PaletteNumber
, pEntries
);
1817 wined3d_mutex_unlock();
1822 static HRESULT WINAPI
IDirect3DDevice8Impl_SetCurrentTexturePalette(IDirect3DDevice8
*iface
,
1825 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1828 TRACE("iface %p, palette_idx %u.\n", iface
, PaletteNumber
);
1830 wined3d_mutex_lock();
1831 hr
= IWineD3DDevice_SetCurrentTexturePalette(This
->WineD3DDevice
, PaletteNumber
);
1832 wined3d_mutex_unlock();
1837 static HRESULT WINAPI
IDirect3DDevice8Impl_GetCurrentTexturePalette(IDirect3DDevice8
*iface
,
1838 UINT
*PaletteNumber
)
1840 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1843 TRACE("iface %p, palette_idx %p.\n", iface
, PaletteNumber
);
1845 wined3d_mutex_lock();
1846 hr
= IWineD3DDevice_GetCurrentTexturePalette(This
->WineD3DDevice
, PaletteNumber
);
1847 wined3d_mutex_unlock();
1852 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawPrimitive(IDirect3DDevice8
*iface
,
1853 D3DPRIMITIVETYPE PrimitiveType
, UINT StartVertex
, UINT PrimitiveCount
)
1855 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1858 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1859 iface
, PrimitiveType
, StartVertex
, PrimitiveCount
);
1861 wined3d_mutex_lock();
1862 IWineD3DDevice_SetPrimitiveType(This
->WineD3DDevice
, PrimitiveType
);
1863 hr
= IWineD3DDevice_DrawPrimitive(This
->WineD3DDevice
, StartVertex
,
1864 vertex_count_from_primitive_count(PrimitiveType
, PrimitiveCount
));
1865 wined3d_mutex_unlock();
1870 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawIndexedPrimitive(IDirect3DDevice8
*iface
,
1871 D3DPRIMITIVETYPE PrimitiveType
, UINT MinVertexIndex
, UINT NumVertices
, UINT startIndex
,
1874 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1877 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, start_idx %u, primitive_count %u.\n",
1878 iface
, PrimitiveType
, MinVertexIndex
, NumVertices
, startIndex
, primCount
);
1880 wined3d_mutex_lock();
1881 IWineD3DDevice_SetPrimitiveType(This
->WineD3DDevice
, PrimitiveType
);
1882 hr
= IWineD3DDevice_DrawIndexedPrimitive(This
->WineD3DDevice
, startIndex
,
1883 vertex_count_from_primitive_count(PrimitiveType
, primCount
));
1884 wined3d_mutex_unlock();
1889 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawPrimitiveUP(IDirect3DDevice8
*iface
,
1890 D3DPRIMITIVETYPE PrimitiveType
, UINT PrimitiveCount
, const void *pVertexStreamZeroData
,
1891 UINT VertexStreamZeroStride
)
1893 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1896 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
1897 iface
, PrimitiveType
, PrimitiveCount
, pVertexStreamZeroData
, VertexStreamZeroStride
);
1899 wined3d_mutex_lock();
1900 IWineD3DDevice_SetPrimitiveType(This
->WineD3DDevice
, PrimitiveType
);
1901 hr
= IWineD3DDevice_DrawPrimitiveUP(This
->WineD3DDevice
,
1902 vertex_count_from_primitive_count(PrimitiveType
, PrimitiveCount
),
1903 pVertexStreamZeroData
, VertexStreamZeroStride
);
1904 wined3d_mutex_unlock();
1909 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(IDirect3DDevice8
*iface
,
1910 D3DPRIMITIVETYPE PrimitiveType
, UINT MinVertexIndex
, UINT NumVertexIndices
,
1911 UINT PrimitiveCount
, const void *pIndexData
, D3DFORMAT IndexDataFormat
,
1912 const void *pVertexStreamZeroData
, UINT VertexStreamZeroStride
)
1914 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1917 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
1918 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
1919 iface
, PrimitiveType
, MinVertexIndex
, NumVertexIndices
, PrimitiveCount
,
1920 pIndexData
, IndexDataFormat
, pVertexStreamZeroData
, VertexStreamZeroStride
);
1922 wined3d_mutex_lock();
1923 IWineD3DDevice_SetPrimitiveType(This
->WineD3DDevice
, PrimitiveType
);
1924 hr
= IWineD3DDevice_DrawIndexedPrimitiveUP(This
->WineD3DDevice
,
1925 vertex_count_from_primitive_count(PrimitiveType
, PrimitiveCount
), pIndexData
,
1926 wined3dformat_from_d3dformat(IndexDataFormat
), pVertexStreamZeroData
, VertexStreamZeroStride
);
1927 wined3d_mutex_unlock();
1932 static HRESULT WINAPI
IDirect3DDevice8Impl_ProcessVertices(IDirect3DDevice8
*iface
,
1933 UINT SrcStartIndex
, UINT DestIndex
, UINT VertexCount
, IDirect3DVertexBuffer8
*pDestBuffer
,
1936 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1938 IDirect3DVertexBuffer8Impl
*dest
= (IDirect3DVertexBuffer8Impl
*) pDestBuffer
;
1940 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, flags %#x.\n",
1941 iface
, SrcStartIndex
, DestIndex
, VertexCount
, pDestBuffer
, Flags
);
1943 wined3d_mutex_lock();
1944 hr
= IWineD3DDevice_ProcessVertices(This
->WineD3DDevice
,SrcStartIndex
, DestIndex
, VertexCount
, dest
->wineD3DVertexBuffer
, NULL
, Flags
, dest
->fvf
);
1945 wined3d_mutex_unlock();
1950 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateVertexShader(IDirect3DDevice8
*iface
,
1951 const DWORD
*declaration
, const DWORD
*byte_code
, DWORD
*shader
, DWORD usage
)
1953 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1954 IDirect3DVertexShader8Impl
*object
;
1955 DWORD shader_handle
;
1959 TRACE("iface %p, declaration %p, byte_code %p, shader %p, usage %#x.\n",
1960 iface
, declaration
, byte_code
, shader
, usage
);
1962 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1965 ERR("Failed to allocate vertex shader memory.\n");
1967 return E_OUTOFMEMORY
;
1970 wined3d_mutex_lock();
1971 handle
= d3d8_allocate_handle(&This
->handle_table
, object
, D3D8_HANDLE_VS
);
1972 wined3d_mutex_unlock();
1973 if (handle
== D3D8_INVALID_HANDLE
)
1975 ERR("Failed to allocate vertex shader handle.\n");
1976 HeapFree(GetProcessHeap(), 0, object
);
1978 return E_OUTOFMEMORY
;
1981 shader_handle
= handle
+ VS_HIGHESTFIXEDFXF
+ 1;
1983 hr
= vertexshader_init(object
, This
, declaration
, byte_code
, shader_handle
, usage
);
1986 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
1987 wined3d_mutex_lock();
1988 d3d8_free_handle(&This
->handle_table
, handle
, D3D8_HANDLE_VS
);
1989 wined3d_mutex_unlock();
1990 HeapFree(GetProcessHeap(), 0, object
);
1995 TRACE("Created vertex shader %p (handle %#x).\n", object
, shader_handle
);
1996 *shader
= shader_handle
;
2001 static IDirect3DVertexDeclaration8Impl
*IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl
*This
, DWORD fvf
)
2003 IDirect3DVertexDeclaration8Impl
*d3d8_declaration
;
2005 int p
, low
, high
; /* deliberately signed */
2006 struct FvfToDecl
*convertedDecls
= This
->decls
;
2008 TRACE("Searching for declaration for fvf %08x... ", fvf
);
2011 high
= This
->numConvertedDecls
- 1;
2012 while(low
<= high
) {
2013 p
= (low
+ high
) >> 1;
2015 if(convertedDecls
[p
].fvf
== fvf
) {
2016 TRACE("found %p\n", convertedDecls
[p
].decl
);
2017 return (IDirect3DVertexDeclaration8Impl
*)convertedDecls
[p
].decl
;
2018 } else if(convertedDecls
[p
].fvf
< fvf
) {
2024 TRACE("not found. Creating and inserting at position %d.\n", low
);
2026 d3d8_declaration
= HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration
));
2027 if (!d3d8_declaration
)
2029 ERR("Memory allocation failed.\n");
2033 hr
= vertexdeclaration_init_fvf(d3d8_declaration
, This
, fvf
);
2036 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr
);
2037 HeapFree(GetProcessHeap(), 0, d3d8_declaration
);
2041 if(This
->declArraySize
== This
->numConvertedDecls
) {
2042 int grow
= This
->declArraySize
/ 2;
2043 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
2044 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
2045 if(!convertedDecls
) {
2046 /* This will destroy it */
2047 IDirect3DVertexDeclaration8_Release((IDirect3DVertexDeclaration8
*)d3d8_declaration
);
2050 This
->decls
= convertedDecls
;
2051 This
->declArraySize
+= grow
;
2054 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
2055 convertedDecls
[low
].decl
= (IDirect3DVertexDeclaration8
*)d3d8_declaration
;
2056 convertedDecls
[low
].fvf
= fvf
;
2057 This
->numConvertedDecls
++;
2059 TRACE("Returning %p. %u decls in array\n", d3d8_declaration
, This
->numConvertedDecls
);
2060 return d3d8_declaration
;
2063 static HRESULT WINAPI
IDirect3DDevice8Impl_SetVertexShader(IDirect3DDevice8
*iface
, DWORD pShader
)
2065 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2066 IDirect3DVertexShader8Impl
*shader
;
2069 TRACE("iface %p, shader %#x.\n", iface
, pShader
);
2071 if (VS_HIGHESTFIXEDFXF
>= pShader
) {
2072 TRACE("Setting FVF, %#x\n", pShader
);
2074 wined3d_mutex_lock();
2075 IWineD3DDevice_SetVertexDeclaration(This
->WineD3DDevice
,
2076 IDirect3DDevice8Impl_FindDecl(This
, pShader
)->wined3d_vertex_declaration
);
2077 IWineD3DDevice_SetVertexShader(This
->WineD3DDevice
, NULL
);
2078 wined3d_mutex_unlock();
2083 TRACE("Setting shader\n");
2085 wined3d_mutex_lock();
2086 shader
= d3d8_get_object(&This
->handle_table
, pShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
);
2089 WARN("Invalid handle (%#x) passed.\n", pShader
);
2090 wined3d_mutex_unlock();
2092 return D3DERR_INVALIDCALL
;
2095 hr
= IWineD3DDevice_SetVertexDeclaration(This
->WineD3DDevice
,
2096 ((IDirect3DVertexDeclaration8Impl
*)shader
->vertex_declaration
)->wined3d_vertex_declaration
);
2098 hr
= IWineD3DDevice_SetVertexShader(This
->WineD3DDevice
, shader
->wined3d_shader
);
2099 wined3d_mutex_unlock();
2101 TRACE("Returning hr %#x\n", hr
);
2106 static HRESULT WINAPI
IDirect3DDevice8Impl_GetVertexShader(IDirect3DDevice8
*iface
, DWORD
*ppShader
)
2108 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2109 struct wined3d_vertex_declaration
*wined3d_declaration
;
2110 IDirect3DVertexDeclaration8
*d3d8_declaration
;
2113 TRACE("iface %p, shader %p.\n", iface
, ppShader
);
2115 wined3d_mutex_lock();
2116 hr
= IWineD3DDevice_GetVertexDeclaration(This
->WineD3DDevice
, &wined3d_declaration
);
2119 wined3d_mutex_unlock();
2120 WARN("(%p) : Call to IWineD3DDevice_GetVertexDeclaration failed %#x (device %p)\n",
2121 This
, hr
, This
->WineD3DDevice
);
2125 if (!wined3d_declaration
)
2127 wined3d_mutex_unlock();
2132 d3d8_declaration
= wined3d_vertex_declaration_get_parent(wined3d_declaration
);
2133 wined3d_vertex_declaration_decref(wined3d_declaration
);
2134 wined3d_mutex_unlock();
2135 *ppShader
= ((IDirect3DVertexDeclaration8Impl
*)d3d8_declaration
)->shader_handle
;
2137 TRACE("(%p) : returning %#x\n", This
, *ppShader
);
2142 static HRESULT WINAPI
IDirect3DDevice8Impl_DeleteVertexShader(IDirect3DDevice8
*iface
, DWORD pShader
)
2144 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2145 IDirect3DVertexShader8Impl
*shader
;
2146 struct wined3d_shader
*cur
;
2148 TRACE("iface %p, shader %#x.\n", iface
, pShader
);
2150 wined3d_mutex_lock();
2151 shader
= d3d8_free_handle(&This
->handle_table
, pShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
);
2154 WARN("Invalid handle (%#x) passed.\n", pShader
);
2155 wined3d_mutex_unlock();
2157 return D3DERR_INVALIDCALL
;
2160 cur
= IWineD3DDevice_GetVertexShader(This
->WineD3DDevice
);
2163 if (cur
== shader
->wined3d_shader
)
2164 IDirect3DDevice8_SetVertexShader(iface
, 0);
2165 wined3d_shader_decref(cur
);
2168 wined3d_mutex_unlock();
2170 if (IDirect3DVertexShader8_Release(&shader
->IDirect3DVertexShader8_iface
))
2172 ERR("Shader %p has references left, this shouldn't happen.\n", shader
);
2178 static HRESULT WINAPI
IDirect3DDevice8Impl_SetVertexShaderConstant(IDirect3DDevice8
*iface
,
2179 DWORD Register
, const void *pConstantData
, DWORD ConstantCount
)
2181 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2184 TRACE("iface %p, register %u, data %p, count %u.\n",
2185 iface
, Register
, pConstantData
, ConstantCount
);
2187 if(Register
+ ConstantCount
> D3D8_MAX_VERTEX_SHADER_CONSTANTF
) {
2188 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2189 Register
+ ConstantCount
, D3D8_MAX_VERTEX_SHADER_CONSTANTF
);
2190 return D3DERR_INVALIDCALL
;
2193 wined3d_mutex_lock();
2194 hr
= IWineD3DDevice_SetVertexShaderConstantF(This
->WineD3DDevice
, Register
, pConstantData
, ConstantCount
);
2195 wined3d_mutex_unlock();
2200 static HRESULT WINAPI
IDirect3DDevice8Impl_GetVertexShaderConstant(IDirect3DDevice8
*iface
,
2201 DWORD Register
, void *pConstantData
, DWORD ConstantCount
)
2203 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2206 TRACE("iface %p, register %u, data %p, count %u.\n",
2207 iface
, Register
, pConstantData
, ConstantCount
);
2209 if(Register
+ ConstantCount
> D3D8_MAX_VERTEX_SHADER_CONSTANTF
) {
2210 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2211 Register
+ ConstantCount
, D3D8_MAX_VERTEX_SHADER_CONSTANTF
);
2212 return D3DERR_INVALIDCALL
;
2215 wined3d_mutex_lock();
2216 hr
= IWineD3DDevice_GetVertexShaderConstantF(This
->WineD3DDevice
, Register
, pConstantData
, ConstantCount
);
2217 wined3d_mutex_unlock();
2222 static HRESULT WINAPI
IDirect3DDevice8Impl_GetVertexShaderDeclaration(IDirect3DDevice8
*iface
,
2223 DWORD pVertexShader
, void *pData
, DWORD
*pSizeOfData
)
2225 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2226 IDirect3DVertexDeclaration8Impl
*declaration
;
2227 IDirect3DVertexShader8Impl
*shader
;
2229 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2230 iface
, pVertexShader
, pData
, pSizeOfData
);
2232 wined3d_mutex_lock();
2233 shader
= d3d8_get_object(&This
->handle_table
, pVertexShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
);
2234 wined3d_mutex_unlock();
2238 WARN("Invalid handle (%#x) passed.\n", pVertexShader
);
2239 return D3DERR_INVALIDCALL
;
2241 declaration
= (IDirect3DVertexDeclaration8Impl
*)shader
->vertex_declaration
;
2243 /* If pData is NULL, we just return the required size of the buffer. */
2245 *pSizeOfData
= declaration
->elements_size
;
2249 /* MSDN claims that if *pSizeOfData is smaller than the required size
2250 * we should write the required size and return D3DERR_MOREDATA.
2251 * That's not actually true. */
2252 if (*pSizeOfData
< declaration
->elements_size
) {
2253 return D3DERR_INVALIDCALL
;
2256 CopyMemory(pData
, declaration
->elements
, declaration
->elements_size
);
2261 static HRESULT WINAPI
IDirect3DDevice8Impl_GetVertexShaderFunction(IDirect3DDevice8
*iface
,
2262 DWORD pVertexShader
, void *pData
, DWORD
*pSizeOfData
)
2264 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2265 IDirect3DVertexShader8Impl
*shader
= NULL
;
2268 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2269 iface
, pVertexShader
, pData
, pSizeOfData
);
2271 wined3d_mutex_lock();
2272 shader
= d3d8_get_object(&This
->handle_table
, pVertexShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
);
2275 WARN("Invalid handle (%#x) passed.\n", pVertexShader
);
2276 wined3d_mutex_unlock();
2278 return D3DERR_INVALIDCALL
;
2281 if (!shader
->wined3d_shader
)
2283 wined3d_mutex_unlock();
2288 hr
= wined3d_shader_get_byte_code(shader
->wined3d_shader
, pData
, pSizeOfData
);
2289 wined3d_mutex_unlock();
2294 static HRESULT WINAPI
IDirect3DDevice8Impl_SetIndices(IDirect3DDevice8
*iface
,
2295 IDirect3DIndexBuffer8
*pIndexData
, UINT baseVertexIndex
)
2297 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2299 IDirect3DIndexBuffer8Impl
*ib
= (IDirect3DIndexBuffer8Impl
*)pIndexData
;
2301 TRACE("iface %p, buffer %p, base_vertex_idx %u.\n", iface
, pIndexData
, baseVertexIndex
);
2303 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
2304 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
2305 * vertex buffers can't be created to address them with an index that requires the 32nd bit
2306 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
2309 wined3d_mutex_lock();
2310 IWineD3DDevice_SetBaseVertexIndex(This
->WineD3DDevice
, baseVertexIndex
);
2311 hr
= IWineD3DDevice_SetIndexBuffer(This
->WineD3DDevice
,
2312 ib
? ib
->wineD3DIndexBuffer
: NULL
,
2313 ib
? ib
->format
: WINED3DFMT_UNKNOWN
);
2314 wined3d_mutex_unlock();
2319 static HRESULT WINAPI
IDirect3DDevice8Impl_GetIndices(IDirect3DDevice8
*iface
,
2320 IDirect3DIndexBuffer8
**ppIndexData
, UINT
*pBaseVertexIndex
)
2322 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2323 struct wined3d_buffer
*retIndexData
= NULL
;
2326 TRACE("iface %p, buffer %p, base_vertex_index %p.\n", iface
, ppIndexData
, pBaseVertexIndex
);
2328 if(ppIndexData
== NULL
){
2329 return D3DERR_INVALIDCALL
;
2332 /* The case from UINT to INT is safe because d3d8 will never set negative values */
2333 wined3d_mutex_lock();
2334 IWineD3DDevice_GetBaseVertexIndex(This
->WineD3DDevice
, (INT
*) pBaseVertexIndex
);
2335 hr
= IWineD3DDevice_GetIndexBuffer(This
->WineD3DDevice
, &retIndexData
);
2336 if (SUCCEEDED(hr
) && retIndexData
)
2338 *ppIndexData
= wined3d_buffer_get_parent(retIndexData
);
2339 IDirect3DIndexBuffer8_AddRef(*ppIndexData
);
2340 wined3d_buffer_decref(retIndexData
);
2342 if (FAILED(hr
)) FIXME("Call to GetIndices failed\n");
2343 *ppIndexData
= NULL
;
2345 wined3d_mutex_unlock();
2350 static HRESULT WINAPI
IDirect3DDevice8Impl_CreatePixelShader(IDirect3DDevice8
*iface
,
2351 const DWORD
*byte_code
, DWORD
*shader
)
2353 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2354 IDirect3DPixelShader8Impl
*object
;
2355 DWORD shader_handle
;
2359 TRACE("iface %p, byte_code %p, shader %p.\n", iface
, byte_code
, shader
);
2363 TRACE("(%p) Invalid call\n", This
);
2364 return D3DERR_INVALIDCALL
;
2367 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2370 ERR("Failed to allocate pixel shader memmory.\n");
2371 return E_OUTOFMEMORY
;
2374 wined3d_mutex_lock();
2375 handle
= d3d8_allocate_handle(&This
->handle_table
, object
, D3D8_HANDLE_PS
);
2376 wined3d_mutex_unlock();
2377 if (handle
== D3D8_INVALID_HANDLE
)
2379 ERR("Failed to allocate pixel shader handle.\n");
2380 HeapFree(GetProcessHeap(), 0, object
);
2381 return E_OUTOFMEMORY
;
2384 shader_handle
= handle
+ VS_HIGHESTFIXEDFXF
+ 1;
2386 hr
= pixelshader_init(object
, This
, byte_code
, shader_handle
);
2389 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
2390 wined3d_mutex_lock();
2391 d3d8_free_handle(&This
->handle_table
, handle
, D3D8_HANDLE_PS
);
2392 wined3d_mutex_unlock();
2393 HeapFree(GetProcessHeap(), 0, object
);
2398 TRACE("Created pixel shader %p (handle %#x).\n", object
, shader_handle
);
2399 *shader
= shader_handle
;
2404 static HRESULT WINAPI
IDirect3DDevice8Impl_SetPixelShader(IDirect3DDevice8
*iface
, DWORD pShader
)
2406 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2407 IDirect3DPixelShader8Impl
*shader
;
2410 TRACE("iface %p, shader %#x.\n", iface
, pShader
);
2412 wined3d_mutex_lock();
2416 hr
= IWineD3DDevice_SetPixelShader(This
->WineD3DDevice
, NULL
);
2417 wined3d_mutex_unlock();
2421 shader
= d3d8_get_object(&This
->handle_table
, pShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
);
2424 WARN("Invalid handle (%#x) passed.\n", pShader
);
2425 wined3d_mutex_unlock();
2426 return D3DERR_INVALIDCALL
;
2429 TRACE("(%p) : Setting shader %p\n", This
, shader
);
2430 hr
= IWineD3DDevice_SetPixelShader(This
->WineD3DDevice
, shader
->wined3d_shader
);
2431 wined3d_mutex_unlock();
2436 static HRESULT WINAPI
IDirect3DDevice8Impl_GetPixelShader(IDirect3DDevice8
*iface
, DWORD
*ppShader
)
2438 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2439 struct wined3d_shader
*object
;
2441 TRACE("iface %p, shader %p.\n", iface
, ppShader
);
2443 if (NULL
== ppShader
) {
2444 TRACE("(%p) Invalid call\n", This
);
2445 return D3DERR_INVALIDCALL
;
2448 wined3d_mutex_lock();
2449 object
= IWineD3DDevice_GetPixelShader(This
->WineD3DDevice
);
2452 IDirect3DPixelShader8Impl
*d3d8_shader
;
2453 d3d8_shader
= wined3d_shader_get_parent(object
);
2454 wined3d_shader_decref(object
);
2455 *ppShader
= d3d8_shader
->handle
;
2461 wined3d_mutex_unlock();
2463 TRACE("(%p) : returning %#x\n", This
, *ppShader
);
2468 static HRESULT WINAPI
IDirect3DDevice8Impl_DeletePixelShader(IDirect3DDevice8
*iface
, DWORD pShader
)
2470 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2471 IDirect3DPixelShader8Impl
*shader
;
2472 struct wined3d_shader
*cur
;
2474 TRACE("iface %p, shader %#x.\n", iface
, pShader
);
2476 wined3d_mutex_lock();
2478 shader
= d3d8_free_handle(&This
->handle_table
, pShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
);
2481 WARN("Invalid handle (%#x) passed.\n", pShader
);
2482 wined3d_mutex_unlock();
2483 return D3DERR_INVALIDCALL
;
2486 cur
= IWineD3DDevice_GetPixelShader(This
->WineD3DDevice
);
2489 if (cur
== shader
->wined3d_shader
)
2490 IDirect3DDevice8_SetPixelShader(iface
, 0);
2491 wined3d_shader_decref(cur
);
2494 wined3d_mutex_unlock();
2496 if (IDirect3DPixelShader8_Release(&shader
->IDirect3DPixelShader8_iface
))
2498 ERR("Shader %p has references left, this shouldn't happen.\n", shader
);
2504 static HRESULT WINAPI
IDirect3DDevice8Impl_SetPixelShaderConstant(IDirect3DDevice8
*iface
,
2505 DWORD Register
, const void *pConstantData
, DWORD ConstantCount
)
2507 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2510 TRACE("iface %p, register %u, data %p, count %u.\n",
2511 iface
, Register
, pConstantData
, ConstantCount
);
2513 wined3d_mutex_lock();
2514 hr
= IWineD3DDevice_SetPixelShaderConstantF(This
->WineD3DDevice
, Register
, pConstantData
, ConstantCount
);
2515 wined3d_mutex_unlock();
2520 static HRESULT WINAPI
IDirect3DDevice8Impl_GetPixelShaderConstant(IDirect3DDevice8
*iface
,
2521 DWORD Register
, void *pConstantData
, DWORD ConstantCount
)
2523 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2526 TRACE("iface %p, register %u, data %p, count %u.\n",
2527 iface
, Register
, pConstantData
, ConstantCount
);
2529 wined3d_mutex_lock();
2530 hr
= IWineD3DDevice_GetPixelShaderConstantF(This
->WineD3DDevice
, Register
, pConstantData
, ConstantCount
);
2531 wined3d_mutex_unlock();
2536 static HRESULT WINAPI
IDirect3DDevice8Impl_GetPixelShaderFunction(IDirect3DDevice8
*iface
,
2537 DWORD pPixelShader
, void *pData
, DWORD
*pSizeOfData
)
2539 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2540 IDirect3DPixelShader8Impl
*shader
= NULL
;
2543 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2544 iface
, pPixelShader
, pData
, pSizeOfData
);
2546 wined3d_mutex_lock();
2547 shader
= d3d8_get_object(&This
->handle_table
, pPixelShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
);
2550 WARN("Invalid handle (%#x) passed.\n", pPixelShader
);
2551 wined3d_mutex_unlock();
2553 return D3DERR_INVALIDCALL
;
2556 hr
= wined3d_shader_get_byte_code(shader
->wined3d_shader
, pData
, pSizeOfData
);
2557 wined3d_mutex_unlock();
2562 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawRectPatch(IDirect3DDevice8
*iface
, UINT Handle
,
2563 const float *pNumSegs
, const D3DRECTPATCH_INFO
*pRectPatchInfo
)
2565 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2568 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2569 iface
, Handle
, pNumSegs
, pRectPatchInfo
);
2571 wined3d_mutex_lock();
2572 hr
= IWineD3DDevice_DrawRectPatch(This
->WineD3DDevice
, Handle
, pNumSegs
, (CONST WINED3DRECTPATCH_INFO
*)pRectPatchInfo
);
2573 wined3d_mutex_unlock();
2578 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawTriPatch(IDirect3DDevice8
*iface
, UINT Handle
,
2579 const float *pNumSegs
, const D3DTRIPATCH_INFO
*pTriPatchInfo
)
2581 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2584 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2585 iface
, Handle
, pNumSegs
, pTriPatchInfo
);
2587 wined3d_mutex_lock();
2588 hr
= IWineD3DDevice_DrawTriPatch(This
->WineD3DDevice
, Handle
, pNumSegs
, (CONST WINED3DTRIPATCH_INFO
*)pTriPatchInfo
);
2589 wined3d_mutex_unlock();
2594 static HRESULT WINAPI
IDirect3DDevice8Impl_DeletePatch(IDirect3DDevice8
*iface
, UINT Handle
)
2596 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2599 TRACE("iface %p, handle %#x.\n", iface
, Handle
);
2601 wined3d_mutex_lock();
2602 hr
= IWineD3DDevice_DeletePatch(This
->WineD3DDevice
, Handle
);
2603 wined3d_mutex_unlock();
2608 static HRESULT WINAPI
IDirect3DDevice8Impl_SetStreamSource(IDirect3DDevice8
*iface
,
2609 UINT StreamNumber
, IDirect3DVertexBuffer8
*pStreamData
, UINT Stride
)
2611 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2614 TRACE("iface %p, stream_idx %u, buffer %p, stride %u.\n",
2615 iface
, StreamNumber
, pStreamData
, Stride
);
2617 wined3d_mutex_lock();
2618 hr
= IWineD3DDevice_SetStreamSource(This
->WineD3DDevice
, StreamNumber
,
2619 NULL
== pStreamData
? NULL
: ((IDirect3DVertexBuffer8Impl
*)pStreamData
)->wineD3DVertexBuffer
,
2620 0/* Offset in bytes */, Stride
);
2621 wined3d_mutex_unlock();
2626 static HRESULT WINAPI
IDirect3DDevice8Impl_GetStreamSource(IDirect3DDevice8
*iface
,
2627 UINT StreamNumber
, IDirect3DVertexBuffer8
**pStream
, UINT
*pStride
)
2629 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2630 struct wined3d_buffer
*retStream
= NULL
;
2633 TRACE("iface %p, stream_idx %u, buffer %p, stride %p.\n",
2634 iface
, StreamNumber
, pStream
, pStride
);
2636 if(pStream
== NULL
){
2637 return D3DERR_INVALIDCALL
;
2640 wined3d_mutex_lock();
2641 hr
= IWineD3DDevice_GetStreamSource(This
->WineD3DDevice
, StreamNumber
,
2642 &retStream
, 0 /* Offset in bytes */, pStride
);
2643 if (SUCCEEDED(hr
) && retStream
)
2645 *pStream
= wined3d_buffer_get_parent(retStream
);
2646 IDirect3DVertexBuffer8_AddRef(*pStream
);
2647 wined3d_buffer_decref(retStream
);
2651 if (FAILED(hr
)) FIXME("Call to GetStreamSource failed, hr %#x.\n", hr
);
2654 wined3d_mutex_unlock();
2659 static const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl
=
2661 IDirect3DDevice8Impl_QueryInterface
,
2662 IDirect3DDevice8Impl_AddRef
,
2663 IDirect3DDevice8Impl_Release
,
2664 IDirect3DDevice8Impl_TestCooperativeLevel
,
2665 IDirect3DDevice8Impl_GetAvailableTextureMem
,
2666 IDirect3DDevice8Impl_ResourceManagerDiscardBytes
,
2667 IDirect3DDevice8Impl_GetDirect3D
,
2668 IDirect3DDevice8Impl_GetDeviceCaps
,
2669 IDirect3DDevice8Impl_GetDisplayMode
,
2670 IDirect3DDevice8Impl_GetCreationParameters
,
2671 IDirect3DDevice8Impl_SetCursorProperties
,
2672 IDirect3DDevice8Impl_SetCursorPosition
,
2673 IDirect3DDevice8Impl_ShowCursor
,
2674 IDirect3DDevice8Impl_CreateAdditionalSwapChain
,
2675 IDirect3DDevice8Impl_Reset
,
2676 IDirect3DDevice8Impl_Present
,
2677 IDirect3DDevice8Impl_GetBackBuffer
,
2678 IDirect3DDevice8Impl_GetRasterStatus
,
2679 IDirect3DDevice8Impl_SetGammaRamp
,
2680 IDirect3DDevice8Impl_GetGammaRamp
,
2681 IDirect3DDevice8Impl_CreateTexture
,
2682 IDirect3DDevice8Impl_CreateVolumeTexture
,
2683 IDirect3DDevice8Impl_CreateCubeTexture
,
2684 IDirect3DDevice8Impl_CreateVertexBuffer
,
2685 IDirect3DDevice8Impl_CreateIndexBuffer
,
2686 IDirect3DDevice8Impl_CreateRenderTarget
,
2687 IDirect3DDevice8Impl_CreateDepthStencilSurface
,
2688 IDirect3DDevice8Impl_CreateImageSurface
,
2689 IDirect3DDevice8Impl_CopyRects
,
2690 IDirect3DDevice8Impl_UpdateTexture
,
2691 IDirect3DDevice8Impl_GetFrontBuffer
,
2692 IDirect3DDevice8Impl_SetRenderTarget
,
2693 IDirect3DDevice8Impl_GetRenderTarget
,
2694 IDirect3DDevice8Impl_GetDepthStencilSurface
,
2695 IDirect3DDevice8Impl_BeginScene
,
2696 IDirect3DDevice8Impl_EndScene
,
2697 IDirect3DDevice8Impl_Clear
,
2698 IDirect3DDevice8Impl_SetTransform
,
2699 IDirect3DDevice8Impl_GetTransform
,
2700 IDirect3DDevice8Impl_MultiplyTransform
,
2701 IDirect3DDevice8Impl_SetViewport
,
2702 IDirect3DDevice8Impl_GetViewport
,
2703 IDirect3DDevice8Impl_SetMaterial
,
2704 IDirect3DDevice8Impl_GetMaterial
,
2705 IDirect3DDevice8Impl_SetLight
,
2706 IDirect3DDevice8Impl_GetLight
,
2707 IDirect3DDevice8Impl_LightEnable
,
2708 IDirect3DDevice8Impl_GetLightEnable
,
2709 IDirect3DDevice8Impl_SetClipPlane
,
2710 IDirect3DDevice8Impl_GetClipPlane
,
2711 IDirect3DDevice8Impl_SetRenderState
,
2712 IDirect3DDevice8Impl_GetRenderState
,
2713 IDirect3DDevice8Impl_BeginStateBlock
,
2714 IDirect3DDevice8Impl_EndStateBlock
,
2715 IDirect3DDevice8Impl_ApplyStateBlock
,
2716 IDirect3DDevice8Impl_CaptureStateBlock
,
2717 IDirect3DDevice8Impl_DeleteStateBlock
,
2718 IDirect3DDevice8Impl_CreateStateBlock
,
2719 IDirect3DDevice8Impl_SetClipStatus
,
2720 IDirect3DDevice8Impl_GetClipStatus
,
2721 IDirect3DDevice8Impl_GetTexture
,
2722 IDirect3DDevice8Impl_SetTexture
,
2723 IDirect3DDevice8Impl_GetTextureStageState
,
2724 IDirect3DDevice8Impl_SetTextureStageState
,
2725 IDirect3DDevice8Impl_ValidateDevice
,
2726 IDirect3DDevice8Impl_GetInfo
,
2727 IDirect3DDevice8Impl_SetPaletteEntries
,
2728 IDirect3DDevice8Impl_GetPaletteEntries
,
2729 IDirect3DDevice8Impl_SetCurrentTexturePalette
,
2730 IDirect3DDevice8Impl_GetCurrentTexturePalette
,
2731 IDirect3DDevice8Impl_DrawPrimitive
,
2732 IDirect3DDevice8Impl_DrawIndexedPrimitive
,
2733 IDirect3DDevice8Impl_DrawPrimitiveUP
,
2734 IDirect3DDevice8Impl_DrawIndexedPrimitiveUP
,
2735 IDirect3DDevice8Impl_ProcessVertices
,
2736 IDirect3DDevice8Impl_CreateVertexShader
,
2737 IDirect3DDevice8Impl_SetVertexShader
,
2738 IDirect3DDevice8Impl_GetVertexShader
,
2739 IDirect3DDevice8Impl_DeleteVertexShader
,
2740 IDirect3DDevice8Impl_SetVertexShaderConstant
,
2741 IDirect3DDevice8Impl_GetVertexShaderConstant
,
2742 IDirect3DDevice8Impl_GetVertexShaderDeclaration
,
2743 IDirect3DDevice8Impl_GetVertexShaderFunction
,
2744 IDirect3DDevice8Impl_SetStreamSource
,
2745 IDirect3DDevice8Impl_GetStreamSource
,
2746 IDirect3DDevice8Impl_SetIndices
,
2747 IDirect3DDevice8Impl_GetIndices
,
2748 IDirect3DDevice8Impl_CreatePixelShader
,
2749 IDirect3DDevice8Impl_SetPixelShader
,
2750 IDirect3DDevice8Impl_GetPixelShader
,
2751 IDirect3DDevice8Impl_DeletePixelShader
,
2752 IDirect3DDevice8Impl_SetPixelShaderConstant
,
2753 IDirect3DDevice8Impl_GetPixelShaderConstant
,
2754 IDirect3DDevice8Impl_GetPixelShaderFunction
,
2755 IDirect3DDevice8Impl_DrawRectPatch
,
2756 IDirect3DDevice8Impl_DrawTriPatch
,
2757 IDirect3DDevice8Impl_DeletePatch
2760 static inline IDirect3DDevice8Impl
*impl_from_IWineD3DDeviceParent(IWineD3DDeviceParent
*iface
)
2762 return CONTAINING_RECORD(iface
, IDirect3DDevice8Impl
, IWineD3DDeviceParent_iface
);
2765 static HRESULT STDMETHODCALLTYPE
device_parent_QueryInterface(IWineD3DDeviceParent
*iface
,
2766 REFIID riid
, void **object
)
2768 IDirect3DDevice8Impl
*This
= impl_from_IWineD3DDeviceParent(iface
);
2769 return IDirect3DDevice8Impl_QueryInterface(&This
->IDirect3DDevice8_iface
, riid
, object
);
2772 static ULONG STDMETHODCALLTYPE
device_parent_AddRef(IWineD3DDeviceParent
*iface
)
2774 IDirect3DDevice8Impl
*This
= impl_from_IWineD3DDeviceParent(iface
);
2775 return IDirect3DDevice8Impl_AddRef(&This
->IDirect3DDevice8_iface
);
2778 static ULONG STDMETHODCALLTYPE
device_parent_Release(IWineD3DDeviceParent
*iface
)
2780 IDirect3DDevice8Impl
*This
= impl_from_IWineD3DDeviceParent(iface
);
2781 return IDirect3DDevice8Impl_Release(&This
->IDirect3DDevice8_iface
);
2784 /* IWineD3DDeviceParent methods */
2786 static void STDMETHODCALLTYPE
device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent
*iface
, IWineD3DDevice
*device
)
2788 TRACE("iface %p, device %p\n", iface
, device
);
2791 static HRESULT STDMETHODCALLTYPE
device_parent_CreateSurface(IWineD3DDeviceParent
*iface
,
2792 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
, DWORD usage
,
2793 WINED3DPOOL pool
, UINT level
, WINED3DCUBEMAP_FACES face
, IWineD3DSurface
**surface
)
2795 IDirect3DDevice8Impl
*This
= impl_from_IWineD3DDeviceParent(iface
);
2796 IDirect3DSurface8Impl
*d3d_surface
;
2797 BOOL lockable
= TRUE
;
2800 TRACE("iface %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
2801 "\tpool %#x, level %u, face %u, surface %p\n",
2802 iface
, container_parent
, width
, height
, format
, usage
, pool
, level
, face
, surface
);
2805 if (pool
== WINED3DPOOL_DEFAULT
&& !(usage
& WINED3DUSAGE_DYNAMIC
)) lockable
= FALSE
;
2807 hr
= IDirect3DDevice8Impl_CreateSurface(This
, width
, height
,
2808 d3dformat_from_wined3dformat(format
), lockable
, FALSE
/* Discard */, level
,
2809 (IDirect3DSurface8
**)&d3d_surface
, usage
, pool
, D3DMULTISAMPLE_NONE
, 0 /* MultisampleQuality */);
2812 ERR("(%p) CreateSurface failed, returning %#x\n", iface
, hr
);
2816 *surface
= d3d_surface
->wineD3DSurface
;
2817 IWineD3DSurface_AddRef(*surface
);
2819 d3d_surface
->container
= container_parent
;
2820 IUnknown_Release(d3d_surface
->parentDevice
);
2821 d3d_surface
->parentDevice
= NULL
;
2823 IDirect3DSurface8_Release((IDirect3DSurface8
*)d3d_surface
);
2824 d3d_surface
->forwardReference
= container_parent
;
2829 static HRESULT STDMETHODCALLTYPE
device_parent_CreateRenderTarget(IWineD3DDeviceParent
*iface
,
2830 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
,
2831 WINED3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
, BOOL lockable
,
2832 IWineD3DSurface
**surface
)
2834 IDirect3DDevice8Impl
*This
= impl_from_IWineD3DDeviceParent(iface
);
2835 IDirect3DSurface8Impl
*d3d_surface
;
2838 TRACE("iface %p, container_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2839 "\tmultisample_quality %u, lockable %u, surface %p\n",
2840 iface
, container_parent
, width
, height
, format
, multisample_type
, multisample_quality
, lockable
, surface
);
2842 hr
= IDirect3DDevice8_CreateRenderTarget(&This
->IDirect3DDevice8_iface
, width
, height
,
2843 d3dformat_from_wined3dformat(format
), multisample_type
, lockable
, (IDirect3DSurface8
**)&d3d_surface
);
2846 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface
, hr
);
2850 *surface
= d3d_surface
->wineD3DSurface
;
2851 IWineD3DSurface_AddRef(*surface
);
2853 d3d_surface
->container
= (IUnknown
*)&This
->IDirect3DDevice8_iface
;
2854 /* Implicit surfaces are created with an refcount of 0 */
2855 IUnknown_Release((IUnknown
*)d3d_surface
);
2860 static HRESULT STDMETHODCALLTYPE
device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent
*iface
,
2861 UINT width
, UINT height
, enum wined3d_format_id format
, WINED3DMULTISAMPLE_TYPE multisample_type
,
2862 DWORD multisample_quality
, BOOL discard
, IWineD3DSurface
**surface
)
2864 IDirect3DDevice8Impl
*This
= impl_from_IWineD3DDeviceParent(iface
);
2865 IDirect3DSurface8Impl
*d3d_surface
;
2868 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2869 "\tmultisample_quality %u, discard %u, surface %p\n",
2870 iface
, width
, height
, format
, multisample_type
, multisample_quality
, discard
, surface
);
2872 hr
= IDirect3DDevice8_CreateDepthStencilSurface(&This
->IDirect3DDevice8_iface
, width
, height
,
2873 d3dformat_from_wined3dformat(format
), multisample_type
, (IDirect3DSurface8
**)&d3d_surface
);
2876 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface
, hr
);
2880 *surface
= d3d_surface
->wineD3DSurface
;
2881 IWineD3DSurface_AddRef(*surface
);
2883 d3d_surface
->container
= (IUnknown
*)&This
->IDirect3DDevice8_iface
;
2884 /* Implicit surfaces are created with an refcount of 0 */
2885 IUnknown_Release((IUnknown
*)d3d_surface
);
2890 static HRESULT STDMETHODCALLTYPE
device_parent_CreateVolume(IWineD3DDeviceParent
*iface
,
2891 void *container_parent
, UINT width
, UINT height
, UINT depth
, enum wined3d_format_id format
,
2892 WINED3DPOOL pool
, DWORD usage
, struct wined3d_volume
**volume
)
2894 IDirect3DDevice8Impl
*This
= impl_from_IWineD3DDeviceParent(iface
);
2895 IDirect3DVolume8Impl
*object
;
2898 TRACE("iface %p, container_parent %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
2899 iface
, container_parent
, width
, height
, depth
, format
, pool
, usage
, volume
);
2901 /* Allocate the storage for the device */
2902 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2905 FIXME("Allocation of memory failed\n");
2907 return D3DERR_OUTOFVIDEOMEMORY
;
2910 hr
= volume_init(object
, This
, width
, height
, depth
, usage
, format
, pool
);
2913 WARN("Failed to initialize volume, hr %#x.\n", hr
);
2914 HeapFree(GetProcessHeap(), 0, object
);
2918 *volume
= object
->wined3d_volume
;
2919 wined3d_volume_incref(*volume
);
2920 IDirect3DVolume8_Release(&object
->IDirect3DVolume8_iface
);
2922 object
->container
= container_parent
;
2923 object
->forwardReference
= container_parent
;
2925 TRACE("(%p) Created volume %p\n", iface
, object
);
2930 static HRESULT STDMETHODCALLTYPE
device_parent_CreateSwapChain(IWineD3DDeviceParent
*iface
,
2931 WINED3DPRESENT_PARAMETERS
*present_parameters
, struct wined3d_swapchain
**swapchain
)
2933 IDirect3DDevice8Impl
*This
= impl_from_IWineD3DDeviceParent(iface
);
2934 D3DPRESENT_PARAMETERS local_parameters
;
2935 IDirect3DSwapChain8
*d3d_swapchain
;
2938 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface
, present_parameters
, swapchain
);
2940 /* Copy the presentation parameters */
2941 local_parameters
.BackBufferWidth
= present_parameters
->BackBufferWidth
;
2942 local_parameters
.BackBufferHeight
= present_parameters
->BackBufferHeight
;
2943 local_parameters
.BackBufferFormat
= d3dformat_from_wined3dformat(present_parameters
->BackBufferFormat
);
2944 local_parameters
.BackBufferCount
= present_parameters
->BackBufferCount
;
2945 local_parameters
.MultiSampleType
= present_parameters
->MultiSampleType
;
2946 local_parameters
.SwapEffect
= present_parameters
->SwapEffect
;
2947 local_parameters
.hDeviceWindow
= present_parameters
->hDeviceWindow
;
2948 local_parameters
.Windowed
= present_parameters
->Windowed
;
2949 local_parameters
.EnableAutoDepthStencil
= present_parameters
->EnableAutoDepthStencil
;
2950 local_parameters
.AutoDepthStencilFormat
= d3dformat_from_wined3dformat(present_parameters
->AutoDepthStencilFormat
);
2951 local_parameters
.Flags
= present_parameters
->Flags
;
2952 local_parameters
.FullScreen_RefreshRateInHz
= present_parameters
->FullScreen_RefreshRateInHz
;
2953 local_parameters
.FullScreen_PresentationInterval
= present_parameters
->PresentationInterval
;
2955 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(&This
->IDirect3DDevice8_iface
,
2956 &local_parameters
, &d3d_swapchain
);
2959 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface
, hr
);
2964 *swapchain
= ((IDirect3DSwapChain8Impl
*)d3d_swapchain
)->wined3d_swapchain
;
2965 wined3d_swapchain_incref(*swapchain
);
2966 IDirect3DSwapChain8_Release(d3d_swapchain
);
2968 /* Copy back the presentation parameters */
2969 present_parameters
->BackBufferWidth
= local_parameters
.BackBufferWidth
;
2970 present_parameters
->BackBufferHeight
= local_parameters
.BackBufferHeight
;
2971 present_parameters
->BackBufferFormat
= wined3dformat_from_d3dformat(local_parameters
.BackBufferFormat
);
2972 present_parameters
->BackBufferCount
= local_parameters
.BackBufferCount
;
2973 present_parameters
->MultiSampleType
= local_parameters
.MultiSampleType
;
2974 present_parameters
->SwapEffect
= local_parameters
.SwapEffect
;
2975 present_parameters
->hDeviceWindow
= local_parameters
.hDeviceWindow
;
2976 present_parameters
->Windowed
= local_parameters
.Windowed
;
2977 present_parameters
->EnableAutoDepthStencil
= local_parameters
.EnableAutoDepthStencil
;
2978 present_parameters
->AutoDepthStencilFormat
= wined3dformat_from_d3dformat(local_parameters
.AutoDepthStencilFormat
);
2979 present_parameters
->Flags
= local_parameters
.Flags
;
2980 present_parameters
->FullScreen_RefreshRateInHz
= local_parameters
.FullScreen_RefreshRateInHz
;
2981 present_parameters
->PresentationInterval
= local_parameters
.FullScreen_PresentationInterval
;
2986 static const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl
=
2988 /* IUnknown methods */
2989 device_parent_QueryInterface
,
2990 device_parent_AddRef
,
2991 device_parent_Release
,
2992 /* IWineD3DDeviceParent methods */
2993 device_parent_WineD3DDeviceCreated
,
2994 device_parent_CreateSurface
,
2995 device_parent_CreateRenderTarget
,
2996 device_parent_CreateDepthStencilSurface
,
2997 device_parent_CreateVolume
,
2998 device_parent_CreateSwapChain
,
3001 static void setup_fpu(void)
3003 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3005 __asm__
volatile ("fnstcw %0" : "=m" (cw
));
3006 cw
= (cw
& ~0xf3f) | 0x3f;
3007 __asm__
volatile ("fldcw %0" : : "m" (cw
));
3009 FIXME("FPU setup not implemented for this platform.\n");
3013 HRESULT
device_init(IDirect3DDevice8Impl
*device
, struct wined3d
*wined3d
, UINT adapter
,
3014 D3DDEVTYPE device_type
, HWND focus_window
, DWORD flags
, D3DPRESENT_PARAMETERS
*parameters
)
3016 WINED3DPRESENT_PARAMETERS wined3d_parameters
;
3019 device
->IDirect3DDevice8_iface
.lpVtbl
= &Direct3DDevice8_Vtbl
;
3020 device
->IWineD3DDeviceParent_iface
.lpVtbl
= &d3d8_wined3d_device_parent_vtbl
;
3022 device
->handle_table
.entries
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
3023 D3D8_INITIAL_HANDLE_TABLE_SIZE
* sizeof(*device
->handle_table
.entries
));
3024 if (!device
->handle_table
.entries
)
3026 ERR("Failed to allocate handle table memory.\n");
3027 return E_OUTOFMEMORY
;
3029 device
->handle_table
.table_size
= D3D8_INITIAL_HANDLE_TABLE_SIZE
;
3031 if (!(flags
& D3DCREATE_FPU_PRESERVE
)) setup_fpu();
3033 wined3d_mutex_lock();
3034 hr
= wined3d_device_create(wined3d
, adapter
, device_type
, focus_window
, flags
,
3035 &device
->IWineD3DDeviceParent_iface
, &device
->WineD3DDevice
);
3038 WARN("Failed to create wined3d device, hr %#x.\n", hr
);
3039 wined3d_mutex_unlock();
3040 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
3044 if (!parameters
->Windowed
)
3046 HWND device_window
= parameters
->hDeviceWindow
;
3048 if (!focus_window
) focus_window
= device_window
;
3049 if (FAILED(hr
= IWineD3DDevice_AcquireFocusWindow(device
->WineD3DDevice
, focus_window
)))
3051 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
3052 IWineD3DDevice_Release(device
->WineD3DDevice
);
3053 wined3d_mutex_unlock();
3054 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
3058 if (!device_window
) device_window
= focus_window
;
3059 IWineD3DDevice_SetupFullscreenWindow(device
->WineD3DDevice
, device_window
,
3060 parameters
->BackBufferWidth
,
3061 parameters
->BackBufferHeight
);
3064 if (flags
& D3DCREATE_MULTITHREADED
) IWineD3DDevice_SetMultithreaded(device
->WineD3DDevice
);
3066 wined3d_parameters
.BackBufferWidth
= parameters
->BackBufferWidth
;
3067 wined3d_parameters
.BackBufferHeight
= parameters
->BackBufferHeight
;
3068 wined3d_parameters
.BackBufferFormat
= wined3dformat_from_d3dformat(parameters
->BackBufferFormat
);
3069 wined3d_parameters
.BackBufferCount
= parameters
->BackBufferCount
;
3070 wined3d_parameters
.MultiSampleType
= parameters
->MultiSampleType
;
3071 wined3d_parameters
.MultiSampleQuality
= 0; /* d3d9 only */
3072 wined3d_parameters
.SwapEffect
= parameters
->SwapEffect
;
3073 wined3d_parameters
.hDeviceWindow
= parameters
->hDeviceWindow
;
3074 wined3d_parameters
.Windowed
= parameters
->Windowed
;
3075 wined3d_parameters
.EnableAutoDepthStencil
= parameters
->EnableAutoDepthStencil
;
3076 wined3d_parameters
.AutoDepthStencilFormat
= wined3dformat_from_d3dformat(parameters
->AutoDepthStencilFormat
);
3077 wined3d_parameters
.Flags
= parameters
->Flags
;
3078 wined3d_parameters
.FullScreen_RefreshRateInHz
= parameters
->FullScreen_RefreshRateInHz
;
3079 wined3d_parameters
.PresentationInterval
= parameters
->FullScreen_PresentationInterval
;
3080 wined3d_parameters
.AutoRestoreDisplayMode
= TRUE
;
3082 hr
= IWineD3DDevice_Init3D(device
->WineD3DDevice
, &wined3d_parameters
);
3085 WARN("Failed to initialize 3D, hr %#x.\n", hr
);
3086 IWineD3DDevice_ReleaseFocusWindow(device
->WineD3DDevice
);
3087 IWineD3DDevice_Release(device
->WineD3DDevice
);
3088 wined3d_mutex_unlock();
3089 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
3093 hr
= IWineD3DDevice_SetRenderState(device
->WineD3DDevice
, WINED3DRS_POINTSIZE_MIN
, 0);
3094 wined3d_mutex_unlock();
3097 ERR("Failed to set minimum pointsize, hr %#x.\n", hr
);
3101 parameters
->BackBufferWidth
= wined3d_parameters
.BackBufferWidth
;
3102 parameters
->BackBufferHeight
= wined3d_parameters
.BackBufferHeight
;
3103 parameters
->BackBufferFormat
= d3dformat_from_wined3dformat(wined3d_parameters
.BackBufferFormat
);
3104 parameters
->BackBufferCount
= wined3d_parameters
.BackBufferCount
;
3105 parameters
->MultiSampleType
= wined3d_parameters
.MultiSampleType
;
3106 parameters
->SwapEffect
= wined3d_parameters
.SwapEffect
;
3107 parameters
->hDeviceWindow
= wined3d_parameters
.hDeviceWindow
;
3108 parameters
->Windowed
= wined3d_parameters
.Windowed
;
3109 parameters
->EnableAutoDepthStencil
= wined3d_parameters
.EnableAutoDepthStencil
;
3110 parameters
->AutoDepthStencilFormat
= d3dformat_from_wined3dformat(wined3d_parameters
.AutoDepthStencilFormat
);
3111 parameters
->Flags
= wined3d_parameters
.Flags
;
3112 parameters
->FullScreen_RefreshRateInHz
= wined3d_parameters
.FullScreen_RefreshRateInHz
;
3113 parameters
->FullScreen_PresentationInterval
= wined3d_parameters
.PresentationInterval
;
3115 device
->declArraySize
= 16;
3116 device
->decls
= HeapAlloc(GetProcessHeap(), 0, device
->declArraySize
* sizeof(*device
->decls
));
3119 ERR("Failed to allocate FVF vertex delcaration map memory.\n");
3127 wined3d_mutex_lock();
3128 IWineD3DDevice_Uninit3D(device
->WineD3DDevice
);
3129 IWineD3DDevice_ReleaseFocusWindow(device
->WineD3DDevice
);
3130 IWineD3DDevice_Release(device
->WineD3DDevice
);
3131 wined3d_mutex_unlock();
3132 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);