2 * Copyright (c) 1998-2004 Lionel Ulmer
3 * Copyright (c) 2002-2005 Christian Costa
4 * Copyright (c) 2006 Stefan Dösinger
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * IDirect3DDevice implementation, version 1, 2, 3 and 7. Rendering is relayed
21 * to WineD3D, some minimal DirectDraw specific management is handled here.
22 * The Direct3DDevice is NOT the parent of the WineD3DDevice, because d3d
23 * is initialized when DirectDraw creates the primary surface.
24 * Some type management is necessary, because some D3D types changed between
30 #include "wine/port.h"
31 #include "wine/debug.h"
44 #include "wine/exception.h"
49 #include "ddraw_private.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(d3d7);
52 WINE_DECLARE_DEBUG_CHANNEL(ddraw_thunk);
55 const GUID IID_D3DDEVICE_WineD3D = {
59 { 0xb7,0x98,0xc6,0x8a,0x77,0x2d,0x72,0x2a }
62 /*****************************************************************************
63 * IUnknown Methods. Common for Version 1, 2, 3 and 7
64 *****************************************************************************/
66 /*****************************************************************************
67 * IDirect3DDevice7::QueryInterface
69 * Used to query other interfaces from a Direct3DDevice interface.
70 * It can return interface pointers to all Direct3DDevice versions as well
71 * as IDirectDraw and IDirect3D. For a link to QueryInterface
72 * rules see ddraw.c, IDirectDraw7::QueryInterface
74 * Exists in Version 1, 2, 3 and 7
77 * refiid: Interface ID queried for
78 * obj: Used to return the interface pointer
81 * D3D_OK or E_NOINTERFACE
83 *****************************************************************************/
85 IDirect3DDeviceImpl_7_QueryInterface(IDirect3DDevice7 *iface,
89 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
90 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(refiid), obj);
92 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
96 return DDERR_INVALIDPARAMS;
98 if ( IsEqualGUID( &IID_IUnknown, refiid ) )
100 *obj = ICOM_INTERFACE(This, IDirect3DDevice7);
103 /* Check DirectDraw Interfac
\ 1s */
104 else if( IsEqualGUID( &IID_IDirectDraw7, refiid ) )
106 *obj = ICOM_INTERFACE(This->ddraw, IDirectDraw7);
107 TRACE("(%p) Returning IDirectDraw7 interface at %p\n", This, *obj);
109 else if ( IsEqualGUID( &IID_IDirectDraw4, refiid ) )
111 *obj = ICOM_INTERFACE(This->ddraw, IDirectDraw4);
112 TRACE("(%p) Returning IDirectDraw4 interface at %p\n", This, *obj);
114 else if ( IsEqualGUID( &IID_IDirectDraw2, refiid ) )
116 *obj = ICOM_INTERFACE(This->ddraw, IDirectDraw2);
117 TRACE("(%p) Returning IDirectDraw2 interface at %p\n", This, *obj);
119 else if( IsEqualGUID( &IID_IDirectDraw, refiid ) )
121 *obj = ICOM_INTERFACE(This->ddraw, IDirectDraw);
122 TRACE("(%p) Returning IDirectDraw interface at %p\n", This, *obj);
126 else if ( IsEqualGUID( &IID_IDirect3D , refiid ) )
128 *obj = ICOM_INTERFACE(This->ddraw, IDirect3D);
129 TRACE("(%p) Returning IDirect3D interface at %p\n", This, *obj);
131 else if ( IsEqualGUID( &IID_IDirect3D2 , refiid ) )
133 *obj = ICOM_INTERFACE(This->ddraw, IDirect3D2);
134 TRACE("(%p) Returning IDirect3D2 interface at %p\n", This, *obj);
136 else if ( IsEqualGUID( &IID_IDirect3D3 , refiid ) )
138 *obj = ICOM_INTERFACE(This->ddraw, IDirect3D3);
139 TRACE("(%p) Returning IDirect3D3 interface at %p\n", This, *obj);
141 else if ( IsEqualGUID( &IID_IDirect3D7 , refiid ) )
143 *obj = ICOM_INTERFACE(This->ddraw, IDirect3D7);
144 TRACE("(%p) Returning IDirect3D7 interface at %p\n", This, *obj);
148 else if ( IsEqualGUID( &IID_IDirect3DDevice , refiid ) )
150 *obj = ICOM_INTERFACE(This, IDirect3DDevice);
151 TRACE("(%p) Returning IDirect3DDevice interface at %p\n", This, *obj);
153 else if ( IsEqualGUID( &IID_IDirect3DDevice2 , refiid ) ) {
154 *obj = ICOM_INTERFACE(This, IDirect3DDevice2);
155 TRACE("(%p) Returning IDirect3DDevice2 interface at %p\n", This, *obj);
157 else if ( IsEqualGUID( &IID_IDirect3DDevice3 , refiid ) ) {
158 *obj = ICOM_INTERFACE(This, IDirect3DDevice3);
159 TRACE("(%p) Returning IDirect3DDevice3 interface at %p\n", This, *obj);
161 else if ( IsEqualGUID( &IID_IDirect3DDevice7 , refiid ) ) {
162 *obj = ICOM_INTERFACE(This, IDirect3DDevice7);
163 TRACE("(%p) Returning IDirect3DDevice7 interface at %p\n", This, *obj);
166 /* Unknown interface */
169 ERR("(%p)->(%s, %p): No interface found\n", This, debugstr_guid(refiid), obj);
170 return E_NOINTERFACE;
173 /* AddRef the returned interface */
174 IUnknown_AddRef( (IUnknown *) *obj);
178 static HRESULT WINAPI
179 Thunk_IDirect3DDeviceImpl_3_QueryInterface(IDirect3DDevice3 *iface,
183 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
184 TRACE_(ddraw_thunk)("(%p)->(%s,%p) thunking to IDirect3DDevice7 interface.\n", This, debugstr_guid(riid), obj);
185 return IDirect3DDevice7_QueryInterface(ICOM_INTERFACE(This, IDirect3DDevice7),
190 static HRESULT WINAPI
191 Thunk_IDirect3DDeviceImpl_2_QueryInterface(IDirect3DDevice2 *iface,
195 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
196 TRACE_(ddraw_thunk)("(%p)->(%s,%p) thunking to IDirect3DDevice7 interface.\n", This, debugstr_guid(riid), obj);
197 return IDirect3DDevice7_QueryInterface(ICOM_INTERFACE(This, IDirect3DDevice7),
202 static HRESULT WINAPI
203 Thunk_IDirect3DDeviceImpl_1_QueryInterface(IDirect3DDevice *iface,
207 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
208 TRACE_(ddraw_thunk)("(%p)->(%s,%p) thunking to IDirect3DDevice7 interface.\n", This, debugstr_guid(riid), obp);
209 return IDirect3DDevice7_QueryInterface(ICOM_INTERFACE(This, IDirect3DDevice7),
214 /*****************************************************************************
215 * IDirect3DDevice7::AddRef
217 * Increases the refcount....
218 * The most exciting Method, definitely
220 * Exists in Version 1, 2, 3 and 7
225 *****************************************************************************/
227 IDirect3DDeviceImpl_7_AddRef(IDirect3DDevice7 *iface)
229 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
230 ULONG ref = InterlockedIncrement(&This->ref);
232 TRACE("(%p) : incrementing from %u.\n", This, ref -1);
238 Thunk_IDirect3DDeviceImpl_3_AddRef(IDirect3DDevice3 *iface)
240 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
241 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
242 return IDirect3DDevice7_AddRef(ICOM_INTERFACE(This, IDirect3DDevice7));
246 Thunk_IDirect3DDeviceImpl_2_AddRef(IDirect3DDevice2 *iface)
248 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
249 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
250 return IDirect3DDevice7_AddRef(ICOM_INTERFACE(This, IDirect3DDevice7));
254 Thunk_IDirect3DDeviceImpl_1_AddRef(IDirect3DDevice *iface)
256 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", iface);
257 return IDirect3DDevice7_AddRef(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice, IDirect3DDevice7, iface));
260 /*****************************************************************************
261 * IDirect3DDevice7::Release
263 * Decreases the refcount of the interface
264 * When the refcount is reduced to 0, the object is destroyed.
266 * Exists in Version 1, 2, 3 and 7
271 *****************************************************************************/
273 IDirect3DDeviceImpl_7_Release(IDirect3DDevice7 *iface)
275 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
276 ULONG ref = InterlockedDecrement(&This->ref);
278 TRACE("(%p)->() decrementing from %u.\n", This, ref +1);
280 /* This method doesn't destroy the WineD3DDevice, because it's still in use for
281 * 2D rendering. IDirectDrawSurface7::Release will destroy the WineD3DDevice
282 * when the render target is released
286 IParent *IndexBufferParent;
289 EnterCriticalSection(&ddraw_cs);
290 /* Free the index buffer. */
291 IWineD3DDevice_SetIndices(This->wineD3DDevice, NULL);
292 IWineD3DIndexBuffer_GetParent(This->indexbuffer,
293 (IUnknown **) &IndexBufferParent);
294 IParent_Release(IndexBufferParent); /* Once for the getParent */
295 if( IParent_Release(IndexBufferParent) != 0) /* And now to destroy it */
297 ERR(" (%p) Something is still holding the index buffer parent %p\n", This, IndexBufferParent);
300 /* There is no need to unset the vertex buffer here, IWineD3DDevice_Uninit3D will do that when
301 * destroying the primary stateblock. If a vertex buffer is destroyed while it is bound
302 * IDirect3DVertexBuffer::Release will unset it.
305 /* Restore the render targets */
306 if(This->OffScreenTarget)
312 vp.Width = This->ddraw->d3d_target->surface_desc.dwWidth;
313 vp.Height = This->ddraw->d3d_target->surface_desc.dwHeight;
316 IWineD3DDevice_SetViewport(This->wineD3DDevice,
319 /* Set the device up to render to the front buffer since the back buffer will
322 IWineD3DDevice_SetRenderTarget(This->wineD3DDevice, 0,
323 This->ddraw->d3d_target->WineD3DSurface);
324 /* This->target is the offscreen target.
325 * This->ddraw->d3d_target is the target used by DDraw
327 TRACE("(%p) Release: Using %p as front buffer, %p as back buffer\n", This, This->ddraw->d3d_target, NULL);
328 IWineD3DDevice_SetFrontBackBuffers(This->wineD3DDevice,
329 This->ddraw->d3d_target->WineD3DSurface,
333 /* Release the WineD3DDevice. This won't destroy it */
334 if(IWineD3DDevice_Release(This->wineD3DDevice) <= 0)
336 ERR(" (%p) The wineD3D device %p was destroyed unexpectadely. Prepare for trouble\n", This, This->wineD3DDevice);
339 /* The texture handles should be unset by now, but there might be some bits
340 * missing in our reference counting(needs test). Do a sanity check
342 for(i = 0; i < This->numHandles; i++)
344 if(This->Handles[i].ptr)
346 switch(This->Handles[i].type)
348 case DDrawHandle_Texture:
350 IDirectDrawSurfaceImpl *surf = (IDirectDrawSurfaceImpl *) This->Handles[i].ptr;
351 FIXME("Texture Handle %d not unset properly\n", i + 1);
356 case DDrawHandle_Material:
358 IDirect3DMaterialImpl *mat = (IDirect3DMaterialImpl *) This->Handles[i].ptr;
359 FIXME("Material handle %d not unset properly\n", i + 1);
364 case DDrawHandle_Matrix:
366 /* No fixme here because this might happen because of sloppy apps */
367 WARN("Leftover matrix handle %d, deleting\n", i + 1);
368 IDirect3DDevice_DeleteMatrix(ICOM_INTERFACE(This, IDirect3DDevice),
373 case DDrawHandle_StateBlock:
375 /* No fixme here because this might happen because of sloppy apps */
376 WARN("Leftover stateblock handle %d, deleting\n", i + 1);
377 IDirect3DDevice7_DeleteStateBlock(ICOM_INTERFACE(This, IDirect3DDevice7),
383 FIXME("Unknown handle %d not unset properly\n", i + 1);
388 HeapFree(GetProcessHeap(), 0, This->Handles);
390 TRACE("Releasing target %p %p\n", This->target, This->ddraw->d3d_target);
391 /* Release the render target and the WineD3D render target
392 * (See IDirect3D7::CreateDevice for more comments on this)
394 IDirectDrawSurface7_Release(ICOM_INTERFACE(This->target, IDirectDrawSurface7));
395 IDirectDrawSurface7_Release(ICOM_INTERFACE(This->ddraw->d3d_target,IDirectDrawSurface7));
396 TRACE("Target release done\n");
398 This->ddraw->d3ddevice = NULL;
400 /* Now free the structure */
401 HeapFree(GetProcessHeap(), 0, This);
402 LeaveCriticalSection(&ddraw_cs);
410 Thunk_IDirect3DDeviceImpl_3_Release(IDirect3DDevice3 *iface)
412 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
413 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
414 return IDirect3DDevice7_Release(ICOM_INTERFACE(This, IDirect3DDevice7));
418 Thunk_IDirect3DDeviceImpl_2_Release(IDirect3DDevice2 *iface)
420 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
421 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
422 return IDirect3DDevice7_Release(ICOM_INTERFACE(This, IDirect3DDevice7));
426 Thunk_IDirect3DDeviceImpl_1_Release(IDirect3DDevice *iface)
428 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
429 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
430 return IDirect3DDevice7_Release(ICOM_INTERFACE(This, IDirect3DDevice7));
433 /*****************************************************************************
434 * IDirect3DDevice Methods
435 *****************************************************************************/
437 /*****************************************************************************
438 * IDirect3DDevice::Initialize
440 * Initializes a Direct3DDevice. This implementation is a no-op, as all
441 * initialization is done at create time.
443 * Exists in Version 1
446 * No idea what they mean, as the MSDN page is gone
450 *****************************************************************************/
451 static HRESULT WINAPI
452 IDirect3DDeviceImpl_1_Initialize(IDirect3DDevice *iface,
453 IDirect3D *Direct3D, GUID *guid,
456 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
458 /* It shouldn't be crucial, but print a FIXME, I'm interested if
459 * any game calls it and when
461 FIXME("(%p)->(%p,%p,%p): No-op!\n", This, Direct3D, guid, Desc);
466 /*****************************************************************************
467 * IDirect3DDevice7::GetCaps
469 * Retrieves the device's capabilities
471 * This implementation is used for Version 7 only, the older versions have
472 * their own implementation.
475 * Desc: Pointer to a D3DDEVICEDESC7 structure to fill
479 * D3DERR_* if a problem occurs. See WineD3D
481 *****************************************************************************/
482 static HRESULT WINAPI
483 IDirect3DDeviceImpl_7_GetCaps(IDirect3DDevice7 *iface,
484 D3DDEVICEDESC7 *Desc)
486 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
487 D3DDEVICEDESC OldDesc;
488 TRACE("(%p)->(%p)\n", This, Desc);
490 /* Call the same function used by IDirect3D, this saves code */
491 return IDirect3DImpl_GetCaps(This->ddraw->wineD3D, &OldDesc, Desc);
494 /*****************************************************************************
495 * IDirect3DDevice3::GetCaps
497 * Retrieves the capabilities of the hardware device and the emulation
498 * device. For Wine, hardware and emulation are the same (it's all HW).
500 * This implementation is used for Version 1, 2, and 3. Version 7 has its own
503 * HWDesc: Structure to fill with the HW caps
504 * HelDesc: Structure to fill with the hardare emulation caps
508 * D3DERR_* if a problem occurs. See WineD3D
510 *****************************************************************************/
511 static HRESULT WINAPI
512 IDirect3DDeviceImpl_3_GetCaps(IDirect3DDevice3 *iface,
513 D3DDEVICEDESC *HWDesc,
514 D3DDEVICEDESC *HelDesc)
516 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
517 D3DDEVICEDESC7 newDesc;
519 TRACE("(%p)->(%p,%p)\n", iface, HWDesc, HelDesc);
521 hr = IDirect3DImpl_GetCaps(This->ddraw->wineD3D, HWDesc, &newDesc);
522 if(hr != D3D_OK) return hr;
528 static HRESULT WINAPI
529 Thunk_IDirect3DDeviceImpl_2_GetCaps(IDirect3DDevice2 *iface,
530 D3DDEVICEDESC *D3DHWDevDesc,
531 D3DDEVICEDESC *D3DHELDevDesc)
533 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
534 TRACE_(ddraw_thunk)("(%p)->(%p,%p) thunking to IDirect3DDevice3 interface.\n", This, D3DHWDevDesc, D3DHELDevDesc);
535 return IDirect3DDevice3_GetCaps(ICOM_INTERFACE(This, IDirect3DDevice3),
540 static HRESULT WINAPI
541 Thunk_IDirect3DDeviceImpl_1_GetCaps(IDirect3DDevice *iface,
542 D3DDEVICEDESC *D3DHWDevDesc,
543 D3DDEVICEDESC *D3DHELDevDesc)
545 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
546 TRACE_(ddraw_thunk)("(%p)->(%p,%p) thunking to IDirect3DDevice3 interface.\n", This, D3DHWDevDesc, D3DHELDevDesc);
547 return IDirect3DDevice3_GetCaps(ICOM_INTERFACE(This, IDirect3DDevice3),
552 /*****************************************************************************
553 * IDirect3DDevice2::SwapTextureHandles
555 * Swaps the texture handles of 2 Texture interfaces. Version 1 and 2
558 * Tex1, Tex2: The 2 Textures to swap
563 *****************************************************************************/
564 static HRESULT WINAPI
565 IDirect3DDeviceImpl_2_SwapTextureHandles(IDirect3DDevice2 *iface,
566 IDirect3DTexture2 *Tex1,
567 IDirect3DTexture2 *Tex2)
569 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
571 IDirectDrawSurfaceImpl *surf1 = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture2, Tex1);
572 IDirectDrawSurfaceImpl *surf2 = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture2, Tex2);
573 TRACE("(%p)->(%p,%p)\n", This, surf1, surf2);
575 EnterCriticalSection(&ddraw_cs);
576 This->Handles[surf1->Handle - 1].ptr = surf2;
577 This->Handles[surf2->Handle - 1].ptr = surf1;
579 swap = surf2->Handle;
580 surf2->Handle = surf1->Handle;
581 surf1->Handle = swap;
582 LeaveCriticalSection(&ddraw_cs);
587 static HRESULT WINAPI
588 Thunk_IDirect3DDeviceImpl_1_SwapTextureHandles(IDirect3DDevice *iface,
589 IDirect3DTexture *D3DTex1,
590 IDirect3DTexture *D3DTex2)
592 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
593 IDirectDrawSurfaceImpl *surf1 = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture, D3DTex1);
594 IDirectDrawSurfaceImpl *surf2 = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture, D3DTex2);
595 TRACE_(ddraw_thunk)("(%p)->(%p,%p) thunking to IDirect3DDevice2 interface.\n", This, surf1, surf2);
596 return IDirect3DDevice2_SwapTextureHandles(ICOM_INTERFACE(This, IDirect3DDevice2),
597 ICOM_INTERFACE(surf1, IDirect3DTexture2),
598 ICOM_INTERFACE(surf2, IDirect3DTexture2));
601 /*****************************************************************************
602 * IDirect3DDevice3::GetStats
604 * This method seems to retrieve some stats from the device.
605 * The MSDN documentation doesn't exist any more, but the D3DSTATS
606 * structure suggests that the amout of drawn primitives and processed
607 * vertices is returned.
609 * Exists in Version 1, 2 and 3
612 * Stats: Pointer to a D3DSTATS structure to be filled
616 * DDERR_INVALIDPARAMS if Stats == NULL
618 *****************************************************************************/
619 static HRESULT WINAPI
620 IDirect3DDeviceImpl_3_GetStats(IDirect3DDevice3 *iface,
623 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
624 FIXME("(%p)->(%p): Stub!\n", This, Stats);
627 return DDERR_INVALIDPARAMS;
629 /* Fill the Stats with 0 */
630 Stats->dwTrianglesDrawn = 0;
631 Stats->dwLinesDrawn = 0;
632 Stats->dwPointsDrawn = 0;
633 Stats->dwSpansDrawn = 0;
634 Stats->dwVerticesProcessed = 0;
639 static HRESULT WINAPI
640 Thunk_IDirect3DDeviceImpl_2_GetStats(IDirect3DDevice2 *iface,
643 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
644 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, Stats);
645 return IDirect3DDevice3_GetStats(ICOM_INTERFACE(This, IDirect3DDevice3),
649 static HRESULT WINAPI
650 Thunk_IDirect3DDeviceImpl_1_GetStats(IDirect3DDevice *iface,
653 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
654 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, Stats);
655 return IDirect3DDevice3_GetStats(ICOM_INTERFACE(This, IDirect3DDevice3),
659 /*****************************************************************************
660 * IDirect3DDevice::CreateExecuteBuffer
662 * Creates an IDirect3DExecuteBuffer, used for rendering with a
668 * Desc: Buffer description
669 * ExecuteBuffer: Address to return the Interface pointer at
670 * UnkOuter: Must be NULL. Basically for aggregation, which ddraw doesn't
674 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
675 * DDERR_OUTOFMEMORY if we ran out of memory
678 *****************************************************************************/
679 static HRESULT WINAPI
680 IDirect3DDeviceImpl_1_CreateExecuteBuffer(IDirect3DDevice *iface,
681 D3DEXECUTEBUFFERDESC *Desc,
682 IDirect3DExecuteBuffer **ExecuteBuffer,
685 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
686 IDirect3DExecuteBufferImpl* object;
687 TRACE("(%p)->(%p,%p,%p)!\n", This, Desc, ExecuteBuffer, UnkOuter);
690 return CLASS_E_NOAGGREGATION;
692 /* Allocate the new Execute Buffer */
693 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DExecuteBufferImpl));
696 ERR("Out of memory when allocating a IDirect3DExecuteBufferImpl structure\n");
697 return DDERR_OUTOFMEMORY;
700 ICOM_INIT_INTERFACE(object, IDirect3DExecuteBuffer, IDirect3DExecuteBuffer_Vtbl);
703 object->d3ddev = This;
705 /* Initializes memory */
706 memcpy(&object->desc, Desc, Desc->dwSize);
708 /* No buffer given */
709 if ((object->desc.dwFlags & D3DDEB_LPDATA) == 0)
710 object->desc.lpData = NULL;
712 /* No buffer size given */
713 if ((object->desc.dwFlags & D3DDEB_BUFSIZE) == 0)
714 object->desc.dwBufferSize = 0;
716 /* Create buffer if asked */
717 if ((object->desc.lpData == NULL) && (object->desc.dwBufferSize > 0))
719 object->need_free = TRUE;
720 object->desc.lpData = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,object->desc.dwBufferSize);
721 if(!object->desc.lpData)
723 ERR("Out of memory when allocating the execute buffer data\n");
724 HeapFree(GetProcessHeap(), 0, object);
725 return DDERR_OUTOFMEMORY;
730 object->need_free = FALSE;
733 /* No vertices for the moment */
734 object->vertex_data = NULL;
736 object->desc.dwFlags |= D3DDEB_LPDATA;
738 object->indices = NULL;
739 object->nb_indices = 0;
741 *ExecuteBuffer = ICOM_INTERFACE(object, IDirect3DExecuteBuffer);
743 TRACE(" Returning IDirect3DExecuteBuffer at %p, implementation is at %p\n", *ExecuteBuffer, object);
748 /*****************************************************************************
749 * IDirect3DDevice::Execute
751 * Executes all the stuff in an execute buffer.
754 * ExecuteBuffer: The buffer to execute
755 * Viewport: The viewport used for rendering
759 * DDERR_INVALIDPARAMS if ExecuteBuffer == NULL
762 *****************************************************************************/
763 static HRESULT WINAPI
764 IDirect3DDeviceImpl_1_Execute(IDirect3DDevice *iface,
765 IDirect3DExecuteBuffer *ExecuteBuffer,
766 IDirect3DViewport *Viewport,
769 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
770 IDirect3DExecuteBufferImpl *Direct3DExecuteBufferImpl = ICOM_OBJECT(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, ExecuteBuffer);
771 IDirect3DViewportImpl *Direct3DViewportImpl = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport);
773 TRACE("(%p)->(%p,%p,%08x)\n", This, Direct3DExecuteBufferImpl, Direct3DViewportImpl, Flags);
775 if(!Direct3DExecuteBufferImpl)
776 return DDERR_INVALIDPARAMS;
779 EnterCriticalSection(&ddraw_cs);
780 IDirect3DExecuteBufferImpl_Execute(Direct3DExecuteBufferImpl, This, Direct3DViewportImpl);
781 LeaveCriticalSection(&ddraw_cs);
786 /*****************************************************************************
787 * IDirect3DDevice3::AddViewport
789 * Add a Direct3DViewport to the device's viewport list. These viewports
790 * are wrapped to IDirect3DDevice7 viewports in viewport.c
792 * Exists in Version 1, 2 and 3. Note that IDirect3DViewport 1, 2 and 3
793 * are the same interfaces.
796 * Viewport: The viewport to add
799 * DDERR_INVALIDPARAMS if Viewport == NULL
802 *****************************************************************************/
803 static HRESULT WINAPI
804 IDirect3DDeviceImpl_3_AddViewport(IDirect3DDevice3 *iface,
805 IDirect3DViewport3 *Viewport)
807 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
808 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport);
810 TRACE("(%p)->(%p)\n", This, vp);
814 return DDERR_INVALIDPARAMS;
816 EnterCriticalSection(&ddraw_cs);
817 vp->next = This->viewport_list;
818 This->viewport_list = vp;
819 LeaveCriticalSection(&ddraw_cs);
824 static HRESULT WINAPI
825 Thunk_IDirect3DDeviceImpl_2_AddViewport(IDirect3DDevice2 *iface,
826 IDirect3DViewport2 *Direct3DViewport2)
828 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
829 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport2);
830 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, vp);
831 return IDirect3DDevice3_AddViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
832 ICOM_INTERFACE(vp, IDirect3DViewport3));
835 static HRESULT WINAPI
836 Thunk_IDirect3DDeviceImpl_1_AddViewport(IDirect3DDevice *iface,
837 IDirect3DViewport *Direct3DViewport)
839 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
840 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport);
841 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, vp);
842 return IDirect3DDevice3_AddViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
843 ICOM_INTERFACE(vp, IDirect3DViewport3));
846 /*****************************************************************************
847 * IDirect3DDevice3::DeleteViewport
849 * Deletes a Direct3DViewport from the device's viewport list.
851 * Exists in Version 1, 2 and 3. Note that all Viewport interface versions
855 * Viewport: The viewport to delete
859 * DDERR_INVALIDPARAMS if the viewport wasn't found in the list
861 *****************************************************************************/
862 static HRESULT WINAPI
863 IDirect3DDeviceImpl_3_DeleteViewport(IDirect3DDevice3 *iface,
864 IDirect3DViewport3 *Viewport)
866 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
867 IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *) Viewport;
868 IDirect3DViewportImpl *cur_viewport, *prev_viewport = NULL;
870 TRACE("(%p)->(%p)\n", This, vp);
872 EnterCriticalSection(&ddraw_cs);
873 cur_viewport = This->viewport_list;
874 while (cur_viewport != NULL)
876 if (cur_viewport == vp)
878 if (prev_viewport == NULL) This->viewport_list = cur_viewport->next;
879 else prev_viewport->next = cur_viewport->next;
880 /* TODO : add desactivate of the viewport and all associated lights... */
881 LeaveCriticalSection(&ddraw_cs);
884 prev_viewport = cur_viewport;
885 cur_viewport = cur_viewport->next;
888 LeaveCriticalSection(&ddraw_cs);
889 return DDERR_INVALIDPARAMS;
892 static HRESULT WINAPI
893 Thunk_IDirect3DDeviceImpl_2_DeleteViewport(IDirect3DDevice2 *iface,
894 IDirect3DViewport2 *Direct3DViewport2)
896 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
897 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport2);
898 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, vp);
899 return IDirect3DDevice3_DeleteViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
900 ICOM_INTERFACE(vp, IDirect3DViewport3));
903 static HRESULT WINAPI
904 Thunk_IDirect3DDeviceImpl_1_DeleteViewport(IDirect3DDevice *iface,
905 IDirect3DViewport *Direct3DViewport)
907 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
908 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport);
909 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, vp);
910 return IDirect3DDevice3_DeleteViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
911 ICOM_INTERFACE(vp, IDirect3DViewport3));
914 /*****************************************************************************
915 * IDirect3DDevice3::NextViewport
917 * Returns a viewport from the viewport list, depending on the
918 * passed viewport and the flags.
920 * Exists in Version 1, 2 and 3. Note that all Viewport interface versions
924 * Viewport: Viewport to use for beginning the search
925 * Flags: D3DNEXT_NEXT, D3DNEXT_HEAD or D3DNEXT_TAIL
929 * DDERR_INVALIDPARAMS if the flags were wrong, or Viewport was NULL
931 *****************************************************************************/
932 static HRESULT WINAPI
933 IDirect3DDeviceImpl_3_NextViewport(IDirect3DDevice3 *iface,
934 IDirect3DViewport3 *Viewport3,
935 IDirect3DViewport3 **lplpDirect3DViewport3,
938 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
939 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport3);
940 IDirect3DViewportImpl *res = NULL;
942 TRACE("(%p)->(%p,%p,%08x)\n", This, vp, lplpDirect3DViewport3, Flags);
946 *lplpDirect3DViewport3 = NULL;
947 return DDERR_INVALIDPARAMS;
951 EnterCriticalSection(&ddraw_cs);
961 res = This->viewport_list;
966 IDirect3DViewportImpl *cur_viewport = This->viewport_list;
967 if (cur_viewport != NULL)
969 while (cur_viewport->next != NULL) cur_viewport = cur_viewport->next;
975 *lplpDirect3DViewport3 = NULL;
976 LeaveCriticalSection(&ddraw_cs);
977 return DDERR_INVALIDPARAMS;
980 *lplpDirect3DViewport3 = ICOM_INTERFACE(res, IDirect3DViewport3);
981 LeaveCriticalSection(&ddraw_cs);
985 static HRESULT WINAPI
986 Thunk_IDirect3DDeviceImpl_2_NextViewport(IDirect3DDevice2 *iface,
987 IDirect3DViewport2 *Viewport2,
988 IDirect3DViewport2 **lplpDirect3DViewport2,
991 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
992 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport2);
993 IDirect3DViewport3 *res;
995 TRACE_(ddraw_thunk)("(%p)->(%p,%p,%08x) thunking to IDirect3DDevice3 interface.\n", This, vp, lplpDirect3DViewport2, Flags);
996 hr = IDirect3DDevice3_NextViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
997 ICOM_INTERFACE(vp, IDirect3DViewport3),
1000 *lplpDirect3DViewport2 = (IDirect3DViewport2 *) COM_INTERFACE_CAST(IDirect3DViewportImpl, IDirect3DViewport3, IDirect3DViewport3, res);
1004 static HRESULT WINAPI
1005 Thunk_IDirect3DDeviceImpl_1_NextViewport(IDirect3DDevice *iface,
1006 IDirect3DViewport *Viewport,
1007 IDirect3DViewport **lplpDirect3DViewport,
1010 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1011 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport);
1012 IDirect3DViewport3 *res;
1014 TRACE_(ddraw_thunk)("(%p)->(%p,%p,%08x) thunking to IDirect3DDevice3 interface.\n", This, vp, lplpDirect3DViewport, Flags);
1015 hr = IDirect3DDevice3_NextViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
1016 ICOM_INTERFACE(vp, IDirect3DViewport3),
1019 *lplpDirect3DViewport = (IDirect3DViewport *) COM_INTERFACE_CAST(IDirect3DViewportImpl, IDirect3DViewport3, IDirect3DViewport3, res);
1023 /*****************************************************************************
1024 * IDirect3DDevice::Pick
1026 * Executes an execute buffer without performing rendering. Instead, a
1027 * list of primitives that intersect with (x1,y1) of the passed rectangle
1028 * is created. IDirect3DDevice::GetPickRecords can be used to retrieve
1034 * ExecuteBuffer: Buffer to execute
1035 * Viewport: Viewport to use for execution
1036 * Flags: None are defined, according to the SDK
1037 * Rect: Specifies the coordinates to be picked. Only x1 and y2 are used,
1038 * x2 and y2 are ignored.
1041 * D3D_OK because it's a stub
1043 *****************************************************************************/
1044 static HRESULT WINAPI
1045 IDirect3DDeviceImpl_1_Pick(IDirect3DDevice *iface,
1046 IDirect3DExecuteBuffer *ExecuteBuffer,
1047 IDirect3DViewport *Viewport,
1051 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1052 IDirect3DExecuteBufferImpl *execbuf = ICOM_OBJECT(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, ExecuteBuffer);
1053 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport);
1054 FIXME("(%p)->(%p,%p,%08x,%p): stub!\n", This, execbuf, vp, Flags, Rect);
1059 /*****************************************************************************
1060 * IDirect3DDevice::GetPickRecords
1062 * Retrieves the pick records generated by IDirect3DDevice::GetPickRecords
1067 * Count: Pointer to a DWORD containing the numbers of pick records to
1069 * D3DPickRec: Address to store the resulting D3DPICKRECORD arry.
1072 * D3D_OK, because it's a stub
1074 *****************************************************************************/
1075 static HRESULT WINAPI
1076 IDirect3DDeviceImpl_1_GetPickRecords(IDirect3DDevice *iface,
1078 D3DPICKRECORD *D3DPickRec)
1080 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1081 FIXME("(%p)->(%p,%p): stub!\n", This, Count, D3DPickRec);
1086 /*****************************************************************************
1087 * IDirect3DDevice7::EnumTextureformats
1089 * Enumerates the supported texture formats. It has a list of all possible
1090 * formats and calls IWineD3D::CheckDeviceFormat for each format to see if
1091 * WineD3D supports it. If so, then it is passed to the app.
1093 * This is for Version 7 and 3, older versions have a different
1094 * callback function and their own implementation
1097 * Callback: Callback to call for each enumerated format
1098 * Arg: Argument to pass to the callback
1102 * DDERR_INVALIDPARAMS if Callback == NULL
1104 *****************************************************************************/
1105 static HRESULT WINAPI
1106 IDirect3DDeviceImpl_7_EnumTextureFormats(IDirect3DDevice7 *iface,
1107 LPD3DENUMPIXELFORMATSCALLBACK Callback,
1110 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1114 WINED3DFORMAT FormatList[] = {
1116 WINED3DFMT_A8R8G8B8,
1117 WINED3DFMT_X8R8G8B8,
1121 WINED3DFMT_A1R5G5B5,
1122 WINED3DFMT_A4R4G4B4,
1124 WINED3DFMT_X1R5G5B5,
1134 WINED3DFORMAT BumpFormatList[] = {
1137 WINED3DFMT_X8L8V8U8,
1138 WINED3DFMT_Q8W8V8U8,
1140 WINED3DFMT_W11V11U10,
1141 WINED3DFMT_A2W10V10U10
1144 TRACE("(%p)->(%p,%p): Relay\n", This, Callback, Arg);
1147 return DDERR_INVALIDPARAMS;
1149 EnterCriticalSection(&ddraw_cs);
1150 for(i = 0; i < sizeof(FormatList) / sizeof(WINED3DFORMAT); i++)
1152 hr = IWineD3D_CheckDeviceFormat(This->ddraw->wineD3D,
1155 0 /* AdapterFormat */,
1157 0 /* ResourceType */,
1161 DDPIXELFORMAT pformat;
1163 memset(&pformat, 0, sizeof(pformat));
1164 pformat.dwSize = sizeof(pformat);
1165 PixelFormat_WineD3DtoDD(&pformat, FormatList[i]);
1167 TRACE("Enumerating WineD3DFormat %d\n", FormatList[i]);
1168 hr = Callback(&pformat, Arg);
1169 if(hr != DDENUMRET_OK)
1171 TRACE("Format enumeration cancelled by application\n");
1172 LeaveCriticalSection(&ddraw_cs);
1178 for(i = 0; i < sizeof(BumpFormatList) / sizeof(WINED3DFORMAT); i++)
1180 hr = IWineD3D_CheckDeviceFormat(This->ddraw->wineD3D,
1183 0 /* AdapterFormat */,
1184 WINED3DUSAGE_QUERY_LEGACYBUMPMAP,
1185 0 /* ResourceType */,
1189 DDPIXELFORMAT pformat;
1191 memset(&pformat, 0, sizeof(pformat));
1192 pformat.dwSize = sizeof(pformat);
1193 PixelFormat_WineD3DtoDD(&pformat, BumpFormatList[i]);
1195 TRACE("Enumerating WineD3DFormat %d\n", BumpFormatList[i]);
1196 hr = Callback(&pformat, Arg);
1197 if(hr != DDENUMRET_OK)
1199 TRACE("Format enumeration cancelled by application\n");
1200 LeaveCriticalSection(&ddraw_cs);
1205 TRACE("End of enumeration\n");
1206 LeaveCriticalSection(&ddraw_cs);
1210 static HRESULT WINAPI
1211 Thunk_IDirect3DDeviceImpl_3_EnumTextureFormats(IDirect3DDevice3 *iface,
1212 LPD3DENUMPIXELFORMATSCALLBACK Callback,
1215 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1216 TRACE_(ddraw_thunk)("(%p)->(%p,%p) thunking to IDirect3DDevice7 interface.\n", This, Callback, Arg);
1217 return IDirect3DDevice7_EnumTextureFormats(ICOM_INTERFACE(This, IDirect3DDevice7),
1222 /*****************************************************************************
1223 * IDirect3DDevice2::EnumTextureformats
1225 * EnumTextureFormats for Version 1 and 2, see
1226 * IDirect3DDevice7::EnumTexureFormats for a more detailed description.
1228 * This version has a different callback and does not enumerate FourCC
1231 *****************************************************************************/
1232 static HRESULT WINAPI
1233 IDirect3DDeviceImpl_2_EnumTextureFormats(IDirect3DDevice2 *iface,
1234 LPD3DENUMTEXTUREFORMATSCALLBACK Callback,
1237 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1241 WINED3DFORMAT FormatList[] = {
1243 WINED3DFMT_A8R8G8B8,
1244 WINED3DFMT_X8R8G8B8,
1248 WINED3DFMT_A1R5G5B5,
1249 WINED3DFMT_A4R4G4B4,
1251 WINED3DFMT_X1R5G5B5,
1255 /* FOURCC codes - Not in this version*/
1258 TRACE("(%p)->(%p,%p): Relay\n", This, Callback, Arg);
1261 return DDERR_INVALIDPARAMS;
1263 EnterCriticalSection(&ddraw_cs);
1264 for(i = 0; i < sizeof(FormatList) / sizeof(WINED3DFORMAT); i++)
1266 hr = IWineD3D_CheckDeviceFormat(This->ddraw->wineD3D,
1269 0 /* AdapterFormat */,
1271 0 /* ResourceType */,
1275 DDSURFACEDESC sdesc;
1277 memset(&sdesc, 0, sizeof(sdesc));
1278 sdesc.dwSize = sizeof(sdesc);
1279 sdesc.dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
1280 sdesc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1281 sdesc.ddpfPixelFormat.dwSize = sizeof(sdesc.ddpfPixelFormat);
1282 PixelFormat_WineD3DtoDD(&sdesc.ddpfPixelFormat, FormatList[i]);
1284 TRACE("Enumerating WineD3DFormat %d\n", FormatList[i]);
1285 hr = Callback(&sdesc, Arg);
1286 if(hr != DDENUMRET_OK)
1288 TRACE("Format enumeration cancelled by application\n");
1289 LeaveCriticalSection(&ddraw_cs);
1294 TRACE("End of enumeration\n");
1295 LeaveCriticalSection(&ddraw_cs);
1299 static HRESULT WINAPI
1300 Thunk_IDirect3DDeviceImpl_1_EnumTextureFormats(IDirect3DDevice *iface,
1301 LPD3DENUMTEXTUREFORMATSCALLBACK Callback,
1304 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1305 TRACE_(ddraw_thunk)("(%p)->(%p,%p) thunking to IDirect3DDevice2 interface.\n", This, Callback, Arg);
1306 return IDirect3DDevice2_EnumTextureFormats(ICOM_INTERFACE(This, IDirect3DDevice2),
1311 /*****************************************************************************
1312 * IDirect3DDevice::CreateMatrix
1314 * Creates a matrix handle. A handle is created and memory for a D3DMATRIX is
1315 * allocated for the handle.
1320 * D3DMatHandle: Address to return the handle at
1324 * DDERR_INVALIDPARAMS if D3DMatHandle = NULL
1326 *****************************************************************************/
1327 static HRESULT WINAPI
1328 IDirect3DDeviceImpl_1_CreateMatrix(IDirect3DDevice *iface, D3DMATRIXHANDLE *D3DMatHandle)
1330 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1332 TRACE("(%p)->(%p)\n", This, D3DMatHandle);
1335 return DDERR_INVALIDPARAMS;
1337 Matrix = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(D3DMATRIX));
1340 ERR("Out of memory when allocating a D3DMATRIX\n");
1341 return DDERR_OUTOFMEMORY;
1344 EnterCriticalSection(&ddraw_cs);
1345 *D3DMatHandle = IDirect3DDeviceImpl_CreateHandle(This);
1346 if(!(*D3DMatHandle))
1348 ERR("Failed to create a matrix handle\n");
1349 HeapFree(GetProcessHeap(), 0, Matrix);
1350 LeaveCriticalSection(&ddraw_cs);
1351 return DDERR_OUTOFMEMORY;
1353 This->Handles[(DWORD) *D3DMatHandle - 1].ptr = Matrix;
1354 This->Handles[(DWORD) *D3DMatHandle - 1].type = DDrawHandle_Matrix;
1355 TRACE(" returning matrix handle %d\n", *D3DMatHandle);
1357 LeaveCriticalSection(&ddraw_cs);
1361 /*****************************************************************************
1362 * IDirect3DDevice::SetMatrix
1364 * Sets a matrix for a matrix handle. The matrix is copied into the memory
1365 * allocated for the handle
1370 * D3DMatHandle: Handle to set the matrix to
1371 * D3DMatrix: Matrix to set
1375 * DDERR_INVALIDPARAMS if the handle of the matrix is invalid or the matrix
1378 *****************************************************************************/
1379 static HRESULT WINAPI
1380 IDirect3DDeviceImpl_1_SetMatrix(IDirect3DDevice *iface,
1381 D3DMATRIXHANDLE D3DMatHandle,
1382 D3DMATRIX *D3DMatrix)
1384 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1385 TRACE("(%p)->(%08x,%p)\n", This, (DWORD) D3DMatHandle, D3DMatrix);
1387 if( (!D3DMatHandle) || (!D3DMatrix) )
1388 return DDERR_INVALIDPARAMS;
1390 EnterCriticalSection(&ddraw_cs);
1391 if(D3DMatHandle > This->numHandles)
1393 ERR("Handle %d out of range\n", D3DMatHandle);
1394 LeaveCriticalSection(&ddraw_cs);
1395 return DDERR_INVALIDPARAMS;
1397 else if(This->Handles[D3DMatHandle - 1].type != DDrawHandle_Matrix)
1399 ERR("Handle %d is not a matrix handle\n", D3DMatHandle);
1400 LeaveCriticalSection(&ddraw_cs);
1401 return DDERR_INVALIDPARAMS;
1405 dump_D3DMATRIX(D3DMatrix);
1407 *((D3DMATRIX *) This->Handles[D3DMatHandle - 1].ptr) = *D3DMatrix;
1409 if(This->world == D3DMatHandle)
1411 IWineD3DDevice_SetTransform(This->wineD3DDevice,
1412 WINED3DTS_WORLDMATRIX(0),
1413 (WINED3DMATRIX *) D3DMatrix);
1415 if(This->view == D3DMatHandle)
1417 IWineD3DDevice_SetTransform(This->wineD3DDevice,
1419 (WINED3DMATRIX *) D3DMatrix);
1421 if(This->proj == D3DMatHandle)
1423 IWineD3DDevice_SetTransform(This->wineD3DDevice,
1424 WINED3DTS_PROJECTION,
1425 (WINED3DMATRIX *) D3DMatrix);
1428 LeaveCriticalSection(&ddraw_cs);
1432 /*****************************************************************************
1433 * IDirect3DDevice::SetMatrix
1435 * Returns the content of a D3DMATRIX handle
1440 * D3DMatHandle: Matrix handle to read the content from
1441 * D3DMatrix: Address to store the content at
1445 * DDERR_INVALIDPARAMS if D3DMatHandle is invalid or D3DMatrix is NULL
1447 *****************************************************************************/
1448 static HRESULT WINAPI
1449 IDirect3DDeviceImpl_1_GetMatrix(IDirect3DDevice *iface,
1450 D3DMATRIXHANDLE D3DMatHandle,
1451 D3DMATRIX *D3DMatrix)
1453 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1454 TRACE("(%p)->(%08x,%p)\n", This, (DWORD) D3DMatHandle, D3DMatrix);
1457 return DDERR_INVALIDPARAMS;
1459 return DDERR_INVALIDPARAMS;
1461 EnterCriticalSection(&ddraw_cs);
1462 if(D3DMatHandle > This->numHandles)
1464 ERR("Handle %d out of range\n", D3DMatHandle);
1465 LeaveCriticalSection(&ddraw_cs);
1466 return DDERR_INVALIDPARAMS;
1468 else if(This->Handles[D3DMatHandle - 1].type != DDrawHandle_Matrix)
1470 ERR("Handle %d is not a matrix handle\n", D3DMatHandle);
1471 LeaveCriticalSection(&ddraw_cs);
1472 return DDERR_INVALIDPARAMS;
1475 /* The handle is simply a pointer to a D3DMATRIX structure */
1476 *D3DMatrix = *((D3DMATRIX *) This->Handles[D3DMatHandle - 1].ptr);
1478 LeaveCriticalSection(&ddraw_cs);
1482 /*****************************************************************************
1483 * IDirect3DDevice::DeleteMatrix
1485 * Destroys a Matrix handle. Frees the memory and unsets the handle data
1490 * D3DMatHandle: Handle to destroy
1494 * DDERR_INVALIDPARAMS if D3DMatHandle is invalid
1496 *****************************************************************************/
1497 static HRESULT WINAPI
1498 IDirect3DDeviceImpl_1_DeleteMatrix(IDirect3DDevice *iface,
1499 D3DMATRIXHANDLE D3DMatHandle)
1501 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1502 TRACE("(%p)->(%08x)\n", This, (DWORD) D3DMatHandle);
1505 return DDERR_INVALIDPARAMS;
1507 EnterCriticalSection(&ddraw_cs);
1508 if(D3DMatHandle > This->numHandles)
1510 ERR("Handle %d out of range\n", D3DMatHandle);
1511 LeaveCriticalSection(&ddraw_cs);
1512 return DDERR_INVALIDPARAMS;
1514 else if(This->Handles[D3DMatHandle - 1].type != DDrawHandle_Matrix)
1516 ERR("Handle %d is not a matrix handle\n", D3DMatHandle);
1517 LeaveCriticalSection(&ddraw_cs);
1518 return DDERR_INVALIDPARAMS;
1521 HeapFree(GetProcessHeap(), 0, This->Handles[D3DMatHandle - 1].ptr);
1522 This->Handles[D3DMatHandle - 1].ptr = NULL;
1523 This->Handles[D3DMatHandle - 1].type = DDrawHandle_Unknown;
1525 LeaveCriticalSection(&ddraw_cs);
1529 /*****************************************************************************
1530 * IDirect3DDevice7::BeginScene
1532 * This method must be called before any rendering is performed.
1533 * IDirect3DDevice::EndScene has to be called after the scene is complete
1535 * Version 1, 2, 3 and 7
1538 * D3D_OK on success, for details see IWineD3DDevice::BeginScene
1539 * D3DERR_SCENE_IN_SCENE if WineD3D returns an error(Only in case of an already
1542 *****************************************************************************/
1543 static HRESULT WINAPI
1544 IDirect3DDeviceImpl_7_BeginScene(IDirect3DDevice7 *iface)
1546 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1548 TRACE("(%p): Relay\n", This);
1550 EnterCriticalSection(&ddraw_cs);
1551 hr = IWineD3DDevice_BeginScene(This->wineD3DDevice);
1552 LeaveCriticalSection(&ddraw_cs);
1553 if(hr == WINED3D_OK) return D3D_OK;
1554 else return D3DERR_SCENE_IN_SCENE; /* TODO: Other possible causes of failure */
1557 static HRESULT WINAPI
1558 Thunk_IDirect3DDeviceImpl_3_BeginScene(IDirect3DDevice3 *iface)
1560 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1561 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1562 return IDirect3DDevice7_BeginScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1565 static HRESULT WINAPI
1566 Thunk_IDirect3DDeviceImpl_2_BeginScene(IDirect3DDevice2 *iface)
1568 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1569 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1570 return IDirect3DDevice7_BeginScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1573 static HRESULT WINAPI
1574 Thunk_IDirect3DDeviceImpl_1_BeginScene(IDirect3DDevice *iface)
1576 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1577 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1578 return IDirect3DDevice7_BeginScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1581 /*****************************************************************************
1582 * IDirect3DDevice7::EndScene
1584 * Ends a scene that has been begun with IDirect3DDevice7::BeginScene.
1585 * This method must be called after rendering is finished.
1587 * Version 1, 2, 3 and 7
1590 * D3D_OK on success, for details see IWineD3DDevice::EndScene
1591 * D3DERR_SCENE_NOT_IN_SCENE is returned if WineD3D returns an error. It does
1592 * that only if the scene was already ended.
1594 *****************************************************************************/
1595 static HRESULT WINAPI
1596 IDirect3DDeviceImpl_7_EndScene(IDirect3DDevice7 *iface)
1598 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1600 TRACE("(%p): Relay\n", This);
1602 EnterCriticalSection(&ddraw_cs);
1603 hr = IWineD3DDevice_EndScene(This->wineD3DDevice);
1604 LeaveCriticalSection(&ddraw_cs);
1605 if(hr == WINED3D_OK) return D3D_OK;
1606 else return D3DERR_SCENE_NOT_IN_SCENE;
1609 static HRESULT WINAPI
1610 Thunk_IDirect3DDeviceImpl_3_EndScene(IDirect3DDevice3 *iface)
1612 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1613 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1614 return IDirect3DDevice7_EndScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1617 static HRESULT WINAPI
1618 Thunk_IDirect3DDeviceImpl_2_EndScene(IDirect3DDevice2 *iface)
1620 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1621 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1622 return IDirect3DDevice7_EndScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1625 static HRESULT WINAPI
1626 Thunk_IDirect3DDeviceImpl_1_EndScene(IDirect3DDevice *iface)
1628 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1629 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1630 return IDirect3DDevice7_EndScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1633 /*****************************************************************************
1634 * IDirect3DDevice7::GetDirect3D
1636 * Returns the IDirect3D(= interface to the DirectDraw object) used to create
1640 * Direct3D7: Address to store the interface pointer at
1644 * DDERR_INVALIDPARAMS if Direct3D7 == NULL
1646 *****************************************************************************/
1647 static HRESULT WINAPI
1648 IDirect3DDeviceImpl_7_GetDirect3D(IDirect3DDevice7 *iface,
1649 IDirect3D7 **Direct3D7)
1651 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1652 TRACE("(%p)->(%p)\n", This, Direct3D7);
1655 return DDERR_INVALIDPARAMS;
1657 *Direct3D7 = ICOM_INTERFACE(This->ddraw, IDirect3D7);
1658 IDirect3D7_AddRef(*Direct3D7);
1660 TRACE(" returning interface %p\n", *Direct3D7);
1664 static HRESULT WINAPI
1665 Thunk_IDirect3DDeviceImpl_3_GetDirect3D(IDirect3DDevice3 *iface,
1666 IDirect3D3 **Direct3D3)
1668 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1670 IDirect3D7 *ret_ptr;
1672 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, Direct3D3);
1673 ret = IDirect3DDevice7_GetDirect3D(ICOM_INTERFACE(This, IDirect3DDevice7),
1677 *Direct3D3 = COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D7, IDirect3D3, ret_ptr);
1678 TRACE(" returning interface %p\n", *Direct3D3);
1682 static HRESULT WINAPI
1683 Thunk_IDirect3DDeviceImpl_2_GetDirect3D(IDirect3DDevice2 *iface,
1684 IDirect3D2 **Direct3D2)
1686 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1688 IDirect3D7 *ret_ptr;
1690 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, Direct3D2);
1691 ret = IDirect3DDevice7_GetDirect3D(ICOM_INTERFACE(This, IDirect3DDevice7),
1695 *Direct3D2 = COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D7, IDirect3D2, ret_ptr);
1696 TRACE(" returning interface %p\n", *Direct3D2);
1700 static HRESULT WINAPI
1701 Thunk_IDirect3DDeviceImpl_1_GetDirect3D(IDirect3DDevice *iface,
1702 IDirect3D **Direct3D)
1704 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1706 IDirect3D7 *ret_ptr;
1708 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, Direct3D);
1709 ret = IDirect3DDevice7_GetDirect3D(ICOM_INTERFACE(This, IDirect3DDevice7),
1713 *Direct3D = COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D7, IDirect3D, ret_ptr);
1714 TRACE(" returning interface %p\n", *Direct3D);
1718 /*****************************************************************************
1719 * IDirect3DDevice3::SetCurrentViewport
1721 * Sets a Direct3DViewport as the current viewport.
1722 * For the thunks note that all viewport interface versions are equal
1725 * Direct3DViewport3: The viewport to set
1731 * (Is a NULL viewport valid?)
1733 *****************************************************************************/
1734 static HRESULT WINAPI
1735 IDirect3DDeviceImpl_3_SetCurrentViewport(IDirect3DDevice3 *iface,
1736 IDirect3DViewport3 *Direct3DViewport3)
1738 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1739 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport3);
1740 TRACE("(%p)->(%p)\n", This, Direct3DViewport3);
1742 EnterCriticalSection(&ddraw_cs);
1743 /* Do nothing if the specified viewport is the same as the current one */
1744 if (This->current_viewport == vp )
1746 LeaveCriticalSection(&ddraw_cs);
1750 /* Should check if the viewport was added or not */
1752 /* Release previous viewport and AddRef the new one */
1753 if (This->current_viewport)
1755 TRACE("ViewportImpl is at %p, interface is at %p\n", This->current_viewport, ICOM_INTERFACE(This->current_viewport, IDirect3DViewport3));
1756 IDirect3DViewport3_Release( ICOM_INTERFACE(This->current_viewport, IDirect3DViewport3) );
1758 IDirect3DViewport3_AddRef(Direct3DViewport3);
1760 /* Set this viewport as the current viewport */
1761 This->current_viewport = vp;
1763 /* Activate this viewport */
1764 This->current_viewport->active_device = This;
1765 This->current_viewport->activate(This->current_viewport);
1767 LeaveCriticalSection(&ddraw_cs);
1771 static HRESULT WINAPI
1772 Thunk_IDirect3DDeviceImpl_2_SetCurrentViewport(IDirect3DDevice2 *iface,
1773 IDirect3DViewport2 *Direct3DViewport2)
1775 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1776 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport2);
1777 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, vp);
1778 return IDirect3DDevice3_SetCurrentViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
1779 ICOM_INTERFACE(vp, IDirect3DViewport3));
1782 /*****************************************************************************
1783 * IDirect3DDevice3::GetCurrentViewport
1785 * Returns the currently active viewport.
1790 * Direct3DViewport3: Address to return the interface pointer at
1794 * DDERR_INVALIDPARAMS if Direct3DViewport == NULL
1796 *****************************************************************************/
1797 static HRESULT WINAPI
1798 IDirect3DDeviceImpl_3_GetCurrentViewport(IDirect3DDevice3 *iface,
1799 IDirect3DViewport3 **Direct3DViewport3)
1801 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1802 TRACE("(%p)->(%p)\n", This, Direct3DViewport3);
1804 if(!Direct3DViewport3)
1805 return DDERR_INVALIDPARAMS;
1807 EnterCriticalSection(&ddraw_cs);
1808 *Direct3DViewport3 = ICOM_INTERFACE(This->current_viewport, IDirect3DViewport3);
1810 /* AddRef the returned viewport */
1811 if(*Direct3DViewport3) IDirect3DViewport3_AddRef(*Direct3DViewport3);
1813 TRACE(" returning interface %p\n", *Direct3DViewport3);
1815 LeaveCriticalSection(&ddraw_cs);
1819 static HRESULT WINAPI
1820 Thunk_IDirect3DDeviceImpl_2_GetCurrentViewport(IDirect3DDevice2 *iface,
1821 IDirect3DViewport2 **Direct3DViewport2)
1823 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1825 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, Direct3DViewport2);
1826 hr = IDirect3DDevice3_GetCurrentViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
1827 (IDirect3DViewport3 **) Direct3DViewport2);
1828 if(hr != D3D_OK) return hr;
1829 *Direct3DViewport2 = (IDirect3DViewport2 *) COM_INTERFACE_CAST(IDirect3DViewportImpl, IDirect3DViewport3, IDirect3DViewport3, *Direct3DViewport2);
1833 /*****************************************************************************
1834 * IDirect3DDevice7::SetRenderTarget
1836 * Sets the render target for the Direct3DDevice.
1837 * For the thunks note that IDirectDrawSurface7 == IDirectDrawSurface4 and
1838 * IDirectDrawSurface3 == IDirectDrawSurface
1840 * Version 2, 3 and 7
1843 * NewTarget: Pointer to an IDirectDrawSurface7 interface to set as the new
1848 * D3D_OK on success, for details see IWineD3DDevice::SetRenderTarget
1850 *****************************************************************************/
1851 static HRESULT WINAPI
1852 IDirect3DDeviceImpl_7_SetRenderTarget(IDirect3DDevice7 *iface,
1853 IDirectDrawSurface7 *NewTarget,
1856 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1857 IDirectDrawSurfaceImpl *Target = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, NewTarget);
1859 TRACE("(%p)->(%p,%08x): Relay\n", This, NewTarget, Flags);
1861 EnterCriticalSection(&ddraw_cs);
1862 /* Flags: Not used */
1864 hr = IWineD3DDevice_SetRenderTarget(This->wineD3DDevice,
1866 Target ? Target->WineD3DSurface : NULL);
1869 LeaveCriticalSection(&ddraw_cs);
1872 IDirectDrawSurface7_AddRef(NewTarget);
1873 IDirectDrawSurface7_Release(ICOM_INTERFACE(This->target, IDirectDrawSurface7));
1874 This->target = Target;
1875 IDirect3DDeviceImpl_UpdateDepthStencil(This);
1876 LeaveCriticalSection(&ddraw_cs);
1880 static HRESULT WINAPI
1881 Thunk_IDirect3DDeviceImpl_3_SetRenderTarget(IDirect3DDevice3 *iface,
1882 IDirectDrawSurface4 *NewRenderTarget,
1885 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1886 IDirectDrawSurfaceImpl *Target = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, NewRenderTarget);
1887 TRACE_(ddraw_thunk)("(%p)->(%p,%08x) thunking to IDirect3DDevice7 interface.\n", This, Target, Flags);
1888 return IDirect3DDevice7_SetRenderTarget(ICOM_INTERFACE(This, IDirect3DDevice7),
1889 ICOM_INTERFACE(Target, IDirectDrawSurface7),
1893 static HRESULT WINAPI
1894 Thunk_IDirect3DDeviceImpl_2_SetRenderTarget(IDirect3DDevice2 *iface,
1895 IDirectDrawSurface *NewRenderTarget,
1898 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1899 IDirectDrawSurfaceImpl *Target = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface3, NewRenderTarget);
1900 TRACE_(ddraw_thunk)("(%p)->(%p,%08x) thunking to IDirect3DDevice7 interface.\n", This, Target, Flags);
1901 return IDirect3DDevice7_SetRenderTarget(ICOM_INTERFACE(This, IDirect3DDevice7),
1902 ICOM_INTERFACE(Target, IDirectDrawSurface7),
1906 /*****************************************************************************
1907 * IDirect3DDevice7::GetRenderTarget
1909 * Returns the current render target.
1910 * This is handled locally, because the WineD3D render target's parent
1913 * Version 2, 3 and 7
1916 * RenderTarget: Address to store the surface interface pointer
1920 * DDERR_INVALIDPARAMS if RenderTarget == NULL
1922 *****************************************************************************/
1923 static HRESULT WINAPI
1924 IDirect3DDeviceImpl_7_GetRenderTarget(IDirect3DDevice7 *iface,
1925 IDirectDrawSurface7 **RenderTarget)
1927 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1928 TRACE("(%p)->(%p): Relay\n", This, RenderTarget);
1931 return DDERR_INVALIDPARAMS;
1933 EnterCriticalSection(&ddraw_cs);
1934 *RenderTarget = ICOM_INTERFACE(This->target, IDirectDrawSurface7);
1935 IDirectDrawSurface7_AddRef(*RenderTarget);
1937 LeaveCriticalSection(&ddraw_cs);
1941 static HRESULT WINAPI
1942 Thunk_IDirect3DDeviceImpl_3_GetRenderTarget(IDirect3DDevice3 *iface,
1943 IDirectDrawSurface4 **RenderTarget)
1945 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1947 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, RenderTarget);
1948 hr = IDirect3DDevice7_GetRenderTarget(ICOM_INTERFACE(This, IDirect3DDevice7),
1949 (IDirectDrawSurface7 **) RenderTarget);
1950 if(hr != D3D_OK) return hr;
1951 *RenderTarget = (IDirectDrawSurface4 *) COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7, IDirectDrawSurface7, *RenderTarget);
1955 static HRESULT WINAPI
1956 Thunk_IDirect3DDeviceImpl_2_GetRenderTarget(IDirect3DDevice2 *iface,
1957 IDirectDrawSurface **RenderTarget)
1959 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1961 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, RenderTarget);
1962 hr = IDirect3DDevice7_GetRenderTarget(ICOM_INTERFACE(This, IDirect3DDevice7),
1963 (IDirectDrawSurface7 **) RenderTarget);
1964 if(hr != D3D_OK) return hr;
1965 *RenderTarget = (IDirectDrawSurface *) COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7, IDirectDrawSurface3, *RenderTarget);
1969 /*****************************************************************************
1970 * IDirect3DDevice3::Begin
1972 * Begins a description block of vertices. This is similar to glBegin()
1973 * and glEnd(). After a call to IDirect3DDevice3::End, the vertices
1974 * described with IDirect3DDevice::Vertex are drawn.
1979 * PrimitiveType: The type of primitives to draw
1980 * VertexTypeDesc: A flexible vertex format description of the vertices
1981 * Flags: Some flags..
1986 *****************************************************************************/
1987 static HRESULT WINAPI
1988 IDirect3DDeviceImpl_3_Begin(IDirect3DDevice3 *iface,
1989 D3DPRIMITIVETYPE PrimitiveType,
1990 DWORD VertexTypeDesc,
1993 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1994 TRACE("(%p)->(%d,%d,%08x)\n", This, PrimitiveType, VertexTypeDesc, Flags);
1996 EnterCriticalSection(&ddraw_cs);
1997 This->primitive_type = PrimitiveType;
1998 This->vertex_type = VertexTypeDesc;
1999 This->render_flags = Flags;
2000 This->vertex_size = get_flexible_vertex_size(This->vertex_type);
2001 This->nb_vertices = 0;
2002 LeaveCriticalSection(&ddraw_cs);
2007 static HRESULT WINAPI
2008 Thunk_IDirect3DDeviceImpl_2_Begin(IDirect3DDevice2 *iface,
2009 D3DPRIMITIVETYPE d3dpt,
2010 D3DVERTEXTYPE dwVertexTypeDesc,
2014 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2015 TRACE_(ddraw_thunk)("(%p/%p)->(%08x,%08x,%08x): Thunking to IDirect3DDevice3\n", This, iface, d3dpt, dwVertexTypeDesc, dwFlags);
2017 switch(dwVertexTypeDesc)
2019 case D3DVT_VERTEX: FVF = D3DFVF_VERTEX; break;
2020 case D3DVT_LVERTEX: FVF = D3DFVF_LVERTEX; break;
2021 case D3DVT_TLVERTEX: FVF = D3DFVF_TLVERTEX; break;
2023 ERR("Unexpected vertex type %d\n", dwVertexTypeDesc);
2024 return DDERR_INVALIDPARAMS; /* Should never happen */
2027 return IDirect3DDevice3_Begin(ICOM_INTERFACE(This, IDirect3DDevice3),
2033 /*****************************************************************************
2034 * IDirect3DDevice3::BeginIndexed
2036 * Draws primitives based on vertices in a vertex array which are specified
2042 * PrimitiveType: Primitive type to draw
2043 * VertexType: A FVF description of the vertex format
2044 * Vertices: pointer to an array containing the vertices
2045 * NumVertices: The number of vertices in the vertex array
2046 * Flags: Some flags ...
2049 * D3D_OK, because it's a stub
2051 *****************************************************************************/
2052 static HRESULT WINAPI
2053 IDirect3DDeviceImpl_3_BeginIndexed(IDirect3DDevice3 *iface,
2054 D3DPRIMITIVETYPE PrimitiveType,
2060 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2061 FIXME("(%p)->(%08x,%08x,%p,%08x,%08x): stub!\n", This, PrimitiveType, VertexType, Vertices, NumVertices, Flags);
2066 static HRESULT WINAPI
2067 Thunk_IDirect3DDeviceImpl_2_BeginIndexed(IDirect3DDevice2 *iface,
2068 D3DPRIMITIVETYPE d3dptPrimitiveType,
2069 D3DVERTEXTYPE d3dvtVertexType,
2071 DWORD dwNumVertices,
2075 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2076 TRACE_(ddraw_thunk)("(%p/%p)->(%08x,%08x,%p,%08x,%08x): Thunking to IDirect3DDevice3\n", This, iface, d3dptPrimitiveType, d3dvtVertexType, lpvVertices, dwNumVertices, dwFlags);
2078 switch(d3dvtVertexType)
2080 case D3DVT_VERTEX: FVF = D3DFVF_VERTEX; break;
2081 case D3DVT_LVERTEX: FVF = D3DFVF_LVERTEX; break;
2082 case D3DVT_TLVERTEX: FVF = D3DFVF_TLVERTEX; break;
2084 ERR("Unexpected vertex type %d\n", d3dvtVertexType);
2085 return DDERR_INVALIDPARAMS; /* Should never happen */
2088 return IDirect3DDevice3_BeginIndexed(ICOM_INTERFACE(This,IDirect3DDevice3),
2096 /*****************************************************************************
2097 * IDirect3DDevice3::Vertex
2099 * Draws a vertex as described by IDirect3DDevice3::Begin. It places all
2100 * drawn vertices in a vertex buffer. If the buffer is too small, its
2101 * size is increased.
2106 * Vertex: Pointer to the vertex
2109 * D3D_OK, on success
2110 * DDERR_INVALIDPARAMS if Vertex is NULL
2112 *****************************************************************************/
2113 static HRESULT WINAPI
2114 IDirect3DDeviceImpl_3_Vertex(IDirect3DDevice3 *iface,
2117 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2118 TRACE("(%p)->(%p)\n", This, Vertex);
2121 return DDERR_INVALIDPARAMS;
2123 EnterCriticalSection(&ddraw_cs);
2124 if ((This->nb_vertices+1)*This->vertex_size > This->buffer_size)
2127 This->buffer_size = This->buffer_size ? This->buffer_size * 2 : This->vertex_size * 3;
2128 old_buffer = This->vertex_buffer;
2129 This->vertex_buffer = HeapAlloc(GetProcessHeap(), 0, This->buffer_size);
2132 CopyMemory(This->vertex_buffer, old_buffer, This->nb_vertices * This->vertex_size);
2133 HeapFree(GetProcessHeap(), 0, old_buffer);
2137 CopyMemory(This->vertex_buffer + This->nb_vertices++ * This->vertex_size, Vertex, This->vertex_size);
2139 LeaveCriticalSection(&ddraw_cs);
2143 static HRESULT WINAPI
2144 Thunk_IDirect3DDeviceImpl_2_Vertex(IDirect3DDevice2 *iface,
2147 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2148 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, lpVertexType);
2149 return IDirect3DDevice3_Vertex(ICOM_INTERFACE(This, IDirect3DDevice3),
2153 /*****************************************************************************
2154 * IDirect3DDevice3::Index
2156 * Specifies an index to a vertex to be drawn. The vertex array has to
2157 * be specified with BeginIndexed first.
2160 * VertexIndex: The index of the vertex to draw
2163 * D3D_OK because it's a stub
2165 *****************************************************************************/
2166 static HRESULT WINAPI
2167 IDirect3DDeviceImpl_3_Index(IDirect3DDevice3 *iface,
2170 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2171 FIXME("(%p)->(%04x): stub!\n", This, VertexIndex);
2175 static HRESULT WINAPI
2176 Thunk_IDirect3DDeviceImpl_2_Index(IDirect3DDevice2 *iface,
2179 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2180 TRACE_(ddraw_thunk)("(%p)->(%04x) thunking to IDirect3DDevice3 interface.\n", This, wVertexIndex);
2181 return IDirect3DDevice3_Index(ICOM_INTERFACE(This, IDirect3DDevice3),
2185 /*****************************************************************************
2186 * IDirect3DDevice3::End
2188 * Ends a draw begun with IDirect3DDevice3::Begin or
2189 * IDirect3DDevice::BeginIndexed. The vertices specified with
2190 * IDirect3DDevice::Vertex or IDirect3DDevice::Index are drawn using
2191 * the IDirect3DDevice7::DrawPrimitive method. So far only
2192 * non-indexed mode is supported
2197 * Flags: Some flags, as usual. Don't know which are defined
2200 * The return value of IDirect3DDevice7::DrawPrimitive
2202 *****************************************************************************/
2203 static HRESULT WINAPI
2204 IDirect3DDeviceImpl_3_End(IDirect3DDevice3 *iface,
2207 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2208 TRACE("(%p)->(%08x)\n", This, Flags);
2210 return IDirect3DDevice7_DrawPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
2211 This->primitive_type, This->vertex_type,
2212 This->vertex_buffer, This->nb_vertices,
2213 This->render_flags);
2216 static HRESULT WINAPI
2217 Thunk_IDirect3DDeviceImpl_2_End(IDirect3DDevice2 *iface,
2220 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2221 TRACE_(ddraw_thunk)("(%p)->(%08x) thunking to IDirect3DDevice3 interface.\n", This, dwFlags);
2222 return IDirect3DDevice3_End(ICOM_INTERFACE(This, IDirect3DDevice3),
2226 /*****************************************************************************
2227 * IDirect3DDevice7::GetRenderState
2229 * Returns the value of a render state. The possible render states are
2230 * defined in include/d3dtypes.h
2232 * Version 2, 3 and 7
2235 * RenderStateType: Render state to return the current setting of
2236 * Value: Address to store the value at
2239 * D3D_OK on success, for details see IWineD3DDevice::GetRenderState
2240 * DDERR_INVALIDPARAMS if Value == NULL
2242 *****************************************************************************/
2243 static HRESULT WINAPI
2244 IDirect3DDeviceImpl_7_GetRenderState(IDirect3DDevice7 *iface,
2245 D3DRENDERSTATETYPE RenderStateType,
2248 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2250 TRACE("(%p)->(%08x,%p): Relay\n", This, RenderStateType, Value);
2253 return DDERR_INVALIDPARAMS;
2255 EnterCriticalSection(&ddraw_cs);
2256 switch(RenderStateType)
2258 case D3DRENDERSTATE_TEXTUREHANDLE:
2260 /* This state is wrapped to SetTexture in SetRenderState, so
2261 * it has to be wrapped to GetTexture here
2263 IWineD3DBaseTexture *tex = NULL;
2266 hr = IWineD3DDevice_GetTexture(This->wineD3DDevice,
2270 if(hr == WINED3D_OK && tex)
2272 IDirectDrawSurface7 *parent = NULL;
2273 hr = IWineD3DBaseTexture_GetParent(tex,
2274 (IUnknown **) &parent);
2277 /* The parent of the texture is the IDirectDrawSurface7 interface
2278 * of the ddraw surface
2280 IDirectDrawSurfaceImpl *texImpl = ICOM_OBJECT(IDirectDrawSurfaceImpl,
2281 IDirectDrawSurface7,
2283 *Value = texImpl->Handle;
2284 IDirectDrawSurface7_Release(parent);
2286 IWineD3DBaseTexture_Release(tex);
2291 case D3DRENDERSTATE_TEXTUREMAG:
2293 WINED3DTEXTUREFILTERTYPE tex_mag;
2295 hr = IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
2296 0, WINED3DSAMP_MAGFILTER,
2301 case WINED3DTEXF_POINT:
2302 *Value = D3DFILTER_NEAREST;
2304 case WINED3DTEXF_LINEAR:
2305 *Value = D3DFILTER_LINEAR;
2308 ERR("Unhandled texture mag %d !\n",tex_mag);
2314 case D3DRENDERSTATE_TEXTUREMIN:
2316 WINED3DTEXTUREFILTERTYPE tex_min;
2318 hr = IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
2319 0, WINED3DSAMP_MINFILTER,
2324 case WINED3DTEXF_POINT:
2325 *Value = D3DFILTER_NEAREST;
2327 case WINED3DTEXF_LINEAR:
2328 *Value = D3DFILTER_LINEAR;
2331 ERR("Unhandled texture mag %d !\n",tex_min);
2337 case D3DRENDERSTATE_TEXTUREADDRESS:
2338 case D3DRENDERSTATE_TEXTUREADDRESSU:
2339 hr = IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
2340 0, WINED3DSAMP_ADDRESSU,
2343 case D3DRENDERSTATE_TEXTUREADDRESSV:
2344 hr = IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
2345 0, WINED3DSAMP_ADDRESSV,
2350 /* FIXME: Unhandled: D3DRENDERSTATE_STIPPLEPATTERN00 - 31 */
2351 hr = IWineD3DDevice_GetRenderState(This->wineD3DDevice,
2355 LeaveCriticalSection(&ddraw_cs);
2359 static HRESULT WINAPI
2360 Thunk_IDirect3DDeviceImpl_3_GetRenderState(IDirect3DDevice3 *iface,
2361 D3DRENDERSTATETYPE dwRenderStateType,
2362 DWORD *lpdwRenderState)
2364 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2365 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, dwRenderStateType, lpdwRenderState);
2366 return IDirect3DDevice7_GetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2371 static HRESULT WINAPI
2372 Thunk_IDirect3DDeviceImpl_2_GetRenderState(IDirect3DDevice2 *iface,
2373 D3DRENDERSTATETYPE dwRenderStateType,
2374 DWORD *lpdwRenderState)
2376 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2377 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, dwRenderStateType, lpdwRenderState);
2378 return IDirect3DDevice7_GetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2383 /*****************************************************************************
2384 * IDirect3DDevice7::SetRenderState
2386 * Sets a render state. The possible render states are defined in
2387 * include/d3dtypes.h
2389 * Version 2, 3 and 7
2392 * RenderStateType: State to set
2393 * Value: Value to assign to that state
2396 * D3D_OK on success,
2397 * for details see IWineD3DDevice::SetRenderState
2399 *****************************************************************************/
2400 static HRESULT WINAPI
2401 IDirect3DDeviceImpl_7_SetRenderState(IDirect3DDevice7 *iface,
2402 D3DRENDERSTATETYPE RenderStateType,
2405 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2407 TRACE("(%p)->(%08x,%d): Relay\n", This, RenderStateType, Value);
2409 EnterCriticalSection(&ddraw_cs);
2410 /* Some render states need special care */
2411 switch(RenderStateType)
2413 case D3DRENDERSTATE_TEXTUREHANDLE:
2417 hr = IWineD3DDevice_SetTexture(This->wineD3DDevice,
2423 if(Value > This->numHandles)
2425 FIXME("Specified handle %d out of range\n", Value);
2426 hr = DDERR_INVALIDPARAMS;
2429 if(This->Handles[Value - 1].type != DDrawHandle_Texture)
2431 FIXME("Handle %d isn't a texture handle\n", Value);
2432 hr = DDERR_INVALIDPARAMS;
2437 IDirectDrawSurfaceImpl *surf = (IDirectDrawSurfaceImpl *) This->Handles[Value - 1].ptr;
2438 hr = IWineD3DDevice_SetTexture(This->wineD3DDevice,
2440 surf->wineD3DTexture);
2445 case D3DRENDERSTATE_TEXTUREMAG:
2447 WINED3DTEXTUREFILTERTYPE tex_mag = WINED3DTEXF_NONE;
2449 switch ((D3DTEXTUREFILTER) Value)
2451 case D3DFILTER_NEAREST:
2452 case D3DFILTER_LINEARMIPNEAREST:
2453 tex_mag = WINED3DTEXF_POINT;
2455 case D3DFILTER_LINEAR:
2456 case D3DFILTER_LINEARMIPLINEAR:
2457 tex_mag = WINED3DTEXF_LINEAR;
2460 ERR("Unhandled texture mag %d !\n",Value);
2463 hr = IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
2464 0, WINED3DSAMP_MAGFILTER,
2469 case D3DRENDERSTATE_TEXTUREMIN:
2471 WINED3DTEXTUREFILTERTYPE tex_min = WINED3DTEXF_NONE;
2472 WINED3DTEXTUREFILTERTYPE tex_mip = WINED3DTEXF_NONE;
2474 switch ((D3DTEXTUREFILTER) Value)
2476 case D3DFILTER_NEAREST:
2477 tex_min = WINED3DTEXF_POINT;
2479 case D3DFILTER_LINEAR:
2480 tex_min = WINED3DTEXF_LINEAR;
2482 case D3DFILTER_MIPNEAREST:
2483 tex_min = WINED3DTEXF_NONE;
2484 tex_mip = WINED3DTEXF_POINT;
2486 case D3DFILTER_MIPLINEAR:
2487 tex_min = WINED3DTEXF_NONE;
2488 tex_mip = WINED3DTEXF_LINEAR;
2490 case D3DFILTER_LINEARMIPNEAREST:
2491 tex_min = WINED3DTEXF_POINT;
2492 tex_mip = WINED3DTEXF_LINEAR;
2494 case D3DFILTER_LINEARMIPLINEAR:
2495 tex_min = WINED3DTEXF_LINEAR;
2496 tex_mip = WINED3DTEXF_LINEAR;
2500 ERR("Unhandled texture min %d !\n",Value);
2503 IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
2504 0, WINED3DSAMP_MIPFILTER,
2506 hr = IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
2507 0, WINED3DSAMP_MINFILTER,
2512 case D3DRENDERSTATE_TEXTUREADDRESS:
2513 IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
2514 0, WINED3DSAMP_ADDRESSV,
2517 case D3DRENDERSTATE_TEXTUREADDRESSU:
2518 hr = IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
2519 0, WINED3DSAMP_ADDRESSU,
2522 case D3DRENDERSTATE_TEXTUREADDRESSV:
2523 hr = IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
2524 0, WINED3DSAMP_ADDRESSV,
2528 case D3DRENDERSTATE_TEXTUREMAPBLEND:
2530 /* Old texture combine setup style, superseded by texture stage states
2531 * in D3D7. It is safe for us to wrap it to texture stage states.
2533 switch ( (D3DTEXTUREBLEND) Value)
2535 case D3DTBLEND_MODULATE:
2536 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLORARG1, WINED3DTA_TEXTURE);
2537 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAARG1, WINED3DTA_TEXTURE);
2538 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLORARG2, WINED3DTA_CURRENT);
2539 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLOROP, WINED3DTOP_MODULATE);
2540 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAOP, WINED3DTOP_SELECTARG1);
2543 case D3DTBLEND_MODULATEALPHA:
2544 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLORARG1, WINED3DTA_TEXTURE);
2545 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAARG1, WINED3DTA_TEXTURE);
2546 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLORARG2, WINED3DTA_CURRENT);
2547 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAARG2, WINED3DTA_CURRENT);
2548 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLOROP, WINED3DTOP_MODULATE);
2549 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAOP, WINED3DTOP_MODULATE);
2552 case D3DTBLEND_DECAL:
2553 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLORARG1, WINED3DTA_TEXTURE);
2554 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAARG1, WINED3DTA_TEXTURE);
2555 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLOROP, WINED3DTOP_SELECTARG1);
2556 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAOP, WINED3DTOP_SELECTARG1);
2559 case D3DTBLEND_DECALALPHA:
2560 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLORARG1, WINED3DTA_TEXTURE);
2561 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAARG1, WINED3DTA_TEXTURE);
2562 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAARG2, WINED3DTA_CURRENT);
2563 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLOROP, WINED3DTOP_SELECTARG1);
2564 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAOP, WINED3DTOP_MODULATE);
2568 ERR("Unhandled texture environment %d !\n",Value);
2576 /* FIXME: Unhandled: D3DRENDERSTATE_STIPPLEPATTERN00 - 31 */
2578 hr = IWineD3DDevice_SetRenderState(This->wineD3DDevice,
2583 LeaveCriticalSection(&ddraw_cs);
2587 static HRESULT WINAPI
2588 Thunk_IDirect3DDeviceImpl_3_SetRenderState(IDirect3DDevice3 *iface,
2589 D3DRENDERSTATETYPE RenderStateType,
2592 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2593 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, RenderStateType, Value);
2594 return IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2599 static HRESULT WINAPI
2600 Thunk_IDirect3DDeviceImpl_2_SetRenderState(IDirect3DDevice2 *iface,
2601 D3DRENDERSTATETYPE RenderStateType,
2604 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2605 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, RenderStateType, Value);
2606 return IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2611 /*****************************************************************************
2612 * Direct3DDevice3::SetLightState
2614 * Sets a light state for Direct3DDevice3 and Direct3DDevice2. The
2615 * light states are forwarded to Direct3DDevice7 render states
2620 * LightStateType: The light state to change
2621 * Value: The value to assign to that light state
2625 * DDERR_INVALIDPARAMS if the parameters were incorrect
2626 * Also check IDirect3DDevice7::SetRenderState
2628 *****************************************************************************/
2629 static HRESULT WINAPI
2630 IDirect3DDeviceImpl_3_SetLightState(IDirect3DDevice3 *iface,
2631 D3DLIGHTSTATETYPE LightStateType,
2634 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2637 TRACE("(%p)->(%08x,%08x)\n", This, LightStateType, Value);
2639 if (!LightStateType && (LightStateType > D3DLIGHTSTATE_COLORVERTEX))
2641 TRACE("Unexpected Light State Type\n");
2642 return DDERR_INVALIDPARAMS;
2645 EnterCriticalSection(&ddraw_cs);
2646 if (LightStateType == D3DLIGHTSTATE_MATERIAL /* 1 */)
2648 IDirect3DMaterialImpl *mat;
2650 if(Value == 0) mat = NULL;
2651 else if(Value > This->numHandles)
2653 ERR("Material handle out of range(%d)\n", Value);
2654 LeaveCriticalSection(&ddraw_cs);
2655 return DDERR_INVALIDPARAMS;
2657 else if(This->Handles[Value - 1].type != DDrawHandle_Material)
2659 ERR("Invalid handle %d\n", Value);
2660 LeaveCriticalSection(&ddraw_cs);
2661 return DDERR_INVALIDPARAMS;
2665 mat = (IDirect3DMaterialImpl *) This->Handles[Value - 1].ptr;
2670 TRACE(" activating material %p.\n", mat);
2675 FIXME(" D3DLIGHTSTATE_MATERIAL called with NULL material !!!\n");
2677 This->material = Value;
2679 else if (LightStateType == D3DLIGHTSTATE_COLORMODEL /* 3 */)
2684 ERR("DDCOLOR_MONO should not happen!\n");
2687 /* We are already in this mode */
2688 TRACE("Setting color model to RGB (no-op).\n");
2691 ERR("Unknown color model!\n");
2692 LeaveCriticalSection(&ddraw_cs);
2693 return DDERR_INVALIDPARAMS;
2698 D3DRENDERSTATETYPE rs;
2699 switch (LightStateType)
2701 case D3DLIGHTSTATE_AMBIENT: /* 2 */
2702 rs = D3DRENDERSTATE_AMBIENT;
2704 case D3DLIGHTSTATE_FOGMODE: /* 4 */
2705 rs = D3DRENDERSTATE_FOGVERTEXMODE;
2707 case D3DLIGHTSTATE_FOGSTART: /* 5 */
2708 rs = D3DRENDERSTATE_FOGSTART;
2710 case D3DLIGHTSTATE_FOGEND: /* 6 */
2711 rs = D3DRENDERSTATE_FOGEND;
2713 case D3DLIGHTSTATE_FOGDENSITY: /* 7 */
2714 rs = D3DRENDERSTATE_FOGDENSITY;
2716 case D3DLIGHTSTATE_COLORVERTEX: /* 8 */
2717 rs = D3DRENDERSTATE_COLORVERTEX;
2720 ERR("Unknown D3DLIGHTSTATETYPE %d.\n", LightStateType);
2721 LeaveCriticalSection(&ddraw_cs);
2722 return DDERR_INVALIDPARAMS;
2725 hr = IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2728 LeaveCriticalSection(&ddraw_cs);
2732 LeaveCriticalSection(&ddraw_cs);
2736 static HRESULT WINAPI
2737 Thunk_IDirect3DDeviceImpl_2_SetLightState(IDirect3DDevice2 *iface,
2738 D3DLIGHTSTATETYPE LightStateType,
2741 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2742 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x) thunking to IDirect3DDevice3 interface.\n", This, LightStateType, Value);
2743 return IDirect3DDevice3_SetLightState(ICOM_INTERFACE(This, IDirect3DDevice3),
2748 /*****************************************************************************
2749 * IDirect3DDevice3::GetLightState
2751 * Returns the current setting of a light state. The state is read from
2752 * the Direct3DDevice7 render state.
2757 * LightStateType: The light state to return
2758 * Value: The address to store the light state setting at
2762 * DDDERR_INVALIDPARAMS if the parameters were incorrect
2763 * Also see IDirect3DDevice7::GetRenderState
2765 *****************************************************************************/
2766 static HRESULT WINAPI
2767 IDirect3DDeviceImpl_3_GetLightState(IDirect3DDevice3 *iface,
2768 D3DLIGHTSTATETYPE LightStateType,
2771 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2774 TRACE("(%p)->(%08x,%p)\n", This, LightStateType, Value);
2776 if (!LightStateType && (LightStateType > D3DLIGHTSTATE_COLORVERTEX))
2778 TRACE("Unexpected Light State Type\n");
2779 return DDERR_INVALIDPARAMS;
2783 return DDERR_INVALIDPARAMS;
2785 EnterCriticalSection(&ddraw_cs);
2786 if (LightStateType == D3DLIGHTSTATE_MATERIAL /* 1 */)
2788 *Value = This->material;
2790 else if (LightStateType == D3DLIGHTSTATE_COLORMODEL /* 3 */)
2792 *Value = D3DCOLOR_RGB;
2796 D3DRENDERSTATETYPE rs;
2797 switch (LightStateType)
2799 case D3DLIGHTSTATE_AMBIENT: /* 2 */
2800 rs = D3DRENDERSTATE_AMBIENT;
2802 case D3DLIGHTSTATE_FOGMODE: /* 4 */
2803 rs = D3DRENDERSTATE_FOGVERTEXMODE;
2805 case D3DLIGHTSTATE_FOGSTART: /* 5 */
2806 rs = D3DRENDERSTATE_FOGSTART;
2808 case D3DLIGHTSTATE_FOGEND: /* 6 */
2809 rs = D3DRENDERSTATE_FOGEND;
2811 case D3DLIGHTSTATE_FOGDENSITY: /* 7 */
2812 rs = D3DRENDERSTATE_FOGDENSITY;
2814 case D3DLIGHTSTATE_COLORVERTEX: /* 8 */
2815 rs = D3DRENDERSTATE_COLORVERTEX;
2818 ERR("Unknown D3DLIGHTSTATETYPE %d.\n", LightStateType);
2819 LeaveCriticalSection(&ddraw_cs);
2820 return DDERR_INVALIDPARAMS;
2823 hr = IDirect3DDevice7_GetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2826 LeaveCriticalSection(&ddraw_cs);
2830 LeaveCriticalSection(&ddraw_cs);
2834 static HRESULT WINAPI
2835 Thunk_IDirect3DDeviceImpl_2_GetLightState(IDirect3DDevice2 *iface,
2836 D3DLIGHTSTATETYPE LightStateType,
2839 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2840 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice3 interface.\n", This, LightStateType, Value);
2841 return IDirect3DDevice3_GetLightState(ICOM_INTERFACE(This, IDirect3DDevice3),
2846 /*****************************************************************************
2847 * IDirect3DDevice7::SetTransform
2849 * Assigns a D3DMATRIX to a transform type. The transform types are defined
2850 * in include/d3dtypes.h.
2851 * The D3DTRANSFORMSTATE_WORLD (=1) is translated to D3DTS_WORLDMATRIX(0)
2852 * (=255) for wined3d, because the 1 transform state was removed in d3d8
2853 * and WineD3D already understands the replacement D3DTS_WORLDMATRIX(0)
2855 * Version 2, 3 and 7
2858 * TransformStateType: transform state to set
2859 * Matrix: Matrix to assign to the state
2863 * DDERR_INVALIDPARAMS if Matrix == NULL
2864 * For details see IWineD3DDevice::SetTransform
2866 *****************************************************************************/
2867 static HRESULT WINAPI
2868 IDirect3DDeviceImpl_7_SetTransform(IDirect3DDevice7 *iface,
2869 D3DTRANSFORMSTATETYPE TransformStateType,
2872 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2873 D3DTRANSFORMSTATETYPE type = TransformStateType;
2875 TRACE("(%p)->(%08x,%p): Relay\n", This, TransformStateType, Matrix);
2877 switch(TransformStateType)
2879 case D3DTRANSFORMSTATE_WORLD : type = WINED3DTS_WORLDMATRIX(0); break;
2880 case D3DTRANSFORMSTATE_WORLD1: type = WINED3DTS_WORLDMATRIX(1); break;
2881 case D3DTRANSFORMSTATE_WORLD2: type = WINED3DTS_WORLDMATRIX(2); break;
2882 case D3DTRANSFORMSTATE_WORLD3: type = WINED3DTS_WORLDMATRIX(3); break;
2883 default: type = TransformStateType;
2887 return DDERR_INVALIDPARAMS;
2889 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
2890 EnterCriticalSection(&ddraw_cs);
2891 hr = IWineD3DDevice_SetTransform(This->wineD3DDevice,
2893 (WINED3DMATRIX*) Matrix);
2894 LeaveCriticalSection(&ddraw_cs);
2898 static HRESULT WINAPI
2899 Thunk_IDirect3DDeviceImpl_3_SetTransform(IDirect3DDevice3 *iface,
2900 D3DTRANSFORMSTATETYPE TransformStateType,
2901 D3DMATRIX *D3DMatrix)
2903 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2904 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2905 return IDirect3DDevice7_SetTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2910 static HRESULT WINAPI
2911 Thunk_IDirect3DDeviceImpl_2_SetTransform(IDirect3DDevice2 *iface,
2912 D3DTRANSFORMSTATETYPE TransformStateType,
2913 D3DMATRIX *D3DMatrix)
2915 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2916 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2917 return IDirect3DDevice7_SetTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2922 /*****************************************************************************
2923 * IDirect3DDevice7::GetTransform
2925 * Returns the matrix assigned to a transform state
2926 * D3DTRANSFORMSTATE_WORLD is translated to D3DTS_WORLDMATRIX(0), see
2930 * TransformStateType: State to read the matrix from
2931 * Matrix: Address to store the matrix at
2935 * DDERR_INVALIDPARAMS if Matrix == NULL
2936 * For details, see IWineD3DDevice::GetTransform
2938 *****************************************************************************/
2939 static HRESULT WINAPI
2940 IDirect3DDeviceImpl_7_GetTransform(IDirect3DDevice7 *iface,
2941 D3DTRANSFORMSTATETYPE TransformStateType,
2944 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2945 D3DTRANSFORMSTATETYPE type = TransformStateType;
2947 TRACE("(%p)->(%08x,%p): Relay\n", This, TransformStateType, Matrix);
2949 switch(TransformStateType)
2951 case D3DTRANSFORMSTATE_WORLD : type = WINED3DTS_WORLDMATRIX(0); break;
2952 case D3DTRANSFORMSTATE_WORLD1: type = WINED3DTS_WORLDMATRIX(1); break;
2953 case D3DTRANSFORMSTATE_WORLD2: type = WINED3DTS_WORLDMATRIX(2); break;
2954 case D3DTRANSFORMSTATE_WORLD3: type = WINED3DTS_WORLDMATRIX(3); break;
2955 default: type = TransformStateType;
2959 return DDERR_INVALIDPARAMS;
2961 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
2962 EnterCriticalSection(&ddraw_cs);
2963 hr = IWineD3DDevice_GetTransform(This->wineD3DDevice, type, (WINED3DMATRIX*) Matrix);
2964 LeaveCriticalSection(&ddraw_cs);
2968 static HRESULT WINAPI
2969 Thunk_IDirect3DDeviceImpl_3_GetTransform(IDirect3DDevice3 *iface,
2970 D3DTRANSFORMSTATETYPE TransformStateType,
2971 D3DMATRIX *D3DMatrix)
2973 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2974 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2975 return IDirect3DDevice7_GetTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2980 static HRESULT WINAPI
2981 Thunk_IDirect3DDeviceImpl_2_GetTransform(IDirect3DDevice2 *iface,
2982 D3DTRANSFORMSTATETYPE TransformStateType,
2983 D3DMATRIX *D3DMatrix)
2985 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2986 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2987 return IDirect3DDevice7_GetTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2992 /*****************************************************************************
2993 * IDirect3DDevice7::MultiplyTransform
2995 * Multiplies the already-set transform matrix of a transform state
2996 * with another matrix. For the world matrix, see SetTransform
2998 * Version 2, 3 and 7
3001 * TransformStateType: Transform state to multiply
3002 * D3DMatrix Matrix to multiply with.
3006 * DDERR_INVALIDPARAMS if D3DMatrix is NULL
3007 * For details, see IWineD3DDevice::MultiplyTransform
3009 *****************************************************************************/
3010 static HRESULT WINAPI
3011 IDirect3DDeviceImpl_7_MultiplyTransform(IDirect3DDevice7 *iface,
3012 D3DTRANSFORMSTATETYPE TransformStateType,
3013 D3DMATRIX *D3DMatrix)
3015 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3017 D3DTRANSFORMSTATETYPE type;
3018 TRACE("(%p)->(%08x,%p): Relay\n", This, TransformStateType, D3DMatrix);
3020 switch(TransformStateType)
3022 case D3DTRANSFORMSTATE_WORLD : type = WINED3DTS_WORLDMATRIX(0); break;
3023 case D3DTRANSFORMSTATE_WORLD1: type = WINED3DTS_WORLDMATRIX(1); break;
3024 case D3DTRANSFORMSTATE_WORLD2: type = WINED3DTS_WORLDMATRIX(2); break;
3025 case D3DTRANSFORMSTATE_WORLD3: type = WINED3DTS_WORLDMATRIX(3); break;
3026 default: type = TransformStateType;
3029 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
3030 EnterCriticalSection(&ddraw_cs);
3031 hr = IWineD3DDevice_MultiplyTransform(This->wineD3DDevice,
3033 (WINED3DMATRIX*) D3DMatrix);
3034 LeaveCriticalSection(&ddraw_cs);
3038 static HRESULT WINAPI
3039 Thunk_IDirect3DDeviceImpl_3_MultiplyTransform(IDirect3DDevice3 *iface,
3040 D3DTRANSFORMSTATETYPE TransformStateType,
3041 D3DMATRIX *D3DMatrix)
3043 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3044 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
3045 return IDirect3DDevice7_MultiplyTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
3050 static HRESULT WINAPI
3051 Thunk_IDirect3DDeviceImpl_2_MultiplyTransform(IDirect3DDevice2 *iface,
3052 D3DTRANSFORMSTATETYPE TransformStateType,
3053 D3DMATRIX *D3DMatrix)
3055 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
3056 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
3057 return IDirect3DDevice7_MultiplyTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
3062 /*****************************************************************************
3063 * IDirect3DDevice7::DrawPrimitive
3065 * Draws primitives based on vertices in an application-provided pointer
3067 * Version 2, 3 and 7. The IDirect3DDevice2 thunk converts the fixed vertex type into
3068 * an FVF format for D3D7
3071 * PrimitiveType: The type of the primitives to draw
3072 * Vertex type: Flexible vertex format vertex description
3073 * Vertices: Pointer to the vertex array
3074 * VertexCount: The number of vertices to draw
3075 * Flags: As usual a few flags
3079 * DDERR_INVALIDPARAMS if Vertices is NULL
3080 * For details, see IWineD3DDevice::DrawPrimitiveUP
3082 *****************************************************************************/
3083 static HRESULT WINAPI
3084 IDirect3DDeviceImpl_7_DrawPrimitive(IDirect3DDevice7 *iface,
3085 D3DPRIMITIVETYPE PrimitiveType,
3091 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3092 UINT PrimitiveCount, stride;
3094 TRACE("(%p)->(%08x,%08x,%p,%08x,%08x): Relay!\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Flags);
3097 return DDERR_INVALIDPARAMS;
3099 /* Get the vertex count */
3100 switch(PrimitiveType)
3102 case D3DPT_POINTLIST:
3103 PrimitiveCount = VertexCount;
3106 case D3DPT_LINELIST:
3107 PrimitiveCount = VertexCount / 2;
3110 case D3DPT_LINESTRIP:
3111 PrimitiveCount = VertexCount - 1;
3114 case D3DPT_TRIANGLELIST:
3115 PrimitiveCount = VertexCount / 3;
3118 case D3DPT_TRIANGLESTRIP:
3119 PrimitiveCount = VertexCount - 2;
3122 case D3DPT_TRIANGLEFAN:
3123 PrimitiveCount = VertexCount - 2;
3127 return DDERR_INVALIDPARAMS;
3130 /* Get the stride */
3131 stride = get_flexible_vertex_size(VertexType);
3134 EnterCriticalSection(&ddraw_cs);
3135 hr = IWineD3DDevice_SetVertexDeclaration(This->wineD3DDevice,
3136 IDirectDrawImpl_FindDecl(This->ddraw, VertexType));
3139 LeaveCriticalSection(&ddraw_cs);
3143 /* This method translates to the user pointer draw of WineD3D */
3144 hr = IWineD3DDevice_DrawPrimitiveUP(This->wineD3DDevice,
3149 LeaveCriticalSection(&ddraw_cs);
3153 static HRESULT WINAPI
3154 Thunk_IDirect3DDeviceImpl_3_DrawPrimitive(IDirect3DDevice3 *iface,
3155 D3DPRIMITIVETYPE PrimitiveType,
3161 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3162 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Flags);
3163 return IDirect3DDevice7_DrawPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
3171 static HRESULT WINAPI
3172 Thunk_IDirect3DDeviceImpl_2_DrawPrimitive(IDirect3DDevice2 *iface,
3173 D3DPRIMITIVETYPE PrimitiveType,
3174 D3DVERTEXTYPE VertexType,
3179 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
3181 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Flags);
3185 case D3DVT_VERTEX: FVF = D3DFVF_VERTEX; break;
3186 case D3DVT_LVERTEX: FVF = D3DFVF_LVERTEX; break;
3187 case D3DVT_TLVERTEX: FVF = D3DFVF_TLVERTEX; break;
3189 ERR("Unexpected vertex type %d\n", VertexType);
3190 return DDERR_INVALIDPARAMS; /* Should never happen */
3193 return IDirect3DDevice7_DrawPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
3201 /*****************************************************************************
3202 * IDirect3DDevice7::DrawIndexedPrimitive
3204 * Draws vertices from an application-provided pointer, based on the index
3205 * numbers in a WORD array.
3207 * Version 2, 3 and 7. The version 7 thunk translates the vertex type into
3208 * an FVF format for D3D7
3211 * PrimitiveType: The primitive type to draw
3212 * VertexType: The FVF vertex description
3213 * Vertices: Pointer to the vertex array
3215 * Indices: Pointer to the index array
3216 * IndexCount: Number of indices = Number of vertices to draw
3217 * Flags: As usual, some flags
3221 * DDERR_INVALIDPARAMS if Vertices or Indices is NULL
3222 * For details, see IWineD3DDevice::DrawIndexedPrimitiveUP
3224 *****************************************************************************/
3225 static HRESULT WINAPI
3226 IDirect3DDeviceImpl_7_DrawIndexedPrimitive(IDirect3DDevice7 *iface,
3227 D3DPRIMITIVETYPE PrimitiveType,
3235 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3236 UINT PrimitiveCount = 0;
3238 TRACE("(%p)->(%08x,%08x,%p,%08x,%p,%08x,%08x): Relay!\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Indices, IndexCount, Flags);
3240 /* Get the primitive number */
3241 switch(PrimitiveType)
3243 case D3DPT_POINTLIST:
3244 PrimitiveCount = IndexCount;
3247 case D3DPT_LINELIST:
3248 PrimitiveCount = IndexCount / 2;
3251 case D3DPT_LINESTRIP:
3252 PrimitiveCount = IndexCount - 1;
3255 case D3DPT_TRIANGLELIST:
3256 PrimitiveCount = IndexCount / 3;
3259 case D3DPT_TRIANGLESTRIP:
3260 PrimitiveCount = IndexCount - 2;
3263 case D3DPT_TRIANGLEFAN:
3264 PrimitiveCount = IndexCount - 2;
3268 return DDERR_INVALIDPARAMS;
3271 /* Set the D3DDevice's FVF */
3272 EnterCriticalSection(&ddraw_cs);
3273 hr = IWineD3DDevice_SetVertexDeclaration(This->wineD3DDevice,
3274 IDirectDrawImpl_FindDecl(This->ddraw, VertexType));
3277 ERR(" (%p) Setting the FVF failed, hr = %x!\n", This, hr);
3278 LeaveCriticalSection(&ddraw_cs);
3282 hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->wineD3DDevice,
3284 0 /* MinVertexIndex */,
3285 VertexCount /* UINT NumVertexIndex */,
3290 get_flexible_vertex_size(VertexType));
3291 LeaveCriticalSection(&ddraw_cs);
3295 static HRESULT WINAPI
3296 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitive(IDirect3DDevice3 *iface,
3297 D3DPRIMITIVETYPE PrimitiveType,
3305 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3306 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Indices, IndexCount, Flags);
3307 return IDirect3DDevice7_DrawIndexedPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
3317 static HRESULT WINAPI
3318 Thunk_IDirect3DDeviceImpl_2_DrawIndexedPrimitive(IDirect3DDevice2 *iface,
3319 D3DPRIMITIVETYPE PrimitiveType,
3320 D3DVERTEXTYPE VertexType,
3328 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
3329 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Indices, IndexCount, Flags);
3333 case D3DVT_VERTEX: FVF = D3DFVF_VERTEX; break;
3334 case D3DVT_LVERTEX: FVF = D3DFVF_LVERTEX; break;
3335 case D3DVT_TLVERTEX: FVF = D3DFVF_TLVERTEX; break;
3337 ERR("Unexpected vertex type %d\n", VertexType);
3338 return DDERR_INVALIDPARAMS; /* Should never happen */
3341 return IDirect3DDevice7_DrawIndexedPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
3351 /*****************************************************************************
3352 * IDirect3DDevice7::SetClipStatus
3354 * Sets the clip status. This defines things as clipping conditions and
3355 * the extents of the clipping region.
3357 * Version 2, 3 and 7
3363 * D3D_OK because it's a stub
3364 * (DDERR_INVALIDPARAMS if ClipStatus == NULL)
3366 *****************************************************************************/
3367 static HRESULT WINAPI
3368 IDirect3DDeviceImpl_7_SetClipStatus(IDirect3DDevice7 *iface,
3369 D3DCLIPSTATUS *ClipStatus)
3371 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3372 FIXME("(%p)->(%p): Stub!\n", This, ClipStatus);
3374 /* D3DCLIPSTATUS and WINED3DCLIPSTATUS are different. I don't know how to convert them
3375 * Perhaps this needs a new data type and an additional IWineD3DDevice method
3377 /* return IWineD3DDevice_SetClipStatus(This->wineD3DDevice, ClipStatus);*/
3381 static HRESULT WINAPI
3382 Thunk_IDirect3DDeviceImpl_3_SetClipStatus(IDirect3DDevice3 *iface,
3383 D3DCLIPSTATUS *ClipStatus)
3385 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3386 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, ClipStatus);
3387 return IDirect3DDevice7_SetClipStatus(ICOM_INTERFACE(This, IDirect3DDevice7),
3391 static HRESULT WINAPI
3392 Thunk_IDirect3DDeviceImpl_2_SetClipStatus(IDirect3DDevice2 *iface,
3393 D3DCLIPSTATUS *ClipStatus)
3395 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
3396 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, ClipStatus);
3397 return IDirect3DDevice7_SetClipStatus(ICOM_INTERFACE(This, IDirect3DDevice7),
3401 /*****************************************************************************
3402 * IDirect3DDevice7::GetClipStatus
3404 * Returns the clip status
3407 * ClipStatus: Address to write the clip status to
3410 * D3D_OK because it's a stub
3412 *****************************************************************************/
3413 static HRESULT WINAPI
3414 IDirect3DDeviceImpl_7_GetClipStatus(IDirect3DDevice7 *iface,
3415 D3DCLIPSTATUS *ClipStatus)
3417 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3418 FIXME("(%p)->(%p): Stub!\n", This, ClipStatus);
3420 /* D3DCLIPSTATUS and WINED3DCLIPSTATUS are different. I don't know how to convert them */
3421 /* return IWineD3DDevice_GetClipStatus(This->wineD3DDevice, ClipStatus);*/
3425 static HRESULT WINAPI
3426 Thunk_IDirect3DDeviceImpl_3_GetClipStatus(IDirect3DDevice3 *iface,
3427 D3DCLIPSTATUS *ClipStatus)
3429 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3430 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, ClipStatus);
3431 return IDirect3DDevice7_GetClipStatus(ICOM_INTERFACE(This, IDirect3DDevice7),
3435 static HRESULT WINAPI
3436 Thunk_IDirect3DDeviceImpl_2_GetClipStatus(IDirect3DDevice2 *iface,
3437 D3DCLIPSTATUS *ClipStatus)
3439 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
3440 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, ClipStatus);
3441 return IDirect3DDevice7_GetClipStatus(ICOM_INTERFACE(This, IDirect3DDevice7),
3445 /*****************************************************************************
3446 * IDirect3DDevice::DrawPrimitiveStrided
3448 * Draws vertices described by a D3DDRAWPRIMITIVESTRIDEDDATA structure.
3453 * PrimitiveType: The primitive type to draw
3454 * VertexType: The FVF description of the vertices to draw (for the stride??)
3455 * D3DDrawPrimStrideData: A D3DDRAWPRIMITIVESTRIDEDDATA structure describing
3456 * the vertex data locations
3457 * VertexCount: The number of vertices to draw
3461 * D3D_OK, because it's a stub
3462 * (DDERR_INVALIDPARAMS if D3DDrawPrimStrideData is NULL)
3463 * (For details, see IWineD3DDevice::DrawPrimitiveStrided)
3465 *****************************************************************************/
3466 static HRESULT WINAPI
3467 IDirect3DDeviceImpl_7_DrawPrimitiveStrided(IDirect3DDevice7 *iface,
3468 D3DPRIMITIVETYPE PrimitiveType,
3470 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3474 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3475 WineDirect3DVertexStridedData WineD3DStrided;
3477 UINT PrimitiveCount;
3480 TRACE("(%p)->(%08x,%08x,%p,%08x,%08x): stub!\n", This, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Flags);
3482 memset(&WineD3DStrided, 0, sizeof(WineD3DStrided));
3483 /* Get the strided data right. the wined3d structure is a bit bigger
3484 * Watch out: The contents of the strided data are determined by the fvf,
3485 * not by the members set in D3DDrawPrimStrideData. So it's valid
3486 * to have diffuse.lpvData set to 0xdeadbeef if the diffuse flag is
3487 * not set in the fvf.
3489 if(VertexType & D3DFVF_POSITION_MASK)
3491 WineD3DStrided.u.s.position.lpData = D3DDrawPrimStrideData->position.lpvData;
3492 WineD3DStrided.u.s.position.dwStride = D3DDrawPrimStrideData->position.dwStride;
3493 WineD3DStrided.u.s.position.dwType = WINED3DDECLTYPE_FLOAT3;
3494 if (VertexType & D3DFVF_XYZRHW)
3496 WineD3DStrided.u.s.position.dwType = WINED3DDECLTYPE_FLOAT4;
3497 WineD3DStrided.u.s.position_transformed = TRUE;
3499 WineD3DStrided.u.s.position_transformed = FALSE;
3502 if(VertexType & D3DFVF_NORMAL)
3504 WineD3DStrided.u.s.normal.lpData = D3DDrawPrimStrideData->normal.lpvData;
3505 WineD3DStrided.u.s.normal.dwStride = D3DDrawPrimStrideData->normal.dwStride;
3506 WineD3DStrided.u.s.normal.dwType = WINED3DDECLTYPE_FLOAT3;
3509 if(VertexType & D3DFVF_DIFFUSE)
3511 WineD3DStrided.u.s.diffuse.lpData = D3DDrawPrimStrideData->diffuse.lpvData;
3512 WineD3DStrided.u.s.diffuse.dwStride = D3DDrawPrimStrideData->diffuse.dwStride;
3513 WineD3DStrided.u.s.diffuse.dwType = WINED3DDECLTYPE_SHORT4;
3516 if(VertexType & D3DFVF_SPECULAR)
3518 WineD3DStrided.u.s.specular.lpData = D3DDrawPrimStrideData->specular.lpvData;
3519 WineD3DStrided.u.s.specular.dwStride = D3DDrawPrimStrideData->specular.dwStride;
3520 WineD3DStrided.u.s.specular.dwType = WINED3DDECLTYPE_SHORT4;
3523 for( i = 0; i < GET_TEXCOUNT_FROM_FVF(VertexType); i++)
3525 WineD3DStrided.u.s.texCoords[i].lpData = D3DDrawPrimStrideData->textureCoords[i].lpvData;
3526 WineD3DStrided.u.s.texCoords[i].dwStride = D3DDrawPrimStrideData->textureCoords[i].dwStride;
3527 switch(GET_TEXCOORD_SIZE_FROM_FVF(VertexType, i))
3529 case 1: WineD3DStrided.u.s.texCoords[i].dwType = WINED3DDECLTYPE_FLOAT1; break;
3530 case 2: WineD3DStrided.u.s.texCoords[i].dwType = WINED3DDECLTYPE_FLOAT2; break;
3531 case 3: WineD3DStrided.u.s.texCoords[i].dwType = WINED3DDECLTYPE_FLOAT3; break;
3532 case 4: WineD3DStrided.u.s.texCoords[i].dwType = WINED3DDECLTYPE_FLOAT4; break;
3533 default: ERR("Unexpected texture coordinate size %d\n",
3534 GET_TEXCOORD_SIZE_FROM_FVF(VertexType, i));
3538 /* Get the primitive count */
3539 switch(PrimitiveType)
3541 case D3DPT_POINTLIST:
3542 PrimitiveCount = VertexCount;
3545 case D3DPT_LINELIST:
3546 PrimitiveCount = VertexCount / 2;
3549 case D3DPT_LINESTRIP:
3550 PrimitiveCount = VertexCount - 1;
3553 case D3DPT_TRIANGLELIST:
3554 PrimitiveCount = VertexCount / 3;
3557 case D3DPT_TRIANGLESTRIP:
3558 PrimitiveCount = VertexCount - 2;
3561 case D3DPT_TRIANGLEFAN:
3562 PrimitiveCount = VertexCount - 2;
3565 default: return DDERR_INVALIDPARAMS;
3568 /* WineD3D doesn't need the FVF here */
3569 EnterCriticalSection(&ddraw_cs);
3570 hr = IWineD3DDevice_DrawPrimitiveStrided(This->wineD3DDevice,
3574 LeaveCriticalSection(&ddraw_cs);
3578 static HRESULT WINAPI
3579 Thunk_IDirect3DDeviceImpl_3_DrawPrimitiveStrided(IDirect3DDevice3 *iface,
3580 D3DPRIMITIVETYPE PrimitiveType,
3582 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3586 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3587 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Flags);
3588 return IDirect3DDevice7_DrawPrimitiveStrided(ICOM_INTERFACE(This, IDirect3DDevice7),
3591 D3DDrawPrimStrideData,
3596 /*****************************************************************************
3597 * IDirect3DDevice7::DrawIndexedPrimitiveStrided
3599 * Draws primitives specified by strided data locations based on indices
3607 * D3D_OK, because it's a stub
3608 * (DDERR_INVALIDPARAMS if D3DDrawPrimStrideData is NULL)
3609 * (DDERR_INVALIDPARAMS if Indices is NULL)
3610 * (For more details, see IWineD3DDevice::DrawIndexedPrimitiveStrided)
3612 *****************************************************************************/
3613 static HRESULT WINAPI
3614 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveStrided(IDirect3DDevice7 *iface,
3615 D3DPRIMITIVETYPE PrimitiveType,
3617 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3623 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3624 WineDirect3DVertexStridedData WineD3DStrided;
3626 UINT PrimitiveCount;
3629 TRACE("(%p)->(%08x,%08x,%p,%08x,%p,%08x,%08x)\n", This, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Indices, IndexCount, Flags);
3631 memset(&WineD3DStrided, 0, sizeof(WineD3DStrided));
3632 /* Get the strided data right. the wined3d structure is a bit bigger
3633 * Watch out: The contents of the strided data are determined by the fvf,
3634 * not by the members set in D3DDrawPrimStrideData. So it's valid
3635 * to have diffuse.lpvData set to 0xdeadbeef if the diffuse flag is
3636 * not set in the fvf.
3638 if(VertexType & D3DFVF_POSITION_MASK)
3640 WineD3DStrided.u.s.position.lpData = D3DDrawPrimStrideData->position.lpvData;
3641 WineD3DStrided.u.s.position.dwStride = D3DDrawPrimStrideData->position.dwStride;
3642 WineD3DStrided.u.s.position.dwType = WINED3DDECLTYPE_FLOAT3;
3643 if (VertexType & D3DFVF_XYZRHW)
3645 WineD3DStrided.u.s.position.dwType = WINED3DDECLTYPE_FLOAT4;
3646 WineD3DStrided.u.s.position_transformed = TRUE;
3648 WineD3DStrided.u.s.position_transformed = FALSE;
3651 if(VertexType & D3DFVF_NORMAL)
3653 WineD3DStrided.u.s.normal.lpData = D3DDrawPrimStrideData->normal.lpvData;
3654 WineD3DStrided.u.s.normal.dwStride = D3DDrawPrimStrideData->normal.dwStride;
3655 WineD3DStrided.u.s.normal.dwType = WINED3DDECLTYPE_FLOAT3;
3658 if(VertexType & D3DFVF_DIFFUSE)
3660 WineD3DStrided.u.s.diffuse.lpData = D3DDrawPrimStrideData->diffuse.lpvData;
3661 WineD3DStrided.u.s.diffuse.dwStride = D3DDrawPrimStrideData->diffuse.dwStride;
3662 WineD3DStrided.u.s.diffuse.dwType = WINED3DDECLTYPE_SHORT4;
3665 if(VertexType & D3DFVF_SPECULAR)
3667 WineD3DStrided.u.s.specular.lpData = D3DDrawPrimStrideData->specular.lpvData;
3668 WineD3DStrided.u.s.specular.dwStride = D3DDrawPrimStrideData->specular.dwStride;
3669 WineD3DStrided.u.s.specular.dwType = WINED3DDECLTYPE_SHORT4;
3672 for( i = 0; i < GET_TEXCOUNT_FROM_FVF(VertexType); i++)
3674 WineD3DStrided.u.s.texCoords[i].lpData = D3DDrawPrimStrideData->textureCoords[i].lpvData;
3675 WineD3DStrided.u.s.texCoords[i].dwStride = D3DDrawPrimStrideData->textureCoords[i].dwStride;
3676 switch(GET_TEXCOORD_SIZE_FROM_FVF(VertexType, i))
3678 case 1: WineD3DStrided.u.s.texCoords[i].dwType = WINED3DDECLTYPE_FLOAT1; break;
3679 case 2: WineD3DStrided.u.s.texCoords[i].dwType = WINED3DDECLTYPE_FLOAT2; break;
3680 case 3: WineD3DStrided.u.s.texCoords[i].dwType = WINED3DDECLTYPE_FLOAT3; break;
3681 case 4: WineD3DStrided.u.s.texCoords[i].dwType = WINED3DDECLTYPE_FLOAT4; break;
3682 default: ERR("Unexpected texture coordinate size %d\n",
3683 GET_TEXCOORD_SIZE_FROM_FVF(VertexType, i));
3687 /* Get the primitive count */
3688 switch(PrimitiveType)
3690 case D3DPT_POINTLIST:
3691 PrimitiveCount = IndexCount;
3694 case D3DPT_LINELIST:
3695 PrimitiveCount = IndexCount / 2;
3698 case D3DPT_LINESTRIP:
3699 PrimitiveCount = IndexCount - 1;
3702 case D3DPT_TRIANGLELIST:
3703 PrimitiveCount = IndexCount / 3;
3706 case D3DPT_TRIANGLESTRIP:
3707 PrimitiveCount = IndexCount - 2;
3710 case D3DPT_TRIANGLEFAN:
3711 PrimitiveCount = IndexCount - 2;
3714 default: return DDERR_INVALIDPARAMS;
3717 /* WineD3D doesn't need the FVF here */
3718 EnterCriticalSection(&ddraw_cs);
3719 hr = IWineD3DDevice_DrawIndexedPrimitiveStrided(This->wineD3DDevice,
3725 WINED3DFMT_INDEX16);
3726 LeaveCriticalSection(&ddraw_cs);
3730 static HRESULT WINAPI
3731 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitiveStrided(IDirect3DDevice3 *iface,
3732 D3DPRIMITIVETYPE PrimitiveType,
3734 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3740 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3741 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", iface, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Indices, IndexCount, Flags);
3742 return IDirect3DDevice7_DrawIndexedPrimitiveStrided(ICOM_INTERFACE(This, IDirect3DDevice7),
3745 D3DDrawPrimStrideData,
3752 /*****************************************************************************
3753 * IDirect3DDevice7::DrawPrimitiveVB
3755 * Draws primitives from a vertex buffer to the screen.
3760 * PrimitiveType: Type of primitive to be rendered.
3761 * D3DVertexBuf: Source Vertex Buffer
3762 * StartVertex: Index of the first vertex from the buffer to be rendered
3763 * NumVertices: Number of vertices to be rendered
3764 * Flags: Can be D3DDP_WAIT to wait until rendering has finished
3768 * DDERR_INVALIDPARAMS if D3DVertexBuf is NULL
3770 *****************************************************************************/
3771 static HRESULT WINAPI
3772 IDirect3DDeviceImpl_7_DrawPrimitiveVB(IDirect3DDevice7 *iface,
3773 D3DPRIMITIVETYPE PrimitiveType,
3774 IDirect3DVertexBuffer7 *D3DVertexBuf,
3779 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3780 IDirect3DVertexBufferImpl *vb = ICOM_OBJECT(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, D3DVertexBuf);
3781 UINT PrimitiveCount;
3784 WINED3DVERTEXBUFFER_DESC Desc;
3786 TRACE("(%p)->(%08x,%p,%08x,%08x,%08x)\n", This, PrimitiveType, D3DVertexBuf, StartVertex, NumVertices, Flags);
3791 ERR("(%p) No Vertex buffer specified\n", This);
3792 return DDERR_INVALIDPARAMS;
3795 /* Get the primitive count */
3796 switch(PrimitiveType)
3798 case D3DPT_POINTLIST:
3799 PrimitiveCount = NumVertices;
3802 case D3DPT_LINELIST:
3803 PrimitiveCount = NumVertices / 2;
3806 case D3DPT_LINESTRIP:
3807 PrimitiveCount = NumVertices - 1;
3810 case D3DPT_TRIANGLELIST:
3811 PrimitiveCount = NumVertices / 3;
3814 case D3DPT_TRIANGLESTRIP:
3815 PrimitiveCount = NumVertices - 2;
3818 case D3DPT_TRIANGLEFAN:
3819 PrimitiveCount = NumVertices - 2;
3823 return DDERR_INVALIDPARAMS;
3826 /* Get the FVF of the vertex buffer, and its stride */
3827 EnterCriticalSection(&ddraw_cs);
3828 hr = IWineD3DVertexBuffer_GetDesc(vb->wineD3DVertexBuffer,
3832 ERR("(%p) IWineD3DVertexBuffer::GetDesc failed with hr = %08x\n", This, hr);
3833 LeaveCriticalSection(&ddraw_cs);
3836 stride = get_flexible_vertex_size(Desc.FVF);
3838 hr = IWineD3DDevice_SetVertexDeclaration(This->wineD3DDevice,
3839 vb->wineD3DVertexDeclaration);
3842 ERR(" (%p) Setting the FVF failed, hr = %x!\n", This, hr);
3843 LeaveCriticalSection(&ddraw_cs);
3847 /* Set the vertex stream source */
3848 hr = IWineD3DDevice_SetStreamSource(This->wineD3DDevice,
3849 0 /* StreamNumber */,
3850 vb->wineD3DVertexBuffer,
3851 0 /* StartVertex - we pass this to DrawPrimitive */,
3855 ERR("(%p) IDirect3DDevice::SetStreamSource failed with hr = %08x\n", This, hr);
3856 LeaveCriticalSection(&ddraw_cs);
3860 /* Now draw the primitives */
3861 hr = IWineD3DDevice_DrawPrimitive(This->wineD3DDevice,
3865 LeaveCriticalSection(&ddraw_cs);
3869 static HRESULT WINAPI
3870 Thunk_IDirect3DDeviceImpl_3_DrawPrimitiveVB(IDirect3DDevice3 *iface,
3871 D3DPRIMITIVETYPE PrimitiveType,
3872 IDirect3DVertexBuffer *D3DVertexBuf,
3877 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3878 IDirect3DVertexBufferImpl *vb = ICOM_OBJECT(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, D3DVertexBuf);
3879 TRACE_(ddraw_thunk)("(%p)->(%08x,%p,%08x,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, vb, StartVertex, NumVertices, Flags);
3880 return IDirect3DDevice7_DrawPrimitiveVB(ICOM_INTERFACE(This, IDirect3DDevice7),
3882 ICOM_INTERFACE(vb, IDirect3DVertexBuffer7),
3889 /*****************************************************************************
3890 * IDirect3DDevice7::DrawIndexedPrimitiveVB
3892 * Draws primitives from a vertex buffer to the screen
3895 * PrimitiveType: Type of primitive to be rendered.
3896 * D3DVertexBuf: Source Vertex Buffer
3897 * StartVertex: Index of the first vertex from the buffer to be rendered
3898 * NumVertices: Number of vertices to be rendered
3899 * Indices: Array of DWORDs used to index into the Vertices
3900 * IndexCount: Number of indices in Indices
3901 * Flags: Can be D3DDP_WAIT to wait until rendering has finished
3905 *****************************************************************************/
3906 static HRESULT WINAPI
3907 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface,
3908 D3DPRIMITIVETYPE PrimitiveType,
3909 IDirect3DVertexBuffer7 *D3DVertexBuf,
3916 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3917 IDirect3DVertexBufferImpl *vb = ICOM_OBJECT(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, D3DVertexBuf);
3919 UINT PrimitiveCount;
3920 WORD *LockedIndices;
3922 WINED3DVERTEXBUFFER_DESC Desc;
3924 TRACE("(%p)->(%08x,%p,%d,%d,%p,%d,%08x)\n", This, PrimitiveType, vb, StartVertex, NumVertices, Indices, IndexCount, Flags);
3927 * 1) Calculate some things: Vertex count -> Primitive count, stride, ...
3928 * 2) Upload the Indices to the index buffer
3929 * 3) Set the index source
3930 * 4) Set the Vertex Buffer as the Stream source
3931 * 5) Call IWineD3DDevice::DrawIndexedPrimitive
3934 /* Get the primitive count */
3935 switch(PrimitiveType)
3937 case D3DPT_POINTLIST:
3938 PrimitiveCount = IndexCount;
3941 case D3DPT_LINELIST:
3942 PrimitiveCount = IndexCount / 2;
3945 case D3DPT_LINESTRIP:
3946 PrimitiveCount = IndexCount - 1;
3949 case D3DPT_TRIANGLELIST:
3950 PrimitiveCount = IndexCount / 3;
3953 case D3DPT_TRIANGLESTRIP:
3954 PrimitiveCount = IndexCount - 2;
3957 case D3DPT_TRIANGLEFAN:
3958 PrimitiveCount = IndexCount - 2;
3961 default: return DDERR_INVALIDPARAMS;
3964 EnterCriticalSection(&ddraw_cs);
3965 /* Get the FVF of the vertex buffer, and its stride */
3966 hr = IWineD3DVertexBuffer_GetDesc(vb->wineD3DVertexBuffer,
3970 ERR("(%p) IWineD3DVertexBuffer::GetDesc failed with hr = %08x\n", This, hr);
3971 LeaveCriticalSection(&ddraw_cs);
3974 stride = get_flexible_vertex_size(Desc.FVF);
3975 TRACE("Vertex buffer FVF = %08x, stride=%d\n", Desc.FVF, stride);
3977 hr = IWineD3DDevice_SetVertexDeclaration(This->wineD3DDevice,
3978 vb->wineD3DVertexDeclaration);
3981 ERR(" (%p) Setting the FVF failed, hr = %x!\n", This, hr);
3982 LeaveCriticalSection(&ddraw_cs);
3986 /* copy the index stream into the index buffer.
3987 * A new IWineD3DDevice method could be created
3988 * which takes an user pointer containing the indices
3989 * or a SetData-Method for the index buffer, which
3990 * overrides the index buffer data with our pointer.
3992 hr = IWineD3DIndexBuffer_Lock(This->indexbuffer,
3993 0 /* OffSetToLock */,
3994 IndexCount * sizeof(WORD),
3995 (BYTE **) &LockedIndices,
3997 assert(IndexCount < 0x100000);
4000 ERR("(%p) IWineD3DIndexBuffer::Lock failed with hr = %08x\n", This, hr);
4001 LeaveCriticalSection(&ddraw_cs);
4004 memcpy(LockedIndices, Indices, IndexCount * sizeof(WORD));
4005 hr = IWineD3DIndexBuffer_Unlock(This->indexbuffer);
4008 ERR("(%p) IWineD3DIndexBuffer::Unlock failed with hr = %08x\n", This, hr);
4009 LeaveCriticalSection(&ddraw_cs);
4013 /* Set the index stream */
4014 IWineD3DDevice_SetBaseVertexIndex(This->wineD3DDevice, StartVertex);
4015 hr = IWineD3DDevice_SetIndices(This->wineD3DDevice, This->indexbuffer);
4017 /* Set the vertex stream source */
4018 hr = IWineD3DDevice_SetStreamSource(This->wineD3DDevice,
4019 0 /* StreamNumber */,
4020 vb->wineD3DVertexBuffer,
4021 0 /* offset, we pass this to DrawIndexedPrimitive */,
4025 ERR("(%p) IDirect3DDevice::SetStreamSource failed with hr = %08x\n", This, hr);
4026 LeaveCriticalSection(&ddraw_cs);
4031 hr = IWineD3DDevice_DrawIndexedPrimitive(This->wineD3DDevice,
4038 LeaveCriticalSection(&ddraw_cs);
4042 static HRESULT WINAPI
4043 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitiveVB(IDirect3DDevice3 *iface,
4044 D3DPRIMITIVETYPE PrimitiveType,
4045 IDirect3DVertexBuffer *D3DVertexBuf,
4050 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
4051 IDirect3DVertexBufferImpl *VB = ICOM_OBJECT(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, D3DVertexBuf);
4052 TRACE_(ddraw_thunk)("(%p)->(%08x,%p,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VB, Indices, IndexCount, Flags);
4054 return IDirect3DDevice7_DrawIndexedPrimitiveVB(ICOM_INTERFACE(This, IDirect3DDevice7),
4056 ICOM_INTERFACE(VB, IDirect3DVertexBuffer7),
4064 /*****************************************************************************
4065 * IDirect3DDevice7::ComputeSphereVisibility
4067 * Calculates the visibility of spheres in the current viewport. The spheres
4068 * are passed in the Centers and Radii arrays, the results are passed back
4069 * in the ReturnValues array. Return values are either completely visible,
4070 * partially visible or completely invisible.
4071 * The return value consist of a combination of D3DCLIP_* flags, or it's
4072 * 0 if the sphere is completely visible(according to the SDK, not checked)
4074 * Sounds like an overdose of math ;)
4079 * Centers: Array containing the sphere centers
4080 * Radii: Array containing the sphere radii
4081 * NumSpheres: The number of centers and radii in the arrays
4083 * ReturnValues: Array to write the results to
4086 * D3D_OK because it's a stub
4087 * (DDERR_INVALIDPARAMS if Centers, Radii or ReturnValues are NULL)
4088 * (D3DERR_INVALIDMATRIX if the combined world, view and proj matrix
4091 *****************************************************************************/
4092 static HRESULT WINAPI
4093 IDirect3DDeviceImpl_7_ComputeSphereVisibility(IDirect3DDevice7 *iface,
4098 DWORD *ReturnValues)
4100 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4101 FIXME("(%p)->(%p,%p,%08x,%08x,%p): stub!\n", This, Centers, Radii, NumSpheres, Flags, ReturnValues);
4103 /* the DirectX 7 sdk says that the visibility is computed by
4104 * back-transforming the viewing frustum to model space
4105 * using the inverse of the combined world, view and projection
4106 * matrix. If the matrix can't be reversed, D3DERR_INVALIDMATRIX
4109 * Basic implementation idea:
4110 * 1) Check if the center is in the viewing frustum
4111 * 2) Cut the sphere with the planes of the viewing
4114 * ->Center inside the frustum, no intersections:
4116 * ->Center outside the frustum, no intersections:
4118 * ->Some intersections: Partially visible
4120 * Implement this call in WineD3D. Either implement the
4121 * matrix and vector stuff in WineD3D, or use some external
4128 static HRESULT WINAPI
4129 Thunk_IDirect3DDeviceImpl_3_ComputeSphereVisibility(IDirect3DDevice3 *iface,
4134 DWORD *ReturnValues)
4136 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
4137 TRACE_(ddraw_thunk)("(%p)->(%p,%p,%08x,%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, Centers, Radii, NumSpheres, Flags, ReturnValues);
4138 return IDirect3DDevice7_ComputeSphereVisibility(ICOM_INTERFACE(This, IDirect3DDevice7),
4146 /*****************************************************************************
4147 * IDirect3DDevice7::GetTexture
4149 * Returns the texture interface handle assigned to a texture stage.
4150 * The returned texture is AddRefed. This is taken from old ddraw,
4151 * not checked in Windows.
4156 * Stage: Texture stage to read the texture from
4157 * Texture: Address to store the interface pointer at
4161 * DDERR_INVALIDPARAMS if Texture is NULL
4162 * For details, see IWineD3DDevice::GetTexture
4164 *****************************************************************************/
4165 static HRESULT WINAPI
4166 IDirect3DDeviceImpl_7_GetTexture(IDirect3DDevice7 *iface,
4168 IDirectDrawSurface7 **Texture)
4170 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4171 IWineD3DBaseTexture *Surf;
4173 TRACE("(%p)->(%d,%p): Relay\n", This, Stage, Texture);
4177 TRACE("Texture == NULL, failing with DDERR_INVALIDPARAMS\n");
4178 return DDERR_INVALIDPARAMS;
4181 EnterCriticalSection(&ddraw_cs);
4182 hr = IWineD3DDevice_GetTexture(This->wineD3DDevice, Stage, &Surf);
4183 if( (hr != D3D_OK) || (!Surf) )
4186 LeaveCriticalSection(&ddraw_cs);
4190 /* GetParent AddRef()s, which is perfectly OK.
4191 * We have passed the IDirectDrawSurface7 interface to WineD3D, so that's OK too.
4193 hr = IWineD3DBaseTexture_GetParent(Surf,
4194 (IUnknown **) Texture);
4195 LeaveCriticalSection(&ddraw_cs);
4199 static HRESULT WINAPI
4200 Thunk_IDirect3DDeviceImpl_3_GetTexture(IDirect3DDevice3 *iface,
4202 IDirect3DTexture2 **Texture2)
4204 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
4206 IDirectDrawSurface7 *ret_val;
4208 TRACE_(ddraw_thunk)("(%p)->(%d,%p) thunking to IDirect3DDevice7 interface.\n", This, Stage, Texture2);
4209 ret = IDirect3DDevice7_GetTexture(ICOM_INTERFACE(This, IDirect3DDevice7),
4213 *Texture2 = COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7, IDirect3DTexture2, ret_val);
4215 TRACE_(ddraw_thunk)(" returning interface %p.\n", *Texture2);
4220 /*****************************************************************************
4221 * IDirect3DDevice7::SetTexture
4223 * Assigns a texture to a texture stage. Is the texture AddRef-ed?
4228 * Stage: The stage to assign the texture to
4229 * Texture: Interface pointer to the texture surface
4233 * For details, see IWineD3DDevice::SetTexture
4235 *****************************************************************************/
4236 static HRESULT WINAPI
4237 IDirect3DDeviceImpl_7_SetTexture(IDirect3DDevice7 *iface,
4239 IDirectDrawSurface7 *Texture)
4241 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4242 IDirectDrawSurfaceImpl *surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Texture);
4244 TRACE("(%p)->(%08x,%p): Relay!\n", This, Stage, surf);
4246 /* Texture may be NULL here */
4247 EnterCriticalSection(&ddraw_cs);
4248 hr = IWineD3DDevice_SetTexture(This->wineD3DDevice,
4250 surf ? surf->wineD3DTexture : NULL);
4251 LeaveCriticalSection(&ddraw_cs);
4255 static HRESULT WINAPI
4256 Thunk_IDirect3DDeviceImpl_3_SetTexture(IDirect3DDevice3 *iface,
4258 IDirect3DTexture2 *Texture2)
4260 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
4261 IDirectDrawSurfaceImpl *tex = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture2, Texture2);
4262 TRACE_(ddraw_thunk)("(%p)->(%d,%p) thunking to IDirect3DDevice7 interface.\n", This, Stage, tex);
4263 return IDirect3DDevice7_SetTexture(ICOM_INTERFACE(This, IDirect3DDevice7),
4265 ICOM_INTERFACE(tex, IDirectDrawSurface7));
4268 /*****************************************************************************
4269 * IDirect3DDevice7::GetTextureStageState
4271 * Retrieves a state from a texture stage.
4276 * Stage: The stage to retrieve the state from
4277 * TexStageStateType: The state type to retrieve
4278 * State: Address to store the state's value at
4282 * DDERR_INVALIDPARAMS if State is NULL
4283 * For details, see IWineD3DDevice::GetTextureStageState
4285 *****************************************************************************/
4286 static HRESULT WINAPI
4287 IDirect3DDeviceImpl_7_GetTextureStageState(IDirect3DDevice7 *iface,
4289 D3DTEXTURESTAGESTATETYPE TexStageStateType,
4292 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4294 TRACE("(%p)->(%08x,%08x,%p): Relay!\n", This, Stage, TexStageStateType, State);
4297 return DDERR_INVALIDPARAMS;
4299 EnterCriticalSection(&ddraw_cs);
4300 switch(TexStageStateType)
4302 /* Mipfilter is a sampler state with different values */
4303 case D3DTSS_MIPFILTER:
4305 WINED3DTEXTUREFILTERTYPE value;
4307 hr = IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
4309 WINED3DSAMP_MIPFILTER,
4313 case WINED3DTEXF_NONE: *State = D3DTFP_NONE; break;
4314 case WINED3DTEXF_POINT: *State = D3DTFP_POINT; break;
4315 case WINED3DTEXF_LINEAR: *State = D3DTFP_LINEAR; break;
4317 ERR("Unexpected mipfilter value %d\n", value);
4318 *State = D3DTFP_NONE;
4323 /* Minfilter is a sampler state too, equal values */
4324 case D3DTSS_MINFILTER:
4325 hr = IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
4327 WINED3DSAMP_MINFILTER,
4331 /* Magfilter has slightly different values */
4332 case D3DTSS_MAGFILTER:
4334 WINED3DTEXTUREFILTERTYPE wined3dfilter;
4335 hr = IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
4337 WINED3DSAMP_MAGFILTER,
4339 switch(wined3dfilter)
4341 case WINED3DTEXF_POINT: *State = D3DTFG_POINT; break;
4342 case WINED3DTEXF_LINEAR: *State = D3DTFG_LINEAR; break;
4343 case WINED3DTEXF_ANISOTROPIC: *State = D3DTFG_ANISOTROPIC; break;
4344 case WINED3DTEXF_FLATCUBIC: *State = D3DTFG_FLATCUBIC; break;
4345 case WINED3DTEXF_GAUSSIANCUBIC: *State = D3DTFG_GAUSSIANCUBIC; break;
4347 ERR("Unexpected wined3d mag filter value %d\n", wined3dfilter);
4348 *State = D3DTFG_POINT;
4353 case D3DTSS_ADDRESS:
4354 case D3DTSS_ADDRESSU:
4355 hr = IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
4357 WINED3DSAMP_ADDRESSU,
4360 case D3DTSS_ADDRESSV:
4361 hr = IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
4363 WINED3DSAMP_ADDRESSV,
4367 hr = IWineD3DDevice_GetTextureStageState(This->wineD3DDevice,
4373 LeaveCriticalSection(&ddraw_cs);
4377 static HRESULT WINAPI
4378 Thunk_IDirect3DDeviceImpl_3_GetTextureStageState(IDirect3DDevice3 *iface,
4380 D3DTEXTURESTAGESTATETYPE TexStageStateType,
4383 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
4384 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, Stage, TexStageStateType, State);
4385 return IDirect3DDevice7_GetTextureStageState(ICOM_INTERFACE(This, IDirect3DDevice7),
4391 /*****************************************************************************
4392 * IDirect3DDevice7::SetTextureStageState
4394 * Sets a texture stage state. Some stage types need to be handled specially,
4395 * because they do not exist in WineD3D and were moved to another place
4400 * Stage: The stage to modify
4401 * TexStageStateType: The state to change
4402 * State: The new value for the state
4406 * For details, see IWineD3DDevice::SetTextureStageState
4408 *****************************************************************************/
4409 static HRESULT WINAPI
4410 IDirect3DDeviceImpl_7_SetTextureStageState(IDirect3DDevice7 *iface,
4412 D3DTEXTURESTAGESTATETYPE TexStageStateType,
4415 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4417 TRACE("(%p)->(%08x,%08x,%08x): Relay!\n", This, Stage, TexStageStateType, State);
4419 EnterCriticalSection(&ddraw_cs);
4420 switch(TexStageStateType)
4422 /* Mipfilter is a sampler state with different values */
4423 case D3DTSS_MIPFILTER:
4425 WINED3DTEXTUREFILTERTYPE value;
4428 case D3DTFP_NONE: value = WINED3DTEXF_NONE; break;
4429 case D3DTFP_POINT: value = WINED3DTEXF_POINT; break;
4430 case 0: /* Unchecked */
4431 case D3DTFP_LINEAR: value = WINED3DTEXF_LINEAR; break;
4433 ERR("Unexpected mipfilter value %d\n", State);
4434 value = WINED3DTEXF_NONE;
4436 hr = IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
4438 WINED3DSAMP_MIPFILTER,
4443 /* Minfilter is a sampler state too, equal values */
4444 case D3DTSS_MINFILTER:
4445 hr = IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
4447 WINED3DSAMP_MINFILTER,
4451 /* Magfilter has slightly different values */
4452 case D3DTSS_MAGFILTER:
4454 WINED3DTEXTUREFILTERTYPE wined3dfilter;
4455 switch((D3DTEXTUREMAGFILTER) State)
4457 case D3DTFG_POINT: wined3dfilter = WINED3DTEXF_POINT; break;
4458 case D3DTFG_LINEAR: wined3dfilter = WINED3DTEXF_LINEAR; break;
4459 case D3DTFG_FLATCUBIC: wined3dfilter = WINED3DTEXF_FLATCUBIC; break;
4460 case D3DTFG_GAUSSIANCUBIC: wined3dfilter = WINED3DTEXF_GAUSSIANCUBIC; break;
4461 case D3DTFG_ANISOTROPIC: wined3dfilter = WINED3DTEXF_ANISOTROPIC; break;
4463 ERR("Unexpected d3d7 mag filter type %d\n", State);
4464 wined3dfilter = WINED3DTEXF_POINT;
4466 hr = IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
4468 WINED3DSAMP_MAGFILTER,
4473 case D3DTSS_ADDRESS:
4474 IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
4476 WINED3DSAMP_ADDRESSV,
4479 case D3DTSS_ADDRESSU:
4480 hr = IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
4482 WINED3DSAMP_ADDRESSU,
4486 case D3DTSS_ADDRESSV:
4487 hr = IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
4489 WINED3DSAMP_ADDRESSV,
4494 hr = IWineD3DDevice_SetTextureStageState(This->wineD3DDevice,
4500 LeaveCriticalSection(&ddraw_cs);
4504 static HRESULT WINAPI
4505 Thunk_IDirect3DDeviceImpl_3_SetTextureStageState(IDirect3DDevice3 *iface,
4507 D3DTEXTURESTAGESTATETYPE TexStageStateType,
4510 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
4511 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, Stage, TexStageStateType, State);
4512 return IDirect3DDevice7_SetTextureStageState(ICOM_INTERFACE(This, IDirect3DDevice7),
4518 /*****************************************************************************
4519 * IDirect3DDevice7::ValidateDevice
4521 * SDK: "Reports the device's ability to render the currently set
4522 * texture-blending operations in a single pass". Whatever that means
4528 * NumPasses: Address to write the number of necessary passes for the
4529 * desired effect to.
4533 * See IWineD3DDevice::ValidateDevice for more details
4535 *****************************************************************************/
4536 static HRESULT WINAPI
4537 IDirect3DDeviceImpl_7_ValidateDevice(IDirect3DDevice7 *iface,
4540 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4542 TRACE("(%p)->(%p): Relay\n", This, NumPasses);
4544 EnterCriticalSection(&ddraw_cs);
4545 hr = IWineD3DDevice_ValidateDevice(This->wineD3DDevice, NumPasses);
4546 LeaveCriticalSection(&ddraw_cs);
4550 static HRESULT WINAPI
4551 Thunk_IDirect3DDeviceImpl_3_ValidateDevice(IDirect3DDevice3 *iface,
4554 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
4555 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, Passes);
4556 return IDirect3DDevice7_ValidateDevice(ICOM_INTERFACE(This, IDirect3DDevice7),
4560 /*****************************************************************************
4561 * IDirect3DDevice7::Clear
4563 * Fills the render target, the z buffer and the stencil buffer with a
4564 * clear color / value
4569 * Count: Number of rectangles in Rects must be 0 if Rects is NULL
4570 * Rects: Rectangles to clear. If NULL, the whole surface is cleared
4571 * Flags: Some flags, as usual
4572 * Color: Clear color for the render target
4573 * Z: Clear value for the Z buffer
4574 * Stencil: Clear value to store in each stencil buffer entry
4578 * For details, see IWineD3DDevice::Clear
4580 *****************************************************************************/
4581 static HRESULT WINAPI
4582 IDirect3DDeviceImpl_7_Clear(IDirect3DDevice7 *iface,
4590 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4592 TRACE("(%p)->(%08x,%p,%08x,%08x,%f,%08x): Relay\n", This, Count, Rects, Flags, (DWORD) Color, Z, Stencil);
4594 /* Note; D3DRECT is compatible with WINED3DRECT */
4595 EnterCriticalSection(&ddraw_cs);
4596 hr = IWineD3DDevice_Clear(This->wineD3DDevice, Count, (WINED3DRECT*) Rects, Flags, Color, Z, Stencil);
4597 LeaveCriticalSection(&ddraw_cs);
4601 /*****************************************************************************
4602 * IDirect3DDevice7::SetViewport
4604 * Sets the current viewport.
4606 * Version 7 only, but IDirect3DViewport uses this call for older
4610 * Data: The new viewport to set
4614 * DDERR_INVALIDPARAMS if Data is NULL
4615 * For more details, see IWineDDDevice::SetViewport
4617 *****************************************************************************/
4618 static HRESULT WINAPI
4619 IDirect3DDeviceImpl_7_SetViewport(IDirect3DDevice7 *iface,
4622 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4624 TRACE("(%p)->(%p) Relay!\n", This, Data);
4627 return DDERR_INVALIDPARAMS;
4629 /* Note: D3DVIEWPORT7 is compatible with WINED3DVIEWPORT */
4630 EnterCriticalSection(&ddraw_cs);
4631 hr = IWineD3DDevice_SetViewport(This->wineD3DDevice,
4632 (WINED3DVIEWPORT*) Data);
4633 LeaveCriticalSection(&ddraw_cs);
4637 /*****************************************************************************
4638 * IDirect3DDevice::GetViewport
4640 * Returns the current viewport
4645 * Data: D3D7Viewport structure to write the viewport information to
4649 * DDERR_INVALIDPARAMS if Data is NULL
4650 * For more details, see IWineD3DDevice::GetViewport
4652 *****************************************************************************/
4653 static HRESULT WINAPI
4654 IDirect3DDeviceImpl_7_GetViewport(IDirect3DDevice7 *iface,
4657 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4659 TRACE("(%p)->(%p) Relay!\n", This, Data);
4662 return DDERR_INVALIDPARAMS;
4664 /* Note: D3DVIEWPORT7 is compatible with WINED3DVIEWPORT */
4665 EnterCriticalSection(&ddraw_cs);
4666 hr = IWineD3DDevice_GetViewport(This->wineD3DDevice,
4667 (WINED3DVIEWPORT*) Data);
4669 LeaveCriticalSection(&ddraw_cs);
4670 return hr_ddraw_from_wined3d(hr);
4673 /*****************************************************************************
4674 * IDirect3DDevice7::SetMaterial
4681 * Mat: The material to set
4685 * DDERR_INVALIDPARAMS if Mat is NULL.
4686 * For more details, see IWineD3DDevice::SetMaterial
4688 *****************************************************************************/
4689 static HRESULT WINAPI
4690 IDirect3DDeviceImpl_7_SetMaterial(IDirect3DDevice7 *iface,
4693 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4695 TRACE("(%p)->(%p): Relay!\n", This, Mat);
4697 /* Note: D3DMATERIAL7 is compatible with WINED3DMATERIAL */
4698 EnterCriticalSection(&ddraw_cs);
4699 hr = IWineD3DDevice_SetMaterial(This->wineD3DDevice,
4700 (WINED3DMATERIAL*) Mat);
4701 LeaveCriticalSection(&ddraw_cs);
4702 return hr_ddraw_from_wined3d(hr);
4705 /*****************************************************************************
4706 * IDirect3DDevice7::GetMaterial
4708 * Returns the current material
4713 * Mat: D3DMATERIAL7 structure to write the material parameters to
4717 * DDERR_INVALIDPARAMS if Mat is NULL
4718 * For more details, see IWineD3DDevice::GetMaterial
4720 *****************************************************************************/
4721 static HRESULT WINAPI
4722 IDirect3DDeviceImpl_7_GetMaterial(IDirect3DDevice7 *iface,
4725 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4727 TRACE("(%p)->(%p): Relay!\n", This, Mat);
4729 EnterCriticalSection(&ddraw_cs);
4730 /* Note: D3DMATERIAL7 is compatible with WINED3DMATERIAL */
4731 hr = IWineD3DDevice_GetMaterial(This->wineD3DDevice,
4732 (WINED3DMATERIAL*) Mat);
4733 LeaveCriticalSection(&ddraw_cs);
4734 return hr_ddraw_from_wined3d(hr);
4737 /*****************************************************************************
4738 * IDirect3DDevice7::SetLight
4740 * Assigns a light to a light index, but doesn't activate it yet.
4742 * Version 7, IDirect3DLight uses this method for older versions
4745 * LightIndex: The index of the new light
4746 * Light: A D3DLIGHT7 structure describing the light
4750 * For more details, see IWineD3DDevice::SetLight
4752 *****************************************************************************/
4753 static HRESULT WINAPI
4754 IDirect3DDeviceImpl_7_SetLight(IDirect3DDevice7 *iface,
4758 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4760 TRACE("(%p)->(%08x,%p): Relay!\n", This, LightIndex, Light);
4762 EnterCriticalSection(&ddraw_cs);
4763 /* Note: D3DLIGHT7 is compatible with WINED3DLIGHT */
4764 hr = IWineD3DDevice_SetLight(This->wineD3DDevice,
4766 (WINED3DLIGHT*) Light);
4767 LeaveCriticalSection(&ddraw_cs);
4768 return hr_ddraw_from_wined3d(hr);
4771 /*****************************************************************************
4772 * IDirect3DDevice7::GetLight
4774 * Returns the light assigned to a light index
4777 * Light: Structure to write the light information to
4781 * DDERR_INVALIDPARAMS if Light is NULL
4782 * For details, see IWineD3DDevice::GetLight
4784 *****************************************************************************/
4785 static HRESULT WINAPI
4786 IDirect3DDeviceImpl_7_GetLight(IDirect3DDevice7 *iface,
4790 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4792 TRACE("(%p)->(%08x,%p): Relay!\n", This, LightIndex, Light);
4794 EnterCriticalSection(&ddraw_cs);
4795 /* Note: D3DLIGHT7 is compatible with WINED3DLIGHT */
4796 rc = IWineD3DDevice_GetLight(This->wineD3DDevice,
4798 (WINED3DLIGHT*) Light);
4800 /* Translate the result. WineD3D returns other values than D3D7 */
4801 LeaveCriticalSection(&ddraw_cs);
4802 return hr_ddraw_from_wined3d(rc);
4805 /*****************************************************************************
4806 * IDirect3DDevice7::BeginStateBlock
4808 * Begins recording to a stateblock
4814 * For details see IWineD3DDevice::BeginStateBlock
4816 *****************************************************************************/
4817 static HRESULT WINAPI
4818 IDirect3DDeviceImpl_7_BeginStateBlock(IDirect3DDevice7 *iface)
4820 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4822 TRACE("(%p)->(): Relay!\n", This);
4824 EnterCriticalSection(&ddraw_cs);
4825 hr = IWineD3DDevice_BeginStateBlock(This->wineD3DDevice);
4826 LeaveCriticalSection(&ddraw_cs);
4827 return hr_ddraw_from_wined3d(hr);
4830 /*****************************************************************************
4831 * IDirect3DDevice7::EndStateBlock
4833 * Stops recording to a state block and returns the created stateblock
4839 * BlockHandle: Address to store the stateblock's handle to
4843 * DDERR_INVALIDPARAMS if BlockHandle is NULL
4844 * See IWineD3DDevice::EndStateBlock for more details
4846 *****************************************************************************/
4847 static HRESULT WINAPI
4848 IDirect3DDeviceImpl_7_EndStateBlock(IDirect3DDevice7 *iface,
4851 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4853 TRACE("(%p)->(%p): Relay!\n", This, BlockHandle);
4857 WARN("BlockHandle == NULL, returning DDERR_INVALIDPARAMS\n");
4858 return DDERR_INVALIDPARAMS;
4861 EnterCriticalSection(&ddraw_cs);
4862 *BlockHandle = IDirect3DDeviceImpl_CreateHandle(This);
4865 ERR("Cannot get a handle number for the stateblock\n");
4866 LeaveCriticalSection(&ddraw_cs);
4867 return DDERR_OUTOFMEMORY;
4869 This->Handles[*BlockHandle - 1].type = DDrawHandle_StateBlock;
4870 hr = IWineD3DDevice_EndStateBlock(This->wineD3DDevice,
4871 (IWineD3DStateBlock **) &This->Handles[*BlockHandle - 1].ptr);
4872 LeaveCriticalSection(&ddraw_cs);
4873 return hr_ddraw_from_wined3d(hr);
4876 /*****************************************************************************
4877 * IDirect3DDevice7::PreLoad
4879 * Allows the app to signal that a texture will be used soon, to allow
4880 * the Direct3DDevice to load it to the video card in the meantime.
4885 * Texture: The texture to preload
4889 * DDERR_INVALIDPARAMS if Texture is NULL
4890 * See IWineD3DSurface::PreLoad for details
4892 *****************************************************************************/
4893 static HRESULT WINAPI
4894 IDirect3DDeviceImpl_7_PreLoad(IDirect3DDevice7 *iface,
4895 IDirectDrawSurface7 *Texture)
4897 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4898 IDirectDrawSurfaceImpl *surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Texture);
4900 TRACE("(%p)->(%p): Relay!\n", This, surf);
4903 return DDERR_INVALIDPARAMS;
4905 EnterCriticalSection(&ddraw_cs);
4906 IWineD3DSurface_PreLoad(surf->WineD3DSurface);
4907 LeaveCriticalSection(&ddraw_cs);
4911 /*****************************************************************************
4912 * IDirect3DDevice7::ApplyStateBlock
4914 * Activates the state stored in a state block handle.
4917 * BlockHandle: The stateblock handle to activate
4921 * D3DERR_INVALIDSTATEBLOCK if BlockHandle is NULL
4923 *****************************************************************************/
4924 static HRESULT WINAPI
4925 IDirect3DDeviceImpl_7_ApplyStateBlock(IDirect3DDevice7 *iface,
4928 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4930 TRACE("(%p)->(%08x): Relay!\n", This, BlockHandle);
4932 EnterCriticalSection(&ddraw_cs);
4933 if(!BlockHandle || BlockHandle > This->numHandles)
4935 WARN("Out of range handle %d, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
4936 LeaveCriticalSection(&ddraw_cs);
4937 return D3DERR_INVALIDSTATEBLOCK;
4939 if(This->Handles[BlockHandle - 1].type != DDrawHandle_StateBlock)
4941 WARN("Handle %d is not a stateblock, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
4942 LeaveCriticalSection(&ddraw_cs);
4943 return D3DERR_INVALIDSTATEBLOCK;
4946 hr = IWineD3DStateBlock_Apply((IWineD3DStateBlock *) This->Handles[BlockHandle - 1].ptr);
4947 LeaveCriticalSection(&ddraw_cs);
4948 return hr_ddraw_from_wined3d(hr);
4951 /*****************************************************************************
4952 * IDirect3DDevice7::CaptureStateBlock
4954 * Updates a stateblock's values to the values currently set for the device
4959 * BlockHandle: Stateblock to update
4963 * D3DERR_INVALIDSTATEBLOCK if BlockHandle is NULL
4964 * See IWineD3DDevice::CaptureStateBlock for more details
4966 *****************************************************************************/
4967 static HRESULT WINAPI
4968 IDirect3DDeviceImpl_7_CaptureStateBlock(IDirect3DDevice7 *iface,
4971 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4973 TRACE("(%p)->(%08x): Relay!\n", This, BlockHandle);
4975 EnterCriticalSection(&ddraw_cs);
4976 if(BlockHandle == 0 || BlockHandle > This->numHandles)
4978 WARN("Out of range handle %d, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
4979 LeaveCriticalSection(&ddraw_cs);
4980 return D3DERR_INVALIDSTATEBLOCK;
4982 if(This->Handles[BlockHandle - 1].type != DDrawHandle_StateBlock)
4984 WARN("Handle %d is not a stateblock, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
4985 LeaveCriticalSection(&ddraw_cs);
4986 return D3DERR_INVALIDSTATEBLOCK;
4989 hr = IWineD3DStateBlock_Capture((IWineD3DStateBlock *) This->Handles[BlockHandle - 1].ptr);
4990 LeaveCriticalSection(&ddraw_cs);
4991 return hr_ddraw_from_wined3d(hr);
4994 /*****************************************************************************
4995 * IDirect3DDevice7::DeleteStateBlock
4997 * Deletes a stateblock handle. This means releasing the WineD3DStateBlock
5002 * BlockHandle: Stateblock handle to delete
5006 * D3DERR_INVALIDSTATEBLOCK if BlockHandle is 0
5008 *****************************************************************************/
5009 static HRESULT WINAPI
5010 IDirect3DDeviceImpl_7_DeleteStateBlock(IDirect3DDevice7 *iface,
5013 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
5015 TRACE("(%p)->(%08x): Relay!\n", This, BlockHandle);
5017 EnterCriticalSection(&ddraw_cs);
5018 if(BlockHandle == 0 || BlockHandle > This->numHandles)
5020 WARN("Out of range handle %d, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
5021 LeaveCriticalSection(&ddraw_cs);
5022 return D3DERR_INVALIDSTATEBLOCK;
5024 if(This->Handles[BlockHandle - 1].type != DDrawHandle_StateBlock)
5026 WARN("Handle %d is not a stateblock, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
5027 LeaveCriticalSection(&ddraw_cs);
5028 return D3DERR_INVALIDSTATEBLOCK;
5031 ref = IWineD3DStateBlock_Release((IWineD3DStateBlock *) This->Handles[BlockHandle - 1].ptr);
5034 ERR("Something is still holding the stateblock %p(Handle %d). Ref = %d\n", This->Handles[BlockHandle - 1].ptr, BlockHandle, ref);
5036 This->Handles[BlockHandle - 1].ptr = NULL;
5037 This->Handles[BlockHandle - 1].type = DDrawHandle_Unknown;
5039 LeaveCriticalSection(&ddraw_cs);
5043 /*****************************************************************************
5044 * IDirect3DDevice7::CreateStateBlock
5046 * Creates a new state block handle.
5051 * Type: The state block type
5052 * BlockHandle: Address to write the created handle to
5056 * DDERR_INVALIDPARAMS if BlockHandle is NULL
5058 *****************************************************************************/
5059 static HRESULT WINAPI
5060 IDirect3DDeviceImpl_7_CreateStateBlock(IDirect3DDevice7 *iface,
5061 D3DSTATEBLOCKTYPE Type,
5064 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
5066 TRACE("(%p)->(%08x,%p)!\n", This, Type, BlockHandle);
5070 WARN("BlockHandle == NULL, returning DDERR_INVALIDPARAMS\n");
5071 return DDERR_INVALIDPARAMS;
5073 if(Type != D3DSBT_ALL && Type != D3DSBT_PIXELSTATE &&
5074 Type != D3DSBT_VERTEXSTATE ) {
5075 WARN("Unexpected stateblock type, returning DDERR_INVALIDPARAMS\n");
5076 return DDERR_INVALIDPARAMS;
5079 EnterCriticalSection(&ddraw_cs);
5080 *BlockHandle = IDirect3DDeviceImpl_CreateHandle(This);
5083 ERR("Cannot get a handle number for the stateblock\n");
5084 LeaveCriticalSection(&ddraw_cs);
5085 return DDERR_OUTOFMEMORY;
5087 This->Handles[*BlockHandle - 1].type = DDrawHandle_StateBlock;
5089 /* The D3DSTATEBLOCKTYPE enum is fine here */
5090 hr = IWineD3DDevice_CreateStateBlock(This->wineD3DDevice,
5092 (IWineD3DStateBlock **) &This->Handles[*BlockHandle - 1].ptr,
5093 NULL /* Parent, hope that works */);
5094 LeaveCriticalSection(&ddraw_cs);
5095 return hr_ddraw_from_wined3d(hr);
5098 /*****************************************************************************
5099 * IDirect3DDevice7::Load
5101 * Loads a rectangular area from the source into the destination texture.
5102 * It can also copy the source to the faces of a cubic environment map
5107 * DestTex: Destination texture
5108 * DestPoint: Point in the destination where the source image should be
5110 * SrcTex: Source texture
5111 * SrcRect: Source rectangle
5116 * DDERR_INVALIDPARAMS if DestTex or SrcTex are NULL
5117 * See IDirect3DTexture2::Load for details
5119 *****************************************************************************/
5120 static HRESULT WINAPI
5121 IDirect3DDeviceImpl_7_Load(IDirect3DDevice7 *iface,
5122 IDirectDrawSurface7 *DestTex,
5124 IDirectDrawSurface7 *SrcTex,
5128 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
5129 IDirectDrawSurfaceImpl *dest = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DestTex);
5130 IDirectDrawSurfaceImpl *src = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, SrcTex);
5131 FIXME("(%p)->(%p,%p,%p,%p,%08x): Partially Implemented!\n", This, dest, DestPoint, src, SrcRect, Flags);
5133 if( (!src) || (!dest) )
5134 return DDERR_INVALIDPARAMS;
5136 IDirect3DTexture2_Load(ICOM_INTERFACE(dest, IDirect3DTexture2),
5137 ICOM_INTERFACE(src, IDirect3DTexture2));
5141 /*****************************************************************************
5142 * IDirect3DDevice7::LightEnable
5144 * Enables or disables a light
5146 * Version 7, IDirect3DLight uses this method too.
5149 * LightIndex: The index of the light to enable / disable
5150 * Enable: Enable or disable the light
5154 * For more details, see IWineD3DDevice::SetLightEnable
5156 *****************************************************************************/
5157 static HRESULT WINAPI
5158 IDirect3DDeviceImpl_7_LightEnable(IDirect3DDevice7 *iface,
5162 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
5164 TRACE("(%p)->(%08x,%d): Relay!\n", This, LightIndex, Enable);
5166 EnterCriticalSection(&ddraw_cs);
5167 hr = IWineD3DDevice_SetLightEnable(This->wineD3DDevice, LightIndex, Enable);
5168 LeaveCriticalSection(&ddraw_cs);
5169 return hr_ddraw_from_wined3d(hr);
5172 /*****************************************************************************
5173 * IDirect3DDevice7::GetLightEnable
5175 * Retrieves if the light with the given index is enabled or not
5180 * LightIndex: Index of desired light
5181 * Enable: Pointer to a BOOL which contains the result
5185 * DDERR_INVALIDPARAMS if Enable is NULL
5186 * See IWineD3DDevice::GetLightEnable for more details
5188 *****************************************************************************/
5189 static HRESULT WINAPI
5190 IDirect3DDeviceImpl_7_GetLightEnable(IDirect3DDevice7 *iface,
5194 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
5196 TRACE("(%p)->(%08x,%p): Relay\n", This, LightIndex, Enable);
5199 return DDERR_INVALIDPARAMS;
5201 EnterCriticalSection(&ddraw_cs);
5202 hr = IWineD3DDevice_GetLightEnable(This->wineD3DDevice, LightIndex, Enable);
5203 LeaveCriticalSection(&ddraw_cs);
5204 return hr_ddraw_from_wined3d(hr);
5207 /*****************************************************************************
5208 * IDirect3DDevice7::SetClipPlane
5210 * Sets custom clipping plane
5215 * Index: The index of the clipping plane
5216 * PlaneEquation: An equation defining the clipping plane
5220 * DDERR_INVALIDPARAMS if PlaneEquation is NULL
5221 * See IWineD3DDevice::SetClipPlane for more details
5223 *****************************************************************************/
5224 static HRESULT WINAPI
5225 IDirect3DDeviceImpl_7_SetClipPlane(IDirect3DDevice7 *iface,
5227 D3DVALUE* PlaneEquation)
5229 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
5231 TRACE("(%p)->(%08x,%p): Relay!\n", This, Index, PlaneEquation);
5234 return DDERR_INVALIDPARAMS;
5236 EnterCriticalSection(&ddraw_cs);
5237 hr = IWineD3DDevice_SetClipPlane(This->wineD3DDevice, Index, PlaneEquation);
5238 LeaveCriticalSection(&ddraw_cs);
5242 /*****************************************************************************
5243 * IDirect3DDevice7::GetClipPlane
5245 * Returns the clipping plane with a specific index
5248 * Index: The index of the desired plane
5249 * PlaneEquation: Address to store the plane equation to
5253 * DDERR_INVALIDPARAMS if PlaneEquation is NULL
5254 * See IWineD3DDevice::GetClipPlane for more details
5256 *****************************************************************************/
5257 static HRESULT WINAPI
5258 IDirect3DDeviceImpl_7_GetClipPlane(IDirect3DDevice7 *iface,
5260 D3DVALUE* PlaneEquation)
5262 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
5264 TRACE("(%p)->(%d,%p): Relay!\n", This, Index, PlaneEquation);
5267 return DDERR_INVALIDPARAMS;
5269 EnterCriticalSection(&ddraw_cs);
5270 hr = IWineD3DDevice_GetClipPlane(This->wineD3DDevice, Index, PlaneEquation);
5271 LeaveCriticalSection(&ddraw_cs);
5275 /*****************************************************************************
5276 * IDirect3DDevice7::GetInfo
5278 * Retrieves some information about the device. The DirectX sdk says that
5279 * this version returns S_FALSE for all retail builds of DirectX, that's what
5280 * this implementation does.
5283 * DevInfoID: Information type requested
5284 * DevInfoStruct: Pointer to a structure to store the info to
5285 * Size: Size of the structure
5288 * S_FALSE, because it's a non-debug driver
5290 *****************************************************************************/
5291 static HRESULT WINAPI
5292 IDirect3DDeviceImpl_7_GetInfo(IDirect3DDevice7 *iface,
5294 void *DevInfoStruct,
5297 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
5298 TRACE("(%p)->(%08x,%p,%08x)\n", This, DevInfoID, DevInfoStruct, Size);
5302 TRACE(" info requested : ");
5305 case D3DDEVINFOID_TEXTUREMANAGER: TRACE("D3DDEVINFOID_TEXTUREMANAGER\n"); break;
5306 case D3DDEVINFOID_D3DTEXTUREMANAGER: TRACE("D3DDEVINFOID_D3DTEXTUREMANAGER\n"); break;
5307 case D3DDEVINFOID_TEXTURING: TRACE("D3DDEVINFOID_TEXTURING\n"); break;
5308 default: ERR(" invalid flag !!!\n"); return DDERR_INVALIDPARAMS;
5312 return S_FALSE; /* According to MSDN, this is valid for a non-debug driver */
5315 const IDirect3DDevice7Vtbl IDirect3DDevice7_Vtbl =
5317 /*** IUnknown Methods ***/
5318 IDirect3DDeviceImpl_7_QueryInterface,
5319 IDirect3DDeviceImpl_7_AddRef,
5320 IDirect3DDeviceImpl_7_Release,
5321 /*** IDirect3DDevice7 ***/
5322 IDirect3DDeviceImpl_7_GetCaps,
5323 IDirect3DDeviceImpl_7_EnumTextureFormats,
5324 IDirect3DDeviceImpl_7_BeginScene,
5325 IDirect3DDeviceImpl_7_EndScene,
5326 IDirect3DDeviceImpl_7_GetDirect3D,
5327 IDirect3DDeviceImpl_7_SetRenderTarget,
5328 IDirect3DDeviceImpl_7_GetRenderTarget,
5329 IDirect3DDeviceImpl_7_Clear,
5330 IDirect3DDeviceImpl_7_SetTransform,
5331 IDirect3DDeviceImpl_7_GetTransform,
5332 IDirect3DDeviceImpl_7_SetViewport,
5333 IDirect3DDeviceImpl_7_MultiplyTransform,
5334 IDirect3DDeviceImpl_7_GetViewport,
5335 IDirect3DDeviceImpl_7_SetMaterial,
5336 IDirect3DDeviceImpl_7_GetMaterial,
5337 IDirect3DDeviceImpl_7_SetLight,
5338 IDirect3DDeviceImpl_7_GetLight,
5339 IDirect3DDeviceImpl_7_SetRenderState,
5340 IDirect3DDeviceImpl_7_GetRenderState,
5341 IDirect3DDeviceImpl_7_BeginStateBlock,
5342 IDirect3DDeviceImpl_7_EndStateBlock,
5343 IDirect3DDeviceImpl_7_PreLoad,
5344 IDirect3DDeviceImpl_7_DrawPrimitive,
5345 IDirect3DDeviceImpl_7_DrawIndexedPrimitive,
5346 IDirect3DDeviceImpl_7_SetClipStatus,
5347 IDirect3DDeviceImpl_7_GetClipStatus,
5348 IDirect3DDeviceImpl_7_DrawPrimitiveStrided,
5349 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveStrided,
5350 IDirect3DDeviceImpl_7_DrawPrimitiveVB,
5351 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB,
5352 IDirect3DDeviceImpl_7_ComputeSphereVisibility,
5353 IDirect3DDeviceImpl_7_GetTexture,
5354 IDirect3DDeviceImpl_7_SetTexture,
5355 IDirect3DDeviceImpl_7_GetTextureStageState,
5356 IDirect3DDeviceImpl_7_SetTextureStageState,
5357 IDirect3DDeviceImpl_7_ValidateDevice,
5358 IDirect3DDeviceImpl_7_ApplyStateBlock,
5359 IDirect3DDeviceImpl_7_CaptureStateBlock,
5360 IDirect3DDeviceImpl_7_DeleteStateBlock,
5361 IDirect3DDeviceImpl_7_CreateStateBlock,
5362 IDirect3DDeviceImpl_7_Load,
5363 IDirect3DDeviceImpl_7_LightEnable,
5364 IDirect3DDeviceImpl_7_GetLightEnable,
5365 IDirect3DDeviceImpl_7_SetClipPlane,
5366 IDirect3DDeviceImpl_7_GetClipPlane,
5367 IDirect3DDeviceImpl_7_GetInfo
5370 const IDirect3DDevice3Vtbl IDirect3DDevice3_Vtbl =
5372 /*** IUnknown Methods ***/
5373 Thunk_IDirect3DDeviceImpl_3_QueryInterface,
5374 Thunk_IDirect3DDeviceImpl_3_AddRef,
5375 Thunk_IDirect3DDeviceImpl_3_Release,
5376 /*** IDirect3DDevice3 ***/
5377 IDirect3DDeviceImpl_3_GetCaps,
5378 IDirect3DDeviceImpl_3_GetStats,
5379 IDirect3DDeviceImpl_3_AddViewport,
5380 IDirect3DDeviceImpl_3_DeleteViewport,
5381 IDirect3DDeviceImpl_3_NextViewport,
5382 Thunk_IDirect3DDeviceImpl_3_EnumTextureFormats,
5383 Thunk_IDirect3DDeviceImpl_3_BeginScene,
5384 Thunk_IDirect3DDeviceImpl_3_EndScene,
5385 Thunk_IDirect3DDeviceImpl_3_GetDirect3D,
5386 IDirect3DDeviceImpl_3_SetCurrentViewport,
5387 IDirect3DDeviceImpl_3_GetCurrentViewport,
5388 Thunk_IDirect3DDeviceImpl_3_SetRenderTarget,
5389 Thunk_IDirect3DDeviceImpl_3_GetRenderTarget,
5390 IDirect3DDeviceImpl_3_Begin,
5391 IDirect3DDeviceImpl_3_BeginIndexed,
5392 IDirect3DDeviceImpl_3_Vertex,
5393 IDirect3DDeviceImpl_3_Index,
5394 IDirect3DDeviceImpl_3_End,
5395 Thunk_IDirect3DDeviceImpl_3_GetRenderState,
5396 Thunk_IDirect3DDeviceImpl_3_SetRenderState,
5397 IDirect3DDeviceImpl_3_GetLightState,
5398 IDirect3DDeviceImpl_3_SetLightState,
5399 Thunk_IDirect3DDeviceImpl_3_SetTransform,
5400 Thunk_IDirect3DDeviceImpl_3_GetTransform,
5401 Thunk_IDirect3DDeviceImpl_3_MultiplyTransform,
5402 Thunk_IDirect3DDeviceImpl_3_DrawPrimitive,
5403 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitive,
5404 Thunk_IDirect3DDeviceImpl_3_SetClipStatus,
5405 Thunk_IDirect3DDeviceImpl_3_GetClipStatus,
5406 Thunk_IDirect3DDeviceImpl_3_DrawPrimitiveStrided,
5407 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitiveStrided,
5408 Thunk_IDirect3DDeviceImpl_3_DrawPrimitiveVB,
5409 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitiveVB,
5410 Thunk_IDirect3DDeviceImpl_3_ComputeSphereVisibility,
5411 Thunk_IDirect3DDeviceImpl_3_GetTexture,
5412 Thunk_IDirect3DDeviceImpl_3_SetTexture,
5413 Thunk_IDirect3DDeviceImpl_3_GetTextureStageState,
5414 Thunk_IDirect3DDeviceImpl_3_SetTextureStageState,
5415 Thunk_IDirect3DDeviceImpl_3_ValidateDevice
5418 const IDirect3DDevice2Vtbl IDirect3DDevice2_Vtbl =
5420 /*** IUnknown Methods ***/
5421 Thunk_IDirect3DDeviceImpl_2_QueryInterface,
5422 Thunk_IDirect3DDeviceImpl_2_AddRef,
5423 Thunk_IDirect3DDeviceImpl_2_Release,
5424 /*** IDirect3DDevice2 ***/
5425 Thunk_IDirect3DDeviceImpl_2_GetCaps,
5426 IDirect3DDeviceImpl_2_SwapTextureHandles,
5427 Thunk_IDirect3DDeviceImpl_2_GetStats,
5428 Thunk_IDirect3DDeviceImpl_2_AddViewport,
5429 Thunk_IDirect3DDeviceImpl_2_DeleteViewport,
5430 Thunk_IDirect3DDeviceImpl_2_NextViewport,
5431 IDirect3DDeviceImpl_2_EnumTextureFormats,
5432 Thunk_IDirect3DDeviceImpl_2_BeginScene,
5433 Thunk_IDirect3DDeviceImpl_2_EndScene,
5434 Thunk_IDirect3DDeviceImpl_2_GetDirect3D,
5435 Thunk_IDirect3DDeviceImpl_2_SetCurrentViewport,
5436 Thunk_IDirect3DDeviceImpl_2_GetCurrentViewport,
5437 Thunk_IDirect3DDeviceImpl_2_SetRenderTarget,
5438 Thunk_IDirect3DDeviceImpl_2_GetRenderTarget,
5439 Thunk_IDirect3DDeviceImpl_2_Begin,
5440 Thunk_IDirect3DDeviceImpl_2_BeginIndexed,
5441 Thunk_IDirect3DDeviceImpl_2_Vertex,
5442 Thunk_IDirect3DDeviceImpl_2_Index,
5443 Thunk_IDirect3DDeviceImpl_2_End,
5444 Thunk_IDirect3DDeviceImpl_2_GetRenderState,
5445 Thunk_IDirect3DDeviceImpl_2_SetRenderState,
5446 Thunk_IDirect3DDeviceImpl_2_GetLightState,
5447 Thunk_IDirect3DDeviceImpl_2_SetLightState,
5448 Thunk_IDirect3DDeviceImpl_2_SetTransform,
5449 Thunk_IDirect3DDeviceImpl_2_GetTransform,
5450 Thunk_IDirect3DDeviceImpl_2_MultiplyTransform,
5451 Thunk_IDirect3DDeviceImpl_2_DrawPrimitive,
5452 Thunk_IDirect3DDeviceImpl_2_DrawIndexedPrimitive,
5453 Thunk_IDirect3DDeviceImpl_2_SetClipStatus,
5454 Thunk_IDirect3DDeviceImpl_2_GetClipStatus
5457 const IDirect3DDeviceVtbl IDirect3DDevice1_Vtbl =
5459 /*** IUnknown Methods ***/
5460 Thunk_IDirect3DDeviceImpl_1_QueryInterface,
5461 Thunk_IDirect3DDeviceImpl_1_AddRef,
5462 Thunk_IDirect3DDeviceImpl_1_Release,
5463 /*** IDirect3DDevice1 ***/
5464 IDirect3DDeviceImpl_1_Initialize,
5465 Thunk_IDirect3DDeviceImpl_1_GetCaps,
5466 Thunk_IDirect3DDeviceImpl_1_SwapTextureHandles,
5467 IDirect3DDeviceImpl_1_CreateExecuteBuffer,
5468 Thunk_IDirect3DDeviceImpl_1_GetStats,
5469 IDirect3DDeviceImpl_1_Execute,
5470 Thunk_IDirect3DDeviceImpl_1_AddViewport,
5471 Thunk_IDirect3DDeviceImpl_1_DeleteViewport,
5472 Thunk_IDirect3DDeviceImpl_1_NextViewport,
5473 IDirect3DDeviceImpl_1_Pick,
5474 IDirect3DDeviceImpl_1_GetPickRecords,
5475 Thunk_IDirect3DDeviceImpl_1_EnumTextureFormats,
5476 IDirect3DDeviceImpl_1_CreateMatrix,
5477 IDirect3DDeviceImpl_1_SetMatrix,
5478 IDirect3DDeviceImpl_1_GetMatrix,
5479 IDirect3DDeviceImpl_1_DeleteMatrix,
5480 Thunk_IDirect3DDeviceImpl_1_BeginScene,
5481 Thunk_IDirect3DDeviceImpl_1_EndScene,
5482 Thunk_IDirect3DDeviceImpl_1_GetDirect3D
5485 /*****************************************************************************
5486 * IDirect3DDeviceImpl_CreateHandle
5488 * Not called from the VTable
5490 * Some older interface versions operate with handles, which are basically
5491 * DWORDs which identify an interface, for example
5492 * IDirect3DDevice::SetRenderState with DIRECT3DRENDERSTATE_TEXTUREHANDLE
5494 * Those handle could be just casts to the interface pointers or vice versa,
5495 * but that is not 64 bit safe and would mean blindly derefering a DWORD
5496 * passed by the app. Instead there is a dynamic array in the device which
5497 * keeps a DWORD to pointer information and a type for the handle.
5499 * Basically this array only grows, when a handle is freed its pointer is
5500 * just set to NULL. There will be much more reads from the array than
5501 * insertion operations, so a dynamic array is fine.
5504 * This: D3DDevice implementation for which this handle should be created
5507 * A free handle on success
5510 *****************************************************************************/
5512 IDirect3DDeviceImpl_CreateHandle(IDirect3DDeviceImpl *This)
5515 struct HandleEntry *oldHandles = This->Handles;
5517 TRACE("(%p)\n", This);
5519 for(i = 0; i < This->numHandles; i++)
5521 if(This->Handles[i].ptr == NULL &&
5522 This->Handles[i].type == DDrawHandle_Unknown)
5524 TRACE("Reusing freed handle %d\n", i + 1);
5529 TRACE("Growing the handle array\n");
5532 This->Handles = HeapAlloc(GetProcessHeap(), 0, sizeof(struct HandleEntry) * This->numHandles);
5535 ERR("Out of memory\n");
5536 This->Handles = oldHandles;
5542 memcpy(This->Handles, oldHandles, (This->numHandles - 1) * sizeof(struct HandleEntry));
5543 HeapFree(GetProcessHeap(), 0, oldHandles);
5546 TRACE("Returning %d\n", This->numHandles);
5547 return This->numHandles;
5550 /*****************************************************************************
5551 * IDirect3DDeviceImpl_UpdateDepthStencil
5553 * Checks the current render target for attached depth stencils and sets the
5554 * WineD3D depth stencil accordingly.
5557 * The depth stencil state to set if creating the device
5559 *****************************************************************************/
5561 IDirect3DDeviceImpl_UpdateDepthStencil(IDirect3DDeviceImpl *This)
5563 IDirectDrawSurface7 *depthStencil = NULL;
5564 IDirectDrawSurfaceImpl *dsi;
5565 static DDSCAPS2 depthcaps = { DDSCAPS_ZBUFFER, 0, 0, 0 };
5567 IDirectDrawSurface7_GetAttachedSurface(ICOM_INTERFACE(This->target, IDirectDrawSurface7),
5572 TRACE("Setting wined3d depth stencil to NULL\n");
5573 IWineD3DDevice_SetDepthStencilSurface(This->wineD3DDevice,
5575 return WINED3DZB_FALSE;
5578 dsi = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, depthStencil);
5579 TRACE("Setting wined3d depth stencil to %p (wined3d %p)\n", dsi, dsi->WineD3DSurface);
5580 IWineD3DDevice_SetDepthStencilSurface(This->wineD3DDevice,
5581 dsi->WineD3DSurface);
5583 IDirectDrawSurface7_Release(depthStencil);
5584 return WINED3DZB_TRUE;