2 * Copyright (c) 1998-2004 Lionel Ulmer
3 * Copyright (c) 2002-2005 Christian Costa
4 * Copyright (c) 2006 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
31 #include "wine/port.h"
33 #include "ddraw_private.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
38 const GUID IID_D3DDEVICE_WineD3D = {
42 { 0xb7,0x98,0xc6,0x8a,0x77,0x2d,0x72,0x2a }
45 static inline void set_fpu_control_word(WORD fpucw)
47 #if defined(__i386__) && defined(__GNUC__)
48 __asm__ volatile ("fldcw %0" : : "m" (fpucw));
49 #elif defined(__i386__) && defined(_MSC_VER)
54 static inline WORD d3d_fpu_setup(void)
58 #if defined(__i386__) && defined(__GNUC__)
59 __asm__ volatile ("fnstcw %0" : "=m" (oldcw));
60 #elif defined(__i386__) && defined(_MSC_VER)
63 static BOOL warned = FALSE;
66 FIXME("FPUPRESERVE not implemented for this platform / compiler\n");
72 set_fpu_control_word(0x37f);
77 /*****************************************************************************
78 * IUnknown Methods. Common for Version 1, 2, 3 and 7
79 *****************************************************************************/
81 /*****************************************************************************
82 * IDirect3DDevice7::QueryInterface
84 * Used to query other interfaces from a Direct3DDevice interface.
85 * It can return interface pointers to all Direct3DDevice versions as well
86 * as IDirectDraw and IDirect3D. For a link to QueryInterface
87 * rules see ddraw.c, IDirectDraw7::QueryInterface
89 * Exists in Version 1, 2, 3 and 7
92 * refiid: Interface ID queried for
93 * obj: Used to return the interface pointer
96 * D3D_OK or E_NOINTERFACE
98 *****************************************************************************/
100 IDirect3DDeviceImpl_7_QueryInterface(IDirect3DDevice7 *iface,
104 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
106 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(refiid), obj);
108 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
112 return DDERR_INVALIDPARAMS;
114 if ( IsEqualGUID( &IID_IUnknown, refiid ) )
119 /* Check DirectDraw Interfaces. */
120 else if( IsEqualGUID( &IID_IDirectDraw7, refiid ) )
122 *obj = &This->ddraw->IDirectDraw7_iface;
123 TRACE("(%p) Returning IDirectDraw7 interface at %p\n", This, *obj);
125 else if ( IsEqualGUID( &IID_IDirectDraw4, refiid ) )
127 *obj = &This->ddraw->IDirectDraw4_iface;
128 TRACE("(%p) Returning IDirectDraw4 interface at %p\n", This, *obj);
130 else if ( IsEqualGUID( &IID_IDirectDraw2, refiid ) )
132 *obj = &This->ddraw->IDirectDraw2_iface;
133 TRACE("(%p) Returning IDirectDraw2 interface at %p\n", This, *obj);
135 else if( IsEqualGUID( &IID_IDirectDraw, refiid ) )
137 *obj = &This->ddraw->IDirectDraw_iface;
138 TRACE("(%p) Returning IDirectDraw interface at %p\n", This, *obj);
142 else if ( IsEqualGUID( &IID_IDirect3D , refiid ) )
144 *obj = &This->ddraw->IDirect3D_iface;
145 TRACE("(%p) Returning IDirect3D interface at %p\n", This, *obj);
147 else if ( IsEqualGUID( &IID_IDirect3D2 , refiid ) )
149 *obj = &This->ddraw->IDirect3D2_iface;
150 TRACE("(%p) Returning IDirect3D2 interface at %p\n", This, *obj);
152 else if ( IsEqualGUID( &IID_IDirect3D3 , refiid ) )
154 *obj = &This->ddraw->IDirect3D3_iface;
155 TRACE("(%p) Returning IDirect3D3 interface at %p\n", This, *obj);
157 else if ( IsEqualGUID( &IID_IDirect3D7 , refiid ) )
159 *obj = &This->ddraw->IDirect3D7_iface;
160 TRACE("(%p) Returning IDirect3D7 interface at %p\n", This, *obj);
164 else if ( IsEqualGUID( &IID_IDirect3DDevice , refiid ) )
166 *obj = &This->IDirect3DDevice_vtbl;
167 TRACE("(%p) Returning IDirect3DDevice interface at %p\n", This, *obj);
169 else if ( IsEqualGUID( &IID_IDirect3DDevice2 , refiid ) ) {
170 *obj = &This->IDirect3DDevice2_vtbl;
171 TRACE("(%p) Returning IDirect3DDevice2 interface at %p\n", This, *obj);
173 else if ( IsEqualGUID( &IID_IDirect3DDevice3 , refiid ) ) {
174 *obj = &This->IDirect3DDevice3_vtbl;
175 TRACE("(%p) Returning IDirect3DDevice3 interface at %p\n", This, *obj);
177 else if ( IsEqualGUID( &IID_IDirect3DDevice7 , refiid ) ) {
179 TRACE("(%p) Returning IDirect3DDevice7 interface at %p\n", This, *obj);
182 /* Unknown interface */
185 ERR("(%p)->(%s, %p): No interface found\n", This, debugstr_guid(refiid), obj);
186 return E_NOINTERFACE;
189 /* AddRef the returned interface */
190 IUnknown_AddRef( (IUnknown *) *obj);
194 static HRESULT WINAPI IDirect3DDeviceImpl_3_QueryInterface(IDirect3DDevice3 *iface, REFIID riid,
197 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obj);
199 return IDirect3DDevice7_QueryInterface((IDirect3DDevice7 *)device_from_device3(iface), riid, obj);
202 static HRESULT WINAPI IDirect3DDeviceImpl_2_QueryInterface(IDirect3DDevice2 *iface, REFIID riid,
205 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obj);
207 return IDirect3DDevice7_QueryInterface((IDirect3DDevice7 *)device_from_device2(iface), riid, obj);
210 static HRESULT WINAPI IDirect3DDeviceImpl_1_QueryInterface(IDirect3DDevice *iface, REFIID riid,
213 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obp);
215 return IDirect3DDevice7_QueryInterface((IDirect3DDevice7 *)device_from_device1(iface), riid, obp);
218 /*****************************************************************************
219 * IDirect3DDevice7::AddRef
221 * Increases the refcount....
222 * The most exciting Method, definitely
224 * Exists in Version 1, 2, 3 and 7
229 *****************************************************************************/
231 IDirect3DDeviceImpl_7_AddRef(IDirect3DDevice7 *iface)
233 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
234 ULONG ref = InterlockedIncrement(&This->ref);
236 TRACE("%p increasing refcount to %u.\n", This, ref);
241 static ULONG WINAPI IDirect3DDeviceImpl_3_AddRef(IDirect3DDevice3 *iface)
243 TRACE("iface %p.\n", iface);
245 return IDirect3DDevice7_AddRef((IDirect3DDevice7 *)device_from_device3(iface));
248 static ULONG WINAPI IDirect3DDeviceImpl_2_AddRef(IDirect3DDevice2 *iface)
250 TRACE("iface %p.\n", iface);
252 return IDirect3DDevice7_AddRef((IDirect3DDevice7 *)device_from_device2(iface));
255 static ULONG WINAPI IDirect3DDeviceImpl_1_AddRef(IDirect3DDevice *iface)
257 TRACE("iface %p.\n", iface);
259 return IDirect3DDevice7_AddRef((IDirect3DDevice7 *)device_from_device1(iface));
262 /*****************************************************************************
263 * IDirect3DDevice7::Release
265 * Decreases the refcount of the interface
266 * When the refcount is reduced to 0, the object is destroyed.
268 * Exists in Version 1, 2, 3 and 7
273 *****************************************************************************/
275 IDirect3DDeviceImpl_7_Release(IDirect3DDevice7 *iface)
277 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
278 ULONG ref = InterlockedDecrement(&This->ref);
280 TRACE("%p decreasing refcount to %u.\n", This, ref);
282 /* This method doesn't destroy the WineD3DDevice, because it's still in use for
283 * 2D rendering. IDirectDrawSurface7::Release will destroy the WineD3DDevice
284 * when the render target is released
290 EnterCriticalSection(&ddraw_cs);
292 /* There is no need to unset any resources here, wined3d will take
293 * care of that on Uninit3D(). */
295 /* Free the index buffer. */
296 wined3d_buffer_decref(This->indexbuffer);
298 /* Set the device up to render to the front buffer since the back
299 * buffer will vanish soon. */
300 wined3d_device_set_render_target(This->wined3d_device, 0,
301 This->ddraw->d3d_target->wined3d_surface, TRUE);
303 /* Release the WineD3DDevice. This won't destroy it. */
304 if (!wined3d_device_decref(This->wined3d_device))
305 ERR("The wined3d device (%p) was destroyed unexpectedly.\n", This->wined3d_device);
307 /* The texture handles should be unset by now, but there might be some bits
308 * missing in our reference counting(needs test). Do a sanity check. */
309 for (i = 0; i < This->handle_table.entry_count; ++i)
311 struct ddraw_handle_entry *entry = &This->handle_table.entries[i];
315 case DDRAW_HANDLE_FREE:
318 case DDRAW_HANDLE_MATERIAL:
320 IDirect3DMaterialImpl *m = entry->object;
321 FIXME("Material handle %#x (%p) not unset properly.\n", i + 1, m);
326 case DDRAW_HANDLE_MATRIX:
328 /* No FIXME here because this might happen because of sloppy applications. */
329 WARN("Leftover matrix handle %#x (%p), deleting.\n", i + 1, entry->object);
330 IDirect3DDevice_DeleteMatrix((IDirect3DDevice *)&This->IDirect3DDevice_vtbl, i + 1);
334 case DDRAW_HANDLE_STATEBLOCK:
336 /* No FIXME here because this might happen because of sloppy applications. */
337 WARN("Leftover stateblock handle %#x (%p), deleting.\n", i + 1, entry->object);
338 IDirect3DDevice7_DeleteStateBlock(iface, i + 1);
342 case DDRAW_HANDLE_SURFACE:
344 IDirectDrawSurfaceImpl *surf = entry->object;
345 FIXME("Texture handle %#x (%p) not unset properly.\n", i + 1, surf);
351 FIXME("Handle %#x (%p) has unknown type %#x.\n", i + 1, entry->object, entry->type);
356 ddraw_handle_table_destroy(&This->handle_table);
358 TRACE("Releasing target %p %p\n", This->target, This->ddraw->d3d_target);
359 /* Release the render target and the WineD3D render target
360 * (See IDirect3D7::CreateDevice for more comments on this)
362 IDirectDrawSurface7_Release(&This->target->IDirectDrawSurface7_iface);
363 IDirectDrawSurface7_Release(&This->ddraw->d3d_target->IDirectDrawSurface7_iface);
364 TRACE("Target release done\n");
366 This->ddraw->d3ddevice = NULL;
368 /* Now free the structure */
369 HeapFree(GetProcessHeap(), 0, This);
370 LeaveCriticalSection(&ddraw_cs);
377 static ULONG WINAPI IDirect3DDeviceImpl_3_Release(IDirect3DDevice3 *iface)
379 TRACE("iface %p.\n", iface);
381 return IDirect3DDevice7_Release((IDirect3DDevice7 *)device_from_device3(iface));
384 static ULONG WINAPI IDirect3DDeviceImpl_2_Release(IDirect3DDevice2 *iface)
386 TRACE("iface %p.\n", iface);
388 return IDirect3DDevice7_Release((IDirect3DDevice7 *)device_from_device2(iface));
391 static ULONG WINAPI IDirect3DDeviceImpl_1_Release(IDirect3DDevice *iface)
393 TRACE("iface %p.\n", iface);
395 return IDirect3DDevice7_Release((IDirect3DDevice7 *)device_from_device1(iface));
398 /*****************************************************************************
399 * IDirect3DDevice Methods
400 *****************************************************************************/
402 /*****************************************************************************
403 * IDirect3DDevice::Initialize
405 * Initializes a Direct3DDevice. This implementation is a no-op, as all
406 * initialization is done at create time.
408 * Exists in Version 1
411 * No idea what they mean, as the MSDN page is gone
415 *****************************************************************************/
416 static HRESULT WINAPI
417 IDirect3DDeviceImpl_1_Initialize(IDirect3DDevice *iface,
418 IDirect3D *Direct3D, GUID *guid,
421 /* It shouldn't be crucial, but print a FIXME, I'm interested if
422 * any game calls it and when. */
423 FIXME("iface %p, d3d %p, guid %s, device_desc %p nop!\n",
424 iface, Direct3D, debugstr_guid(guid), Desc);
429 /*****************************************************************************
430 * IDirect3DDevice7::GetCaps
432 * Retrieves the device's capabilities
434 * This implementation is used for Version 7 only, the older versions have
435 * their own implementation.
438 * Desc: Pointer to a D3DDEVICEDESC7 structure to fill
442 * D3DERR_* if a problem occurs. See WineD3D
444 *****************************************************************************/
446 IDirect3DDeviceImpl_7_GetCaps(IDirect3DDevice7 *iface,
447 D3DDEVICEDESC7 *Desc)
449 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
450 D3DDEVICEDESC OldDesc;
452 TRACE("iface %p, device_desc %p.\n", iface, Desc);
454 /* Call the same function used by IDirect3D, this saves code */
455 return IDirect3DImpl_GetCaps(This->ddraw->wineD3D, &OldDesc, Desc);
458 static HRESULT WINAPI
459 IDirect3DDeviceImpl_7_GetCaps_FPUSetup(IDirect3DDevice7 *iface,
460 D3DDEVICEDESC7 *Desc)
462 return IDirect3DDeviceImpl_7_GetCaps(iface, Desc);
465 static HRESULT WINAPI
466 IDirect3DDeviceImpl_7_GetCaps_FPUPreserve(IDirect3DDevice7 *iface,
467 D3DDEVICEDESC7 *Desc)
472 old_fpucw = d3d_fpu_setup();
473 hr = IDirect3DDeviceImpl_7_GetCaps(iface, Desc);
474 set_fpu_control_word(old_fpucw);
478 /*****************************************************************************
479 * IDirect3DDevice3::GetCaps
481 * Retrieves the capabilities of the hardware device and the emulation
482 * device. For Wine, hardware and emulation are the same (it's all HW).
484 * This implementation is used for Version 1, 2, and 3. Version 7 has its own
487 * HWDesc: Structure to fill with the HW caps
488 * HelDesc: Structure to fill with the hardware emulation caps
492 * D3DERR_* if a problem occurs. See WineD3D
494 *****************************************************************************/
495 static HRESULT WINAPI
496 IDirect3DDeviceImpl_3_GetCaps(IDirect3DDevice3 *iface,
497 D3DDEVICEDESC *HWDesc,
498 D3DDEVICEDESC *HelDesc)
500 IDirect3DDeviceImpl *This = device_from_device3(iface);
501 D3DDEVICEDESC7 newDesc;
504 TRACE("iface %p, hw_desc %p, hel_desc %p.\n", iface, HWDesc, HelDesc);
506 hr = IDirect3DImpl_GetCaps(This->ddraw->wineD3D, HWDesc, &newDesc);
507 if(hr != D3D_OK) return hr;
513 static HRESULT WINAPI IDirect3DDeviceImpl_2_GetCaps(IDirect3DDevice2 *iface,
514 D3DDEVICEDESC *D3DHWDevDesc, D3DDEVICEDESC *D3DHELDevDesc)
516 IDirect3DDeviceImpl *This = device_from_device2(iface);
517 TRACE("iface %p, hw_desc %p, hel_desc %p.\n", iface, D3DHWDevDesc, D3DHELDevDesc);
518 return IDirect3DDevice3_GetCaps((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, D3DHWDevDesc, D3DHELDevDesc);
521 static HRESULT WINAPI IDirect3DDeviceImpl_1_GetCaps(IDirect3DDevice *iface,
522 D3DDEVICEDESC *D3DHWDevDesc, D3DDEVICEDESC *D3DHELDevDesc)
524 IDirect3DDeviceImpl *This = device_from_device1(iface);
525 TRACE("iface %p, hw_desc %p, hel_desc %p.\n", iface, D3DHWDevDesc, D3DHELDevDesc);
526 return IDirect3DDevice3_GetCaps((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, D3DHWDevDesc, D3DHELDevDesc);
529 /*****************************************************************************
530 * IDirect3DDevice2::SwapTextureHandles
532 * Swaps the texture handles of 2 Texture interfaces. Version 1 and 2
535 * Tex1, Tex2: The 2 Textures to swap
540 *****************************************************************************/
541 static HRESULT WINAPI
542 IDirect3DDeviceImpl_2_SwapTextureHandles(IDirect3DDevice2 *iface,
543 IDirect3DTexture2 *Tex1,
544 IDirect3DTexture2 *Tex2)
546 IDirect3DDeviceImpl *This = device_from_device2(iface);
547 IDirectDrawSurfaceImpl *surf1 = surface_from_texture2(Tex1);
548 IDirectDrawSurfaceImpl *surf2 = surface_from_texture2(Tex2);
551 TRACE("iface %p, tex1 %p, tex2 %p.\n", iface, Tex1, Tex2);
553 EnterCriticalSection(&ddraw_cs);
555 h1 = surf1->Handle - 1;
556 h2 = surf2->Handle - 1;
557 This->handle_table.entries[h1].object = surf2;
558 This->handle_table.entries[h2].object = surf1;
559 surf2->Handle = h1 + 1;
560 surf1->Handle = h2 + 1;
562 LeaveCriticalSection(&ddraw_cs);
567 static HRESULT WINAPI IDirect3DDeviceImpl_1_SwapTextureHandles(IDirect3DDevice *iface,
568 IDirect3DTexture *D3DTex1, IDirect3DTexture *D3DTex2)
570 IDirect3DDeviceImpl *This = device_from_device1(iface);
571 IDirectDrawSurfaceImpl *surf1 = surface_from_texture1(D3DTex1);
572 IDirectDrawSurfaceImpl *surf2 = surface_from_texture1(D3DTex2);
573 IDirect3DTexture2 *t1 = surf1 ? (IDirect3DTexture2 *)&surf1->IDirect3DTexture2_vtbl : NULL;
574 IDirect3DTexture2 *t2 = surf2 ? (IDirect3DTexture2 *)&surf2->IDirect3DTexture2_vtbl : NULL;
576 TRACE("iface %p, tex1 %p, tex2 %p.\n", iface, D3DTex1, D3DTex2);
578 return IDirect3DDevice2_SwapTextureHandles((IDirect3DDevice2 *)&This->IDirect3DDevice2_vtbl, t1, t2);
581 /*****************************************************************************
582 * IDirect3DDevice3::GetStats
584 * This method seems to retrieve some stats from the device.
585 * The MSDN documentation doesn't exist any more, but the D3DSTATS
586 * structure suggests that the amount of drawn primitives and processed
587 * vertices is returned.
589 * Exists in Version 1, 2 and 3
592 * Stats: Pointer to a D3DSTATS structure to be filled
596 * DDERR_INVALIDPARAMS if Stats == NULL
598 *****************************************************************************/
599 static HRESULT WINAPI
600 IDirect3DDeviceImpl_3_GetStats(IDirect3DDevice3 *iface,
603 FIXME("iface %p, stats %p stub!\n", iface, Stats);
606 return DDERR_INVALIDPARAMS;
608 /* Fill the Stats with 0 */
609 Stats->dwTrianglesDrawn = 0;
610 Stats->dwLinesDrawn = 0;
611 Stats->dwPointsDrawn = 0;
612 Stats->dwSpansDrawn = 0;
613 Stats->dwVerticesProcessed = 0;
618 static HRESULT WINAPI IDirect3DDeviceImpl_2_GetStats(IDirect3DDevice2 *iface, D3DSTATS *Stats)
620 IDirect3DDeviceImpl *This = device_from_device2(iface);
622 TRACE("iface %p, stats %p.\n", iface, Stats);
624 return IDirect3DDevice3_GetStats((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, Stats);
627 static HRESULT WINAPI IDirect3DDeviceImpl_1_GetStats(IDirect3DDevice *iface, D3DSTATS *Stats)
629 IDirect3DDeviceImpl *This = device_from_device1(iface);
631 TRACE("iface %p, stats %p.\n", iface, Stats);
633 return IDirect3DDevice3_GetStats((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, Stats);
636 /*****************************************************************************
637 * IDirect3DDevice::CreateExecuteBuffer
639 * Creates an IDirect3DExecuteBuffer, used for rendering with a
645 * Desc: Buffer description
646 * ExecuteBuffer: Address to return the Interface pointer at
647 * UnkOuter: Must be NULL. Basically for aggregation, which ddraw doesn't
651 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
652 * DDERR_OUTOFMEMORY if we ran out of memory
655 *****************************************************************************/
656 static HRESULT WINAPI
657 IDirect3DDeviceImpl_1_CreateExecuteBuffer(IDirect3DDevice *iface,
658 D3DEXECUTEBUFFERDESC *Desc,
659 IDirect3DExecuteBuffer **ExecuteBuffer,
662 IDirect3DDeviceImpl *This = device_from_device1(iface);
663 IDirect3DExecuteBufferImpl* object;
666 TRACE("iface %p, buffer_desc %p, buffer %p, outer_unknown %p.\n",
667 iface, Desc, ExecuteBuffer, UnkOuter);
670 return CLASS_E_NOAGGREGATION;
672 /* Allocate the new Execute Buffer */
673 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DExecuteBufferImpl));
676 ERR("Out of memory when allocating a IDirect3DExecuteBufferImpl structure\n");
677 return DDERR_OUTOFMEMORY;
680 hr = d3d_execute_buffer_init(object, This, Desc);
683 WARN("Failed to initialize execute buffer, hr %#x.\n", hr);
684 HeapFree(GetProcessHeap(), 0, object);
688 *ExecuteBuffer = (IDirect3DExecuteBuffer *)object;
690 TRACE(" Returning IDirect3DExecuteBuffer at %p, implementation is at %p\n", *ExecuteBuffer, object);
695 /*****************************************************************************
696 * IDirect3DDevice::Execute
698 * Executes all the stuff in an execute buffer.
701 * ExecuteBuffer: The buffer to execute
702 * Viewport: The viewport used for rendering
706 * DDERR_INVALIDPARAMS if ExecuteBuffer == NULL
709 *****************************************************************************/
710 static HRESULT WINAPI
711 IDirect3DDeviceImpl_1_Execute(IDirect3DDevice *iface,
712 IDirect3DExecuteBuffer *ExecuteBuffer,
713 IDirect3DViewport *Viewport,
716 IDirect3DDeviceImpl *This = device_from_device1(iface);
717 IDirect3DExecuteBufferImpl *Direct3DExecuteBufferImpl = (IDirect3DExecuteBufferImpl *)ExecuteBuffer;
718 IDirect3DViewportImpl *Direct3DViewportImpl = (IDirect3DViewportImpl *)Viewport;
721 TRACE("iface %p, buffer %p, viewport %p, flags %#x.\n", iface, ExecuteBuffer, Viewport, Flags);
723 if(!Direct3DExecuteBufferImpl)
724 return DDERR_INVALIDPARAMS;
727 EnterCriticalSection(&ddraw_cs);
728 hr = d3d_execute_buffer_execute(Direct3DExecuteBufferImpl, This, Direct3DViewportImpl);
729 LeaveCriticalSection(&ddraw_cs);
734 /*****************************************************************************
735 * IDirect3DDevice3::AddViewport
737 * Add a Direct3DViewport to the device's viewport list. These viewports
738 * are wrapped to IDirect3DDevice7 viewports in viewport.c
740 * Exists in Version 1, 2 and 3. Note that IDirect3DViewport 1, 2 and 3
741 * are the same interfaces.
744 * Viewport: The viewport to add
747 * DDERR_INVALIDPARAMS if Viewport == NULL
750 *****************************************************************************/
751 static HRESULT WINAPI
752 IDirect3DDeviceImpl_3_AddViewport(IDirect3DDevice3 *iface,
753 IDirect3DViewport3 *Viewport)
755 IDirect3DDeviceImpl *This = device_from_device3(iface);
756 IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *)Viewport;
758 TRACE("iface %p, viewport %p.\n", iface, Viewport);
762 return DDERR_INVALIDPARAMS;
764 EnterCriticalSection(&ddraw_cs);
765 list_add_head(&This->viewport_list, &vp->entry);
766 vp->active_device = This; /* Viewport must be usable for Clear() after AddViewport,
767 so set active_device here. */
768 LeaveCriticalSection(&ddraw_cs);
773 static HRESULT WINAPI IDirect3DDeviceImpl_2_AddViewport(IDirect3DDevice2 *iface,
774 IDirect3DViewport2 *Direct3DViewport2)
776 IDirect3DDeviceImpl *This = device_from_device2(iface);
777 IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *)Direct3DViewport2;
779 TRACE("iface %p, viewport %p.\n", iface, Direct3DViewport2);
781 return IDirect3DDevice3_AddViewport((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, (IDirect3DViewport3 *)vp);
784 static HRESULT WINAPI IDirect3DDeviceImpl_1_AddViewport(IDirect3DDevice *iface,
785 IDirect3DViewport *Direct3DViewport)
787 IDirect3DDeviceImpl *This = device_from_device1(iface);
788 IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *)Direct3DViewport;
790 TRACE("iface %p, viewport %p.\n", iface, Direct3DViewport);
792 return IDirect3DDevice3_AddViewport((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, (IDirect3DViewport3 *)vp);
795 /*****************************************************************************
796 * IDirect3DDevice3::DeleteViewport
798 * Deletes a Direct3DViewport from the device's viewport list.
800 * Exists in Version 1, 2 and 3. Note that all Viewport interface versions
804 * Viewport: The viewport to delete
808 * DDERR_INVALIDPARAMS if the viewport wasn't found in the list
810 *****************************************************************************/
811 static HRESULT WINAPI IDirect3DDeviceImpl_3_DeleteViewport(IDirect3DDevice3 *iface, IDirect3DViewport3 *viewport)
813 IDirect3DDeviceImpl *device = device_from_device3(iface);
814 IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *)viewport;
816 TRACE("iface %p, viewport %p.\n", iface, viewport);
818 EnterCriticalSection(&ddraw_cs);
820 if (vp->active_device != device)
822 WARN("Viewport %p active device is %p.\n", vp, vp->active_device);
823 LeaveCriticalSection(&ddraw_cs);
824 return DDERR_INVALIDPARAMS;
827 vp->active_device = NULL;
828 list_remove(&vp->entry);
830 LeaveCriticalSection(&ddraw_cs);
834 static HRESULT WINAPI IDirect3DDeviceImpl_2_DeleteViewport(IDirect3DDevice2 *iface,
835 IDirect3DViewport2 *Direct3DViewport2)
837 IDirect3DDeviceImpl *This = device_from_device2(iface);
838 IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *)Direct3DViewport2;
840 TRACE("iface %p, viewport %p.\n", iface, Direct3DViewport2);
842 return IDirect3DDevice3_DeleteViewport((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, (IDirect3DViewport3 *)vp);
845 static HRESULT WINAPI IDirect3DDeviceImpl_1_DeleteViewport(IDirect3DDevice *iface,
846 IDirect3DViewport *Direct3DViewport)
848 IDirect3DDeviceImpl *This = device_from_device1(iface);
849 IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *)Direct3DViewport;
851 TRACE("iface %p, viewport %p.\n", iface, Direct3DViewport);
853 return IDirect3DDevice3_DeleteViewport((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, (IDirect3DViewport3 *)vp);
856 /*****************************************************************************
857 * IDirect3DDevice3::NextViewport
859 * Returns a viewport from the viewport list, depending on the
860 * passed viewport and the flags.
862 * Exists in Version 1, 2 and 3. Note that all Viewport interface versions
866 * Viewport: Viewport to use for beginning the search
867 * Flags: D3DNEXT_NEXT, D3DNEXT_HEAD or D3DNEXT_TAIL
871 * DDERR_INVALIDPARAMS if the flags were wrong, or Viewport was NULL
873 *****************************************************************************/
874 static HRESULT WINAPI
875 IDirect3DDeviceImpl_3_NextViewport(IDirect3DDevice3 *iface,
876 IDirect3DViewport3 *Viewport3,
877 IDirect3DViewport3 **lplpDirect3DViewport3,
880 IDirect3DDeviceImpl *This = device_from_device3(iface);
881 IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *)Viewport3;
884 TRACE("iface %p, viewport %p, next %p, flags %#x.\n",
885 iface, Viewport3, lplpDirect3DViewport3, Flags);
889 *lplpDirect3DViewport3 = NULL;
890 return DDERR_INVALIDPARAMS;
894 EnterCriticalSection(&ddraw_cs);
898 entry = list_next(&This->viewport_list, &vp->entry);
902 entry = list_head(&This->viewport_list);
906 entry = list_tail(&This->viewport_list);
910 WARN("Invalid flags %#x.\n", Flags);
911 *lplpDirect3DViewport3 = NULL;
912 LeaveCriticalSection(&ddraw_cs);
913 return DDERR_INVALIDPARAMS;
917 *lplpDirect3DViewport3 = (IDirect3DViewport3 *)LIST_ENTRY(entry, IDirect3DViewportImpl, entry);
919 *lplpDirect3DViewport3 = NULL;
921 LeaveCriticalSection(&ddraw_cs);
925 static HRESULT WINAPI IDirect3DDeviceImpl_2_NextViewport(IDirect3DDevice2 *iface,
926 IDirect3DViewport2 *Viewport2, IDirect3DViewport2 **lplpDirect3DViewport2, DWORD Flags)
928 IDirect3DDeviceImpl *This = device_from_device2(iface);
929 IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *)Viewport2;
930 IDirect3DViewport3 *res;
933 TRACE("iface %p, viewport %p, next %p, flags %#x.\n",
934 iface, Viewport2, lplpDirect3DViewport2, Flags);
936 hr = IDirect3DDevice3_NextViewport((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl,
937 (IDirect3DViewport3 *)vp, &res, Flags);
938 *lplpDirect3DViewport2 = (IDirect3DViewport2 *)res;
942 static HRESULT WINAPI IDirect3DDeviceImpl_1_NextViewport(IDirect3DDevice *iface,
943 IDirect3DViewport *Viewport, IDirect3DViewport **lplpDirect3DViewport, DWORD Flags)
945 IDirect3DDeviceImpl *This = device_from_device1(iface);
946 IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *)Viewport;
947 IDirect3DViewport3 *res;
950 TRACE("iface %p, viewport %p, next %p, flags %#x.\n",
951 iface, Viewport, lplpDirect3DViewport, Flags);
953 hr = IDirect3DDevice3_NextViewport((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl,
954 (IDirect3DViewport3 *)vp, &res, Flags);
955 *lplpDirect3DViewport = (IDirect3DViewport *)res;
959 /*****************************************************************************
960 * IDirect3DDevice::Pick
962 * Executes an execute buffer without performing rendering. Instead, a
963 * list of primitives that intersect with (x1,y1) of the passed rectangle
964 * is created. IDirect3DDevice::GetPickRecords can be used to retrieve
970 * ExecuteBuffer: Buffer to execute
971 * Viewport: Viewport to use for execution
972 * Flags: None are defined, according to the SDK
973 * Rect: Specifies the coordinates to be picked. Only x1 and y2 are used,
974 * x2 and y2 are ignored.
977 * D3D_OK because it's a stub
979 *****************************************************************************/
980 static HRESULT WINAPI
981 IDirect3DDeviceImpl_1_Pick(IDirect3DDevice *iface,
982 IDirect3DExecuteBuffer *ExecuteBuffer,
983 IDirect3DViewport *Viewport,
987 FIXME("iface %p, buffer %p, viewport %p, flags %#x, rect %s stub!\n",
988 iface, ExecuteBuffer, Viewport, Flags, wine_dbgstr_rect((RECT *)Rect));
993 /*****************************************************************************
994 * IDirect3DDevice::GetPickRecords
996 * Retrieves the pick records generated by IDirect3DDevice::GetPickRecords
1001 * Count: Pointer to a DWORD containing the numbers of pick records to
1003 * D3DPickRec: Address to store the resulting D3DPICKRECORD array.
1006 * D3D_OK, because it's a stub
1008 *****************************************************************************/
1009 static HRESULT WINAPI
1010 IDirect3DDeviceImpl_1_GetPickRecords(IDirect3DDevice *iface,
1012 D3DPICKRECORD *D3DPickRec)
1014 FIXME("iface %p, count %p, records %p stub!\n", iface, Count, D3DPickRec);
1019 /*****************************************************************************
1020 * IDirect3DDevice7::EnumTextureformats
1022 * Enumerates the supported texture formats. It has a list of all possible
1023 * formats and calls IWineD3D::CheckDeviceFormat for each format to see if
1024 * WineD3D supports it. If so, then it is passed to the app.
1026 * This is for Version 7 and 3, older versions have a different
1027 * callback function and their own implementation
1030 * Callback: Callback to call for each enumerated format
1031 * Arg: Argument to pass to the callback
1035 * DDERR_INVALIDPARAMS if Callback == NULL
1037 *****************************************************************************/
1039 IDirect3DDeviceImpl_7_EnumTextureFormats(IDirect3DDevice7 *iface,
1040 LPD3DENUMPIXELFORMATSCALLBACK Callback,
1043 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
1045 WINED3DDISPLAYMODE mode;
1048 static const enum wined3d_format_id FormatList[] =
1051 WINED3DFMT_B8G8R8A8_UNORM,
1052 WINED3DFMT_B8G8R8X8_UNORM,
1054 WINED3DFMT_B8G8R8_UNORM,
1056 WINED3DFMT_B5G5R5A1_UNORM,
1057 WINED3DFMT_B4G4R4A4_UNORM,
1058 WINED3DFMT_B5G6R5_UNORM,
1059 WINED3DFMT_B5G5R5X1_UNORM,
1061 WINED3DFMT_B2G3R3_UNORM,
1069 static const enum wined3d_format_id BumpFormatList[] =
1071 WINED3DFMT_R8G8_SNORM,
1072 WINED3DFMT_R5G5_SNORM_L6_UNORM,
1073 WINED3DFMT_R8G8_SNORM_L8X8_UNORM,
1074 WINED3DFMT_R16G16_SNORM,
1075 WINED3DFMT_R10G11B11_SNORM,
1076 WINED3DFMT_R10G10B10_SNORM_A2_UNORM
1079 TRACE("iface %p, callback %p, context %p.\n", iface, Callback, Arg);
1082 return DDERR_INVALIDPARAMS;
1084 EnterCriticalSection(&ddraw_cs);
1086 memset(&mode, 0, sizeof(mode));
1087 hr = wined3d_device_get_display_mode(This->ddraw->wined3d_device, 0, &mode);
1090 LeaveCriticalSection(&ddraw_cs);
1091 WARN("Cannot get the current adapter format\n");
1095 for (i = 0; i < sizeof(FormatList) / sizeof(*FormatList); ++i)
1097 hr = wined3d_check_device_format(This->ddraw->wineD3D, WINED3DADAPTER_DEFAULT, WINED3DDEVTYPE_HAL,
1098 mode.Format, 0, WINED3DRTYPE_TEXTURE, FormatList[i], SURFACE_OPENGL);
1101 DDPIXELFORMAT pformat;
1103 memset(&pformat, 0, sizeof(pformat));
1104 pformat.dwSize = sizeof(pformat);
1105 PixelFormat_WineD3DtoDD(&pformat, FormatList[i]);
1107 TRACE("Enumerating WineD3DFormat %d\n", FormatList[i]);
1108 hr = Callback(&pformat, Arg);
1109 if(hr != DDENUMRET_OK)
1111 TRACE("Format enumeration cancelled by application\n");
1112 LeaveCriticalSection(&ddraw_cs);
1118 for (i = 0; i < sizeof(BumpFormatList) / sizeof(*BumpFormatList); ++i)
1120 hr = wined3d_check_device_format(This->ddraw->wineD3D, WINED3DADAPTER_DEFAULT,
1121 WINED3DDEVTYPE_HAL, mode.Format, WINED3DUSAGE_QUERY_LEGACYBUMPMAP,
1122 WINED3DRTYPE_TEXTURE, BumpFormatList[i], SURFACE_OPENGL);
1125 DDPIXELFORMAT pformat;
1127 memset(&pformat, 0, sizeof(pformat));
1128 pformat.dwSize = sizeof(pformat);
1129 PixelFormat_WineD3DtoDD(&pformat, BumpFormatList[i]);
1131 TRACE("Enumerating WineD3DFormat %d\n", BumpFormatList[i]);
1132 hr = Callback(&pformat, Arg);
1133 if(hr != DDENUMRET_OK)
1135 TRACE("Format enumeration cancelled by application\n");
1136 LeaveCriticalSection(&ddraw_cs);
1141 TRACE("End of enumeration\n");
1142 LeaveCriticalSection(&ddraw_cs);
1146 static HRESULT WINAPI
1147 IDirect3DDeviceImpl_7_EnumTextureFormats_FPUSetup(IDirect3DDevice7 *iface,
1148 LPD3DENUMPIXELFORMATSCALLBACK Callback,
1151 return IDirect3DDeviceImpl_7_EnumTextureFormats(iface, Callback, Arg);
1154 static HRESULT WINAPI
1155 IDirect3DDeviceImpl_7_EnumTextureFormats_FPUPreserve(IDirect3DDevice7 *iface,
1156 LPD3DENUMPIXELFORMATSCALLBACK Callback,
1162 old_fpucw = d3d_fpu_setup();
1163 hr = IDirect3DDeviceImpl_7_EnumTextureFormats(iface, Callback, Arg);
1164 set_fpu_control_word(old_fpucw);
1169 static HRESULT WINAPI IDirect3DDeviceImpl_3_EnumTextureFormats(IDirect3DDevice3 *iface,
1170 LPD3DENUMPIXELFORMATSCALLBACK Callback, void *Arg)
1172 IDirect3DDeviceImpl *This = device_from_device3(iface);
1174 TRACE("iface %p, callback %p, context %p.\n", iface, Callback, Arg);
1176 return IDirect3DDevice7_EnumTextureFormats((IDirect3DDevice7 *)This, Callback, Arg);
1179 /*****************************************************************************
1180 * IDirect3DDevice2::EnumTextureformats
1182 * EnumTextureFormats for Version 1 and 2, see
1183 * IDirect3DDevice7::EnumTexureFormats for a more detailed description.
1185 * This version has a different callback and does not enumerate FourCC
1188 *****************************************************************************/
1189 static HRESULT WINAPI
1190 IDirect3DDeviceImpl_2_EnumTextureFormats(IDirect3DDevice2 *iface,
1191 LPD3DENUMTEXTUREFORMATSCALLBACK Callback,
1194 IDirect3DDeviceImpl *This = device_from_device2(iface);
1197 WINED3DDISPLAYMODE mode;
1199 static const enum wined3d_format_id FormatList[] =
1202 WINED3DFMT_B8G8R8A8_UNORM,
1203 WINED3DFMT_B8G8R8X8_UNORM,
1205 WINED3DFMT_B8G8R8_UNORM,
1207 WINED3DFMT_B5G5R5A1_UNORM,
1208 WINED3DFMT_B4G4R4A4_UNORM,
1209 WINED3DFMT_B5G6R5_UNORM,
1210 WINED3DFMT_B5G5R5X1_UNORM,
1212 WINED3DFMT_B2G3R3_UNORM,
1214 /* FOURCC codes - Not in this version*/
1217 TRACE("iface %p, callback %p, context %p.\n", iface, Callback, Arg);
1220 return DDERR_INVALIDPARAMS;
1222 EnterCriticalSection(&ddraw_cs);
1224 memset(&mode, 0, sizeof(mode));
1225 hr = wined3d_device_get_display_mode(This->ddraw->wined3d_device, 0, &mode);
1228 LeaveCriticalSection(&ddraw_cs);
1229 WARN("Cannot get the current adapter format\n");
1233 for (i = 0; i < sizeof(FormatList) / sizeof(*FormatList); ++i)
1235 hr = wined3d_check_device_format(This->ddraw->wineD3D, 0, WINED3DDEVTYPE_HAL,
1236 mode.Format, 0, WINED3DRTYPE_TEXTURE, FormatList[i], SURFACE_OPENGL);
1239 DDSURFACEDESC sdesc;
1241 memset(&sdesc, 0, sizeof(sdesc));
1242 sdesc.dwSize = sizeof(sdesc);
1243 sdesc.dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
1244 sdesc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1245 sdesc.ddpfPixelFormat.dwSize = sizeof(sdesc.ddpfPixelFormat);
1246 PixelFormat_WineD3DtoDD(&sdesc.ddpfPixelFormat, FormatList[i]);
1248 TRACE("Enumerating WineD3DFormat %d\n", FormatList[i]);
1249 hr = Callback(&sdesc, Arg);
1250 if(hr != DDENUMRET_OK)
1252 TRACE("Format enumeration cancelled by application\n");
1253 LeaveCriticalSection(&ddraw_cs);
1258 TRACE("End of enumeration\n");
1259 LeaveCriticalSection(&ddraw_cs);
1263 static HRESULT WINAPI IDirect3DDeviceImpl_1_EnumTextureFormats(IDirect3DDevice *iface,
1264 LPD3DENUMTEXTUREFORMATSCALLBACK Callback, void *Arg)
1266 IDirect3DDeviceImpl *This = device_from_device1(iface);
1268 TRACE("iface %p, callback %p, context %p.\n", iface, Callback, Arg);
1270 return IDirect3DDevice2_EnumTextureFormats((IDirect3DDevice2 *)&This->IDirect3DDevice2_vtbl, Callback, Arg);
1273 /*****************************************************************************
1274 * IDirect3DDevice::CreateMatrix
1276 * Creates a matrix handle. A handle is created and memory for a D3DMATRIX is
1277 * allocated for the handle.
1282 * D3DMatHandle: Address to return the handle at
1286 * DDERR_INVALIDPARAMS if D3DMatHandle = NULL
1288 *****************************************************************************/
1289 static HRESULT WINAPI
1290 IDirect3DDeviceImpl_1_CreateMatrix(IDirect3DDevice *iface, D3DMATRIXHANDLE *D3DMatHandle)
1292 IDirect3DDeviceImpl *This = device_from_device1(iface);
1296 TRACE("iface %p, matrix_handle %p.\n", iface, D3DMatHandle);
1299 return DDERR_INVALIDPARAMS;
1301 Matrix = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(D3DMATRIX));
1304 ERR("Out of memory when allocating a D3DMATRIX\n");
1305 return DDERR_OUTOFMEMORY;
1308 EnterCriticalSection(&ddraw_cs);
1310 h = ddraw_allocate_handle(&This->handle_table, Matrix, DDRAW_HANDLE_MATRIX);
1311 if (h == DDRAW_INVALID_HANDLE)
1313 ERR("Failed to allocate a matrix handle.\n");
1314 HeapFree(GetProcessHeap(), 0, Matrix);
1315 LeaveCriticalSection(&ddraw_cs);
1316 return DDERR_OUTOFMEMORY;
1319 *D3DMatHandle = h + 1;
1321 TRACE(" returning matrix handle %d\n", *D3DMatHandle);
1323 LeaveCriticalSection(&ddraw_cs);
1327 /*****************************************************************************
1328 * IDirect3DDevice::SetMatrix
1330 * Sets a matrix for a matrix handle. The matrix is copied into the memory
1331 * allocated for the handle
1336 * D3DMatHandle: Handle to set the matrix to
1337 * D3DMatrix: Matrix to set
1341 * DDERR_INVALIDPARAMS if the handle of the matrix is invalid or the matrix
1344 *****************************************************************************/
1345 static HRESULT WINAPI
1346 IDirect3DDeviceImpl_1_SetMatrix(IDirect3DDevice *iface,
1347 D3DMATRIXHANDLE D3DMatHandle,
1348 D3DMATRIX *D3DMatrix)
1350 IDirect3DDeviceImpl *This = device_from_device1(iface);
1353 TRACE("iface %p, matrix_handle %#x, matrix %p.\n", iface, D3DMatHandle, D3DMatrix);
1355 if (!D3DMatrix) return DDERR_INVALIDPARAMS;
1357 EnterCriticalSection(&ddraw_cs);
1359 m = ddraw_get_object(&This->handle_table, D3DMatHandle - 1, DDRAW_HANDLE_MATRIX);
1362 WARN("Invalid matrix handle.\n");
1363 LeaveCriticalSection(&ddraw_cs);
1364 return DDERR_INVALIDPARAMS;
1367 if (TRACE_ON(ddraw))
1368 dump_D3DMATRIX(D3DMatrix);
1372 if (D3DMatHandle == This->world)
1373 wined3d_device_set_transform(This->wined3d_device, WINED3DTS_WORLDMATRIX(0), (WINED3DMATRIX *)D3DMatrix);
1375 if (D3DMatHandle == This->view)
1376 wined3d_device_set_transform(This->wined3d_device, WINED3DTS_VIEW, (WINED3DMATRIX *)D3DMatrix);
1378 if (D3DMatHandle == This->proj)
1379 wined3d_device_set_transform(This->wined3d_device, WINED3DTS_PROJECTION, (WINED3DMATRIX *)D3DMatrix);
1381 LeaveCriticalSection(&ddraw_cs);
1385 /*****************************************************************************
1386 * IDirect3DDevice::GetMatrix
1388 * Returns the content of a D3DMATRIX handle
1393 * D3DMatHandle: Matrix handle to read the content from
1394 * D3DMatrix: Address to store the content at
1398 * DDERR_INVALIDPARAMS if D3DMatHandle is invalid or D3DMatrix is NULL
1400 *****************************************************************************/
1401 static HRESULT WINAPI
1402 IDirect3DDeviceImpl_1_GetMatrix(IDirect3DDevice *iface,
1403 D3DMATRIXHANDLE D3DMatHandle,
1404 D3DMATRIX *D3DMatrix)
1406 IDirect3DDeviceImpl *This = device_from_device1(iface);
1409 TRACE("iface %p, matrix_handle %#x, matrix %p.\n", iface, D3DMatHandle, D3DMatrix);
1411 if (!D3DMatrix) return DDERR_INVALIDPARAMS;
1413 EnterCriticalSection(&ddraw_cs);
1415 m = ddraw_get_object(&This->handle_table, D3DMatHandle - 1, DDRAW_HANDLE_MATRIX);
1418 WARN("Invalid matrix handle.\n");
1419 LeaveCriticalSection(&ddraw_cs);
1420 return DDERR_INVALIDPARAMS;
1425 LeaveCriticalSection(&ddraw_cs);
1429 /*****************************************************************************
1430 * IDirect3DDevice::DeleteMatrix
1432 * Destroys a Matrix handle. Frees the memory and unsets the handle data
1437 * D3DMatHandle: Handle to destroy
1441 * DDERR_INVALIDPARAMS if D3DMatHandle is invalid
1443 *****************************************************************************/
1444 static HRESULT WINAPI
1445 IDirect3DDeviceImpl_1_DeleteMatrix(IDirect3DDevice *iface,
1446 D3DMATRIXHANDLE D3DMatHandle)
1448 IDirect3DDeviceImpl *This = device_from_device1(iface);
1451 TRACE("iface %p, matrix_handle %#x.\n", iface, D3DMatHandle);
1453 EnterCriticalSection(&ddraw_cs);
1455 m = ddraw_free_handle(&This->handle_table, D3DMatHandle - 1, DDRAW_HANDLE_MATRIX);
1458 WARN("Invalid matrix handle.\n");
1459 LeaveCriticalSection(&ddraw_cs);
1460 return DDERR_INVALIDPARAMS;
1463 LeaveCriticalSection(&ddraw_cs);
1465 HeapFree(GetProcessHeap(), 0, m);
1470 /*****************************************************************************
1471 * IDirect3DDevice7::BeginScene
1473 * This method must be called before any rendering is performed.
1474 * IDirect3DDevice::EndScene has to be called after the scene is complete
1476 * Version 1, 2, 3 and 7
1479 * D3D_OK on success, for details see IWineD3DDevice::BeginScene
1480 * D3DERR_SCENE_IN_SCENE if WineD3D returns an error(Only in case of an already
1483 *****************************************************************************/
1485 IDirect3DDeviceImpl_7_BeginScene(IDirect3DDevice7 *iface)
1487 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
1490 TRACE("iface %p.\n", iface);
1492 EnterCriticalSection(&ddraw_cs);
1493 hr = wined3d_device_begin_scene(This->wined3d_device);
1494 LeaveCriticalSection(&ddraw_cs);
1495 if(hr == WINED3D_OK) return D3D_OK;
1496 else return D3DERR_SCENE_IN_SCENE; /* TODO: Other possible causes of failure */
1499 static HRESULT WINAPI
1500 IDirect3DDeviceImpl_7_BeginScene_FPUSetup(IDirect3DDevice7 *iface)
1502 return IDirect3DDeviceImpl_7_BeginScene(iface);
1505 static HRESULT WINAPI
1506 IDirect3DDeviceImpl_7_BeginScene_FPUPreserve(IDirect3DDevice7 *iface)
1511 old_fpucw = d3d_fpu_setup();
1512 hr = IDirect3DDeviceImpl_7_BeginScene(iface);
1513 set_fpu_control_word(old_fpucw);
1518 static HRESULT WINAPI IDirect3DDeviceImpl_3_BeginScene(IDirect3DDevice3 *iface)
1520 TRACE("iface %p.\n", iface);
1522 return IDirect3DDevice7_BeginScene((IDirect3DDevice7 *)device_from_device3(iface));
1525 static HRESULT WINAPI IDirect3DDeviceImpl_2_BeginScene(IDirect3DDevice2 *iface)
1527 TRACE("iface %p.\n", iface);
1529 return IDirect3DDevice7_BeginScene((IDirect3DDevice7 *)device_from_device2(iface));
1532 static HRESULT WINAPI IDirect3DDeviceImpl_1_BeginScene(IDirect3DDevice *iface)
1534 TRACE("iface %p.\n", iface);
1536 return IDirect3DDevice7_BeginScene((IDirect3DDevice7 *)device_from_device1(iface));
1539 /*****************************************************************************
1540 * IDirect3DDevice7::EndScene
1542 * Ends a scene that has been begun with IDirect3DDevice7::BeginScene.
1543 * This method must be called after rendering is finished.
1545 * Version 1, 2, 3 and 7
1548 * D3D_OK on success, for details see IWineD3DDevice::EndScene
1549 * D3DERR_SCENE_NOT_IN_SCENE is returned if WineD3D returns an error. It does
1550 * that only if the scene was already ended.
1552 *****************************************************************************/
1554 IDirect3DDeviceImpl_7_EndScene(IDirect3DDevice7 *iface)
1556 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
1559 TRACE("iface %p.\n", iface);
1561 EnterCriticalSection(&ddraw_cs);
1562 hr = wined3d_device_end_scene(This->wined3d_device);
1563 LeaveCriticalSection(&ddraw_cs);
1564 if(hr == WINED3D_OK) return D3D_OK;
1565 else return D3DERR_SCENE_NOT_IN_SCENE;
1568 static HRESULT WINAPI DECLSPEC_HOTPATCH
1569 IDirect3DDeviceImpl_7_EndScene_FPUSetup(IDirect3DDevice7 *iface)
1571 return IDirect3DDeviceImpl_7_EndScene(iface);
1574 static HRESULT WINAPI DECLSPEC_HOTPATCH
1575 IDirect3DDeviceImpl_7_EndScene_FPUPreserve(IDirect3DDevice7 *iface)
1580 old_fpucw = d3d_fpu_setup();
1581 hr = IDirect3DDeviceImpl_7_EndScene(iface);
1582 set_fpu_control_word(old_fpucw);
1587 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDeviceImpl_3_EndScene(IDirect3DDevice3 *iface)
1589 TRACE("iface %p.\n", iface);
1591 return IDirect3DDevice7_EndScene((IDirect3DDevice7 *)device_from_device3(iface));
1594 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDeviceImpl_2_EndScene(IDirect3DDevice2 *iface)
1596 TRACE("iface %p.\n", iface);
1598 return IDirect3DDevice7_EndScene((IDirect3DDevice7 *)device_from_device2(iface));
1601 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDeviceImpl_1_EndScene(IDirect3DDevice *iface)
1603 TRACE("iface %p.\n", iface);
1605 return IDirect3DDevice7_EndScene((IDirect3DDevice7 *)device_from_device1(iface));
1608 /*****************************************************************************
1609 * IDirect3DDevice7::GetDirect3D
1611 * Returns the IDirect3D(= interface to the DirectDraw object) used to create
1615 * Direct3D7: Address to store the interface pointer at
1619 * DDERR_INVALIDPARAMS if Direct3D7 == NULL
1621 *****************************************************************************/
1622 static HRESULT WINAPI
1623 IDirect3DDeviceImpl_7_GetDirect3D(IDirect3DDevice7 *iface,
1624 IDirect3D7 **Direct3D7)
1626 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
1628 TRACE("iface %p, d3d %p.\n", iface, Direct3D7);
1631 return DDERR_INVALIDPARAMS;
1633 *Direct3D7 = &This->ddraw->IDirect3D7_iface;
1634 IDirect3D7_AddRef(*Direct3D7);
1636 TRACE(" returning interface %p\n", *Direct3D7);
1640 static HRESULT WINAPI IDirect3DDeviceImpl_3_GetDirect3D(IDirect3DDevice3 *iface,
1641 IDirect3D3 **Direct3D3)
1643 IDirect3DDeviceImpl *This = device_from_device3(iface);
1645 TRACE("iface %p, d3d %p.\n", iface, Direct3D3);
1648 return DDERR_INVALIDPARAMS;
1650 IDirect3D3_AddRef(&This->ddraw->IDirect3D3_iface);
1651 *Direct3D3 = &This->ddraw->IDirect3D3_iface;
1652 TRACE(" returning interface %p\n", *Direct3D3);
1656 static HRESULT WINAPI IDirect3DDeviceImpl_2_GetDirect3D(IDirect3DDevice2 *iface,
1657 IDirect3D2 **Direct3D2)
1659 IDirect3DDeviceImpl *This = device_from_device2(iface);
1661 TRACE("iface %p, d3d %p.\n", iface, Direct3D2);
1664 return DDERR_INVALIDPARAMS;
1666 IDirect3D2_AddRef(&This->ddraw->IDirect3D2_iface);
1667 *Direct3D2 = &This->ddraw->IDirect3D2_iface;
1668 TRACE(" returning interface %p\n", *Direct3D2);
1672 static HRESULT WINAPI IDirect3DDeviceImpl_1_GetDirect3D(IDirect3DDevice *iface,
1673 IDirect3D **Direct3D)
1675 IDirect3DDeviceImpl *This = device_from_device1(iface);
1677 TRACE("iface %p, d3d %p.\n", iface, Direct3D);
1680 return DDERR_INVALIDPARAMS;
1682 IDirect3D_AddRef(&This->ddraw->IDirect3D_iface);
1683 *Direct3D = &This->ddraw->IDirect3D_iface;
1684 TRACE(" returning interface %p\n", *Direct3D);
1688 /*****************************************************************************
1689 * IDirect3DDevice3::SetCurrentViewport
1691 * Sets a Direct3DViewport as the current viewport.
1692 * For the thunks note that all viewport interface versions are equal
1695 * Direct3DViewport3: The viewport to set
1701 * (Is a NULL viewport valid?)
1703 *****************************************************************************/
1704 static HRESULT WINAPI
1705 IDirect3DDeviceImpl_3_SetCurrentViewport(IDirect3DDevice3 *iface,
1706 IDirect3DViewport3 *Direct3DViewport3)
1708 IDirect3DDeviceImpl *This = device_from_device3(iface);
1709 IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *)Direct3DViewport3;
1711 TRACE("iface %p, viewport %p.\n", iface, Direct3DViewport3);
1713 EnterCriticalSection(&ddraw_cs);
1714 /* Do nothing if the specified viewport is the same as the current one */
1715 if (This->current_viewport == vp )
1717 LeaveCriticalSection(&ddraw_cs);
1721 if (vp->active_device != This)
1723 WARN("Viewport %p active device is %p.\n", vp, vp->active_device);
1724 LeaveCriticalSection(&ddraw_cs);
1725 return DDERR_INVALIDPARAMS;
1728 /* Release previous viewport and AddRef the new one */
1729 if (This->current_viewport)
1731 TRACE("ViewportImpl is at %p, interface is at %p\n", This->current_viewport,
1732 (IDirect3DViewport3 *)This->current_viewport);
1733 IDirect3DViewport3_Release((IDirect3DViewport3 *)This->current_viewport);
1735 IDirect3DViewport3_AddRef(Direct3DViewport3);
1737 /* Set this viewport as the current viewport */
1738 This->current_viewport = vp;
1740 /* Activate this viewport */
1741 viewport_activate(This->current_viewport, FALSE);
1743 LeaveCriticalSection(&ddraw_cs);
1747 static HRESULT WINAPI IDirect3DDeviceImpl_2_SetCurrentViewport(IDirect3DDevice2 *iface,
1748 IDirect3DViewport2 *Direct3DViewport2)
1750 IDirect3DDeviceImpl *This = device_from_device2(iface);
1751 IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *)Direct3DViewport2;
1753 TRACE("iface %p, viewport %p.\n", iface, Direct3DViewport2);
1755 return IDirect3DDevice3_SetCurrentViewport((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl,
1756 (IDirect3DViewport3 *)vp);
1759 /*****************************************************************************
1760 * IDirect3DDevice3::GetCurrentViewport
1762 * Returns the currently active viewport.
1767 * Direct3DViewport3: Address to return the interface pointer at
1771 * DDERR_INVALIDPARAMS if Direct3DViewport == NULL
1773 *****************************************************************************/
1774 static HRESULT WINAPI
1775 IDirect3DDeviceImpl_3_GetCurrentViewport(IDirect3DDevice3 *iface,
1776 IDirect3DViewport3 **Direct3DViewport3)
1778 IDirect3DDeviceImpl *This = device_from_device3(iface);
1780 TRACE("iface %p, viewport %p.\n", iface, Direct3DViewport3);
1782 if(!Direct3DViewport3)
1783 return DDERR_INVALIDPARAMS;
1785 EnterCriticalSection(&ddraw_cs);
1786 *Direct3DViewport3 = (IDirect3DViewport3 *)This->current_viewport;
1788 /* AddRef the returned viewport */
1789 if(*Direct3DViewport3) IDirect3DViewport3_AddRef(*Direct3DViewport3);
1791 TRACE(" returning interface %p\n", *Direct3DViewport3);
1793 LeaveCriticalSection(&ddraw_cs);
1797 static HRESULT WINAPI IDirect3DDeviceImpl_2_GetCurrentViewport(IDirect3DDevice2 *iface,
1798 IDirect3DViewport2 **Direct3DViewport2)
1800 IDirect3DDeviceImpl *This = device_from_device2(iface);
1803 TRACE("iface %p, viewport %p.\n", iface, Direct3DViewport2);
1805 hr = IDirect3DDevice3_GetCurrentViewport((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl,
1806 (IDirect3DViewport3 **)Direct3DViewport2);
1807 if(hr != D3D_OK) return hr;
1811 /*****************************************************************************
1812 * IDirect3DDevice7::SetRenderTarget
1814 * Sets the render target for the Direct3DDevice.
1815 * For the thunks note that IDirectDrawSurface7 == IDirectDrawSurface4 and
1816 * IDirectDrawSurface3 == IDirectDrawSurface
1818 * Version 2, 3 and 7
1821 * NewTarget: Pointer to an IDirectDrawSurface7 interface to set as the new
1826 * D3D_OK on success, for details see IWineD3DDevice::SetRenderTarget
1828 *****************************************************************************/
1830 IDirect3DDeviceImpl_7_SetRenderTarget(IDirect3DDevice7 *iface,
1831 IDirectDrawSurface7 *NewTarget,
1834 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
1835 IDirectDrawSurfaceImpl *Target = unsafe_impl_from_IDirectDrawSurface7(NewTarget);
1838 TRACE("iface %p, target %p, flags %#x.\n", iface, NewTarget, Flags);
1840 EnterCriticalSection(&ddraw_cs);
1841 /* Flags: Not used */
1843 if(This->target == Target)
1845 TRACE("No-op SetRenderTarget operation, not doing anything\n");
1846 LeaveCriticalSection(&ddraw_cs);
1850 hr = wined3d_device_set_render_target(This->wined3d_device, 0,
1851 Target ? Target->wined3d_surface : NULL, FALSE);
1854 LeaveCriticalSection(&ddraw_cs);
1857 IDirectDrawSurface7_AddRef(NewTarget);
1858 IDirectDrawSurface7_Release(&This->target->IDirectDrawSurface7_iface);
1859 This->target = Target;
1860 IDirect3DDeviceImpl_UpdateDepthStencil(This);
1861 LeaveCriticalSection(&ddraw_cs);
1865 static HRESULT WINAPI
1866 IDirect3DDeviceImpl_7_SetRenderTarget_FPUSetup(IDirect3DDevice7 *iface,
1867 IDirectDrawSurface7 *NewTarget,
1870 return IDirect3DDeviceImpl_7_SetRenderTarget(iface, NewTarget, Flags);
1873 static HRESULT WINAPI
1874 IDirect3DDeviceImpl_7_SetRenderTarget_FPUPreserve(IDirect3DDevice7 *iface,
1875 IDirectDrawSurface7 *NewTarget,
1881 old_fpucw = d3d_fpu_setup();
1882 hr = IDirect3DDeviceImpl_7_SetRenderTarget(iface, NewTarget, Flags);
1883 set_fpu_control_word(old_fpucw);
1888 static HRESULT WINAPI IDirect3DDeviceImpl_3_SetRenderTarget(IDirect3DDevice3 *iface,
1889 IDirectDrawSurface4 *NewRenderTarget, DWORD Flags)
1891 IDirect3DDeviceImpl *This = device_from_device3(iface);
1892 IDirectDrawSurfaceImpl *Target = unsafe_impl_from_IDirectDrawSurface4(NewRenderTarget);
1894 TRACE("iface %p, target %p, flags %#x.\n", iface, NewRenderTarget, Flags);
1896 return IDirect3DDevice7_SetRenderTarget((IDirect3DDevice7 *)This,
1897 Target ? &Target->IDirectDrawSurface7_iface : NULL, Flags);
1900 static HRESULT WINAPI IDirect3DDeviceImpl_2_SetRenderTarget(IDirect3DDevice2 *iface,
1901 IDirectDrawSurface *NewRenderTarget, DWORD Flags)
1903 IDirect3DDeviceImpl *This = device_from_device2(iface);
1904 IDirectDrawSurfaceImpl *Target = unsafe_impl_from_IDirectDrawSurface(NewRenderTarget);
1906 TRACE("iface %p, target %p, flags %#x.\n", iface, NewRenderTarget, Flags);
1908 return IDirect3DDevice7_SetRenderTarget((IDirect3DDevice7 *)This,
1909 Target ? &Target->IDirectDrawSurface7_iface : NULL, Flags);
1912 /*****************************************************************************
1913 * IDirect3DDevice7::GetRenderTarget
1915 * Returns the current render target.
1916 * This is handled locally, because the WineD3D render target's parent
1919 * Version 2, 3 and 7
1922 * RenderTarget: Address to store the surface interface pointer
1926 * DDERR_INVALIDPARAMS if RenderTarget == NULL
1928 *****************************************************************************/
1929 static HRESULT WINAPI
1930 IDirect3DDeviceImpl_7_GetRenderTarget(IDirect3DDevice7 *iface,
1931 IDirectDrawSurface7 **RenderTarget)
1933 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
1935 TRACE("iface %p, target %p.\n", iface, RenderTarget);
1938 return DDERR_INVALIDPARAMS;
1940 EnterCriticalSection(&ddraw_cs);
1941 *RenderTarget = &This->target->IDirectDrawSurface7_iface;
1942 IDirectDrawSurface7_AddRef(*RenderTarget);
1944 LeaveCriticalSection(&ddraw_cs);
1948 static HRESULT WINAPI IDirect3DDeviceImpl_3_GetRenderTarget(IDirect3DDevice3 *iface,
1949 IDirectDrawSurface4 **RenderTarget)
1951 IDirect3DDeviceImpl *This = device_from_device3(iface);
1952 IDirectDrawSurface7 *RenderTarget7;
1953 IDirectDrawSurfaceImpl *RenderTargetImpl;
1956 TRACE("iface %p, target %p.\n", iface, RenderTarget);
1959 return DDERR_INVALIDPARAMS;
1961 hr = IDirect3DDevice7_GetRenderTarget((IDirect3DDevice7 *)This, &RenderTarget7);
1962 if(hr != D3D_OK) return hr;
1963 RenderTargetImpl = impl_from_IDirectDrawSurface7(RenderTarget7);
1964 *RenderTarget = &RenderTargetImpl->IDirectDrawSurface4_iface;
1968 static HRESULT WINAPI IDirect3DDeviceImpl_2_GetRenderTarget(IDirect3DDevice2 *iface,
1969 IDirectDrawSurface **RenderTarget)
1971 IDirect3DDeviceImpl *This = device_from_device2(iface);
1972 IDirectDrawSurface7 *RenderTarget7;
1973 IDirectDrawSurfaceImpl *RenderTargetImpl;
1976 TRACE("iface %p, target %p.\n", iface, RenderTarget);
1979 return DDERR_INVALIDPARAMS;
1981 hr = IDirect3DDevice7_GetRenderTarget((IDirect3DDevice7 *)This, &RenderTarget7);
1982 if(hr != D3D_OK) return hr;
1983 RenderTargetImpl = impl_from_IDirectDrawSurface7(RenderTarget7);
1984 *RenderTarget = &RenderTargetImpl->IDirectDrawSurface_iface;
1988 /*****************************************************************************
1989 * IDirect3DDevice3::Begin
1991 * Begins a description block of vertices. This is similar to glBegin()
1992 * and glEnd(). After a call to IDirect3DDevice3::End, the vertices
1993 * described with IDirect3DDevice::Vertex are drawn.
1998 * PrimitiveType: The type of primitives to draw
1999 * VertexTypeDesc: A flexible vertex format description of the vertices
2000 * Flags: Some flags..
2005 *****************************************************************************/
2006 static HRESULT WINAPI
2007 IDirect3DDeviceImpl_3_Begin(IDirect3DDevice3 *iface,
2008 D3DPRIMITIVETYPE PrimitiveType,
2009 DWORD VertexTypeDesc,
2012 IDirect3DDeviceImpl *This = device_from_device3(iface);
2014 TRACE("iface %p, primitive_type %#x, FVF %#x, flags %#x.\n",
2015 iface, PrimitiveType, VertexTypeDesc, Flags);
2017 EnterCriticalSection(&ddraw_cs);
2018 This->primitive_type = PrimitiveType;
2019 This->vertex_type = VertexTypeDesc;
2020 This->render_flags = Flags;
2021 This->vertex_size = get_flexible_vertex_size(This->vertex_type);
2022 This->nb_vertices = 0;
2023 LeaveCriticalSection(&ddraw_cs);
2028 static HRESULT WINAPI IDirect3DDeviceImpl_2_Begin(IDirect3DDevice2 *iface, D3DPRIMITIVETYPE d3dpt,
2029 D3DVERTEXTYPE dwVertexTypeDesc, DWORD dwFlags)
2032 IDirect3DDeviceImpl *This = device_from_device2(iface);
2034 TRACE("iface %p, primitive_type %#x, vertex_type %#x, flags %#x.\n",
2035 iface, d3dpt, dwVertexTypeDesc, dwFlags);
2037 switch(dwVertexTypeDesc)
2039 case D3DVT_VERTEX: FVF = D3DFVF_VERTEX; break;
2040 case D3DVT_LVERTEX: FVF = D3DFVF_LVERTEX; break;
2041 case D3DVT_TLVERTEX: FVF = D3DFVF_TLVERTEX; break;
2043 ERR("Unexpected vertex type %d\n", dwVertexTypeDesc);
2044 return DDERR_INVALIDPARAMS; /* Should never happen */
2047 return IDirect3DDevice3_Begin((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, d3dpt, FVF, dwFlags);
2050 /*****************************************************************************
2051 * IDirect3DDevice3::BeginIndexed
2053 * Draws primitives based on vertices in a vertex array which are specified
2059 * PrimitiveType: Primitive type to draw
2060 * VertexType: A FVF description of the vertex format
2061 * Vertices: pointer to an array containing the vertices
2062 * NumVertices: The number of vertices in the vertex array
2063 * Flags: Some flags ...
2066 * D3D_OK, because it's a stub
2068 *****************************************************************************/
2069 static HRESULT WINAPI
2070 IDirect3DDeviceImpl_3_BeginIndexed(IDirect3DDevice3 *iface,
2071 D3DPRIMITIVETYPE PrimitiveType,
2077 FIXME("iface %p, primitive_type %#x, FVF %#x, vertices %p, vertex_count %u, flags %#x stub!\n",
2078 iface, PrimitiveType, VertexType, Vertices, NumVertices, Flags);
2084 static HRESULT WINAPI IDirect3DDeviceImpl_2_BeginIndexed(IDirect3DDevice2 *iface,
2085 D3DPRIMITIVETYPE d3dptPrimitiveType, D3DVERTEXTYPE d3dvtVertexType,
2086 void *lpvVertices, DWORD dwNumVertices, DWORD dwFlags)
2089 IDirect3DDeviceImpl *This = device_from_device2(iface);
2091 TRACE("iface %p, primitive_type %#x, vertex_type %#x, vertices %p, vertex_count %u, flags %#x stub!\n",
2092 iface, d3dptPrimitiveType, d3dvtVertexType, lpvVertices, dwNumVertices, dwFlags);
2094 switch(d3dvtVertexType)
2096 case D3DVT_VERTEX: FVF = D3DFVF_VERTEX; break;
2097 case D3DVT_LVERTEX: FVF = D3DFVF_LVERTEX; break;
2098 case D3DVT_TLVERTEX: FVF = D3DFVF_TLVERTEX; break;
2100 ERR("Unexpected vertex type %d\n", d3dvtVertexType);
2101 return DDERR_INVALIDPARAMS; /* Should never happen */
2104 return IDirect3DDevice3_BeginIndexed((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl,
2105 d3dptPrimitiveType, FVF, lpvVertices, dwNumVertices, dwFlags);
2108 /*****************************************************************************
2109 * IDirect3DDevice3::Vertex
2111 * Draws a vertex as described by IDirect3DDevice3::Begin. It places all
2112 * drawn vertices in a vertex buffer. If the buffer is too small, its
2113 * size is increased.
2118 * Vertex: Pointer to the vertex
2121 * D3D_OK, on success
2122 * DDERR_INVALIDPARAMS if Vertex is NULL
2124 *****************************************************************************/
2125 static HRESULT WINAPI
2126 IDirect3DDeviceImpl_3_Vertex(IDirect3DDevice3 *iface,
2129 IDirect3DDeviceImpl *This = device_from_device3(iface);
2131 TRACE("iface %p, vertex %p.\n", iface, Vertex);
2134 return DDERR_INVALIDPARAMS;
2136 EnterCriticalSection(&ddraw_cs);
2137 if ((This->nb_vertices+1)*This->vertex_size > This->buffer_size)
2140 This->buffer_size = This->buffer_size ? This->buffer_size * 2 : This->vertex_size * 3;
2141 old_buffer = This->vertex_buffer;
2142 This->vertex_buffer = HeapAlloc(GetProcessHeap(), 0, This->buffer_size);
2145 CopyMemory(This->vertex_buffer, old_buffer, This->nb_vertices * This->vertex_size);
2146 HeapFree(GetProcessHeap(), 0, old_buffer);
2150 CopyMemory(This->vertex_buffer + This->nb_vertices++ * This->vertex_size, Vertex, This->vertex_size);
2152 LeaveCriticalSection(&ddraw_cs);
2156 static HRESULT WINAPI IDirect3DDeviceImpl_2_Vertex(IDirect3DDevice2 *iface, void *lpVertexType)
2158 IDirect3DDeviceImpl *This = device_from_device2(iface);
2160 TRACE("iface %p, vertex %p.\n", iface, lpVertexType);
2162 return IDirect3DDevice3_Vertex((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, lpVertexType);
2165 /*****************************************************************************
2166 * IDirect3DDevice3::Index
2168 * Specifies an index to a vertex to be drawn. The vertex array has to
2169 * be specified with BeginIndexed first.
2172 * VertexIndex: The index of the vertex to draw
2175 * D3D_OK because it's a stub
2177 *****************************************************************************/
2178 static HRESULT WINAPI
2179 IDirect3DDeviceImpl_3_Index(IDirect3DDevice3 *iface,
2182 FIXME("iface %p, index %#x stub!\n", iface, VertexIndex);
2187 static HRESULT WINAPI IDirect3DDeviceImpl_2_Index(IDirect3DDevice2 *iface, WORD wVertexIndex)
2189 IDirect3DDeviceImpl *This = device_from_device2(iface);
2191 TRACE("iface %p, index %#x.\n", iface, wVertexIndex);
2193 return IDirect3DDevice3_Index((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, wVertexIndex);
2196 /*****************************************************************************
2197 * IDirect3DDevice3::End
2199 * Ends a draw begun with IDirect3DDevice3::Begin or
2200 * IDirect3DDevice::BeginIndexed. The vertices specified with
2201 * IDirect3DDevice::Vertex or IDirect3DDevice::Index are drawn using
2202 * the IDirect3DDevice7::DrawPrimitive method. So far only
2203 * non-indexed mode is supported
2208 * Flags: Some flags, as usual. Don't know which are defined
2211 * The return value of IDirect3DDevice7::DrawPrimitive
2213 *****************************************************************************/
2214 static HRESULT WINAPI
2215 IDirect3DDeviceImpl_3_End(IDirect3DDevice3 *iface,
2218 IDirect3DDeviceImpl *This = device_from_device3(iface);
2220 TRACE("iface %p, flags %#x.\n", iface, Flags);
2222 return IDirect3DDevice7_DrawPrimitive((IDirect3DDevice7 *)This, This->primitive_type,
2223 This->vertex_type, This->vertex_buffer, This->nb_vertices, This->render_flags);
2226 static HRESULT WINAPI IDirect3DDeviceImpl_2_End(IDirect3DDevice2 *iface, DWORD dwFlags)
2228 IDirect3DDeviceImpl *This = device_from_device2(iface);
2230 TRACE("iface %p, flags %#x.\n", iface, dwFlags);
2232 return IDirect3DDevice3_End((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, dwFlags);
2235 /*****************************************************************************
2236 * IDirect3DDevice7::GetRenderState
2238 * Returns the value of a render state. The possible render states are
2239 * defined in include/d3dtypes.h
2241 * Version 2, 3 and 7
2244 * RenderStateType: Render state to return the current setting of
2245 * Value: Address to store the value at
2248 * D3D_OK on success, for details see IWineD3DDevice::GetRenderState
2249 * DDERR_INVALIDPARAMS if Value == NULL
2251 *****************************************************************************/
2252 static const float zbias_factor = -0.000005f;
2255 IDirect3DDeviceImpl_7_GetRenderState(IDirect3DDevice7 *iface,
2256 D3DRENDERSTATETYPE RenderStateType,
2259 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
2262 TRACE("iface %p, state %#x, value %p.\n", iface, RenderStateType, Value);
2265 return DDERR_INVALIDPARAMS;
2267 EnterCriticalSection(&ddraw_cs);
2268 switch(RenderStateType)
2270 case D3DRENDERSTATE_TEXTUREMAG:
2272 WINED3DTEXTUREFILTERTYPE tex_mag;
2274 hr = wined3d_device_get_sampler_state(This->wined3d_device, 0, WINED3DSAMP_MAGFILTER, &tex_mag);
2278 case WINED3DTEXF_POINT:
2279 *Value = D3DFILTER_NEAREST;
2281 case WINED3DTEXF_LINEAR:
2282 *Value = D3DFILTER_LINEAR;
2285 ERR("Unhandled texture mag %d !\n",tex_mag);
2291 case D3DRENDERSTATE_TEXTUREMIN:
2293 WINED3DTEXTUREFILTERTYPE tex_min;
2294 WINED3DTEXTUREFILTERTYPE tex_mip;
2296 hr = wined3d_device_get_sampler_state(This->wined3d_device,
2297 0, WINED3DSAMP_MINFILTER, &tex_min);
2300 LeaveCriticalSection(&ddraw_cs);
2303 hr = wined3d_device_get_sampler_state(This->wined3d_device,
2304 0, WINED3DSAMP_MIPFILTER, &tex_mip);
2308 case WINED3DTEXF_POINT:
2311 case WINED3DTEXF_NONE:
2312 *Value = D3DFILTER_NEAREST;
2314 case WINED3DTEXF_POINT:
2315 *Value = D3DFILTER_MIPNEAREST;
2317 case WINED3DTEXF_LINEAR:
2318 *Value = D3DFILTER_LINEARMIPNEAREST;
2321 ERR("Unhandled mip filter %#x.\n", tex_mip);
2322 *Value = D3DFILTER_NEAREST;
2326 case WINED3DTEXF_LINEAR:
2329 case WINED3DTEXF_NONE:
2330 *Value = D3DFILTER_LINEAR;
2332 case WINED3DTEXF_POINT:
2333 *Value = D3DFILTER_MIPLINEAR;
2335 case WINED3DTEXF_LINEAR:
2336 *Value = D3DFILTER_LINEARMIPLINEAR;
2339 ERR("Unhandled mip filter %#x.\n", tex_mip);
2340 *Value = D3DFILTER_LINEAR;
2345 ERR("Unhandled texture min filter %#x.\n",tex_min);
2346 *Value = D3DFILTER_NEAREST;
2352 case D3DRENDERSTATE_TEXTUREADDRESS:
2353 case D3DRENDERSTATE_TEXTUREADDRESSU:
2354 hr = wined3d_device_get_sampler_state(This->wined3d_device,
2355 0, WINED3DSAMP_ADDRESSU, Value);
2357 case D3DRENDERSTATE_TEXTUREADDRESSV:
2358 hr = wined3d_device_get_sampler_state(This->wined3d_device,
2359 0, WINED3DSAMP_ADDRESSV, Value);
2362 case D3DRENDERSTATE_BORDERCOLOR:
2363 FIXME("Unhandled render state D3DRENDERSTATE_BORDERCOLOR.\n");
2367 case D3DRENDERSTATE_TEXTUREHANDLE:
2368 case D3DRENDERSTATE_TEXTUREMAPBLEND:
2369 WARN("Render state %#x is invalid in d3d7.\n", RenderStateType);
2370 hr = DDERR_INVALIDPARAMS;
2373 case D3DRENDERSTATE_ZBIAS:
2381 hr = wined3d_device_get_render_state(This->wined3d_device, WINED3DRS_DEPTHBIAS, &wined3d_value.d);
2383 *Value = wined3d_value.f / zbias_factor;
2388 if (RenderStateType >= D3DRENDERSTATE_STIPPLEPATTERN00
2389 && RenderStateType <= D3DRENDERSTATE_STIPPLEPATTERN31)
2391 FIXME("Unhandled stipple pattern render state (%#x).\n",
2396 hr = wined3d_device_get_render_state(This->wined3d_device, RenderStateType, Value);
2398 LeaveCriticalSection(&ddraw_cs);
2402 static HRESULT WINAPI
2403 IDirect3DDeviceImpl_7_GetRenderState_FPUSetup(IDirect3DDevice7 *iface,
2404 D3DRENDERSTATETYPE RenderStateType,
2407 return IDirect3DDeviceImpl_7_GetRenderState(iface, RenderStateType, Value);
2410 static HRESULT WINAPI
2411 IDirect3DDeviceImpl_7_GetRenderState_FPUPreserve(IDirect3DDevice7 *iface,
2412 D3DRENDERSTATETYPE RenderStateType,
2418 old_fpucw = d3d_fpu_setup();
2419 hr = IDirect3DDeviceImpl_7_GetRenderState(iface, RenderStateType, Value);
2420 set_fpu_control_word(old_fpucw);
2425 static HRESULT WINAPI
2426 IDirect3DDeviceImpl_3_GetRenderState(IDirect3DDevice3 *iface,
2427 D3DRENDERSTATETYPE dwRenderStateType,
2428 DWORD *lpdwRenderState)
2430 IDirect3DDeviceImpl *This = device_from_device3(iface);
2433 TRACE("iface %p, state %#x, value %p.\n", iface, dwRenderStateType, lpdwRenderState);
2435 switch(dwRenderStateType)
2437 case D3DRENDERSTATE_TEXTUREHANDLE:
2439 /* This state is wrapped to SetTexture in SetRenderState, so
2440 * it has to be wrapped to GetTexture here. */
2441 struct wined3d_texture *tex = NULL;
2442 *lpdwRenderState = 0;
2444 EnterCriticalSection(&ddraw_cs);
2446 hr = wined3d_device_get_texture(This->wined3d_device, 0, &tex);
2447 if (SUCCEEDED(hr) && tex)
2449 /* The parent of the texture is the IDirectDrawSurface7
2450 * interface of the ddraw surface. */
2451 IDirectDrawSurfaceImpl *parent = wined3d_texture_get_parent(tex);
2452 if (parent) *lpdwRenderState = parent->Handle;
2453 wined3d_texture_decref(tex);
2456 LeaveCriticalSection(&ddraw_cs);
2461 case D3DRENDERSTATE_TEXTUREMAPBLEND:
2463 /* D3DRENDERSTATE_TEXTUREMAPBLEND is mapped to texture state stages in SetRenderState; reverse
2464 the mapping to get the value. */
2465 DWORD colorop, colorarg1, colorarg2;
2466 DWORD alphaop, alphaarg1, alphaarg2;
2468 EnterCriticalSection(&ddraw_cs);
2470 This->legacyTextureBlending = TRUE;
2472 wined3d_device_get_texture_stage_state(This->wined3d_device, 0, WINED3DTSS_COLOROP, &colorop);
2473 wined3d_device_get_texture_stage_state(This->wined3d_device, 0, WINED3DTSS_COLORARG1, &colorarg1);
2474 wined3d_device_get_texture_stage_state(This->wined3d_device, 0, WINED3DTSS_COLORARG2, &colorarg2);
2475 wined3d_device_get_texture_stage_state(This->wined3d_device, 0, WINED3DTSS_ALPHAOP, &alphaop);
2476 wined3d_device_get_texture_stage_state(This->wined3d_device, 0, WINED3DTSS_ALPHAARG1, &alphaarg1);
2477 wined3d_device_get_texture_stage_state(This->wined3d_device, 0, WINED3DTSS_ALPHAARG2, &alphaarg2);
2479 if (colorop == WINED3DTOP_SELECTARG1 && colorarg1 == WINED3DTA_TEXTURE &&
2480 alphaop == WINED3DTOP_SELECTARG1 && alphaarg1 == WINED3DTA_TEXTURE)
2482 *lpdwRenderState = D3DTBLEND_DECAL;
2484 else if (colorop == WINED3DTOP_SELECTARG1 && colorarg1 == WINED3DTA_TEXTURE &&
2485 alphaop == WINED3DTOP_MODULATE && alphaarg1 == WINED3DTA_TEXTURE && alphaarg2 == WINED3DTA_CURRENT)
2487 *lpdwRenderState = D3DTBLEND_DECALALPHA;
2489 else if (colorop == WINED3DTOP_MODULATE && colorarg1 == WINED3DTA_TEXTURE && colorarg2 == WINED3DTA_CURRENT &&
2490 alphaop == WINED3DTOP_MODULATE && alphaarg1 == WINED3DTA_TEXTURE && alphaarg2 == WINED3DTA_CURRENT)
2492 *lpdwRenderState = D3DTBLEND_MODULATEALPHA;
2496 struct wined3d_texture *tex = NULL;
2498 BOOL tex_alpha = FALSE;
2499 DDPIXELFORMAT ddfmt;
2501 hr = wined3d_device_get_texture(This->wined3d_device, 0, &tex);
2503 if(hr == WINED3D_OK && tex)
2505 struct wined3d_resource *sub_resource;
2507 if ((sub_resource = wined3d_texture_get_sub_resource(tex, 0)))
2509 struct wined3d_resource_desc desc;
2511 wined3d_resource_get_desc(sub_resource, &desc);
2512 ddfmt.dwSize = sizeof(ddfmt);
2513 PixelFormat_WineD3DtoDD(&ddfmt, desc.format);
2514 if (ddfmt.u5.dwRGBAlphaBitMask) tex_alpha = TRUE;
2517 wined3d_texture_decref(tex);
2520 if (!(colorop == WINED3DTOP_MODULATE && colorarg1 == WINED3DTA_TEXTURE && colorarg2 == WINED3DTA_CURRENT &&
2521 alphaop == (tex_alpha ? WINED3DTOP_SELECTARG1 : WINED3DTOP_SELECTARG2) &&
2522 alphaarg1 == WINED3DTA_TEXTURE && alphaarg2 == WINED3DTA_CURRENT))
2524 ERR("Unexpected texture stage state setup, returning D3DTBLEND_MODULATE - likely erroneous\n");
2527 *lpdwRenderState = D3DTBLEND_MODULATE;
2530 LeaveCriticalSection(&ddraw_cs);
2536 return IDirect3DDevice7_GetRenderState((IDirect3DDevice7 *)This, dwRenderStateType, lpdwRenderState);
2540 static HRESULT WINAPI IDirect3DDeviceImpl_2_GetRenderState(IDirect3DDevice2 *iface,
2541 D3DRENDERSTATETYPE dwRenderStateType, DWORD *lpdwRenderState)
2543 IDirect3DDeviceImpl *This = device_from_device2(iface);
2545 TRACE("iface %p, state %#x, value %p.\n", iface, dwRenderStateType, lpdwRenderState);
2547 return IDirect3DDevice3_GetRenderState((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl,
2548 dwRenderStateType, lpdwRenderState);
2551 /*****************************************************************************
2552 * IDirect3DDevice7::SetRenderState
2554 * Sets a render state. The possible render states are defined in
2555 * include/d3dtypes.h
2557 * Version 2, 3 and 7
2560 * RenderStateType: State to set
2561 * Value: Value to assign to that state
2564 * D3D_OK on success,
2565 * for details see IWineD3DDevice::SetRenderState
2567 *****************************************************************************/
2569 IDirect3DDeviceImpl_7_SetRenderState(IDirect3DDevice7 *iface,
2570 D3DRENDERSTATETYPE RenderStateType,
2573 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
2576 TRACE("iface %p, state %#x, value %#x.\n", iface, RenderStateType, Value);
2578 EnterCriticalSection(&ddraw_cs);
2579 /* Some render states need special care */
2580 switch(RenderStateType)
2583 * The ddraw texture filter mapping works like this:
2584 * D3DFILTER_NEAREST Point min/mag, no mip
2585 * D3DFILTER_MIPNEAREST Point min/mag, point mip
2586 * D3DFILTER_LINEARMIPNEAREST: Point min/mag, linear mip
2588 * D3DFILTER_LINEAR Linear min/mag, no mip
2589 * D3DFILTER_MIPLINEAR Linear min/mag, point mip
2590 * D3DFILTER_LINEARMIPLINEAR Linear min/mag, linear mip
2592 * This is the opposite of the GL naming convention,
2593 * D3DFILTER_LINEARMIPNEAREST corresponds to GL_NEAREST_MIPMAP_LINEAR.
2595 case D3DRENDERSTATE_TEXTUREMAG:
2597 WINED3DTEXTUREFILTERTYPE tex_mag;
2601 case D3DFILTER_NEAREST:
2602 case D3DFILTER_MIPNEAREST:
2603 case D3DFILTER_LINEARMIPNEAREST:
2604 tex_mag = WINED3DTEXF_POINT;
2606 case D3DFILTER_LINEAR:
2607 case D3DFILTER_MIPLINEAR:
2608 case D3DFILTER_LINEARMIPLINEAR:
2609 tex_mag = WINED3DTEXF_LINEAR;
2612 tex_mag = WINED3DTEXF_POINT;
2613 ERR("Unhandled texture mag %d !\n",Value);
2617 hr = wined3d_device_set_sampler_state(This->wined3d_device, 0, WINED3DSAMP_MAGFILTER, tex_mag);
2621 case D3DRENDERSTATE_TEXTUREMIN:
2623 WINED3DTEXTUREFILTERTYPE tex_min;
2624 WINED3DTEXTUREFILTERTYPE tex_mip;
2626 switch ((D3DTEXTUREFILTER) Value)
2628 case D3DFILTER_NEAREST:
2629 tex_min = WINED3DTEXF_POINT;
2630 tex_mip = WINED3DTEXF_NONE;
2632 case D3DFILTER_LINEAR:
2633 tex_min = WINED3DTEXF_LINEAR;
2634 tex_mip = WINED3DTEXF_NONE;
2636 case D3DFILTER_MIPNEAREST:
2637 tex_min = WINED3DTEXF_POINT;
2638 tex_mip = WINED3DTEXF_POINT;
2640 case D3DFILTER_MIPLINEAR:
2641 tex_min = WINED3DTEXF_LINEAR;
2642 tex_mip = WINED3DTEXF_POINT;
2644 case D3DFILTER_LINEARMIPNEAREST:
2645 tex_min = WINED3DTEXF_POINT;
2646 tex_mip = WINED3DTEXF_LINEAR;
2648 case D3DFILTER_LINEARMIPLINEAR:
2649 tex_min = WINED3DTEXF_LINEAR;
2650 tex_mip = WINED3DTEXF_LINEAR;
2654 ERR("Unhandled texture min %d !\n",Value);
2655 tex_min = WINED3DTEXF_POINT;
2656 tex_mip = WINED3DTEXF_NONE;
2660 wined3d_device_set_sampler_state(This->wined3d_device,
2661 0, WINED3DSAMP_MIPFILTER, tex_mip);
2662 hr = wined3d_device_set_sampler_state(This->wined3d_device,
2663 0, WINED3DSAMP_MINFILTER, tex_min);
2667 case D3DRENDERSTATE_TEXTUREADDRESS:
2668 wined3d_device_set_sampler_state(This->wined3d_device,
2669 0, WINED3DSAMP_ADDRESSV, Value);
2671 case D3DRENDERSTATE_TEXTUREADDRESSU:
2672 hr = wined3d_device_set_sampler_state(This->wined3d_device,
2673 0, WINED3DSAMP_ADDRESSU, Value);
2675 case D3DRENDERSTATE_TEXTUREADDRESSV:
2676 hr = wined3d_device_set_sampler_state(This->wined3d_device,
2677 0, WINED3DSAMP_ADDRESSV, Value);
2680 case D3DRENDERSTATE_BORDERCOLOR:
2681 /* This should probably just forward to the corresponding sampler
2682 * state. Needs tests. */
2683 FIXME("Unhandled render state D3DRENDERSTATE_BORDERCOLOR.\n");
2687 case D3DRENDERSTATE_TEXTUREHANDLE:
2688 case D3DRENDERSTATE_TEXTUREMAPBLEND:
2689 WARN("Render state %#x is invalid in d3d7.\n", RenderStateType);
2690 hr = DDERR_INVALIDPARAMS;
2693 case D3DRENDERSTATE_ZBIAS:
2700 wined3d_value.f = Value * zbias_factor;
2701 hr = wined3d_device_set_render_state(This->wined3d_device, WINED3DRS_DEPTHBIAS, wined3d_value.d);
2706 if (RenderStateType >= D3DRENDERSTATE_STIPPLEPATTERN00
2707 && RenderStateType <= D3DRENDERSTATE_STIPPLEPATTERN31)
2709 FIXME("Unhandled stipple pattern render state (%#x).\n",
2715 hr = wined3d_device_set_render_state(This->wined3d_device, RenderStateType, Value);
2718 LeaveCriticalSection(&ddraw_cs);
2722 static HRESULT WINAPI
2723 IDirect3DDeviceImpl_7_SetRenderState_FPUSetup(IDirect3DDevice7 *iface,
2724 D3DRENDERSTATETYPE RenderStateType,
2727 return IDirect3DDeviceImpl_7_SetRenderState(iface, RenderStateType, Value);
2730 static HRESULT WINAPI
2731 IDirect3DDeviceImpl_7_SetRenderState_FPUPreserve(IDirect3DDevice7 *iface,
2732 D3DRENDERSTATETYPE RenderStateType,
2738 old_fpucw = d3d_fpu_setup();
2739 hr = IDirect3DDeviceImpl_7_SetRenderState(iface, RenderStateType, Value);
2740 set_fpu_control_word(old_fpucw);
2745 static HRESULT WINAPI
2746 IDirect3DDeviceImpl_3_SetRenderState(IDirect3DDevice3 *iface,
2747 D3DRENDERSTATETYPE RenderStateType,
2750 /* Note about D3DRENDERSTATE_TEXTUREMAPBLEND implementation: most of values
2751 for this state can be directly mapped to texture stage colorop and alphaop, but
2752 D3DTBLEND_MODULATE is tricky: it uses alpha from texture when available and alpha
2753 from diffuse otherwise. So changing the texture must be monitored in SetTexture to modify
2754 alphaarg when needed.
2756 Aliens vs Predator 1 depends on accurate D3DTBLEND_MODULATE emulation
2758 Legacy texture blending (TEXTUREMAPBLEND) and texture stage states: directx6 docs state that
2759 TEXTUREMAPBLEND is deprecated, yet can still be used. Games must not use both or results
2760 are undefined. D3DTBLEND_MODULATE mode in particular is dependent on texture pixel format and
2761 requires fixup of stage 0 texture states when texture changes, but this fixup can interfere
2762 with games not using this deprecated state. So a flag 'legacyTextureBlending' has to be kept
2763 in device - TRUE if the app is using TEXTUREMAPBLEND.
2765 Tests show that setting TEXTUREMAPBLEND on native doesn't seem to change values returned by
2766 GetTextureStageState and vice versa. Not so on Wine, but it is 'undefined' anyway so, probably, ok,
2767 unless some broken game will be found that cares. */
2770 IDirect3DDeviceImpl *This = device_from_device3(iface);
2772 TRACE("iface %p, state %#x, value %#x.\n", iface, RenderStateType, Value);
2774 EnterCriticalSection(&ddraw_cs);
2776 switch(RenderStateType)
2778 case D3DRENDERSTATE_TEXTUREHANDLE:
2780 IDirectDrawSurfaceImpl *surf;
2784 hr = wined3d_device_set_texture(This->wined3d_device, 0, NULL);
2788 surf = ddraw_get_object(&This->handle_table, Value - 1, DDRAW_HANDLE_SURFACE);
2791 WARN("Invalid texture handle.\n");
2792 hr = DDERR_INVALIDPARAMS;
2796 hr = IDirect3DDevice3_SetTexture(iface, 0, (IDirect3DTexture2 *)&surf->IDirect3DTexture2_vtbl);
2800 case D3DRENDERSTATE_TEXTUREMAPBLEND:
2802 This->legacyTextureBlending = TRUE;
2804 switch ( (D3DTEXTUREBLEND) Value)
2806 case D3DTBLEND_MODULATE:
2808 struct wined3d_texture *tex = NULL;
2809 BOOL tex_alpha = FALSE;
2810 DDPIXELFORMAT ddfmt;
2812 hr = wined3d_device_get_texture(This->wined3d_device, 0, &tex);
2814 if(hr == WINED3D_OK && tex)
2816 struct wined3d_resource *sub_resource;
2818 if ((sub_resource = wined3d_texture_get_sub_resource(tex, 0)))
2820 struct wined3d_resource_desc desc;
2822 wined3d_resource_get_desc(sub_resource, &desc);
2823 ddfmt.dwSize = sizeof(ddfmt);
2824 PixelFormat_WineD3DtoDD(&ddfmt, desc.format);
2825 if (ddfmt.u5.dwRGBAlphaBitMask) tex_alpha = TRUE;
2828 wined3d_texture_decref(tex);
2832 wined3d_device_set_texture_stage_state(This->wined3d_device,
2833 0, WINED3DTSS_ALPHAOP, WINED3DTOP_SELECTARG1);
2835 wined3d_device_set_texture_stage_state(This->wined3d_device,
2836 0, WINED3DTSS_ALPHAOP, WINED3DTOP_SELECTARG2);
2837 wined3d_device_set_texture_stage_state(This->wined3d_device,
2838 0, WINED3DTSS_ALPHAARG1, WINED3DTA_TEXTURE);
2839 wined3d_device_set_texture_stage_state(This->wined3d_device,
2840 0, WINED3DTSS_ALPHAARG2, WINED3DTA_CURRENT);
2841 wined3d_device_set_texture_stage_state(This->wined3d_device,
2842 0, WINED3DTSS_COLORARG1, WINED3DTA_TEXTURE);
2843 wined3d_device_set_texture_stage_state(This->wined3d_device,
2844 0, WINED3DTSS_COLORARG2, WINED3DTA_CURRENT);
2845 wined3d_device_set_texture_stage_state(This->wined3d_device,
2846 0, WINED3DTSS_COLOROP, WINED3DTOP_MODULATE);
2851 wined3d_device_set_texture_stage_state(This->wined3d_device,
2852 0, WINED3DTSS_COLOROP, WINED3DTOP_ADD);
2853 wined3d_device_set_texture_stage_state(This->wined3d_device,
2854 0, WINED3DTSS_COLORARG1, WINED3DTA_TEXTURE);
2855 wined3d_device_set_texture_stage_state(This->wined3d_device,
2856 0, WINED3DTSS_COLORARG2, WINED3DTA_CURRENT);
2857 wined3d_device_set_texture_stage_state(This->wined3d_device,
2858 0, WINED3DTSS_ALPHAOP, WINED3DTOP_SELECTARG2);
2859 wined3d_device_set_texture_stage_state(This->wined3d_device,
2860 0, WINED3DTSS_ALPHAARG2, WINED3DTA_CURRENT);
2863 case D3DTBLEND_MODULATEALPHA:
2864 wined3d_device_set_texture_stage_state(This->wined3d_device,
2865 0, WINED3DTSS_COLORARG1, WINED3DTA_TEXTURE);
2866 wined3d_device_set_texture_stage_state(This->wined3d_device,
2867 0, WINED3DTSS_ALPHAARG1, WINED3DTA_TEXTURE);
2868 wined3d_device_set_texture_stage_state(This->wined3d_device,
2869 0, WINED3DTSS_COLORARG2, WINED3DTA_CURRENT);
2870 wined3d_device_set_texture_stage_state(This->wined3d_device,
2871 0, WINED3DTSS_ALPHAARG2, WINED3DTA_CURRENT);
2872 wined3d_device_set_texture_stage_state(This->wined3d_device,
2873 0, WINED3DTSS_COLOROP, WINED3DTOP_MODULATE);
2874 wined3d_device_set_texture_stage_state(This->wined3d_device,
2875 0, WINED3DTSS_ALPHAOP, WINED3DTOP_MODULATE);
2878 case D3DTBLEND_COPY:
2879 case D3DTBLEND_DECAL:
2880 wined3d_device_set_texture_stage_state(This->wined3d_device,
2881 0, WINED3DTSS_COLORARG1, WINED3DTA_TEXTURE);
2882 wined3d_device_set_texture_stage_state(This->wined3d_device,
2883 0, WINED3DTSS_ALPHAARG1, WINED3DTA_TEXTURE);
2884 wined3d_device_set_texture_stage_state(This->wined3d_device,
2885 0, WINED3DTSS_COLOROP, WINED3DTOP_SELECTARG1);
2886 wined3d_device_set_texture_stage_state(This->wined3d_device,
2887 0, WINED3DTSS_ALPHAOP, WINED3DTOP_SELECTARG1);
2890 case D3DTBLEND_DECALALPHA:
2891 wined3d_device_set_texture_stage_state(This->wined3d_device,
2892 0, WINED3DTSS_COLOROP, WINED3DTOP_BLENDTEXTUREALPHA);
2893 wined3d_device_set_texture_stage_state(This->wined3d_device,
2894 0, WINED3DTSS_COLORARG1, WINED3DTA_TEXTURE);
2895 wined3d_device_set_texture_stage_state(This->wined3d_device,
2896 0, WINED3DTSS_COLORARG2, WINED3DTA_CURRENT);
2897 wined3d_device_set_texture_stage_state(This->wined3d_device,
2898 0, WINED3DTSS_ALPHAOP, WINED3DTOP_SELECTARG2);
2899 wined3d_device_set_texture_stage_state(This->wined3d_device,
2900 0, WINED3DTSS_ALPHAARG2, WINED3DTA_CURRENT);
2904 ERR("Unhandled texture environment %d !\n",Value);
2912 hr = IDirect3DDevice7_SetRenderState((IDirect3DDevice7 *)This, RenderStateType, Value);
2916 LeaveCriticalSection(&ddraw_cs);
2921 static HRESULT WINAPI IDirect3DDeviceImpl_2_SetRenderState(IDirect3DDevice2 *iface,
2922 D3DRENDERSTATETYPE RenderStateType, DWORD Value)
2924 IDirect3DDeviceImpl *This = device_from_device2(iface);
2926 TRACE("iface %p, state %#x, value %#x.\n", iface, RenderStateType, Value);
2928 return IDirect3DDevice3_SetRenderState((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, RenderStateType, Value);
2931 /*****************************************************************************
2932 * Direct3DDevice3::SetLightState
2934 * Sets a light state for Direct3DDevice3 and Direct3DDevice2. The
2935 * light states are forwarded to Direct3DDevice7 render states
2940 * LightStateType: The light state to change
2941 * Value: The value to assign to that light state
2945 * DDERR_INVALIDPARAMS if the parameters were incorrect
2946 * Also check IDirect3DDevice7::SetRenderState
2948 *****************************************************************************/
2949 static HRESULT WINAPI
2950 IDirect3DDeviceImpl_3_SetLightState(IDirect3DDevice3 *iface,
2951 D3DLIGHTSTATETYPE LightStateType,
2954 IDirect3DDeviceImpl *This = device_from_device3(iface);
2957 TRACE("iface %p, state %#x, value %#x.\n", iface, LightStateType, Value);
2959 if (!LightStateType || (LightStateType > D3DLIGHTSTATE_COLORVERTEX))
2961 TRACE("Unexpected Light State Type\n");
2962 return DDERR_INVALIDPARAMS;
2965 EnterCriticalSection(&ddraw_cs);
2966 if (LightStateType == D3DLIGHTSTATE_MATERIAL /* 1 */)
2968 IDirect3DMaterialImpl *m = ddraw_get_object(&This->handle_table, Value - 1, DDRAW_HANDLE_MATERIAL);
2971 WARN("Invalid material handle.\n");
2972 LeaveCriticalSection(&ddraw_cs);
2973 return DDERR_INVALIDPARAMS;
2976 TRACE(" activating material %p.\n", m);
2977 material_activate(m);
2979 This->material = Value;
2981 else if (LightStateType == D3DLIGHTSTATE_COLORMODEL /* 3 */)
2986 ERR("DDCOLOR_MONO should not happen!\n");
2989 /* We are already in this mode */
2990 TRACE("Setting color model to RGB (no-op).\n");
2993 ERR("Unknown color model!\n");
2994 LeaveCriticalSection(&ddraw_cs);
2995 return DDERR_INVALIDPARAMS;
3000 D3DRENDERSTATETYPE rs;
3001 switch (LightStateType)
3003 case D3DLIGHTSTATE_AMBIENT: /* 2 */
3004 rs = D3DRENDERSTATE_AMBIENT;
3006 case D3DLIGHTSTATE_FOGMODE: /* 4 */
3007 rs = D3DRENDERSTATE_FOGVERTEXMODE;
3009 case D3DLIGHTSTATE_FOGSTART: /* 5 */
3010 rs = D3DRENDERSTATE_FOGSTART;
3012 case D3DLIGHTSTATE_FOGEND: /* 6 */
3013 rs = D3DRENDERSTATE_FOGEND;
3015 case D3DLIGHTSTATE_FOGDENSITY: /* 7 */
3016 rs = D3DRENDERSTATE_FOGDENSITY;
3018 case D3DLIGHTSTATE_COLORVERTEX: /* 8 */
3019 rs = D3DRENDERSTATE_COLORVERTEX;
3022 ERR("Unknown D3DLIGHTSTATETYPE %d.\n", LightStateType);
3023 LeaveCriticalSection(&ddraw_cs);
3024 return DDERR_INVALIDPARAMS;
3027 hr = IDirect3DDevice7_SetRenderState((IDirect3DDevice7 *)This, rs, Value);
3028 LeaveCriticalSection(&ddraw_cs);
3032 LeaveCriticalSection(&ddraw_cs);
3036 static HRESULT WINAPI IDirect3DDeviceImpl_2_SetLightState(IDirect3DDevice2 *iface,
3037 D3DLIGHTSTATETYPE LightStateType, DWORD Value)
3039 IDirect3DDeviceImpl *This = device_from_device2(iface);
3041 TRACE("iface %p, state %#x, value %#x.\n", iface, LightStateType, Value);
3043 return IDirect3DDevice3_SetLightState((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, LightStateType, Value);
3046 /*****************************************************************************
3047 * IDirect3DDevice3::GetLightState
3049 * Returns the current setting of a light state. The state is read from
3050 * the Direct3DDevice7 render state.
3055 * LightStateType: The light state to return
3056 * Value: The address to store the light state setting at
3060 * DDDERR_INVALIDPARAMS if the parameters were incorrect
3061 * Also see IDirect3DDevice7::GetRenderState
3063 *****************************************************************************/
3064 static HRESULT WINAPI
3065 IDirect3DDeviceImpl_3_GetLightState(IDirect3DDevice3 *iface,
3066 D3DLIGHTSTATETYPE LightStateType,
3069 IDirect3DDeviceImpl *This = device_from_device3(iface);
3072 TRACE("iface %p, state %#x, value %p.\n", iface, LightStateType, Value);
3074 if (!LightStateType || (LightStateType > D3DLIGHTSTATE_COLORVERTEX))
3076 TRACE("Unexpected Light State Type\n");
3077 return DDERR_INVALIDPARAMS;
3081 return DDERR_INVALIDPARAMS;
3083 EnterCriticalSection(&ddraw_cs);
3084 if (LightStateType == D3DLIGHTSTATE_MATERIAL /* 1 */)
3086 *Value = This->material;
3088 else if (LightStateType == D3DLIGHTSTATE_COLORMODEL /* 3 */)
3090 *Value = D3DCOLOR_RGB;
3094 D3DRENDERSTATETYPE rs;
3095 switch (LightStateType)
3097 case D3DLIGHTSTATE_AMBIENT: /* 2 */
3098 rs = D3DRENDERSTATE_AMBIENT;
3100 case D3DLIGHTSTATE_FOGMODE: /* 4 */
3101 rs = D3DRENDERSTATE_FOGVERTEXMODE;
3103 case D3DLIGHTSTATE_FOGSTART: /* 5 */
3104 rs = D3DRENDERSTATE_FOGSTART;
3106 case D3DLIGHTSTATE_FOGEND: /* 6 */
3107 rs = D3DRENDERSTATE_FOGEND;
3109 case D3DLIGHTSTATE_FOGDENSITY: /* 7 */
3110 rs = D3DRENDERSTATE_FOGDENSITY;
3112 case D3DLIGHTSTATE_COLORVERTEX: /* 8 */
3113 rs = D3DRENDERSTATE_COLORVERTEX;
3116 ERR("Unknown D3DLIGHTSTATETYPE %d.\n", LightStateType);
3117 LeaveCriticalSection(&ddraw_cs);
3118 return DDERR_INVALIDPARAMS;
3121 hr = IDirect3DDevice7_GetRenderState((IDirect3DDevice7 *)This, rs, Value);
3122 LeaveCriticalSection(&ddraw_cs);
3126 LeaveCriticalSection(&ddraw_cs);
3130 static HRESULT WINAPI IDirect3DDeviceImpl_2_GetLightState(IDirect3DDevice2 *iface,
3131 D3DLIGHTSTATETYPE LightStateType, DWORD *Value)
3133 IDirect3DDeviceImpl *This = device_from_device2(iface);
3135 TRACE("iface %p, state %#x, value %p.\n", iface, LightStateType, Value);
3137 return IDirect3DDevice3_GetLightState((IDirect3DDevice3 *)&This->IDirect3DDevice3_vtbl, LightStateType, Value);
3140 /*****************************************************************************
3141 * IDirect3DDevice7::SetTransform
3143 * Assigns a D3DMATRIX to a transform type. The transform types are defined
3144 * in include/d3dtypes.h.
3145 * The D3DTRANSFORMSTATE_WORLD (=1) is translated to D3DTS_WORLDMATRIX(0)
3146 * (=255) for wined3d, because the 1 transform state was removed in d3d8
3147 * and WineD3D already understands the replacement D3DTS_WORLDMATRIX(0)
3149 * Version 2, 3 and 7
3152 * TransformStateType: transform state to set
3153 * Matrix: Matrix to assign to the state
3157 * DDERR_INVALIDPARAMS if Matrix == NULL
3158 * For details see IWineD3DDevice::SetTransform
3160 *****************************************************************************/
3162 IDirect3DDeviceImpl_7_SetTransform(IDirect3DDevice7 *iface,
3163 D3DTRANSFORMSTATETYPE TransformStateType,
3166 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
3167 D3DTRANSFORMSTATETYPE type;
3170 TRACE("iface %p, state %#x, matrix %p.\n", iface, TransformStateType, Matrix);
3172 switch(TransformStateType)
3174 case D3DTRANSFORMSTATE_WORLD : type = WINED3DTS_WORLDMATRIX(0); break;
3175 case D3DTRANSFORMSTATE_WORLD1: type = WINED3DTS_WORLDMATRIX(1); break;
3176 case D3DTRANSFORMSTATE_WORLD2: type = WINED3DTS_WORLDMATRIX(2); break;
3177 case D3DTRANSFORMSTATE_WORLD3: type = WINED3DTS_WORLDMATRIX(3); break;
3178 default: type = TransformStateType;
3182 return DDERR_INVALIDPARAMS;
3184 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
3185 EnterCriticalSection(&ddraw_cs);
3186 hr = wined3d_device_set_transform(This->wined3d_device, type, (WINED3DMATRIX *)Matrix);
3187 LeaveCriticalSection(&ddraw_cs);
3191 static HRESULT WINAPI
3192 IDirect3DDeviceImpl_7_SetTransform_FPUSetup(IDirect3DDevice7 *iface,
3193 D3DTRANSFORMSTATETYPE TransformStateType,
3196 return IDirect3DDeviceImpl_7_SetTransform(iface, TransformStateType, Matrix);
3199 static HRESULT WINAPI
3200 IDirect3DDeviceImpl_7_SetTransform_FPUPreserve(IDirect3DDevice7 *iface,
3201 D3DTRANSFORMSTATETYPE TransformStateType,
3207 old_fpucw = d3d_fpu_setup();
3208 hr = IDirect3DDeviceImpl_7_SetTransform(iface, TransformStateType, Matrix);
3209 set_fpu_control_word(old_fpucw);
3214 static HRESULT WINAPI IDirect3DDeviceImpl_3_SetTransform(IDirect3DDevice3 *iface,
3215 D3DTRANSFORMSTATETYPE TransformStateType, D3DMATRIX *D3DMatrix)
3217 IDirect3DDeviceImpl *This = device_from_device3(iface);
3219 TRACE("iface %p, state %#x, matrix %p.\n", iface, TransformStateType, D3DMatrix);
3221 return IDirect3DDevice7_SetTransform((IDirect3DDevice7 *)This, TransformStateType, D3DMatrix);
3224 static HRESULT WINAPI IDirect3DDeviceImpl_2_SetTransform(IDirect3DDevice2 *iface,
3225 D3DTRANSFORMSTATETYPE TransformStateType, D3DMATRIX *D3DMatrix)
3227 IDirect3DDeviceImpl *This = device_from_device2(iface);
3229 TRACE("iface %p, state %#x, matrix %p.\n", iface, TransformStateType, D3DMatrix);
3231 return IDirect3DDevice7_SetTransform((IDirect3DDevice7 *)This, TransformStateType, D3DMatrix);
3234 /*****************************************************************************
3235 * IDirect3DDevice7::GetTransform
3237 * Returns the matrix assigned to a transform state
3238 * D3DTRANSFORMSTATE_WORLD is translated to D3DTS_WORLDMATRIX(0), see
3242 * TransformStateType: State to read the matrix from
3243 * Matrix: Address to store the matrix at
3247 * DDERR_INVALIDPARAMS if Matrix == NULL
3248 * For details, see IWineD3DDevice::GetTransform
3250 *****************************************************************************/
3252 IDirect3DDeviceImpl_7_GetTransform(IDirect3DDevice7 *iface,
3253 D3DTRANSFORMSTATETYPE TransformStateType,
3256 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
3257 D3DTRANSFORMSTATETYPE type;
3260 TRACE("iface %p, state %#x, matrix %p.\n", iface, TransformStateType, Matrix);
3262 switch(TransformStateType)
3264 case D3DTRANSFORMSTATE_WORLD : type = WINED3DTS_WORLDMATRIX(0); break;
3265 case D3DTRANSFORMSTATE_WORLD1: type = WINED3DTS_WORLDMATRIX(1); break;
3266 case D3DTRANSFORMSTATE_WORLD2: type = WINED3DTS_WORLDMATRIX(2); break;
3267 case D3DTRANSFORMSTATE_WORLD3: type = WINED3DTS_WORLDMATRIX(3); break;
3268 default: type = TransformStateType;
3272 return DDERR_INVALIDPARAMS;
3274 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
3275 EnterCriticalSection(&ddraw_cs);
3276 hr = wined3d_device_get_transform(This->wined3d_device, type, (WINED3DMATRIX *)Matrix);
3277 LeaveCriticalSection(&ddraw_cs);
3281 static HRESULT WINAPI
3282 IDirect3DDeviceImpl_7_GetTransform_FPUSetup(IDirect3DDevice7 *iface,
3283 D3DTRANSFORMSTATETYPE TransformStateType,
3286 return IDirect3DDeviceImpl_7_GetTransform(iface, TransformStateType, Matrix);
3289 static HRESULT WINAPI
3290 IDirect3DDeviceImpl_7_GetTransform_FPUPreserve(IDirect3DDevice7 *iface,
3291 D3DTRANSFORMSTATETYPE TransformStateType,
3297 old_fpucw = d3d_fpu_setup();
3298 hr = IDirect3DDeviceImpl_7_GetTransform(iface, TransformStateType, Matrix);
3299 set_fpu_control_word(old_fpucw);
3304 static HRESULT WINAPI IDirect3DDeviceImpl_3_GetTransform(IDirect3DDevice3 *iface,
3305 D3DTRANSFORMSTATETYPE TransformStateType, D3DMATRIX *D3DMatrix)
3307 IDirect3DDeviceImpl *This = device_from_device3(iface);
3309 TRACE("iface %p, state %#x, matrix %p.\n", iface, TransformStateType, D3DMatrix);
3311 return IDirect3DDevice7_GetTransform((IDirect3DDevice7 *)This, TransformStateType, D3DMatrix);
3314 static HRESULT WINAPI IDirect3DDeviceImpl_2_GetTransform(IDirect3DDevice2 *iface,
3315 D3DTRANSFORMSTATETYPE TransformStateType, D3DMATRIX *D3DMatrix)
3317 IDirect3DDeviceImpl *This = device_from_device2(iface);
3319 TRACE("iface %p, state %#x, matrix %p.\n", iface, TransformStateType, D3DMatrix);
3321 return IDirect3DDevice7_GetTransform((IDirect3DDevice7 *)This, TransformStateType, D3DMatrix);
3324 /*****************************************************************************
3325 * IDirect3DDevice7::MultiplyTransform
3327 * Multiplies the already-set transform matrix of a transform state
3328 * with another matrix. For the world matrix, see SetTransform
3330 * Version 2, 3 and 7
3333 * TransformStateType: Transform state to multiply
3334 * D3DMatrix Matrix to multiply with.
3338 * DDERR_INVALIDPARAMS if D3DMatrix is NULL
3339 * For details, see IWineD3DDevice::MultiplyTransform
3341 *****************************************************************************/
3343 IDirect3DDeviceImpl_7_MultiplyTransform(IDirect3DDevice7 *iface,
3344 D3DTRANSFORMSTATETYPE TransformStateType,
3345 D3DMATRIX *D3DMatrix)
3347 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
3349 D3DTRANSFORMSTATETYPE type;
3351 TRACE("iface %p, state %#x, matrix %p.\n", iface, TransformStateType, D3DMatrix);
3353 switch(TransformStateType)
3355 case D3DTRANSFORMSTATE_WORLD : type = WINED3DTS_WORLDMATRIX(0); break;
3356 case D3DTRANSFORMSTATE_WORLD1: type = WINED3DTS_WORLDMATRIX(1); break;
3357 case D3DTRANSFORMSTATE_WORLD2: type = WINED3DTS_WORLDMATRIX(2); break;
3358 case D3DTRANSFORMSTATE_WORLD3: type = WINED3DTS_WORLDMATRIX(3); break;
3359 default: type = TransformStateType;
3362 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
3363 EnterCriticalSection(&ddraw_cs);
3364 hr = wined3d_device_multiply_transform(This->wined3d_device,
3365 type, (WINED3DMATRIX *)D3DMatrix);
3366 LeaveCriticalSection(&ddraw_cs);
3370 static HRESULT WINAPI
3371 IDirect3DDeviceImpl_7_MultiplyTransform_FPUSetup(IDirect3DDevice7 *iface,
3372 D3DTRANSFORMSTATETYPE TransformStateType,
3373 D3DMATRIX *D3DMatrix)
3375 return IDirect3DDeviceImpl_7_MultiplyTransform(iface, TransformStateType, D3DMatrix);
3378 static HRESULT WINAPI
3379 IDirect3DDeviceImpl_7_MultiplyTransform_FPUPreserve(IDirect3DDevice7 *iface,
3380 D3DTRANSFORMSTATETYPE TransformStateType,
3381 D3DMATRIX *D3DMatrix)
3386 old_fpucw = d3d_fpu_setup();
3387 hr = IDirect3DDeviceImpl_7_MultiplyTransform(iface, TransformStateType, D3DMatrix);
3388 set_fpu_control_word(old_fpucw);
3393 static HRESULT WINAPI IDirect3DDeviceImpl_3_MultiplyTransform(IDirect3DDevice3 *iface,
3394 D3DTRANSFORMSTATETYPE TransformStateType, D3DMATRIX *D3DMatrix)
3396 IDirect3DDeviceImpl *This = device_from_device3(iface);
3398 TRACE("iface %p, state %#x, matrix %p.\n", iface, TransformStateType, D3DMatrix);
3400 return IDirect3DDevice7_MultiplyTransform((IDirect3DDevice7 *)This, TransformStateType, D3DMatrix);
3403 static HRESULT WINAPI IDirect3DDeviceImpl_2_MultiplyTransform(IDirect3DDevice2 *iface,
3404 D3DTRANSFORMSTATETYPE TransformStateType, D3DMATRIX *D3DMatrix)
3406 IDirect3DDeviceImpl *This = device_from_device2(iface);
3408 TRACE("iface %p, state %#x, matrix %p.\n", iface, TransformStateType, D3DMatrix);
3410 return IDirect3DDevice7_MultiplyTransform((IDirect3DDevice7 *)This, TransformStateType, D3DMatrix);
3413 /*****************************************************************************
3414 * IDirect3DDevice7::DrawPrimitive
3416 * Draws primitives based on vertices in an application-provided pointer
3418 * Version 2, 3 and 7. The IDirect3DDevice2 thunk converts the fixed vertex type into
3419 * an FVF format for D3D7
3422 * PrimitiveType: The type of the primitives to draw
3423 * Vertex type: Flexible vertex format vertex description
3424 * Vertices: Pointer to the vertex array
3425 * VertexCount: The number of vertices to draw
3426 * Flags: As usual a few flags
3430 * DDERR_INVALIDPARAMS if Vertices is NULL
3431 * For details, see IWineD3DDevice::DrawPrimitiveUP
3433 *****************************************************************************/
3435 IDirect3DDeviceImpl_7_DrawPrimitive(IDirect3DDevice7 *iface,
3436 D3DPRIMITIVETYPE PrimitiveType,
3442 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
3446 TRACE("iface %p, primitive_type %#x, FVF %#x, vertices %p, vertex_count %u, flags %#x.\n",
3447 iface, PrimitiveType, VertexType, Vertices, VertexCount, Flags);
3450 return DDERR_INVALIDPARAMS;
3452 /* Get the stride */
3453 stride = get_flexible_vertex_size(VertexType);
3456 EnterCriticalSection(&ddraw_cs);
3457 hr = wined3d_device_set_vertex_declaration(This->wined3d_device, ddraw_find_decl(This->ddraw, VertexType));
3460 LeaveCriticalSection(&ddraw_cs);
3464 /* This method translates to the user pointer draw of WineD3D */
3465 wined3d_device_set_primitive_type(This->wined3d_device, PrimitiveType);
3466 hr = wined3d_device_draw_primitive_up(This->wined3d_device, VertexCount, Vertices, stride);
3467 LeaveCriticalSection(&ddraw_cs);
3471 static HRESULT WINAPI
3472 IDirect3DDeviceImpl_7_DrawPrimitive_FPUSetup(IDirect3DDevice7 *iface,
3473 D3DPRIMITIVETYPE PrimitiveType,
3479 return IDirect3DDeviceImpl_7_DrawPrimitive(iface, PrimitiveType, VertexType, Vertices, VertexCount, Flags);
3482 static HRESULT WINAPI
3483 IDirect3DDeviceImpl_7_DrawPrimitive_FPUPreserve(IDirect3DDevice7 *iface,
3484 D3DPRIMITIVETYPE PrimitiveType,
3493 old_fpucw = d3d_fpu_setup();
3494 hr = IDirect3DDeviceImpl_7_DrawPrimitive(iface, PrimitiveType, VertexType, Vertices, VertexCount, Flags);
3495 set_fpu_control_word(old_fpucw);
3500 static HRESULT WINAPI IDirect3DDeviceImpl_3_DrawPrimitive(IDirect3DDevice3 *iface,
3501 D3DPRIMITIVETYPE PrimitiveType, DWORD VertexType, void *Vertices, DWORD VertexCount,
3504 TRACE("iface %p, primitive_type %#x, FVF %#x, vertices %p, vertex_count %u, flags %#x.\n",
3505 iface, PrimitiveType, VertexType, Vertices, VertexCount, Flags);
3507 return IDirect3DDevice7_DrawPrimitive((IDirect3DDevice7 *)device_from_device3(iface),
3508 PrimitiveType, VertexType, Vertices, VertexCount, Flags);
3511 static HRESULT WINAPI IDirect3DDeviceImpl_2_DrawPrimitive(IDirect3DDevice2 *iface,
3512 D3DPRIMITIVETYPE PrimitiveType, D3DVERTEXTYPE VertexType, void *Vertices,
3513 DWORD VertexCount, DWORD Flags)
3517 TRACE("iface %p, primitive_type %#x, vertex_type %#x, vertices %p, vertex_count %u, flags %#x.\n",
3518 iface, PrimitiveType, VertexType, Vertices, VertexCount, Flags);
3522 case D3DVT_VERTEX: FVF = D3DFVF_VERTEX; break;
3523 case D3DVT_LVERTEX: FVF = D3DFVF_LVERTEX; break;
3524 case D3DVT_TLVERTEX: FVF = D3DFVF_TLVERTEX; break;
3526 ERR("Unexpected vertex type %d\n", VertexType);
3527 return DDERR_INVALIDPARAMS; /* Should never happen */
3530 return IDirect3DDevice7_DrawPrimitive((IDirect3DDevice7 *)device_from_device2(iface),
3531 PrimitiveType, FVF, Vertices, VertexCount, Flags);
3534 /*****************************************************************************
3535 * IDirect3DDevice7::DrawIndexedPrimitive
3537 * Draws vertices from an application-provided pointer, based on the index
3538 * numbers in a WORD array.
3540 * Version 2, 3 and 7. The version 7 thunk translates the vertex type into
3541 * an FVF format for D3D7
3544 * PrimitiveType: The primitive type to draw
3545 * VertexType: The FVF vertex description
3546 * Vertices: Pointer to the vertex array
3548 * Indices: Pointer to the index array
3549 * IndexCount: Number of indices = Number of vertices to draw
3550 * Flags: As usual, some flags
3554 * DDERR_INVALIDPARAMS if Vertices or Indices is NULL
3555 * For details, see IWineD3DDevice::DrawIndexedPrimitiveUP
3557 *****************************************************************************/
3559 IDirect3DDeviceImpl_7_DrawIndexedPrimitive(IDirect3DDevice7 *iface,
3560 D3DPRIMITIVETYPE PrimitiveType,
3568 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
3571 TRACE("iface %p, primitive_type %#x, FVF %#x, vertices %p, vertex_count %u, indices %p, index_count %u, flags %#x.\n",
3572 iface, PrimitiveType, VertexType, Vertices, VertexCount, Indices, IndexCount, Flags);
3574 /* Set the D3DDevice's FVF */
3575 EnterCriticalSection(&ddraw_cs);
3576 hr = wined3d_device_set_vertex_declaration(This->wined3d_device, ddraw_find_decl(This->ddraw, VertexType));
3579 ERR(" (%p) Setting the FVF failed, hr = %x!\n", This, hr);
3580 LeaveCriticalSection(&ddraw_cs);
3584 wined3d_device_set_primitive_type(This->wined3d_device, PrimitiveType);
3585 hr = wined3d_device_draw_indexed_primitive_up(This->wined3d_device, IndexCount, Indices,
3586 WINED3DFMT_R16_UINT, Vertices, get_flexible_vertex_size(VertexType));
3587 LeaveCriticalSection(&ddraw_cs);
3591 static HRESULT WINAPI
3592 IDirect3DDeviceImpl_7_DrawIndexedPrimitive_FPUSetup(IDirect3DDevice7 *iface,
3593 D3DPRIMITIVETYPE PrimitiveType,
3601 return IDirect3DDeviceImpl_7_DrawIndexedPrimitive(iface, PrimitiveType, VertexType, Vertices, VertexCount, Indices, IndexCount, Flags);
3604 static HRESULT WINAPI
3605 IDirect3DDeviceImpl_7_DrawIndexedPrimitive_FPUPreserve(IDirect3DDevice7 *iface,
3606 D3DPRIMITIVETYPE PrimitiveType,
3617 old_fpucw = d3d_fpu_setup();
3618 hr = IDirect3DDeviceImpl_7_DrawIndexedPrimitive(iface, PrimitiveType, VertexType, Vertices, VertexCount, Indices, IndexCount, Flags);
3619 set_fpu_control_word(old_fpucw);
3624 static HRESULT WINAPI IDirect3DDeviceImpl_3_DrawIndexedPrimitive(IDirect3DDevice3 *iface,
3625 D3DPRIMITIVETYPE PrimitiveType, DWORD VertexType, void *Vertices, DWORD VertexCount,
3626 WORD *Indices, DWORD IndexCount, DWORD Flags)
3628 TRACE("iface %p, primitive_type %#x, FVF %#x, vertices %p, vertex_count %u, indices %p, index_count %u, flags %#x.\n",
3629 iface, PrimitiveType, VertexType, Vertices, VertexCount, Indices, IndexCount, Flags);
3631 return IDirect3DDevice7_DrawIndexedPrimitive((IDirect3DDevice7 *)device_from_device3(iface),
3632 PrimitiveType, VertexType, Vertices, VertexCount, Indices, IndexCount, Flags);
3635 static HRESULT WINAPI IDirect3DDeviceImpl_2_DrawIndexedPrimitive(IDirect3DDevice2 *iface,
3636 D3DPRIMITIVETYPE PrimitiveType, D3DVERTEXTYPE VertexType, void *Vertices,
3637 DWORD VertexCount, WORD *Indices, DWORD IndexCount, DWORD Flags)
3641 TRACE("iface %p, primitive_type %#x, vertex_type %#x, vertices %p, vertex_count %u, indices %p, index_count %u, flags %#x.\n",
3642 iface, PrimitiveType, VertexType, Vertices, VertexCount, Indices, IndexCount, Flags);
3646 case D3DVT_VERTEX: FVF = D3DFVF_VERTEX; break;
3647 case D3DVT_LVERTEX: FVF = D3DFVF_LVERTEX; break;
3648 case D3DVT_TLVERTEX: FVF = D3DFVF_TLVERTEX; break;
3650 ERR("Unexpected vertex type %d\n", VertexType);
3651 return DDERR_INVALIDPARAMS; /* Should never happen */
3654 return IDirect3DDevice7_DrawIndexedPrimitive((IDirect3DDevice7 *)device_from_device2(iface),
3655 PrimitiveType, FVF, Vertices, VertexCount, Indices, IndexCount, Flags);
3658 /*****************************************************************************
3659 * IDirect3DDevice7::SetClipStatus
3661 * Sets the clip status. This defines things as clipping conditions and
3662 * the extents of the clipping region.
3664 * Version 2, 3 and 7
3670 * D3D_OK because it's a stub
3671 * (DDERR_INVALIDPARAMS if ClipStatus == NULL)
3673 *****************************************************************************/
3674 static HRESULT WINAPI
3675 IDirect3DDeviceImpl_7_SetClipStatus(IDirect3DDevice7 *iface,
3676 D3DCLIPSTATUS *ClipStatus)
3678 FIXME("iface %p, clip_status %p stub!\n", iface, ClipStatus);
3680 /* D3DCLIPSTATUS and WINED3DCLIPSTATUS are different. I don't know how to convert them
3681 * Perhaps this needs a new data type and an additional IWineD3DDevice method
3683 /* return IWineD3DDevice_SetClipStatus(This->wineD3DDevice, ClipStatus);*/
3687 static HRESULT WINAPI IDirect3DDeviceImpl_3_SetClipStatus(IDirect3DDevice3 *iface,
3688 D3DCLIPSTATUS *ClipStatus)
3690 TRACE("iface %p, clip_status %p.\n", iface, ClipStatus);
3692 return IDirect3DDevice7_SetClipStatus((IDirect3DDevice7 *)device_from_device3(iface), ClipStatus);
3695 static HRESULT WINAPI IDirect3DDeviceImpl_2_SetClipStatus(IDirect3DDevice2 *iface,
3696 D3DCLIPSTATUS *ClipStatus)
3698 TRACE("iface %p, clip_status %p.\n", iface, ClipStatus);
3700 return IDirect3DDevice7_SetClipStatus((IDirect3DDevice7 *)device_from_device2(iface), ClipStatus);
3703 /*****************************************************************************
3704 * IDirect3DDevice7::GetClipStatus
3706 * Returns the clip status
3709 * ClipStatus: Address to write the clip status to
3712 * D3D_OK because it's a stub
3714 *****************************************************************************/
3715 static HRESULT WINAPI
3716 IDirect3DDeviceImpl_7_GetClipStatus(IDirect3DDevice7 *iface,
3717 D3DCLIPSTATUS *ClipStatus)
3719 FIXME("iface %p, clip_status %p stub!\n", iface, ClipStatus);
3721 /* D3DCLIPSTATUS and WINED3DCLIPSTATUS are different. I don't know how to convert them */
3722 /* return IWineD3DDevice_GetClipStatus(This->wineD3DDevice, ClipStatus);*/
3726 static HRESULT WINAPI IDirect3DDeviceImpl_3_GetClipStatus(IDirect3DDevice3 *iface,
3727 D3DCLIPSTATUS *ClipStatus)
3729 TRACE("iface %p, clip_status %p.\n", iface, ClipStatus);
3731 return IDirect3DDevice7_GetClipStatus((IDirect3DDevice7 *)device_from_device3(iface), ClipStatus);
3734 static HRESULT WINAPI IDirect3DDeviceImpl_2_GetClipStatus(IDirect3DDevice2 *iface,
3735 D3DCLIPSTATUS *ClipStatus)
3737 TRACE("iface %p, clip_status %p.\n", iface, ClipStatus);
3739 return IDirect3DDevice7_GetClipStatus((IDirect3DDevice7 *)device_from_device2(iface), ClipStatus);
3742 /*****************************************************************************
3743 * IDirect3DDevice::DrawPrimitiveStrided
3745 * Draws vertices described by a D3DDRAWPRIMITIVESTRIDEDDATA structure.
3750 * PrimitiveType: The primitive type to draw
3751 * VertexType: The FVF description of the vertices to draw (for the stride??)
3752 * D3DDrawPrimStrideData: A D3DDRAWPRIMITIVESTRIDEDDATA structure describing
3753 * the vertex data locations
3754 * VertexCount: The number of vertices to draw
3758 * D3D_OK, because it's a stub
3759 * (DDERR_INVALIDPARAMS if D3DDrawPrimStrideData is NULL)
3760 * (For details, see IWineD3DDevice::DrawPrimitiveStrided)
3762 *****************************************************************************/
3764 IDirect3DDeviceImpl_7_DrawPrimitiveStrided(IDirect3DDevice7 *iface,
3765 D3DPRIMITIVETYPE PrimitiveType,
3767 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3771 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
3772 WineDirect3DVertexStridedData WineD3DStrided;
3776 TRACE("iface %p, primitive_type %#x, FVF %#x, strided_data %p, vertex_count %u, flags %#x.\n",
3777 iface, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Flags);
3779 memset(&WineD3DStrided, 0, sizeof(WineD3DStrided));
3780 /* Get the strided data right. the wined3d structure is a bit bigger
3781 * Watch out: The contents of the strided data are determined by the fvf,
3782 * not by the members set in D3DDrawPrimStrideData. So it's valid
3783 * to have diffuse.lpvData set to 0xdeadbeef if the diffuse flag is
3784 * not set in the fvf.
3786 if(VertexType & D3DFVF_POSITION_MASK)
3788 WineD3DStrided.position.format = WINED3DFMT_R32G32B32_FLOAT;
3789 WineD3DStrided.position.lpData = D3DDrawPrimStrideData->position.lpvData;
3790 WineD3DStrided.position.dwStride = D3DDrawPrimStrideData->position.dwStride;
3791 if (VertexType & D3DFVF_XYZRHW)
3793 WineD3DStrided.position.format = WINED3DFMT_R32G32B32A32_FLOAT;
3794 WineD3DStrided.position_transformed = TRUE;
3796 WineD3DStrided.position_transformed = FALSE;
3799 if(VertexType & D3DFVF_NORMAL)
3801 WineD3DStrided.normal.format = WINED3DFMT_R32G32B32_FLOAT;
3802 WineD3DStrided.normal.lpData = D3DDrawPrimStrideData->normal.lpvData;
3803 WineD3DStrided.normal.dwStride = D3DDrawPrimStrideData->normal.dwStride;
3806 if(VertexType & D3DFVF_DIFFUSE)
3808 WineD3DStrided.diffuse.format = WINED3DFMT_B8G8R8A8_UNORM;
3809 WineD3DStrided.diffuse.lpData = D3DDrawPrimStrideData->diffuse.lpvData;
3810 WineD3DStrided.diffuse.dwStride = D3DDrawPrimStrideData->diffuse.dwStride;
3813 if(VertexType & D3DFVF_SPECULAR)
3815 WineD3DStrided.specular.format = WINED3DFMT_B8G8R8A8_UNORM;
3816 WineD3DStrided.specular.lpData = D3DDrawPrimStrideData->specular.lpvData;
3817 WineD3DStrided.specular.dwStride = D3DDrawPrimStrideData->specular.dwStride;
3820 for( i = 0; i < GET_TEXCOUNT_FROM_FVF(VertexType); i++)
3822 switch(GET_TEXCOORD_SIZE_FROM_FVF(VertexType, i))
3824 case 1: WineD3DStrided.texCoords[i].format = WINED3DFMT_R32_FLOAT; break;
3825 case 2: WineD3DStrided.texCoords[i].format = WINED3DFMT_R32G32_FLOAT; break;
3826 case 3: WineD3DStrided.texCoords[i].format = WINED3DFMT_R32G32B32_FLOAT; break;
3827 case 4: WineD3DStrided.texCoords[i].format = WINED3DFMT_R32G32B32A32_FLOAT; break;
3828 default: ERR("Unexpected texture coordinate size %d\n",
3829 GET_TEXCOORD_SIZE_FROM_FVF(VertexType, i));
3831 WineD3DStrided.texCoords[i].lpData = D3DDrawPrimStrideData->textureCoords[i].lpvData;
3832 WineD3DStrided.texCoords[i].dwStride = D3DDrawPrimStrideData->textureCoords[i].dwStride;
3835 /* WineD3D doesn't need the FVF here */
3836 EnterCriticalSection(&ddraw_cs);
3837 wined3d_device_set_primitive_type(This->wined3d_device, PrimitiveType);
3838 hr = wined3d_device_draw_primitive_strided(This->wined3d_device, VertexCount, &WineD3DStrided);
3839 LeaveCriticalSection(&ddraw_cs);
3843 static HRESULT WINAPI
3844 IDirect3DDeviceImpl_7_DrawPrimitiveStrided_FPUSetup(IDirect3DDevice7 *iface,
3845 D3DPRIMITIVETYPE PrimitiveType,
3847 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3851 return IDirect3DDeviceImpl_7_DrawPrimitiveStrided(iface, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Flags);
3854 static HRESULT WINAPI
3855 IDirect3DDeviceImpl_7_DrawPrimitiveStrided_FPUPreserve(IDirect3DDevice7 *iface,
3856 D3DPRIMITIVETYPE PrimitiveType,
3858 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3865 old_fpucw = d3d_fpu_setup();
3866 hr = IDirect3DDeviceImpl_7_DrawPrimitiveStrided(iface, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Flags);
3867 set_fpu_control_word(old_fpucw);
3872 static HRESULT WINAPI IDirect3DDeviceImpl_3_DrawPrimitiveStrided(IDirect3DDevice3 *iface,
3873 D3DPRIMITIVETYPE PrimitiveType, DWORD VertexType,
3874 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData, DWORD VertexCount, DWORD Flags)
3876 TRACE("iface %p, primitive_type %#x, FVF %#x, strided_data %p, vertex_count %u, flags %#x.\n",
3877 iface, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Flags);
3879 return IDirect3DDevice7_DrawPrimitiveStrided((IDirect3DDevice7 *)device_from_device3(iface),
3880 PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Flags);
3883 /*****************************************************************************
3884 * IDirect3DDevice7::DrawIndexedPrimitiveStrided
3886 * Draws primitives specified by strided data locations based on indices
3894 * D3D_OK, because it's a stub
3895 * (DDERR_INVALIDPARAMS if D3DDrawPrimStrideData is NULL)
3896 * (DDERR_INVALIDPARAMS if Indices is NULL)
3897 * (For more details, see IWineD3DDevice::DrawIndexedPrimitiveStrided)
3899 *****************************************************************************/
3901 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveStrided(IDirect3DDevice7 *iface,
3902 D3DPRIMITIVETYPE PrimitiveType,
3904 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3910 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
3911 WineDirect3DVertexStridedData WineD3DStrided;
3915 TRACE("iface %p, primitive_type %#x, FVF %#x, strided_data %p, vertex_count %u, indices %p, index_count %u, flags %#x.\n",
3916 iface, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Indices, IndexCount, Flags);
3918 memset(&WineD3DStrided, 0, sizeof(WineD3DStrided));
3919 /* Get the strided data right. the wined3d structure is a bit bigger
3920 * Watch out: The contents of the strided data are determined by the fvf,
3921 * not by the members set in D3DDrawPrimStrideData. So it's valid
3922 * to have diffuse.lpvData set to 0xdeadbeef if the diffuse flag is
3923 * not set in the fvf.
3925 if(VertexType & D3DFVF_POSITION_MASK)
3927 WineD3DStrided.position.format = WINED3DFMT_R32G32B32_FLOAT;
3928 WineD3DStrided.position.lpData = D3DDrawPrimStrideData->position.lpvData;
3929 WineD3DStrided.position.dwStride = D3DDrawPrimStrideData->position.dwStride;
3930 if (VertexType & D3DFVF_XYZRHW)
3932 WineD3DStrided.position.format = WINED3DFMT_R32G32B32A32_FLOAT;
3933 WineD3DStrided.position_transformed = TRUE;
3935 WineD3DStrided.position_transformed = FALSE;
3938 if(VertexType & D3DFVF_NORMAL)
3940 WineD3DStrided.normal.format = WINED3DFMT_R32G32B32_FLOAT;
3941 WineD3DStrided.normal.lpData = D3DDrawPrimStrideData->normal.lpvData;
3942 WineD3DStrided.normal.dwStride = D3DDrawPrimStrideData->normal.dwStride;
3945 if(VertexType & D3DFVF_DIFFUSE)
3947 WineD3DStrided.diffuse.format = WINED3DFMT_B8G8R8A8_UNORM;
3948 WineD3DStrided.diffuse.lpData = D3DDrawPrimStrideData->diffuse.lpvData;
3949 WineD3DStrided.diffuse.dwStride = D3DDrawPrimStrideData->diffuse.dwStride;
3952 if(VertexType & D3DFVF_SPECULAR)
3954 WineD3DStrided.specular.format = WINED3DFMT_B8G8R8A8_UNORM;
3955 WineD3DStrided.specular.lpData = D3DDrawPrimStrideData->specular.lpvData;
3956 WineD3DStrided.specular.dwStride = D3DDrawPrimStrideData->specular.dwStride;
3959 for( i = 0; i < GET_TEXCOUNT_FROM_FVF(VertexType); i++)
3961 switch(GET_TEXCOORD_SIZE_FROM_FVF(VertexType, i))
3963 case 1: WineD3DStrided.texCoords[i].format = WINED3DFMT_R32_FLOAT; break;
3964 case 2: WineD3DStrided.texCoords[i].format = WINED3DFMT_R32G32_FLOAT; break;
3965 case 3: WineD3DStrided.texCoords[i].format = WINED3DFMT_R32G32B32_FLOAT; break;
3966 case 4: WineD3DStrided.texCoords[i].format = WINED3DFMT_R32G32B32A32_FLOAT; break;
3967 default: ERR("Unexpected texture coordinate size %d\n",
3968 GET_TEXCOORD_SIZE_FROM_FVF(VertexType, i));
3970 WineD3DStrided.texCoords[i].lpData = D3DDrawPrimStrideData->textureCoords[i].lpvData;
3971 WineD3DStrided.texCoords[i].dwStride = D3DDrawPrimStrideData->textureCoords[i].dwStride;
3974 /* WineD3D doesn't need the FVF here */
3975 EnterCriticalSection(&ddraw_cs);
3976 wined3d_device_set_primitive_type(This->wined3d_device, PrimitiveType);
3977 hr = wined3d_device_draw_indexed_primitive_strided(This->wined3d_device,
3978 IndexCount, &WineD3DStrided, VertexCount, Indices, WINED3DFMT_R16_UINT);
3979 LeaveCriticalSection(&ddraw_cs);
3983 static HRESULT WINAPI
3984 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveStrided_FPUSetup(IDirect3DDevice7 *iface,
3985 D3DPRIMITIVETYPE PrimitiveType,
3987 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3993 return IDirect3DDeviceImpl_7_DrawIndexedPrimitiveStrided(iface, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Indices, IndexCount, Flags);
3996 static HRESULT WINAPI
3997 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveStrided_FPUPreserve(IDirect3DDevice7 *iface,
3998 D3DPRIMITIVETYPE PrimitiveType,
4000 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
4009 old_fpucw = d3d_fpu_setup();
4010 hr = IDirect3DDeviceImpl_7_DrawIndexedPrimitiveStrided(iface, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Indices, IndexCount, Flags);
4011 set_fpu_control_word(old_fpucw);
4016 static HRESULT WINAPI IDirect3DDeviceImpl_3_DrawIndexedPrimitiveStrided(IDirect3DDevice3 *iface,
4017 D3DPRIMITIVETYPE PrimitiveType, DWORD VertexType,
4018 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData, DWORD VertexCount, WORD *Indices,
4019 DWORD IndexCount, DWORD Flags)
4021 TRACE("iface %p, primitive_type %#x, FVF %#x, strided_data %p, vertex_count %u, indices %p, index_count %u, flags %#x.\n",
4022 iface, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Indices, IndexCount, Flags);
4024 return IDirect3DDevice7_DrawIndexedPrimitiveStrided((IDirect3DDevice7 *)device_from_device3(iface),
4025 PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Indices, IndexCount, Flags);
4028 /*****************************************************************************
4029 * IDirect3DDevice7::DrawPrimitiveVB
4031 * Draws primitives from a vertex buffer to the screen.
4036 * PrimitiveType: Type of primitive to be rendered.
4037 * D3DVertexBuf: Source Vertex Buffer
4038 * StartVertex: Index of the first vertex from the buffer to be rendered
4039 * NumVertices: Number of vertices to be rendered
4040 * Flags: Can be D3DDP_WAIT to wait until rendering has finished
4044 * DDERR_INVALIDPARAMS if D3DVertexBuf is NULL
4046 *****************************************************************************/
4048 IDirect3DDeviceImpl_7_DrawPrimitiveVB(IDirect3DDevice7 *iface,
4049 D3DPRIMITIVETYPE PrimitiveType,
4050 IDirect3DVertexBuffer7 *D3DVertexBuf,
4055 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
4056 IDirect3DVertexBufferImpl *vb = unsafe_impl_from_IDirect3DVertexBuffer7(D3DVertexBuf);
4060 TRACE("iface %p, primitive_type %#x, vb %p, start_vertex %u, vertex_count %u, flags %#x.\n",
4061 iface, PrimitiveType, D3DVertexBuf, StartVertex, NumVertices, Flags);
4066 ERR("(%p) No Vertex buffer specified\n", This);
4067 return DDERR_INVALIDPARAMS;
4069 stride = get_flexible_vertex_size(vb->fvf);
4071 EnterCriticalSection(&ddraw_cs);
4072 hr = wined3d_device_set_vertex_declaration(This->wined3d_device, vb->wineD3DVertexDeclaration);
4075 ERR(" (%p) Setting the FVF failed, hr = %x!\n", This, hr);
4076 LeaveCriticalSection(&ddraw_cs);
4080 /* Set the vertex stream source */
4081 hr = wined3d_device_set_stream_source(This->wined3d_device, 0, vb->wineD3DVertexBuffer, 0, stride);
4084 ERR("(%p) IDirect3DDevice::SetStreamSource failed with hr = %08x\n", This, hr);
4085 LeaveCriticalSection(&ddraw_cs);
4089 /* Now draw the primitives */
4090 wined3d_device_set_primitive_type(This->wined3d_device, PrimitiveType);
4091 hr = wined3d_device_draw_primitive(This->wined3d_device, StartVertex, NumVertices);
4092 LeaveCriticalSection(&ddraw_cs);
4096 static HRESULT WINAPI
4097 IDirect3DDeviceImpl_7_DrawPrimitiveVB_FPUSetup(IDirect3DDevice7 *iface,
4098 D3DPRIMITIVETYPE PrimitiveType,
4099 IDirect3DVertexBuffer7 *D3DVertexBuf,
4104 return IDirect3DDeviceImpl_7_DrawPrimitiveVB(iface, PrimitiveType, D3DVertexBuf, StartVertex, NumVertices, Flags);
4107 static HRESULT WINAPI
4108 IDirect3DDeviceImpl_7_DrawPrimitiveVB_FPUPreserve(IDirect3DDevice7 *iface,
4109 D3DPRIMITIVETYPE PrimitiveType,
4110 IDirect3DVertexBuffer7 *D3DVertexBuf,
4118 old_fpucw = d3d_fpu_setup();
4119 hr = IDirect3DDeviceImpl_7_DrawPrimitiveVB(iface, PrimitiveType, D3DVertexBuf, StartVertex, NumVertices, Flags);
4120 set_fpu_control_word(old_fpucw);
4125 static HRESULT WINAPI IDirect3DDeviceImpl_3_DrawPrimitiveVB(IDirect3DDevice3 *iface,
4126 D3DPRIMITIVETYPE PrimitiveType, IDirect3DVertexBuffer *D3DVertexBuf, DWORD StartVertex,
4127 DWORD NumVertices, DWORD Flags)
4129 IDirect3DVertexBufferImpl *vb = unsafe_impl_from_IDirect3DVertexBuffer(D3DVertexBuf);
4131 TRACE("iface %p, primitive_type %#x, vb %p, start_vertex %u, vertex_count %u, flags %#x.\n",
4132 iface, PrimitiveType, D3DVertexBuf, StartVertex, NumVertices, Flags);
4134 return IDirect3DDevice7_DrawPrimitiveVB((IDirect3DDevice7 *)device_from_device3(iface),
4135 PrimitiveType, &vb->IDirect3DVertexBuffer7_iface, StartVertex, NumVertices, Flags);
4139 /*****************************************************************************
4140 * IDirect3DDevice7::DrawIndexedPrimitiveVB
4142 * Draws primitives from a vertex buffer to the screen
4145 * PrimitiveType: Type of primitive to be rendered.
4146 * D3DVertexBuf: Source Vertex Buffer
4147 * StartVertex: Index of the first vertex from the buffer to be rendered
4148 * NumVertices: Number of vertices to be rendered
4149 * Indices: Array of DWORDs used to index into the Vertices
4150 * IndexCount: Number of indices in Indices
4151 * Flags: Can be D3DDP_WAIT to wait until rendering has finished
4155 *****************************************************************************/
4157 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface,
4158 D3DPRIMITIVETYPE PrimitiveType,
4159 IDirect3DVertexBuffer7 *D3DVertexBuf,
4166 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
4167 IDirect3DVertexBufferImpl *vb = unsafe_impl_from_IDirect3DVertexBuffer7(D3DVertexBuf);
4168 DWORD stride = get_flexible_vertex_size(vb->fvf);
4169 struct wined3d_resource *wined3d_resource;
4170 struct wined3d_resource_desc desc;
4171 WORD *LockedIndices;
4174 TRACE("iface %p, primitive_type %#x, vb %p, start_vertex %u, vertex_count %u, indices %p, index_count %u, flags %#x.\n",
4175 iface, PrimitiveType, D3DVertexBuf, StartVertex, NumVertices, Indices, IndexCount, Flags);
4178 * 1) Upload the Indices to the index buffer
4179 * 2) Set the index source
4180 * 3) Set the Vertex Buffer as the Stream source
4181 * 4) Call IWineD3DDevice::DrawIndexedPrimitive
4184 EnterCriticalSection(&ddraw_cs);
4186 hr = wined3d_device_set_vertex_declaration(This->wined3d_device, vb->wineD3DVertexDeclaration);
4189 ERR(" (%p) Setting the FVF failed, hr = %x!\n", This, hr);
4190 LeaveCriticalSection(&ddraw_cs);
4194 /* check that the buffer is large enough to hold the indices,
4195 * reallocate if necessary. */
4196 wined3d_resource = wined3d_buffer_get_resource(This->indexbuffer);
4197 wined3d_resource_get_desc(wined3d_resource, &desc);
4198 if (desc.size < IndexCount * sizeof(WORD))
4200 UINT size = max(desc.size * 2, IndexCount * sizeof(WORD));
4201 struct wined3d_buffer *buffer;
4203 TRACE("Growing index buffer to %u bytes\n", size);
4205 hr = wined3d_buffer_create_ib(This->wined3d_device, size, WINED3DUSAGE_DYNAMIC /* Usage */,
4206 WINED3DPOOL_DEFAULT, NULL, &ddraw_null_wined3d_parent_ops, &buffer);
4209 ERR("(%p) IWineD3DDevice::CreateIndexBuffer failed with hr = %08x\n", This, hr);
4210 LeaveCriticalSection(&ddraw_cs);
4214 wined3d_buffer_decref(This->indexbuffer);
4215 This->indexbuffer = buffer;
4218 /* Copy the index stream into the index buffer. A new IWineD3DDevice
4219 * method could be created which takes an user pointer containing the
4220 * indices or a SetData-Method for the index buffer, which overrides the
4221 * index buffer data with our pointer. */
4222 hr = wined3d_buffer_map(This->indexbuffer, 0, IndexCount * sizeof(WORD),
4223 (BYTE **)&LockedIndices, 0);
4226 ERR("Failed to map buffer, hr %#x.\n", hr);
4227 LeaveCriticalSection(&ddraw_cs);
4230 memcpy(LockedIndices, Indices, IndexCount * sizeof(WORD));
4231 wined3d_buffer_unmap(This->indexbuffer);
4233 /* Set the index stream */
4234 wined3d_device_set_base_vertex_index(This->wined3d_device, StartVertex);
4235 hr = wined3d_device_set_index_buffer(This->wined3d_device, This->indexbuffer, WINED3DFMT_R16_UINT);
4237 /* Set the vertex stream source */
4238 hr = wined3d_device_set_stream_source(This->wined3d_device, 0, vb->wineD3DVertexBuffer, 0, stride);
4241 ERR("(%p) IDirect3DDevice::SetStreamSource failed with hr = %08x\n", This, hr);
4242 LeaveCriticalSection(&ddraw_cs);
4247 wined3d_device_set_primitive_type(This->wined3d_device, PrimitiveType);
4248 hr = wined3d_device_draw_indexed_primitive(This->wined3d_device, 0, IndexCount);
4250 LeaveCriticalSection(&ddraw_cs);
4254 static HRESULT WINAPI
4255 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB_FPUSetup(IDirect3DDevice7 *iface,
4256 D3DPRIMITIVETYPE PrimitiveType,
4257 IDirect3DVertexBuffer7 *D3DVertexBuf,
4264 return IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB(iface, PrimitiveType, D3DVertexBuf, StartVertex, NumVertices, Indices, IndexCount, Flags);
4267 static HRESULT WINAPI
4268 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB_FPUPreserve(IDirect3DDevice7 *iface,
4269 D3DPRIMITIVETYPE PrimitiveType,
4270 IDirect3DVertexBuffer7 *D3DVertexBuf,
4280 old_fpucw = d3d_fpu_setup();
4281 hr = IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB(iface, PrimitiveType, D3DVertexBuf, StartVertex, NumVertices, Indices, IndexCount, Flags);
4282 set_fpu_control_word(old_fpucw);
4287 static HRESULT WINAPI IDirect3DDeviceImpl_3_DrawIndexedPrimitiveVB(IDirect3DDevice3 *iface,
4288 D3DPRIMITIVETYPE PrimitiveType, IDirect3DVertexBuffer *D3DVertexBuf, WORD *Indices,
4289 DWORD IndexCount, DWORD Flags)
4291 IDirect3DVertexBufferImpl *vb = unsafe_impl_from_IDirect3DVertexBuffer(D3DVertexBuf);
4293 TRACE("iface %p, primitive_type %#x, vb %p, indices %p, index_count %u, flags %#x.\n",
4294 iface, PrimitiveType, D3DVertexBuf, Indices, IndexCount, Flags);
4296 return IDirect3DDevice7_DrawIndexedPrimitiveVB((IDirect3DDevice7 *)device_from_device3(iface),
4297 PrimitiveType, &vb->IDirect3DVertexBuffer7_iface, 0, IndexCount, Indices, IndexCount,
4301 /*****************************************************************************
4302 * IDirect3DDevice7::ComputeSphereVisibility
4304 * Calculates the visibility of spheres in the current viewport. The spheres
4305 * are passed in the Centers and Radii arrays, the results are passed back
4306 * in the ReturnValues array. Return values are either completely visible,
4307 * partially visible or completely invisible.
4308 * The return value consist of a combination of D3DCLIP_* flags, or it's
4309 * 0 if the sphere is completely visible(according to the SDK, not checked)
4314 * Centers: Array containing the sphere centers
4315 * Radii: Array containing the sphere radii
4316 * NumSpheres: The number of centers and radii in the arrays
4318 * ReturnValues: Array to write the results to
4322 * (DDERR_INVALIDPARAMS if Centers, Radii or ReturnValues are NULL)
4323 * (D3DERR_INVALIDMATRIX if the combined world, view and proj matrix
4326 *****************************************************************************/
4328 static DWORD in_plane(UINT plane, D3DVECTOR normal, D3DVALUE origin_plane, D3DVECTOR center, D3DVALUE radius)
4330 float distance, norm;
4332 norm = sqrt( normal.u1.x * normal.u1.x + normal.u2.y * normal.u2.y + normal.u3.z * normal.u3.z );
4333 distance = ( origin_plane + normal.u1.x * center.u1.x + normal.u2.y * center.u2.y + normal.u3.z * center.u3.z ) / norm;
4335 if ( fabs( distance ) < radius ) return D3DSTATUS_CLIPUNIONLEFT << plane;
4336 if ( distance < -radius ) return (D3DSTATUS_CLIPUNIONLEFT | D3DSTATUS_CLIPINTERSECTIONLEFT) << plane;
4340 static HRESULT WINAPI
4341 IDirect3DDeviceImpl_7_ComputeSphereVisibility(IDirect3DDevice7 *iface,
4346 DWORD *ReturnValues)
4349 D3DVALUE origin_plane[6];
4354 TRACE("iface %p, centers %p, radii %p, sphere_count %u, flags %#x, return_values %p.\n",
4355 iface, Centers, Radii, NumSpheres, Flags, ReturnValues);
4357 hr = IDirect3DDeviceImpl_7_GetTransform(iface, D3DTRANSFORMSTATE_WORLD, &m);
4358 if ( hr != DD_OK ) return DDERR_INVALIDPARAMS;
4359 hr = IDirect3DDeviceImpl_7_GetTransform(iface, D3DTRANSFORMSTATE_VIEW, &temp);
4360 if ( hr != DD_OK ) return DDERR_INVALIDPARAMS;
4361 multiply_matrix(&m, &temp, &m);
4363 hr = IDirect3DDeviceImpl_7_GetTransform(iface, D3DTRANSFORMSTATE_PROJECTION, &temp);
4364 if ( hr != DD_OK ) return DDERR_INVALIDPARAMS;
4365 multiply_matrix(&m, &temp, &m);
4368 vec[0].u1.x = m._14 + m._11;
4369 vec[0].u2.y = m._24 + m._21;
4370 vec[0].u3.z = m._34 + m._31;
4371 origin_plane[0] = m._44 + m._41;
4374 vec[1].u1.x = m._14 - m._11;
4375 vec[1].u2.y = m._24 - m._21;
4376 vec[1].u3.z = m._34 - m._31;
4377 origin_plane[1] = m._44 - m._41;
4380 vec[2].u1.x = m._14 - m._12;
4381 vec[2].u2.y = m._24 - m._22;
4382 vec[2].u3.z = m._34 - m._32;
4383 origin_plane[2] = m._44 - m._42;
4386 vec[3].u1.x = m._14 + m._12;
4387 vec[3].u2.y = m._24 + m._22;
4388 vec[3].u3.z = m._34 + m._32;
4389 origin_plane[3] = m._44 + m._42;
4392 vec[4].u1.x = m._13;
4393 vec[4].u2.y = m._23;
4394 vec[4].u3.z = m._33;
4395 origin_plane[4] = m._43;
4398 vec[5].u1.x = m._14 - m._13;
4399 vec[5].u2.y = m._24 - m._23;
4400 vec[5].u3.z = m._34 - m._33;
4401 origin_plane[5] = m._44 - m._43;
4403 for(i=0; i<NumSpheres; i++)
4405 ReturnValues[i] = 0;
4406 for(j=0; j<6; j++) ReturnValues[i] |= in_plane(j, vec[j], origin_plane[j], Centers[i], Radii[i]);
4412 static HRESULT WINAPI IDirect3DDeviceImpl_3_ComputeSphereVisibility(IDirect3DDevice3 *iface,
4413 D3DVECTOR *Centers, D3DVALUE *Radii, DWORD NumSpheres, DWORD Flags, DWORD *ReturnValues)
4415 TRACE("iface %p, centers %p, radii %p, sphere_count %u, flags %#x, return_values %p.\n",
4416 iface, Centers, Radii, NumSpheres, Flags, ReturnValues);
4418 return IDirect3DDevice7_ComputeSphereVisibility((IDirect3DDevice7 *)device_from_device3(iface),
4419 Centers, Radii, NumSpheres, Flags, ReturnValues);
4422 /*****************************************************************************
4423 * IDirect3DDevice7::GetTexture
4425 * Returns the texture interface handle assigned to a texture stage.
4426 * The returned texture is AddRefed. This is taken from old ddraw,
4427 * not checked in Windows.
4432 * Stage: Texture stage to read the texture from
4433 * Texture: Address to store the interface pointer at
4437 * DDERR_INVALIDPARAMS if Texture is NULL
4438 * For details, see IWineD3DDevice::GetTexture
4440 *****************************************************************************/
4442 IDirect3DDeviceImpl_7_GetTexture(IDirect3DDevice7 *iface,
4444 IDirectDrawSurface7 **Texture)
4446 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
4447 struct wined3d_texture *wined3d_texture;
4450 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, Texture);
4454 TRACE("Texture == NULL, failing with DDERR_INVALIDPARAMS\n");
4455 return DDERR_INVALIDPARAMS;
4458 EnterCriticalSection(&ddraw_cs);
4459 hr = wined3d_device_get_texture(This->wined3d_device, Stage, &wined3d_texture);
4460 if (FAILED(hr) || !wined3d_texture)
4463 LeaveCriticalSection(&ddraw_cs);
4467 *Texture = wined3d_texture_get_parent(wined3d_texture);
4468 IDirectDrawSurface7_AddRef(*Texture);
4469 LeaveCriticalSection(&ddraw_cs);
4473 static HRESULT WINAPI
4474 IDirect3DDeviceImpl_7_GetTexture_FPUSetup(IDirect3DDevice7 *iface,
4476 IDirectDrawSurface7 **Texture)
4478 return IDirect3DDeviceImpl_7_GetTexture(iface, Stage, Texture);
4481 static HRESULT WINAPI
4482 IDirect3DDeviceImpl_7_GetTexture_FPUPreserve(IDirect3DDevice7 *iface,
4484 IDirectDrawSurface7 **Texture)
4489 old_fpucw = d3d_fpu_setup();
4490 hr = IDirect3DDeviceImpl_7_GetTexture(iface, Stage, Texture);
4491 set_fpu_control_word(old_fpucw);
4496 static HRESULT WINAPI IDirect3DDeviceImpl_3_GetTexture(IDirect3DDevice3 *iface, DWORD Stage,
4497 IDirect3DTexture2 **Texture2)
4500 IDirectDrawSurface7 *ret_val;
4501 IDirectDrawSurfaceImpl *ret_val_impl;
4503 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, Texture2);
4505 ret = IDirect3DDevice7_GetTexture((IDirect3DDevice7 *)device_from_device3(iface), Stage, &ret_val);
4507 ret_val_impl = unsafe_impl_from_IDirectDrawSurface7(ret_val);
4508 *Texture2 = ret_val_impl ? (IDirect3DTexture2 *)&ret_val_impl->IDirect3DTexture2_vtbl : NULL;
4510 TRACE("Returning texture %p.\n", *Texture2);
4515 /*****************************************************************************
4516 * IDirect3DDevice7::SetTexture
4518 * Assigns a texture to a texture stage. Is the texture AddRef-ed?
4523 * Stage: The stage to assign the texture to
4524 * Texture: Interface pointer to the texture surface
4528 * For details, see IWineD3DDevice::SetTexture
4530 *****************************************************************************/
4532 IDirect3DDeviceImpl_7_SetTexture(IDirect3DDevice7 *iface,
4534 IDirectDrawSurface7 *Texture)
4536 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
4537 IDirectDrawSurfaceImpl *surf = unsafe_impl_from_IDirectDrawSurface7(Texture);
4540 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, Texture);
4542 /* Texture may be NULL here */
4543 EnterCriticalSection(&ddraw_cs);
4544 hr = wined3d_device_set_texture(This->wined3d_device,
4545 Stage, surf ? surf->wined3d_texture : NULL);
4546 LeaveCriticalSection(&ddraw_cs);
4550 static HRESULT WINAPI
4551 IDirect3DDeviceImpl_7_SetTexture_FPUSetup(IDirect3DDevice7 *iface,
4553 IDirectDrawSurface7 *Texture)
4555 return IDirect3DDeviceImpl_7_SetTexture(iface, Stage, Texture);
4558 static HRESULT WINAPI
4559 IDirect3DDeviceImpl_7_SetTexture_FPUPreserve(IDirect3DDevice7 *iface,
4561 IDirectDrawSurface7 *Texture)
4566 old_fpucw = d3d_fpu_setup();
4567 hr = IDirect3DDeviceImpl_7_SetTexture(iface, Stage, Texture);
4568 set_fpu_control_word(old_fpucw);
4573 static HRESULT WINAPI
4574 IDirect3DDeviceImpl_3_SetTexture(IDirect3DDevice3 *iface,
4576 IDirect3DTexture2 *Texture2)
4578 IDirect3DDeviceImpl *This = device_from_device3(iface);
4579 IDirectDrawSurfaceImpl *tex = Texture2 ? surface_from_texture2(Texture2) : NULL;
4583 TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, Texture2);
4585 EnterCriticalSection(&ddraw_cs);
4587 if (This->legacyTextureBlending)
4588 IDirect3DDevice3_GetRenderState(iface, D3DRENDERSTATE_TEXTUREMAPBLEND, &texmapblend);
4590 hr = IDirect3DDevice7_SetTexture((IDirect3DDevice7 *)This, Stage, &tex->IDirectDrawSurface7_iface);
4592 if (This->legacyTextureBlending && texmapblend == D3DTBLEND_MODULATE)
4594 /* This fixup is required by the way D3DTBLEND_MODULATE maps to texture stage states.
4595 See IDirect3DDeviceImpl_3_SetRenderState for details. */
4596 struct wined3d_texture *tex = NULL;
4597 BOOL tex_alpha = FALSE;
4598 DDPIXELFORMAT ddfmt;
4601 result = wined3d_device_get_texture(This->wined3d_device, 0, &tex);
4602 if (result == WINED3D_OK && tex)
4604 struct wined3d_resource *sub_resource;
4606 if ((sub_resource = wined3d_texture_get_sub_resource(tex, 0)))
4608 struct wined3d_resource_desc desc;
4610 wined3d_resource_get_desc(sub_resource, &desc);
4611 ddfmt.dwSize = sizeof(ddfmt);
4612 PixelFormat_WineD3DtoDD(&ddfmt, desc.format);
4613 if (ddfmt.u5.dwRGBAlphaBitMask) tex_alpha = TRUE;
4616 wined3d_texture_decref(tex);
4619 /* Arg 1/2 are already set to WINED3DTA_TEXTURE/WINED3DTA_CURRENT in case of D3DTBLEND_MODULATE */
4621 wined3d_device_set_texture_stage_state(This->wined3d_device, 0, WINED3DTSS_ALPHAOP, WINED3DTOP_SELECTARG1);
4623 wined3d_device_set_texture_stage_state(This->wined3d_device, 0, WINED3DTSS_ALPHAOP, WINED3DTOP_SELECTARG2);
4626 LeaveCriticalSection(&ddraw_cs);
4631 static const struct tss_lookup
4638 {FALSE, WINED3DTSS_FORCE_DWORD}, /* 0, unused */
4639 {FALSE, WINED3DTSS_COLOROP}, /* 1, D3DTSS_COLOROP */
4640 {FALSE, WINED3DTSS_COLORARG1}, /* 2, D3DTSS_COLORARG1 */
4641 {FALSE, WINED3DTSS_COLORARG2}, /* 3, D3DTSS_COLORARG2 */
4642 {FALSE, WINED3DTSS_ALPHAOP}, /* 4, D3DTSS_ALPHAOP */
4643 {FALSE, WINED3DTSS_ALPHAARG1}, /* 5, D3DTSS_ALPHAARG1 */
4644 {FALSE, WINED3DTSS_ALPHAARG2}, /* 6, D3DTSS_ALPHAARG2 */
4645 {FALSE, WINED3DTSS_BUMPENVMAT00}, /* 7, D3DTSS_BUMPENVMAT00 */
4646 {FALSE, WINED3DTSS_BUMPENVMAT01}, /* 8, D3DTSS_BUMPENVMAT01 */
4647 {FALSE, WINED3DTSS_BUMPENVMAT10}, /* 9, D3DTSS_BUMPENVMAT10 */
4648 {FALSE, WINED3DTSS_BUMPENVMAT11}, /* 10, D3DTSS_BUMPENVMAT11 */
4649 {FALSE, WINED3DTSS_TEXCOORDINDEX}, /* 11, D3DTSS_TEXCOORDINDEX */
4650 {TRUE, WINED3DSAMP_ADDRESSU}, /* 12, D3DTSS_ADDRESS */
4651 {TRUE, WINED3DSAMP_ADDRESSU}, /* 13, D3DTSS_ADDRESSU */
4652 {TRUE, WINED3DSAMP_ADDRESSV}, /* 14, D3DTSS_ADDRESSV */
4653 {TRUE, WINED3DSAMP_BORDERCOLOR}, /* 15, D3DTSS_BORDERCOLOR */
4654 {TRUE, WINED3DSAMP_MAGFILTER}, /* 16, D3DTSS_MAGFILTER */
4655 {TRUE, WINED3DSAMP_MINFILTER}, /* 17, D3DTSS_MINFILTER */
4656 {TRUE, WINED3DSAMP_MIPFILTER}, /* 18, D3DTSS_MIPFILTER */
4657 {TRUE, WINED3DSAMP_MIPMAPLODBIAS}, /* 19, D3DTSS_MIPMAPLODBIAS */
4658 {TRUE, WINED3DSAMP_MAXMIPLEVEL}, /* 20, D3DTSS_MAXMIPLEVEL */
4659 {TRUE, WINED3DSAMP_MAXANISOTROPY}, /* 21, D3DTSS_MAXANISOTROPY */
4660 {FALSE, WINED3DTSS_BUMPENVLSCALE}, /* 22, D3DTSS_BUMPENVLSCALE */
4661 {FALSE, WINED3DTSS_BUMPENVLOFFSET}, /* 23, D3DTSS_BUMPENVLOFFSET */
4662 {FALSE, WINED3DTSS_TEXTURETRANSFORMFLAGS}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
4665 /*****************************************************************************
4666 * IDirect3DDevice7::GetTextureStageState
4668 * Retrieves a state from a texture stage.
4673 * Stage: The stage to retrieve the state from
4674 * TexStageStateType: The state type to retrieve
4675 * State: Address to store the state's value at
4679 * DDERR_INVALIDPARAMS if State is NULL
4680 * For details, see IWineD3DDevice::GetTextureStageState
4682 *****************************************************************************/
4684 IDirect3DDeviceImpl_7_GetTextureStageState(IDirect3DDevice7 *iface,
4686 D3DTEXTURESTAGESTATETYPE TexStageStateType,
4689 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
4691 const struct tss_lookup *l;
4693 TRACE("iface %p, stage %u, state %#x, value %p.\n",
4694 iface, Stage, TexStageStateType, State);
4697 return DDERR_INVALIDPARAMS;
4699 if (TexStageStateType > D3DTSS_TEXTURETRANSFORMFLAGS)
4701 WARN("Invalid TexStageStateType %#x passed.\n", TexStageStateType);
4705 l = &tss_lookup[TexStageStateType];
4707 EnterCriticalSection(&ddraw_cs);
4709 if (l->sampler_state)
4711 hr = wined3d_device_get_sampler_state(This->wined3d_device, Stage, l->state, State);
4713 switch(TexStageStateType)
4715 /* Mipfilter is a sampler state with different values */
4716 case D3DTSS_MIPFILTER:
4720 case WINED3DTEXF_NONE: *State = D3DTFP_NONE; break;
4721 case WINED3DTEXF_POINT: *State = D3DTFP_POINT; break;
4722 case WINED3DTEXF_LINEAR: *State = D3DTFP_LINEAR; break;
4724 ERR("Unexpected mipfilter value %#x\n", *State);
4725 *State = D3DTFP_NONE;
4731 /* Magfilter has slightly different values */
4732 case D3DTSS_MAGFILTER:
4736 case WINED3DTEXF_POINT: *State = D3DTFG_POINT; break;
4737 case WINED3DTEXF_LINEAR: *State = D3DTFG_LINEAR; break;
4738 case WINED3DTEXF_ANISOTROPIC: *State = D3DTFG_ANISOTROPIC; break;
4739 case WINED3DTEXF_FLATCUBIC: *State = D3DTFG_FLATCUBIC; break;
4740 case WINED3DTEXF_GAUSSIANCUBIC: *State = D3DTFG_GAUSSIANCUBIC; break;
4742 ERR("Unexpected wined3d mag filter value %#x\n", *State);
4743 *State = D3DTFG_POINT;
4755 hr = wined3d_device_get_texture_stage_state(This->wined3d_device, Stage, l->state, State);
4758 LeaveCriticalSection(&ddraw_cs);
4762 static HRESULT WINAPI
4763 IDirect3DDeviceImpl_7_GetTextureStageState_FPUSetup(IDirect3DDevice7 *iface,
4765 D3DTEXTURESTAGESTATETYPE TexStageStateType,
4768 return IDirect3DDeviceImpl_7_GetTextureStageState(iface, Stage, TexStageStateType, State);
4771 static HRESULT WINAPI
4772 IDirect3DDeviceImpl_7_GetTextureStageState_FPUPreserve(IDirect3DDevice7 *iface,
4774 D3DTEXTURESTAGESTATETYPE TexStageStateType,
4780 old_fpucw = d3d_fpu_setup();
4781 hr = IDirect3DDeviceImpl_7_GetTextureStageState(iface, Stage, TexStageStateType, State);
4782 set_fpu_control_word(old_fpucw);
4787 static HRESULT WINAPI IDirect3DDeviceImpl_3_GetTextureStageState(IDirect3DDevice3 *iface,
4788 DWORD Stage, D3DTEXTURESTAGESTATETYPE TexStageStateType, DWORD *State)
4790 TRACE("iface %p, stage %u, state %#x, value %p.\n",
4791 iface, Stage, TexStageStateType, State);
4793 return IDirect3DDevice7_GetTextureStageState((IDirect3DDevice7 *)device_from_device3(iface),
4794 Stage, TexStageStateType, State);
4797 /*****************************************************************************
4798 * IDirect3DDevice7::SetTextureStageState
4800 * Sets a texture stage state. Some stage types need to be handled specially,
4801 * because they do not exist in WineD3D and were moved to another place
4806 * Stage: The stage to modify
4807 * TexStageStateType: The state to change
4808 * State: The new value for the state
4812 * For details, see IWineD3DDevice::SetTextureStageState
4814 *****************************************************************************/
4816 IDirect3DDeviceImpl_7_SetTextureStageState(IDirect3DDevice7 *iface,
4818 D3DTEXTURESTAGESTATETYPE TexStageStateType,
4821 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
4822 const struct tss_lookup *l;
4825 TRACE("iface %p, stage %u, state %#x, value %#x.\n",
4826 iface, Stage, TexStageStateType, State);
4828 if (TexStageStateType > D3DTSS_TEXTURETRANSFORMFLAGS)
4830 WARN("Invalid TexStageStateType %#x passed.\n", TexStageStateType);
4834 l = &tss_lookup[TexStageStateType];
4836 EnterCriticalSection(&ddraw_cs);
4838 if (l->sampler_state)
4840 switch(TexStageStateType)
4842 /* Mipfilter is a sampler state with different values */
4843 case D3DTSS_MIPFILTER:
4847 case D3DTFP_NONE: State = WINED3DTEXF_NONE; break;
4848 case D3DTFP_POINT: State = WINED3DTEXF_POINT; break;
4849 case 0: /* Unchecked */
4850 case D3DTFP_LINEAR: State = WINED3DTEXF_LINEAR; break;
4852 ERR("Unexpected mipfilter value %d\n", State);
4853 State = WINED3DTEXF_NONE;
4859 /* Magfilter has slightly different values */
4860 case D3DTSS_MAGFILTER:
4864 case D3DTFG_POINT: State = WINED3DTEXF_POINT; break;
4865 case D3DTFG_LINEAR: State = WINED3DTEXF_LINEAR; break;
4866 case D3DTFG_FLATCUBIC: State = WINED3DTEXF_FLATCUBIC; break;
4867 case D3DTFG_GAUSSIANCUBIC: State = WINED3DTEXF_GAUSSIANCUBIC; break;
4868 case D3DTFG_ANISOTROPIC: State = WINED3DTEXF_ANISOTROPIC; break;
4870 ERR("Unexpected d3d7 mag filter type %d\n", State);
4871 State = WINED3DTEXF_POINT;
4877 case D3DTSS_ADDRESS:
4878 wined3d_device_set_sampler_state(This->wined3d_device, Stage, WINED3DSAMP_ADDRESSV, State);
4885 hr = wined3d_device_set_sampler_state(This->wined3d_device, Stage, l->state, State);
4889 hr = wined3d_device_set_texture_stage_state(This->wined3d_device, Stage, l->state, State);
4892 LeaveCriticalSection(&ddraw_cs);
4896 static HRESULT WINAPI
4897 IDirect3DDeviceImpl_7_SetTextureStageState_FPUSetup(IDirect3DDevice7 *iface,
4899 D3DTEXTURESTAGESTATETYPE TexStageStateType,
4902 return IDirect3DDeviceImpl_7_SetTextureStageState(iface, Stage, TexStageStateType, State);
4905 static HRESULT WINAPI
4906 IDirect3DDeviceImpl_7_SetTextureStageState_FPUPreserve(IDirect3DDevice7 *iface,
4908 D3DTEXTURESTAGESTATETYPE TexStageStateType,
4914 old_fpucw = d3d_fpu_setup();
4915 hr = IDirect3DDeviceImpl_7_SetTextureStageState(iface, Stage, TexStageStateType, State);
4916 set_fpu_control_word(old_fpucw);
4921 static HRESULT WINAPI IDirect3DDeviceImpl_3_SetTextureStageState(IDirect3DDevice3 *iface,
4922 DWORD Stage, D3DTEXTURESTAGESTATETYPE TexStageStateType, DWORD State)
4924 TRACE("iface %p, stage %u, state %#x, value %#x.\n",
4925 iface, Stage, TexStageStateType, State);
4927 return IDirect3DDevice7_SetTextureStageState((IDirect3DDevice7 *)device_from_device3(iface),
4928 Stage, TexStageStateType, State);
4931 /*****************************************************************************
4932 * IDirect3DDevice7::ValidateDevice
4934 * SDK: "Reports the device's ability to render the currently set
4935 * texture-blending operations in a single pass". Whatever that means
4941 * NumPasses: Address to write the number of necessary passes for the
4942 * desired effect to.
4946 * See IWineD3DDevice::ValidateDevice for more details
4948 *****************************************************************************/
4950 IDirect3DDeviceImpl_7_ValidateDevice(IDirect3DDevice7 *iface,
4953 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
4956 TRACE("iface %p, pass_count %p.\n", iface, NumPasses);
4958 EnterCriticalSection(&ddraw_cs);
4959 hr = wined3d_device_validate_device(This->wined3d_device, NumPasses);
4960 LeaveCriticalSection(&ddraw_cs);
4964 static HRESULT WINAPI
4965 IDirect3DDeviceImpl_7_ValidateDevice_FPUSetup(IDirect3DDevice7 *iface,
4968 return IDirect3DDeviceImpl_7_ValidateDevice(iface, NumPasses);
4971 static HRESULT WINAPI
4972 IDirect3DDeviceImpl_7_ValidateDevice_FPUPreserve(IDirect3DDevice7 *iface,
4978 old_fpucw = d3d_fpu_setup();
4979 hr = IDirect3DDeviceImpl_7_ValidateDevice(iface, NumPasses);
4980 set_fpu_control_word(old_fpucw);
4985 static HRESULT WINAPI IDirect3DDeviceImpl_3_ValidateDevice(IDirect3DDevice3 *iface, DWORD *Passes)
4987 TRACE("iface %p, pass_count %p.\n", iface, Passes);
4989 return IDirect3DDevice7_ValidateDevice((IDirect3DDevice7 *)device_from_device3(iface), Passes);
4992 /*****************************************************************************
4993 * IDirect3DDevice7::Clear
4995 * Fills the render target, the z buffer and the stencil buffer with a
4996 * clear color / value
5001 * Count: Number of rectangles in Rects must be 0 if Rects is NULL
5002 * Rects: Rectangles to clear. If NULL, the whole surface is cleared
5003 * Flags: Some flags, as usual
5004 * Color: Clear color for the render target
5005 * Z: Clear value for the Z buffer
5006 * Stencil: Clear value to store in each stencil buffer entry
5010 * For details, see IWineD3DDevice::Clear
5012 *****************************************************************************/
5014 IDirect3DDeviceImpl_7_Clear(IDirect3DDevice7 *iface,
5022 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
5025 TRACE("iface %p, count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %#x.\n",
5026 iface, Count, Rects, Flags, Color, Z, Stencil);
5028 EnterCriticalSection(&ddraw_cs);
5029 hr = wined3d_device_clear(This->wined3d_device, Count, (RECT *)Rects, Flags, Color, Z, Stencil);
5030 LeaveCriticalSection(&ddraw_cs);
5034 static HRESULT WINAPI
5035 IDirect3DDeviceImpl_7_Clear_FPUSetup(IDirect3DDevice7 *iface,
5043 return IDirect3DDeviceImpl_7_Clear(iface, Count, Rects, Flags, Color, Z, Stencil);
5046 static HRESULT WINAPI
5047 IDirect3DDeviceImpl_7_Clear_FPUPreserve(IDirect3DDevice7 *iface,
5058 old_fpucw = d3d_fpu_setup();
5059 hr = IDirect3DDeviceImpl_7_Clear(iface, Count, Rects, Flags, Color, Z, Stencil);
5060 set_fpu_control_word(old_fpucw);
5065 /*****************************************************************************
5066 * IDirect3DDevice7::SetViewport
5068 * Sets the current viewport.
5070 * Version 7 only, but IDirect3DViewport uses this call for older
5074 * Data: The new viewport to set
5078 * DDERR_INVALIDPARAMS if Data is NULL
5079 * For more details, see IWineDDDevice::SetViewport
5081 *****************************************************************************/
5083 IDirect3DDeviceImpl_7_SetViewport(IDirect3DDevice7 *iface,
5086 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
5089 TRACE("iface %p, viewport %p.\n", iface, Data);
5092 return DDERR_INVALIDPARAMS;
5094 /* Note: D3DVIEWPORT7 is compatible with WINED3DVIEWPORT */
5095 EnterCriticalSection(&ddraw_cs);
5096 hr = wined3d_device_set_viewport(This->wined3d_device, (WINED3DVIEWPORT *)Data);
5097 LeaveCriticalSection(&ddraw_cs);
5101 static HRESULT WINAPI
5102 IDirect3DDeviceImpl_7_SetViewport_FPUSetup(IDirect3DDevice7 *iface,
5105 return IDirect3DDeviceImpl_7_SetViewport(iface, Data);
5108 static HRESULT WINAPI
5109 IDirect3DDeviceImpl_7_SetViewport_FPUPreserve(IDirect3DDevice7 *iface,
5115 old_fpucw = d3d_fpu_setup();
5116 hr = IDirect3DDeviceImpl_7_SetViewport(iface, Data);
5117 set_fpu_control_word(old_fpucw);
5122 /*****************************************************************************
5123 * IDirect3DDevice::GetViewport
5125 * Returns the current viewport
5130 * Data: D3D7Viewport structure to write the viewport information to
5134 * DDERR_INVALIDPARAMS if Data is NULL
5135 * For more details, see IWineD3DDevice::GetViewport
5137 *****************************************************************************/
5139 IDirect3DDeviceImpl_7_GetViewport(IDirect3DDevice7 *iface,
5142 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
5145 TRACE("iface %p, viewport %p.\n", iface, Data);
5148 return DDERR_INVALIDPARAMS;
5150 /* Note: D3DVIEWPORT7 is compatible with WINED3DVIEWPORT */
5151 EnterCriticalSection(&ddraw_cs);
5152 hr = wined3d_device_get_viewport(This->wined3d_device, (WINED3DVIEWPORT *)Data);
5154 LeaveCriticalSection(&ddraw_cs);
5155 return hr_ddraw_from_wined3d(hr);
5158 static HRESULT WINAPI
5159 IDirect3DDeviceImpl_7_GetViewport_FPUSetup(IDirect3DDevice7 *iface,
5162 return IDirect3DDeviceImpl_7_GetViewport(iface, Data);
5165 static HRESULT WINAPI
5166 IDirect3DDeviceImpl_7_GetViewport_FPUPreserve(IDirect3DDevice7 *iface,
5172 old_fpucw = d3d_fpu_setup();
5173 hr = IDirect3DDeviceImpl_7_GetViewport(iface, Data);
5174 set_fpu_control_word(old_fpucw);
5179 /*****************************************************************************
5180 * IDirect3DDevice7::SetMaterial
5187 * Mat: The material to set
5191 * DDERR_INVALIDPARAMS if Mat is NULL.
5192 * For more details, see IWineD3DDevice::SetMaterial
5194 *****************************************************************************/
5196 IDirect3DDeviceImpl_7_SetMaterial(IDirect3DDevice7 *iface,
5199 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
5202 TRACE("iface %p, material %p.\n", iface, Mat);
5204 if (!Mat) return DDERR_INVALIDPARAMS;
5205 /* Note: D3DMATERIAL7 is compatible with WINED3DMATERIAL */
5206 EnterCriticalSection(&ddraw_cs);
5207 hr = wined3d_device_set_material(This->wined3d_device, (WINED3DMATERIAL *)Mat);
5208 LeaveCriticalSection(&ddraw_cs);
5209 return hr_ddraw_from_wined3d(hr);
5212 static HRESULT WINAPI
5213 IDirect3DDeviceImpl_7_SetMaterial_FPUSetup(IDirect3DDevice7 *iface,
5216 return IDirect3DDeviceImpl_7_SetMaterial(iface, Mat);
5219 static HRESULT WINAPI
5220 IDirect3DDeviceImpl_7_SetMaterial_FPUPreserve(IDirect3DDevice7 *iface,
5226 old_fpucw = d3d_fpu_setup();
5227 hr = IDirect3DDeviceImpl_7_SetMaterial(iface, Mat);
5228 set_fpu_control_word(old_fpucw);
5233 /*****************************************************************************
5234 * IDirect3DDevice7::GetMaterial
5236 * Returns the current material
5241 * Mat: D3DMATERIAL7 structure to write the material parameters to
5245 * DDERR_INVALIDPARAMS if Mat is NULL
5246 * For more details, see IWineD3DDevice::GetMaterial
5248 *****************************************************************************/
5250 IDirect3DDeviceImpl_7_GetMaterial(IDirect3DDevice7 *iface,
5253 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
5256 TRACE("iface %p, material %p.\n", iface, Mat);
5258 EnterCriticalSection(&ddraw_cs);
5259 /* Note: D3DMATERIAL7 is compatible with WINED3DMATERIAL */
5260 hr = wined3d_device_get_material(This->wined3d_device, (WINED3DMATERIAL *)Mat);
5261 LeaveCriticalSection(&ddraw_cs);
5262 return hr_ddraw_from_wined3d(hr);
5265 static HRESULT WINAPI
5266 IDirect3DDeviceImpl_7_GetMaterial_FPUSetup(IDirect3DDevice7 *iface,
5269 return IDirect3DDeviceImpl_7_GetMaterial(iface, Mat);
5272 static HRESULT WINAPI
5273 IDirect3DDeviceImpl_7_GetMaterial_FPUPreserve(IDirect3DDevice7 *iface,
5279 old_fpucw = d3d_fpu_setup();
5280 hr = IDirect3DDeviceImpl_7_GetMaterial(iface, Mat);
5281 set_fpu_control_word(old_fpucw);
5286 /*****************************************************************************
5287 * IDirect3DDevice7::SetLight
5289 * Assigns a light to a light index, but doesn't activate it yet.
5291 * Version 7, IDirect3DLight uses this method for older versions
5294 * LightIndex: The index of the new light
5295 * Light: A D3DLIGHT7 structure describing the light
5299 * For more details, see IWineD3DDevice::SetLight
5301 *****************************************************************************/
5303 IDirect3DDeviceImpl_7_SetLight(IDirect3DDevice7 *iface,
5307 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
5310 TRACE("iface %p, light_idx %u, light %p.\n", iface, LightIndex, Light);
5312 EnterCriticalSection(&ddraw_cs);
5313 /* Note: D3DLIGHT7 is compatible with WINED3DLIGHT */
5314 hr = wined3d_device_set_light(This->wined3d_device, LightIndex, (WINED3DLIGHT *)Light);
5315 LeaveCriticalSection(&ddraw_cs);
5316 return hr_ddraw_from_wined3d(hr);
5319 static HRESULT WINAPI
5320 IDirect3DDeviceImpl_7_SetLight_FPUSetup(IDirect3DDevice7 *iface,
5324 return IDirect3DDeviceImpl_7_SetLight(iface, LightIndex, Light);
5327 static HRESULT WINAPI
5328 IDirect3DDeviceImpl_7_SetLight_FPUPreserve(IDirect3DDevice7 *iface,
5335 old_fpucw = d3d_fpu_setup();
5336 hr = IDirect3DDeviceImpl_7_SetLight(iface, LightIndex, Light);
5337 set_fpu_control_word(old_fpucw);
5342 /*****************************************************************************
5343 * IDirect3DDevice7::GetLight
5345 * Returns the light assigned to a light index
5348 * Light: Structure to write the light information to
5352 * DDERR_INVALIDPARAMS if Light is NULL
5353 * For details, see IWineD3DDevice::GetLight
5355 *****************************************************************************/
5357 IDirect3DDeviceImpl_7_GetLight(IDirect3DDevice7 *iface,
5361 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
5364 TRACE("iface %p, light_idx %u, light %p.\n", iface, LightIndex, Light);
5366 EnterCriticalSection(&ddraw_cs);
5367 /* Note: D3DLIGHT7 is compatible with WINED3DLIGHT */
5368 rc = wined3d_device_get_light(This->wined3d_device, LightIndex, (WINED3DLIGHT *)Light);
5370 /* Translate the result. WineD3D returns other values than D3D7 */
5371 LeaveCriticalSection(&ddraw_cs);
5372 return hr_ddraw_from_wined3d(rc);
5375 static HRESULT WINAPI
5376 IDirect3DDeviceImpl_7_GetLight_FPUSetup(IDirect3DDevice7 *iface,
5380 return IDirect3DDeviceImpl_7_GetLight(iface, LightIndex, Light);
5383 static HRESULT WINAPI
5384 IDirect3DDeviceImpl_7_GetLight_FPUPreserve(IDirect3DDevice7 *iface,
5391 old_fpucw = d3d_fpu_setup();
5392 hr = IDirect3DDeviceImpl_7_GetLight(iface, LightIndex, Light);
5393 set_fpu_control_word(old_fpucw);
5398 /*****************************************************************************
5399 * IDirect3DDevice7::BeginStateBlock
5401 * Begins recording to a stateblock
5407 * For details see IWineD3DDevice::BeginStateBlock
5409 *****************************************************************************/
5411 IDirect3DDeviceImpl_7_BeginStateBlock(IDirect3DDevice7 *iface)
5413 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
5416 TRACE("iface %p.\n", iface);
5418 EnterCriticalSection(&ddraw_cs);
5419 hr = wined3d_device_begin_stateblock(This->wined3d_device);
5420 LeaveCriticalSection(&ddraw_cs);
5421 return hr_ddraw_from_wined3d(hr);
5424 static HRESULT WINAPI
5425 IDirect3DDeviceImpl_7_BeginStateBlock_FPUSetup(IDirect3DDevice7 *iface)
5427 return IDirect3DDeviceImpl_7_BeginStateBlock(iface);
5430 static HRESULT WINAPI
5431 IDirect3DDeviceImpl_7_BeginStateBlock_FPUPreserve(IDirect3DDevice7 *iface)
5436 old_fpucw = d3d_fpu_setup();
5437 hr = IDirect3DDeviceImpl_7_BeginStateBlock(iface);
5438 set_fpu_control_word(old_fpucw);
5443 /*****************************************************************************
5444 * IDirect3DDevice7::EndStateBlock
5446 * Stops recording to a state block and returns the created stateblock
5452 * BlockHandle: Address to store the stateblock's handle to
5456 * DDERR_INVALIDPARAMS if BlockHandle is NULL
5457 * See IWineD3DDevice::EndStateBlock for more details
5459 *****************************************************************************/
5461 IDirect3DDeviceImpl_7_EndStateBlock(IDirect3DDevice7 *iface,
5464 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
5465 struct wined3d_stateblock *wined3d_sb;
5469 TRACE("iface %p, stateblock %p.\n", iface, BlockHandle);
5473 WARN("BlockHandle == NULL, returning DDERR_INVALIDPARAMS\n");
5474 return DDERR_INVALIDPARAMS;
5477 EnterCriticalSection(&ddraw_cs);
5479 hr = wined3d_device_end_stateblock(This->wined3d_device, &wined3d_sb);
5482 WARN("Failed to end stateblock, hr %#x.\n", hr);
5483 LeaveCriticalSection(&ddraw_cs);
5485 return hr_ddraw_from_wined3d(hr);
5488 h = ddraw_allocate_handle(&This->handle_table, wined3d_sb, DDRAW_HANDLE_STATEBLOCK);
5489 if (h == DDRAW_INVALID_HANDLE)
5491 ERR("Failed to allocate a stateblock handle.\n");
5492 wined3d_stateblock_decref(wined3d_sb);
5493 LeaveCriticalSection(&ddraw_cs);
5495 return DDERR_OUTOFMEMORY;
5498 LeaveCriticalSection(&ddraw_cs);
5499 *BlockHandle = h + 1;
5501 return hr_ddraw_from_wined3d(hr);
5504 static HRESULT WINAPI
5505 IDirect3DDeviceImpl_7_EndStateBlock_FPUSetup(IDirect3DDevice7 *iface,
5508 return IDirect3DDeviceImpl_7_EndStateBlock(iface, BlockHandle);
5511 static HRESULT WINAPI
5512 IDirect3DDeviceImpl_7_EndStateBlock_FPUPreserve(IDirect3DDevice7 *iface,
5518 old_fpucw = d3d_fpu_setup();
5519 hr = IDirect3DDeviceImpl_7_EndStateBlock(iface, BlockHandle);
5520 set_fpu_control_word(old_fpucw);
5525 /*****************************************************************************
5526 * IDirect3DDevice7::PreLoad
5528 * Allows the app to signal that a texture will be used soon, to allow
5529 * the Direct3DDevice to load it to the video card in the meantime.
5534 * Texture: The texture to preload
5538 * DDERR_INVALIDPARAMS if Texture is NULL
5539 * See IWineD3DSurface::PreLoad for details
5541 *****************************************************************************/
5543 IDirect3DDeviceImpl_7_PreLoad(IDirect3DDevice7 *iface,
5544 IDirectDrawSurface7 *Texture)
5546 IDirectDrawSurfaceImpl *surf = unsafe_impl_from_IDirectDrawSurface7(Texture);
5548 TRACE("iface %p, texture %p.\n", iface, Texture);
5551 return DDERR_INVALIDPARAMS;
5553 EnterCriticalSection(&ddraw_cs);
5554 wined3d_surface_preload(surf->wined3d_surface);
5555 LeaveCriticalSection(&ddraw_cs);
5559 static HRESULT WINAPI
5560 IDirect3DDeviceImpl_7_PreLoad_FPUSetup(IDirect3DDevice7 *iface,
5561 IDirectDrawSurface7 *Texture)
5563 return IDirect3DDeviceImpl_7_PreLoad(iface, Texture);
5566 static HRESULT WINAPI
5567 IDirect3DDeviceImpl_7_PreLoad_FPUPreserve(IDirect3DDevice7 *iface,
5568 IDirectDrawSurface7 *Texture)
5573 old_fpucw = d3d_fpu_setup();
5574 hr = IDirect3DDeviceImpl_7_PreLoad(iface, Texture);
5575 set_fpu_control_word(old_fpucw);
5580 /*****************************************************************************
5581 * IDirect3DDevice7::ApplyStateBlock
5583 * Activates the state stored in a state block handle.
5586 * BlockHandle: The stateblock handle to activate
5590 * D3DERR_INVALIDSTATEBLOCK if BlockHandle is NULL
5592 *****************************************************************************/
5594 IDirect3DDeviceImpl_7_ApplyStateBlock(IDirect3DDevice7 *iface,
5597 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
5598 struct wined3d_stateblock *wined3d_sb;
5601 TRACE("iface %p, stateblock %#x.\n", iface, BlockHandle);
5603 EnterCriticalSection(&ddraw_cs);
5605 wined3d_sb = ddraw_get_object(&This->handle_table, BlockHandle - 1, DDRAW_HANDLE_STATEBLOCK);
5608 WARN("Invalid stateblock handle.\n");
5609 LeaveCriticalSection(&ddraw_cs);
5610 return D3DERR_INVALIDSTATEBLOCK;
5613 hr = wined3d_stateblock_apply(wined3d_sb);
5614 LeaveCriticalSection(&ddraw_cs);
5616 return hr_ddraw_from_wined3d(hr);
5619 static HRESULT WINAPI
5620 IDirect3DDeviceImpl_7_ApplyStateBlock_FPUSetup(IDirect3DDevice7 *iface,
5623 return IDirect3DDeviceImpl_7_ApplyStateBlock(iface, BlockHandle);
5626 static HRESULT WINAPI
5627 IDirect3DDeviceImpl_7_ApplyStateBlock_FPUPreserve(IDirect3DDevice7 *iface,
5633 old_fpucw = d3d_fpu_setup();
5634 hr = IDirect3DDeviceImpl_7_ApplyStateBlock(iface, BlockHandle);
5635 set_fpu_control_word(old_fpucw);
5640 /*****************************************************************************
5641 * IDirect3DDevice7::CaptureStateBlock
5643 * Updates a stateblock's values to the values currently set for the device
5648 * BlockHandle: Stateblock to update
5652 * D3DERR_INVALIDSTATEBLOCK if BlockHandle is NULL
5653 * See IWineD3DDevice::CaptureStateBlock for more details
5655 *****************************************************************************/
5657 IDirect3DDeviceImpl_7_CaptureStateBlock(IDirect3DDevice7 *iface,
5660 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
5661 struct wined3d_stateblock *wined3d_sb;
5664 TRACE("iface %p, stateblock %#x.\n", iface, BlockHandle);
5666 EnterCriticalSection(&ddraw_cs);
5668 wined3d_sb = ddraw_get_object(&This->handle_table, BlockHandle - 1, DDRAW_HANDLE_STATEBLOCK);
5671 WARN("Invalid stateblock handle.\n");
5672 LeaveCriticalSection(&ddraw_cs);
5673 return D3DERR_INVALIDSTATEBLOCK;
5676 hr = wined3d_stateblock_capture(wined3d_sb);
5677 LeaveCriticalSection(&ddraw_cs);
5678 return hr_ddraw_from_wined3d(hr);
5681 static HRESULT WINAPI
5682 IDirect3DDeviceImpl_7_CaptureStateBlock_FPUSetup(IDirect3DDevice7 *iface,
5685 return IDirect3DDeviceImpl_7_CaptureStateBlock(iface, BlockHandle);
5688 static HRESULT WINAPI
5689 IDirect3DDeviceImpl_7_CaptureStateBlock_FPUPreserve(IDirect3DDevice7 *iface,
5695 old_fpucw = d3d_fpu_setup();
5696 hr = IDirect3DDeviceImpl_7_CaptureStateBlock(iface, BlockHandle);
5697 set_fpu_control_word(old_fpucw);
5702 /*****************************************************************************
5703 * IDirect3DDevice7::DeleteStateBlock
5705 * Deletes a stateblock handle. This means releasing the WineD3DStateBlock
5710 * BlockHandle: Stateblock handle to delete
5714 * D3DERR_INVALIDSTATEBLOCK if BlockHandle is 0
5716 *****************************************************************************/
5718 IDirect3DDeviceImpl_7_DeleteStateBlock(IDirect3DDevice7 *iface,
5721 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
5722 struct wined3d_stateblock *wined3d_sb;
5725 TRACE("iface %p, stateblock %#x.\n", iface, BlockHandle);
5727 EnterCriticalSection(&ddraw_cs);
5729 wined3d_sb = ddraw_free_handle(&This->handle_table, BlockHandle - 1, DDRAW_HANDLE_STATEBLOCK);
5732 WARN("Invalid stateblock handle.\n");
5733 LeaveCriticalSection(&ddraw_cs);
5734 return D3DERR_INVALIDSTATEBLOCK;
5737 if ((ref = wined3d_stateblock_decref(wined3d_sb)))
5739 ERR("Something is still holding stateblock %p (refcount %u).\n", wined3d_sb, ref);
5742 LeaveCriticalSection(&ddraw_cs);
5746 static HRESULT WINAPI
5747 IDirect3DDeviceImpl_7_DeleteStateBlock_FPUSetup(IDirect3DDevice7 *iface,
5750 return IDirect3DDeviceImpl_7_DeleteStateBlock(iface, BlockHandle);
5753 static HRESULT WINAPI
5754 IDirect3DDeviceImpl_7_DeleteStateBlock_FPUPreserve(IDirect3DDevice7 *iface,
5760 old_fpucw = d3d_fpu_setup();
5761 hr = IDirect3DDeviceImpl_7_DeleteStateBlock(iface, BlockHandle);
5762 set_fpu_control_word(old_fpucw);
5767 /*****************************************************************************
5768 * IDirect3DDevice7::CreateStateBlock
5770 * Creates a new state block handle.
5775 * Type: The state block type
5776 * BlockHandle: Address to write the created handle to
5780 * DDERR_INVALIDPARAMS if BlockHandle is NULL
5782 *****************************************************************************/
5784 IDirect3DDeviceImpl_7_CreateStateBlock(IDirect3DDevice7 *iface,
5785 D3DSTATEBLOCKTYPE Type,
5788 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
5789 struct wined3d_stateblock *wined3d_sb;
5793 TRACE("iface %p, type %#x, stateblock %p.\n", iface, Type, BlockHandle);
5797 WARN("BlockHandle == NULL, returning DDERR_INVALIDPARAMS\n");
5798 return DDERR_INVALIDPARAMS;
5800 if(Type != D3DSBT_ALL && Type != D3DSBT_PIXELSTATE &&
5801 Type != D3DSBT_VERTEXSTATE ) {
5802 WARN("Unexpected stateblock type, returning DDERR_INVALIDPARAMS\n");
5803 return DDERR_INVALIDPARAMS;
5806 EnterCriticalSection(&ddraw_cs);
5808 /* The D3DSTATEBLOCKTYPE enum is fine here. */
5809 hr = wined3d_stateblock_create(This->wined3d_device, Type, &wined3d_sb);
5812 WARN("Failed to create stateblock, hr %#x.\n", hr);
5813 LeaveCriticalSection(&ddraw_cs);
5814 return hr_ddraw_from_wined3d(hr);
5817 h = ddraw_allocate_handle(&This->handle_table, wined3d_sb, DDRAW_HANDLE_STATEBLOCK);
5818 if (h == DDRAW_INVALID_HANDLE)
5820 ERR("Failed to allocate stateblock handle.\n");
5821 wined3d_stateblock_decref(wined3d_sb);
5822 LeaveCriticalSection(&ddraw_cs);
5823 return DDERR_OUTOFMEMORY;
5826 *BlockHandle = h + 1;
5827 LeaveCriticalSection(&ddraw_cs);
5829 return hr_ddraw_from_wined3d(hr);
5832 static HRESULT WINAPI
5833 IDirect3DDeviceImpl_7_CreateStateBlock_FPUSetup(IDirect3DDevice7 *iface,
5834 D3DSTATEBLOCKTYPE Type,
5837 return IDirect3DDeviceImpl_7_CreateStateBlock(iface, Type, BlockHandle);
5840 static HRESULT WINAPI
5841 IDirect3DDeviceImpl_7_CreateStateBlock_FPUPreserve(IDirect3DDevice7 *iface,
5842 D3DSTATEBLOCKTYPE Type,
5848 old_fpucw = d3d_fpu_setup();
5849 hr =IDirect3DDeviceImpl_7_CreateStateBlock(iface, Type, BlockHandle);
5850 set_fpu_control_word(old_fpucw);
5855 /* Helper function for IDirect3DDeviceImpl_7_Load. */
5856 static BOOL is_mip_level_subset(IDirectDrawSurfaceImpl *dest,
5857 IDirectDrawSurfaceImpl *src)
5859 IDirectDrawSurfaceImpl *src_level, *dest_level;
5860 IDirectDrawSurface7 *temp;
5861 DDSURFACEDESC2 ddsd;
5862 BOOL levelFound; /* at least one suitable sublevel in dest found */
5864 /* To satisfy "destination is mip level subset of source" criteria (regular texture counts as 1 level),
5865 * 1) there must be at least one mip level in destination that matched dimensions of some mip level in source and
5866 * 2) there must be no destination levels that don't match any levels in source. Otherwise it's INVALIDPARAMS.
5873 for (;src_level && dest_level;)
5875 if (src_level->surface_desc.dwWidth == dest_level->surface_desc.dwWidth &&
5876 src_level->surface_desc.dwHeight == dest_level->surface_desc.dwHeight)
5880 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
5881 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_MIPMAPSUBLEVEL;
5882 IDirectDrawSurface7_GetAttachedSurface(&dest_level->IDirectDrawSurface7_iface, &ddsd.ddsCaps, &temp);
5884 if (dest_level != dest) IDirectDrawSurface7_Release(&dest_level->IDirectDrawSurface7_iface);
5886 dest_level = unsafe_impl_from_IDirectDrawSurface7(temp);
5889 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
5890 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_MIPMAPSUBLEVEL;
5891 IDirectDrawSurface7_GetAttachedSurface(&src_level->IDirectDrawSurface7_iface, &ddsd.ddsCaps, &temp);
5893 if (src_level != src) IDirectDrawSurface7_Release(&src_level->IDirectDrawSurface7_iface);
5895 src_level = unsafe_impl_from_IDirectDrawSurface7(temp);
5898 if (src_level && src_level != src) IDirectDrawSurface7_Release(&src_level->IDirectDrawSurface7_iface);
5899 if (dest_level && dest_level != dest) IDirectDrawSurface7_Release(&dest_level->IDirectDrawSurface7_iface);
5901 return !dest_level && levelFound;
5904 /* Helper function for IDirect3DDeviceImpl_7_Load. */
5905 static void copy_mipmap_chain(IDirect3DDeviceImpl *device,
5906 IDirectDrawSurfaceImpl *dest,
5907 IDirectDrawSurfaceImpl *src,
5908 const POINT *DestPoint,
5909 const RECT *SrcRect)
5911 IDirectDrawSurfaceImpl *src_level, *dest_level;
5912 IDirectDrawSurface7 *temp;
5913 DDSURFACEDESC2 ddsd;
5917 IDirectDrawPalette *pal = NULL, *pal_src = NULL;
5920 BOOL palette_missing = FALSE;
5922 /* Copy palette, if possible. */
5923 IDirectDrawSurface7_GetPalette(&src->IDirectDrawSurface7_iface, &pal_src);
5924 IDirectDrawSurface7_GetPalette(&dest->IDirectDrawSurface7_iface, &pal);
5926 if (pal_src != NULL && pal != NULL)
5928 PALETTEENTRY palent[256];
5930 IDirectDrawPalette_GetEntries(pal_src, 0, 0, 256, palent);
5931 IDirectDrawPalette_SetEntries(pal, 0, 0, 256, palent);
5934 if (dest->surface_desc.u4.ddpfPixelFormat.dwFlags & (DDPF_PALETTEINDEXED1 | DDPF_PALETTEINDEXED2 |
5935 DDPF_PALETTEINDEXED4 | DDPF_PALETTEINDEXED8 | DDPF_PALETTEINDEXEDTO8) && !pal)
5937 palette_missing = TRUE;
5940 if (pal) IDirectDrawPalette_Release(pal);
5941 if (pal_src) IDirectDrawPalette_Release(pal_src);
5943 /* Copy colorkeys, if present. */
5944 for (ckeyflag = DDCKEY_DESTBLT; ckeyflag <= DDCKEY_SRCOVERLAY; ckeyflag <<= 1)
5946 hr = IDirectDrawSurface7_GetColorKey(&src->IDirectDrawSurface7_iface, ckeyflag, &ddckey);
5950 IDirectDrawSurface7_SetColorKey(&dest->IDirectDrawSurface7_iface, ckeyflag, &ddckey);
5960 for (;src_level && dest_level;)
5962 if (src_level->surface_desc.dwWidth == dest_level->surface_desc.dwWidth &&
5963 src_level->surface_desc.dwHeight == dest_level->surface_desc.dwHeight)
5965 /* Try UpdateSurface that may perform a more direct OpenGL
5966 * loading. But skip this if destination is paletted texture and
5967 * has no palette. Some games like Sacrifice set palette after
5968 * Load, and it is a waste of effort to try to load texture
5969 * without palette and generates warnings in wined3d. */
5970 if (!palette_missing)
5971 hr = wined3d_device_update_surface(device->wined3d_device, src_level->wined3d_surface,
5972 &rect, dest_level->wined3d_surface, &point);
5974 if (palette_missing || FAILED(hr))
5976 /* UpdateSurface may fail e.g. if dest is in system memory. Fall back to BltFast that is less strict. */
5977 wined3d_surface_bltfast(dest_level->wined3d_surface, point.x, point.y,
5978 src_level->wined3d_surface, &rect, 0);
5981 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
5982 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_MIPMAPSUBLEVEL;
5983 IDirectDrawSurface7_GetAttachedSurface(&dest_level->IDirectDrawSurface7_iface, &ddsd.ddsCaps, &temp);
5985 if (dest_level != dest) IDirectDrawSurface7_Release(&dest_level->IDirectDrawSurface7_iface);
5987 dest_level = unsafe_impl_from_IDirectDrawSurface7(temp);
5990 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
5991 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_MIPMAPSUBLEVEL;
5992 IDirectDrawSurface7_GetAttachedSurface(&src_level->IDirectDrawSurface7_iface, &ddsd.ddsCaps, &temp);
5994 if (src_level != src) IDirectDrawSurface7_Release(&src_level->IDirectDrawSurface7_iface);
5996 src_level = unsafe_impl_from_IDirectDrawSurface7(temp);
6003 rect.right = (rect.right + 1) / 2;
6004 rect.bottom = (rect.bottom + 1) / 2;
6007 if (src_level && src_level != src) IDirectDrawSurface7_Release(&src_level->IDirectDrawSurface7_iface);
6008 if (dest_level && dest_level != dest) IDirectDrawSurface7_Release(&dest_level->IDirectDrawSurface7_iface);
6011 /*****************************************************************************
6012 * IDirect3DDevice7::Load
6014 * Loads a rectangular area from the source into the destination texture.
6015 * It can also copy the source to the faces of a cubic environment map
6020 * DestTex: Destination texture
6021 * DestPoint: Point in the destination where the source image should be
6023 * SrcTex: Source texture
6024 * SrcRect: Source rectangle
6025 * Flags: Cubemap faces to load (DDSCAPS2_CUBEMAP_ALLFACES, DDSCAPS2_CUBEMAP_POSITIVEX,
6026 * DDSCAPS2_CUBEMAP_NEGATIVEX, DDSCAPS2_CUBEMAP_POSITIVEY, DDSCAPS2_CUBEMAP_NEGATIVEY,
6027 * DDSCAPS2_CUBEMAP_POSITIVEZ, DDSCAPS2_CUBEMAP_NEGATIVEZ)
6031 * DDERR_INVALIDPARAMS if DestTex or SrcTex are NULL, broken coordinates or anything unexpected.
6034 *****************************************************************************/
6037 IDirect3DDeviceImpl_7_Load(IDirect3DDevice7 *iface,
6038 IDirectDrawSurface7 *DestTex,
6040 IDirectDrawSurface7 *SrcTex,
6044 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
6045 IDirectDrawSurfaceImpl *dest = unsafe_impl_from_IDirectDrawSurface7(DestTex);
6046 IDirectDrawSurfaceImpl *src = unsafe_impl_from_IDirectDrawSurface7(SrcTex);
6050 TRACE("iface %p, dst_texture %p, dst_pos %s, src_texture %p, src_rect %s, flags %#x.\n",
6051 iface, DestTex, wine_dbgstr_point(DestPoint), SrcTex, wine_dbgstr_rect(SrcRect), Flags);
6053 if( (!src) || (!dest) )
6054 return DDERR_INVALIDPARAMS;
6056 EnterCriticalSection(&ddraw_cs);
6058 if (SrcRect) srcrect = *SrcRect;
6061 srcrect.left = srcrect.top = 0;
6062 srcrect.right = src->surface_desc.dwWidth;
6063 srcrect.bottom = src->surface_desc.dwHeight;
6066 if (DestPoint) destpoint = *DestPoint;
6069 destpoint.x = destpoint.y = 0;
6071 /* Check bad dimensions. DestPoint is validated against src, not dest, because
6072 * destination can be a subset of mip levels, in which case actual coordinates used
6073 * for it may be divided. If any dimension of dest is larger than source, it can't be
6074 * mip level subset, so an error can be returned early.
6076 if (srcrect.left >= srcrect.right || srcrect.top >= srcrect.bottom ||
6077 srcrect.right > src->surface_desc.dwWidth ||
6078 srcrect.bottom > src->surface_desc.dwHeight ||
6079 destpoint.x + srcrect.right - srcrect.left > src->surface_desc.dwWidth ||
6080 destpoint.y + srcrect.bottom - srcrect.top > src->surface_desc.dwHeight ||
6081 dest->surface_desc.dwWidth > src->surface_desc.dwWidth ||
6082 dest->surface_desc.dwHeight > src->surface_desc.dwHeight)
6084 LeaveCriticalSection(&ddraw_cs);
6085 return DDERR_INVALIDPARAMS;
6088 /* Must be top level surfaces. */
6089 if (src->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_MIPMAPSUBLEVEL ||
6090 dest->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_MIPMAPSUBLEVEL)
6092 LeaveCriticalSection(&ddraw_cs);
6093 return DDERR_INVALIDPARAMS;
6096 if (src->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_CUBEMAP)
6098 DWORD src_face_flag, dest_face_flag;
6099 IDirectDrawSurfaceImpl *src_face, *dest_face;
6100 IDirectDrawSurface7 *temp;
6101 DDSURFACEDESC2 ddsd;
6104 if (!(dest->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_CUBEMAP))
6106 LeaveCriticalSection(&ddraw_cs);
6107 return DDERR_INVALIDPARAMS;
6110 /* Iterate through cube faces 2 times. First time is just to check INVALIDPARAMS conditions, second
6111 * time it's actual surface loading. */
6112 for (i = 0; i < 2; i++)
6117 for (;dest_face && src_face;)
6119 src_face_flag = src_face->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_CUBEMAP_ALLFACES;
6120 dest_face_flag = dest_face->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_CUBEMAP_ALLFACES;
6122 if (src_face_flag == dest_face_flag)
6126 /* Destination mip levels must be subset of source mip levels. */
6127 if (!is_mip_level_subset(dest_face, src_face))
6129 LeaveCriticalSection(&ddraw_cs);
6130 return DDERR_INVALIDPARAMS;
6133 else if (Flags & dest_face_flag)
6135 copy_mipmap_chain(This, dest_face, src_face, &destpoint, &srcrect);
6138 if (src_face_flag < DDSCAPS2_CUBEMAP_NEGATIVEZ)
6140 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
6141 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP | (src_face_flag << 1);
6142 IDirectDrawSurface7_GetAttachedSurface(&src->IDirectDrawSurface7_iface, &ddsd.ddsCaps, &temp);
6144 if (src_face != src) IDirectDrawSurface7_Release(&src_face->IDirectDrawSurface7_iface);
6146 src_face = unsafe_impl_from_IDirectDrawSurface7(temp);
6150 if (src_face != src) IDirectDrawSurface7_Release(&src_face->IDirectDrawSurface7_iface);
6156 if (dest_face_flag < DDSCAPS2_CUBEMAP_NEGATIVEZ)
6158 ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
6159 ddsd.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP | (dest_face_flag << 1);
6160 IDirectDrawSurface7_GetAttachedSurface(&dest->IDirectDrawSurface7_iface, &ddsd.ddsCaps, &temp);
6162 if (dest_face != dest) IDirectDrawSurface7_Release(&dest_face->IDirectDrawSurface7_iface);
6164 dest_face = unsafe_impl_from_IDirectDrawSurface7(temp);
6168 if (dest_face != dest) IDirectDrawSurface7_Release(&dest_face->IDirectDrawSurface7_iface);
6176 /* Native returns error if src faces are not subset of dest faces. */
6179 LeaveCriticalSection(&ddraw_cs);
6180 return DDERR_INVALIDPARAMS;
6185 LeaveCriticalSection(&ddraw_cs);
6188 else if (dest->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_CUBEMAP)
6190 LeaveCriticalSection(&ddraw_cs);
6191 return DDERR_INVALIDPARAMS;
6194 /* Handle non cube map textures. */
6196 /* Destination mip levels must be subset of source mip levels. */
6197 if (!is_mip_level_subset(dest, src))
6199 LeaveCriticalSection(&ddraw_cs);
6200 return DDERR_INVALIDPARAMS;
6203 copy_mipmap_chain(This, dest, src, &destpoint, &srcrect);
6205 LeaveCriticalSection(&ddraw_cs);
6209 static HRESULT WINAPI
6210 IDirect3DDeviceImpl_7_Load_FPUSetup(IDirect3DDevice7 *iface,
6211 IDirectDrawSurface7 *DestTex,
6213 IDirectDrawSurface7 *SrcTex,
6217 return IDirect3DDeviceImpl_7_Load(iface, DestTex, DestPoint, SrcTex, SrcRect, Flags);
6220 static HRESULT WINAPI
6221 IDirect3DDeviceImpl_7_Load_FPUPreserve(IDirect3DDevice7 *iface,
6222 IDirectDrawSurface7 *DestTex,
6224 IDirectDrawSurface7 *SrcTex,
6231 old_fpucw = d3d_fpu_setup();
6232 hr = IDirect3DDeviceImpl_7_Load(iface, DestTex, DestPoint, SrcTex, SrcRect, Flags);
6233 set_fpu_control_word(old_fpucw);
6238 /*****************************************************************************
6239 * IDirect3DDevice7::LightEnable
6241 * Enables or disables a light
6243 * Version 7, IDirect3DLight uses this method too.
6246 * LightIndex: The index of the light to enable / disable
6247 * Enable: Enable or disable the light
6251 * For more details, see IWineD3DDevice::SetLightEnable
6253 *****************************************************************************/
6255 IDirect3DDeviceImpl_7_LightEnable(IDirect3DDevice7 *iface,
6259 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
6262 TRACE("iface %p, light_idx %u, enabled %#x.\n", iface, LightIndex, Enable);
6264 EnterCriticalSection(&ddraw_cs);
6265 hr = wined3d_device_set_light_enable(This->wined3d_device, LightIndex, Enable);
6266 LeaveCriticalSection(&ddraw_cs);
6267 return hr_ddraw_from_wined3d(hr);
6270 static HRESULT WINAPI
6271 IDirect3DDeviceImpl_7_LightEnable_FPUSetup(IDirect3DDevice7 *iface,
6275 return IDirect3DDeviceImpl_7_LightEnable(iface, LightIndex, Enable);
6278 static HRESULT WINAPI
6279 IDirect3DDeviceImpl_7_LightEnable_FPUPreserve(IDirect3DDevice7 *iface,
6286 old_fpucw = d3d_fpu_setup();
6287 hr = IDirect3DDeviceImpl_7_LightEnable(iface, LightIndex, Enable);
6288 set_fpu_control_word(old_fpucw);
6293 /*****************************************************************************
6294 * IDirect3DDevice7::GetLightEnable
6296 * Retrieves if the light with the given index is enabled or not
6301 * LightIndex: Index of desired light
6302 * Enable: Pointer to a BOOL which contains the result
6306 * DDERR_INVALIDPARAMS if Enable is NULL
6307 * See IWineD3DDevice::GetLightEnable for more details
6309 *****************************************************************************/
6311 IDirect3DDeviceImpl_7_GetLightEnable(IDirect3DDevice7 *iface,
6315 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
6318 TRACE("iface %p, light_idx %u, enabled %p.\n", iface, LightIndex, Enable);
6321 return DDERR_INVALIDPARAMS;
6323 EnterCriticalSection(&ddraw_cs);
6324 hr = wined3d_device_get_light_enable(This->wined3d_device, LightIndex, Enable);
6325 LeaveCriticalSection(&ddraw_cs);
6326 return hr_ddraw_from_wined3d(hr);
6329 static HRESULT WINAPI
6330 IDirect3DDeviceImpl_7_GetLightEnable_FPUSetup(IDirect3DDevice7 *iface,
6334 return IDirect3DDeviceImpl_7_GetLightEnable(iface, LightIndex, Enable);
6337 static HRESULT WINAPI
6338 IDirect3DDeviceImpl_7_GetLightEnable_FPUPreserve(IDirect3DDevice7 *iface,
6345 old_fpucw = d3d_fpu_setup();
6346 hr = IDirect3DDeviceImpl_7_GetLightEnable(iface, LightIndex, Enable);
6347 set_fpu_control_word(old_fpucw);
6352 /*****************************************************************************
6353 * IDirect3DDevice7::SetClipPlane
6355 * Sets custom clipping plane
6360 * Index: The index of the clipping plane
6361 * PlaneEquation: An equation defining the clipping plane
6365 * DDERR_INVALIDPARAMS if PlaneEquation is NULL
6366 * See IWineD3DDevice::SetClipPlane for more details
6368 *****************************************************************************/
6370 IDirect3DDeviceImpl_7_SetClipPlane(IDirect3DDevice7 *iface,
6372 D3DVALUE* PlaneEquation)
6374 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
6377 TRACE("iface %p, idx %u, plane %p.\n", iface, Index, PlaneEquation);
6380 return DDERR_INVALIDPARAMS;
6382 EnterCriticalSection(&ddraw_cs);
6383 hr = wined3d_device_set_clip_plane(This->wined3d_device, Index, PlaneEquation);
6384 LeaveCriticalSection(&ddraw_cs);
6388 static HRESULT WINAPI
6389 IDirect3DDeviceImpl_7_SetClipPlane_FPUSetup(IDirect3DDevice7 *iface,
6391 D3DVALUE* PlaneEquation)
6393 return IDirect3DDeviceImpl_7_SetClipPlane(iface, Index, PlaneEquation);
6396 static HRESULT WINAPI
6397 IDirect3DDeviceImpl_7_SetClipPlane_FPUPreserve(IDirect3DDevice7 *iface,
6399 D3DVALUE* PlaneEquation)
6404 old_fpucw = d3d_fpu_setup();
6405 hr = IDirect3DDeviceImpl_7_SetClipPlane(iface, Index, PlaneEquation);
6406 set_fpu_control_word(old_fpucw);
6411 /*****************************************************************************
6412 * IDirect3DDevice7::GetClipPlane
6414 * Returns the clipping plane with a specific index
6417 * Index: The index of the desired plane
6418 * PlaneEquation: Address to store the plane equation to
6422 * DDERR_INVALIDPARAMS if PlaneEquation is NULL
6423 * See IWineD3DDevice::GetClipPlane for more details
6425 *****************************************************************************/
6427 IDirect3DDeviceImpl_7_GetClipPlane(IDirect3DDevice7 *iface,
6429 D3DVALUE* PlaneEquation)
6431 IDirect3DDeviceImpl *This = (IDirect3DDeviceImpl *)iface;
6434 TRACE("iface %p, idx %u, plane %p.\n", iface, Index, PlaneEquation);
6437 return DDERR_INVALIDPARAMS;
6439 EnterCriticalSection(&ddraw_cs);
6440 hr = wined3d_device_get_clip_plane(This->wined3d_device, Index, PlaneEquation);
6441 LeaveCriticalSection(&ddraw_cs);
6445 static HRESULT WINAPI
6446 IDirect3DDeviceImpl_7_GetClipPlane_FPUSetup(IDirect3DDevice7 *iface,
6448 D3DVALUE* PlaneEquation)
6450 return IDirect3DDeviceImpl_7_GetClipPlane(iface, Index, PlaneEquation);
6453 static HRESULT WINAPI
6454 IDirect3DDeviceImpl_7_GetClipPlane_FPUPreserve(IDirect3DDevice7 *iface,
6456 D3DVALUE* PlaneEquation)
6461 old_fpucw = d3d_fpu_setup();
6462 hr = IDirect3DDeviceImpl_7_GetClipPlane(iface, Index, PlaneEquation);
6463 set_fpu_control_word(old_fpucw);
6468 /*****************************************************************************
6469 * IDirect3DDevice7::GetInfo
6471 * Retrieves some information about the device. The DirectX sdk says that
6472 * this version returns S_FALSE for all retail builds of DirectX, that's what
6473 * this implementation does.
6476 * DevInfoID: Information type requested
6477 * DevInfoStruct: Pointer to a structure to store the info to
6478 * Size: Size of the structure
6481 * S_FALSE, because it's a non-debug driver
6483 *****************************************************************************/
6484 static HRESULT WINAPI
6485 IDirect3DDeviceImpl_7_GetInfo(IDirect3DDevice7 *iface,
6487 void *DevInfoStruct,
6490 TRACE("iface %p, info_id %#x, info %p, info_size %u.\n",
6491 iface, DevInfoID, DevInfoStruct, Size);
6493 if (TRACE_ON(ddraw))
6495 TRACE(" info requested : ");
6498 case D3DDEVINFOID_TEXTUREMANAGER: TRACE("D3DDEVINFOID_TEXTUREMANAGER\n"); break;
6499 case D3DDEVINFOID_D3DTEXTUREMANAGER: TRACE("D3DDEVINFOID_D3DTEXTUREMANAGER\n"); break;
6500 case D3DDEVINFOID_TEXTURING: TRACE("D3DDEVINFOID_TEXTURING\n"); break;
6501 default: ERR(" invalid flag !!!\n"); return DDERR_INVALIDPARAMS;
6505 return S_FALSE; /* According to MSDN, this is valid for a non-debug driver */
6508 /* For performance optimization, devices created in FPUSETUP and FPUPRESERVE modes
6509 * have separate vtables. Simple functions where this doesn't matter like GetDirect3D
6510 * are not duplicated.
6512 * Device created with DDSCL_FPUSETUP (d3d7 default) - device methods assume that FPU
6513 * has already been setup for optimal d3d operation.
6515 * Device created with DDSCL_FPUPRESERVE - resets and restores FPU mode when necessary in
6516 * d3d calls (FPU may be in a mode non-suitable for d3d when the app calls d3d). Required
6517 * by Sacrifice (game). */
6518 static const struct IDirect3DDevice7Vtbl d3d_device7_fpu_setup_vtbl =
6520 /*** IUnknown Methods ***/
6521 IDirect3DDeviceImpl_7_QueryInterface,
6522 IDirect3DDeviceImpl_7_AddRef,
6523 IDirect3DDeviceImpl_7_Release,
6524 /*** IDirect3DDevice7 ***/
6525 IDirect3DDeviceImpl_7_GetCaps_FPUSetup,
6526 IDirect3DDeviceImpl_7_EnumTextureFormats_FPUSetup,
6527 IDirect3DDeviceImpl_7_BeginScene_FPUSetup,
6528 IDirect3DDeviceImpl_7_EndScene_FPUSetup,
6529 IDirect3DDeviceImpl_7_GetDirect3D,
6530 IDirect3DDeviceImpl_7_SetRenderTarget_FPUSetup,
6531 IDirect3DDeviceImpl_7_GetRenderTarget,
6532 IDirect3DDeviceImpl_7_Clear_FPUSetup,
6533 IDirect3DDeviceImpl_7_SetTransform_FPUSetup,
6534 IDirect3DDeviceImpl_7_GetTransform_FPUSetup,
6535 IDirect3DDeviceImpl_7_SetViewport_FPUSetup,
6536 IDirect3DDeviceImpl_7_MultiplyTransform_FPUSetup,
6537 IDirect3DDeviceImpl_7_GetViewport_FPUSetup,
6538 IDirect3DDeviceImpl_7_SetMaterial_FPUSetup,
6539 IDirect3DDeviceImpl_7_GetMaterial_FPUSetup,
6540 IDirect3DDeviceImpl_7_SetLight_FPUSetup,
6541 IDirect3DDeviceImpl_7_GetLight_FPUSetup,
6542 IDirect3DDeviceImpl_7_SetRenderState_FPUSetup,
6543 IDirect3DDeviceImpl_7_GetRenderState_FPUSetup,
6544 IDirect3DDeviceImpl_7_BeginStateBlock_FPUSetup,
6545 IDirect3DDeviceImpl_7_EndStateBlock_FPUSetup,
6546 IDirect3DDeviceImpl_7_PreLoad_FPUSetup,
6547 IDirect3DDeviceImpl_7_DrawPrimitive_FPUSetup,
6548 IDirect3DDeviceImpl_7_DrawIndexedPrimitive_FPUSetup,
6549 IDirect3DDeviceImpl_7_SetClipStatus,
6550 IDirect3DDeviceImpl_7_GetClipStatus,
6551 IDirect3DDeviceImpl_7_DrawPrimitiveStrided_FPUSetup,
6552 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveStrided_FPUSetup,
6553 IDirect3DDeviceImpl_7_DrawPrimitiveVB_FPUSetup,
6554 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB_FPUSetup,
6555 IDirect3DDeviceImpl_7_ComputeSphereVisibility,
6556 IDirect3DDeviceImpl_7_GetTexture_FPUSetup,
6557 IDirect3DDeviceImpl_7_SetTexture_FPUSetup,
6558 IDirect3DDeviceImpl_7_GetTextureStageState_FPUSetup,
6559 IDirect3DDeviceImpl_7_SetTextureStageState_FPUSetup,
6560 IDirect3DDeviceImpl_7_ValidateDevice_FPUSetup,
6561 IDirect3DDeviceImpl_7_ApplyStateBlock_FPUSetup,
6562 IDirect3DDeviceImpl_7_CaptureStateBlock_FPUSetup,
6563 IDirect3DDeviceImpl_7_DeleteStateBlock_FPUSetup,
6564 IDirect3DDeviceImpl_7_CreateStateBlock_FPUSetup,
6565 IDirect3DDeviceImpl_7_Load_FPUSetup,
6566 IDirect3DDeviceImpl_7_LightEnable_FPUSetup,
6567 IDirect3DDeviceImpl_7_GetLightEnable_FPUSetup,
6568 IDirect3DDeviceImpl_7_SetClipPlane_FPUSetup,
6569 IDirect3DDeviceImpl_7_GetClipPlane_FPUSetup,
6570 IDirect3DDeviceImpl_7_GetInfo
6573 static const struct IDirect3DDevice7Vtbl d3d_device7_fpu_preserve_vtbl =
6575 /*** IUnknown Methods ***/
6576 IDirect3DDeviceImpl_7_QueryInterface,
6577 IDirect3DDeviceImpl_7_AddRef,
6578 IDirect3DDeviceImpl_7_Release,
6579 /*** IDirect3DDevice7 ***/
6580 IDirect3DDeviceImpl_7_GetCaps_FPUPreserve,
6581 IDirect3DDeviceImpl_7_EnumTextureFormats_FPUPreserve,
6582 IDirect3DDeviceImpl_7_BeginScene_FPUPreserve,
6583 IDirect3DDeviceImpl_7_EndScene_FPUPreserve,
6584 IDirect3DDeviceImpl_7_GetDirect3D,
6585 IDirect3DDeviceImpl_7_SetRenderTarget_FPUPreserve,
6586 IDirect3DDeviceImpl_7_GetRenderTarget,
6587 IDirect3DDeviceImpl_7_Clear_FPUPreserve,
6588 IDirect3DDeviceImpl_7_SetTransform_FPUPreserve,
6589 IDirect3DDeviceImpl_7_GetTransform_FPUPreserve,
6590 IDirect3DDeviceImpl_7_SetViewport_FPUPreserve,
6591 IDirect3DDeviceImpl_7_MultiplyTransform_FPUPreserve,
6592 IDirect3DDeviceImpl_7_GetViewport_FPUPreserve,
6593 IDirect3DDeviceImpl_7_SetMaterial_FPUPreserve,
6594 IDirect3DDeviceImpl_7_GetMaterial_FPUPreserve,
6595 IDirect3DDeviceImpl_7_SetLight_FPUPreserve,
6596 IDirect3DDeviceImpl_7_GetLight_FPUPreserve,
6597 IDirect3DDeviceImpl_7_SetRenderState_FPUPreserve,
6598 IDirect3DDeviceImpl_7_GetRenderState_FPUPreserve,
6599 IDirect3DDeviceImpl_7_BeginStateBlock_FPUPreserve,
6600 IDirect3DDeviceImpl_7_EndStateBlock_FPUPreserve,
6601 IDirect3DDeviceImpl_7_PreLoad_FPUPreserve,
6602 IDirect3DDeviceImpl_7_DrawPrimitive_FPUPreserve,
6603 IDirect3DDeviceImpl_7_DrawIndexedPrimitive_FPUPreserve,
6604 IDirect3DDeviceImpl_7_SetClipStatus,
6605 IDirect3DDeviceImpl_7_GetClipStatus,
6606 IDirect3DDeviceImpl_7_DrawPrimitiveStrided_FPUPreserve,
6607 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveStrided_FPUPreserve,
6608 IDirect3DDeviceImpl_7_DrawPrimitiveVB_FPUPreserve,
6609 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB_FPUPreserve,
6610 IDirect3DDeviceImpl_7_ComputeSphereVisibility,
6611 IDirect3DDeviceImpl_7_GetTexture_FPUPreserve,
6612 IDirect3DDeviceImpl_7_SetTexture_FPUPreserve,
6613 IDirect3DDeviceImpl_7_GetTextureStageState_FPUPreserve,
6614 IDirect3DDeviceImpl_7_SetTextureStageState_FPUPreserve,
6615 IDirect3DDeviceImpl_7_ValidateDevice_FPUPreserve,
6616 IDirect3DDeviceImpl_7_ApplyStateBlock_FPUPreserve,
6617 IDirect3DDeviceImpl_7_CaptureStateBlock_FPUPreserve,
6618 IDirect3DDeviceImpl_7_DeleteStateBlock_FPUPreserve,
6619 IDirect3DDeviceImpl_7_CreateStateBlock_FPUPreserve,
6620 IDirect3DDeviceImpl_7_Load_FPUPreserve,
6621 IDirect3DDeviceImpl_7_LightEnable_FPUPreserve,
6622 IDirect3DDeviceImpl_7_GetLightEnable_FPUPreserve,
6623 IDirect3DDeviceImpl_7_SetClipPlane_FPUPreserve,
6624 IDirect3DDeviceImpl_7_GetClipPlane_FPUPreserve,
6625 IDirect3DDeviceImpl_7_GetInfo
6628 static const struct IDirect3DDevice3Vtbl d3d_device3_vtbl =
6630 /*** IUnknown Methods ***/
6631 IDirect3DDeviceImpl_3_QueryInterface,
6632 IDirect3DDeviceImpl_3_AddRef,
6633 IDirect3DDeviceImpl_3_Release,
6634 /*** IDirect3DDevice3 ***/
6635 IDirect3DDeviceImpl_3_GetCaps,
6636 IDirect3DDeviceImpl_3_GetStats,
6637 IDirect3DDeviceImpl_3_AddViewport,
6638 IDirect3DDeviceImpl_3_DeleteViewport,
6639 IDirect3DDeviceImpl_3_NextViewport,
6640 IDirect3DDeviceImpl_3_EnumTextureFormats,
6641 IDirect3DDeviceImpl_3_BeginScene,
6642 IDirect3DDeviceImpl_3_EndScene,
6643 IDirect3DDeviceImpl_3_GetDirect3D,
6644 IDirect3DDeviceImpl_3_SetCurrentViewport,
6645 IDirect3DDeviceImpl_3_GetCurrentViewport,
6646 IDirect3DDeviceImpl_3_SetRenderTarget,
6647 IDirect3DDeviceImpl_3_GetRenderTarget,
6648 IDirect3DDeviceImpl_3_Begin,
6649 IDirect3DDeviceImpl_3_BeginIndexed,
6650 IDirect3DDeviceImpl_3_Vertex,
6651 IDirect3DDeviceImpl_3_Index,
6652 IDirect3DDeviceImpl_3_End,
6653 IDirect3DDeviceImpl_3_GetRenderState,
6654 IDirect3DDeviceImpl_3_SetRenderState,
6655 IDirect3DDeviceImpl_3_GetLightState,
6656 IDirect3DDeviceImpl_3_SetLightState,
6657 IDirect3DDeviceImpl_3_SetTransform,
6658 IDirect3DDeviceImpl_3_GetTransform,
6659 IDirect3DDeviceImpl_3_MultiplyTransform,
6660 IDirect3DDeviceImpl_3_DrawPrimitive,
6661 IDirect3DDeviceImpl_3_DrawIndexedPrimitive,
6662 IDirect3DDeviceImpl_3_SetClipStatus,
6663 IDirect3DDeviceImpl_3_GetClipStatus,
6664 IDirect3DDeviceImpl_3_DrawPrimitiveStrided,
6665 IDirect3DDeviceImpl_3_DrawIndexedPrimitiveStrided,
6666 IDirect3DDeviceImpl_3_DrawPrimitiveVB,
6667 IDirect3DDeviceImpl_3_DrawIndexedPrimitiveVB,
6668 IDirect3DDeviceImpl_3_ComputeSphereVisibility,
6669 IDirect3DDeviceImpl_3_GetTexture,
6670 IDirect3DDeviceImpl_3_SetTexture,
6671 IDirect3DDeviceImpl_3_GetTextureStageState,
6672 IDirect3DDeviceImpl_3_SetTextureStageState,
6673 IDirect3DDeviceImpl_3_ValidateDevice
6676 static const struct IDirect3DDevice2Vtbl d3d_device2_vtbl =
6678 /*** IUnknown Methods ***/
6679 IDirect3DDeviceImpl_2_QueryInterface,
6680 IDirect3DDeviceImpl_2_AddRef,
6681 IDirect3DDeviceImpl_2_Release,
6682 /*** IDirect3DDevice2 ***/
6683 IDirect3DDeviceImpl_2_GetCaps,
6684 IDirect3DDeviceImpl_2_SwapTextureHandles,
6685 IDirect3DDeviceImpl_2_GetStats,
6686 IDirect3DDeviceImpl_2_AddViewport,
6687 IDirect3DDeviceImpl_2_DeleteViewport,
6688 IDirect3DDeviceImpl_2_NextViewport,
6689 IDirect3DDeviceImpl_2_EnumTextureFormats,
6690 IDirect3DDeviceImpl_2_BeginScene,
6691 IDirect3DDeviceImpl_2_EndScene,
6692 IDirect3DDeviceImpl_2_GetDirect3D,
6693 IDirect3DDeviceImpl_2_SetCurrentViewport,
6694 IDirect3DDeviceImpl_2_GetCurrentViewport,
6695 IDirect3DDeviceImpl_2_SetRenderTarget,
6696 IDirect3DDeviceImpl_2_GetRenderTarget,
6697 IDirect3DDeviceImpl_2_Begin,
6698 IDirect3DDeviceImpl_2_BeginIndexed,
6699 IDirect3DDeviceImpl_2_Vertex,
6700 IDirect3DDeviceImpl_2_Index,
6701 IDirect3DDeviceImpl_2_End,
6702 IDirect3DDeviceImpl_2_GetRenderState,
6703 IDirect3DDeviceImpl_2_SetRenderState,
6704 IDirect3DDeviceImpl_2_GetLightState,
6705 IDirect3DDeviceImpl_2_SetLightState,
6706 IDirect3DDeviceImpl_2_SetTransform,
6707 IDirect3DDeviceImpl_2_GetTransform,
6708 IDirect3DDeviceImpl_2_MultiplyTransform,
6709 IDirect3DDeviceImpl_2_DrawPrimitive,
6710 IDirect3DDeviceImpl_2_DrawIndexedPrimitive,
6711 IDirect3DDeviceImpl_2_SetClipStatus,
6712 IDirect3DDeviceImpl_2_GetClipStatus
6715 static const struct IDirect3DDeviceVtbl d3d_device1_vtbl =
6717 /*** IUnknown Methods ***/
6718 IDirect3DDeviceImpl_1_QueryInterface,
6719 IDirect3DDeviceImpl_1_AddRef,
6720 IDirect3DDeviceImpl_1_Release,
6721 /*** IDirect3DDevice1 ***/
6722 IDirect3DDeviceImpl_1_Initialize,
6723 IDirect3DDeviceImpl_1_GetCaps,
6724 IDirect3DDeviceImpl_1_SwapTextureHandles,
6725 IDirect3DDeviceImpl_1_CreateExecuteBuffer,
6726 IDirect3DDeviceImpl_1_GetStats,
6727 IDirect3DDeviceImpl_1_Execute,
6728 IDirect3DDeviceImpl_1_AddViewport,
6729 IDirect3DDeviceImpl_1_DeleteViewport,
6730 IDirect3DDeviceImpl_1_NextViewport,
6731 IDirect3DDeviceImpl_1_Pick,
6732 IDirect3DDeviceImpl_1_GetPickRecords,
6733 IDirect3DDeviceImpl_1_EnumTextureFormats,
6734 IDirect3DDeviceImpl_1_CreateMatrix,
6735 IDirect3DDeviceImpl_1_SetMatrix,
6736 IDirect3DDeviceImpl_1_GetMatrix,
6737 IDirect3DDeviceImpl_1_DeleteMatrix,
6738 IDirect3DDeviceImpl_1_BeginScene,
6739 IDirect3DDeviceImpl_1_EndScene,
6740 IDirect3DDeviceImpl_1_GetDirect3D
6743 /*****************************************************************************
6744 * IDirect3DDeviceImpl_UpdateDepthStencil
6746 * Checks the current render target for attached depth stencils and sets the
6747 * WineD3D depth stencil accordingly.
6750 * The depth stencil state to set if creating the device
6752 *****************************************************************************/
6754 IDirect3DDeviceImpl_UpdateDepthStencil(IDirect3DDeviceImpl *This)
6756 IDirectDrawSurface7 *depthStencil = NULL;
6757 IDirectDrawSurfaceImpl *dsi;
6758 static DDSCAPS2 depthcaps = { DDSCAPS_ZBUFFER, 0, 0, 0 };
6760 IDirectDrawSurface7_GetAttachedSurface(&This->target->IDirectDrawSurface7_iface, &depthcaps, &depthStencil);
6763 TRACE("Setting wined3d depth stencil to NULL\n");
6764 wined3d_device_set_depth_stencil(This->wined3d_device, NULL);
6765 return WINED3DZB_FALSE;
6768 dsi = impl_from_IDirectDrawSurface7(depthStencil);
6769 TRACE("Setting wined3d depth stencil to %p (wined3d %p)\n", dsi, dsi->wined3d_surface);
6770 wined3d_device_set_depth_stencil(This->wined3d_device, dsi->wined3d_surface);
6772 IDirectDrawSurface7_Release(depthStencil);
6773 return WINED3DZB_TRUE;
6776 HRESULT d3d_device_init(IDirect3DDeviceImpl *device, IDirectDrawImpl *ddraw, IDirectDrawSurfaceImpl *target)
6780 if (ddraw->cooperative_level & DDSCL_FPUPRESERVE)
6781 device->lpVtbl = &d3d_device7_fpu_preserve_vtbl;
6783 device->lpVtbl = &d3d_device7_fpu_setup_vtbl;
6785 device->IDirect3DDevice3_vtbl = &d3d_device3_vtbl;
6786 device->IDirect3DDevice2_vtbl = &d3d_device2_vtbl;
6787 device->IDirect3DDevice_vtbl = &d3d_device1_vtbl;
6789 device->ddraw = ddraw;
6790 device->target = target;
6791 list_init(&device->viewport_list);
6793 if (!ddraw_handle_table_init(&device->handle_table, 64))
6795 ERR("Failed to initialize handle table.\n");
6796 return DDERR_OUTOFMEMORY;
6799 device->legacyTextureBlending = FALSE;
6801 /* Create an index buffer, it's needed for indexed drawing */
6802 hr = wined3d_buffer_create_ib(ddraw->wined3d_device, 0x40000 /* Length. Don't know how long it should be */,
6803 WINED3DUSAGE_DYNAMIC /* Usage */, WINED3DPOOL_DEFAULT, NULL,
6804 &ddraw_null_wined3d_parent_ops, &device->indexbuffer);
6807 ERR("Failed to create an index buffer, hr %#x.\n", hr);
6808 ddraw_handle_table_destroy(&device->handle_table);
6812 /* This is for convenience. */
6813 device->wined3d_device = ddraw->wined3d_device;
6814 wined3d_device_incref(ddraw->wined3d_device);
6816 /* Render to the back buffer */
6817 hr = wined3d_device_set_render_target(ddraw->wined3d_device, 0, target->wined3d_surface, TRUE);
6820 ERR("Failed to set render target, hr %#x.\n", hr);
6821 wined3d_buffer_decref(device->indexbuffer);
6822 ddraw_handle_table_destroy(&device->handle_table);
6826 /* FIXME: This is broken. The target AddRef() makes some sense, because
6827 * we store a pointer during initialization, but then that's also where
6828 * the AddRef() should be. We don't store ddraw->d3d_target anywhere. */
6829 /* AddRef the render target. Also AddRef the render target from ddraw,
6830 * because if it is released before the app releases the D3D device, the
6831 * D3D capabilities of wined3d will be uninitialized, which has bad effects.
6833 * In most cases, those surfaces are the same anyway, but this will simply
6834 * add another ref which is released when the device is destroyed. */
6835 IDirectDrawSurface7_AddRef(&target->IDirectDrawSurface7_iface);
6836 IDirectDrawSurface7_AddRef(&ddraw->d3d_target->IDirectDrawSurface7_iface);
6838 ddraw->d3ddevice = device;
6840 wined3d_device_set_render_state(ddraw->wined3d_device, WINED3DRS_ZENABLE,
6841 IDirect3DDeviceImpl_UpdateDepthStencil(device));