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", 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 %lu.\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 %lu.\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 %ld not unset properly\n", i + 1);
338 case DDrawHandle_Material:
340 IDirect3DMaterialImpl *mat = (IDirect3DMaterialImpl *) This->Handles[i].ptr;
341 FIXME("Material handle %ld 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 %ld, deleting\n", i + 1);
350 IDirect3DDevice_DeleteMatrix(ICOM_INTERFACE(This, IDirect3DDevice),
356 FIXME("Unknown handle %ld 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,%08lx)\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,%08lx)\n", This, vp, lplpDirect3DViewport3, Flags);
906 return DDERR_INVALIDPARAMS;
907 *lplpDirect3DViewport3 = NULL;
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,%08lx) 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,%08lx) 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,%08lx,%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 %ld\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)->(%08lx,%p)\n", This, (DWORD) D3DMatHandle, D3DMatrix);
1296 if( (!D3DMatHandle) || (!D3DMatrix) )
1297 return DDERR_INVALIDPARAMS;
1299 if(D3DMatHandle > This->numHandles)
1301 ERR("Handle %ld out of range\n", D3DMatHandle);
1302 return DDERR_INVALIDPARAMS;
1304 else if(This->Handles[D3DMatHandle - 1].type != DDrawHandle_Matrix)
1306 ERR("Handle %ld 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)->(%08lx,%p)\n", This, (DWORD) D3DMatHandle, D3DMatrix);
1343 return DDERR_INVALIDPARAMS;
1345 return DDERR_INVALIDPARAMS;
1347 if(D3DMatHandle > This->numHandles)
1349 ERR("Handle %ld out of range\n", D3DMatHandle);
1350 return DDERR_INVALIDPARAMS;
1352 else if(This->Handles[D3DMatHandle - 1].type != DDrawHandle_Matrix)
1354 ERR("Handle %ld 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)->(%08lx)\n", This, (DWORD) D3DMatHandle);
1387 return DDERR_INVALIDPARAMS;
1389 if(D3DMatHandle > This->numHandles)
1391 ERR("Handle %ld out of range\n", D3DMatHandle);
1392 return DDERR_INVALIDPARAMS;
1394 else if(This->Handles[D3DMatHandle - 1].type != DDrawHandle_Matrix)
1396 ERR("Handle %ld 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,%08lx): 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,%08lx) 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,%08lx) 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,%ld,%08lx)\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,%08lx): 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,%08lx,%p,%08lx,%08lx): 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,%08lx,%08lx): 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)->(%08lx)\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)->(%08lx) 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 return IWineD3DDevice_GetRenderState(This->wineD3DDevice,
2098 static HRESULT WINAPI
2099 Thunk_IDirect3DDeviceImpl_3_GetRenderState(IDirect3DDevice3 *iface,
2100 D3DRENDERSTATETYPE dwRenderStateType,
2101 DWORD *lpdwRenderState)
2103 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2104 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, dwRenderStateType, lpdwRenderState);
2105 return IDirect3DDevice7_GetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2110 static HRESULT WINAPI
2111 Thunk_IDirect3DDeviceImpl_2_GetRenderState(IDirect3DDevice2 *iface,
2112 D3DRENDERSTATETYPE dwRenderStateType,
2113 DWORD *lpdwRenderState)
2115 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2116 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, dwRenderStateType, lpdwRenderState);
2117 return IDirect3DDevice7_GetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2122 /*****************************************************************************
2123 * IDirect3DDevice7::SetRenderState
2125 * Sets a render state. The possible render states are defined in
2126 * include/d3dtypes.h
2128 * Version 2, 3 and 7
2131 * RenderStateType: State to set
2132 * Value: Value to assign to that state
2135 * D3D_OK on success,
2136 * for details see IWineD3DDevice::SetRenderState
2138 *****************************************************************************/
2139 static HRESULT WINAPI
2140 IDirect3DDeviceImpl_7_SetRenderState(IDirect3DDevice7 *iface,
2141 D3DRENDERSTATETYPE RenderStateType,
2144 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2145 TRACE("(%p)->(%08x,%ld): Relay\n", This, RenderStateType, Value);
2147 /* Some render states need special care */
2148 switch(RenderStateType)
2150 case D3DRENDERSTATE_TEXTUREHANDLE:
2154 return IWineD3DDevice_SetTexture(This->wineD3DDevice,
2159 if(Value > This->numHandles)
2161 FIXME("Specified handle %ld out of range\n", Value);
2162 return DDERR_INVALIDPARAMS;
2164 if(This->Handles[Value - 1].type != DDrawHandle_Texture)
2166 FIXME("Handle %ld isn't a texture handle\n", Value);
2167 return DDERR_INVALIDPARAMS;
2171 IDirectDrawSurfaceImpl *surf = (IDirectDrawSurfaceImpl *) This->Handles[Value - 1].ptr;
2172 return IWineD3DDevice_SetTexture(This->wineD3DDevice,
2174 (IWineD3DBaseTexture *) surf->wineD3DTexture);
2178 case D3DRENDERSTATE_TEXTUREMAG:
2180 WINED3DTEXTUREFILTERTYPE tex_mag = WINED3DTEXF_NONE;
2182 switch ((D3DTEXTUREFILTER) Value)
2184 case D3DFILTER_NEAREST:
2185 tex_mag = WINED3DTEXF_POINT;
2187 case D3DFILTER_LINEAR:
2188 tex_mag = WINED3DTEXF_LINEAR;
2191 ERR("Unhandled texture mag %ld !\n",Value);
2194 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
2195 0, WINED3DSAMP_MAGFILTER,
2199 case D3DRENDERSTATE_TEXTUREMIN:
2201 WINED3DTEXTUREFILTERTYPE tex_min = WINED3DTEXF_NONE;
2203 switch ((D3DTEXTUREFILTER) Value)
2205 case D3DFILTER_NEAREST:
2206 tex_min = WINED3DTEXF_POINT;
2208 case D3DFILTER_LINEAR:
2209 tex_min = WINED3DTEXF_LINEAR;
2212 ERR("Unhandled texture mag %ld !\n",Value);
2215 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
2216 0, WINED3DSAMP_MINFILTER,
2220 case D3DRENDERSTATE_TEXTUREADDRESSU:
2221 case D3DRENDERSTATE_TEXTUREADDRESSV:
2222 case D3DRENDERSTATE_TEXTUREADDRESS:
2224 WINED3DTEXTURESTAGESTATETYPE TexStageStateType;
2226 if (RenderStateType == D3DRENDERSTATE_TEXTUREADDRESS)
2228 TexStageStateType = WINED3DTSS_ADDRESS;
2230 else if (RenderStateType == D3DRENDERSTATE_TEXTUREADDRESSU)
2232 TexStageStateType = WINED3DTSS_ADDRESSU;
2236 TexStageStateType = WINED3DTSS_ADDRESSV;
2239 return IWineD3DDevice_SetTextureStageState(This->wineD3DDevice,
2240 0, TexStageStateType,
2245 return IWineD3DDevice_SetRenderState(This->wineD3DDevice,
2251 static HRESULT WINAPI
2252 Thunk_IDirect3DDeviceImpl_3_SetRenderState(IDirect3DDevice3 *iface,
2253 D3DRENDERSTATETYPE RenderStateType,
2256 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2257 TRACE_(ddraw_thunk)("(%p)->(%08x,%08lx) thunking to IDirect3DDevice7 interface.\n", This, RenderStateType, Value);
2258 return IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2263 static HRESULT WINAPI
2264 Thunk_IDirect3DDeviceImpl_2_SetRenderState(IDirect3DDevice2 *iface,
2265 D3DRENDERSTATETYPE RenderStateType,
2268 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2269 TRACE_(ddraw_thunk)("(%p)->(%08x,%08lx) thunking to IDirect3DDevice7 interface.\n", This, RenderStateType, Value);
2270 return IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2275 /*****************************************************************************
2276 * Direct3DDevice3::SetLightState
2278 * Sets a light state for Direct3DDevice3 and Direct3DDevice2. The
2279 * light states are forwarded to Direct3DDevice7 render states
2284 * LightStateType: The light state to change
2285 * Value: The value to assign to that light state
2289 * DDERR_INVALIDPARAMS if the parameters were incorrect
2290 * Also check IDirect3DDevice7::SetRenderState
2292 *****************************************************************************/
2293 static HRESULT WINAPI
2294 IDirect3DDeviceImpl_3_SetLightState(IDirect3DDevice3 *iface,
2295 D3DLIGHTSTATETYPE LightStateType,
2298 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2300 TRACE("(%p)->(%08x,%08lx)\n", This, LightStateType, Value);
2302 if (!LightStateType && (LightStateType > D3DLIGHTSTATE_COLORVERTEX))
2304 TRACE("Unexpected Light State Type\n");
2305 return DDERR_INVALIDPARAMS;
2308 if (LightStateType == D3DLIGHTSTATE_MATERIAL /* 1 */)
2310 IDirect3DMaterialImpl *mat;
2312 if(Value == 0) mat = NULL;
2313 else if(Value > This->numHandles)
2315 ERR("Material handle out of range(%ld)\n", Value);
2316 return DDERR_INVALIDPARAMS;
2318 else if(This->Handles[Value - 1].type != DDrawHandle_Material)
2320 ERR("Invalid handle %ld\n", Value);
2321 return DDERR_INVALIDPARAMS;
2325 mat = (IDirect3DMaterialImpl *) This->Handles[Value - 1].ptr;
2330 TRACE(" activating material %p.\n", mat);
2335 FIXME(" D3DLIGHTSTATE_MATERIAL called with NULL material !!!\n");
2337 This->material = Value;
2339 else if (LightStateType == D3DLIGHTSTATE_COLORMODEL /* 3 */)
2344 ERR("DDCOLOR_MONO should not happen!\n");
2347 /* We are already in this mode */
2348 TRACE("Setting color model to RGB (no-op).\n");
2351 ERR("Unknown color model!\n");
2352 return DDERR_INVALIDPARAMS;
2357 D3DRENDERSTATETYPE rs;
2358 switch (LightStateType)
2360 case D3DLIGHTSTATE_AMBIENT: /* 2 */
2361 rs = D3DRENDERSTATE_AMBIENT;
2363 case D3DLIGHTSTATE_FOGMODE: /* 4 */
2364 rs = D3DRENDERSTATE_FOGVERTEXMODE;
2366 case D3DLIGHTSTATE_FOGSTART: /* 5 */
2367 rs = D3DRENDERSTATE_FOGSTART;
2369 case D3DLIGHTSTATE_FOGEND: /* 6 */
2370 rs = D3DRENDERSTATE_FOGEND;
2372 case D3DLIGHTSTATE_FOGDENSITY: /* 7 */
2373 rs = D3DRENDERSTATE_FOGDENSITY;
2375 case D3DLIGHTSTATE_COLORVERTEX: /* 8 */
2376 rs = D3DRENDERSTATE_COLORVERTEX;
2379 ERR("Unknown D3DLIGHTSTATETYPE %d.\n", LightStateType);
2380 return DDERR_INVALIDPARAMS;
2383 return IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2391 static HRESULT WINAPI
2392 Thunk_IDirect3DDeviceImpl_2_SetLightState(IDirect3DDevice2 *iface,
2393 D3DLIGHTSTATETYPE LightStateType,
2396 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2397 TRACE_(ddraw_thunk)("(%p)->(%08x,%08lx) thunking to IDirect3DDevice3 interface.\n", This, LightStateType, Value);
2398 return IDirect3DDevice3_SetLightState(ICOM_INTERFACE(This, IDirect3DDevice3),
2403 /*****************************************************************************
2404 * IDirect3DDevice3::GetLightState
2406 * Returns the current setting of a light state. The state is read from
2407 * the Direct3DDevice7 render state.
2412 * LightStateType: The light state to return
2413 * Value: The address to store the light state setting at
2417 * DDDERR_INVALIDPARAMS if the parameters were incorrect
2418 * Also see IDirect3DDevice7::GetRenderState
2420 *****************************************************************************/
2421 static HRESULT WINAPI
2422 IDirect3DDeviceImpl_3_GetLightState(IDirect3DDevice3 *iface,
2423 D3DLIGHTSTATETYPE LightStateType,
2426 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2428 TRACE("(%p)->(%08x,%p)\n", This, LightStateType, Value);
2430 if (!LightStateType && (LightStateType > D3DLIGHTSTATE_COLORVERTEX))
2432 TRACE("Unexpected Light State Type\n");
2433 return DDERR_INVALIDPARAMS;
2437 return DDERR_INVALIDPARAMS;
2439 if (LightStateType == D3DLIGHTSTATE_MATERIAL /* 1 */)
2441 *Value = This->material;
2443 else if (LightStateType == D3DLIGHTSTATE_COLORMODEL /* 3 */)
2445 *Value = D3DCOLOR_RGB;
2449 D3DRENDERSTATETYPE rs;
2450 switch (LightStateType)
2452 case D3DLIGHTSTATE_AMBIENT: /* 2 */
2453 rs = D3DRENDERSTATE_AMBIENT;
2455 case D3DLIGHTSTATE_FOGMODE: /* 4 */
2456 rs = D3DRENDERSTATE_FOGVERTEXMODE;
2458 case D3DLIGHTSTATE_FOGSTART: /* 5 */
2459 rs = D3DRENDERSTATE_FOGSTART;
2461 case D3DLIGHTSTATE_FOGEND: /* 6 */
2462 rs = D3DRENDERSTATE_FOGEND;
2464 case D3DLIGHTSTATE_FOGDENSITY: /* 7 */
2465 rs = D3DRENDERSTATE_FOGDENSITY;
2467 case D3DLIGHTSTATE_COLORVERTEX: /* 8 */
2468 rs = D3DRENDERSTATE_COLORVERTEX;
2471 ERR("Unknown D3DLIGHTSTATETYPE %d.\n", LightStateType);
2472 return DDERR_INVALIDPARAMS;
2475 return IDirect3DDevice7_GetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2483 static HRESULT WINAPI
2484 Thunk_IDirect3DDeviceImpl_2_GetLightState(IDirect3DDevice2 *iface,
2485 D3DLIGHTSTATETYPE LightStateType,
2488 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2489 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice3 interface.\n", This, LightStateType, Value);
2490 return IDirect3DDevice3_GetLightState(ICOM_INTERFACE(This, IDirect3DDevice3),
2495 /*****************************************************************************
2496 * IDirect3DDevice7::SetTransform
2498 * Assigns a D3DMATRIX to a transform type. The transform types are defined
2499 * in include/d3dtypes.h.
2500 * The D3DTRANSFORMSTATE_WORLD (=1) is translated to D3DTS_WORLDMATRIX(0)
2501 * (=255) for wined3d, because the 1 transform state was removed in d3d8
2502 * and WineD3D already understands the replacement D3DTS_WORLDMATRIX(0)
2504 * Version 2, 3 and 7
2507 * TransformStateType: transform state to set
2508 * Matrix: Matrix to assign to the state
2512 * DDERR_INVALIDPARAMS if Matrix == NULL
2513 * For details see IWineD3DDevice::SetTransform
2515 *****************************************************************************/
2516 static HRESULT WINAPI
2517 IDirect3DDeviceImpl_7_SetTransform(IDirect3DDevice7 *iface,
2518 D3DTRANSFORMSTATETYPE TransformStateType,
2521 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2522 D3DTRANSFORMSTATETYPE type = TransformStateType;
2523 TRACE("(%p)->(%08x,%p): Relay\n", This, TransformStateType, Matrix);
2526 return DDERR_INVALIDPARAMS;
2528 /* D3DTRANSFORMSTATE_WORLD doesn't exist in WineD3D,
2529 * use D3DTS_WORLDMATRIX(0) instead
2530 * D3DTS_WORLDMATRIX(index) is (D3DTRANSFORMSTATETYPE)(index + 256)
2532 if(TransformStateType == D3DTRANSFORMSTATE_WORLD)
2533 type = (D3DTRANSFORMSTATETYPE)(0 + 256);
2535 return IWineD3DDevice_SetTransform(This->wineD3DDevice,
2540 static HRESULT WINAPI
2541 Thunk_IDirect3DDeviceImpl_3_SetTransform(IDirect3DDevice3 *iface,
2542 D3DTRANSFORMSTATETYPE TransformStateType,
2543 D3DMATRIX *D3DMatrix)
2545 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2546 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2547 return IDirect3DDevice7_SetTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2552 static HRESULT WINAPI
2553 Thunk_IDirect3DDeviceImpl_2_SetTransform(IDirect3DDevice2 *iface,
2554 D3DTRANSFORMSTATETYPE TransformStateType,
2555 D3DMATRIX *D3DMatrix)
2557 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2558 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2559 return IDirect3DDevice7_SetTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2564 /*****************************************************************************
2565 * IDirect3DDevice7::GetTransform
2567 * Returns the matrix assigned to a transform state
2568 * D3DTRANSFORMSTATE_WORLD is translated to D3DTS_WORLDMATRIX(0), see
2572 * TransformStateType: State to read the matrix from
2573 * Matrix: Address to store the matrix at
2577 * DDERR_INVALIDPARAMS if Matrix == NULL
2578 * For details, see IWineD3DDevice::GetTransform
2580 *****************************************************************************/
2581 static HRESULT WINAPI
2582 IDirect3DDeviceImpl_7_GetTransform(IDirect3DDevice7 *iface,
2583 D3DTRANSFORMSTATETYPE TransformStateType,
2586 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2587 D3DTRANSFORMSTATETYPE type = TransformStateType;
2588 TRACE("(%p)->(%08x,%p): Relay\n", This, TransformStateType, Matrix);
2591 return DDERR_INVALIDPARAMS;
2593 /* D3DTRANSFORMSTATE_WORLD doesn't exist in WineD3D,
2594 * use D3DTS_WORLDMATRIX(0) instead
2595 * D3DTS_WORLDMATRIX(index) is (D3DTRANSFORMSTATETYPE)(index + 256)
2597 if(TransformStateType == D3DTRANSFORMSTATE_WORLD)
2598 type = (D3DTRANSFORMSTATETYPE)(0 + 256);
2600 return IWineD3DDevice_GetTransform(This->wineD3DDevice, type, Matrix);
2603 static HRESULT WINAPI
2604 Thunk_IDirect3DDeviceImpl_3_GetTransform(IDirect3DDevice3 *iface,
2605 D3DTRANSFORMSTATETYPE TransformStateType,
2606 D3DMATRIX *D3DMatrix)
2608 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2609 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2610 return IDirect3DDevice7_GetTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2615 static HRESULT WINAPI
2616 Thunk_IDirect3DDeviceImpl_2_GetTransform(IDirect3DDevice2 *iface,
2617 D3DTRANSFORMSTATETYPE TransformStateType,
2618 D3DMATRIX *D3DMatrix)
2620 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2621 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2622 return IDirect3DDevice7_GetTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2627 /*****************************************************************************
2628 * IDirect3DDevice7::MultiplyTransform
2630 * Multiplies the already-set transform matrix of a transform state
2631 * with another matrix. For the world matrix, see SetTransform
2633 * Version 2, 3 and 7
2636 * TransformStateType: Transform state to multiply
2637 * D3DMatrix Matrix to multiply with.
2641 * DDERR_INVALIDPARAMS if D3DMatrix is NULL
2642 * For details, see IWineD3DDevice::MultiplyTransform
2644 *****************************************************************************/
2645 static HRESULT WINAPI
2646 IDirect3DDeviceImpl_7_MultiplyTransform(IDirect3DDevice7 *iface,
2647 D3DTRANSFORMSTATETYPE TransformStateType,
2648 D3DMATRIX *D3DMatrix)
2650 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2651 TRACE("(%p)->(%08x,%p): Relay\n", This, TransformStateType, D3DMatrix);
2653 /* D3DTRANSFORMSTATE_WORLD doesn't exist in WineD3D,
2654 * use D3DTS_WORLDMATRIX(0) instead
2655 * D3DTS_WORLDMATRIX(index) is (D3DTRANSFORMSTATETYPE)(index + 256)
2657 if(TransformStateType == D3DTRANSFORMSTATE_WORLD)
2658 TransformStateType = (D3DTRANSFORMSTATETYPE)(0 + 256);
2660 return IWineD3DDevice_MultiplyTransform(This->wineD3DDevice,
2665 static HRESULT WINAPI
2666 Thunk_IDirect3DDeviceImpl_3_MultiplyTransform(IDirect3DDevice3 *iface,
2667 D3DTRANSFORMSTATETYPE TransformStateType,
2668 D3DMATRIX *D3DMatrix)
2670 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2671 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2672 return IDirect3DDevice7_MultiplyTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2677 static HRESULT WINAPI
2678 Thunk_IDirect3DDeviceImpl_2_MultiplyTransform(IDirect3DDevice2 *iface,
2679 D3DTRANSFORMSTATETYPE TransformStateType,
2680 D3DMATRIX *D3DMatrix)
2682 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2683 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2684 return IDirect3DDevice7_MultiplyTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2689 /*****************************************************************************
2690 * IDirect3DDevice7::DrawPrimitive
2692 * Draws primitives based on vertices in an application-provided pointer
2694 * Version 2, 3 and 7. The IDirect3DDevice2 thunk converts the fixed vertex type into
2695 * an FVF format for D3D7
2698 * PrimitiveType: The type of the primitives to draw
2699 * Vertex type: Flexible vertex format vertex description
2700 * Vertices: Pointer to the vertex array
2701 * VertexCount: The number of vertices to draw
2702 * Flags: As usual a few flags
2706 * DDERR_INVALIDPARAMS if Vertices is NULL
2707 * For details, see IWineD3DDevice::DrawPrimitiveUP
2709 *****************************************************************************/
2710 static HRESULT WINAPI
2711 IDirect3DDeviceImpl_7_DrawPrimitive(IDirect3DDevice7 *iface,
2712 D3DPRIMITIVETYPE PrimitiveType,
2718 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2719 UINT PrimitiveCount, stride;
2721 TRACE("(%p)->(%08x,%08lx,%p,%08lx,%08lx): Relay!\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Flags);
2724 return DDERR_INVALIDPARAMS;
2726 /* Get the vertex count */
2727 switch(PrimitiveType)
2729 case D3DPT_POINTLIST:
2730 PrimitiveCount = VertexCount;
2733 case D3DPT_LINELIST:
2734 PrimitiveCount = VertexCount / 2;
2737 case D3DPT_LINESTRIP:
2738 PrimitiveCount = VertexCount - 1;
2741 case D3DPT_TRIANGLELIST:
2742 PrimitiveCount = VertexCount / 3;
2745 case D3DPT_TRIANGLESTRIP:
2746 PrimitiveCount = VertexCount - 2;
2749 case D3DPT_TRIANGLEFAN:
2750 PrimitiveCount = VertexCount - 2;
2753 default: return DDERR_INVALIDPARAMS;
2756 /* Get the stride */
2757 stride = get_flexible_vertex_size(VertexType);
2760 hr = IWineD3DDevice_SetFVF(This->wineD3DDevice, VertexType);
2761 if(hr != D3D_OK) return hr;
2763 /* This method translates to the user pointer draw of WineD3D */
2764 return IWineD3DDevice_DrawPrimitiveUP(This->wineD3DDevice,
2771 static HRESULT WINAPI
2772 Thunk_IDirect3DDeviceImpl_3_DrawPrimitive(IDirect3DDevice3 *iface,
2773 D3DPRIMITIVETYPE PrimitiveType,
2779 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2780 TRACE_(ddraw_thunk)("(%p)->(%08x,%08lx,%p,%08lx,%08lx) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Flags);
2781 return IDirect3DDevice7_DrawPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
2789 static HRESULT WINAPI
2790 Thunk_IDirect3DDeviceImpl_2_DrawPrimitive(IDirect3DDevice2 *iface,
2791 D3DPRIMITIVETYPE PrimitiveType,
2792 D3DVERTEXTYPE VertexType,
2797 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2799 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08lx,%08lx) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Flags);
2803 case D3DVT_VERTEX: FVF = D3DFVF_VERTEX; break;
2804 case D3DVT_LVERTEX: FVF = D3DFVF_LVERTEX; break;
2805 case D3DVT_TLVERTEX: FVF = D3DFVF_TLVERTEX; break;
2807 ERR("Unexpected vertex type %d\n", VertexType);
2808 return DDERR_INVALIDPARAMS; /* Should never happen */
2811 return IDirect3DDevice7_DrawPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
2819 /*****************************************************************************
2820 * IDirect3DDevice7::DrawIndexedPrimitive
2822 * Draws vertices from an application-provided pointer, based on the index
2823 * numbers in a WORD array.
2825 * Version 2, 3 and 7. The version 7 thunk translates the vertex type into
2826 * an FVF format for D3D7
2829 * PrimitiveType: The primitive type to draw
2830 * VertexType: The FVF vertex description
2831 * Vertices: Pointer to the vertex array
2833 * Indices: Pointer to the index array
2834 * IndexCount: Number of indices = Number of vertices to draw
2835 * Flags: As usual, some flags
2839 * DDERR_INVALIDPARAMS if Vertices or Indices is NULL
2840 * For details, see IWineD3DDevice::DrawIndexedPrimitiveUP
2842 *****************************************************************************/
2843 static HRESULT WINAPI
2844 IDirect3DDeviceImpl_7_DrawIndexedPrimitive(IDirect3DDevice7 *iface,
2845 D3DPRIMITIVETYPE PrimitiveType,
2853 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2854 UINT PrimitiveCount = 0;
2856 TRACE("(%p)->(%08x,%08lx,%p,%08lx,%p,%08lx,%08lx): Relay!\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Indices, IndexCount, Flags);
2857 /* Get the primitive number */
2858 switch(PrimitiveType)
2860 case D3DPT_POINTLIST:
2861 PrimitiveCount = IndexCount;
2864 case D3DPT_LINELIST:
2865 PrimitiveCount = IndexCount / 2;
2868 case D3DPT_LINESTRIP:
2869 PrimitiveCount = IndexCount - 1;
2872 case D3DPT_TRIANGLELIST:
2873 PrimitiveCount = IndexCount / 3;
2876 case D3DPT_TRIANGLESTRIP:
2877 PrimitiveCount = IndexCount - 2;
2880 case D3DPT_TRIANGLEFAN:
2881 PrimitiveCount = IndexCount - 2;
2884 default: return DDERR_INVALIDPARAMS;
2887 /* Set the D3DDevice's FVF */
2888 hr = IWineD3DDevice_SetFVF(This->wineD3DDevice, VertexType);
2891 ERR(" (%p) Setting the FVF failed, hr = %lx!\n", This, hr);
2895 return IWineD3DDevice_DrawIndexedPrimitiveUP(This->wineD3DDevice,
2897 0 /* MinVertexIndex */,
2898 VertexCount /* UINT NumVertexIndex */,
2903 get_flexible_vertex_size(VertexType));
2906 static HRESULT WINAPI
2907 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitive(IDirect3DDevice3 *iface,
2908 D3DPRIMITIVETYPE PrimitiveType,
2916 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2917 TRACE_(ddraw_thunk)("(%p)->(%08x,%08lx,%p,%08lx,%p,%08lx,%08lx) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Indices, IndexCount, Flags);
2918 return IDirect3DDevice7_DrawIndexedPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
2928 static HRESULT WINAPI
2929 Thunk_IDirect3DDeviceImpl_2_DrawIndexedPrimitive(IDirect3DDevice2 *iface,
2930 D3DPRIMITIVETYPE PrimitiveType,
2931 D3DVERTEXTYPE VertexType,
2939 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2940 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08lx,%p,%08lx,%08lx) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Indices, IndexCount, Flags);
2944 case D3DVT_VERTEX: FVF = D3DFVF_VERTEX; break;
2945 case D3DVT_LVERTEX: FVF = D3DFVF_LVERTEX; break;
2946 case D3DVT_TLVERTEX: FVF = D3DFVF_TLVERTEX; break;
2948 ERR("Unexpected vertex type %d\n", VertexType);
2949 return DDERR_INVALIDPARAMS; /* Should never happen */
2952 return IDirect3DDevice7_DrawIndexedPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
2962 /*****************************************************************************
2963 * IDirect3DDevice7::SetClipStatus
2965 * Sets the clip status. This defines things as clipping conditions and
2966 * the extents of the clipping region.
2968 * Version 2, 3 and 7
2974 * D3D_OK because it's a stub
2975 * (DDERR_INVALIDPARAMS if ClipStatus == NULL)
2977 *****************************************************************************/
2978 static HRESULT WINAPI
2979 IDirect3DDeviceImpl_7_SetClipStatus(IDirect3DDevice7 *iface,
2980 D3DCLIPSTATUS *ClipStatus)
2982 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2983 FIXME("(%p)->(%p): Stub!\n", This, ClipStatus);
2985 /* D3DCLIPSTATUS and WINED3DCLIPSTATUS are different. I don't know how to convert them
2986 * Perhaps this needs a new data type and an additional IWineD3DDevice method
2988 /* return IWineD3DDevice_SetClipStatus(This->wineD3DDevice, ClipStatus);*/
2992 static HRESULT WINAPI
2993 Thunk_IDirect3DDeviceImpl_3_SetClipStatus(IDirect3DDevice3 *iface,
2994 D3DCLIPSTATUS *ClipStatus)
2996 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2997 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, ClipStatus);
2998 return IDirect3DDevice7_SetClipStatus(ICOM_INTERFACE(This, IDirect3DDevice7),
3002 static HRESULT WINAPI
3003 Thunk_IDirect3DDeviceImpl_2_SetClipStatus(IDirect3DDevice2 *iface,
3004 D3DCLIPSTATUS *ClipStatus)
3006 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
3007 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, ClipStatus);
3008 return IDirect3DDevice7_SetClipStatus(ICOM_INTERFACE(This, IDirect3DDevice7),
3012 /*****************************************************************************
3013 * IDirect3DDevice7::GetClipStatus
3015 * Returns the clip status
3018 * ClipStatus: Address to write the clip status to
3021 * D3D_OK because it's a stub
3023 *****************************************************************************/
3024 static HRESULT WINAPI
3025 IDirect3DDeviceImpl_7_GetClipStatus(IDirect3DDevice7 *iface,
3026 D3DCLIPSTATUS *ClipStatus)
3028 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3029 FIXME("(%p)->(%p): Stub!\n", This, ClipStatus);
3031 /* D3DCLIPSTATUS and WINED3DCLIPSTATUS are different. I don't know how to convert them */
3032 /* return IWineD3DDevice_GetClipStatus(This->wineD3DDevice, ClipStatus);*/
3036 static HRESULT WINAPI
3037 Thunk_IDirect3DDeviceImpl_3_GetClipStatus(IDirect3DDevice3 *iface,
3038 D3DCLIPSTATUS *ClipStatus)
3040 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3041 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, ClipStatus);
3042 return IDirect3DDevice7_GetClipStatus(ICOM_INTERFACE(This, IDirect3DDevice7),
3046 static HRESULT WINAPI
3047 Thunk_IDirect3DDeviceImpl_2_GetClipStatus(IDirect3DDevice2 *iface,
3048 D3DCLIPSTATUS *ClipStatus)
3050 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
3051 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, ClipStatus);
3052 return IDirect3DDevice7_GetClipStatus(ICOM_INTERFACE(This, IDirect3DDevice7),
3056 /*****************************************************************************
3057 * IDirect3DDevice::DrawPrimitiveStrided
3059 * Draws vertices described by a D3DDRAWPRIMITIVESTRIDEDDATA structure.
3064 * PrimitiveType: The primitive type to draw
3065 * VertexType: The FVF description of the vertices to draw (for the stride??)
3066 * D3DDrawPrimStrideData: A D3DDRAWPRIMITIVESTRIDEDDATA structure describing
3067 * the vertex data locations
3068 * VertexCount: The number of vertices to draw
3072 * D3D_OK, because it's a stub
3073 * (DDERR_INVALIDPARAMS if D3DDrawPrimStrideData is NULL)
3074 * (For details, see IWineD3DDevice::DrawPrimitiveStrided)
3076 *****************************************************************************/
3077 static HRESULT WINAPI
3078 IDirect3DDeviceImpl_7_DrawPrimitiveStrided(IDirect3DDevice7 *iface,
3079 D3DPRIMITIVETYPE PrimitiveType,
3081 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3085 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3086 WineDirect3DVertexStridedData WineD3DStrided;
3088 UINT PrimitiveCount;
3090 TRACE("(%p)->(%08x,%08lx,%p,%08lx,%08lx): stub!\n", This, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Flags);
3092 /* Get the strided data right. the wined3d structure is a bit bigger
3093 * Watch out: The contents of the strided data are determined by the fvf,
3094 * not by the members set in D3DDrawPrimStrideData. So it's valid
3095 * to have diffuse.lpvData set to 0xdeadbeef if the diffuse flag is
3096 * not set in the fvf.
3098 if(VertexType & D3DFVF_POSITION_MASK)
3100 memset(&WineD3DStrided, 0, sizeof(WineD3DStrided));
3101 WineD3DStrided.u.s.position.lpData = D3DDrawPrimStrideData->position.lpvData;
3102 WineD3DStrided.u.s.position.dwStride = D3DDrawPrimStrideData->position.dwStride;
3103 WineD3DStrided.u.s.position.dwType = WINED3DDECLTYPE_FLOAT3;
3104 if (VertexType & D3DFVF_XYZRHW)
3106 WineD3DStrided.u.s.position.dwType = WINED3DDECLTYPE_FLOAT4;
3107 WineD3DStrided.u.s.position_transformed = TRUE;
3109 WineD3DStrided.u.s.position_transformed = FALSE;
3112 if(VertexType & D3DFVF_NORMAL)
3114 WineD3DStrided.u.s.normal.lpData = D3DDrawPrimStrideData->normal.lpvData;
3115 WineD3DStrided.u.s.normal.dwStride = D3DDrawPrimStrideData->normal.dwStride;
3116 WineD3DStrided.u.s.normal.dwType = WINED3DDECLTYPE_FLOAT3;
3119 if(VertexType & D3DFVF_DIFFUSE)
3121 WineD3DStrided.u.s.diffuse.lpData = D3DDrawPrimStrideData->diffuse.lpvData;
3122 WineD3DStrided.u.s.diffuse.dwStride = D3DDrawPrimStrideData->diffuse.dwStride;
3123 WineD3DStrided.u.s.diffuse.dwType = WINED3DDECLTYPE_SHORT4;
3126 if(VertexType & D3DFVF_SPECULAR)
3128 WineD3DStrided.u.s.specular.lpData = D3DDrawPrimStrideData->specular.lpvData;
3129 WineD3DStrided.u.s.specular.dwStride = D3DDrawPrimStrideData->specular.dwStride;
3130 WineD3DStrided.u.s.specular.dwType = WINED3DDECLTYPE_SHORT4;
3133 for( i = 0; i < GET_TEXCOUNT_FROM_FVF(VertexType); i++)
3135 WineD3DStrided.u.s.texCoords[i].lpData = D3DDrawPrimStrideData->textureCoords[i].lpvData;
3136 WineD3DStrided.u.s.texCoords[i].dwStride = D3DDrawPrimStrideData->textureCoords[i].dwStride;
3137 switch(GET_TEXCOORD_SIZE_FROM_FVF(VertexType, i))
3139 case 1: WineD3DStrided.u.s.texCoords[i].dwType = WINED3DDECLTYPE_FLOAT1; break;
3140 case 2: WineD3DStrided.u.s.texCoords[i].dwType = WINED3DDECLTYPE_FLOAT2; break;
3141 case 3: WineD3DStrided.u.s.texCoords[i].dwType = WINED3DDECLTYPE_FLOAT3; break;
3142 case 4: WineD3DStrided.u.s.texCoords[i].dwType = WINED3DDECLTYPE_FLOAT4; break;
3143 default: ERR("Unexpected texture coordinate size %ld\n",
3144 GET_TEXCOORD_SIZE_FROM_FVF(VertexType, i));
3148 /* Get the primitive count */
3149 switch(PrimitiveType)
3151 case D3DPT_POINTLIST:
3152 PrimitiveCount = VertexCount;
3155 case D3DPT_LINELIST:
3156 PrimitiveCount = VertexCount / 2;
3159 case D3DPT_LINESTRIP:
3160 PrimitiveCount = VertexCount - 1;
3163 case D3DPT_TRIANGLELIST:
3164 PrimitiveCount = VertexCount / 3;
3167 case D3DPT_TRIANGLESTRIP:
3168 PrimitiveCount = VertexCount - 2;
3171 case D3DPT_TRIANGLEFAN:
3172 PrimitiveCount = VertexCount - 2;
3175 default: return DDERR_INVALIDPARAMS;
3178 IWineD3DDevice_SetFVF(This->wineD3DDevice,
3181 return IWineD3DDevice_DrawPrimitiveStrided(This->wineD3DDevice,
3187 static HRESULT WINAPI
3188 Thunk_IDirect3DDeviceImpl_3_DrawPrimitiveStrided(IDirect3DDevice3 *iface,
3189 D3DPRIMITIVETYPE PrimitiveType,
3191 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3195 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3196 TRACE_(ddraw_thunk)("(%p)->(%08x,%08lx,%p,%08lx,%08lx) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Flags);
3197 return IDirect3DDevice7_DrawPrimitiveStrided(ICOM_INTERFACE(This, IDirect3DDevice7),
3200 D3DDrawPrimStrideData,
3205 /*****************************************************************************
3206 * IDirect3DDevice7::DrawIndexedPrimitiveStrided
3208 * Draws primitives specified by strided data locations based on indices
3216 * D3D_OK, because it's a stub
3217 * (DDERR_INVALIDPARAMS if D3DDrawPrimStrideData is NULL)
3218 * (DDERR_INVALIDPARAMS if Indices is NULL)
3219 * (For more details, see IWineD3DDevice::DrawIndexedPrimitiveStrided)
3221 *****************************************************************************/
3222 static HRESULT WINAPI
3223 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveStrided(IDirect3DDevice7 *iface,
3224 D3DPRIMITIVETYPE PrimitiveType,
3226 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3232 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3233 FIXME("(%p)->(%08x,%08lx,%p,%08lx,%p,%08lx,%08lx): stub!\n", This, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Indices, IndexCount, Flags);
3235 /* I'll implement it as soon as I find a app to test it.
3236 * This needs an additional method in IWineD3DDevice.
3241 static HRESULT WINAPI
3242 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitiveStrided(IDirect3DDevice3 *iface,
3243 D3DPRIMITIVETYPE PrimitiveType,
3245 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3251 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3252 TRACE_(ddraw_thunk)("(%p)->(%08x,%08lx,%p,%08lx,%p,%08lx,%08lx) thunking to IDirect3DDevice7 interface.\n", iface, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Indices, IndexCount, Flags);
3253 return IDirect3DDevice7_DrawIndexedPrimitiveStrided(ICOM_INTERFACE(This, IDirect3DDevice7),
3256 D3DDrawPrimStrideData,
3263 /*****************************************************************************
3264 * IDirect3DDevice7::DrawPrimitiveVB
3266 * Draws primitives from a vertex buffer to the screen.
3271 * PrimitiveType: Type of primitive to be rendered.
3272 * D3DVertexBuf: Source Vertex Buffer
3273 * StartVertex: Index of the first vertex from the buffer to be rendered
3274 * NumVertices: Number of vertices to be rendered
3275 * Flags: Can be D3DDP_WAIT to wait until rendering has finished
3279 * DDERR_INVALIDPARAMS if D3DVertexBuf is NULL
3281 *****************************************************************************/
3282 static HRESULT WINAPI
3283 IDirect3DDeviceImpl_7_DrawPrimitiveVB(IDirect3DDevice7 *iface,
3284 D3DPRIMITIVETYPE PrimitiveType,
3285 IDirect3DVertexBuffer7 *D3DVertexBuf,
3290 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3291 IDirect3DVertexBufferImpl *vb = ICOM_OBJECT(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, D3DVertexBuf);
3292 UINT PrimitiveCount;
3295 WINED3DVERTEXBUFFER_DESC Desc;
3297 TRACE("(%p)->(%08x,%p,%08lx,%08lx,%08lx)\n", This, PrimitiveType, D3DVertexBuf, StartVertex, NumVertices, Flags);
3302 ERR("(%p) No Vertex buffer specified\n", This);
3303 return DDERR_INVALIDPARAMS;
3306 /* Get the primitive count */
3307 switch(PrimitiveType)
3309 case D3DPT_POINTLIST:
3310 PrimitiveCount = NumVertices;
3313 case D3DPT_LINELIST:
3314 PrimitiveCount = NumVertices / 2;
3317 case D3DPT_LINESTRIP:
3318 PrimitiveCount = NumVertices - 1;
3321 case D3DPT_TRIANGLELIST:
3322 PrimitiveCount = NumVertices / 3;
3325 case D3DPT_TRIANGLESTRIP:
3326 PrimitiveCount = NumVertices - 2;
3329 case D3DPT_TRIANGLEFAN:
3330 PrimitiveCount = NumVertices - 2;
3333 default: return DDERR_INVALIDPARAMS;
3336 /* Get the FVF of the vertex buffer, and its stride */
3337 hr = IWineD3DVertexBuffer_GetDesc(vb->wineD3DVertexBuffer,
3341 ERR("(%p) IWineD3DVertexBuffer::GetDesc failed with hr = %08lx\n", This, hr);
3344 stride = get_flexible_vertex_size(Desc.FVF);
3346 hr = IWineD3DDevice_SetFVF(This->wineD3DDevice, Desc.FVF);
3349 ERR(" (%p) Setting the FVF failed, hr = %lx!\n", This, hr);
3353 /* Set the vertex stream source */
3354 hr = IWineD3DDevice_SetStreamSource(This->wineD3DDevice,
3355 0 /* StreamNumber */,
3356 vb->wineD3DVertexBuffer,
3357 0 /* StartVertex - we pass this to DrawPrimitive */,
3361 ERR("(%p) IDirect3DDevice::SetStreamSource failed with hr = %08lx\n", This, hr);
3365 /* Now draw the primitives */
3366 return IWineD3DDevice_DrawPrimitive(This->wineD3DDevice,
3372 static HRESULT WINAPI
3373 Thunk_IDirect3DDeviceImpl_3_DrawPrimitiveVB(IDirect3DDevice3 *iface,
3374 D3DPRIMITIVETYPE PrimitiveType,
3375 IDirect3DVertexBuffer *D3DVertexBuf,
3380 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3381 IDirect3DVertexBufferImpl *vb = ICOM_OBJECT(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, D3DVertexBuf);
3382 TRACE_(ddraw_thunk)("(%p)->(%08x,%p,%08lx,%08lx,%08lx) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, vb, StartVertex, NumVertices, Flags);
3383 return IDirect3DDevice7_DrawPrimitiveVB(ICOM_INTERFACE(This, IDirect3DDevice7),
3385 ICOM_INTERFACE(vb, IDirect3DVertexBuffer7),
3392 /*****************************************************************************
3393 * IDirect3DDevice7::DrawIndexedPrimitiveVB
3395 * Draws primitives from a vertex buffer to the screen
3398 * PrimitiveType: Type of primitive to be rendered.
3399 * D3DVertexBuf: Source Vertex Buffer
3400 * StartVertex: Index of the first vertex from the buffer to be rendered
3401 * NumVertices: Number of vertices to be rendered
3402 * Indices: Array of DWORDs used to index into the Vertices
3403 * IndexCount: Number of indices in Indices
3404 * Flags: Can be D3DDP_WAIT to wait until rendering has finished
3408 *****************************************************************************/
3409 static HRESULT WINAPI
3410 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface,
3411 D3DPRIMITIVETYPE PrimitiveType,
3412 IDirect3DVertexBuffer7 *D3DVertexBuf,
3419 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3420 IDirect3DVertexBufferImpl *vb = ICOM_OBJECT(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, D3DVertexBuf);
3422 UINT PrimitiveCount;
3423 WORD *LockedIndices;
3425 WINED3DVERTEXBUFFER_DESC Desc;
3427 TRACE("(%p)->(%08x,%p,%ld,%ld,%p,%ld,%08lx)\n", This, PrimitiveType, vb, StartVertex, NumVertices, Indices, IndexCount, Flags);
3430 * 1) Calculate some things: Vertex count -> Primitive count, stride, ...
3431 * 2) Upload the Indices to the index buffer
3432 * 3) Set the index source
3433 * 4) Set the Vertex Buffer as the Stream source
3434 * 5) Call IWineD3DDevice::DrawIndexedPrimitive
3437 /* Get the primitive count */
3438 switch(PrimitiveType)
3440 case D3DPT_POINTLIST:
3441 PrimitiveCount = IndexCount;
3444 case D3DPT_LINELIST:
3445 PrimitiveCount = IndexCount / 2;
3448 case D3DPT_LINESTRIP:
3449 PrimitiveCount = IndexCount - 1;
3452 case D3DPT_TRIANGLELIST:
3453 PrimitiveCount = IndexCount / 3;
3456 case D3DPT_TRIANGLESTRIP:
3457 PrimitiveCount = IndexCount - 2;
3460 case D3DPT_TRIANGLEFAN:
3461 PrimitiveCount = IndexCount - 2;
3464 default: return DDERR_INVALIDPARAMS;
3467 /* Get the FVF of the vertex buffer, and its stride */
3468 hr = IWineD3DVertexBuffer_GetDesc(vb->wineD3DVertexBuffer,
3472 ERR("(%p) IWineD3DVertexBuffer::GetDesc failed with hr = %08lx\n", This, hr);
3475 stride = get_flexible_vertex_size(Desc.FVF);
3476 TRACE("Vertex buffer FVF = %08lx, stride=%ld\n", Desc.FVF, stride);
3478 hr = IWineD3DDevice_SetFVF(This->wineD3DDevice, Desc.FVF);
3481 ERR(" (%p) Setting the FVF failed, hr = %lx!\n", This, hr);
3485 /* copy the index stream into the index buffer.
3486 * A new IWineD3DDevice method could be created
3487 * which takes an user pointer containing the indices
3488 * or a SetData-Method for the index buffer, which
3489 * overrides the index buffer data with our pointer.
3491 hr = IWineD3DIndexBuffer_Lock(This->indexbuffer,
3492 0 /* OffSetToLock */,
3493 0 /* SizeToLock - doesn't matter */,
3494 (BYTE **) &LockedIndices,
3496 assert(IndexCount < 0x100000);
3499 ERR("(%p) IWineD3DIndexBuffer::Lock failed with hr = %08lx\n", This, hr);
3502 memcpy(LockedIndices, Indices, IndexCount * sizeof(WORD));
3503 hr = IWineD3DIndexBuffer_Unlock(This->indexbuffer);
3506 ERR("(%p) IWineD3DIndexBuffer::Unlock failed with hr = %08lx\n", This, hr);
3510 /* Set the index stream */
3511 hr = IWineD3DDevice_SetIndices(This->wineD3DDevice,
3515 /* Set the vertex stream source */
3516 hr = IWineD3DDevice_SetStreamSource(This->wineD3DDevice,
3517 0 /* StreamNumber */,
3518 vb->wineD3DVertexBuffer,
3519 0 /* offset, we pass this to DrawIndexedPrimitive */,
3523 ERR("(%p) IDirect3DDevice::SetStreamSource failed with hr = %08lx\n", This, hr);
3528 hr = IWineD3DDevice_DrawIndexedPrimitive(This->wineD3DDevice,
3539 static HRESULT WINAPI
3540 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitiveVB(IDirect3DDevice3 *iface,
3541 D3DPRIMITIVETYPE PrimitiveType,
3542 IDirect3DVertexBuffer *D3DVertexBuf,
3547 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3548 IDirect3DVertexBufferImpl *VB = ICOM_OBJECT(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, D3DVertexBuf);
3549 TRACE_(ddraw_thunk)("(%p)->(%08x,%p,%p,%08lx,%08lx) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VB, Indices, IndexCount, Flags);
3551 return IDirect3DDevice7_DrawIndexedPrimitiveVB(ICOM_INTERFACE(This, IDirect3DDevice7),
3553 ICOM_INTERFACE(VB, IDirect3DVertexBuffer7),
3561 /*****************************************************************************
3562 * IDirect3DDevice7::ComputeSphereVisibility
3564 * Calculates the visibility of spheres in the current viewport. The spheres
3565 * are passed in the Centers and Radii arrays, the results are passed back
3566 * in the ReturnValues array. Return values are either completely visible,
3567 * partially visible or completely invisible.
3568 * The return value consist of a combination of D3DCLIP_* flags, or it's
3569 * 0 if the sphere is completely visible(according to the SDK, not checked)
3571 * Sounds like an overdose of math ;)
3576 * Centers: Array containing the sphere centers
3577 * Radii: Array containing the sphere radii
3578 * NumSpheres: The number of centers and radii in the arrays
3580 * ReturnValues: Array to write the results to
3583 * D3D_OK because it's a stub
3584 * (DDERR_INVALIDPARAMS if Centers, Radii or ReturnValues are NULL)
3585 * (D3DERR_INVALIDMATRIX if the combined world, view and proj matrix
3588 *****************************************************************************/
3589 static HRESULT WINAPI
3590 IDirect3DDeviceImpl_7_ComputeSphereVisibility(IDirect3DDevice7 *iface,
3595 DWORD *ReturnValues)
3597 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3598 FIXME("(%p)->(%p,%p,%08lx,%08lx,%p): stub!\n", This, Centers, Radii, NumSpheres, Flags, ReturnValues);
3600 /* the DirectX 7 sdk says that the visibility is computed by
3601 * back-transforming the viewing frustum to model space
3602 * using the inverse of the combined world, view and projection
3603 * matrix. If the matrix can't be reversed, D3DERR_INVALIDMATRIX
3606 * Basic implementation idea:
3607 * 1) Check if the center is in the viewing frustum
3608 * 2) Cut the sphere with the planes of the viewing
3611 * ->Center inside the frustum, no intersections:
3613 * ->Center outside the frustum, no intersections:
3615 * ->Some intersections: Partially visible
3617 * Implement this call in WineD3D. Either implement the
3618 * matrix and vector stuff in WineD3D, or use some external
3625 static HRESULT WINAPI
3626 Thunk_IDirect3DDeviceImpl_3_ComputeSphereVisibility(IDirect3DDevice3 *iface,
3631 DWORD *ReturnValues)
3633 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3634 TRACE_(ddraw_thunk)("(%p)->(%p,%p,%08lx,%08lx,%p) thunking to IDirect3DDevice7 interface.\n", This, Centers, Radii, NumSpheres, Flags, ReturnValues);
3635 return IDirect3DDevice7_ComputeSphereVisibility(ICOM_INTERFACE(This, IDirect3DDevice7),
3643 /*****************************************************************************
3644 * IDirect3DDevice7::GetTexture
3646 * Returns the texture interface handle assigned to a texture stage.
3647 * The returned texture is AddRefed. This is taken from old ddraw,
3648 * not checked in Windows.
3653 * Stage: Texture stage to read the texture from
3654 * Texture: Address to store the interface pointer at
3658 * DDERR_INVALIDPARAMS if Texture is NULL
3659 * For details, see IWineD3DDevice::GetTexture
3661 *****************************************************************************/
3662 static HRESULT WINAPI
3663 IDirect3DDeviceImpl_7_GetTexture(IDirect3DDevice7 *iface,
3665 IDirectDrawSurface7 **Texture)
3667 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3668 IWineD3DBaseTexture *Surf;
3670 TRACE("(%p)->(%ld,%p): Relay\n", This, Stage, Texture);
3674 TRACE("Texture == NULL, failing with DDERR_INVALIDPARAMS\n");
3675 return DDERR_INVALIDPARAMS;
3678 hr = IWineD3DDevice_GetTexture(This->wineD3DDevice, Stage, (IWineD3DBaseTexture **) &Surf);
3679 if( (hr != D3D_OK) || (!Surf) )
3685 /* GetParent AddRef()s, which is perfectly OK.
3686 * We have passed the IDirectDrawSurface7 interface to WineD3D, so that's OK too.
3688 return IWineD3DBaseTexture_GetParent(Surf,
3689 (IUnknown **) Texture);
3692 static HRESULT WINAPI
3693 Thunk_IDirect3DDeviceImpl_3_GetTexture(IDirect3DDevice3 *iface,
3695 IDirect3DTexture2 **Texture2)
3697 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3699 IDirectDrawSurface7 *ret_val;
3701 TRACE_(ddraw_thunk)("(%p)->(%ld,%p) thunking to IDirect3DDevice7 interface.\n", This, Stage, Texture2);
3702 ret = IDirect3DDevice7_GetTexture(ICOM_INTERFACE(This, IDirect3DDevice7),
3706 *Texture2 = COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7, IDirect3DTexture2, ret_val);
3708 TRACE_(ddraw_thunk)(" returning interface %p.\n", *Texture2);
3713 /*****************************************************************************
3714 * IDirect3DDevice7::SetTexture
3716 * Assigns a texture to a texture stage. Is the texture AddRef-ed?
3721 * Stage: The stage to assign the texture to
3722 * Texture: Interface pointer to the texture surface
3726 * For details, see IWineD3DDevice::SetTexture
3728 *****************************************************************************/
3729 static HRESULT WINAPI
3730 IDirect3DDeviceImpl_7_SetTexture(IDirect3DDevice7 *iface,
3732 IDirectDrawSurface7 *Texture)
3734 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3735 IDirectDrawSurfaceImpl *surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Texture);
3736 TRACE("(%p)->(%08lx,%p): Relay!\n", This, Stage, surf);
3738 /* Texture may be NULL here */
3739 return IWineD3DDevice_SetTexture(This->wineD3DDevice,
3741 surf ? (IWineD3DBaseTexture * ) surf->wineD3DTexture : NULL);
3744 static HRESULT WINAPI
3745 Thunk_IDirect3DDeviceImpl_3_SetTexture(IDirect3DDevice3 *iface,
3747 IDirect3DTexture2 *Texture2)
3749 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3750 IDirectDrawSurfaceImpl *tex = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture2, Texture2);
3751 TRACE_(ddraw_thunk)("(%p)->(%ld,%p) thunking to IDirect3DDevice7 interface.\n", This, Stage, tex);
3752 return IDirect3DDevice7_SetTexture(ICOM_INTERFACE(This, IDirect3DDevice7),
3754 ICOM_INTERFACE(tex, IDirectDrawSurface7));
3757 /*****************************************************************************
3758 * IDirect3DDevice7::GetTextureStageState
3760 * Retrieves a state from a texture stage.
3765 * Stage: The stage to retrieve the state from
3766 * TexStageStateType: The state type to retrieve
3767 * State: Address to store the state's value at
3771 * DDERR_INVALIDPARAMS if State is NULL
3772 * For details, see IWineD3DDevice::GetTextureStageState
3774 *****************************************************************************/
3775 static HRESULT WINAPI
3776 IDirect3DDeviceImpl_7_GetTextureStageState(IDirect3DDevice7 *iface,
3778 D3DTEXTURESTAGESTATETYPE TexStageStateType,
3781 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3782 TRACE("(%p)->(%08lx,%08x,%p): Relay!\n", This, Stage, TexStageStateType, State);
3785 return DDERR_INVALIDPARAMS;
3787 return IWineD3DDevice_GetTextureStageState(This->wineD3DDevice,
3793 static HRESULT WINAPI
3794 Thunk_IDirect3DDeviceImpl_3_GetTextureStageState(IDirect3DDevice3 *iface,
3796 D3DTEXTURESTAGESTATETYPE TexStageStateType,
3799 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3800 TRACE_(ddraw_thunk)("(%p)->(%08lx,%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, Stage, TexStageStateType, State);
3801 return IDirect3DDevice7_GetTextureStageState(ICOM_INTERFACE(This, IDirect3DDevice7),
3807 /*****************************************************************************
3808 * IDirect3DDevice7::SetTextureStageState
3810 * Sets a texture stage state. Some stage types need to be handled specially,
3811 * because they do not exist in WineD3D and were moved to another place
3816 * Stage: The stage to modify
3817 * TexStageStateType: The state to change
3818 * State: The new value for the state
3822 * For details, see IWineD3DDevice::SetTextureStageState
3824 *****************************************************************************/
3825 static HRESULT WINAPI
3826 IDirect3DDeviceImpl_7_SetTextureStageState(IDirect3DDevice7 *iface,
3828 D3DTEXTURESTAGESTATETYPE TexStageStateType,
3831 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3832 TRACE("(%p)->(%08lx,%08x,%08lx): Relay!\n", This, Stage, TexStageStateType, State);
3833 switch(TexStageStateType)
3835 /* Mipfilter is a sampler state with different values */
3836 case D3DTSS_MIPFILTER:
3838 WINED3DTEXTUREFILTERTYPE value;
3841 case D3DTFP_NONE: value = WINED3DTEXF_NONE; break;
3842 case D3DTFP_POINT: value = WINED3DTEXF_POINT; break;
3843 case 0: /* Unchecked */
3844 case D3DTFP_LINEAR: value = WINED3DTEXF_LINEAR; break;
3846 ERR("Unexpected mipfilter value %ld\n", State);
3847 value = WINED3DTEXF_NONE;
3849 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
3851 WINED3DSAMP_MIPFILTER,
3855 /* Minfilter is a sampler state too, equal values */
3856 case D3DTSS_MINFILTER:
3857 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
3859 WINED3DSAMP_MINFILTER,
3861 /* Same for MAGFILTER */
3862 case D3DTSS_MAGFILTER:
3863 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
3865 WINED3DSAMP_MAGFILTER,
3870 return IWineD3DDevice_SetTextureStageState(This->wineD3DDevice,
3877 static HRESULT WINAPI
3878 Thunk_IDirect3DDeviceImpl_3_SetTextureStageState(IDirect3DDevice3 *iface,
3880 D3DTEXTURESTAGESTATETYPE TexStageStateType,
3883 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3884 TRACE_(ddraw_thunk)("(%p)->(%08lx,%08x,%08lx) thunking to IDirect3DDevice7 interface.\n", This, Stage, TexStageStateType, State);
3885 return IDirect3DDevice7_SetTextureStageState(ICOM_INTERFACE(This, IDirect3DDevice7),
3891 /*****************************************************************************
3892 * IDirect3DDevice7::ValidateDevice
3894 * SDK: "Reports the device's ability to render the currently set
3895 * texture-blending operations in a single pass". Whatever that means
3901 * NumPasses: Address to write the number of necessary passes for the
3902 * desired effect to.
3906 * See IWineD3DDevice::ValidateDevice for more details
3908 *****************************************************************************/
3909 static HRESULT WINAPI
3910 IDirect3DDeviceImpl_7_ValidateDevice(IDirect3DDevice7 *iface,
3913 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3914 TRACE("(%p)->(%p): Relay\n", This, NumPasses);
3916 return IWineD3DDevice_ValidateDevice(This->wineD3DDevice, NumPasses);
3919 static HRESULT WINAPI
3920 Thunk_IDirect3DDeviceImpl_3_ValidateDevice(IDirect3DDevice3 *iface,
3923 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3924 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, Passes);
3925 return IDirect3DDevice7_ValidateDevice(ICOM_INTERFACE(This, IDirect3DDevice7),
3929 /*****************************************************************************
3930 * IDirect3DDevice7::Clear
3932 * Fills the render target, the z buffer and the stencil buffer with a
3933 * clear color / value
3938 * Count: Number of rectangles in Rects must be 0 if Rects is NULL
3939 * Rects: Rectangles to clear. If NULL, the whole surface is cleared
3940 * Flags: Some flags, as usual
3941 * Color: Clear color for the render target
3942 * Z: Clear value for the Z buffer
3943 * Stencil: Clear value to store in each stencil buffer entry
3947 * For details, see IWineD3DDevice::Clear
3949 *****************************************************************************/
3950 static HRESULT WINAPI
3951 IDirect3DDeviceImpl_7_Clear(IDirect3DDevice7 *iface,
3959 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3960 TRACE("(%p)->(%08lx,%p,%08lx,%08lx,%f,%08lx): Relay\n", This, Count, Rects, Flags, (DWORD) Color, Z, Stencil);
3962 return IWineD3DDevice_Clear(This->wineD3DDevice, Count, Rects, Flags, Color, Z, Stencil);
3965 /*****************************************************************************
3966 * IDirect3DDevice7::SetViewport
3968 * Sets the current viewport.
3970 * Version 7 only, but IDirect3DViewport uses this call for older
3974 * Data: The new viewport to set
3978 * DDERR_INVALIDPARAMS if Data is NULL
3979 * For more details, see IWineDDDevice::SetViewport
3981 *****************************************************************************/
3982 static HRESULT WINAPI
3983 IDirect3DDeviceImpl_7_SetViewport(IDirect3DDevice7 *iface,
3986 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3987 TRACE("(%p)->(%p) Relay!\n", This, Data);
3990 return DDERR_INVALIDPARAMS;
3992 return IWineD3DDevice_SetViewport(This->wineD3DDevice,
3996 /*****************************************************************************
3997 * IDirect3DDevice::GetViewport
3999 * Returns the current viewport
4004 * Data: D3D7Viewport structure to write the viewport information to
4008 * DDERR_INVALIDPARAMS if Data is NULL
4009 * For more details, see IWineD3DDevice::GetViewport
4011 *****************************************************************************/
4012 static HRESULT WINAPI
4013 IDirect3DDeviceImpl_7_GetViewport(IDirect3DDevice7 *iface,
4016 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4018 TRACE("(%p)->(%p) Relay!\n", This, Data);
4021 return DDERR_INVALIDPARAMS;
4023 hr = IWineD3DDevice_GetViewport(This->wineD3DDevice,
4025 return hr_ddraw_from_wined3d(hr);
4028 /*****************************************************************************
4029 * IDirect3DDevice7::SetMaterial
4036 * Mat: The material to set
4040 * DDERR_INVALIDPARAMS if Mat is NULL.
4041 * For more details, see IWineD3DDevice::SetMaterial
4043 *****************************************************************************/
4044 static HRESULT WINAPI
4045 IDirect3DDeviceImpl_7_SetMaterial(IDirect3DDevice7 *iface,
4048 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4050 TRACE("(%p)->(%p): Relay!\n", This, Mat);
4052 hr = IWineD3DDevice_SetMaterial(This->wineD3DDevice,
4054 return hr_ddraw_from_wined3d(hr);
4057 /*****************************************************************************
4058 * IDirect3DDevice7::GetMaterial
4060 * Returns the current material
4065 * Mat: D3DMATERIAL7 structure to write the material parameters to
4069 * DDERR_INVALIDPARAMS if Mat is NULL
4070 * For more details, see IWineD3DDevice::GetMaterial
4072 *****************************************************************************/
4073 static HRESULT WINAPI
4074 IDirect3DDeviceImpl_7_GetMaterial(IDirect3DDevice7 *iface,
4077 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4079 TRACE("(%p)->(%p): Relay!\n", This, Mat);
4081 hr = IWineD3DDevice_GetMaterial(This->wineD3DDevice,
4083 return hr_ddraw_from_wined3d(hr);
4086 /*****************************************************************************
4087 * IDirect3DDevice7::SetLight
4089 * Assigns a light to a light index, but doesn't activate it yet.
4091 * Version 7, IDirect3DLight uses this method for older versions
4094 * LightIndex: The index of the new light
4095 * Light: A D3DLIGHT7 structure describing the light
4099 * For more details, see IWineD3DDevice::SetLight
4101 *****************************************************************************/
4102 static HRESULT WINAPI
4103 IDirect3DDeviceImpl_7_SetLight(IDirect3DDevice7 *iface,
4107 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4109 TRACE("(%p)->(%08lx,%p): Relay!\n", This, LightIndex, Light);
4111 hr = IWineD3DDevice_SetLight(This->wineD3DDevice,
4114 return hr_ddraw_from_wined3d(hr);
4117 /*****************************************************************************
4118 * IDirect3DDevice7::GetLight
4120 * Returns the light assigned to a light index
4123 * Light: Structure to write the light information to
4127 * DDERR_INVALIDPARAMS if Light is NULL
4128 * For details, see IWineD3DDevice::GetLight
4130 *****************************************************************************/
4131 static HRESULT WINAPI
4132 IDirect3DDeviceImpl_7_GetLight(IDirect3DDevice7 *iface,
4136 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4138 TRACE("(%p)->(%08lx,%p): Relay!\n", This, LightIndex, Light);
4140 rc = IWineD3DDevice_GetLight(This->wineD3DDevice,
4144 /* Translate the result. WineD3D returns other values than D3D7 */
4145 return hr_ddraw_from_wined3d(rc);
4148 /*****************************************************************************
4149 * IDirect3DDevice7::BeginStateBlock
4151 * Begins recording to a stateblock
4157 * For details see IWineD3DDevice::BeginStateBlock
4159 *****************************************************************************/
4160 static HRESULT WINAPI
4161 IDirect3DDeviceImpl_7_BeginStateBlock(IDirect3DDevice7 *iface)
4163 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4165 TRACE("(%p)->(): Relay!\n", This);
4167 hr = IWineD3DDevice_BeginStateBlock(This->wineD3DDevice);
4168 return hr_ddraw_from_wined3d(hr);
4171 /*****************************************************************************
4172 * IDirect3DDevice7::EndStateBlock
4174 * Stops recording to a state block and returns the created stateblock
4175 * handle. The d3d7 stateblock handles are the interface pointers of the
4176 * IWineD3DStateBlock interface
4181 * BlockHandle: Address to store the stateblock's handle to
4185 * DDERR_INVALIDPARAMS if BlockHandle is NULL
4186 * See IWineD3DDevice::EndStateBlock for more details
4188 *****************************************************************************/
4189 static HRESULT WINAPI
4190 IDirect3DDeviceImpl_7_EndStateBlock(IDirect3DDevice7 *iface,
4193 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4195 TRACE("(%p)->(%p): Relay!\n", This, BlockHandle);
4198 return DDERR_INVALIDPARAMS;
4200 hr = IWineD3DDevice_EndStateBlock(This->wineD3DDevice,
4201 (IWineD3DStateBlock **) BlockHandle);
4202 return hr_ddraw_from_wined3d(hr);
4205 /*****************************************************************************
4206 * IDirect3DDevice7::PreLoad
4208 * Allows the app to signal that a texture will be used soon, to allow
4209 * the Direct3DDevice to load it to the video card in the meantime.
4214 * Texture: The texture to preload
4218 * DDERR_INVALIDPARAMS if Texture is NULL
4219 * See IWineD3DSurface::PreLoad for details
4221 *****************************************************************************/
4222 static HRESULT WINAPI
4223 IDirect3DDeviceImpl_7_PreLoad(IDirect3DDevice7 *iface,
4224 IDirectDrawSurface7 *Texture)
4226 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4227 IDirectDrawSurfaceImpl *surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Texture);
4229 TRACE("(%p)->(%p): Relay!\n", This, surf);
4232 return DDERR_INVALIDPARAMS;
4234 IWineD3DSurface_PreLoad(surf->WineD3DSurface);
4238 /*****************************************************************************
4239 * IDirect3DDevice7::ApplyStateBlock
4241 * Activates the state stored in a state block handle.
4244 * BlockHandle: The stateblock handle to activate
4248 * D3DERR_INVALIDSTATEBLOCK if BlockHandle is NULL
4250 *****************************************************************************/
4251 static HRESULT WINAPI
4252 IDirect3DDeviceImpl_7_ApplyStateBlock(IDirect3DDevice7 *iface,
4255 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4257 TRACE("(%p)->(%08lx): Relay!\n", This, BlockHandle);
4260 return D3DERR_INVALIDSTATEBLOCK;
4262 hr = IWineD3DStateBlock_Apply((IWineD3DStateBlock *) BlockHandle);
4263 return hr_ddraw_from_wined3d(hr);
4266 /*****************************************************************************
4267 * IDirect3DDevice7::CaptureStateBlock
4269 * Updates a stateblock's values to the values currently set for the device
4274 * BlockHandle: Stateblock to update
4278 * D3DERR_INVALIDSTATEBLOCK if BlockHandle is NULL
4279 * See IWineD3DDevice::CaptureStateBlock for more details
4281 *****************************************************************************/
4282 static HRESULT WINAPI
4283 IDirect3DDeviceImpl_7_CaptureStateBlock(IDirect3DDevice7 *iface,
4286 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4288 TRACE("(%p)->(%08lx): Relay!\n", This, BlockHandle);
4290 if(BlockHandle == 0)
4291 return D3DERR_INVALIDSTATEBLOCK;
4293 hr = IWineD3DStateBlock_Capture((IWineD3DStateBlock *) BlockHandle);
4294 return hr_ddraw_from_wined3d(hr);
4297 /*****************************************************************************
4298 * IDirect3DDevice7::DeleteStateBlock
4300 * Deletes a stateblock handle. This means releasing the WineD3DStateBlock
4305 * BlockHandle: Stateblock handle to delete
4309 * D3DERR_INVALIDSTATEBLOCK if BlockHandle is 0
4311 *****************************************************************************/
4312 static HRESULT WINAPI
4313 IDirect3DDeviceImpl_7_DeleteStateBlock(IDirect3DDevice7 *iface,
4316 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4317 TRACE("(%p)->(%08lx): Relay!\n", This, BlockHandle);
4319 if(BlockHandle == 0)
4320 return D3DERR_INVALIDSTATEBLOCK;
4322 IWineD3DStateBlock_Release((IWineD3DStateBlock *) BlockHandle);
4327 /*****************************************************************************
4328 * IDirect3DDevice7::CreateStateBlock
4330 * Creates a new state block handle.
4335 * Type: The state block type
4336 * BlockHandle: Address to write the created handle to
4340 * DDERR_INVALIDPARAMS if BlockHandle is NULL
4342 *****************************************************************************/
4343 static HRESULT WINAPI
4344 IDirect3DDeviceImpl_7_CreateStateBlock(IDirect3DDevice7 *iface,
4345 D3DSTATEBLOCKTYPE Type,
4348 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4350 TRACE("(%p)->(%08x,%p)!\n", This, Type, BlockHandle);
4353 return DDERR_INVALIDPARAMS;
4355 /* The D3DSTATEBLOCKTYPE enum is fine here */
4356 hr = IWineD3DDevice_CreateStateBlock(This->wineD3DDevice,
4358 (IWineD3DStateBlock **) BlockHandle,
4359 NULL /* Parent, hope that works */);
4360 return hr_ddraw_from_wined3d(hr);
4363 /*****************************************************************************
4364 * IDirect3DDevice7::Load
4366 * Loads a rectangular area from the source into the destination texture.
4367 * It can also copy the source to the faces of a cubic environment map
4372 * DestTex: Destination texture
4373 * DestPoint: Point in the destination where the source image should be
4375 * SrcTex: Source texture
4376 * SrcRect: Source rectangle
4381 * DDERR_INVALIDPARAMS if DestTex or SrcTex are NULL
4382 * See IDirect3DTexture2::Load for details
4384 *****************************************************************************/
4385 static HRESULT WINAPI
4386 IDirect3DDeviceImpl_7_Load(IDirect3DDevice7 *iface,
4387 IDirectDrawSurface7 *DestTex,
4389 IDirectDrawSurface7 *SrcTex,
4393 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4394 IDirectDrawSurfaceImpl *dest = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DestTex);
4395 IDirectDrawSurfaceImpl *src = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, SrcTex);
4396 FIXME("(%p)->(%p,%p,%p,%p,%08lx): Partially Implemented!\n", This, dest, DestPoint, src, SrcRect, Flags);
4398 if( (!src) || (!dest) )
4399 return DDERR_INVALIDPARAMS;
4401 IDirect3DTexture2_Load(ICOM_INTERFACE(dest, IDirect3DTexture2),
4402 ICOM_INTERFACE(src, IDirect3DTexture2));
4406 /*****************************************************************************
4407 * IDirect3DDevice7::LightEnable
4409 * Enables or disables a light
4411 * Version 7, IDirect3DLight uses this method too.
4414 * LightIndex: The index of the light to enable / disable
4415 * Enable: Enable or disable the light
4419 * For more details, see IWineD3DDevice::SetLightEnable
4421 *****************************************************************************/
4422 static HRESULT WINAPI
4423 IDirect3DDeviceImpl_7_LightEnable(IDirect3DDevice7 *iface,
4427 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4429 TRACE("(%p)->(%08lx,%d): Relay!\n", This, LightIndex, Enable);
4431 hr = IWineD3DDevice_SetLightEnable(This->wineD3DDevice, LightIndex, Enable);
4432 return hr_ddraw_from_wined3d(hr);
4435 /*****************************************************************************
4436 * IDirect3DDevice7::GetLightEnable
4438 * Retrieves if the light with the given index is enabled or not
4443 * LightIndex: Index of desired light
4444 * Enable: Pointer to a BOOL which contains the result
4448 * DDERR_INVALIDPARAMS if Enable is NULL
4449 * See IWineD3DDevice::GetLightEnable for more details
4451 *****************************************************************************/
4452 static HRESULT WINAPI
4453 IDirect3DDeviceImpl_7_GetLightEnable(IDirect3DDevice7 *iface,
4457 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4459 TRACE("(%p)->(%08lx,%p): Relay\n", This, LightIndex, Enable);
4462 return DDERR_INVALIDPARAMS;
4464 hr = IWineD3DDevice_GetLightEnable(This->wineD3DDevice, LightIndex, Enable);
4465 return hr_ddraw_from_wined3d(hr);
4468 /*****************************************************************************
4469 * IDirect3DDevice7::SetClipPlane
4471 * Sets custom clipping plane
4476 * Index: The index of the clipping plane
4477 * PlaneEquation: An equation defining the clipping plane
4481 * DDERR_INVALIDPARAMS if PlaneEquation is NULL
4482 * See IWineD3DDevice::SetClipPlane for more details
4484 *****************************************************************************/
4485 static HRESULT WINAPI
4486 IDirect3DDeviceImpl_7_SetClipPlane(IDirect3DDevice7 *iface,
4488 D3DVALUE* PlaneEquation)
4490 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4491 TRACE("(%p)->(%08lx,%p): Relay!\n", This, Index, PlaneEquation);
4494 return DDERR_INVALIDPARAMS;
4496 return IWineD3DDevice_SetClipPlane(This->wineD3DDevice, Index, PlaneEquation);
4499 /*****************************************************************************
4500 * IDirect3DDevice7::GetClipPlane
4502 * Returns the clipping plane with a specific index
4505 * Index: The index of the desired plane
4506 * PlaneEquation: Address to store the plane equation to
4510 * DDERR_INVALIDPARAMS if PlaneEquation is NULL
4511 * See IWineD3DDevice::GetClipPlane for more details
4513 *****************************************************************************/
4514 static HRESULT WINAPI
4515 IDirect3DDeviceImpl_7_GetClipPlane(IDirect3DDevice7 *iface,
4517 D3DVALUE* PlaneEquation)
4519 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4520 TRACE("(%p)->(%ld,%p): Relay!\n", This, Index, PlaneEquation);
4523 return DDERR_INVALIDPARAMS;
4525 return IWineD3DDevice_GetClipPlane(This->wineD3DDevice, Index, PlaneEquation);
4528 /*****************************************************************************
4529 * IDirect3DDevice7::GetInfo
4531 * Retrieves some information about the device. The DirectX sdk says that
4532 * this version returns S_FALSE for all retail builds of DirectX, that's what
4533 * this implementation does.
4536 * DevInfoID: Information type requested
4537 * DevInfoStruct: Pointer to a structure to store the info to
4538 * Size: Size of the structure
4541 * S_FALSE, because it's a non-debug driver
4543 *****************************************************************************/
4544 static HRESULT WINAPI
4545 IDirect3DDeviceImpl_7_GetInfo(IDirect3DDevice7 *iface,
4547 void *DevInfoStruct,
4550 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4551 TRACE("(%p)->(%08lx,%p,%08lx)\n", This, DevInfoID, DevInfoStruct, Size);
4555 TRACE(" info requested : ");
4558 case D3DDEVINFOID_TEXTUREMANAGER: TRACE("D3DDEVINFOID_TEXTUREMANAGER\n"); break;
4559 case D3DDEVINFOID_D3DTEXTUREMANAGER: TRACE("D3DDEVINFOID_D3DTEXTUREMANAGER\n"); break;
4560 case D3DDEVINFOID_TEXTURING: TRACE("D3DDEVINFOID_TEXTURING\n"); break;
4561 default: ERR(" invalid flag !!!\n"); return DDERR_INVALIDPARAMS;
4565 return S_FALSE; /* According to MSDN, this is valid for a non-debug driver */
4568 const IDirect3DDevice7Vtbl IDirect3DDevice7_Vtbl =
4570 /*** IUnknown Methods ***/
4571 IDirect3DDeviceImpl_7_QueryInterface,
4572 IDirect3DDeviceImpl_7_AddRef,
4573 IDirect3DDeviceImpl_7_Release,
4574 /*** IDirect3DDevice7 ***/
4575 IDirect3DDeviceImpl_7_GetCaps,
4576 IDirect3DDeviceImpl_7_EnumTextureFormats,
4577 IDirect3DDeviceImpl_7_BeginScene,
4578 IDirect3DDeviceImpl_7_EndScene,
4579 IDirect3DDeviceImpl_7_GetDirect3D,
4580 IDirect3DDeviceImpl_7_SetRenderTarget,
4581 IDirect3DDeviceImpl_7_GetRenderTarget,
4582 IDirect3DDeviceImpl_7_Clear,
4583 IDirect3DDeviceImpl_7_SetTransform,
4584 IDirect3DDeviceImpl_7_GetTransform,
4585 IDirect3DDeviceImpl_7_SetViewport,
4586 IDirect3DDeviceImpl_7_MultiplyTransform,
4587 IDirect3DDeviceImpl_7_GetViewport,
4588 IDirect3DDeviceImpl_7_SetMaterial,
4589 IDirect3DDeviceImpl_7_GetMaterial,
4590 IDirect3DDeviceImpl_7_SetLight,
4591 IDirect3DDeviceImpl_7_GetLight,
4592 IDirect3DDeviceImpl_7_SetRenderState,
4593 IDirect3DDeviceImpl_7_GetRenderState,
4594 IDirect3DDeviceImpl_7_BeginStateBlock,
4595 IDirect3DDeviceImpl_7_EndStateBlock,
4596 IDirect3DDeviceImpl_7_PreLoad,
4597 IDirect3DDeviceImpl_7_DrawPrimitive,
4598 IDirect3DDeviceImpl_7_DrawIndexedPrimitive,
4599 IDirect3DDeviceImpl_7_SetClipStatus,
4600 IDirect3DDeviceImpl_7_GetClipStatus,
4601 IDirect3DDeviceImpl_7_DrawPrimitiveStrided,
4602 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveStrided,
4603 IDirect3DDeviceImpl_7_DrawPrimitiveVB,
4604 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB,
4605 IDirect3DDeviceImpl_7_ComputeSphereVisibility,
4606 IDirect3DDeviceImpl_7_GetTexture,
4607 IDirect3DDeviceImpl_7_SetTexture,
4608 IDirect3DDeviceImpl_7_GetTextureStageState,
4609 IDirect3DDeviceImpl_7_SetTextureStageState,
4610 IDirect3DDeviceImpl_7_ValidateDevice,
4611 IDirect3DDeviceImpl_7_ApplyStateBlock,
4612 IDirect3DDeviceImpl_7_CaptureStateBlock,
4613 IDirect3DDeviceImpl_7_DeleteStateBlock,
4614 IDirect3DDeviceImpl_7_CreateStateBlock,
4615 IDirect3DDeviceImpl_7_Load,
4616 IDirect3DDeviceImpl_7_LightEnable,
4617 IDirect3DDeviceImpl_7_GetLightEnable,
4618 IDirect3DDeviceImpl_7_SetClipPlane,
4619 IDirect3DDeviceImpl_7_GetClipPlane,
4620 IDirect3DDeviceImpl_7_GetInfo
4623 const IDirect3DDevice3Vtbl IDirect3DDevice3_Vtbl =
4625 /*** IUnknown Methods ***/
4626 Thunk_IDirect3DDeviceImpl_3_QueryInterface,
4627 Thunk_IDirect3DDeviceImpl_3_AddRef,
4628 Thunk_IDirect3DDeviceImpl_3_Release,
4629 /*** IDirect3DDevice3 ***/
4630 IDirect3DDeviceImpl_3_GetCaps,
4631 IDirect3DDeviceImpl_3_GetStats,
4632 IDirect3DDeviceImpl_3_AddViewport,
4633 IDirect3DDeviceImpl_3_DeleteViewport,
4634 IDirect3DDeviceImpl_3_NextViewport,
4635 Thunk_IDirect3DDeviceImpl_3_EnumTextureFormats,
4636 Thunk_IDirect3DDeviceImpl_3_BeginScene,
4637 Thunk_IDirect3DDeviceImpl_3_EndScene,
4638 Thunk_IDirect3DDeviceImpl_3_GetDirect3D,
4639 IDirect3DDeviceImpl_3_SetCurrentViewport,
4640 IDirect3DDeviceImpl_3_GetCurrentViewport,
4641 Thunk_IDirect3DDeviceImpl_3_SetRenderTarget,
4642 Thunk_IDirect3DDeviceImpl_3_GetRenderTarget,
4643 IDirect3DDeviceImpl_3_Begin,
4644 IDirect3DDeviceImpl_3_BeginIndexed,
4645 IDirect3DDeviceImpl_3_Vertex,
4646 IDirect3DDeviceImpl_3_Index,
4647 IDirect3DDeviceImpl_3_End,
4648 Thunk_IDirect3DDeviceImpl_3_GetRenderState,
4649 Thunk_IDirect3DDeviceImpl_3_SetRenderState,
4650 IDirect3DDeviceImpl_3_GetLightState,
4651 IDirect3DDeviceImpl_3_SetLightState,
4652 Thunk_IDirect3DDeviceImpl_3_SetTransform,
4653 Thunk_IDirect3DDeviceImpl_3_GetTransform,
4654 Thunk_IDirect3DDeviceImpl_3_MultiplyTransform,
4655 Thunk_IDirect3DDeviceImpl_3_DrawPrimitive,
4656 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitive,
4657 Thunk_IDirect3DDeviceImpl_3_SetClipStatus,
4658 Thunk_IDirect3DDeviceImpl_3_GetClipStatus,
4659 Thunk_IDirect3DDeviceImpl_3_DrawPrimitiveStrided,
4660 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitiveStrided,
4661 Thunk_IDirect3DDeviceImpl_3_DrawPrimitiveVB,
4662 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitiveVB,
4663 Thunk_IDirect3DDeviceImpl_3_ComputeSphereVisibility,
4664 Thunk_IDirect3DDeviceImpl_3_GetTexture,
4665 Thunk_IDirect3DDeviceImpl_3_SetTexture,
4666 Thunk_IDirect3DDeviceImpl_3_GetTextureStageState,
4667 Thunk_IDirect3DDeviceImpl_3_SetTextureStageState,
4668 Thunk_IDirect3DDeviceImpl_3_ValidateDevice
4671 const IDirect3DDevice2Vtbl IDirect3DDevice2_Vtbl =
4673 /*** IUnknown Methods ***/
4674 Thunk_IDirect3DDeviceImpl_2_QueryInterface,
4675 Thunk_IDirect3DDeviceImpl_2_AddRef,
4676 Thunk_IDirect3DDeviceImpl_2_Release,
4677 /*** IDirect3DDevice2 ***/
4678 Thunk_IDirect3DDeviceImpl_2_GetCaps,
4679 IDirect3DDeviceImpl_2_SwapTextureHandles,
4680 Thunk_IDirect3DDeviceImpl_2_GetStats,
4681 Thunk_IDirect3DDeviceImpl_2_AddViewport,
4682 Thunk_IDirect3DDeviceImpl_2_DeleteViewport,
4683 Thunk_IDirect3DDeviceImpl_2_NextViewport,
4684 IDirect3DDeviceImpl_2_EnumTextureFormats,
4685 Thunk_IDirect3DDeviceImpl_2_BeginScene,
4686 Thunk_IDirect3DDeviceImpl_2_EndScene,
4687 Thunk_IDirect3DDeviceImpl_2_GetDirect3D,
4688 Thunk_IDirect3DDeviceImpl_2_SetCurrentViewport,
4689 Thunk_IDirect3DDeviceImpl_2_GetCurrentViewport,
4690 Thunk_IDirect3DDeviceImpl_2_SetRenderTarget,
4691 Thunk_IDirect3DDeviceImpl_2_GetRenderTarget,
4692 Thunk_IDirect3DDeviceImpl_2_Begin,
4693 Thunk_IDirect3DDeviceImpl_2_BeginIndexed,
4694 Thunk_IDirect3DDeviceImpl_2_Vertex,
4695 Thunk_IDirect3DDeviceImpl_2_Index,
4696 Thunk_IDirect3DDeviceImpl_2_End,
4697 Thunk_IDirect3DDeviceImpl_2_GetRenderState,
4698 Thunk_IDirect3DDeviceImpl_2_SetRenderState,
4699 Thunk_IDirect3DDeviceImpl_2_GetLightState,
4700 Thunk_IDirect3DDeviceImpl_2_SetLightState,
4701 Thunk_IDirect3DDeviceImpl_2_SetTransform,
4702 Thunk_IDirect3DDeviceImpl_2_GetTransform,
4703 Thunk_IDirect3DDeviceImpl_2_MultiplyTransform,
4704 Thunk_IDirect3DDeviceImpl_2_DrawPrimitive,
4705 Thunk_IDirect3DDeviceImpl_2_DrawIndexedPrimitive,
4706 Thunk_IDirect3DDeviceImpl_2_SetClipStatus,
4707 Thunk_IDirect3DDeviceImpl_2_GetClipStatus
4710 const IDirect3DDeviceVtbl IDirect3DDevice1_Vtbl =
4712 /*** IUnknown Methods ***/
4713 Thunk_IDirect3DDeviceImpl_1_QueryInterface,
4714 Thunk_IDirect3DDeviceImpl_1_AddRef,
4715 Thunk_IDirect3DDeviceImpl_1_Release,
4716 /*** IDirect3DDevice1 ***/
4717 IDirect3DDeviceImpl_1_Initialize,
4718 Thunk_IDirect3DDeviceImpl_1_GetCaps,
4719 Thunk_IDirect3DDeviceImpl_1_SwapTextureHandles,
4720 IDirect3DDeviceImpl_1_CreateExecuteBuffer,
4721 Thunk_IDirect3DDeviceImpl_1_GetStats,
4722 IDirect3DDeviceImpl_1_Execute,
4723 Thunk_IDirect3DDeviceImpl_1_AddViewport,
4724 Thunk_IDirect3DDeviceImpl_1_DeleteViewport,
4725 Thunk_IDirect3DDeviceImpl_1_NextViewport,
4726 IDirect3DDeviceImpl_1_Pick,
4727 IDirect3DDeviceImpl_1_GetPickRecords,
4728 Thunk_IDirect3DDeviceImpl_1_EnumTextureFormats,
4729 IDirect3DDeviceImpl_1_CreateMatrix,
4730 IDirect3DDeviceImpl_1_SetMatrix,
4731 IDirect3DDeviceImpl_1_GetMatrix,
4732 IDirect3DDeviceImpl_1_DeleteMatrix,
4733 Thunk_IDirect3DDeviceImpl_1_EndScene,
4734 Thunk_IDirect3DDeviceImpl_1_BeginScene,
4735 Thunk_IDirect3DDeviceImpl_1_GetDirect3D
4738 /*****************************************************************************
4739 * IDirect3DDeviceImpl_CreateHandle
4741 * Not called from the VTable
4743 * Some older interface versions operate with handles, which are basically
4744 * DWORDs which identify an interface, for example
4745 * IDirect3DDevice::SetRenderState with DIRECT3DRENDERSTATE_TEXTUREHANDLE
4747 * Those handle could be just casts to the interface pointers or vice versa,
4748 * but that is not 64 bit safe and would mean blindly derefering a DWORD
4749 * passed by the app. Instead there is a dynamic array in the device which
4750 * keeps a DWORD to pointer information and a type for the handle.
4752 * Basically this array only grows, when a handle is freed its pointer is
4753 * just set to NULL. There will be much more reads from the array than
4754 * insertion operations, so a dynamic array is fine.
4757 * This: D3DDevice implementation for which this handle should be created
4760 * A free handle on success
4763 *****************************************************************************/
4765 IDirect3DDeviceImpl_CreateHandle(IDirect3DDeviceImpl *This)
4768 struct HandleEntry *oldHandles = This->Handles;
4770 TRACE("(%p)\n", This);
4772 for(i = 0; i < This->numHandles; i++)
4774 if(This->Handles[i].ptr == NULL &&
4775 This->Handles[i].type == DDrawHandle_Unknown)
4777 TRACE("Reusing freed handle %ld\n", i + 1);
4782 TRACE("Growing the handle array\n");
4785 This->Handles = HeapAlloc(GetProcessHeap(), 0, sizeof(struct HandleEntry) * This->numHandles);
4788 ERR("Out of memory\n");
4789 This->Handles = oldHandles;
4795 memcpy(This->Handles, oldHandles, (This->numHandles - 1) * sizeof(struct HandleEntry));
4796 HeapFree(GetProcessHeap(), 0, oldHandles);
4799 TRACE("Returning %ld\n", This->numHandles);
4800 return This->numHandles;