2 * Copyright (c) 1998-2004 Lionel Ulmer
3 * Copyright (c) 2002-2005 Christian Costa
4 * Copyright (c) 2006 Stefan Dösinger
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * IDirect3DDevice implementation, version 1, 2, 3 and 7. Rendering is relayed
21 * to WineD3D, some minimal DirectDraw specific management is handled here.
22 * The Direct3DDevice is NOT the parent of the WineD3DDevice, because d3d
23 * is initialized when DirectDraw creates the primary surface.
24 * Some type management is necessary, because some D3D types changed between
30 #include "wine/port.h"
31 #include "wine/debug.h"
45 #include "wine/exception.h"
51 #include "ddraw_private.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(d3d7);
54 WINE_DECLARE_DEBUG_CHANNEL(ddraw_thunk);
57 const GUID IID_D3DDEVICE_WineD3D = {
61 { 0xb7,0x98,0xc6,0x8a,0x77,0x2d,0x72,0x2a }
64 /*****************************************************************************
65 * IUnknown Methods. Common for Version 1, 2, 3 and 7
66 *****************************************************************************/
68 /*****************************************************************************
69 * IDirect3DDevice7::QueryInterface
71 * Used to query other interfaces from a Direct3DDevice interface.
72 * It can return interface pointers to all Direct3DDevice versions as well
73 * as IDirectDraw and IDirect3D. For a link to QueryInterface
74 * rules see ddraw.c, IDirectDraw7::QueryInterface
76 * Exists in Version 1, 2, 3 and 7
79 * refiid: Interface ID queried for
80 * obj: Used to return the interface pointer
83 * D3D_OK or E_NOINTERFACE
85 *****************************************************************************/
87 IDirect3DDeviceImpl_7_QueryInterface(IDirect3DDevice7 *iface,
91 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
92 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(refiid), obj);
94 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
98 return DDERR_INVALIDPARAMS;
100 if ( IsEqualGUID( &IID_IUnknown, refiid ) )
102 *obj = ICOM_INTERFACE(This, IDirect3DDevice7);
105 /* Check DirectDraw Interfac
\ 1s */
106 else if( IsEqualGUID( &IID_IDirectDraw7, refiid ) )
108 *obj = ICOM_INTERFACE(This->ddraw, IDirectDraw7);
109 TRACE("(%p) Returning IDirectDraw7 interface at %p\n", This, *obj);
111 else if ( IsEqualGUID( &IID_IDirectDraw4, refiid ) )
113 *obj = ICOM_INTERFACE(This->ddraw, IDirectDraw4);
114 TRACE("(%p) Returning IDirectDraw4 interface at %p\n", This, *obj);
116 else if ( IsEqualGUID( &IID_IDirectDraw2, refiid ) )
118 *obj = ICOM_INTERFACE(This->ddraw, IDirectDraw2);
119 TRACE("(%p) Returning IDirectDraw2 interface at %p\n", This, *obj);
121 else if( IsEqualGUID( &IID_IDirectDraw, refiid ) )
123 *obj = ICOM_INTERFACE(This->ddraw, IDirectDraw);
124 TRACE("(%p) Returning IDirectDraw interface at %p\n", This, *obj);
128 else if ( IsEqualGUID( &IID_IDirect3D , refiid ) )
130 *obj = ICOM_INTERFACE(This->ddraw, IDirect3D);
131 TRACE("(%p) Returning IDirect3D interface at %p\n", This, *obj);
133 else if ( IsEqualGUID( &IID_IDirect3D2 , refiid ) )
135 *obj = ICOM_INTERFACE(This->ddraw, IDirect3D2);
136 TRACE("(%p) Returning IDirect3D2 interface at %p\n", This, *obj);
138 else if ( IsEqualGUID( &IID_IDirect3D3 , refiid ) )
140 *obj = ICOM_INTERFACE(This->ddraw, IDirect3D3);
141 TRACE("(%p) Returning IDirect3D3 interface at %p\n", This, *obj);
143 else if ( IsEqualGUID( &IID_IDirect3D7 , refiid ) )
145 *obj = ICOM_INTERFACE(This->ddraw, IDirect3D7);
146 TRACE("(%p) Returning IDirect3D7 interface at %p\n", This, *obj);
150 else if ( IsEqualGUID( &IID_IDirect3DDevice , refiid ) )
152 *obj = ICOM_INTERFACE(This, IDirect3DDevice);
153 TRACE("(%p) Returning IDirect3DDevice interface at %p\n", This, *obj);
155 else if ( IsEqualGUID( &IID_IDirect3DDevice2 , refiid ) ) {
156 *obj = ICOM_INTERFACE(This, IDirect3DDevice2);
157 TRACE("(%p) Returning IDirect3DDevice2 interface at %p\n", This, *obj);
159 else if ( IsEqualGUID( &IID_IDirect3DDevice3 , refiid ) ) {
160 *obj = ICOM_INTERFACE(This, IDirect3DDevice3);
161 TRACE("(%p) Returning IDirect3DDevice3 interface at %p\n", This, *obj);
163 else if ( IsEqualGUID( &IID_IDirect3DDevice7 , refiid ) ) {
164 *obj = ICOM_INTERFACE(This, IDirect3DDevice7);
165 TRACE("(%p) Returning IDirect3DDevice7 interface at %p\n", This, *obj);
168 /* Unknown interface */
171 ERR("(%p)->(%s, %p): No interface found\n", This, debugstr_guid(refiid), obj);
172 return E_NOINTERFACE;
175 /* AddRef the returned interface */
176 IUnknown_AddRef( (IUnknown *) *obj);
180 static HRESULT WINAPI
181 Thunk_IDirect3DDeviceImpl_3_QueryInterface(IDirect3DDevice3 *iface,
185 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
186 TRACE_(ddraw_thunk)("(%p)->(%s,%p) thunking to IDirect3DDevice7 interface.\n", This, debugstr_guid(riid), obj);
187 return IDirect3DDevice7_QueryInterface(ICOM_INTERFACE(This, IDirect3DDevice7),
192 static HRESULT WINAPI
193 Thunk_IDirect3DDeviceImpl_2_QueryInterface(IDirect3DDevice2 *iface,
197 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
198 TRACE_(ddraw_thunk)("(%p)->(%s,%p) thunking to IDirect3DDevice7 interface.\n", This, debugstr_guid(riid), obj);
199 return IDirect3DDevice7_QueryInterface(ICOM_INTERFACE(This, IDirect3DDevice7),
204 static HRESULT WINAPI
205 Thunk_IDirect3DDeviceImpl_1_QueryInterface(IDirect3DDevice *iface,
209 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
210 TRACE_(ddraw_thunk)("(%p)->(%s,%p) thunking to IDirect3DDevice7 interface.\n", This, debugstr_guid(riid), obp);
211 return IDirect3DDevice7_QueryInterface(ICOM_INTERFACE(This, IDirect3DDevice7),
216 /*****************************************************************************
217 * IDirect3DDevice7::AddRef
219 * Increases the refcount....
220 * The most exciting Method, definitely
222 * Exists in Version 1, 2, 3 and 7
227 *****************************************************************************/
229 IDirect3DDeviceImpl_7_AddRef(IDirect3DDevice7 *iface)
231 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
232 ULONG ref = InterlockedIncrement(&This->ref);
234 TRACE("(%p) : incrementing from %u.\n", This, ref -1);
240 Thunk_IDirect3DDeviceImpl_3_AddRef(IDirect3DDevice3 *iface)
242 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
243 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
244 return IDirect3DDevice7_AddRef(ICOM_INTERFACE(This, IDirect3DDevice7));
248 Thunk_IDirect3DDeviceImpl_2_AddRef(IDirect3DDevice2 *iface)
250 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
251 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
252 return IDirect3DDevice7_AddRef(ICOM_INTERFACE(This, IDirect3DDevice7));
256 Thunk_IDirect3DDeviceImpl_1_AddRef(IDirect3DDevice *iface)
258 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", iface);
259 return IDirect3DDevice7_AddRef(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice, IDirect3DDevice7, iface));
262 /*****************************************************************************
263 * IDirect3DDevice7::Release
265 * Decreases the refcount of the interface
266 * When the refcount is reduced to 0, the object is destroyed.
268 * Exists in Version 1, 2, 3 and 7
273 *****************************************************************************/
275 IDirect3DDeviceImpl_7_Release(IDirect3DDevice7 *iface)
277 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
278 ULONG ref = InterlockedDecrement(&This->ref);
280 TRACE("(%p)->() decrementing from %u.\n", This, ref +1);
282 /* This method doesn't destroy the WineD3DDevice, because it's still in use for
283 * 2D rendering. IDirectDrawSurface7::Release will destroy the WineD3DDevice
284 * when the render target is released
288 IParent *IndexBufferParent;
291 /* Free the index buffer. */
292 IWineD3DDevice_SetIndices(This->wineD3DDevice,
295 IWineD3DIndexBuffer_GetParent(This->indexbuffer,
296 (IUnknown **) &IndexBufferParent);
297 IParent_Release(IndexBufferParent); /* Once for the getParent */
298 if( IParent_Release(IndexBufferParent) != 0) /* And now to destroy it */
300 ERR(" (%p) Something is still holding the index buffer parent %p\n", This, IndexBufferParent);
303 /* There is no need to unset the vertex buffer here, IWineD3DDevice_Uninit3D will do that when
304 * destroying the primary stateblock. If a vertex buffer is destroyed while it is bound
305 * IDirect3DVertexBuffer::Release will unset it.
308 /* Restore the render targets */
309 if(This->OffScreenTarget)
311 /* This->target is the offscreen target.
312 * This->ddraw->d3d_target is the target used by DDraw
314 TRACE("(%p) Release: Using %p as front buffer, %p as back buffer\n", This, This->ddraw->d3d_target, NULL);
315 IWineD3DDevice_SetFrontBackBuffers(This->wineD3DDevice,
316 This->ddraw->d3d_target->WineD3DSurface,
320 /* Release the WineD3DDevice. This won't destroy it */
321 if(IWineD3DDevice_Release(This->wineD3DDevice) <= 0)
323 ERR(" (%p) The wineD3D device %p was destroyed unexpectadely. Prepare for trouble\n", This, This->wineD3DDevice);
326 /* The texture handles should be unset by now, but there might be some bits
327 * missing in our reference counting(needs test). Do a sanity check
329 for(i = 0; i < This->numHandles; i++)
331 if(This->Handles[i].ptr)
333 switch(This->Handles[i].type)
335 case DDrawHandle_Texture:
337 IDirectDrawSurfaceImpl *surf = (IDirectDrawSurfaceImpl *) This->Handles[i].ptr;
338 FIXME("Texture Handle %d not unset properly\n", i + 1);
343 case DDrawHandle_Material:
345 IDirect3DMaterialImpl *mat = (IDirect3DMaterialImpl *) This->Handles[i].ptr;
346 FIXME("Material handle %d not unset properly\n", i + 1);
351 case DDrawHandle_Matrix:
353 /* No fixme here because this might happen because of sloppy apps */
354 WARN("Leftover matrix handle %d, deleting\n", i + 1);
355 IDirect3DDevice_DeleteMatrix(ICOM_INTERFACE(This, IDirect3DDevice),
360 case DDrawHandle_StateBlock:
362 /* No fixme here because this might happen because of sloppy apps */
363 WARN("Leftover stateblock handle %d, deleting\n", i + 1);
364 IDirect3DDevice7_DeleteStateBlock(ICOM_INTERFACE(This, IDirect3DDevice7),
370 FIXME("Unknown handle %d not unset properly\n", i + 1);
375 HeapFree(GetProcessHeap(), 0, This->Handles);
377 /* Release the render target and the WineD3D render target
378 * (See IDirect3D7::CreateDevice for more comments on this)
380 IDirectDrawSurface7_Release(ICOM_INTERFACE(This->target, IDirectDrawSurface7));
381 IDirectDrawSurface7_Release(ICOM_INTERFACE(This->ddraw->d3d_target,IDirectDrawSurface7));
383 This->ddraw->d3ddevice = NULL;
385 /* Now free the structure */
386 HeapFree(GetProcessHeap(), 0, This);
393 Thunk_IDirect3DDeviceImpl_3_Release(IDirect3DDevice3 *iface)
395 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
396 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
397 return IDirect3DDevice7_Release(ICOM_INTERFACE(This, IDirect3DDevice7));
401 Thunk_IDirect3DDeviceImpl_2_Release(IDirect3DDevice2 *iface)
403 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
404 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
405 return IDirect3DDevice7_Release(ICOM_INTERFACE(This, IDirect3DDevice7));
409 Thunk_IDirect3DDeviceImpl_1_Release(IDirect3DDevice *iface)
411 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
412 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
413 return IDirect3DDevice7_Release(ICOM_INTERFACE(This, IDirect3DDevice7));
416 /*****************************************************************************
417 * IDirect3DDevice Methods
418 *****************************************************************************/
420 /*****************************************************************************
421 * IDirect3DDevice::Initialize
423 * Initializes a Direct3DDevice. This implementation is a no-op, as all
424 * initialization is done at create time.
426 * Exists in Version 1
429 * No idea what they mean, as the MSDN page is gone
433 *****************************************************************************/
434 static HRESULT WINAPI
435 IDirect3DDeviceImpl_1_Initialize(IDirect3DDevice *iface,
436 IDirect3D *Direct3D, GUID *guid,
439 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
441 /* It shouldn't be crucial, but print a FIXME, I'm interested if
442 * any game calls it and when
444 FIXME("(%p)->(%p,%p,%p): No-op!\n", This, Direct3D, guid, Desc);
449 /*****************************************************************************
450 * IDirect3DDevice7::GetCaps
452 * Retrieves the device's capabilities
454 * This implementation is used for Version 7 only, the older versions have
455 * their own implementation.
458 * Desc: Pointer to a D3DDEVICEDESC7 structure to fill
462 * D3DERR_* if a problem occurs. See WineD3D
464 *****************************************************************************/
465 static HRESULT WINAPI
466 IDirect3DDeviceImpl_7_GetCaps(IDirect3DDevice7 *iface,
467 D3DDEVICEDESC7 *Desc)
469 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
470 D3DDEVICEDESC OldDesc;
471 TRACE("(%p)->(%p)\n", This, Desc);
473 /* Call the same function used by IDirect3D, this saves code */
474 return IDirect3DImpl_GetCaps(This->ddraw->wineD3D, &OldDesc, Desc);
477 /*****************************************************************************
478 * IDirect3DDevice3::GetCaps
480 * Retrieves the capabilities of the hardware device and the emulation
481 * device. For Wine, hardware and emulation are the same (it's all HW).
483 * This implementation is used for Version 1, 2, and 3. Version 7 has its own
486 * HWDesc: Structure to fill with the HW caps
487 * HelDesc: Structure to fill with the hardare emulation caps
491 * D3DERR_* if a problem occurs. See WineD3D
493 *****************************************************************************/
494 static HRESULT WINAPI
495 IDirect3DDeviceImpl_3_GetCaps(IDirect3DDevice3 *iface,
496 D3DDEVICEDESC *HWDesc,
497 D3DDEVICEDESC *HelDesc)
499 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
500 D3DDEVICEDESC7 newDesc;
502 TRACE("(%p)->(%p,%p)\n", iface, HWDesc, HelDesc);
504 hr = IDirect3DImpl_GetCaps(This->ddraw->wineD3D, HWDesc, &newDesc);
505 if(hr != D3D_OK) return hr;
511 static HRESULT WINAPI
512 Thunk_IDirect3DDeviceImpl_2_GetCaps(IDirect3DDevice2 *iface,
513 D3DDEVICEDESC *D3DHWDevDesc,
514 D3DDEVICEDESC *D3DHELDevDesc)
516 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
517 TRACE_(ddraw_thunk)("(%p)->(%p,%p) thunking to IDirect3DDevice3 interface.\n", This, D3DHWDevDesc, D3DHELDevDesc);
518 return IDirect3DDevice3_GetCaps(ICOM_INTERFACE(This, IDirect3DDevice3),
523 static HRESULT WINAPI
524 Thunk_IDirect3DDeviceImpl_1_GetCaps(IDirect3DDevice *iface,
525 D3DDEVICEDESC *D3DHWDevDesc,
526 D3DDEVICEDESC *D3DHELDevDesc)
528 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
529 TRACE_(ddraw_thunk)("(%p)->(%p,%p) thunking to IDirect3DDevice3 interface.\n", This, D3DHWDevDesc, D3DHELDevDesc);
530 return IDirect3DDevice3_GetCaps(ICOM_INTERFACE(This, IDirect3DDevice3),
535 /*****************************************************************************
536 * IDirect3DDevice2::SwapTextureHandles
538 * Swaps the texture handles of 2 Texture interfaces. Version 1 and 2
541 * Tex1, Tex2: The 2 Textures to swap
546 *****************************************************************************/
547 static HRESULT WINAPI
548 IDirect3DDeviceImpl_2_SwapTextureHandles(IDirect3DDevice2 *iface,
549 IDirect3DTexture2 *Tex1,
550 IDirect3DTexture2 *Tex2)
552 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
554 IDirectDrawSurfaceImpl *surf1 = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture2, Tex1);
555 IDirectDrawSurfaceImpl *surf2 = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture2, Tex2);
556 TRACE("(%p)->(%p,%p)\n", This, surf1, surf2);
558 This->Handles[surf1->Handle - 1].ptr = surf2;
559 This->Handles[surf2->Handle - 1].ptr = surf1;
561 swap = surf2->Handle;
562 surf2->Handle = surf1->Handle;
563 surf1->Handle = swap;
568 static HRESULT WINAPI
569 Thunk_IDirect3DDeviceImpl_1_SwapTextureHandles(IDirect3DDevice *iface,
570 IDirect3DTexture *D3DTex1,
571 IDirect3DTexture *D3DTex2)
573 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
574 IDirectDrawSurfaceImpl *surf1 = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture, D3DTex1);
575 IDirectDrawSurfaceImpl *surf2 = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture, D3DTex2);
576 TRACE_(ddraw_thunk)("(%p)->(%p,%p) thunking to IDirect3DDevice2 interface.\n", This, surf1, surf2);
577 return IDirect3DDevice2_SwapTextureHandles(ICOM_INTERFACE(This, IDirect3DDevice2),
578 ICOM_INTERFACE(surf1, IDirect3DTexture2),
579 ICOM_INTERFACE(surf2, IDirect3DTexture2));
582 /*****************************************************************************
583 * IDirect3DDevice3::GetStats
585 * This method seems to retrieve some stats from the device.
586 * The MSDN documentation doesn't exist any more, but the D3DSTATS
587 * structure suggests that the amout of drawn primitives and processed
588 * vertices is returned.
590 * Exists in Version 1, 2 and 3
593 * Stats: Pointer to a D3DSTATS structure to be filled
597 * DDERR_INVALIDPARAMS if Stats == NULL
599 *****************************************************************************/
600 static HRESULT WINAPI
601 IDirect3DDeviceImpl_3_GetStats(IDirect3DDevice3 *iface,
604 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
605 FIXME("(%p)->(%p): Stub!\n", This, Stats);
608 return DDERR_INVALIDPARAMS;
610 /* Fill the Stats with 0 */
611 Stats->dwTrianglesDrawn = 0;
612 Stats->dwLinesDrawn = 0;
613 Stats->dwPointsDrawn = 0;
614 Stats->dwSpansDrawn = 0;
615 Stats->dwVerticesProcessed = 0;
620 static HRESULT WINAPI
621 Thunk_IDirect3DDeviceImpl_2_GetStats(IDirect3DDevice2 *iface,
624 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
625 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, Stats);
626 return IDirect3DDevice3_GetStats(ICOM_INTERFACE(This, IDirect3DDevice3),
630 static HRESULT WINAPI
631 Thunk_IDirect3DDeviceImpl_1_GetStats(IDirect3DDevice *iface,
634 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
635 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, Stats);
636 return IDirect3DDevice3_GetStats(ICOM_INTERFACE(This, IDirect3DDevice3),
640 /*****************************************************************************
641 * IDirect3DDevice::CreateExecuteBuffer
643 * Creates an IDirect3DExecuteBuffer, used for rendering with a
649 * Desc: Buffer description
650 * ExecuteBuffer: Address to return the Interface pointer at
651 * UnkOuter: Must be NULL. Basically for aggregation, which ddraw doesn't
655 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
656 * DDERR_OUTOFMEMORY if we ran out of memory
659 *****************************************************************************/
660 static HRESULT WINAPI
661 IDirect3DDeviceImpl_1_CreateExecuteBuffer(IDirect3DDevice *iface,
662 D3DEXECUTEBUFFERDESC *Desc,
663 IDirect3DExecuteBuffer **ExecuteBuffer,
666 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
667 IDirect3DExecuteBufferImpl* object;
668 TRACE("(%p)->(%p,%p,%p)!\n", This, Desc, ExecuteBuffer, UnkOuter);
671 return CLASS_E_NOAGGREGATION;
673 /* Allocate the new Execute Buffer */
674 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DExecuteBufferImpl));
677 ERR("Out of memory when allocating a IDirect3DExecuteBufferImpl structure\n");
678 return DDERR_OUTOFMEMORY;
681 ICOM_INIT_INTERFACE(object, IDirect3DExecuteBuffer, IDirect3DExecuteBuffer_Vtbl);
684 object->d3ddev = This;
686 /* Initializes memory */
687 memcpy(&object->desc, Desc, Desc->dwSize);
689 /* No buffer given */
690 if ((object->desc.dwFlags & D3DDEB_LPDATA) == 0)
691 object->desc.lpData = NULL;
693 /* No buffer size given */
694 if ((object->desc.dwFlags & D3DDEB_BUFSIZE) == 0)
695 object->desc.dwBufferSize = 0;
697 /* Create buffer if asked */
698 if ((object->desc.lpData == NULL) && (object->desc.dwBufferSize > 0))
700 object->need_free = TRUE;
701 object->desc.lpData = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,object->desc.dwBufferSize);
702 if(!object->desc.lpData)
704 ERR("Out of memory when allocating the execute buffer data\n");
705 HeapFree(GetProcessHeap(), 0, object);
706 return DDERR_OUTOFMEMORY;
711 object->need_free = FALSE;
714 /* No vertices for the moment */
715 object->vertex_data = NULL;
717 object->desc.dwFlags |= D3DDEB_LPDATA;
719 object->indices = NULL;
720 object->nb_indices = 0;
722 *ExecuteBuffer = ICOM_INTERFACE(object, IDirect3DExecuteBuffer);
724 TRACE(" Returning IDirect3DExecuteBuffer at %p, implementation is at %p\n", *ExecuteBuffer, object);
729 /*****************************************************************************
730 * IDirect3DDevice::Execute
732 * Executes all the stuff in an execute buffer.
735 * ExecuteBuffer: The buffer to execute
736 * Viewport: The viewport used for rendering
740 * DDERR_INVALIDPARAMS if ExecuteBuffer == NULL
743 *****************************************************************************/
744 static HRESULT WINAPI
745 IDirect3DDeviceImpl_1_Execute(IDirect3DDevice *iface,
746 IDirect3DExecuteBuffer *ExecuteBuffer,
747 IDirect3DViewport *Viewport,
750 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
751 IDirect3DExecuteBufferImpl *Direct3DExecuteBufferImpl = ICOM_OBJECT(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, ExecuteBuffer);
752 IDirect3DViewportImpl *Direct3DViewportImpl = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport);
754 TRACE("(%p)->(%p,%p,%08x)\n", This, Direct3DExecuteBufferImpl, Direct3DViewportImpl, Flags);
756 if(!Direct3DExecuteBufferImpl)
757 return DDERR_INVALIDPARAMS;
760 IDirect3DExecuteBufferImpl_Execute(Direct3DExecuteBufferImpl, This, Direct3DViewportImpl);
765 /*****************************************************************************
766 * IDirect3DDevice3::AddViewport
768 * Add a Direct3DViewport to the device's viewport list. These viewports
769 * are wrapped to IDirect3DDevice7 viewports in viewport.c
771 * Exists in Version 1, 2 and 3. Note that IDirect3DViewport 1, 2 and 3
772 * are the same interfaces.
775 * Viewport: The viewport to add
778 * DDERR_INVALIDPARAMS if Viewport == NULL
781 *****************************************************************************/
782 static HRESULT WINAPI
783 IDirect3DDeviceImpl_3_AddViewport(IDirect3DDevice3 *iface,
784 IDirect3DViewport3 *Viewport)
786 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
787 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport);
789 TRACE("(%p)->(%p)\n", This, vp);
793 return DDERR_INVALIDPARAMS;
795 vp->next = This->viewport_list;
796 This->viewport_list = vp;
801 static HRESULT WINAPI
802 Thunk_IDirect3DDeviceImpl_2_AddViewport(IDirect3DDevice2 *iface,
803 IDirect3DViewport2 *Direct3DViewport2)
805 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
806 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport2);
807 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, vp);
808 return IDirect3DDevice3_AddViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
809 ICOM_INTERFACE(vp, IDirect3DViewport3));
812 static HRESULT WINAPI
813 Thunk_IDirect3DDeviceImpl_1_AddViewport(IDirect3DDevice *iface,
814 IDirect3DViewport *Direct3DViewport)
816 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
817 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport);
818 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, vp);
819 return IDirect3DDevice3_AddViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
820 ICOM_INTERFACE(vp, IDirect3DViewport3));
823 /*****************************************************************************
824 * IDirect3DDevice3::DeleteViewport
826 * Deletes a Direct3DViewport from the device's viewport list.
828 * Exists in Version 1, 2 and 3. Note that all Viewport interface versions
832 * Viewport: The viewport to delete
836 * DDERR_INVALIDPARAMS if the viewport wasn't found in the list
838 *****************************************************************************/
839 static HRESULT WINAPI
840 IDirect3DDeviceImpl_3_DeleteViewport(IDirect3DDevice3 *iface,
841 IDirect3DViewport3 *Viewport)
843 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
844 IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *) Viewport;
845 IDirect3DViewportImpl *cur_viewport, *prev_viewport = NULL;
847 TRACE("(%p)->(%p)\n", This, vp);
849 cur_viewport = This->viewport_list;
850 while (cur_viewport != NULL)
852 if (cur_viewport == vp)
854 if (prev_viewport == NULL) This->viewport_list = cur_viewport->next;
855 else prev_viewport->next = cur_viewport->next;
856 /* TODO : add desactivate of the viewport and all associated lights... */
859 prev_viewport = cur_viewport;
860 cur_viewport = cur_viewport->next;
863 return DDERR_INVALIDPARAMS;
866 static HRESULT WINAPI
867 Thunk_IDirect3DDeviceImpl_2_DeleteViewport(IDirect3DDevice2 *iface,
868 IDirect3DViewport2 *Direct3DViewport2)
870 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
871 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport2);
872 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, vp);
873 return IDirect3DDevice3_DeleteViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
874 ICOM_INTERFACE(vp, IDirect3DViewport3));
877 static HRESULT WINAPI
878 Thunk_IDirect3DDeviceImpl_1_DeleteViewport(IDirect3DDevice *iface,
879 IDirect3DViewport *Direct3DViewport)
881 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
882 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport);
883 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, vp);
884 return IDirect3DDevice3_DeleteViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
885 ICOM_INTERFACE(vp, IDirect3DViewport3));
888 /*****************************************************************************
889 * IDirect3DDevice3::NextViewport
891 * Returns a viewport from the viewport list, depending on the
892 * passed viewport and the flags.
894 * Exists in Version 1, 2 and 3. Note that all Viewport interface versions
898 * Viewport: Viewport to use for beginning the search
899 * Flags: D3DNEXT_NEXT, D3DNEXT_HEAD or D3DNEXT_TAIL
903 * DDERR_INVALIDPARAMS if the flags were wrong, or Viewport was NULL
905 *****************************************************************************/
906 static HRESULT WINAPI
907 IDirect3DDeviceImpl_3_NextViewport(IDirect3DDevice3 *iface,
908 IDirect3DViewport3 *Viewport3,
909 IDirect3DViewport3 **lplpDirect3DViewport3,
912 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
913 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport3);
914 IDirect3DViewportImpl *res = NULL;
916 TRACE("(%p)->(%p,%p,%08x)\n", This, vp, lplpDirect3DViewport3, Flags);
920 *lplpDirect3DViewport3 = NULL;
921 return DDERR_INVALIDPARAMS;
934 res = This->viewport_list;
939 IDirect3DViewportImpl *cur_viewport = This->viewport_list;
940 if (cur_viewport != NULL)
942 while (cur_viewport->next != NULL) cur_viewport = cur_viewport->next;
948 *lplpDirect3DViewport3 = NULL;
949 return DDERR_INVALIDPARAMS;
952 *lplpDirect3DViewport3 = ICOM_INTERFACE(res, IDirect3DViewport3);
956 static HRESULT WINAPI
957 Thunk_IDirect3DDeviceImpl_2_NextViewport(IDirect3DDevice2 *iface,
958 IDirect3DViewport2 *Viewport2,
959 IDirect3DViewport2 **lplpDirect3DViewport2,
962 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
963 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport2);
964 IDirect3DViewport3 *res;
966 TRACE_(ddraw_thunk)("(%p)->(%p,%p,%08x) thunking to IDirect3DDevice3 interface.\n", This, vp, lplpDirect3DViewport2, Flags);
967 hr = IDirect3DDevice3_NextViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
968 ICOM_INTERFACE(vp, IDirect3DViewport3),
971 *lplpDirect3DViewport2 = (IDirect3DViewport2 *) COM_INTERFACE_CAST(IDirect3DViewportImpl, IDirect3DViewport3, IDirect3DViewport3, res);
975 static HRESULT WINAPI
976 Thunk_IDirect3DDeviceImpl_1_NextViewport(IDirect3DDevice *iface,
977 IDirect3DViewport *Viewport,
978 IDirect3DViewport **lplpDirect3DViewport,
981 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
982 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport);
983 IDirect3DViewport3 *res;
985 TRACE_(ddraw_thunk)("(%p)->(%p,%p,%08x) thunking to IDirect3DDevice3 interface.\n", This, vp, lplpDirect3DViewport, Flags);
986 hr = IDirect3DDevice3_NextViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
987 ICOM_INTERFACE(vp, IDirect3DViewport3),
990 *lplpDirect3DViewport = (IDirect3DViewport *) COM_INTERFACE_CAST(IDirect3DViewportImpl, IDirect3DViewport3, IDirect3DViewport3, res);
994 /*****************************************************************************
995 * IDirect3DDevice::Pick
997 * Executes an execute buffer without performing rendering. Instead, a
998 * list of primitives that intersect with (x1,y1) of the passed rectangle
999 * is created. IDirect3DDevice::GetPickRecords can be used to retrieve
1005 * ExecuteBuffer: Buffer to execute
1006 * Viewport: Viewport to use for execution
1007 * Flags: None are defined, according to the SDK
1008 * Rect: Specifies the coordinates to be picked. Only x1 and y2 are used,
1009 * x2 and y2 are ignored.
1012 * D3D_OK because it's a stub
1014 *****************************************************************************/
1015 static HRESULT WINAPI
1016 IDirect3DDeviceImpl_1_Pick(IDirect3DDevice *iface,
1017 IDirect3DExecuteBuffer *ExecuteBuffer,
1018 IDirect3DViewport *Viewport,
1022 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1023 IDirect3DExecuteBufferImpl *execbuf = ICOM_OBJECT(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, ExecuteBuffer);
1024 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport);
1025 FIXME("(%p)->(%p,%p,%08x,%p): stub!\n", This, execbuf, vp, Flags, Rect);
1030 /*****************************************************************************
1031 * IDirect3DDevice::GetPickRecords
1033 * Retrieves the pick records generated by IDirect3DDevice::GetPickRecords
1038 * Count: Pointer to a DWORD containing the numbers of pick records to
1040 * D3DPickRec: Address to store the resulting D3DPICKRECORD arry.
1043 * D3D_OK, because it's a stub
1045 *****************************************************************************/
1046 static HRESULT WINAPI
1047 IDirect3DDeviceImpl_1_GetPickRecords(IDirect3DDevice *iface,
1049 D3DPICKRECORD *D3DPickRec)
1051 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1052 FIXME("(%p)->(%p,%p): stub!\n", This, Count, D3DPickRec);
1057 /*****************************************************************************
1058 * IDirect3DDevice7::EnumTextureformats
1060 * Enumerates the supported texture formats. It has a list of all possible
1061 * formats and calls IWineD3D::CheckDeviceFormat for each format to see if
1062 * WineD3D supports it. If so, then it is passed to the app.
1064 * This is for Version 7 and 3, older versions have a different
1065 * callback function and their own implementation
1068 * Callback: Callback to call for each enumerated format
1069 * Arg: Argument to pass to the callback
1073 * DDERR_INVALIDPARAMS if Callback == NULL
1075 *****************************************************************************/
1076 static HRESULT WINAPI
1077 IDirect3DDeviceImpl_7_EnumTextureFormats(IDirect3DDevice7 *iface,
1078 LPD3DENUMPIXELFORMATSCALLBACK Callback,
1081 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1085 WINED3DFORMAT FormatList[] = {
1087 WINED3DFMT_A8R8G8B8,
1088 WINED3DFMT_X8R8G8B8,
1092 WINED3DFMT_A1R5G5B5,
1093 WINED3DFMT_A4R4G4B4,
1095 WINED3DFMT_X1R5G5B5,
1105 TRACE("(%p)->(%p,%p): Relay\n", This, Callback, Arg);
1108 return DDERR_INVALIDPARAMS;
1110 for(i = 0; i < sizeof(FormatList) / sizeof(WINED3DFORMAT); i++)
1112 hr = IWineD3D_CheckDeviceFormat(This->ddraw->wineD3D,
1115 0 /* AdapterFormat */,
1117 0 /* ResourceType */,
1121 DDPIXELFORMAT pformat;
1123 memset(&pformat, 0, sizeof(pformat));
1124 pformat.dwSize = sizeof(pformat);
1125 PixelFormat_WineD3DtoDD(&pformat, FormatList[i]);
1127 TRACE("Enumerating WineD3DFormat %d\n", FormatList[i]);
1128 hr = Callback(&pformat, Arg);
1129 if(hr != DDENUMRET_OK)
1131 TRACE("Format enumeration cancelled by application\n");
1136 TRACE("End of enumeration\n");
1140 static HRESULT WINAPI
1141 Thunk_IDirect3DDeviceImpl_3_EnumTextureFormats(IDirect3DDevice3 *iface,
1142 LPD3DENUMPIXELFORMATSCALLBACK Callback,
1145 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1146 TRACE_(ddraw_thunk)("(%p)->(%p,%p) thunking to IDirect3DDevice7 interface.\n", This, Callback, Arg);
1147 return IDirect3DDevice7_EnumTextureFormats(ICOM_INTERFACE(This, IDirect3DDevice7),
1152 /*****************************************************************************
1153 * IDirect3DDevice2::EnumTextureformats
1155 * EnumTextureFormats for Version 1 and 2, see
1156 * IDirect3DDevice7::EnumTexureFormats for a more detailed description.
1158 * This version has a different callback and does not enumerate FourCC
1161 *****************************************************************************/
1162 static HRESULT WINAPI
1163 IDirect3DDeviceImpl_2_EnumTextureFormats(IDirect3DDevice2 *iface,
1164 LPD3DENUMTEXTUREFORMATSCALLBACK Callback,
1167 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1171 WINED3DFORMAT FormatList[] = {
1173 WINED3DFMT_A8R8G8B8,
1174 WINED3DFMT_X8R8G8B8,
1178 WINED3DFMT_A1R5G5B5,
1179 WINED3DFMT_A4R4G4B4,
1181 WINED3DFMT_X1R5G5B5,
1185 /* FOURCC codes - Not in this version*/
1188 TRACE("(%p)->(%p,%p): Relay\n", This, Callback, Arg);
1191 return DDERR_INVALIDPARAMS;
1193 for(i = 0; i < sizeof(FormatList) / sizeof(WINED3DFORMAT); i++)
1195 hr = IWineD3D_CheckDeviceFormat(This->ddraw->wineD3D,
1198 0 /* AdapterFormat */,
1200 0 /* ResourceType */,
1204 DDSURFACEDESC sdesc;
1206 memset(&sdesc, 0, sizeof(sdesc));
1207 sdesc.dwSize = sizeof(sdesc);
1208 sdesc.dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
1209 sdesc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1210 sdesc.ddpfPixelFormat.dwSize = sizeof(sdesc.ddpfPixelFormat.dwSize);
1211 PixelFormat_WineD3DtoDD(&sdesc.ddpfPixelFormat, FormatList[i]);
1213 TRACE("Enumerating WineD3DFormat %d\n", FormatList[i]);
1214 hr = Callback(&sdesc, Arg);
1215 if(hr != DDENUMRET_OK)
1217 TRACE("Format enumeration cancelled by application\n");
1222 TRACE("End of enumeration\n");
1226 static HRESULT WINAPI
1227 Thunk_IDirect3DDeviceImpl_1_EnumTextureFormats(IDirect3DDevice *iface,
1228 LPD3DENUMTEXTUREFORMATSCALLBACK Callback,
1231 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1232 TRACE_(ddraw_thunk)("(%p)->(%p,%p) thunking to IDirect3DDevice2 interface.\n", This, Callback, Arg);
1233 return IDirect3DDevice2_EnumTextureFormats(ICOM_INTERFACE(This, IDirect3DDevice2),
1238 /*****************************************************************************
1239 * IDirect3DDevice::CreateMatrix
1241 * Creates a matrix handle. A handle is created and memory for a D3DMATRIX is
1242 * allocated for the handle.
1247 * D3DMatHandle: Address to return the handle at
1251 * DDERR_INVALIDPARAMS if D3DMatHandle = NULL
1253 *****************************************************************************/
1254 static HRESULT WINAPI
1255 IDirect3DDeviceImpl_1_CreateMatrix(IDirect3DDevice *iface, D3DMATRIXHANDLE *D3DMatHandle)
1257 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1259 TRACE("(%p)->(%p)\n", This, D3DMatHandle);
1262 return DDERR_INVALIDPARAMS;
1264 Matrix = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(D3DMATRIX));
1267 ERR("Out of memory when allocating a D3DMATRIX\n");
1268 return DDERR_OUTOFMEMORY;
1270 *D3DMatHandle = IDirect3DDeviceImpl_CreateHandle(This);
1271 if(!(*D3DMatHandle))
1273 ERR("Failed to create a matrix handle\n");
1274 HeapFree(GetProcessHeap(), 0, Matrix);
1275 return DDERR_OUTOFMEMORY;
1277 This->Handles[(DWORD) *D3DMatHandle - 1].ptr = Matrix;
1278 This->Handles[(DWORD) *D3DMatHandle - 1].type = DDrawHandle_Matrix;
1279 TRACE(" returning matrix handle %d\n", *D3DMatHandle);
1284 /*****************************************************************************
1285 * IDirect3DDevice::SetMatrix
1287 * Sets a matrix for a matrix handle. The matrix is copied into the memory
1288 * allocated for the handle
1293 * D3DMatHandle: Handle to set the matrix to
1294 * D3DMatrix: Matrix to set
1298 * DDERR_INVALIDPARAMS if the handle of the matrix is invalid or the matrix
1301 *****************************************************************************/
1302 static HRESULT WINAPI
1303 IDirect3DDeviceImpl_1_SetMatrix(IDirect3DDevice *iface,
1304 D3DMATRIXHANDLE D3DMatHandle,
1305 D3DMATRIX *D3DMatrix)
1307 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1308 TRACE("(%p)->(%08x,%p)\n", This, (DWORD) D3DMatHandle, D3DMatrix);
1310 if( (!D3DMatHandle) || (!D3DMatrix) )
1311 return DDERR_INVALIDPARAMS;
1313 if(D3DMatHandle > This->numHandles)
1315 ERR("Handle %d out of range\n", D3DMatHandle);
1316 return DDERR_INVALIDPARAMS;
1318 else if(This->Handles[D3DMatHandle - 1].type != DDrawHandle_Matrix)
1320 ERR("Handle %d is not a matrix handle\n", D3DMatHandle);
1321 return DDERR_INVALIDPARAMS;
1325 dump_D3DMATRIX(D3DMatrix);
1327 *((D3DMATRIX *) This->Handles[D3DMatHandle - 1].ptr) = *D3DMatrix;
1332 /*****************************************************************************
1333 * IDirect3DDevice::SetMatrix
1335 * Returns the content of a D3DMATRIX handle
1340 * D3DMatHandle: Matrix handle to read the content from
1341 * D3DMatrix: Address to store the content at
1345 * DDERR_INVALIDPARAMS if D3DMatHandle is invalid or D3DMatrix is NULL
1347 *****************************************************************************/
1348 static HRESULT WINAPI
1349 IDirect3DDeviceImpl_1_GetMatrix(IDirect3DDevice *iface,
1350 D3DMATRIXHANDLE D3DMatHandle,
1351 D3DMATRIX *D3DMatrix)
1353 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1354 TRACE("(%p)->(%08x,%p)\n", This, (DWORD) D3DMatHandle, D3DMatrix);
1357 return DDERR_INVALIDPARAMS;
1359 return DDERR_INVALIDPARAMS;
1361 if(D3DMatHandle > This->numHandles)
1363 ERR("Handle %d out of range\n", D3DMatHandle);
1364 return DDERR_INVALIDPARAMS;
1366 else if(This->Handles[D3DMatHandle - 1].type != DDrawHandle_Matrix)
1368 ERR("Handle %d is not a matrix handle\n", D3DMatHandle);
1369 return DDERR_INVALIDPARAMS;
1372 /* The handle is simply a pointer to a D3DMATRIX structure */
1373 *D3DMatrix = *((D3DMATRIX *) This->Handles[D3DMatHandle - 1].ptr);
1378 /*****************************************************************************
1379 * IDirect3DDevice::DeleteMatrix
1381 * Destroys a Matrix handle. Frees the memory and unsets the handle data
1386 * D3DMatHandle: Handle to destroy
1390 * DDERR_INVALIDPARAMS if D3DMatHandle is invalid
1392 *****************************************************************************/
1393 static HRESULT WINAPI
1394 IDirect3DDeviceImpl_1_DeleteMatrix(IDirect3DDevice *iface,
1395 D3DMATRIXHANDLE D3DMatHandle)
1397 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1398 TRACE("(%p)->(%08x)\n", This, (DWORD) D3DMatHandle);
1401 return DDERR_INVALIDPARAMS;
1403 if(D3DMatHandle > This->numHandles)
1405 ERR("Handle %d out of range\n", D3DMatHandle);
1406 return DDERR_INVALIDPARAMS;
1408 else if(This->Handles[D3DMatHandle - 1].type != DDrawHandle_Matrix)
1410 ERR("Handle %d is not a matrix handle\n", D3DMatHandle);
1411 return DDERR_INVALIDPARAMS;
1414 HeapFree(GetProcessHeap(), 0, This->Handles[D3DMatHandle - 1].ptr);
1415 This->Handles[D3DMatHandle - 1].ptr = NULL;
1416 This->Handles[D3DMatHandle - 1].type = DDrawHandle_Unknown;
1421 /*****************************************************************************
1422 * IDirect3DDevice7::BeginScene
1424 * This method must be called before any rendering is performed.
1425 * IDirect3DDevice::EndScene has to be called after the scene is complete
1427 * Version 1, 2, 3 and 7
1430 * D3D_OK on success, for details see IWineD3DDevice::BeginScene
1431 * D3DERR_SCENE_IN_SCENE if WineD3D returns an error(Only in case of an already
1434 *****************************************************************************/
1435 static HRESULT WINAPI
1436 IDirect3DDeviceImpl_7_BeginScene(IDirect3DDevice7 *iface)
1438 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1440 TRACE("(%p): Relay\n", This);
1442 hr = IWineD3DDevice_BeginScene(This->wineD3DDevice);
1443 if(hr == WINED3D_OK) return D3D_OK;
1444 else return D3DERR_SCENE_IN_SCENE; /* TODO: Other possible causes of failure */
1447 static HRESULT WINAPI
1448 Thunk_IDirect3DDeviceImpl_3_BeginScene(IDirect3DDevice3 *iface)
1450 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1451 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1452 return IDirect3DDevice7_BeginScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1455 static HRESULT WINAPI
1456 Thunk_IDirect3DDeviceImpl_2_BeginScene(IDirect3DDevice2 *iface)
1458 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1459 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1460 return IDirect3DDevice7_BeginScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1463 static HRESULT WINAPI
1464 Thunk_IDirect3DDeviceImpl_1_BeginScene(IDirect3DDevice *iface)
1466 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1467 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1468 return IDirect3DDevice7_BeginScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1471 /*****************************************************************************
1472 * IDirect3DDevice7::EndScene
1474 * Ends a scene that has been begun with IDirect3DDevice7::BeginScene.
1475 * This method must be called after rendering is finished.
1477 * Version 1, 2, 3 and 7
1480 * D3D_OK on success, for details see IWineD3DDevice::EndScene
1481 * D3DERR_SCENE_NOT_IN_SCENE is returned if WineD3D returns an error. It does
1482 * that only if the scene was already ended.
1484 *****************************************************************************/
1485 static HRESULT WINAPI
1486 IDirect3DDeviceImpl_7_EndScene(IDirect3DDevice7 *iface)
1488 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1490 TRACE("(%p): Relay\n", This);
1492 hr = IWineD3DDevice_EndScene(This->wineD3DDevice);
1493 if(hr == WINED3D_OK) return D3D_OK;
1494 else return D3DERR_SCENE_NOT_IN_SCENE;
1497 static HRESULT WINAPI
1498 Thunk_IDirect3DDeviceImpl_3_EndScene(IDirect3DDevice3 *iface)
1500 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1501 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1502 return IDirect3DDevice7_EndScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1505 static HRESULT WINAPI
1506 Thunk_IDirect3DDeviceImpl_2_EndScene(IDirect3DDevice2 *iface)
1508 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1509 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1510 return IDirect3DDevice7_EndScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1513 static HRESULT WINAPI
1514 Thunk_IDirect3DDeviceImpl_1_EndScene(IDirect3DDevice *iface)
1516 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1517 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1518 return IDirect3DDevice7_EndScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1521 /*****************************************************************************
1522 * IDirect3DDevice7::GetDirect3D
1524 * Returns the IDirect3D(= interface to the DirectDraw object) used to create
1528 * Direct3D7: Address to store the interface pointer at
1532 * DDERR_INVALIDPARAMS if Direct3D7 == NULL
1534 *****************************************************************************/
1535 static HRESULT WINAPI
1536 IDirect3DDeviceImpl_7_GetDirect3D(IDirect3DDevice7 *iface,
1537 IDirect3D7 **Direct3D7)
1539 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1540 TRACE("(%p)->(%p)\n", This, Direct3D7);
1543 return DDERR_INVALIDPARAMS;
1545 *Direct3D7 = ICOM_INTERFACE(This->ddraw, IDirect3D7);
1546 IDirect3D7_AddRef(*Direct3D7);
1548 TRACE(" returning interface %p\n", *Direct3D7);
1552 static HRESULT WINAPI
1553 Thunk_IDirect3DDeviceImpl_3_GetDirect3D(IDirect3DDevice3 *iface,
1554 IDirect3D3 **Direct3D3)
1556 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1558 IDirect3D7 *ret_ptr;
1560 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, Direct3D3);
1561 ret = IDirect3DDevice7_GetDirect3D(ICOM_INTERFACE(This, IDirect3DDevice7),
1565 *Direct3D3 = COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D7, IDirect3D3, ret_ptr);
1566 TRACE(" returning interface %p\n", *Direct3D3);
1570 static HRESULT WINAPI
1571 Thunk_IDirect3DDeviceImpl_2_GetDirect3D(IDirect3DDevice2 *iface,
1572 IDirect3D2 **Direct3D2)
1574 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1576 IDirect3D7 *ret_ptr;
1578 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, Direct3D2);
1579 ret = IDirect3DDevice7_GetDirect3D(ICOM_INTERFACE(This, IDirect3DDevice7),
1583 *Direct3D2 = COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D7, IDirect3D2, ret_ptr);
1584 TRACE(" returning interface %p\n", *Direct3D2);
1588 static HRESULT WINAPI
1589 Thunk_IDirect3DDeviceImpl_1_GetDirect3D(IDirect3DDevice *iface,
1590 IDirect3D **Direct3D)
1592 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1594 IDirect3D7 *ret_ptr;
1596 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, Direct3D);
1597 ret = IDirect3DDevice7_GetDirect3D(ICOM_INTERFACE(This, IDirect3DDevice7),
1601 *Direct3D = COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D7, IDirect3D, ret_ptr);
1602 TRACE(" returning interface %p\n", *Direct3D);
1606 /*****************************************************************************
1607 * IDirect3DDevice3::SetCurrentViewport
1609 * Sets a Direct3DViewport as the current viewport.
1610 * For the thunks note that all viewport interface versions are equal
1613 * Direct3DViewport3: The viewport to set
1619 * (Is a NULL viewport valid?)
1621 *****************************************************************************/
1622 static HRESULT WINAPI
1623 IDirect3DDeviceImpl_3_SetCurrentViewport(IDirect3DDevice3 *iface,
1624 IDirect3DViewport3 *Direct3DViewport3)
1626 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1627 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport3);
1628 TRACE("(%p)->(%p)\n", This, Direct3DViewport3);
1630 /* Do nothing if the specified viewport is the same as the current one */
1631 if (This->current_viewport == vp )
1634 /* Should check if the viewport was added or not */
1636 /* Release previous viewport and AddRef the new one */
1637 if (This->current_viewport)
1639 TRACE("ViewportImpl is at %p, interface is at %p\n", This->current_viewport, ICOM_INTERFACE(This->current_viewport, IDirect3DViewport3));
1640 IDirect3DViewport3_Release( ICOM_INTERFACE(This->current_viewport, IDirect3DViewport3) );
1642 IDirect3DViewport3_AddRef(Direct3DViewport3);
1644 /* Set this viewport as the current viewport */
1645 This->current_viewport = vp;
1647 /* Activate this viewport */
1648 This->current_viewport->active_device = This;
1649 This->current_viewport->activate(This->current_viewport);
1654 static HRESULT WINAPI
1655 Thunk_IDirect3DDeviceImpl_2_SetCurrentViewport(IDirect3DDevice2 *iface,
1656 IDirect3DViewport2 *Direct3DViewport2)
1658 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1659 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport2);
1660 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, vp);
1661 return IDirect3DDevice3_SetCurrentViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
1662 ICOM_INTERFACE(vp, IDirect3DViewport3));
1665 /*****************************************************************************
1666 * IDirect3DDevice3::GetCurrentViewport
1668 * Returns the currently active viewport.
1673 * Direct3DViewport3: Address to return the interface pointer at
1677 * DDERR_INVALIDPARAMS if Direct3DViewport == NULL
1679 *****************************************************************************/
1680 static HRESULT WINAPI
1681 IDirect3DDeviceImpl_3_GetCurrentViewport(IDirect3DDevice3 *iface,
1682 IDirect3DViewport3 **Direct3DViewport3)
1684 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1685 TRACE("(%p)->(%p)\n", This, Direct3DViewport3);
1687 if(!Direct3DViewport3)
1688 return DDERR_INVALIDPARAMS;
1690 *Direct3DViewport3 = ICOM_INTERFACE(This->current_viewport, IDirect3DViewport3);
1692 /* AddRef the returned viewport */
1693 if(*Direct3DViewport3) IDirect3DViewport3_AddRef(*Direct3DViewport3);
1695 TRACE(" returning interface %p\n", *Direct3DViewport3);
1700 static HRESULT WINAPI
1701 Thunk_IDirect3DDeviceImpl_2_GetCurrentViewport(IDirect3DDevice2 *iface,
1702 IDirect3DViewport2 **Direct3DViewport2)
1704 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1706 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, Direct3DViewport2);
1707 hr = IDirect3DDevice3_GetCurrentViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
1708 (IDirect3DViewport3 **) Direct3DViewport2);
1709 if(hr != D3D_OK) return hr;
1710 *Direct3DViewport2 = (IDirect3DViewport2 *) COM_INTERFACE_CAST(IDirect3DViewportImpl, IDirect3DViewport3, IDirect3DViewport3, *Direct3DViewport2);
1714 /*****************************************************************************
1715 * IDirect3DDevice7::SetRenderTarget
1717 * Sets the render target for the Direct3DDevice.
1718 * For the thunks note that IDirectDrawSurface7 == IDirectDrawSurface4 and
1719 * IDirectDrawSurface3 == IDirectDrawSurface
1721 * Version 2, 3 and 7
1724 * NewTarget: Pointer to an IDirectDrawSurface7 interface to set as the new
1729 * D3D_OK on success, for details see IWineD3DDevice::SetRenderTarget
1731 *****************************************************************************/
1732 static HRESULT WINAPI
1733 IDirect3DDeviceImpl_7_SetRenderTarget(IDirect3DDevice7 *iface,
1734 IDirectDrawSurface7 *NewTarget,
1737 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1738 IDirectDrawSurfaceImpl *Target = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, NewTarget);
1739 TRACE("(%p)->(%p,%08x): Relay\n", This, NewTarget, Flags);
1741 /* Flags: Not used */
1743 return IWineD3DDevice_SetRenderTarget(This->wineD3DDevice,
1745 Target ? Target->WineD3DSurface : NULL);
1748 static HRESULT WINAPI
1749 Thunk_IDirect3DDeviceImpl_3_SetRenderTarget(IDirect3DDevice3 *iface,
1750 IDirectDrawSurface4 *NewRenderTarget,
1753 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1754 IDirectDrawSurfaceImpl *Target = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, NewRenderTarget);
1755 TRACE_(ddraw_thunk)("(%p)->(%p,%08x) thunking to IDirect3DDevice7 interface.\n", This, Target, Flags);
1756 return IDirect3DDevice7_SetRenderTarget(ICOM_INTERFACE(This, IDirect3DDevice7),
1757 ICOM_INTERFACE(Target, IDirectDrawSurface7),
1761 static HRESULT WINAPI
1762 Thunk_IDirect3DDeviceImpl_2_SetRenderTarget(IDirect3DDevice2 *iface,
1763 IDirectDrawSurface *NewRenderTarget,
1766 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1767 IDirectDrawSurfaceImpl *Target = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface3, NewRenderTarget);
1768 TRACE_(ddraw_thunk)("(%p)->(%p,%08x) thunking to IDirect3DDevice7 interface.\n", This, Target, Flags);
1769 return IDirect3DDevice7_SetRenderTarget(ICOM_INTERFACE(This, IDirect3DDevice7),
1770 ICOM_INTERFACE(Target, IDirectDrawSurface7),
1774 /*****************************************************************************
1775 * IDirect3DDevice7::GetRenderTarget
1777 * Returns the current render target.
1778 * This is handled locally, because the WineD3D render target's parent
1781 * Version 2, 3 and 7
1784 * RenderTarget: Address to store the surface interface pointer
1788 * DDERR_INVALIDPARAMS if RenderTarget == NULL
1790 *****************************************************************************/
1791 static HRESULT WINAPI
1792 IDirect3DDeviceImpl_7_GetRenderTarget(IDirect3DDevice7 *iface,
1793 IDirectDrawSurface7 **RenderTarget)
1795 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1796 TRACE("(%p)->(%p): Relay\n", This, RenderTarget);
1799 return DDERR_INVALIDPARAMS;
1801 *RenderTarget = ICOM_INTERFACE(This->target, IDirectDrawSurface7);
1802 IDirectDrawSurface7_AddRef(*RenderTarget);
1807 static HRESULT WINAPI
1808 Thunk_IDirect3DDeviceImpl_3_GetRenderTarget(IDirect3DDevice3 *iface,
1809 IDirectDrawSurface4 **RenderTarget)
1811 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1813 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, RenderTarget);
1814 hr = IDirect3DDevice7_GetRenderTarget(ICOM_INTERFACE(This, IDirect3DDevice7),
1815 (IDirectDrawSurface7 **) RenderTarget);
1816 if(hr != D3D_OK) return hr;
1817 *RenderTarget = (IDirectDrawSurface4 *) COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7, IDirectDrawSurface7, *RenderTarget);
1821 static HRESULT WINAPI
1822 Thunk_IDirect3DDeviceImpl_2_GetRenderTarget(IDirect3DDevice2 *iface,
1823 IDirectDrawSurface **RenderTarget)
1825 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1827 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, RenderTarget);
1828 hr = IDirect3DDevice7_GetRenderTarget(ICOM_INTERFACE(This, IDirect3DDevice7),
1829 (IDirectDrawSurface7 **) RenderTarget);
1830 if(hr != D3D_OK) return hr;
1831 *RenderTarget = (IDirectDrawSurface *) COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7, IDirectDrawSurface3, *RenderTarget);
1835 /*****************************************************************************
1836 * IDirect3DDevice3::Begin
1838 * Begins a description block of vertices. This is similar to glBegin()
1839 * and glEnd(). After a call to IDirect3DDevice3::End, the vertices
1840 * described with IDirect3DDevice::Vertex are drawn.
1845 * PrimitiveType: The type of primitives to draw
1846 * VertexTypeDesc: A flexible vertex format description of the vertices
1847 * Flags: Some flags..
1852 *****************************************************************************/
1853 static HRESULT WINAPI
1854 IDirect3DDeviceImpl_3_Begin(IDirect3DDevice3 *iface,
1855 D3DPRIMITIVETYPE PrimitiveType,
1856 DWORD VertexTypeDesc,
1859 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1860 TRACE("(%p)->(%d,%d,%08x)\n", This, PrimitiveType, VertexTypeDesc, Flags);
1862 This->primitive_type = PrimitiveType;
1863 This->vertex_type = VertexTypeDesc;
1864 This->render_flags = Flags;
1865 This->vertex_size = get_flexible_vertex_size(This->vertex_type);
1866 This->nb_vertices = 0;
1871 static HRESULT WINAPI
1872 Thunk_IDirect3DDeviceImpl_2_Begin(IDirect3DDevice2 *iface,
1873 D3DPRIMITIVETYPE d3dpt,
1874 D3DVERTEXTYPE dwVertexTypeDesc,
1878 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1879 TRACE_(ddraw_thunk)("(%p/%p)->(%08x,%08x,%08x): Thunking to IDirect3DDevice3\n", This, iface, d3dpt, dwVertexTypeDesc, dwFlags);
1881 switch(dwVertexTypeDesc)
1883 case D3DVT_VERTEX: FVF = D3DFVF_VERTEX; break;
1884 case D3DVT_LVERTEX: FVF = D3DFVF_LVERTEX; break;
1885 case D3DVT_TLVERTEX: FVF = D3DFVF_TLVERTEX; break;
1887 ERR("Unexpected vertex type %d\n", dwVertexTypeDesc);
1888 return DDERR_INVALIDPARAMS; /* Should never happen */
1891 return IDirect3DDevice3_Begin(ICOM_INTERFACE(This, IDirect3DDevice3),
1897 /*****************************************************************************
1898 * IDirect3DDevice3::BeginIndexed
1900 * Draws primitives based on vertices in a vertex array which are specified
1906 * PrimitiveType: Primitive type to draw
1907 * VertexType: A FVF description of the vertex format
1908 * Vertices: pointer to an array containing the vertices
1909 * NumVertices: The number of vertices in the vertex array
1910 * Flags: Some flags ...
1913 * D3D_OK, because it's a stub
1915 *****************************************************************************/
1916 static HRESULT WINAPI
1917 IDirect3DDeviceImpl_3_BeginIndexed(IDirect3DDevice3 *iface,
1918 D3DPRIMITIVETYPE PrimitiveType,
1924 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1925 FIXME("(%p)->(%08x,%08x,%p,%08x,%08x): stub!\n", This, PrimitiveType, VertexType, Vertices, NumVertices, Flags);
1930 static HRESULT WINAPI
1931 Thunk_IDirect3DDeviceImpl_2_BeginIndexed(IDirect3DDevice2 *iface,
1932 D3DPRIMITIVETYPE d3dptPrimitiveType,
1933 D3DVERTEXTYPE d3dvtVertexType,
1935 DWORD dwNumVertices,
1939 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1940 TRACE_(ddraw_thunk)("(%p/%p)->(%08x,%08x,%p,%08x,%08x): Thunking to IDirect3DDevice3\n", This, iface, d3dptPrimitiveType, d3dvtVertexType, lpvVertices, dwNumVertices, dwFlags);
1942 switch(d3dvtVertexType)
1944 case D3DVT_VERTEX: FVF = D3DFVF_VERTEX; break;
1945 case D3DVT_LVERTEX: FVF = D3DFVF_LVERTEX; break;
1946 case D3DVT_TLVERTEX: FVF = D3DFVF_TLVERTEX; break;
1948 ERR("Unexpected vertex type %d\n", d3dvtVertexType);
1949 return DDERR_INVALIDPARAMS; /* Should never happen */
1952 return IDirect3DDevice3_BeginIndexed(ICOM_INTERFACE(This,IDirect3DDevice3),
1960 /*****************************************************************************
1961 * IDirect3DDevice3::Vertex
1963 * Draws a vertex as described by IDirect3DDevice3::Begin. It places all
1964 * drawn vertices in a vertex buffer. If the buffer is too small, its
1965 * size is increased.
1970 * Vertex: Pointer to the vertex
1973 * D3D_OK, on success
1974 * DDERR_INVALIDPARAMS if Vertex is NULL
1976 *****************************************************************************/
1977 static HRESULT WINAPI
1978 IDirect3DDeviceImpl_3_Vertex(IDirect3DDevice3 *iface,
1981 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1982 TRACE("(%p)->(%p)\n", This, Vertex);
1985 return DDERR_INVALIDPARAMS;
1987 if ((This->nb_vertices+1)*This->vertex_size > This->buffer_size)
1990 This->buffer_size = This->buffer_size ? This->buffer_size * 2 : This->vertex_size * 3;
1991 old_buffer = This->vertex_buffer;
1992 This->vertex_buffer = HeapAlloc(GetProcessHeap(), 0, This->buffer_size);
1995 CopyMemory(This->vertex_buffer, old_buffer, This->nb_vertices * This->vertex_size);
1996 HeapFree(GetProcessHeap(), 0, old_buffer);
2000 CopyMemory(This->vertex_buffer + This->nb_vertices++ * This->vertex_size, Vertex, This->vertex_size);
2005 static HRESULT WINAPI
2006 Thunk_IDirect3DDeviceImpl_2_Vertex(IDirect3DDevice2 *iface,
2009 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2010 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, lpVertexType);
2011 return IDirect3DDevice3_Vertex(ICOM_INTERFACE(This, IDirect3DDevice3),
2015 /*****************************************************************************
2016 * IDirect3DDevice3::Index
2018 * Specifies an index to a vertex to be drawn. The vertex array has to
2019 * be specified with BeginIndexed first.
2022 * VertexIndex: The index of the vertex to draw
2025 * D3D_OK because it's a stub
2027 *****************************************************************************/
2028 static HRESULT WINAPI
2029 IDirect3DDeviceImpl_3_Index(IDirect3DDevice3 *iface,
2032 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2033 FIXME("(%p)->(%04x): stub!\n", This, VertexIndex);
2037 static HRESULT WINAPI
2038 Thunk_IDirect3DDeviceImpl_2_Index(IDirect3DDevice2 *iface,
2041 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2042 TRACE_(ddraw_thunk)("(%p)->(%04x) thunking to IDirect3DDevice3 interface.\n", This, wVertexIndex);
2043 return IDirect3DDevice3_Index(ICOM_INTERFACE(This, IDirect3DDevice3),
2047 /*****************************************************************************
2048 * IDirect3DDevice3::End
2050 * Ends a draw begun with IDirect3DDevice3::Begin or
2051 * IDirect3DDevice::BeginIndexed. The vertices specified with
2052 * IDirect3DDevice::Vertex or IDirect3DDevice::Index are drawn using
2053 * the IDirect3DDevice7::DrawPrimitive method. So far only
2054 * non-indexed mode is supported
2059 * Flags: Some flags, as usual. Don't know which are defined
2062 * The return value of IDirect3DDevice7::DrawPrimitive
2064 *****************************************************************************/
2065 static HRESULT WINAPI
2066 IDirect3DDeviceImpl_3_End(IDirect3DDevice3 *iface,
2069 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2070 TRACE("(%p)->(%08x)\n", This, Flags);
2072 return IDirect3DDevice7_DrawPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
2073 This->primitive_type, This->vertex_type,
2074 This->vertex_buffer, This->nb_vertices,
2075 This->render_flags);
2078 static HRESULT WINAPI
2079 Thunk_IDirect3DDeviceImpl_2_End(IDirect3DDevice2 *iface,
2082 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2083 TRACE_(ddraw_thunk)("(%p)->(%08x) thunking to IDirect3DDevice3 interface.\n", This, dwFlags);
2084 return IDirect3DDevice3_End(ICOM_INTERFACE(This, IDirect3DDevice3),
2088 /*****************************************************************************
2089 * IDirect3DDevice7::GetRenderState
2091 * Returns the value of a render state. The possible render states are
2092 * defined in include/d3dtypes.h
2094 * Version 2, 3 and 7
2097 * RenderStateType: Render state to return the current setting of
2098 * Value: Address to store the value at
2101 * D3D_OK on success, for details see IWineD3DDevice::GetRenderState
2102 * DDERR_INVALIDPARAMS if Value == NULL
2104 *****************************************************************************/
2105 static HRESULT WINAPI
2106 IDirect3DDeviceImpl_7_GetRenderState(IDirect3DDevice7 *iface,
2107 D3DRENDERSTATETYPE RenderStateType,
2110 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2112 TRACE("(%p)->(%08x,%p): Relay\n", This, RenderStateType, Value);
2115 return DDERR_INVALIDPARAMS;
2117 switch(RenderStateType)
2119 case D3DRENDERSTATE_TEXTUREHANDLE:
2121 /* This state is wrapped to SetTexture in SetRenderState, so
2122 * it has to be wrapped to GetTexture here
2124 IWineD3DBaseTexture *tex = NULL;
2127 hr = IWineD3DDevice_GetTexture(This->wineD3DDevice,
2131 if(hr == WINED3D_OK && tex)
2133 IDirectDrawSurface7 *parent = NULL;
2134 hr = IWineD3DBaseTexture_GetParent(tex,
2135 (IUnknown **) &parent);
2138 /* The parent of the texture is the IDirectDrawSurface7 interface
2139 * of the ddraw surface
2141 IDirectDrawSurfaceImpl *texImpl = ICOM_OBJECT(IDirectDrawSurfaceImpl,
2142 IDirectDrawSurface7,
2144 *Value = texImpl->Handle;
2145 IDirectDrawSurface7_Release(parent);
2147 IWineD3DBaseTexture_Release(tex);
2152 case D3DRENDERSTATE_TEXTUREMAG:
2154 WINED3DTEXTUREFILTERTYPE tex_mag;
2156 hr = IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
2157 0, WINED3DSAMP_MAGFILTER,
2162 case WINED3DTEXF_POINT:
2163 *Value = D3DFILTER_NEAREST;
2165 case WINED3DTEXF_LINEAR:
2166 *Value = D3DFILTER_LINEAR;
2169 ERR("Unhandled texture mag %d !\n",tex_mag);
2175 case D3DRENDERSTATE_TEXTUREMIN:
2177 WINED3DTEXTUREFILTERTYPE tex_min;
2179 hr = IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
2180 0, WINED3DSAMP_MINFILTER,
2185 case WINED3DTEXF_POINT:
2186 *Value = D3DFILTER_NEAREST;
2188 case WINED3DTEXF_LINEAR:
2189 *Value = D3DFILTER_LINEAR;
2192 ERR("Unhandled texture mag %d !\n",tex_min);
2198 case D3DRENDERSTATE_TEXTUREADDRESS:
2199 case D3DRENDERSTATE_TEXTUREADDRESSU:
2200 return IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
2201 0, WINED3DSAMP_ADDRESSU,
2203 case D3DRENDERSTATE_TEXTUREADDRESSV:
2204 return IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
2205 0, WINED3DSAMP_ADDRESSV,
2209 /* FIXME: Unhandled: D3DRENDERSTATE_STIPPLEPATTERN00 - 31 */
2210 return IWineD3DDevice_GetRenderState(This->wineD3DDevice,
2216 static HRESULT WINAPI
2217 Thunk_IDirect3DDeviceImpl_3_GetRenderState(IDirect3DDevice3 *iface,
2218 D3DRENDERSTATETYPE dwRenderStateType,
2219 DWORD *lpdwRenderState)
2221 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2222 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, dwRenderStateType, lpdwRenderState);
2223 return IDirect3DDevice7_GetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2228 static HRESULT WINAPI
2229 Thunk_IDirect3DDeviceImpl_2_GetRenderState(IDirect3DDevice2 *iface,
2230 D3DRENDERSTATETYPE dwRenderStateType,
2231 DWORD *lpdwRenderState)
2233 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2234 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, dwRenderStateType, lpdwRenderState);
2235 return IDirect3DDevice7_GetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2240 /*****************************************************************************
2241 * IDirect3DDevice7::SetRenderState
2243 * Sets a render state. The possible render states are defined in
2244 * include/d3dtypes.h
2246 * Version 2, 3 and 7
2249 * RenderStateType: State to set
2250 * Value: Value to assign to that state
2253 * D3D_OK on success,
2254 * for details see IWineD3DDevice::SetRenderState
2256 *****************************************************************************/
2257 static HRESULT WINAPI
2258 IDirect3DDeviceImpl_7_SetRenderState(IDirect3DDevice7 *iface,
2259 D3DRENDERSTATETYPE RenderStateType,
2262 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2263 TRACE("(%p)->(%08x,%d): Relay\n", This, RenderStateType, Value);
2265 /* Some render states need special care */
2266 switch(RenderStateType)
2268 case D3DRENDERSTATE_TEXTUREHANDLE:
2272 return IWineD3DDevice_SetTexture(This->wineD3DDevice,
2277 if(Value > This->numHandles)
2279 FIXME("Specified handle %d out of range\n", Value);
2280 return DDERR_INVALIDPARAMS;
2282 if(This->Handles[Value - 1].type != DDrawHandle_Texture)
2284 FIXME("Handle %d isn't a texture handle\n", Value);
2285 return DDERR_INVALIDPARAMS;
2289 IDirectDrawSurfaceImpl *surf = (IDirectDrawSurfaceImpl *) This->Handles[Value - 1].ptr;
2290 return IWineD3DDevice_SetTexture(This->wineD3DDevice,
2292 (IWineD3DBaseTexture *) surf->wineD3DTexture);
2296 case D3DRENDERSTATE_TEXTUREMAG:
2298 WINED3DTEXTUREFILTERTYPE tex_mag = WINED3DTEXF_NONE;
2300 switch ((D3DTEXTUREFILTER) Value)
2302 case D3DFILTER_NEAREST:
2303 case D3DFILTER_LINEARMIPNEAREST:
2304 tex_mag = WINED3DTEXF_POINT;
2306 case D3DFILTER_LINEAR:
2307 case D3DFILTER_LINEARMIPLINEAR:
2308 tex_mag = WINED3DTEXF_LINEAR;
2311 ERR("Unhandled texture mag %d !\n",Value);
2314 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
2315 0, WINED3DSAMP_MAGFILTER,
2319 case D3DRENDERSTATE_TEXTUREMIN:
2321 WINED3DTEXTUREFILTERTYPE tex_min = WINED3DTEXF_NONE;
2322 WINED3DTEXTUREFILTERTYPE tex_mip = WINED3DTEXF_NONE;
2324 switch ((D3DTEXTUREFILTER) Value)
2326 case D3DFILTER_NEAREST:
2327 tex_min = WINED3DTEXF_POINT;
2329 case D3DFILTER_LINEAR:
2330 tex_min = WINED3DTEXF_LINEAR;
2332 case D3DFILTER_MIPNEAREST:
2333 tex_min = WINED3DTEXF_NONE;
2334 tex_mip = WINED3DTEXF_POINT;
2336 case D3DFILTER_MIPLINEAR:
2337 tex_min = WINED3DTEXF_NONE;
2338 tex_mip = WINED3DTEXF_LINEAR;
2340 case D3DFILTER_LINEARMIPNEAREST:
2341 tex_min = WINED3DTEXF_POINT;
2342 tex_mip = WINED3DTEXF_LINEAR;
2344 case D3DFILTER_LINEARMIPLINEAR:
2345 tex_min = WINED3DTEXF_LINEAR;
2346 tex_mip = WINED3DTEXF_LINEAR;
2350 ERR("Unhandled texture min %d !\n",Value);
2353 IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
2354 0, WINED3DSAMP_MIPFILTER,
2356 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
2357 0, WINED3DSAMP_MINFILTER,
2361 case D3DRENDERSTATE_TEXTUREADDRESS:
2362 IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
2363 0, WINED3DSAMP_ADDRESSV,
2366 case D3DRENDERSTATE_TEXTUREADDRESSU:
2367 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
2368 0, WINED3DSAMP_ADDRESSU,
2370 case D3DRENDERSTATE_TEXTUREADDRESSV:
2371 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
2372 0, WINED3DSAMP_ADDRESSV,
2375 case D3DRENDERSTATE_TEXTUREMAPBLEND:
2377 /* Old texture combine setup style, superseded by texture stage states
2378 * in D3D7. It is safe for us to wrap it to texture stage states.
2380 switch ( (D3DTEXTUREBLEND) Value)
2382 case D3DTBLEND_MODULATE:
2383 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLORARG1, WINED3DTA_TEXTURE);
2384 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAARG1, WINED3DTA_TEXTURE);
2385 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLORARG2, WINED3DTA_CURRENT);
2386 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLOROP, WINED3DTOP_MODULATE);
2387 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAOP, WINED3DTOP_SELECTARG1);
2390 case D3DTBLEND_MODULATEALPHA:
2391 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLORARG1, WINED3DTA_TEXTURE);
2392 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAARG1, WINED3DTA_TEXTURE);
2393 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLORARG2, WINED3DTA_CURRENT);
2394 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAARG2, WINED3DTA_CURRENT);
2395 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLOROP, WINED3DTOP_MODULATE);
2396 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAOP, WINED3DTOP_MODULATE);
2399 case D3DTBLEND_DECAL:
2400 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLORARG1, WINED3DTA_TEXTURE);
2401 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAARG1, WINED3DTA_TEXTURE);
2402 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLOROP, WINED3DTOP_SELECTARG1);
2403 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAOP, WINED3DTOP_SELECTARG1);
2406 case D3DTBLEND_DECALALPHA:
2407 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLORARG1, WINED3DTA_TEXTURE);
2408 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAARG1, WINED3DTA_TEXTURE);
2409 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAARG2, WINED3DTA_CURRENT);
2410 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLOROP, WINED3DTOP_SELECTARG1);
2411 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAOP, WINED3DTOP_MODULATE);
2415 ERR("Unhandled texture environment %d !\n",Value);
2423 /* FIXME: Unhandled: D3DRENDERSTATE_STIPPLEPATTERN00 - 31 */
2425 return IWineD3DDevice_SetRenderState(This->wineD3DDevice,
2431 static HRESULT WINAPI
2432 Thunk_IDirect3DDeviceImpl_3_SetRenderState(IDirect3DDevice3 *iface,
2433 D3DRENDERSTATETYPE RenderStateType,
2436 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2437 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, RenderStateType, Value);
2438 return IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2443 static HRESULT WINAPI
2444 Thunk_IDirect3DDeviceImpl_2_SetRenderState(IDirect3DDevice2 *iface,
2445 D3DRENDERSTATETYPE RenderStateType,
2448 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2449 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, RenderStateType, Value);
2450 return IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2455 /*****************************************************************************
2456 * Direct3DDevice3::SetLightState
2458 * Sets a light state for Direct3DDevice3 and Direct3DDevice2. The
2459 * light states are forwarded to Direct3DDevice7 render states
2464 * LightStateType: The light state to change
2465 * Value: The value to assign to that light state
2469 * DDERR_INVALIDPARAMS if the parameters were incorrect
2470 * Also check IDirect3DDevice7::SetRenderState
2472 *****************************************************************************/
2473 static HRESULT WINAPI
2474 IDirect3DDeviceImpl_3_SetLightState(IDirect3DDevice3 *iface,
2475 D3DLIGHTSTATETYPE LightStateType,
2478 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2480 TRACE("(%p)->(%08x,%08x)\n", This, LightStateType, Value);
2482 if (!LightStateType && (LightStateType > D3DLIGHTSTATE_COLORVERTEX))
2484 TRACE("Unexpected Light State Type\n");
2485 return DDERR_INVALIDPARAMS;
2488 if (LightStateType == D3DLIGHTSTATE_MATERIAL /* 1 */)
2490 IDirect3DMaterialImpl *mat;
2492 if(Value == 0) mat = NULL;
2493 else if(Value > This->numHandles)
2495 ERR("Material handle out of range(%d)\n", Value);
2496 return DDERR_INVALIDPARAMS;
2498 else if(This->Handles[Value - 1].type != DDrawHandle_Material)
2500 ERR("Invalid handle %d\n", Value);
2501 return DDERR_INVALIDPARAMS;
2505 mat = (IDirect3DMaterialImpl *) This->Handles[Value - 1].ptr;
2510 TRACE(" activating material %p.\n", mat);
2515 FIXME(" D3DLIGHTSTATE_MATERIAL called with NULL material !!!\n");
2517 This->material = Value;
2519 else if (LightStateType == D3DLIGHTSTATE_COLORMODEL /* 3 */)
2524 ERR("DDCOLOR_MONO should not happen!\n");
2527 /* We are already in this mode */
2528 TRACE("Setting color model to RGB (no-op).\n");
2531 ERR("Unknown color model!\n");
2532 return DDERR_INVALIDPARAMS;
2537 D3DRENDERSTATETYPE rs;
2538 switch (LightStateType)
2540 case D3DLIGHTSTATE_AMBIENT: /* 2 */
2541 rs = D3DRENDERSTATE_AMBIENT;
2543 case D3DLIGHTSTATE_FOGMODE: /* 4 */
2544 rs = D3DRENDERSTATE_FOGVERTEXMODE;
2546 case D3DLIGHTSTATE_FOGSTART: /* 5 */
2547 rs = D3DRENDERSTATE_FOGSTART;
2549 case D3DLIGHTSTATE_FOGEND: /* 6 */
2550 rs = D3DRENDERSTATE_FOGEND;
2552 case D3DLIGHTSTATE_FOGDENSITY: /* 7 */
2553 rs = D3DRENDERSTATE_FOGDENSITY;
2555 case D3DLIGHTSTATE_COLORVERTEX: /* 8 */
2556 rs = D3DRENDERSTATE_COLORVERTEX;
2559 ERR("Unknown D3DLIGHTSTATETYPE %d.\n", LightStateType);
2560 return DDERR_INVALIDPARAMS;
2563 return IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2571 static HRESULT WINAPI
2572 Thunk_IDirect3DDeviceImpl_2_SetLightState(IDirect3DDevice2 *iface,
2573 D3DLIGHTSTATETYPE LightStateType,
2576 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2577 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x) thunking to IDirect3DDevice3 interface.\n", This, LightStateType, Value);
2578 return IDirect3DDevice3_SetLightState(ICOM_INTERFACE(This, IDirect3DDevice3),
2583 /*****************************************************************************
2584 * IDirect3DDevice3::GetLightState
2586 * Returns the current setting of a light state. The state is read from
2587 * the Direct3DDevice7 render state.
2592 * LightStateType: The light state to return
2593 * Value: The address to store the light state setting at
2597 * DDDERR_INVALIDPARAMS if the parameters were incorrect
2598 * Also see IDirect3DDevice7::GetRenderState
2600 *****************************************************************************/
2601 static HRESULT WINAPI
2602 IDirect3DDeviceImpl_3_GetLightState(IDirect3DDevice3 *iface,
2603 D3DLIGHTSTATETYPE LightStateType,
2606 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2608 TRACE("(%p)->(%08x,%p)\n", This, LightStateType, Value);
2610 if (!LightStateType && (LightStateType > D3DLIGHTSTATE_COLORVERTEX))
2612 TRACE("Unexpected Light State Type\n");
2613 return DDERR_INVALIDPARAMS;
2617 return DDERR_INVALIDPARAMS;
2619 if (LightStateType == D3DLIGHTSTATE_MATERIAL /* 1 */)
2621 *Value = This->material;
2623 else if (LightStateType == D3DLIGHTSTATE_COLORMODEL /* 3 */)
2625 *Value = D3DCOLOR_RGB;
2629 D3DRENDERSTATETYPE rs;
2630 switch (LightStateType)
2632 case D3DLIGHTSTATE_AMBIENT: /* 2 */
2633 rs = D3DRENDERSTATE_AMBIENT;
2635 case D3DLIGHTSTATE_FOGMODE: /* 4 */
2636 rs = D3DRENDERSTATE_FOGVERTEXMODE;
2638 case D3DLIGHTSTATE_FOGSTART: /* 5 */
2639 rs = D3DRENDERSTATE_FOGSTART;
2641 case D3DLIGHTSTATE_FOGEND: /* 6 */
2642 rs = D3DRENDERSTATE_FOGEND;
2644 case D3DLIGHTSTATE_FOGDENSITY: /* 7 */
2645 rs = D3DRENDERSTATE_FOGDENSITY;
2647 case D3DLIGHTSTATE_COLORVERTEX: /* 8 */
2648 rs = D3DRENDERSTATE_COLORVERTEX;
2651 ERR("Unknown D3DLIGHTSTATETYPE %d.\n", LightStateType);
2652 return DDERR_INVALIDPARAMS;
2655 return IDirect3DDevice7_GetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2663 static HRESULT WINAPI
2664 Thunk_IDirect3DDeviceImpl_2_GetLightState(IDirect3DDevice2 *iface,
2665 D3DLIGHTSTATETYPE LightStateType,
2668 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2669 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice3 interface.\n", This, LightStateType, Value);
2670 return IDirect3DDevice3_GetLightState(ICOM_INTERFACE(This, IDirect3DDevice3),
2675 /*****************************************************************************
2676 * IDirect3DDevice7::SetTransform
2678 * Assigns a D3DMATRIX to a transform type. The transform types are defined
2679 * in include/d3dtypes.h.
2680 * The D3DTRANSFORMSTATE_WORLD (=1) is translated to D3DTS_WORLDMATRIX(0)
2681 * (=255) for wined3d, because the 1 transform state was removed in d3d8
2682 * and WineD3D already understands the replacement D3DTS_WORLDMATRIX(0)
2684 * Version 2, 3 and 7
2687 * TransformStateType: transform state to set
2688 * Matrix: Matrix to assign to the state
2692 * DDERR_INVALIDPARAMS if Matrix == NULL
2693 * For details see IWineD3DDevice::SetTransform
2695 *****************************************************************************/
2696 static HRESULT WINAPI
2697 IDirect3DDeviceImpl_7_SetTransform(IDirect3DDevice7 *iface,
2698 D3DTRANSFORMSTATETYPE TransformStateType,
2701 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2702 D3DTRANSFORMSTATETYPE type = TransformStateType;
2703 TRACE("(%p)->(%08x,%p): Relay\n", This, TransformStateType, Matrix);
2706 return DDERR_INVALIDPARAMS;
2708 /* D3DTRANSFORMSTATE_WORLD doesn't exist in WineD3D,
2709 * use D3DTS_WORLDMATRIX(0) instead
2710 * D3DTS_WORLDMATRIX(index) is (D3DTRANSFORMSTATETYPE)(index + 256)
2712 if(TransformStateType == D3DTRANSFORMSTATE_WORLD)
2713 type = (D3DTRANSFORMSTATETYPE)(0 + 256);
2716 Unhandled: D3DTRANSFORMSTATE_WORLD1
2717 Unhandled: D3DTRANSFORMSTATE_WORLD2
2718 Unhandled: D3DTRANSFORMSTATE_WORLD3
2721 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
2722 return IWineD3DDevice_SetTransform(This->wineD3DDevice,
2724 (WINED3DMATRIX*) Matrix);
2727 static HRESULT WINAPI
2728 Thunk_IDirect3DDeviceImpl_3_SetTransform(IDirect3DDevice3 *iface,
2729 D3DTRANSFORMSTATETYPE TransformStateType,
2730 D3DMATRIX *D3DMatrix)
2732 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2733 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2734 return IDirect3DDevice7_SetTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2739 static HRESULT WINAPI
2740 Thunk_IDirect3DDeviceImpl_2_SetTransform(IDirect3DDevice2 *iface,
2741 D3DTRANSFORMSTATETYPE TransformStateType,
2742 D3DMATRIX *D3DMatrix)
2744 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2745 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2746 return IDirect3DDevice7_SetTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2751 /*****************************************************************************
2752 * IDirect3DDevice7::GetTransform
2754 * Returns the matrix assigned to a transform state
2755 * D3DTRANSFORMSTATE_WORLD is translated to D3DTS_WORLDMATRIX(0), see
2759 * TransformStateType: State to read the matrix from
2760 * Matrix: Address to store the matrix at
2764 * DDERR_INVALIDPARAMS if Matrix == NULL
2765 * For details, see IWineD3DDevice::GetTransform
2767 *****************************************************************************/
2768 static HRESULT WINAPI
2769 IDirect3DDeviceImpl_7_GetTransform(IDirect3DDevice7 *iface,
2770 D3DTRANSFORMSTATETYPE TransformStateType,
2773 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2774 D3DTRANSFORMSTATETYPE type = TransformStateType;
2775 TRACE("(%p)->(%08x,%p): Relay\n", This, TransformStateType, Matrix);
2778 return DDERR_INVALIDPARAMS;
2780 /* D3DTRANSFORMSTATE_WORLD doesn't exist in WineD3D,
2781 * use D3DTS_WORLDMATRIX(0) instead
2782 * D3DTS_WORLDMATRIX(index) is (D3DTRANSFORMSTATETYPE)(index + 256)
2784 if(TransformStateType == D3DTRANSFORMSTATE_WORLD)
2785 type = (D3DTRANSFORMSTATETYPE)(0 + 256);
2788 Unhandled: D3DTRANSFORMSTATE_WORLD1
2789 Unhandled: D3DTRANSFORMSTATE_WORLD2
2790 Unhandled: D3DTRANSFORMSTATE_WORLD3
2793 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
2794 return IWineD3DDevice_GetTransform(This->wineD3DDevice, type, (WINED3DMATRIX*) Matrix);
2797 static HRESULT WINAPI
2798 Thunk_IDirect3DDeviceImpl_3_GetTransform(IDirect3DDevice3 *iface,
2799 D3DTRANSFORMSTATETYPE TransformStateType,
2800 D3DMATRIX *D3DMatrix)
2802 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2803 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2804 return IDirect3DDevice7_GetTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2809 static HRESULT WINAPI
2810 Thunk_IDirect3DDeviceImpl_2_GetTransform(IDirect3DDevice2 *iface,
2811 D3DTRANSFORMSTATETYPE TransformStateType,
2812 D3DMATRIX *D3DMatrix)
2814 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2815 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2816 return IDirect3DDevice7_GetTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2821 /*****************************************************************************
2822 * IDirect3DDevice7::MultiplyTransform
2824 * Multiplies the already-set transform matrix of a transform state
2825 * with another matrix. For the world matrix, see SetTransform
2827 * Version 2, 3 and 7
2830 * TransformStateType: Transform state to multiply
2831 * D3DMatrix Matrix to multiply with.
2835 * DDERR_INVALIDPARAMS if D3DMatrix is NULL
2836 * For details, see IWineD3DDevice::MultiplyTransform
2838 *****************************************************************************/
2839 static HRESULT WINAPI
2840 IDirect3DDeviceImpl_7_MultiplyTransform(IDirect3DDevice7 *iface,
2841 D3DTRANSFORMSTATETYPE TransformStateType,
2842 D3DMATRIX *D3DMatrix)
2844 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2845 TRACE("(%p)->(%08x,%p): Relay\n", This, TransformStateType, D3DMatrix);
2847 /* D3DTRANSFORMSTATE_WORLD doesn't exist in WineD3D,
2848 * use D3DTS_WORLDMATRIX(0) instead
2849 * D3DTS_WORLDMATRIX(index) is (D3DTRANSFORMSTATETYPE)(index + 256)
2851 if(TransformStateType == D3DTRANSFORMSTATE_WORLD)
2852 TransformStateType = (D3DTRANSFORMSTATETYPE)(0 + 256);
2855 Unhandled: D3DTRANSFORMSTATE_WORLD1
2856 Unhandled: D3DTRANSFORMSTATE_WORLD2
2857 Unhandled: D3DTRANSFORMSTATE_WORLD3
2860 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
2861 return IWineD3DDevice_MultiplyTransform(This->wineD3DDevice,
2863 (WINED3DMATRIX*) D3DMatrix);
2866 static HRESULT WINAPI
2867 Thunk_IDirect3DDeviceImpl_3_MultiplyTransform(IDirect3DDevice3 *iface,
2868 D3DTRANSFORMSTATETYPE TransformStateType,
2869 D3DMATRIX *D3DMatrix)
2871 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2872 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2873 return IDirect3DDevice7_MultiplyTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2878 static HRESULT WINAPI
2879 Thunk_IDirect3DDeviceImpl_2_MultiplyTransform(IDirect3DDevice2 *iface,
2880 D3DTRANSFORMSTATETYPE TransformStateType,
2881 D3DMATRIX *D3DMatrix)
2883 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2884 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2885 return IDirect3DDevice7_MultiplyTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2890 /*****************************************************************************
2891 * IDirect3DDevice7::DrawPrimitive
2893 * Draws primitives based on vertices in an application-provided pointer
2895 * Version 2, 3 and 7. The IDirect3DDevice2 thunk converts the fixed vertex type into
2896 * an FVF format for D3D7
2899 * PrimitiveType: The type of the primitives to draw
2900 * Vertex type: Flexible vertex format vertex description
2901 * Vertices: Pointer to the vertex array
2902 * VertexCount: The number of vertices to draw
2903 * Flags: As usual a few flags
2907 * DDERR_INVALIDPARAMS if Vertices is NULL
2908 * For details, see IWineD3DDevice::DrawPrimitiveUP
2910 *****************************************************************************/
2911 static HRESULT WINAPI
2912 IDirect3DDeviceImpl_7_DrawPrimitive(IDirect3DDevice7 *iface,
2913 D3DPRIMITIVETYPE PrimitiveType,
2919 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2920 UINT PrimitiveCount, stride;
2922 TRACE("(%p)->(%08x,%08x,%p,%08x,%08x): Relay!\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Flags);
2925 return DDERR_INVALIDPARAMS;
2927 /* Get the vertex count */
2928 switch(PrimitiveType)
2930 case D3DPT_POINTLIST:
2931 PrimitiveCount = VertexCount;
2934 case D3DPT_LINELIST:
2935 PrimitiveCount = VertexCount / 2;
2938 case D3DPT_LINESTRIP:
2939 PrimitiveCount = VertexCount - 1;
2942 case D3DPT_TRIANGLELIST:
2943 PrimitiveCount = VertexCount / 3;
2946 case D3DPT_TRIANGLESTRIP:
2947 PrimitiveCount = VertexCount - 2;
2950 case D3DPT_TRIANGLEFAN:
2951 PrimitiveCount = VertexCount - 2;
2954 default: return DDERR_INVALIDPARAMS;
2957 /* Get the stride */
2958 stride = get_flexible_vertex_size(VertexType);
2961 hr = IWineD3DDevice_SetFVF(This->wineD3DDevice, VertexType);
2962 if(hr != D3D_OK) return hr;
2964 /* This method translates to the user pointer draw of WineD3D */
2965 return IWineD3DDevice_DrawPrimitiveUP(This->wineD3DDevice,
2972 static HRESULT WINAPI
2973 Thunk_IDirect3DDeviceImpl_3_DrawPrimitive(IDirect3DDevice3 *iface,
2974 D3DPRIMITIVETYPE PrimitiveType,
2980 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2981 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Flags);
2982 return IDirect3DDevice7_DrawPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
2990 static HRESULT WINAPI
2991 Thunk_IDirect3DDeviceImpl_2_DrawPrimitive(IDirect3DDevice2 *iface,
2992 D3DPRIMITIVETYPE PrimitiveType,
2993 D3DVERTEXTYPE VertexType,
2998 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
3000 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Flags);
3004 case D3DVT_VERTEX: FVF = D3DFVF_VERTEX; break;
3005 case D3DVT_LVERTEX: FVF = D3DFVF_LVERTEX; break;
3006 case D3DVT_TLVERTEX: FVF = D3DFVF_TLVERTEX; break;
3008 ERR("Unexpected vertex type %d\n", VertexType);
3009 return DDERR_INVALIDPARAMS; /* Should never happen */
3012 return IDirect3DDevice7_DrawPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
3020 /*****************************************************************************
3021 * IDirect3DDevice7::DrawIndexedPrimitive
3023 * Draws vertices from an application-provided pointer, based on the index
3024 * numbers in a WORD array.
3026 * Version 2, 3 and 7. The version 7 thunk translates the vertex type into
3027 * an FVF format for D3D7
3030 * PrimitiveType: The primitive type to draw
3031 * VertexType: The FVF vertex description
3032 * Vertices: Pointer to the vertex array
3034 * Indices: Pointer to the index array
3035 * IndexCount: Number of indices = Number of vertices to draw
3036 * Flags: As usual, some flags
3040 * DDERR_INVALIDPARAMS if Vertices or Indices is NULL
3041 * For details, see IWineD3DDevice::DrawIndexedPrimitiveUP
3043 *****************************************************************************/
3044 static HRESULT WINAPI
3045 IDirect3DDeviceImpl_7_DrawIndexedPrimitive(IDirect3DDevice7 *iface,
3046 D3DPRIMITIVETYPE PrimitiveType,
3054 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3055 UINT PrimitiveCount = 0;
3057 TRACE("(%p)->(%08x,%08x,%p,%08x,%p,%08x,%08x): Relay!\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Indices, IndexCount, Flags);
3058 /* Get the primitive number */
3059 switch(PrimitiveType)
3061 case D3DPT_POINTLIST:
3062 PrimitiveCount = IndexCount;
3065 case D3DPT_LINELIST:
3066 PrimitiveCount = IndexCount / 2;
3069 case D3DPT_LINESTRIP:
3070 PrimitiveCount = IndexCount - 1;
3073 case D3DPT_TRIANGLELIST:
3074 PrimitiveCount = IndexCount / 3;
3077 case D3DPT_TRIANGLESTRIP:
3078 PrimitiveCount = IndexCount - 2;
3081 case D3DPT_TRIANGLEFAN:
3082 PrimitiveCount = IndexCount - 2;
3085 default: return DDERR_INVALIDPARAMS;
3088 /* Set the D3DDevice's FVF */
3089 hr = IWineD3DDevice_SetFVF(This->wineD3DDevice, VertexType);
3092 ERR(" (%p) Setting the FVF failed, hr = %x!\n", This, hr);
3096 return IWineD3DDevice_DrawIndexedPrimitiveUP(This->wineD3DDevice,
3098 0 /* MinVertexIndex */,
3099 VertexCount /* UINT NumVertexIndex */,
3104 get_flexible_vertex_size(VertexType));
3107 static HRESULT WINAPI
3108 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitive(IDirect3DDevice3 *iface,
3109 D3DPRIMITIVETYPE PrimitiveType,
3117 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3118 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Indices, IndexCount, Flags);
3119 return IDirect3DDevice7_DrawIndexedPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
3129 static HRESULT WINAPI
3130 Thunk_IDirect3DDeviceImpl_2_DrawIndexedPrimitive(IDirect3DDevice2 *iface,
3131 D3DPRIMITIVETYPE PrimitiveType,
3132 D3DVERTEXTYPE VertexType,
3140 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
3141 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Indices, IndexCount, Flags);
3145 case D3DVT_VERTEX: FVF = D3DFVF_VERTEX; break;
3146 case D3DVT_LVERTEX: FVF = D3DFVF_LVERTEX; break;
3147 case D3DVT_TLVERTEX: FVF = D3DFVF_TLVERTEX; break;
3149 ERR("Unexpected vertex type %d\n", VertexType);
3150 return DDERR_INVALIDPARAMS; /* Should never happen */
3153 return IDirect3DDevice7_DrawIndexedPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
3163 /*****************************************************************************
3164 * IDirect3DDevice7::SetClipStatus
3166 * Sets the clip status. This defines things as clipping conditions and
3167 * the extents of the clipping region.
3169 * Version 2, 3 and 7
3175 * D3D_OK because it's a stub
3176 * (DDERR_INVALIDPARAMS if ClipStatus == NULL)
3178 *****************************************************************************/
3179 static HRESULT WINAPI
3180 IDirect3DDeviceImpl_7_SetClipStatus(IDirect3DDevice7 *iface,
3181 D3DCLIPSTATUS *ClipStatus)
3183 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3184 FIXME("(%p)->(%p): Stub!\n", This, ClipStatus);
3186 /* D3DCLIPSTATUS and WINED3DCLIPSTATUS are different. I don't know how to convert them
3187 * Perhaps this needs a new data type and an additional IWineD3DDevice method
3189 /* return IWineD3DDevice_SetClipStatus(This->wineD3DDevice, ClipStatus);*/
3193 static HRESULT WINAPI
3194 Thunk_IDirect3DDeviceImpl_3_SetClipStatus(IDirect3DDevice3 *iface,
3195 D3DCLIPSTATUS *ClipStatus)
3197 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3198 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, ClipStatus);
3199 return IDirect3DDevice7_SetClipStatus(ICOM_INTERFACE(This, IDirect3DDevice7),
3203 static HRESULT WINAPI
3204 Thunk_IDirect3DDeviceImpl_2_SetClipStatus(IDirect3DDevice2 *iface,
3205 D3DCLIPSTATUS *ClipStatus)
3207 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
3208 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, ClipStatus);
3209 return IDirect3DDevice7_SetClipStatus(ICOM_INTERFACE(This, IDirect3DDevice7),
3213 /*****************************************************************************
3214 * IDirect3DDevice7::GetClipStatus
3216 * Returns the clip status
3219 * ClipStatus: Address to write the clip status to
3222 * D3D_OK because it's a stub
3224 *****************************************************************************/
3225 static HRESULT WINAPI
3226 IDirect3DDeviceImpl_7_GetClipStatus(IDirect3DDevice7 *iface,
3227 D3DCLIPSTATUS *ClipStatus)
3229 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3230 FIXME("(%p)->(%p): Stub!\n", This, ClipStatus);
3232 /* D3DCLIPSTATUS and WINED3DCLIPSTATUS are different. I don't know how to convert them */
3233 /* return IWineD3DDevice_GetClipStatus(This->wineD3DDevice, ClipStatus);*/
3237 static HRESULT WINAPI
3238 Thunk_IDirect3DDeviceImpl_3_GetClipStatus(IDirect3DDevice3 *iface,
3239 D3DCLIPSTATUS *ClipStatus)
3241 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3242 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, ClipStatus);
3243 return IDirect3DDevice7_GetClipStatus(ICOM_INTERFACE(This, IDirect3DDevice7),
3247 static HRESULT WINAPI
3248 Thunk_IDirect3DDeviceImpl_2_GetClipStatus(IDirect3DDevice2 *iface,
3249 D3DCLIPSTATUS *ClipStatus)
3251 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
3252 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, ClipStatus);
3253 return IDirect3DDevice7_GetClipStatus(ICOM_INTERFACE(This, IDirect3DDevice7),
3257 /*****************************************************************************
3258 * IDirect3DDevice::DrawPrimitiveStrided
3260 * Draws vertices described by a D3DDRAWPRIMITIVESTRIDEDDATA structure.
3265 * PrimitiveType: The primitive type to draw
3266 * VertexType: The FVF description of the vertices to draw (for the stride??)
3267 * D3DDrawPrimStrideData: A D3DDRAWPRIMITIVESTRIDEDDATA structure describing
3268 * the vertex data locations
3269 * VertexCount: The number of vertices to draw
3273 * D3D_OK, because it's a stub
3274 * (DDERR_INVALIDPARAMS if D3DDrawPrimStrideData is NULL)
3275 * (For details, see IWineD3DDevice::DrawPrimitiveStrided)
3277 *****************************************************************************/
3278 static HRESULT WINAPI
3279 IDirect3DDeviceImpl_7_DrawPrimitiveStrided(IDirect3DDevice7 *iface,
3280 D3DPRIMITIVETYPE PrimitiveType,
3282 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3286 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3287 WineDirect3DVertexStridedData WineD3DStrided;
3289 UINT PrimitiveCount;
3291 TRACE("(%p)->(%08x,%08x,%p,%08x,%08x): stub!\n", This, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Flags);
3293 memset(&WineD3DStrided, 0, sizeof(WineD3DStrided));
3294 /* Get the strided data right. the wined3d structure is a bit bigger
3295 * Watch out: The contents of the strided data are determined by the fvf,
3296 * not by the members set in D3DDrawPrimStrideData. So it's valid
3297 * to have diffuse.lpvData set to 0xdeadbeef if the diffuse flag is
3298 * not set in the fvf.
3300 if(VertexType & D3DFVF_POSITION_MASK)
3302 WineD3DStrided.u.s.position.lpData = D3DDrawPrimStrideData->position.lpvData;
3303 WineD3DStrided.u.s.position.dwStride = D3DDrawPrimStrideData->position.dwStride;
3304 WineD3DStrided.u.s.position.dwType = WINED3DDECLTYPE_FLOAT3;
3305 if (VertexType & D3DFVF_XYZRHW)
3307 WineD3DStrided.u.s.position.dwType = WINED3DDECLTYPE_FLOAT4;
3308 WineD3DStrided.u.s.position_transformed = TRUE;
3310 WineD3DStrided.u.s.position_transformed = FALSE;
3313 if(VertexType & D3DFVF_NORMAL)
3315 WineD3DStrided.u.s.normal.lpData = D3DDrawPrimStrideData->normal.lpvData;
3316 WineD3DStrided.u.s.normal.dwStride = D3DDrawPrimStrideData->normal.dwStride;
3317 WineD3DStrided.u.s.normal.dwType = WINED3DDECLTYPE_FLOAT3;
3320 if(VertexType & D3DFVF_DIFFUSE)
3322 WineD3DStrided.u.s.diffuse.lpData = D3DDrawPrimStrideData->diffuse.lpvData;
3323 WineD3DStrided.u.s.diffuse.dwStride = D3DDrawPrimStrideData->diffuse.dwStride;
3324 WineD3DStrided.u.s.diffuse.dwType = WINED3DDECLTYPE_SHORT4;
3327 if(VertexType & D3DFVF_SPECULAR)
3329 WineD3DStrided.u.s.specular.lpData = D3DDrawPrimStrideData->specular.lpvData;
3330 WineD3DStrided.u.s.specular.dwStride = D3DDrawPrimStrideData->specular.dwStride;
3331 WineD3DStrided.u.s.specular.dwType = WINED3DDECLTYPE_SHORT4;
3334 for( i = 0; i < GET_TEXCOUNT_FROM_FVF(VertexType); i++)
3336 WineD3DStrided.u.s.texCoords[i].lpData = D3DDrawPrimStrideData->textureCoords[i].lpvData;
3337 WineD3DStrided.u.s.texCoords[i].dwStride = D3DDrawPrimStrideData->textureCoords[i].dwStride;
3338 switch(GET_TEXCOORD_SIZE_FROM_FVF(VertexType, i))
3340 case 1: WineD3DStrided.u.s.texCoords[i].dwType = WINED3DDECLTYPE_FLOAT1; break;
3341 case 2: WineD3DStrided.u.s.texCoords[i].dwType = WINED3DDECLTYPE_FLOAT2; break;
3342 case 3: WineD3DStrided.u.s.texCoords[i].dwType = WINED3DDECLTYPE_FLOAT3; break;
3343 case 4: WineD3DStrided.u.s.texCoords[i].dwType = WINED3DDECLTYPE_FLOAT4; break;
3344 default: ERR("Unexpected texture coordinate size %d\n",
3345 GET_TEXCOORD_SIZE_FROM_FVF(VertexType, i));
3349 /* Get the primitive count */
3350 switch(PrimitiveType)
3352 case D3DPT_POINTLIST:
3353 PrimitiveCount = VertexCount;
3356 case D3DPT_LINELIST:
3357 PrimitiveCount = VertexCount / 2;
3360 case D3DPT_LINESTRIP:
3361 PrimitiveCount = VertexCount - 1;
3364 case D3DPT_TRIANGLELIST:
3365 PrimitiveCount = VertexCount / 3;
3368 case D3DPT_TRIANGLESTRIP:
3369 PrimitiveCount = VertexCount - 2;
3372 case D3DPT_TRIANGLEFAN:
3373 PrimitiveCount = VertexCount - 2;
3376 default: return DDERR_INVALIDPARAMS;
3379 IWineD3DDevice_SetFVF(This->wineD3DDevice,
3382 return IWineD3DDevice_DrawPrimitiveStrided(This->wineD3DDevice,
3388 static HRESULT WINAPI
3389 Thunk_IDirect3DDeviceImpl_3_DrawPrimitiveStrided(IDirect3DDevice3 *iface,
3390 D3DPRIMITIVETYPE PrimitiveType,
3392 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3396 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3397 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Flags);
3398 return IDirect3DDevice7_DrawPrimitiveStrided(ICOM_INTERFACE(This, IDirect3DDevice7),
3401 D3DDrawPrimStrideData,
3406 /*****************************************************************************
3407 * IDirect3DDevice7::DrawIndexedPrimitiveStrided
3409 * Draws primitives specified by strided data locations based on indices
3417 * D3D_OK, because it's a stub
3418 * (DDERR_INVALIDPARAMS if D3DDrawPrimStrideData is NULL)
3419 * (DDERR_INVALIDPARAMS if Indices is NULL)
3420 * (For more details, see IWineD3DDevice::DrawIndexedPrimitiveStrided)
3422 *****************************************************************************/
3423 static HRESULT WINAPI
3424 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveStrided(IDirect3DDevice7 *iface,
3425 D3DPRIMITIVETYPE PrimitiveType,
3427 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3433 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3434 FIXME("(%p)->(%08x,%08x,%p,%08x,%p,%08x,%08x): stub!\n", This, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Indices, IndexCount, Flags);
3436 /* I'll implement it as soon as I find a app to test it.
3437 * This needs an additional method in IWineD3DDevice.
3442 static HRESULT WINAPI
3443 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitiveStrided(IDirect3DDevice3 *iface,
3444 D3DPRIMITIVETYPE PrimitiveType,
3446 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3452 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3453 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", iface, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Indices, IndexCount, Flags);
3454 return IDirect3DDevice7_DrawIndexedPrimitiveStrided(ICOM_INTERFACE(This, IDirect3DDevice7),
3457 D3DDrawPrimStrideData,
3464 /*****************************************************************************
3465 * IDirect3DDevice7::DrawPrimitiveVB
3467 * Draws primitives from a vertex buffer to the screen.
3472 * PrimitiveType: Type of primitive to be rendered.
3473 * D3DVertexBuf: Source Vertex Buffer
3474 * StartVertex: Index of the first vertex from the buffer to be rendered
3475 * NumVertices: Number of vertices to be rendered
3476 * Flags: Can be D3DDP_WAIT to wait until rendering has finished
3480 * DDERR_INVALIDPARAMS if D3DVertexBuf is NULL
3482 *****************************************************************************/
3483 static HRESULT WINAPI
3484 IDirect3DDeviceImpl_7_DrawPrimitiveVB(IDirect3DDevice7 *iface,
3485 D3DPRIMITIVETYPE PrimitiveType,
3486 IDirect3DVertexBuffer7 *D3DVertexBuf,
3491 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3492 IDirect3DVertexBufferImpl *vb = ICOM_OBJECT(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, D3DVertexBuf);
3493 UINT PrimitiveCount;
3496 WINED3DVERTEXBUFFER_DESC Desc;
3498 TRACE("(%p)->(%08x,%p,%08x,%08x,%08x)\n", This, PrimitiveType, D3DVertexBuf, StartVertex, NumVertices, Flags);
3503 ERR("(%p) No Vertex buffer specified\n", This);
3504 return DDERR_INVALIDPARAMS;
3507 /* Get the primitive count */
3508 switch(PrimitiveType)
3510 case D3DPT_POINTLIST:
3511 PrimitiveCount = NumVertices;
3514 case D3DPT_LINELIST:
3515 PrimitiveCount = NumVertices / 2;
3518 case D3DPT_LINESTRIP:
3519 PrimitiveCount = NumVertices - 1;
3522 case D3DPT_TRIANGLELIST:
3523 PrimitiveCount = NumVertices / 3;
3526 case D3DPT_TRIANGLESTRIP:
3527 PrimitiveCount = NumVertices - 2;
3530 case D3DPT_TRIANGLEFAN:
3531 PrimitiveCount = NumVertices - 2;
3534 default: return DDERR_INVALIDPARAMS;
3537 /* Get the FVF of the vertex buffer, and its stride */
3538 hr = IWineD3DVertexBuffer_GetDesc(vb->wineD3DVertexBuffer,
3542 ERR("(%p) IWineD3DVertexBuffer::GetDesc failed with hr = %08x\n", This, hr);
3545 stride = get_flexible_vertex_size(Desc.FVF);
3547 hr = IWineD3DDevice_SetFVF(This->wineD3DDevice, Desc.FVF);
3550 ERR(" (%p) Setting the FVF failed, hr = %x!\n", This, hr);
3554 /* Set the vertex stream source */
3555 hr = IWineD3DDevice_SetStreamSource(This->wineD3DDevice,
3556 0 /* StreamNumber */,
3557 vb->wineD3DVertexBuffer,
3558 0 /* StartVertex - we pass this to DrawPrimitive */,
3562 ERR("(%p) IDirect3DDevice::SetStreamSource failed with hr = %08x\n", This, hr);
3566 /* Now draw the primitives */
3567 return IWineD3DDevice_DrawPrimitive(This->wineD3DDevice,
3573 static HRESULT WINAPI
3574 Thunk_IDirect3DDeviceImpl_3_DrawPrimitiveVB(IDirect3DDevice3 *iface,
3575 D3DPRIMITIVETYPE PrimitiveType,
3576 IDirect3DVertexBuffer *D3DVertexBuf,
3581 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3582 IDirect3DVertexBufferImpl *vb = ICOM_OBJECT(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, D3DVertexBuf);
3583 TRACE_(ddraw_thunk)("(%p)->(%08x,%p,%08x,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, vb, StartVertex, NumVertices, Flags);
3584 return IDirect3DDevice7_DrawPrimitiveVB(ICOM_INTERFACE(This, IDirect3DDevice7),
3586 ICOM_INTERFACE(vb, IDirect3DVertexBuffer7),
3593 /*****************************************************************************
3594 * IDirect3DDevice7::DrawIndexedPrimitiveVB
3596 * Draws primitives from a vertex buffer to the screen
3599 * PrimitiveType: Type of primitive to be rendered.
3600 * D3DVertexBuf: Source Vertex Buffer
3601 * StartVertex: Index of the first vertex from the buffer to be rendered
3602 * NumVertices: Number of vertices to be rendered
3603 * Indices: Array of DWORDs used to index into the Vertices
3604 * IndexCount: Number of indices in Indices
3605 * Flags: Can be D3DDP_WAIT to wait until rendering has finished
3609 *****************************************************************************/
3610 static HRESULT WINAPI
3611 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface,
3612 D3DPRIMITIVETYPE PrimitiveType,
3613 IDirect3DVertexBuffer7 *D3DVertexBuf,
3620 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3621 IDirect3DVertexBufferImpl *vb = ICOM_OBJECT(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, D3DVertexBuf);
3623 UINT PrimitiveCount;
3624 WORD *LockedIndices;
3626 WINED3DVERTEXBUFFER_DESC Desc;
3628 TRACE("(%p)->(%08x,%p,%d,%d,%p,%d,%08x)\n", This, PrimitiveType, vb, StartVertex, NumVertices, Indices, IndexCount, Flags);
3631 * 1) Calculate some things: Vertex count -> Primitive count, stride, ...
3632 * 2) Upload the Indices to the index buffer
3633 * 3) Set the index source
3634 * 4) Set the Vertex Buffer as the Stream source
3635 * 5) Call IWineD3DDevice::DrawIndexedPrimitive
3638 /* Get the primitive count */
3639 switch(PrimitiveType)
3641 case D3DPT_POINTLIST:
3642 PrimitiveCount = IndexCount;
3645 case D3DPT_LINELIST:
3646 PrimitiveCount = IndexCount / 2;
3649 case D3DPT_LINESTRIP:
3650 PrimitiveCount = IndexCount - 1;
3653 case D3DPT_TRIANGLELIST:
3654 PrimitiveCount = IndexCount / 3;
3657 case D3DPT_TRIANGLESTRIP:
3658 PrimitiveCount = IndexCount - 2;
3661 case D3DPT_TRIANGLEFAN:
3662 PrimitiveCount = IndexCount - 2;
3665 default: return DDERR_INVALIDPARAMS;
3668 /* Get the FVF of the vertex buffer, and its stride */
3669 hr = IWineD3DVertexBuffer_GetDesc(vb->wineD3DVertexBuffer,
3673 ERR("(%p) IWineD3DVertexBuffer::GetDesc failed with hr = %08x\n", This, hr);
3676 stride = get_flexible_vertex_size(Desc.FVF);
3677 TRACE("Vertex buffer FVF = %08x, stride=%d\n", Desc.FVF, stride);
3679 hr = IWineD3DDevice_SetFVF(This->wineD3DDevice, Desc.FVF);
3682 ERR(" (%p) Setting the FVF failed, hr = %x!\n", This, hr);
3686 /* copy the index stream into the index buffer.
3687 * A new IWineD3DDevice method could be created
3688 * which takes an user pointer containing the indices
3689 * or a SetData-Method for the index buffer, which
3690 * overrides the index buffer data with our pointer.
3692 hr = IWineD3DIndexBuffer_Lock(This->indexbuffer,
3693 0 /* OffSetToLock */,
3694 IndexCount * sizeof(WORD),
3695 (BYTE **) &LockedIndices,
3697 assert(IndexCount < 0x100000);
3700 ERR("(%p) IWineD3DIndexBuffer::Lock failed with hr = %08x\n", This, hr);
3703 memcpy(LockedIndices, Indices, IndexCount * sizeof(WORD));
3704 hr = IWineD3DIndexBuffer_Unlock(This->indexbuffer);
3707 ERR("(%p) IWineD3DIndexBuffer::Unlock failed with hr = %08x\n", This, hr);
3711 /* Set the index stream */
3712 hr = IWineD3DDevice_SetIndices(This->wineD3DDevice,
3716 /* Set the vertex stream source */
3717 hr = IWineD3DDevice_SetStreamSource(This->wineD3DDevice,
3718 0 /* StreamNumber */,
3719 vb->wineD3DVertexBuffer,
3720 0 /* offset, we pass this to DrawIndexedPrimitive */,
3724 ERR("(%p) IDirect3DDevice::SetStreamSource failed with hr = %08x\n", This, hr);
3729 hr = IWineD3DDevice_DrawIndexedPrimitive(This->wineD3DDevice,
3739 static HRESULT WINAPI
3740 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitiveVB(IDirect3DDevice3 *iface,
3741 D3DPRIMITIVETYPE PrimitiveType,
3742 IDirect3DVertexBuffer *D3DVertexBuf,
3747 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3748 IDirect3DVertexBufferImpl *VB = ICOM_OBJECT(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, D3DVertexBuf);
3749 TRACE_(ddraw_thunk)("(%p)->(%08x,%p,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VB, Indices, IndexCount, Flags);
3751 return IDirect3DDevice7_DrawIndexedPrimitiveVB(ICOM_INTERFACE(This, IDirect3DDevice7),
3753 ICOM_INTERFACE(VB, IDirect3DVertexBuffer7),
3761 /*****************************************************************************
3762 * IDirect3DDevice7::ComputeSphereVisibility
3764 * Calculates the visibility of spheres in the current viewport. The spheres
3765 * are passed in the Centers and Radii arrays, the results are passed back
3766 * in the ReturnValues array. Return values are either completely visible,
3767 * partially visible or completely invisible.
3768 * The return value consist of a combination of D3DCLIP_* flags, or it's
3769 * 0 if the sphere is completely visible(according to the SDK, not checked)
3771 * Sounds like an overdose of math ;)
3776 * Centers: Array containing the sphere centers
3777 * Radii: Array containing the sphere radii
3778 * NumSpheres: The number of centers and radii in the arrays
3780 * ReturnValues: Array to write the results to
3783 * D3D_OK because it's a stub
3784 * (DDERR_INVALIDPARAMS if Centers, Radii or ReturnValues are NULL)
3785 * (D3DERR_INVALIDMATRIX if the combined world, view and proj matrix
3788 *****************************************************************************/
3789 static HRESULT WINAPI
3790 IDirect3DDeviceImpl_7_ComputeSphereVisibility(IDirect3DDevice7 *iface,
3795 DWORD *ReturnValues)
3797 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3798 FIXME("(%p)->(%p,%p,%08x,%08x,%p): stub!\n", This, Centers, Radii, NumSpheres, Flags, ReturnValues);
3800 /* the DirectX 7 sdk says that the visibility is computed by
3801 * back-transforming the viewing frustum to model space
3802 * using the inverse of the combined world, view and projection
3803 * matrix. If the matrix can't be reversed, D3DERR_INVALIDMATRIX
3806 * Basic implementation idea:
3807 * 1) Check if the center is in the viewing frustum
3808 * 2) Cut the sphere with the planes of the viewing
3811 * ->Center inside the frustum, no intersections:
3813 * ->Center outside the frustum, no intersections:
3815 * ->Some intersections: Partially visible
3817 * Implement this call in WineD3D. Either implement the
3818 * matrix and vector stuff in WineD3D, or use some external
3825 static HRESULT WINAPI
3826 Thunk_IDirect3DDeviceImpl_3_ComputeSphereVisibility(IDirect3DDevice3 *iface,
3831 DWORD *ReturnValues)
3833 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3834 TRACE_(ddraw_thunk)("(%p)->(%p,%p,%08x,%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, Centers, Radii, NumSpheres, Flags, ReturnValues);
3835 return IDirect3DDevice7_ComputeSphereVisibility(ICOM_INTERFACE(This, IDirect3DDevice7),
3843 /*****************************************************************************
3844 * IDirect3DDevice7::GetTexture
3846 * Returns the texture interface handle assigned to a texture stage.
3847 * The returned texture is AddRefed. This is taken from old ddraw,
3848 * not checked in Windows.
3853 * Stage: Texture stage to read the texture from
3854 * Texture: Address to store the interface pointer at
3858 * DDERR_INVALIDPARAMS if Texture is NULL
3859 * For details, see IWineD3DDevice::GetTexture
3861 *****************************************************************************/
3862 static HRESULT WINAPI
3863 IDirect3DDeviceImpl_7_GetTexture(IDirect3DDevice7 *iface,
3865 IDirectDrawSurface7 **Texture)
3867 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3868 IWineD3DBaseTexture *Surf;
3870 TRACE("(%p)->(%d,%p): Relay\n", This, Stage, Texture);
3874 TRACE("Texture == NULL, failing with DDERR_INVALIDPARAMS\n");
3875 return DDERR_INVALIDPARAMS;
3878 hr = IWineD3DDevice_GetTexture(This->wineD3DDevice, Stage, (IWineD3DBaseTexture **) &Surf);
3879 if( (hr != D3D_OK) || (!Surf) )
3885 /* GetParent AddRef()s, which is perfectly OK.
3886 * We have passed the IDirectDrawSurface7 interface to WineD3D, so that's OK too.
3888 return IWineD3DBaseTexture_GetParent(Surf,
3889 (IUnknown **) Texture);
3892 static HRESULT WINAPI
3893 Thunk_IDirect3DDeviceImpl_3_GetTexture(IDirect3DDevice3 *iface,
3895 IDirect3DTexture2 **Texture2)
3897 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3899 IDirectDrawSurface7 *ret_val;
3901 TRACE_(ddraw_thunk)("(%p)->(%d,%p) thunking to IDirect3DDevice7 interface.\n", This, Stage, Texture2);
3902 ret = IDirect3DDevice7_GetTexture(ICOM_INTERFACE(This, IDirect3DDevice7),
3906 *Texture2 = COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7, IDirect3DTexture2, ret_val);
3908 TRACE_(ddraw_thunk)(" returning interface %p.\n", *Texture2);
3913 /*****************************************************************************
3914 * IDirect3DDevice7::SetTexture
3916 * Assigns a texture to a texture stage. Is the texture AddRef-ed?
3921 * Stage: The stage to assign the texture to
3922 * Texture: Interface pointer to the texture surface
3926 * For details, see IWineD3DDevice::SetTexture
3928 *****************************************************************************/
3929 static HRESULT WINAPI
3930 IDirect3DDeviceImpl_7_SetTexture(IDirect3DDevice7 *iface,
3932 IDirectDrawSurface7 *Texture)
3934 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3935 IDirectDrawSurfaceImpl *surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Texture);
3936 TRACE("(%p)->(%08x,%p): Relay!\n", This, Stage, surf);
3938 /* Texture may be NULL here */
3939 return IWineD3DDevice_SetTexture(This->wineD3DDevice,
3941 surf ? (IWineD3DBaseTexture * ) surf->wineD3DTexture : NULL);
3944 static HRESULT WINAPI
3945 Thunk_IDirect3DDeviceImpl_3_SetTexture(IDirect3DDevice3 *iface,
3947 IDirect3DTexture2 *Texture2)
3949 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3950 IDirectDrawSurfaceImpl *tex = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture2, Texture2);
3951 TRACE_(ddraw_thunk)("(%p)->(%d,%p) thunking to IDirect3DDevice7 interface.\n", This, Stage, tex);
3952 return IDirect3DDevice7_SetTexture(ICOM_INTERFACE(This, IDirect3DDevice7),
3954 ICOM_INTERFACE(tex, IDirectDrawSurface7));
3957 /*****************************************************************************
3958 * IDirect3DDevice7::GetTextureStageState
3960 * Retrieves a state from a texture stage.
3965 * Stage: The stage to retrieve the state from
3966 * TexStageStateType: The state type to retrieve
3967 * State: Address to store the state's value at
3971 * DDERR_INVALIDPARAMS if State is NULL
3972 * For details, see IWineD3DDevice::GetTextureStageState
3974 *****************************************************************************/
3975 static HRESULT WINAPI
3976 IDirect3DDeviceImpl_7_GetTextureStageState(IDirect3DDevice7 *iface,
3978 D3DTEXTURESTAGESTATETYPE TexStageStateType,
3981 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3982 TRACE("(%p)->(%08x,%08x,%p): Relay!\n", This, Stage, TexStageStateType, State);
3985 return DDERR_INVALIDPARAMS;
3987 switch(TexStageStateType)
3989 /* Mipfilter is a sampler state with different values */
3990 case D3DTSS_MIPFILTER:
3993 WINED3DTEXTUREFILTERTYPE value;
3995 hr = IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
3997 WINED3DSAMP_MIPFILTER,
4001 case WINED3DTEXF_NONE: *State = D3DTFP_NONE; break;
4002 case WINED3DTEXF_POINT: *State = D3DTFP_POINT; break;
4003 case WINED3DTEXF_LINEAR: *State = D3DTFP_LINEAR; break;
4005 ERR("Unexpected mipfilter value %d\n", value);
4006 *State = D3DTFP_NONE;
4011 /* Minfilter is a sampler state too, equal values */
4012 case D3DTSS_MINFILTER:
4013 return IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
4015 WINED3DSAMP_MINFILTER,
4017 /* Same for MAGFILTER */
4018 case D3DTSS_MAGFILTER:
4019 return IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
4021 WINED3DSAMP_MAGFILTER,
4024 case D3DTSS_ADDRESS:
4025 case D3DTSS_ADDRESSU:
4026 return IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
4028 WINED3DSAMP_ADDRESSU,
4030 case D3DTSS_ADDRESSV:
4031 return IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
4033 WINED3DSAMP_ADDRESSV,
4036 return IWineD3DDevice_GetTextureStageState(This->wineD3DDevice,
4043 static HRESULT WINAPI
4044 Thunk_IDirect3DDeviceImpl_3_GetTextureStageState(IDirect3DDevice3 *iface,
4046 D3DTEXTURESTAGESTATETYPE TexStageStateType,
4049 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
4050 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, Stage, TexStageStateType, State);
4051 return IDirect3DDevice7_GetTextureStageState(ICOM_INTERFACE(This, IDirect3DDevice7),
4057 /*****************************************************************************
4058 * IDirect3DDevice7::SetTextureStageState
4060 * Sets a texture stage state. Some stage types need to be handled specially,
4061 * because they do not exist in WineD3D and were moved to another place
4066 * Stage: The stage to modify
4067 * TexStageStateType: The state to change
4068 * State: The new value for the state
4072 * For details, see IWineD3DDevice::SetTextureStageState
4074 *****************************************************************************/
4075 static HRESULT WINAPI
4076 IDirect3DDeviceImpl_7_SetTextureStageState(IDirect3DDevice7 *iface,
4078 D3DTEXTURESTAGESTATETYPE TexStageStateType,
4081 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4082 TRACE("(%p)->(%08x,%08x,%08x): Relay!\n", This, Stage, TexStageStateType, State);
4083 switch(TexStageStateType)
4085 /* Mipfilter is a sampler state with different values */
4086 case D3DTSS_MIPFILTER:
4088 WINED3DTEXTUREFILTERTYPE value;
4091 case D3DTFP_NONE: value = WINED3DTEXF_NONE; break;
4092 case D3DTFP_POINT: value = WINED3DTEXF_POINT; break;
4093 case 0: /* Unchecked */
4094 case D3DTFP_LINEAR: value = WINED3DTEXF_LINEAR; break;
4096 ERR("Unexpected mipfilter value %d\n", State);
4097 value = WINED3DTEXF_NONE;
4099 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
4101 WINED3DSAMP_MIPFILTER,
4105 /* Minfilter is a sampler state too, equal values */
4106 case D3DTSS_MINFILTER:
4107 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
4109 WINED3DSAMP_MINFILTER,
4111 /* Same for MAGFILTER */
4112 case D3DTSS_MAGFILTER:
4113 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
4115 WINED3DSAMP_MAGFILTER,
4118 case D3DTSS_ADDRESS:
4119 IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
4121 WINED3DSAMP_ADDRESSV,
4124 case D3DTSS_ADDRESSU:
4125 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
4127 WINED3DSAMP_ADDRESSU,
4129 case D3DTSS_ADDRESSV:
4130 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
4132 WINED3DSAMP_ADDRESSV,
4136 return IWineD3DDevice_SetTextureStageState(This->wineD3DDevice,
4143 static HRESULT WINAPI
4144 Thunk_IDirect3DDeviceImpl_3_SetTextureStageState(IDirect3DDevice3 *iface,
4146 D3DTEXTURESTAGESTATETYPE TexStageStateType,
4149 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
4150 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, Stage, TexStageStateType, State);
4151 return IDirect3DDevice7_SetTextureStageState(ICOM_INTERFACE(This, IDirect3DDevice7),
4157 /*****************************************************************************
4158 * IDirect3DDevice7::ValidateDevice
4160 * SDK: "Reports the device's ability to render the currently set
4161 * texture-blending operations in a single pass". Whatever that means
4167 * NumPasses: Address to write the number of necessary passes for the
4168 * desired effect to.
4172 * See IWineD3DDevice::ValidateDevice for more details
4174 *****************************************************************************/
4175 static HRESULT WINAPI
4176 IDirect3DDeviceImpl_7_ValidateDevice(IDirect3DDevice7 *iface,
4179 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4180 TRACE("(%p)->(%p): Relay\n", This, NumPasses);
4182 return IWineD3DDevice_ValidateDevice(This->wineD3DDevice, NumPasses);
4185 static HRESULT WINAPI
4186 Thunk_IDirect3DDeviceImpl_3_ValidateDevice(IDirect3DDevice3 *iface,
4189 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
4190 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, Passes);
4191 return IDirect3DDevice7_ValidateDevice(ICOM_INTERFACE(This, IDirect3DDevice7),
4195 /*****************************************************************************
4196 * IDirect3DDevice7::Clear
4198 * Fills the render target, the z buffer and the stencil buffer with a
4199 * clear color / value
4204 * Count: Number of rectangles in Rects must be 0 if Rects is NULL
4205 * Rects: Rectangles to clear. If NULL, the whole surface is cleared
4206 * Flags: Some flags, as usual
4207 * Color: Clear color for the render target
4208 * Z: Clear value for the Z buffer
4209 * Stencil: Clear value to store in each stencil buffer entry
4213 * For details, see IWineD3DDevice::Clear
4215 *****************************************************************************/
4216 static HRESULT WINAPI
4217 IDirect3DDeviceImpl_7_Clear(IDirect3DDevice7 *iface,
4225 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4226 TRACE("(%p)->(%08x,%p,%08x,%08x,%f,%08x): Relay\n", This, Count, Rects, Flags, (DWORD) Color, Z, Stencil);
4228 /* Note; D3DRECT is compatible with WINED3DRECT */
4229 return IWineD3DDevice_Clear(This->wineD3DDevice, Count, (WINED3DRECT*) Rects, Flags, Color, Z, Stencil);
4232 /*****************************************************************************
4233 * IDirect3DDevice7::SetViewport
4235 * Sets the current viewport.
4237 * Version 7 only, but IDirect3DViewport uses this call for older
4241 * Data: The new viewport to set
4245 * DDERR_INVALIDPARAMS if Data is NULL
4246 * For more details, see IWineDDDevice::SetViewport
4248 *****************************************************************************/
4249 static HRESULT WINAPI
4250 IDirect3DDeviceImpl_7_SetViewport(IDirect3DDevice7 *iface,
4253 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4254 TRACE("(%p)->(%p) Relay!\n", This, Data);
4257 return DDERR_INVALIDPARAMS;
4259 /* Note: D3DVIEWPORT7 is compatible with WINED3DVIEWPORT */
4260 return IWineD3DDevice_SetViewport(This->wineD3DDevice,
4261 (WINED3DVIEWPORT*) Data);
4264 /*****************************************************************************
4265 * IDirect3DDevice::GetViewport
4267 * Returns the current viewport
4272 * Data: D3D7Viewport structure to write the viewport information to
4276 * DDERR_INVALIDPARAMS if Data is NULL
4277 * For more details, see IWineD3DDevice::GetViewport
4279 *****************************************************************************/
4280 static HRESULT WINAPI
4281 IDirect3DDeviceImpl_7_GetViewport(IDirect3DDevice7 *iface,
4284 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4286 TRACE("(%p)->(%p) Relay!\n", This, Data);
4289 return DDERR_INVALIDPARAMS;
4291 /* Note: D3DVIEWPORT7 is compatible with WINED3DVIEWPORT */
4292 hr = IWineD3DDevice_GetViewport(This->wineD3DDevice,
4293 (WINED3DVIEWPORT*) Data);
4295 return hr_ddraw_from_wined3d(hr);
4298 /*****************************************************************************
4299 * IDirect3DDevice7::SetMaterial
4306 * Mat: The material to set
4310 * DDERR_INVALIDPARAMS if Mat is NULL.
4311 * For more details, see IWineD3DDevice::SetMaterial
4313 *****************************************************************************/
4314 static HRESULT WINAPI
4315 IDirect3DDeviceImpl_7_SetMaterial(IDirect3DDevice7 *iface,
4318 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4320 TRACE("(%p)->(%p): Relay!\n", This, Mat);
4322 /* Note: D3DMATERIAL7 is compatible with WINED3DMATERIAL */
4323 hr = IWineD3DDevice_SetMaterial(This->wineD3DDevice,
4324 (WINED3DMATERIAL*) Mat);
4326 return hr_ddraw_from_wined3d(hr);
4329 /*****************************************************************************
4330 * IDirect3DDevice7::GetMaterial
4332 * Returns the current material
4337 * Mat: D3DMATERIAL7 structure to write the material parameters to
4341 * DDERR_INVALIDPARAMS if Mat is NULL
4342 * For more details, see IWineD3DDevice::GetMaterial
4344 *****************************************************************************/
4345 static HRESULT WINAPI
4346 IDirect3DDeviceImpl_7_GetMaterial(IDirect3DDevice7 *iface,
4349 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4351 TRACE("(%p)->(%p): Relay!\n", This, Mat);
4353 /* Note: D3DMATERIAL7 is compatible with WINED3DMATERIAL */
4354 hr = IWineD3DDevice_GetMaterial(This->wineD3DDevice,
4355 (WINED3DMATERIAL*) Mat);
4357 return hr_ddraw_from_wined3d(hr);
4360 /*****************************************************************************
4361 * IDirect3DDevice7::SetLight
4363 * Assigns a light to a light index, but doesn't activate it yet.
4365 * Version 7, IDirect3DLight uses this method for older versions
4368 * LightIndex: The index of the new light
4369 * Light: A D3DLIGHT7 structure describing the light
4373 * For more details, see IWineD3DDevice::SetLight
4375 *****************************************************************************/
4376 static HRESULT WINAPI
4377 IDirect3DDeviceImpl_7_SetLight(IDirect3DDevice7 *iface,
4381 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4383 TRACE("(%p)->(%08x,%p): Relay!\n", This, LightIndex, Light);
4385 /* Note: D3DLIGHT7 is compatible with WINED3DLIGHT */
4386 hr = IWineD3DDevice_SetLight(This->wineD3DDevice,
4388 (WINED3DLIGHT*) Light);
4390 return hr_ddraw_from_wined3d(hr);
4393 /*****************************************************************************
4394 * IDirect3DDevice7::GetLight
4396 * Returns the light assigned to a light index
4399 * Light: Structure to write the light information to
4403 * DDERR_INVALIDPARAMS if Light is NULL
4404 * For details, see IWineD3DDevice::GetLight
4406 *****************************************************************************/
4407 static HRESULT WINAPI
4408 IDirect3DDeviceImpl_7_GetLight(IDirect3DDevice7 *iface,
4412 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4414 TRACE("(%p)->(%08x,%p): Relay!\n", This, LightIndex, Light);
4416 /* Note: D3DLIGHT7 is compatible with WINED3DLIGHT */
4417 rc = IWineD3DDevice_GetLight(This->wineD3DDevice,
4419 (WINED3DLIGHT*) Light);
4421 /* Translate the result. WineD3D returns other values than D3D7 */
4422 return hr_ddraw_from_wined3d(rc);
4425 /*****************************************************************************
4426 * IDirect3DDevice7::BeginStateBlock
4428 * Begins recording to a stateblock
4434 * For details see IWineD3DDevice::BeginStateBlock
4436 *****************************************************************************/
4437 static HRESULT WINAPI
4438 IDirect3DDeviceImpl_7_BeginStateBlock(IDirect3DDevice7 *iface)
4440 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4442 TRACE("(%p)->(): Relay!\n", This);
4444 hr = IWineD3DDevice_BeginStateBlock(This->wineD3DDevice);
4445 return hr_ddraw_from_wined3d(hr);
4448 /*****************************************************************************
4449 * IDirect3DDevice7::EndStateBlock
4451 * Stops recording to a state block and returns the created stateblock
4457 * BlockHandle: Address to store the stateblock's handle to
4461 * DDERR_INVALIDPARAMS if BlockHandle is NULL
4462 * See IWineD3DDevice::EndStateBlock for more details
4464 *****************************************************************************/
4465 static HRESULT WINAPI
4466 IDirect3DDeviceImpl_7_EndStateBlock(IDirect3DDevice7 *iface,
4469 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4471 TRACE("(%p)->(%p): Relay!\n", This, BlockHandle);
4475 WARN("BlockHandle == NULL, returning DDERR_INVALIDPARAMS\n");
4476 return DDERR_INVALIDPARAMS;
4479 *BlockHandle = IDirect3DDeviceImpl_CreateHandle(This);
4482 ERR("Cannot get a handle number for the stateblock\n");
4483 return DDERR_OUTOFMEMORY;
4485 This->Handles[*BlockHandle - 1].type = DDrawHandle_StateBlock;
4486 hr = IWineD3DDevice_EndStateBlock(This->wineD3DDevice,
4487 (IWineD3DStateBlock **) &This->Handles[*BlockHandle - 1].ptr);
4488 return hr_ddraw_from_wined3d(hr);
4491 /*****************************************************************************
4492 * IDirect3DDevice7::PreLoad
4494 * Allows the app to signal that a texture will be used soon, to allow
4495 * the Direct3DDevice to load it to the video card in the meantime.
4500 * Texture: The texture to preload
4504 * DDERR_INVALIDPARAMS if Texture is NULL
4505 * See IWineD3DSurface::PreLoad for details
4507 *****************************************************************************/
4508 static HRESULT WINAPI
4509 IDirect3DDeviceImpl_7_PreLoad(IDirect3DDevice7 *iface,
4510 IDirectDrawSurface7 *Texture)
4512 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4513 IDirectDrawSurfaceImpl *surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Texture);
4515 TRACE("(%p)->(%p): Relay!\n", This, surf);
4518 return DDERR_INVALIDPARAMS;
4520 IWineD3DSurface_PreLoad(surf->WineD3DSurface);
4524 /*****************************************************************************
4525 * IDirect3DDevice7::ApplyStateBlock
4527 * Activates the state stored in a state block handle.
4530 * BlockHandle: The stateblock handle to activate
4534 * D3DERR_INVALIDSTATEBLOCK if BlockHandle is NULL
4536 *****************************************************************************/
4537 static HRESULT WINAPI
4538 IDirect3DDeviceImpl_7_ApplyStateBlock(IDirect3DDevice7 *iface,
4541 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4543 TRACE("(%p)->(%08x): Relay!\n", This, BlockHandle);
4545 if(!BlockHandle || BlockHandle > This->numHandles)
4547 WARN("Out of range handle %d, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
4548 return D3DERR_INVALIDSTATEBLOCK;
4550 if(This->Handles[BlockHandle - 1].type != DDrawHandle_StateBlock)
4552 WARN("Handle %d is not a stateblock, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
4553 return D3DERR_INVALIDSTATEBLOCK;
4556 hr = IWineD3DStateBlock_Apply((IWineD3DStateBlock *) This->Handles[BlockHandle - 1].ptr);
4557 return hr_ddraw_from_wined3d(hr);
4560 /*****************************************************************************
4561 * IDirect3DDevice7::CaptureStateBlock
4563 * Updates a stateblock's values to the values currently set for the device
4568 * BlockHandle: Stateblock to update
4572 * D3DERR_INVALIDSTATEBLOCK if BlockHandle is NULL
4573 * See IWineD3DDevice::CaptureStateBlock for more details
4575 *****************************************************************************/
4576 static HRESULT WINAPI
4577 IDirect3DDeviceImpl_7_CaptureStateBlock(IDirect3DDevice7 *iface,
4580 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4582 TRACE("(%p)->(%08x): Relay!\n", This, BlockHandle);
4584 if(BlockHandle == 0 || BlockHandle > This->numHandles)
4586 WARN("Out of range handle %d, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
4587 return D3DERR_INVALIDSTATEBLOCK;
4589 if(This->Handles[BlockHandle - 1].type != DDrawHandle_StateBlock)
4591 WARN("Handle %d is not a stateblock, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
4592 return D3DERR_INVALIDSTATEBLOCK;
4595 hr = IWineD3DStateBlock_Capture((IWineD3DStateBlock *) This->Handles[BlockHandle - 1].ptr);
4596 return hr_ddraw_from_wined3d(hr);
4599 /*****************************************************************************
4600 * IDirect3DDevice7::DeleteStateBlock
4602 * Deletes a stateblock handle. This means releasing the WineD3DStateBlock
4607 * BlockHandle: Stateblock handle to delete
4611 * D3DERR_INVALIDSTATEBLOCK if BlockHandle is 0
4613 *****************************************************************************/
4614 static HRESULT WINAPI
4615 IDirect3DDeviceImpl_7_DeleteStateBlock(IDirect3DDevice7 *iface,
4618 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4620 TRACE("(%p)->(%08x): Relay!\n", This, BlockHandle);
4622 if(BlockHandle == 0 || BlockHandle > This->numHandles)
4624 WARN("Out of range handle %d, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
4625 return D3DERR_INVALIDSTATEBLOCK;
4627 if(This->Handles[BlockHandle - 1].type != DDrawHandle_StateBlock)
4629 WARN("Handle %d is not a stateblock, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
4630 return D3DERR_INVALIDSTATEBLOCK;
4633 ref = IWineD3DStateBlock_Release((IWineD3DStateBlock *) This->Handles[BlockHandle - 1].ptr);
4636 ERR("Something is still holding the stateblock %p(Handle %d). Ref = %d\n", This->Handles[BlockHandle - 1].ptr, BlockHandle, ref);
4638 This->Handles[BlockHandle - 1].ptr = NULL;
4639 This->Handles[BlockHandle - 1].type = DDrawHandle_Unknown;
4644 /*****************************************************************************
4645 * IDirect3DDevice7::CreateStateBlock
4647 * Creates a new state block handle.
4652 * Type: The state block type
4653 * BlockHandle: Address to write the created handle to
4657 * DDERR_INVALIDPARAMS if BlockHandle is NULL
4659 *****************************************************************************/
4660 static HRESULT WINAPI
4661 IDirect3DDeviceImpl_7_CreateStateBlock(IDirect3DDevice7 *iface,
4662 D3DSTATEBLOCKTYPE Type,
4665 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4667 TRACE("(%p)->(%08x,%p)!\n", This, Type, BlockHandle);
4671 WARN("BlockHandle == NULL, returning DDERR_INVALIDPARAMS\n");
4672 return DDERR_INVALIDPARAMS;
4675 *BlockHandle = IDirect3DDeviceImpl_CreateHandle(This);
4678 ERR("Cannot get a handle number for the stateblock\n");
4679 return DDERR_OUTOFMEMORY;
4681 This->Handles[*BlockHandle - 1].type = DDrawHandle_StateBlock;
4683 /* The D3DSTATEBLOCKTYPE enum is fine here */
4684 hr = IWineD3DDevice_CreateStateBlock(This->wineD3DDevice,
4686 (IWineD3DStateBlock **) &This->Handles[*BlockHandle - 1].ptr,
4687 NULL /* Parent, hope that works */);
4688 return hr_ddraw_from_wined3d(hr);
4691 /*****************************************************************************
4692 * IDirect3DDevice7::Load
4694 * Loads a rectangular area from the source into the destination texture.
4695 * It can also copy the source to the faces of a cubic environment map
4700 * DestTex: Destination texture
4701 * DestPoint: Point in the destination where the source image should be
4703 * SrcTex: Source texture
4704 * SrcRect: Source rectangle
4709 * DDERR_INVALIDPARAMS if DestTex or SrcTex are NULL
4710 * See IDirect3DTexture2::Load for details
4712 *****************************************************************************/
4713 static HRESULT WINAPI
4714 IDirect3DDeviceImpl_7_Load(IDirect3DDevice7 *iface,
4715 IDirectDrawSurface7 *DestTex,
4717 IDirectDrawSurface7 *SrcTex,
4721 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4722 IDirectDrawSurfaceImpl *dest = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DestTex);
4723 IDirectDrawSurfaceImpl *src = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, SrcTex);
4724 FIXME("(%p)->(%p,%p,%p,%p,%08x): Partially Implemented!\n", This, dest, DestPoint, src, SrcRect, Flags);
4726 if( (!src) || (!dest) )
4727 return DDERR_INVALIDPARAMS;
4729 IDirect3DTexture2_Load(ICOM_INTERFACE(dest, IDirect3DTexture2),
4730 ICOM_INTERFACE(src, IDirect3DTexture2));
4734 /*****************************************************************************
4735 * IDirect3DDevice7::LightEnable
4737 * Enables or disables a light
4739 * Version 7, IDirect3DLight uses this method too.
4742 * LightIndex: The index of the light to enable / disable
4743 * Enable: Enable or disable the light
4747 * For more details, see IWineD3DDevice::SetLightEnable
4749 *****************************************************************************/
4750 static HRESULT WINAPI
4751 IDirect3DDeviceImpl_7_LightEnable(IDirect3DDevice7 *iface,
4755 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4757 TRACE("(%p)->(%08x,%d): Relay!\n", This, LightIndex, Enable);
4759 hr = IWineD3DDevice_SetLightEnable(This->wineD3DDevice, LightIndex, Enable);
4760 return hr_ddraw_from_wined3d(hr);
4763 /*****************************************************************************
4764 * IDirect3DDevice7::GetLightEnable
4766 * Retrieves if the light with the given index is enabled or not
4771 * LightIndex: Index of desired light
4772 * Enable: Pointer to a BOOL which contains the result
4776 * DDERR_INVALIDPARAMS if Enable is NULL
4777 * See IWineD3DDevice::GetLightEnable for more details
4779 *****************************************************************************/
4780 static HRESULT WINAPI
4781 IDirect3DDeviceImpl_7_GetLightEnable(IDirect3DDevice7 *iface,
4785 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4787 TRACE("(%p)->(%08x,%p): Relay\n", This, LightIndex, Enable);
4790 return DDERR_INVALIDPARAMS;
4792 hr = IWineD3DDevice_GetLightEnable(This->wineD3DDevice, LightIndex, Enable);
4793 return hr_ddraw_from_wined3d(hr);
4796 /*****************************************************************************
4797 * IDirect3DDevice7::SetClipPlane
4799 * Sets custom clipping plane
4804 * Index: The index of the clipping plane
4805 * PlaneEquation: An equation defining the clipping plane
4809 * DDERR_INVALIDPARAMS if PlaneEquation is NULL
4810 * See IWineD3DDevice::SetClipPlane for more details
4812 *****************************************************************************/
4813 static HRESULT WINAPI
4814 IDirect3DDeviceImpl_7_SetClipPlane(IDirect3DDevice7 *iface,
4816 D3DVALUE* PlaneEquation)
4818 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4819 TRACE("(%p)->(%08x,%p): Relay!\n", This, Index, PlaneEquation);
4822 return DDERR_INVALIDPARAMS;
4824 return IWineD3DDevice_SetClipPlane(This->wineD3DDevice, Index, PlaneEquation);
4827 /*****************************************************************************
4828 * IDirect3DDevice7::GetClipPlane
4830 * Returns the clipping plane with a specific index
4833 * Index: The index of the desired plane
4834 * PlaneEquation: Address to store the plane equation to
4838 * DDERR_INVALIDPARAMS if PlaneEquation is NULL
4839 * See IWineD3DDevice::GetClipPlane for more details
4841 *****************************************************************************/
4842 static HRESULT WINAPI
4843 IDirect3DDeviceImpl_7_GetClipPlane(IDirect3DDevice7 *iface,
4845 D3DVALUE* PlaneEquation)
4847 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4848 TRACE("(%p)->(%d,%p): Relay!\n", This, Index, PlaneEquation);
4851 return DDERR_INVALIDPARAMS;
4853 return IWineD3DDevice_GetClipPlane(This->wineD3DDevice, Index, PlaneEquation);
4856 /*****************************************************************************
4857 * IDirect3DDevice7::GetInfo
4859 * Retrieves some information about the device. The DirectX sdk says that
4860 * this version returns S_FALSE for all retail builds of DirectX, that's what
4861 * this implementation does.
4864 * DevInfoID: Information type requested
4865 * DevInfoStruct: Pointer to a structure to store the info to
4866 * Size: Size of the structure
4869 * S_FALSE, because it's a non-debug driver
4871 *****************************************************************************/
4872 static HRESULT WINAPI
4873 IDirect3DDeviceImpl_7_GetInfo(IDirect3DDevice7 *iface,
4875 void *DevInfoStruct,
4878 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4879 TRACE("(%p)->(%08x,%p,%08x)\n", This, DevInfoID, DevInfoStruct, Size);
4883 TRACE(" info requested : ");
4886 case D3DDEVINFOID_TEXTUREMANAGER: TRACE("D3DDEVINFOID_TEXTUREMANAGER\n"); break;
4887 case D3DDEVINFOID_D3DTEXTUREMANAGER: TRACE("D3DDEVINFOID_D3DTEXTUREMANAGER\n"); break;
4888 case D3DDEVINFOID_TEXTURING: TRACE("D3DDEVINFOID_TEXTURING\n"); break;
4889 default: ERR(" invalid flag !!!\n"); return DDERR_INVALIDPARAMS;
4893 return S_FALSE; /* According to MSDN, this is valid for a non-debug driver */
4896 const IDirect3DDevice7Vtbl IDirect3DDevice7_Vtbl =
4898 /*** IUnknown Methods ***/
4899 IDirect3DDeviceImpl_7_QueryInterface,
4900 IDirect3DDeviceImpl_7_AddRef,
4901 IDirect3DDeviceImpl_7_Release,
4902 /*** IDirect3DDevice7 ***/
4903 IDirect3DDeviceImpl_7_GetCaps,
4904 IDirect3DDeviceImpl_7_EnumTextureFormats,
4905 IDirect3DDeviceImpl_7_BeginScene,
4906 IDirect3DDeviceImpl_7_EndScene,
4907 IDirect3DDeviceImpl_7_GetDirect3D,
4908 IDirect3DDeviceImpl_7_SetRenderTarget,
4909 IDirect3DDeviceImpl_7_GetRenderTarget,
4910 IDirect3DDeviceImpl_7_Clear,
4911 IDirect3DDeviceImpl_7_SetTransform,
4912 IDirect3DDeviceImpl_7_GetTransform,
4913 IDirect3DDeviceImpl_7_SetViewport,
4914 IDirect3DDeviceImpl_7_MultiplyTransform,
4915 IDirect3DDeviceImpl_7_GetViewport,
4916 IDirect3DDeviceImpl_7_SetMaterial,
4917 IDirect3DDeviceImpl_7_GetMaterial,
4918 IDirect3DDeviceImpl_7_SetLight,
4919 IDirect3DDeviceImpl_7_GetLight,
4920 IDirect3DDeviceImpl_7_SetRenderState,
4921 IDirect3DDeviceImpl_7_GetRenderState,
4922 IDirect3DDeviceImpl_7_BeginStateBlock,
4923 IDirect3DDeviceImpl_7_EndStateBlock,
4924 IDirect3DDeviceImpl_7_PreLoad,
4925 IDirect3DDeviceImpl_7_DrawPrimitive,
4926 IDirect3DDeviceImpl_7_DrawIndexedPrimitive,
4927 IDirect3DDeviceImpl_7_SetClipStatus,
4928 IDirect3DDeviceImpl_7_GetClipStatus,
4929 IDirect3DDeviceImpl_7_DrawPrimitiveStrided,
4930 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveStrided,
4931 IDirect3DDeviceImpl_7_DrawPrimitiveVB,
4932 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB,
4933 IDirect3DDeviceImpl_7_ComputeSphereVisibility,
4934 IDirect3DDeviceImpl_7_GetTexture,
4935 IDirect3DDeviceImpl_7_SetTexture,
4936 IDirect3DDeviceImpl_7_GetTextureStageState,
4937 IDirect3DDeviceImpl_7_SetTextureStageState,
4938 IDirect3DDeviceImpl_7_ValidateDevice,
4939 IDirect3DDeviceImpl_7_ApplyStateBlock,
4940 IDirect3DDeviceImpl_7_CaptureStateBlock,
4941 IDirect3DDeviceImpl_7_DeleteStateBlock,
4942 IDirect3DDeviceImpl_7_CreateStateBlock,
4943 IDirect3DDeviceImpl_7_Load,
4944 IDirect3DDeviceImpl_7_LightEnable,
4945 IDirect3DDeviceImpl_7_GetLightEnable,
4946 IDirect3DDeviceImpl_7_SetClipPlane,
4947 IDirect3DDeviceImpl_7_GetClipPlane,
4948 IDirect3DDeviceImpl_7_GetInfo
4951 const IDirect3DDevice3Vtbl IDirect3DDevice3_Vtbl =
4953 /*** IUnknown Methods ***/
4954 Thunk_IDirect3DDeviceImpl_3_QueryInterface,
4955 Thunk_IDirect3DDeviceImpl_3_AddRef,
4956 Thunk_IDirect3DDeviceImpl_3_Release,
4957 /*** IDirect3DDevice3 ***/
4958 IDirect3DDeviceImpl_3_GetCaps,
4959 IDirect3DDeviceImpl_3_GetStats,
4960 IDirect3DDeviceImpl_3_AddViewport,
4961 IDirect3DDeviceImpl_3_DeleteViewport,
4962 IDirect3DDeviceImpl_3_NextViewport,
4963 Thunk_IDirect3DDeviceImpl_3_EnumTextureFormats,
4964 Thunk_IDirect3DDeviceImpl_3_BeginScene,
4965 Thunk_IDirect3DDeviceImpl_3_EndScene,
4966 Thunk_IDirect3DDeviceImpl_3_GetDirect3D,
4967 IDirect3DDeviceImpl_3_SetCurrentViewport,
4968 IDirect3DDeviceImpl_3_GetCurrentViewport,
4969 Thunk_IDirect3DDeviceImpl_3_SetRenderTarget,
4970 Thunk_IDirect3DDeviceImpl_3_GetRenderTarget,
4971 IDirect3DDeviceImpl_3_Begin,
4972 IDirect3DDeviceImpl_3_BeginIndexed,
4973 IDirect3DDeviceImpl_3_Vertex,
4974 IDirect3DDeviceImpl_3_Index,
4975 IDirect3DDeviceImpl_3_End,
4976 Thunk_IDirect3DDeviceImpl_3_GetRenderState,
4977 Thunk_IDirect3DDeviceImpl_3_SetRenderState,
4978 IDirect3DDeviceImpl_3_GetLightState,
4979 IDirect3DDeviceImpl_3_SetLightState,
4980 Thunk_IDirect3DDeviceImpl_3_SetTransform,
4981 Thunk_IDirect3DDeviceImpl_3_GetTransform,
4982 Thunk_IDirect3DDeviceImpl_3_MultiplyTransform,
4983 Thunk_IDirect3DDeviceImpl_3_DrawPrimitive,
4984 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitive,
4985 Thunk_IDirect3DDeviceImpl_3_SetClipStatus,
4986 Thunk_IDirect3DDeviceImpl_3_GetClipStatus,
4987 Thunk_IDirect3DDeviceImpl_3_DrawPrimitiveStrided,
4988 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitiveStrided,
4989 Thunk_IDirect3DDeviceImpl_3_DrawPrimitiveVB,
4990 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitiveVB,
4991 Thunk_IDirect3DDeviceImpl_3_ComputeSphereVisibility,
4992 Thunk_IDirect3DDeviceImpl_3_GetTexture,
4993 Thunk_IDirect3DDeviceImpl_3_SetTexture,
4994 Thunk_IDirect3DDeviceImpl_3_GetTextureStageState,
4995 Thunk_IDirect3DDeviceImpl_3_SetTextureStageState,
4996 Thunk_IDirect3DDeviceImpl_3_ValidateDevice
4999 const IDirect3DDevice2Vtbl IDirect3DDevice2_Vtbl =
5001 /*** IUnknown Methods ***/
5002 Thunk_IDirect3DDeviceImpl_2_QueryInterface,
5003 Thunk_IDirect3DDeviceImpl_2_AddRef,
5004 Thunk_IDirect3DDeviceImpl_2_Release,
5005 /*** IDirect3DDevice2 ***/
5006 Thunk_IDirect3DDeviceImpl_2_GetCaps,
5007 IDirect3DDeviceImpl_2_SwapTextureHandles,
5008 Thunk_IDirect3DDeviceImpl_2_GetStats,
5009 Thunk_IDirect3DDeviceImpl_2_AddViewport,
5010 Thunk_IDirect3DDeviceImpl_2_DeleteViewport,
5011 Thunk_IDirect3DDeviceImpl_2_NextViewport,
5012 IDirect3DDeviceImpl_2_EnumTextureFormats,
5013 Thunk_IDirect3DDeviceImpl_2_BeginScene,
5014 Thunk_IDirect3DDeviceImpl_2_EndScene,
5015 Thunk_IDirect3DDeviceImpl_2_GetDirect3D,
5016 Thunk_IDirect3DDeviceImpl_2_SetCurrentViewport,
5017 Thunk_IDirect3DDeviceImpl_2_GetCurrentViewport,
5018 Thunk_IDirect3DDeviceImpl_2_SetRenderTarget,
5019 Thunk_IDirect3DDeviceImpl_2_GetRenderTarget,
5020 Thunk_IDirect3DDeviceImpl_2_Begin,
5021 Thunk_IDirect3DDeviceImpl_2_BeginIndexed,
5022 Thunk_IDirect3DDeviceImpl_2_Vertex,
5023 Thunk_IDirect3DDeviceImpl_2_Index,
5024 Thunk_IDirect3DDeviceImpl_2_End,
5025 Thunk_IDirect3DDeviceImpl_2_GetRenderState,
5026 Thunk_IDirect3DDeviceImpl_2_SetRenderState,
5027 Thunk_IDirect3DDeviceImpl_2_GetLightState,
5028 Thunk_IDirect3DDeviceImpl_2_SetLightState,
5029 Thunk_IDirect3DDeviceImpl_2_SetTransform,
5030 Thunk_IDirect3DDeviceImpl_2_GetTransform,
5031 Thunk_IDirect3DDeviceImpl_2_MultiplyTransform,
5032 Thunk_IDirect3DDeviceImpl_2_DrawPrimitive,
5033 Thunk_IDirect3DDeviceImpl_2_DrawIndexedPrimitive,
5034 Thunk_IDirect3DDeviceImpl_2_SetClipStatus,
5035 Thunk_IDirect3DDeviceImpl_2_GetClipStatus
5038 const IDirect3DDeviceVtbl IDirect3DDevice1_Vtbl =
5040 /*** IUnknown Methods ***/
5041 Thunk_IDirect3DDeviceImpl_1_QueryInterface,
5042 Thunk_IDirect3DDeviceImpl_1_AddRef,
5043 Thunk_IDirect3DDeviceImpl_1_Release,
5044 /*** IDirect3DDevice1 ***/
5045 IDirect3DDeviceImpl_1_Initialize,
5046 Thunk_IDirect3DDeviceImpl_1_GetCaps,
5047 Thunk_IDirect3DDeviceImpl_1_SwapTextureHandles,
5048 IDirect3DDeviceImpl_1_CreateExecuteBuffer,
5049 Thunk_IDirect3DDeviceImpl_1_GetStats,
5050 IDirect3DDeviceImpl_1_Execute,
5051 Thunk_IDirect3DDeviceImpl_1_AddViewport,
5052 Thunk_IDirect3DDeviceImpl_1_DeleteViewport,
5053 Thunk_IDirect3DDeviceImpl_1_NextViewport,
5054 IDirect3DDeviceImpl_1_Pick,
5055 IDirect3DDeviceImpl_1_GetPickRecords,
5056 Thunk_IDirect3DDeviceImpl_1_EnumTextureFormats,
5057 IDirect3DDeviceImpl_1_CreateMatrix,
5058 IDirect3DDeviceImpl_1_SetMatrix,
5059 IDirect3DDeviceImpl_1_GetMatrix,
5060 IDirect3DDeviceImpl_1_DeleteMatrix,
5061 Thunk_IDirect3DDeviceImpl_1_EndScene,
5062 Thunk_IDirect3DDeviceImpl_1_BeginScene,
5063 Thunk_IDirect3DDeviceImpl_1_GetDirect3D
5066 /*****************************************************************************
5067 * IDirect3DDeviceImpl_CreateHandle
5069 * Not called from the VTable
5071 * Some older interface versions operate with handles, which are basically
5072 * DWORDs which identify an interface, for example
5073 * IDirect3DDevice::SetRenderState with DIRECT3DRENDERSTATE_TEXTUREHANDLE
5075 * Those handle could be just casts to the interface pointers or vice versa,
5076 * but that is not 64 bit safe and would mean blindly derefering a DWORD
5077 * passed by the app. Instead there is a dynamic array in the device which
5078 * keeps a DWORD to pointer information and a type for the handle.
5080 * Basically this array only grows, when a handle is freed its pointer is
5081 * just set to NULL. There will be much more reads from the array than
5082 * insertion operations, so a dynamic array is fine.
5085 * This: D3DDevice implementation for which this handle should be created
5088 * A free handle on success
5091 *****************************************************************************/
5093 IDirect3DDeviceImpl_CreateHandle(IDirect3DDeviceImpl *This)
5096 struct HandleEntry *oldHandles = This->Handles;
5098 TRACE("(%p)\n", This);
5100 for(i = 0; i < This->numHandles; i++)
5102 if(This->Handles[i].ptr == NULL &&
5103 This->Handles[i].type == DDrawHandle_Unknown)
5105 TRACE("Reusing freed handle %d\n", i + 1);
5110 TRACE("Growing the handle array\n");
5113 This->Handles = HeapAlloc(GetProcessHeap(), 0, sizeof(struct HandleEntry) * This->numHandles);
5116 ERR("Out of memory\n");
5117 This->Handles = oldHandles;
5123 memcpy(This->Handles, oldHandles, (This->numHandles - 1) * sizeof(struct HandleEntry));
5124 HeapFree(GetProcessHeap(), 0, oldHandles);
5127 TRACE("Returning %d\n", This->numHandles);
5128 return This->numHandles;