2 * Copyright (c) 1998-2004 Lionel Ulmer
3 * Copyright (c) 2002-2005 Christian Costa
4 * Copyright (c) 2006-2009, 2011-2013 Stefan Dösinger
5 * Copyright (c) 2008 Alexander Dorofeyev
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
21 * IDirect3DDevice implementation, version 1, 2, 3 and 7. Rendering is relayed
22 * to WineD3D, some minimal DirectDraw specific management is handled here.
23 * The Direct3DDevice is NOT the parent of the WineD3DDevice, because d3d
24 * is initialized when DirectDraw creates the primary surface.
25 * Some type management is necessary, because some D3D types changed between
30 #include "ddraw_private.h"
32 WINE_DECLARE_DEBUG_CHANNEL(winediag
);
35 const GUID IID_D3DDEVICE_WineD3D
= {
39 { 0xb7,0x98,0xc6,0x8a,0x77,0x2d,0x72,0x2a }
42 static inline void set_fpu_control_word(WORD fpucw
)
44 #if defined(__i386__) && defined(__GNUC__)
45 __asm__
volatile ("fldcw %0" : : "m" (fpucw
));
46 #elif defined(__i386__) && defined(_MSC_VER)
51 static inline WORD
d3d_fpu_setup(void)
55 #if defined(__i386__) && defined(__GNUC__)
56 __asm__
volatile ("fnstcw %0" : "=m" (oldcw
));
57 #elif defined(__i386__) && defined(_MSC_VER)
60 static BOOL warned
= FALSE
;
63 FIXME("FPUPRESERVE not implemented for this platform / compiler\n");
69 set_fpu_control_word(0x37f);
74 static inline struct d3d_device
*impl_from_IUnknown(IUnknown
*iface
)
76 return CONTAINING_RECORD(iface
, struct d3d_device
, IUnknown_inner
);
79 static HRESULT WINAPI
d3d_device_inner_QueryInterface(IUnknown
*iface
, REFIID riid
, void **out
)
81 struct d3d_device
*device
= impl_from_IUnknown(iface
);
83 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
88 return DDERR_INVALIDPARAMS
;
91 if (IsEqualGUID(&IID_IUnknown
, riid
))
93 IDirect3DDevice7_AddRef(&device
->IDirect3DDevice7_iface
);
94 *out
= &device
->IDirect3DDevice7_iface
;
98 if (device
->version
== 7)
100 if (IsEqualGUID(&IID_IDirect3DDevice7
, riid
))
102 IDirect3DDevice7_AddRef(&device
->IDirect3DDevice7_iface
);
103 *out
= &device
->IDirect3DDevice7_iface
;
109 if (IsEqualGUID(&IID_IDirect3DDevice3
, riid
) && device
->version
== 3)
111 IDirect3DDevice3_AddRef(&device
->IDirect3DDevice3_iface
);
112 *out
= &device
->IDirect3DDevice3_iface
;
116 if (IsEqualGUID(&IID_IDirect3DDevice2
, riid
) && device
->version
>= 2)
118 IDirect3DDevice2_AddRef(&device
->IDirect3DDevice2_iface
);
119 *out
= &device
->IDirect3DDevice2_iface
;
123 if (IsEqualGUID(&IID_IDirect3DDevice
, riid
))
125 IDirect3DDevice_AddRef(&device
->IDirect3DDevice_iface
);
126 *out
= &device
->IDirect3DDevice_iface
;
131 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
134 return E_NOINTERFACE
;
137 static HRESULT WINAPI
d3d_device7_QueryInterface(IDirect3DDevice7
*iface
, REFIID riid
, void **out
)
139 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
141 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
143 return IUnknown_QueryInterface(device
->outer_unknown
, riid
, out
);
146 static HRESULT WINAPI
d3d_device3_QueryInterface(IDirect3DDevice3
*iface
, REFIID riid
, void **out
)
148 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
150 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
152 return IUnknown_QueryInterface(device
->outer_unknown
, riid
, out
);
155 static HRESULT WINAPI
d3d_device2_QueryInterface(IDirect3DDevice2
*iface
, REFIID riid
, void **out
)
157 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
159 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
161 return IUnknown_QueryInterface(device
->outer_unknown
, riid
, out
);
164 static HRESULT WINAPI
d3d_device1_QueryInterface(IDirect3DDevice
*iface
, REFIID riid
, void **out
)
166 struct d3d_device
*device
= impl_from_IDirect3DDevice(iface
);
168 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
170 return IUnknown_QueryInterface(device
->outer_unknown
, riid
, out
);
173 static ULONG WINAPI
d3d_device_inner_AddRef(IUnknown
*iface
)
175 struct d3d_device
*device
= impl_from_IUnknown(iface
);
176 ULONG ref
= InterlockedIncrement(&device
->ref
);
178 TRACE("%p increasing refcount to %u.\n", device
, ref
);
183 static ULONG WINAPI
d3d_device7_AddRef(IDirect3DDevice7
*iface
)
185 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
187 TRACE("iface %p.\n", iface
);
189 return IUnknown_AddRef(device
->outer_unknown
);
192 static ULONG WINAPI
d3d_device3_AddRef(IDirect3DDevice3
*iface
)
194 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
196 TRACE("iface %p.\n", iface
);
198 return IUnknown_AddRef(device
->outer_unknown
);
201 static ULONG WINAPI
d3d_device2_AddRef(IDirect3DDevice2
*iface
)
203 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
205 TRACE("iface %p.\n", iface
);
207 return IUnknown_AddRef(device
->outer_unknown
);
210 static ULONG WINAPI
d3d_device1_AddRef(IDirect3DDevice
*iface
)
212 struct d3d_device
*device
= impl_from_IDirect3DDevice(iface
);
214 TRACE("iface %p.\n", iface
);
216 return IUnknown_AddRef(device
->outer_unknown
);
219 static ULONG WINAPI
d3d_device_inner_Release(IUnknown
*iface
)
221 struct d3d_device
*This
= impl_from_IUnknown(iface
);
222 ULONG ref
= InterlockedDecrement(&This
->ref
);
225 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
227 /* This method doesn't destroy the wined3d device, because it's still in
228 * use for 2D rendering. IDirectDrawSurface7::Release will destroy the
229 * wined3d device when the render target is released. */
233 struct list
*vp_entry
, *vp_entry2
;
235 wined3d_mutex_lock();
237 /* There is no need to unset any resources here, wined3d will take
238 * care of that on uninit_3d(). */
240 if (This
->index_buffer
)
241 wined3d_buffer_decref(This
->index_buffer
);
242 if (This
->vertex_buffer
)
243 wined3d_buffer_decref(This
->vertex_buffer
);
245 wined3d_device_set_render_target(This
->wined3d_device
, 0, NULL
, FALSE
);
247 /* Release the wined3d device. This won't destroy it. */
248 if (!wined3d_device_decref(This
->wined3d_device
))
249 ERR("The wined3d device (%p) was destroyed unexpectedly.\n", This
->wined3d_device
);
251 /* The texture handles should be unset by now, but there might be some bits
252 * missing in our reference counting(needs test). Do a sanity check. */
253 for (i
= 0; i
< This
->handle_table
.entry_count
; ++i
)
255 struct ddraw_handle_entry
*entry
= &This
->handle_table
.entries
[i
];
259 case DDRAW_HANDLE_FREE
:
262 case DDRAW_HANDLE_MATERIAL
:
264 struct d3d_material
*m
= entry
->object
;
265 FIXME("Material handle %#x (%p) not unset properly.\n", i
+ 1, m
);
270 case DDRAW_HANDLE_MATRIX
:
272 /* No FIXME here because this might happen because of sloppy applications. */
273 WARN("Leftover matrix handle %#x (%p), deleting.\n", i
+ 1, entry
->object
);
274 IDirect3DDevice_DeleteMatrix(&This
->IDirect3DDevice_iface
, i
+ 1);
278 case DDRAW_HANDLE_STATEBLOCK
:
280 /* No FIXME here because this might happen because of sloppy applications. */
281 WARN("Leftover stateblock handle %#x (%p), deleting.\n", i
+ 1, entry
->object
);
282 IDirect3DDevice7_DeleteStateBlock(&This
->IDirect3DDevice7_iface
, i
+ 1);
286 case DDRAW_HANDLE_SURFACE
:
288 struct ddraw_surface
*surf
= entry
->object
;
289 FIXME("Texture handle %#x (%p) not unset properly.\n", i
+ 1, surf
);
295 FIXME("Handle %#x (%p) has unknown type %#x.\n", i
+ 1, entry
->object
, entry
->type
);
300 ddraw_handle_table_destroy(&This
->handle_table
);
302 LIST_FOR_EACH_SAFE(vp_entry
, vp_entry2
, &This
->viewport_list
)
304 struct d3d_viewport
*vp
= LIST_ENTRY(vp_entry
, struct d3d_viewport
, entry
);
305 IDirect3DDevice3_DeleteViewport(&This
->IDirect3DDevice3_iface
, &vp
->IDirect3DViewport3_iface
);
308 TRACE("Releasing render target %p.\n", This
->rt_iface
);
309 rt_iface
= This
->rt_iface
;
310 This
->rt_iface
= NULL
;
311 if (This
->version
!= 1)
312 IUnknown_Release(rt_iface
);
313 TRACE("Render target release done.\n");
315 This
->ddraw
->d3ddevice
= NULL
;
317 /* Now free the structure */
318 HeapFree(GetProcessHeap(), 0, This
);
319 wined3d_mutex_unlock();
326 static ULONG WINAPI
d3d_device7_Release(IDirect3DDevice7
*iface
)
328 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
330 TRACE("iface %p.\n", iface
);
332 return IUnknown_Release(device
->outer_unknown
);
335 static ULONG WINAPI
d3d_device3_Release(IDirect3DDevice3
*iface
)
337 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
339 TRACE("iface %p.\n", iface
);
341 return IUnknown_Release(device
->outer_unknown
);
344 static ULONG WINAPI
d3d_device2_Release(IDirect3DDevice2
*iface
)
346 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
348 TRACE("iface %p.\n", iface
);
350 return IUnknown_Release(device
->outer_unknown
);
353 static ULONG WINAPI
d3d_device1_Release(IDirect3DDevice
*iface
)
355 struct d3d_device
*device
= impl_from_IDirect3DDevice(iface
);
357 TRACE("iface %p.\n", iface
);
359 return IUnknown_Release(device
->outer_unknown
);
362 /*****************************************************************************
363 * IDirect3DDevice Methods
364 *****************************************************************************/
366 /*****************************************************************************
367 * IDirect3DDevice::Initialize
369 * Initializes a Direct3DDevice. This implementation is a no-op, as all
370 * initialization is done at create time.
372 * Exists in Version 1
375 * No idea what they mean, as the MSDN page is gone
379 *****************************************************************************/
380 static HRESULT WINAPI
d3d_device1_Initialize(IDirect3DDevice
*iface
,
381 IDirect3D
*d3d
, GUID
*guid
, D3DDEVICEDESC
*device_desc
)
383 /* It shouldn't be crucial, but print a FIXME, I'm interested if
384 * any game calls it and when. */
385 FIXME("iface %p, d3d %p, guid %s, device_desc %p nop!\n",
386 iface
, d3d
, debugstr_guid(guid
), device_desc
);
391 static HRESULT
d3d_device7_GetCaps(IDirect3DDevice7
*iface
, D3DDEVICEDESC7
*device_desc
)
393 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
395 TRACE("iface %p, device_desc %p.\n", iface
, device_desc
);
399 WARN("device_desc is NULL, returning DDERR_INVALIDPARAMS.\n");
400 return DDERR_INVALIDPARAMS
;
403 /* Call the same function used by IDirect3D, this saves code */
404 return ddraw_get_d3dcaps(device
->ddraw
, device_desc
);
407 static HRESULT WINAPI
d3d_device7_GetCaps_FPUSetup(IDirect3DDevice7
*iface
, D3DDEVICEDESC7
*desc
)
409 return d3d_device7_GetCaps(iface
, desc
);
412 static HRESULT WINAPI
d3d_device7_GetCaps_FPUPreserve(IDirect3DDevice7
*iface
, D3DDEVICEDESC7
*desc
)
417 old_fpucw
= d3d_fpu_setup();
418 hr
= d3d_device7_GetCaps(iface
, desc
);
419 set_fpu_control_word(old_fpucw
);
423 /*****************************************************************************
424 * IDirect3DDevice3::GetCaps
426 * Retrieves the capabilities of the hardware device and the emulation
427 * device. For Wine, hardware and emulation are the same (it's all HW).
429 * This implementation is used for Version 1, 2, and 3. Version 7 has its own
432 * HWDesc: Structure to fill with the HW caps
433 * HelDesc: Structure to fill with the hardware emulation caps
437 * D3DERR_* if a problem occurs. See WineD3D
439 *****************************************************************************/
441 /* There are 3 versions of D3DDEVICEDESC. All 3 share the same name because
442 * Microsoft just expanded the existing structure without naming them
443 * D3DDEVICEDESC2 and D3DDEVICEDESC3. Which version is used have depends
444 * on the version of the DirectX SDK. DirectX 6+ and Wine use the latest
445 * one with 252 bytes.
447 * All 3 versions are allowed as parameters and only the specified amount of
450 * Note that Direct3D7 and earlier are not available in native Win64
451 * ddraw.dll builds, so possible size differences between 32 bit and
452 * 64 bit are a non-issue.
454 static inline BOOL
check_d3ddevicedesc_size(DWORD size
)
456 if (size
== FIELD_OFFSET(D3DDEVICEDESC
, dwMinTextureWidth
) /* 172 */
457 || size
== FIELD_OFFSET(D3DDEVICEDESC
, dwMaxTextureRepeat
) /* 204 */
458 || size
== sizeof(D3DDEVICEDESC
) /* 252 */) return TRUE
;
462 static HRESULT WINAPI
d3d_device3_GetCaps(IDirect3DDevice3
*iface
,
463 D3DDEVICEDESC
*HWDesc
, D3DDEVICEDESC
*HelDesc
)
465 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
466 D3DDEVICEDESC7 desc7
;
470 TRACE("iface %p, hw_desc %p, hel_desc %p.\n", iface
, HWDesc
, HelDesc
);
474 WARN("HWDesc is NULL, returning DDERR_INVALIDPARAMS.\n");
475 return DDERR_INVALIDPARAMS
;
477 if (!check_d3ddevicedesc_size(HWDesc
->dwSize
))
479 WARN("HWDesc->dwSize is %u, returning DDERR_INVALIDPARAMS.\n", HWDesc
->dwSize
);
480 return DDERR_INVALIDPARAMS
;
484 WARN("HelDesc is NULL, returning DDERR_INVALIDPARAMS.\n");
485 return DDERR_INVALIDPARAMS
;
487 if (!check_d3ddevicedesc_size(HelDesc
->dwSize
))
489 WARN("HelDesc->dwSize is %u, returning DDERR_INVALIDPARAMS.\n", HelDesc
->dwSize
);
490 return DDERR_INVALIDPARAMS
;
493 if (FAILED(hr
= ddraw_get_d3dcaps(device
->ddraw
, &desc7
)))
496 ddraw_d3dcaps1_from_7(&desc1
, &desc7
);
497 DD_STRUCT_COPY_BYSIZE(HWDesc
, &desc1
);
498 DD_STRUCT_COPY_BYSIZE(HelDesc
, &desc1
);
502 static HRESULT WINAPI
d3d_device2_GetCaps(IDirect3DDevice2
*iface
,
503 D3DDEVICEDESC
*hw_desc
, D3DDEVICEDESC
*hel_desc
)
505 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
507 TRACE("iface %p, hw_desc %p, hel_desc %p.\n", iface
, hw_desc
, hel_desc
);
509 return d3d_device3_GetCaps(&device
->IDirect3DDevice3_iface
, hw_desc
, hel_desc
);
512 static HRESULT WINAPI
d3d_device1_GetCaps(IDirect3DDevice
*iface
,
513 D3DDEVICEDESC
*hw_desc
, D3DDEVICEDESC
*hel_desc
)
515 struct d3d_device
*device
= impl_from_IDirect3DDevice(iface
);
517 TRACE("iface %p, hw_desc %p, hel_desc %p.\n", iface
, hw_desc
, hel_desc
);
519 return d3d_device3_GetCaps(&device
->IDirect3DDevice3_iface
, hw_desc
, hel_desc
);
522 /*****************************************************************************
523 * IDirect3DDevice2::SwapTextureHandles
525 * Swaps the texture handles of 2 Texture interfaces. Version 1 and 2
528 * Tex1, Tex2: The 2 Textures to swap
533 *****************************************************************************/
534 static HRESULT WINAPI
d3d_device2_SwapTextureHandles(IDirect3DDevice2
*iface
,
535 IDirect3DTexture2
*tex1
, IDirect3DTexture2
*tex2
)
537 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
538 struct ddraw_surface
*surf1
= unsafe_impl_from_IDirect3DTexture2(tex1
);
539 struct ddraw_surface
*surf2
= unsafe_impl_from_IDirect3DTexture2(tex2
);
542 TRACE("iface %p, tex1 %p, tex2 %p.\n", iface
, tex1
, tex2
);
544 wined3d_mutex_lock();
546 h1
= surf1
->Handle
- 1;
547 h2
= surf2
->Handle
- 1;
548 device
->handle_table
.entries
[h1
].object
= surf2
;
549 device
->handle_table
.entries
[h2
].object
= surf1
;
550 surf2
->Handle
= h1
+ 1;
551 surf1
->Handle
= h2
+ 1;
553 wined3d_mutex_unlock();
558 static HRESULT WINAPI
d3d_device1_SwapTextureHandles(IDirect3DDevice
*iface
,
559 IDirect3DTexture
*tex1
, IDirect3DTexture
*tex2
)
561 struct d3d_device
*device
= impl_from_IDirect3DDevice(iface
);
562 struct ddraw_surface
*surf1
= unsafe_impl_from_IDirect3DTexture(tex1
);
563 struct ddraw_surface
*surf2
= unsafe_impl_from_IDirect3DTexture(tex2
);
564 IDirect3DTexture2
*t1
= surf1
? &surf1
->IDirect3DTexture2_iface
: NULL
;
565 IDirect3DTexture2
*t2
= surf2
? &surf2
->IDirect3DTexture2_iface
: NULL
;
567 TRACE("iface %p, tex1 %p, tex2 %p.\n", iface
, tex1
, tex2
);
569 return d3d_device2_SwapTextureHandles(&device
->IDirect3DDevice2_iface
, t1
, t2
);
572 /*****************************************************************************
573 * IDirect3DDevice3::GetStats
575 * This method seems to retrieve some stats from the device.
576 * The MSDN documentation doesn't exist any more, but the D3DSTATS
577 * structure suggests that the amount of drawn primitives and processed
578 * vertices is returned.
580 * Exists in Version 1, 2 and 3
583 * Stats: Pointer to a D3DSTATS structure to be filled
587 * DDERR_INVALIDPARAMS if Stats == NULL
589 *****************************************************************************/
590 static HRESULT WINAPI
d3d_device3_GetStats(IDirect3DDevice3
*iface
, D3DSTATS
*Stats
)
592 FIXME("iface %p, stats %p stub!\n", iface
, Stats
);
595 return DDERR_INVALIDPARAMS
;
597 /* Fill the Stats with 0 */
598 Stats
->dwTrianglesDrawn
= 0;
599 Stats
->dwLinesDrawn
= 0;
600 Stats
->dwPointsDrawn
= 0;
601 Stats
->dwSpansDrawn
= 0;
602 Stats
->dwVerticesProcessed
= 0;
607 static HRESULT WINAPI
d3d_device2_GetStats(IDirect3DDevice2
*iface
, D3DSTATS
*stats
)
609 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
611 TRACE("iface %p, stats %p.\n", iface
, stats
);
613 return d3d_device3_GetStats(&device
->IDirect3DDevice3_iface
, stats
);
616 static HRESULT WINAPI
d3d_device1_GetStats(IDirect3DDevice
*iface
, D3DSTATS
*stats
)
618 struct d3d_device
*device
= impl_from_IDirect3DDevice(iface
);
620 TRACE("iface %p, stats %p.\n", iface
, stats
);
622 return d3d_device3_GetStats(&device
->IDirect3DDevice3_iface
, stats
);
625 /*****************************************************************************
626 * IDirect3DDevice::CreateExecuteBuffer
628 * Creates an IDirect3DExecuteBuffer, used for rendering with a
634 * Desc: Buffer description
635 * ExecuteBuffer: Address to return the Interface pointer at
636 * UnkOuter: Must be NULL. Basically for aggregation, which ddraw doesn't
640 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
641 * DDERR_OUTOFMEMORY if we ran out of memory
644 *****************************************************************************/
645 static HRESULT WINAPI
d3d_device1_CreateExecuteBuffer(IDirect3DDevice
*iface
,
646 D3DEXECUTEBUFFERDESC
*buffer_desc
, IDirect3DExecuteBuffer
**ExecuteBuffer
, IUnknown
*outer_unknown
)
648 struct d3d_device
*device
= impl_from_IDirect3DDevice(iface
);
649 struct d3d_execute_buffer
*object
;
652 TRACE("iface %p, buffer_desc %p, buffer %p, outer_unknown %p.\n",
653 iface
, buffer_desc
, ExecuteBuffer
, outer_unknown
);
656 return CLASS_E_NOAGGREGATION
;
658 /* Allocate the new Execute Buffer */
659 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
662 ERR("Failed to allocate execute buffer memory.\n");
663 return DDERR_OUTOFMEMORY
;
666 hr
= d3d_execute_buffer_init(object
, device
, buffer_desc
);
669 WARN("Failed to initialize execute buffer, hr %#x.\n", hr
);
670 HeapFree(GetProcessHeap(), 0, object
);
674 *ExecuteBuffer
= &object
->IDirect3DExecuteBuffer_iface
;
676 TRACE(" Returning IDirect3DExecuteBuffer at %p, implementation is at %p\n", *ExecuteBuffer
, object
);
681 /*****************************************************************************
682 * IDirect3DDevice::Execute
684 * Executes all the stuff in an execute buffer.
687 * ExecuteBuffer: The buffer to execute
688 * Viewport: The viewport used for rendering
692 * DDERR_INVALIDPARAMS if ExecuteBuffer == NULL
695 *****************************************************************************/
696 static HRESULT WINAPI
d3d_device1_Execute(IDirect3DDevice
*iface
,
697 IDirect3DExecuteBuffer
*ExecuteBuffer
, IDirect3DViewport
*viewport
, DWORD flags
)
699 struct d3d_device
*device
= impl_from_IDirect3DDevice(iface
);
700 struct d3d_execute_buffer
*buffer
= unsafe_impl_from_IDirect3DExecuteBuffer(ExecuteBuffer
);
701 struct d3d_viewport
*viewport_impl
= unsafe_impl_from_IDirect3DViewport(viewport
);
704 TRACE("iface %p, buffer %p, viewport %p, flags %#x.\n", iface
, ExecuteBuffer
, viewport
, flags
);
707 return DDERR_INVALIDPARAMS
;
710 wined3d_mutex_lock();
711 hr
= d3d_execute_buffer_execute(buffer
, device
, viewport_impl
);
712 wined3d_mutex_unlock();
717 /*****************************************************************************
718 * IDirect3DDevice3::AddViewport
720 * Add a Direct3DViewport to the device's viewport list. These viewports
721 * are wrapped to IDirect3DDevice7 viewports in viewport.c
723 * Exists in Version 1, 2 and 3. Note that IDirect3DViewport 1, 2 and 3
724 * are the same interfaces.
727 * Viewport: The viewport to add
730 * DDERR_INVALIDPARAMS if Viewport == NULL
733 *****************************************************************************/
734 static HRESULT WINAPI
d3d_device3_AddViewport(IDirect3DDevice3
*iface
, IDirect3DViewport3
*viewport
)
736 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
737 struct d3d_viewport
*vp
= unsafe_impl_from_IDirect3DViewport3(viewport
);
739 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
743 return DDERR_INVALIDPARAMS
;
745 wined3d_mutex_lock();
746 IDirect3DViewport3_AddRef(viewport
);
747 list_add_head(&device
->viewport_list
, &vp
->entry
);
748 /* Viewport must be usable for Clear() after AddViewport, so set active_device here. */
749 vp
->active_device
= device
;
750 wined3d_mutex_unlock();
755 static HRESULT WINAPI
d3d_device2_AddViewport(IDirect3DDevice2
*iface
,
756 IDirect3DViewport2
*viewport
)
758 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
759 struct d3d_viewport
*vp
= unsafe_impl_from_IDirect3DViewport2(viewport
);
761 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
763 return d3d_device3_AddViewport(&device
->IDirect3DDevice3_iface
, &vp
->IDirect3DViewport3_iface
);
766 static HRESULT WINAPI
d3d_device1_AddViewport(IDirect3DDevice
*iface
, IDirect3DViewport
*viewport
)
768 struct d3d_device
*device
= impl_from_IDirect3DDevice(iface
);
769 struct d3d_viewport
*vp
= unsafe_impl_from_IDirect3DViewport(viewport
);
771 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
773 return d3d_device3_AddViewport(&device
->IDirect3DDevice3_iface
, &vp
->IDirect3DViewport3_iface
);
776 /*****************************************************************************
777 * IDirect3DDevice3::DeleteViewport
779 * Deletes a Direct3DViewport from the device's viewport list.
781 * Exists in Version 1, 2 and 3. Note that all Viewport interface versions
785 * Viewport: The viewport to delete
789 * DDERR_INVALIDPARAMS if the viewport wasn't found in the list
791 *****************************************************************************/
792 static HRESULT WINAPI
d3d_device3_DeleteViewport(IDirect3DDevice3
*iface
, IDirect3DViewport3
*viewport
)
794 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
795 struct d3d_viewport
*vp
= unsafe_impl_from_IDirect3DViewport3(viewport
);
797 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
801 WARN("NULL viewport, returning DDERR_INVALIDPARAMS\n");
802 return DDERR_INVALIDPARAMS
;
805 wined3d_mutex_lock();
807 if (vp
->active_device
!= device
)
809 WARN("Viewport %p active device is %p.\n", vp
, vp
->active_device
);
810 wined3d_mutex_unlock();
811 return DDERR_INVALIDPARAMS
;
814 if (device
->current_viewport
== vp
)
816 TRACE("Deleting current viewport, unsetting and releasing\n");
817 IDirect3DViewport3_Release(viewport
);
818 device
->current_viewport
= NULL
;
821 vp
->active_device
= NULL
;
822 list_remove(&vp
->entry
);
824 IDirect3DViewport3_Release(viewport
);
826 wined3d_mutex_unlock();
831 static HRESULT WINAPI
d3d_device2_DeleteViewport(IDirect3DDevice2
*iface
, IDirect3DViewport2
*viewport
)
833 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
834 struct d3d_viewport
*vp
= unsafe_impl_from_IDirect3DViewport2(viewport
);
836 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
838 return d3d_device3_DeleteViewport(&device
->IDirect3DDevice3_iface
,
839 vp
? &vp
->IDirect3DViewport3_iface
: NULL
);
842 static HRESULT WINAPI
d3d_device1_DeleteViewport(IDirect3DDevice
*iface
, IDirect3DViewport
*viewport
)
844 struct d3d_device
*device
= impl_from_IDirect3DDevice(iface
);
845 struct d3d_viewport
*vp
= unsafe_impl_from_IDirect3DViewport(viewport
);
847 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
849 return d3d_device3_DeleteViewport(&device
->IDirect3DDevice3_iface
,
850 vp
? &vp
->IDirect3DViewport3_iface
: NULL
);
853 /*****************************************************************************
854 * IDirect3DDevice3::NextViewport
856 * Returns a viewport from the viewport list, depending on the
857 * passed viewport and the flags.
859 * Exists in Version 1, 2 and 3. Note that all Viewport interface versions
863 * Viewport: Viewport to use for beginning the search
864 * Flags: D3DNEXT_NEXT, D3DNEXT_HEAD or D3DNEXT_TAIL
868 * DDERR_INVALIDPARAMS if the flags were wrong, or Viewport was NULL
870 *****************************************************************************/
871 static HRESULT WINAPI
d3d_device3_NextViewport(IDirect3DDevice3
*iface
,
872 IDirect3DViewport3
*Viewport3
, IDirect3DViewport3
**lplpDirect3DViewport3
, DWORD flags
)
874 struct d3d_device
*This
= impl_from_IDirect3DDevice3(iface
);
875 struct d3d_viewport
*vp
= unsafe_impl_from_IDirect3DViewport3(Viewport3
);
876 struct d3d_viewport
*next
;
879 TRACE("iface %p, viewport %p, next %p, flags %#x.\n",
880 iface
, Viewport3
, lplpDirect3DViewport3
, flags
);
884 *lplpDirect3DViewport3
= NULL
;
885 return DDERR_INVALIDPARAMS
;
889 wined3d_mutex_lock();
893 entry
= list_next(&This
->viewport_list
, &vp
->entry
);
897 entry
= list_head(&This
->viewport_list
);
901 entry
= list_tail(&This
->viewport_list
);
905 WARN("Invalid flags %#x.\n", flags
);
906 *lplpDirect3DViewport3
= NULL
;
907 wined3d_mutex_unlock();
908 return DDERR_INVALIDPARAMS
;
913 next
= LIST_ENTRY(entry
, struct d3d_viewport
, entry
);
914 *lplpDirect3DViewport3
= &next
->IDirect3DViewport3_iface
;
917 *lplpDirect3DViewport3
= NULL
;
919 wined3d_mutex_unlock();
924 static HRESULT WINAPI
d3d_device2_NextViewport(IDirect3DDevice2
*iface
,
925 IDirect3DViewport2
*viewport
, IDirect3DViewport2
**next
, DWORD flags
)
927 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
928 struct d3d_viewport
*vp
= unsafe_impl_from_IDirect3DViewport2(viewport
);
929 IDirect3DViewport3
*res
;
932 TRACE("iface %p, viewport %p, next %p, flags %#x.\n",
933 iface
, viewport
, next
, flags
);
935 hr
= d3d_device3_NextViewport(&device
->IDirect3DDevice3_iface
,
936 &vp
->IDirect3DViewport3_iface
, &res
, flags
);
937 *next
= (IDirect3DViewport2
*)res
;
941 static HRESULT WINAPI
d3d_device1_NextViewport(IDirect3DDevice
*iface
,
942 IDirect3DViewport
*viewport
, IDirect3DViewport
**next
, DWORD flags
)
944 struct d3d_device
*device
= impl_from_IDirect3DDevice(iface
);
945 struct d3d_viewport
*vp
= unsafe_impl_from_IDirect3DViewport(viewport
);
946 IDirect3DViewport3
*res
;
949 TRACE("iface %p, viewport %p, next %p, flags %#x.\n",
950 iface
, viewport
, next
, flags
);
952 hr
= d3d_device3_NextViewport(&device
->IDirect3DDevice3_iface
,
953 &vp
->IDirect3DViewport3_iface
, &res
, flags
);
954 *next
= (IDirect3DViewport
*)res
;
958 /*****************************************************************************
959 * IDirect3DDevice::Pick
961 * Executes an execute buffer without performing rendering. Instead, a
962 * list of primitives that intersect with (x1,y1) of the passed rectangle
963 * is created. IDirect3DDevice::GetPickRecords can be used to retrieve
969 * ExecuteBuffer: Buffer to execute
970 * Viewport: Viewport to use for execution
971 * Flags: None are defined, according to the SDK
972 * Rect: Specifies the coordinates to be picked. Only x1 and y2 are used,
973 * x2 and y2 are ignored.
976 * D3D_OK because it's a stub
978 *****************************************************************************/
979 static HRESULT WINAPI
d3d_device1_Pick(IDirect3DDevice
*iface
, IDirect3DExecuteBuffer
*buffer
,
980 IDirect3DViewport
*viewport
, DWORD flags
, D3DRECT
*rect
)
982 FIXME("iface %p, buffer %p, viewport %p, flags %#x, rect %s stub!\n",
983 iface
, buffer
, viewport
, flags
, wine_dbgstr_rect((RECT
*)rect
));
988 /*****************************************************************************
989 * IDirect3DDevice::GetPickRecords
991 * Retrieves the pick records generated by IDirect3DDevice::GetPickRecords
996 * Count: Pointer to a DWORD containing the numbers of pick records to
998 * D3DPickRec: Address to store the resulting D3DPICKRECORD array.
1001 * D3D_OK, because it's a stub
1003 *****************************************************************************/
1004 static HRESULT WINAPI
d3d_device1_GetPickRecords(IDirect3DDevice
*iface
,
1005 DWORD
*count
, D3DPICKRECORD
*records
)
1007 FIXME("iface %p, count %p, records %p stub!\n", iface
, count
, records
);
1012 /*****************************************************************************
1013 * IDirect3DDevice7::EnumTextureformats
1015 * Enumerates the supported texture formats. It has a list of all possible
1016 * formats and calls IWineD3D::CheckDeviceFormat for each format to see if
1017 * WineD3D supports it. If so, then it is passed to the app.
1019 * This is for Version 7 and 3, older versions have a different
1020 * callback function and their own implementation
1023 * Callback: Callback to call for each enumerated format
1024 * Arg: Argument to pass to the callback
1028 * DDERR_INVALIDPARAMS if Callback == NULL
1030 *****************************************************************************/
1031 static HRESULT
d3d_device7_EnumTextureFormats(IDirect3DDevice7
*iface
,
1032 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
1034 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
1035 struct wined3d_display_mode mode
;
1039 static const enum wined3d_format_id FormatList
[] =
1042 WINED3DFMT_B5G5R5X1_UNORM
,
1043 WINED3DFMT_B5G5R5A1_UNORM
,
1044 WINED3DFMT_B4G4R4A4_UNORM
,
1045 WINED3DFMT_B5G6R5_UNORM
,
1047 WINED3DFMT_B8G8R8X8_UNORM
,
1048 WINED3DFMT_B8G8R8A8_UNORM
,
1050 WINED3DFMT_B2G3R3_UNORM
,
1060 static const enum wined3d_format_id BumpFormatList
[] =
1062 WINED3DFMT_R8G8_SNORM
,
1063 WINED3DFMT_R5G5_SNORM_L6_UNORM
,
1064 WINED3DFMT_R8G8_SNORM_L8X8_UNORM
,
1065 WINED3DFMT_R16G16_SNORM
,
1066 WINED3DFMT_R10G11B11_SNORM
,
1067 WINED3DFMT_R10G10B10_SNORM_A2_UNORM
1070 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
1073 return DDERR_INVALIDPARAMS
;
1075 wined3d_mutex_lock();
1077 memset(&mode
, 0, sizeof(mode
));
1078 if (FAILED(hr
= wined3d_get_adapter_display_mode(device
->ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1080 wined3d_mutex_unlock();
1081 WARN("Cannot get the current adapter format\n");
1085 for (i
= 0; i
< sizeof(FormatList
) / sizeof(*FormatList
); ++i
)
1087 if (wined3d_check_device_format(device
->ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, WINED3D_DEVICE_TYPE_HAL
,
1088 mode
.format_id
, 0, WINED3D_RTYPE_TEXTURE
, FormatList
[i
]) == D3D_OK
)
1090 DDPIXELFORMAT pformat
;
1092 memset(&pformat
, 0, sizeof(pformat
));
1093 pformat
.dwSize
= sizeof(pformat
);
1094 ddrawformat_from_wined3dformat(&pformat
, FormatList
[i
]);
1096 TRACE("Enumerating WineD3DFormat %d\n", FormatList
[i
]);
1097 hr
= callback(&pformat
, context
);
1098 if(hr
!= DDENUMRET_OK
)
1100 TRACE("Format enumeration cancelled by application\n");
1101 wined3d_mutex_unlock();
1107 for (i
= 0; i
< sizeof(BumpFormatList
) / sizeof(*BumpFormatList
); ++i
)
1109 if (wined3d_check_device_format(device
->ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
1110 WINED3D_DEVICE_TYPE_HAL
, mode
.format_id
, WINED3DUSAGE_QUERY_LEGACYBUMPMAP
,
1111 WINED3D_RTYPE_TEXTURE
, BumpFormatList
[i
]) == D3D_OK
)
1113 DDPIXELFORMAT pformat
;
1115 memset(&pformat
, 0, sizeof(pformat
));
1116 pformat
.dwSize
= sizeof(pformat
);
1117 ddrawformat_from_wined3dformat(&pformat
, BumpFormatList
[i
]);
1119 TRACE("Enumerating WineD3DFormat %d\n", BumpFormatList
[i
]);
1120 hr
= callback(&pformat
, context
);
1121 if(hr
!= DDENUMRET_OK
)
1123 TRACE("Format enumeration cancelled by application\n");
1124 wined3d_mutex_unlock();
1129 TRACE("End of enumeration\n");
1130 wined3d_mutex_unlock();
1135 static HRESULT WINAPI
d3d_device7_EnumTextureFormats_FPUSetup(IDirect3DDevice7
*iface
,
1136 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
1138 return d3d_device7_EnumTextureFormats(iface
, callback
, context
);
1141 static HRESULT WINAPI
d3d_device7_EnumTextureFormats_FPUPreserve(IDirect3DDevice7
*iface
,
1142 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
1147 old_fpucw
= d3d_fpu_setup();
1148 hr
= d3d_device7_EnumTextureFormats(iface
, callback
, context
);
1149 set_fpu_control_word(old_fpucw
);
1154 static HRESULT WINAPI
d3d_device3_EnumTextureFormats(IDirect3DDevice3
*iface
,
1155 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
1157 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
1159 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
1161 return IDirect3DDevice7_EnumTextureFormats(&device
->IDirect3DDevice7_iface
, callback
, context
);
1164 /*****************************************************************************
1165 * IDirect3DDevice2::EnumTextureformats
1167 * EnumTextureFormats for Version 1 and 2, see
1168 * IDirect3DDevice7::EnumTexureFormats for a more detailed description.
1170 * This version has a different callback and does not enumerate FourCC
1173 *****************************************************************************/
1174 static HRESULT WINAPI
d3d_device2_EnumTextureFormats(IDirect3DDevice2
*iface
,
1175 LPD3DENUMTEXTUREFORMATSCALLBACK callback
, void *context
)
1177 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
1178 struct wined3d_display_mode mode
;
1182 static const enum wined3d_format_id FormatList
[] =
1185 WINED3DFMT_B5G5R5X1_UNORM
,
1186 WINED3DFMT_B5G5R5A1_UNORM
,
1187 WINED3DFMT_B4G4R4A4_UNORM
,
1188 WINED3DFMT_B5G6R5_UNORM
,
1190 WINED3DFMT_B8G8R8X8_UNORM
,
1191 WINED3DFMT_B8G8R8A8_UNORM
,
1193 WINED3DFMT_B2G3R3_UNORM
,
1195 /* FOURCC codes - Not in this version*/
1198 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
1201 return DDERR_INVALIDPARAMS
;
1203 wined3d_mutex_lock();
1205 memset(&mode
, 0, sizeof(mode
));
1206 if (FAILED(hr
= wined3d_get_adapter_display_mode(device
->ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1208 wined3d_mutex_unlock();
1209 WARN("Cannot get the current adapter format\n");
1213 for (i
= 0; i
< sizeof(FormatList
) / sizeof(*FormatList
); ++i
)
1215 if (wined3d_check_device_format(device
->ddraw
->wined3d
, 0, WINED3D_DEVICE_TYPE_HAL
,
1216 mode
.format_id
, 0, WINED3D_RTYPE_TEXTURE
, FormatList
[i
]) == D3D_OK
)
1218 DDSURFACEDESC sdesc
;
1220 memset(&sdesc
, 0, sizeof(sdesc
));
1221 sdesc
.dwSize
= sizeof(sdesc
);
1222 sdesc
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_CAPS
;
1223 sdesc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1224 sdesc
.ddpfPixelFormat
.dwSize
= sizeof(sdesc
.ddpfPixelFormat
);
1225 ddrawformat_from_wined3dformat(&sdesc
.ddpfPixelFormat
, FormatList
[i
]);
1227 TRACE("Enumerating WineD3DFormat %d\n", FormatList
[i
]);
1228 hr
= callback(&sdesc
, context
);
1229 if(hr
!= DDENUMRET_OK
)
1231 TRACE("Format enumeration cancelled by application\n");
1232 wined3d_mutex_unlock();
1237 TRACE("End of enumeration\n");
1238 wined3d_mutex_unlock();
1243 static HRESULT WINAPI
d3d_device1_EnumTextureFormats(IDirect3DDevice
*iface
,
1244 LPD3DENUMTEXTUREFORMATSCALLBACK callback
, void *context
)
1246 struct d3d_device
*device
= impl_from_IDirect3DDevice(iface
);
1248 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
1250 return d3d_device2_EnumTextureFormats(&device
->IDirect3DDevice2_iface
, callback
, context
);
1253 /*****************************************************************************
1254 * IDirect3DDevice::CreateMatrix
1256 * Creates a matrix handle. A handle is created and memory for a D3DMATRIX is
1257 * allocated for the handle.
1262 * D3DMatHandle: Address to return the handle at
1266 * DDERR_INVALIDPARAMS if D3DMatHandle = NULL
1268 *****************************************************************************/
1269 static HRESULT WINAPI
d3d_device1_CreateMatrix(IDirect3DDevice
*iface
, D3DMATRIXHANDLE
*D3DMatHandle
)
1271 struct d3d_device
*device
= impl_from_IDirect3DDevice(iface
);
1275 TRACE("iface %p, matrix_handle %p.\n", iface
, D3DMatHandle
);
1278 return DDERR_INVALIDPARAMS
;
1280 Matrix
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(D3DMATRIX
));
1283 ERR("Out of memory when allocating a D3DMATRIX\n");
1284 return DDERR_OUTOFMEMORY
;
1287 wined3d_mutex_lock();
1289 h
= ddraw_allocate_handle(&device
->handle_table
, Matrix
, DDRAW_HANDLE_MATRIX
);
1290 if (h
== DDRAW_INVALID_HANDLE
)
1292 ERR("Failed to allocate a matrix handle.\n");
1293 HeapFree(GetProcessHeap(), 0, Matrix
);
1294 wined3d_mutex_unlock();
1295 return DDERR_OUTOFMEMORY
;
1298 *D3DMatHandle
= h
+ 1;
1300 TRACE(" returning matrix handle %d\n", *D3DMatHandle
);
1302 wined3d_mutex_unlock();
1307 /*****************************************************************************
1308 * IDirect3DDevice::SetMatrix
1310 * Sets a matrix for a matrix handle. The matrix is copied into the memory
1311 * allocated for the handle
1316 * D3DMatHandle: Handle to set the matrix to
1317 * D3DMatrix: Matrix to set
1321 * DDERR_INVALIDPARAMS if the handle of the matrix is invalid or the matrix
1324 *****************************************************************************/
1325 static HRESULT WINAPI
d3d_device1_SetMatrix(IDirect3DDevice
*iface
,
1326 D3DMATRIXHANDLE D3DMatHandle
, D3DMATRIX
*D3DMatrix
)
1328 struct d3d_device
*This
= impl_from_IDirect3DDevice(iface
);
1331 TRACE("iface %p, matrix_handle %#x, matrix %p.\n", iface
, D3DMatHandle
, D3DMatrix
);
1333 if (!D3DMatrix
) return DDERR_INVALIDPARAMS
;
1335 wined3d_mutex_lock();
1337 m
= ddraw_get_object(&This
->handle_table
, D3DMatHandle
- 1, DDRAW_HANDLE_MATRIX
);
1340 WARN("Invalid matrix handle.\n");
1341 wined3d_mutex_unlock();
1342 return DDERR_INVALIDPARAMS
;
1345 if (TRACE_ON(ddraw
))
1346 dump_D3DMATRIX(D3DMatrix
);
1350 if (D3DMatHandle
== This
->world
)
1351 wined3d_device_set_transform(This
->wined3d_device
,
1352 WINED3D_TS_WORLD_MATRIX(0), (struct wined3d_matrix
*)D3DMatrix
);
1354 if (D3DMatHandle
== This
->view
)
1355 wined3d_device_set_transform(This
->wined3d_device
,
1356 WINED3D_TS_VIEW
, (struct wined3d_matrix
*)D3DMatrix
);
1358 if (D3DMatHandle
== This
->proj
)
1359 wined3d_device_set_transform(This
->wined3d_device
,
1360 WINED3D_TS_PROJECTION
, (struct wined3d_matrix
*)D3DMatrix
);
1362 wined3d_mutex_unlock();
1367 /*****************************************************************************
1368 * IDirect3DDevice::GetMatrix
1370 * Returns the content of a D3DMATRIX handle
1375 * D3DMatHandle: Matrix handle to read the content from
1376 * D3DMatrix: Address to store the content at
1380 * DDERR_INVALIDPARAMS if D3DMatHandle is invalid or D3DMatrix is NULL
1382 *****************************************************************************/
1383 static HRESULT WINAPI
d3d_device1_GetMatrix(IDirect3DDevice
*iface
,
1384 D3DMATRIXHANDLE D3DMatHandle
, D3DMATRIX
*D3DMatrix
)
1386 struct d3d_device
*device
= impl_from_IDirect3DDevice(iface
);
1389 TRACE("iface %p, matrix_handle %#x, matrix %p.\n", iface
, D3DMatHandle
, D3DMatrix
);
1391 if (!D3DMatrix
) return DDERR_INVALIDPARAMS
;
1393 wined3d_mutex_lock();
1395 m
= ddraw_get_object(&device
->handle_table
, D3DMatHandle
- 1, DDRAW_HANDLE_MATRIX
);
1398 WARN("Invalid matrix handle.\n");
1399 wined3d_mutex_unlock();
1400 return DDERR_INVALIDPARAMS
;
1405 wined3d_mutex_unlock();
1410 /*****************************************************************************
1411 * IDirect3DDevice::DeleteMatrix
1413 * Destroys a Matrix handle. Frees the memory and unsets the handle data
1418 * D3DMatHandle: Handle to destroy
1422 * DDERR_INVALIDPARAMS if D3DMatHandle is invalid
1424 *****************************************************************************/
1425 static HRESULT WINAPI
d3d_device1_DeleteMatrix(IDirect3DDevice
*iface
, D3DMATRIXHANDLE D3DMatHandle
)
1427 struct d3d_device
*device
= impl_from_IDirect3DDevice(iface
);
1430 TRACE("iface %p, matrix_handle %#x.\n", iface
, D3DMatHandle
);
1432 wined3d_mutex_lock();
1434 m
= ddraw_free_handle(&device
->handle_table
, D3DMatHandle
- 1, DDRAW_HANDLE_MATRIX
);
1437 WARN("Invalid matrix handle.\n");
1438 wined3d_mutex_unlock();
1439 return DDERR_INVALIDPARAMS
;
1442 wined3d_mutex_unlock();
1444 HeapFree(GetProcessHeap(), 0, m
);
1449 /*****************************************************************************
1450 * IDirect3DDevice7::BeginScene
1452 * This method must be called before any rendering is performed.
1453 * IDirect3DDevice::EndScene has to be called after the scene is complete
1455 * Version 1, 2, 3 and 7
1458 * D3D_OK on success, for details see IWineD3DDevice::BeginScene
1459 * D3DERR_SCENE_IN_SCENE if WineD3D returns an error(Only in case of an already
1462 *****************************************************************************/
1463 static HRESULT
d3d_device7_BeginScene(IDirect3DDevice7
*iface
)
1465 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
1468 TRACE("iface %p.\n", iface
);
1470 wined3d_mutex_lock();
1471 hr
= wined3d_device_begin_scene(device
->wined3d_device
);
1472 wined3d_mutex_unlock();
1474 if(hr
== WINED3D_OK
) return D3D_OK
;
1475 else return D3DERR_SCENE_IN_SCENE
; /* TODO: Other possible causes of failure */
1478 static HRESULT WINAPI
d3d_device7_BeginScene_FPUSetup(IDirect3DDevice7
*iface
)
1480 return d3d_device7_BeginScene(iface
);
1483 static HRESULT WINAPI
d3d_device7_BeginScene_FPUPreserve(IDirect3DDevice7
*iface
)
1488 old_fpucw
= d3d_fpu_setup();
1489 hr
= d3d_device7_BeginScene(iface
);
1490 set_fpu_control_word(old_fpucw
);
1495 static HRESULT WINAPI
d3d_device3_BeginScene(IDirect3DDevice3
*iface
)
1497 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
1499 TRACE("iface %p.\n", iface
);
1501 return IDirect3DDevice7_BeginScene(&device
->IDirect3DDevice7_iface
);
1504 static HRESULT WINAPI
d3d_device2_BeginScene(IDirect3DDevice2
*iface
)
1506 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
1508 TRACE("iface %p.\n", iface
);
1510 return IDirect3DDevice7_BeginScene(&device
->IDirect3DDevice7_iface
);
1513 static HRESULT WINAPI
d3d_device1_BeginScene(IDirect3DDevice
*iface
)
1515 struct d3d_device
*device
= impl_from_IDirect3DDevice(iface
);
1517 TRACE("iface %p.\n", iface
);
1519 return IDirect3DDevice7_BeginScene(&device
->IDirect3DDevice7_iface
);
1522 /*****************************************************************************
1523 * IDirect3DDevice7::EndScene
1525 * Ends a scene that has been begun with IDirect3DDevice7::BeginScene.
1526 * This method must be called after rendering is finished.
1528 * Version 1, 2, 3 and 7
1531 * D3D_OK on success, for details see IWineD3DDevice::EndScene
1532 * D3DERR_SCENE_NOT_IN_SCENE is returned if WineD3D returns an error. It does
1533 * that only if the scene was already ended.
1535 *****************************************************************************/
1536 static HRESULT
d3d_device7_EndScene(IDirect3DDevice7
*iface
)
1538 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
1541 TRACE("iface %p.\n", iface
);
1543 wined3d_mutex_lock();
1544 hr
= wined3d_device_end_scene(device
->wined3d_device
);
1545 wined3d_mutex_unlock();
1547 if(hr
== WINED3D_OK
) return D3D_OK
;
1548 else return D3DERR_SCENE_NOT_IN_SCENE
;
1551 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d_device7_EndScene_FPUSetup(IDirect3DDevice7
*iface
)
1553 return d3d_device7_EndScene(iface
);
1556 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d_device7_EndScene_FPUPreserve(IDirect3DDevice7
*iface
)
1561 old_fpucw
= d3d_fpu_setup();
1562 hr
= d3d_device7_EndScene(iface
);
1563 set_fpu_control_word(old_fpucw
);
1568 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d_device3_EndScene(IDirect3DDevice3
*iface
)
1570 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
1572 TRACE("iface %p.\n", iface
);
1574 return IDirect3DDevice7_EndScene(&device
->IDirect3DDevice7_iface
);
1577 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d_device2_EndScene(IDirect3DDevice2
*iface
)
1579 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
1581 TRACE("iface %p.\n", iface
);
1583 return IDirect3DDevice7_EndScene(&device
->IDirect3DDevice7_iface
);
1586 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d_device1_EndScene(IDirect3DDevice
*iface
)
1588 struct d3d_device
*device
= impl_from_IDirect3DDevice(iface
);
1590 TRACE("iface %p.\n", iface
);
1592 return IDirect3DDevice7_EndScene(&device
->IDirect3DDevice7_iface
);
1595 /*****************************************************************************
1596 * IDirect3DDevice7::GetDirect3D
1598 * Returns the IDirect3D(= interface to the DirectDraw object) used to create
1602 * Direct3D7: Address to store the interface pointer at
1606 * DDERR_INVALIDPARAMS if Direct3D7 == NULL
1608 *****************************************************************************/
1609 static HRESULT WINAPI
d3d_device7_GetDirect3D(IDirect3DDevice7
*iface
, IDirect3D7
**d3d
)
1611 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
1613 TRACE("iface %p, d3d %p.\n", iface
, d3d
);
1616 return DDERR_INVALIDPARAMS
;
1618 *d3d
= &device
->ddraw
->IDirect3D7_iface
;
1619 IDirect3D7_AddRef(*d3d
);
1621 TRACE("Returning interface %p.\n", *d3d
);
1625 static HRESULT WINAPI
d3d_device3_GetDirect3D(IDirect3DDevice3
*iface
, IDirect3D3
**d3d
)
1627 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
1629 TRACE("iface %p, d3d %p.\n", iface
, d3d
);
1632 return DDERR_INVALIDPARAMS
;
1634 *d3d
= &device
->ddraw
->IDirect3D3_iface
;
1635 IDirect3D3_AddRef(*d3d
);
1637 TRACE("Returning interface %p.\n", *d3d
);
1641 static HRESULT WINAPI
d3d_device2_GetDirect3D(IDirect3DDevice2
*iface
, IDirect3D2
**d3d
)
1643 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
1645 TRACE("iface %p, d3d %p.\n", iface
, d3d
);
1648 return DDERR_INVALIDPARAMS
;
1650 *d3d
= &device
->ddraw
->IDirect3D2_iface
;
1651 IDirect3D2_AddRef(*d3d
);
1653 TRACE("Returning interface %p.\n", *d3d
);
1657 static HRESULT WINAPI
d3d_device1_GetDirect3D(IDirect3DDevice
*iface
, IDirect3D
**d3d
)
1659 struct d3d_device
*device
= impl_from_IDirect3DDevice(iface
);
1661 TRACE("iface %p, d3d %p.\n", iface
, d3d
);
1664 return DDERR_INVALIDPARAMS
;
1666 *d3d
= &device
->ddraw
->IDirect3D_iface
;
1667 IDirect3D_AddRef(*d3d
);
1669 TRACE("Returning interface %p.\n", *d3d
);
1673 /*****************************************************************************
1674 * IDirect3DDevice3::SetCurrentViewport
1676 * Sets a Direct3DViewport as the current viewport.
1677 * For the thunks note that all viewport interface versions are equal
1680 * Direct3DViewport3: The viewport to set
1686 * (Is a NULL viewport valid?)
1688 *****************************************************************************/
1689 static HRESULT WINAPI
d3d_device3_SetCurrentViewport(IDirect3DDevice3
*iface
, IDirect3DViewport3
*Direct3DViewport3
)
1691 struct d3d_device
*This
= impl_from_IDirect3DDevice3(iface
);
1692 struct d3d_viewport
*vp
= unsafe_impl_from_IDirect3DViewport3(Direct3DViewport3
);
1694 TRACE("iface %p, viewport %p.\n", iface
, Direct3DViewport3
);
1698 WARN("Direct3DViewport3 is NULL, returning DDERR_INVALIDPARAMS\n");
1699 return DDERR_INVALIDPARAMS
;
1702 wined3d_mutex_lock();
1703 /* Do nothing if the specified viewport is the same as the current one */
1704 if (This
->current_viewport
== vp
)
1706 wined3d_mutex_unlock();
1710 if (vp
->active_device
!= This
)
1712 WARN("Viewport %p active device is %p.\n", vp
, vp
->active_device
);
1713 wined3d_mutex_unlock();
1714 return DDERR_INVALIDPARAMS
;
1717 /* Release previous viewport and AddRef the new one */
1718 if (This
->current_viewport
)
1720 TRACE("ViewportImpl is at %p, interface is at %p\n", This
->current_viewport
,
1721 &This
->current_viewport
->IDirect3DViewport3_iface
);
1722 IDirect3DViewport3_Release(&This
->current_viewport
->IDirect3DViewport3_iface
);
1724 IDirect3DViewport3_AddRef(Direct3DViewport3
);
1726 /* Set this viewport as the current viewport */
1727 This
->current_viewport
= vp
;
1729 /* Activate this viewport */
1730 viewport_activate(This
->current_viewport
, FALSE
);
1732 wined3d_mutex_unlock();
1737 static HRESULT WINAPI
d3d_device2_SetCurrentViewport(IDirect3DDevice2
*iface
, IDirect3DViewport2
*viewport
)
1739 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
1740 struct d3d_viewport
*vp
= unsafe_impl_from_IDirect3DViewport2(viewport
);
1742 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
1744 return d3d_device3_SetCurrentViewport(&device
->IDirect3DDevice3_iface
,
1745 vp
? &vp
->IDirect3DViewport3_iface
: NULL
);
1748 /*****************************************************************************
1749 * IDirect3DDevice3::GetCurrentViewport
1751 * Returns the currently active viewport.
1756 * Direct3DViewport3: Address to return the interface pointer at
1760 * DDERR_INVALIDPARAMS if Direct3DViewport == NULL
1762 *****************************************************************************/
1763 static HRESULT WINAPI
d3d_device3_GetCurrentViewport(IDirect3DDevice3
*iface
, IDirect3DViewport3
**viewport
)
1765 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
1767 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
1769 wined3d_mutex_lock();
1770 if (!device
->current_viewport
)
1772 wined3d_mutex_unlock();
1773 WARN("No current viewport, returning D3DERR_NOCURRENTVIEWPORT\n");
1774 return D3DERR_NOCURRENTVIEWPORT
;
1777 *viewport
= &device
->current_viewport
->IDirect3DViewport3_iface
;
1778 IDirect3DViewport3_AddRef(*viewport
);
1780 TRACE("Returning interface %p.\n", *viewport
);
1781 wined3d_mutex_unlock();
1785 static HRESULT WINAPI
d3d_device2_GetCurrentViewport(IDirect3DDevice2
*iface
, IDirect3DViewport2
**viewport
)
1787 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
1789 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
1791 return d3d_device3_GetCurrentViewport(&device
->IDirect3DDevice3_iface
,
1792 (IDirect3DViewport3
**)viewport
);
1795 static BOOL
validate_surface_palette(struct ddraw_surface
*surface
)
1797 return !(surface
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
1798 & (DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
1799 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
1800 | DDPF_PALETTEINDEXEDTO8
))
1801 || wined3d_surface_get_palette(surface
->wined3d_surface
);
1804 static HRESULT
d3d_device_set_render_target(struct d3d_device
*device
,
1805 struct ddraw_surface
*target
, IUnknown
*rt_iface
)
1809 if (device
->rt_iface
== rt_iface
)
1811 TRACE("No-op SetRenderTarget operation, not doing anything\n");
1816 WARN("Trying to set render target to NULL.\n");
1817 return DDERR_INVALIDPARAMS
;
1820 if (FAILED(hr
= wined3d_device_set_render_target(device
->wined3d_device
,
1821 0, target
->wined3d_surface
, FALSE
)))
1824 IUnknown_AddRef(rt_iface
);
1825 IUnknown_Release(device
->rt_iface
);
1826 device
->rt_iface
= rt_iface
;
1827 d3d_device_update_depth_stencil(device
);
1832 static HRESULT
d3d_device7_SetRenderTarget(IDirect3DDevice7
*iface
,
1833 IDirectDrawSurface7
*target
, DWORD flags
)
1835 struct ddraw_surface
*target_impl
= unsafe_impl_from_IDirectDrawSurface7(target
);
1836 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
1839 TRACE("iface %p, target %p, flags %#x.\n", iface
, target
, flags
);
1841 wined3d_mutex_lock();
1843 if (!validate_surface_palette(target_impl
))
1845 WARN("Surface %p has an indexed pixel format, but no palette.\n", target_impl
);
1846 wined3d_mutex_unlock();
1847 return DDERR_INVALIDCAPS
;
1850 if (!(target_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
))
1852 WARN("Surface %p is not a render target.\n", target_impl
);
1853 wined3d_mutex_unlock();
1854 return DDERR_INVALIDCAPS
;
1857 if (!(target_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
))
1859 WARN("Surface %p is not in video memory.\n", target_impl
);
1860 wined3d_mutex_unlock();
1861 return DDERR_INVALIDPARAMS
;
1864 if (target_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
1866 WARN("Surface %p is a depth buffer.\n", target_impl
);
1867 IDirectDrawSurface7_AddRef(target
);
1868 IUnknown_Release(device
->rt_iface
);
1869 device
->rt_iface
= (IUnknown
*)target
;
1870 wined3d_mutex_unlock();
1871 return DDERR_INVALIDPIXELFORMAT
;
1874 hr
= d3d_device_set_render_target(device
, target_impl
, (IUnknown
*)target
);
1875 wined3d_mutex_unlock();
1879 static HRESULT WINAPI
d3d_device7_SetRenderTarget_FPUSetup(IDirect3DDevice7
*iface
,
1880 IDirectDrawSurface7
*NewTarget
, DWORD flags
)
1882 return d3d_device7_SetRenderTarget(iface
, NewTarget
, flags
);
1885 static HRESULT WINAPI
d3d_device7_SetRenderTarget_FPUPreserve(IDirect3DDevice7
*iface
,
1886 IDirectDrawSurface7
*NewTarget
, DWORD flags
)
1891 old_fpucw
= d3d_fpu_setup();
1892 hr
= d3d_device7_SetRenderTarget(iface
, NewTarget
, flags
);
1893 set_fpu_control_word(old_fpucw
);
1898 static HRESULT WINAPI
d3d_device3_SetRenderTarget(IDirect3DDevice3
*iface
,
1899 IDirectDrawSurface4
*target
, DWORD flags
)
1901 struct ddraw_surface
*target_impl
= unsafe_impl_from_IDirectDrawSurface4(target
);
1902 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
1905 TRACE("iface %p, target %p, flags %#x.\n", iface
, target
, flags
);
1907 wined3d_mutex_lock();
1909 if (!validate_surface_palette(target_impl
))
1911 WARN("Surface %p has an indexed pixel format, but no palette.\n", target_impl
);
1912 wined3d_mutex_unlock();
1913 return DDERR_INVALIDCAPS
;
1916 if (!(target_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
))
1918 WARN("Surface %p is not a render target.\n", target_impl
);
1919 wined3d_mutex_unlock();
1920 return DDERR_INVALIDCAPS
;
1923 if (target_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
1925 WARN("Surface %p is a depth buffer.\n", target_impl
);
1926 IDirectDrawSurface4_AddRef(target
);
1927 IUnknown_Release(device
->rt_iface
);
1928 device
->rt_iface
= (IUnknown
*)target
;
1929 wined3d_mutex_unlock();
1930 return DDERR_INVALIDPIXELFORMAT
;
1933 if (!(target_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
))
1935 WARN("Surface %p is not in video memory.\n", target_impl
);
1936 IDirectDrawSurface4_AddRef(target
);
1937 IUnknown_Release(device
->rt_iface
);
1938 device
->rt_iface
= (IUnknown
*)target
;
1939 wined3d_mutex_unlock();
1943 hr
= d3d_device_set_render_target(device
, target_impl
, (IUnknown
*)target
);
1944 wined3d_mutex_unlock();
1948 static HRESULT WINAPI
d3d_device2_SetRenderTarget(IDirect3DDevice2
*iface
,
1949 IDirectDrawSurface
*target
, DWORD flags
)
1951 struct ddraw_surface
*target_impl
= unsafe_impl_from_IDirectDrawSurface(target
);
1952 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
1955 TRACE("iface %p, target %p, flags %#x.\n", iface
, target
, flags
);
1957 wined3d_mutex_lock();
1959 if (!validate_surface_palette(target_impl
))
1961 WARN("Surface %p has an indexed pixel format, but no palette.\n", target_impl
);
1962 wined3d_mutex_unlock();
1963 return DDERR_INVALIDCAPS
;
1966 if (!(target_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
))
1968 WARN("Surface %p is not a render target.\n", target_impl
);
1969 wined3d_mutex_unlock();
1970 return DDERR_INVALIDCAPS
;
1973 if (target_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
1975 WARN("Surface %p is a depth buffer.\n", target_impl
);
1976 IUnknown_Release(device
->rt_iface
);
1977 device
->rt_iface
= (IUnknown
*)target
;
1978 wined3d_mutex_unlock();
1979 return DDERR_INVALIDPIXELFORMAT
;
1982 if (!(target_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
))
1984 WARN("Surface %p is not in video memory.\n", target_impl
);
1985 IDirectDrawSurface_AddRef(target
);
1986 IUnknown_Release(device
->rt_iface
);
1987 device
->rt_iface
= (IUnknown
*)target
;
1988 wined3d_mutex_unlock();
1992 hr
= d3d_device_set_render_target(device
, target_impl
, (IUnknown
*)target
);
1993 wined3d_mutex_unlock();
1997 /*****************************************************************************
1998 * IDirect3DDevice7::GetRenderTarget
2000 * Returns the current render target.
2001 * This is handled locally, because the WineD3D render target's parent
2004 * Version 2, 3 and 7
2007 * RenderTarget: Address to store the surface interface pointer
2011 * DDERR_INVALIDPARAMS if RenderTarget == NULL
2013 *****************************************************************************/
2014 static HRESULT WINAPI
d3d_device7_GetRenderTarget(IDirect3DDevice7
*iface
, IDirectDrawSurface7
**RenderTarget
)
2016 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
2019 TRACE("iface %p, target %p.\n", iface
, RenderTarget
);
2022 return DDERR_INVALIDPARAMS
;
2024 wined3d_mutex_lock();
2025 hr
= IUnknown_QueryInterface(device
->rt_iface
, &IID_IDirectDrawSurface7
, (void **)RenderTarget
);
2026 wined3d_mutex_unlock();
2031 static HRESULT WINAPI
d3d_device3_GetRenderTarget(IDirect3DDevice3
*iface
, IDirectDrawSurface4
**RenderTarget
)
2033 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
2034 IDirectDrawSurface7
*RenderTarget7
;
2035 struct ddraw_surface
*RenderTargetImpl
;
2038 TRACE("iface %p, target %p.\n", iface
, RenderTarget
);
2041 return DDERR_INVALIDPARAMS
;
2043 hr
= d3d_device7_GetRenderTarget(&device
->IDirect3DDevice7_iface
, &RenderTarget7
);
2044 if(hr
!= D3D_OK
) return hr
;
2045 RenderTargetImpl
= impl_from_IDirectDrawSurface7(RenderTarget7
);
2046 *RenderTarget
= &RenderTargetImpl
->IDirectDrawSurface4_iface
;
2047 IDirectDrawSurface4_AddRef(*RenderTarget
);
2048 IDirectDrawSurface7_Release(RenderTarget7
);
2052 static HRESULT WINAPI
d3d_device2_GetRenderTarget(IDirect3DDevice2
*iface
, IDirectDrawSurface
**RenderTarget
)
2054 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
2055 IDirectDrawSurface7
*RenderTarget7
;
2056 struct ddraw_surface
*RenderTargetImpl
;
2059 TRACE("iface %p, target %p.\n", iface
, RenderTarget
);
2062 return DDERR_INVALIDPARAMS
;
2064 hr
= d3d_device7_GetRenderTarget(&device
->IDirect3DDevice7_iface
, &RenderTarget7
);
2065 if(hr
!= D3D_OK
) return hr
;
2066 RenderTargetImpl
= impl_from_IDirectDrawSurface7(RenderTarget7
);
2067 *RenderTarget
= &RenderTargetImpl
->IDirectDrawSurface_iface
;
2068 IDirectDrawSurface_AddRef(*RenderTarget
);
2069 IDirectDrawSurface7_Release(RenderTarget7
);
2073 /*****************************************************************************
2074 * IDirect3DDevice3::Begin
2076 * Begins a description block of vertices. This is similar to glBegin()
2077 * and glEnd(). After a call to IDirect3DDevice3::End, the vertices
2078 * described with IDirect3DDevice::Vertex are drawn.
2083 * PrimitiveType: The type of primitives to draw
2084 * VertexTypeDesc: A flexible vertex format description of the vertices
2085 * Flags: Some flags..
2090 *****************************************************************************/
2091 static HRESULT WINAPI
d3d_device3_Begin(IDirect3DDevice3
*iface
,
2092 D3DPRIMITIVETYPE primitive_type
, DWORD fvf
, DWORD flags
)
2094 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
2096 TRACE("iface %p, primitive_type %#x, fvf %#x, flags %#x.\n",
2097 iface
, primitive_type
, fvf
, flags
);
2099 wined3d_mutex_lock();
2100 device
->primitive_type
= primitive_type
;
2101 device
->vertex_type
= fvf
;
2102 device
->render_flags
= flags
;
2103 device
->vertex_size
= get_flexible_vertex_size(device
->vertex_type
);
2104 device
->nb_vertices
= 0;
2105 wined3d_mutex_unlock();
2110 static HRESULT WINAPI
d3d_device2_Begin(IDirect3DDevice2
*iface
,
2111 D3DPRIMITIVETYPE primitive_type
, D3DVERTEXTYPE vertex_type
, DWORD flags
)
2113 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
2116 TRACE("iface %p, primitive_type %#x, vertex_type %#x, flags %#x.\n",
2117 iface
, primitive_type
, vertex_type
, flags
);
2119 switch (vertex_type
)
2121 case D3DVT_VERTEX
: fvf
= D3DFVF_VERTEX
; break;
2122 case D3DVT_LVERTEX
: fvf
= D3DFVF_LVERTEX
; break;
2123 case D3DVT_TLVERTEX
: fvf
= D3DFVF_TLVERTEX
; break;
2125 ERR("Unexpected vertex type %#x.\n", vertex_type
);
2126 return DDERR_INVALIDPARAMS
; /* Should never happen */
2129 return d3d_device3_Begin(&device
->IDirect3DDevice3_iface
, primitive_type
, fvf
, flags
);
2132 /*****************************************************************************
2133 * IDirect3DDevice3::BeginIndexed
2135 * Draws primitives based on vertices in a vertex array which are specified
2141 * PrimitiveType: Primitive type to draw
2142 * VertexType: A FVF description of the vertex format
2143 * Vertices: pointer to an array containing the vertices
2144 * NumVertices: The number of vertices in the vertex array
2145 * Flags: Some flags ...
2148 * D3D_OK, because it's a stub
2150 *****************************************************************************/
2151 static HRESULT WINAPI
d3d_device3_BeginIndexed(IDirect3DDevice3
*iface
,
2152 D3DPRIMITIVETYPE primitive_type
, DWORD fvf
,
2153 void *vertices
, DWORD vertex_count
, DWORD flags
)
2155 FIXME("iface %p, primitive_type %#x, fvf %#x, vertices %p, vertex_count %u, flags %#x stub!\n",
2156 iface
, primitive_type
, fvf
, vertices
, vertex_count
, flags
);
2162 static HRESULT WINAPI
d3d_device2_BeginIndexed(IDirect3DDevice2
*iface
,
2163 D3DPRIMITIVETYPE primitive_type
, D3DVERTEXTYPE vertex_type
,
2164 void *vertices
, DWORD vertex_count
, DWORD flags
)
2166 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
2169 TRACE("iface %p, primitive_type %#x, vertex_type %#x, vertices %p, vertex_count %u, flags %#x stub!\n",
2170 iface
, primitive_type
, vertex_type
, vertices
, vertex_count
, flags
);
2172 switch (vertex_type
)
2174 case D3DVT_VERTEX
: fvf
= D3DFVF_VERTEX
; break;
2175 case D3DVT_LVERTEX
: fvf
= D3DFVF_LVERTEX
; break;
2176 case D3DVT_TLVERTEX
: fvf
= D3DFVF_TLVERTEX
; break;
2178 ERR("Unexpected vertex type %#x.\n", vertex_type
);
2179 return DDERR_INVALIDPARAMS
; /* Should never happen */
2182 return d3d_device3_BeginIndexed(&device
->IDirect3DDevice3_iface
,
2183 primitive_type
, fvf
, vertices
, vertex_count
, flags
);
2186 /*****************************************************************************
2187 * IDirect3DDevice3::Vertex
2189 * Draws a vertex as described by IDirect3DDevice3::Begin. It places all
2190 * drawn vertices in a vertex buffer. If the buffer is too small, its
2191 * size is increased.
2196 * Vertex: Pointer to the vertex
2199 * D3D_OK, on success
2200 * DDERR_INVALIDPARAMS if Vertex is NULL
2202 *****************************************************************************/
2203 static HRESULT WINAPI
d3d_device3_Vertex(IDirect3DDevice3
*iface
, void *vertex
)
2205 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
2207 TRACE("iface %p, vertex %p.\n", iface
, vertex
);
2210 return DDERR_INVALIDPARAMS
;
2212 wined3d_mutex_lock();
2213 if ((device
->nb_vertices
+ 1) * device
->vertex_size
> device
->buffer_size
)
2217 device
->buffer_size
= device
->buffer_size
? device
->buffer_size
* 2 : device
->vertex_size
* 3;
2218 old_buffer
= device
->sysmem_vertex_buffer
;
2219 device
->sysmem_vertex_buffer
= HeapAlloc(GetProcessHeap(), 0, device
->buffer_size
);
2222 memcpy(device
->sysmem_vertex_buffer
, old_buffer
, device
->nb_vertices
* device
->vertex_size
);
2223 HeapFree(GetProcessHeap(), 0, old_buffer
);
2227 memcpy(device
->sysmem_vertex_buffer
+ device
->nb_vertices
++ * device
->vertex_size
, vertex
, device
->vertex_size
);
2228 wined3d_mutex_unlock();
2233 static HRESULT WINAPI
d3d_device2_Vertex(IDirect3DDevice2
*iface
, void *vertex
)
2235 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
2237 TRACE("iface %p, vertex %p.\n", iface
, vertex
);
2239 return d3d_device3_Vertex(&device
->IDirect3DDevice3_iface
, vertex
);
2242 /*****************************************************************************
2243 * IDirect3DDevice3::Index
2245 * Specifies an index to a vertex to be drawn. The vertex array has to
2246 * be specified with BeginIndexed first.
2249 * VertexIndex: The index of the vertex to draw
2252 * D3D_OK because it's a stub
2254 *****************************************************************************/
2255 static HRESULT WINAPI
d3d_device3_Index(IDirect3DDevice3
*iface
, WORD index
)
2257 FIXME("iface %p, index %#x stub!\n", iface
, index
);
2262 static HRESULT WINAPI
d3d_device2_Index(IDirect3DDevice2
*iface
, WORD index
)
2264 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
2266 TRACE("iface %p, index %#x.\n", iface
, index
);
2268 return d3d_device3_Index(&device
->IDirect3DDevice3_iface
, index
);
2271 /*****************************************************************************
2272 * IDirect3DDevice7::GetRenderState
2274 * Returns the value of a render state. The possible render states are
2275 * defined in include/d3dtypes.h
2277 * Version 2, 3 and 7
2280 * RenderStateType: Render state to return the current setting of
2281 * Value: Address to store the value at
2284 * D3D_OK on success, for details see IWineD3DDevice::GetRenderState
2285 * DDERR_INVALIDPARAMS if Value == NULL
2287 *****************************************************************************/
2288 static HRESULT
d3d_device7_GetRenderState(IDirect3DDevice7
*iface
,
2289 D3DRENDERSTATETYPE state
, DWORD
*value
)
2291 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
2292 HRESULT hr
= D3D_OK
;
2294 TRACE("iface %p, state %#x, value %p.\n", iface
, state
, value
);
2297 return DDERR_INVALIDPARAMS
;
2299 wined3d_mutex_lock();
2302 case D3DRENDERSTATE_TEXTUREMAG
:
2304 enum wined3d_texture_filter_type tex_mag
;
2306 tex_mag
= wined3d_device_get_sampler_state(device
->wined3d_device
, 0, WINED3D_SAMP_MAG_FILTER
);
2309 case WINED3D_TEXF_POINT
:
2310 *value
= D3DFILTER_NEAREST
;
2312 case WINED3D_TEXF_LINEAR
:
2313 *value
= D3DFILTER_LINEAR
;
2316 ERR("Unhandled texture mag %d !\n",tex_mag
);
2322 case D3DRENDERSTATE_TEXTUREMIN
:
2324 enum wined3d_texture_filter_type tex_min
;
2325 enum wined3d_texture_filter_type tex_mip
;
2327 tex_min
= wined3d_device_get_sampler_state(device
->wined3d_device
, 0, WINED3D_SAMP_MIN_FILTER
);
2328 tex_mip
= wined3d_device_get_sampler_state(device
->wined3d_device
, 0, WINED3D_SAMP_MIP_FILTER
);
2331 case WINED3D_TEXF_POINT
:
2334 case WINED3D_TEXF_NONE
:
2335 *value
= D3DFILTER_NEAREST
;
2337 case WINED3D_TEXF_POINT
:
2338 *value
= D3DFILTER_MIPNEAREST
;
2340 case WINED3D_TEXF_LINEAR
:
2341 *value
= D3DFILTER_LINEARMIPNEAREST
;
2344 ERR("Unhandled mip filter %#x.\n", tex_mip
);
2345 *value
= D3DFILTER_NEAREST
;
2349 case WINED3D_TEXF_LINEAR
:
2352 case WINED3D_TEXF_NONE
:
2353 *value
= D3DFILTER_LINEAR
;
2355 case WINED3D_TEXF_POINT
:
2356 *value
= D3DFILTER_MIPLINEAR
;
2358 case WINED3D_TEXF_LINEAR
:
2359 *value
= D3DFILTER_LINEARMIPLINEAR
;
2362 ERR("Unhandled mip filter %#x.\n", tex_mip
);
2363 *value
= D3DFILTER_LINEAR
;
2368 ERR("Unhandled texture min filter %#x.\n",tex_min
);
2369 *value
= D3DFILTER_NEAREST
;
2375 case D3DRENDERSTATE_TEXTUREADDRESS
:
2376 case D3DRENDERSTATE_TEXTUREADDRESSU
:
2377 *value
= wined3d_device_get_sampler_state(device
->wined3d_device
, 0, WINED3D_SAMP_ADDRESS_U
);
2379 case D3DRENDERSTATE_TEXTUREADDRESSV
:
2380 *value
= wined3d_device_get_sampler_state(device
->wined3d_device
, 0, WINED3D_SAMP_ADDRESS_V
);
2383 case D3DRENDERSTATE_BORDERCOLOR
:
2384 FIXME("Unhandled render state D3DRENDERSTATE_BORDERCOLOR.\n");
2388 case D3DRENDERSTATE_TEXTUREHANDLE
:
2389 case D3DRENDERSTATE_TEXTUREMAPBLEND
:
2390 WARN("Render state %#x is invalid in d3d7.\n", state
);
2391 hr
= DDERR_INVALIDPARAMS
;
2394 case D3DRENDERSTATE_ZBIAS
:
2395 *value
= wined3d_device_get_render_state(device
->wined3d_device
, WINED3D_RS_DEPTHBIAS
);
2399 if (state
>= D3DRENDERSTATE_STIPPLEPATTERN00
2400 && state
<= D3DRENDERSTATE_STIPPLEPATTERN31
)
2402 FIXME("Unhandled stipple pattern render state (%#x).\n", state
);
2406 *value
= wined3d_device_get_render_state(device
->wined3d_device
, state
);
2408 wined3d_mutex_unlock();
2413 static HRESULT WINAPI
d3d_device7_GetRenderState_FPUSetup(IDirect3DDevice7
*iface
,
2414 D3DRENDERSTATETYPE state
, DWORD
*value
)
2416 return d3d_device7_GetRenderState(iface
, state
, value
);
2419 static HRESULT WINAPI
d3d_device7_GetRenderState_FPUPreserve(IDirect3DDevice7
*iface
,
2420 D3DRENDERSTATETYPE state
, DWORD
*value
)
2425 old_fpucw
= d3d_fpu_setup();
2426 hr
= d3d_device7_GetRenderState(iface
, state
, value
);
2427 set_fpu_control_word(old_fpucw
);
2432 static HRESULT WINAPI
d3d_device3_GetRenderState(IDirect3DDevice3
*iface
,
2433 D3DRENDERSTATETYPE state
, DWORD
*value
)
2435 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
2437 TRACE("iface %p, state %#x, value %p.\n", iface
, state
, value
);
2441 case D3DRENDERSTATE_TEXTUREHANDLE
:
2443 /* This state is wrapped to SetTexture in SetRenderState, so
2444 * it has to be wrapped to GetTexture here. */
2445 struct wined3d_texture
*tex
= NULL
;
2448 wined3d_mutex_lock();
2449 if ((tex
= wined3d_device_get_texture(device
->wined3d_device
, 0)))
2451 /* The parent of the texture is the IDirectDrawSurface7
2452 * interface of the ddraw surface. */
2453 struct ddraw_texture
*parent
= wined3d_texture_get_parent(tex
);
2455 *value
= parent
->root
->Handle
;
2457 wined3d_mutex_unlock();
2462 case D3DRENDERSTATE_TEXTUREMAPBLEND
:
2464 /* D3DRENDERSTATE_TEXTUREMAPBLEND is mapped to texture state stages in SetRenderState; reverse
2465 the mapping to get the value. */
2466 DWORD colorop
, colorarg1
, colorarg2
;
2467 DWORD alphaop
, alphaarg1
, alphaarg2
;
2469 wined3d_mutex_lock();
2471 device
->legacyTextureBlending
= TRUE
;
2473 colorop
= wined3d_device_get_texture_stage_state(device
->wined3d_device
, 0, WINED3D_TSS_COLOR_OP
);
2474 colorarg1
= wined3d_device_get_texture_stage_state(device
->wined3d_device
, 0, WINED3D_TSS_COLOR_ARG1
);
2475 colorarg2
= wined3d_device_get_texture_stage_state(device
->wined3d_device
, 0, WINED3D_TSS_COLOR_ARG2
);
2476 alphaop
= wined3d_device_get_texture_stage_state(device
->wined3d_device
, 0, WINED3D_TSS_ALPHA_OP
);
2477 alphaarg1
= wined3d_device_get_texture_stage_state(device
->wined3d_device
, 0, WINED3D_TSS_ALPHA_ARG1
);
2478 alphaarg2
= wined3d_device_get_texture_stage_state(device
->wined3d_device
, 0, WINED3D_TSS_ALPHA_ARG2
);
2480 if (colorop
== WINED3D_TOP_SELECT_ARG1
&& colorarg1
== WINED3DTA_TEXTURE
2481 && alphaop
== WINED3D_TOP_SELECT_ARG1
&& alphaarg1
== WINED3DTA_TEXTURE
)
2482 *value
= D3DTBLEND_DECAL
;
2483 else if (colorop
== WINED3D_TOP_SELECT_ARG1
&& colorarg1
== WINED3DTA_TEXTURE
2484 && alphaop
== WINED3D_TOP_MODULATE
2485 && alphaarg1
== WINED3DTA_TEXTURE
&& alphaarg2
== WINED3DTA_CURRENT
)
2486 *value
= D3DTBLEND_DECALALPHA
;
2487 else if (colorop
== WINED3D_TOP_MODULATE
2488 && colorarg1
== WINED3DTA_TEXTURE
&& colorarg2
== WINED3DTA_CURRENT
2489 && alphaop
== WINED3D_TOP_MODULATE
2490 && alphaarg1
== WINED3DTA_TEXTURE
&& alphaarg2
== WINED3DTA_CURRENT
)
2491 *value
= D3DTBLEND_MODULATEALPHA
;
2494 struct wined3d_texture
*tex
= NULL
;
2495 BOOL tex_alpha
= FALSE
;
2496 DDPIXELFORMAT ddfmt
;
2498 if ((tex
= wined3d_device_get_texture(device
->wined3d_device
, 0)))
2500 struct wined3d_resource
*sub_resource
;
2502 if ((sub_resource
= wined3d_texture_get_sub_resource(tex
, 0)))
2504 struct wined3d_resource_desc desc
;
2506 wined3d_resource_get_desc(sub_resource
, &desc
);
2507 ddfmt
.dwSize
= sizeof(ddfmt
);
2508 ddrawformat_from_wined3dformat(&ddfmt
, desc
.format
);
2509 if (ddfmt
.u5
.dwRGBAlphaBitMask
) tex_alpha
= TRUE
;
2513 if (!(colorop
== WINED3D_TOP_MODULATE
2514 && colorarg1
== WINED3DTA_TEXTURE
&& colorarg2
== WINED3DTA_CURRENT
2515 && alphaop
== (tex_alpha
? WINED3D_TOP_SELECT_ARG1
: WINED3D_TOP_SELECT_ARG2
)
2516 && alphaarg1
== WINED3DTA_TEXTURE
&& alphaarg2
== WINED3DTA_CURRENT
))
2517 ERR("Unexpected texture stage state setup, returning D3DTBLEND_MODULATE - likely erroneous.\n");
2519 *value
= D3DTBLEND_MODULATE
;
2522 wined3d_mutex_unlock();
2527 case D3DRENDERSTATE_LIGHTING
:
2528 *value
= 0xffffffff;
2532 return IDirect3DDevice7_GetRenderState(&device
->IDirect3DDevice7_iface
, state
, value
);
2536 static HRESULT WINAPI
d3d_device2_GetRenderState(IDirect3DDevice2
*iface
,
2537 D3DRENDERSTATETYPE state
, DWORD
*value
)
2539 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
2541 TRACE("iface %p, state %#x, value %p.\n", iface
, state
, value
);
2543 return IDirect3DDevice3_GetRenderState(&device
->IDirect3DDevice3_iface
, state
, value
);
2546 /*****************************************************************************
2547 * IDirect3DDevice7::SetRenderState
2549 * Sets a render state. The possible render states are defined in
2550 * include/d3dtypes.h
2552 * Version 2, 3 and 7
2555 * RenderStateType: State to set
2556 * Value: Value to assign to that state
2559 * D3D_OK on success,
2560 * for details see IWineD3DDevice::SetRenderState
2562 *****************************************************************************/
2563 static HRESULT
d3d_device7_SetRenderState(IDirect3DDevice7
*iface
,
2564 D3DRENDERSTATETYPE state
, DWORD value
)
2566 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
2567 HRESULT hr
= D3D_OK
;
2569 TRACE("iface %p, state %#x, value %#x.\n", iface
, state
, value
);
2571 wined3d_mutex_lock();
2572 /* Some render states need special care */
2576 * The ddraw texture filter mapping works like this:
2577 * D3DFILTER_NEAREST Point min/mag, no mip
2578 * D3DFILTER_MIPNEAREST Point min/mag, point mip
2579 * D3DFILTER_LINEARMIPNEAREST: Point min/mag, linear mip
2581 * D3DFILTER_LINEAR Linear min/mag, no mip
2582 * D3DFILTER_MIPLINEAR Linear min/mag, point mip
2583 * D3DFILTER_LINEARMIPLINEAR Linear min/mag, linear mip
2585 * This is the opposite of the GL naming convention,
2586 * D3DFILTER_LINEARMIPNEAREST corresponds to GL_NEAREST_MIPMAP_LINEAR.
2588 case D3DRENDERSTATE_TEXTUREMAG
:
2590 enum wined3d_texture_filter_type tex_mag
;
2594 case D3DFILTER_NEAREST
:
2595 case D3DFILTER_MIPNEAREST
:
2596 case D3DFILTER_LINEARMIPNEAREST
:
2597 tex_mag
= WINED3D_TEXF_POINT
;
2599 case D3DFILTER_LINEAR
:
2600 case D3DFILTER_MIPLINEAR
:
2601 case D3DFILTER_LINEARMIPLINEAR
:
2602 tex_mag
= WINED3D_TEXF_LINEAR
;
2605 tex_mag
= WINED3D_TEXF_POINT
;
2606 FIXME("Unhandled texture mag %#x.\n", value
);
2610 wined3d_device_set_sampler_state(device
->wined3d_device
, 0, WINED3D_SAMP_MAG_FILTER
, tex_mag
);
2614 case D3DRENDERSTATE_TEXTUREMIN
:
2616 enum wined3d_texture_filter_type tex_min
;
2617 enum wined3d_texture_filter_type tex_mip
;
2621 case D3DFILTER_NEAREST
:
2622 tex_min
= WINED3D_TEXF_POINT
;
2623 tex_mip
= WINED3D_TEXF_NONE
;
2625 case D3DFILTER_LINEAR
:
2626 tex_min
= WINED3D_TEXF_LINEAR
;
2627 tex_mip
= WINED3D_TEXF_NONE
;
2629 case D3DFILTER_MIPNEAREST
:
2630 tex_min
= WINED3D_TEXF_POINT
;
2631 tex_mip
= WINED3D_TEXF_POINT
;
2633 case D3DFILTER_MIPLINEAR
:
2634 tex_min
= WINED3D_TEXF_LINEAR
;
2635 tex_mip
= WINED3D_TEXF_POINT
;
2637 case D3DFILTER_LINEARMIPNEAREST
:
2638 tex_min
= WINED3D_TEXF_POINT
;
2639 tex_mip
= WINED3D_TEXF_LINEAR
;
2641 case D3DFILTER_LINEARMIPLINEAR
:
2642 tex_min
= WINED3D_TEXF_LINEAR
;
2643 tex_mip
= WINED3D_TEXF_LINEAR
;
2647 FIXME("Unhandled texture min %#x.\n",value
);
2648 tex_min
= WINED3D_TEXF_POINT
;
2649 tex_mip
= WINED3D_TEXF_NONE
;
2653 wined3d_device_set_sampler_state(device
->wined3d_device
,
2654 0, WINED3D_SAMP_MIP_FILTER
, tex_mip
);
2655 wined3d_device_set_sampler_state(device
->wined3d_device
,
2656 0, WINED3D_SAMP_MIN_FILTER
, tex_min
);
2660 case D3DRENDERSTATE_TEXTUREADDRESS
:
2661 wined3d_device_set_sampler_state(device
->wined3d_device
,
2662 0, WINED3D_SAMP_ADDRESS_V
, value
);
2664 case D3DRENDERSTATE_TEXTUREADDRESSU
:
2665 wined3d_device_set_sampler_state(device
->wined3d_device
,
2666 0, WINED3D_SAMP_ADDRESS_U
, value
);
2668 case D3DRENDERSTATE_TEXTUREADDRESSV
:
2669 wined3d_device_set_sampler_state(device
->wined3d_device
,
2670 0, WINED3D_SAMP_ADDRESS_V
, value
);
2673 case D3DRENDERSTATE_BORDERCOLOR
:
2674 /* This should probably just forward to the corresponding sampler
2675 * state. Needs tests. */
2676 FIXME("Unhandled render state D3DRENDERSTATE_BORDERCOLOR.\n");
2680 case D3DRENDERSTATE_TEXTUREHANDLE
:
2681 case D3DRENDERSTATE_TEXTUREMAPBLEND
:
2682 WARN("Render state %#x is invalid in d3d7.\n", state
);
2683 hr
= DDERR_INVALIDPARAMS
;
2686 case D3DRENDERSTATE_ZBIAS
:
2687 wined3d_device_set_render_state(device
->wined3d_device
, WINED3D_RS_DEPTHBIAS
, value
);
2691 if (state
>= D3DRENDERSTATE_STIPPLEPATTERN00
2692 && state
<= D3DRENDERSTATE_STIPPLEPATTERN31
)
2694 FIXME("Unhandled stipple pattern render state (%#x).\n", state
);
2699 wined3d_device_set_render_state(device
->wined3d_device
, state
, value
);
2702 wined3d_mutex_unlock();
2707 static HRESULT WINAPI
d3d_device7_SetRenderState_FPUSetup(IDirect3DDevice7
*iface
,
2708 D3DRENDERSTATETYPE state
, DWORD value
)
2710 return d3d_device7_SetRenderState(iface
, state
, value
);
2713 static HRESULT WINAPI
d3d_device7_SetRenderState_FPUPreserve(IDirect3DDevice7
*iface
,
2714 D3DRENDERSTATETYPE state
, DWORD value
)
2719 old_fpucw
= d3d_fpu_setup();
2720 hr
= d3d_device7_SetRenderState(iface
, state
, value
);
2721 set_fpu_control_word(old_fpucw
);
2726 static HRESULT WINAPI
d3d_device3_SetRenderState(IDirect3DDevice3
*iface
,
2727 D3DRENDERSTATETYPE state
, DWORD value
)
2729 /* Note about D3DRENDERSTATE_TEXTUREMAPBLEND implementation: most of values
2730 for this state can be directly mapped to texture stage colorop and alphaop, but
2731 D3DTBLEND_MODULATE is tricky: it uses alpha from texture when available and alpha
2732 from diffuse otherwise. So changing the texture must be monitored in SetTexture to modify
2733 alphaarg when needed.
2735 Aliens vs Predator 1 depends on accurate D3DTBLEND_MODULATE emulation
2737 Legacy texture blending (TEXTUREMAPBLEND) and texture stage states: directx6 docs state that
2738 TEXTUREMAPBLEND is deprecated, yet can still be used. Games must not use both or results
2739 are undefined. D3DTBLEND_MODULATE mode in particular is dependent on texture pixel format and
2740 requires fixup of stage 0 texture states when texture changes, but this fixup can interfere
2741 with games not using this deprecated state. So a flag 'legacyTextureBlending' has to be kept
2742 in device - TRUE if the app is using TEXTUREMAPBLEND.
2744 Tests show that setting TEXTUREMAPBLEND on native doesn't seem to change values returned by
2745 GetTextureStageState and vice versa. Not so on Wine, but it is 'undefined' anyway so, probably, ok,
2746 unless some broken game will be found that cares. */
2748 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
2751 TRACE("iface %p, state %#x, value %#x.\n", iface
, state
, value
);
2753 wined3d_mutex_lock();
2757 case D3DRENDERSTATE_TEXTUREHANDLE
:
2759 struct ddraw_surface
*surf
;
2763 hr
= wined3d_device_set_texture(device
->wined3d_device
, 0, NULL
);
2767 surf
= ddraw_get_object(&device
->handle_table
, value
- 1, DDRAW_HANDLE_SURFACE
);
2770 WARN("Invalid texture handle.\n");
2771 hr
= DDERR_INVALIDPARAMS
;
2775 hr
= IDirect3DDevice3_SetTexture(iface
, 0, &surf
->IDirect3DTexture2_iface
);
2779 case D3DRENDERSTATE_TEXTUREMAPBLEND
:
2781 device
->legacyTextureBlending
= TRUE
;
2785 case D3DTBLEND_MODULATE
:
2787 struct wined3d_texture
*tex
= NULL
;
2788 BOOL tex_alpha
= FALSE
;
2789 DDPIXELFORMAT ddfmt
;
2791 if ((tex
= wined3d_device_get_texture(device
->wined3d_device
, 0)))
2793 struct wined3d_resource
*sub_resource
;
2795 if ((sub_resource
= wined3d_texture_get_sub_resource(tex
, 0)))
2797 struct wined3d_resource_desc desc
;
2799 wined3d_resource_get_desc(sub_resource
, &desc
);
2800 ddfmt
.dwSize
= sizeof(ddfmt
);
2801 ddrawformat_from_wined3dformat(&ddfmt
, desc
.format
);
2802 if (ddfmt
.u5
.dwRGBAlphaBitMask
) tex_alpha
= TRUE
;
2807 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
2808 0, WINED3D_TSS_ALPHA_OP
, WINED3D_TOP_SELECT_ARG1
);
2810 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
2811 0, WINED3D_TSS_ALPHA_OP
, WINED3D_TOP_SELECT_ARG2
);
2812 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
2813 0, WINED3D_TSS_ALPHA_ARG1
, WINED3DTA_TEXTURE
);
2814 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
2815 0, WINED3D_TSS_ALPHA_ARG2
, WINED3DTA_CURRENT
);
2816 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
2817 0, WINED3D_TSS_COLOR_ARG1
, WINED3DTA_TEXTURE
);
2818 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
2819 0, WINED3D_TSS_COLOR_ARG2
, WINED3DTA_CURRENT
);
2820 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
2821 0, WINED3D_TSS_COLOR_OP
, WINED3D_TOP_MODULATE
);
2826 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
2827 0, WINED3D_TSS_COLOR_OP
, WINED3D_TOP_ADD
);
2828 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
2829 0, WINED3D_TSS_COLOR_ARG1
, WINED3DTA_TEXTURE
);
2830 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
2831 0, WINED3D_TSS_COLOR_ARG2
, WINED3DTA_CURRENT
);
2832 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
2833 0, WINED3D_TSS_ALPHA_OP
, WINED3D_TOP_SELECT_ARG2
);
2834 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
2835 0, WINED3D_TSS_ALPHA_ARG2
, WINED3DTA_CURRENT
);
2838 case D3DTBLEND_MODULATEALPHA
:
2839 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
2840 0, WINED3D_TSS_COLOR_ARG1
, WINED3DTA_TEXTURE
);
2841 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
2842 0, WINED3D_TSS_ALPHA_ARG1
, WINED3DTA_TEXTURE
);
2843 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
2844 0, WINED3D_TSS_COLOR_ARG2
, WINED3DTA_CURRENT
);
2845 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
2846 0, WINED3D_TSS_ALPHA_ARG2
, WINED3DTA_CURRENT
);
2847 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
2848 0, WINED3D_TSS_COLOR_OP
, WINED3D_TOP_MODULATE
);
2849 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
2850 0, WINED3D_TSS_ALPHA_OP
, WINED3D_TOP_MODULATE
);
2853 case D3DTBLEND_COPY
:
2854 case D3DTBLEND_DECAL
:
2855 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
2856 0, WINED3D_TSS_COLOR_ARG1
, WINED3DTA_TEXTURE
);
2857 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
2858 0, WINED3D_TSS_ALPHA_ARG1
, WINED3DTA_TEXTURE
);
2859 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
2860 0, WINED3D_TSS_COLOR_OP
, WINED3D_TOP_SELECT_ARG1
);
2861 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
2862 0, WINED3D_TSS_ALPHA_OP
, WINED3D_TOP_SELECT_ARG1
);
2865 case D3DTBLEND_DECALALPHA
:
2866 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
2867 0, WINED3D_TSS_COLOR_OP
, WINED3D_TOP_BLEND_TEXTURE_ALPHA
);
2868 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
2869 0, WINED3D_TSS_COLOR_ARG1
, WINED3DTA_TEXTURE
);
2870 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
2871 0, WINED3D_TSS_COLOR_ARG2
, WINED3DTA_CURRENT
);
2872 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
2873 0, WINED3D_TSS_ALPHA_OP
, WINED3D_TOP_SELECT_ARG2
);
2874 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
2875 0, WINED3D_TSS_ALPHA_ARG2
, WINED3DTA_CURRENT
);
2879 FIXME("Unhandled texture environment %#x.\n", value
);
2886 case D3DRENDERSTATE_LIGHTING
:
2891 hr
= IDirect3DDevice7_SetRenderState(&device
->IDirect3DDevice7_iface
, state
, value
);
2894 wined3d_mutex_unlock();
2899 static HRESULT WINAPI
d3d_device2_SetRenderState(IDirect3DDevice2
*iface
,
2900 D3DRENDERSTATETYPE state
, DWORD value
)
2902 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
2904 TRACE("iface %p, state %#x, value %#x.\n", iface
, state
, value
);
2906 return IDirect3DDevice3_SetRenderState(&device
->IDirect3DDevice3_iface
, state
, value
);
2909 /*****************************************************************************
2910 * Direct3DDevice3::SetLightState
2912 * Sets a light state for Direct3DDevice3 and Direct3DDevice2. The
2913 * light states are forwarded to Direct3DDevice7 render states
2918 * LightStateType: The light state to change
2919 * Value: The value to assign to that light state
2923 * DDERR_INVALIDPARAMS if the parameters were incorrect
2924 * Also check IDirect3DDevice7::SetRenderState
2926 *****************************************************************************/
2927 static HRESULT WINAPI
d3d_device3_SetLightState(IDirect3DDevice3
*iface
,
2928 D3DLIGHTSTATETYPE state
, DWORD value
)
2930 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
2933 TRACE("iface %p, state %#x, value %#x.\n", iface
, state
, value
);
2935 if (!state
|| (state
> D3DLIGHTSTATE_COLORVERTEX
))
2937 TRACE("Unexpected Light State Type\n");
2938 return DDERR_INVALIDPARAMS
;
2941 wined3d_mutex_lock();
2942 if (state
== D3DLIGHTSTATE_MATERIAL
)
2944 struct d3d_material
*m
= ddraw_get_object(&device
->handle_table
, value
- 1, DDRAW_HANDLE_MATERIAL
);
2947 WARN("Invalid material handle.\n");
2948 wined3d_mutex_unlock();
2949 return DDERR_INVALIDPARAMS
;
2952 TRACE(" activating material %p.\n", m
);
2953 material_activate(m
);
2955 device
->material
= value
;
2957 else if (state
== D3DLIGHTSTATE_COLORMODEL
)
2962 ERR("DDCOLOR_MONO should not happen!\n");
2965 /* We are already in this mode */
2966 TRACE("Setting color model to RGB (no-op).\n");
2969 ERR("Unknown color model!\n");
2970 wined3d_mutex_unlock();
2971 return DDERR_INVALIDPARAMS
;
2976 D3DRENDERSTATETYPE rs
;
2979 case D3DLIGHTSTATE_AMBIENT
: /* 2 */
2980 rs
= D3DRENDERSTATE_AMBIENT
;
2982 case D3DLIGHTSTATE_FOGMODE
: /* 4 */
2983 rs
= D3DRENDERSTATE_FOGVERTEXMODE
;
2985 case D3DLIGHTSTATE_FOGSTART
: /* 5 */
2986 rs
= D3DRENDERSTATE_FOGSTART
;
2988 case D3DLIGHTSTATE_FOGEND
: /* 6 */
2989 rs
= D3DRENDERSTATE_FOGEND
;
2991 case D3DLIGHTSTATE_FOGDENSITY
: /* 7 */
2992 rs
= D3DRENDERSTATE_FOGDENSITY
;
2994 case D3DLIGHTSTATE_COLORVERTEX
: /* 8 */
2995 rs
= D3DRENDERSTATE_COLORVERTEX
;
2998 FIXME("Unhandled D3DLIGHTSTATETYPE %#x.\n", state
);
2999 wined3d_mutex_unlock();
3000 return DDERR_INVALIDPARAMS
;
3003 hr
= IDirect3DDevice7_SetRenderState(&device
->IDirect3DDevice7_iface
, rs
, value
);
3004 wined3d_mutex_unlock();
3007 wined3d_mutex_unlock();
3012 static HRESULT WINAPI
d3d_device2_SetLightState(IDirect3DDevice2
*iface
,
3013 D3DLIGHTSTATETYPE state
, DWORD value
)
3015 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
3017 TRACE("iface %p, state %#x, value %#x.\n", iface
, state
, value
);
3019 return d3d_device3_SetLightState(&device
->IDirect3DDevice3_iface
, state
, value
);
3022 /*****************************************************************************
3023 * IDirect3DDevice3::GetLightState
3025 * Returns the current setting of a light state. The state is read from
3026 * the Direct3DDevice7 render state.
3031 * LightStateType: The light state to return
3032 * Value: The address to store the light state setting at
3036 * DDDERR_INVALIDPARAMS if the parameters were incorrect
3037 * Also see IDirect3DDevice7::GetRenderState
3039 *****************************************************************************/
3040 static HRESULT WINAPI
d3d_device3_GetLightState(IDirect3DDevice3
*iface
,
3041 D3DLIGHTSTATETYPE state
, DWORD
*value
)
3043 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
3046 TRACE("iface %p, state %#x, value %p.\n", iface
, state
, value
);
3048 if (!state
|| (state
> D3DLIGHTSTATE_COLORVERTEX
))
3050 TRACE("Unexpected Light State Type\n");
3051 return DDERR_INVALIDPARAMS
;
3055 return DDERR_INVALIDPARAMS
;
3057 wined3d_mutex_lock();
3058 if (state
== D3DLIGHTSTATE_MATERIAL
)
3060 *value
= device
->material
;
3062 else if (state
== D3DLIGHTSTATE_COLORMODEL
)
3064 *value
= D3DCOLOR_RGB
;
3068 D3DRENDERSTATETYPE rs
;
3071 case D3DLIGHTSTATE_AMBIENT
: /* 2 */
3072 rs
= D3DRENDERSTATE_AMBIENT
;
3074 case D3DLIGHTSTATE_FOGMODE
: /* 4 */
3075 rs
= D3DRENDERSTATE_FOGVERTEXMODE
;
3077 case D3DLIGHTSTATE_FOGSTART
: /* 5 */
3078 rs
= D3DRENDERSTATE_FOGSTART
;
3080 case D3DLIGHTSTATE_FOGEND
: /* 6 */
3081 rs
= D3DRENDERSTATE_FOGEND
;
3083 case D3DLIGHTSTATE_FOGDENSITY
: /* 7 */
3084 rs
= D3DRENDERSTATE_FOGDENSITY
;
3086 case D3DLIGHTSTATE_COLORVERTEX
: /* 8 */
3087 rs
= D3DRENDERSTATE_COLORVERTEX
;
3090 FIXME("Unhandled D3DLIGHTSTATETYPE %#x.\n", state
);
3091 wined3d_mutex_unlock();
3092 return DDERR_INVALIDPARAMS
;
3095 hr
= IDirect3DDevice7_GetRenderState(&device
->IDirect3DDevice7_iface
, rs
, value
);
3096 wined3d_mutex_unlock();
3099 wined3d_mutex_unlock();
3104 static HRESULT WINAPI
d3d_device2_GetLightState(IDirect3DDevice2
*iface
,
3105 D3DLIGHTSTATETYPE state
, DWORD
*value
)
3107 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
3109 TRACE("iface %p, state %#x, value %p.\n", iface
, state
, value
);
3111 return d3d_device3_GetLightState(&device
->IDirect3DDevice3_iface
, state
, value
);
3114 /*****************************************************************************
3115 * IDirect3DDevice7::SetTransform
3117 * Assigns a D3DMATRIX to a transform type. The transform types are defined
3118 * in include/d3dtypes.h.
3119 * The D3DTRANSFORMSTATE_WORLD (=1) is translated to D3DTS_WORLDMATRIX(0)
3120 * (=255) for wined3d, because the 1 transform state was removed in d3d8
3121 * and WineD3D already understands the replacement D3DTS_WORLDMATRIX(0)
3123 * Version 2, 3 and 7
3126 * TransformStateType: transform state to set
3127 * Matrix: Matrix to assign to the state
3131 * DDERR_INVALIDPARAMS if Matrix == NULL
3132 * For details see IWineD3DDevice::SetTransform
3134 *****************************************************************************/
3135 static HRESULT
d3d_device7_SetTransform(IDirect3DDevice7
*iface
,
3136 D3DTRANSFORMSTATETYPE state
, D3DMATRIX
*matrix
)
3138 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
3139 enum wined3d_transform_state wined3d_state
;
3141 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
3145 case D3DTRANSFORMSTATE_WORLD
:
3146 wined3d_state
= WINED3D_TS_WORLD_MATRIX(0);
3148 case D3DTRANSFORMSTATE_WORLD1
:
3149 wined3d_state
= WINED3D_TS_WORLD_MATRIX(1);
3151 case D3DTRANSFORMSTATE_WORLD2
:
3152 wined3d_state
= WINED3D_TS_WORLD_MATRIX(2);
3154 case D3DTRANSFORMSTATE_WORLD3
:
3155 wined3d_state
= WINED3D_TS_WORLD_MATRIX(3);
3158 wined3d_state
= state
;
3162 return DDERR_INVALIDPARAMS
;
3164 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
3165 wined3d_mutex_lock();
3166 wined3d_device_set_transform(device
->wined3d_device
, wined3d_state
, (struct wined3d_matrix
*)matrix
);
3167 wined3d_mutex_unlock();
3172 static HRESULT WINAPI
d3d_device7_SetTransform_FPUSetup(IDirect3DDevice7
*iface
,
3173 D3DTRANSFORMSTATETYPE state
, D3DMATRIX
*matrix
)
3175 return d3d_device7_SetTransform(iface
, state
, matrix
);
3178 static HRESULT WINAPI
d3d_device7_SetTransform_FPUPreserve(IDirect3DDevice7
*iface
,
3179 D3DTRANSFORMSTATETYPE state
, D3DMATRIX
*matrix
)
3184 old_fpucw
= d3d_fpu_setup();
3185 hr
= d3d_device7_SetTransform(iface
, state
, matrix
);
3186 set_fpu_control_word(old_fpucw
);
3191 static HRESULT WINAPI
d3d_device3_SetTransform(IDirect3DDevice3
*iface
,
3192 D3DTRANSFORMSTATETYPE state
, D3DMATRIX
*matrix
)
3194 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
3196 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
3199 return DDERR_INVALIDPARAMS
;
3201 if (state
== D3DTRANSFORMSTATE_PROJECTION
)
3203 D3DMATRIX projection
;
3205 wined3d_mutex_lock();
3206 multiply_matrix(&projection
, &device
->legacy_clipspace
, matrix
);
3207 wined3d_device_set_transform(device
->wined3d_device
,
3208 WINED3D_TS_PROJECTION
, (struct wined3d_matrix
*)&projection
);
3209 device
->legacy_projection
= *matrix
;
3210 wined3d_mutex_unlock();
3215 return IDirect3DDevice7_SetTransform(&device
->IDirect3DDevice7_iface
, state
, matrix
);
3218 static HRESULT WINAPI
d3d_device2_SetTransform(IDirect3DDevice2
*iface
,
3219 D3DTRANSFORMSTATETYPE state
, D3DMATRIX
*matrix
)
3221 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
3223 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
3225 return IDirect3DDevice7_SetTransform(&device
->IDirect3DDevice7_iface
, state
, matrix
);
3228 /*****************************************************************************
3229 * IDirect3DDevice7::GetTransform
3231 * Returns the matrix assigned to a transform state
3232 * D3DTRANSFORMSTATE_WORLD is translated to D3DTS_WORLDMATRIX(0), see
3236 * TransformStateType: State to read the matrix from
3237 * Matrix: Address to store the matrix at
3241 * DDERR_INVALIDPARAMS if Matrix == NULL
3242 * For details, see IWineD3DDevice::GetTransform
3244 *****************************************************************************/
3245 static HRESULT
d3d_device7_GetTransform(IDirect3DDevice7
*iface
,
3246 D3DTRANSFORMSTATETYPE state
, D3DMATRIX
*matrix
)
3248 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
3249 enum wined3d_transform_state wined3d_state
;
3251 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
3255 case D3DTRANSFORMSTATE_WORLD
:
3256 wined3d_state
= WINED3D_TS_WORLD_MATRIX(0);
3258 case D3DTRANSFORMSTATE_WORLD1
:
3259 wined3d_state
= WINED3D_TS_WORLD_MATRIX(1);
3261 case D3DTRANSFORMSTATE_WORLD2
:
3262 wined3d_state
= WINED3D_TS_WORLD_MATRIX(2);
3264 case D3DTRANSFORMSTATE_WORLD3
:
3265 wined3d_state
= WINED3D_TS_WORLD_MATRIX(3);
3268 wined3d_state
= state
;
3272 return DDERR_INVALIDPARAMS
;
3274 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
3275 wined3d_mutex_lock();
3276 wined3d_device_get_transform(device
->wined3d_device
, wined3d_state
, (struct wined3d_matrix
*)matrix
);
3277 wined3d_mutex_unlock();
3282 static HRESULT WINAPI
d3d_device7_GetTransform_FPUSetup(IDirect3DDevice7
*iface
,
3283 D3DTRANSFORMSTATETYPE state
, D3DMATRIX
*matrix
)
3285 return d3d_device7_GetTransform(iface
, state
, matrix
);
3288 static HRESULT WINAPI
d3d_device7_GetTransform_FPUPreserve(IDirect3DDevice7
*iface
,
3289 D3DTRANSFORMSTATETYPE state
, D3DMATRIX
*matrix
)
3294 old_fpucw
= d3d_fpu_setup();
3295 hr
= d3d_device7_GetTransform(iface
, state
, matrix
);
3296 set_fpu_control_word(old_fpucw
);
3301 static HRESULT WINAPI
d3d_device3_GetTransform(IDirect3DDevice3
*iface
,
3302 D3DTRANSFORMSTATETYPE state
, D3DMATRIX
*matrix
)
3304 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
3306 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
3309 return DDERR_INVALIDPARAMS
;
3311 if (state
== D3DTRANSFORMSTATE_PROJECTION
)
3313 wined3d_mutex_lock();
3314 *matrix
= device
->legacy_projection
;
3315 wined3d_mutex_unlock();
3319 return IDirect3DDevice7_GetTransform(&device
->IDirect3DDevice7_iface
, state
, matrix
);
3322 static HRESULT WINAPI
d3d_device2_GetTransform(IDirect3DDevice2
*iface
,
3323 D3DTRANSFORMSTATETYPE state
, D3DMATRIX
*matrix
)
3325 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
3327 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
3329 return IDirect3DDevice7_GetTransform(&device
->IDirect3DDevice7_iface
, state
, matrix
);
3332 /*****************************************************************************
3333 * IDirect3DDevice7::MultiplyTransform
3335 * Multiplies the already-set transform matrix of a transform state
3336 * with another matrix. For the world matrix, see SetTransform
3338 * Version 2, 3 and 7
3341 * TransformStateType: Transform state to multiply
3342 * D3DMatrix Matrix to multiply with.
3346 * DDERR_INVALIDPARAMS if D3DMatrix is NULL
3347 * For details, see IWineD3DDevice::MultiplyTransform
3349 *****************************************************************************/
3350 static HRESULT
d3d_device7_MultiplyTransform(IDirect3DDevice7
*iface
,
3351 D3DTRANSFORMSTATETYPE state
, D3DMATRIX
*matrix
)
3353 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
3354 enum wined3d_transform_state wined3d_state
;
3356 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
3360 case D3DTRANSFORMSTATE_WORLD
:
3361 wined3d_state
= WINED3D_TS_WORLD_MATRIX(0);
3363 case D3DTRANSFORMSTATE_WORLD1
:
3364 wined3d_state
= WINED3D_TS_WORLD_MATRIX(1);
3366 case D3DTRANSFORMSTATE_WORLD2
:
3367 wined3d_state
= WINED3D_TS_WORLD_MATRIX(2);
3369 case D3DTRANSFORMSTATE_WORLD3
:
3370 wined3d_state
= WINED3D_TS_WORLD_MATRIX(3);
3373 wined3d_state
= state
;
3376 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
3377 wined3d_mutex_lock();
3378 wined3d_device_multiply_transform(device
->wined3d_device
,
3379 wined3d_state
, (struct wined3d_matrix
*)matrix
);
3380 wined3d_mutex_unlock();
3385 static HRESULT WINAPI
d3d_device7_MultiplyTransform_FPUSetup(IDirect3DDevice7
*iface
,
3386 D3DTRANSFORMSTATETYPE state
, D3DMATRIX
*matrix
)
3388 return d3d_device7_MultiplyTransform(iface
, state
, matrix
);
3391 static HRESULT WINAPI
d3d_device7_MultiplyTransform_FPUPreserve(IDirect3DDevice7
*iface
,
3392 D3DTRANSFORMSTATETYPE state
, D3DMATRIX
*matrix
)
3397 old_fpucw
= d3d_fpu_setup();
3398 hr
= d3d_device7_MultiplyTransform(iface
, state
, matrix
);
3399 set_fpu_control_word(old_fpucw
);
3404 static HRESULT WINAPI
d3d_device3_MultiplyTransform(IDirect3DDevice3
*iface
,
3405 D3DTRANSFORMSTATETYPE state
, D3DMATRIX
*matrix
)
3407 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
3409 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
3411 if (state
== D3DTRANSFORMSTATE_PROJECTION
)
3413 D3DMATRIX projection
, tmp
;
3415 wined3d_mutex_lock();
3416 multiply_matrix(&tmp
, &device
->legacy_projection
, matrix
);
3417 multiply_matrix(&projection
, &device
->legacy_clipspace
, &tmp
);
3418 wined3d_device_set_transform(device
->wined3d_device
,
3419 WINED3D_TS_PROJECTION
, (struct wined3d_matrix
*)&projection
);
3420 device
->legacy_projection
= tmp
;
3421 wined3d_mutex_unlock();
3426 return IDirect3DDevice7_MultiplyTransform(&device
->IDirect3DDevice7_iface
, state
, matrix
);
3429 static HRESULT WINAPI
d3d_device2_MultiplyTransform(IDirect3DDevice2
*iface
,
3430 D3DTRANSFORMSTATETYPE state
, D3DMATRIX
*matrix
)
3432 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
3434 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
3436 return IDirect3DDevice7_MultiplyTransform(&device
->IDirect3DDevice7_iface
, state
, matrix
);
3439 /*****************************************************************************
3440 * IDirect3DDevice7::DrawPrimitive
3442 * Draws primitives based on vertices in an application-provided pointer
3444 * Version 2, 3 and 7. The IDirect3DDevice2 thunk converts the fixed vertex type into
3445 * an FVF format for D3D7
3448 * PrimitiveType: The type of the primitives to draw
3449 * Vertex type: Flexible vertex format vertex description
3450 * Vertices: Pointer to the vertex array
3451 * VertexCount: The number of vertices to draw
3452 * Flags: As usual a few flags
3456 * DDERR_INVALIDPARAMS if Vertices is NULL
3457 * For details, see IWineD3DDevice::DrawPrimitiveUP
3459 *****************************************************************************/
3461 /* The caller is responsible for wined3d locking */
3462 static HRESULT
d3d_device_prepare_vertex_buffer(struct d3d_device
*device
, UINT min_size
)
3466 if (device
->vertex_buffer_size
< min_size
|| !device
->vertex_buffer
)
3468 UINT size
= max(device
->vertex_buffer_size
* 2, min_size
);
3469 struct wined3d_buffer
*buffer
;
3471 TRACE("Growing vertex buffer to %u bytes\n", size
);
3473 hr
= wined3d_buffer_create_vb(device
->wined3d_device
, size
, WINED3DUSAGE_DYNAMIC
| WINED3DUSAGE_WRITEONLY
,
3474 WINED3D_POOL_DEFAULT
, NULL
, &ddraw_null_wined3d_parent_ops
, &buffer
);
3477 ERR("(%p) wined3d_buffer_create_vb failed with hr = %08x\n", device
, hr
);
3481 if (device
->vertex_buffer
)
3482 wined3d_buffer_decref(device
->vertex_buffer
);
3484 device
->vertex_buffer
= buffer
;
3485 device
->vertex_buffer_size
= size
;
3486 device
->vertex_buffer_pos
= 0;
3491 static HRESULT
d3d_device7_DrawPrimitive(IDirect3DDevice7
*iface
,
3492 D3DPRIMITIVETYPE primitive_type
, DWORD fvf
, void *vertices
,
3493 DWORD vertex_count
, DWORD flags
)
3495 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
3496 UINT stride
, vb_pos
, size
, align
;
3500 TRACE("iface %p, primitive_type %#x, fvf %#x, vertices %p, vertex_count %u, flags %#x.\n",
3501 iface
, primitive_type
, fvf
, vertices
, vertex_count
, flags
);
3504 return DDERR_INVALIDPARAMS
;
3506 /* Get the stride */
3507 stride
= get_flexible_vertex_size(fvf
);
3508 size
= vertex_count
* stride
;
3510 wined3d_mutex_lock();
3511 hr
= d3d_device_prepare_vertex_buffer(device
, size
);
3515 vb_pos
= device
->vertex_buffer_pos
;
3516 align
= vb_pos
% stride
;
3517 if (align
) align
= stride
- align
;
3518 if (vb_pos
+ size
+ align
> device
->vertex_buffer_size
)
3523 hr
= wined3d_buffer_map(device
->vertex_buffer
, vb_pos
, size
, &data
,
3524 vb_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
);
3527 memcpy(data
, vertices
, size
);
3528 wined3d_buffer_unmap(device
->vertex_buffer
);
3529 device
->vertex_buffer_pos
= vb_pos
+ size
;
3531 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, 0, device
->vertex_buffer
, 0, stride
);
3535 wined3d_device_set_vertex_declaration(device
->wined3d_device
, ddraw_find_decl(device
->ddraw
, fvf
));
3536 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
3537 hr
= wined3d_device_draw_primitive(device
->wined3d_device
, vb_pos
/ stride
, vertex_count
);
3540 wined3d_mutex_unlock();
3544 static HRESULT WINAPI
d3d_device7_DrawPrimitive_FPUSetup(IDirect3DDevice7
*iface
,
3545 D3DPRIMITIVETYPE primitive_type
, DWORD fvf
, void *vertices
,
3546 DWORD vertex_count
, DWORD flags
)
3548 return d3d_device7_DrawPrimitive(iface
, primitive_type
, fvf
, vertices
, vertex_count
, flags
);
3551 static HRESULT WINAPI
d3d_device7_DrawPrimitive_FPUPreserve(IDirect3DDevice7
*iface
,
3552 D3DPRIMITIVETYPE primitive_type
, DWORD fvf
, void *vertices
,
3553 DWORD vertex_count
, DWORD flags
)
3558 old_fpucw
= d3d_fpu_setup();
3559 hr
= d3d_device7_DrawPrimitive(iface
, primitive_type
, fvf
, vertices
, vertex_count
, flags
);
3560 set_fpu_control_word(old_fpucw
);
3565 static void setup_lighting(const struct d3d_device
*device
, DWORD fvf
, DWORD flags
)
3569 /* Ignore the D3DFVF_XYZRHW case here, wined3d takes care of that */
3570 if (flags
& D3DDP_DONOTLIGHT
)
3572 else if (!(fvf
& D3DFVF_NORMAL
))
3577 wined3d_device_set_render_state(device
->wined3d_device
, WINED3D_RS_LIGHTING
, enable
);
3581 static HRESULT WINAPI
d3d_device3_DrawPrimitive(IDirect3DDevice3
*iface
,
3582 D3DPRIMITIVETYPE primitive_type
, DWORD fvf
, void *vertices
, DWORD vertex_count
,
3585 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
3587 TRACE("iface %p, primitive_type %#x, fvf %#x, vertices %p, vertex_count %u, flags %#x.\n",
3588 iface
, primitive_type
, fvf
, vertices
, vertex_count
, flags
);
3590 setup_lighting(device
, fvf
, flags
);
3592 return IDirect3DDevice7_DrawPrimitive(&device
->IDirect3DDevice7_iface
,
3593 primitive_type
, fvf
, vertices
, vertex_count
, flags
);
3596 static HRESULT WINAPI
d3d_device2_DrawPrimitive(IDirect3DDevice2
*iface
,
3597 D3DPRIMITIVETYPE primitive_type
, D3DVERTEXTYPE vertex_type
, void *vertices
,
3598 DWORD vertex_count
, DWORD flags
)
3600 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
3603 TRACE("iface %p, primitive_type %#x, vertex_type %#x, vertices %p, vertex_count %u, flags %#x.\n",
3604 iface
, primitive_type
, vertex_type
, vertices
, vertex_count
, flags
);
3606 switch (vertex_type
)
3608 case D3DVT_VERTEX
: fvf
= D3DFVF_VERTEX
; break;
3609 case D3DVT_LVERTEX
: fvf
= D3DFVF_LVERTEX
; break;
3610 case D3DVT_TLVERTEX
: fvf
= D3DFVF_TLVERTEX
; break;
3612 FIXME("Unhandled vertex type %#x.\n", vertex_type
);
3613 return DDERR_INVALIDPARAMS
; /* Should never happen */
3616 return d3d_device3_DrawPrimitive(&device
->IDirect3DDevice3_iface
,
3617 primitive_type
, fvf
, vertices
, vertex_count
, flags
);
3620 /*****************************************************************************
3621 * IDirect3DDevice7::DrawIndexedPrimitive
3623 * Draws vertices from an application-provided pointer, based on the index
3624 * numbers in a WORD array.
3626 * Version 2, 3 and 7. The version 7 thunk translates the vertex type into
3627 * an FVF format for D3D7
3630 * PrimitiveType: The primitive type to draw
3631 * VertexType: The FVF vertex description
3632 * Vertices: Pointer to the vertex array
3634 * Indices: Pointer to the index array
3635 * IndexCount: Number of indices = Number of vertices to draw
3636 * Flags: As usual, some flags
3640 * DDERR_INVALIDPARAMS if Vertices or Indices is NULL
3641 * For details, see IWineD3DDevice::DrawIndexedPrimitiveUP
3643 *****************************************************************************/
3644 /* The caller is responsible for wined3d locking */
3645 static HRESULT
d3d_device_prepare_index_buffer(struct d3d_device
*device
, UINT min_size
)
3649 if (device
->index_buffer_size
< min_size
|| !device
->index_buffer
)
3651 UINT size
= max(device
->index_buffer_size
* 2, min_size
);
3652 struct wined3d_buffer
*buffer
;
3654 TRACE("Growing index buffer to %u bytes\n", size
);
3656 hr
= wined3d_buffer_create_ib(device
->wined3d_device
, size
, WINED3DUSAGE_DYNAMIC
| WINED3DUSAGE_WRITEONLY
,
3657 WINED3D_POOL_DEFAULT
, NULL
, &ddraw_null_wined3d_parent_ops
, &buffer
);
3660 ERR("(%p) wined3d_buffer_create_ib failed with hr = %08x\n", device
, hr
);
3664 if (device
->index_buffer
)
3665 wined3d_buffer_decref(device
->index_buffer
);
3666 device
->index_buffer
= buffer
;
3667 device
->index_buffer_size
= size
;
3668 device
->index_buffer_pos
= 0;
3673 static HRESULT
d3d_device7_DrawIndexedPrimitive(IDirect3DDevice7
*iface
,
3674 D3DPRIMITIVETYPE primitive_type
, DWORD fvf
, void *vertices
, DWORD vertex_count
,
3675 WORD
*indices
, DWORD index_count
, DWORD flags
)
3677 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
3679 UINT stride
= get_flexible_vertex_size(fvf
);
3680 UINT vtx_size
= stride
* vertex_count
, idx_size
= index_count
* sizeof(*indices
);
3681 UINT vb_pos
, ib_pos
, align
;
3684 TRACE("iface %p, primitive_type %#x, fvf %#x, vertices %p, vertex_count %u, "
3685 "indices %p, index_count %u, flags %#x.\n",
3686 iface
, primitive_type
, fvf
, vertices
, vertex_count
, indices
, index_count
, flags
);
3688 /* Set the D3DDevice's FVF */
3689 wined3d_mutex_lock();
3691 hr
= d3d_device_prepare_vertex_buffer(device
, vtx_size
);
3695 vb_pos
= device
->vertex_buffer_pos
;
3696 align
= vb_pos
% stride
;
3697 if (align
) align
= stride
- align
;
3698 if (vb_pos
+ vtx_size
+ align
> device
->vertex_buffer_size
)
3703 hr
= wined3d_buffer_map(device
->vertex_buffer
, vb_pos
, vtx_size
, &data
,
3704 vb_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
);
3707 memcpy(data
, vertices
, vtx_size
);
3708 wined3d_buffer_unmap(device
->vertex_buffer
);
3709 device
->vertex_buffer_pos
= vb_pos
+ vtx_size
;
3711 hr
= d3d_device_prepare_index_buffer(device
, idx_size
);
3714 ib_pos
= device
->index_buffer_pos
;
3715 if (device
->index_buffer_size
- idx_size
< ib_pos
)
3718 hr
= wined3d_buffer_map(device
->index_buffer
, ib_pos
, idx_size
, &data
,
3719 ib_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
);
3722 memcpy(data
, indices
, idx_size
);
3723 wined3d_buffer_unmap(device
->index_buffer
);
3724 device
->index_buffer_pos
= ib_pos
+ idx_size
;
3726 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, 0, device
->vertex_buffer
, 0, stride
);
3729 wined3d_device_set_index_buffer(device
->wined3d_device
, device
->index_buffer
, WINED3DFMT_R16_UINT
);
3731 wined3d_device_set_vertex_declaration(device
->wined3d_device
, ddraw_find_decl(device
->ddraw
, fvf
));
3732 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
3733 wined3d_device_set_base_vertex_index(device
->wined3d_device
, vb_pos
/ stride
);
3734 hr
= wined3d_device_draw_indexed_primitive(device
->wined3d_device
, ib_pos
/ sizeof(*indices
), index_count
);
3737 wined3d_mutex_unlock();
3741 static HRESULT WINAPI
d3d_device7_DrawIndexedPrimitive_FPUSetup(IDirect3DDevice7
*iface
,
3742 D3DPRIMITIVETYPE primitive_type
, DWORD fvf
, void *vertices
, DWORD vertex_count
,
3743 WORD
*indices
, DWORD index_count
, DWORD flags
)
3745 return d3d_device7_DrawIndexedPrimitive(iface
, primitive_type
, fvf
,
3746 vertices
, vertex_count
, indices
, index_count
, flags
);
3749 static HRESULT WINAPI
d3d_device7_DrawIndexedPrimitive_FPUPreserve(IDirect3DDevice7
*iface
,
3750 D3DPRIMITIVETYPE primitive_type
, DWORD fvf
, void *vertices
, DWORD vertex_count
,
3751 WORD
*indices
, DWORD index_count
, DWORD flags
)
3756 old_fpucw
= d3d_fpu_setup();
3757 hr
= d3d_device7_DrawIndexedPrimitive(iface
, primitive_type
, fvf
,
3758 vertices
, vertex_count
, indices
, index_count
, flags
);
3759 set_fpu_control_word(old_fpucw
);
3764 static HRESULT WINAPI
d3d_device3_DrawIndexedPrimitive(IDirect3DDevice3
*iface
,
3765 D3DPRIMITIVETYPE primitive_type
, DWORD fvf
, void *vertices
, DWORD vertex_count
,
3766 WORD
*indices
, DWORD index_count
, DWORD flags
)
3768 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
3770 TRACE("iface %p, primitive_type %#x, fvf %#x, vertices %p, vertex_count %u, "
3771 "indices %p, index_count %u, flags %#x.\n",
3772 iface
, primitive_type
, fvf
, vertices
, vertex_count
, indices
, index_count
, flags
);
3774 setup_lighting(device
, fvf
, flags
);
3776 return IDirect3DDevice7_DrawIndexedPrimitive(&device
->IDirect3DDevice7_iface
,
3777 primitive_type
, fvf
, vertices
, vertex_count
, indices
, index_count
, flags
);
3780 static HRESULT WINAPI
d3d_device2_DrawIndexedPrimitive(IDirect3DDevice2
*iface
,
3781 D3DPRIMITIVETYPE primitive_type
, D3DVERTEXTYPE vertex_type
, void *vertices
,
3782 DWORD vertex_count
, WORD
*indices
, DWORD index_count
, DWORD flags
)
3784 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
3787 TRACE("iface %p, primitive_type %#x, vertex_type %#x, vertices %p, vertex_count %u, "
3788 "indices %p, index_count %u, flags %#x.\n",
3789 iface
, primitive_type
, vertex_type
, vertices
, vertex_count
, indices
, index_count
, flags
);
3791 switch (vertex_type
)
3793 case D3DVT_VERTEX
: fvf
= D3DFVF_VERTEX
; break;
3794 case D3DVT_LVERTEX
: fvf
= D3DFVF_LVERTEX
; break;
3795 case D3DVT_TLVERTEX
: fvf
= D3DFVF_TLVERTEX
; break;
3797 ERR("Unhandled vertex type %#x.\n", vertex_type
);
3798 return DDERR_INVALIDPARAMS
; /* Should never happen */
3801 return d3d_device3_DrawIndexedPrimitive(&device
->IDirect3DDevice3_iface
,
3802 primitive_type
, fvf
, vertices
, vertex_count
, indices
, index_count
, flags
);
3805 /*****************************************************************************
3806 * IDirect3DDevice3::End
3808 * Ends a draw begun with IDirect3DDevice3::Begin or
3809 * IDirect3DDevice::BeginIndexed. The vertices specified with
3810 * IDirect3DDevice::Vertex or IDirect3DDevice::Index are drawn using
3811 * the IDirect3DDevice3::DrawPrimitive method. So far only
3812 * non-indexed mode is supported
3817 * Flags: Some flags, as usual. Don't know which are defined
3820 * The return value of IDirect3DDevice3::DrawPrimitive
3822 *****************************************************************************/
3823 static HRESULT WINAPI
d3d_device3_End(IDirect3DDevice3
*iface
, DWORD flags
)
3825 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
3827 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3829 return d3d_device3_DrawPrimitive(&device
->IDirect3DDevice3_iface
, device
->primitive_type
,
3830 device
->vertex_type
, device
->sysmem_vertex_buffer
, device
->nb_vertices
, device
->render_flags
);
3833 static HRESULT WINAPI
d3d_device2_End(IDirect3DDevice2
*iface
, DWORD flags
)
3835 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
3837 TRACE("iface %p, flags %#x.\n", iface
, flags
);
3839 return d3d_device3_End(&device
->IDirect3DDevice3_iface
, flags
);
3842 /*****************************************************************************
3843 * IDirect3DDevice7::SetClipStatus
3845 * Sets the clip status. This defines things as clipping conditions and
3846 * the extents of the clipping region.
3848 * Version 2, 3 and 7
3854 * D3D_OK because it's a stub
3855 * (DDERR_INVALIDPARAMS if ClipStatus == NULL)
3857 *****************************************************************************/
3858 static HRESULT WINAPI
d3d_device7_SetClipStatus(IDirect3DDevice7
*iface
, D3DCLIPSTATUS
*clip_status
)
3860 FIXME("iface %p, clip_status %p stub!\n", iface
, clip_status
);
3862 /* D3DCLIPSTATUS and WINED3DCLIPSTATUS are different. I don't know how to convert them
3863 * Perhaps this needs a new data type and an additional IWineD3DDevice method
3865 /* return IWineD3DDevice_SetClipStatus(This->wineD3DDevice, ClipStatus);*/
3869 static HRESULT WINAPI
d3d_device3_SetClipStatus(IDirect3DDevice3
*iface
, D3DCLIPSTATUS
*clip_status
)
3871 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
3873 TRACE("iface %p, clip_status %p.\n", iface
, clip_status
);
3875 return IDirect3DDevice7_SetClipStatus(&device
->IDirect3DDevice7_iface
, clip_status
);
3878 static HRESULT WINAPI
d3d_device2_SetClipStatus(IDirect3DDevice2
*iface
, D3DCLIPSTATUS
*clip_status
)
3880 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
3882 TRACE("iface %p, clip_status %p.\n", iface
, clip_status
);
3884 return IDirect3DDevice7_SetClipStatus(&device
->IDirect3DDevice7_iface
, clip_status
);
3887 /*****************************************************************************
3888 * IDirect3DDevice7::GetClipStatus
3890 * Returns the clip status
3893 * ClipStatus: Address to write the clip status to
3896 * D3D_OK because it's a stub
3898 *****************************************************************************/
3899 static HRESULT WINAPI
d3d_device7_GetClipStatus(IDirect3DDevice7
*iface
, D3DCLIPSTATUS
*clip_status
)
3901 FIXME("iface %p, clip_status %p stub!\n", iface
, clip_status
);
3903 /* D3DCLIPSTATUS and WINED3DCLIPSTATUS are different. I don't know how to convert them */
3904 /* return IWineD3DDevice_GetClipStatus(This->wineD3DDevice, ClipStatus);*/
3908 static HRESULT WINAPI
d3d_device3_GetClipStatus(IDirect3DDevice3
*iface
, D3DCLIPSTATUS
*clip_status
)
3910 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
3912 TRACE("iface %p, clip_status %p.\n", iface
, clip_status
);
3914 return IDirect3DDevice7_GetClipStatus(&device
->IDirect3DDevice7_iface
, clip_status
);
3917 static HRESULT WINAPI
d3d_device2_GetClipStatus(IDirect3DDevice2
*iface
, D3DCLIPSTATUS
*clip_status
)
3919 struct d3d_device
*device
= impl_from_IDirect3DDevice2(iface
);
3921 TRACE("iface %p, clip_status %p.\n", iface
, clip_status
);
3923 return IDirect3DDevice7_GetClipStatus(&device
->IDirect3DDevice7_iface
, clip_status
);
3926 /*****************************************************************************
3927 * IDirect3DDevice::DrawPrimitiveStrided
3929 * Draws vertices described by a D3DDRAWPRIMITIVESTRIDEDDATA structure.
3934 * PrimitiveType: The primitive type to draw
3935 * VertexType: The FVF description of the vertices to draw (for the stride??)
3936 * D3DDrawPrimStrideData: A D3DDRAWPRIMITIVESTRIDEDDATA structure describing
3937 * the vertex data locations
3938 * VertexCount: The number of vertices to draw
3942 * D3D_OK, because it's a stub
3943 * (DDERR_INVALIDPARAMS if D3DDrawPrimStrideData is NULL)
3944 * (For details, see IWineD3DDevice::DrawPrimitiveStrided)
3946 *****************************************************************************/
3947 static void pack_strided_data(BYTE
*dst
, DWORD count
, const D3DDRAWPRIMITIVESTRIDEDDATA
*src
, DWORD fvf
)
3949 DWORD i
, tex
, offset
;
3951 for (i
= 0; i
< count
; i
++)
3953 /* The contents of the strided data are determined by the fvf,
3954 * not by the members set in src. So it's valid
3955 * to have diffuse.lpvData set to 0xdeadbeef if the diffuse flag is
3956 * not set in the fvf. */
3957 if (fvf
& D3DFVF_POSITION_MASK
)
3959 offset
= i
* src
->position
.dwStride
;
3960 if (fvf
& D3DFVF_XYZRHW
)
3962 memcpy(dst
, ((BYTE
*)src
->position
.lpvData
) + offset
, 4 * sizeof(float));
3963 dst
+= 4 * sizeof(float);
3967 memcpy(dst
, ((BYTE
*)src
->position
.lpvData
) + offset
, 3 * sizeof(float));
3968 dst
+= 3 * sizeof(float);
3972 if (fvf
& D3DFVF_NORMAL
)
3974 offset
= i
* src
->normal
.dwStride
;
3975 memcpy(dst
, ((BYTE
*)src
->normal
.lpvData
) + offset
, 3 * sizeof(float));
3976 dst
+= 3 * sizeof(float);
3979 if (fvf
& D3DFVF_DIFFUSE
)
3981 offset
= i
* src
->diffuse
.dwStride
;
3982 memcpy(dst
, ((BYTE
*)src
->diffuse
.lpvData
) + offset
, sizeof(DWORD
));
3983 dst
+= sizeof(DWORD
);
3986 if (fvf
& D3DFVF_SPECULAR
)
3988 offset
= i
* src
->specular
.dwStride
;
3989 memcpy(dst
, ((BYTE
*)src
->specular
.lpvData
) + offset
, sizeof(DWORD
));
3990 dst
+= sizeof(DWORD
);
3993 for (tex
= 0; tex
< GET_TEXCOUNT_FROM_FVF(fvf
); ++tex
)
3995 DWORD attrib_count
= GET_TEXCOORD_SIZE_FROM_FVF(fvf
, tex
);
3996 offset
= i
* src
->textureCoords
[tex
].dwStride
;
3997 memcpy(dst
, ((BYTE
*)src
->textureCoords
[tex
].lpvData
) + offset
, attrib_count
* sizeof(float));
3998 dst
+= attrib_count
* sizeof(float);
4003 static HRESULT
d3d_device7_DrawPrimitiveStrided(IDirect3DDevice7
*iface
, D3DPRIMITIVETYPE PrimitiveType
,
4004 DWORD VertexType
, D3DDRAWPRIMITIVESTRIDEDDATA
*D3DDrawPrimStrideData
, DWORD VertexCount
, DWORD Flags
)
4006 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
4008 UINT dst_stride
= get_flexible_vertex_size(VertexType
);
4009 UINT dst_size
= dst_stride
* VertexCount
;
4013 TRACE("iface %p, primitive_type %#x, FVF %#x, strided_data %p, vertex_count %u, flags %#x.\n",
4014 iface
, PrimitiveType
, VertexType
, D3DDrawPrimStrideData
, VertexCount
, Flags
);
4016 wined3d_mutex_lock();
4017 hr
= d3d_device_prepare_vertex_buffer(device
, dst_size
);
4021 vb_pos
= device
->vertex_buffer_pos
;
4022 align
= vb_pos
% dst_stride
;
4023 if (align
) align
= dst_stride
- align
;
4024 if (vb_pos
+ dst_size
+ align
> device
->vertex_buffer_size
)
4029 hr
= wined3d_buffer_map(device
->vertex_buffer
, vb_pos
, dst_size
, &dst_data
,
4030 vb_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
);
4033 pack_strided_data(dst_data
, VertexCount
, D3DDrawPrimStrideData
, VertexType
);
4034 wined3d_buffer_unmap(device
->vertex_buffer
);
4035 device
->vertex_buffer_pos
= vb_pos
+ dst_size
;
4037 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, 0, device
->vertex_buffer
, 0, dst_stride
);
4040 wined3d_device_set_vertex_declaration(device
->wined3d_device
, ddraw_find_decl(device
->ddraw
, VertexType
));
4042 wined3d_device_set_primitive_type(device
->wined3d_device
, PrimitiveType
);
4043 hr
= wined3d_device_draw_primitive(device
->wined3d_device
, vb_pos
/ dst_stride
, VertexCount
);
4046 wined3d_mutex_unlock();
4050 static HRESULT WINAPI
d3d_device7_DrawPrimitiveStrided_FPUSetup(IDirect3DDevice7
*iface
,
4051 D3DPRIMITIVETYPE PrimitiveType
, DWORD VertexType
,
4052 D3DDRAWPRIMITIVESTRIDEDDATA
*D3DDrawPrimStrideData
, DWORD VertexCount
, DWORD Flags
)
4054 return d3d_device7_DrawPrimitiveStrided(iface
, PrimitiveType
,
4055 VertexType
, D3DDrawPrimStrideData
, VertexCount
, Flags
);
4058 static HRESULT WINAPI
d3d_device7_DrawPrimitiveStrided_FPUPreserve(IDirect3DDevice7
*iface
,
4059 D3DPRIMITIVETYPE PrimitiveType
, DWORD VertexType
,
4060 D3DDRAWPRIMITIVESTRIDEDDATA
*D3DDrawPrimStrideData
, DWORD VertexCount
, DWORD Flags
)
4065 old_fpucw
= d3d_fpu_setup();
4066 hr
= d3d_device7_DrawPrimitiveStrided(iface
, PrimitiveType
,
4067 VertexType
, D3DDrawPrimStrideData
, VertexCount
, Flags
);
4068 set_fpu_control_word(old_fpucw
);
4073 static HRESULT WINAPI
d3d_device3_DrawPrimitiveStrided(IDirect3DDevice3
*iface
,
4074 D3DPRIMITIVETYPE PrimitiveType
, DWORD VertexType
,
4075 D3DDRAWPRIMITIVESTRIDEDDATA
*D3DDrawPrimStrideData
, DWORD VertexCount
, DWORD Flags
)
4077 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
4079 TRACE("iface %p, primitive_type %#x, FVF %#x, strided_data %p, vertex_count %u, flags %#x.\n",
4080 iface
, PrimitiveType
, VertexType
, D3DDrawPrimStrideData
, VertexCount
, Flags
);
4082 setup_lighting(device
, VertexType
, Flags
);
4084 return IDirect3DDevice7_DrawPrimitiveStrided(&device
->IDirect3DDevice7_iface
,
4085 PrimitiveType
, VertexType
, D3DDrawPrimStrideData
, VertexCount
, Flags
);
4088 /*****************************************************************************
4089 * IDirect3DDevice7::DrawIndexedPrimitiveStrided
4091 * Draws primitives specified by strided data locations based on indices
4099 * D3D_OK, because it's a stub
4100 * (DDERR_INVALIDPARAMS if D3DDrawPrimStrideData is NULL)
4101 * (DDERR_INVALIDPARAMS if Indices is NULL)
4102 * (For more details, see IWineD3DDevice::DrawIndexedPrimitiveStrided)
4104 *****************************************************************************/
4105 static HRESULT
d3d_device7_DrawIndexedPrimitiveStrided(IDirect3DDevice7
*iface
,
4106 D3DPRIMITIVETYPE PrimitiveType
, DWORD VertexType
,
4107 D3DDRAWPRIMITIVESTRIDEDDATA
*D3DDrawPrimStrideData
, DWORD VertexCount
,
4108 WORD
*Indices
, DWORD IndexCount
, DWORD Flags
)
4110 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
4112 UINT vtx_dst_stride
= get_flexible_vertex_size(VertexType
);
4113 UINT vtx_dst_size
= VertexCount
* vtx_dst_stride
;
4115 UINT idx_size
= IndexCount
* sizeof(WORD
);
4119 TRACE("iface %p, primitive_type %#x, FVF %#x, strided_data %p, vertex_count %u, indices %p, index_count %u, flags %#x.\n",
4120 iface
, PrimitiveType
, VertexType
, D3DDrawPrimStrideData
, VertexCount
, Indices
, IndexCount
, Flags
);
4122 wined3d_mutex_lock();
4124 hr
= d3d_device_prepare_vertex_buffer(device
, vtx_dst_size
);
4128 vb_pos
= device
->vertex_buffer_pos
;
4129 align
= vb_pos
% vtx_dst_stride
;
4130 if (align
) align
= vtx_dst_stride
- align
;
4131 if (vb_pos
+ vtx_dst_size
+ align
> device
->vertex_buffer_size
)
4136 hr
= wined3d_buffer_map(device
->vertex_buffer
, vb_pos
, vtx_dst_size
, &dst_data
,
4137 vb_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
);
4140 pack_strided_data(dst_data
, VertexCount
, D3DDrawPrimStrideData
, VertexType
);
4141 wined3d_buffer_unmap(device
->vertex_buffer
);
4142 device
->vertex_buffer_pos
= vb_pos
+ vtx_dst_size
;
4144 hr
= d3d_device_prepare_index_buffer(device
, idx_size
);
4147 ib_pos
= device
->index_buffer_pos
;
4148 if (device
->index_buffer_size
- idx_size
< ib_pos
)
4151 hr
= wined3d_buffer_map(device
->index_buffer
, ib_pos
, idx_size
, &dst_data
,
4152 ib_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
);
4155 memcpy(dst_data
, Indices
, idx_size
);
4156 wined3d_buffer_unmap(device
->index_buffer
);
4157 device
->index_buffer_pos
= ib_pos
+ idx_size
;
4159 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, 0, device
->vertex_buffer
, 0, vtx_dst_stride
);
4162 wined3d_device_set_index_buffer(device
->wined3d_device
, device
->index_buffer
, WINED3DFMT_R16_UINT
);
4163 wined3d_device_set_base_vertex_index(device
->wined3d_device
, vb_pos
/ vtx_dst_stride
);
4165 wined3d_device_set_vertex_declaration(device
->wined3d_device
, ddraw_find_decl(device
->ddraw
, VertexType
));
4166 wined3d_device_set_primitive_type(device
->wined3d_device
, PrimitiveType
);
4167 hr
= wined3d_device_draw_indexed_primitive(device
->wined3d_device
, ib_pos
/ sizeof(WORD
), IndexCount
);
4170 wined3d_mutex_unlock();
4174 static HRESULT WINAPI
d3d_device7_DrawIndexedPrimitiveStrided_FPUSetup(IDirect3DDevice7
*iface
,
4175 D3DPRIMITIVETYPE PrimitiveType
, DWORD VertexType
,
4176 D3DDRAWPRIMITIVESTRIDEDDATA
*D3DDrawPrimStrideData
, DWORD VertexCount
,
4177 WORD
*Indices
, DWORD IndexCount
, DWORD Flags
)
4179 return d3d_device7_DrawIndexedPrimitiveStrided(iface
, PrimitiveType
, VertexType
,
4180 D3DDrawPrimStrideData
, VertexCount
, Indices
, IndexCount
, Flags
);
4183 static HRESULT WINAPI
d3d_device7_DrawIndexedPrimitiveStrided_FPUPreserve(IDirect3DDevice7
*iface
,
4184 D3DPRIMITIVETYPE PrimitiveType
, DWORD VertexType
,
4185 D3DDRAWPRIMITIVESTRIDEDDATA
*D3DDrawPrimStrideData
, DWORD VertexCount
,
4186 WORD
*Indices
, DWORD IndexCount
, DWORD Flags
)
4191 old_fpucw
= d3d_fpu_setup();
4192 hr
= d3d_device7_DrawIndexedPrimitiveStrided(iface
, PrimitiveType
, VertexType
,
4193 D3DDrawPrimStrideData
, VertexCount
, Indices
, IndexCount
, Flags
);
4194 set_fpu_control_word(old_fpucw
);
4199 static HRESULT WINAPI
d3d_device3_DrawIndexedPrimitiveStrided(IDirect3DDevice3
*iface
,
4200 D3DPRIMITIVETYPE PrimitiveType
, DWORD VertexType
,
4201 D3DDRAWPRIMITIVESTRIDEDDATA
*D3DDrawPrimStrideData
, DWORD VertexCount
, WORD
*Indices
,
4202 DWORD IndexCount
, DWORD Flags
)
4204 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
4206 TRACE("iface %p, primitive_type %#x, FVF %#x, strided_data %p, vertex_count %u, indices %p, index_count %u, flags %#x.\n",
4207 iface
, PrimitiveType
, VertexType
, D3DDrawPrimStrideData
, VertexCount
, Indices
, IndexCount
, Flags
);
4209 setup_lighting(device
, VertexType
, Flags
);
4211 return IDirect3DDevice7_DrawIndexedPrimitiveStrided(&device
->IDirect3DDevice7_iface
,
4212 PrimitiveType
, VertexType
, D3DDrawPrimStrideData
, VertexCount
, Indices
, IndexCount
, Flags
);
4215 /*****************************************************************************
4216 * IDirect3DDevice7::DrawPrimitiveVB
4218 * Draws primitives from a vertex buffer to the screen.
4223 * PrimitiveType: Type of primitive to be rendered.
4224 * D3DVertexBuf: Source Vertex Buffer
4225 * StartVertex: Index of the first vertex from the buffer to be rendered
4226 * NumVertices: Number of vertices to be rendered
4227 * Flags: Can be D3DDP_WAIT to wait until rendering has finished
4231 * DDERR_INVALIDPARAMS if D3DVertexBuf is NULL
4233 *****************************************************************************/
4234 static HRESULT
d3d_device7_DrawPrimitiveVB(IDirect3DDevice7
*iface
, D3DPRIMITIVETYPE PrimitiveType
,
4235 IDirect3DVertexBuffer7
*D3DVertexBuf
, DWORD StartVertex
, DWORD NumVertices
, DWORD Flags
)
4237 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
4238 struct d3d_vertex_buffer
*vb
= unsafe_impl_from_IDirect3DVertexBuffer7(D3DVertexBuf
);
4242 TRACE("iface %p, primitive_type %#x, vb %p, start_vertex %u, vertex_count %u, flags %#x.\n",
4243 iface
, PrimitiveType
, D3DVertexBuf
, StartVertex
, NumVertices
, Flags
);
4248 WARN("No Vertex buffer specified.\n");
4249 return DDERR_INVALIDPARAMS
;
4251 stride
= get_flexible_vertex_size(vb
->fvf
);
4253 wined3d_mutex_lock();
4254 wined3d_device_set_vertex_declaration(device
->wined3d_device
, vb
->wineD3DVertexDeclaration
);
4255 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, 0, vb
->wineD3DVertexBuffer
, 0, stride
);
4258 WARN("Failed to set stream source, hr %#x.\n", hr
);
4259 wined3d_mutex_unlock();
4263 /* Now draw the primitives */
4264 wined3d_device_set_primitive_type(device
->wined3d_device
, PrimitiveType
);
4265 hr
= wined3d_device_draw_primitive(device
->wined3d_device
, StartVertex
, NumVertices
);
4267 wined3d_mutex_unlock();
4272 static HRESULT WINAPI
d3d_device7_DrawPrimitiveVB_FPUSetup(IDirect3DDevice7
*iface
, D3DPRIMITIVETYPE PrimitiveType
,
4273 IDirect3DVertexBuffer7
*D3DVertexBuf
, DWORD StartVertex
, DWORD NumVertices
, DWORD Flags
)
4275 return d3d_device7_DrawPrimitiveVB(iface
, PrimitiveType
, D3DVertexBuf
, StartVertex
, NumVertices
, Flags
);
4278 static HRESULT WINAPI
d3d_device7_DrawPrimitiveVB_FPUPreserve(IDirect3DDevice7
*iface
, D3DPRIMITIVETYPE PrimitiveType
,
4279 IDirect3DVertexBuffer7
*D3DVertexBuf
, DWORD StartVertex
, DWORD NumVertices
, DWORD Flags
)
4284 old_fpucw
= d3d_fpu_setup();
4285 hr
= d3d_device7_DrawPrimitiveVB(iface
, PrimitiveType
, D3DVertexBuf
, StartVertex
, NumVertices
, Flags
);
4286 set_fpu_control_word(old_fpucw
);
4291 static HRESULT WINAPI
d3d_device3_DrawPrimitiveVB(IDirect3DDevice3
*iface
, D3DPRIMITIVETYPE PrimitiveType
,
4292 IDirect3DVertexBuffer
*D3DVertexBuf
, DWORD StartVertex
, DWORD NumVertices
, DWORD Flags
)
4294 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
4295 struct d3d_vertex_buffer
*vb
= unsafe_impl_from_IDirect3DVertexBuffer(D3DVertexBuf
);
4297 TRACE("iface %p, primitive_type %#x, vb %p, start_vertex %u, vertex_count %u, flags %#x.\n",
4298 iface
, PrimitiveType
, D3DVertexBuf
, StartVertex
, NumVertices
, Flags
);
4300 setup_lighting(device
, vb
->fvf
, Flags
);
4302 return IDirect3DDevice7_DrawPrimitiveVB(&device
->IDirect3DDevice7_iface
,
4303 PrimitiveType
, &vb
->IDirect3DVertexBuffer7_iface
, StartVertex
, NumVertices
, Flags
);
4306 /*****************************************************************************
4307 * IDirect3DDevice7::DrawIndexedPrimitiveVB
4309 * Draws primitives from a vertex buffer to the screen
4312 * PrimitiveType: Type of primitive to be rendered.
4313 * D3DVertexBuf: Source Vertex Buffer
4314 * StartVertex: Index of the first vertex from the buffer to be rendered
4315 * NumVertices: Number of vertices to be rendered
4316 * Indices: Array of DWORDs used to index into the Vertices
4317 * IndexCount: Number of indices in Indices
4318 * Flags: Can be D3DDP_WAIT to wait until rendering has finished
4322 *****************************************************************************/
4323 static HRESULT
d3d_device7_DrawIndexedPrimitiveVB(IDirect3DDevice7
*iface
,
4324 D3DPRIMITIVETYPE PrimitiveType
, IDirect3DVertexBuffer7
*D3DVertexBuf
,
4325 DWORD StartVertex
, DWORD NumVertices
, WORD
*Indices
, DWORD IndexCount
, DWORD Flags
)
4327 struct d3d_device
*This
= impl_from_IDirect3DDevice7(iface
);
4328 struct d3d_vertex_buffer
*vb
= unsafe_impl_from_IDirect3DVertexBuffer7(D3DVertexBuf
);
4329 DWORD stride
= get_flexible_vertex_size(vb
->fvf
);
4330 WORD
*LockedIndices
;
4334 TRACE("iface %p, primitive_type %#x, vb %p, start_vertex %u, vertex_count %u, indices %p, index_count %u, flags %#x.\n",
4335 iface
, PrimitiveType
, D3DVertexBuf
, StartVertex
, NumVertices
, Indices
, IndexCount
, Flags
);
4338 * 1) Upload the Indices to the index buffer
4339 * 2) Set the index source
4340 * 3) Set the Vertex Buffer as the Stream source
4341 * 4) Call IWineD3DDevice::DrawIndexedPrimitive
4344 wined3d_mutex_lock();
4346 wined3d_device_set_vertex_declaration(This
->wined3d_device
, vb
->wineD3DVertexDeclaration
);
4348 hr
= d3d_device_prepare_index_buffer(This
, IndexCount
* sizeof(WORD
));
4351 wined3d_mutex_unlock();
4354 ib_pos
= This
->index_buffer_pos
;
4356 if (This
->index_buffer_size
- IndexCount
* sizeof(WORD
) < ib_pos
)
4359 /* Copy the index stream into the index buffer. A new IWineD3DDevice
4360 * method could be created which takes an user pointer containing the
4361 * indices or a SetData-Method for the index buffer, which overrides the
4362 * index buffer data with our pointer. */
4363 hr
= wined3d_buffer_map(This
->index_buffer
, ib_pos
, IndexCount
* sizeof(WORD
),
4364 (BYTE
**)&LockedIndices
, ib_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
);
4367 ERR("Failed to map buffer, hr %#x.\n", hr
);
4368 wined3d_mutex_unlock();
4371 memcpy(LockedIndices
, Indices
, IndexCount
* sizeof(WORD
));
4372 wined3d_buffer_unmap(This
->index_buffer
);
4373 This
->index_buffer_pos
= ib_pos
+ IndexCount
* sizeof(WORD
);
4375 /* Set the index stream */
4376 wined3d_device_set_base_vertex_index(This
->wined3d_device
, StartVertex
);
4377 wined3d_device_set_index_buffer(This
->wined3d_device
, This
->index_buffer
, WINED3DFMT_R16_UINT
);
4379 /* Set the vertex stream source */
4380 hr
= wined3d_device_set_stream_source(This
->wined3d_device
, 0, vb
->wineD3DVertexBuffer
, 0, stride
);
4383 ERR("(%p) IDirect3DDevice::SetStreamSource failed with hr = %08x\n", This
, hr
);
4384 wined3d_mutex_unlock();
4389 wined3d_device_set_primitive_type(This
->wined3d_device
, PrimitiveType
);
4390 hr
= wined3d_device_draw_indexed_primitive(This
->wined3d_device
, ib_pos
/ sizeof(WORD
), IndexCount
);
4392 wined3d_mutex_unlock();
4397 static HRESULT WINAPI
d3d_device7_DrawIndexedPrimitiveVB_FPUSetup(IDirect3DDevice7
*iface
,
4398 D3DPRIMITIVETYPE PrimitiveType
, IDirect3DVertexBuffer7
*D3DVertexBuf
,
4399 DWORD StartVertex
, DWORD NumVertices
, WORD
*Indices
, DWORD IndexCount
, DWORD Flags
)
4401 return d3d_device7_DrawIndexedPrimitiveVB(iface
, PrimitiveType
,
4402 D3DVertexBuf
, StartVertex
, NumVertices
, Indices
, IndexCount
, Flags
);
4405 static HRESULT WINAPI
d3d_device7_DrawIndexedPrimitiveVB_FPUPreserve(IDirect3DDevice7
*iface
,
4406 D3DPRIMITIVETYPE PrimitiveType
, IDirect3DVertexBuffer7
*D3DVertexBuf
,
4407 DWORD StartVertex
, DWORD NumVertices
, WORD
*Indices
, DWORD IndexCount
, DWORD Flags
)
4412 old_fpucw
= d3d_fpu_setup();
4413 hr
= d3d_device7_DrawIndexedPrimitiveVB(iface
, PrimitiveType
,
4414 D3DVertexBuf
, StartVertex
, NumVertices
, Indices
, IndexCount
, Flags
);
4415 set_fpu_control_word(old_fpucw
);
4420 static HRESULT WINAPI
d3d_device3_DrawIndexedPrimitiveVB(IDirect3DDevice3
*iface
,
4421 D3DPRIMITIVETYPE PrimitiveType
, IDirect3DVertexBuffer
*D3DVertexBuf
, WORD
*Indices
,
4422 DWORD IndexCount
, DWORD Flags
)
4424 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
4425 struct d3d_vertex_buffer
*vb
= unsafe_impl_from_IDirect3DVertexBuffer(D3DVertexBuf
);
4427 TRACE("iface %p, primitive_type %#x, vb %p, indices %p, index_count %u, flags %#x.\n",
4428 iface
, PrimitiveType
, D3DVertexBuf
, Indices
, IndexCount
, Flags
);
4430 setup_lighting(device
, vb
->fvf
, Flags
);
4432 return IDirect3DDevice7_DrawIndexedPrimitiveVB(&device
->IDirect3DDevice7_iface
, PrimitiveType
,
4433 &vb
->IDirect3DVertexBuffer7_iface
, 0, IndexCount
, Indices
, IndexCount
, Flags
);
4436 /*****************************************************************************
4437 * IDirect3DDevice7::ComputeSphereVisibility
4439 * Calculates the visibility of spheres in the current viewport. The spheres
4440 * are passed in the Centers and Radii arrays, the results are passed back
4441 * in the ReturnValues array. Return values are either completely visible,
4442 * partially visible or completely invisible.
4443 * The return value consist of a combination of D3DCLIP_* flags, or it's
4444 * 0 if the sphere is completely visible(according to the SDK, not checked)
4449 * Centers: Array containing the sphere centers
4450 * Radii: Array containing the sphere radii
4451 * NumSpheres: The number of centers and radii in the arrays
4453 * ReturnValues: Array to write the results to
4457 * (DDERR_INVALIDPARAMS if Centers, Radii or ReturnValues are NULL)
4458 * (D3DERR_INVALIDMATRIX if the combined world, view and proj matrix
4461 *****************************************************************************/
4463 static DWORD
in_plane(UINT plane
, D3DVECTOR normal
, D3DVALUE origin_plane
, D3DVECTOR center
, D3DVALUE radius
)
4465 float distance
, norm
;
4467 norm
= sqrtf(normal
.u1
.x
* normal
.u1
.x
+ normal
.u2
.y
* normal
.u2
.y
+ normal
.u3
.z
* normal
.u3
.z
);
4468 distance
= ( origin_plane
+ normal
.u1
.x
* center
.u1
.x
+ normal
.u2
.y
* center
.u2
.y
+ normal
.u3
.z
* center
.u3
.z
) / norm
;
4470 if ( fabs( distance
) < radius
) return D3DSTATUS_CLIPUNIONLEFT
<< plane
;
4471 if ( distance
< -radius
) return (D3DSTATUS_CLIPUNIONLEFT
| D3DSTATUS_CLIPINTERSECTIONLEFT
) << plane
;
4475 static HRESULT WINAPI
d3d_device7_ComputeSphereVisibility(IDirect3DDevice7
*iface
,
4476 D3DVECTOR
*centers
, D3DVALUE
*radii
, DWORD sphere_count
, DWORD flags
, DWORD
*return_values
)
4479 D3DVALUE origin_plane
[6];
4484 TRACE("iface %p, centers %p, radii %p, sphere_count %u, flags %#x, return_values %p.\n",
4485 iface
, centers
, radii
, sphere_count
, flags
, return_values
);
4487 hr
= d3d_device7_GetTransform(iface
, D3DTRANSFORMSTATE_WORLD
, &m
);
4488 if ( hr
!= DD_OK
) return DDERR_INVALIDPARAMS
;
4489 hr
= d3d_device7_GetTransform(iface
, D3DTRANSFORMSTATE_VIEW
, &temp
);
4490 if ( hr
!= DD_OK
) return DDERR_INVALIDPARAMS
;
4491 multiply_matrix(&m
, &temp
, &m
);
4493 hr
= d3d_device7_GetTransform(iface
, D3DTRANSFORMSTATE_PROJECTION
, &temp
);
4494 if ( hr
!= DD_OK
) return DDERR_INVALIDPARAMS
;
4495 multiply_matrix(&m
, &temp
, &m
);
4498 vec
[0].u1
.x
= m
._14
+ m
._11
;
4499 vec
[0].u2
.y
= m
._24
+ m
._21
;
4500 vec
[0].u3
.z
= m
._34
+ m
._31
;
4501 origin_plane
[0] = m
._44
+ m
._41
;
4504 vec
[1].u1
.x
= m
._14
- m
._11
;
4505 vec
[1].u2
.y
= m
._24
- m
._21
;
4506 vec
[1].u3
.z
= m
._34
- m
._31
;
4507 origin_plane
[1] = m
._44
- m
._41
;
4510 vec
[2].u1
.x
= m
._14
- m
._12
;
4511 vec
[2].u2
.y
= m
._24
- m
._22
;
4512 vec
[2].u3
.z
= m
._34
- m
._32
;
4513 origin_plane
[2] = m
._44
- m
._42
;
4516 vec
[3].u1
.x
= m
._14
+ m
._12
;
4517 vec
[3].u2
.y
= m
._24
+ m
._22
;
4518 vec
[3].u3
.z
= m
._34
+ m
._32
;
4519 origin_plane
[3] = m
._44
+ m
._42
;
4522 vec
[4].u1
.x
= m
._13
;
4523 vec
[4].u2
.y
= m
._23
;
4524 vec
[4].u3
.z
= m
._33
;
4525 origin_plane
[4] = m
._43
;
4528 vec
[5].u1
.x
= m
._14
- m
._13
;
4529 vec
[5].u2
.y
= m
._24
- m
._23
;
4530 vec
[5].u3
.z
= m
._34
- m
._33
;
4531 origin_plane
[5] = m
._44
- m
._43
;
4533 for (i
= 0; i
< sphere_count
; ++i
)
4535 return_values
[i
] = 0;
4536 for (j
= 0; j
< 6; ++j
)
4537 return_values
[i
] |= in_plane(j
, vec
[j
], origin_plane
[j
], centers
[i
], radii
[i
]);
4543 static HRESULT WINAPI
d3d_device3_ComputeSphereVisibility(IDirect3DDevice3
*iface
,
4544 D3DVECTOR
*centers
, D3DVALUE
*radii
, DWORD sphere_count
, DWORD flags
, DWORD
*return_values
)
4546 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
4548 TRACE("iface %p, centers %p, radii %p, sphere_count %u, flags %#x, return_values %p.\n",
4549 iface
, centers
, radii
, sphere_count
, flags
, return_values
);
4551 return IDirect3DDevice7_ComputeSphereVisibility(&device
->IDirect3DDevice7_iface
,
4552 centers
, radii
, sphere_count
, flags
, return_values
);
4555 /*****************************************************************************
4556 * IDirect3DDevice7::GetTexture
4558 * Returns the texture interface handle assigned to a texture stage.
4559 * The returned texture is AddRefed. This is taken from old ddraw,
4560 * not checked in Windows.
4565 * Stage: Texture stage to read the texture from
4566 * Texture: Address to store the interface pointer at
4570 * DDERR_INVALIDPARAMS if Texture is NULL
4571 * For details, see IWineD3DDevice::GetTexture
4573 *****************************************************************************/
4574 static HRESULT
d3d_device7_GetTexture(IDirect3DDevice7
*iface
,
4575 DWORD stage
, IDirectDrawSurface7
**texture
)
4577 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
4578 struct wined3d_texture
*wined3d_texture
;
4579 struct ddraw_texture
*ddraw_texture
;
4581 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
4584 return DDERR_INVALIDPARAMS
;
4586 wined3d_mutex_lock();
4587 if (!(wined3d_texture
= wined3d_device_get_texture(device
->wined3d_device
, stage
)))
4590 wined3d_mutex_unlock();
4594 ddraw_texture
= wined3d_texture_get_parent(wined3d_texture
);
4595 *texture
= &ddraw_texture
->root
->IDirectDrawSurface7_iface
;
4596 IDirectDrawSurface7_AddRef(*texture
);
4597 wined3d_mutex_unlock();
4602 static HRESULT WINAPI
d3d_device7_GetTexture_FPUSetup(IDirect3DDevice7
*iface
,
4603 DWORD stage
, IDirectDrawSurface7
**Texture
)
4605 return d3d_device7_GetTexture(iface
, stage
, Texture
);
4608 static HRESULT WINAPI
d3d_device7_GetTexture_FPUPreserve(IDirect3DDevice7
*iface
,
4609 DWORD stage
, IDirectDrawSurface7
**Texture
)
4614 old_fpucw
= d3d_fpu_setup();
4615 hr
= d3d_device7_GetTexture(iface
, stage
, Texture
);
4616 set_fpu_control_word(old_fpucw
);
4621 static HRESULT WINAPI
d3d_device3_GetTexture(IDirect3DDevice3
*iface
, DWORD stage
, IDirect3DTexture2
**Texture2
)
4623 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
4624 struct ddraw_surface
*ret_val_impl
;
4626 IDirectDrawSurface7
*ret_val
;
4628 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, Texture2
);
4630 ret
= IDirect3DDevice7_GetTexture(&device
->IDirect3DDevice7_iface
, stage
, &ret_val
);
4632 ret_val_impl
= unsafe_impl_from_IDirectDrawSurface7(ret_val
);
4633 *Texture2
= ret_val_impl
? &ret_val_impl
->IDirect3DTexture2_iface
: NULL
;
4635 TRACE("Returning texture %p.\n", *Texture2
);
4640 /*****************************************************************************
4641 * IDirect3DDevice7::SetTexture
4643 * Assigns a texture to a texture stage. Is the texture AddRef-ed?
4648 * Stage: The stage to assign the texture to
4649 * Texture: Interface pointer to the texture surface
4653 * For details, see IWineD3DDevice::SetTexture
4655 *****************************************************************************/
4656 static HRESULT
d3d_device7_SetTexture(IDirect3DDevice7
*iface
,
4657 DWORD stage
, IDirectDrawSurface7
*texture
)
4659 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
4660 struct ddraw_surface
*surf
= unsafe_impl_from_IDirectDrawSurface7(texture
);
4661 struct wined3d_texture
*wined3d_texture
= NULL
;
4664 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
4666 if (surf
&& (surf
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
4667 wined3d_texture
= surf
->wined3d_texture
;
4669 wined3d_mutex_lock();
4670 hr
= wined3d_device_set_texture(device
->wined3d_device
, stage
, wined3d_texture
);
4671 wined3d_mutex_unlock();
4676 static HRESULT WINAPI
d3d_device7_SetTexture_FPUSetup(IDirect3DDevice7
*iface
,
4677 DWORD stage
, IDirectDrawSurface7
*texture
)
4679 return d3d_device7_SetTexture(iface
, stage
, texture
);
4682 static HRESULT WINAPI
d3d_device7_SetTexture_FPUPreserve(IDirect3DDevice7
*iface
,
4683 DWORD stage
, IDirectDrawSurface7
*texture
)
4688 old_fpucw
= d3d_fpu_setup();
4689 hr
= d3d_device7_SetTexture(iface
, stage
, texture
);
4690 set_fpu_control_word(old_fpucw
);
4695 static HRESULT WINAPI
d3d_device3_SetTexture(IDirect3DDevice3
*iface
,
4696 DWORD stage
, IDirect3DTexture2
*texture
)
4698 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
4699 struct ddraw_surface
*tex
= unsafe_impl_from_IDirect3DTexture2(texture
);
4703 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
4705 wined3d_mutex_lock();
4707 if (device
->legacyTextureBlending
)
4708 IDirect3DDevice3_GetRenderState(iface
, D3DRENDERSTATE_TEXTUREMAPBLEND
, &texmapblend
);
4710 hr
= IDirect3DDevice7_SetTexture(&device
->IDirect3DDevice7_iface
, stage
, &tex
->IDirectDrawSurface7_iface
);
4712 if (device
->legacyTextureBlending
&& texmapblend
== D3DTBLEND_MODULATE
)
4714 /* This fixup is required by the way D3DTBLEND_MODULATE maps to texture stage states.
4715 See d3d_device3_SetRenderState() for details. */
4716 struct wined3d_texture
*tex
= NULL
;
4717 BOOL tex_alpha
= FALSE
;
4718 DDPIXELFORMAT ddfmt
;
4720 if ((tex
= wined3d_device_get_texture(device
->wined3d_device
, 0)))
4722 struct wined3d_resource
*sub_resource
;
4724 if ((sub_resource
= wined3d_texture_get_sub_resource(tex
, 0)))
4726 struct wined3d_resource_desc desc
;
4728 wined3d_resource_get_desc(sub_resource
, &desc
);
4729 ddfmt
.dwSize
= sizeof(ddfmt
);
4730 ddrawformat_from_wined3dformat(&ddfmt
, desc
.format
);
4731 if (ddfmt
.u5
.dwRGBAlphaBitMask
) tex_alpha
= TRUE
;
4735 /* Arg 1/2 are already set to WINED3DTA_TEXTURE/WINED3DTA_CURRENT in case of D3DTBLEND_MODULATE */
4737 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
4738 0, WINED3D_TSS_ALPHA_OP
, WINED3D_TOP_SELECT_ARG1
);
4740 wined3d_device_set_texture_stage_state(device
->wined3d_device
,
4741 0, WINED3D_TSS_ALPHA_OP
, WINED3D_TOP_SELECT_ARG2
);
4744 wined3d_mutex_unlock();
4749 static const struct tss_lookup
4752 enum wined3d_texture_stage_state state
;
4756 {FALSE
, WINED3D_TSS_INVALID
}, /* 0, unused */
4757 {FALSE
, WINED3D_TSS_COLOR_OP
}, /* 1, D3DTSS_COLOROP */
4758 {FALSE
, WINED3D_TSS_COLOR_ARG1
}, /* 2, D3DTSS_COLORARG1 */
4759 {FALSE
, WINED3D_TSS_COLOR_ARG2
}, /* 3, D3DTSS_COLORARG2 */
4760 {FALSE
, WINED3D_TSS_ALPHA_OP
}, /* 4, D3DTSS_ALPHAOP */
4761 {FALSE
, WINED3D_TSS_ALPHA_ARG1
}, /* 5, D3DTSS_ALPHAARG1 */
4762 {FALSE
, WINED3D_TSS_ALPHA_ARG2
}, /* 6, D3DTSS_ALPHAARG2 */
4763 {FALSE
, WINED3D_TSS_BUMPENV_MAT00
}, /* 7, D3DTSS_BUMPENVMAT00 */
4764 {FALSE
, WINED3D_TSS_BUMPENV_MAT01
}, /* 8, D3DTSS_BUMPENVMAT01 */
4765 {FALSE
, WINED3D_TSS_BUMPENV_MAT10
}, /* 9, D3DTSS_BUMPENVMAT10 */
4766 {FALSE
, WINED3D_TSS_BUMPENV_MAT11
}, /* 10, D3DTSS_BUMPENVMAT11 */
4767 {FALSE
, WINED3D_TSS_TEXCOORD_INDEX
}, /* 11, D3DTSS_TEXCOORDINDEX */
4768 {TRUE
, WINED3D_SAMP_ADDRESS_U
}, /* 12, D3DTSS_ADDRESS */
4769 {TRUE
, WINED3D_SAMP_ADDRESS_U
}, /* 13, D3DTSS_ADDRESSU */
4770 {TRUE
, WINED3D_SAMP_ADDRESS_V
}, /* 14, D3DTSS_ADDRESSV */
4771 {TRUE
, WINED3D_SAMP_BORDER_COLOR
}, /* 15, D3DTSS_BORDERCOLOR */
4772 {TRUE
, WINED3D_SAMP_MAG_FILTER
}, /* 16, D3DTSS_MAGFILTER */
4773 {TRUE
, WINED3D_SAMP_MIN_FILTER
}, /* 17, D3DTSS_MINFILTER */
4774 {TRUE
, WINED3D_SAMP_MIP_FILTER
}, /* 18, D3DTSS_MIPFILTER */
4775 {TRUE
, WINED3D_SAMP_MIPMAP_LOD_BIAS
}, /* 19, D3DTSS_MIPMAPLODBIAS */
4776 {TRUE
, WINED3D_SAMP_MAX_MIP_LEVEL
}, /* 20, D3DTSS_MAXMIPLEVEL */
4777 {TRUE
, WINED3D_SAMP_MAX_ANISOTROPY
}, /* 21, D3DTSS_MAXANISOTROPY */
4778 {FALSE
, WINED3D_TSS_BUMPENV_LSCALE
}, /* 22, D3DTSS_BUMPENVLSCALE */
4779 {FALSE
, WINED3D_TSS_BUMPENV_LOFFSET
}, /* 23, D3DTSS_BUMPENVLOFFSET */
4780 {FALSE
, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
4783 /*****************************************************************************
4784 * IDirect3DDevice7::GetTextureStageState
4786 * Retrieves a state from a texture stage.
4791 * Stage: The stage to retrieve the state from
4792 * TexStageStateType: The state type to retrieve
4793 * State: Address to store the state's value at
4797 * DDERR_INVALIDPARAMS if State is NULL
4798 * For details, see IWineD3DDevice::GetTextureStageState
4800 *****************************************************************************/
4801 static HRESULT
d3d_device7_GetTextureStageState(IDirect3DDevice7
*iface
,
4802 DWORD stage
, D3DTEXTURESTAGESTATETYPE state
, DWORD
*value
)
4804 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
4805 const struct tss_lookup
*l
;
4807 TRACE("iface %p, stage %u, state %#x, value %p.\n",
4808 iface
, stage
, state
, value
);
4811 return DDERR_INVALIDPARAMS
;
4813 if (state
> D3DTSS_TEXTURETRANSFORMFLAGS
)
4815 WARN("Invalid state %#x passed.\n", state
);
4819 l
= &tss_lookup
[state
];
4821 wined3d_mutex_lock();
4823 if (l
->sampler_state
)
4825 *value
= wined3d_device_get_sampler_state(device
->wined3d_device
, stage
, l
->state
);
4829 /* Mipfilter is a sampler state with different values */
4830 case D3DTSS_MIPFILTER
:
4834 case WINED3D_TEXF_NONE
:
4835 *value
= D3DTFP_NONE
;
4837 case WINED3D_TEXF_POINT
:
4838 *value
= D3DTFP_POINT
;
4840 case WINED3D_TEXF_LINEAR
:
4841 *value
= D3DTFP_LINEAR
;
4844 ERR("Unexpected mipfilter value %#x.\n", *value
);
4845 *value
= D3DTFP_NONE
;
4851 /* Magfilter has slightly different values */
4852 case D3DTSS_MAGFILTER
:
4856 case WINED3D_TEXF_POINT
:
4857 *value
= D3DTFG_POINT
;
4859 case WINED3D_TEXF_LINEAR
:
4860 *value
= D3DTFG_LINEAR
;
4862 case WINED3D_TEXF_ANISOTROPIC
:
4863 *value
= D3DTFG_ANISOTROPIC
;
4865 case WINED3D_TEXF_FLAT_CUBIC
:
4866 *value
= D3DTFG_FLATCUBIC
;
4868 case WINED3D_TEXF_GAUSSIAN_CUBIC
:
4869 *value
= D3DTFG_GAUSSIANCUBIC
;
4872 ERR("Unexpected wined3d mag filter value %#x.\n", *value
);
4873 *value
= D3DTFG_POINT
;
4885 *value
= wined3d_device_get_texture_stage_state(device
->wined3d_device
, stage
, l
->state
);
4888 wined3d_mutex_unlock();
4893 static HRESULT WINAPI
d3d_device7_GetTextureStageState_FPUSetup(IDirect3DDevice7
*iface
,
4894 DWORD stage
, D3DTEXTURESTAGESTATETYPE state
, DWORD
*value
)
4896 return d3d_device7_GetTextureStageState(iface
, stage
, state
, value
);
4899 static HRESULT WINAPI
d3d_device7_GetTextureStageState_FPUPreserve(IDirect3DDevice7
*iface
,
4900 DWORD stage
, D3DTEXTURESTAGESTATETYPE state
, DWORD
*value
)
4905 old_fpucw
= d3d_fpu_setup();
4906 hr
= d3d_device7_GetTextureStageState(iface
, stage
, state
, value
);
4907 set_fpu_control_word(old_fpucw
);
4912 static HRESULT WINAPI
d3d_device3_GetTextureStageState(IDirect3DDevice3
*iface
,
4913 DWORD stage
, D3DTEXTURESTAGESTATETYPE state
, DWORD
*value
)
4915 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
4917 TRACE("iface %p, stage %u, state %#x, value %p.\n",
4918 iface
, stage
, state
, value
);
4920 return IDirect3DDevice7_GetTextureStageState(&device
->IDirect3DDevice7_iface
, stage
, state
, value
);
4923 /*****************************************************************************
4924 * IDirect3DDevice7::SetTextureStageState
4926 * Sets a texture stage state. Some stage types need to be handled specially,
4927 * because they do not exist in WineD3D and were moved to another place
4932 * Stage: The stage to modify
4933 * TexStageStateType: The state to change
4934 * State: The new value for the state
4938 * For details, see IWineD3DDevice::SetTextureStageState
4940 *****************************************************************************/
4941 static HRESULT
d3d_device7_SetTextureStageState(IDirect3DDevice7
*iface
,
4942 DWORD stage
, D3DTEXTURESTAGESTATETYPE state
, DWORD value
)
4944 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
4945 const struct tss_lookup
*l
;
4947 TRACE("iface %p, stage %u, state %#x, value %#x.\n",
4948 iface
, stage
, state
, value
);
4950 if (state
> D3DTSS_TEXTURETRANSFORMFLAGS
)
4952 WARN("Invalid state %#x passed.\n", state
);
4956 l
= &tss_lookup
[state
];
4958 wined3d_mutex_lock();
4960 if (l
->sampler_state
)
4964 /* Mipfilter is a sampler state with different values */
4965 case D3DTSS_MIPFILTER
:
4970 value
= WINED3D_TEXF_NONE
;
4973 value
= WINED3D_TEXF_POINT
;
4975 case 0: /* Unchecked */
4977 value
= WINED3D_TEXF_LINEAR
;
4980 ERR("Unexpected mipfilter value %#x.\n", value
);
4981 value
= WINED3D_TEXF_NONE
;
4987 /* Magfilter has slightly different values */
4988 case D3DTSS_MAGFILTER
:
4993 value
= WINED3D_TEXF_POINT
;
4996 value
= WINED3D_TEXF_LINEAR
;
4998 case D3DTFG_FLATCUBIC
:
4999 value
= WINED3D_TEXF_FLAT_CUBIC
;
5001 case D3DTFG_GAUSSIANCUBIC
:
5002 value
= WINED3D_TEXF_GAUSSIAN_CUBIC
;
5004 case D3DTFG_ANISOTROPIC
:
5005 value
= WINED3D_TEXF_ANISOTROPIC
;
5008 ERR("Unexpected d3d7 mag filter value %#x.\n", value
);
5009 value
= WINED3D_TEXF_POINT
;
5015 case D3DTSS_ADDRESS
:
5016 wined3d_device_set_sampler_state(device
->wined3d_device
, stage
, WINED3D_SAMP_ADDRESS_V
, value
);
5023 wined3d_device_set_sampler_state(device
->wined3d_device
, stage
, l
->state
, value
);
5027 wined3d_device_set_texture_stage_state(device
->wined3d_device
, stage
, l
->state
, value
);
5030 wined3d_mutex_unlock();
5035 static HRESULT WINAPI
d3d_device7_SetTextureStageState_FPUSetup(IDirect3DDevice7
*iface
,
5036 DWORD stage
, D3DTEXTURESTAGESTATETYPE state
, DWORD value
)
5038 return d3d_device7_SetTextureStageState(iface
, stage
, state
, value
);
5041 static HRESULT WINAPI
d3d_device7_SetTextureStageState_FPUPreserve(IDirect3DDevice7
*iface
,
5042 DWORD stage
, D3DTEXTURESTAGESTATETYPE state
, DWORD value
)
5047 old_fpucw
= d3d_fpu_setup();
5048 hr
= d3d_device7_SetTextureStageState(iface
, stage
, state
, value
);
5049 set_fpu_control_word(old_fpucw
);
5054 static HRESULT WINAPI
d3d_device3_SetTextureStageState(IDirect3DDevice3
*iface
,
5055 DWORD stage
, D3DTEXTURESTAGESTATETYPE state
, DWORD value
)
5057 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
5059 TRACE("iface %p, stage %u, state %#x, value %#x.\n",
5060 iface
, stage
, state
, value
);
5062 return IDirect3DDevice7_SetTextureStageState(&device
->IDirect3DDevice7_iface
, stage
, state
, value
);
5065 /*****************************************************************************
5066 * IDirect3DDevice7::ValidateDevice
5068 * SDK: "Reports the device's ability to render the currently set
5069 * texture-blending operations in a single pass". Whatever that means
5075 * NumPasses: Address to write the number of necessary passes for the
5076 * desired effect to.
5080 * See IWineD3DDevice::ValidateDevice for more details
5082 *****************************************************************************/
5083 static HRESULT
d3d_device7_ValidateDevice(IDirect3DDevice7
*iface
, DWORD
*pass_count
)
5085 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
5088 TRACE("iface %p, pass_count %p.\n", iface
, pass_count
);
5090 wined3d_mutex_lock();
5091 hr
= wined3d_device_validate_device(device
->wined3d_device
, pass_count
);
5092 wined3d_mutex_unlock();
5097 static HRESULT WINAPI
d3d_device7_ValidateDevice_FPUSetup(IDirect3DDevice7
*iface
, DWORD
*pass_count
)
5099 return d3d_device7_ValidateDevice(iface
, pass_count
);
5102 static HRESULT WINAPI
d3d_device7_ValidateDevice_FPUPreserve(IDirect3DDevice7
*iface
, DWORD
*pass_count
)
5107 old_fpucw
= d3d_fpu_setup();
5108 hr
= d3d_device7_ValidateDevice(iface
, pass_count
);
5109 set_fpu_control_word(old_fpucw
);
5114 static HRESULT WINAPI
d3d_device3_ValidateDevice(IDirect3DDevice3
*iface
, DWORD
*pass_count
)
5116 struct d3d_device
*device
= impl_from_IDirect3DDevice3(iface
);
5118 TRACE("iface %p, pass_count %p.\n", iface
, pass_count
);
5120 return IDirect3DDevice7_ValidateDevice(&device
->IDirect3DDevice7_iface
, pass_count
);
5123 /*****************************************************************************
5124 * IDirect3DDevice7::Clear
5126 * Fills the render target, the z buffer and the stencil buffer with a
5127 * clear color / value
5132 * Count: Number of rectangles in Rects must be 0 if Rects is NULL
5133 * Rects: Rectangles to clear. If NULL, the whole surface is cleared
5134 * Flags: Some flags, as usual
5135 * Color: Clear color for the render target
5136 * Z: Clear value for the Z buffer
5137 * Stencil: Clear value to store in each stencil buffer entry
5141 * For details, see IWineD3DDevice::Clear
5143 *****************************************************************************/
5144 static HRESULT
d3d_device7_Clear(IDirect3DDevice7
*iface
, DWORD count
,
5145 D3DRECT
*rects
, DWORD flags
, D3DCOLOR color
, D3DVALUE z
, DWORD stencil
)
5147 const struct wined3d_color c
=
5149 ((color
>> 16) & 0xff) / 255.0f
,
5150 ((color
>> 8) & 0xff) / 255.0f
,
5151 (color
& 0xff) / 255.0f
,
5152 ((color
>> 24) & 0xff) / 255.0f
,
5154 struct d3d_device
*This
= impl_from_IDirect3DDevice7(iface
);
5157 TRACE("iface %p, count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %#x.\n",
5158 iface
, count
, rects
, flags
, color
, z
, stencil
);
5160 wined3d_mutex_lock();
5161 hr
= wined3d_device_clear(This
->wined3d_device
, count
, (RECT
*)rects
, flags
, &c
, z
, stencil
);
5162 wined3d_mutex_unlock();
5167 static HRESULT WINAPI
d3d_device7_Clear_FPUSetup(IDirect3DDevice7
*iface
, DWORD count
,
5168 D3DRECT
*rects
, DWORD flags
, D3DCOLOR color
, D3DVALUE z
, DWORD stencil
)
5170 return d3d_device7_Clear(iface
, count
, rects
, flags
, color
, z
, stencil
);
5173 static HRESULT WINAPI
d3d_device7_Clear_FPUPreserve(IDirect3DDevice7
*iface
, DWORD count
,
5174 D3DRECT
*rects
, DWORD flags
, D3DCOLOR color
, D3DVALUE z
, DWORD stencil
)
5179 old_fpucw
= d3d_fpu_setup();
5180 hr
= d3d_device7_Clear(iface
, count
, rects
, flags
, color
, z
, stencil
);
5181 set_fpu_control_word(old_fpucw
);
5186 /*****************************************************************************
5187 * IDirect3DDevice7::SetViewport
5189 * Sets the current viewport.
5191 * Version 7 only, but IDirect3DViewport uses this call for older
5195 * Data: The new viewport to set
5199 * DDERR_INVALIDPARAMS if Data is NULL
5200 * For more details, see IWineDDDevice::SetViewport
5202 *****************************************************************************/
5203 static HRESULT
d3d_device7_SetViewport(IDirect3DDevice7
*iface
, D3DVIEWPORT7
*viewport
)
5205 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
5207 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
5210 return DDERR_INVALIDPARAMS
;
5212 /* Note: D3DVIEWPORT7 is compatible with struct wined3d_viewport. */
5213 wined3d_mutex_lock();
5214 wined3d_device_set_viewport(device
->wined3d_device
, (struct wined3d_viewport
*)viewport
);
5215 wined3d_mutex_unlock();
5220 static HRESULT WINAPI
d3d_device7_SetViewport_FPUSetup(IDirect3DDevice7
*iface
, D3DVIEWPORT7
*viewport
)
5222 return d3d_device7_SetViewport(iface
, viewport
);
5225 static HRESULT WINAPI
d3d_device7_SetViewport_FPUPreserve(IDirect3DDevice7
*iface
, D3DVIEWPORT7
*viewport
)
5230 old_fpucw
= d3d_fpu_setup();
5231 hr
= d3d_device7_SetViewport(iface
, viewport
);
5232 set_fpu_control_word(old_fpucw
);
5237 /*****************************************************************************
5238 * IDirect3DDevice::GetViewport
5240 * Returns the current viewport
5245 * Data: D3D7Viewport structure to write the viewport information to
5249 * DDERR_INVALIDPARAMS if Data is NULL
5250 * For more details, see IWineD3DDevice::GetViewport
5252 *****************************************************************************/
5253 static HRESULT
d3d_device7_GetViewport(IDirect3DDevice7
*iface
, D3DVIEWPORT7
*viewport
)
5255 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
5257 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
5260 return DDERR_INVALIDPARAMS
;
5262 /* Note: D3DVIEWPORT7 is compatible with struct wined3d_viewport. */
5263 wined3d_mutex_lock();
5264 wined3d_device_get_viewport(device
->wined3d_device
, (struct wined3d_viewport
*)viewport
);
5265 wined3d_mutex_unlock();
5270 static HRESULT WINAPI
d3d_device7_GetViewport_FPUSetup(IDirect3DDevice7
*iface
, D3DVIEWPORT7
*viewport
)
5272 return d3d_device7_GetViewport(iface
, viewport
);
5275 static HRESULT WINAPI
d3d_device7_GetViewport_FPUPreserve(IDirect3DDevice7
*iface
, D3DVIEWPORT7
*viewport
)
5280 old_fpucw
= d3d_fpu_setup();
5281 hr
= d3d_device7_GetViewport(iface
, viewport
);
5282 set_fpu_control_word(old_fpucw
);
5287 /*****************************************************************************
5288 * IDirect3DDevice7::SetMaterial
5295 * Mat: The material to set
5299 * DDERR_INVALIDPARAMS if Mat is NULL.
5300 * For more details, see IWineD3DDevice::SetMaterial
5302 *****************************************************************************/
5303 static HRESULT
d3d_device7_SetMaterial(IDirect3DDevice7
*iface
, D3DMATERIAL7
*material
)
5305 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
5307 TRACE("iface %p, material %p.\n", iface
, material
);
5310 return DDERR_INVALIDPARAMS
;
5312 wined3d_mutex_lock();
5313 /* Note: D3DMATERIAL7 is compatible with struct wined3d_material. */
5314 wined3d_device_set_material(device
->wined3d_device
, (struct wined3d_material
*)material
);
5315 wined3d_mutex_unlock();
5320 static HRESULT WINAPI
d3d_device7_SetMaterial_FPUSetup(IDirect3DDevice7
*iface
, D3DMATERIAL7
*material
)
5322 return d3d_device7_SetMaterial(iface
, material
);
5325 static HRESULT WINAPI
d3d_device7_SetMaterial_FPUPreserve(IDirect3DDevice7
*iface
, D3DMATERIAL7
*material
)
5330 old_fpucw
= d3d_fpu_setup();
5331 hr
= d3d_device7_SetMaterial(iface
, material
);
5332 set_fpu_control_word(old_fpucw
);
5337 /*****************************************************************************
5338 * IDirect3DDevice7::GetMaterial
5340 * Returns the current material
5345 * Mat: D3DMATERIAL7 structure to write the material parameters to
5349 * DDERR_INVALIDPARAMS if Mat is NULL
5350 * For more details, see IWineD3DDevice::GetMaterial
5352 *****************************************************************************/
5353 static HRESULT
d3d_device7_GetMaterial(IDirect3DDevice7
*iface
, D3DMATERIAL7
*material
)
5355 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
5357 TRACE("iface %p, material %p.\n", iface
, material
);
5359 wined3d_mutex_lock();
5360 /* Note: D3DMATERIAL7 is compatible with struct wined3d_material. */
5361 wined3d_device_get_material(device
->wined3d_device
, (struct wined3d_material
*)material
);
5362 wined3d_mutex_unlock();
5367 static HRESULT WINAPI
d3d_device7_GetMaterial_FPUSetup(IDirect3DDevice7
*iface
, D3DMATERIAL7
*material
)
5369 return d3d_device7_GetMaterial(iface
, material
);
5372 static HRESULT WINAPI
d3d_device7_GetMaterial_FPUPreserve(IDirect3DDevice7
*iface
, D3DMATERIAL7
*material
)
5377 old_fpucw
= d3d_fpu_setup();
5378 hr
= d3d_device7_GetMaterial(iface
, material
);
5379 set_fpu_control_word(old_fpucw
);
5384 /*****************************************************************************
5385 * IDirect3DDevice7::SetLight
5387 * Assigns a light to a light index, but doesn't activate it yet.
5389 * Version 7, IDirect3DLight uses this method for older versions
5392 * LightIndex: The index of the new light
5393 * Light: A D3DLIGHT7 structure describing the light
5397 * For more details, see IWineD3DDevice::SetLight
5399 *****************************************************************************/
5400 static HRESULT
d3d_device7_SetLight(IDirect3DDevice7
*iface
, DWORD light_idx
, D3DLIGHT7
*light
)
5402 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
5405 TRACE("iface %p, light_idx %u, light %p.\n", iface
, light_idx
, light
);
5407 wined3d_mutex_lock();
5408 /* Note: D3DLIGHT7 is compatible with struct wined3d_light. */
5409 hr
= wined3d_device_set_light(device
->wined3d_device
, light_idx
, (struct wined3d_light
*)light
);
5410 wined3d_mutex_unlock();
5412 return hr_ddraw_from_wined3d(hr
);
5415 static HRESULT WINAPI
d3d_device7_SetLight_FPUSetup(IDirect3DDevice7
*iface
, DWORD light_idx
, D3DLIGHT7
*light
)
5417 return d3d_device7_SetLight(iface
, light_idx
, light
);
5420 static HRESULT WINAPI
d3d_device7_SetLight_FPUPreserve(IDirect3DDevice7
*iface
, DWORD light_idx
, D3DLIGHT7
*light
)
5425 old_fpucw
= d3d_fpu_setup();
5426 hr
= d3d_device7_SetLight(iface
, light_idx
, light
);
5427 set_fpu_control_word(old_fpucw
);
5432 /*****************************************************************************
5433 * IDirect3DDevice7::GetLight
5435 * Returns the light assigned to a light index
5438 * Light: Structure to write the light information to
5442 * DDERR_INVALIDPARAMS if Light is NULL
5443 * For details, see IWineD3DDevice::GetLight
5445 *****************************************************************************/
5446 static HRESULT
d3d_device7_GetLight(IDirect3DDevice7
*iface
, DWORD light_idx
, D3DLIGHT7
*light
)
5448 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
5451 TRACE("iface %p, light_idx %u, light %p.\n", iface
, light_idx
, light
);
5453 wined3d_mutex_lock();
5454 /* Note: D3DLIGHT7 is compatible with struct wined3d_light. */
5455 rc
= wined3d_device_get_light(device
->wined3d_device
, light_idx
, (struct wined3d_light
*)light
);
5456 wined3d_mutex_unlock();
5458 /* Translate the result. WineD3D returns other values than D3D7 */
5459 return hr_ddraw_from_wined3d(rc
);
5462 static HRESULT WINAPI
d3d_device7_GetLight_FPUSetup(IDirect3DDevice7
*iface
, DWORD light_idx
, D3DLIGHT7
*light
)
5464 return d3d_device7_GetLight(iface
, light_idx
, light
);
5467 static HRESULT WINAPI
d3d_device7_GetLight_FPUPreserve(IDirect3DDevice7
*iface
, DWORD light_idx
, D3DLIGHT7
*light
)
5472 old_fpucw
= d3d_fpu_setup();
5473 hr
= d3d_device7_GetLight(iface
, light_idx
, light
);
5474 set_fpu_control_word(old_fpucw
);
5479 /*****************************************************************************
5480 * IDirect3DDevice7::BeginStateBlock
5482 * Begins recording to a stateblock
5488 * For details see IWineD3DDevice::BeginStateBlock
5490 *****************************************************************************/
5491 static HRESULT
d3d_device7_BeginStateBlock(IDirect3DDevice7
*iface
)
5493 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
5496 TRACE("iface %p.\n", iface
);
5498 wined3d_mutex_lock();
5499 hr
= wined3d_device_begin_stateblock(device
->wined3d_device
);
5500 wined3d_mutex_unlock();
5502 return hr_ddraw_from_wined3d(hr
);
5505 static HRESULT WINAPI
d3d_device7_BeginStateBlock_FPUSetup(IDirect3DDevice7
*iface
)
5507 return d3d_device7_BeginStateBlock(iface
);
5510 static HRESULT WINAPI
d3d_device7_BeginStateBlock_FPUPreserve(IDirect3DDevice7
*iface
)
5515 old_fpucw
= d3d_fpu_setup();
5516 hr
= d3d_device7_BeginStateBlock(iface
);
5517 set_fpu_control_word(old_fpucw
);
5522 /*****************************************************************************
5523 * IDirect3DDevice7::EndStateBlock
5525 * Stops recording to a state block and returns the created stateblock
5531 * BlockHandle: Address to store the stateblock's handle to
5535 * DDERR_INVALIDPARAMS if BlockHandle is NULL
5536 * See IWineD3DDevice::EndStateBlock for more details
5538 *****************************************************************************/
5539 static HRESULT
d3d_device7_EndStateBlock(IDirect3DDevice7
*iface
, DWORD
*stateblock
)
5541 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
5542 struct wined3d_stateblock
*wined3d_sb
;
5546 TRACE("iface %p, stateblock %p.\n", iface
, stateblock
);
5549 return DDERR_INVALIDPARAMS
;
5551 wined3d_mutex_lock();
5553 hr
= wined3d_device_end_stateblock(device
->wined3d_device
, &wined3d_sb
);
5556 WARN("Failed to end stateblock, hr %#x.\n", hr
);
5557 wined3d_mutex_unlock();
5559 return hr_ddraw_from_wined3d(hr
);
5562 h
= ddraw_allocate_handle(&device
->handle_table
, wined3d_sb
, DDRAW_HANDLE_STATEBLOCK
);
5563 if (h
== DDRAW_INVALID_HANDLE
)
5565 ERR("Failed to allocate a stateblock handle.\n");
5566 wined3d_stateblock_decref(wined3d_sb
);
5567 wined3d_mutex_unlock();
5569 return DDERR_OUTOFMEMORY
;
5572 wined3d_mutex_unlock();
5573 *stateblock
= h
+ 1;
5575 return hr_ddraw_from_wined3d(hr
);
5578 static HRESULT WINAPI
d3d_device7_EndStateBlock_FPUSetup(IDirect3DDevice7
*iface
, DWORD
*stateblock
)
5580 return d3d_device7_EndStateBlock(iface
, stateblock
);
5583 static HRESULT WINAPI
d3d_device7_EndStateBlock_FPUPreserve(IDirect3DDevice7
*iface
, DWORD
*stateblock
)
5588 old_fpucw
= d3d_fpu_setup();
5589 hr
= d3d_device7_EndStateBlock(iface
, stateblock
);
5590 set_fpu_control_word(old_fpucw
);
5595 /*****************************************************************************
5596 * IDirect3DDevice7::PreLoad
5598 * Allows the app to signal that a texture will be used soon, to allow
5599 * the Direct3DDevice to load it to the video card in the meantime.
5604 * Texture: The texture to preload
5608 * DDERR_INVALIDPARAMS if Texture is NULL
5609 * See IWineD3DSurface::PreLoad for details
5611 *****************************************************************************/
5612 static HRESULT
d3d_device7_PreLoad(IDirect3DDevice7
*iface
, IDirectDrawSurface7
*texture
)
5614 struct ddraw_surface
*surface
= unsafe_impl_from_IDirectDrawSurface7(texture
);
5616 TRACE("iface %p, texture %p.\n", iface
, texture
);
5619 return DDERR_INVALIDPARAMS
;
5621 wined3d_mutex_lock();
5622 wined3d_surface_preload(surface
->wined3d_surface
);
5623 wined3d_mutex_unlock();
5628 static HRESULT WINAPI
d3d_device7_PreLoad_FPUSetup(IDirect3DDevice7
*iface
, IDirectDrawSurface7
*texture
)
5630 return d3d_device7_PreLoad(iface
, texture
);
5633 static HRESULT WINAPI
d3d_device7_PreLoad_FPUPreserve(IDirect3DDevice7
*iface
, IDirectDrawSurface7
*texture
)
5638 old_fpucw
= d3d_fpu_setup();
5639 hr
= d3d_device7_PreLoad(iface
, texture
);
5640 set_fpu_control_word(old_fpucw
);
5645 /*****************************************************************************
5646 * IDirect3DDevice7::ApplyStateBlock
5648 * Activates the state stored in a state block handle.
5651 * BlockHandle: The stateblock handle to activate
5655 * D3DERR_INVALIDSTATEBLOCK if BlockHandle is NULL
5657 *****************************************************************************/
5658 static HRESULT
d3d_device7_ApplyStateBlock(IDirect3DDevice7
*iface
, DWORD stateblock
)
5660 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
5661 struct wined3d_stateblock
*wined3d_sb
;
5663 TRACE("iface %p, stateblock %#x.\n", iface
, stateblock
);
5665 wined3d_mutex_lock();
5666 wined3d_sb
= ddraw_get_object(&device
->handle_table
, stateblock
- 1, DDRAW_HANDLE_STATEBLOCK
);
5669 WARN("Invalid stateblock handle.\n");
5670 wined3d_mutex_unlock();
5671 return D3DERR_INVALIDSTATEBLOCK
;
5674 wined3d_stateblock_apply(wined3d_sb
);
5675 wined3d_mutex_unlock();
5680 static HRESULT WINAPI
d3d_device7_ApplyStateBlock_FPUSetup(IDirect3DDevice7
*iface
, DWORD stateblock
)
5682 return d3d_device7_ApplyStateBlock(iface
, stateblock
);
5685 static HRESULT WINAPI
d3d_device7_ApplyStateBlock_FPUPreserve(IDirect3DDevice7
*iface
, DWORD stateblock
)
5690 old_fpucw
= d3d_fpu_setup();
5691 hr
= d3d_device7_ApplyStateBlock(iface
, stateblock
);
5692 set_fpu_control_word(old_fpucw
);
5697 /*****************************************************************************
5698 * IDirect3DDevice7::CaptureStateBlock
5700 * Updates a stateblock's values to the values currently set for the device
5705 * BlockHandle: Stateblock to update
5709 * D3DERR_INVALIDSTATEBLOCK if BlockHandle is NULL
5710 * See IWineD3DDevice::CaptureStateBlock for more details
5712 *****************************************************************************/
5713 static HRESULT
d3d_device7_CaptureStateBlock(IDirect3DDevice7
*iface
, DWORD stateblock
)
5715 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
5716 struct wined3d_stateblock
*wined3d_sb
;
5718 TRACE("iface %p, stateblock %#x.\n", iface
, stateblock
);
5720 wined3d_mutex_lock();
5721 wined3d_sb
= ddraw_get_object(&device
->handle_table
, stateblock
- 1, DDRAW_HANDLE_STATEBLOCK
);
5724 WARN("Invalid stateblock handle.\n");
5725 wined3d_mutex_unlock();
5726 return D3DERR_INVALIDSTATEBLOCK
;
5729 wined3d_stateblock_capture(wined3d_sb
);
5730 wined3d_mutex_unlock();
5735 static HRESULT WINAPI
d3d_device7_CaptureStateBlock_FPUSetup(IDirect3DDevice7
*iface
, DWORD stateblock
)
5737 return d3d_device7_CaptureStateBlock(iface
, stateblock
);
5740 static HRESULT WINAPI
d3d_device7_CaptureStateBlock_FPUPreserve(IDirect3DDevice7
*iface
, DWORD stateblock
)
5745 old_fpucw
= d3d_fpu_setup();
5746 hr
= d3d_device7_CaptureStateBlock(iface
, stateblock
);
5747 set_fpu_control_word(old_fpucw
);
5752 /*****************************************************************************
5753 * IDirect3DDevice7::DeleteStateBlock
5755 * Deletes a stateblock handle. This means releasing the WineD3DStateBlock
5760 * BlockHandle: Stateblock handle to delete
5764 * D3DERR_INVALIDSTATEBLOCK if BlockHandle is 0
5766 *****************************************************************************/
5767 static HRESULT
d3d_device7_DeleteStateBlock(IDirect3DDevice7
*iface
, DWORD stateblock
)
5769 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
5770 struct wined3d_stateblock
*wined3d_sb
;
5773 TRACE("iface %p, stateblock %#x.\n", iface
, stateblock
);
5775 wined3d_mutex_lock();
5777 wined3d_sb
= ddraw_free_handle(&device
->handle_table
, stateblock
- 1, DDRAW_HANDLE_STATEBLOCK
);
5780 WARN("Invalid stateblock handle.\n");
5781 wined3d_mutex_unlock();
5782 return D3DERR_INVALIDSTATEBLOCK
;
5785 if ((ref
= wined3d_stateblock_decref(wined3d_sb
)))
5787 ERR("Something is still holding stateblock %p (refcount %u).\n", wined3d_sb
, ref
);
5790 wined3d_mutex_unlock();
5795 static HRESULT WINAPI
d3d_device7_DeleteStateBlock_FPUSetup(IDirect3DDevice7
*iface
, DWORD stateblock
)
5797 return d3d_device7_DeleteStateBlock(iface
, stateblock
);
5800 static HRESULT WINAPI
d3d_device7_DeleteStateBlock_FPUPreserve(IDirect3DDevice7
*iface
, DWORD stateblock
)
5805 old_fpucw
= d3d_fpu_setup();
5806 hr
= d3d_device7_DeleteStateBlock(iface
, stateblock
);
5807 set_fpu_control_word(old_fpucw
);
5812 /*****************************************************************************
5813 * IDirect3DDevice7::CreateStateBlock
5815 * Creates a new state block handle.
5820 * Type: The state block type
5821 * BlockHandle: Address to write the created handle to
5825 * DDERR_INVALIDPARAMS if BlockHandle is NULL
5827 *****************************************************************************/
5828 static HRESULT
d3d_device7_CreateStateBlock(IDirect3DDevice7
*iface
,
5829 D3DSTATEBLOCKTYPE type
, DWORD
*stateblock
)
5831 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
5832 struct wined3d_stateblock
*wined3d_sb
;
5836 TRACE("iface %p, type %#x, stateblock %p.\n", iface
, type
, stateblock
);
5839 return DDERR_INVALIDPARAMS
;
5841 if (type
!= D3DSBT_ALL
5842 && type
!= D3DSBT_PIXELSTATE
5843 && type
!= D3DSBT_VERTEXSTATE
)
5845 WARN("Unexpected stateblock type, returning DDERR_INVALIDPARAMS\n");
5846 return DDERR_INVALIDPARAMS
;
5849 wined3d_mutex_lock();
5851 /* The D3DSTATEBLOCKTYPE enum is fine here. */
5852 hr
= wined3d_stateblock_create(device
->wined3d_device
, type
, &wined3d_sb
);
5855 WARN("Failed to create stateblock, hr %#x.\n", hr
);
5856 wined3d_mutex_unlock();
5857 return hr_ddraw_from_wined3d(hr
);
5860 h
= ddraw_allocate_handle(&device
->handle_table
, wined3d_sb
, DDRAW_HANDLE_STATEBLOCK
);
5861 if (h
== DDRAW_INVALID_HANDLE
)
5863 ERR("Failed to allocate stateblock handle.\n");
5864 wined3d_stateblock_decref(wined3d_sb
);
5865 wined3d_mutex_unlock();
5866 return DDERR_OUTOFMEMORY
;
5869 *stateblock
= h
+ 1;
5870 wined3d_mutex_unlock();
5872 return hr_ddraw_from_wined3d(hr
);
5875 static HRESULT WINAPI
d3d_device7_CreateStateBlock_FPUSetup(IDirect3DDevice7
*iface
,
5876 D3DSTATEBLOCKTYPE type
, DWORD
*stateblock
)
5878 return d3d_device7_CreateStateBlock(iface
, type
, stateblock
);
5881 static HRESULT WINAPI
d3d_device7_CreateStateBlock_FPUPreserve(IDirect3DDevice7
*iface
,
5882 D3DSTATEBLOCKTYPE type
, DWORD
*stateblock
)
5887 old_fpucw
= d3d_fpu_setup();
5888 hr
= d3d_device7_CreateStateBlock(iface
, type
, stateblock
);
5889 set_fpu_control_word(old_fpucw
);
5894 static BOOL
is_mip_level_subset(struct ddraw_surface
*dest
, struct ddraw_surface
*src
)
5896 struct ddraw_surface
*src_level
, *dest_level
;
5897 IDirectDrawSurface7
*temp
;
5898 DDSURFACEDESC2 ddsd
;
5899 BOOL levelFound
; /* at least one suitable sublevel in dest found */
5901 /* To satisfy "destination is mip level subset of source" criteria (regular texture counts as 1 level),
5902 * 1) there must be at least one mip level in destination that matched dimensions of some mip level in source and
5903 * 2) there must be no destination levels that don't match any levels in source. Otherwise it's INVALIDPARAMS.
5910 for (;src_level
&& dest_level
;)
5912 if (src_level
->surface_desc
.dwWidth
== dest_level
->surface_desc
.dwWidth
&&
5913 src_level
->surface_desc
.dwHeight
== dest_level
->surface_desc
.dwHeight
)
5917 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
5918 ddsd
.ddsCaps
.dwCaps2
= DDSCAPS2_MIPMAPSUBLEVEL
;
5919 IDirectDrawSurface7_GetAttachedSurface(&dest_level
->IDirectDrawSurface7_iface
, &ddsd
.ddsCaps
, &temp
);
5921 if (dest_level
!= dest
) IDirectDrawSurface7_Release(&dest_level
->IDirectDrawSurface7_iface
);
5923 dest_level
= unsafe_impl_from_IDirectDrawSurface7(temp
);
5926 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
5927 ddsd
.ddsCaps
.dwCaps2
= DDSCAPS2_MIPMAPSUBLEVEL
;
5928 IDirectDrawSurface7_GetAttachedSurface(&src_level
->IDirectDrawSurface7_iface
, &ddsd
.ddsCaps
, &temp
);
5930 if (src_level
!= src
) IDirectDrawSurface7_Release(&src_level
->IDirectDrawSurface7_iface
);
5932 src_level
= unsafe_impl_from_IDirectDrawSurface7(temp
);
5935 if (src_level
&& src_level
!= src
) IDirectDrawSurface7_Release(&src_level
->IDirectDrawSurface7_iface
);
5936 if (dest_level
&& dest_level
!= dest
) IDirectDrawSurface7_Release(&dest_level
->IDirectDrawSurface7_iface
);
5938 return !dest_level
&& levelFound
;
5941 static void copy_mipmap_chain(struct d3d_device
*device
, struct ddraw_surface
*dest
,
5942 struct ddraw_surface
*src
, const POINT
*DestPoint
, const RECT
*SrcRect
)
5944 struct ddraw_surface
*src_level
, *dest_level
;
5945 IDirectDrawSurface7
*temp
;
5946 DDSURFACEDESC2 ddsd
;
5950 IDirectDrawPalette
*pal
= NULL
, *pal_src
= NULL
;
5954 /* Copy palette, if possible. */
5955 IDirectDrawSurface7_GetPalette(&src
->IDirectDrawSurface7_iface
, &pal_src
);
5956 IDirectDrawSurface7_GetPalette(&dest
->IDirectDrawSurface7_iface
, &pal
);
5958 if (pal_src
!= NULL
&& pal
!= NULL
)
5960 PALETTEENTRY palent
[256];
5962 IDirectDrawPalette_GetEntries(pal_src
, 0, 0, 256, palent
);
5963 IDirectDrawPalette_SetEntries(pal
, 0, 0, 256, palent
);
5966 if (pal
) IDirectDrawPalette_Release(pal
);
5967 if (pal_src
) IDirectDrawPalette_Release(pal_src
);
5969 /* Copy colorkeys, if present. */
5970 for (ckeyflag
= DDCKEY_DESTBLT
; ckeyflag
<= DDCKEY_SRCOVERLAY
; ckeyflag
<<= 1)
5972 hr
= IDirectDrawSurface7_GetColorKey(&src
->IDirectDrawSurface7_iface
, ckeyflag
, &ddckey
);
5976 IDirectDrawSurface7_SetColorKey(&dest
->IDirectDrawSurface7_iface
, ckeyflag
, &ddckey
);
5984 src_rect
= *SrcRect
;
5986 for (;src_level
&& dest_level
;)
5988 if (src_level
->surface_desc
.dwWidth
== dest_level
->surface_desc
.dwWidth
&&
5989 src_level
->surface_desc
.dwHeight
== dest_level
->surface_desc
.dwHeight
)
5991 UINT src_w
= src_rect
.right
- src_rect
.left
;
5992 UINT src_h
= src_rect
.bottom
- src_rect
.top
;
5993 RECT dst_rect
= {point
.x
, point
.y
, point
.x
+ src_w
, point
.y
+ src_h
};
5995 if (FAILED(hr
= wined3d_surface_blt(dest_level
->wined3d_surface
, &dst_rect
,
5996 src_level
->wined3d_surface
, &src_rect
, 0, NULL
, WINED3D_TEXF_POINT
)))
5997 ERR("Blit failed, hr %#x.\n", hr
);
5999 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
6000 ddsd
.ddsCaps
.dwCaps2
= DDSCAPS2_MIPMAPSUBLEVEL
;
6001 IDirectDrawSurface7_GetAttachedSurface(&dest_level
->IDirectDrawSurface7_iface
, &ddsd
.ddsCaps
, &temp
);
6003 if (dest_level
!= dest
) IDirectDrawSurface7_Release(&dest_level
->IDirectDrawSurface7_iface
);
6005 dest_level
= unsafe_impl_from_IDirectDrawSurface7(temp
);
6008 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
6009 ddsd
.ddsCaps
.dwCaps2
= DDSCAPS2_MIPMAPSUBLEVEL
;
6010 IDirectDrawSurface7_GetAttachedSurface(&src_level
->IDirectDrawSurface7_iface
, &ddsd
.ddsCaps
, &temp
);
6012 if (src_level
!= src
) IDirectDrawSurface7_Release(&src_level
->IDirectDrawSurface7_iface
);
6014 src_level
= unsafe_impl_from_IDirectDrawSurface7(temp
);
6021 src_rect
.right
= (src_rect
.right
+ 1) / 2;
6022 src_rect
.bottom
= (src_rect
.bottom
+ 1) / 2;
6025 if (src_level
&& src_level
!= src
) IDirectDrawSurface7_Release(&src_level
->IDirectDrawSurface7_iface
);
6026 if (dest_level
&& dest_level
!= dest
) IDirectDrawSurface7_Release(&dest_level
->IDirectDrawSurface7_iface
);
6029 /*****************************************************************************
6030 * IDirect3DDevice7::Load
6032 * Loads a rectangular area from the source into the destination texture.
6033 * It can also copy the source to the faces of a cubic environment map
6038 * DestTex: Destination texture
6039 * DestPoint: Point in the destination where the source image should be
6041 * SrcTex: Source texture
6042 * SrcRect: Source rectangle
6043 * Flags: Cubemap faces to load (DDSCAPS2_CUBEMAP_ALLFACES, DDSCAPS2_CUBEMAP_POSITIVEX,
6044 * DDSCAPS2_CUBEMAP_NEGATIVEX, DDSCAPS2_CUBEMAP_POSITIVEY, DDSCAPS2_CUBEMAP_NEGATIVEY,
6045 * DDSCAPS2_CUBEMAP_POSITIVEZ, DDSCAPS2_CUBEMAP_NEGATIVEZ)
6049 * DDERR_INVALIDPARAMS if DestTex or SrcTex are NULL, broken coordinates or anything unexpected.
6052 *****************************************************************************/
6053 static HRESULT
d3d_device7_Load(IDirect3DDevice7
*iface
, IDirectDrawSurface7
*dst_texture
, POINT
*dst_pos
,
6054 IDirectDrawSurface7
*src_texture
, RECT
*src_rect
, DWORD flags
)
6056 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
6057 struct ddraw_surface
*dest
= unsafe_impl_from_IDirectDrawSurface7(dst_texture
);
6058 struct ddraw_surface
*src
= unsafe_impl_from_IDirectDrawSurface7(src_texture
);
6062 TRACE("iface %p, dst_texture %p, dst_pos %s, src_texture %p, src_rect %s, flags %#x.\n",
6063 iface
, dst_texture
, wine_dbgstr_point(dst_pos
), src_texture
, wine_dbgstr_rect(src_rect
), flags
);
6065 if( (!src
) || (!dest
) )
6066 return DDERR_INVALIDPARAMS
;
6068 wined3d_mutex_lock();
6072 srcrect
.left
= srcrect
.top
= 0;
6073 srcrect
.right
= src
->surface_desc
.dwWidth
;
6074 srcrect
.bottom
= src
->surface_desc
.dwHeight
;
6077 srcrect
= *src_rect
;
6080 destpoint
.x
= destpoint
.y
= 0;
6082 destpoint
= *dst_pos
;
6084 /* Check bad dimensions. dst_pos is validated against src, not dest, because
6085 * destination can be a subset of mip levels, in which case actual coordinates used
6086 * for it may be divided. If any dimension of dest is larger than source, it can't be
6087 * mip level subset, so an error can be returned early.
6089 if (srcrect
.left
>= srcrect
.right
|| srcrect
.top
>= srcrect
.bottom
||
6090 srcrect
.right
> src
->surface_desc
.dwWidth
||
6091 srcrect
.bottom
> src
->surface_desc
.dwHeight
||
6092 destpoint
.x
+ srcrect
.right
- srcrect
.left
> src
->surface_desc
.dwWidth
||
6093 destpoint
.y
+ srcrect
.bottom
- srcrect
.top
> src
->surface_desc
.dwHeight
||
6094 dest
->surface_desc
.dwWidth
> src
->surface_desc
.dwWidth
||
6095 dest
->surface_desc
.dwHeight
> src
->surface_desc
.dwHeight
)
6097 wined3d_mutex_unlock();
6098 return DDERR_INVALIDPARAMS
;
6101 /* Must be top level surfaces. */
6102 if (src
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_MIPMAPSUBLEVEL
||
6103 dest
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_MIPMAPSUBLEVEL
)
6105 wined3d_mutex_unlock();
6106 return DDERR_INVALIDPARAMS
;
6109 if (src
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
6111 struct ddraw_surface
*src_face
, *dest_face
;
6112 DWORD src_face_flag
, dest_face_flag
;
6113 IDirectDrawSurface7
*temp
;
6114 DDSURFACEDESC2 ddsd
;
6117 if (!(dest
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
))
6119 wined3d_mutex_unlock();
6120 return DDERR_INVALIDPARAMS
;
6123 /* Iterate through cube faces 2 times. First time is just to check INVALIDPARAMS conditions, second
6124 * time it's actual surface loading. */
6125 for (i
= 0; i
< 2; i
++)
6130 for (;dest_face
&& src_face
;)
6132 src_face_flag
= src_face
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
;
6133 dest_face_flag
= dest_face
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
;
6135 if (src_face_flag
== dest_face_flag
)
6139 /* Destination mip levels must be subset of source mip levels. */
6140 if (!is_mip_level_subset(dest_face
, src_face
))
6142 wined3d_mutex_unlock();
6143 return DDERR_INVALIDPARAMS
;
6146 else if (flags
& dest_face_flag
)
6148 copy_mipmap_chain(device
, dest_face
, src_face
, &destpoint
, &srcrect
);
6151 if (src_face_flag
< DDSCAPS2_CUBEMAP_NEGATIVEZ
)
6153 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
6154 ddsd
.ddsCaps
.dwCaps2
= DDSCAPS2_CUBEMAP
| (src_face_flag
<< 1);
6155 IDirectDrawSurface7_GetAttachedSurface(&src
->IDirectDrawSurface7_iface
, &ddsd
.ddsCaps
, &temp
);
6157 if (src_face
!= src
) IDirectDrawSurface7_Release(&src_face
->IDirectDrawSurface7_iface
);
6159 src_face
= unsafe_impl_from_IDirectDrawSurface7(temp
);
6163 if (src_face
!= src
) IDirectDrawSurface7_Release(&src_face
->IDirectDrawSurface7_iface
);
6169 if (dest_face_flag
< DDSCAPS2_CUBEMAP_NEGATIVEZ
)
6171 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
6172 ddsd
.ddsCaps
.dwCaps2
= DDSCAPS2_CUBEMAP
| (dest_face_flag
<< 1);
6173 IDirectDrawSurface7_GetAttachedSurface(&dest
->IDirectDrawSurface7_iface
, &ddsd
.ddsCaps
, &temp
);
6175 if (dest_face
!= dest
) IDirectDrawSurface7_Release(&dest_face
->IDirectDrawSurface7_iface
);
6177 dest_face
= unsafe_impl_from_IDirectDrawSurface7(temp
);
6181 if (dest_face
!= dest
) IDirectDrawSurface7_Release(&dest_face
->IDirectDrawSurface7_iface
);
6189 /* Native returns error if src faces are not subset of dest faces. */
6192 wined3d_mutex_unlock();
6193 return DDERR_INVALIDPARAMS
;
6198 wined3d_mutex_unlock();
6201 else if (dest
->surface_desc
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
6203 wined3d_mutex_unlock();
6204 return DDERR_INVALIDPARAMS
;
6207 /* Handle non cube map textures. */
6209 /* Destination mip levels must be subset of source mip levels. */
6210 if (!is_mip_level_subset(dest
, src
))
6212 wined3d_mutex_unlock();
6213 return DDERR_INVALIDPARAMS
;
6216 copy_mipmap_chain(device
, dest
, src
, &destpoint
, &srcrect
);
6218 wined3d_mutex_unlock();
6223 static HRESULT WINAPI
d3d_device7_Load_FPUSetup(IDirect3DDevice7
*iface
, IDirectDrawSurface7
*dst_texture
,
6224 POINT
*dst_pos
, IDirectDrawSurface7
*src_texture
, RECT
*src_rect
, DWORD flags
)
6226 return d3d_device7_Load(iface
, dst_texture
, dst_pos
, src_texture
, src_rect
, flags
);
6229 static HRESULT WINAPI
d3d_device7_Load_FPUPreserve(IDirect3DDevice7
*iface
, IDirectDrawSurface7
*dst_texture
,
6230 POINT
*dst_pos
, IDirectDrawSurface7
*src_texture
, RECT
*src_rect
, DWORD flags
)
6235 old_fpucw
= d3d_fpu_setup();
6236 hr
= d3d_device7_Load(iface
, dst_texture
, dst_pos
, src_texture
, src_rect
, flags
);
6237 set_fpu_control_word(old_fpucw
);
6242 /*****************************************************************************
6243 * IDirect3DDevice7::LightEnable
6245 * Enables or disables a light
6247 * Version 7, IDirect3DLight uses this method too.
6250 * LightIndex: The index of the light to enable / disable
6251 * Enable: Enable or disable the light
6255 * For more details, see IWineD3DDevice::SetLightEnable
6257 *****************************************************************************/
6258 static HRESULT
d3d_device7_LightEnable(IDirect3DDevice7
*iface
, DWORD light_idx
, BOOL enabled
)
6260 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
6263 TRACE("iface %p, light_idx %u, enabled %#x.\n", iface
, light_idx
, enabled
);
6265 wined3d_mutex_lock();
6266 hr
= wined3d_device_set_light_enable(device
->wined3d_device
, light_idx
, enabled
);
6267 wined3d_mutex_unlock();
6269 return hr_ddraw_from_wined3d(hr
);
6272 static HRESULT WINAPI
d3d_device7_LightEnable_FPUSetup(IDirect3DDevice7
*iface
, DWORD light_idx
, BOOL enabled
)
6274 return d3d_device7_LightEnable(iface
, light_idx
, enabled
);
6277 static HRESULT WINAPI
d3d_device7_LightEnable_FPUPreserve(IDirect3DDevice7
*iface
, DWORD light_idx
, BOOL enabled
)
6282 old_fpucw
= d3d_fpu_setup();
6283 hr
= d3d_device7_LightEnable(iface
, light_idx
, enabled
);
6284 set_fpu_control_word(old_fpucw
);
6289 /*****************************************************************************
6290 * IDirect3DDevice7::GetLightEnable
6292 * Retrieves if the light with the given index is enabled or not
6297 * LightIndex: Index of desired light
6298 * Enable: Pointer to a BOOL which contains the result
6302 * DDERR_INVALIDPARAMS if Enable is NULL
6303 * See IWineD3DDevice::GetLightEnable for more details
6305 *****************************************************************************/
6306 static HRESULT
d3d_device7_GetLightEnable(IDirect3DDevice7
*iface
, DWORD light_idx
, BOOL
*enabled
)
6308 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
6311 TRACE("iface %p, light_idx %u, enabled %p.\n", iface
, light_idx
, enabled
);
6314 return DDERR_INVALIDPARAMS
;
6316 wined3d_mutex_lock();
6317 hr
= wined3d_device_get_light_enable(device
->wined3d_device
, light_idx
, enabled
);
6318 wined3d_mutex_unlock();
6320 return hr_ddraw_from_wined3d(hr
);
6323 static HRESULT WINAPI
d3d_device7_GetLightEnable_FPUSetup(IDirect3DDevice7
*iface
, DWORD light_idx
, BOOL
*enabled
)
6325 return d3d_device7_GetLightEnable(iface
, light_idx
, enabled
);
6328 static HRESULT WINAPI
d3d_device7_GetLightEnable_FPUPreserve(IDirect3DDevice7
*iface
, DWORD light_idx
, BOOL
*enabled
)
6333 old_fpucw
= d3d_fpu_setup();
6334 hr
= d3d_device7_GetLightEnable(iface
, light_idx
, enabled
);
6335 set_fpu_control_word(old_fpucw
);
6340 /*****************************************************************************
6341 * IDirect3DDevice7::SetClipPlane
6343 * Sets custom clipping plane
6348 * Index: The index of the clipping plane
6349 * PlaneEquation: An equation defining the clipping plane
6353 * DDERR_INVALIDPARAMS if PlaneEquation is NULL
6354 * See IWineD3DDevice::SetClipPlane for more details
6356 *****************************************************************************/
6357 static HRESULT
d3d_device7_SetClipPlane(IDirect3DDevice7
*iface
, DWORD idx
, D3DVALUE
*plane
)
6359 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
6362 TRACE("iface %p, idx %u, plane %p.\n", iface
, idx
, plane
);
6365 return DDERR_INVALIDPARAMS
;
6367 wined3d_mutex_lock();
6368 hr
= wined3d_device_set_clip_plane(device
->wined3d_device
, idx
, (struct wined3d_vec4
*)plane
);
6369 wined3d_mutex_unlock();
6374 static HRESULT WINAPI
d3d_device7_SetClipPlane_FPUSetup(IDirect3DDevice7
*iface
, DWORD idx
, D3DVALUE
*plane
)
6376 return d3d_device7_SetClipPlane(iface
, idx
, plane
);
6379 static HRESULT WINAPI
d3d_device7_SetClipPlane_FPUPreserve(IDirect3DDevice7
*iface
, DWORD idx
, D3DVALUE
*plane
)
6384 old_fpucw
= d3d_fpu_setup();
6385 hr
= d3d_device7_SetClipPlane(iface
, idx
, plane
);
6386 set_fpu_control_word(old_fpucw
);
6391 /*****************************************************************************
6392 * IDirect3DDevice7::GetClipPlane
6394 * Returns the clipping plane with a specific index
6397 * Index: The index of the desired plane
6398 * PlaneEquation: Address to store the plane equation to
6402 * DDERR_INVALIDPARAMS if PlaneEquation is NULL
6403 * See IWineD3DDevice::GetClipPlane for more details
6405 *****************************************************************************/
6406 static HRESULT
d3d_device7_GetClipPlane(IDirect3DDevice7
*iface
, DWORD idx
, D3DVALUE
*plane
)
6408 struct d3d_device
*device
= impl_from_IDirect3DDevice7(iface
);
6411 TRACE("iface %p, idx %u, plane %p.\n", iface
, idx
, plane
);
6414 return DDERR_INVALIDPARAMS
;
6416 wined3d_mutex_lock();
6417 hr
= wined3d_device_get_clip_plane(device
->wined3d_device
, idx
, (struct wined3d_vec4
*)plane
);
6418 wined3d_mutex_unlock();
6423 static HRESULT WINAPI
d3d_device7_GetClipPlane_FPUSetup(IDirect3DDevice7
*iface
, DWORD idx
, D3DVALUE
*plane
)
6425 return d3d_device7_GetClipPlane(iface
, idx
, plane
);
6428 static HRESULT WINAPI
d3d_device7_GetClipPlane_FPUPreserve(IDirect3DDevice7
*iface
, DWORD idx
, D3DVALUE
*plane
)
6433 old_fpucw
= d3d_fpu_setup();
6434 hr
= d3d_device7_GetClipPlane(iface
, idx
, plane
);
6435 set_fpu_control_word(old_fpucw
);
6440 /*****************************************************************************
6441 * IDirect3DDevice7::GetInfo
6443 * Retrieves some information about the device. The DirectX sdk says that
6444 * this version returns S_FALSE for all retail builds of DirectX, that's what
6445 * this implementation does.
6448 * DevInfoID: Information type requested
6449 * DevInfoStruct: Pointer to a structure to store the info to
6450 * Size: Size of the structure
6453 * S_FALSE, because it's a non-debug driver
6455 *****************************************************************************/
6456 static HRESULT WINAPI
d3d_device7_GetInfo(IDirect3DDevice7
*iface
, DWORD info_id
, void *info
, DWORD info_size
)
6458 TRACE("iface %p, info_id %#x, info %p, info_size %u.\n",
6459 iface
, info_id
, info
, info_size
);
6461 if (TRACE_ON(ddraw
))
6463 TRACE(" info requested : ");
6466 case D3DDEVINFOID_TEXTUREMANAGER
: TRACE("D3DDEVINFOID_TEXTUREMANAGER\n"); break;
6467 case D3DDEVINFOID_D3DTEXTUREMANAGER
: TRACE("D3DDEVINFOID_D3DTEXTUREMANAGER\n"); break;
6468 case D3DDEVINFOID_TEXTURING
: TRACE("D3DDEVINFOID_TEXTURING\n"); break;
6469 default: ERR(" invalid flag !!!\n"); return DDERR_INVALIDPARAMS
;
6473 return S_FALSE
; /* According to MSDN, this is valid for a non-debug driver */
6476 /* For performance optimization, devices created in FPUSETUP and FPUPRESERVE modes
6477 * have separate vtables. Simple functions where this doesn't matter like GetDirect3D
6478 * are not duplicated.
6480 * Device created with DDSCL_FPUSETUP (d3d7 default) - device methods assume that FPU
6481 * has already been setup for optimal d3d operation.
6483 * Device created with DDSCL_FPUPRESERVE - resets and restores FPU mode when necessary in
6484 * d3d calls (FPU may be in a mode non-suitable for d3d when the app calls d3d). Required
6485 * by Sacrifice (game). */
6486 static const struct IDirect3DDevice7Vtbl d3d_device7_fpu_setup_vtbl
=
6488 /*** IUnknown Methods ***/
6489 d3d_device7_QueryInterface
,
6491 d3d_device7_Release
,
6492 /*** IDirect3DDevice7 ***/
6493 d3d_device7_GetCaps_FPUSetup
,
6494 d3d_device7_EnumTextureFormats_FPUSetup
,
6495 d3d_device7_BeginScene_FPUSetup
,
6496 d3d_device7_EndScene_FPUSetup
,
6497 d3d_device7_GetDirect3D
,
6498 d3d_device7_SetRenderTarget_FPUSetup
,
6499 d3d_device7_GetRenderTarget
,
6500 d3d_device7_Clear_FPUSetup
,
6501 d3d_device7_SetTransform_FPUSetup
,
6502 d3d_device7_GetTransform_FPUSetup
,
6503 d3d_device7_SetViewport_FPUSetup
,
6504 d3d_device7_MultiplyTransform_FPUSetup
,
6505 d3d_device7_GetViewport_FPUSetup
,
6506 d3d_device7_SetMaterial_FPUSetup
,
6507 d3d_device7_GetMaterial_FPUSetup
,
6508 d3d_device7_SetLight_FPUSetup
,
6509 d3d_device7_GetLight_FPUSetup
,
6510 d3d_device7_SetRenderState_FPUSetup
,
6511 d3d_device7_GetRenderState_FPUSetup
,
6512 d3d_device7_BeginStateBlock_FPUSetup
,
6513 d3d_device7_EndStateBlock_FPUSetup
,
6514 d3d_device7_PreLoad_FPUSetup
,
6515 d3d_device7_DrawPrimitive_FPUSetup
,
6516 d3d_device7_DrawIndexedPrimitive_FPUSetup
,
6517 d3d_device7_SetClipStatus
,
6518 d3d_device7_GetClipStatus
,
6519 d3d_device7_DrawPrimitiveStrided_FPUSetup
,
6520 d3d_device7_DrawIndexedPrimitiveStrided_FPUSetup
,
6521 d3d_device7_DrawPrimitiveVB_FPUSetup
,
6522 d3d_device7_DrawIndexedPrimitiveVB_FPUSetup
,
6523 d3d_device7_ComputeSphereVisibility
,
6524 d3d_device7_GetTexture_FPUSetup
,
6525 d3d_device7_SetTexture_FPUSetup
,
6526 d3d_device7_GetTextureStageState_FPUSetup
,
6527 d3d_device7_SetTextureStageState_FPUSetup
,
6528 d3d_device7_ValidateDevice_FPUSetup
,
6529 d3d_device7_ApplyStateBlock_FPUSetup
,
6530 d3d_device7_CaptureStateBlock_FPUSetup
,
6531 d3d_device7_DeleteStateBlock_FPUSetup
,
6532 d3d_device7_CreateStateBlock_FPUSetup
,
6533 d3d_device7_Load_FPUSetup
,
6534 d3d_device7_LightEnable_FPUSetup
,
6535 d3d_device7_GetLightEnable_FPUSetup
,
6536 d3d_device7_SetClipPlane_FPUSetup
,
6537 d3d_device7_GetClipPlane_FPUSetup
,
6541 static const struct IDirect3DDevice7Vtbl d3d_device7_fpu_preserve_vtbl
=
6543 /*** IUnknown Methods ***/
6544 d3d_device7_QueryInterface
,
6546 d3d_device7_Release
,
6547 /*** IDirect3DDevice7 ***/
6548 d3d_device7_GetCaps_FPUPreserve
,
6549 d3d_device7_EnumTextureFormats_FPUPreserve
,
6550 d3d_device7_BeginScene_FPUPreserve
,
6551 d3d_device7_EndScene_FPUPreserve
,
6552 d3d_device7_GetDirect3D
,
6553 d3d_device7_SetRenderTarget_FPUPreserve
,
6554 d3d_device7_GetRenderTarget
,
6555 d3d_device7_Clear_FPUPreserve
,
6556 d3d_device7_SetTransform_FPUPreserve
,
6557 d3d_device7_GetTransform_FPUPreserve
,
6558 d3d_device7_SetViewport_FPUPreserve
,
6559 d3d_device7_MultiplyTransform_FPUPreserve
,
6560 d3d_device7_GetViewport_FPUPreserve
,
6561 d3d_device7_SetMaterial_FPUPreserve
,
6562 d3d_device7_GetMaterial_FPUPreserve
,
6563 d3d_device7_SetLight_FPUPreserve
,
6564 d3d_device7_GetLight_FPUPreserve
,
6565 d3d_device7_SetRenderState_FPUPreserve
,
6566 d3d_device7_GetRenderState_FPUPreserve
,
6567 d3d_device7_BeginStateBlock_FPUPreserve
,
6568 d3d_device7_EndStateBlock_FPUPreserve
,
6569 d3d_device7_PreLoad_FPUPreserve
,
6570 d3d_device7_DrawPrimitive_FPUPreserve
,
6571 d3d_device7_DrawIndexedPrimitive_FPUPreserve
,
6572 d3d_device7_SetClipStatus
,
6573 d3d_device7_GetClipStatus
,
6574 d3d_device7_DrawPrimitiveStrided_FPUPreserve
,
6575 d3d_device7_DrawIndexedPrimitiveStrided_FPUPreserve
,
6576 d3d_device7_DrawPrimitiveVB_FPUPreserve
,
6577 d3d_device7_DrawIndexedPrimitiveVB_FPUPreserve
,
6578 d3d_device7_ComputeSphereVisibility
,
6579 d3d_device7_GetTexture_FPUPreserve
,
6580 d3d_device7_SetTexture_FPUPreserve
,
6581 d3d_device7_GetTextureStageState_FPUPreserve
,
6582 d3d_device7_SetTextureStageState_FPUPreserve
,
6583 d3d_device7_ValidateDevice_FPUPreserve
,
6584 d3d_device7_ApplyStateBlock_FPUPreserve
,
6585 d3d_device7_CaptureStateBlock_FPUPreserve
,
6586 d3d_device7_DeleteStateBlock_FPUPreserve
,
6587 d3d_device7_CreateStateBlock_FPUPreserve
,
6588 d3d_device7_Load_FPUPreserve
,
6589 d3d_device7_LightEnable_FPUPreserve
,
6590 d3d_device7_GetLightEnable_FPUPreserve
,
6591 d3d_device7_SetClipPlane_FPUPreserve
,
6592 d3d_device7_GetClipPlane_FPUPreserve
,
6596 static const struct IDirect3DDevice3Vtbl d3d_device3_vtbl
=
6598 /*** IUnknown Methods ***/
6599 d3d_device3_QueryInterface
,
6601 d3d_device3_Release
,
6602 /*** IDirect3DDevice3 ***/
6603 d3d_device3_GetCaps
,
6604 d3d_device3_GetStats
,
6605 d3d_device3_AddViewport
,
6606 d3d_device3_DeleteViewport
,
6607 d3d_device3_NextViewport
,
6608 d3d_device3_EnumTextureFormats
,
6609 d3d_device3_BeginScene
,
6610 d3d_device3_EndScene
,
6611 d3d_device3_GetDirect3D
,
6612 d3d_device3_SetCurrentViewport
,
6613 d3d_device3_GetCurrentViewport
,
6614 d3d_device3_SetRenderTarget
,
6615 d3d_device3_GetRenderTarget
,
6617 d3d_device3_BeginIndexed
,
6621 d3d_device3_GetRenderState
,
6622 d3d_device3_SetRenderState
,
6623 d3d_device3_GetLightState
,
6624 d3d_device3_SetLightState
,
6625 d3d_device3_SetTransform
,
6626 d3d_device3_GetTransform
,
6627 d3d_device3_MultiplyTransform
,
6628 d3d_device3_DrawPrimitive
,
6629 d3d_device3_DrawIndexedPrimitive
,
6630 d3d_device3_SetClipStatus
,
6631 d3d_device3_GetClipStatus
,
6632 d3d_device3_DrawPrimitiveStrided
,
6633 d3d_device3_DrawIndexedPrimitiveStrided
,
6634 d3d_device3_DrawPrimitiveVB
,
6635 d3d_device3_DrawIndexedPrimitiveVB
,
6636 d3d_device3_ComputeSphereVisibility
,
6637 d3d_device3_GetTexture
,
6638 d3d_device3_SetTexture
,
6639 d3d_device3_GetTextureStageState
,
6640 d3d_device3_SetTextureStageState
,
6641 d3d_device3_ValidateDevice
6644 static const struct IDirect3DDevice2Vtbl d3d_device2_vtbl
=
6646 /*** IUnknown Methods ***/
6647 d3d_device2_QueryInterface
,
6649 d3d_device2_Release
,
6650 /*** IDirect3DDevice2 ***/
6651 d3d_device2_GetCaps
,
6652 d3d_device2_SwapTextureHandles
,
6653 d3d_device2_GetStats
,
6654 d3d_device2_AddViewport
,
6655 d3d_device2_DeleteViewport
,
6656 d3d_device2_NextViewport
,
6657 d3d_device2_EnumTextureFormats
,
6658 d3d_device2_BeginScene
,
6659 d3d_device2_EndScene
,
6660 d3d_device2_GetDirect3D
,
6661 d3d_device2_SetCurrentViewport
,
6662 d3d_device2_GetCurrentViewport
,
6663 d3d_device2_SetRenderTarget
,
6664 d3d_device2_GetRenderTarget
,
6666 d3d_device2_BeginIndexed
,
6670 d3d_device2_GetRenderState
,
6671 d3d_device2_SetRenderState
,
6672 d3d_device2_GetLightState
,
6673 d3d_device2_SetLightState
,
6674 d3d_device2_SetTransform
,
6675 d3d_device2_GetTransform
,
6676 d3d_device2_MultiplyTransform
,
6677 d3d_device2_DrawPrimitive
,
6678 d3d_device2_DrawIndexedPrimitive
,
6679 d3d_device2_SetClipStatus
,
6680 d3d_device2_GetClipStatus
6683 static const struct IDirect3DDeviceVtbl d3d_device1_vtbl
=
6685 /*** IUnknown Methods ***/
6686 d3d_device1_QueryInterface
,
6688 d3d_device1_Release
,
6689 /*** IDirect3DDevice1 ***/
6690 d3d_device1_Initialize
,
6691 d3d_device1_GetCaps
,
6692 d3d_device1_SwapTextureHandles
,
6693 d3d_device1_CreateExecuteBuffer
,
6694 d3d_device1_GetStats
,
6695 d3d_device1_Execute
,
6696 d3d_device1_AddViewport
,
6697 d3d_device1_DeleteViewport
,
6698 d3d_device1_NextViewport
,
6700 d3d_device1_GetPickRecords
,
6701 d3d_device1_EnumTextureFormats
,
6702 d3d_device1_CreateMatrix
,
6703 d3d_device1_SetMatrix
,
6704 d3d_device1_GetMatrix
,
6705 d3d_device1_DeleteMatrix
,
6706 d3d_device1_BeginScene
,
6707 d3d_device1_EndScene
,
6708 d3d_device1_GetDirect3D
6711 static const struct IUnknownVtbl d3d_device_inner_vtbl
=
6713 d3d_device_inner_QueryInterface
,
6714 d3d_device_inner_AddRef
,
6715 d3d_device_inner_Release
,
6718 struct d3d_device
*unsafe_impl_from_IDirect3DDevice7(IDirect3DDevice7
*iface
)
6720 if (!iface
) return NULL
;
6721 assert((iface
->lpVtbl
== &d3d_device7_fpu_preserve_vtbl
) || (iface
->lpVtbl
== &d3d_device7_fpu_setup_vtbl
));
6722 return CONTAINING_RECORD(iface
, struct d3d_device
, IDirect3DDevice7_iface
);
6725 struct d3d_device
*unsafe_impl_from_IDirect3DDevice3(IDirect3DDevice3
*iface
)
6727 if (!iface
) return NULL
;
6728 assert(iface
->lpVtbl
== &d3d_device3_vtbl
);
6729 return CONTAINING_RECORD(iface
, struct d3d_device
, IDirect3DDevice3_iface
);
6732 struct d3d_device
*unsafe_impl_from_IDirect3DDevice2(IDirect3DDevice2
*iface
)
6734 if (!iface
) return NULL
;
6735 assert(iface
->lpVtbl
== &d3d_device2_vtbl
);
6736 return CONTAINING_RECORD(iface
, struct d3d_device
, IDirect3DDevice2_iface
);
6739 struct d3d_device
*unsafe_impl_from_IDirect3DDevice(IDirect3DDevice
*iface
)
6741 if (!iface
) return NULL
;
6742 assert(iface
->lpVtbl
== &d3d_device1_vtbl
);
6743 return CONTAINING_RECORD(iface
, struct d3d_device
, IDirect3DDevice_iface
);
6746 enum wined3d_depth_buffer_type
d3d_device_update_depth_stencil(struct d3d_device
*device
)
6748 IDirectDrawSurface7
*depthStencil
= NULL
;
6749 IDirectDrawSurface7
*render_target
;
6750 static DDSCAPS2 depthcaps
= { DDSCAPS_ZBUFFER
, 0, 0, {0} };
6751 struct ddraw_surface
*dsi
;
6753 if (device
->rt_iface
&& SUCCEEDED(IUnknown_QueryInterface(device
->rt_iface
,
6754 &IID_IDirectDrawSurface7
, (void **)&render_target
)))
6756 IDirectDrawSurface7_GetAttachedSurface(render_target
, &depthcaps
, &depthStencil
);
6757 IDirectDrawSurface7_Release(render_target
);
6761 TRACE("Setting wined3d depth stencil to NULL\n");
6762 wined3d_device_set_depth_stencil(device
->wined3d_device
, NULL
);
6763 return WINED3D_ZB_FALSE
;
6766 dsi
= impl_from_IDirectDrawSurface7(depthStencil
);
6767 TRACE("Setting wined3d depth stencil to %p (wined3d %p)\n", dsi
, dsi
->wined3d_surface
);
6768 wined3d_device_set_depth_stencil(device
->wined3d_device
, dsi
->wined3d_surface
);
6770 IDirectDrawSurface7_Release(depthStencil
);
6771 return WINED3D_ZB_TRUE
;
6774 static HRESULT
d3d_device_init(struct d3d_device
*device
, struct ddraw
*ddraw
,
6775 struct ddraw_surface
*target
, IUnknown
*rt_iface
, UINT version
, IUnknown
*outer_unknown
)
6777 static const D3DMATRIX ident
=
6779 1.0f
, 0.0f
, 0.0f
, 0.0f
,
6780 0.0f
, 1.0f
, 0.0f
, 0.0f
,
6781 0.0f
, 0.0f
, 1.0f
, 0.0f
,
6782 0.0f
, 0.0f
, 0.0f
, 1.0f
,
6786 if (ddraw
->cooperative_level
& DDSCL_FPUPRESERVE
)
6787 device
->IDirect3DDevice7_iface
.lpVtbl
= &d3d_device7_fpu_preserve_vtbl
;
6789 device
->IDirect3DDevice7_iface
.lpVtbl
= &d3d_device7_fpu_setup_vtbl
;
6791 device
->IDirect3DDevice3_iface
.lpVtbl
= &d3d_device3_vtbl
;
6792 device
->IDirect3DDevice2_iface
.lpVtbl
= &d3d_device2_vtbl
;
6793 device
->IDirect3DDevice_iface
.lpVtbl
= &d3d_device1_vtbl
;
6794 device
->IUnknown_inner
.lpVtbl
= &d3d_device_inner_vtbl
;
6796 device
->version
= version
;
6799 device
->outer_unknown
= outer_unknown
;
6801 device
->outer_unknown
= &device
->IUnknown_inner
;
6803 device
->ddraw
= ddraw
;
6804 list_init(&device
->viewport_list
);
6806 if (!ddraw_handle_table_init(&device
->handle_table
, 64))
6808 ERR("Failed to initialize handle table.\n");
6809 return DDERR_OUTOFMEMORY
;
6812 device
->legacyTextureBlending
= FALSE
;
6813 device
->legacy_projection
= ident
;
6814 device
->legacy_clipspace
= ident
;
6816 /* This is for convenience. */
6817 device
->wined3d_device
= ddraw
->wined3d_device
;
6818 wined3d_device_incref(ddraw
->wined3d_device
);
6820 /* Render to the back buffer */
6821 hr
= wined3d_device_set_render_target(ddraw
->wined3d_device
, 0, target
->wined3d_surface
, TRUE
);
6824 ERR("Failed to set render target, hr %#x.\n", hr
);
6825 ddraw_handle_table_destroy(&device
->handle_table
);
6829 device
->rt_iface
= rt_iface
;
6831 IUnknown_AddRef(device
->rt_iface
);
6833 ddraw
->d3ddevice
= device
;
6835 wined3d_device_set_render_state(ddraw
->wined3d_device
, WINED3D_RS_ZENABLE
,
6836 d3d_device_update_depth_stencil(device
));
6837 if (version
== 1) /* Color keying is initially enabled for version 1 devices. */
6838 wined3d_device_set_render_state(ddraw
->wined3d_device
, WINED3D_RS_COLORKEYENABLE
, TRUE
);
6839 else if (version
== 2)
6840 wined3d_device_set_render_state(ddraw
->wined3d_device
, WINED3D_RS_SPECULARENABLE
, TRUE
);
6845 HRESULT
d3d_device_create(struct ddraw
*ddraw
, struct ddraw_surface
*target
, IUnknown
*rt_iface
,
6846 UINT version
, struct d3d_device
**device
, IUnknown
*outer_unknown
)
6848 struct d3d_device
*object
;
6851 TRACE("ddraw %p, target %p, version %u, device %p, outer_unknown %p.\n",
6852 ddraw
, target
, version
, device
, outer_unknown
);
6854 if (!(target
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
6855 || (target
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
))
6857 WARN("Surface %p is not a render target.\n", target
);
6858 return DDERR_INVALIDCAPS
;
6861 if (!validate_surface_palette(target
))
6863 WARN("Surface %p has an indexed pixel format, but no palette.\n", target
);
6864 return DDERR_NOPALETTEATTACHED
;
6867 if (!(target
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
))
6869 WARN("Surface %p is not in video memory.\n", target
);
6870 return D3DERR_SURFACENOTINVIDMEM
;
6873 if (ddraw
->flags
& DDRAW_NO3D
)
6875 ERR_(winediag
)("The application wants to create a Direct3D device, "
6876 "but the current DirectDrawRenderer does not support this.\n");
6881 if (ddraw
->d3ddevice
)
6883 FIXME("Only one Direct3D device per DirectDraw object supported.\n");
6884 return DDERR_INVALIDPARAMS
;
6887 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
6890 ERR("Failed to allocate device memory.\n");
6891 return DDERR_OUTOFMEMORY
;
6894 if (FAILED(hr
= d3d_device_init(object
, ddraw
, target
, rt_iface
, version
, outer_unknown
)))
6896 WARN("Failed to initialize device, hr %#x.\n", hr
);
6897 HeapFree(GetProcessHeap(), 0, object
);
6901 TRACE("Created device %p.\n", object
);