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"
45 #include "wine/exception.h"
51 #include "ddraw_private.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(d3d7);
54 WINE_DECLARE_DEBUG_CHANNEL(ddraw_thunk);
57 const GUID IID_D3DDEVICE_WineD3D = {
61 { 0xb7,0x98,0xc6,0x8a,0x77,0x2d,0x72,0x2a }
64 /*****************************************************************************
65 * IUnknown Methods. Common for Version 1, 2, 3 and 7
66 *****************************************************************************/
68 /*****************************************************************************
69 * IDirect3DDevice7::QueryInterface
71 * Used to query other interfaces from a Direct3DDevice interface.
72 * It can return interface pointers to all Direct3DDevice versions as well
73 * as IDirectDraw and IDirect3D. For a link to QueryInterface
74 * rules see ddraw.c, IDirectDraw7::QueryInterface
76 * Exists in Version 1, 2, 3 and 7
79 * refiid: Interface ID queried for
80 * obj: Used to return the interface pointer
83 * D3D_OK or E_NOINTERFACE
85 *****************************************************************************/
87 IDirect3DDeviceImpl_7_QueryInterface(IDirect3DDevice7 *iface,
91 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
92 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(refiid), obj);
94 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
98 return DDERR_INVALIDPARAMS;
100 if ( IsEqualGUID( &IID_IUnknown, refiid ) )
102 *obj = ICOM_INTERFACE(This, IDirect3DDevice7);
105 /* Check DirectDraw Interfac
\ 1s */
106 else if( IsEqualGUID( &IID_IDirectDraw7, refiid ) )
108 *obj = ICOM_INTERFACE(This->ddraw, IDirectDraw7);
109 TRACE("(%p) Returning IDirectDraw7 interface at %p\n", This, *obj);
111 else if ( IsEqualGUID( &IID_IDirectDraw4, refiid ) )
113 *obj = ICOM_INTERFACE(This->ddraw, IDirectDraw4);
114 TRACE("(%p) Returning IDirectDraw4 interface at %p\n", This, *obj);
116 else if ( IsEqualGUID( &IID_IDirectDraw2, refiid ) )
118 *obj = ICOM_INTERFACE(This->ddraw, IDirectDraw2);
119 TRACE("(%p) Returning IDirectDraw2 interface at %p\n", This, *obj);
121 else if( IsEqualGUID( &IID_IDirectDraw, refiid ) )
123 *obj = ICOM_INTERFACE(This->ddraw, IDirectDraw);
124 TRACE("(%p) Returning IDirectDraw interface at %p\n", This, *obj);
128 else if ( IsEqualGUID( &IID_IDirect3D , refiid ) )
130 *obj = ICOM_INTERFACE(This->ddraw, IDirect3D);
131 TRACE("(%p) Returning IDirect3D interface at %p\n", This, *obj);
133 else if ( IsEqualGUID( &IID_IDirect3D2 , refiid ) )
135 *obj = ICOM_INTERFACE(This->ddraw, IDirect3D2);
136 TRACE("(%p) Returning IDirect3D2 interface at %p\n", This, *obj);
138 else if ( IsEqualGUID( &IID_IDirect3D3 , refiid ) )
140 *obj = ICOM_INTERFACE(This->ddraw, IDirect3D3);
141 TRACE("(%p) Returning IDirect3D3 interface at %p\n", This, *obj);
143 else if ( IsEqualGUID( &IID_IDirect3D7 , refiid ) )
145 *obj = ICOM_INTERFACE(This->ddraw, IDirect3D7);
146 TRACE("(%p) Returning IDirect3D7 interface at %p\n", This, *obj);
150 else if ( IsEqualGUID( &IID_IDirect3DDevice , refiid ) )
152 *obj = ICOM_INTERFACE(This, IDirect3DDevice);
153 TRACE("(%p) Returning IDirect3DDevice interface at %p\n", This, *obj);
155 else if ( IsEqualGUID( &IID_IDirect3DDevice2 , refiid ) ) {
156 *obj = ICOM_INTERFACE(This, IDirect3DDevice2);
157 TRACE("(%p) Returning IDirect3DDevice2 interface at %p\n", This, *obj);
159 else if ( IsEqualGUID( &IID_IDirect3DDevice3 , refiid ) ) {
160 *obj = ICOM_INTERFACE(This, IDirect3DDevice3);
161 TRACE("(%p) Returning IDirect3DDevice3 interface at %p\n", This, *obj);
163 else if ( IsEqualGUID( &IID_IDirect3DDevice7 , refiid ) ) {
164 *obj = ICOM_INTERFACE(This, IDirect3DDevice7);
165 TRACE("(%p) Returning IDirect3DDevice7 interface at %p\n", This, *obj);
168 /* Unknown interface */
171 ERR("(%p)->(%s, %p): No interface found\n", This, debugstr_guid(refiid), obj);
172 return E_NOINTERFACE;
175 /* AddRef the returned interface */
176 IUnknown_AddRef( (IUnknown *) *obj);
180 static HRESULT WINAPI
181 Thunk_IDirect3DDeviceImpl_3_QueryInterface(IDirect3DDevice3 *iface,
185 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
186 TRACE_(ddraw_thunk)("(%p)->(%s,%p) thunking to IDirect3DDevice7 interface.\n", This, debugstr_guid(riid), obj);
187 return IDirect3DDevice7_QueryInterface(ICOM_INTERFACE(This, IDirect3DDevice7),
192 static HRESULT WINAPI
193 Thunk_IDirect3DDeviceImpl_2_QueryInterface(IDirect3DDevice2 *iface,
197 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
198 TRACE_(ddraw_thunk)("(%p)->(%s,%p) thunking to IDirect3DDevice7 interface.\n", This, debugstr_guid(riid), obj);
199 return IDirect3DDevice7_QueryInterface(ICOM_INTERFACE(This, IDirect3DDevice7),
204 static HRESULT WINAPI
205 Thunk_IDirect3DDeviceImpl_1_QueryInterface(IDirect3DDevice *iface,
209 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
210 TRACE_(ddraw_thunk)("(%p)->(%s,%p) thunking to IDirect3DDevice7 interface.\n", This, debugstr_guid(riid), obp);
211 return IDirect3DDevice7_QueryInterface(ICOM_INTERFACE(This, IDirect3DDevice7),
216 /*****************************************************************************
217 * IDirect3DDevice7::AddRef
219 * Increases the refcount....
220 * The most exciting Method, definitely
222 * Exists in Version 1, 2, 3 and 7
227 *****************************************************************************/
229 IDirect3DDeviceImpl_7_AddRef(IDirect3DDevice7 *iface)
231 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
232 ULONG ref = InterlockedIncrement(&This->ref);
234 TRACE("(%p) : incrementing from %u.\n", This, ref -1);
240 Thunk_IDirect3DDeviceImpl_3_AddRef(IDirect3DDevice3 *iface)
242 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
243 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
244 return IDirect3DDevice7_AddRef(ICOM_INTERFACE(This, IDirect3DDevice7));
248 Thunk_IDirect3DDeviceImpl_2_AddRef(IDirect3DDevice2 *iface)
250 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
251 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
252 return IDirect3DDevice7_AddRef(ICOM_INTERFACE(This, IDirect3DDevice7));
256 Thunk_IDirect3DDeviceImpl_1_AddRef(IDirect3DDevice *iface)
258 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", iface);
259 return IDirect3DDevice7_AddRef(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice, IDirect3DDevice7, iface));
262 /*****************************************************************************
263 * IDirect3DDevice7::Release
265 * Decreases the refcount of the interface
266 * When the refcount is reduced to 0, the object is destroyed.
268 * Exists in Version 1, 2, 3 and 7
273 *****************************************************************************/
275 IDirect3DDeviceImpl_7_Release(IDirect3DDevice7 *iface)
277 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
278 ULONG ref = InterlockedDecrement(&This->ref);
280 TRACE("(%p)->() decrementing from %u.\n", This, ref +1);
282 /* This method doesn't destroy the WineD3DDevice, because it's still in use for
283 * 2D rendering. IDirectDrawSurface7::Release will destroy the WineD3DDevice
284 * when the render target is released
288 IParent *IndexBufferParent;
291 /* Free the index buffer */
292 IWineD3DDevice_SetIndices(This->wineD3DDevice,
295 IWineD3DIndexBuffer_GetParent(This->indexbuffer,
296 (IUnknown **) &IndexBufferParent);
297 IParent_Release(IndexBufferParent); /* Once for the getParent */
298 if( IParent_Release(IndexBufferParent) != 0) /* And now to destroy it */
300 ERR(" (%p) Something is still holding the index buffer parent %p\n", This, IndexBufferParent);
303 /* Restore the render targets */
304 if(This->OffScreenTarget)
306 /* This->target is the offscreen target.
307 * This->ddraw->d3d_target is the target used by DDraw
309 TRACE("(%p) Release: Using %p as front buffer, %p as back buffer\n", This, This->ddraw->d3d_target, NULL);
310 IWineD3DDevice_SetFrontBackBuffers(This->wineD3DDevice,
311 This->ddraw->d3d_target->WineD3DSurface,
315 /* Release the WineD3DDevice. This won't destroy it */
316 if(IWineD3DDevice_Release(This->wineD3DDevice) <= 0)
318 ERR(" (%p) The wineD3D device %p was destroyed unexpectadely. Prepare for trouble\n", This, This->wineD3DDevice);
321 /* The texture handles should be unset by now, but there might be some bits
322 * missing in our reference counting(needs test). Do a sanity check
324 for(i = 0; i < This->numHandles; i++)
326 if(This->Handles[i].ptr)
328 switch(This->Handles[i].type)
330 case DDrawHandle_Texture:
332 IDirectDrawSurfaceImpl *surf = (IDirectDrawSurfaceImpl *) This->Handles[i].ptr;
333 FIXME("Texture Handle %d not unset properly\n", i + 1);
338 case DDrawHandle_Material:
340 IDirect3DMaterialImpl *mat = (IDirect3DMaterialImpl *) This->Handles[i].ptr;
341 FIXME("Material handle %d not unset properly\n", i + 1);
346 case DDrawHandle_Matrix:
348 /* No fixme here because this might happen because of sloppy apps */
349 WARN("Leftover matrix handle %d, deleting\n", i + 1);
350 IDirect3DDevice_DeleteMatrix(ICOM_INTERFACE(This, IDirect3DDevice),
356 FIXME("Unknown handle %d not unset properly\n", i + 1);
361 HeapFree(GetProcessHeap(), 0, This->Handles);
363 /* Release the render target and the WineD3D render target
364 * (See IDirect3D7::CreateDevice for more comments on this)
366 IDirectDrawSurface7_Release(ICOM_INTERFACE(This->target, IDirectDrawSurface7));
367 IDirectDrawSurface7_Release(ICOM_INTERFACE(This->ddraw->d3d_target,IDirectDrawSurface7));
369 This->ddraw->d3ddevice = NULL;
371 /* Now free the structure */
372 HeapFree(GetProcessHeap(), 0, This);
379 Thunk_IDirect3DDeviceImpl_3_Release(IDirect3DDevice3 *iface)
381 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
382 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
383 return IDirect3DDevice7_Release(ICOM_INTERFACE(This, IDirect3DDevice7));
387 Thunk_IDirect3DDeviceImpl_2_Release(IDirect3DDevice2 *iface)
389 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
390 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
391 return IDirect3DDevice7_Release(ICOM_INTERFACE(This, IDirect3DDevice7));
395 Thunk_IDirect3DDeviceImpl_1_Release(IDirect3DDevice *iface)
397 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
398 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
399 return IDirect3DDevice7_Release(ICOM_INTERFACE(This, IDirect3DDevice7));
402 /*****************************************************************************
403 * IDirect3DDevice Methods
404 *****************************************************************************/
406 /*****************************************************************************
407 * IDirect3DDevice::Initialize
409 * Initializes a Direct3DDevice. This implementation is a no-op, as all
410 * initialization is done at create time.
412 * Exists in Version 1
415 * No idea what they mean, as the MSDN page is gone
419 *****************************************************************************/
420 static HRESULT WINAPI
421 IDirect3DDeviceImpl_1_Initialize(IDirect3DDevice *iface,
422 IDirect3D *Direct3D, GUID *guid,
425 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
427 /* It shouldn't be crucial, but print a FIXME, I'm interested if
428 * any game calls it and when
430 FIXME("(%p)->(%p,%p,%p): No-op!\n", This, Direct3D, guid, Desc);
435 /*****************************************************************************
436 * IDirect3DDevice7::GetCaps
438 * Retrieves the device's capabilities
440 * This implementation is used for Version 7 only, the older versions have
441 * their own implementation.
444 * Desc: Pointer to a D3DDEVICEDESC7 structure to fill
448 * D3DERR_* if a problem occurs. See WineD3D
450 *****************************************************************************/
451 static HRESULT WINAPI
452 IDirect3DDeviceImpl_7_GetCaps(IDirect3DDevice7 *iface,
453 D3DDEVICEDESC7 *Desc)
455 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
456 D3DDEVICEDESC OldDesc;
457 TRACE("(%p)->(%p)\n", This, Desc);
459 /* Call the same function used by IDirect3D, this saves code */
460 return IDirect3DImpl_GetCaps(This->ddraw->wineD3D, &OldDesc, Desc);
463 /*****************************************************************************
464 * IDirect3DDevice3::GetCaps
466 * Retrieves the capabilities of the hardware device and the emulation
467 * device. For Wine, hardware and emulation are the same (it's all HW).
469 * This implementation is used for Version 1, 2, and 3. Version 7 has its own
472 * HWDesc: Structure to fill with the HW caps
473 * HelDesc: Structure to fill with the hardare emulation caps
477 * D3DERR_* if a problem occurs. See WineD3D
479 *****************************************************************************/
480 static HRESULT WINAPI
481 IDirect3DDeviceImpl_3_GetCaps(IDirect3DDevice3 *iface,
482 D3DDEVICEDESC *HWDesc,
483 D3DDEVICEDESC *HelDesc)
485 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
486 D3DDEVICEDESC7 newDesc;
488 TRACE("(%p)->(%p,%p)\n", iface, HWDesc, HelDesc);
490 hr = IDirect3DImpl_GetCaps(This->ddraw->wineD3D, HWDesc, &newDesc);
491 if(hr != D3D_OK) return hr;
497 static HRESULT WINAPI
498 Thunk_IDirect3DDeviceImpl_2_GetCaps(IDirect3DDevice2 *iface,
499 D3DDEVICEDESC *D3DHWDevDesc,
500 D3DDEVICEDESC *D3DHELDevDesc)
502 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
503 TRACE_(ddraw_thunk)("(%p)->(%p,%p) thunking to IDirect3DDevice3 interface.\n", This, D3DHWDevDesc, D3DHELDevDesc);
504 return IDirect3DDevice3_GetCaps(ICOM_INTERFACE(This, IDirect3DDevice3),
509 static HRESULT WINAPI
510 Thunk_IDirect3DDeviceImpl_1_GetCaps(IDirect3DDevice *iface,
511 D3DDEVICEDESC *D3DHWDevDesc,
512 D3DDEVICEDESC *D3DHELDevDesc)
514 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
515 TRACE_(ddraw_thunk)("(%p)->(%p,%p) thunking to IDirect3DDevice3 interface.\n", This, D3DHWDevDesc, D3DHELDevDesc);
516 return IDirect3DDevice3_GetCaps(ICOM_INTERFACE(This, IDirect3DDevice3),
521 /*****************************************************************************
522 * IDirect3DDevice2::SwapTextureHandles
524 * Swaps the texture handles of 2 Texture interfaces. Version 1 and 2
527 * Tex1, Tex2: The 2 Textures to swap
532 *****************************************************************************/
533 static HRESULT WINAPI
534 IDirect3DDeviceImpl_2_SwapTextureHandles(IDirect3DDevice2 *iface,
535 IDirect3DTexture2 *Tex1,
536 IDirect3DTexture2 *Tex2)
538 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
540 IDirectDrawSurfaceImpl *surf1 = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture2, Tex1);
541 IDirectDrawSurfaceImpl *surf2 = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture2, Tex2);
542 TRACE("(%p)->(%p,%p)\n", This, surf1, surf2);
544 This->Handles[surf1->Handle - 1].ptr = surf2;
545 This->Handles[surf2->Handle - 1].ptr = surf1;
547 swap = surf2->Handle;
548 surf2->Handle = surf1->Handle;
549 surf1->Handle = swap;
554 static HRESULT WINAPI
555 Thunk_IDirect3DDeviceImpl_1_SwapTextureHandles(IDirect3DDevice *iface,
556 IDirect3DTexture *D3DTex1,
557 IDirect3DTexture *D3DTex2)
559 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
560 IDirectDrawSurfaceImpl *surf1 = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture, D3DTex1);
561 IDirectDrawSurfaceImpl *surf2 = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture, D3DTex2);
562 TRACE_(ddraw_thunk)("(%p)->(%p,%p) thunking to IDirect3DDevice2 interface.\n", This, surf1, surf2);
563 return IDirect3DDevice2_SwapTextureHandles(ICOM_INTERFACE(This, IDirect3DDevice2),
564 ICOM_INTERFACE(surf1, IDirect3DTexture2),
565 ICOM_INTERFACE(surf2, IDirect3DTexture2));
568 /*****************************************************************************
569 * IDirect3DDevice3::GetStats
571 * This method seems to retrieve some stats from the device.
572 * The MSDN documentation doesn't exist any more, but the D3DSTATS
573 * structure suggests that the amout of drawn primitives and processed
574 * vertices is returned.
576 * Exists in Version 1, 2 and 3
579 * Stats: Pointer to a D3DSTATS structure to be filled
583 * DDERR_INVALIDPARAMS if Stats == NULL
585 *****************************************************************************/
586 static HRESULT WINAPI
587 IDirect3DDeviceImpl_3_GetStats(IDirect3DDevice3 *iface,
590 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
591 FIXME("(%p)->(%p): Stub!\n", This, Stats);
594 return DDERR_INVALIDPARAMS;
596 /* Fill the Stats with 0 */
597 Stats->dwTrianglesDrawn = 0;
598 Stats->dwLinesDrawn = 0;
599 Stats->dwPointsDrawn = 0;
600 Stats->dwSpansDrawn = 0;
601 Stats->dwVerticesProcessed = 0;
606 static HRESULT WINAPI
607 Thunk_IDirect3DDeviceImpl_2_GetStats(IDirect3DDevice2 *iface,
610 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
611 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, Stats);
612 return IDirect3DDevice3_GetStats(ICOM_INTERFACE(This, IDirect3DDevice3),
616 static HRESULT WINAPI
617 Thunk_IDirect3DDeviceImpl_1_GetStats(IDirect3DDevice *iface,
620 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
621 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, Stats);
622 return IDirect3DDevice3_GetStats(ICOM_INTERFACE(This, IDirect3DDevice3),
626 /*****************************************************************************
627 * IDirect3DDevice::CreateExecuteBuffer
629 * Creates an IDirect3DExecuteBuffer, used for rendering with a
635 * Desc: Buffer description
636 * ExecuteBuffer: Address to return the Interface pointer at
637 * UnkOuter: Must be NULL. Basically for aggregation, which ddraw doesn't
641 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
642 * DDERR_OUTOFMEMORY if we ran out of memory
645 *****************************************************************************/
646 static HRESULT WINAPI
647 IDirect3DDeviceImpl_1_CreateExecuteBuffer(IDirect3DDevice *iface,
648 D3DEXECUTEBUFFERDESC *Desc,
649 IDirect3DExecuteBuffer **ExecuteBuffer,
652 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
653 IDirect3DExecuteBufferImpl* object;
654 TRACE("(%p)->(%p,%p,%p)!\n", This, Desc, ExecuteBuffer, UnkOuter);
657 return CLASS_E_NOAGGREGATION;
659 /* Allocate the new Execute Buffer */
660 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DExecuteBufferImpl));
663 ERR("Out of memory when allocating a IDirect3DExecuteBufferImpl structure\n");
664 return DDERR_OUTOFMEMORY;
667 ICOM_INIT_INTERFACE(object, IDirect3DExecuteBuffer, IDirect3DExecuteBuffer_Vtbl);
670 object->d3ddev = This;
672 /* Initializes memory */
673 memcpy(&object->desc, Desc, Desc->dwSize);
675 /* No buffer given */
676 if ((object->desc.dwFlags & D3DDEB_LPDATA) == 0)
677 object->desc.lpData = NULL;
679 /* No buffer size given */
680 if ((object->desc.dwFlags & D3DDEB_BUFSIZE) == 0)
681 object->desc.dwBufferSize = 0;
683 /* Create buffer if asked */
684 if ((object->desc.lpData == NULL) && (object->desc.dwBufferSize > 0))
686 object->need_free = TRUE;
687 object->desc.lpData = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,object->desc.dwBufferSize);
688 if(!object->desc.lpData)
690 ERR("Out of memory when allocating the execute buffer data\n");
691 HeapFree(GetProcessHeap(), 0, object);
692 return DDERR_OUTOFMEMORY;
697 object->need_free = FALSE;
700 /* No vertices for the moment */
701 object->vertex_data = NULL;
703 object->desc.dwFlags |= D3DDEB_LPDATA;
705 object->indices = NULL;
706 object->nb_indices = 0;
708 *ExecuteBuffer = ICOM_INTERFACE(object, IDirect3DExecuteBuffer);
710 TRACE(" Returning IDirect3DExecuteBuffer at %p, implementation is at %p\n", *ExecuteBuffer, object);
715 /*****************************************************************************
716 * IDirect3DDevice::Execute
718 * Executes all the stuff in an execute buffer.
721 * ExecuteBuffer: The buffer to execute
722 * Viewport: The viewport used for rendering
726 * DDERR_INVALIDPARAMS if ExecuteBuffer == NULL
729 *****************************************************************************/
730 static HRESULT WINAPI
731 IDirect3DDeviceImpl_1_Execute(IDirect3DDevice *iface,
732 IDirect3DExecuteBuffer *ExecuteBuffer,
733 IDirect3DViewport *Viewport,
736 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
737 IDirect3DExecuteBufferImpl *Direct3DExecuteBufferImpl = ICOM_OBJECT(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, ExecuteBuffer);
738 IDirect3DViewportImpl *Direct3DViewportImpl = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport);
740 TRACE("(%p)->(%p,%p,%08x)\n", This, Direct3DExecuteBufferImpl, Direct3DViewportImpl, Flags);
742 if(!Direct3DExecuteBufferImpl)
743 return DDERR_INVALIDPARAMS;
746 IDirect3DExecuteBufferImpl_Execute(Direct3DExecuteBufferImpl, This, Direct3DViewportImpl);
751 /*****************************************************************************
752 * IDirect3DDevice3::AddViewport
754 * Add a Direct3DViewport to the device's viewport list. These viewports
755 * are wrapped to IDirect3DDevice7 viewports in viewport.c
757 * Exists in Version 1, 2 and 3. Note that IDirect3DViewport 1, 2 and 3
758 * are the same interfaces.
761 * Viewport: The viewport to add
764 * DDERR_INVALIDPARAMS if Viewport == NULL
767 *****************************************************************************/
768 static HRESULT WINAPI
769 IDirect3DDeviceImpl_3_AddViewport(IDirect3DDevice3 *iface,
770 IDirect3DViewport3 *Viewport)
772 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
773 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport);
775 TRACE("(%p)->(%p)\n", This, vp);
779 return DDERR_INVALIDPARAMS;
781 vp->next = This->viewport_list;
782 This->viewport_list = vp;
787 static HRESULT WINAPI
788 Thunk_IDirect3DDeviceImpl_2_AddViewport(IDirect3DDevice2 *iface,
789 IDirect3DViewport2 *Direct3DViewport2)
791 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
792 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport2);
793 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, vp);
794 return IDirect3DDevice3_AddViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
795 ICOM_INTERFACE(vp, IDirect3DViewport3));
798 static HRESULT WINAPI
799 Thunk_IDirect3DDeviceImpl_1_AddViewport(IDirect3DDevice *iface,
800 IDirect3DViewport *Direct3DViewport)
802 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
803 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport);
804 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, vp);
805 return IDirect3DDevice3_AddViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
806 ICOM_INTERFACE(vp, IDirect3DViewport3));
809 /*****************************************************************************
810 * IDirect3DDevice3::DeleteViewport
812 * Deletes a Direct3DViewport from the device's viewport list.
814 * Exists in Version 1, 2 and 3. Note that all Viewport interface versions
818 * Viewport: The viewport to delete
822 * DDERR_INVALIDPARAMS if the viewport wasn't found in the list
824 *****************************************************************************/
825 static HRESULT WINAPI
826 IDirect3DDeviceImpl_3_DeleteViewport(IDirect3DDevice3 *iface,
827 IDirect3DViewport3 *Viewport)
829 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
830 IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *) Viewport;
831 IDirect3DViewportImpl *cur_viewport, *prev_viewport = NULL;
833 TRACE("(%p)->(%p)\n", This, vp);
835 cur_viewport = This->viewport_list;
836 while (cur_viewport != NULL)
838 if (cur_viewport == vp)
840 if (prev_viewport == NULL) This->viewport_list = cur_viewport->next;
841 else prev_viewport->next = cur_viewport->next;
842 /* TODO : add desactivate of the viewport and all associated lights... */
845 prev_viewport = cur_viewport;
846 cur_viewport = cur_viewport->next;
849 return DDERR_INVALIDPARAMS;
852 static HRESULT WINAPI
853 Thunk_IDirect3DDeviceImpl_2_DeleteViewport(IDirect3DDevice2 *iface,
854 IDirect3DViewport2 *Direct3DViewport2)
856 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
857 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport2);
858 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, vp);
859 return IDirect3DDevice3_DeleteViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
860 ICOM_INTERFACE(vp, IDirect3DViewport3));
863 static HRESULT WINAPI
864 Thunk_IDirect3DDeviceImpl_1_DeleteViewport(IDirect3DDevice *iface,
865 IDirect3DViewport *Direct3DViewport2)
867 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
868 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport2);
869 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, vp);
870 return IDirect3DDevice3_DeleteViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
871 ICOM_INTERFACE(vp, IDirect3DViewport3));
874 /*****************************************************************************
875 * IDirect3DDevice3::NextViewport
877 * Returns a viewport from the viewport list, depending on the
878 * passed viewport and the flags.
880 * Exists in Version 1, 2 and 3. Note that all Viewport interface versions
884 * Viewport: Viewport to use for beginning the search
885 * Flags: D3DNEXT_NEXT, D3DNEXT_HEAD or D3DNEXT_TAIL
889 * DDERR_INVALIDPARAMS if the flags were wrong, or Viewport was NULL
891 *****************************************************************************/
892 static HRESULT WINAPI
893 IDirect3DDeviceImpl_3_NextViewport(IDirect3DDevice3 *iface,
894 IDirect3DViewport3 *Viewport3,
895 IDirect3DViewport3 **lplpDirect3DViewport3,
898 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
899 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport3);
900 IDirect3DViewportImpl *res = NULL;
902 TRACE("(%p)->(%p,%p,%08x)\n", This, vp, lplpDirect3DViewport3, Flags);
906 *lplpDirect3DViewport3 = NULL;
907 return DDERR_INVALIDPARAMS;
920 res = This->viewport_list;
925 IDirect3DViewportImpl *cur_viewport = This->viewport_list;
926 if (cur_viewport != NULL)
928 while (cur_viewport->next != NULL) cur_viewport = cur_viewport->next;
934 *lplpDirect3DViewport3 = NULL;
935 return DDERR_INVALIDPARAMS;
938 *lplpDirect3DViewport3 = ICOM_INTERFACE(res, IDirect3DViewport3);
942 static HRESULT WINAPI
943 Thunk_IDirect3DDeviceImpl_2_NextViewport(IDirect3DDevice2 *iface,
944 IDirect3DViewport2 *Viewport2,
945 IDirect3DViewport2 **lplpDirect3DViewport2,
948 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
949 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport2);
950 IDirect3DViewport3 *res;
952 TRACE_(ddraw_thunk)("(%p)->(%p,%p,%08x) thunking to IDirect3DDevice3 interface.\n", This, vp, lplpDirect3DViewport2, Flags);
953 hr = IDirect3DDevice3_NextViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
954 ICOM_INTERFACE(vp, IDirect3DViewport3),
957 *lplpDirect3DViewport2 = (IDirect3DViewport2 *) COM_INTERFACE_CAST(IDirect3DViewportImpl, IDirect3DViewport3, IDirect3DViewport3, res);
961 static HRESULT WINAPI
962 Thunk_IDirect3DDeviceImpl_1_NextViewport(IDirect3DDevice *iface,
963 IDirect3DViewport *Viewport,
964 IDirect3DViewport **lplpDirect3DViewport,
967 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
968 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport);
969 IDirect3DViewport3 *res;
971 TRACE_(ddraw_thunk)("(%p)->(%p,%p,%08x) thunking to IDirect3DDevice3 interface.\n", This, vp, lplpDirect3DViewport, Flags);
972 hr = IDirect3DDevice3_NextViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
973 ICOM_INTERFACE(vp, IDirect3DViewport3),
976 *lplpDirect3DViewport = (IDirect3DViewport *) COM_INTERFACE_CAST(IDirect3DViewportImpl, IDirect3DViewport3, IDirect3DViewport3, res);
980 /*****************************************************************************
981 * IDirect3DDevice::Pick
983 * Executes an execute buffer without performing rendering. Instead, a
984 * list of primitives that intersect with (x1,y1) of the passed rectangle
985 * is created. IDirect3DDevice::GetPickRecords can be used to retrieve
991 * ExecuteBuffer: Buffer to execute
992 * Viewport: Viewport to use for execution
993 * Flags: None are defined, according to the SDK
994 * Rect: Specifies the coordinates to be picked. Only x1 and y2 are used,
995 * x2 and y2 are ignored.
998 * D3D_OK because it's a stub
1000 *****************************************************************************/
1001 static HRESULT WINAPI
1002 IDirect3DDeviceImpl_1_Pick(IDirect3DDevice *iface,
1003 IDirect3DExecuteBuffer *ExecuteBuffer,
1004 IDirect3DViewport *Viewport,
1008 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1009 IDirect3DExecuteBufferImpl *execbuf = ICOM_OBJECT(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, ExecuteBuffer);
1010 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport);
1011 FIXME("(%p)->(%p,%p,%08x,%p): stub!\n", This, execbuf, vp, Flags, Rect);
1016 /*****************************************************************************
1017 * IDirect3DDevice::GetPickRecords
1019 * Retrieves the pick records generated by IDirect3DDevice::GetPickRecords
1024 * Count: Pointer to a DWORD containing the numbers of pick records to
1026 * D3DPickRec: Address to store the resulting D3DPICKRECORD arry.
1029 * D3D_OK, because it's a stub
1031 *****************************************************************************/
1032 static HRESULT WINAPI
1033 IDirect3DDeviceImpl_1_GetPickRecords(IDirect3DDevice *iface,
1035 D3DPICKRECORD *D3DPickRec)
1037 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1038 FIXME("(%p)->(%p,%p): stub!\n", This, Count, D3DPickRec);
1043 /*****************************************************************************
1044 * IDirect3DDevice7::EnumTextureformats
1046 * Enumerates the supported texture formats. It has a list of all possible
1047 * formats and calls IWineD3D::CheckDeviceFormat for each format to see if
1048 * WineD3D supports it. If so, then it is passed to the app.
1050 * This is for Version 7 and 3, older versions have a different
1051 * callback function and their own implementation
1054 * Callback: Callback to call for each enumerated format
1055 * Arg: Argument to pass to the callback
1059 * DDERR_INVALIDPARAMS if Callback == NULL
1061 *****************************************************************************/
1062 static HRESULT WINAPI
1063 IDirect3DDeviceImpl_7_EnumTextureFormats(IDirect3DDevice7 *iface,
1064 LPD3DENUMPIXELFORMATSCALLBACK Callback,
1067 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1071 WINED3DFORMAT FormatList[] = {
1073 WINED3DFMT_A8R8G8B8,
1074 WINED3DFMT_X8R8G8B8,
1078 WINED3DFMT_A1R5G5B5,
1079 WINED3DFMT_A4R4G4B4,
1081 WINED3DFMT_X1R5G5B5,
1091 TRACE("(%p)->(%p,%p): Relay\n", This, Callback, Arg);
1094 return DDERR_INVALIDPARAMS;
1096 for(i = 0; i < sizeof(FormatList) / sizeof(WINED3DFORMAT); i++)
1098 hr = IWineD3D_CheckDeviceFormat(This->ddraw->wineD3D,
1101 0 /* AdapterFormat */,
1103 0 /* ResourceType */,
1107 DDPIXELFORMAT pformat;
1109 memset(&pformat, 0, sizeof(pformat));
1110 pformat.dwSize = sizeof(pformat);
1111 PixelFormat_WineD3DtoDD(&pformat, FormatList[i]);
1113 TRACE("Enumerating WineD3DFormat %d\n", FormatList[i]);
1114 hr = Callback(&pformat, Arg);
1115 if(hr != DDENUMRET_OK)
1117 TRACE("Format enumeration cancelled by application\n");
1122 TRACE("End of enumeration\n");
1126 static HRESULT WINAPI
1127 Thunk_IDirect3DDeviceImpl_3_EnumTextureFormats(IDirect3DDevice3 *iface,
1128 LPD3DENUMPIXELFORMATSCALLBACK Callback,
1131 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1132 TRACE_(ddraw_thunk)("(%p)->(%p,%p) thunking to IDirect3DDevice7 interface.\n", This, Callback, Arg);
1133 return IDirect3DDevice7_EnumTextureFormats(ICOM_INTERFACE(This, IDirect3DDevice7),
1138 /*****************************************************************************
1139 * IDirect3DDevice2::EnumTextureformats
1141 * EnumTextureFormats for Version 1 and 2, see
1142 * IDirect3DDevice7::EnumTexureFormats for a more detailed description.
1144 * This version has a different callback and does not enumerate FourCC
1147 *****************************************************************************/
1148 static HRESULT WINAPI
1149 IDirect3DDeviceImpl_2_EnumTextureFormats(IDirect3DDevice2 *iface,
1150 LPD3DENUMTEXTUREFORMATSCALLBACK Callback,
1153 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1157 WINED3DFORMAT FormatList[] = {
1159 WINED3DFMT_A8R8G8B8,
1160 WINED3DFMT_X8R8G8B8,
1164 WINED3DFMT_A1R5G5B5,
1165 WINED3DFMT_A4R4G4B4,
1167 WINED3DFMT_X1R5G5B5,
1171 /* FOURCC codes - Not in this version*/
1174 TRACE("(%p)->(%p,%p): Relay\n", This, Callback, Arg);
1177 return DDERR_INVALIDPARAMS;
1179 for(i = 0; i < sizeof(FormatList) / sizeof(WINED3DFORMAT); i++)
1181 hr = IWineD3D_CheckDeviceFormat(This->ddraw->wineD3D,
1184 0 /* AdapterFormat */,
1186 0 /* ResourceType */,
1190 DDSURFACEDESC sdesc;
1192 memset(&sdesc, 0, sizeof(sdesc));
1193 sdesc.dwSize = sizeof(sdesc);
1194 sdesc.dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
1195 sdesc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1196 sdesc.ddpfPixelFormat.dwSize = sizeof(sdesc.ddpfPixelFormat.dwSize);
1197 PixelFormat_WineD3DtoDD(&sdesc.ddpfPixelFormat, FormatList[i]);
1199 TRACE("Enumerating WineD3DFormat %d\n", FormatList[i]);
1200 hr = Callback(&sdesc, Arg);
1201 if(hr != DDENUMRET_OK)
1203 TRACE("Format enumeration cancelled by application\n");
1208 TRACE("End of enumeration\n");
1212 static HRESULT WINAPI
1213 Thunk_IDirect3DDeviceImpl_1_EnumTextureFormats(IDirect3DDevice *iface,
1214 LPD3DENUMTEXTUREFORMATSCALLBACK Callback,
1217 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1218 TRACE_(ddraw_thunk)("(%p)->(%p,%p) thunking to IDirect3DDevice2 interface.\n", This, Callback, Arg);
1219 return IDirect3DDevice2_EnumTextureFormats(ICOM_INTERFACE(This, IDirect3DDevice2),
1224 /*****************************************************************************
1225 * IDirect3DDevice::CreateMatrix
1227 * Creates a matrix handle. A handle is created and memory for a D3DMATRIX is
1228 * allocated for the handle.
1233 * D3DMatHandle: Address to return the handle at
1237 * DDERR_INVALIDPARAMS if D3DMatHandle = NULL
1239 *****************************************************************************/
1240 static HRESULT WINAPI
1241 IDirect3DDeviceImpl_1_CreateMatrix(IDirect3DDevice *iface, D3DMATRIXHANDLE *D3DMatHandle)
1243 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1245 TRACE("(%p)->(%p)\n", This, D3DMatHandle);
1248 return DDERR_INVALIDPARAMS;
1250 Matrix = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(D3DMATRIX));
1253 ERR("Out of memory when allocating a D3DMATRIX\n");
1254 return DDERR_OUTOFMEMORY;
1256 *D3DMatHandle = IDirect3DDeviceImpl_CreateHandle(This);
1257 if(!(*D3DMatHandle))
1259 ERR("Failed to create a matrix handle\n");
1260 HeapFree(GetProcessHeap(), 0, Matrix);
1261 return DDERR_OUTOFMEMORY;
1263 This->Handles[(DWORD) *D3DMatHandle - 1].ptr = Matrix;
1264 This->Handles[(DWORD) *D3DMatHandle - 1].type = DDrawHandle_Matrix;
1265 TRACE(" returning matrix handle %d\n", *D3DMatHandle);
1270 /*****************************************************************************
1271 * IDirect3DDevice::SetMatrix
1273 * Sets a matrix for a matrix handle. The matrix is copied into the memory
1274 * allocated for the handle
1279 * D3DMatHandle: Handle to set the matrix to
1280 * D3DMatrix: Matrix to set
1284 * DDERR_INVALIDPARAMS if the handle of the matrix is invalid or the matrix
1287 *****************************************************************************/
1288 static HRESULT WINAPI
1289 IDirect3DDeviceImpl_1_SetMatrix(IDirect3DDevice *iface,
1290 D3DMATRIXHANDLE D3DMatHandle,
1291 D3DMATRIX *D3DMatrix)
1293 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1294 TRACE("(%p)->(%08x,%p)\n", This, (DWORD) D3DMatHandle, D3DMatrix);
1296 if( (!D3DMatHandle) || (!D3DMatrix) )
1297 return DDERR_INVALIDPARAMS;
1299 if(D3DMatHandle > This->numHandles)
1301 ERR("Handle %d out of range\n", D3DMatHandle);
1302 return DDERR_INVALIDPARAMS;
1304 else if(This->Handles[D3DMatHandle - 1].type != DDrawHandle_Matrix)
1306 ERR("Handle %d is not a matrix handle\n", D3DMatHandle);
1307 return DDERR_INVALIDPARAMS;
1311 dump_D3DMATRIX(D3DMatrix);
1313 *((D3DMATRIX *) This->Handles[D3DMatHandle - 1].ptr) = *D3DMatrix;
1318 /*****************************************************************************
1319 * IDirect3DDevice::SetMatrix
1321 * Returns the content of a D3DMATRIX handle
1326 * D3DMatHandle: Matrix handle to read the content from
1327 * D3DMatrix: Address to store the content at
1331 * DDERR_INVALIDPARAMS if D3DMatHandle is invalid or D3DMatrix is NULL
1333 *****************************************************************************/
1334 static HRESULT WINAPI
1335 IDirect3DDeviceImpl_1_GetMatrix(IDirect3DDevice *iface,
1336 D3DMATRIXHANDLE D3DMatHandle,
1337 D3DMATRIX *D3DMatrix)
1339 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1340 TRACE("(%p)->(%08x,%p)\n", This, (DWORD) D3DMatHandle, D3DMatrix);
1343 return DDERR_INVALIDPARAMS;
1345 return DDERR_INVALIDPARAMS;
1347 if(D3DMatHandle > This->numHandles)
1349 ERR("Handle %d out of range\n", D3DMatHandle);
1350 return DDERR_INVALIDPARAMS;
1352 else if(This->Handles[D3DMatHandle - 1].type != DDrawHandle_Matrix)
1354 ERR("Handle %d is not a matrix handle\n", D3DMatHandle);
1355 return DDERR_INVALIDPARAMS;
1358 /* The handle is simply a pointer to a D3DMATRIX structure */
1359 *D3DMatrix = *((D3DMATRIX *) This->Handles[D3DMatHandle - 1].ptr);
1364 /*****************************************************************************
1365 * IDirect3DDevice::DeleteMatrix
1367 * Destroys a Matrix handle. Frees the memory and unsets the handle data
1372 * D3DMatHandle: Handle to destroy
1376 * DDERR_INVALIDPARAMS if D3DMatHandle is invalid
1378 *****************************************************************************/
1379 static HRESULT WINAPI
1380 IDirect3DDeviceImpl_1_DeleteMatrix(IDirect3DDevice *iface,
1381 D3DMATRIXHANDLE D3DMatHandle)
1383 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1384 TRACE("(%p)->(%08x)\n", This, (DWORD) D3DMatHandle);
1387 return DDERR_INVALIDPARAMS;
1389 if(D3DMatHandle > This->numHandles)
1391 ERR("Handle %d out of range\n", D3DMatHandle);
1392 return DDERR_INVALIDPARAMS;
1394 else if(This->Handles[D3DMatHandle - 1].type != DDrawHandle_Matrix)
1396 ERR("Handle %d is not a matrix handle\n", D3DMatHandle);
1397 return DDERR_INVALIDPARAMS;
1400 HeapFree(GetProcessHeap(), 0, This->Handles[D3DMatHandle - 1].ptr);
1401 This->Handles[D3DMatHandle - 1].ptr = NULL;
1402 This->Handles[D3DMatHandle - 1].type = DDrawHandle_Unknown;
1407 /*****************************************************************************
1408 * IDirect3DDevice7::BeginScene
1410 * This method must be called before any rendering is performed.
1411 * IDirect3DDevice::EndScene has to be called after the scene is complete
1413 * Version 1, 2, 3 and 7
1416 * D3D_OK on success, for details see IWineD3DDevice::BeginScene
1418 *****************************************************************************/
1419 static HRESULT WINAPI
1420 IDirect3DDeviceImpl_7_BeginScene(IDirect3DDevice7 *iface)
1422 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1423 TRACE("(%p): Relay\n", This);
1425 return IWineD3DDevice_BeginScene(This->wineD3DDevice);
1428 static HRESULT WINAPI
1429 Thunk_IDirect3DDeviceImpl_3_BeginScene(IDirect3DDevice3 *iface)
1431 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1432 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1433 return IDirect3DDevice7_BeginScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1436 static HRESULT WINAPI
1437 Thunk_IDirect3DDeviceImpl_2_BeginScene(IDirect3DDevice2 *iface)
1439 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1440 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1441 return IDirect3DDevice7_BeginScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1444 static HRESULT WINAPI
1445 Thunk_IDirect3DDeviceImpl_1_BeginScene(IDirect3DDevice *iface)
1447 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1448 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1449 return IDirect3DDevice7_BeginScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1452 /*****************************************************************************
1453 * IDirect3DDevice7::EndScene
1455 * Ends a scene that has been begun with IDirect3DDevice7::BeginScene.
1456 * This method must be called after rendering is finished.
1458 * Version 1, 2, 3 and 7
1461 * D3D_OK on success, for details see IWineD3DDevice::EndScene
1463 *****************************************************************************/
1464 static HRESULT WINAPI
1465 IDirect3DDeviceImpl_7_EndScene(IDirect3DDevice7 *iface)
1467 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1468 TRACE("(%p): Relay\n", This);
1470 IWineD3DDevice_EndScene(This->wineD3DDevice);
1474 static HRESULT WINAPI
1475 Thunk_IDirect3DDeviceImpl_3_EndScene(IDirect3DDevice3 *iface)
1477 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1478 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1479 return IDirect3DDevice7_EndScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1482 static HRESULT WINAPI
1483 Thunk_IDirect3DDeviceImpl_2_EndScene(IDirect3DDevice2 *iface)
1485 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1486 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1487 return IDirect3DDevice7_EndScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1490 static HRESULT WINAPI
1491 Thunk_IDirect3DDeviceImpl_1_EndScene(IDirect3DDevice *iface)
1493 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1494 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1495 return IDirect3DDevice7_EndScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1498 /*****************************************************************************
1499 * IDirect3DDevice7::GetDirect3D
1501 * Returns the IDirect3D(= interface to the DirectDraw object) used to create
1505 * Direct3D7: Address to store the interface pointer at
1509 * DDERR_INVALIDPARAMS if Direct3D7 == NULL
1511 *****************************************************************************/
1512 static HRESULT WINAPI
1513 IDirect3DDeviceImpl_7_GetDirect3D(IDirect3DDevice7 *iface,
1514 IDirect3D7 **Direct3D7)
1516 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1517 TRACE("(%p)->(%p)\n", This, Direct3D7);
1520 return DDERR_INVALIDPARAMS;
1522 *Direct3D7 = ICOM_INTERFACE(This->ddraw, IDirect3D7);
1523 IDirect3D7_AddRef(*Direct3D7);
1525 TRACE(" returning interface %p\n", *Direct3D7);
1529 static HRESULT WINAPI
1530 Thunk_IDirect3DDeviceImpl_3_GetDirect3D(IDirect3DDevice3 *iface,
1531 IDirect3D3 **Direct3D3)
1533 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1535 IDirect3D7 *ret_ptr;
1537 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, Direct3D3);
1538 ret = IDirect3DDevice7_GetDirect3D(ICOM_INTERFACE(This, IDirect3DDevice7),
1542 *Direct3D3 = COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D7, IDirect3D3, ret_ptr);
1543 TRACE(" returning interface %p\n", *Direct3D3);
1547 static HRESULT WINAPI
1548 Thunk_IDirect3DDeviceImpl_2_GetDirect3D(IDirect3DDevice2 *iface,
1549 IDirect3D2 **Direct3D2)
1551 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1553 IDirect3D7 *ret_ptr;
1555 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, Direct3D2);
1556 ret = IDirect3DDevice7_GetDirect3D(ICOM_INTERFACE(This, IDirect3DDevice7),
1560 *Direct3D2 = COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D7, IDirect3D2, ret_ptr);
1561 TRACE(" returning interface %p\n", *Direct3D2);
1565 static HRESULT WINAPI
1566 Thunk_IDirect3DDeviceImpl_1_GetDirect3D(IDirect3DDevice *iface,
1567 IDirect3D **Direct3D)
1569 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1571 IDirect3D7 *ret_ptr;
1573 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, Direct3D);
1574 ret = IDirect3DDevice7_GetDirect3D(ICOM_INTERFACE(This, IDirect3DDevice7),
1578 *Direct3D = COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D7, IDirect3D, ret_ptr);
1579 TRACE(" returning interface %p\n", *Direct3D);
1583 /*****************************************************************************
1584 * IDirect3DDevice3::SetCurrentViewport
1586 * Sets a Direct3DViewport as the current viewport.
1587 * For the thunks note that all viewport interface versions are equal
1590 * Direct3DViewport3: The viewport to set
1596 * (Is a NULL viewport valid?)
1598 *****************************************************************************/
1599 static HRESULT WINAPI
1600 IDirect3DDeviceImpl_3_SetCurrentViewport(IDirect3DDevice3 *iface,
1601 IDirect3DViewport3 *Direct3DViewport3)
1603 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1604 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport3);
1605 TRACE("(%p)->(%p)\n", This, Direct3DViewport3);
1607 /* Do nothing if the specified viewport is the same as the current one */
1608 if (This->current_viewport == vp )
1611 /* Should check if the viewport was added or not */
1613 /* Release previous viewport and AddRef the new one */
1614 if (This->current_viewport)
1616 TRACE("ViewportImpl is at %p, interface is at %p\n", This->current_viewport, ICOM_INTERFACE(This->current_viewport, IDirect3DViewport3));
1617 IDirect3DViewport3_Release( ICOM_INTERFACE(This->current_viewport, IDirect3DViewport3) );
1619 IDirect3DViewport3_AddRef(Direct3DViewport3);
1621 /* Set this viewport as the current viewport */
1622 This->current_viewport = vp;
1624 /* Activate this viewport */
1625 This->current_viewport->active_device = This;
1626 This->current_viewport->activate(This->current_viewport);
1631 static HRESULT WINAPI
1632 Thunk_IDirect3DDeviceImpl_2_SetCurrentViewport(IDirect3DDevice2 *iface,
1633 IDirect3DViewport2 *Direct3DViewport2)
1635 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1636 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport2);
1637 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, vp);
1638 return IDirect3DDevice3_SetCurrentViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
1639 ICOM_INTERFACE(vp, IDirect3DViewport3));
1642 /*****************************************************************************
1643 * IDirect3DDevice3::GetCurrentViewport
1645 * Returns the currently active viewport.
1650 * Direct3DViewport3: Address to return the interface pointer at
1654 * DDERR_INVALIDPARAMS if Direct3DViewport == NULL
1656 *****************************************************************************/
1657 static HRESULT WINAPI
1658 IDirect3DDeviceImpl_3_GetCurrentViewport(IDirect3DDevice3 *iface,
1659 IDirect3DViewport3 **Direct3DViewport3)
1661 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1662 TRACE("(%p)->(%p)\n", This, Direct3DViewport3);
1664 if(!Direct3DViewport3)
1665 return DDERR_INVALIDPARAMS;
1667 *Direct3DViewport3 = ICOM_INTERFACE(This->current_viewport, IDirect3DViewport3);
1669 /* AddRef the returned viewport */
1670 if(*Direct3DViewport3) IDirect3DViewport3_AddRef(*Direct3DViewport3);
1672 TRACE(" returning interface %p\n", *Direct3DViewport3);
1677 static HRESULT WINAPI
1678 Thunk_IDirect3DDeviceImpl_2_GetCurrentViewport(IDirect3DDevice2 *iface,
1679 IDirect3DViewport2 **Direct3DViewport2)
1681 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1683 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, Direct3DViewport2);
1684 hr = IDirect3DDevice3_GetCurrentViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
1685 (IDirect3DViewport3 **) Direct3DViewport2);
1686 if(hr != D3D_OK) return hr;
1687 *Direct3DViewport2 = (IDirect3DViewport2 *) COM_INTERFACE_CAST(IDirect3DViewportImpl, IDirect3DViewport3, IDirect3DViewport3, Direct3DViewport2);
1691 /*****************************************************************************
1692 * IDirect3DDevice7::SetRenderTarget
1694 * Sets the render target for the Direct3DDevice.
1695 * For the thunks note that IDirectDrawSurface7 == IDirectDrawSurface4 and
1696 * IDirectDrawSurface3 == IDirectDrawSurface
1698 * Version 2, 3 and 7
1701 * NewTarget: Pointer to an IDirectDrawSurface7 interface to set as the new
1706 * D3D_OK on success, for details see IWineD3DDevice::SetRenderTarget
1708 *****************************************************************************/
1709 static HRESULT WINAPI
1710 IDirect3DDeviceImpl_7_SetRenderTarget(IDirect3DDevice7 *iface,
1711 IDirectDrawSurface7 *NewTarget,
1714 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1715 IDirectDrawSurfaceImpl *Target = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, NewTarget);
1716 TRACE("(%p)->(%p,%08x): Relay\n", This, NewTarget, Flags);
1718 /* Flags: Not used */
1720 return IWineD3DDevice_SetRenderTarget(This->wineD3DDevice,
1722 Target ? Target->WineD3DSurface : NULL);
1725 static HRESULT WINAPI
1726 Thunk_IDirect3DDeviceImpl_3_SetRenderTarget(IDirect3DDevice3 *iface,
1727 IDirectDrawSurface4 *NewRenderTarget,
1730 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1731 IDirectDrawSurfaceImpl *Target = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, NewRenderTarget);
1732 TRACE_(ddraw_thunk)("(%p)->(%p,%08x) thunking to IDirect3DDevice7 interface.\n", This, Target, Flags);
1733 return IDirect3DDevice7_SetRenderTarget(ICOM_INTERFACE(This, IDirect3DDevice7),
1734 ICOM_INTERFACE(Target, IDirectDrawSurface7),
1738 static HRESULT WINAPI
1739 Thunk_IDirect3DDeviceImpl_2_SetRenderTarget(IDirect3DDevice2 *iface,
1740 IDirectDrawSurface *NewRenderTarget,
1743 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1744 IDirectDrawSurfaceImpl *Target = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface3, NewRenderTarget);
1745 TRACE_(ddraw_thunk)("(%p)->(%p,%08x) thunking to IDirect3DDevice7 interface.\n", This, Target, Flags);
1746 return IDirect3DDevice7_SetRenderTarget(ICOM_INTERFACE(This, IDirect3DDevice7),
1747 ICOM_INTERFACE(Target, IDirectDrawSurface7),
1751 /*****************************************************************************
1752 * IDirect3DDevice7::GetRenderTarget
1754 * Returns the current render target.
1755 * This is handled locally, because the WineD3D render target's parent
1758 * Version 2, 3 and 7
1761 * RenderTarget: Address to store the surface interface pointer
1765 * DDERR_INVALIDPARAMS if RenderTarget == NULL
1767 *****************************************************************************/
1768 static HRESULT WINAPI
1769 IDirect3DDeviceImpl_7_GetRenderTarget(IDirect3DDevice7 *iface,
1770 IDirectDrawSurface7 **RenderTarget)
1772 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1773 TRACE("(%p)->(%p): Relay\n", This, RenderTarget);
1776 return DDERR_INVALIDPARAMS;
1778 *RenderTarget = ICOM_INTERFACE(This->target, IDirectDrawSurface7);
1779 IDirectDrawSurface7_AddRef(*RenderTarget);
1784 static HRESULT WINAPI
1785 Thunk_IDirect3DDeviceImpl_3_GetRenderTarget(IDirect3DDevice3 *iface,
1786 IDirectDrawSurface4 **RenderTarget)
1788 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1790 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, RenderTarget);
1791 hr = IDirect3DDevice7_GetRenderTarget(ICOM_INTERFACE(This, IDirect3DDevice7),
1792 (IDirectDrawSurface7 **) RenderTarget);
1793 if(hr != D3D_OK) return hr;
1794 *RenderTarget = (IDirectDrawSurface4 *) COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7, IDirectDrawSurface7, RenderTarget);
1798 static HRESULT WINAPI
1799 Thunk_IDirect3DDeviceImpl_2_GetRenderTarget(IDirect3DDevice2 *iface,
1800 IDirectDrawSurface **RenderTarget)
1802 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1804 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, RenderTarget);
1805 hr = IDirect3DDevice7_GetRenderTarget(ICOM_INTERFACE(This, IDirect3DDevice7),
1806 (IDirectDrawSurface7 **) RenderTarget);
1807 if(hr != D3D_OK) return hr;
1808 *RenderTarget = (IDirectDrawSurface *) COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7, IDirectDrawSurface3, RenderTarget);
1812 /*****************************************************************************
1813 * IDirect3DDevice3::Begin
1815 * Begins a description block of vertices. This is similar to glBegin()
1816 * and glEnd(). After a call to IDirect3DDevice3::End, the vertices
1817 * described with IDirect3DDevice::Vertex are drawn.
1822 * PrimitiveType: The type of primitives to draw
1823 * VertexTypeDesc: A flexible vertex format description of the vertices
1824 * Flags: Some flags..
1829 *****************************************************************************/
1830 static HRESULT WINAPI
1831 IDirect3DDeviceImpl_3_Begin(IDirect3DDevice3 *iface,
1832 D3DPRIMITIVETYPE PrimitiveType,
1833 DWORD VertexTypeDesc,
1836 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1837 TRACE("(%p)->(%d,%d,%08x)\n", This, PrimitiveType, VertexTypeDesc, Flags);
1839 This->primitive_type = PrimitiveType;
1840 This->vertex_type = VertexTypeDesc;
1841 This->render_flags = Flags;
1842 This->vertex_size = get_flexible_vertex_size(This->vertex_type);
1843 This->nb_vertices = 0;
1848 static HRESULT WINAPI
1849 Thunk_IDirect3DDeviceImpl_2_Begin(IDirect3DDevice2 *iface,
1850 D3DPRIMITIVETYPE d3dpt,
1851 D3DVERTEXTYPE dwVertexTypeDesc,
1855 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1856 TRACE_(ddraw_thunk)("(%p/%p)->(%08x,%08x,%08x): Thunking to IDirect3DDevice3\n", This, iface, d3dpt, dwVertexTypeDesc, dwFlags);
1858 switch(dwVertexTypeDesc)
1860 case D3DVT_VERTEX: FVF = D3DFVF_VERTEX; break;
1861 case D3DVT_LVERTEX: FVF = D3DFVF_LVERTEX; break;
1862 case D3DVT_TLVERTEX: FVF = D3DFVF_TLVERTEX; break;
1864 ERR("Unexpected vertex type %d\n", dwVertexTypeDesc);
1865 return DDERR_INVALIDPARAMS; /* Should never happen */
1868 return IDirect3DDevice3_Begin(ICOM_INTERFACE(This, IDirect3DDevice3),
1874 /*****************************************************************************
1875 * IDirect3DDevice3::BeginIndexed
1877 * Draws primitives based on vertices in a vertex array which are specified
1883 * PrimitiveType: Primitive type to draw
1884 * VertexType: A FVF description of the vertex format
1885 * Vertices: pointer to an array containing the vertices
1886 * NumVertices: The number of vertices in the vertex array
1887 * Flags: Some flags ...
1890 * D3D_OK, because it's a stub
1892 *****************************************************************************/
1893 static HRESULT WINAPI
1894 IDirect3DDeviceImpl_3_BeginIndexed(IDirect3DDevice3 *iface,
1895 D3DPRIMITIVETYPE PrimitiveType,
1901 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1902 FIXME("(%p)->(%08x,%08x,%p,%08x,%08x): stub!\n", This, PrimitiveType, VertexType, Vertices, NumVertices, Flags);
1907 static HRESULT WINAPI
1908 Thunk_IDirect3DDeviceImpl_2_BeginIndexed(IDirect3DDevice2 *iface,
1909 D3DPRIMITIVETYPE d3dptPrimitiveType,
1910 D3DVERTEXTYPE d3dvtVertexType,
1912 DWORD dwNumVertices,
1916 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1917 TRACE_(ddraw_thunk)("(%p/%p)->(%08x,%08x,%p,%08x,%08x): Thunking to IDirect3DDevice3\n", This, iface, d3dptPrimitiveType, d3dvtVertexType, lpvVertices, dwNumVertices, dwFlags);
1919 switch(d3dvtVertexType)
1921 case D3DVT_VERTEX: FVF = D3DFVF_VERTEX; break;
1922 case D3DVT_LVERTEX: FVF = D3DFVF_LVERTEX; break;
1923 case D3DVT_TLVERTEX: FVF = D3DFVF_TLVERTEX; break;
1925 ERR("Unexpected vertex type %d\n", d3dvtVertexType);
1926 return DDERR_INVALIDPARAMS; /* Should never happen */
1929 return IDirect3DDevice3_BeginIndexed(ICOM_INTERFACE(This,IDirect3DDevice3),
1937 /*****************************************************************************
1938 * IDirect3DDevice3::Vertex
1940 * Draws a vertex as described by IDirect3DDevice3::Begin. It places all
1941 * drawn vertices in a vertex buffer. If the buffer is too small, its
1942 * size is increased.
1947 * Vertex: Pointer to the vertex
1950 * D3D_OK, on success
1951 * DDERR_INVALIDPARAMS if Vertex is NULL
1953 *****************************************************************************/
1954 static HRESULT WINAPI
1955 IDirect3DDeviceImpl_3_Vertex(IDirect3DDevice3 *iface,
1958 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1959 TRACE("(%p)->(%p)\n", This, Vertex);
1962 return DDERR_INVALIDPARAMS;
1964 if ((This->nb_vertices+1)*This->vertex_size > This->buffer_size)
1967 This->buffer_size = This->buffer_size ? This->buffer_size * 2 : This->vertex_size * 3;
1968 old_buffer = This->vertex_buffer;
1969 This->vertex_buffer = HeapAlloc(GetProcessHeap(), 0, This->buffer_size);
1972 CopyMemory(This->vertex_buffer, old_buffer, This->nb_vertices * This->vertex_size);
1973 HeapFree(GetProcessHeap(), 0, old_buffer);
1977 CopyMemory(This->vertex_buffer + This->nb_vertices++ * This->vertex_size, Vertex, This->vertex_size);
1982 static HRESULT WINAPI
1983 Thunk_IDirect3DDeviceImpl_2_Vertex(IDirect3DDevice2 *iface,
1986 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1987 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, lpVertexType);
1988 return IDirect3DDevice3_Vertex(ICOM_INTERFACE(This, IDirect3DDevice3),
1992 /*****************************************************************************
1993 * IDirect3DDevice3::Index
1995 * Specifies an index to a vertex to be drawn. The vertex array has to
1996 * be specified with BeginIndexed first.
1999 * VertexIndex: The index of the vertex to draw
2002 * D3D_OK because it's a stub
2004 *****************************************************************************/
2005 static HRESULT WINAPI
2006 IDirect3DDeviceImpl_3_Index(IDirect3DDevice3 *iface,
2009 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2010 FIXME("(%p)->(%04x): stub!\n", This, VertexIndex);
2014 static HRESULT WINAPI
2015 Thunk_IDirect3DDeviceImpl_2_Index(IDirect3DDevice2 *iface,
2018 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2019 TRACE_(ddraw_thunk)("(%p)->(%04x) thunking to IDirect3DDevice3 interface.\n", This, wVertexIndex);
2020 return IDirect3DDevice3_Index(ICOM_INTERFACE(This, IDirect3DDevice3),
2024 /*****************************************************************************
2025 * IDirect3DDevice3::End
2027 * Ends a draw begun with IDirect3DDevice3::Begin or
2028 * IDirect3DDevice::BeginIndexed. The vertices specified with
2029 * IDirect3DDevice::Vertex or IDirect3DDevice::Index are drawn using
2030 * the IDirect3DDevice7::DrawPrimitive method. So far only
2031 * non-indexed mode is supported
2036 * Flags: Some flags, as usual. Don't know which are defined
2039 * The return value of IDirect3DDevice7::DrawPrimitive
2041 *****************************************************************************/
2042 static HRESULT WINAPI
2043 IDirect3DDeviceImpl_3_End(IDirect3DDevice3 *iface,
2046 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2047 TRACE("(%p)->(%08x)\n", This, Flags);
2049 return IDirect3DDevice7_DrawPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
2050 This->primitive_type, This->vertex_type,
2051 This->vertex_buffer, This->nb_vertices,
2052 This->render_flags);
2055 static HRESULT WINAPI
2056 Thunk_IDirect3DDeviceImpl_2_End(IDirect3DDevice2 *iface,
2059 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2060 TRACE_(ddraw_thunk)("(%p)->(%08x) thunking to IDirect3DDevice3 interface.\n", This, dwFlags);
2061 return IDirect3DDevice3_End(ICOM_INTERFACE(This, IDirect3DDevice3),
2065 /*****************************************************************************
2066 * IDirect3DDevice7::GetRenderState
2068 * Returns the value of a render state. The possible render states are
2069 * defined in include/d3dtypes.h
2071 * Version 2, 3 and 7
2074 * RenderStateType: Render state to return the current setting of
2075 * Value: Address to store the value at
2078 * D3D_OK on success, for details see IWineD3DDevice::GetRenderState
2079 * DDERR_INVALIDPARAMS if Value == NULL
2081 *****************************************************************************/
2082 static HRESULT WINAPI
2083 IDirect3DDeviceImpl_7_GetRenderState(IDirect3DDevice7 *iface,
2084 D3DRENDERSTATETYPE RenderStateType,
2087 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2088 TRACE("(%p)->(%08x,%p): Relay\n", This, RenderStateType, Value);
2091 return DDERR_INVALIDPARAMS;
2093 /* FIXME: Unhandled: D3DRENDERSTATE_STIPPLEPATTERN00 - 31 */
2095 return IWineD3DDevice_GetRenderState(This->wineD3DDevice,
2100 static HRESULT WINAPI
2101 Thunk_IDirect3DDeviceImpl_3_GetRenderState(IDirect3DDevice3 *iface,
2102 D3DRENDERSTATETYPE dwRenderStateType,
2103 DWORD *lpdwRenderState)
2105 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2106 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, dwRenderStateType, lpdwRenderState);
2107 return IDirect3DDevice7_GetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2112 static HRESULT WINAPI
2113 Thunk_IDirect3DDeviceImpl_2_GetRenderState(IDirect3DDevice2 *iface,
2114 D3DRENDERSTATETYPE dwRenderStateType,
2115 DWORD *lpdwRenderState)
2117 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2118 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, dwRenderStateType, lpdwRenderState);
2119 return IDirect3DDevice7_GetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2124 /*****************************************************************************
2125 * IDirect3DDevice7::SetRenderState
2127 * Sets a render state. The possible render states are defined in
2128 * include/d3dtypes.h
2130 * Version 2, 3 and 7
2133 * RenderStateType: State to set
2134 * Value: Value to assign to that state
2137 * D3D_OK on success,
2138 * for details see IWineD3DDevice::SetRenderState
2140 *****************************************************************************/
2141 static HRESULT WINAPI
2142 IDirect3DDeviceImpl_7_SetRenderState(IDirect3DDevice7 *iface,
2143 D3DRENDERSTATETYPE RenderStateType,
2146 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2147 TRACE("(%p)->(%08x,%d): Relay\n", This, RenderStateType, Value);
2149 /* Some render states need special care */
2150 switch(RenderStateType)
2152 case D3DRENDERSTATE_TEXTUREHANDLE:
2156 return IWineD3DDevice_SetTexture(This->wineD3DDevice,
2161 if(Value > This->numHandles)
2163 FIXME("Specified handle %d out of range\n", Value);
2164 return DDERR_INVALIDPARAMS;
2166 if(This->Handles[Value - 1].type != DDrawHandle_Texture)
2168 FIXME("Handle %d isn't a texture handle\n", Value);
2169 return DDERR_INVALIDPARAMS;
2173 IDirectDrawSurfaceImpl *surf = (IDirectDrawSurfaceImpl *) This->Handles[Value - 1].ptr;
2174 return IWineD3DDevice_SetTexture(This->wineD3DDevice,
2176 (IWineD3DBaseTexture *) surf->wineD3DTexture);
2180 case D3DRENDERSTATE_TEXTUREMAG:
2182 WINED3DTEXTUREFILTERTYPE tex_mag = WINED3DTEXF_NONE;
2184 switch ((D3DTEXTUREFILTER) Value)
2186 case D3DFILTER_NEAREST:
2187 tex_mag = WINED3DTEXF_POINT;
2189 case D3DFILTER_LINEAR:
2190 tex_mag = WINED3DTEXF_LINEAR;
2193 ERR("Unhandled texture mag %d !\n",Value);
2196 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
2197 0, WINED3DSAMP_MAGFILTER,
2201 case D3DRENDERSTATE_TEXTUREMIN:
2203 WINED3DTEXTUREFILTERTYPE tex_min = WINED3DTEXF_NONE;
2205 switch ((D3DTEXTUREFILTER) Value)
2207 case D3DFILTER_NEAREST:
2208 tex_min = WINED3DTEXF_POINT;
2210 case D3DFILTER_LINEAR:
2211 tex_min = WINED3DTEXF_LINEAR;
2214 ERR("Unhandled texture mag %d !\n",Value);
2217 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
2218 0, WINED3DSAMP_MINFILTER,
2222 case D3DRENDERSTATE_TEXTUREADDRESSU:
2223 case D3DRENDERSTATE_TEXTUREADDRESSV:
2224 case D3DRENDERSTATE_TEXTUREADDRESS:
2226 WINED3DTEXTURESTAGESTATETYPE TexStageStateType;
2228 if (RenderStateType == D3DRENDERSTATE_TEXTUREADDRESS)
2230 TexStageStateType = WINED3DTSS_ADDRESS;
2232 else if (RenderStateType == D3DRENDERSTATE_TEXTUREADDRESSU)
2234 TexStageStateType = WINED3DTSS_ADDRESSU;
2238 TexStageStateType = WINED3DTSS_ADDRESSV;
2241 return IWineD3DDevice_SetTextureStageState(This->wineD3DDevice,
2242 0, TexStageStateType,
2246 case D3DRENDERSTATE_TEXTUREMAPBLEND:
2248 /* Old texture combine setup style, superseded by texture stage states
2249 * in D3D7. It is safe for us to wrap it to texture stage states.
2251 switch ( (D3DTEXTUREBLEND) Value)
2253 case D3DTBLEND_MODULATE:
2254 IWineD3DDevice_SetTextureStageState(iface, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
2255 IWineD3DDevice_SetTextureStageState(iface, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
2256 IWineD3DDevice_SetTextureStageState(iface, 0, D3DTSS_COLORARG2, D3DTA_CURRENT);
2257 IWineD3DDevice_SetTextureStageState(iface, 0, D3DTSS_COLOROP, WINED3DTOP_MODULATE);
2258 IWineD3DDevice_SetTextureStageState(iface, 0, D3DTSS_ALPHAOP, WINED3DTOP_SELECTARG1);
2261 case D3DTBLEND_MODULATEALPHA:
2262 IWineD3DDevice_SetTextureStageState(iface, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
2263 IWineD3DDevice_SetTextureStageState(iface, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
2264 IWineD3DDevice_SetTextureStageState(iface, 0, D3DTSS_COLORARG2, D3DTA_CURRENT);
2265 IWineD3DDevice_SetTextureStageState(iface, 0, D3DTSS_ALPHAARG2, D3DTA_CURRENT);
2266 IWineD3DDevice_SetTextureStageState(iface, 0, D3DTSS_COLOROP, WINED3DTOP_MODULATE);
2267 IWineD3DDevice_SetTextureStageState(iface, 0, D3DTSS_ALPHAOP, WINED3DTOP_MODULATE);
2270 case D3DTBLEND_DECAL:
2271 IWineD3DDevice_SetTextureStageState(iface, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
2272 IWineD3DDevice_SetTextureStageState(iface, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
2273 IWineD3DDevice_SetTextureStageState(iface, 0, D3DTSS_COLOROP, WINED3DTOP_SELECTARG1);
2274 IWineD3DDevice_SetTextureStageState(iface, 0, D3DTSS_ALPHAOP, WINED3DTOP_SELECTARG1);
2277 case D3DTBLEND_DECALALPHA:
2278 IWineD3DDevice_SetTextureStageState(iface, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
2279 IWineD3DDevice_SetTextureStageState(iface, 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
2280 IWineD3DDevice_SetTextureStageState(iface, 0, D3DTSS_ALPHAARG2, D3DTA_CURRENT);
2281 IWineD3DDevice_SetTextureStageState(iface, 0, D3DTSS_COLOROP, WINED3DTOP_SELECTARG1);
2282 IWineD3DDevice_SetTextureStageState(iface, 0, D3DTSS_ALPHAOP, WINED3DTOP_MODULATE);
2286 ERR("Unhandled texture environment %d !\n",Value);
2294 /* FIXME: Unhandled: D3DRENDERSTATE_STIPPLEPATTERN00 - 31 */
2296 return IWineD3DDevice_SetRenderState(This->wineD3DDevice,
2302 static HRESULT WINAPI
2303 Thunk_IDirect3DDeviceImpl_3_SetRenderState(IDirect3DDevice3 *iface,
2304 D3DRENDERSTATETYPE RenderStateType,
2307 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2308 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, RenderStateType, Value);
2309 return IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2314 static HRESULT WINAPI
2315 Thunk_IDirect3DDeviceImpl_2_SetRenderState(IDirect3DDevice2 *iface,
2316 D3DRENDERSTATETYPE RenderStateType,
2319 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2320 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, RenderStateType, Value);
2321 return IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2326 /*****************************************************************************
2327 * Direct3DDevice3::SetLightState
2329 * Sets a light state for Direct3DDevice3 and Direct3DDevice2. The
2330 * light states are forwarded to Direct3DDevice7 render states
2335 * LightStateType: The light state to change
2336 * Value: The value to assign to that light state
2340 * DDERR_INVALIDPARAMS if the parameters were incorrect
2341 * Also check IDirect3DDevice7::SetRenderState
2343 *****************************************************************************/
2344 static HRESULT WINAPI
2345 IDirect3DDeviceImpl_3_SetLightState(IDirect3DDevice3 *iface,
2346 D3DLIGHTSTATETYPE LightStateType,
2349 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2351 TRACE("(%p)->(%08x,%08x)\n", This, LightStateType, Value);
2353 if (!LightStateType && (LightStateType > D3DLIGHTSTATE_COLORVERTEX))
2355 TRACE("Unexpected Light State Type\n");
2356 return DDERR_INVALIDPARAMS;
2359 if (LightStateType == D3DLIGHTSTATE_MATERIAL /* 1 */)
2361 IDirect3DMaterialImpl *mat;
2363 if(Value == 0) mat = NULL;
2364 else if(Value > This->numHandles)
2366 ERR("Material handle out of range(%d)\n", Value);
2367 return DDERR_INVALIDPARAMS;
2369 else if(This->Handles[Value - 1].type != DDrawHandle_Material)
2371 ERR("Invalid handle %d\n", Value);
2372 return DDERR_INVALIDPARAMS;
2376 mat = (IDirect3DMaterialImpl *) This->Handles[Value - 1].ptr;
2381 TRACE(" activating material %p.\n", mat);
2386 FIXME(" D3DLIGHTSTATE_MATERIAL called with NULL material !!!\n");
2388 This->material = Value;
2390 else if (LightStateType == D3DLIGHTSTATE_COLORMODEL /* 3 */)
2395 ERR("DDCOLOR_MONO should not happen!\n");
2398 /* We are already in this mode */
2399 TRACE("Setting color model to RGB (no-op).\n");
2402 ERR("Unknown color model!\n");
2403 return DDERR_INVALIDPARAMS;
2408 D3DRENDERSTATETYPE rs;
2409 switch (LightStateType)
2411 case D3DLIGHTSTATE_AMBIENT: /* 2 */
2412 rs = D3DRENDERSTATE_AMBIENT;
2414 case D3DLIGHTSTATE_FOGMODE: /* 4 */
2415 rs = D3DRENDERSTATE_FOGVERTEXMODE;
2417 case D3DLIGHTSTATE_FOGSTART: /* 5 */
2418 rs = D3DRENDERSTATE_FOGSTART;
2420 case D3DLIGHTSTATE_FOGEND: /* 6 */
2421 rs = D3DRENDERSTATE_FOGEND;
2423 case D3DLIGHTSTATE_FOGDENSITY: /* 7 */
2424 rs = D3DRENDERSTATE_FOGDENSITY;
2426 case D3DLIGHTSTATE_COLORVERTEX: /* 8 */
2427 rs = D3DRENDERSTATE_COLORVERTEX;
2430 ERR("Unknown D3DLIGHTSTATETYPE %d.\n", LightStateType);
2431 return DDERR_INVALIDPARAMS;
2434 return IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2442 static HRESULT WINAPI
2443 Thunk_IDirect3DDeviceImpl_2_SetLightState(IDirect3DDevice2 *iface,
2444 D3DLIGHTSTATETYPE LightStateType,
2447 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2448 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x) thunking to IDirect3DDevice3 interface.\n", This, LightStateType, Value);
2449 return IDirect3DDevice3_SetLightState(ICOM_INTERFACE(This, IDirect3DDevice3),
2454 /*****************************************************************************
2455 * IDirect3DDevice3::GetLightState
2457 * Returns the current setting of a light state. The state is read from
2458 * the Direct3DDevice7 render state.
2463 * LightStateType: The light state to return
2464 * Value: The address to store the light state setting at
2468 * DDDERR_INVALIDPARAMS if the parameters were incorrect
2469 * Also see IDirect3DDevice7::GetRenderState
2471 *****************************************************************************/
2472 static HRESULT WINAPI
2473 IDirect3DDeviceImpl_3_GetLightState(IDirect3DDevice3 *iface,
2474 D3DLIGHTSTATETYPE LightStateType,
2477 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2479 TRACE("(%p)->(%08x,%p)\n", This, LightStateType, Value);
2481 if (!LightStateType && (LightStateType > D3DLIGHTSTATE_COLORVERTEX))
2483 TRACE("Unexpected Light State Type\n");
2484 return DDERR_INVALIDPARAMS;
2488 return DDERR_INVALIDPARAMS;
2490 if (LightStateType == D3DLIGHTSTATE_MATERIAL /* 1 */)
2492 *Value = This->material;
2494 else if (LightStateType == D3DLIGHTSTATE_COLORMODEL /* 3 */)
2496 *Value = D3DCOLOR_RGB;
2500 D3DRENDERSTATETYPE rs;
2501 switch (LightStateType)
2503 case D3DLIGHTSTATE_AMBIENT: /* 2 */
2504 rs = D3DRENDERSTATE_AMBIENT;
2506 case D3DLIGHTSTATE_FOGMODE: /* 4 */
2507 rs = D3DRENDERSTATE_FOGVERTEXMODE;
2509 case D3DLIGHTSTATE_FOGSTART: /* 5 */
2510 rs = D3DRENDERSTATE_FOGSTART;
2512 case D3DLIGHTSTATE_FOGEND: /* 6 */
2513 rs = D3DRENDERSTATE_FOGEND;
2515 case D3DLIGHTSTATE_FOGDENSITY: /* 7 */
2516 rs = D3DRENDERSTATE_FOGDENSITY;
2518 case D3DLIGHTSTATE_COLORVERTEX: /* 8 */
2519 rs = D3DRENDERSTATE_COLORVERTEX;
2522 ERR("Unknown D3DLIGHTSTATETYPE %d.\n", LightStateType);
2523 return DDERR_INVALIDPARAMS;
2526 return IDirect3DDevice7_GetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2534 static HRESULT WINAPI
2535 Thunk_IDirect3DDeviceImpl_2_GetLightState(IDirect3DDevice2 *iface,
2536 D3DLIGHTSTATETYPE LightStateType,
2539 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2540 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice3 interface.\n", This, LightStateType, Value);
2541 return IDirect3DDevice3_GetLightState(ICOM_INTERFACE(This, IDirect3DDevice3),
2546 /*****************************************************************************
2547 * IDirect3DDevice7::SetTransform
2549 * Assigns a D3DMATRIX to a transform type. The transform types are defined
2550 * in include/d3dtypes.h.
2551 * The D3DTRANSFORMSTATE_WORLD (=1) is translated to D3DTS_WORLDMATRIX(0)
2552 * (=255) for wined3d, because the 1 transform state was removed in d3d8
2553 * and WineD3D already understands the replacement D3DTS_WORLDMATRIX(0)
2555 * Version 2, 3 and 7
2558 * TransformStateType: transform state to set
2559 * Matrix: Matrix to assign to the state
2563 * DDERR_INVALIDPARAMS if Matrix == NULL
2564 * For details see IWineD3DDevice::SetTransform
2566 *****************************************************************************/
2567 static HRESULT WINAPI
2568 IDirect3DDeviceImpl_7_SetTransform(IDirect3DDevice7 *iface,
2569 D3DTRANSFORMSTATETYPE TransformStateType,
2572 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2573 D3DTRANSFORMSTATETYPE type = TransformStateType;
2574 TRACE("(%p)->(%08x,%p): Relay\n", This, TransformStateType, Matrix);
2577 return DDERR_INVALIDPARAMS;
2579 /* D3DTRANSFORMSTATE_WORLD doesn't exist in WineD3D,
2580 * use D3DTS_WORLDMATRIX(0) instead
2581 * D3DTS_WORLDMATRIX(index) is (D3DTRANSFORMSTATETYPE)(index + 256)
2583 if(TransformStateType == D3DTRANSFORMSTATE_WORLD)
2584 type = (D3DTRANSFORMSTATETYPE)(0 + 256);
2587 Unhandled: D3DTRANSFORMSTATE_WORLD1
2588 Unhandled: D3DTRANSFORMSTATE_WORLD2
2589 Unhandled: D3DTRANSFORMSTATE_WORLD3
2592 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
2593 return IWineD3DDevice_SetTransform(This->wineD3DDevice,
2595 (WINED3DMATRIX*) Matrix);
2598 static HRESULT WINAPI
2599 Thunk_IDirect3DDeviceImpl_3_SetTransform(IDirect3DDevice3 *iface,
2600 D3DTRANSFORMSTATETYPE TransformStateType,
2601 D3DMATRIX *D3DMatrix)
2603 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2604 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2605 return IDirect3DDevice7_SetTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2610 static HRESULT WINAPI
2611 Thunk_IDirect3DDeviceImpl_2_SetTransform(IDirect3DDevice2 *iface,
2612 D3DTRANSFORMSTATETYPE TransformStateType,
2613 D3DMATRIX *D3DMatrix)
2615 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2616 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2617 return IDirect3DDevice7_SetTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2622 /*****************************************************************************
2623 * IDirect3DDevice7::GetTransform
2625 * Returns the matrix assigned to a transform state
2626 * D3DTRANSFORMSTATE_WORLD is translated to D3DTS_WORLDMATRIX(0), see
2630 * TransformStateType: State to read the matrix from
2631 * Matrix: Address to store the matrix at
2635 * DDERR_INVALIDPARAMS if Matrix == NULL
2636 * For details, see IWineD3DDevice::GetTransform
2638 *****************************************************************************/
2639 static HRESULT WINAPI
2640 IDirect3DDeviceImpl_7_GetTransform(IDirect3DDevice7 *iface,
2641 D3DTRANSFORMSTATETYPE TransformStateType,
2644 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2645 D3DTRANSFORMSTATETYPE type = TransformStateType;
2646 TRACE("(%p)->(%08x,%p): Relay\n", This, TransformStateType, Matrix);
2649 return DDERR_INVALIDPARAMS;
2651 /* D3DTRANSFORMSTATE_WORLD doesn't exist in WineD3D,
2652 * use D3DTS_WORLDMATRIX(0) instead
2653 * D3DTS_WORLDMATRIX(index) is (D3DTRANSFORMSTATETYPE)(index + 256)
2655 if(TransformStateType == D3DTRANSFORMSTATE_WORLD)
2656 type = (D3DTRANSFORMSTATETYPE)(0 + 256);
2659 Unhandled: D3DTRANSFORMSTATE_WORLD1
2660 Unhandled: D3DTRANSFORMSTATE_WORLD2
2661 Unhandled: D3DTRANSFORMSTATE_WORLD3
2664 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
2665 return IWineD3DDevice_GetTransform(This->wineD3DDevice, type, (WINED3DMATRIX*) Matrix);
2668 static HRESULT WINAPI
2669 Thunk_IDirect3DDeviceImpl_3_GetTransform(IDirect3DDevice3 *iface,
2670 D3DTRANSFORMSTATETYPE TransformStateType,
2671 D3DMATRIX *D3DMatrix)
2673 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2674 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2675 return IDirect3DDevice7_GetTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2680 static HRESULT WINAPI
2681 Thunk_IDirect3DDeviceImpl_2_GetTransform(IDirect3DDevice2 *iface,
2682 D3DTRANSFORMSTATETYPE TransformStateType,
2683 D3DMATRIX *D3DMatrix)
2685 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2686 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2687 return IDirect3DDevice7_GetTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2692 /*****************************************************************************
2693 * IDirect3DDevice7::MultiplyTransform
2695 * Multiplies the already-set transform matrix of a transform state
2696 * with another matrix. For the world matrix, see SetTransform
2698 * Version 2, 3 and 7
2701 * TransformStateType: Transform state to multiply
2702 * D3DMatrix Matrix to multiply with.
2706 * DDERR_INVALIDPARAMS if D3DMatrix is NULL
2707 * For details, see IWineD3DDevice::MultiplyTransform
2709 *****************************************************************************/
2710 static HRESULT WINAPI
2711 IDirect3DDeviceImpl_7_MultiplyTransform(IDirect3DDevice7 *iface,
2712 D3DTRANSFORMSTATETYPE TransformStateType,
2713 D3DMATRIX *D3DMatrix)
2715 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2716 TRACE("(%p)->(%08x,%p): Relay\n", This, TransformStateType, D3DMatrix);
2718 /* D3DTRANSFORMSTATE_WORLD doesn't exist in WineD3D,
2719 * use D3DTS_WORLDMATRIX(0) instead
2720 * D3DTS_WORLDMATRIX(index) is (D3DTRANSFORMSTATETYPE)(index + 256)
2722 if(TransformStateType == D3DTRANSFORMSTATE_WORLD)
2723 TransformStateType = (D3DTRANSFORMSTATETYPE)(0 + 256);
2726 Unhandled: D3DTRANSFORMSTATE_WORLD1
2727 Unhandled: D3DTRANSFORMSTATE_WORLD2
2728 Unhandled: D3DTRANSFORMSTATE_WORLD3
2731 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
2732 return IWineD3DDevice_MultiplyTransform(This->wineD3DDevice,
2734 (WINED3DMATRIX*) D3DMatrix);
2737 static HRESULT WINAPI
2738 Thunk_IDirect3DDeviceImpl_3_MultiplyTransform(IDirect3DDevice3 *iface,
2739 D3DTRANSFORMSTATETYPE TransformStateType,
2740 D3DMATRIX *D3DMatrix)
2742 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2743 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2744 return IDirect3DDevice7_MultiplyTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2749 static HRESULT WINAPI
2750 Thunk_IDirect3DDeviceImpl_2_MultiplyTransform(IDirect3DDevice2 *iface,
2751 D3DTRANSFORMSTATETYPE TransformStateType,
2752 D3DMATRIX *D3DMatrix)
2754 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2755 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2756 return IDirect3DDevice7_MultiplyTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2761 /*****************************************************************************
2762 * IDirect3DDevice7::DrawPrimitive
2764 * Draws primitives based on vertices in an application-provided pointer
2766 * Version 2, 3 and 7. The IDirect3DDevice2 thunk converts the fixed vertex type into
2767 * an FVF format for D3D7
2770 * PrimitiveType: The type of the primitives to draw
2771 * Vertex type: Flexible vertex format vertex description
2772 * Vertices: Pointer to the vertex array
2773 * VertexCount: The number of vertices to draw
2774 * Flags: As usual a few flags
2778 * DDERR_INVALIDPARAMS if Vertices is NULL
2779 * For details, see IWineD3DDevice::DrawPrimitiveUP
2781 *****************************************************************************/
2782 static HRESULT WINAPI
2783 IDirect3DDeviceImpl_7_DrawPrimitive(IDirect3DDevice7 *iface,
2784 D3DPRIMITIVETYPE PrimitiveType,
2790 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2791 UINT PrimitiveCount, stride;
2793 TRACE("(%p)->(%08x,%08x,%p,%08x,%08x): Relay!\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Flags);
2796 return DDERR_INVALIDPARAMS;
2798 /* Get the vertex count */
2799 switch(PrimitiveType)
2801 case D3DPT_POINTLIST:
2802 PrimitiveCount = VertexCount;
2805 case D3DPT_LINELIST:
2806 PrimitiveCount = VertexCount / 2;
2809 case D3DPT_LINESTRIP:
2810 PrimitiveCount = VertexCount - 1;
2813 case D3DPT_TRIANGLELIST:
2814 PrimitiveCount = VertexCount / 3;
2817 case D3DPT_TRIANGLESTRIP:
2818 PrimitiveCount = VertexCount - 2;
2821 case D3DPT_TRIANGLEFAN:
2822 PrimitiveCount = VertexCount - 2;
2825 default: return DDERR_INVALIDPARAMS;
2828 /* Get the stride */
2829 stride = get_flexible_vertex_size(VertexType);
2832 hr = IWineD3DDevice_SetFVF(This->wineD3DDevice, VertexType);
2833 if(hr != D3D_OK) return hr;
2835 /* This method translates to the user pointer draw of WineD3D */
2836 return IWineD3DDevice_DrawPrimitiveUP(This->wineD3DDevice,
2843 static HRESULT WINAPI
2844 Thunk_IDirect3DDeviceImpl_3_DrawPrimitive(IDirect3DDevice3 *iface,
2845 D3DPRIMITIVETYPE PrimitiveType,
2851 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2852 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Flags);
2853 return IDirect3DDevice7_DrawPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
2861 static HRESULT WINAPI
2862 Thunk_IDirect3DDeviceImpl_2_DrawPrimitive(IDirect3DDevice2 *iface,
2863 D3DPRIMITIVETYPE PrimitiveType,
2864 D3DVERTEXTYPE VertexType,
2869 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2871 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Flags);
2875 case D3DVT_VERTEX: FVF = D3DFVF_VERTEX; break;
2876 case D3DVT_LVERTEX: FVF = D3DFVF_LVERTEX; break;
2877 case D3DVT_TLVERTEX: FVF = D3DFVF_TLVERTEX; break;
2879 ERR("Unexpected vertex type %d\n", VertexType);
2880 return DDERR_INVALIDPARAMS; /* Should never happen */
2883 return IDirect3DDevice7_DrawPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
2891 /*****************************************************************************
2892 * IDirect3DDevice7::DrawIndexedPrimitive
2894 * Draws vertices from an application-provided pointer, based on the index
2895 * numbers in a WORD array.
2897 * Version 2, 3 and 7. The version 7 thunk translates the vertex type into
2898 * an FVF format for D3D7
2901 * PrimitiveType: The primitive type to draw
2902 * VertexType: The FVF vertex description
2903 * Vertices: Pointer to the vertex array
2905 * Indices: Pointer to the index array
2906 * IndexCount: Number of indices = Number of vertices to draw
2907 * Flags: As usual, some flags
2911 * DDERR_INVALIDPARAMS if Vertices or Indices is NULL
2912 * For details, see IWineD3DDevice::DrawIndexedPrimitiveUP
2914 *****************************************************************************/
2915 static HRESULT WINAPI
2916 IDirect3DDeviceImpl_7_DrawIndexedPrimitive(IDirect3DDevice7 *iface,
2917 D3DPRIMITIVETYPE PrimitiveType,
2925 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2926 UINT PrimitiveCount = 0;
2928 TRACE("(%p)->(%08x,%08x,%p,%08x,%p,%08x,%08x): Relay!\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Indices, IndexCount, Flags);
2929 /* Get the primitive number */
2930 switch(PrimitiveType)
2932 case D3DPT_POINTLIST:
2933 PrimitiveCount = IndexCount;
2936 case D3DPT_LINELIST:
2937 PrimitiveCount = IndexCount / 2;
2940 case D3DPT_LINESTRIP:
2941 PrimitiveCount = IndexCount - 1;
2944 case D3DPT_TRIANGLELIST:
2945 PrimitiveCount = IndexCount / 3;
2948 case D3DPT_TRIANGLESTRIP:
2949 PrimitiveCount = IndexCount - 2;
2952 case D3DPT_TRIANGLEFAN:
2953 PrimitiveCount = IndexCount - 2;
2956 default: return DDERR_INVALIDPARAMS;
2959 /* Set the D3DDevice's FVF */
2960 hr = IWineD3DDevice_SetFVF(This->wineD3DDevice, VertexType);
2963 ERR(" (%p) Setting the FVF failed, hr = %x!\n", This, hr);
2967 return IWineD3DDevice_DrawIndexedPrimitiveUP(This->wineD3DDevice,
2969 0 /* MinVertexIndex */,
2970 VertexCount /* UINT NumVertexIndex */,
2975 get_flexible_vertex_size(VertexType));
2978 static HRESULT WINAPI
2979 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitive(IDirect3DDevice3 *iface,
2980 D3DPRIMITIVETYPE PrimitiveType,
2988 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2989 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Indices, IndexCount, Flags);
2990 return IDirect3DDevice7_DrawIndexedPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
3000 static HRESULT WINAPI
3001 Thunk_IDirect3DDeviceImpl_2_DrawIndexedPrimitive(IDirect3DDevice2 *iface,
3002 D3DPRIMITIVETYPE PrimitiveType,
3003 D3DVERTEXTYPE VertexType,
3011 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
3012 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Indices, IndexCount, Flags);
3016 case D3DVT_VERTEX: FVF = D3DFVF_VERTEX; break;
3017 case D3DVT_LVERTEX: FVF = D3DFVF_LVERTEX; break;
3018 case D3DVT_TLVERTEX: FVF = D3DFVF_TLVERTEX; break;
3020 ERR("Unexpected vertex type %d\n", VertexType);
3021 return DDERR_INVALIDPARAMS; /* Should never happen */
3024 return IDirect3DDevice7_DrawIndexedPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
3034 /*****************************************************************************
3035 * IDirect3DDevice7::SetClipStatus
3037 * Sets the clip status. This defines things as clipping conditions and
3038 * the extents of the clipping region.
3040 * Version 2, 3 and 7
3046 * D3D_OK because it's a stub
3047 * (DDERR_INVALIDPARAMS if ClipStatus == NULL)
3049 *****************************************************************************/
3050 static HRESULT WINAPI
3051 IDirect3DDeviceImpl_7_SetClipStatus(IDirect3DDevice7 *iface,
3052 D3DCLIPSTATUS *ClipStatus)
3054 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3055 FIXME("(%p)->(%p): Stub!\n", This, ClipStatus);
3057 /* D3DCLIPSTATUS and WINED3DCLIPSTATUS are different. I don't know how to convert them
3058 * Perhaps this needs a new data type and an additional IWineD3DDevice method
3060 /* return IWineD3DDevice_SetClipStatus(This->wineD3DDevice, ClipStatus);*/
3064 static HRESULT WINAPI
3065 Thunk_IDirect3DDeviceImpl_3_SetClipStatus(IDirect3DDevice3 *iface,
3066 D3DCLIPSTATUS *ClipStatus)
3068 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3069 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, ClipStatus);
3070 return IDirect3DDevice7_SetClipStatus(ICOM_INTERFACE(This, IDirect3DDevice7),
3074 static HRESULT WINAPI
3075 Thunk_IDirect3DDeviceImpl_2_SetClipStatus(IDirect3DDevice2 *iface,
3076 D3DCLIPSTATUS *ClipStatus)
3078 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
3079 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, ClipStatus);
3080 return IDirect3DDevice7_SetClipStatus(ICOM_INTERFACE(This, IDirect3DDevice7),
3084 /*****************************************************************************
3085 * IDirect3DDevice7::GetClipStatus
3087 * Returns the clip status
3090 * ClipStatus: Address to write the clip status to
3093 * D3D_OK because it's a stub
3095 *****************************************************************************/
3096 static HRESULT WINAPI
3097 IDirect3DDeviceImpl_7_GetClipStatus(IDirect3DDevice7 *iface,
3098 D3DCLIPSTATUS *ClipStatus)
3100 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3101 FIXME("(%p)->(%p): Stub!\n", This, ClipStatus);
3103 /* D3DCLIPSTATUS and WINED3DCLIPSTATUS are different. I don't know how to convert them */
3104 /* return IWineD3DDevice_GetClipStatus(This->wineD3DDevice, ClipStatus);*/
3108 static HRESULT WINAPI
3109 Thunk_IDirect3DDeviceImpl_3_GetClipStatus(IDirect3DDevice3 *iface,
3110 D3DCLIPSTATUS *ClipStatus)
3112 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3113 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, ClipStatus);
3114 return IDirect3DDevice7_GetClipStatus(ICOM_INTERFACE(This, IDirect3DDevice7),
3118 static HRESULT WINAPI
3119 Thunk_IDirect3DDeviceImpl_2_GetClipStatus(IDirect3DDevice2 *iface,
3120 D3DCLIPSTATUS *ClipStatus)
3122 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
3123 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, ClipStatus);
3124 return IDirect3DDevice7_GetClipStatus(ICOM_INTERFACE(This, IDirect3DDevice7),
3128 /*****************************************************************************
3129 * IDirect3DDevice::DrawPrimitiveStrided
3131 * Draws vertices described by a D3DDRAWPRIMITIVESTRIDEDDATA structure.
3136 * PrimitiveType: The primitive type to draw
3137 * VertexType: The FVF description of the vertices to draw (for the stride??)
3138 * D3DDrawPrimStrideData: A D3DDRAWPRIMITIVESTRIDEDDATA structure describing
3139 * the vertex data locations
3140 * VertexCount: The number of vertices to draw
3144 * D3D_OK, because it's a stub
3145 * (DDERR_INVALIDPARAMS if D3DDrawPrimStrideData is NULL)
3146 * (For details, see IWineD3DDevice::DrawPrimitiveStrided)
3148 *****************************************************************************/
3149 static HRESULT WINAPI
3150 IDirect3DDeviceImpl_7_DrawPrimitiveStrided(IDirect3DDevice7 *iface,
3151 D3DPRIMITIVETYPE PrimitiveType,
3153 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3157 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3158 WineDirect3DVertexStridedData WineD3DStrided;
3160 UINT PrimitiveCount;
3162 TRACE("(%p)->(%08x,%08x,%p,%08x,%08x): stub!\n", This, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Flags);
3164 /* Get the strided data right. the wined3d structure is a bit bigger
3165 * Watch out: The contents of the strided data are determined by the fvf,
3166 * not by the members set in D3DDrawPrimStrideData. So it's valid
3167 * to have diffuse.lpvData set to 0xdeadbeef if the diffuse flag is
3168 * not set in the fvf.
3170 if(VertexType & D3DFVF_POSITION_MASK)
3172 memset(&WineD3DStrided, 0, sizeof(WineD3DStrided));
3173 WineD3DStrided.u.s.position.lpData = D3DDrawPrimStrideData->position.lpvData;
3174 WineD3DStrided.u.s.position.dwStride = D3DDrawPrimStrideData->position.dwStride;
3175 WineD3DStrided.u.s.position.dwType = WINED3DDECLTYPE_FLOAT3;
3176 if (VertexType & D3DFVF_XYZRHW)
3178 WineD3DStrided.u.s.position.dwType = WINED3DDECLTYPE_FLOAT4;
3179 WineD3DStrided.u.s.position_transformed = TRUE;
3181 WineD3DStrided.u.s.position_transformed = FALSE;
3184 if(VertexType & D3DFVF_NORMAL)
3186 WineD3DStrided.u.s.normal.lpData = D3DDrawPrimStrideData->normal.lpvData;
3187 WineD3DStrided.u.s.normal.dwStride = D3DDrawPrimStrideData->normal.dwStride;
3188 WineD3DStrided.u.s.normal.dwType = WINED3DDECLTYPE_FLOAT3;
3191 if(VertexType & D3DFVF_DIFFUSE)
3193 WineD3DStrided.u.s.diffuse.lpData = D3DDrawPrimStrideData->diffuse.lpvData;
3194 WineD3DStrided.u.s.diffuse.dwStride = D3DDrawPrimStrideData->diffuse.dwStride;
3195 WineD3DStrided.u.s.diffuse.dwType = WINED3DDECLTYPE_SHORT4;
3198 if(VertexType & D3DFVF_SPECULAR)
3200 WineD3DStrided.u.s.specular.lpData = D3DDrawPrimStrideData->specular.lpvData;
3201 WineD3DStrided.u.s.specular.dwStride = D3DDrawPrimStrideData->specular.dwStride;
3202 WineD3DStrided.u.s.specular.dwType = WINED3DDECLTYPE_SHORT4;
3205 for( i = 0; i < GET_TEXCOUNT_FROM_FVF(VertexType); i++)
3207 WineD3DStrided.u.s.texCoords[i].lpData = D3DDrawPrimStrideData->textureCoords[i].lpvData;
3208 WineD3DStrided.u.s.texCoords[i].dwStride = D3DDrawPrimStrideData->textureCoords[i].dwStride;
3209 switch(GET_TEXCOORD_SIZE_FROM_FVF(VertexType, i))
3211 case 1: WineD3DStrided.u.s.texCoords[i].dwType = WINED3DDECLTYPE_FLOAT1; break;
3212 case 2: WineD3DStrided.u.s.texCoords[i].dwType = WINED3DDECLTYPE_FLOAT2; break;
3213 case 3: WineD3DStrided.u.s.texCoords[i].dwType = WINED3DDECLTYPE_FLOAT3; break;
3214 case 4: WineD3DStrided.u.s.texCoords[i].dwType = WINED3DDECLTYPE_FLOAT4; break;
3215 default: ERR("Unexpected texture coordinate size %d\n",
3216 GET_TEXCOORD_SIZE_FROM_FVF(VertexType, i));
3220 /* Get the primitive count */
3221 switch(PrimitiveType)
3223 case D3DPT_POINTLIST:
3224 PrimitiveCount = VertexCount;
3227 case D3DPT_LINELIST:
3228 PrimitiveCount = VertexCount / 2;
3231 case D3DPT_LINESTRIP:
3232 PrimitiveCount = VertexCount - 1;
3235 case D3DPT_TRIANGLELIST:
3236 PrimitiveCount = VertexCount / 3;
3239 case D3DPT_TRIANGLESTRIP:
3240 PrimitiveCount = VertexCount - 2;
3243 case D3DPT_TRIANGLEFAN:
3244 PrimitiveCount = VertexCount - 2;
3247 default: return DDERR_INVALIDPARAMS;
3250 IWineD3DDevice_SetFVF(This->wineD3DDevice,
3253 return IWineD3DDevice_DrawPrimitiveStrided(This->wineD3DDevice,
3259 static HRESULT WINAPI
3260 Thunk_IDirect3DDeviceImpl_3_DrawPrimitiveStrided(IDirect3DDevice3 *iface,
3261 D3DPRIMITIVETYPE PrimitiveType,
3263 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3267 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3268 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Flags);
3269 return IDirect3DDevice7_DrawPrimitiveStrided(ICOM_INTERFACE(This, IDirect3DDevice7),
3272 D3DDrawPrimStrideData,
3277 /*****************************************************************************
3278 * IDirect3DDevice7::DrawIndexedPrimitiveStrided
3280 * Draws primitives specified by strided data locations based on indices
3288 * D3D_OK, because it's a stub
3289 * (DDERR_INVALIDPARAMS if D3DDrawPrimStrideData is NULL)
3290 * (DDERR_INVALIDPARAMS if Indices is NULL)
3291 * (For more details, see IWineD3DDevice::DrawIndexedPrimitiveStrided)
3293 *****************************************************************************/
3294 static HRESULT WINAPI
3295 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveStrided(IDirect3DDevice7 *iface,
3296 D3DPRIMITIVETYPE PrimitiveType,
3298 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3304 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3305 FIXME("(%p)->(%08x,%08x,%p,%08x,%p,%08x,%08x): stub!\n", This, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Indices, IndexCount, Flags);
3307 /* I'll implement it as soon as I find a app to test it.
3308 * This needs an additional method in IWineD3DDevice.
3313 static HRESULT WINAPI
3314 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitiveStrided(IDirect3DDevice3 *iface,
3315 D3DPRIMITIVETYPE PrimitiveType,
3317 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3323 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3324 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", iface, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Indices, IndexCount, Flags);
3325 return IDirect3DDevice7_DrawIndexedPrimitiveStrided(ICOM_INTERFACE(This, IDirect3DDevice7),
3328 D3DDrawPrimStrideData,
3335 /*****************************************************************************
3336 * IDirect3DDevice7::DrawPrimitiveVB
3338 * Draws primitives from a vertex buffer to the screen.
3343 * PrimitiveType: Type of primitive to be rendered.
3344 * D3DVertexBuf: Source Vertex Buffer
3345 * StartVertex: Index of the first vertex from the buffer to be rendered
3346 * NumVertices: Number of vertices to be rendered
3347 * Flags: Can be D3DDP_WAIT to wait until rendering has finished
3351 * DDERR_INVALIDPARAMS if D3DVertexBuf is NULL
3353 *****************************************************************************/
3354 static HRESULT WINAPI
3355 IDirect3DDeviceImpl_7_DrawPrimitiveVB(IDirect3DDevice7 *iface,
3356 D3DPRIMITIVETYPE PrimitiveType,
3357 IDirect3DVertexBuffer7 *D3DVertexBuf,
3362 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3363 IDirect3DVertexBufferImpl *vb = ICOM_OBJECT(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, D3DVertexBuf);
3364 UINT PrimitiveCount;
3367 WINED3DVERTEXBUFFER_DESC Desc;
3369 TRACE("(%p)->(%08x,%p,%08x,%08x,%08x)\n", This, PrimitiveType, D3DVertexBuf, StartVertex, NumVertices, Flags);
3374 ERR("(%p) No Vertex buffer specified\n", This);
3375 return DDERR_INVALIDPARAMS;
3378 /* Get the primitive count */
3379 switch(PrimitiveType)
3381 case D3DPT_POINTLIST:
3382 PrimitiveCount = NumVertices;
3385 case D3DPT_LINELIST:
3386 PrimitiveCount = NumVertices / 2;
3389 case D3DPT_LINESTRIP:
3390 PrimitiveCount = NumVertices - 1;
3393 case D3DPT_TRIANGLELIST:
3394 PrimitiveCount = NumVertices / 3;
3397 case D3DPT_TRIANGLESTRIP:
3398 PrimitiveCount = NumVertices - 2;
3401 case D3DPT_TRIANGLEFAN:
3402 PrimitiveCount = NumVertices - 2;
3405 default: return DDERR_INVALIDPARAMS;
3408 /* Get the FVF of the vertex buffer, and its stride */
3409 hr = IWineD3DVertexBuffer_GetDesc(vb->wineD3DVertexBuffer,
3413 ERR("(%p) IWineD3DVertexBuffer::GetDesc failed with hr = %08x\n", This, hr);
3416 stride = get_flexible_vertex_size(Desc.FVF);
3418 hr = IWineD3DDevice_SetFVF(This->wineD3DDevice, Desc.FVF);
3421 ERR(" (%p) Setting the FVF failed, hr = %x!\n", This, hr);
3425 /* Set the vertex stream source */
3426 hr = IWineD3DDevice_SetStreamSource(This->wineD3DDevice,
3427 0 /* StreamNumber */,
3428 vb->wineD3DVertexBuffer,
3429 0 /* StartVertex - we pass this to DrawPrimitive */,
3433 ERR("(%p) IDirect3DDevice::SetStreamSource failed with hr = %08x\n", This, hr);
3437 /* Now draw the primitives */
3438 return IWineD3DDevice_DrawPrimitive(This->wineD3DDevice,
3444 static HRESULT WINAPI
3445 Thunk_IDirect3DDeviceImpl_3_DrawPrimitiveVB(IDirect3DDevice3 *iface,
3446 D3DPRIMITIVETYPE PrimitiveType,
3447 IDirect3DVertexBuffer *D3DVertexBuf,
3452 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3453 IDirect3DVertexBufferImpl *vb = ICOM_OBJECT(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, D3DVertexBuf);
3454 TRACE_(ddraw_thunk)("(%p)->(%08x,%p,%08x,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, vb, StartVertex, NumVertices, Flags);
3455 return IDirect3DDevice7_DrawPrimitiveVB(ICOM_INTERFACE(This, IDirect3DDevice7),
3457 ICOM_INTERFACE(vb, IDirect3DVertexBuffer7),
3464 /*****************************************************************************
3465 * IDirect3DDevice7::DrawIndexedPrimitiveVB
3467 * Draws primitives from a vertex buffer to the screen
3470 * PrimitiveType: Type of primitive to be rendered.
3471 * D3DVertexBuf: Source Vertex Buffer
3472 * StartVertex: Index of the first vertex from the buffer to be rendered
3473 * NumVertices: Number of vertices to be rendered
3474 * Indices: Array of DWORDs used to index into the Vertices
3475 * IndexCount: Number of indices in Indices
3476 * Flags: Can be D3DDP_WAIT to wait until rendering has finished
3480 *****************************************************************************/
3481 static HRESULT WINAPI
3482 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface,
3483 D3DPRIMITIVETYPE PrimitiveType,
3484 IDirect3DVertexBuffer7 *D3DVertexBuf,
3491 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3492 IDirect3DVertexBufferImpl *vb = ICOM_OBJECT(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, D3DVertexBuf);
3494 UINT PrimitiveCount;
3495 WORD *LockedIndices;
3497 WINED3DVERTEXBUFFER_DESC Desc;
3499 TRACE("(%p)->(%08x,%p,%d,%d,%p,%d,%08x)\n", This, PrimitiveType, vb, StartVertex, NumVertices, Indices, IndexCount, Flags);
3502 * 1) Calculate some things: Vertex count -> Primitive count, stride, ...
3503 * 2) Upload the Indices to the index buffer
3504 * 3) Set the index source
3505 * 4) Set the Vertex Buffer as the Stream source
3506 * 5) Call IWineD3DDevice::DrawIndexedPrimitive
3509 /* Get the primitive count */
3510 switch(PrimitiveType)
3512 case D3DPT_POINTLIST:
3513 PrimitiveCount = IndexCount;
3516 case D3DPT_LINELIST:
3517 PrimitiveCount = IndexCount / 2;
3520 case D3DPT_LINESTRIP:
3521 PrimitiveCount = IndexCount - 1;
3524 case D3DPT_TRIANGLELIST:
3525 PrimitiveCount = IndexCount / 3;
3528 case D3DPT_TRIANGLESTRIP:
3529 PrimitiveCount = IndexCount - 2;
3532 case D3DPT_TRIANGLEFAN:
3533 PrimitiveCount = IndexCount - 2;
3536 default: return DDERR_INVALIDPARAMS;
3539 /* Get the FVF of the vertex buffer, and its stride */
3540 hr = IWineD3DVertexBuffer_GetDesc(vb->wineD3DVertexBuffer,
3544 ERR("(%p) IWineD3DVertexBuffer::GetDesc failed with hr = %08x\n", This, hr);
3547 stride = get_flexible_vertex_size(Desc.FVF);
3548 TRACE("Vertex buffer FVF = %08x, stride=%d\n", Desc.FVF, stride);
3550 hr = IWineD3DDevice_SetFVF(This->wineD3DDevice, Desc.FVF);
3553 ERR(" (%p) Setting the FVF failed, hr = %x!\n", This, hr);
3557 /* copy the index stream into the index buffer.
3558 * A new IWineD3DDevice method could be created
3559 * which takes an user pointer containing the indices
3560 * or a SetData-Method for the index buffer, which
3561 * overrides the index buffer data with our pointer.
3563 hr = IWineD3DIndexBuffer_Lock(This->indexbuffer,
3564 0 /* OffSetToLock */,
3565 0 /* SizeToLock - doesn't matter */,
3566 (BYTE **) &LockedIndices,
3568 assert(IndexCount < 0x100000);
3571 ERR("(%p) IWineD3DIndexBuffer::Lock failed with hr = %08x\n", This, hr);
3574 memcpy(LockedIndices, Indices, IndexCount * sizeof(WORD));
3575 hr = IWineD3DIndexBuffer_Unlock(This->indexbuffer);
3578 ERR("(%p) IWineD3DIndexBuffer::Unlock failed with hr = %08x\n", This, hr);
3582 /* Set the index stream */
3583 hr = IWineD3DDevice_SetIndices(This->wineD3DDevice,
3587 /* Set the vertex stream source */
3588 hr = IWineD3DDevice_SetStreamSource(This->wineD3DDevice,
3589 0 /* StreamNumber */,
3590 vb->wineD3DVertexBuffer,
3591 0 /* offset, we pass this to DrawIndexedPrimitive */,
3595 ERR("(%p) IDirect3DDevice::SetStreamSource failed with hr = %08x\n", This, hr);
3600 hr = IWineD3DDevice_DrawIndexedPrimitive(This->wineD3DDevice,
3611 static HRESULT WINAPI
3612 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitiveVB(IDirect3DDevice3 *iface,
3613 D3DPRIMITIVETYPE PrimitiveType,
3614 IDirect3DVertexBuffer *D3DVertexBuf,
3619 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3620 IDirect3DVertexBufferImpl *VB = ICOM_OBJECT(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, D3DVertexBuf);
3621 TRACE_(ddraw_thunk)("(%p)->(%08x,%p,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VB, Indices, IndexCount, Flags);
3623 return IDirect3DDevice7_DrawIndexedPrimitiveVB(ICOM_INTERFACE(This, IDirect3DDevice7),
3625 ICOM_INTERFACE(VB, IDirect3DVertexBuffer7),
3633 /*****************************************************************************
3634 * IDirect3DDevice7::ComputeSphereVisibility
3636 * Calculates the visibility of spheres in the current viewport. The spheres
3637 * are passed in the Centers and Radii arrays, the results are passed back
3638 * in the ReturnValues array. Return values are either completely visible,
3639 * partially visible or completely invisible.
3640 * The return value consist of a combination of D3DCLIP_* flags, or it's
3641 * 0 if the sphere is completely visible(according to the SDK, not checked)
3643 * Sounds like an overdose of math ;)
3648 * Centers: Array containing the sphere centers
3649 * Radii: Array containing the sphere radii
3650 * NumSpheres: The number of centers and radii in the arrays
3652 * ReturnValues: Array to write the results to
3655 * D3D_OK because it's a stub
3656 * (DDERR_INVALIDPARAMS if Centers, Radii or ReturnValues are NULL)
3657 * (D3DERR_INVALIDMATRIX if the combined world, view and proj matrix
3660 *****************************************************************************/
3661 static HRESULT WINAPI
3662 IDirect3DDeviceImpl_7_ComputeSphereVisibility(IDirect3DDevice7 *iface,
3667 DWORD *ReturnValues)
3669 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3670 FIXME("(%p)->(%p,%p,%08x,%08x,%p): stub!\n", This, Centers, Radii, NumSpheres, Flags, ReturnValues);
3672 /* the DirectX 7 sdk says that the visibility is computed by
3673 * back-transforming the viewing frustum to model space
3674 * using the inverse of the combined world, view and projection
3675 * matrix. If the matrix can't be reversed, D3DERR_INVALIDMATRIX
3678 * Basic implementation idea:
3679 * 1) Check if the center is in the viewing frustum
3680 * 2) Cut the sphere with the planes of the viewing
3683 * ->Center inside the frustum, no intersections:
3685 * ->Center outside the frustum, no intersections:
3687 * ->Some intersections: Partially visible
3689 * Implement this call in WineD3D. Either implement the
3690 * matrix and vector stuff in WineD3D, or use some external
3697 static HRESULT WINAPI
3698 Thunk_IDirect3DDeviceImpl_3_ComputeSphereVisibility(IDirect3DDevice3 *iface,
3703 DWORD *ReturnValues)
3705 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3706 TRACE_(ddraw_thunk)("(%p)->(%p,%p,%08x,%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, Centers, Radii, NumSpheres, Flags, ReturnValues);
3707 return IDirect3DDevice7_ComputeSphereVisibility(ICOM_INTERFACE(This, IDirect3DDevice7),
3715 /*****************************************************************************
3716 * IDirect3DDevice7::GetTexture
3718 * Returns the texture interface handle assigned to a texture stage.
3719 * The returned texture is AddRefed. This is taken from old ddraw,
3720 * not checked in Windows.
3725 * Stage: Texture stage to read the texture from
3726 * Texture: Address to store the interface pointer at
3730 * DDERR_INVALIDPARAMS if Texture is NULL
3731 * For details, see IWineD3DDevice::GetTexture
3733 *****************************************************************************/
3734 static HRESULT WINAPI
3735 IDirect3DDeviceImpl_7_GetTexture(IDirect3DDevice7 *iface,
3737 IDirectDrawSurface7 **Texture)
3739 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3740 IWineD3DBaseTexture *Surf;
3742 TRACE("(%p)->(%d,%p): Relay\n", This, Stage, Texture);
3746 TRACE("Texture == NULL, failing with DDERR_INVALIDPARAMS\n");
3747 return DDERR_INVALIDPARAMS;
3750 hr = IWineD3DDevice_GetTexture(This->wineD3DDevice, Stage, (IWineD3DBaseTexture **) &Surf);
3751 if( (hr != D3D_OK) || (!Surf) )
3757 /* GetParent AddRef()s, which is perfectly OK.
3758 * We have passed the IDirectDrawSurface7 interface to WineD3D, so that's OK too.
3760 return IWineD3DBaseTexture_GetParent(Surf,
3761 (IUnknown **) Texture);
3764 static HRESULT WINAPI
3765 Thunk_IDirect3DDeviceImpl_3_GetTexture(IDirect3DDevice3 *iface,
3767 IDirect3DTexture2 **Texture2)
3769 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3771 IDirectDrawSurface7 *ret_val;
3773 TRACE_(ddraw_thunk)("(%p)->(%d,%p) thunking to IDirect3DDevice7 interface.\n", This, Stage, Texture2);
3774 ret = IDirect3DDevice7_GetTexture(ICOM_INTERFACE(This, IDirect3DDevice7),
3778 *Texture2 = COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7, IDirect3DTexture2, ret_val);
3780 TRACE_(ddraw_thunk)(" returning interface %p.\n", *Texture2);
3785 /*****************************************************************************
3786 * IDirect3DDevice7::SetTexture
3788 * Assigns a texture to a texture stage. Is the texture AddRef-ed?
3793 * Stage: The stage to assign the texture to
3794 * Texture: Interface pointer to the texture surface
3798 * For details, see IWineD3DDevice::SetTexture
3800 *****************************************************************************/
3801 static HRESULT WINAPI
3802 IDirect3DDeviceImpl_7_SetTexture(IDirect3DDevice7 *iface,
3804 IDirectDrawSurface7 *Texture)
3806 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3807 IDirectDrawSurfaceImpl *surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Texture);
3808 TRACE("(%p)->(%08x,%p): Relay!\n", This, Stage, surf);
3810 /* Texture may be NULL here */
3811 return IWineD3DDevice_SetTexture(This->wineD3DDevice,
3813 surf ? (IWineD3DBaseTexture * ) surf->wineD3DTexture : NULL);
3816 static HRESULT WINAPI
3817 Thunk_IDirect3DDeviceImpl_3_SetTexture(IDirect3DDevice3 *iface,
3819 IDirect3DTexture2 *Texture2)
3821 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3822 IDirectDrawSurfaceImpl *tex = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture2, Texture2);
3823 TRACE_(ddraw_thunk)("(%p)->(%d,%p) thunking to IDirect3DDevice7 interface.\n", This, Stage, tex);
3824 return IDirect3DDevice7_SetTexture(ICOM_INTERFACE(This, IDirect3DDevice7),
3826 ICOM_INTERFACE(tex, IDirectDrawSurface7));
3829 /*****************************************************************************
3830 * IDirect3DDevice7::GetTextureStageState
3832 * Retrieves a state from a texture stage.
3837 * Stage: The stage to retrieve the state from
3838 * TexStageStateType: The state type to retrieve
3839 * State: Address to store the state's value at
3843 * DDERR_INVALIDPARAMS if State is NULL
3844 * For details, see IWineD3DDevice::GetTextureStageState
3846 *****************************************************************************/
3847 static HRESULT WINAPI
3848 IDirect3DDeviceImpl_7_GetTextureStageState(IDirect3DDevice7 *iface,
3850 D3DTEXTURESTAGESTATETYPE TexStageStateType,
3853 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3854 TRACE("(%p)->(%08x,%08x,%p): Relay!\n", This, Stage, TexStageStateType, State);
3857 return DDERR_INVALIDPARAMS;
3859 return IWineD3DDevice_GetTextureStageState(This->wineD3DDevice,
3865 static HRESULT WINAPI
3866 Thunk_IDirect3DDeviceImpl_3_GetTextureStageState(IDirect3DDevice3 *iface,
3868 D3DTEXTURESTAGESTATETYPE TexStageStateType,
3871 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3872 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, Stage, TexStageStateType, State);
3873 return IDirect3DDevice7_GetTextureStageState(ICOM_INTERFACE(This, IDirect3DDevice7),
3879 /*****************************************************************************
3880 * IDirect3DDevice7::SetTextureStageState
3882 * Sets a texture stage state. Some stage types need to be handled specially,
3883 * because they do not exist in WineD3D and were moved to another place
3888 * Stage: The stage to modify
3889 * TexStageStateType: The state to change
3890 * State: The new value for the state
3894 * For details, see IWineD3DDevice::SetTextureStageState
3896 *****************************************************************************/
3897 static HRESULT WINAPI
3898 IDirect3DDeviceImpl_7_SetTextureStageState(IDirect3DDevice7 *iface,
3900 D3DTEXTURESTAGESTATETYPE TexStageStateType,
3903 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3904 TRACE("(%p)->(%08x,%08x,%08x): Relay!\n", This, Stage, TexStageStateType, State);
3905 switch(TexStageStateType)
3907 /* Mipfilter is a sampler state with different values */
3908 case D3DTSS_MIPFILTER:
3910 WINED3DTEXTUREFILTERTYPE value;
3913 case D3DTFP_NONE: value = WINED3DTEXF_NONE; break;
3914 case D3DTFP_POINT: value = WINED3DTEXF_POINT; break;
3915 case 0: /* Unchecked */
3916 case D3DTFP_LINEAR: value = WINED3DTEXF_LINEAR; break;
3918 ERR("Unexpected mipfilter value %d\n", State);
3919 value = WINED3DTEXF_NONE;
3921 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
3923 WINED3DSAMP_MIPFILTER,
3927 /* Minfilter is a sampler state too, equal values */
3928 case D3DTSS_MINFILTER:
3929 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
3931 WINED3DSAMP_MINFILTER,
3933 /* Same for MAGFILTER */
3934 case D3DTSS_MAGFILTER:
3935 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
3937 WINED3DSAMP_MAGFILTER,
3942 return IWineD3DDevice_SetTextureStageState(This->wineD3DDevice,
3949 static HRESULT WINAPI
3950 Thunk_IDirect3DDeviceImpl_3_SetTextureStageState(IDirect3DDevice3 *iface,
3952 D3DTEXTURESTAGESTATETYPE TexStageStateType,
3955 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3956 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, Stage, TexStageStateType, State);
3957 return IDirect3DDevice7_SetTextureStageState(ICOM_INTERFACE(This, IDirect3DDevice7),
3963 /*****************************************************************************
3964 * IDirect3DDevice7::ValidateDevice
3966 * SDK: "Reports the device's ability to render the currently set
3967 * texture-blending operations in a single pass". Whatever that means
3973 * NumPasses: Address to write the number of necessary passes for the
3974 * desired effect to.
3978 * See IWineD3DDevice::ValidateDevice for more details
3980 *****************************************************************************/
3981 static HRESULT WINAPI
3982 IDirect3DDeviceImpl_7_ValidateDevice(IDirect3DDevice7 *iface,
3985 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3986 TRACE("(%p)->(%p): Relay\n", This, NumPasses);
3988 return IWineD3DDevice_ValidateDevice(This->wineD3DDevice, NumPasses);
3991 static HRESULT WINAPI
3992 Thunk_IDirect3DDeviceImpl_3_ValidateDevice(IDirect3DDevice3 *iface,
3995 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3996 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, Passes);
3997 return IDirect3DDevice7_ValidateDevice(ICOM_INTERFACE(This, IDirect3DDevice7),
4001 /*****************************************************************************
4002 * IDirect3DDevice7::Clear
4004 * Fills the render target, the z buffer and the stencil buffer with a
4005 * clear color / value
4010 * Count: Number of rectangles in Rects must be 0 if Rects is NULL
4011 * Rects: Rectangles to clear. If NULL, the whole surface is cleared
4012 * Flags: Some flags, as usual
4013 * Color: Clear color for the render target
4014 * Z: Clear value for the Z buffer
4015 * Stencil: Clear value to store in each stencil buffer entry
4019 * For details, see IWineD3DDevice::Clear
4021 *****************************************************************************/
4022 static HRESULT WINAPI
4023 IDirect3DDeviceImpl_7_Clear(IDirect3DDevice7 *iface,
4031 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4032 TRACE("(%p)->(%08x,%p,%08x,%08x,%f,%08x): Relay\n", This, Count, Rects, Flags, (DWORD) Color, Z, Stencil);
4034 /* Note; D3DRECT is compatible with WINED3DRECT */
4035 return IWineD3DDevice_Clear(This->wineD3DDevice, Count, (WINED3DRECT*) Rects, Flags, Color, Z, Stencil);
4038 /*****************************************************************************
4039 * IDirect3DDevice7::SetViewport
4041 * Sets the current viewport.
4043 * Version 7 only, but IDirect3DViewport uses this call for older
4047 * Data: The new viewport to set
4051 * DDERR_INVALIDPARAMS if Data is NULL
4052 * For more details, see IWineDDDevice::SetViewport
4054 *****************************************************************************/
4055 static HRESULT WINAPI
4056 IDirect3DDeviceImpl_7_SetViewport(IDirect3DDevice7 *iface,
4059 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4060 TRACE("(%p)->(%p) Relay!\n", This, Data);
4063 return DDERR_INVALIDPARAMS;
4065 /* Note: D3DVIEWPORT7 is compatible with WINED3DVIEWPORT */
4066 return IWineD3DDevice_SetViewport(This->wineD3DDevice,
4067 (WINED3DVIEWPORT*) Data);
4070 /*****************************************************************************
4071 * IDirect3DDevice::GetViewport
4073 * Returns the current viewport
4078 * Data: D3D7Viewport structure to write the viewport information to
4082 * DDERR_INVALIDPARAMS if Data is NULL
4083 * For more details, see IWineD3DDevice::GetViewport
4085 *****************************************************************************/
4086 static HRESULT WINAPI
4087 IDirect3DDeviceImpl_7_GetViewport(IDirect3DDevice7 *iface,
4090 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4092 TRACE("(%p)->(%p) Relay!\n", This, Data);
4095 return DDERR_INVALIDPARAMS;
4097 /* Note: D3DVIEWPORT7 is compatible with WINED3DVIEWPORT */
4098 hr = IWineD3DDevice_GetViewport(This->wineD3DDevice,
4099 (WINED3DVIEWPORT*) Data);
4101 return hr_ddraw_from_wined3d(hr);
4104 /*****************************************************************************
4105 * IDirect3DDevice7::SetMaterial
4112 * Mat: The material to set
4116 * DDERR_INVALIDPARAMS if Mat is NULL.
4117 * For more details, see IWineD3DDevice::SetMaterial
4119 *****************************************************************************/
4120 static HRESULT WINAPI
4121 IDirect3DDeviceImpl_7_SetMaterial(IDirect3DDevice7 *iface,
4124 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4126 TRACE("(%p)->(%p): Relay!\n", This, Mat);
4128 /* Note: D3DMATERIAL7 is compatible with WINED3DMATERIAL */
4129 hr = IWineD3DDevice_SetMaterial(This->wineD3DDevice,
4130 (WINED3DMATERIAL*) Mat);
4132 return hr_ddraw_from_wined3d(hr);
4135 /*****************************************************************************
4136 * IDirect3DDevice7::GetMaterial
4138 * Returns the current material
4143 * Mat: D3DMATERIAL7 structure to write the material parameters to
4147 * DDERR_INVALIDPARAMS if Mat is NULL
4148 * For more details, see IWineD3DDevice::GetMaterial
4150 *****************************************************************************/
4151 static HRESULT WINAPI
4152 IDirect3DDeviceImpl_7_GetMaterial(IDirect3DDevice7 *iface,
4155 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4157 TRACE("(%p)->(%p): Relay!\n", This, Mat);
4159 /* Note: D3DMATERIAL7 is compatible with WINED3DMATERIAL */
4160 hr = IWineD3DDevice_GetMaterial(This->wineD3DDevice,
4161 (WINED3DMATERIAL*) Mat);
4163 return hr_ddraw_from_wined3d(hr);
4166 /*****************************************************************************
4167 * IDirect3DDevice7::SetLight
4169 * Assigns a light to a light index, but doesn't activate it yet.
4171 * Version 7, IDirect3DLight uses this method for older versions
4174 * LightIndex: The index of the new light
4175 * Light: A D3DLIGHT7 structure describing the light
4179 * For more details, see IWineD3DDevice::SetLight
4181 *****************************************************************************/
4182 static HRESULT WINAPI
4183 IDirect3DDeviceImpl_7_SetLight(IDirect3DDevice7 *iface,
4187 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4189 TRACE("(%p)->(%08x,%p): Relay!\n", This, LightIndex, Light);
4191 /* Note: D3DLIGHT7 is compatible with WINED3DLIGHT */
4192 hr = IWineD3DDevice_SetLight(This->wineD3DDevice,
4194 (WINED3DLIGHT*) Light);
4196 return hr_ddraw_from_wined3d(hr);
4199 /*****************************************************************************
4200 * IDirect3DDevice7::GetLight
4202 * Returns the light assigned to a light index
4205 * Light: Structure to write the light information to
4209 * DDERR_INVALIDPARAMS if Light is NULL
4210 * For details, see IWineD3DDevice::GetLight
4212 *****************************************************************************/
4213 static HRESULT WINAPI
4214 IDirect3DDeviceImpl_7_GetLight(IDirect3DDevice7 *iface,
4218 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4220 TRACE("(%p)->(%08x,%p): Relay!\n", This, LightIndex, Light);
4222 /* Note: D3DLIGHT7 is compatible with WINED3DLIGHT */
4223 rc = IWineD3DDevice_GetLight(This->wineD3DDevice,
4225 (WINED3DLIGHT*) Light);
4227 /* Translate the result. WineD3D returns other values than D3D7 */
4228 return hr_ddraw_from_wined3d(rc);
4231 /*****************************************************************************
4232 * IDirect3DDevice7::BeginStateBlock
4234 * Begins recording to a stateblock
4240 * For details see IWineD3DDevice::BeginStateBlock
4242 *****************************************************************************/
4243 static HRESULT WINAPI
4244 IDirect3DDeviceImpl_7_BeginStateBlock(IDirect3DDevice7 *iface)
4246 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4248 TRACE("(%p)->(): Relay!\n", This);
4250 hr = IWineD3DDevice_BeginStateBlock(This->wineD3DDevice);
4251 return hr_ddraw_from_wined3d(hr);
4254 /*****************************************************************************
4255 * IDirect3DDevice7::EndStateBlock
4257 * Stops recording to a state block and returns the created stateblock
4258 * handle. The d3d7 stateblock handles are the interface pointers of the
4259 * IWineD3DStateBlock interface
4264 * BlockHandle: Address to store the stateblock's handle to
4268 * DDERR_INVALIDPARAMS if BlockHandle is NULL
4269 * See IWineD3DDevice::EndStateBlock for more details
4271 *****************************************************************************/
4272 static HRESULT WINAPI
4273 IDirect3DDeviceImpl_7_EndStateBlock(IDirect3DDevice7 *iface,
4276 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4278 TRACE("(%p)->(%p): Relay!\n", This, BlockHandle);
4281 return DDERR_INVALIDPARAMS;
4283 hr = IWineD3DDevice_EndStateBlock(This->wineD3DDevice,
4284 (IWineD3DStateBlock **) BlockHandle);
4285 return hr_ddraw_from_wined3d(hr);
4288 /*****************************************************************************
4289 * IDirect3DDevice7::PreLoad
4291 * Allows the app to signal that a texture will be used soon, to allow
4292 * the Direct3DDevice to load it to the video card in the meantime.
4297 * Texture: The texture to preload
4301 * DDERR_INVALIDPARAMS if Texture is NULL
4302 * See IWineD3DSurface::PreLoad for details
4304 *****************************************************************************/
4305 static HRESULT WINAPI
4306 IDirect3DDeviceImpl_7_PreLoad(IDirect3DDevice7 *iface,
4307 IDirectDrawSurface7 *Texture)
4309 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4310 IDirectDrawSurfaceImpl *surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Texture);
4312 TRACE("(%p)->(%p): Relay!\n", This, surf);
4315 return DDERR_INVALIDPARAMS;
4317 IWineD3DSurface_PreLoad(surf->WineD3DSurface);
4321 /*****************************************************************************
4322 * IDirect3DDevice7::ApplyStateBlock
4324 * Activates the state stored in a state block handle.
4327 * BlockHandle: The stateblock handle to activate
4331 * D3DERR_INVALIDSTATEBLOCK if BlockHandle is NULL
4333 *****************************************************************************/
4334 static HRESULT WINAPI
4335 IDirect3DDeviceImpl_7_ApplyStateBlock(IDirect3DDevice7 *iface,
4338 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4340 TRACE("(%p)->(%08x): Relay!\n", This, BlockHandle);
4343 return D3DERR_INVALIDSTATEBLOCK;
4345 hr = IWineD3DStateBlock_Apply((IWineD3DStateBlock *) BlockHandle);
4346 return hr_ddraw_from_wined3d(hr);
4349 /*****************************************************************************
4350 * IDirect3DDevice7::CaptureStateBlock
4352 * Updates a stateblock's values to the values currently set for the device
4357 * BlockHandle: Stateblock to update
4361 * D3DERR_INVALIDSTATEBLOCK if BlockHandle is NULL
4362 * See IWineD3DDevice::CaptureStateBlock for more details
4364 *****************************************************************************/
4365 static HRESULT WINAPI
4366 IDirect3DDeviceImpl_7_CaptureStateBlock(IDirect3DDevice7 *iface,
4369 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4371 TRACE("(%p)->(%08x): Relay!\n", This, BlockHandle);
4373 if(BlockHandle == 0)
4374 return D3DERR_INVALIDSTATEBLOCK;
4376 hr = IWineD3DStateBlock_Capture((IWineD3DStateBlock *) BlockHandle);
4377 return hr_ddraw_from_wined3d(hr);
4380 /*****************************************************************************
4381 * IDirect3DDevice7::DeleteStateBlock
4383 * Deletes a stateblock handle. This means releasing the WineD3DStateBlock
4388 * BlockHandle: Stateblock handle to delete
4392 * D3DERR_INVALIDSTATEBLOCK if BlockHandle is 0
4394 *****************************************************************************/
4395 static HRESULT WINAPI
4396 IDirect3DDeviceImpl_7_DeleteStateBlock(IDirect3DDevice7 *iface,
4399 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4400 TRACE("(%p)->(%08x): Relay!\n", This, BlockHandle);
4402 if(BlockHandle == 0)
4403 return D3DERR_INVALIDSTATEBLOCK;
4405 IWineD3DStateBlock_Release((IWineD3DStateBlock *) BlockHandle);
4410 /*****************************************************************************
4411 * IDirect3DDevice7::CreateStateBlock
4413 * Creates a new state block handle.
4418 * Type: The state block type
4419 * BlockHandle: Address to write the created handle to
4423 * DDERR_INVALIDPARAMS if BlockHandle is NULL
4425 *****************************************************************************/
4426 static HRESULT WINAPI
4427 IDirect3DDeviceImpl_7_CreateStateBlock(IDirect3DDevice7 *iface,
4428 D3DSTATEBLOCKTYPE Type,
4431 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4433 TRACE("(%p)->(%08x,%p)!\n", This, Type, BlockHandle);
4436 return DDERR_INVALIDPARAMS;
4438 /* The D3DSTATEBLOCKTYPE enum is fine here */
4439 hr = IWineD3DDevice_CreateStateBlock(This->wineD3DDevice,
4441 (IWineD3DStateBlock **) BlockHandle,
4442 NULL /* Parent, hope that works */);
4443 return hr_ddraw_from_wined3d(hr);
4446 /*****************************************************************************
4447 * IDirect3DDevice7::Load
4449 * Loads a rectangular area from the source into the destination texture.
4450 * It can also copy the source to the faces of a cubic environment map
4455 * DestTex: Destination texture
4456 * DestPoint: Point in the destination where the source image should be
4458 * SrcTex: Source texture
4459 * SrcRect: Source rectangle
4464 * DDERR_INVALIDPARAMS if DestTex or SrcTex are NULL
4465 * See IDirect3DTexture2::Load for details
4467 *****************************************************************************/
4468 static HRESULT WINAPI
4469 IDirect3DDeviceImpl_7_Load(IDirect3DDevice7 *iface,
4470 IDirectDrawSurface7 *DestTex,
4472 IDirectDrawSurface7 *SrcTex,
4476 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4477 IDirectDrawSurfaceImpl *dest = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DestTex);
4478 IDirectDrawSurfaceImpl *src = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, SrcTex);
4479 FIXME("(%p)->(%p,%p,%p,%p,%08x): Partially Implemented!\n", This, dest, DestPoint, src, SrcRect, Flags);
4481 if( (!src) || (!dest) )
4482 return DDERR_INVALIDPARAMS;
4484 IDirect3DTexture2_Load(ICOM_INTERFACE(dest, IDirect3DTexture2),
4485 ICOM_INTERFACE(src, IDirect3DTexture2));
4489 /*****************************************************************************
4490 * IDirect3DDevice7::LightEnable
4492 * Enables or disables a light
4494 * Version 7, IDirect3DLight uses this method too.
4497 * LightIndex: The index of the light to enable / disable
4498 * Enable: Enable or disable the light
4502 * For more details, see IWineD3DDevice::SetLightEnable
4504 *****************************************************************************/
4505 static HRESULT WINAPI
4506 IDirect3DDeviceImpl_7_LightEnable(IDirect3DDevice7 *iface,
4510 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4512 TRACE("(%p)->(%08x,%d): Relay!\n", This, LightIndex, Enable);
4514 hr = IWineD3DDevice_SetLightEnable(This->wineD3DDevice, LightIndex, Enable);
4515 return hr_ddraw_from_wined3d(hr);
4518 /*****************************************************************************
4519 * IDirect3DDevice7::GetLightEnable
4521 * Retrieves if the light with the given index is enabled or not
4526 * LightIndex: Index of desired light
4527 * Enable: Pointer to a BOOL which contains the result
4531 * DDERR_INVALIDPARAMS if Enable is NULL
4532 * See IWineD3DDevice::GetLightEnable for more details
4534 *****************************************************************************/
4535 static HRESULT WINAPI
4536 IDirect3DDeviceImpl_7_GetLightEnable(IDirect3DDevice7 *iface,
4540 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4542 TRACE("(%p)->(%08x,%p): Relay\n", This, LightIndex, Enable);
4545 return DDERR_INVALIDPARAMS;
4547 hr = IWineD3DDevice_GetLightEnable(This->wineD3DDevice, LightIndex, Enable);
4548 return hr_ddraw_from_wined3d(hr);
4551 /*****************************************************************************
4552 * IDirect3DDevice7::SetClipPlane
4554 * Sets custom clipping plane
4559 * Index: The index of the clipping plane
4560 * PlaneEquation: An equation defining the clipping plane
4564 * DDERR_INVALIDPARAMS if PlaneEquation is NULL
4565 * See IWineD3DDevice::SetClipPlane for more details
4567 *****************************************************************************/
4568 static HRESULT WINAPI
4569 IDirect3DDeviceImpl_7_SetClipPlane(IDirect3DDevice7 *iface,
4571 D3DVALUE* PlaneEquation)
4573 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4574 TRACE("(%p)->(%08x,%p): Relay!\n", This, Index, PlaneEquation);
4577 return DDERR_INVALIDPARAMS;
4579 return IWineD3DDevice_SetClipPlane(This->wineD3DDevice, Index, PlaneEquation);
4582 /*****************************************************************************
4583 * IDirect3DDevice7::GetClipPlane
4585 * Returns the clipping plane with a specific index
4588 * Index: The index of the desired plane
4589 * PlaneEquation: Address to store the plane equation to
4593 * DDERR_INVALIDPARAMS if PlaneEquation is NULL
4594 * See IWineD3DDevice::GetClipPlane for more details
4596 *****************************************************************************/
4597 static HRESULT WINAPI
4598 IDirect3DDeviceImpl_7_GetClipPlane(IDirect3DDevice7 *iface,
4600 D3DVALUE* PlaneEquation)
4602 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4603 TRACE("(%p)->(%d,%p): Relay!\n", This, Index, PlaneEquation);
4606 return DDERR_INVALIDPARAMS;
4608 return IWineD3DDevice_GetClipPlane(This->wineD3DDevice, Index, PlaneEquation);
4611 /*****************************************************************************
4612 * IDirect3DDevice7::GetInfo
4614 * Retrieves some information about the device. The DirectX sdk says that
4615 * this version returns S_FALSE for all retail builds of DirectX, that's what
4616 * this implementation does.
4619 * DevInfoID: Information type requested
4620 * DevInfoStruct: Pointer to a structure to store the info to
4621 * Size: Size of the structure
4624 * S_FALSE, because it's a non-debug driver
4626 *****************************************************************************/
4627 static HRESULT WINAPI
4628 IDirect3DDeviceImpl_7_GetInfo(IDirect3DDevice7 *iface,
4630 void *DevInfoStruct,
4633 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4634 TRACE("(%p)->(%08x,%p,%08x)\n", This, DevInfoID, DevInfoStruct, Size);
4638 TRACE(" info requested : ");
4641 case D3DDEVINFOID_TEXTUREMANAGER: TRACE("D3DDEVINFOID_TEXTUREMANAGER\n"); break;
4642 case D3DDEVINFOID_D3DTEXTUREMANAGER: TRACE("D3DDEVINFOID_D3DTEXTUREMANAGER\n"); break;
4643 case D3DDEVINFOID_TEXTURING: TRACE("D3DDEVINFOID_TEXTURING\n"); break;
4644 default: ERR(" invalid flag !!!\n"); return DDERR_INVALIDPARAMS;
4648 return S_FALSE; /* According to MSDN, this is valid for a non-debug driver */
4651 const IDirect3DDevice7Vtbl IDirect3DDevice7_Vtbl =
4653 /*** IUnknown Methods ***/
4654 IDirect3DDeviceImpl_7_QueryInterface,
4655 IDirect3DDeviceImpl_7_AddRef,
4656 IDirect3DDeviceImpl_7_Release,
4657 /*** IDirect3DDevice7 ***/
4658 IDirect3DDeviceImpl_7_GetCaps,
4659 IDirect3DDeviceImpl_7_EnumTextureFormats,
4660 IDirect3DDeviceImpl_7_BeginScene,
4661 IDirect3DDeviceImpl_7_EndScene,
4662 IDirect3DDeviceImpl_7_GetDirect3D,
4663 IDirect3DDeviceImpl_7_SetRenderTarget,
4664 IDirect3DDeviceImpl_7_GetRenderTarget,
4665 IDirect3DDeviceImpl_7_Clear,
4666 IDirect3DDeviceImpl_7_SetTransform,
4667 IDirect3DDeviceImpl_7_GetTransform,
4668 IDirect3DDeviceImpl_7_SetViewport,
4669 IDirect3DDeviceImpl_7_MultiplyTransform,
4670 IDirect3DDeviceImpl_7_GetViewport,
4671 IDirect3DDeviceImpl_7_SetMaterial,
4672 IDirect3DDeviceImpl_7_GetMaterial,
4673 IDirect3DDeviceImpl_7_SetLight,
4674 IDirect3DDeviceImpl_7_GetLight,
4675 IDirect3DDeviceImpl_7_SetRenderState,
4676 IDirect3DDeviceImpl_7_GetRenderState,
4677 IDirect3DDeviceImpl_7_BeginStateBlock,
4678 IDirect3DDeviceImpl_7_EndStateBlock,
4679 IDirect3DDeviceImpl_7_PreLoad,
4680 IDirect3DDeviceImpl_7_DrawPrimitive,
4681 IDirect3DDeviceImpl_7_DrawIndexedPrimitive,
4682 IDirect3DDeviceImpl_7_SetClipStatus,
4683 IDirect3DDeviceImpl_7_GetClipStatus,
4684 IDirect3DDeviceImpl_7_DrawPrimitiveStrided,
4685 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveStrided,
4686 IDirect3DDeviceImpl_7_DrawPrimitiveVB,
4687 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB,
4688 IDirect3DDeviceImpl_7_ComputeSphereVisibility,
4689 IDirect3DDeviceImpl_7_GetTexture,
4690 IDirect3DDeviceImpl_7_SetTexture,
4691 IDirect3DDeviceImpl_7_GetTextureStageState,
4692 IDirect3DDeviceImpl_7_SetTextureStageState,
4693 IDirect3DDeviceImpl_7_ValidateDevice,
4694 IDirect3DDeviceImpl_7_ApplyStateBlock,
4695 IDirect3DDeviceImpl_7_CaptureStateBlock,
4696 IDirect3DDeviceImpl_7_DeleteStateBlock,
4697 IDirect3DDeviceImpl_7_CreateStateBlock,
4698 IDirect3DDeviceImpl_7_Load,
4699 IDirect3DDeviceImpl_7_LightEnable,
4700 IDirect3DDeviceImpl_7_GetLightEnable,
4701 IDirect3DDeviceImpl_7_SetClipPlane,
4702 IDirect3DDeviceImpl_7_GetClipPlane,
4703 IDirect3DDeviceImpl_7_GetInfo
4706 const IDirect3DDevice3Vtbl IDirect3DDevice3_Vtbl =
4708 /*** IUnknown Methods ***/
4709 Thunk_IDirect3DDeviceImpl_3_QueryInterface,
4710 Thunk_IDirect3DDeviceImpl_3_AddRef,
4711 Thunk_IDirect3DDeviceImpl_3_Release,
4712 /*** IDirect3DDevice3 ***/
4713 IDirect3DDeviceImpl_3_GetCaps,
4714 IDirect3DDeviceImpl_3_GetStats,
4715 IDirect3DDeviceImpl_3_AddViewport,
4716 IDirect3DDeviceImpl_3_DeleteViewport,
4717 IDirect3DDeviceImpl_3_NextViewport,
4718 Thunk_IDirect3DDeviceImpl_3_EnumTextureFormats,
4719 Thunk_IDirect3DDeviceImpl_3_BeginScene,
4720 Thunk_IDirect3DDeviceImpl_3_EndScene,
4721 Thunk_IDirect3DDeviceImpl_3_GetDirect3D,
4722 IDirect3DDeviceImpl_3_SetCurrentViewport,
4723 IDirect3DDeviceImpl_3_GetCurrentViewport,
4724 Thunk_IDirect3DDeviceImpl_3_SetRenderTarget,
4725 Thunk_IDirect3DDeviceImpl_3_GetRenderTarget,
4726 IDirect3DDeviceImpl_3_Begin,
4727 IDirect3DDeviceImpl_3_BeginIndexed,
4728 IDirect3DDeviceImpl_3_Vertex,
4729 IDirect3DDeviceImpl_3_Index,
4730 IDirect3DDeviceImpl_3_End,
4731 Thunk_IDirect3DDeviceImpl_3_GetRenderState,
4732 Thunk_IDirect3DDeviceImpl_3_SetRenderState,
4733 IDirect3DDeviceImpl_3_GetLightState,
4734 IDirect3DDeviceImpl_3_SetLightState,
4735 Thunk_IDirect3DDeviceImpl_3_SetTransform,
4736 Thunk_IDirect3DDeviceImpl_3_GetTransform,
4737 Thunk_IDirect3DDeviceImpl_3_MultiplyTransform,
4738 Thunk_IDirect3DDeviceImpl_3_DrawPrimitive,
4739 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitive,
4740 Thunk_IDirect3DDeviceImpl_3_SetClipStatus,
4741 Thunk_IDirect3DDeviceImpl_3_GetClipStatus,
4742 Thunk_IDirect3DDeviceImpl_3_DrawPrimitiveStrided,
4743 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitiveStrided,
4744 Thunk_IDirect3DDeviceImpl_3_DrawPrimitiveVB,
4745 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitiveVB,
4746 Thunk_IDirect3DDeviceImpl_3_ComputeSphereVisibility,
4747 Thunk_IDirect3DDeviceImpl_3_GetTexture,
4748 Thunk_IDirect3DDeviceImpl_3_SetTexture,
4749 Thunk_IDirect3DDeviceImpl_3_GetTextureStageState,
4750 Thunk_IDirect3DDeviceImpl_3_SetTextureStageState,
4751 Thunk_IDirect3DDeviceImpl_3_ValidateDevice
4754 const IDirect3DDevice2Vtbl IDirect3DDevice2_Vtbl =
4756 /*** IUnknown Methods ***/
4757 Thunk_IDirect3DDeviceImpl_2_QueryInterface,
4758 Thunk_IDirect3DDeviceImpl_2_AddRef,
4759 Thunk_IDirect3DDeviceImpl_2_Release,
4760 /*** IDirect3DDevice2 ***/
4761 Thunk_IDirect3DDeviceImpl_2_GetCaps,
4762 IDirect3DDeviceImpl_2_SwapTextureHandles,
4763 Thunk_IDirect3DDeviceImpl_2_GetStats,
4764 Thunk_IDirect3DDeviceImpl_2_AddViewport,
4765 Thunk_IDirect3DDeviceImpl_2_DeleteViewport,
4766 Thunk_IDirect3DDeviceImpl_2_NextViewport,
4767 IDirect3DDeviceImpl_2_EnumTextureFormats,
4768 Thunk_IDirect3DDeviceImpl_2_BeginScene,
4769 Thunk_IDirect3DDeviceImpl_2_EndScene,
4770 Thunk_IDirect3DDeviceImpl_2_GetDirect3D,
4771 Thunk_IDirect3DDeviceImpl_2_SetCurrentViewport,
4772 Thunk_IDirect3DDeviceImpl_2_GetCurrentViewport,
4773 Thunk_IDirect3DDeviceImpl_2_SetRenderTarget,
4774 Thunk_IDirect3DDeviceImpl_2_GetRenderTarget,
4775 Thunk_IDirect3DDeviceImpl_2_Begin,
4776 Thunk_IDirect3DDeviceImpl_2_BeginIndexed,
4777 Thunk_IDirect3DDeviceImpl_2_Vertex,
4778 Thunk_IDirect3DDeviceImpl_2_Index,
4779 Thunk_IDirect3DDeviceImpl_2_End,
4780 Thunk_IDirect3DDeviceImpl_2_GetRenderState,
4781 Thunk_IDirect3DDeviceImpl_2_SetRenderState,
4782 Thunk_IDirect3DDeviceImpl_2_GetLightState,
4783 Thunk_IDirect3DDeviceImpl_2_SetLightState,
4784 Thunk_IDirect3DDeviceImpl_2_SetTransform,
4785 Thunk_IDirect3DDeviceImpl_2_GetTransform,
4786 Thunk_IDirect3DDeviceImpl_2_MultiplyTransform,
4787 Thunk_IDirect3DDeviceImpl_2_DrawPrimitive,
4788 Thunk_IDirect3DDeviceImpl_2_DrawIndexedPrimitive,
4789 Thunk_IDirect3DDeviceImpl_2_SetClipStatus,
4790 Thunk_IDirect3DDeviceImpl_2_GetClipStatus
4793 const IDirect3DDeviceVtbl IDirect3DDevice1_Vtbl =
4795 /*** IUnknown Methods ***/
4796 Thunk_IDirect3DDeviceImpl_1_QueryInterface,
4797 Thunk_IDirect3DDeviceImpl_1_AddRef,
4798 Thunk_IDirect3DDeviceImpl_1_Release,
4799 /*** IDirect3DDevice1 ***/
4800 IDirect3DDeviceImpl_1_Initialize,
4801 Thunk_IDirect3DDeviceImpl_1_GetCaps,
4802 Thunk_IDirect3DDeviceImpl_1_SwapTextureHandles,
4803 IDirect3DDeviceImpl_1_CreateExecuteBuffer,
4804 Thunk_IDirect3DDeviceImpl_1_GetStats,
4805 IDirect3DDeviceImpl_1_Execute,
4806 Thunk_IDirect3DDeviceImpl_1_AddViewport,
4807 Thunk_IDirect3DDeviceImpl_1_DeleteViewport,
4808 Thunk_IDirect3DDeviceImpl_1_NextViewport,
4809 IDirect3DDeviceImpl_1_Pick,
4810 IDirect3DDeviceImpl_1_GetPickRecords,
4811 Thunk_IDirect3DDeviceImpl_1_EnumTextureFormats,
4812 IDirect3DDeviceImpl_1_CreateMatrix,
4813 IDirect3DDeviceImpl_1_SetMatrix,
4814 IDirect3DDeviceImpl_1_GetMatrix,
4815 IDirect3DDeviceImpl_1_DeleteMatrix,
4816 Thunk_IDirect3DDeviceImpl_1_EndScene,
4817 Thunk_IDirect3DDeviceImpl_1_BeginScene,
4818 Thunk_IDirect3DDeviceImpl_1_GetDirect3D
4821 /*****************************************************************************
4822 * IDirect3DDeviceImpl_CreateHandle
4824 * Not called from the VTable
4826 * Some older interface versions operate with handles, which are basically
4827 * DWORDs which identify an interface, for example
4828 * IDirect3DDevice::SetRenderState with DIRECT3DRENDERSTATE_TEXTUREHANDLE
4830 * Those handle could be just casts to the interface pointers or vice versa,
4831 * but that is not 64 bit safe and would mean blindly derefering a DWORD
4832 * passed by the app. Instead there is a dynamic array in the device which
4833 * keeps a DWORD to pointer information and a type for the handle.
4835 * Basically this array only grows, when a handle is freed its pointer is
4836 * just set to NULL. There will be much more reads from the array than
4837 * insertion operations, so a dynamic array is fine.
4840 * This: D3DDevice implementation for which this handle should be created
4843 * A free handle on success
4846 *****************************************************************************/
4848 IDirect3DDeviceImpl_CreateHandle(IDirect3DDeviceImpl *This)
4851 struct HandleEntry *oldHandles = This->Handles;
4853 TRACE("(%p)\n", This);
4855 for(i = 0; i < This->numHandles; i++)
4857 if(This->Handles[i].ptr == NULL &&
4858 This->Handles[i].type == DDrawHandle_Unknown)
4860 TRACE("Reusing freed handle %d\n", i + 1);
4865 TRACE("Growing the handle array\n");
4868 This->Handles = HeapAlloc(GetProcessHeap(), 0, sizeof(struct HandleEntry) * This->numHandles);
4871 ERR("Out of memory\n");
4872 This->Handles = oldHandles;
4878 memcpy(This->Handles, oldHandles, (This->numHandles - 1) * sizeof(struct HandleEntry));
4879 HeapFree(GetProcessHeap(), 0, oldHandles);
4882 TRACE("Returning %d\n", This->numHandles);
4883 return This->numHandles;