2 * IDirect3DDevice8 implementation
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2004 Christian Costa
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
33 #include "wine/debug.h"
35 #include "d3d8_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(d3d8
);
39 D3DFORMAT
d3dformat_from_wined3dformat(WINED3DFORMAT format
)
41 BYTE
*c
= (BYTE
*)&format
;
43 /* Don't translate FOURCC formats */
44 if (isprint(c
[0]) && isprint(c
[1]) && isprint(c
[2]) && isprint(c
[3])) return format
;
48 case WINED3DFMT_UNKNOWN
: return D3DFMT_UNKNOWN
;
49 case WINED3DFMT_B8G8R8_UNORM
: return D3DFMT_R8G8B8
;
50 case WINED3DFMT_B8G8R8A8_UNORM
: return D3DFMT_A8R8G8B8
;
51 case WINED3DFMT_B8G8R8X8_UNORM
: return D3DFMT_X8R8G8B8
;
52 case WINED3DFMT_B5G6R5_UNORM
: return D3DFMT_R5G6B5
;
53 case WINED3DFMT_B5G5R5X1_UNORM
: return D3DFMT_X1R5G5B5
;
54 case WINED3DFMT_B5G5R5A1_UNORM
: return D3DFMT_A1R5G5B5
;
55 case WINED3DFMT_B4G4R4A4_UNORM
: return D3DFMT_A4R4G4B4
;
56 case WINED3DFMT_B2G3R3_UNORM
: return D3DFMT_R3G3B2
;
57 case WINED3DFMT_A8_UNORM
: return D3DFMT_A8
;
58 case WINED3DFMT_B2G3R3A8_UNORM
: return D3DFMT_A8R3G3B2
;
59 case WINED3DFMT_B4G4R4X4_UNORM
: return D3DFMT_X4R4G4B4
;
60 case WINED3DFMT_R10G10B10A2_UNORM
: return D3DFMT_A2B10G10R10
;
61 case WINED3DFMT_R16G16_UNORM
: return D3DFMT_G16R16
;
62 case WINED3DFMT_P8_UINT_A8_UNORM
: return D3DFMT_A8P8
;
63 case WINED3DFMT_P8_UINT
: return D3DFMT_P8
;
64 case WINED3DFMT_L8_UNORM
: return D3DFMT_L8
;
65 case WINED3DFMT_L8A8_UNORM
: return D3DFMT_A8L8
;
66 case WINED3DFMT_L4A4_UNORM
: return D3DFMT_A4L4
;
67 case WINED3DFMT_R8G8_SNORM
: return D3DFMT_V8U8
;
68 case WINED3DFMT_R5G5_SNORM_L6_UNORM
: return D3DFMT_L6V5U5
;
69 case WINED3DFMT_R8G8_SNORM_L8X8_UNORM
: return D3DFMT_X8L8V8U8
;
70 case WINED3DFMT_R8G8B8A8_SNORM
: return D3DFMT_Q8W8V8U8
;
71 case WINED3DFMT_R16G16_SNORM
: return D3DFMT_V16U16
;
72 case WINED3DFMT_R10G11B11_SNORM
: return D3DFMT_W11V11U10
;
73 case WINED3DFMT_R10G10B10_SNORM_A2_UNORM
: return D3DFMT_A2W10V10U10
;
74 case WINED3DFMT_D16_LOCKABLE
: return D3DFMT_D16_LOCKABLE
;
75 case WINED3DFMT_D32_UNORM
: return D3DFMT_D32
;
76 case WINED3DFMT_S1_UINT_D15_UNORM
: return D3DFMT_D15S1
;
77 case WINED3DFMT_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 WINED3DFORMAT %#x\n", format
);
86 return D3DFMT_UNKNOWN
;
90 WINED3DFORMAT
wined3dformat_from_d3dformat(D3DFORMAT format
)
92 BYTE
*c
= (BYTE
*)&format
;
94 /* Don't translate FOURCC formats */
95 if (isprint(c
[0]) && isprint(c
[1]) && isprint(c
[2]) && isprint(c
[3])) return format
;
99 case D3DFMT_UNKNOWN
: return WINED3DFMT_UNKNOWN
;
100 case D3DFMT_R8G8B8
: return WINED3DFMT_B8G8R8_UNORM
;
101 case D3DFMT_A8R8G8B8
: return WINED3DFMT_B8G8R8A8_UNORM
;
102 case D3DFMT_X8R8G8B8
: return WINED3DFMT_B8G8R8X8_UNORM
;
103 case D3DFMT_R5G6B5
: return WINED3DFMT_B5G6R5_UNORM
;
104 case D3DFMT_X1R5G5B5
: return WINED3DFMT_B5G5R5X1_UNORM
;
105 case D3DFMT_A1R5G5B5
: return WINED3DFMT_B5G5R5A1_UNORM
;
106 case D3DFMT_A4R4G4B4
: return WINED3DFMT_B4G4R4A4_UNORM
;
107 case D3DFMT_R3G3B2
: return WINED3DFMT_B2G3R3_UNORM
;
108 case D3DFMT_A8
: return WINED3DFMT_A8_UNORM
;
109 case D3DFMT_A8R3G3B2
: return WINED3DFMT_B2G3R3A8_UNORM
;
110 case D3DFMT_X4R4G4B4
: return WINED3DFMT_B4G4R4X4_UNORM
;
111 case D3DFMT_A2B10G10R10
: return WINED3DFMT_R10G10B10A2_UNORM
;
112 case D3DFMT_G16R16
: return WINED3DFMT_R16G16_UNORM
;
113 case D3DFMT_A8P8
: return WINED3DFMT_P8_UINT_A8_UNORM
;
114 case D3DFMT_P8
: return WINED3DFMT_P8_UINT
;
115 case D3DFMT_L8
: return WINED3DFMT_L8_UNORM
;
116 case D3DFMT_A8L8
: return WINED3DFMT_L8A8_UNORM
;
117 case D3DFMT_A4L4
: return WINED3DFMT_L4A4_UNORM
;
118 case D3DFMT_V8U8
: return WINED3DFMT_R8G8_SNORM
;
119 case D3DFMT_L6V5U5
: return WINED3DFMT_R5G5_SNORM_L6_UNORM
;
120 case D3DFMT_X8L8V8U8
: return WINED3DFMT_R8G8_SNORM_L8X8_UNORM
;
121 case D3DFMT_Q8W8V8U8
: return WINED3DFMT_R8G8B8A8_SNORM
;
122 case D3DFMT_V16U16
: return WINED3DFMT_R16G16_SNORM
;
123 case D3DFMT_W11V11U10
: return WINED3DFMT_R10G11B11_SNORM
;
124 case D3DFMT_A2W10V10U10
: return WINED3DFMT_R10G10B10_SNORM_A2_UNORM
;
125 case D3DFMT_D16_LOCKABLE
: return WINED3DFMT_D16_LOCKABLE
;
126 case D3DFMT_D32
: return WINED3DFMT_D32_UNORM
;
127 case D3DFMT_D15S1
: return WINED3DFMT_S1_UINT_D15_UNORM
;
128 case D3DFMT_D24S8
: return WINED3DFMT_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 /* Use a free handle */
175 entry
= t
->free_entries
;
176 if (entry
->type
!= D3D8_HANDLE_FREE
)
178 ERR("Handle %u(%p) is in the free list, but has type %#x.\n", (entry
- t
->entries
), entry
, entry
->type
);
179 return D3D8_INVALID_HANDLE
;
181 t
->free_entries
= entry
->object
;
182 entry
->object
= object
;
185 return entry
- t
->entries
;
188 if (!(t
->entry_count
< t
->table_size
))
191 UINT new_size
= t
->table_size
+ (t
->table_size
>> 1);
192 struct d3d8_handle_entry
*new_entries
= HeapReAlloc(GetProcessHeap(),
193 0, t
->entries
, new_size
* sizeof(*t
->entries
));
196 ERR("Failed to grow the handle table.\n");
197 return D3D8_INVALID_HANDLE
;
199 t
->entries
= new_entries
;
200 t
->table_size
= new_size
;
203 entry
= &t
->entries
[t
->entry_count
];
204 entry
->object
= object
;
207 return t
->entry_count
++;
210 static void *d3d8_free_handle(struct d3d8_handle_table
*t
, DWORD handle
, enum d3d8_handle_type type
)
212 struct d3d8_handle_entry
*entry
;
215 if (handle
== D3D8_INVALID_HANDLE
|| handle
>= t
->entry_count
)
217 WARN("Invalid handle %u passed.\n", handle
);
221 entry
= &t
->entries
[handle
];
222 if (entry
->type
!= type
)
224 WARN("Handle %u(%p) is not of type %#x.\n", handle
, entry
, type
);
228 object
= entry
->object
;
229 entry
->object
= t
->free_entries
;
230 entry
->type
= D3D8_HANDLE_FREE
;
231 t
->free_entries
= entry
;
236 static void *d3d8_get_object(struct d3d8_handle_table
*t
, DWORD handle
, enum d3d8_handle_type type
)
238 struct d3d8_handle_entry
*entry
;
240 if (handle
== D3D8_INVALID_HANDLE
|| handle
>= t
->entry_count
)
242 WARN("Invalid handle %u passed.\n", handle
);
246 entry
= &t
->entries
[handle
];
247 if (entry
->type
!= type
)
249 WARN("Handle %u(%p) is not of type %#x.\n", handle
, entry
, type
);
253 return entry
->object
;
256 static ULONG WINAPI
D3D8CB_DestroySwapChain(IWineD3DSwapChain
*swapchain
)
260 TRACE("swapchain %p.\n", swapchain
);
262 IWineD3DSwapChain_GetParent(swapchain
, &parent
);
263 IUnknown_Release(parent
);
264 return IUnknown_Release(parent
);
267 /* IDirect3D IUnknown parts follow: */
268 static HRESULT WINAPI
IDirect3DDevice8Impl_QueryInterface(LPDIRECT3DDEVICE8 iface
,REFIID riid
,LPVOID
*ppobj
)
270 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
272 TRACE("iface %p, riid %s, object %p.\n",
273 iface
, debugstr_guid(riid
), ppobj
);
275 if (IsEqualGUID(riid
, &IID_IUnknown
)
276 || IsEqualGUID(riid
, &IID_IDirect3DDevice8
)) {
277 IUnknown_AddRef(iface
);
282 if (IsEqualGUID(riid
, &IID_IWineD3DDeviceParent
))
284 IUnknown_AddRef((IUnknown
*)&This
->device_parent_vtbl
);
285 *ppobj
= &This
->device_parent_vtbl
;
289 WARN("(%p)->(%s,%p),not found\n", This
, debugstr_guid(riid
), ppobj
);
291 return E_NOINTERFACE
;
294 static ULONG WINAPI
IDirect3DDevice8Impl_AddRef(LPDIRECT3DDEVICE8 iface
) {
295 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
296 ULONG ref
= InterlockedIncrement(&This
->ref
);
298 TRACE("%p increasing refcount to %u.\n", iface
, ref
);
303 static ULONG WINAPI
IDirect3DDevice8Impl_Release(LPDIRECT3DDEVICE8 iface
) {
304 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
307 if (This
->inDestruction
) return 0;
308 ref
= InterlockedDecrement(&This
->ref
);
310 TRACE("%p decreasing refcount to %u.\n", iface
, ref
);
315 TRACE("Releasing wined3d device %p\n", This
->WineD3DDevice
);
317 wined3d_mutex_lock();
319 This
->inDestruction
= TRUE
;
321 for(i
= 0; i
< This
->numConvertedDecls
; i
++) {
322 IDirect3DVertexDeclaration8_Release(This
->decls
[i
].decl
);
324 HeapFree(GetProcessHeap(), 0, This
->decls
);
326 IWineD3DDevice_Uninit3D(This
->WineD3DDevice
, D3D8CB_DestroySwapChain
);
327 IWineD3DDevice_ReleaseFocusWindow(This
->WineD3DDevice
);
328 IWineD3DDevice_Release(This
->WineD3DDevice
);
329 HeapFree(GetProcessHeap(), 0, This
->handle_table
.entries
);
330 HeapFree(GetProcessHeap(), 0, This
);
332 wined3d_mutex_unlock();
337 /* IDirect3DDevice Interface follow: */
338 static HRESULT WINAPI
IDirect3DDevice8Impl_TestCooperativeLevel(IDirect3DDevice8
*iface
)
340 TRACE("iface %p.\n", iface
);
345 static UINT WINAPI
IDirect3DDevice8Impl_GetAvailableTextureMem(LPDIRECT3DDEVICE8 iface
) {
346 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
349 TRACE("iface %p.\n", iface
);
351 wined3d_mutex_lock();
352 hr
= IWineD3DDevice_GetAvailableTextureMem(This
->WineD3DDevice
);
353 wined3d_mutex_unlock();
358 static HRESULT WINAPI
IDirect3DDevice8Impl_ResourceManagerDiscardBytes(LPDIRECT3DDEVICE8 iface
, DWORD Bytes
) {
359 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
362 TRACE("iface %p, byte_count %u.\n", iface
, Bytes
);
363 FIXME("Byte count ignored.\n");
365 wined3d_mutex_lock();
366 hr
= IWineD3DDevice_EvictManagedResources(This
->WineD3DDevice
);
367 wined3d_mutex_unlock();
372 static HRESULT WINAPI
IDirect3DDevice8Impl_GetDirect3D(LPDIRECT3DDEVICE8 iface
, IDirect3D8
** ppD3D8
) {
373 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
377 TRACE("iface %p, d3d8 %p.\n", iface
, ppD3D8
);
379 if (NULL
== ppD3D8
) {
380 return D3DERR_INVALIDCALL
;
383 wined3d_mutex_lock();
384 hr
= IWineD3DDevice_GetDirect3D(This
->WineD3DDevice
, &pWineD3D
);
385 if (hr
== D3D_OK
&& pWineD3D
!= NULL
)
387 IWineD3D_GetParent(pWineD3D
,(IUnknown
**)ppD3D8
);
388 IWineD3D_Release(pWineD3D
);
390 FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
393 wined3d_mutex_unlock();
395 TRACE("(%p) returning %p\n",This
, *ppD3D8
);
400 static HRESULT WINAPI
IDirect3DDevice8Impl_GetDeviceCaps(LPDIRECT3DDEVICE8 iface
, D3DCAPS8
* pCaps
) {
401 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
402 HRESULT hrc
= D3D_OK
;
403 WINED3DCAPS
*pWineCaps
;
405 TRACE("iface %p, caps %p.\n", iface
, pCaps
);
408 return D3DERR_INVALIDCALL
;
410 pWineCaps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WINED3DCAPS
));
411 if(pWineCaps
== NULL
){
412 return D3DERR_INVALIDCALL
; /* well this is what MSDN says to return */
415 wined3d_mutex_lock();
416 hrc
= IWineD3DDevice_GetDeviceCaps(This
->WineD3DDevice
, pWineCaps
);
417 wined3d_mutex_unlock();
419 fixup_caps(pWineCaps
);
420 WINECAPSTOD3D8CAPS(pCaps
, pWineCaps
)
421 HeapFree(GetProcessHeap(), 0, pWineCaps
);
423 TRACE("Returning %p %p\n", This
, pCaps
);
427 static HRESULT WINAPI
IDirect3DDevice8Impl_GetDisplayMode(LPDIRECT3DDEVICE8 iface
, D3DDISPLAYMODE
* pMode
) {
428 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
431 TRACE("iface %p, mode %p.\n", iface
, pMode
);
433 wined3d_mutex_lock();
434 hr
= IWineD3DDevice_GetDisplayMode(This
->WineD3DDevice
, 0, (WINED3DDISPLAYMODE
*) pMode
);
435 wined3d_mutex_unlock();
437 if (SUCCEEDED(hr
)) pMode
->Format
= d3dformat_from_wined3dformat(pMode
->Format
);
442 static HRESULT WINAPI
IDirect3DDevice8Impl_GetCreationParameters(LPDIRECT3DDEVICE8 iface
, D3DDEVICE_CREATION_PARAMETERS
*pParameters
) {
443 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
446 TRACE("iface %p, parameters %p.\n", iface
, pParameters
);
448 wined3d_mutex_lock();
449 hr
= IWineD3DDevice_GetCreationParameters(This
->WineD3DDevice
, (WINED3DDEVICE_CREATION_PARAMETERS
*) pParameters
);
450 wined3d_mutex_unlock();
455 static HRESULT WINAPI
IDirect3DDevice8Impl_SetCursorProperties(LPDIRECT3DDEVICE8 iface
, UINT XHotSpot
, UINT YHotSpot
, IDirect3DSurface8
* pCursorBitmap
) {
456 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
457 IDirect3DSurface8Impl
*pSurface
= (IDirect3DSurface8Impl
*)pCursorBitmap
;
460 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
461 iface
, XHotSpot
, YHotSpot
, pCursorBitmap
);
464 WARN("No cursor bitmap, returning WINED3DERR_INVALIDCALL\n");
465 return WINED3DERR_INVALIDCALL
;
468 wined3d_mutex_lock();
469 hr
= IWineD3DDevice_SetCursorProperties(This
->WineD3DDevice
,XHotSpot
,YHotSpot
,pSurface
->wineD3DSurface
);
470 wined3d_mutex_unlock();
475 static void WINAPI
IDirect3DDevice8Impl_SetCursorPosition(LPDIRECT3DDEVICE8 iface
, UINT XScreenSpace
, UINT YScreenSpace
, DWORD Flags
) {
476 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
478 TRACE("iface %p, x %u, y %u, flags %#x.\n",
479 iface
, XScreenSpace
, YScreenSpace
, Flags
);
481 wined3d_mutex_lock();
482 IWineD3DDevice_SetCursorPosition(This
->WineD3DDevice
, XScreenSpace
, YScreenSpace
, Flags
);
483 wined3d_mutex_unlock();
486 static BOOL WINAPI
IDirect3DDevice8Impl_ShowCursor(LPDIRECT3DDEVICE8 iface
, BOOL bShow
) {
487 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
490 TRACE("iface %p, show %#x.\n", iface
, bShow
);
492 wined3d_mutex_lock();
493 ret
= IWineD3DDevice_ShowCursor(This
->WineD3DDevice
, bShow
);
494 wined3d_mutex_unlock();
499 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateAdditionalSwapChain(IDirect3DDevice8
*iface
,
500 D3DPRESENT_PARAMETERS
*present_parameters
, IDirect3DSwapChain8
**swapchain
)
502 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
503 IDirect3DSwapChain8Impl
*object
;
506 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
507 iface
, present_parameters
, swapchain
);
509 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
512 ERR("Failed to allocate swapchain memory.\n");
513 return E_OUTOFMEMORY
;
516 hr
= swapchain_init(object
, This
, present_parameters
);
519 WARN("Failed to initialize swapchain, hr %#x.\n", hr
);
520 HeapFree(GetProcessHeap(), 0, object
);
524 TRACE("Created swapchain %p.\n", object
);
525 *swapchain
= (IDirect3DSwapChain8
*)object
;
530 static HRESULT WINAPI
IDirect3DDevice8Impl_Reset(LPDIRECT3DDEVICE8 iface
, D3DPRESENT_PARAMETERS
* pPresentationParameters
) {
531 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
532 WINED3DPRESENT_PARAMETERS localParameters
;
535 TRACE("iface %p, present_parameters %p.\n", iface
, pPresentationParameters
);
537 localParameters
.BackBufferWidth
= pPresentationParameters
->BackBufferWidth
;
538 localParameters
.BackBufferHeight
= pPresentationParameters
->BackBufferHeight
;
539 localParameters
.BackBufferFormat
= wined3dformat_from_d3dformat(pPresentationParameters
->BackBufferFormat
);
540 localParameters
.BackBufferCount
= pPresentationParameters
->BackBufferCount
;
541 localParameters
.MultiSampleType
= pPresentationParameters
->MultiSampleType
;
542 localParameters
.MultiSampleQuality
= 0; /* d3d9 only */
543 localParameters
.SwapEffect
= pPresentationParameters
->SwapEffect
;
544 localParameters
.hDeviceWindow
= pPresentationParameters
->hDeviceWindow
;
545 localParameters
.Windowed
= pPresentationParameters
->Windowed
;
546 localParameters
.EnableAutoDepthStencil
= pPresentationParameters
->EnableAutoDepthStencil
;
547 localParameters
.AutoDepthStencilFormat
= wined3dformat_from_d3dformat(pPresentationParameters
->AutoDepthStencilFormat
);
548 localParameters
.Flags
= pPresentationParameters
->Flags
;
549 localParameters
.FullScreen_RefreshRateInHz
= pPresentationParameters
->FullScreen_RefreshRateInHz
;
550 localParameters
.PresentationInterval
= pPresentationParameters
->FullScreen_PresentationInterval
;
551 localParameters
.AutoRestoreDisplayMode
= TRUE
;
553 wined3d_mutex_lock();
554 hr
= IWineD3DDevice_Reset(This
->WineD3DDevice
, &localParameters
);
556 hr
= IWineD3DDevice_SetRenderState(This
->WineD3DDevice
, WINED3DRS_POINTSIZE_MIN
, 0);
558 wined3d_mutex_unlock();
560 pPresentationParameters
->BackBufferWidth
= localParameters
.BackBufferWidth
;
561 pPresentationParameters
->BackBufferHeight
= localParameters
.BackBufferHeight
;
562 pPresentationParameters
->BackBufferFormat
= d3dformat_from_wined3dformat(localParameters
.BackBufferFormat
);
563 pPresentationParameters
->BackBufferCount
= localParameters
.BackBufferCount
;
564 pPresentationParameters
->MultiSampleType
= localParameters
.MultiSampleType
;
565 pPresentationParameters
->SwapEffect
= localParameters
.SwapEffect
;
566 pPresentationParameters
->hDeviceWindow
= localParameters
.hDeviceWindow
;
567 pPresentationParameters
->Windowed
= localParameters
.Windowed
;
568 pPresentationParameters
->EnableAutoDepthStencil
= localParameters
.EnableAutoDepthStencil
;
569 pPresentationParameters
->AutoDepthStencilFormat
= d3dformat_from_wined3dformat(localParameters
.AutoDepthStencilFormat
);
570 pPresentationParameters
->Flags
= localParameters
.Flags
;
571 pPresentationParameters
->FullScreen_RefreshRateInHz
= localParameters
.FullScreen_RefreshRateInHz
;
572 pPresentationParameters
->FullScreen_PresentationInterval
= localParameters
.PresentationInterval
;
577 static HRESULT WINAPI
IDirect3DDevice8Impl_Present(LPDIRECT3DDEVICE8 iface
, CONST RECT
* pSourceRect
,CONST RECT
* pDestRect
,HWND hDestWindowOverride
,CONST RGNDATA
* pDirtyRegion
) {
578 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
581 TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
582 iface
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
584 wined3d_mutex_lock();
585 hr
= IWineD3DDevice_Present(This
->WineD3DDevice
, pSourceRect
, pDestRect
, hDestWindowOverride
, pDirtyRegion
);
586 wined3d_mutex_unlock();
591 static HRESULT WINAPI
IDirect3DDevice8Impl_GetBackBuffer(LPDIRECT3DDEVICE8 iface
, UINT BackBuffer
, D3DBACKBUFFER_TYPE Type
, IDirect3DSurface8
** ppBackBuffer
) {
592 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
593 IWineD3DSurface
*retSurface
= NULL
;
596 TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
597 iface
, BackBuffer
, Type
, ppBackBuffer
);
599 wined3d_mutex_lock();
600 rc
= IWineD3DDevice_GetBackBuffer(This
->WineD3DDevice
, 0, BackBuffer
, (WINED3DBACKBUFFER_TYPE
) Type
, &retSurface
);
601 if (rc
== D3D_OK
&& NULL
!= retSurface
&& NULL
!= ppBackBuffer
) {
602 IWineD3DSurface_GetParent(retSurface
, (IUnknown
**)ppBackBuffer
);
603 IWineD3DSurface_Release(retSurface
);
605 wined3d_mutex_unlock();
610 static HRESULT WINAPI
IDirect3DDevice8Impl_GetRasterStatus(LPDIRECT3DDEVICE8 iface
, D3DRASTER_STATUS
* pRasterStatus
) {
611 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
614 TRACE("iface %p, raster_status %p.\n", iface
, pRasterStatus
);
616 wined3d_mutex_lock();
617 hr
= IWineD3DDevice_GetRasterStatus(This
->WineD3DDevice
, 0, (WINED3DRASTER_STATUS
*) pRasterStatus
);
618 wined3d_mutex_unlock();
623 static void WINAPI
IDirect3DDevice8Impl_SetGammaRamp(LPDIRECT3DDEVICE8 iface
, DWORD Flags
, CONST D3DGAMMARAMP
* pRamp
) {
624 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
626 TRACE("iface %p, flags %#x, ramp %p.\n", iface
, Flags
, pRamp
);
628 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
629 wined3d_mutex_lock();
630 IWineD3DDevice_SetGammaRamp(This
->WineD3DDevice
, 0, Flags
, (CONST WINED3DGAMMARAMP
*) pRamp
);
631 wined3d_mutex_unlock();
634 static void WINAPI
IDirect3DDevice8Impl_GetGammaRamp(LPDIRECT3DDEVICE8 iface
, D3DGAMMARAMP
* pRamp
) {
635 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
637 TRACE("iface %p, ramp %p.\n", iface
, pRamp
);
639 /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
640 wined3d_mutex_lock();
641 IWineD3DDevice_GetGammaRamp(This
->WineD3DDevice
, 0, (WINED3DGAMMARAMP
*) pRamp
);
642 wined3d_mutex_unlock();
645 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateTexture(IDirect3DDevice8
*iface
,
646 UINT width
, UINT height
, UINT levels
, DWORD usage
, D3DFORMAT format
,
647 D3DPOOL pool
, IDirect3DTexture8
**texture
)
649 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
650 IDirect3DTexture8Impl
*object
;
653 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
654 iface
, width
, height
, levels
, usage
, format
, pool
, texture
);
656 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
659 ERR("Failed to allocate texture memory.\n");
660 return D3DERR_OUTOFVIDEOMEMORY
;
663 hr
= texture_init(object
, This
, width
, height
, levels
, usage
, format
, pool
);
666 WARN("Failed to initialize texture, hr %#x.\n", hr
);
667 HeapFree(GetProcessHeap(), 0, object
);
671 TRACE("Created texture %p.\n", object
);
672 *texture
= (IDirect3DTexture8
*)object
;
677 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateVolumeTexture(IDirect3DDevice8
*iface
,
678 UINT width
, UINT height
, UINT depth
, UINT levels
, DWORD usage
, D3DFORMAT format
,
679 D3DPOOL pool
, IDirect3DVolumeTexture8
**texture
)
681 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
682 IDirect3DVolumeTexture8Impl
*object
;
685 TRACE("iface %p, width %u, height %u, depth %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
686 iface
, width
, height
, depth
, levels
, usage
, format
, pool
, texture
);
688 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
691 ERR("Failed to allocate volume texture memory.\n");
692 return D3DERR_OUTOFVIDEOMEMORY
;
695 hr
= volumetexture_init(object
, This
, width
, height
, depth
, levels
, usage
, format
, pool
);
698 WARN("Failed to initialize volume texture, hr %#x.\n", hr
);
699 HeapFree(GetProcessHeap(), 0, object
);
703 TRACE("Created volume texture %p.\n", object
);
704 *texture
= (IDirect3DVolumeTexture8
*)object
;
709 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateCubeTexture(IDirect3DDevice8
*iface
, UINT edge_length
,
710 UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DCubeTexture8
**texture
)
712 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
713 IDirect3DCubeTexture8Impl
*object
;
716 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
717 iface
, edge_length
, levels
, usage
, format
, pool
, texture
);
719 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
722 ERR("Failed to allocate cube texture memory.\n");
723 return D3DERR_OUTOFVIDEOMEMORY
;
726 hr
= cubetexture_init(object
, This
, edge_length
, levels
, usage
, format
, pool
);
729 WARN("Failed to initialize cube texture, hr %#x.\n", hr
);
730 HeapFree(GetProcessHeap(), 0, object
);
734 TRACE("Created cube texture %p.\n", object
);
735 *texture
= (IDirect3DCubeTexture8
*)object
;
740 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateVertexBuffer(IDirect3DDevice8
*iface
, UINT size
, DWORD usage
,
741 DWORD fvf
, D3DPOOL pool
, IDirect3DVertexBuffer8
**buffer
)
743 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
744 IDirect3DVertexBuffer8Impl
*object
;
747 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p.\n",
748 iface
, size
, usage
, fvf
, pool
, buffer
);
750 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
753 ERR("Failed to allocate buffer memory.\n");
754 return D3DERR_OUTOFVIDEOMEMORY
;
757 hr
= vertexbuffer_init(object
, This
, size
, usage
, fvf
, pool
);
760 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr
);
761 HeapFree(GetProcessHeap(), 0, object
);
765 TRACE("Created vertex buffer %p.\n", object
);
766 *buffer
= (IDirect3DVertexBuffer8
*)object
;
771 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateIndexBuffer(IDirect3DDevice8
*iface
, UINT size
, DWORD usage
,
772 D3DFORMAT format
, D3DPOOL pool
, IDirect3DIndexBuffer8
**buffer
)
774 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
775 IDirect3DIndexBuffer8Impl
*object
;
778 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p.\n",
779 iface
, size
, usage
, format
, pool
, buffer
);
781 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
784 ERR("Failed to allocate buffer memory.\n");
785 return D3DERR_OUTOFVIDEOMEMORY
;
788 hr
= indexbuffer_init(object
, This
, size
, usage
, format
, pool
);
791 WARN("Failed to initialize index buffer, hr %#x.\n", hr
);
792 HeapFree(GetProcessHeap(), 0, object
);
796 TRACE("Created index buffer %p.\n", object
);
797 *buffer
= (IDirect3DIndexBuffer8
*)object
;
802 static HRESULT
IDirect3DDevice8Impl_CreateSurface(LPDIRECT3DDEVICE8 iface
, UINT Width
, UINT Height
,
803 D3DFORMAT Format
, BOOL Lockable
, BOOL Discard
, UINT Level
, IDirect3DSurface8
**ppSurface
,
804 UINT Usage
, D3DPOOL Pool
, D3DMULTISAMPLE_TYPE MultiSample
, DWORD MultisampleQuality
)
806 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
807 IDirect3DSurface8Impl
*object
;
810 TRACE("iface %p, width %u, height %u, format %#x, lockable %#x, discard %#x, level %u, surface %p,\n"
811 "\tusage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
812 iface
, Width
, Height
, Format
, Lockable
, Discard
, Level
, ppSurface
,
813 Usage
, Pool
, MultiSample
, MultisampleQuality
);
815 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirect3DSurface8Impl
));
818 FIXME("Failed to allocate surface memory.\n");
819 return D3DERR_OUTOFVIDEOMEMORY
;
822 hr
= surface_init(object
, This
, Width
, Height
, Format
, Lockable
, Discard
,
823 Level
, Usage
, Pool
, MultiSample
, MultisampleQuality
);
826 WARN("Failed to initialize surface, hr %#x.\n", hr
);
827 HeapFree(GetProcessHeap(), 0, object
);
831 TRACE("Created surface %p.\n", object
);
832 *ppSurface
= (IDirect3DSurface8
*)object
;
837 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateRenderTarget(LPDIRECT3DDEVICE8 iface
, UINT Width
, UINT Height
, D3DFORMAT Format
, D3DMULTISAMPLE_TYPE MultiSample
, BOOL Lockable
, IDirect3DSurface8
** ppSurface
) {
840 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, lockable %#x, surface %p.\n",
841 iface
, Width
, Height
, Format
, MultiSample
, Lockable
, ppSurface
);
843 hr
= IDirect3DDevice8Impl_CreateSurface(iface
, Width
, Height
, Format
, Lockable
, FALSE
/* Discard */,
844 0 /* Level */, ppSurface
, D3DUSAGE_RENDERTARGET
, D3DPOOL_DEFAULT
, MultiSample
, 0);
849 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE8 iface
, UINT Width
, UINT Height
, D3DFORMAT Format
, D3DMULTISAMPLE_TYPE MultiSample
, IDirect3DSurface8
** ppSurface
) {
852 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, surface %p.\n",
853 iface
, Width
, Height
, Format
, MultiSample
, ppSurface
);
855 /* TODO: Verify that Discard is false */
856 hr
= IDirect3DDevice8Impl_CreateSurface(iface
, Width
, Height
, Format
, TRUE
/* Lockable */, FALSE
,
857 0 /* Level */, ppSurface
, D3DUSAGE_DEPTHSTENCIL
, D3DPOOL_DEFAULT
, MultiSample
, 0);
862 /* IDirect3DDevice8Impl::CreateImageSurface returns surface with pool type SYSTEMMEM */
863 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateImageSurface(LPDIRECT3DDEVICE8 iface
, UINT Width
, UINT Height
, D3DFORMAT Format
, IDirect3DSurface8
** ppSurface
) {
866 TRACE("iface %p, width %u, height %u, format %#x, surface %p.\n",
867 iface
, Width
, Height
, Format
, ppSurface
);
869 hr
= IDirect3DDevice8Impl_CreateSurface(iface
, Width
, Height
, Format
, TRUE
/* Lockable */, FALSE
/* Discard */,
870 0 /* Level */, ppSurface
, 0 /* Usage (undefined/none) */, D3DPOOL_SYSTEMMEM
, D3DMULTISAMPLE_NONE
,
871 0 /* MultisampleQuality */);
876 static HRESULT WINAPI
IDirect3DDevice8Impl_CopyRects(LPDIRECT3DDEVICE8 iface
, IDirect3DSurface8
*pSourceSurface
, CONST RECT
*pSourceRects
, UINT cRects
, IDirect3DSurface8
*pDestinationSurface
, CONST POINT
*pDestPoints
) {
877 IDirect3DSurface8Impl
*Source
= (IDirect3DSurface8Impl
*) pSourceSurface
;
878 IDirect3DSurface8Impl
*Dest
= (IDirect3DSurface8Impl
*) pDestinationSurface
;
880 HRESULT hr
= WINED3D_OK
;
881 WINED3DFORMAT srcFormat
, destFormat
;
882 WINED3DSURFACE_DESC winedesc
;
884 TRACE("iface %p, src_surface %p, src_rects %p, rect_count %u, dst_surface %p, dst_points %p.\n",
885 iface
, pSourceSurface
, pSourceRects
, cRects
, pDestinationSurface
, pDestPoints
);
887 /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the
888 * destination texture is in WINED3DPOOL_DEFAULT. */
890 wined3d_mutex_lock();
891 IWineD3DSurface_GetDesc(Source
->wineD3DSurface
, &winedesc
);
892 srcFormat
= winedesc
.format
;
894 IWineD3DSurface_GetDesc(Dest
->wineD3DSurface
, &winedesc
);
895 destFormat
= winedesc
.format
;
897 /* Check that the source and destination formats match */
898 if (srcFormat
!= destFormat
&& WINED3DFMT_UNKNOWN
!= destFormat
) {
899 WARN("(%p) source %p format must match the dest %p format, returning WINED3DERR_INVALIDCALL\n", iface
, pSourceSurface
, pDestinationSurface
);
900 wined3d_mutex_unlock();
901 return WINED3DERR_INVALIDCALL
;
902 } else if (WINED3DFMT_UNKNOWN
== destFormat
) {
903 TRACE("(%p) : Converting destination surface from WINED3DFMT_UNKNOWN to the source format\n", iface
);
904 IWineD3DSurface_SetFormat(Dest
->wineD3DSurface
, srcFormat
);
907 /* Quick if complete copy ... */
908 if (cRects
== 0 && pSourceRects
== NULL
&& pDestPoints
== NULL
) {
909 IWineD3DSurface_BltFast(Dest
->wineD3DSurface
, 0, 0, Source
->wineD3DSurface
, NULL
, WINEDDBLTFAST_NOCOLORKEY
);
912 /* Copy rect by rect */
913 if (NULL
!= pSourceRects
&& NULL
!= pDestPoints
) {
914 for (i
= 0; i
< cRects
; ++i
) {
915 IWineD3DSurface_BltFast(Dest
->wineD3DSurface
, pDestPoints
[i
].x
, pDestPoints
[i
].y
, Source
->wineD3DSurface
, &pSourceRects
[i
], WINEDDBLTFAST_NOCOLORKEY
);
918 for (i
= 0; i
< cRects
; ++i
) {
919 IWineD3DSurface_BltFast(Dest
->wineD3DSurface
, 0, 0, Source
->wineD3DSurface
, &pSourceRects
[i
], WINEDDBLTFAST_NOCOLORKEY
);
923 wined3d_mutex_unlock();
928 static HRESULT WINAPI
IDirect3DDevice8Impl_UpdateTexture(LPDIRECT3DDEVICE8 iface
, IDirect3DBaseTexture8
* pSourceTexture
, IDirect3DBaseTexture8
* pDestinationTexture
) {
929 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
932 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface
, pSourceTexture
, pDestinationTexture
);
934 wined3d_mutex_lock();
935 hr
= IWineD3DDevice_UpdateTexture(This
->WineD3DDevice
, ((IDirect3DBaseTexture8Impl
*)pSourceTexture
)->wineD3DBaseTexture
, ((IDirect3DBaseTexture8Impl
*)pDestinationTexture
)->wineD3DBaseTexture
);
936 wined3d_mutex_unlock();
941 static HRESULT WINAPI
IDirect3DDevice8Impl_GetFrontBuffer(LPDIRECT3DDEVICE8 iface
, IDirect3DSurface8
* pDestSurface
) {
942 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
943 IDirect3DSurface8Impl
*destSurface
= (IDirect3DSurface8Impl
*)pDestSurface
;
946 TRACE("iface %p, dst_surface %p.\n", iface
, pDestSurface
);
948 if (pDestSurface
== NULL
) {
949 WARN("(%p) : Caller passed NULL as pDestSurface returning D3DERR_INVALIDCALL\n", This
);
950 return D3DERR_INVALIDCALL
;
953 wined3d_mutex_lock();
954 hr
= IWineD3DDevice_GetFrontBufferData(This
->WineD3DDevice
, 0, destSurface
->wineD3DSurface
);
955 wined3d_mutex_unlock();
960 static HRESULT WINAPI
IDirect3DDevice8Impl_SetRenderTarget(LPDIRECT3DDEVICE8 iface
, IDirect3DSurface8
* pRenderTarget
, IDirect3DSurface8
* pNewZStencil
) {
961 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
962 IDirect3DSurface8Impl
*pSurface
= (IDirect3DSurface8Impl
*)pRenderTarget
;
963 IDirect3DSurface8Impl
*pZSurface
= (IDirect3DSurface8Impl
*)pNewZStencil
;
964 IWineD3DSurface
*original_ds
= NULL
;
967 TRACE("iface %p, render_target %p, depth_stencil %p.\n", iface
, pRenderTarget
, pNewZStencil
);
969 wined3d_mutex_lock();
971 hr
= IWineD3DDevice_GetDepthStencilSurface(This
->WineD3DDevice
, &original_ds
);
972 if (hr
== WINED3D_OK
|| hr
== WINED3DERR_NOTFOUND
)
974 hr
= IWineD3DDevice_SetDepthStencilSurface(This
->WineD3DDevice
, pZSurface
? pZSurface
->wineD3DSurface
: NULL
);
975 if (SUCCEEDED(hr
) && pSurface
)
976 hr
= IWineD3DDevice_SetRenderTarget(This
->WineD3DDevice
, 0, pSurface
->wineD3DSurface
, TRUE
);
977 if (FAILED(hr
)) IWineD3DDevice_SetDepthStencilSurface(This
->WineD3DDevice
, original_ds
);
979 if (original_ds
) IWineD3DSurface_Release(original_ds
);
981 wined3d_mutex_unlock();
986 static HRESULT WINAPI
IDirect3DDevice8Impl_GetRenderTarget(LPDIRECT3DDEVICE8 iface
, IDirect3DSurface8
** ppRenderTarget
) {
987 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
989 IWineD3DSurface
*pRenderTarget
;
991 TRACE("iface %p, render_target %p.\n", iface
, ppRenderTarget
);
993 if (ppRenderTarget
== NULL
) {
994 return D3DERR_INVALIDCALL
;
997 wined3d_mutex_lock();
998 hr
= IWineD3DDevice_GetRenderTarget(This
->WineD3DDevice
, 0, &pRenderTarget
);
1000 if (hr
== D3D_OK
&& pRenderTarget
!= NULL
) {
1001 IWineD3DSurface_GetParent(pRenderTarget
,(IUnknown
**)ppRenderTarget
);
1002 IWineD3DSurface_Release(pRenderTarget
);
1004 FIXME("Call to IWineD3DDevice_GetRenderTarget failed\n");
1005 *ppRenderTarget
= NULL
;
1007 wined3d_mutex_unlock();
1012 static HRESULT WINAPI
IDirect3DDevice8Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE8 iface
, IDirect3DSurface8
** ppZStencilSurface
) {
1013 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1014 HRESULT hr
= D3D_OK
;
1015 IWineD3DSurface
*pZStencilSurface
;
1017 TRACE("iface %p, depth_stencil %p.\n", iface
, ppZStencilSurface
);
1019 if(ppZStencilSurface
== NULL
){
1020 return D3DERR_INVALIDCALL
;
1023 wined3d_mutex_lock();
1024 hr
=IWineD3DDevice_GetDepthStencilSurface(This
->WineD3DDevice
,&pZStencilSurface
);
1025 if (hr
== WINED3D_OK
) {
1026 IWineD3DSurface_GetParent(pZStencilSurface
,(IUnknown
**)ppZStencilSurface
);
1027 IWineD3DSurface_Release(pZStencilSurface
);
1029 if (hr
!= WINED3DERR_NOTFOUND
)
1030 FIXME("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr
);
1031 *ppZStencilSurface
= NULL
;
1033 wined3d_mutex_unlock();
1038 static HRESULT WINAPI
IDirect3DDevice8Impl_BeginScene(LPDIRECT3DDEVICE8 iface
) {
1039 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1042 TRACE("iface %p.\n", iface
);
1044 wined3d_mutex_lock();
1045 hr
= IWineD3DDevice_BeginScene(This
->WineD3DDevice
);
1046 wined3d_mutex_unlock();
1051 static HRESULT WINAPI DECLSPEC_HOTPATCH
IDirect3DDevice8Impl_EndScene(LPDIRECT3DDEVICE8 iface
) {
1052 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1055 TRACE("iface %p.\n", iface
);
1057 wined3d_mutex_lock();
1058 hr
= IWineD3DDevice_EndScene(This
->WineD3DDevice
);
1059 wined3d_mutex_unlock();
1064 static HRESULT WINAPI
IDirect3DDevice8Impl_Clear(LPDIRECT3DDEVICE8 iface
, DWORD Count
, CONST D3DRECT
* pRects
, DWORD Flags
, D3DCOLOR Color
, float Z
, DWORD Stencil
) {
1065 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1068 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1069 iface
, Count
, pRects
, Flags
, Color
, Z
, Stencil
);
1071 /* Note: D3DRECT is compatible with WINED3DRECT */
1072 wined3d_mutex_lock();
1073 hr
= IWineD3DDevice_Clear(This
->WineD3DDevice
, Count
, (CONST WINED3DRECT
*) pRects
, Flags
, Color
, Z
, Stencil
);
1074 wined3d_mutex_unlock();
1079 static HRESULT WINAPI
IDirect3DDevice8Impl_SetTransform(LPDIRECT3DDEVICE8 iface
, D3DTRANSFORMSTATETYPE State
, CONST D3DMATRIX
* lpMatrix
) {
1080 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1083 TRACE("iface %p, state %#x, matrix %p.\n", iface
, State
, lpMatrix
);
1085 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1086 wined3d_mutex_lock();
1087 hr
= IWineD3DDevice_SetTransform(This
->WineD3DDevice
, State
, (CONST WINED3DMATRIX
*) lpMatrix
);
1088 wined3d_mutex_unlock();
1093 static HRESULT WINAPI
IDirect3DDevice8Impl_GetTransform(LPDIRECT3DDEVICE8 iface
, D3DTRANSFORMSTATETYPE State
,D3DMATRIX
* pMatrix
) {
1094 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1097 TRACE("iface %p, state %#x, matrix %p.\n", iface
, State
, pMatrix
);
1099 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1100 wined3d_mutex_lock();
1101 hr
= IWineD3DDevice_GetTransform(This
->WineD3DDevice
, State
, (WINED3DMATRIX
*) pMatrix
);
1102 wined3d_mutex_unlock();
1107 static HRESULT WINAPI
IDirect3DDevice8Impl_MultiplyTransform(LPDIRECT3DDEVICE8 iface
, D3DTRANSFORMSTATETYPE State
, CONST D3DMATRIX
* pMatrix
) {
1108 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1111 TRACE("iface %p, state %#x, matrix %p.\n", iface
, State
, pMatrix
);
1113 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
1114 wined3d_mutex_lock();
1115 hr
= IWineD3DDevice_MultiplyTransform(This
->WineD3DDevice
, State
, (CONST WINED3DMATRIX
*) pMatrix
);
1116 wined3d_mutex_unlock();
1121 static HRESULT WINAPI
IDirect3DDevice8Impl_SetViewport(LPDIRECT3DDEVICE8 iface
, CONST D3DVIEWPORT8
* pViewport
) {
1122 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1125 TRACE("iface %p, viewport %p.\n", iface
, pViewport
);
1127 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1128 wined3d_mutex_lock();
1129 hr
= IWineD3DDevice_SetViewport(This
->WineD3DDevice
, (const WINED3DVIEWPORT
*)pViewport
);
1130 wined3d_mutex_unlock();
1135 static HRESULT WINAPI
IDirect3DDevice8Impl_GetViewport(LPDIRECT3DDEVICE8 iface
, D3DVIEWPORT8
* pViewport
) {
1136 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1139 TRACE("iface %p, viewport %p.\n", iface
, pViewport
);
1141 /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
1142 wined3d_mutex_lock();
1143 hr
= IWineD3DDevice_GetViewport(This
->WineD3DDevice
, (WINED3DVIEWPORT
*)pViewport
);
1144 wined3d_mutex_unlock();
1149 static HRESULT WINAPI
IDirect3DDevice8Impl_SetMaterial(LPDIRECT3DDEVICE8 iface
, CONST D3DMATERIAL8
* pMaterial
) {
1150 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1153 TRACE("iface %p, material %p.\n", iface
, pMaterial
);
1155 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1156 wined3d_mutex_lock();
1157 hr
= IWineD3DDevice_SetMaterial(This
->WineD3DDevice
, (const WINED3DMATERIAL
*)pMaterial
);
1158 wined3d_mutex_unlock();
1163 static HRESULT WINAPI
IDirect3DDevice8Impl_GetMaterial(LPDIRECT3DDEVICE8 iface
, D3DMATERIAL8
* pMaterial
) {
1164 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1167 TRACE("iface %p, material %p.\n", iface
, pMaterial
);
1169 /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
1170 wined3d_mutex_lock();
1171 hr
= IWineD3DDevice_GetMaterial(This
->WineD3DDevice
, (WINED3DMATERIAL
*)pMaterial
);
1172 wined3d_mutex_unlock();
1177 static HRESULT WINAPI
IDirect3DDevice8Impl_SetLight(LPDIRECT3DDEVICE8 iface
, DWORD Index
, CONST D3DLIGHT8
* pLight
) {
1178 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1181 TRACE("iface %p, index %u, light %p.\n", iface
, Index
, pLight
);
1183 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1184 wined3d_mutex_lock();
1185 hr
= IWineD3DDevice_SetLight(This
->WineD3DDevice
, Index
, (const WINED3DLIGHT
*)pLight
);
1186 wined3d_mutex_unlock();
1191 static HRESULT WINAPI
IDirect3DDevice8Impl_GetLight(LPDIRECT3DDEVICE8 iface
, DWORD Index
,D3DLIGHT8
* pLight
) {
1192 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1195 TRACE("iface %p, index %u, light %p.\n", iface
, Index
, pLight
);
1197 /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
1198 wined3d_mutex_lock();
1199 hr
= IWineD3DDevice_GetLight(This
->WineD3DDevice
, Index
, (WINED3DLIGHT
*)pLight
);
1200 wined3d_mutex_unlock();
1205 static HRESULT WINAPI
IDirect3DDevice8Impl_LightEnable(LPDIRECT3DDEVICE8 iface
, DWORD Index
,BOOL Enable
) {
1206 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1209 TRACE("iface %p, index %u, enable %#x.\n", iface
, Index
, Enable
);
1211 wined3d_mutex_lock();
1212 hr
= IWineD3DDevice_SetLightEnable(This
->WineD3DDevice
, Index
, Enable
);
1213 wined3d_mutex_unlock();
1218 static HRESULT WINAPI
IDirect3DDevice8Impl_GetLightEnable(LPDIRECT3DDEVICE8 iface
, DWORD Index
,BOOL
* pEnable
) {
1219 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1222 TRACE("iface %p, index %u, enable %p.\n", iface
, Index
, pEnable
);
1224 wined3d_mutex_lock();
1225 hr
= IWineD3DDevice_GetLightEnable(This
->WineD3DDevice
, Index
, pEnable
);
1226 wined3d_mutex_unlock();
1231 static HRESULT WINAPI
IDirect3DDevice8Impl_SetClipPlane(LPDIRECT3DDEVICE8 iface
, DWORD Index
,CONST
float* pPlane
) {
1232 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1235 TRACE("iface %p, index %u, plane %p.\n", iface
, Index
, pPlane
);
1237 wined3d_mutex_lock();
1238 hr
= IWineD3DDevice_SetClipPlane(This
->WineD3DDevice
, Index
, pPlane
);
1239 wined3d_mutex_unlock();
1244 static HRESULT WINAPI
IDirect3DDevice8Impl_GetClipPlane(LPDIRECT3DDEVICE8 iface
, DWORD Index
,float* pPlane
) {
1245 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1248 TRACE("iface %p, index %u, plane %p.\n", iface
, Index
, pPlane
);
1250 wined3d_mutex_lock();
1251 hr
= IWineD3DDevice_GetClipPlane(This
->WineD3DDevice
, Index
, pPlane
);
1252 wined3d_mutex_unlock();
1257 static HRESULT WINAPI
IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface
, D3DRENDERSTATETYPE State
,DWORD Value
) {
1258 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1261 TRACE("iface %p, state %#x, value %#x.\n", iface
, State
, Value
);
1263 wined3d_mutex_lock();
1264 hr
= IWineD3DDevice_SetRenderState(This
->WineD3DDevice
, State
, Value
);
1265 wined3d_mutex_unlock();
1270 static HRESULT WINAPI
IDirect3DDevice8Impl_GetRenderState(LPDIRECT3DDEVICE8 iface
, D3DRENDERSTATETYPE State
,DWORD
* pValue
) {
1271 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1274 TRACE("iface %p, state %#x, value %p.\n", iface
, State
, pValue
);
1276 wined3d_mutex_lock();
1277 hr
= IWineD3DDevice_GetRenderState(This
->WineD3DDevice
, State
, pValue
);
1278 wined3d_mutex_unlock();
1283 static HRESULT WINAPI
IDirect3DDevice8Impl_BeginStateBlock(LPDIRECT3DDEVICE8 iface
) {
1284 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1287 TRACE("iface %p.\n", iface
);
1289 wined3d_mutex_lock();
1290 hr
= IWineD3DDevice_BeginStateBlock(This
->WineD3DDevice
);
1291 wined3d_mutex_unlock();
1296 static HRESULT WINAPI
IDirect3DDevice8Impl_EndStateBlock(LPDIRECT3DDEVICE8 iface
, DWORD
* pToken
) {
1297 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1298 IWineD3DStateBlock
*stateblock
;
1301 TRACE("iface %p, token %p.\n", iface
, pToken
);
1303 /* Tell wineD3D to endstateblock before anything else (in case we run out
1304 * of memory later and cause locking problems)
1306 wined3d_mutex_lock();
1307 hr
= IWineD3DDevice_EndStateBlock(This
->WineD3DDevice
, &stateblock
);
1309 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
1310 wined3d_mutex_unlock();
1314 *pToken
= d3d8_allocate_handle(&This
->handle_table
, stateblock
, D3D8_HANDLE_SB
);
1315 wined3d_mutex_unlock();
1317 if (*pToken
== D3D8_INVALID_HANDLE
)
1319 ERR("Failed to create a handle\n");
1320 wined3d_mutex_lock();
1321 IWineD3DStateBlock_Release(stateblock
);
1322 wined3d_mutex_unlock();
1327 TRACE("Returning %#x (%p).\n", *pToken
, stateblock
);
1332 static HRESULT WINAPI
IDirect3DDevice8Impl_ApplyStateBlock(LPDIRECT3DDEVICE8 iface
, DWORD Token
) {
1333 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1334 IWineD3DStateBlock
*stateblock
;
1337 TRACE("iface %p, token %#x.\n", iface
, Token
);
1339 wined3d_mutex_lock();
1340 stateblock
= d3d8_get_object(&This
->handle_table
, Token
- 1, D3D8_HANDLE_SB
);
1343 WARN("Invalid handle (%#x) passed.\n", Token
);
1344 wined3d_mutex_unlock();
1345 return D3DERR_INVALIDCALL
;
1347 hr
= IWineD3DStateBlock_Apply(stateblock
);
1348 wined3d_mutex_unlock();
1353 static HRESULT WINAPI
IDirect3DDevice8Impl_CaptureStateBlock(LPDIRECT3DDEVICE8 iface
, DWORD Token
) {
1354 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1355 IWineD3DStateBlock
*stateblock
;
1358 TRACE("iface %p, token %#x.\n", iface
, Token
);
1360 wined3d_mutex_lock();
1361 stateblock
= d3d8_get_object(&This
->handle_table
, Token
- 1, D3D8_HANDLE_SB
);
1364 WARN("Invalid handle (%#x) passed.\n", Token
);
1365 wined3d_mutex_unlock();
1366 return D3DERR_INVALIDCALL
;
1368 hr
= IWineD3DStateBlock_Capture(stateblock
);
1369 wined3d_mutex_unlock();
1374 static HRESULT WINAPI
IDirect3DDevice8Impl_DeleteStateBlock(LPDIRECT3DDEVICE8 iface
, DWORD Token
) {
1375 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1376 IWineD3DStateBlock
*stateblock
;
1378 TRACE("iface %p, token %#x.\n", iface
, Token
);
1380 wined3d_mutex_lock();
1381 stateblock
= d3d8_free_handle(&This
->handle_table
, Token
- 1, D3D8_HANDLE_SB
);
1385 WARN("Invalid handle (%#x) passed.\n", Token
);
1386 wined3d_mutex_unlock();
1387 return D3DERR_INVALIDCALL
;
1390 if (IWineD3DStateBlock_Release((IUnknown
*)stateblock
))
1392 ERR("Stateblock %p has references left, this shouldn't happen.\n", stateblock
);
1394 wined3d_mutex_unlock();
1399 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateStateBlock(IDirect3DDevice8
*iface
,
1400 D3DSTATEBLOCKTYPE Type
, DWORD
*handle
)
1402 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1403 IWineD3DStateBlock
*stateblock
;
1406 TRACE("iface %p, type %#x, handle %p.\n", iface
, Type
, handle
);
1408 if (Type
!= D3DSBT_ALL
1409 && Type
!= D3DSBT_PIXELSTATE
1410 && Type
!= D3DSBT_VERTEXSTATE
)
1412 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
1413 return D3DERR_INVALIDCALL
;
1416 wined3d_mutex_lock();
1417 hr
= IWineD3DDevice_CreateStateBlock(This
->WineD3DDevice
, (WINED3DSTATEBLOCKTYPE
)Type
,
1421 wined3d_mutex_unlock();
1422 ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr
);
1426 *handle
= d3d8_allocate_handle(&This
->handle_table
, stateblock
, D3D8_HANDLE_SB
);
1427 wined3d_mutex_unlock();
1429 if (*handle
== D3D8_INVALID_HANDLE
)
1431 ERR("Failed to allocate a handle.\n");
1432 wined3d_mutex_lock();
1433 IWineD3DStateBlock_Release(stateblock
);
1434 wined3d_mutex_unlock();
1439 TRACE("Returning %#x (%p).\n", *handle
, stateblock
);
1444 static HRESULT WINAPI
IDirect3DDevice8Impl_SetClipStatus(LPDIRECT3DDEVICE8 iface
, CONST D3DCLIPSTATUS8
* pClipStatus
) {
1445 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1448 TRACE("iface %p, clip_status %p.\n", iface
, pClipStatus
);
1449 /* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
1451 wined3d_mutex_lock();
1452 hr
= IWineD3DDevice_SetClipStatus(This
->WineD3DDevice
, (const WINED3DCLIPSTATUS
*)pClipStatus
);
1453 wined3d_mutex_unlock();
1458 static HRESULT WINAPI
IDirect3DDevice8Impl_GetClipStatus(LPDIRECT3DDEVICE8 iface
, D3DCLIPSTATUS8
* pClipStatus
) {
1459 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1462 TRACE("iface %p, clip_status %p.\n", iface
, pClipStatus
);
1464 wined3d_mutex_lock();
1465 hr
= IWineD3DDevice_GetClipStatus(This
->WineD3DDevice
, (WINED3DCLIPSTATUS
*)pClipStatus
);
1466 wined3d_mutex_unlock();
1471 static HRESULT WINAPI
IDirect3DDevice8Impl_GetTexture(LPDIRECT3DDEVICE8 iface
, DWORD Stage
,IDirect3DBaseTexture8
** ppTexture
) {
1472 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1473 IWineD3DBaseTexture
*retTexture
;
1476 TRACE("iface %p, stage %u, texture %p.\n", iface
, Stage
, ppTexture
);
1478 if(ppTexture
== NULL
){
1479 return D3DERR_INVALIDCALL
;
1482 wined3d_mutex_lock();
1483 hr
= IWineD3DDevice_GetTexture(This
->WineD3DDevice
, Stage
, &retTexture
);
1486 WARN("Failed to get texture for stage %u, hr %#x.\n", Stage
, hr
);
1487 wined3d_mutex_unlock();
1494 IWineD3DBaseTexture_GetParent(retTexture
, (IUnknown
**)ppTexture
);
1495 IWineD3DBaseTexture_Release(retTexture
);
1501 wined3d_mutex_unlock();
1506 static HRESULT WINAPI
IDirect3DDevice8Impl_SetTexture(LPDIRECT3DDEVICE8 iface
, DWORD Stage
, IDirect3DBaseTexture8
* pTexture
) {
1507 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1510 TRACE("iface %p, stage %u, texture %p.\n", iface
, Stage
, pTexture
);
1512 wined3d_mutex_lock();
1513 hr
= IWineD3DDevice_SetTexture(This
->WineD3DDevice
, Stage
,
1514 pTexture
==NULL
? NULL
: ((IDirect3DBaseTexture8Impl
*)pTexture
)->wineD3DBaseTexture
);
1515 wined3d_mutex_unlock();
1520 static const struct tss_lookup
1527 {FALSE
, WINED3DTSS_FORCE_DWORD
}, /* 0, unused */
1528 {FALSE
, WINED3DTSS_COLOROP
}, /* 1, D3DTSS_COLOROP */
1529 {FALSE
, WINED3DTSS_COLORARG1
}, /* 2, D3DTSS_COLORARG1 */
1530 {FALSE
, WINED3DTSS_COLORARG2
}, /* 3, D3DTSS_COLORARG2 */
1531 {FALSE
, WINED3DTSS_ALPHAOP
}, /* 4, D3DTSS_ALPHAOP */
1532 {FALSE
, WINED3DTSS_ALPHAARG1
}, /* 5, D3DTSS_ALPHAARG1 */
1533 {FALSE
, WINED3DTSS_ALPHAARG2
}, /* 6, D3DTSS_ALPHAARG2 */
1534 {FALSE
, WINED3DTSS_BUMPENVMAT00
}, /* 7, D3DTSS_BUMPENVMAT00 */
1535 {FALSE
, WINED3DTSS_BUMPENVMAT01
}, /* 8, D3DTSS_BUMPENVMAT01 */
1536 {FALSE
, WINED3DTSS_BUMPENVMAT10
}, /* 9, D3DTSS_BUMPENVMAT10 */
1537 {FALSE
, WINED3DTSS_BUMPENVMAT11
}, /* 10, D3DTSS_BUMPENVMAT11 */
1538 {FALSE
, WINED3DTSS_TEXCOORDINDEX
}, /* 11, D3DTSS_TEXCOORDINDEX */
1539 {FALSE
, WINED3DTSS_FORCE_DWORD
}, /* 12, unused */
1540 {TRUE
, WINED3DSAMP_ADDRESSU
}, /* 13, D3DTSS_ADDRESSU */
1541 {TRUE
, WINED3DSAMP_ADDRESSV
}, /* 14, D3DTSS_ADDRESSV */
1542 {TRUE
, WINED3DSAMP_BORDERCOLOR
}, /* 15, D3DTSS_BORDERCOLOR */
1543 {TRUE
, WINED3DSAMP_MAGFILTER
}, /* 16, D3DTSS_MAGFILTER */
1544 {TRUE
, WINED3DSAMP_MINFILTER
}, /* 17, D3DTSS_MINFILTER */
1545 {TRUE
, WINED3DSAMP_MIPFILTER
}, /* 18, D3DTSS_MIPFILTER */
1546 {TRUE
, WINED3DSAMP_MIPMAPLODBIAS
}, /* 19, D3DTSS_MIPMAPLODBIAS */
1547 {TRUE
, WINED3DSAMP_MAXMIPLEVEL
}, /* 20, D3DTSS_MAXMIPLEVEL */
1548 {TRUE
, WINED3DSAMP_MAXANISOTROPY
}, /* 21, D3DTSS_MAXANISOTROPY */
1549 {FALSE
, WINED3DTSS_BUMPENVLSCALE
}, /* 22, D3DTSS_BUMPENVLSCALE */
1550 {FALSE
, WINED3DTSS_BUMPENVLOFFSET
}, /* 23, D3DTSS_BUMPENVLOFFSET */
1551 {FALSE
, WINED3DTSS_TEXTURETRANSFORMFLAGS
}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1552 {TRUE
, WINED3DSAMP_ADDRESSW
}, /* 25, D3DTSS_ADDRESSW */
1553 {FALSE
, WINED3DTSS_COLORARG0
}, /* 26, D3DTSS_COLORARG0 */
1554 {FALSE
, WINED3DTSS_ALPHAARG0
}, /* 27, D3DTSS_ALPHAARG0 */
1555 {FALSE
, WINED3DTSS_RESULTARG
}, /* 28, D3DTSS_RESULTARG */
1558 static HRESULT WINAPI
IDirect3DDevice8Impl_GetTextureStageState(LPDIRECT3DDEVICE8 iface
, DWORD Stage
,D3DTEXTURESTAGESTATETYPE Type
,DWORD
* pValue
) {
1559 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1560 const struct tss_lookup
*l
= &tss_lookup
[Type
];
1563 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface
, Stage
, Type
, pValue
);
1565 wined3d_mutex_lock();
1566 if (l
->sampler_state
) hr
= IWineD3DDevice_GetSamplerState(This
->WineD3DDevice
, Stage
, l
->state
, pValue
);
1567 else hr
= IWineD3DDevice_GetTextureStageState(This
->WineD3DDevice
, Stage
, l
->state
, pValue
);
1568 wined3d_mutex_unlock();
1573 static HRESULT WINAPI
IDirect3DDevice8Impl_SetTextureStageState(LPDIRECT3DDEVICE8 iface
, DWORD Stage
, D3DTEXTURESTAGESTATETYPE Type
, DWORD Value
) {
1574 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1575 const struct tss_lookup
*l
= &tss_lookup
[Type
];
1578 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface
, Stage
, Type
, Value
);
1580 wined3d_mutex_lock();
1581 if (l
->sampler_state
) hr
= IWineD3DDevice_SetSamplerState(This
->WineD3DDevice
, Stage
, l
->state
, Value
);
1582 else hr
= IWineD3DDevice_SetTextureStageState(This
->WineD3DDevice
, Stage
, l
->state
, Value
);
1583 wined3d_mutex_unlock();
1588 static HRESULT WINAPI
IDirect3DDevice8Impl_ValidateDevice(LPDIRECT3DDEVICE8 iface
, DWORD
* pNumPasses
) {
1589 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1592 TRACE("iface %p, pass_count %p.\n", iface
, pNumPasses
);
1594 wined3d_mutex_lock();
1595 hr
= IWineD3DDevice_ValidateDevice(This
->WineD3DDevice
, pNumPasses
);
1596 wined3d_mutex_unlock();
1601 static HRESULT WINAPI
IDirect3DDevice8Impl_GetInfo(IDirect3DDevice8
*iface
,
1602 DWORD info_id
, void *info
, DWORD info_size
)
1604 FIXME("iface %p, info_id %#x, info %p, info_size %u stub!\n", iface
, info_id
, info
, info_size
);
1609 static HRESULT WINAPI
IDirect3DDevice8Impl_SetPaletteEntries(LPDIRECT3DDEVICE8 iface
, UINT PaletteNumber
, CONST PALETTEENTRY
* pEntries
) {
1610 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1613 TRACE("iface %p, palette_idx %u, entries %p.\n", iface
, PaletteNumber
, pEntries
);
1615 wined3d_mutex_lock();
1616 hr
= IWineD3DDevice_SetPaletteEntries(This
->WineD3DDevice
, PaletteNumber
, pEntries
);
1617 wined3d_mutex_unlock();
1622 static HRESULT WINAPI
IDirect3DDevice8Impl_GetPaletteEntries(LPDIRECT3DDEVICE8 iface
, UINT PaletteNumber
, PALETTEENTRY
* pEntries
) {
1623 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1626 TRACE("iface %p, palette_idx %u, entries %p.\n", iface
, PaletteNumber
, pEntries
);
1628 wined3d_mutex_lock();
1629 hr
= IWineD3DDevice_GetPaletteEntries(This
->WineD3DDevice
, PaletteNumber
, pEntries
);
1630 wined3d_mutex_unlock();
1635 static HRESULT WINAPI
IDirect3DDevice8Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface
, UINT PaletteNumber
) {
1636 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1639 TRACE("iface %p, palette_idx %u.\n", iface
, PaletteNumber
);
1641 wined3d_mutex_lock();
1642 hr
= IWineD3DDevice_SetCurrentTexturePalette(This
->WineD3DDevice
, PaletteNumber
);
1643 wined3d_mutex_unlock();
1648 static HRESULT WINAPI
IDirect3DDevice8Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface
, UINT
*PaletteNumber
) {
1649 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1652 TRACE("iface %p, palette_idx %p.\n", iface
, PaletteNumber
);
1654 wined3d_mutex_lock();
1655 hr
= IWineD3DDevice_GetCurrentTexturePalette(This
->WineD3DDevice
, PaletteNumber
);
1656 wined3d_mutex_unlock();
1661 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawPrimitive(IDirect3DDevice8
*iface
, D3DPRIMITIVETYPE PrimitiveType
,
1662 UINT StartVertex
, UINT PrimitiveCount
)
1664 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1667 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1668 iface
, PrimitiveType
, StartVertex
, PrimitiveCount
);
1670 wined3d_mutex_lock();
1671 IWineD3DDevice_SetPrimitiveType(This
->WineD3DDevice
, PrimitiveType
);
1672 hr
= IWineD3DDevice_DrawPrimitive(This
->WineD3DDevice
, StartVertex
,
1673 vertex_count_from_primitive_count(PrimitiveType
, PrimitiveCount
));
1674 wined3d_mutex_unlock();
1679 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE8 iface
, D3DPRIMITIVETYPE PrimitiveType
,
1680 UINT MinVertexIndex
,UINT NumVertices
,UINT startIndex
,UINT primCount
) {
1681 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1684 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, start_idx %u, primitive_count %u.\n",
1685 iface
, PrimitiveType
, MinVertexIndex
, NumVertices
, startIndex
, primCount
);
1687 wined3d_mutex_lock();
1688 IWineD3DDevice_SetPrimitiveType(This
->WineD3DDevice
, PrimitiveType
);
1689 hr
= IWineD3DDevice_DrawIndexedPrimitive(This
->WineD3DDevice
, startIndex
,
1690 vertex_count_from_primitive_count(PrimitiveType
, primCount
));
1691 wined3d_mutex_unlock();
1696 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE8 iface
, D3DPRIMITIVETYPE PrimitiveType
,UINT PrimitiveCount
,CONST
void* pVertexStreamZeroData
,UINT VertexStreamZeroStride
) {
1697 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1700 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
1701 iface
, PrimitiveType
, PrimitiveCount
, pVertexStreamZeroData
, VertexStreamZeroStride
);
1703 wined3d_mutex_lock();
1704 IWineD3DDevice_SetPrimitiveType(This
->WineD3DDevice
, PrimitiveType
);
1705 hr
= IWineD3DDevice_DrawPrimitiveUP(This
->WineD3DDevice
,
1706 vertex_count_from_primitive_count(PrimitiveType
, PrimitiveCount
),
1707 pVertexStreamZeroData
, VertexStreamZeroStride
);
1708 wined3d_mutex_unlock();
1713 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE8 iface
, D3DPRIMITIVETYPE PrimitiveType
,UINT MinVertexIndex
,
1714 UINT NumVertexIndices
,UINT PrimitiveCount
,CONST
void* pIndexData
,
1715 D3DFORMAT IndexDataFormat
,CONST
void* pVertexStreamZeroData
,
1716 UINT VertexStreamZeroStride
) {
1717 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1720 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
1721 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
1722 iface
, PrimitiveType
, MinVertexIndex
, NumVertexIndices
, PrimitiveCount
,
1723 pIndexData
, IndexDataFormat
, pVertexStreamZeroData
, VertexStreamZeroStride
);
1725 wined3d_mutex_lock();
1726 IWineD3DDevice_SetPrimitiveType(This
->WineD3DDevice
, PrimitiveType
);
1727 hr
= IWineD3DDevice_DrawIndexedPrimitiveUP(This
->WineD3DDevice
,
1728 vertex_count_from_primitive_count(PrimitiveType
, PrimitiveCount
), pIndexData
,
1729 wined3dformat_from_d3dformat(IndexDataFormat
), pVertexStreamZeroData
, VertexStreamZeroStride
);
1730 wined3d_mutex_unlock();
1735 static HRESULT WINAPI
IDirect3DDevice8Impl_ProcessVertices(LPDIRECT3DDEVICE8 iface
, UINT SrcStartIndex
,UINT DestIndex
,UINT VertexCount
,IDirect3DVertexBuffer8
* pDestBuffer
,DWORD Flags
) {
1736 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1738 IDirect3DVertexBuffer8Impl
*dest
= (IDirect3DVertexBuffer8Impl
*) pDestBuffer
;
1740 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, flags %#x.\n",
1741 iface
, SrcStartIndex
, DestIndex
, VertexCount
, pDestBuffer
, Flags
);
1743 wined3d_mutex_lock();
1744 hr
= IWineD3DDevice_ProcessVertices(This
->WineD3DDevice
,SrcStartIndex
, DestIndex
, VertexCount
, dest
->wineD3DVertexBuffer
, NULL
, Flags
, dest
->fvf
);
1745 wined3d_mutex_unlock();
1750 static HRESULT WINAPI
IDirect3DDevice8Impl_CreateVertexShader(IDirect3DDevice8
*iface
,
1751 const DWORD
*declaration
, const DWORD
*byte_code
, DWORD
*shader
, DWORD usage
)
1753 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1754 IDirect3DVertexShader8Impl
*object
;
1755 DWORD shader_handle
;
1759 TRACE("iface %p, declaration %p, byte_code %p, shader %p, usage %#x.\n",
1760 iface
, declaration
, byte_code
, shader
, usage
);
1762 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1765 ERR("Failed to allocate vertex shader memory.\n");
1767 return E_OUTOFMEMORY
;
1770 wined3d_mutex_lock();
1771 handle
= d3d8_allocate_handle(&This
->handle_table
, object
, D3D8_HANDLE_VS
);
1772 wined3d_mutex_unlock();
1773 if (handle
== D3D8_INVALID_HANDLE
)
1775 ERR("Failed to allocate vertex shader handle.\n");
1776 HeapFree(GetProcessHeap(), 0, object
);
1778 return E_OUTOFMEMORY
;
1781 shader_handle
= handle
+ VS_HIGHESTFIXEDFXF
+ 1;
1783 hr
= vertexshader_init(object
, This
, declaration
, byte_code
, shader_handle
, usage
);
1786 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
1787 wined3d_mutex_lock();
1788 d3d8_free_handle(&This
->handle_table
, handle
, D3D8_HANDLE_VS
);
1789 wined3d_mutex_unlock();
1790 HeapFree(GetProcessHeap(), 0, object
);
1795 TRACE("Created vertex shader %p (handle %#x).\n", object
, shader_handle
);
1796 *shader
= shader_handle
;
1801 static IDirect3DVertexDeclaration8Impl
*IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl
*This
, DWORD fvf
)
1803 IDirect3DVertexDeclaration8Impl
*d3d8_declaration
;
1805 int p
, low
, high
; /* deliberately signed */
1806 struct FvfToDecl
*convertedDecls
= This
->decls
;
1808 TRACE("Searching for declaration for fvf %08x... ", fvf
);
1811 high
= This
->numConvertedDecls
- 1;
1812 while(low
<= high
) {
1813 p
= (low
+ high
) >> 1;
1815 if(convertedDecls
[p
].fvf
== fvf
) {
1816 TRACE("found %p\n", convertedDecls
[p
].decl
);
1817 return (IDirect3DVertexDeclaration8Impl
*)convertedDecls
[p
].decl
;
1818 } else if(convertedDecls
[p
].fvf
< fvf
) {
1824 TRACE("not found. Creating and inserting at position %d.\n", low
);
1826 d3d8_declaration
= HeapAlloc(GetProcessHeap(), 0, sizeof(*d3d8_declaration
));
1827 if (!d3d8_declaration
)
1829 ERR("Memory allocation failed.\n");
1833 hr
= vertexdeclaration_init_fvf(d3d8_declaration
, This
, fvf
);
1836 WARN("Failed to initialize vertex declaration, hr %#x.\n", hr
);
1837 HeapFree(GetProcessHeap(), 0, d3d8_declaration
);
1841 if(This
->declArraySize
== This
->numConvertedDecls
) {
1842 int grow
= This
->declArraySize
/ 2;
1843 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
1844 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
1845 if(!convertedDecls
) {
1846 /* This will destroy it */
1847 IDirect3DVertexDeclaration8_Release((IDirect3DVertexDeclaration8
*)d3d8_declaration
);
1850 This
->decls
= convertedDecls
;
1851 This
->declArraySize
+= grow
;
1854 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
1855 convertedDecls
[low
].decl
= (IDirect3DVertexDeclaration8
*)d3d8_declaration
;
1856 convertedDecls
[low
].fvf
= fvf
;
1857 This
->numConvertedDecls
++;
1859 TRACE("Returning %p. %u decls in array\n", d3d8_declaration
, This
->numConvertedDecls
);
1860 return d3d8_declaration
;
1863 static HRESULT WINAPI
IDirect3DDevice8Impl_SetVertexShader(LPDIRECT3DDEVICE8 iface
, DWORD pShader
) {
1864 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1865 IDirect3DVertexShader8Impl
*shader
;
1868 TRACE("iface %p, shader %#x.\n", iface
, pShader
);
1870 if (VS_HIGHESTFIXEDFXF
>= pShader
) {
1871 TRACE("Setting FVF, %#x\n", pShader
);
1873 wined3d_mutex_lock();
1874 IWineD3DDevice_SetVertexDeclaration(This
->WineD3DDevice
,
1875 IDirect3DDevice8Impl_FindDecl(This
, pShader
)->wined3d_vertex_declaration
);
1876 IWineD3DDevice_SetVertexShader(This
->WineD3DDevice
, NULL
);
1877 wined3d_mutex_unlock();
1882 TRACE("Setting shader\n");
1884 wined3d_mutex_lock();
1885 shader
= d3d8_get_object(&This
->handle_table
, pShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
);
1888 WARN("Invalid handle (%#x) passed.\n", pShader
);
1889 wined3d_mutex_unlock();
1891 return D3DERR_INVALIDCALL
;
1894 hr
= IWineD3DDevice_SetVertexDeclaration(This
->WineD3DDevice
,
1895 ((IDirect3DVertexDeclaration8Impl
*)shader
->vertex_declaration
)->wined3d_vertex_declaration
);
1896 if (SUCCEEDED(hr
)) hr
= IWineD3DDevice_SetVertexShader(This
->WineD3DDevice
, shader
->wineD3DVertexShader
);
1897 wined3d_mutex_unlock();
1899 TRACE("Returning hr %#x\n", hr
);
1904 static HRESULT WINAPI
IDirect3DDevice8Impl_GetVertexShader(LPDIRECT3DDEVICE8 iface
, DWORD
* ppShader
) {
1905 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1906 IWineD3DVertexDeclaration
*wined3d_declaration
;
1907 IDirect3DVertexDeclaration8
*d3d8_declaration
;
1910 TRACE("iface %p, shader %p.\n", iface
, ppShader
);
1912 wined3d_mutex_lock();
1913 hrc
= IWineD3DDevice_GetVertexDeclaration(This
->WineD3DDevice
, &wined3d_declaration
);
1916 wined3d_mutex_unlock();
1917 WARN("(%p) : Call to IWineD3DDevice_GetVertexDeclaration failed %#x (device %p)\n",
1918 This
, hrc
, This
->WineD3DDevice
);
1922 if (!wined3d_declaration
)
1924 wined3d_mutex_unlock();
1929 hrc
= IWineD3DVertexDeclaration_GetParent(wined3d_declaration
, (IUnknown
**)&d3d8_declaration
);
1930 IWineD3DVertexDeclaration_Release(wined3d_declaration
);
1931 wined3d_mutex_unlock();
1934 *ppShader
= ((IDirect3DVertexDeclaration8Impl
*)d3d8_declaration
)->shader_handle
;
1935 IDirect3DVertexDeclaration8_Release(d3d8_declaration
);
1938 TRACE("(%p) : returning %#x\n", This
, *ppShader
);
1943 static HRESULT WINAPI
IDirect3DDevice8Impl_DeleteVertexShader(LPDIRECT3DDEVICE8 iface
, DWORD pShader
) {
1944 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1945 IDirect3DVertexShader8Impl
*shader
;
1946 IWineD3DVertexShader
*cur
= NULL
;
1948 TRACE("iface %p, shader %#x.\n", iface
, pShader
);
1950 wined3d_mutex_lock();
1951 shader
= d3d8_free_handle(&This
->handle_table
, pShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
);
1954 WARN("Invalid handle (%#x) passed.\n", pShader
);
1955 wined3d_mutex_unlock();
1957 return D3DERR_INVALIDCALL
;
1960 IWineD3DDevice_GetVertexShader(This
->WineD3DDevice
, &cur
);
1964 if (cur
== shader
->wineD3DVertexShader
) IDirect3DDevice8_SetVertexShader(iface
, 0);
1965 IWineD3DVertexShader_Release(cur
);
1968 wined3d_mutex_unlock();
1970 if (IUnknown_Release((IUnknown
*)shader
))
1972 ERR("Shader %p has references left, this shouldn't happen.\n", shader
);
1978 static HRESULT WINAPI
IDirect3DDevice8Impl_SetVertexShaderConstant(LPDIRECT3DDEVICE8 iface
, DWORD Register
, CONST
void* pConstantData
, DWORD ConstantCount
) {
1979 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
1982 TRACE("iface %p, register %u, data %p, count %u.\n",
1983 iface
, Register
, pConstantData
, ConstantCount
);
1985 if(Register
+ ConstantCount
> D3D8_MAX_VERTEX_SHADER_CONSTANTF
) {
1986 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
1987 Register
+ ConstantCount
, D3D8_MAX_VERTEX_SHADER_CONSTANTF
);
1988 return D3DERR_INVALIDCALL
;
1991 wined3d_mutex_lock();
1992 hr
= IWineD3DDevice_SetVertexShaderConstantF(This
->WineD3DDevice
, Register
, pConstantData
, ConstantCount
);
1993 wined3d_mutex_unlock();
1998 static HRESULT WINAPI
IDirect3DDevice8Impl_GetVertexShaderConstant(LPDIRECT3DDEVICE8 iface
, DWORD Register
, void* pConstantData
, DWORD ConstantCount
) {
1999 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2002 TRACE("iface %p, register %u, data %p, count %u.\n",
2003 iface
, Register
, pConstantData
, ConstantCount
);
2005 if(Register
+ ConstantCount
> D3D8_MAX_VERTEX_SHADER_CONSTANTF
) {
2006 WARN("Trying to access %u constants, but d3d8 only supports %u\n",
2007 Register
+ ConstantCount
, D3D8_MAX_VERTEX_SHADER_CONSTANTF
);
2008 return D3DERR_INVALIDCALL
;
2011 wined3d_mutex_lock();
2012 hr
= IWineD3DDevice_GetVertexShaderConstantF(This
->WineD3DDevice
, Register
, pConstantData
, ConstantCount
);
2013 wined3d_mutex_unlock();
2018 static HRESULT WINAPI
IDirect3DDevice8Impl_GetVertexShaderDeclaration(LPDIRECT3DDEVICE8 iface
, DWORD pVertexShader
, void* pData
, DWORD
* pSizeOfData
) {
2019 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2020 IDirect3DVertexDeclaration8Impl
*declaration
;
2021 IDirect3DVertexShader8Impl
*shader
;
2023 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2024 iface
, pVertexShader
, pData
, pSizeOfData
);
2026 wined3d_mutex_lock();
2027 shader
= d3d8_get_object(&This
->handle_table
, pVertexShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
);
2028 wined3d_mutex_unlock();
2032 WARN("Invalid handle (%#x) passed.\n", pVertexShader
);
2033 return D3DERR_INVALIDCALL
;
2035 declaration
= (IDirect3DVertexDeclaration8Impl
*)shader
->vertex_declaration
;
2037 /* If pData is NULL, we just return the required size of the buffer. */
2039 *pSizeOfData
= declaration
->elements_size
;
2043 /* MSDN claims that if *pSizeOfData is smaller than the required size
2044 * we should write the required size and return D3DERR_MOREDATA.
2045 * That's not actually true. */
2046 if (*pSizeOfData
< declaration
->elements_size
) {
2047 return D3DERR_INVALIDCALL
;
2050 CopyMemory(pData
, declaration
->elements
, declaration
->elements_size
);
2055 static HRESULT WINAPI
IDirect3DDevice8Impl_GetVertexShaderFunction(LPDIRECT3DDEVICE8 iface
, DWORD pVertexShader
, void* pData
, DWORD
* pSizeOfData
) {
2056 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2057 IDirect3DVertexShader8Impl
*shader
= NULL
;
2060 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2061 iface
, pVertexShader
, pData
, pSizeOfData
);
2063 wined3d_mutex_lock();
2064 shader
= d3d8_get_object(&This
->handle_table
, pVertexShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_VS
);
2067 WARN("Invalid handle (%#x) passed.\n", pVertexShader
);
2068 wined3d_mutex_unlock();
2070 return D3DERR_INVALIDCALL
;
2073 if (!shader
->wineD3DVertexShader
)
2075 wined3d_mutex_unlock();
2080 hr
= IWineD3DVertexShader_GetFunction(shader
->wineD3DVertexShader
, pData
, pSizeOfData
);
2081 wined3d_mutex_unlock();
2086 static HRESULT WINAPI
IDirect3DDevice8Impl_SetIndices(LPDIRECT3DDEVICE8 iface
, IDirect3DIndexBuffer8
* pIndexData
, UINT baseVertexIndex
) {
2087 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2089 IDirect3DIndexBuffer8Impl
*ib
= (IDirect3DIndexBuffer8Impl
*)pIndexData
;
2091 TRACE("iface %p, buffer %p, base_vertex_idx %u.\n", iface
, pIndexData
, baseVertexIndex
);
2093 /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
2094 * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
2095 * vertex buffers can't be created to address them with an index that requires the 32nd bit
2096 * (4 Byte minimum vertex size * 2^31-1 -> 8 gb buffer. The index sign would be the least
2099 wined3d_mutex_lock();
2100 IWineD3DDevice_SetBaseVertexIndex(This
->WineD3DDevice
, baseVertexIndex
);
2101 hr
= IWineD3DDevice_SetIndexBuffer(This
->WineD3DDevice
,
2102 ib
? ib
->wineD3DIndexBuffer
: NULL
,
2103 ib
? ib
->format
: WINED3DFMT_UNKNOWN
);
2104 wined3d_mutex_unlock();
2109 static HRESULT WINAPI
IDirect3DDevice8Impl_GetIndices(LPDIRECT3DDEVICE8 iface
, IDirect3DIndexBuffer8
** ppIndexData
,UINT
* pBaseVertexIndex
) {
2110 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2111 IWineD3DBuffer
*retIndexData
= NULL
;
2112 HRESULT rc
= D3D_OK
;
2114 TRACE("iface %p, buffer %p, base_vertex_index %p.\n", iface
, ppIndexData
, pBaseVertexIndex
);
2116 if(ppIndexData
== NULL
){
2117 return D3DERR_INVALIDCALL
;
2120 /* The case from UINT to INT is safe because d3d8 will never set negative values */
2121 wined3d_mutex_lock();
2122 IWineD3DDevice_GetBaseVertexIndex(This
->WineD3DDevice
, (INT
*) pBaseVertexIndex
);
2123 rc
= IWineD3DDevice_GetIndexBuffer(This
->WineD3DDevice
, &retIndexData
);
2124 if (SUCCEEDED(rc
) && retIndexData
) {
2125 IWineD3DBuffer_GetParent(retIndexData
, (IUnknown
**)ppIndexData
);
2126 IWineD3DBuffer_Release(retIndexData
);
2128 if (FAILED(rc
)) FIXME("Call to GetIndices failed\n");
2129 *ppIndexData
= NULL
;
2131 wined3d_mutex_unlock();
2136 static HRESULT WINAPI
IDirect3DDevice8Impl_CreatePixelShader(IDirect3DDevice8
*iface
,
2137 const DWORD
*byte_code
, DWORD
*shader
)
2139 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2140 IDirect3DPixelShader8Impl
*object
;
2141 DWORD shader_handle
;
2145 TRACE("iface %p, byte_code %p, shader %p.\n", iface
, byte_code
, shader
);
2149 TRACE("(%p) Invalid call\n", This
);
2150 return D3DERR_INVALIDCALL
;
2153 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2156 ERR("Failed to allocate pixel shader memmory.\n");
2157 return E_OUTOFMEMORY
;
2160 wined3d_mutex_lock();
2161 handle
= d3d8_allocate_handle(&This
->handle_table
, object
, D3D8_HANDLE_PS
);
2162 wined3d_mutex_unlock();
2163 if (handle
== D3D8_INVALID_HANDLE
)
2165 ERR("Failed to allocate pixel shader handle.\n");
2166 HeapFree(GetProcessHeap(), 0, object
);
2167 return E_OUTOFMEMORY
;
2170 shader_handle
= handle
+ VS_HIGHESTFIXEDFXF
+ 1;
2172 hr
= pixelshader_init(object
, This
, byte_code
, shader_handle
);
2175 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
2176 wined3d_mutex_lock();
2177 d3d8_free_handle(&This
->handle_table
, handle
, D3D8_HANDLE_PS
);
2178 wined3d_mutex_unlock();
2179 HeapFree(GetProcessHeap(), 0, object
);
2184 TRACE("Created pixel shader %p (handle %#x).\n", object
, shader_handle
);
2185 *shader
= shader_handle
;
2190 static HRESULT WINAPI
IDirect3DDevice8Impl_SetPixelShader(LPDIRECT3DDEVICE8 iface
, DWORD pShader
) {
2191 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2192 IDirect3DPixelShader8Impl
*shader
;
2195 TRACE("iface %p, shader %#x.\n", iface
, pShader
);
2197 wined3d_mutex_lock();
2201 hr
= IWineD3DDevice_SetPixelShader(This
->WineD3DDevice
, NULL
);
2202 wined3d_mutex_unlock();
2206 shader
= d3d8_get_object(&This
->handle_table
, pShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
);
2209 WARN("Invalid handle (%#x) passed.\n", pShader
);
2210 wined3d_mutex_unlock();
2211 return D3DERR_INVALIDCALL
;
2214 TRACE("(%p) : Setting shader %p\n", This
, shader
);
2215 hr
= IWineD3DDevice_SetPixelShader(This
->WineD3DDevice
, shader
->wineD3DPixelShader
);
2216 wined3d_mutex_unlock();
2221 static HRESULT WINAPI
IDirect3DDevice8Impl_GetPixelShader(LPDIRECT3DDEVICE8 iface
, DWORD
* ppShader
) {
2222 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2223 IWineD3DPixelShader
*object
;
2224 HRESULT hrc
= D3D_OK
;
2226 TRACE("iface %p, shader %p.\n", iface
, ppShader
);
2228 if (NULL
== ppShader
) {
2229 TRACE("(%p) Invalid call\n", This
);
2230 return D3DERR_INVALIDCALL
;
2233 wined3d_mutex_lock();
2234 hrc
= IWineD3DDevice_GetPixelShader(This
->WineD3DDevice
, &object
);
2235 if (D3D_OK
== hrc
&& NULL
!= object
) {
2236 IDirect3DPixelShader8Impl
*d3d8_shader
;
2237 hrc
= IWineD3DPixelShader_GetParent(object
, (IUnknown
**)&d3d8_shader
);
2238 IWineD3DPixelShader_Release(object
);
2239 *ppShader
= d3d8_shader
->handle
;
2240 IDirect3DPixelShader8_Release((IDirect3DPixelShader8
*)d3d8_shader
);
2244 wined3d_mutex_unlock();
2246 TRACE("(%p) : returning %#x\n", This
, *ppShader
);
2251 static HRESULT WINAPI
IDirect3DDevice8Impl_DeletePixelShader(LPDIRECT3DDEVICE8 iface
, DWORD pShader
) {
2252 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2253 IDirect3DPixelShader8Impl
*shader
;
2254 IWineD3DPixelShader
*cur
= NULL
;
2256 TRACE("iface %p, shader %#x.\n", iface
, pShader
);
2258 wined3d_mutex_lock();
2260 shader
= d3d8_free_handle(&This
->handle_table
, pShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
);
2263 WARN("Invalid handle (%#x) passed.\n", pShader
);
2264 wined3d_mutex_unlock();
2265 return D3DERR_INVALIDCALL
;
2268 IWineD3DDevice_GetPixelShader(This
->WineD3DDevice
, &cur
);
2272 if (cur
== shader
->wineD3DPixelShader
) IDirect3DDevice8_SetPixelShader(iface
, 0);
2273 IWineD3DPixelShader_Release(cur
);
2276 wined3d_mutex_unlock();
2278 if (IUnknown_Release((IUnknown
*)shader
))
2280 ERR("Shader %p has references left, this shouldn't happen.\n", shader
);
2286 static HRESULT WINAPI
IDirect3DDevice8Impl_SetPixelShaderConstant(LPDIRECT3DDEVICE8 iface
, DWORD Register
, CONST
void* pConstantData
, DWORD ConstantCount
) {
2287 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2290 TRACE("iface %p, register %u, data %p, count %u.\n",
2291 iface
, Register
, pConstantData
, ConstantCount
);
2293 wined3d_mutex_lock();
2294 hr
= IWineD3DDevice_SetPixelShaderConstantF(This
->WineD3DDevice
, Register
, pConstantData
, ConstantCount
);
2295 wined3d_mutex_unlock();
2300 static HRESULT WINAPI
IDirect3DDevice8Impl_GetPixelShaderConstant(LPDIRECT3DDEVICE8 iface
, DWORD Register
, void* pConstantData
, DWORD ConstantCount
) {
2301 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2304 TRACE("iface %p, register %u, data %p, count %u.\n",
2305 iface
, Register
, pConstantData
, ConstantCount
);
2307 wined3d_mutex_lock();
2308 hr
= IWineD3DDevice_GetPixelShaderConstantF(This
->WineD3DDevice
, Register
, pConstantData
, ConstantCount
);
2309 wined3d_mutex_unlock();
2314 static HRESULT WINAPI
IDirect3DDevice8Impl_GetPixelShaderFunction(LPDIRECT3DDEVICE8 iface
, DWORD pPixelShader
, void* pData
, DWORD
* pSizeOfData
) {
2315 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2316 IDirect3DPixelShader8Impl
*shader
= NULL
;
2319 TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
2320 iface
, pPixelShader
, pData
, pSizeOfData
);
2322 wined3d_mutex_lock();
2323 shader
= d3d8_get_object(&This
->handle_table
, pPixelShader
- (VS_HIGHESTFIXEDFXF
+ 1), D3D8_HANDLE_PS
);
2326 WARN("Invalid handle (%#x) passed.\n", pPixelShader
);
2327 wined3d_mutex_unlock();
2329 return D3DERR_INVALIDCALL
;
2332 hr
= IWineD3DPixelShader_GetFunction(shader
->wineD3DPixelShader
, pData
, pSizeOfData
);
2333 wined3d_mutex_unlock();
2338 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawRectPatch(LPDIRECT3DDEVICE8 iface
, UINT Handle
,CONST
float* pNumSegs
,CONST D3DRECTPATCH_INFO
* pRectPatchInfo
) {
2339 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2342 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2343 iface
, Handle
, pNumSegs
, pRectPatchInfo
);
2345 wined3d_mutex_lock();
2346 hr
= IWineD3DDevice_DrawRectPatch(This
->WineD3DDevice
, Handle
, pNumSegs
, (CONST WINED3DRECTPATCH_INFO
*)pRectPatchInfo
);
2347 wined3d_mutex_unlock();
2352 static HRESULT WINAPI
IDirect3DDevice8Impl_DrawTriPatch(LPDIRECT3DDEVICE8 iface
, UINT Handle
,CONST
float* pNumSegs
,CONST D3DTRIPATCH_INFO
* pTriPatchInfo
) {
2353 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2356 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2357 iface
, Handle
, pNumSegs
, pTriPatchInfo
);
2359 wined3d_mutex_lock();
2360 hr
= IWineD3DDevice_DrawTriPatch(This
->WineD3DDevice
, Handle
, pNumSegs
, (CONST WINED3DTRIPATCH_INFO
*)pTriPatchInfo
);
2361 wined3d_mutex_unlock();
2366 static HRESULT WINAPI
IDirect3DDevice8Impl_DeletePatch(LPDIRECT3DDEVICE8 iface
, UINT Handle
) {
2367 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2370 TRACE("iface %p, handle %#x.\n", iface
, Handle
);
2372 wined3d_mutex_lock();
2373 hr
= IWineD3DDevice_DeletePatch(This
->WineD3DDevice
, Handle
);
2374 wined3d_mutex_unlock();
2379 static HRESULT WINAPI
IDirect3DDevice8Impl_SetStreamSource(LPDIRECT3DDEVICE8 iface
, UINT StreamNumber
,IDirect3DVertexBuffer8
* pStreamData
,UINT Stride
) {
2380 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2383 TRACE("iface %p, stream_idx %u, buffer %p, stride %u.\n",
2384 iface
, StreamNumber
, pStreamData
, Stride
);
2386 wined3d_mutex_lock();
2387 hr
= IWineD3DDevice_SetStreamSource(This
->WineD3DDevice
, StreamNumber
,
2388 NULL
== pStreamData
? NULL
: ((IDirect3DVertexBuffer8Impl
*)pStreamData
)->wineD3DVertexBuffer
,
2389 0/* Offset in bytes */, Stride
);
2390 wined3d_mutex_unlock();
2395 static HRESULT WINAPI
IDirect3DDevice8Impl_GetStreamSource(LPDIRECT3DDEVICE8 iface
, UINT StreamNumber
,IDirect3DVertexBuffer8
** pStream
,UINT
* pStride
) {
2396 IDirect3DDevice8Impl
*This
= (IDirect3DDevice8Impl
*)iface
;
2397 IWineD3DBuffer
*retStream
= NULL
;
2398 HRESULT rc
= D3D_OK
;
2400 TRACE("iface %p, stream_idx %u, buffer %p, stride %p.\n",
2401 iface
, StreamNumber
, pStream
, pStride
);
2403 if(pStream
== NULL
){
2404 return D3DERR_INVALIDCALL
;
2407 wined3d_mutex_lock();
2408 rc
= IWineD3DDevice_GetStreamSource(This
->WineD3DDevice
, StreamNumber
, &retStream
, 0 /* Offset in bytes */, pStride
);
2409 if (rc
== D3D_OK
&& NULL
!= retStream
) {
2410 IWineD3DBuffer_GetParent(retStream
, (IUnknown
**)pStream
);
2411 IWineD3DBuffer_Release(retStream
);
2414 FIXME("Call to GetStreamSource failed %p\n", pStride
);
2418 wined3d_mutex_unlock();
2423 static const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl
=
2425 IDirect3DDevice8Impl_QueryInterface
,
2426 IDirect3DDevice8Impl_AddRef
,
2427 IDirect3DDevice8Impl_Release
,
2428 IDirect3DDevice8Impl_TestCooperativeLevel
,
2429 IDirect3DDevice8Impl_GetAvailableTextureMem
,
2430 IDirect3DDevice8Impl_ResourceManagerDiscardBytes
,
2431 IDirect3DDevice8Impl_GetDirect3D
,
2432 IDirect3DDevice8Impl_GetDeviceCaps
,
2433 IDirect3DDevice8Impl_GetDisplayMode
,
2434 IDirect3DDevice8Impl_GetCreationParameters
,
2435 IDirect3DDevice8Impl_SetCursorProperties
,
2436 IDirect3DDevice8Impl_SetCursorPosition
,
2437 IDirect3DDevice8Impl_ShowCursor
,
2438 IDirect3DDevice8Impl_CreateAdditionalSwapChain
,
2439 IDirect3DDevice8Impl_Reset
,
2440 IDirect3DDevice8Impl_Present
,
2441 IDirect3DDevice8Impl_GetBackBuffer
,
2442 IDirect3DDevice8Impl_GetRasterStatus
,
2443 IDirect3DDevice8Impl_SetGammaRamp
,
2444 IDirect3DDevice8Impl_GetGammaRamp
,
2445 IDirect3DDevice8Impl_CreateTexture
,
2446 IDirect3DDevice8Impl_CreateVolumeTexture
,
2447 IDirect3DDevice8Impl_CreateCubeTexture
,
2448 IDirect3DDevice8Impl_CreateVertexBuffer
,
2449 IDirect3DDevice8Impl_CreateIndexBuffer
,
2450 IDirect3DDevice8Impl_CreateRenderTarget
,
2451 IDirect3DDevice8Impl_CreateDepthStencilSurface
,
2452 IDirect3DDevice8Impl_CreateImageSurface
,
2453 IDirect3DDevice8Impl_CopyRects
,
2454 IDirect3DDevice8Impl_UpdateTexture
,
2455 IDirect3DDevice8Impl_GetFrontBuffer
,
2456 IDirect3DDevice8Impl_SetRenderTarget
,
2457 IDirect3DDevice8Impl_GetRenderTarget
,
2458 IDirect3DDevice8Impl_GetDepthStencilSurface
,
2459 IDirect3DDevice8Impl_BeginScene
,
2460 IDirect3DDevice8Impl_EndScene
,
2461 IDirect3DDevice8Impl_Clear
,
2462 IDirect3DDevice8Impl_SetTransform
,
2463 IDirect3DDevice8Impl_GetTransform
,
2464 IDirect3DDevice8Impl_MultiplyTransform
,
2465 IDirect3DDevice8Impl_SetViewport
,
2466 IDirect3DDevice8Impl_GetViewport
,
2467 IDirect3DDevice8Impl_SetMaterial
,
2468 IDirect3DDevice8Impl_GetMaterial
,
2469 IDirect3DDevice8Impl_SetLight
,
2470 IDirect3DDevice8Impl_GetLight
,
2471 IDirect3DDevice8Impl_LightEnable
,
2472 IDirect3DDevice8Impl_GetLightEnable
,
2473 IDirect3DDevice8Impl_SetClipPlane
,
2474 IDirect3DDevice8Impl_GetClipPlane
,
2475 IDirect3DDevice8Impl_SetRenderState
,
2476 IDirect3DDevice8Impl_GetRenderState
,
2477 IDirect3DDevice8Impl_BeginStateBlock
,
2478 IDirect3DDevice8Impl_EndStateBlock
,
2479 IDirect3DDevice8Impl_ApplyStateBlock
,
2480 IDirect3DDevice8Impl_CaptureStateBlock
,
2481 IDirect3DDevice8Impl_DeleteStateBlock
,
2482 IDirect3DDevice8Impl_CreateStateBlock
,
2483 IDirect3DDevice8Impl_SetClipStatus
,
2484 IDirect3DDevice8Impl_GetClipStatus
,
2485 IDirect3DDevice8Impl_GetTexture
,
2486 IDirect3DDevice8Impl_SetTexture
,
2487 IDirect3DDevice8Impl_GetTextureStageState
,
2488 IDirect3DDevice8Impl_SetTextureStageState
,
2489 IDirect3DDevice8Impl_ValidateDevice
,
2490 IDirect3DDevice8Impl_GetInfo
,
2491 IDirect3DDevice8Impl_SetPaletteEntries
,
2492 IDirect3DDevice8Impl_GetPaletteEntries
,
2493 IDirect3DDevice8Impl_SetCurrentTexturePalette
,
2494 IDirect3DDevice8Impl_GetCurrentTexturePalette
,
2495 IDirect3DDevice8Impl_DrawPrimitive
,
2496 IDirect3DDevice8Impl_DrawIndexedPrimitive
,
2497 IDirect3DDevice8Impl_DrawPrimitiveUP
,
2498 IDirect3DDevice8Impl_DrawIndexedPrimitiveUP
,
2499 IDirect3DDevice8Impl_ProcessVertices
,
2500 IDirect3DDevice8Impl_CreateVertexShader
,
2501 IDirect3DDevice8Impl_SetVertexShader
,
2502 IDirect3DDevice8Impl_GetVertexShader
,
2503 IDirect3DDevice8Impl_DeleteVertexShader
,
2504 IDirect3DDevice8Impl_SetVertexShaderConstant
,
2505 IDirect3DDevice8Impl_GetVertexShaderConstant
,
2506 IDirect3DDevice8Impl_GetVertexShaderDeclaration
,
2507 IDirect3DDevice8Impl_GetVertexShaderFunction
,
2508 IDirect3DDevice8Impl_SetStreamSource
,
2509 IDirect3DDevice8Impl_GetStreamSource
,
2510 IDirect3DDevice8Impl_SetIndices
,
2511 IDirect3DDevice8Impl_GetIndices
,
2512 IDirect3DDevice8Impl_CreatePixelShader
,
2513 IDirect3DDevice8Impl_SetPixelShader
,
2514 IDirect3DDevice8Impl_GetPixelShader
,
2515 IDirect3DDevice8Impl_DeletePixelShader
,
2516 IDirect3DDevice8Impl_SetPixelShaderConstant
,
2517 IDirect3DDevice8Impl_GetPixelShaderConstant
,
2518 IDirect3DDevice8Impl_GetPixelShaderFunction
,
2519 IDirect3DDevice8Impl_DrawRectPatch
,
2520 IDirect3DDevice8Impl_DrawTriPatch
,
2521 IDirect3DDevice8Impl_DeletePatch
2524 /* IWineD3DDeviceParent IUnknown methods */
2526 static inline struct IDirect3DDevice8Impl
*device_from_device_parent(IWineD3DDeviceParent
*iface
)
2528 return (struct IDirect3DDevice8Impl
*)((char*)iface
2529 - FIELD_OFFSET(struct IDirect3DDevice8Impl
, device_parent_vtbl
));
2532 static HRESULT STDMETHODCALLTYPE
device_parent_QueryInterface(IWineD3DDeviceParent
*iface
, REFIID riid
, void **object
)
2534 struct IDirect3DDevice8Impl
*This
= device_from_device_parent(iface
);
2535 return IDirect3DDevice8Impl_QueryInterface((IDirect3DDevice8
*)This
, riid
, object
);
2538 static ULONG STDMETHODCALLTYPE
device_parent_AddRef(IWineD3DDeviceParent
*iface
)
2540 struct IDirect3DDevice8Impl
*This
= device_from_device_parent(iface
);
2541 return IDirect3DDevice8Impl_AddRef((IDirect3DDevice8
*)This
);
2544 static ULONG STDMETHODCALLTYPE
device_parent_Release(IWineD3DDeviceParent
*iface
)
2546 struct IDirect3DDevice8Impl
*This
= device_from_device_parent(iface
);
2547 return IDirect3DDevice8Impl_Release((IDirect3DDevice8
*)This
);
2550 /* IWineD3DDeviceParent methods */
2552 static void STDMETHODCALLTYPE
device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent
*iface
, IWineD3DDevice
*device
)
2554 TRACE("iface %p, device %p\n", iface
, device
);
2557 static HRESULT STDMETHODCALLTYPE
device_parent_CreateSurface(IWineD3DDeviceParent
*iface
,
2558 IUnknown
*superior
, UINT width
, UINT height
, WINED3DFORMAT format
, DWORD usage
,
2559 WINED3DPOOL pool
, UINT level
, WINED3DCUBEMAP_FACES face
, IWineD3DSurface
**surface
)
2561 struct IDirect3DDevice8Impl
*This
= device_from_device_parent(iface
);
2562 IDirect3DSurface8Impl
*d3d_surface
;
2563 BOOL lockable
= TRUE
;
2566 TRACE("iface %p, superior %p, width %u, height %u, format %#x, usage %#x,\n"
2567 "\tpool %#x, level %u, face %u, surface %p\n",
2568 iface
, superior
, width
, height
, format
, usage
, pool
, level
, face
, surface
);
2571 if (pool
== WINED3DPOOL_DEFAULT
&& !(usage
& WINED3DUSAGE_DYNAMIC
)) lockable
= FALSE
;
2573 hr
= IDirect3DDevice8Impl_CreateSurface((IDirect3DDevice8
*)This
, width
, height
,
2574 d3dformat_from_wined3dformat(format
), lockable
, FALSE
/* Discard */, level
,
2575 (IDirect3DSurface8
**)&d3d_surface
, usage
, pool
, D3DMULTISAMPLE_NONE
, 0 /* MultisampleQuality */);
2578 ERR("(%p) CreateSurface failed, returning %#x\n", iface
, hr
);
2582 *surface
= d3d_surface
->wineD3DSurface
;
2583 IWineD3DSurface_AddRef(*surface
);
2585 d3d_surface
->container
= superior
;
2586 IUnknown_Release(d3d_surface
->parentDevice
);
2587 d3d_surface
->parentDevice
= NULL
;
2589 IDirect3DSurface8_Release((IDirect3DSurface8
*)d3d_surface
);
2590 d3d_surface
->forwardReference
= superior
;
2595 static HRESULT STDMETHODCALLTYPE
device_parent_CreateRenderTarget(IWineD3DDeviceParent
*iface
,
2596 IUnknown
*superior
, UINT width
, UINT height
, WINED3DFORMAT format
, WINED3DMULTISAMPLE_TYPE multisample_type
,
2597 DWORD multisample_quality
, BOOL lockable
, IWineD3DSurface
**surface
)
2599 struct IDirect3DDevice8Impl
*This
= device_from_device_parent(iface
);
2600 IDirect3DSurface8Impl
*d3d_surface
;
2603 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2604 "\tmultisample_quality %u, lockable %u, surface %p\n",
2605 iface
, superior
, width
, height
, format
, multisample_type
, multisample_quality
, lockable
, surface
);
2607 hr
= IDirect3DDevice8_CreateRenderTarget((IDirect3DDevice8
*)This
, width
, height
,
2608 d3dformat_from_wined3dformat(format
), multisample_type
, lockable
, (IDirect3DSurface8
**)&d3d_surface
);
2611 ERR("(%p) CreateRenderTarget failed, returning %#x\n", iface
, hr
);
2615 *surface
= d3d_surface
->wineD3DSurface
;
2616 IWineD3DSurface_AddRef(*surface
);
2618 d3d_surface
->container
= (IUnknown
*)This
;
2619 /* Implicit surfaces are created with an refcount of 0 */
2620 IUnknown_Release((IUnknown
*)d3d_surface
);
2625 static HRESULT STDMETHODCALLTYPE
device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent
*iface
,
2626 IUnknown
*superior
, UINT width
, UINT height
, WINED3DFORMAT format
, WINED3DMULTISAMPLE_TYPE multisample_type
,
2627 DWORD multisample_quality
, BOOL discard
, IWineD3DSurface
**surface
)
2629 struct IDirect3DDevice8Impl
*This
= device_from_device_parent(iface
);
2630 IDirect3DSurface8Impl
*d3d_surface
;
2633 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
2634 "\tmultisample_quality %u, discard %u, surface %p\n",
2635 iface
, superior
, width
, height
, format
, multisample_type
, multisample_quality
, discard
, surface
);
2637 hr
= IDirect3DDevice8_CreateDepthStencilSurface((IDirect3DDevice8
*)This
, width
, height
,
2638 d3dformat_from_wined3dformat(format
), multisample_type
, (IDirect3DSurface8
**)&d3d_surface
);
2641 ERR("(%p) CreateDepthStencilSurface failed, returning %#x\n", iface
, hr
);
2645 *surface
= d3d_surface
->wineD3DSurface
;
2646 IWineD3DSurface_AddRef(*surface
);
2648 d3d_surface
->container
= (IUnknown
*)This
;
2649 /* Implicit surfaces are created with an refcount of 0 */
2650 IUnknown_Release((IUnknown
*)d3d_surface
);
2655 static HRESULT STDMETHODCALLTYPE
device_parent_CreateVolume(IWineD3DDeviceParent
*iface
,
2656 IUnknown
*superior
, UINT width
, UINT height
, UINT depth
, WINED3DFORMAT format
,
2657 WINED3DPOOL pool
, DWORD usage
, IWineD3DVolume
**volume
)
2659 struct IDirect3DDevice8Impl
*This
= device_from_device_parent(iface
);
2660 IDirect3DVolume8Impl
*object
;
2663 TRACE("iface %p, superior %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
2664 iface
, superior
, width
, height
, depth
, format
, pool
, usage
, volume
);
2666 /* Allocate the storage for the device */
2667 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2670 FIXME("Allocation of memory failed\n");
2672 return D3DERR_OUTOFVIDEOMEMORY
;
2675 hr
= volume_init(object
, This
, width
, height
, depth
, usage
, format
, pool
);
2678 WARN("Failed to initialize volume, hr %#x.\n", hr
);
2679 HeapFree(GetProcessHeap(), 0, object
);
2683 *volume
= object
->wineD3DVolume
;
2684 IWineD3DVolume_AddRef(*volume
);
2685 IDirect3DVolume8_Release((IDirect3DVolume8
*)object
);
2687 object
->container
= superior
;
2688 object
->forwardReference
= superior
;
2690 TRACE("(%p) Created volume %p\n", iface
, object
);
2695 static HRESULT STDMETHODCALLTYPE
device_parent_CreateSwapChain(IWineD3DDeviceParent
*iface
,
2696 WINED3DPRESENT_PARAMETERS
*present_parameters
, IWineD3DSwapChain
**swapchain
)
2698 struct IDirect3DDevice8Impl
*This
= device_from_device_parent(iface
);
2699 IDirect3DSwapChain8Impl
*d3d_swapchain
;
2700 D3DPRESENT_PARAMETERS local_parameters
;
2703 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface
, present_parameters
, swapchain
);
2705 /* Copy the presentation parameters */
2706 local_parameters
.BackBufferWidth
= present_parameters
->BackBufferWidth
;
2707 local_parameters
.BackBufferHeight
= present_parameters
->BackBufferHeight
;
2708 local_parameters
.BackBufferFormat
= d3dformat_from_wined3dformat(present_parameters
->BackBufferFormat
);
2709 local_parameters
.BackBufferCount
= present_parameters
->BackBufferCount
;
2710 local_parameters
.MultiSampleType
= present_parameters
->MultiSampleType
;
2711 local_parameters
.SwapEffect
= present_parameters
->SwapEffect
;
2712 local_parameters
.hDeviceWindow
= present_parameters
->hDeviceWindow
;
2713 local_parameters
.Windowed
= present_parameters
->Windowed
;
2714 local_parameters
.EnableAutoDepthStencil
= present_parameters
->EnableAutoDepthStencil
;
2715 local_parameters
.AutoDepthStencilFormat
= d3dformat_from_wined3dformat(present_parameters
->AutoDepthStencilFormat
);
2716 local_parameters
.Flags
= present_parameters
->Flags
;
2717 local_parameters
.FullScreen_RefreshRateInHz
= present_parameters
->FullScreen_RefreshRateInHz
;
2718 local_parameters
.FullScreen_PresentationInterval
= present_parameters
->PresentationInterval
;
2720 hr
= IDirect3DDevice8_CreateAdditionalSwapChain((IDirect3DDevice8
*)This
,
2721 &local_parameters
, (IDirect3DSwapChain8
**)&d3d_swapchain
);
2724 ERR("(%p) CreateAdditionalSwapChain failed, returning %#x\n", iface
, hr
);
2729 *swapchain
= d3d_swapchain
->wineD3DSwapChain
;
2730 IUnknown_Release(d3d_swapchain
->parentDevice
);
2731 d3d_swapchain
->parentDevice
= NULL
;
2733 /* Copy back the presentation parameters */
2734 present_parameters
->BackBufferWidth
= local_parameters
.BackBufferWidth
;
2735 present_parameters
->BackBufferHeight
= local_parameters
.BackBufferHeight
;
2736 present_parameters
->BackBufferFormat
= wined3dformat_from_d3dformat(local_parameters
.BackBufferFormat
);
2737 present_parameters
->BackBufferCount
= local_parameters
.BackBufferCount
;
2738 present_parameters
->MultiSampleType
= local_parameters
.MultiSampleType
;
2739 present_parameters
->SwapEffect
= local_parameters
.SwapEffect
;
2740 present_parameters
->hDeviceWindow
= local_parameters
.hDeviceWindow
;
2741 present_parameters
->Windowed
= local_parameters
.Windowed
;
2742 present_parameters
->EnableAutoDepthStencil
= local_parameters
.EnableAutoDepthStencil
;
2743 present_parameters
->AutoDepthStencilFormat
= wined3dformat_from_d3dformat(local_parameters
.AutoDepthStencilFormat
);
2744 present_parameters
->Flags
= local_parameters
.Flags
;
2745 present_parameters
->FullScreen_RefreshRateInHz
= local_parameters
.FullScreen_RefreshRateInHz
;
2746 present_parameters
->PresentationInterval
= local_parameters
.FullScreen_PresentationInterval
;
2751 static const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl
=
2753 /* IUnknown methods */
2754 device_parent_QueryInterface
,
2755 device_parent_AddRef
,
2756 device_parent_Release
,
2757 /* IWineD3DDeviceParent methods */
2758 device_parent_WineD3DDeviceCreated
,
2759 device_parent_CreateSurface
,
2760 device_parent_CreateRenderTarget
,
2761 device_parent_CreateDepthStencilSurface
,
2762 device_parent_CreateVolume
,
2763 device_parent_CreateSwapChain
,
2766 HRESULT
device_init(IDirect3DDevice8Impl
*device
, IWineD3D
*wined3d
, UINT adapter
,
2767 D3DDEVTYPE device_type
, HWND focus_window
, DWORD flags
, D3DPRESENT_PARAMETERS
*parameters
)
2769 WINED3DPRESENT_PARAMETERS wined3d_parameters
;
2772 device
->lpVtbl
= &Direct3DDevice8_Vtbl
;
2773 device
->device_parent_vtbl
= &d3d8_wined3d_device_parent_vtbl
;
2775 device
->handle_table
.entries
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2776 D3D8_INITIAL_HANDLE_TABLE_SIZE
* sizeof(*device
->handle_table
.entries
));
2777 if (!device
->handle_table
.entries
)
2779 ERR("Failed to allocate handle table memory.\n");
2780 return E_OUTOFMEMORY
;
2782 device
->handle_table
.table_size
= D3D8_INITIAL_HANDLE_TABLE_SIZE
;
2784 wined3d_mutex_lock();
2785 hr
= IWineD3D_CreateDevice(wined3d
, adapter
, device_type
, focus_window
, flags
, (IUnknown
*)device
,
2786 (IWineD3DDeviceParent
*)&device
->device_parent_vtbl
, &device
->WineD3DDevice
);
2789 WARN("Failed to create wined3d device, hr %#x.\n", hr
);
2790 wined3d_mutex_unlock();
2791 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
2795 if (!parameters
->Windowed
)
2797 if (!focus_window
) focus_window
= parameters
->hDeviceWindow
;
2798 if (FAILED(hr
= IWineD3DDevice_AcquireFocusWindow(device
->WineD3DDevice
, focus_window
)))
2800 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
2801 IWineD3DDevice_Release(device
->WineD3DDevice
);
2802 wined3d_mutex_unlock();
2803 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
2808 if (flags
& D3DCREATE_MULTITHREADED
) IWineD3DDevice_SetMultithreaded(device
->WineD3DDevice
);
2810 wined3d_parameters
.BackBufferWidth
= parameters
->BackBufferWidth
;
2811 wined3d_parameters
.BackBufferHeight
= parameters
->BackBufferHeight
;
2812 wined3d_parameters
.BackBufferFormat
= wined3dformat_from_d3dformat(parameters
->BackBufferFormat
);
2813 wined3d_parameters
.BackBufferCount
= parameters
->BackBufferCount
;
2814 wined3d_parameters
.MultiSampleType
= parameters
->MultiSampleType
;
2815 wined3d_parameters
.MultiSampleQuality
= 0; /* d3d9 only */
2816 wined3d_parameters
.SwapEffect
= parameters
->SwapEffect
;
2817 wined3d_parameters
.hDeviceWindow
= parameters
->hDeviceWindow
;
2818 wined3d_parameters
.Windowed
= parameters
->Windowed
;
2819 wined3d_parameters
.EnableAutoDepthStencil
= parameters
->EnableAutoDepthStencil
;
2820 wined3d_parameters
.AutoDepthStencilFormat
= wined3dformat_from_d3dformat(parameters
->AutoDepthStencilFormat
);
2821 wined3d_parameters
.Flags
= parameters
->Flags
;
2822 wined3d_parameters
.FullScreen_RefreshRateInHz
= parameters
->FullScreen_RefreshRateInHz
;
2823 wined3d_parameters
.PresentationInterval
= parameters
->FullScreen_PresentationInterval
;
2824 wined3d_parameters
.AutoRestoreDisplayMode
= TRUE
;
2826 hr
= IWineD3DDevice_Init3D(device
->WineD3DDevice
, &wined3d_parameters
);
2829 WARN("Failed to initialize 3D, hr %#x.\n", hr
);
2830 IWineD3DDevice_ReleaseFocusWindow(device
->WineD3DDevice
);
2831 IWineD3DDevice_Release(device
->WineD3DDevice
);
2832 wined3d_mutex_unlock();
2833 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);
2837 hr
= IWineD3DDevice_SetRenderState(device
->WineD3DDevice
, WINED3DRS_POINTSIZE_MIN
, 0);
2838 wined3d_mutex_unlock();
2841 ERR("Failed to set minimum pointsize, hr %#x.\n", hr
);
2845 parameters
->BackBufferWidth
= wined3d_parameters
.BackBufferWidth
;
2846 parameters
->BackBufferHeight
= wined3d_parameters
.BackBufferHeight
;
2847 parameters
->BackBufferFormat
= d3dformat_from_wined3dformat(wined3d_parameters
.BackBufferFormat
);
2848 parameters
->BackBufferCount
= wined3d_parameters
.BackBufferCount
;
2849 parameters
->MultiSampleType
= wined3d_parameters
.MultiSampleType
;
2850 parameters
->SwapEffect
= wined3d_parameters
.SwapEffect
;
2851 parameters
->hDeviceWindow
= wined3d_parameters
.hDeviceWindow
;
2852 parameters
->Windowed
= wined3d_parameters
.Windowed
;
2853 parameters
->EnableAutoDepthStencil
= wined3d_parameters
.EnableAutoDepthStencil
;
2854 parameters
->AutoDepthStencilFormat
= d3dformat_from_wined3dformat(wined3d_parameters
.AutoDepthStencilFormat
);
2855 parameters
->Flags
= wined3d_parameters
.Flags
;
2856 parameters
->FullScreen_RefreshRateInHz
= wined3d_parameters
.FullScreen_RefreshRateInHz
;
2857 parameters
->FullScreen_PresentationInterval
= wined3d_parameters
.PresentationInterval
;
2859 device
->declArraySize
= 16;
2860 device
->decls
= HeapAlloc(GetProcessHeap(), 0, device
->declArraySize
* sizeof(*device
->decls
));
2863 ERR("Failed to allocate FVF vertex delcaration map memory.\n");
2871 wined3d_mutex_lock();
2872 IWineD3DDevice_Uninit3D(device
->WineD3DDevice
, D3D8CB_DestroySwapChain
);
2873 IWineD3DDevice_ReleaseFocusWindow(device
->WineD3DDevice
);
2874 IWineD3DDevice_Release(device
->WineD3DDevice
);
2875 wined3d_mutex_unlock();
2876 HeapFree(GetProcessHeap(), 0, device
->handle_table
.entries
);