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 ULONG WINAPI
D3D8CB_DestroySwapChain(IWineD3DSwapChain
*swapchain
)
259 TRACE("swapchain %p.\n", swapchain
);
261 return IWineD3DSwapChain_Release(swapchain
);
264 static inline IDirect3DDevice8Impl
*impl_from_IDirect3DDevice8(IDirect3DDevice8
*iface
)
266 return CONTAINING_RECORD(iface
, IDirect3DDevice8Impl
, IDirect3DDevice8_iface
);
269 static HRESULT WINAPI
IDirect3DDevice8Impl_QueryInterface(IDirect3DDevice8
*iface
, REFIID riid
,
272 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
274 TRACE("iface %p, riid %s, object %p.\n",
275 iface
, debugstr_guid(riid
), ppobj
);
277 if (IsEqualGUID(riid
, &IID_IUnknown
)
278 || IsEqualGUID(riid
, &IID_IDirect3DDevice8
)) {
279 IUnknown_AddRef(iface
);
284 if (IsEqualGUID(riid
, &IID_IWineD3DDeviceParent
))
286 IWineD3DDeviceParent_AddRef(&This
->IWineD3DDeviceParent_iface
);
287 *ppobj
= &This
->IWineD3DDeviceParent_iface
;
291 WARN("(%p)->(%s,%p),not found\n", This
, debugstr_guid(riid
), ppobj
);
293 return E_NOINTERFACE
;
296 static ULONG WINAPI
IDirect3DDevice8Impl_AddRef(IDirect3DDevice8
*iface
)
298 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
299 ULONG ref
= InterlockedIncrement(&This
->ref
);
301 TRACE("%p increasing refcount to %u.\n", iface
, ref
);
306 static ULONG WINAPI
IDirect3DDevice8Impl_Release(IDirect3DDevice8
*iface
)
308 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
311 if (This
->inDestruction
) return 0;
312 ref
= InterlockedDecrement(&This
->ref
);
314 TRACE("%p decreasing refcount to %u.\n", iface
, ref
);
319 TRACE("Releasing wined3d device %p\n", This
->WineD3DDevice
);
321 wined3d_mutex_lock();
323 This
->inDestruction
= TRUE
;
325 for(i
= 0; i
< This
->numConvertedDecls
; i
++) {
326 IDirect3DVertexDeclaration8_Release(This
->decls
[i
].decl
);
328 HeapFree(GetProcessHeap(), 0, This
->decls
);
330 IWineD3DDevice_Uninit3D(This
->WineD3DDevice
, D3D8CB_DestroySwapChain
);
331 IWineD3DDevice_ReleaseFocusWindow(This
->WineD3DDevice
);
332 IWineD3DDevice_Release(This
->WineD3DDevice
);
333 HeapFree(GetProcessHeap(), 0, This
->handle_table
.entries
);
334 HeapFree(GetProcessHeap(), 0, This
);
336 wined3d_mutex_unlock();
341 /* IDirect3DDevice Interface follow: */
342 static HRESULT WINAPI
IDirect3DDevice8Impl_TestCooperativeLevel(IDirect3DDevice8
*iface
)
344 TRACE("iface %p.\n", iface
);
349 static UINT WINAPI
IDirect3DDevice8Impl_GetAvailableTextureMem(IDirect3DDevice8
*iface
)
351 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
354 TRACE("iface %p.\n", iface
);
356 wined3d_mutex_lock();
357 hr
= IWineD3DDevice_GetAvailableTextureMem(This
->WineD3DDevice
);
358 wined3d_mutex_unlock();
363 static HRESULT WINAPI
IDirect3DDevice8Impl_ResourceManagerDiscardBytes(IDirect3DDevice8
*iface
,
366 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
369 TRACE("iface %p, byte_count %u.\n", iface
, Bytes
);
370 FIXME("Byte count ignored.\n");
372 wined3d_mutex_lock();
373 hr
= IWineD3DDevice_EvictManagedResources(This
->WineD3DDevice
);
374 wined3d_mutex_unlock();
379 static HRESULT WINAPI
IDirect3DDevice8Impl_GetDirect3D(IDirect3DDevice8
*iface
, IDirect3D8
**ppD3D8
)
381 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
382 struct wined3d
*wined3d
;
385 TRACE("iface %p, d3d8 %p.\n", iface
, ppD3D8
);
387 if (NULL
== ppD3D8
) {
388 return D3DERR_INVALIDCALL
;
391 wined3d_mutex_lock();
392 hr
= IWineD3DDevice_GetDirect3D(This
->WineD3DDevice
, &wined3d
);
393 if (SUCCEEDED(hr
) && wined3d
)
395 *ppD3D8
= wined3d_get_parent(wined3d
);
396 IDirect3D8_AddRef(*ppD3D8
);
397 wined3d_decref(wined3d
);
401 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
404 wined3d_mutex_unlock();
406 TRACE("(%p) returning %p\n",This
, *ppD3D8
);
411 static HRESULT WINAPI
IDirect3DDevice8Impl_GetDeviceCaps(IDirect3DDevice8
*iface
, D3DCAPS8
*pCaps
)
413 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
414 HRESULT hrc
= D3D_OK
;
415 WINED3DCAPS
*pWineCaps
;
417 TRACE("iface %p, caps %p.\n", iface
, pCaps
);
420 return D3DERR_INVALIDCALL
;
422 pWineCaps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WINED3DCAPS
));
423 if(pWineCaps
== NULL
){
424 return D3DERR_INVALIDCALL
; /* well this is what MSDN says to return */
427 wined3d_mutex_lock();
428 hrc
= IWineD3DDevice_GetDeviceCaps(This
->WineD3DDevice
, pWineCaps
);
429 wined3d_mutex_unlock();
431 fixup_caps(pWineCaps
);
432 WINECAPSTOD3D8CAPS(pCaps
, pWineCaps
)
433 HeapFree(GetProcessHeap(), 0, pWineCaps
);
435 TRACE("Returning %p %p\n", This
, pCaps
);
439 static HRESULT WINAPI
IDirect3DDevice8Impl_GetDisplayMode(IDirect3DDevice8
*iface
,
440 D3DDISPLAYMODE
*pMode
)
442 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
445 TRACE("iface %p, mode %p.\n", iface
, pMode
);
447 wined3d_mutex_lock();
448 hr
= IWineD3DDevice_GetDisplayMode(This
->WineD3DDevice
, 0, (WINED3DDISPLAYMODE
*) pMode
);
449 wined3d_mutex_unlock();
451 if (SUCCEEDED(hr
)) pMode
->Format
= d3dformat_from_wined3dformat(pMode
->Format
);
456 static HRESULT WINAPI
IDirect3DDevice8Impl_GetCreationParameters(IDirect3DDevice8
*iface
,
457 D3DDEVICE_CREATION_PARAMETERS
*pParameters
)
459 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
462 TRACE("iface %p, parameters %p.\n", iface
, pParameters
);
464 wined3d_mutex_lock();
465 hr
= IWineD3DDevice_GetCreationParameters(This
->WineD3DDevice
, (WINED3DDEVICE_CREATION_PARAMETERS
*) pParameters
);
466 wined3d_mutex_unlock();
471 static HRESULT WINAPI
IDirect3DDevice8Impl_SetCursorProperties(IDirect3DDevice8
*iface
,
472 UINT XHotSpot
, UINT YHotSpot
, IDirect3DSurface8
*pCursorBitmap
)
474 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
475 IDirect3DSurface8Impl
*pSurface
= (IDirect3DSurface8Impl
*)pCursorBitmap
;
478 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
479 iface
, XHotSpot
, YHotSpot
, pCursorBitmap
);
483 WARN("No cursor bitmap, returning D3DERR_INVALIDCALL.\n");
484 return D3DERR_INVALIDCALL
;
487 wined3d_mutex_lock();
488 hr
= IWineD3DDevice_SetCursorProperties(This
->WineD3DDevice
,XHotSpot
,YHotSpot
,pSurface
->wineD3DSurface
);
489 wined3d_mutex_unlock();
494 static void WINAPI
IDirect3DDevice8Impl_SetCursorPosition(IDirect3DDevice8
*iface
,
495 UINT XScreenSpace
, UINT YScreenSpace
, DWORD Flags
)
497 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
499 TRACE("iface %p, x %u, y %u, flags %#x.\n",
500 iface
, XScreenSpace
, YScreenSpace
, Flags
);
502 wined3d_mutex_lock();
503 IWineD3DDevice_SetCursorPosition(This
->WineD3DDevice
, XScreenSpace
, YScreenSpace
, Flags
);
504 wined3d_mutex_unlock();
507 static BOOL WINAPI
IDirect3DDevice8Impl_ShowCursor(IDirect3DDevice8
*iface
, BOOL bShow
)
509 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
512 TRACE("iface %p, show %#x.\n", iface
, bShow
);
514 wined3d_mutex_lock();
515 ret
= IWineD3DDevice_ShowCursor(This
->WineD3DDevice
, bShow
);
516 wined3d_mutex_unlock();
521 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateAdditionalSwapChain(IDirect3DDevice8
*iface
,
522 D3DPRESENT_PARAMETERS
*present_parameters
, IDirect3DSwapChain8
**swapchain
)
524 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
525 IDirect3DSwapChain8Impl
*object
;
528 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
529 iface
, present_parameters
, swapchain
);
531 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
534 ERR("Failed to allocate swapchain memory.\n");
535 return E_OUTOFMEMORY
;
538 hr
= swapchain_init(object
, This
, present_parameters
);
541 WARN("Failed to initialize swapchain, hr %#x.\n", hr
);
542 HeapFree(GetProcessHeap(), 0, object
);
546 TRACE("Created swapchain %p.\n", object
);
547 *swapchain
= &object
->IDirect3DSwapChain8_iface
;
552 static HRESULT WINAPI
IDirect3DDevice8Impl_Reset(IDirect3DDevice8
*iface
,
553 D3DPRESENT_PARAMETERS
*pPresentationParameters
)
555 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
556 WINED3DPRESENT_PARAMETERS localParameters
;
559 TRACE("iface %p, present_parameters %p.\n", iface
, pPresentationParameters
);
561 localParameters
.BackBufferWidth
= pPresentationParameters
->BackBufferWidth
;
562 localParameters
.BackBufferHeight
= pPresentationParameters
->BackBufferHeight
;
563 localParameters
.BackBufferFormat
= wined3dformat_from_d3dformat(pPresentationParameters
->BackBufferFormat
);
564 localParameters
.BackBufferCount
= pPresentationParameters
->BackBufferCount
;
565 localParameters
.MultiSampleType
= pPresentationParameters
->MultiSampleType
;
566 localParameters
.MultiSampleQuality
= 0; /* d3d9 only */
567 localParameters
.SwapEffect
= pPresentationParameters
->SwapEffect
;
568 localParameters
.hDeviceWindow
= pPresentationParameters
->hDeviceWindow
;
569 localParameters
.Windowed
= pPresentationParameters
->Windowed
;
570 localParameters
.EnableAutoDepthStencil
= pPresentationParameters
->EnableAutoDepthStencil
;
571 localParameters
.AutoDepthStencilFormat
= wined3dformat_from_d3dformat(pPresentationParameters
->AutoDepthStencilFormat
);
572 localParameters
.Flags
= pPresentationParameters
->Flags
;
573 localParameters
.FullScreen_RefreshRateInHz
= pPresentationParameters
->FullScreen_RefreshRateInHz
;
574 localParameters
.PresentationInterval
= pPresentationParameters
->FullScreen_PresentationInterval
;
575 localParameters
.AutoRestoreDisplayMode
= TRUE
;
577 wined3d_mutex_lock();
578 hr
= IWineD3DDevice_Reset(This
->WineD3DDevice
, &localParameters
);
580 hr
= IWineD3DDevice_SetRenderState(This
->WineD3DDevice
, WINED3DRS_POINTSIZE_MIN
, 0);
582 wined3d_mutex_unlock();
584 pPresentationParameters
->BackBufferWidth
= localParameters
.BackBufferWidth
;
585 pPresentationParameters
->BackBufferHeight
= localParameters
.BackBufferHeight
;
586 pPresentationParameters
->BackBufferFormat
= d3dformat_from_wined3dformat(localParameters
.BackBufferFormat
);
587 pPresentationParameters
->BackBufferCount
= localParameters
.BackBufferCount
;
588 pPresentationParameters
->MultiSampleType
= localParameters
.MultiSampleType
;
589 pPresentationParameters
->SwapEffect
= localParameters
.SwapEffect
;
590 pPresentationParameters
->hDeviceWindow
= localParameters
.hDeviceWindow
;
591 pPresentationParameters
->Windowed
= localParameters
.Windowed
;
592 pPresentationParameters
->EnableAutoDepthStencil
= localParameters
.EnableAutoDepthStencil
;
593 pPresentationParameters
->AutoDepthStencilFormat
= d3dformat_from_wined3dformat(localParameters
.AutoDepthStencilFormat
);
594 pPresentationParameters
->Flags
= localParameters
.Flags
;
595 pPresentationParameters
->FullScreen_RefreshRateInHz
= localParameters
.FullScreen_RefreshRateInHz
;
596 pPresentationParameters
->FullScreen_PresentationInterval
= localParameters
.PresentationInterval
;
601 static HRESULT WINAPI
IDirect3DDevice8Impl_Present(IDirect3DDevice8
*iface
, const RECT
*pSourceRect
,
602 const RECT
*pDestRect
, HWND hDestWindowOverride
, const RGNDATA
*pDirtyRegion
)
604 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
607 TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
608 iface
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
610 wined3d_mutex_lock();
611 hr
= IWineD3DDevice_Present(This
->WineD3DDevice
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
612 wined3d_mutex_unlock();
617 static HRESULT WINAPI
IDirect3DDevice8Impl_GetBackBuffer(IDirect3DDevice8
*iface
,
618 UINT BackBuffer
, D3DBACKBUFFER_TYPE Type
, IDirect3DSurface8
**ppBackBuffer
)
620 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
621 IWineD3DSurface
*retSurface
= NULL
;
624 TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
625 iface
, BackBuffer
, Type
, ppBackBuffer
);
627 wined3d_mutex_lock();
628 hr
= IWineD3DDevice_GetBackBuffer(This
->WineD3DDevice
, 0, BackBuffer
, (WINED3DBACKBUFFER_TYPE
)Type
, &retSurface
);
629 if (SUCCEEDED(hr
) && retSurface
&& ppBackBuffer
)
631 *ppBackBuffer
= IWineD3DSurface_GetParent(retSurface
);
632 IDirect3DSurface8_AddRef(*ppBackBuffer
);
633 IWineD3DSurface_Release(retSurface
);
635 wined3d_mutex_unlock();
640 static HRESULT WINAPI
IDirect3DDevice8Impl_GetRasterStatus(IDirect3DDevice8
*iface
,
641 D3DRASTER_STATUS
*pRasterStatus
)
643 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
646 TRACE("iface %p, raster_status %p.\n", iface
, pRasterStatus
);
648 wined3d_mutex_lock();
649 hr
= IWineD3DDevice_GetRasterStatus(This
->WineD3DDevice
, 0, (WINED3DRASTER_STATUS
*) pRasterStatus
);
650 wined3d_mutex_unlock();
655 static void WINAPI
IDirect3DDevice8Impl_SetGammaRamp(IDirect3DDevice8
*iface
, DWORD Flags
,
656 const D3DGAMMARAMP
*pRamp
)
658 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
660 TRACE("iface %p, flags %#x, ramp %p.\n", iface
, Flags
, pRamp
);
662 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
663 wined3d_mutex_lock();
664 IWineD3DDevice_SetGammaRamp(This
->WineD3DDevice
, 0, Flags
, (CONST WINED3DGAMMARAMP
*) pRamp
);
665 wined3d_mutex_unlock();
668 static void WINAPI
IDirect3DDevice8Impl_GetGammaRamp(IDirect3DDevice8
*iface
, D3DGAMMARAMP
*pRamp
)
670 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
672 TRACE("iface %p, ramp %p.\n", iface
, pRamp
);
674 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
675 wined3d_mutex_lock();
676 IWineD3DDevice_GetGammaRamp(This
->WineD3DDevice
, 0, (WINED3DGAMMARAMP
*) pRamp
);
677 wined3d_mutex_unlock();
680 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateTexture(IDirect3DDevice8
*iface
,
681 UINT width
, UINT height
, UINT levels
, DWORD usage
, D3DFORMAT format
,
682 D3DPOOL pool
, IDirect3DTexture8
**texture
)
684 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
685 IDirect3DTexture8Impl
*object
;
688 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
689 iface
, width
, height
, levels
, usage
, format
, pool
, texture
);
691 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
694 ERR("Failed to allocate texture memory.\n");
695 return D3DERR_OUTOFVIDEOMEMORY
;
698 hr
= texture_init(object
, This
, width
, height
, levels
, usage
, format
, pool
);
701 WARN("Failed to initialize texture, hr %#x.\n", hr
);
702 HeapFree(GetProcessHeap(), 0, object
);
706 TRACE("Created texture %p.\n", object
);
707 *texture
= &object
->IDirect3DTexture8_iface
;
712 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateVolumeTexture(IDirect3DDevice8
*iface
,
713 UINT width
, UINT height
, UINT depth
, UINT levels
, DWORD usage
, D3DFORMAT format
,
714 D3DPOOL pool
, IDirect3DVolumeTexture8
**texture
)
716 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
717 IDirect3DVolumeTexture8Impl
*object
;
720 TRACE("iface %p, width %u, height %u, depth %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
721 iface
, width
, height
, depth
, levels
, usage
, format
, pool
, texture
);
723 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
726 ERR("Failed to allocate volume texture memory.\n");
727 return D3DERR_OUTOFVIDEOMEMORY
;
730 hr
= volumetexture_init(object
, This
, width
, height
, depth
, levels
, usage
, format
, pool
);
733 WARN("Failed to initialize volume texture, hr %#x.\n", hr
);
734 HeapFree(GetProcessHeap(), 0, object
);
738 TRACE("Created volume texture %p.\n", object
);
739 *texture
= &object
->IDirect3DVolumeTexture8_iface
;
744 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateCubeTexture(IDirect3DDevice8
*iface
, UINT edge_length
,
745 UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DCubeTexture8
**texture
)
747 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
748 IDirect3DCubeTexture8Impl
*object
;
751 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
752 iface
, edge_length
, levels
, usage
, format
, pool
, texture
);
754 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
757 ERR("Failed to allocate cube texture memory.\n");
758 return D3DERR_OUTOFVIDEOMEMORY
;
761 hr
= cubetexture_init(object
, This
, edge_length
, levels
, usage
, format
, pool
);
764 WARN("Failed to initialize cube texture, hr %#x.\n", hr
);
765 HeapFree(GetProcessHeap(), 0, object
);
769 TRACE("Created cube texture %p.\n", object
);
770 *texture
= &object
->IDirect3DCubeTexture8_iface
;
775 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateVertexBuffer(IDirect3DDevice8
*iface
, UINT size
,
776 DWORD usage
, DWORD fvf
, D3DPOOL pool
, IDirect3DVertexBuffer8
**buffer
)
778 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
779 IDirect3DVertexBuffer8Impl
*object
;
782 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p.\n",
783 iface
, size
, usage
, fvf
, pool
, buffer
);
785 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
788 ERR("Failed to allocate buffer memory.\n");
789 return D3DERR_OUTOFVIDEOMEMORY
;
792 hr
= vertexbuffer_init(object
, This
, size
, usage
, fvf
, pool
);
795 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr
);
796 HeapFree(GetProcessHeap(), 0, object
);
800 TRACE("Created vertex buffer %p.\n", object
);
801 *buffer
= (IDirect3DVertexBuffer8
*)object
;
806 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateIndexBuffer(IDirect3DDevice8
*iface
, UINT size
,
807 DWORD usage
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DIndexBuffer8
**buffer
)
809 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
810 IDirect3DIndexBuffer8Impl
*object
;
813 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p.\n",
814 iface
, size
, usage
, format
, pool
, buffer
);
816 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
819 ERR("Failed to allocate buffer memory.\n");
820 return D3DERR_OUTOFVIDEOMEMORY
;
823 hr
= indexbuffer_init(object
, This
, size
, usage
, format
, pool
);
826 WARN("Failed to initialize index buffer, hr %#x.\n", hr
);
827 HeapFree(GetProcessHeap(), 0, object
);
831 TRACE("Created index buffer %p.\n", object
);
832 *buffer
= (IDirect3DIndexBuffer8
*)object
;
837 static HRESULT
IDirect3DDevice8Impl_CreateSurface(IDirect3DDevice8Impl
*device
, UINT Width
,
838 UINT Height
, D3DFORMAT Format
, BOOL Lockable
, BOOL Discard
, UINT Level
,
839 IDirect3DSurface8
**ppSurface
, UINT Usage
, D3DPOOL Pool
, D3DMULTISAMPLE_TYPE MultiSample
,
840 DWORD MultisampleQuality
)
842 IDirect3DSurface8Impl
*object
;
845 TRACE("device %p, width %u, height %u, format %#x, lockable %#x, discard %#x, level %u, surface %p,\n"
846 "\tusage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
847 device
, Width
, Height
, Format
, Lockable
, Discard
, Level
, ppSurface
,
848 Usage
, Pool
, MultiSample
, MultisampleQuality
);
850 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirect3DSurface8Impl
));
853 FIXME("Failed to allocate surface memory.\n");
854 return D3DERR_OUTOFVIDEOMEMORY
;
857 hr
= surface_init(object
, device
, Width
, Height
, Format
, Lockable
, Discard
, Level
, Usage
,
858 Pool
, MultiSample
, MultisampleQuality
);
861 WARN("Failed to initialize surface, hr %#x.\n", hr
);
862 HeapFree(GetProcessHeap(), 0, object
);
866 TRACE("Created surface %p.\n", object
);
867 *ppSurface
= (IDirect3DSurface8
*)object
;
872 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateRenderTarget(IDirect3DDevice8
*iface
, UINT Width
,
873 UINT Height
, D3DFORMAT Format
, D3DMULTISAMPLE_TYPE MultiSample
, BOOL Lockable
,
874 IDirect3DSurface8
**ppSurface
)
876 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
879 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, lockable %#x, surface %p.\n",
880 iface
, Width
, Height
, Format
, MultiSample
, Lockable
, ppSurface
);
882 hr
= IDirect3DDevice8Impl_CreateSurface(This
, Width
, Height
, Format
, Lockable
,
883 FALSE
/* Discard */, 0 /* Level */, ppSurface
, D3DUSAGE_RENDERTARGET
, D3DPOOL_DEFAULT
,
889 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateDepthStencilSurface(IDirect3DDevice8
*iface
,
890 UINT Width
, UINT Height
, D3DFORMAT Format
, D3DMULTISAMPLE_TYPE MultiSample
,
891 IDirect3DSurface8
**ppSurface
)
893 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
896 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, surface %p.\n",
897 iface
, Width
, Height
, Format
, MultiSample
, ppSurface
);
899 /* TODO: Verify that Discard is false */
900 hr
= IDirect3DDevice8Impl_CreateSurface(This
, Width
, Height
, Format
, TRUE
/* Lockable */, FALSE
,
901 0 /* Level */, ppSurface
, D3DUSAGE_DEPTHSTENCIL
, D3DPOOL_DEFAULT
, MultiSample
, 0);
906 /* IDirect3DDevice8Impl::CreateImageSurface returns surface with pool type SYSTEMMEM */
907 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateImageSurface(IDirect3DDevice8
*iface
, UINT Width
,
908 UINT Height
, D3DFORMAT Format
, IDirect3DSurface8
**ppSurface
)
910 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
913 TRACE("iface %p, width %u, height %u, format %#x, surface %p.\n",
914 iface
, Width
, Height
, Format
, ppSurface
);
916 hr
= IDirect3DDevice8Impl_CreateSurface(This
, Width
, Height
, Format
, TRUE
/* Lockable */,
917 FALSE
/* Discard */, 0 /* Level */, ppSurface
, 0 /* Usage (undefined/none) */,
918 D3DPOOL_SYSTEMMEM
, D3DMULTISAMPLE_NONE
, 0 /* MultisampleQuality */);
923 static HRESULT WINAPI
IDirect3DDevice8Impl_CopyRects(IDirect3DDevice8
*iface
,
924 IDirect3DSurface8
*pSourceSurface
, const RECT
*pSourceRects
, UINT cRects
,
925 IDirect3DSurface8
*pDestinationSurface
, const POINT
*pDestPoints
)
927 IDirect3DSurface8Impl
*Source
= (IDirect3DSurface8Impl
*) pSourceSurface
;
928 IDirect3DSurface8Impl
*Dest
= (IDirect3DSurface8Impl
*) pDestinationSurface
;
929 enum wined3d_format_id srcFormat
, destFormat
;
930 struct wined3d_resource_desc wined3d_desc
;
931 struct wined3d_resource
*wined3d_resource
;
933 TRACE("iface %p, src_surface %p, src_rects %p, rect_count %u, dst_surface %p, dst_points %p.\n",
934 iface
, pSourceSurface
, pSourceRects
, cRects
, pDestinationSurface
, pDestPoints
);
936 /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the
937 * destination texture is in WINED3DPOOL_DEFAULT. */
939 wined3d_mutex_lock();
940 wined3d_resource
= IWineD3DSurface_GetResource(Source
->wineD3DSurface
);
941 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
942 srcFormat
= wined3d_desc
.format
;
944 wined3d_resource
= IWineD3DSurface_GetResource(Dest
->wineD3DSurface
);
945 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
946 destFormat
= wined3d_desc
.format
;
948 /* Check that the source and destination formats match */
949 if (srcFormat
!= destFormat
&& WINED3DFMT_UNKNOWN
!= destFormat
)
951 WARN("Source %p format must match the dest %p format, returning D3DERR_INVALIDCALL.\n",
952 pSourceSurface
, pDestinationSurface
);
953 wined3d_mutex_unlock();
954 return D3DERR_INVALIDCALL
;
956 else if (WINED3DFMT_UNKNOWN
== destFormat
)
958 TRACE("(%p) : Converting destination surface from WINED3DFMT_UNKNOWN to the source format\n", iface
);
959 IWineD3DSurface_SetFormat(Dest
->wineD3DSurface
, srcFormat
);
962 /* Quick if complete copy ... */
963 if (cRects
== 0 && pSourceRects
== NULL
&& pDestPoints
== NULL
) {
964 IWineD3DSurface_BltFast(Dest
->wineD3DSurface
, 0, 0, Source
->wineD3DSurface
, NULL
, WINEDDBLTFAST_NOCOLORKEY
);
967 /* Copy rect by rect */
968 if (NULL
!= pSourceRects
&& NULL
!= pDestPoints
) {
969 for (i
= 0; i
< cRects
; ++i
) {
970 IWineD3DSurface_BltFast(Dest
->wineD3DSurface
, pDestPoints
[i
].x
, pDestPoints
[i
].y
, Source
->wineD3DSurface
, &pSourceRects
[i
], WINEDDBLTFAST_NOCOLORKEY
);
973 for (i
= 0; i
< cRects
; ++i
) {
974 IWineD3DSurface_BltFast(Dest
->wineD3DSurface
, 0, 0, Source
->wineD3DSurface
, &pSourceRects
[i
], WINEDDBLTFAST_NOCOLORKEY
);
978 wined3d_mutex_unlock();
983 static HRESULT WINAPI
IDirect3DDevice8Impl_UpdateTexture(IDirect3DDevice8
*iface
,
984 IDirect3DBaseTexture8
*src_texture
, IDirect3DBaseTexture8
*dst_texture
)
986 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
989 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface
, src_texture
, dst_texture
);
991 wined3d_mutex_lock();
992 hr
= IWineD3DDevice_UpdateTexture(This
->WineD3DDevice
,
993 ((IDirect3DBaseTexture8Impl
*)src_texture
)->wined3d_texture
,
994 ((IDirect3DBaseTexture8Impl
*)dst_texture
)->wined3d_texture
);
995 wined3d_mutex_unlock();
1000 static HRESULT WINAPI
IDirect3DDevice8Impl_GetFrontBuffer(IDirect3DDevice8
*iface
,
1001 IDirect3DSurface8
*pDestSurface
)
1003 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1004 IDirect3DSurface8Impl
*destSurface
= (IDirect3DSurface8Impl
*)pDestSurface
;
1007 TRACE("iface %p, dst_surface %p.\n", iface
, pDestSurface
);
1009 if (pDestSurface
== NULL
) {
1010 WARN("(%p) : Caller passed NULL as pDestSurface returning D3DERR_INVALIDCALL\n", This
);
1011 return D3DERR_INVALIDCALL
;
1014 wined3d_mutex_lock();
1015 hr
= IWineD3DDevice_GetFrontBufferData(This
->WineD3DDevice
, 0, destSurface
->wineD3DSurface
);
1016 wined3d_mutex_unlock();
1021 static HRESULT WINAPI
IDirect3DDevice8Impl_SetRenderTarget(IDirect3DDevice8
*iface
,
1022 IDirect3DSurface8
*pRenderTarget
, IDirect3DSurface8
*pNewZStencil
)
1024 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1025 IDirect3DSurface8Impl
*pSurface
= (IDirect3DSurface8Impl
*)pRenderTarget
;
1026 IDirect3DSurface8Impl
*pZSurface
= (IDirect3DSurface8Impl
*)pNewZStencil
;
1027 IWineD3DSurface
*original_ds
= NULL
;
1030 TRACE("iface %p, render_target %p, depth_stencil %p.\n", iface
, pRenderTarget
, pNewZStencil
);
1032 wined3d_mutex_lock();
1036 struct wined3d_resource_desc ds_desc
, rt_desc
;
1037 struct wined3d_resource
*wined3d_resource
;
1039 wined3d_resource
= IWineD3DSurface_GetResource(pZSurface
->wineD3DSurface
);
1040 wined3d_resource_get_desc(wined3d_resource
, &ds_desc
);
1041 wined3d_resource
= IWineD3DSurface_GetResource(pSurface
->wineD3DSurface
);
1042 wined3d_resource_get_desc(wined3d_resource
, &rt_desc
);
1044 if (ds_desc
.width
< rt_desc
.width
|| ds_desc
.height
< rt_desc
.height
)
1046 WARN("Depth stencil is smaller than the render target, returning D3DERR_INVALIDCALL\n");
1047 wined3d_mutex_unlock();
1048 return D3DERR_INVALIDCALL
;
1052 hr
= IWineD3DDevice_GetDepthStencilSurface(This
->WineD3DDevice
, &original_ds
);
1053 if (hr
== WINED3D_OK
|| hr
== WINED3DERR_NOTFOUND
)
1055 hr
= IWineD3DDevice_SetDepthStencilSurface(This
->WineD3DDevice
, pZSurface
? pZSurface
->wineD3DSurface
: NULL
);
1056 if (SUCCEEDED(hr
) && pSurface
)
1057 hr
= IWineD3DDevice_SetRenderTarget(This
->WineD3DDevice
, 0, pSurface
->wineD3DSurface
, TRUE
);
1058 if (FAILED(hr
)) IWineD3DDevice_SetDepthStencilSurface(This
->WineD3DDevice
, original_ds
);
1060 if (original_ds
) IWineD3DSurface_Release(original_ds
);
1062 wined3d_mutex_unlock();
1067 static HRESULT WINAPI
IDirect3DDevice8Impl_GetRenderTarget(IDirect3DDevice8
*iface
,
1068 IDirect3DSurface8
**ppRenderTarget
)
1070 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1071 IWineD3DSurface
*pRenderTarget
;
1074 TRACE("iface %p, render_target %p.\n", iface
, ppRenderTarget
);
1076 if (ppRenderTarget
== NULL
) {
1077 return D3DERR_INVALIDCALL
;
1080 wined3d_mutex_lock();
1081 hr
= IWineD3DDevice_GetRenderTarget(This
->WineD3DDevice
, 0, &pRenderTarget
);
1082 if (SUCCEEDED(hr
) && pRenderTarget
)
1084 *ppRenderTarget
= IWineD3DSurface_GetParent(pRenderTarget
);
1085 IDirect3DSurface8_AddRef(*ppRenderTarget
);
1086 IWineD3DSurface_Release(pRenderTarget
);
1090 FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
1091 *ppRenderTarget
= NULL
;
1093 wined3d_mutex_unlock();
1098 static HRESULT WINAPI
IDirect3DDevice8Impl_GetDepthStencilSurface(IDirect3DDevice8
*iface
,
1099 IDirect3DSurface8
**ppZStencilSurface
)
1101 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1102 IWineD3DSurface
*pZStencilSurface
;
1105 TRACE("iface %p, depth_stencil %p.\n", iface
, ppZStencilSurface
);
1107 if(ppZStencilSurface
== NULL
){
1108 return D3DERR_INVALIDCALL
;
1111 wined3d_mutex_lock();
1112 hr
= IWineD3DDevice_GetDepthStencilSurface(This
->WineD3DDevice
, &pZStencilSurface
);
1115 *ppZStencilSurface
= IWineD3DSurface_GetParent(pZStencilSurface
);
1116 IDirect3DSurface8_AddRef(*ppZStencilSurface
);
1117 IWineD3DSurface_Release(pZStencilSurface
);
1121 if (hr
!= WINED3DERR_NOTFOUND
)
1122 FIXME("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr
);
1123 *ppZStencilSurface
= NULL
;
1125 wined3d_mutex_unlock();
1130 static HRESULT WINAPI
IDirect3DDevice8Impl_BeginScene(IDirect3DDevice8
*iface
)
1132 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1135 TRACE("iface %p.\n", iface
);
1137 wined3d_mutex_lock();
1138 hr
= IWineD3DDevice_BeginScene(This
->WineD3DDevice
);
1139 wined3d_mutex_unlock();
1144 static HRESULT WINAPI DECLSPEC_HOTPATCH
IDirect3DDevice8Impl_EndScene(IDirect3DDevice8
*iface
)
1146 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1149 TRACE("iface %p.\n", iface
);
1151 wined3d_mutex_lock();
1152 hr
= IWineD3DDevice_EndScene(This
->WineD3DDevice
);
1153 wined3d_mutex_unlock();
1158 static HRESULT WINAPI
IDirect3DDevice8Impl_Clear(IDirect3DDevice8
*iface
, DWORD Count
,
1159 const D3DRECT
*pRects
, DWORD Flags
, D3DCOLOR Color
, float Z
, DWORD Stencil
)
1161 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1164 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1165 iface
, Count
, pRects
, Flags
, Color
, Z
, Stencil
);
1167 wined3d_mutex_lock();
1168 hr
= IWineD3DDevice_Clear(This
->WineD3DDevice
, Count
, (const RECT
*)pRects
, Flags
, Color
, Z
, Stencil
);
1169 wined3d_mutex_unlock();
1174 static HRESULT WINAPI
IDirect3DDevice8Impl_SetTransform(IDirect3DDevice8
*iface
,
1175 D3DTRANSFORMSTATETYPE State
, const D3DMATRIX
*lpMatrix
)
1177 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1180 TRACE("iface %p, state %#x, matrix %p.\n", iface
, State
, lpMatrix
);
1182 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1183 wined3d_mutex_lock();
1184 hr
= IWineD3DDevice_SetTransform(This
->WineD3DDevice
, State
, (CONST WINED3DMATRIX
*) lpMatrix
);
1185 wined3d_mutex_unlock();
1190 static HRESULT WINAPI
IDirect3DDevice8Impl_GetTransform(IDirect3DDevice8
*iface
,
1191 D3DTRANSFORMSTATETYPE State
, D3DMATRIX
*pMatrix
)
1193 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1196 TRACE("iface %p, state %#x, matrix %p.\n", iface
, State
, pMatrix
);
1198 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1199 wined3d_mutex_lock();
1200 hr
= IWineD3DDevice_GetTransform(This
->WineD3DDevice
, State
, (WINED3DMATRIX
*) pMatrix
);
1201 wined3d_mutex_unlock();
1206 static HRESULT WINAPI
IDirect3DDevice8Impl_MultiplyTransform(IDirect3DDevice8
*iface
,
1207 D3DTRANSFORMSTATETYPE State
, const D3DMATRIX
*pMatrix
)
1209 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1212 TRACE("iface %p, state %#x, matrix %p.\n", iface
, State
, pMatrix
);
1214 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1215 wined3d_mutex_lock();
1216 hr
= IWineD3DDevice_MultiplyTransform(This
->WineD3DDevice
, State
, (CONST WINED3DMATRIX
*) pMatrix
);
1217 wined3d_mutex_unlock();
1222 static HRESULT WINAPI
IDirect3DDevice8Impl_SetViewport(IDirect3DDevice8
*iface
,
1223 const D3DVIEWPORT8
*pViewport
)
1225 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1228 TRACE("iface %p, viewport %p.\n", iface
, pViewport
);
1230 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1231 wined3d_mutex_lock();
1232 hr
= IWineD3DDevice_SetViewport(This
->WineD3DDevice
, (const WINED3DVIEWPORT
*)pViewport
);
1233 wined3d_mutex_unlock();
1238 static HRESULT WINAPI
IDirect3DDevice8Impl_GetViewport(IDirect3DDevice8
*iface
,
1239 D3DVIEWPORT8
*pViewport
)
1241 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1244 TRACE("iface %p, viewport %p.\n", iface
, pViewport
);
1246 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1247 wined3d_mutex_lock();
1248 hr
= IWineD3DDevice_GetViewport(This
->WineD3DDevice
, (WINED3DVIEWPORT
*)pViewport
);
1249 wined3d_mutex_unlock();
1254 static HRESULT WINAPI
IDirect3DDevice8Impl_SetMaterial(IDirect3DDevice8
*iface
,
1255 const D3DMATERIAL8
*pMaterial
)
1257 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1260 TRACE("iface %p, material %p.\n", iface
, pMaterial
);
1262 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1263 wined3d_mutex_lock();
1264 hr
= IWineD3DDevice_SetMaterial(This
->WineD3DDevice
, (const WINED3DMATERIAL
*)pMaterial
);
1265 wined3d_mutex_unlock();
1270 static HRESULT WINAPI
IDirect3DDevice8Impl_GetMaterial(IDirect3DDevice8
*iface
,
1271 D3DMATERIAL8
*pMaterial
)
1273 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1276 TRACE("iface %p, material %p.\n", iface
, pMaterial
);
1278 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1279 wined3d_mutex_lock();
1280 hr
= IWineD3DDevice_GetMaterial(This
->WineD3DDevice
, (WINED3DMATERIAL
*)pMaterial
);
1281 wined3d_mutex_unlock();
1286 static HRESULT WINAPI
IDirect3DDevice8Impl_SetLight(IDirect3DDevice8
*iface
, DWORD Index
,
1287 const D3DLIGHT8
*pLight
)
1289 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1292 TRACE("iface %p, index %u, light %p.\n", iface
, Index
, pLight
);
1294 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1295 wined3d_mutex_lock();
1296 hr
= IWineD3DDevice_SetLight(This
->WineD3DDevice
, Index
, (const WINED3DLIGHT
*)pLight
);
1297 wined3d_mutex_unlock();
1302 static HRESULT WINAPI
IDirect3DDevice8Impl_GetLight(IDirect3DDevice8
*iface
, DWORD Index
,
1305 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1308 TRACE("iface %p, index %u, light %p.\n", iface
, Index
, pLight
);
1310 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1311 wined3d_mutex_lock();
1312 hr
= IWineD3DDevice_GetLight(This
->WineD3DDevice
, Index
, (WINED3DLIGHT
*)pLight
);
1313 wined3d_mutex_unlock();
1318 static HRESULT WINAPI
IDirect3DDevice8Impl_LightEnable(IDirect3DDevice8
*iface
, DWORD Index
,
1321 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1324 TRACE("iface %p, index %u, enable %#x.\n", iface
, Index
, Enable
);
1326 wined3d_mutex_lock();
1327 hr
= IWineD3DDevice_SetLightEnable(This
->WineD3DDevice
, Index
, Enable
);
1328 wined3d_mutex_unlock();
1333 static HRESULT WINAPI
IDirect3DDevice8Impl_GetLightEnable(IDirect3DDevice8
*iface
, DWORD Index
,
1336 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1339 TRACE("iface %p, index %u, enable %p.\n", iface
, Index
, pEnable
);
1341 wined3d_mutex_lock();
1342 hr
= IWineD3DDevice_GetLightEnable(This
->WineD3DDevice
, Index
, pEnable
);
1343 wined3d_mutex_unlock();
1348 static HRESULT WINAPI
IDirect3DDevice8Impl_SetClipPlane(IDirect3DDevice8
*iface
, DWORD Index
,
1349 const float *pPlane
)
1351 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1354 TRACE("iface %p, index %u, plane %p.\n", iface
, Index
, pPlane
);
1356 wined3d_mutex_lock();
1357 hr
= IWineD3DDevice_SetClipPlane(This
->WineD3DDevice
, Index
, pPlane
);
1358 wined3d_mutex_unlock();
1363 static HRESULT WINAPI
IDirect3DDevice8Impl_GetClipPlane(IDirect3DDevice8
*iface
, DWORD Index
,
1366 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1369 TRACE("iface %p, index %u, plane %p.\n", iface
, Index
, pPlane
);
1371 wined3d_mutex_lock();
1372 hr
= IWineD3DDevice_GetClipPlane(This
->WineD3DDevice
, Index
, pPlane
);
1373 wined3d_mutex_unlock();
1378 static HRESULT WINAPI
IDirect3DDevice8Impl_SetRenderState(IDirect3DDevice8
*iface
,
1379 D3DRENDERSTATETYPE State
, DWORD Value
)
1381 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1384 TRACE("iface %p, state %#x, value %#x.\n", iface
, State
, Value
);
1386 wined3d_mutex_lock();
1387 hr
= IWineD3DDevice_SetRenderState(This
->WineD3DDevice
, State
, Value
);
1388 wined3d_mutex_unlock();
1393 static HRESULT WINAPI
IDirect3DDevice8Impl_GetRenderState(IDirect3DDevice8
*iface
,
1394 D3DRENDERSTATETYPE State
, DWORD
*pValue
)
1396 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1399 TRACE("iface %p, state %#x, value %p.\n", iface
, State
, pValue
);
1401 wined3d_mutex_lock();
1402 hr
= IWineD3DDevice_GetRenderState(This
->WineD3DDevice
, State
, pValue
);
1403 wined3d_mutex_unlock();
1408 static HRESULT WINAPI
IDirect3DDevice8Impl_BeginStateBlock(IDirect3DDevice8
*iface
)
1410 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1413 TRACE("iface %p.\n", iface
);
1415 wined3d_mutex_lock();
1416 hr
= IWineD3DDevice_BeginStateBlock(This
->WineD3DDevice
);
1417 wined3d_mutex_unlock();
1422 static HRESULT WINAPI
IDirect3DDevice8Impl_EndStateBlock(IDirect3DDevice8
*iface
, DWORD
*pToken
)
1424 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1425 struct wined3d_stateblock
*stateblock
;
1428 TRACE("iface %p, token %p.\n", iface
, pToken
);
1430 /* Tell wineD3D to endstateblock before anything else (in case we run out
1431 * of memory later and cause locking problems)
1433 wined3d_mutex_lock();
1434 hr
= IWineD3DDevice_EndStateBlock(This
->WineD3DDevice
, &stateblock
);
1436 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
1437 wined3d_mutex_unlock();
1441 *pToken
= d3d8_allocate_handle(&This
->handle_table
, stateblock
, D3D8_HANDLE_SB
);
1442 wined3d_mutex_unlock();
1444 if (*pToken
== D3D8_INVALID_HANDLE
)
1446 ERR("Failed to create a handle\n");
1447 wined3d_mutex_lock();
1448 wined3d_stateblock_decref(stateblock
);
1449 wined3d_mutex_unlock();
1454 TRACE("Returning %#x (%p).\n", *pToken
, stateblock
);
1459 static HRESULT WINAPI
IDirect3DDevice8Impl_ApplyStateBlock(IDirect3DDevice8
*iface
, DWORD Token
)
1461 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1462 struct wined3d_stateblock
*stateblock
;
1465 TRACE("iface %p, token %#x.\n", iface
, Token
);
1467 if (!Token
) return D3D_OK
;
1469 wined3d_mutex_lock();
1470 stateblock
= d3d8_get_object(&This
->handle_table
, Token
- 1, D3D8_HANDLE_SB
);
1473 WARN("Invalid handle (%#x) passed.\n", Token
);
1474 wined3d_mutex_unlock();
1475 return D3DERR_INVALIDCALL
;
1477 hr
= wined3d_stateblock_apply(stateblock
);
1478 wined3d_mutex_unlock();
1483 static HRESULT WINAPI
IDirect3DDevice8Impl_CaptureStateBlock(IDirect3DDevice8
*iface
, DWORD Token
)
1485 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1486 struct wined3d_stateblock
*stateblock
;
1489 TRACE("iface %p, token %#x.\n", iface
, Token
);
1491 wined3d_mutex_lock();
1492 stateblock
= d3d8_get_object(&This
->handle_table
, Token
- 1, D3D8_HANDLE_SB
);
1495 WARN("Invalid handle (%#x) passed.\n", Token
);
1496 wined3d_mutex_unlock();
1497 return D3DERR_INVALIDCALL
;
1499 hr
= wined3d_stateblock_capture(stateblock
);
1500 wined3d_mutex_unlock();
1505 static HRESULT WINAPI
IDirect3DDevice8Impl_DeleteStateBlock(IDirect3DDevice8
*iface
, DWORD Token
)
1507 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1508 struct wined3d_stateblock
*stateblock
;
1510 TRACE("iface %p, token %#x.\n", iface
, Token
);
1512 wined3d_mutex_lock();
1513 stateblock
= d3d8_free_handle(&This
->handle_table
, Token
- 1, D3D8_HANDLE_SB
);
1517 WARN("Invalid handle (%#x) passed.\n", Token
);
1518 wined3d_mutex_unlock();
1519 return D3DERR_INVALIDCALL
;
1522 if (wined3d_stateblock_decref(stateblock
))
1524 ERR("Stateblock %p has references left, this shouldn't happen.\n", stateblock
);
1526 wined3d_mutex_unlock();
1531 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateStateBlock(IDirect3DDevice8
*iface
,
1532 D3DSTATEBLOCKTYPE Type
, DWORD
*handle
)
1534 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1535 struct wined3d_stateblock
*stateblock
;
1538 TRACE("iface %p, type %#x, handle %p.\n", iface
, Type
, handle
);
1540 if (Type
!= D3DSBT_ALL
1541 && Type
!= D3DSBT_PIXELSTATE
1542 && Type
!= D3DSBT_VERTEXSTATE
)
1544 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1545 return D3DERR_INVALIDCALL
;
1548 wined3d_mutex_lock();
1549 hr
= IWineD3DDevice_CreateStateBlock(This
->WineD3DDevice
, (WINED3DSTATEBLOCKTYPE
)Type
, &stateblock
);
1552 wined3d_mutex_unlock();
1553 ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr
);
1557 *handle
= d3d8_allocate_handle(&This
->handle_table
, stateblock
, D3D8_HANDLE_SB
);
1558 wined3d_mutex_unlock();
1560 if (*handle
== D3D8_INVALID_HANDLE
)
1562 ERR("Failed to allocate a handle.\n");
1563 wined3d_mutex_lock();
1564 wined3d_stateblock_decref(stateblock
);
1565 wined3d_mutex_unlock();
1570 TRACE("Returning %#x (%p).\n", *handle
, stateblock
);
1575 static HRESULT WINAPI
IDirect3DDevice8Impl_SetClipStatus(IDirect3DDevice8
*iface
,
1576 const D3DCLIPSTATUS8
*pClipStatus
)
1578 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1581 TRACE("iface %p, clip_status %p.\n", iface
, pClipStatus
);
1582 /* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
1584 wined3d_mutex_lock();
1585 hr
= IWineD3DDevice_SetClipStatus(This
->WineD3DDevice
, (const WINED3DCLIPSTATUS
*)pClipStatus
);
1586 wined3d_mutex_unlock();
1591 static HRESULT WINAPI
IDirect3DDevice8Impl_GetClipStatus(IDirect3DDevice8
*iface
,
1592 D3DCLIPSTATUS8
*pClipStatus
)
1594 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1597 TRACE("iface %p, clip_status %p.\n", iface
, pClipStatus
);
1599 wined3d_mutex_lock();
1600 hr
= IWineD3DDevice_GetClipStatus(This
->WineD3DDevice
, (WINED3DCLIPSTATUS
*)pClipStatus
);
1601 wined3d_mutex_unlock();
1606 static HRESULT WINAPI
IDirect3DDevice8Impl_GetTexture(IDirect3DDevice8
*iface
,
1607 DWORD Stage
, IDirect3DBaseTexture8
**ppTexture
)
1609 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1610 struct wined3d_texture
*wined3d_texture
;
1613 TRACE("iface %p, stage %u, texture %p.\n", iface
, Stage
, ppTexture
);
1615 if(ppTexture
== NULL
){
1616 return D3DERR_INVALIDCALL
;
1619 wined3d_mutex_lock();
1620 hr
= IWineD3DDevice_GetTexture(This
->WineD3DDevice
, Stage
, &wined3d_texture
);
1623 WARN("Failed to get texture for stage %u, hr %#x.\n", Stage
, hr
);
1624 wined3d_mutex_unlock();
1629 if (wined3d_texture
)
1631 *ppTexture
= wined3d_texture_get_parent(wined3d_texture
);
1632 IDirect3DBaseTexture8_AddRef(*ppTexture
);
1633 wined3d_texture_decref(wined3d_texture
);
1639 wined3d_mutex_unlock();
1644 static HRESULT WINAPI
IDirect3DDevice8Impl_SetTexture(IDirect3DDevice8
*iface
, DWORD Stage
,
1645 IDirect3DBaseTexture8
*pTexture
)
1647 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1650 TRACE("iface %p, stage %u, texture %p.\n", iface
, Stage
, pTexture
);
1652 wined3d_mutex_lock();
1653 hr
= IWineD3DDevice_SetTexture(This
->WineD3DDevice
, Stage
,
1654 pTexture
? ((IDirect3DBaseTexture8Impl
*)pTexture
)->wined3d_texture
: NULL
);
1655 wined3d_mutex_unlock();
1660 static const struct tss_lookup
1667 {FALSE
, WINED3DTSS_FORCE_DWORD
}, /* 0, unused */
1668 {FALSE
, WINED3DTSS_COLOROP
}, /* 1, D3DTSS_COLOROP */
1669 {FALSE
, WINED3DTSS_COLORARG1
}, /* 2, D3DTSS_COLORARG1 */
1670 {FALSE
, WINED3DTSS_COLORARG2
}, /* 3, D3DTSS_COLORARG2 */
1671 {FALSE
, WINED3DTSS_ALPHAOP
}, /* 4, D3DTSS_ALPHAOP */
1672 {FALSE
, WINED3DTSS_ALPHAARG1
}, /* 5, D3DTSS_ALPHAARG1 */
1673 {FALSE
, WINED3DTSS_ALPHAARG2
}, /* 6, D3DTSS_ALPHAARG2 */
1674 {FALSE
, WINED3DTSS_BUMPENVMAT00
}, /* 7, D3DTSS_BUMPENVMAT00 */
1675 {FALSE
, WINED3DTSS_BUMPENVMAT01
}, /* 8, D3DTSS_BUMPENVMAT01 */
1676 {FALSE
, WINED3DTSS_BUMPENVMAT10
}, /* 9, D3DTSS_BUMPENVMAT10 */
1677 {FALSE
, WINED3DTSS_BUMPENVMAT11
}, /* 10, D3DTSS_BUMPENVMAT11 */
1678 {FALSE
, WINED3DTSS_TEXCOORDINDEX
}, /* 11, D3DTSS_TEXCOORDINDEX */
1679 {FALSE
, WINED3DTSS_FORCE_DWORD
}, /* 12, unused */
1680 {TRUE
, WINED3DSAMP_ADDRESSU
}, /* 13, D3DTSS_ADDRESSU */
1681 {TRUE
, WINED3DSAMP_ADDRESSV
}, /* 14, D3DTSS_ADDRESSV */
1682 {TRUE
, WINED3DSAMP_BORDERCOLOR
}, /* 15, D3DTSS_BORDERCOLOR */
1683 {TRUE
, WINED3DSAMP_MAGFILTER
}, /* 16, D3DTSS_MAGFILTER */
1684 {TRUE
, WINED3DSAMP_MINFILTER
}, /* 17, D3DTSS_MINFILTER */
1685 {TRUE
, WINED3DSAMP_MIPFILTER
}, /* 18, D3DTSS_MIPFILTER */
1686 {TRUE
, WINED3DSAMP_MIPMAPLODBIAS
}, /* 19, D3DTSS_MIPMAPLODBIAS */
1687 {TRUE
, WINED3DSAMP_MAXMIPLEVEL
}, /* 20, D3DTSS_MAXMIPLEVEL */
1688 {TRUE
, WINED3DSAMP_MAXANISOTROPY
}, /* 21, D3DTSS_MAXANISOTROPY */
1689 {FALSE
, WINED3DTSS_BUMPENVLSCALE
}, /* 22, D3DTSS_BUMPENVLSCALE */
1690 {FALSE
, WINED3DTSS_BUMPENVLOFFSET
}, /* 23, D3DTSS_BUMPENVLOFFSET */
1691 {FALSE
, WINED3DTSS_TEXTURETRANSFORMFLAGS
}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1692 {TRUE
, WINED3DSAMP_ADDRESSW
}, /* 25, D3DTSS_ADDRESSW */
1693 {FALSE
, WINED3DTSS_COLORARG0
}, /* 26, D3DTSS_COLORARG0 */
1694 {FALSE
, WINED3DTSS_ALPHAARG0
}, /* 27, D3DTSS_ALPHAARG0 */
1695 {FALSE
, WINED3DTSS_RESULTARG
}, /* 28, D3DTSS_RESULTARG */
1698 static HRESULT WINAPI
IDirect3DDevice8Impl_GetTextureStageState(IDirect3DDevice8
*iface
,
1699 DWORD Stage
, D3DTEXTURESTAGESTATETYPE Type
, DWORD
*pValue
)
1701 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1702 const struct tss_lookup
*l
;
1705 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface
, Stage
, Type
, pValue
);
1707 if (Type
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
1709 WARN("Invalid Type %#x passed.\n", Type
);
1713 l
= &tss_lookup
[Type
];
1715 wined3d_mutex_lock();
1716 if (l
->sampler_state
) hr
= IWineD3DDevice_GetSamplerState(This
->WineD3DDevice
, Stage
, l
->state
, pValue
);
1717 else hr
= IWineD3DDevice_GetTextureStageState(This
->WineD3DDevice
, Stage
, l
->state
, pValue
);
1718 wined3d_mutex_unlock();
1723 static HRESULT WINAPI
IDirect3DDevice8Impl_SetTextureStageState(IDirect3DDevice8
*iface
,
1724 DWORD Stage
, D3DTEXTURESTAGESTATETYPE Type
, DWORD Value
)
1726 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1727 const struct tss_lookup
*l
;
1730 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface
, Stage
, Type
, Value
);
1732 if (Type
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
1734 WARN("Invalid Type %#x passed.\n", Type
);
1738 l
= &tss_lookup
[Type
];
1740 wined3d_mutex_lock();
1741 if (l
->sampler_state
) hr
= IWineD3DDevice_SetSamplerState(This
->WineD3DDevice
, Stage
, l
->state
, Value
);
1742 else hr
= IWineD3DDevice_SetTextureStageState(This
->WineD3DDevice
, Stage
, l
->state
, Value
);
1743 wined3d_mutex_unlock();
1748 static HRESULT WINAPI
IDirect3DDevice8Impl_ValidateDevice(IDirect3DDevice8
*iface
,
1751 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1754 TRACE("iface %p, pass_count %p.\n", iface
, pNumPasses
);
1756 wined3d_mutex_lock();
1757 hr
= IWineD3DDevice_ValidateDevice(This
->WineD3DDevice
, pNumPasses
);
1758 wined3d_mutex_unlock();
1763 static HRESULT WINAPI
IDirect3DDevice8Impl_GetInfo(IDirect3DDevice8
*iface
,
1764 DWORD info_id
, void *info
, DWORD info_size
)
1766 FIXME("iface %p, info_id %#x, info %p, info_size %u stub!\n", iface
, info_id
, info
, info_size
);
1771 static HRESULT WINAPI
IDirect3DDevice8Impl_SetPaletteEntries(IDirect3DDevice8
*iface
,
1772 UINT PaletteNumber
, const PALETTEENTRY
*pEntries
)
1774 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1777 TRACE("iface %p, palette_idx %u, entries %p.\n", iface
, PaletteNumber
, pEntries
);
1779 wined3d_mutex_lock();
1780 hr
= IWineD3DDevice_SetPaletteEntries(This
->WineD3DDevice
, PaletteNumber
, pEntries
);
1781 wined3d_mutex_unlock();
1786 static HRESULT WINAPI
IDirect3DDevice8Impl_GetPaletteEntries(IDirect3DDevice8
*iface
,
1787 UINT PaletteNumber
, PALETTEENTRY
*pEntries
)
1789 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1792 TRACE("iface %p, palette_idx %u, entries %p.\n", iface
, PaletteNumber
, pEntries
);
1794 wined3d_mutex_lock();
1795 hr
= IWineD3DDevice_GetPaletteEntries(This
->WineD3DDevice
, PaletteNumber
, pEntries
);
1796 wined3d_mutex_unlock();
1801 static HRESULT WINAPI
IDirect3DDevice8Impl_SetCurrentTexturePalette(IDirect3DDevice8
*iface
,
1804 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1807 TRACE("iface %p, palette_idx %u.\n", iface
, PaletteNumber
);
1809 wined3d_mutex_lock();
1810 hr
= IWineD3DDevice_SetCurrentTexturePalette(This
->WineD3DDevice
, PaletteNumber
);
1811 wined3d_mutex_unlock();
1816 static HRESULT WINAPI
IDirect3DDevice8Impl_GetCurrentTexturePalette(IDirect3DDevice8
*iface
,
1817 UINT
*PaletteNumber
)
1819 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1822 TRACE("iface %p, palette_idx %p.\n", iface
, PaletteNumber
);
1824 wined3d_mutex_lock();
1825 hr
= IWineD3DDevice_GetCurrentTexturePalette(This
->WineD3DDevice
, PaletteNumber
);
1826 wined3d_mutex_unlock();
1831 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawPrimitive(IDirect3DDevice8
*iface
,
1832 D3DPRIMITIVETYPE PrimitiveType
, UINT StartVertex
, UINT PrimitiveCount
)
1834 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1837 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1838 iface
, PrimitiveType
, StartVertex
, PrimitiveCount
);
1840 wined3d_mutex_lock();
1841 IWineD3DDevice_SetPrimitiveType(This
->WineD3DDevice
, PrimitiveType
);
1842 hr
= IWineD3DDevice_DrawPrimitive(This
->WineD3DDevice
, StartVertex
,
1843 vertex_count_from_primitive_count(PrimitiveType
, PrimitiveCount
));
1844 wined3d_mutex_unlock();
1849 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawIndexedPrimitive(IDirect3DDevice8
*iface
,
1850 D3DPRIMITIVETYPE PrimitiveType
, UINT MinVertexIndex
, UINT NumVertices
, UINT startIndex
,
1853 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1856 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, start_idx %u, primitive_count %u.\n",
1857 iface
, PrimitiveType
, MinVertexIndex
, NumVertices
, startIndex
, primCount
);
1859 wined3d_mutex_lock();
1860 IWineD3DDevice_SetPrimitiveType(This
->WineD3DDevice
, PrimitiveType
);
1861 hr
= IWineD3DDevice_DrawIndexedPrimitive(This
->WineD3DDevice
, startIndex
,
1862 vertex_count_from_primitive_count(PrimitiveType
, primCount
));
1863 wined3d_mutex_unlock();
1868 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawPrimitiveUP(IDirect3DDevice8
*iface
,
1869 D3DPRIMITIVETYPE PrimitiveType
, UINT PrimitiveCount
, const void *pVertexStreamZeroData
,
1870 UINT VertexStreamZeroStride
)
1872 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1875 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
1876 iface
, PrimitiveType
, PrimitiveCount
, pVertexStreamZeroData
, VertexStreamZeroStride
);
1878 wined3d_mutex_lock();
1879 IWineD3DDevice_SetPrimitiveType(This
->WineD3DDevice
, PrimitiveType
);
1880 hr
= IWineD3DDevice_DrawPrimitiveUP(This
->WineD3DDevice
,
1881 vertex_count_from_primitive_count(PrimitiveType
, PrimitiveCount
),
1882 pVertexStreamZeroData
, VertexStreamZeroStride
);
1883 wined3d_mutex_unlock();
1888 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(IDirect3DDevice8
*iface
,
1889 D3DPRIMITIVETYPE PrimitiveType
, UINT MinVertexIndex
, UINT NumVertexIndices
,
1890 UINT PrimitiveCount
, const void *pIndexData
, D3DFORMAT IndexDataFormat
,
1891 const void *pVertexStreamZeroData
, UINT VertexStreamZeroStride
)
1893 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1896 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
1897 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
1898 iface
, PrimitiveType
, MinVertexIndex
, NumVertexIndices
, PrimitiveCount
,
1899 pIndexData
, IndexDataFormat
, pVertexStreamZeroData
, VertexStreamZeroStride
);
1901 wined3d_mutex_lock();
1902 IWineD3DDevice_SetPrimitiveType(This
->WineD3DDevice
, PrimitiveType
);
1903 hr
= IWineD3DDevice_DrawIndexedPrimitiveUP(This
->WineD3DDevice
,
1904 vertex_count_from_primitive_count(PrimitiveType
, PrimitiveCount
), pIndexData
,
1905 wined3dformat_from_d3dformat(IndexDataFormat
), pVertexStreamZeroData
, VertexStreamZeroStride
);
1906 wined3d_mutex_unlock();
1911 static HRESULT WINAPI
IDirect3DDevice8Impl_ProcessVertices(IDirect3DDevice8
*iface
,
1912 UINT SrcStartIndex
, UINT DestIndex
, UINT VertexCount
, IDirect3DVertexBuffer8
*pDestBuffer
,
1915 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1917 IDirect3DVertexBuffer8Impl
*dest
= (IDirect3DVertexBuffer8Impl
*) pDestBuffer
;
1919 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, flags %#x.\n",
1920 iface
, SrcStartIndex
, DestIndex
, VertexCount
, pDestBuffer
, Flags
);
1922 wined3d_mutex_lock();
1923 hr
= IWineD3DDevice_ProcessVertices(This
->WineD3DDevice
,SrcStartIndex
, DestIndex
, VertexCount
, dest
->wineD3DVertexBuffer
, NULL
, Flags
, dest
->fvf
);
1924 wined3d_mutex_unlock();
1929 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateVertexShader(IDirect3DDevice8
*iface
,
1930 const DWORD
*declaration
, const DWORD
*byte_code
, DWORD
*shader
, DWORD usage
)
1932 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
1933 IDirect3DVertexShader8Impl
*object
;
1934 DWORD shader_handle
;
1938 TRACE("iface %p, declaration %p, byte_code %p, shader %p, usage %#x.\n",
1939 iface
, declaration
, byte_code
, shader
, usage
);
1941 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1944 ERR("Failed to allocate vertex shader memory.\n");
1946 return E_OUTOFMEMORY
;
1949 wined3d_mutex_lock();
1950 handle
= d3d8_allocate_handle(&This
->handle_table
, object
, D3D8_HANDLE_VS
);
1951 wined3d_mutex_unlock();
1952 if (handle
== D3D8_INVALID_HANDLE
)
1954 ERR("Failed to allocate vertex shader handle.\n");
1955 HeapFree(GetProcessHeap(), 0, object
);
1957 return E_OUTOFMEMORY
;
1960 shader_handle
= handle
+ VS_HIGHESTFIXEDFXF
+ 1;
1962 hr
= vertexshader_init(object
, This
, declaration
, byte_code
, shader_handle
, usage
);
1965 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
1966 wined3d_mutex_lock();
1967 d3d8_free_handle(&This
->handle_table
, handle
, D3D8_HANDLE_VS
);
1968 wined3d_mutex_unlock();
1969 HeapFree(GetProcessHeap(), 0, object
);
1974 TRACE("Created vertex shader %p (handle %#x).\n", object
, shader_handle
);
1975 *shader
= shader_handle
;
1980 static IDirect3DVertexDeclaration8Impl
*IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl
*This
, DWORD fvf
)
1982 IDirect3DVertexDeclaration8Impl
*d3d8_declaration
;
1984 int p
, low
, high
; /* deliberately signed */
1985 struct FvfToDecl
*convertedDecls
= This
->decls
;
1987 TRACE("Searching for declaration for fvf %08x... ", fvf
);
1990 high
= This
->numConvertedDecls
- 1;
1991 while(low
<= high
) {
1992 p
= (low
+ high
) >> 1;
1994 if(convertedDecls
[p
].fvf
== fvf
) {
1995 TRACE("found %p\n", convertedDecls
[p
].decl
);
1996 return (IDirect3DVertexDeclaration8Impl
*)convertedDecls
[p
].decl
;
1997 } else if(convertedDecls
[p
].fvf
< fvf
) {
2003 TRACE("not found. Creating and inserting at position %d.\n", low
);
2005 d3d8_declaration
= HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration
));
2006 if (!d3d8_declaration
)
2008 ERR("Memory allocation failed.\n");
2012 hr
= vertexdeclaration_init_fvf(d3d8_declaration
, This
, fvf
);
2015 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr
);
2016 HeapFree(GetProcessHeap(), 0, d3d8_declaration
);
2020 if(This
->declArraySize
== This
->numConvertedDecls
) {
2021 int grow
= This
->declArraySize
/ 2;
2022 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
2023 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
2024 if(!convertedDecls
) {
2025 /* This will destroy it */
2026 IDirect3DVertexDeclaration8_Release((IDirect3DVertexDeclaration8
*)d3d8_declaration
);
2029 This
->decls
= convertedDecls
;
2030 This
->declArraySize
+= grow
;
2033 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
2034 convertedDecls
[low
].decl
= (IDirect3DVertexDeclaration8
*)d3d8_declaration
;
2035 convertedDecls
[low
].fvf
= fvf
;
2036 This
->numConvertedDecls
++;
2038 TRACE("Returning %p. %u decls in array\n", d3d8_declaration
, This
->numConvertedDecls
);
2039 return d3d8_declaration
;
2042 static HRESULT WINAPI
IDirect3DDevice8Impl_SetVertexShader(IDirect3DDevice8
*iface
, DWORD pShader
)
2044 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2045 IDirect3DVertexShader8Impl
*shader
;
2048 TRACE("iface %p, shader %#x.\n", iface
, pShader
);
2050 if (VS_HIGHESTFIXEDFXF
>= pShader
) {
2051 TRACE("Setting FVF, %#x\n", pShader
);
2053 wined3d_mutex_lock();
2054 IWineD3DDevice_SetVertexDeclaration(This
->WineD3DDevice
,
2055 IDirect3DDevice8Impl_FindDecl(This
, pShader
)->wined3d_vertex_declaration
);
2056 IWineD3DDevice_SetVertexShader(This
->WineD3DDevice
, NULL
);
2057 wined3d_mutex_unlock();
2062 TRACE("Setting shader\n");
2064 wined3d_mutex_lock();
2065 shader
= d3d8_get_object(&This
->handle_table
, pShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
);
2068 WARN("Invalid handle (%#x) passed.\n", pShader
);
2069 wined3d_mutex_unlock();
2071 return D3DERR_INVALIDCALL
;
2074 hr
= IWineD3DDevice_SetVertexDeclaration(This
->WineD3DDevice
,
2075 ((IDirect3DVertexDeclaration8Impl
*)shader
->vertex_declaration
)->wined3d_vertex_declaration
);
2077 hr
= IWineD3DDevice_SetVertexShader(This
->WineD3DDevice
, shader
->wined3d_shader
);
2078 wined3d_mutex_unlock();
2080 TRACE("Returning hr %#x\n", hr
);
2085 static HRESULT WINAPI
IDirect3DDevice8Impl_GetVertexShader(IDirect3DDevice8
*iface
, DWORD
*ppShader
)
2087 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2088 struct wined3d_vertex_declaration
*wined3d_declaration
;
2089 IDirect3DVertexDeclaration8
*d3d8_declaration
;
2092 TRACE("iface %p, shader %p.\n", iface
, ppShader
);
2094 wined3d_mutex_lock();
2095 hr
= IWineD3DDevice_GetVertexDeclaration(This
->WineD3DDevice
, &wined3d_declaration
);
2098 wined3d_mutex_unlock();
2099 WARN("(%p) : Call to IWineD3DDevice_GetVertexDeclaration failed %#x (device %p)\n",
2100 This
, hr
, This
->WineD3DDevice
);
2104 if (!wined3d_declaration
)
2106 wined3d_mutex_unlock();
2111 d3d8_declaration
= wined3d_vertex_declaration_get_parent(wined3d_declaration
);
2112 wined3d_vertex_declaration_decref(wined3d_declaration
);
2113 wined3d_mutex_unlock();
2114 *ppShader
= ((IDirect3DVertexDeclaration8Impl
*)d3d8_declaration
)->shader_handle
;
2116 TRACE("(%p) : returning %#x\n", This
, *ppShader
);
2121 static HRESULT WINAPI
IDirect3DDevice8Impl_DeleteVertexShader(IDirect3DDevice8
*iface
, DWORD pShader
)
2123 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2124 IDirect3DVertexShader8Impl
*shader
;
2125 struct wined3d_shader
*cur
;
2127 TRACE("iface %p, shader %#x.\n", iface
, pShader
);
2129 wined3d_mutex_lock();
2130 shader
= d3d8_free_handle(&This
->handle_table
, pShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
);
2133 WARN("Invalid handle (%#x) passed.\n", pShader
);
2134 wined3d_mutex_unlock();
2136 return D3DERR_INVALIDCALL
;
2139 cur
= IWineD3DDevice_GetVertexShader(This
->WineD3DDevice
);
2142 if (cur
== shader
->wined3d_shader
)
2143 IDirect3DDevice8_SetVertexShader(iface
, 0);
2144 wined3d_shader_decref(cur
);
2147 wined3d_mutex_unlock();
2149 if (IDirect3DVertexShader8_Release(&shader
->IDirect3DVertexShader8_iface
))
2151 ERR("Shader %p has references left, this shouldn't happen.\n", shader
);
2157 static HRESULT WINAPI
IDirect3DDevice8Impl_SetVertexShaderConstant(IDirect3DDevice8
*iface
,
2158 DWORD Register
, const void *pConstantData
, DWORD ConstantCount
)
2160 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2163 TRACE("iface %p, register %u, data %p, count %u.\n",
2164 iface
, Register
, pConstantData
, ConstantCount
);
2166 if(Register
+ ConstantCount
> D3D8_MAX_VERTEX_SHADER_CONSTANTF
) {
2167 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2168 Register
+ ConstantCount
, D3D8_MAX_VERTEX_SHADER_CONSTANTF
);
2169 return D3DERR_INVALIDCALL
;
2172 wined3d_mutex_lock();
2173 hr
= IWineD3DDevice_SetVertexShaderConstantF(This
->WineD3DDevice
, Register
, pConstantData
, ConstantCount
);
2174 wined3d_mutex_unlock();
2179 static HRESULT WINAPI
IDirect3DDevice8Impl_GetVertexShaderConstant(IDirect3DDevice8
*iface
,
2180 DWORD Register
, void *pConstantData
, DWORD ConstantCount
)
2182 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2185 TRACE("iface %p, register %u, data %p, count %u.\n",
2186 iface
, Register
, pConstantData
, ConstantCount
);
2188 if(Register
+ ConstantCount
> D3D8_MAX_VERTEX_SHADER_CONSTANTF
) {
2189 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2190 Register
+ ConstantCount
, D3D8_MAX_VERTEX_SHADER_CONSTANTF
);
2191 return D3DERR_INVALIDCALL
;
2194 wined3d_mutex_lock();
2195 hr
= IWineD3DDevice_GetVertexShaderConstantF(This
->WineD3DDevice
, Register
, pConstantData
, ConstantCount
);
2196 wined3d_mutex_unlock();
2201 static HRESULT WINAPI
IDirect3DDevice8Impl_GetVertexShaderDeclaration(IDirect3DDevice8
*iface
,
2202 DWORD pVertexShader
, void *pData
, DWORD
*pSizeOfData
)
2204 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2205 IDirect3DVertexDeclaration8Impl
*declaration
;
2206 IDirect3DVertexShader8Impl
*shader
;
2208 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2209 iface
, pVertexShader
, pData
, pSizeOfData
);
2211 wined3d_mutex_lock();
2212 shader
= d3d8_get_object(&This
->handle_table
, pVertexShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
);
2213 wined3d_mutex_unlock();
2217 WARN("Invalid handle (%#x) passed.\n", pVertexShader
);
2218 return D3DERR_INVALIDCALL
;
2220 declaration
= (IDirect3DVertexDeclaration8Impl
*)shader
->vertex_declaration
;
2222 /* If pData is NULL, we just return the required size of the buffer. */
2224 *pSizeOfData
= declaration
->elements_size
;
2228 /* MSDN claims that if *pSizeOfData is smaller than the required size
2229 * we should write the required size and return D3DERR_MOREDATA.
2230 * That's not actually true. */
2231 if (*pSizeOfData
< declaration
->elements_size
) {
2232 return D3DERR_INVALIDCALL
;
2235 CopyMemory(pData
, declaration
->elements
, declaration
->elements_size
);
2240 static HRESULT WINAPI
IDirect3DDevice8Impl_GetVertexShaderFunction(IDirect3DDevice8
*iface
,
2241 DWORD pVertexShader
, void *pData
, DWORD
*pSizeOfData
)
2243 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2244 IDirect3DVertexShader8Impl
*shader
= NULL
;
2247 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2248 iface
, pVertexShader
, pData
, pSizeOfData
);
2250 wined3d_mutex_lock();
2251 shader
= d3d8_get_object(&This
->handle_table
, pVertexShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
);
2254 WARN("Invalid handle (%#x) passed.\n", pVertexShader
);
2255 wined3d_mutex_unlock();
2257 return D3DERR_INVALIDCALL
;
2260 if (!shader
->wined3d_shader
)
2262 wined3d_mutex_unlock();
2267 hr
= wined3d_shader_get_byte_code(shader
->wined3d_shader
, pData
, pSizeOfData
);
2268 wined3d_mutex_unlock();
2273 static HRESULT WINAPI
IDirect3DDevice8Impl_SetIndices(IDirect3DDevice8
*iface
,
2274 IDirect3DIndexBuffer8
*pIndexData
, UINT baseVertexIndex
)
2276 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2278 IDirect3DIndexBuffer8Impl
*ib
= (IDirect3DIndexBuffer8Impl
*)pIndexData
;
2280 TRACE("iface %p, buffer %p, base_vertex_idx %u.\n", iface
, pIndexData
, baseVertexIndex
);
2282 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
2283 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
2284 * vertex buffers can't be created to address them with an index that requires the 32nd bit
2285 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
2288 wined3d_mutex_lock();
2289 IWineD3DDevice_SetBaseVertexIndex(This
->WineD3DDevice
, baseVertexIndex
);
2290 hr
= IWineD3DDevice_SetIndexBuffer(This
->WineD3DDevice
,
2291 ib
? ib
->wineD3DIndexBuffer
: NULL
,
2292 ib
? ib
->format
: WINED3DFMT_UNKNOWN
);
2293 wined3d_mutex_unlock();
2298 static HRESULT WINAPI
IDirect3DDevice8Impl_GetIndices(IDirect3DDevice8
*iface
,
2299 IDirect3DIndexBuffer8
**ppIndexData
, UINT
*pBaseVertexIndex
)
2301 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2302 struct wined3d_buffer
*retIndexData
= NULL
;
2305 TRACE("iface %p, buffer %p, base_vertex_index %p.\n", iface
, ppIndexData
, pBaseVertexIndex
);
2307 if(ppIndexData
== NULL
){
2308 return D3DERR_INVALIDCALL
;
2311 /* The case from UINT to INT is safe because d3d8 will never set negative values */
2312 wined3d_mutex_lock();
2313 IWineD3DDevice_GetBaseVertexIndex(This
->WineD3DDevice
, (INT
*) pBaseVertexIndex
);
2314 hr
= IWineD3DDevice_GetIndexBuffer(This
->WineD3DDevice
, &retIndexData
);
2315 if (SUCCEEDED(hr
) && retIndexData
)
2317 *ppIndexData
= wined3d_buffer_get_parent(retIndexData
);
2318 IDirect3DIndexBuffer8_AddRef(*ppIndexData
);
2319 wined3d_buffer_decref(retIndexData
);
2321 if (FAILED(hr
)) FIXME("Call to GetIndices failed\n");
2322 *ppIndexData
= NULL
;
2324 wined3d_mutex_unlock();
2329 static HRESULT WINAPI
IDirect3DDevice8Impl_CreatePixelShader(IDirect3DDevice8
*iface
,
2330 const DWORD
*byte_code
, DWORD
*shader
)
2332 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2333 IDirect3DPixelShader8Impl
*object
;
2334 DWORD shader_handle
;
2338 TRACE("iface %p, byte_code %p, shader %p.\n", iface
, byte_code
, shader
);
2342 TRACE("(%p) Invalid call\n", This
);
2343 return D3DERR_INVALIDCALL
;
2346 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2349 ERR("Failed to allocate pixel shader memmory.\n");
2350 return E_OUTOFMEMORY
;
2353 wined3d_mutex_lock();
2354 handle
= d3d8_allocate_handle(&This
->handle_table
, object
, D3D8_HANDLE_PS
);
2355 wined3d_mutex_unlock();
2356 if (handle
== D3D8_INVALID_HANDLE
)
2358 ERR("Failed to allocate pixel shader handle.\n");
2359 HeapFree(GetProcessHeap(), 0, object
);
2360 return E_OUTOFMEMORY
;
2363 shader_handle
= handle
+ VS_HIGHESTFIXEDFXF
+ 1;
2365 hr
= pixelshader_init(object
, This
, byte_code
, shader_handle
);
2368 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
2369 wined3d_mutex_lock();
2370 d3d8_free_handle(&This
->handle_table
, handle
, D3D8_HANDLE_PS
);
2371 wined3d_mutex_unlock();
2372 HeapFree(GetProcessHeap(), 0, object
);
2377 TRACE("Created pixel shader %p (handle %#x).\n", object
, shader_handle
);
2378 *shader
= shader_handle
;
2383 static HRESULT WINAPI
IDirect3DDevice8Impl_SetPixelShader(IDirect3DDevice8
*iface
, DWORD pShader
)
2385 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2386 IDirect3DPixelShader8Impl
*shader
;
2389 TRACE("iface %p, shader %#x.\n", iface
, pShader
);
2391 wined3d_mutex_lock();
2395 hr
= IWineD3DDevice_SetPixelShader(This
->WineD3DDevice
, NULL
);
2396 wined3d_mutex_unlock();
2400 shader
= d3d8_get_object(&This
->handle_table
, pShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
);
2403 WARN("Invalid handle (%#x) passed.\n", pShader
);
2404 wined3d_mutex_unlock();
2405 return D3DERR_INVALIDCALL
;
2408 TRACE("(%p) : Setting shader %p\n", This
, shader
);
2409 hr
= IWineD3DDevice_SetPixelShader(This
->WineD3DDevice
, shader
->wined3d_shader
);
2410 wined3d_mutex_unlock();
2415 static HRESULT WINAPI
IDirect3DDevice8Impl_GetPixelShader(IDirect3DDevice8
*iface
, DWORD
*ppShader
)
2417 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2418 struct wined3d_shader
*object
;
2420 TRACE("iface %p, shader %p.\n", iface
, ppShader
);
2422 if (NULL
== ppShader
) {
2423 TRACE("(%p) Invalid call\n", This
);
2424 return D3DERR_INVALIDCALL
;
2427 wined3d_mutex_lock();
2428 object
= IWineD3DDevice_GetPixelShader(This
->WineD3DDevice
);
2431 IDirect3DPixelShader8Impl
*d3d8_shader
;
2432 d3d8_shader
= wined3d_shader_get_parent(object
);
2433 wined3d_shader_decref(object
);
2434 *ppShader
= d3d8_shader
->handle
;
2440 wined3d_mutex_unlock();
2442 TRACE("(%p) : returning %#x\n", This
, *ppShader
);
2447 static HRESULT WINAPI
IDirect3DDevice8Impl_DeletePixelShader(IDirect3DDevice8
*iface
, DWORD pShader
)
2449 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2450 IDirect3DPixelShader8Impl
*shader
;
2451 struct wined3d_shader
*cur
;
2453 TRACE("iface %p, shader %#x.\n", iface
, pShader
);
2455 wined3d_mutex_lock();
2457 shader
= d3d8_free_handle(&This
->handle_table
, pShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
);
2460 WARN("Invalid handle (%#x) passed.\n", pShader
);
2461 wined3d_mutex_unlock();
2462 return D3DERR_INVALIDCALL
;
2465 cur
= IWineD3DDevice_GetPixelShader(This
->WineD3DDevice
);
2468 if (cur
== shader
->wined3d_shader
)
2469 IDirect3DDevice8_SetPixelShader(iface
, 0);
2470 wined3d_shader_decref(cur
);
2473 wined3d_mutex_unlock();
2475 if (IDirect3DPixelShader8_Release(&shader
->IDirect3DPixelShader8_iface
))
2477 ERR("Shader %p has references left, this shouldn't happen.\n", shader
);
2483 static HRESULT WINAPI
IDirect3DDevice8Impl_SetPixelShaderConstant(IDirect3DDevice8
*iface
,
2484 DWORD Register
, const void *pConstantData
, DWORD ConstantCount
)
2486 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2489 TRACE("iface %p, register %u, data %p, count %u.\n",
2490 iface
, Register
, pConstantData
, ConstantCount
);
2492 wined3d_mutex_lock();
2493 hr
= IWineD3DDevice_SetPixelShaderConstantF(This
->WineD3DDevice
, Register
, pConstantData
, ConstantCount
);
2494 wined3d_mutex_unlock();
2499 static HRESULT WINAPI
IDirect3DDevice8Impl_GetPixelShaderConstant(IDirect3DDevice8
*iface
,
2500 DWORD Register
, void *pConstantData
, DWORD ConstantCount
)
2502 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2505 TRACE("iface %p, register %u, data %p, count %u.\n",
2506 iface
, Register
, pConstantData
, ConstantCount
);
2508 wined3d_mutex_lock();
2509 hr
= IWineD3DDevice_GetPixelShaderConstantF(This
->WineD3DDevice
, Register
, pConstantData
, ConstantCount
);
2510 wined3d_mutex_unlock();
2515 static HRESULT WINAPI
IDirect3DDevice8Impl_GetPixelShaderFunction(IDirect3DDevice8
*iface
,
2516 DWORD pPixelShader
, void *pData
, DWORD
*pSizeOfData
)
2518 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2519 IDirect3DPixelShader8Impl
*shader
= NULL
;
2522 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2523 iface
, pPixelShader
, pData
, pSizeOfData
);
2525 wined3d_mutex_lock();
2526 shader
= d3d8_get_object(&This
->handle_table
, pPixelShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
);
2529 WARN("Invalid handle (%#x) passed.\n", pPixelShader
);
2530 wined3d_mutex_unlock();
2532 return D3DERR_INVALIDCALL
;
2535 hr
= wined3d_shader_get_byte_code(shader
->wined3d_shader
, pData
, pSizeOfData
);
2536 wined3d_mutex_unlock();
2541 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawRectPatch(IDirect3DDevice8
*iface
, UINT Handle
,
2542 const float *pNumSegs
, const D3DRECTPATCH_INFO
*pRectPatchInfo
)
2544 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2547 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2548 iface
, Handle
, pNumSegs
, pRectPatchInfo
);
2550 wined3d_mutex_lock();
2551 hr
= IWineD3DDevice_DrawRectPatch(This
->WineD3DDevice
, Handle
, pNumSegs
, (CONST WINED3DRECTPATCH_INFO
*)pRectPatchInfo
);
2552 wined3d_mutex_unlock();
2557 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawTriPatch(IDirect3DDevice8
*iface
, UINT Handle
,
2558 const float *pNumSegs
, const D3DTRIPATCH_INFO
*pTriPatchInfo
)
2560 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2563 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2564 iface
, Handle
, pNumSegs
, pTriPatchInfo
);
2566 wined3d_mutex_lock();
2567 hr
= IWineD3DDevice_DrawTriPatch(This
->WineD3DDevice
, Handle
, pNumSegs
, (CONST WINED3DTRIPATCH_INFO
*)pTriPatchInfo
);
2568 wined3d_mutex_unlock();
2573 static HRESULT WINAPI
IDirect3DDevice8Impl_DeletePatch(IDirect3DDevice8
*iface
, UINT Handle
)
2575 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2578 TRACE("iface %p, handle %#x.\n", iface
, Handle
);
2580 wined3d_mutex_lock();
2581 hr
= IWineD3DDevice_DeletePatch(This
->WineD3DDevice
, Handle
);
2582 wined3d_mutex_unlock();
2587 static HRESULT WINAPI
IDirect3DDevice8Impl_SetStreamSource(IDirect3DDevice8
*iface
,
2588 UINT StreamNumber
, IDirect3DVertexBuffer8
*pStreamData
, UINT Stride
)
2590 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2593 TRACE("iface %p, stream_idx %u, buffer %p, stride %u.\n",
2594 iface
, StreamNumber
, pStreamData
, Stride
);
2596 wined3d_mutex_lock();
2597 hr
= IWineD3DDevice_SetStreamSource(This
->WineD3DDevice
, StreamNumber
,
2598 NULL
== pStreamData
? NULL
: ((IDirect3DVertexBuffer8Impl
*)pStreamData
)->wineD3DVertexBuffer
,
2599 0/* Offset in bytes */, Stride
);
2600 wined3d_mutex_unlock();
2605 static HRESULT WINAPI
IDirect3DDevice8Impl_GetStreamSource(IDirect3DDevice8
*iface
,
2606 UINT StreamNumber
, IDirect3DVertexBuffer8
**pStream
, UINT
*pStride
)
2608 IDirect3DDevice8Impl
*This
= impl_from_IDirect3DDevice8(iface
);
2609 struct wined3d_buffer
*retStream
= NULL
;
2612 TRACE("iface %p, stream_idx %u, buffer %p, stride %p.\n",
2613 iface
, StreamNumber
, pStream
, pStride
);
2615 if(pStream
== NULL
){
2616 return D3DERR_INVALIDCALL
;
2619 wined3d_mutex_lock();
2620 hr
= IWineD3DDevice_GetStreamSource(This
->WineD3DDevice
, StreamNumber
,
2621 &retStream
, 0 /* Offset in bytes */, pStride
);
2622 if (SUCCEEDED(hr
) && retStream
)
2624 *pStream
= wined3d_buffer_get_parent(retStream
);
2625 IDirect3DVertexBuffer8_AddRef(*pStream
);
2626 wined3d_buffer_decref(retStream
);
2630 if (FAILED(hr
)) FIXME("Call to GetStreamSource failed, hr %#x.\n", hr
);
2633 wined3d_mutex_unlock();
2638 static const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl
=
2640 IDirect3DDevice8Impl_QueryInterface
,
2641 IDirect3DDevice8Impl_AddRef
,
2642 IDirect3DDevice8Impl_Release
,
2643 IDirect3DDevice8Impl_TestCooperativeLevel
,
2644 IDirect3DDevice8Impl_GetAvailableTextureMem
,
2645 IDirect3DDevice8Impl_ResourceManagerDiscardBytes
,
2646 IDirect3DDevice8Impl_GetDirect3D
,
2647 IDirect3DDevice8Impl_GetDeviceCaps
,
2648 IDirect3DDevice8Impl_GetDisplayMode
,
2649 IDirect3DDevice8Impl_GetCreationParameters
,
2650 IDirect3DDevice8Impl_SetCursorProperties
,
2651 IDirect3DDevice8Impl_SetCursorPosition
,
2652 IDirect3DDevice8Impl_ShowCursor
,
2653 IDirect3DDevice8Impl_CreateAdditionalSwapChain
,
2654 IDirect3DDevice8Impl_Reset
,
2655 IDirect3DDevice8Impl_Present
,
2656 IDirect3DDevice8Impl_GetBackBuffer
,
2657 IDirect3DDevice8Impl_GetRasterStatus
,
2658 IDirect3DDevice8Impl_SetGammaRamp
,
2659 IDirect3DDevice8Impl_GetGammaRamp
,
2660 IDirect3DDevice8Impl_CreateTexture
,
2661 IDirect3DDevice8Impl_CreateVolumeTexture
,
2662 IDirect3DDevice8Impl_CreateCubeTexture
,
2663 IDirect3DDevice8Impl_CreateVertexBuffer
,
2664 IDirect3DDevice8Impl_CreateIndexBuffer
,
2665 IDirect3DDevice8Impl_CreateRenderTarget
,
2666 IDirect3DDevice8Impl_CreateDepthStencilSurface
,
2667 IDirect3DDevice8Impl_CreateImageSurface
,
2668 IDirect3DDevice8Impl_CopyRects
,
2669 IDirect3DDevice8Impl_UpdateTexture
,
2670 IDirect3DDevice8Impl_GetFrontBuffer
,
2671 IDirect3DDevice8Impl_SetRenderTarget
,
2672 IDirect3DDevice8Impl_GetRenderTarget
,
2673 IDirect3DDevice8Impl_GetDepthStencilSurface
,
2674 IDirect3DDevice8Impl_BeginScene
,
2675 IDirect3DDevice8Impl_EndScene
,
2676 IDirect3DDevice8Impl_Clear
,
2677 IDirect3DDevice8Impl_SetTransform
,
2678 IDirect3DDevice8Impl_GetTransform
,
2679 IDirect3DDevice8Impl_MultiplyTransform
,
2680 IDirect3DDevice8Impl_SetViewport
,
2681 IDirect3DDevice8Impl_GetViewport
,
2682 IDirect3DDevice8Impl_SetMaterial
,
2683 IDirect3DDevice8Impl_GetMaterial
,
2684 IDirect3DDevice8Impl_SetLight
,
2685 IDirect3DDevice8Impl_GetLight
,
2686 IDirect3DDevice8Impl_LightEnable
,
2687 IDirect3DDevice8Impl_GetLightEnable
,
2688 IDirect3DDevice8Impl_SetClipPlane
,
2689 IDirect3DDevice8Impl_GetClipPlane
,
2690 IDirect3DDevice8Impl_SetRenderState
,
2691 IDirect3DDevice8Impl_GetRenderState
,
2692 IDirect3DDevice8Impl_BeginStateBlock
,
2693 IDirect3DDevice8Impl_EndStateBlock
,
2694 IDirect3DDevice8Impl_ApplyStateBlock
,
2695 IDirect3DDevice8Impl_CaptureStateBlock
,
2696 IDirect3DDevice8Impl_DeleteStateBlock
,
2697 IDirect3DDevice8Impl_CreateStateBlock
,
2698 IDirect3DDevice8Impl_SetClipStatus
,
2699 IDirect3DDevice8Impl_GetClipStatus
,
2700 IDirect3DDevice8Impl_GetTexture
,
2701 IDirect3DDevice8Impl_SetTexture
,
2702 IDirect3DDevice8Impl_GetTextureStageState
,
2703 IDirect3DDevice8Impl_SetTextureStageState
,
2704 IDirect3DDevice8Impl_ValidateDevice
,
2705 IDirect3DDevice8Impl_GetInfo
,
2706 IDirect3DDevice8Impl_SetPaletteEntries
,
2707 IDirect3DDevice8Impl_GetPaletteEntries
,
2708 IDirect3DDevice8Impl_SetCurrentTexturePalette
,
2709 IDirect3DDevice8Impl_GetCurrentTexturePalette
,
2710 IDirect3DDevice8Impl_DrawPrimitive
,
2711 IDirect3DDevice8Impl_DrawIndexedPrimitive
,
2712 IDirect3DDevice8Impl_DrawPrimitiveUP
,
2713 IDirect3DDevice8Impl_DrawIndexedPrimitiveUP
,
2714 IDirect3DDevice8Impl_ProcessVertices
,
2715 IDirect3DDevice8Impl_CreateVertexShader
,
2716 IDirect3DDevice8Impl_SetVertexShader
,
2717 IDirect3DDevice8Impl_GetVertexShader
,
2718 IDirect3DDevice8Impl_DeleteVertexShader
,
2719 IDirect3DDevice8Impl_SetVertexShaderConstant
,
2720 IDirect3DDevice8Impl_GetVertexShaderConstant
,
2721 IDirect3DDevice8Impl_GetVertexShaderDeclaration
,
2722 IDirect3DDevice8Impl_GetVertexShaderFunction
,
2723 IDirect3DDevice8Impl_SetStreamSource
,
2724 IDirect3DDevice8Impl_GetStreamSource
,
2725 IDirect3DDevice8Impl_SetIndices
,
2726 IDirect3DDevice8Impl_GetIndices
,
2727 IDirect3DDevice8Impl_CreatePixelShader
,
2728 IDirect3DDevice8Impl_SetPixelShader
,
2729 IDirect3DDevice8Impl_GetPixelShader
,
2730 IDirect3DDevice8Impl_DeletePixelShader
,
2731 IDirect3DDevice8Impl_SetPixelShaderConstant
,
2732 IDirect3DDevice8Impl_GetPixelShaderConstant
,
2733 IDirect3DDevice8Impl_GetPixelShaderFunction
,
2734 IDirect3DDevice8Impl_DrawRectPatch
,
2735 IDirect3DDevice8Impl_DrawTriPatch
,
2736 IDirect3DDevice8Impl_DeletePatch
2739 static inline IDirect3DDevice8Impl
*impl_from_IWineD3DDeviceParent(IWineD3DDeviceParent
*iface
)
2741 return CONTAINING_RECORD(iface
, IDirect3DDevice8Impl
, IWineD3DDeviceParent_iface
);
2744 static HRESULT STDMETHODCALLTYPE
device_parent_QueryInterface(IWineD3DDeviceParent
*iface
,
2745 REFIID riid
, void **object
)
2747 IDirect3DDevice8Impl
*This
= impl_from_IWineD3DDeviceParent(iface
);
2748 return IDirect3DDevice8Impl_QueryInterface(&This
->IDirect3DDevice8_iface
, riid
, object
);
2751 static ULONG STDMETHODCALLTYPE
device_parent_AddRef(IWineD3DDeviceParent
*iface
)
2753 IDirect3DDevice8Impl
*This
= impl_from_IWineD3DDeviceParent(iface
);
2754 return IDirect3DDevice8Impl_AddRef(&This
->IDirect3DDevice8_iface
);
2757 static ULONG STDMETHODCALLTYPE
device_parent_Release(IWineD3DDeviceParent
*iface
)
2759 IDirect3DDevice8Impl
*This
= impl_from_IWineD3DDeviceParent(iface
);
2760 return IDirect3DDevice8Impl_Release(&This
->IDirect3DDevice8_iface
);
2763 /* IWineD3DDeviceParent methods */
2765 static void STDMETHODCALLTYPE
device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent
*iface
, IWineD3DDevice
*device
)
2767 TRACE("iface %p, device %p\n", iface
, device
);
2770 static HRESULT STDMETHODCALLTYPE
device_parent_CreateSurface(IWineD3DDeviceParent
*iface
,
2771 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
, DWORD usage
,
2772 WINED3DPOOL pool
, UINT level
, WINED3DCUBEMAP_FACES face
, IWineD3DSurface
**surface
)
2774 IDirect3DDevice8Impl
*This
= impl_from_IWineD3DDeviceParent(iface
);
2775 IDirect3DSurface8Impl
*d3d_surface
;
2776 BOOL lockable
= TRUE
;
2779 TRACE("iface %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
2780 "\tpool %#x, level %u, face %u, surface %p\n",
2781 iface
, container_parent
, width
, height
, format
, usage
, pool
, level
, face
, surface
);
2784 if (pool
== WINED3DPOOL_DEFAULT
&& !(usage
& WINED3DUSAGE_DYNAMIC
)) lockable
= FALSE
;
2786 hr
= IDirect3DDevice8Impl_CreateSurface(This
, width
, height
,
2787 d3dformat_from_wined3dformat(format
), lockable
, FALSE
/* Discard */, level
,
2788 (IDirect3DSurface8
**)&d3d_surface
, usage
, pool
, D3DMULTISAMPLE_NONE
, 0 /* MultisampleQuality */);
2791 ERR("(%p) CreateSurface failed, returning %#x\n", iface
, hr
);
2795 *surface
= d3d_surface
->wineD3DSurface
;
2796 IWineD3DSurface_AddRef(*surface
);
2798 d3d_surface
->container
= container_parent
;
2799 IUnknown_Release(d3d_surface
->parentDevice
);
2800 d3d_surface
->parentDevice
= NULL
;
2802 IDirect3DSurface8_Release((IDirect3DSurface8
*)d3d_surface
);
2803 d3d_surface
->forwardReference
= container_parent
;
2808 static HRESULT STDMETHODCALLTYPE
device_parent_CreateRenderTarget(IWineD3DDeviceParent
*iface
,
2809 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
,
2810 WINED3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
, BOOL lockable
,
2811 IWineD3DSurface
**surface
)
2813 IDirect3DDevice8Impl
*This
= impl_from_IWineD3DDeviceParent(iface
);
2814 IDirect3DSurface8Impl
*d3d_surface
;
2817 TRACE("iface %p, container_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2818 "\tmultisample_quality %u, lockable %u, surface %p\n",
2819 iface
, container_parent
, width
, height
, format
, multisample_type
, multisample_quality
, lockable
, surface
);
2821 hr
= IDirect3DDevice8_CreateRenderTarget(&This
->IDirect3DDevice8_iface
, width
, height
,
2822 d3dformat_from_wined3dformat(format
), multisample_type
, lockable
, (IDirect3DSurface8
**)&d3d_surface
);
2825 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface
, hr
);
2829 *surface
= d3d_surface
->wineD3DSurface
;
2830 IWineD3DSurface_AddRef(*surface
);
2832 d3d_surface
->container
= (IUnknown
*)&This
->IDirect3DDevice8_iface
;
2833 /* Implicit surfaces are created with an refcount of 0 */
2834 IUnknown_Release((IUnknown
*)d3d_surface
);
2839 static HRESULT STDMETHODCALLTYPE
device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent
*iface
,
2840 UINT width
, UINT height
, enum wined3d_format_id format
, WINED3DMULTISAMPLE_TYPE multisample_type
,
2841 DWORD multisample_quality
, BOOL discard
, IWineD3DSurface
**surface
)
2843 IDirect3DDevice8Impl
*This
= impl_from_IWineD3DDeviceParent(iface
);
2844 IDirect3DSurface8Impl
*d3d_surface
;
2847 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2848 "\tmultisample_quality %u, discard %u, surface %p\n",
2849 iface
, width
, height
, format
, multisample_type
, multisample_quality
, discard
, surface
);
2851 hr
= IDirect3DDevice8_CreateDepthStencilSurface(&This
->IDirect3DDevice8_iface
, width
, height
,
2852 d3dformat_from_wined3dformat(format
), multisample_type
, (IDirect3DSurface8
**)&d3d_surface
);
2855 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface
, hr
);
2859 *surface
= d3d_surface
->wineD3DSurface
;
2860 IWineD3DSurface_AddRef(*surface
);
2862 d3d_surface
->container
= (IUnknown
*)&This
->IDirect3DDevice8_iface
;
2863 /* Implicit surfaces are created with an refcount of 0 */
2864 IUnknown_Release((IUnknown
*)d3d_surface
);
2869 static HRESULT STDMETHODCALLTYPE
device_parent_CreateVolume(IWineD3DDeviceParent
*iface
,
2870 void *container_parent
, UINT width
, UINT height
, UINT depth
, enum wined3d_format_id format
,
2871 WINED3DPOOL pool
, DWORD usage
, IWineD3DVolume
**volume
)
2873 IDirect3DDevice8Impl
*This
= impl_from_IWineD3DDeviceParent(iface
);
2874 IDirect3DVolume8Impl
*object
;
2877 TRACE("iface %p, container_parent %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
2878 iface
, container_parent
, width
, height
, depth
, format
, pool
, usage
, volume
);
2880 /* Allocate the storage for the device */
2881 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2884 FIXME("Allocation of memory failed\n");
2886 return D3DERR_OUTOFVIDEOMEMORY
;
2889 hr
= volume_init(object
, This
, width
, height
, depth
, usage
, format
, pool
);
2892 WARN("Failed to initialize volume, hr %#x.\n", hr
);
2893 HeapFree(GetProcessHeap(), 0, object
);
2897 *volume
= object
->wineD3DVolume
;
2898 IWineD3DVolume_AddRef(*volume
);
2899 IDirect3DVolume8_Release(&object
->IDirect3DVolume8_iface
);
2901 object
->container
= container_parent
;
2902 object
->forwardReference
= container_parent
;
2904 TRACE("(%p) Created volume %p\n", iface
, object
);
2909 static HRESULT STDMETHODCALLTYPE
device_parent_CreateSwapChain(IWineD3DDeviceParent
*iface
,
2910 WINED3DPRESENT_PARAMETERS
*present_parameters
, IWineD3DSwapChain
**swapchain
)
2912 IDirect3DDevice8Impl
*This
= impl_from_IWineD3DDeviceParent(iface
);
2913 D3DPRESENT_PARAMETERS local_parameters
;
2914 IDirect3DSwapChain8
*d3d_swapchain
;
2917 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface
, present_parameters
, swapchain
);
2919 /* Copy the presentation parameters */
2920 local_parameters
.BackBufferWidth
= present_parameters
->BackBufferWidth
;
2921 local_parameters
.BackBufferHeight
= present_parameters
->BackBufferHeight
;
2922 local_parameters
.BackBufferFormat
= d3dformat_from_wined3dformat(present_parameters
->BackBufferFormat
);
2923 local_parameters
.BackBufferCount
= present_parameters
->BackBufferCount
;
2924 local_parameters
.MultiSampleType
= present_parameters
->MultiSampleType
;
2925 local_parameters
.SwapEffect
= present_parameters
->SwapEffect
;
2926 local_parameters
.hDeviceWindow
= present_parameters
->hDeviceWindow
;
2927 local_parameters
.Windowed
= present_parameters
->Windowed
;
2928 local_parameters
.EnableAutoDepthStencil
= present_parameters
->EnableAutoDepthStencil
;
2929 local_parameters
.AutoDepthStencilFormat
= d3dformat_from_wined3dformat(present_parameters
->AutoDepthStencilFormat
);
2930 local_parameters
.Flags
= present_parameters
->Flags
;
2931 local_parameters
.FullScreen_RefreshRateInHz
= present_parameters
->FullScreen_RefreshRateInHz
;
2932 local_parameters
.FullScreen_PresentationInterval
= present_parameters
->PresentationInterval
;
2934 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(&This
->IDirect3DDevice8_iface
,
2935 &local_parameters
, &d3d_swapchain
);
2938 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface
, hr
);
2943 *swapchain
= ((IDirect3DSwapChain8Impl
*)d3d_swapchain
)->wineD3DSwapChain
;
2944 IWineD3DSwapChain_AddRef(*swapchain
);
2945 IDirect3DSwapChain8_Release(d3d_swapchain
);
2947 /* Copy back the presentation parameters */
2948 present_parameters
->BackBufferWidth
= local_parameters
.BackBufferWidth
;
2949 present_parameters
->BackBufferHeight
= local_parameters
.BackBufferHeight
;
2950 present_parameters
->BackBufferFormat
= wined3dformat_from_d3dformat(local_parameters
.BackBufferFormat
);
2951 present_parameters
->BackBufferCount
= local_parameters
.BackBufferCount
;
2952 present_parameters
->MultiSampleType
= local_parameters
.MultiSampleType
;
2953 present_parameters
->SwapEffect
= local_parameters
.SwapEffect
;
2954 present_parameters
->hDeviceWindow
= local_parameters
.hDeviceWindow
;
2955 present_parameters
->Windowed
= local_parameters
.Windowed
;
2956 present_parameters
->EnableAutoDepthStencil
= local_parameters
.EnableAutoDepthStencil
;
2957 present_parameters
->AutoDepthStencilFormat
= wined3dformat_from_d3dformat(local_parameters
.AutoDepthStencilFormat
);
2958 present_parameters
->Flags
= local_parameters
.Flags
;
2959 present_parameters
->FullScreen_RefreshRateInHz
= local_parameters
.FullScreen_RefreshRateInHz
;
2960 present_parameters
->PresentationInterval
= local_parameters
.FullScreen_PresentationInterval
;
2965 static const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl
=
2967 /* IUnknown methods */
2968 device_parent_QueryInterface
,
2969 device_parent_AddRef
,
2970 device_parent_Release
,
2971 /* IWineD3DDeviceParent methods */
2972 device_parent_WineD3DDeviceCreated
,
2973 device_parent_CreateSurface
,
2974 device_parent_CreateRenderTarget
,
2975 device_parent_CreateDepthStencilSurface
,
2976 device_parent_CreateVolume
,
2977 device_parent_CreateSwapChain
,
2980 static void setup_fpu(void)
2982 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
2984 __asm__
volatile ("fnstcw %0" : "=m" (cw
));
2985 cw
= (cw
& ~0xf3f) | 0x3f;
2986 __asm__
volatile ("fldcw %0" : : "m" (cw
));
2988 FIXME("FPU setup not implemented for this platform.\n");
2992 HRESULT
device_init(IDirect3DDevice8Impl
*device
, struct wined3d
*wined3d
, UINT adapter
,
2993 D3DDEVTYPE device_type
, HWND focus_window
, DWORD flags
, D3DPRESENT_PARAMETERS
*parameters
)
2995 WINED3DPRESENT_PARAMETERS wined3d_parameters
;
2998 device
->IDirect3DDevice8_iface
.lpVtbl
= &Direct3DDevice8_Vtbl
;
2999 device
->IWineD3DDeviceParent_iface
.lpVtbl
= &d3d8_wined3d_device_parent_vtbl
;
3001 device
->handle_table
.entries
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
3002 D3D8_INITIAL_HANDLE_TABLE_SIZE
* sizeof(*device
->handle_table
.entries
));
3003 if (!device
->handle_table
.entries
)
3005 ERR("Failed to allocate handle table memory.\n");
3006 return E_OUTOFMEMORY
;
3008 device
->handle_table
.table_size
= D3D8_INITIAL_HANDLE_TABLE_SIZE
;
3010 if (!(flags
& D3DCREATE_FPU_PRESERVE
)) setup_fpu();
3012 wined3d_mutex_lock();
3013 hr
= wined3d_device_create(wined3d
, adapter
, device_type
, focus_window
, flags
,
3014 &device
->IWineD3DDeviceParent_iface
, &device
->WineD3DDevice
);
3017 WARN("Failed to create wined3d device, hr %#x.\n", hr
);
3018 wined3d_mutex_unlock();
3019 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
3023 if (!parameters
->Windowed
)
3025 HWND device_window
= parameters
->hDeviceWindow
;
3027 if (!focus_window
) focus_window
= device_window
;
3028 if (FAILED(hr
= IWineD3DDevice_AcquireFocusWindow(device
->WineD3DDevice
, focus_window
)))
3030 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
3031 IWineD3DDevice_Release(device
->WineD3DDevice
);
3032 wined3d_mutex_unlock();
3033 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
3037 if (!device_window
) device_window
= focus_window
;
3038 IWineD3DDevice_SetupFullscreenWindow(device
->WineD3DDevice
, device_window
,
3039 parameters
->BackBufferWidth
,
3040 parameters
->BackBufferHeight
);
3043 if (flags
& D3DCREATE_MULTITHREADED
) IWineD3DDevice_SetMultithreaded(device
->WineD3DDevice
);
3045 wined3d_parameters
.BackBufferWidth
= parameters
->BackBufferWidth
;
3046 wined3d_parameters
.BackBufferHeight
= parameters
->BackBufferHeight
;
3047 wined3d_parameters
.BackBufferFormat
= wined3dformat_from_d3dformat(parameters
->BackBufferFormat
);
3048 wined3d_parameters
.BackBufferCount
= parameters
->BackBufferCount
;
3049 wined3d_parameters
.MultiSampleType
= parameters
->MultiSampleType
;
3050 wined3d_parameters
.MultiSampleQuality
= 0; /* d3d9 only */
3051 wined3d_parameters
.SwapEffect
= parameters
->SwapEffect
;
3052 wined3d_parameters
.hDeviceWindow
= parameters
->hDeviceWindow
;
3053 wined3d_parameters
.Windowed
= parameters
->Windowed
;
3054 wined3d_parameters
.EnableAutoDepthStencil
= parameters
->EnableAutoDepthStencil
;
3055 wined3d_parameters
.AutoDepthStencilFormat
= wined3dformat_from_d3dformat(parameters
->AutoDepthStencilFormat
);
3056 wined3d_parameters
.Flags
= parameters
->Flags
;
3057 wined3d_parameters
.FullScreen_RefreshRateInHz
= parameters
->FullScreen_RefreshRateInHz
;
3058 wined3d_parameters
.PresentationInterval
= parameters
->FullScreen_PresentationInterval
;
3059 wined3d_parameters
.AutoRestoreDisplayMode
= TRUE
;
3061 hr
= IWineD3DDevice_Init3D(device
->WineD3DDevice
, &wined3d_parameters
);
3064 WARN("Failed to initialize 3D, hr %#x.\n", hr
);
3065 IWineD3DDevice_ReleaseFocusWindow(device
->WineD3DDevice
);
3066 IWineD3DDevice_Release(device
->WineD3DDevice
);
3067 wined3d_mutex_unlock();
3068 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
3072 hr
= IWineD3DDevice_SetRenderState(device
->WineD3DDevice
, WINED3DRS_POINTSIZE_MIN
, 0);
3073 wined3d_mutex_unlock();
3076 ERR("Failed to set minimum pointsize, hr %#x.\n", hr
);
3080 parameters
->BackBufferWidth
= wined3d_parameters
.BackBufferWidth
;
3081 parameters
->BackBufferHeight
= wined3d_parameters
.BackBufferHeight
;
3082 parameters
->BackBufferFormat
= d3dformat_from_wined3dformat(wined3d_parameters
.BackBufferFormat
);
3083 parameters
->BackBufferCount
= wined3d_parameters
.BackBufferCount
;
3084 parameters
->MultiSampleType
= wined3d_parameters
.MultiSampleType
;
3085 parameters
->SwapEffect
= wined3d_parameters
.SwapEffect
;
3086 parameters
->hDeviceWindow
= wined3d_parameters
.hDeviceWindow
;
3087 parameters
->Windowed
= wined3d_parameters
.Windowed
;
3088 parameters
->EnableAutoDepthStencil
= wined3d_parameters
.EnableAutoDepthStencil
;
3089 parameters
->AutoDepthStencilFormat
= d3dformat_from_wined3dformat(wined3d_parameters
.AutoDepthStencilFormat
);
3090 parameters
->Flags
= wined3d_parameters
.Flags
;
3091 parameters
->FullScreen_RefreshRateInHz
= wined3d_parameters
.FullScreen_RefreshRateInHz
;
3092 parameters
->FullScreen_PresentationInterval
= wined3d_parameters
.PresentationInterval
;
3094 device
->declArraySize
= 16;
3095 device
->decls
= HeapAlloc(GetProcessHeap(), 0, device
->declArraySize
* sizeof(*device
->decls
));
3098 ERR("Failed to allocate FVF vertex delcaration map memory.\n");
3106 wined3d_mutex_lock();
3107 IWineD3DDevice_Uninit3D(device
->WineD3DDevice
, D3D8CB_DestroySwapChain
);
3108 IWineD3DDevice_ReleaseFocusWindow(device
->WineD3DDevice
);
3109 IWineD3DDevice_Release(device
->WineD3DDevice
);
3110 wined3d_mutex_unlock();
3111 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);