2 * Copyright (c) 1998-2004 Lionel Ulmer
3 * Copyright (c) 2002-2005 Christian Costa
4 * Copyright (c) 2006 Stefan Dösinger
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * IDirect3DDevice implementation, version 1, 2, 3 and 7. Rendering is relayed
21 * to WineD3D, some minimal DirectDraw specific management is handled here.
22 * The Direct3DDevice is NOT the parent of the WineD3DDevice, because d3d
23 * is initialized when DirectDraw creates the primary surface.
24 * Some type management is necessary, because some D3D types changed between
30 #include "wine/port.h"
31 #include "wine/debug.h"
44 #include "wine/exception.h"
49 #include "ddraw_private.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(d3d7);
52 WINE_DECLARE_DEBUG_CHANNEL(ddraw_thunk);
55 const GUID IID_D3DDEVICE_WineD3D = {
59 { 0xb7,0x98,0xc6,0x8a,0x77,0x2d,0x72,0x2a }
62 /*****************************************************************************
63 * IUnknown Methods. Common for Version 1, 2, 3 and 7
64 *****************************************************************************/
66 /*****************************************************************************
67 * IDirect3DDevice7::QueryInterface
69 * Used to query other interfaces from a Direct3DDevice interface.
70 * It can return interface pointers to all Direct3DDevice versions as well
71 * as IDirectDraw and IDirect3D. For a link to QueryInterface
72 * rules see ddraw.c, IDirectDraw7::QueryInterface
74 * Exists in Version 1, 2, 3 and 7
77 * refiid: Interface ID queried for
78 * obj: Used to return the interface pointer
81 * D3D_OK or E_NOINTERFACE
83 *****************************************************************************/
85 IDirect3DDeviceImpl_7_QueryInterface(IDirect3DDevice7 *iface,
89 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
90 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(refiid), obj);
92 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
96 return DDERR_INVALIDPARAMS;
98 if ( IsEqualGUID( &IID_IUnknown, refiid ) )
100 *obj = ICOM_INTERFACE(This, IDirect3DDevice7);
103 /* Check DirectDraw Interfac
\ 1s */
104 else if( IsEqualGUID( &IID_IDirectDraw7, refiid ) )
106 *obj = ICOM_INTERFACE(This->ddraw, IDirectDraw7);
107 TRACE("(%p) Returning IDirectDraw7 interface at %p\n", This, *obj);
109 else if ( IsEqualGUID( &IID_IDirectDraw4, refiid ) )
111 *obj = ICOM_INTERFACE(This->ddraw, IDirectDraw4);
112 TRACE("(%p) Returning IDirectDraw4 interface at %p\n", This, *obj);
114 else if ( IsEqualGUID( &IID_IDirectDraw2, refiid ) )
116 *obj = ICOM_INTERFACE(This->ddraw, IDirectDraw2);
117 TRACE("(%p) Returning IDirectDraw2 interface at %p\n", This, *obj);
119 else if( IsEqualGUID( &IID_IDirectDraw, refiid ) )
121 *obj = ICOM_INTERFACE(This->ddraw, IDirectDraw);
122 TRACE("(%p) Returning IDirectDraw interface at %p\n", This, *obj);
126 else if ( IsEqualGUID( &IID_IDirect3D , refiid ) )
128 *obj = ICOM_INTERFACE(This->ddraw, IDirect3D);
129 TRACE("(%p) Returning IDirect3D interface at %p\n", This, *obj);
131 else if ( IsEqualGUID( &IID_IDirect3D2 , refiid ) )
133 *obj = ICOM_INTERFACE(This->ddraw, IDirect3D2);
134 TRACE("(%p) Returning IDirect3D2 interface at %p\n", This, *obj);
136 else if ( IsEqualGUID( &IID_IDirect3D3 , refiid ) )
138 *obj = ICOM_INTERFACE(This->ddraw, IDirect3D3);
139 TRACE("(%p) Returning IDirect3D3 interface at %p\n", This, *obj);
141 else if ( IsEqualGUID( &IID_IDirect3D7 , refiid ) )
143 *obj = ICOM_INTERFACE(This->ddraw, IDirect3D7);
144 TRACE("(%p) Returning IDirect3D7 interface at %p\n", This, *obj);
148 else if ( IsEqualGUID( &IID_IDirect3DDevice , refiid ) )
150 *obj = ICOM_INTERFACE(This, IDirect3DDevice);
151 TRACE("(%p) Returning IDirect3DDevice interface at %p\n", This, *obj);
153 else if ( IsEqualGUID( &IID_IDirect3DDevice2 , refiid ) ) {
154 *obj = ICOM_INTERFACE(This, IDirect3DDevice2);
155 TRACE("(%p) Returning IDirect3DDevice2 interface at %p\n", This, *obj);
157 else if ( IsEqualGUID( &IID_IDirect3DDevice3 , refiid ) ) {
158 *obj = ICOM_INTERFACE(This, IDirect3DDevice3);
159 TRACE("(%p) Returning IDirect3DDevice3 interface at %p\n", This, *obj);
161 else if ( IsEqualGUID( &IID_IDirect3DDevice7 , refiid ) ) {
162 *obj = ICOM_INTERFACE(This, IDirect3DDevice7);
163 TRACE("(%p) Returning IDirect3DDevice7 interface at %p\n", This, *obj);
166 /* Unknown interface */
169 ERR("(%p)->(%s, %p): No interface found\n", This, debugstr_guid(refiid), obj);
170 return E_NOINTERFACE;
173 /* AddRef the returned interface */
174 IUnknown_AddRef( (IUnknown *) *obj);
178 static HRESULT WINAPI
179 Thunk_IDirect3DDeviceImpl_3_QueryInterface(IDirect3DDevice3 *iface,
183 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
184 TRACE_(ddraw_thunk)("(%p)->(%s,%p) thunking to IDirect3DDevice7 interface.\n", This, debugstr_guid(riid), obj);
185 return IDirect3DDevice7_QueryInterface(ICOM_INTERFACE(This, IDirect3DDevice7),
190 static HRESULT WINAPI
191 Thunk_IDirect3DDeviceImpl_2_QueryInterface(IDirect3DDevice2 *iface,
195 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
196 TRACE_(ddraw_thunk)("(%p)->(%s,%p) thunking to IDirect3DDevice7 interface.\n", This, debugstr_guid(riid), obj);
197 return IDirect3DDevice7_QueryInterface(ICOM_INTERFACE(This, IDirect3DDevice7),
202 static HRESULT WINAPI
203 Thunk_IDirect3DDeviceImpl_1_QueryInterface(IDirect3DDevice *iface,
207 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
208 TRACE_(ddraw_thunk)("(%p)->(%s,%p) thunking to IDirect3DDevice7 interface.\n", This, debugstr_guid(riid), obp);
209 return IDirect3DDevice7_QueryInterface(ICOM_INTERFACE(This, IDirect3DDevice7),
214 /*****************************************************************************
215 * IDirect3DDevice7::AddRef
217 * Increases the refcount....
218 * The most exciting Method, definitely
220 * Exists in Version 1, 2, 3 and 7
225 *****************************************************************************/
227 IDirect3DDeviceImpl_7_AddRef(IDirect3DDevice7 *iface)
229 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
230 ULONG ref = InterlockedIncrement(&This->ref);
232 TRACE("(%p) : incrementing from %u.\n", This, ref -1);
238 Thunk_IDirect3DDeviceImpl_3_AddRef(IDirect3DDevice3 *iface)
240 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
241 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
242 return IDirect3DDevice7_AddRef(ICOM_INTERFACE(This, IDirect3DDevice7));
246 Thunk_IDirect3DDeviceImpl_2_AddRef(IDirect3DDevice2 *iface)
248 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
249 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
250 return IDirect3DDevice7_AddRef(ICOM_INTERFACE(This, IDirect3DDevice7));
254 Thunk_IDirect3DDeviceImpl_1_AddRef(IDirect3DDevice *iface)
256 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", iface);
257 return IDirect3DDevice7_AddRef(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice, IDirect3DDevice7, iface));
260 /*****************************************************************************
261 * IDirect3DDevice7::Release
263 * Decreases the refcount of the interface
264 * When the refcount is reduced to 0, the object is destroyed.
266 * Exists in Version 1, 2, 3 and 7
271 *****************************************************************************/
273 IDirect3DDeviceImpl_7_Release(IDirect3DDevice7 *iface)
275 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
276 ULONG ref = InterlockedDecrement(&This->ref);
278 TRACE("(%p)->() decrementing from %u.\n", This, ref +1);
280 /* This method doesn't destroy the WineD3DDevice, because it's still in use for
281 * 2D rendering. IDirectDrawSurface7::Release will destroy the WineD3DDevice
282 * when the render target is released
286 IParent *IndexBufferParent;
289 /* Free the index buffer. */
290 IWineD3DDevice_SetIndices(This->wineD3DDevice,
293 IWineD3DIndexBuffer_GetParent(This->indexbuffer,
294 (IUnknown **) &IndexBufferParent);
295 IParent_Release(IndexBufferParent); /* Once for the getParent */
296 if( IParent_Release(IndexBufferParent) != 0) /* And now to destroy it */
298 ERR(" (%p) Something is still holding the index buffer parent %p\n", This, IndexBufferParent);
301 /* There is no need to unset the vertex buffer here, IWineD3DDevice_Uninit3D will do that when
302 * destroying the primary stateblock. If a vertex buffer is destroyed while it is bound
303 * IDirect3DVertexBuffer::Release will unset it.
306 /* Restore the render targets */
307 if(This->OffScreenTarget)
309 /* Set the device up to render to the front buffer since the back buffer will
312 IWineD3DDevice_SetRenderTarget(This->wineD3DDevice, 0,
313 This->ddraw->d3d_target->WineD3DSurface);
314 /* This->target is the offscreen target.
315 * This->ddraw->d3d_target is the target used by DDraw
317 TRACE("(%p) Release: Using %p as front buffer, %p as back buffer\n", This, This->ddraw->d3d_target, NULL);
318 IWineD3DDevice_SetFrontBackBuffers(This->wineD3DDevice,
319 This->ddraw->d3d_target->WineD3DSurface,
323 /* Release the WineD3DDevice. This won't destroy it */
324 if(IWineD3DDevice_Release(This->wineD3DDevice) <= 0)
326 ERR(" (%p) The wineD3D device %p was destroyed unexpectadely. Prepare for trouble\n", This, This->wineD3DDevice);
329 /* The texture handles should be unset by now, but there might be some bits
330 * missing in our reference counting(needs test). Do a sanity check
332 for(i = 0; i < This->numHandles; i++)
334 if(This->Handles[i].ptr)
336 switch(This->Handles[i].type)
338 case DDrawHandle_Texture:
340 IDirectDrawSurfaceImpl *surf = (IDirectDrawSurfaceImpl *) This->Handles[i].ptr;
341 FIXME("Texture Handle %d not unset properly\n", i + 1);
346 case DDrawHandle_Material:
348 IDirect3DMaterialImpl *mat = (IDirect3DMaterialImpl *) This->Handles[i].ptr;
349 FIXME("Material handle %d not unset properly\n", i + 1);
354 case DDrawHandle_Matrix:
356 /* No fixme here because this might happen because of sloppy apps */
357 WARN("Leftover matrix handle %d, deleting\n", i + 1);
358 IDirect3DDevice_DeleteMatrix(ICOM_INTERFACE(This, IDirect3DDevice),
363 case DDrawHandle_StateBlock:
365 /* No fixme here because this might happen because of sloppy apps */
366 WARN("Leftover stateblock handle %d, deleting\n", i + 1);
367 IDirect3DDevice7_DeleteStateBlock(ICOM_INTERFACE(This, IDirect3DDevice7),
373 FIXME("Unknown handle %d not unset properly\n", i + 1);
378 HeapFree(GetProcessHeap(), 0, This->Handles);
380 TRACE("Releasing target %p %p\n", This->target, This->ddraw->d3d_target);
381 /* Release the render target and the WineD3D render target
382 * (See IDirect3D7::CreateDevice for more comments on this)
384 IDirectDrawSurface7_Release(ICOM_INTERFACE(This->target, IDirectDrawSurface7));
385 IDirectDrawSurface7_Release(ICOM_INTERFACE(This->ddraw->d3d_target,IDirectDrawSurface7));
386 TRACE("Target release done\n");
388 This->ddraw->d3ddevice = NULL;
390 /* Now free the structure */
391 HeapFree(GetProcessHeap(), 0, This);
399 Thunk_IDirect3DDeviceImpl_3_Release(IDirect3DDevice3 *iface)
401 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
402 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
403 return IDirect3DDevice7_Release(ICOM_INTERFACE(This, IDirect3DDevice7));
407 Thunk_IDirect3DDeviceImpl_2_Release(IDirect3DDevice2 *iface)
409 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
410 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
411 return IDirect3DDevice7_Release(ICOM_INTERFACE(This, IDirect3DDevice7));
415 Thunk_IDirect3DDeviceImpl_1_Release(IDirect3DDevice *iface)
417 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
418 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
419 return IDirect3DDevice7_Release(ICOM_INTERFACE(This, IDirect3DDevice7));
422 /*****************************************************************************
423 * IDirect3DDevice Methods
424 *****************************************************************************/
426 /*****************************************************************************
427 * IDirect3DDevice::Initialize
429 * Initializes a Direct3DDevice. This implementation is a no-op, as all
430 * initialization is done at create time.
432 * Exists in Version 1
435 * No idea what they mean, as the MSDN page is gone
439 *****************************************************************************/
440 static HRESULT WINAPI
441 IDirect3DDeviceImpl_1_Initialize(IDirect3DDevice *iface,
442 IDirect3D *Direct3D, GUID *guid,
445 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
447 /* It shouldn't be crucial, but print a FIXME, I'm interested if
448 * any game calls it and when
450 FIXME("(%p)->(%p,%p,%p): No-op!\n", This, Direct3D, guid, Desc);
455 /*****************************************************************************
456 * IDirect3DDevice7::GetCaps
458 * Retrieves the device's capabilities
460 * This implementation is used for Version 7 only, the older versions have
461 * their own implementation.
464 * Desc: Pointer to a D3DDEVICEDESC7 structure to fill
468 * D3DERR_* if a problem occurs. See WineD3D
470 *****************************************************************************/
471 static HRESULT WINAPI
472 IDirect3DDeviceImpl_7_GetCaps(IDirect3DDevice7 *iface,
473 D3DDEVICEDESC7 *Desc)
475 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
476 D3DDEVICEDESC OldDesc;
477 TRACE("(%p)->(%p)\n", This, Desc);
479 /* Call the same function used by IDirect3D, this saves code */
480 return IDirect3DImpl_GetCaps(This->ddraw->wineD3D, &OldDesc, Desc);
483 /*****************************************************************************
484 * IDirect3DDevice3::GetCaps
486 * Retrieves the capabilities of the hardware device and the emulation
487 * device. For Wine, hardware and emulation are the same (it's all HW).
489 * This implementation is used for Version 1, 2, and 3. Version 7 has its own
492 * HWDesc: Structure to fill with the HW caps
493 * HelDesc: Structure to fill with the hardare emulation caps
497 * D3DERR_* if a problem occurs. See WineD3D
499 *****************************************************************************/
500 static HRESULT WINAPI
501 IDirect3DDeviceImpl_3_GetCaps(IDirect3DDevice3 *iface,
502 D3DDEVICEDESC *HWDesc,
503 D3DDEVICEDESC *HelDesc)
505 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
506 D3DDEVICEDESC7 newDesc;
508 TRACE("(%p)->(%p,%p)\n", iface, HWDesc, HelDesc);
510 hr = IDirect3DImpl_GetCaps(This->ddraw->wineD3D, HWDesc, &newDesc);
511 if(hr != D3D_OK) return hr;
517 static HRESULT WINAPI
518 Thunk_IDirect3DDeviceImpl_2_GetCaps(IDirect3DDevice2 *iface,
519 D3DDEVICEDESC *D3DHWDevDesc,
520 D3DDEVICEDESC *D3DHELDevDesc)
522 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
523 TRACE_(ddraw_thunk)("(%p)->(%p,%p) thunking to IDirect3DDevice3 interface.\n", This, D3DHWDevDesc, D3DHELDevDesc);
524 return IDirect3DDevice3_GetCaps(ICOM_INTERFACE(This, IDirect3DDevice3),
529 static HRESULT WINAPI
530 Thunk_IDirect3DDeviceImpl_1_GetCaps(IDirect3DDevice *iface,
531 D3DDEVICEDESC *D3DHWDevDesc,
532 D3DDEVICEDESC *D3DHELDevDesc)
534 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
535 TRACE_(ddraw_thunk)("(%p)->(%p,%p) thunking to IDirect3DDevice3 interface.\n", This, D3DHWDevDesc, D3DHELDevDesc);
536 return IDirect3DDevice3_GetCaps(ICOM_INTERFACE(This, IDirect3DDevice3),
541 /*****************************************************************************
542 * IDirect3DDevice2::SwapTextureHandles
544 * Swaps the texture handles of 2 Texture interfaces. Version 1 and 2
547 * Tex1, Tex2: The 2 Textures to swap
552 *****************************************************************************/
553 static HRESULT WINAPI
554 IDirect3DDeviceImpl_2_SwapTextureHandles(IDirect3DDevice2 *iface,
555 IDirect3DTexture2 *Tex1,
556 IDirect3DTexture2 *Tex2)
558 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
560 IDirectDrawSurfaceImpl *surf1 = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture2, Tex1);
561 IDirectDrawSurfaceImpl *surf2 = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture2, Tex2);
562 TRACE("(%p)->(%p,%p)\n", This, surf1, surf2);
564 This->Handles[surf1->Handle - 1].ptr = surf2;
565 This->Handles[surf2->Handle - 1].ptr = surf1;
567 swap = surf2->Handle;
568 surf2->Handle = surf1->Handle;
569 surf1->Handle = swap;
574 static HRESULT WINAPI
575 Thunk_IDirect3DDeviceImpl_1_SwapTextureHandles(IDirect3DDevice *iface,
576 IDirect3DTexture *D3DTex1,
577 IDirect3DTexture *D3DTex2)
579 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
580 IDirectDrawSurfaceImpl *surf1 = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture, D3DTex1);
581 IDirectDrawSurfaceImpl *surf2 = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture, D3DTex2);
582 TRACE_(ddraw_thunk)("(%p)->(%p,%p) thunking to IDirect3DDevice2 interface.\n", This, surf1, surf2);
583 return IDirect3DDevice2_SwapTextureHandles(ICOM_INTERFACE(This, IDirect3DDevice2),
584 ICOM_INTERFACE(surf1, IDirect3DTexture2),
585 ICOM_INTERFACE(surf2, IDirect3DTexture2));
588 /*****************************************************************************
589 * IDirect3DDevice3::GetStats
591 * This method seems to retrieve some stats from the device.
592 * The MSDN documentation doesn't exist any more, but the D3DSTATS
593 * structure suggests that the amout of drawn primitives and processed
594 * vertices is returned.
596 * Exists in Version 1, 2 and 3
599 * Stats: Pointer to a D3DSTATS structure to be filled
603 * DDERR_INVALIDPARAMS if Stats == NULL
605 *****************************************************************************/
606 static HRESULT WINAPI
607 IDirect3DDeviceImpl_3_GetStats(IDirect3DDevice3 *iface,
610 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
611 FIXME("(%p)->(%p): Stub!\n", This, Stats);
614 return DDERR_INVALIDPARAMS;
616 /* Fill the Stats with 0 */
617 Stats->dwTrianglesDrawn = 0;
618 Stats->dwLinesDrawn = 0;
619 Stats->dwPointsDrawn = 0;
620 Stats->dwSpansDrawn = 0;
621 Stats->dwVerticesProcessed = 0;
626 static HRESULT WINAPI
627 Thunk_IDirect3DDeviceImpl_2_GetStats(IDirect3DDevice2 *iface,
630 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
631 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, Stats);
632 return IDirect3DDevice3_GetStats(ICOM_INTERFACE(This, IDirect3DDevice3),
636 static HRESULT WINAPI
637 Thunk_IDirect3DDeviceImpl_1_GetStats(IDirect3DDevice *iface,
640 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
641 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, Stats);
642 return IDirect3DDevice3_GetStats(ICOM_INTERFACE(This, IDirect3DDevice3),
646 /*****************************************************************************
647 * IDirect3DDevice::CreateExecuteBuffer
649 * Creates an IDirect3DExecuteBuffer, used for rendering with a
655 * Desc: Buffer description
656 * ExecuteBuffer: Address to return the Interface pointer at
657 * UnkOuter: Must be NULL. Basically for aggregation, which ddraw doesn't
661 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
662 * DDERR_OUTOFMEMORY if we ran out of memory
665 *****************************************************************************/
666 static HRESULT WINAPI
667 IDirect3DDeviceImpl_1_CreateExecuteBuffer(IDirect3DDevice *iface,
668 D3DEXECUTEBUFFERDESC *Desc,
669 IDirect3DExecuteBuffer **ExecuteBuffer,
672 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
673 IDirect3DExecuteBufferImpl* object;
674 TRACE("(%p)->(%p,%p,%p)!\n", This, Desc, ExecuteBuffer, UnkOuter);
677 return CLASS_E_NOAGGREGATION;
679 /* Allocate the new Execute Buffer */
680 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DExecuteBufferImpl));
683 ERR("Out of memory when allocating a IDirect3DExecuteBufferImpl structure\n");
684 return DDERR_OUTOFMEMORY;
687 ICOM_INIT_INTERFACE(object, IDirect3DExecuteBuffer, IDirect3DExecuteBuffer_Vtbl);
690 object->d3ddev = This;
692 /* Initializes memory */
693 memcpy(&object->desc, Desc, Desc->dwSize);
695 /* No buffer given */
696 if ((object->desc.dwFlags & D3DDEB_LPDATA) == 0)
697 object->desc.lpData = NULL;
699 /* No buffer size given */
700 if ((object->desc.dwFlags & D3DDEB_BUFSIZE) == 0)
701 object->desc.dwBufferSize = 0;
703 /* Create buffer if asked */
704 if ((object->desc.lpData == NULL) && (object->desc.dwBufferSize > 0))
706 object->need_free = TRUE;
707 object->desc.lpData = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,object->desc.dwBufferSize);
708 if(!object->desc.lpData)
710 ERR("Out of memory when allocating the execute buffer data\n");
711 HeapFree(GetProcessHeap(), 0, object);
712 return DDERR_OUTOFMEMORY;
717 object->need_free = FALSE;
720 /* No vertices for the moment */
721 object->vertex_data = NULL;
723 object->desc.dwFlags |= D3DDEB_LPDATA;
725 object->indices = NULL;
726 object->nb_indices = 0;
728 *ExecuteBuffer = ICOM_INTERFACE(object, IDirect3DExecuteBuffer);
730 TRACE(" Returning IDirect3DExecuteBuffer at %p, implementation is at %p\n", *ExecuteBuffer, object);
735 /*****************************************************************************
736 * IDirect3DDevice::Execute
738 * Executes all the stuff in an execute buffer.
741 * ExecuteBuffer: The buffer to execute
742 * Viewport: The viewport used for rendering
746 * DDERR_INVALIDPARAMS if ExecuteBuffer == NULL
749 *****************************************************************************/
750 static HRESULT WINAPI
751 IDirect3DDeviceImpl_1_Execute(IDirect3DDevice *iface,
752 IDirect3DExecuteBuffer *ExecuteBuffer,
753 IDirect3DViewport *Viewport,
756 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
757 IDirect3DExecuteBufferImpl *Direct3DExecuteBufferImpl = ICOM_OBJECT(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, ExecuteBuffer);
758 IDirect3DViewportImpl *Direct3DViewportImpl = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport);
760 TRACE("(%p)->(%p,%p,%08x)\n", This, Direct3DExecuteBufferImpl, Direct3DViewportImpl, Flags);
762 if(!Direct3DExecuteBufferImpl)
763 return DDERR_INVALIDPARAMS;
766 IDirect3DExecuteBufferImpl_Execute(Direct3DExecuteBufferImpl, This, Direct3DViewportImpl);
771 /*****************************************************************************
772 * IDirect3DDevice3::AddViewport
774 * Add a Direct3DViewport to the device's viewport list. These viewports
775 * are wrapped to IDirect3DDevice7 viewports in viewport.c
777 * Exists in Version 1, 2 and 3. Note that IDirect3DViewport 1, 2 and 3
778 * are the same interfaces.
781 * Viewport: The viewport to add
784 * DDERR_INVALIDPARAMS if Viewport == NULL
787 *****************************************************************************/
788 static HRESULT WINAPI
789 IDirect3DDeviceImpl_3_AddViewport(IDirect3DDevice3 *iface,
790 IDirect3DViewport3 *Viewport)
792 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
793 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport);
795 TRACE("(%p)->(%p)\n", This, vp);
799 return DDERR_INVALIDPARAMS;
801 vp->next = This->viewport_list;
802 This->viewport_list = vp;
807 static HRESULT WINAPI
808 Thunk_IDirect3DDeviceImpl_2_AddViewport(IDirect3DDevice2 *iface,
809 IDirect3DViewport2 *Direct3DViewport2)
811 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
812 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport2);
813 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, vp);
814 return IDirect3DDevice3_AddViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
815 ICOM_INTERFACE(vp, IDirect3DViewport3));
818 static HRESULT WINAPI
819 Thunk_IDirect3DDeviceImpl_1_AddViewport(IDirect3DDevice *iface,
820 IDirect3DViewport *Direct3DViewport)
822 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
823 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport);
824 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, vp);
825 return IDirect3DDevice3_AddViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
826 ICOM_INTERFACE(vp, IDirect3DViewport3));
829 /*****************************************************************************
830 * IDirect3DDevice3::DeleteViewport
832 * Deletes a Direct3DViewport from the device's viewport list.
834 * Exists in Version 1, 2 and 3. Note that all Viewport interface versions
838 * Viewport: The viewport to delete
842 * DDERR_INVALIDPARAMS if the viewport wasn't found in the list
844 *****************************************************************************/
845 static HRESULT WINAPI
846 IDirect3DDeviceImpl_3_DeleteViewport(IDirect3DDevice3 *iface,
847 IDirect3DViewport3 *Viewport)
849 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
850 IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *) Viewport;
851 IDirect3DViewportImpl *cur_viewport, *prev_viewport = NULL;
853 TRACE("(%p)->(%p)\n", This, vp);
855 cur_viewport = This->viewport_list;
856 while (cur_viewport != NULL)
858 if (cur_viewport == vp)
860 if (prev_viewport == NULL) This->viewport_list = cur_viewport->next;
861 else prev_viewport->next = cur_viewport->next;
862 /* TODO : add desactivate of the viewport and all associated lights... */
865 prev_viewport = cur_viewport;
866 cur_viewport = cur_viewport->next;
869 return DDERR_INVALIDPARAMS;
872 static HRESULT WINAPI
873 Thunk_IDirect3DDeviceImpl_2_DeleteViewport(IDirect3DDevice2 *iface,
874 IDirect3DViewport2 *Direct3DViewport2)
876 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
877 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport2);
878 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, vp);
879 return IDirect3DDevice3_DeleteViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
880 ICOM_INTERFACE(vp, IDirect3DViewport3));
883 static HRESULT WINAPI
884 Thunk_IDirect3DDeviceImpl_1_DeleteViewport(IDirect3DDevice *iface,
885 IDirect3DViewport *Direct3DViewport)
887 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
888 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport);
889 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, vp);
890 return IDirect3DDevice3_DeleteViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
891 ICOM_INTERFACE(vp, IDirect3DViewport3));
894 /*****************************************************************************
895 * IDirect3DDevice3::NextViewport
897 * Returns a viewport from the viewport list, depending on the
898 * passed viewport and the flags.
900 * Exists in Version 1, 2 and 3. Note that all Viewport interface versions
904 * Viewport: Viewport to use for beginning the search
905 * Flags: D3DNEXT_NEXT, D3DNEXT_HEAD or D3DNEXT_TAIL
909 * DDERR_INVALIDPARAMS if the flags were wrong, or Viewport was NULL
911 *****************************************************************************/
912 static HRESULT WINAPI
913 IDirect3DDeviceImpl_3_NextViewport(IDirect3DDevice3 *iface,
914 IDirect3DViewport3 *Viewport3,
915 IDirect3DViewport3 **lplpDirect3DViewport3,
918 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
919 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport3);
920 IDirect3DViewportImpl *res = NULL;
922 TRACE("(%p)->(%p,%p,%08x)\n", This, vp, lplpDirect3DViewport3, Flags);
926 *lplpDirect3DViewport3 = NULL;
927 return DDERR_INVALIDPARAMS;
940 res = This->viewport_list;
945 IDirect3DViewportImpl *cur_viewport = This->viewport_list;
946 if (cur_viewport != NULL)
948 while (cur_viewport->next != NULL) cur_viewport = cur_viewport->next;
954 *lplpDirect3DViewport3 = NULL;
955 return DDERR_INVALIDPARAMS;
958 *lplpDirect3DViewport3 = ICOM_INTERFACE(res, IDirect3DViewport3);
962 static HRESULT WINAPI
963 Thunk_IDirect3DDeviceImpl_2_NextViewport(IDirect3DDevice2 *iface,
964 IDirect3DViewport2 *Viewport2,
965 IDirect3DViewport2 **lplpDirect3DViewport2,
968 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
969 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport2);
970 IDirect3DViewport3 *res;
972 TRACE_(ddraw_thunk)("(%p)->(%p,%p,%08x) thunking to IDirect3DDevice3 interface.\n", This, vp, lplpDirect3DViewport2, Flags);
973 hr = IDirect3DDevice3_NextViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
974 ICOM_INTERFACE(vp, IDirect3DViewport3),
977 *lplpDirect3DViewport2 = (IDirect3DViewport2 *) COM_INTERFACE_CAST(IDirect3DViewportImpl, IDirect3DViewport3, IDirect3DViewport3, res);
981 static HRESULT WINAPI
982 Thunk_IDirect3DDeviceImpl_1_NextViewport(IDirect3DDevice *iface,
983 IDirect3DViewport *Viewport,
984 IDirect3DViewport **lplpDirect3DViewport,
987 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
988 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport);
989 IDirect3DViewport3 *res;
991 TRACE_(ddraw_thunk)("(%p)->(%p,%p,%08x) thunking to IDirect3DDevice3 interface.\n", This, vp, lplpDirect3DViewport, Flags);
992 hr = IDirect3DDevice3_NextViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
993 ICOM_INTERFACE(vp, IDirect3DViewport3),
996 *lplpDirect3DViewport = (IDirect3DViewport *) COM_INTERFACE_CAST(IDirect3DViewportImpl, IDirect3DViewport3, IDirect3DViewport3, res);
1000 /*****************************************************************************
1001 * IDirect3DDevice::Pick
1003 * Executes an execute buffer without performing rendering. Instead, a
1004 * list of primitives that intersect with (x1,y1) of the passed rectangle
1005 * is created. IDirect3DDevice::GetPickRecords can be used to retrieve
1011 * ExecuteBuffer: Buffer to execute
1012 * Viewport: Viewport to use for execution
1013 * Flags: None are defined, according to the SDK
1014 * Rect: Specifies the coordinates to be picked. Only x1 and y2 are used,
1015 * x2 and y2 are ignored.
1018 * D3D_OK because it's a stub
1020 *****************************************************************************/
1021 static HRESULT WINAPI
1022 IDirect3DDeviceImpl_1_Pick(IDirect3DDevice *iface,
1023 IDirect3DExecuteBuffer *ExecuteBuffer,
1024 IDirect3DViewport *Viewport,
1028 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1029 IDirect3DExecuteBufferImpl *execbuf = ICOM_OBJECT(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, ExecuteBuffer);
1030 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport);
1031 FIXME("(%p)->(%p,%p,%08x,%p): stub!\n", This, execbuf, vp, Flags, Rect);
1036 /*****************************************************************************
1037 * IDirect3DDevice::GetPickRecords
1039 * Retrieves the pick records generated by IDirect3DDevice::GetPickRecords
1044 * Count: Pointer to a DWORD containing the numbers of pick records to
1046 * D3DPickRec: Address to store the resulting D3DPICKRECORD arry.
1049 * D3D_OK, because it's a stub
1051 *****************************************************************************/
1052 static HRESULT WINAPI
1053 IDirect3DDeviceImpl_1_GetPickRecords(IDirect3DDevice *iface,
1055 D3DPICKRECORD *D3DPickRec)
1057 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1058 FIXME("(%p)->(%p,%p): stub!\n", This, Count, D3DPickRec);
1063 /*****************************************************************************
1064 * IDirect3DDevice7::EnumTextureformats
1066 * Enumerates the supported texture formats. It has a list of all possible
1067 * formats and calls IWineD3D::CheckDeviceFormat for each format to see if
1068 * WineD3D supports it. If so, then it is passed to the app.
1070 * This is for Version 7 and 3, older versions have a different
1071 * callback function and their own implementation
1074 * Callback: Callback to call for each enumerated format
1075 * Arg: Argument to pass to the callback
1079 * DDERR_INVALIDPARAMS if Callback == NULL
1081 *****************************************************************************/
1082 static HRESULT WINAPI
1083 IDirect3DDeviceImpl_7_EnumTextureFormats(IDirect3DDevice7 *iface,
1084 LPD3DENUMPIXELFORMATSCALLBACK Callback,
1087 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1091 WINED3DFORMAT FormatList[] = {
1093 WINED3DFMT_A8R8G8B8,
1094 WINED3DFMT_X8R8G8B8,
1098 WINED3DFMT_A1R5G5B5,
1099 WINED3DFMT_A4R4G4B4,
1101 WINED3DFMT_X1R5G5B5,
1111 TRACE("(%p)->(%p,%p): Relay\n", This, Callback, Arg);
1114 return DDERR_INVALIDPARAMS;
1116 for(i = 0; i < sizeof(FormatList) / sizeof(WINED3DFORMAT); i++)
1118 hr = IWineD3D_CheckDeviceFormat(This->ddraw->wineD3D,
1121 0 /* AdapterFormat */,
1123 0 /* ResourceType */,
1127 DDPIXELFORMAT pformat;
1129 memset(&pformat, 0, sizeof(pformat));
1130 pformat.dwSize = sizeof(pformat);
1131 PixelFormat_WineD3DtoDD(&pformat, FormatList[i]);
1133 TRACE("Enumerating WineD3DFormat %d\n", FormatList[i]);
1134 hr = Callback(&pformat, Arg);
1135 if(hr != DDENUMRET_OK)
1137 TRACE("Format enumeration cancelled by application\n");
1142 TRACE("End of enumeration\n");
1146 static HRESULT WINAPI
1147 Thunk_IDirect3DDeviceImpl_3_EnumTextureFormats(IDirect3DDevice3 *iface,
1148 LPD3DENUMPIXELFORMATSCALLBACK Callback,
1151 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1152 TRACE_(ddraw_thunk)("(%p)->(%p,%p) thunking to IDirect3DDevice7 interface.\n", This, Callback, Arg);
1153 return IDirect3DDevice7_EnumTextureFormats(ICOM_INTERFACE(This, IDirect3DDevice7),
1158 /*****************************************************************************
1159 * IDirect3DDevice2::EnumTextureformats
1161 * EnumTextureFormats for Version 1 and 2, see
1162 * IDirect3DDevice7::EnumTexureFormats for a more detailed description.
1164 * This version has a different callback and does not enumerate FourCC
1167 *****************************************************************************/
1168 static HRESULT WINAPI
1169 IDirect3DDeviceImpl_2_EnumTextureFormats(IDirect3DDevice2 *iface,
1170 LPD3DENUMTEXTUREFORMATSCALLBACK Callback,
1173 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1177 WINED3DFORMAT FormatList[] = {
1179 WINED3DFMT_A8R8G8B8,
1180 WINED3DFMT_X8R8G8B8,
1184 WINED3DFMT_A1R5G5B5,
1185 WINED3DFMT_A4R4G4B4,
1187 WINED3DFMT_X1R5G5B5,
1191 /* FOURCC codes - Not in this version*/
1194 TRACE("(%p)->(%p,%p): Relay\n", This, Callback, Arg);
1197 return DDERR_INVALIDPARAMS;
1199 for(i = 0; i < sizeof(FormatList) / sizeof(WINED3DFORMAT); i++)
1201 hr = IWineD3D_CheckDeviceFormat(This->ddraw->wineD3D,
1204 0 /* AdapterFormat */,
1206 0 /* ResourceType */,
1210 DDSURFACEDESC sdesc;
1212 memset(&sdesc, 0, sizeof(sdesc));
1213 sdesc.dwSize = sizeof(sdesc);
1214 sdesc.dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
1215 sdesc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1216 sdesc.ddpfPixelFormat.dwSize = sizeof(sdesc.ddpfPixelFormat);
1217 PixelFormat_WineD3DtoDD(&sdesc.ddpfPixelFormat, FormatList[i]);
1219 TRACE("Enumerating WineD3DFormat %d\n", FormatList[i]);
1220 hr = Callback(&sdesc, Arg);
1221 if(hr != DDENUMRET_OK)
1223 TRACE("Format enumeration cancelled by application\n");
1228 TRACE("End of enumeration\n");
1232 static HRESULT WINAPI
1233 Thunk_IDirect3DDeviceImpl_1_EnumTextureFormats(IDirect3DDevice *iface,
1234 LPD3DENUMTEXTUREFORMATSCALLBACK Callback,
1237 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1238 TRACE_(ddraw_thunk)("(%p)->(%p,%p) thunking to IDirect3DDevice2 interface.\n", This, Callback, Arg);
1239 return IDirect3DDevice2_EnumTextureFormats(ICOM_INTERFACE(This, IDirect3DDevice2),
1244 /*****************************************************************************
1245 * IDirect3DDevice::CreateMatrix
1247 * Creates a matrix handle. A handle is created and memory for a D3DMATRIX is
1248 * allocated for the handle.
1253 * D3DMatHandle: Address to return the handle at
1257 * DDERR_INVALIDPARAMS if D3DMatHandle = NULL
1259 *****************************************************************************/
1260 static HRESULT WINAPI
1261 IDirect3DDeviceImpl_1_CreateMatrix(IDirect3DDevice *iface, D3DMATRIXHANDLE *D3DMatHandle)
1263 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1265 TRACE("(%p)->(%p)\n", This, D3DMatHandle);
1268 return DDERR_INVALIDPARAMS;
1270 Matrix = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(D3DMATRIX));
1273 ERR("Out of memory when allocating a D3DMATRIX\n");
1274 return DDERR_OUTOFMEMORY;
1276 *D3DMatHandle = IDirect3DDeviceImpl_CreateHandle(This);
1277 if(!(*D3DMatHandle))
1279 ERR("Failed to create a matrix handle\n");
1280 HeapFree(GetProcessHeap(), 0, Matrix);
1281 return DDERR_OUTOFMEMORY;
1283 This->Handles[(DWORD) *D3DMatHandle - 1].ptr = Matrix;
1284 This->Handles[(DWORD) *D3DMatHandle - 1].type = DDrawHandle_Matrix;
1285 TRACE(" returning matrix handle %d\n", *D3DMatHandle);
1290 /*****************************************************************************
1291 * IDirect3DDevice::SetMatrix
1293 * Sets a matrix for a matrix handle. The matrix is copied into the memory
1294 * allocated for the handle
1299 * D3DMatHandle: Handle to set the matrix to
1300 * D3DMatrix: Matrix to set
1304 * DDERR_INVALIDPARAMS if the handle of the matrix is invalid or the matrix
1307 *****************************************************************************/
1308 static HRESULT WINAPI
1309 IDirect3DDeviceImpl_1_SetMatrix(IDirect3DDevice *iface,
1310 D3DMATRIXHANDLE D3DMatHandle,
1311 D3DMATRIX *D3DMatrix)
1313 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1314 TRACE("(%p)->(%08x,%p)\n", This, (DWORD) D3DMatHandle, D3DMatrix);
1316 if( (!D3DMatHandle) || (!D3DMatrix) )
1317 return DDERR_INVALIDPARAMS;
1319 if(D3DMatHandle > This->numHandles)
1321 ERR("Handle %d out of range\n", D3DMatHandle);
1322 return DDERR_INVALIDPARAMS;
1324 else if(This->Handles[D3DMatHandle - 1].type != DDrawHandle_Matrix)
1326 ERR("Handle %d is not a matrix handle\n", D3DMatHandle);
1327 return DDERR_INVALIDPARAMS;
1331 dump_D3DMATRIX(D3DMatrix);
1333 *((D3DMATRIX *) This->Handles[D3DMatHandle - 1].ptr) = *D3DMatrix;
1338 /*****************************************************************************
1339 * IDirect3DDevice::SetMatrix
1341 * Returns the content of a D3DMATRIX handle
1346 * D3DMatHandle: Matrix handle to read the content from
1347 * D3DMatrix: Address to store the content at
1351 * DDERR_INVALIDPARAMS if D3DMatHandle is invalid or D3DMatrix is NULL
1353 *****************************************************************************/
1354 static HRESULT WINAPI
1355 IDirect3DDeviceImpl_1_GetMatrix(IDirect3DDevice *iface,
1356 D3DMATRIXHANDLE D3DMatHandle,
1357 D3DMATRIX *D3DMatrix)
1359 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1360 TRACE("(%p)->(%08x,%p)\n", This, (DWORD) D3DMatHandle, D3DMatrix);
1363 return DDERR_INVALIDPARAMS;
1365 return DDERR_INVALIDPARAMS;
1367 if(D3DMatHandle > This->numHandles)
1369 ERR("Handle %d out of range\n", D3DMatHandle);
1370 return DDERR_INVALIDPARAMS;
1372 else if(This->Handles[D3DMatHandle - 1].type != DDrawHandle_Matrix)
1374 ERR("Handle %d is not a matrix handle\n", D3DMatHandle);
1375 return DDERR_INVALIDPARAMS;
1378 /* The handle is simply a pointer to a D3DMATRIX structure */
1379 *D3DMatrix = *((D3DMATRIX *) This->Handles[D3DMatHandle - 1].ptr);
1384 /*****************************************************************************
1385 * IDirect3DDevice::DeleteMatrix
1387 * Destroys a Matrix handle. Frees the memory and unsets the handle data
1392 * D3DMatHandle: Handle to destroy
1396 * DDERR_INVALIDPARAMS if D3DMatHandle is invalid
1398 *****************************************************************************/
1399 static HRESULT WINAPI
1400 IDirect3DDeviceImpl_1_DeleteMatrix(IDirect3DDevice *iface,
1401 D3DMATRIXHANDLE D3DMatHandle)
1403 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1404 TRACE("(%p)->(%08x)\n", This, (DWORD) D3DMatHandle);
1407 return DDERR_INVALIDPARAMS;
1409 if(D3DMatHandle > This->numHandles)
1411 ERR("Handle %d out of range\n", D3DMatHandle);
1412 return DDERR_INVALIDPARAMS;
1414 else if(This->Handles[D3DMatHandle - 1].type != DDrawHandle_Matrix)
1416 ERR("Handle %d is not a matrix handle\n", D3DMatHandle);
1417 return DDERR_INVALIDPARAMS;
1420 HeapFree(GetProcessHeap(), 0, This->Handles[D3DMatHandle - 1].ptr);
1421 This->Handles[D3DMatHandle - 1].ptr = NULL;
1422 This->Handles[D3DMatHandle - 1].type = DDrawHandle_Unknown;
1427 /*****************************************************************************
1428 * IDirect3DDevice7::BeginScene
1430 * This method must be called before any rendering is performed.
1431 * IDirect3DDevice::EndScene has to be called after the scene is complete
1433 * Version 1, 2, 3 and 7
1436 * D3D_OK on success, for details see IWineD3DDevice::BeginScene
1437 * D3DERR_SCENE_IN_SCENE if WineD3D returns an error(Only in case of an already
1440 *****************************************************************************/
1441 static HRESULT WINAPI
1442 IDirect3DDeviceImpl_7_BeginScene(IDirect3DDevice7 *iface)
1444 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1446 TRACE("(%p): Relay\n", This);
1448 hr = IWineD3DDevice_BeginScene(This->wineD3DDevice);
1449 if(hr == WINED3D_OK) return D3D_OK;
1450 else return D3DERR_SCENE_IN_SCENE; /* TODO: Other possible causes of failure */
1453 static HRESULT WINAPI
1454 Thunk_IDirect3DDeviceImpl_3_BeginScene(IDirect3DDevice3 *iface)
1456 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1457 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1458 return IDirect3DDevice7_BeginScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1461 static HRESULT WINAPI
1462 Thunk_IDirect3DDeviceImpl_2_BeginScene(IDirect3DDevice2 *iface)
1464 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1465 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1466 return IDirect3DDevice7_BeginScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1469 static HRESULT WINAPI
1470 Thunk_IDirect3DDeviceImpl_1_BeginScene(IDirect3DDevice *iface)
1472 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1473 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1474 return IDirect3DDevice7_BeginScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1477 /*****************************************************************************
1478 * IDirect3DDevice7::EndScene
1480 * Ends a scene that has been begun with IDirect3DDevice7::BeginScene.
1481 * This method must be called after rendering is finished.
1483 * Version 1, 2, 3 and 7
1486 * D3D_OK on success, for details see IWineD3DDevice::EndScene
1487 * D3DERR_SCENE_NOT_IN_SCENE is returned if WineD3D returns an error. It does
1488 * that only if the scene was already ended.
1490 *****************************************************************************/
1491 static HRESULT WINAPI
1492 IDirect3DDeviceImpl_7_EndScene(IDirect3DDevice7 *iface)
1494 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1496 TRACE("(%p): Relay\n", This);
1498 hr = IWineD3DDevice_EndScene(This->wineD3DDevice);
1499 if(hr == WINED3D_OK) return D3D_OK;
1500 else return D3DERR_SCENE_NOT_IN_SCENE;
1503 static HRESULT WINAPI
1504 Thunk_IDirect3DDeviceImpl_3_EndScene(IDirect3DDevice3 *iface)
1506 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1507 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1508 return IDirect3DDevice7_EndScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1511 static HRESULT WINAPI
1512 Thunk_IDirect3DDeviceImpl_2_EndScene(IDirect3DDevice2 *iface)
1514 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1515 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1516 return IDirect3DDevice7_EndScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1519 static HRESULT WINAPI
1520 Thunk_IDirect3DDeviceImpl_1_EndScene(IDirect3DDevice *iface)
1522 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1523 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1524 return IDirect3DDevice7_EndScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1527 /*****************************************************************************
1528 * IDirect3DDevice7::GetDirect3D
1530 * Returns the IDirect3D(= interface to the DirectDraw object) used to create
1534 * Direct3D7: Address to store the interface pointer at
1538 * DDERR_INVALIDPARAMS if Direct3D7 == NULL
1540 *****************************************************************************/
1541 static HRESULT WINAPI
1542 IDirect3DDeviceImpl_7_GetDirect3D(IDirect3DDevice7 *iface,
1543 IDirect3D7 **Direct3D7)
1545 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1546 TRACE("(%p)->(%p)\n", This, Direct3D7);
1549 return DDERR_INVALIDPARAMS;
1551 *Direct3D7 = ICOM_INTERFACE(This->ddraw, IDirect3D7);
1552 IDirect3D7_AddRef(*Direct3D7);
1554 TRACE(" returning interface %p\n", *Direct3D7);
1558 static HRESULT WINAPI
1559 Thunk_IDirect3DDeviceImpl_3_GetDirect3D(IDirect3DDevice3 *iface,
1560 IDirect3D3 **Direct3D3)
1562 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1564 IDirect3D7 *ret_ptr;
1566 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, Direct3D3);
1567 ret = IDirect3DDevice7_GetDirect3D(ICOM_INTERFACE(This, IDirect3DDevice7),
1571 *Direct3D3 = COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D7, IDirect3D3, ret_ptr);
1572 TRACE(" returning interface %p\n", *Direct3D3);
1576 static HRESULT WINAPI
1577 Thunk_IDirect3DDeviceImpl_2_GetDirect3D(IDirect3DDevice2 *iface,
1578 IDirect3D2 **Direct3D2)
1580 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1582 IDirect3D7 *ret_ptr;
1584 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, Direct3D2);
1585 ret = IDirect3DDevice7_GetDirect3D(ICOM_INTERFACE(This, IDirect3DDevice7),
1589 *Direct3D2 = COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D7, IDirect3D2, ret_ptr);
1590 TRACE(" returning interface %p\n", *Direct3D2);
1594 static HRESULT WINAPI
1595 Thunk_IDirect3DDeviceImpl_1_GetDirect3D(IDirect3DDevice *iface,
1596 IDirect3D **Direct3D)
1598 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1600 IDirect3D7 *ret_ptr;
1602 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, Direct3D);
1603 ret = IDirect3DDevice7_GetDirect3D(ICOM_INTERFACE(This, IDirect3DDevice7),
1607 *Direct3D = COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D7, IDirect3D, ret_ptr);
1608 TRACE(" returning interface %p\n", *Direct3D);
1612 /*****************************************************************************
1613 * IDirect3DDevice3::SetCurrentViewport
1615 * Sets a Direct3DViewport as the current viewport.
1616 * For the thunks note that all viewport interface versions are equal
1619 * Direct3DViewport3: The viewport to set
1625 * (Is a NULL viewport valid?)
1627 *****************************************************************************/
1628 static HRESULT WINAPI
1629 IDirect3DDeviceImpl_3_SetCurrentViewport(IDirect3DDevice3 *iface,
1630 IDirect3DViewport3 *Direct3DViewport3)
1632 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1633 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport3);
1634 TRACE("(%p)->(%p)\n", This, Direct3DViewport3);
1636 /* Do nothing if the specified viewport is the same as the current one */
1637 if (This->current_viewport == vp )
1640 /* Should check if the viewport was added or not */
1642 /* Release previous viewport and AddRef the new one */
1643 if (This->current_viewport)
1645 TRACE("ViewportImpl is at %p, interface is at %p\n", This->current_viewport, ICOM_INTERFACE(This->current_viewport, IDirect3DViewport3));
1646 IDirect3DViewport3_Release( ICOM_INTERFACE(This->current_viewport, IDirect3DViewport3) );
1648 IDirect3DViewport3_AddRef(Direct3DViewport3);
1650 /* Set this viewport as the current viewport */
1651 This->current_viewport = vp;
1653 /* Activate this viewport */
1654 This->current_viewport->active_device = This;
1655 This->current_viewport->activate(This->current_viewport);
1660 static HRESULT WINAPI
1661 Thunk_IDirect3DDeviceImpl_2_SetCurrentViewport(IDirect3DDevice2 *iface,
1662 IDirect3DViewport2 *Direct3DViewport2)
1664 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1665 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport2);
1666 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, vp);
1667 return IDirect3DDevice3_SetCurrentViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
1668 ICOM_INTERFACE(vp, IDirect3DViewport3));
1671 /*****************************************************************************
1672 * IDirect3DDevice3::GetCurrentViewport
1674 * Returns the currently active viewport.
1679 * Direct3DViewport3: Address to return the interface pointer at
1683 * DDERR_INVALIDPARAMS if Direct3DViewport == NULL
1685 *****************************************************************************/
1686 static HRESULT WINAPI
1687 IDirect3DDeviceImpl_3_GetCurrentViewport(IDirect3DDevice3 *iface,
1688 IDirect3DViewport3 **Direct3DViewport3)
1690 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1691 TRACE("(%p)->(%p)\n", This, Direct3DViewport3);
1693 if(!Direct3DViewport3)
1694 return DDERR_INVALIDPARAMS;
1696 *Direct3DViewport3 = ICOM_INTERFACE(This->current_viewport, IDirect3DViewport3);
1698 /* AddRef the returned viewport */
1699 if(*Direct3DViewport3) IDirect3DViewport3_AddRef(*Direct3DViewport3);
1701 TRACE(" returning interface %p\n", *Direct3DViewport3);
1706 static HRESULT WINAPI
1707 Thunk_IDirect3DDeviceImpl_2_GetCurrentViewport(IDirect3DDevice2 *iface,
1708 IDirect3DViewport2 **Direct3DViewport2)
1710 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1712 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, Direct3DViewport2);
1713 hr = IDirect3DDevice3_GetCurrentViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
1714 (IDirect3DViewport3 **) Direct3DViewport2);
1715 if(hr != D3D_OK) return hr;
1716 *Direct3DViewport2 = (IDirect3DViewport2 *) COM_INTERFACE_CAST(IDirect3DViewportImpl, IDirect3DViewport3, IDirect3DViewport3, *Direct3DViewport2);
1720 /*****************************************************************************
1721 * IDirect3DDevice7::SetRenderTarget
1723 * Sets the render target for the Direct3DDevice.
1724 * For the thunks note that IDirectDrawSurface7 == IDirectDrawSurface4 and
1725 * IDirectDrawSurface3 == IDirectDrawSurface
1727 * Version 2, 3 and 7
1730 * NewTarget: Pointer to an IDirectDrawSurface7 interface to set as the new
1735 * D3D_OK on success, for details see IWineD3DDevice::SetRenderTarget
1737 *****************************************************************************/
1738 static HRESULT WINAPI
1739 IDirect3DDeviceImpl_7_SetRenderTarget(IDirect3DDevice7 *iface,
1740 IDirectDrawSurface7 *NewTarget,
1743 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1744 IDirectDrawSurfaceImpl *Target = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, NewTarget);
1746 TRACE("(%p)->(%p,%08x): Relay\n", This, NewTarget, Flags);
1748 /* Flags: Not used */
1750 hr = IWineD3DDevice_SetRenderTarget(This->wineD3DDevice,
1752 Target ? Target->WineD3DSurface : NULL);
1757 IDirectDrawSurface7_AddRef(NewTarget);
1758 IDirectDrawSurface7_Release(ICOM_INTERFACE(This->target, IDirectDrawSurface7));
1759 This->target = Target;
1760 IDirect3DDeviceImpl_UpdateDepthStencil(This);
1764 static HRESULT WINAPI
1765 Thunk_IDirect3DDeviceImpl_3_SetRenderTarget(IDirect3DDevice3 *iface,
1766 IDirectDrawSurface4 *NewRenderTarget,
1769 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1770 IDirectDrawSurfaceImpl *Target = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, NewRenderTarget);
1771 TRACE_(ddraw_thunk)("(%p)->(%p,%08x) thunking to IDirect3DDevice7 interface.\n", This, Target, Flags);
1772 return IDirect3DDevice7_SetRenderTarget(ICOM_INTERFACE(This, IDirect3DDevice7),
1773 ICOM_INTERFACE(Target, IDirectDrawSurface7),
1777 static HRESULT WINAPI
1778 Thunk_IDirect3DDeviceImpl_2_SetRenderTarget(IDirect3DDevice2 *iface,
1779 IDirectDrawSurface *NewRenderTarget,
1782 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1783 IDirectDrawSurfaceImpl *Target = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface3, NewRenderTarget);
1784 TRACE_(ddraw_thunk)("(%p)->(%p,%08x) thunking to IDirect3DDevice7 interface.\n", This, Target, Flags);
1785 return IDirect3DDevice7_SetRenderTarget(ICOM_INTERFACE(This, IDirect3DDevice7),
1786 ICOM_INTERFACE(Target, IDirectDrawSurface7),
1790 /*****************************************************************************
1791 * IDirect3DDevice7::GetRenderTarget
1793 * Returns the current render target.
1794 * This is handled locally, because the WineD3D render target's parent
1797 * Version 2, 3 and 7
1800 * RenderTarget: Address to store the surface interface pointer
1804 * DDERR_INVALIDPARAMS if RenderTarget == NULL
1806 *****************************************************************************/
1807 static HRESULT WINAPI
1808 IDirect3DDeviceImpl_7_GetRenderTarget(IDirect3DDevice7 *iface,
1809 IDirectDrawSurface7 **RenderTarget)
1811 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1812 TRACE("(%p)->(%p): Relay\n", This, RenderTarget);
1815 return DDERR_INVALIDPARAMS;
1817 *RenderTarget = ICOM_INTERFACE(This->target, IDirectDrawSurface7);
1818 IDirectDrawSurface7_AddRef(*RenderTarget);
1823 static HRESULT WINAPI
1824 Thunk_IDirect3DDeviceImpl_3_GetRenderTarget(IDirect3DDevice3 *iface,
1825 IDirectDrawSurface4 **RenderTarget)
1827 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1829 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, RenderTarget);
1830 hr = IDirect3DDevice7_GetRenderTarget(ICOM_INTERFACE(This, IDirect3DDevice7),
1831 (IDirectDrawSurface7 **) RenderTarget);
1832 if(hr != D3D_OK) return hr;
1833 *RenderTarget = (IDirectDrawSurface4 *) COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7, IDirectDrawSurface7, *RenderTarget);
1837 static HRESULT WINAPI
1838 Thunk_IDirect3DDeviceImpl_2_GetRenderTarget(IDirect3DDevice2 *iface,
1839 IDirectDrawSurface **RenderTarget)
1841 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1843 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, RenderTarget);
1844 hr = IDirect3DDevice7_GetRenderTarget(ICOM_INTERFACE(This, IDirect3DDevice7),
1845 (IDirectDrawSurface7 **) RenderTarget);
1846 if(hr != D3D_OK) return hr;
1847 *RenderTarget = (IDirectDrawSurface *) COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7, IDirectDrawSurface3, *RenderTarget);
1851 /*****************************************************************************
1852 * IDirect3DDevice3::Begin
1854 * Begins a description block of vertices. This is similar to glBegin()
1855 * and glEnd(). After a call to IDirect3DDevice3::End, the vertices
1856 * described with IDirect3DDevice::Vertex are drawn.
1861 * PrimitiveType: The type of primitives to draw
1862 * VertexTypeDesc: A flexible vertex format description of the vertices
1863 * Flags: Some flags..
1868 *****************************************************************************/
1869 static HRESULT WINAPI
1870 IDirect3DDeviceImpl_3_Begin(IDirect3DDevice3 *iface,
1871 D3DPRIMITIVETYPE PrimitiveType,
1872 DWORD VertexTypeDesc,
1875 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1876 TRACE("(%p)->(%d,%d,%08x)\n", This, PrimitiveType, VertexTypeDesc, Flags);
1878 This->primitive_type = PrimitiveType;
1879 This->vertex_type = VertexTypeDesc;
1880 This->render_flags = Flags;
1881 This->vertex_size = get_flexible_vertex_size(This->vertex_type);
1882 This->nb_vertices = 0;
1887 static HRESULT WINAPI
1888 Thunk_IDirect3DDeviceImpl_2_Begin(IDirect3DDevice2 *iface,
1889 D3DPRIMITIVETYPE d3dpt,
1890 D3DVERTEXTYPE dwVertexTypeDesc,
1894 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1895 TRACE_(ddraw_thunk)("(%p/%p)->(%08x,%08x,%08x): Thunking to IDirect3DDevice3\n", This, iface, d3dpt, dwVertexTypeDesc, dwFlags);
1897 switch(dwVertexTypeDesc)
1899 case D3DVT_VERTEX: FVF = D3DFVF_VERTEX; break;
1900 case D3DVT_LVERTEX: FVF = D3DFVF_LVERTEX; break;
1901 case D3DVT_TLVERTEX: FVF = D3DFVF_TLVERTEX; break;
1903 ERR("Unexpected vertex type %d\n", dwVertexTypeDesc);
1904 return DDERR_INVALIDPARAMS; /* Should never happen */
1907 return IDirect3DDevice3_Begin(ICOM_INTERFACE(This, IDirect3DDevice3),
1913 /*****************************************************************************
1914 * IDirect3DDevice3::BeginIndexed
1916 * Draws primitives based on vertices in a vertex array which are specified
1922 * PrimitiveType: Primitive type to draw
1923 * VertexType: A FVF description of the vertex format
1924 * Vertices: pointer to an array containing the vertices
1925 * NumVertices: The number of vertices in the vertex array
1926 * Flags: Some flags ...
1929 * D3D_OK, because it's a stub
1931 *****************************************************************************/
1932 static HRESULT WINAPI
1933 IDirect3DDeviceImpl_3_BeginIndexed(IDirect3DDevice3 *iface,
1934 D3DPRIMITIVETYPE PrimitiveType,
1940 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1941 FIXME("(%p)->(%08x,%08x,%p,%08x,%08x): stub!\n", This, PrimitiveType, VertexType, Vertices, NumVertices, Flags);
1946 static HRESULT WINAPI
1947 Thunk_IDirect3DDeviceImpl_2_BeginIndexed(IDirect3DDevice2 *iface,
1948 D3DPRIMITIVETYPE d3dptPrimitiveType,
1949 D3DVERTEXTYPE d3dvtVertexType,
1951 DWORD dwNumVertices,
1955 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1956 TRACE_(ddraw_thunk)("(%p/%p)->(%08x,%08x,%p,%08x,%08x): Thunking to IDirect3DDevice3\n", This, iface, d3dptPrimitiveType, d3dvtVertexType, lpvVertices, dwNumVertices, dwFlags);
1958 switch(d3dvtVertexType)
1960 case D3DVT_VERTEX: FVF = D3DFVF_VERTEX; break;
1961 case D3DVT_LVERTEX: FVF = D3DFVF_LVERTEX; break;
1962 case D3DVT_TLVERTEX: FVF = D3DFVF_TLVERTEX; break;
1964 ERR("Unexpected vertex type %d\n", d3dvtVertexType);
1965 return DDERR_INVALIDPARAMS; /* Should never happen */
1968 return IDirect3DDevice3_BeginIndexed(ICOM_INTERFACE(This,IDirect3DDevice3),
1976 /*****************************************************************************
1977 * IDirect3DDevice3::Vertex
1979 * Draws a vertex as described by IDirect3DDevice3::Begin. It places all
1980 * drawn vertices in a vertex buffer. If the buffer is too small, its
1981 * size is increased.
1986 * Vertex: Pointer to the vertex
1989 * D3D_OK, on success
1990 * DDERR_INVALIDPARAMS if Vertex is NULL
1992 *****************************************************************************/
1993 static HRESULT WINAPI
1994 IDirect3DDeviceImpl_3_Vertex(IDirect3DDevice3 *iface,
1997 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1998 TRACE("(%p)->(%p)\n", This, Vertex);
2001 return DDERR_INVALIDPARAMS;
2003 if ((This->nb_vertices+1)*This->vertex_size > This->buffer_size)
2006 This->buffer_size = This->buffer_size ? This->buffer_size * 2 : This->vertex_size * 3;
2007 old_buffer = This->vertex_buffer;
2008 This->vertex_buffer = HeapAlloc(GetProcessHeap(), 0, This->buffer_size);
2011 CopyMemory(This->vertex_buffer, old_buffer, This->nb_vertices * This->vertex_size);
2012 HeapFree(GetProcessHeap(), 0, old_buffer);
2016 CopyMemory(This->vertex_buffer + This->nb_vertices++ * This->vertex_size, Vertex, This->vertex_size);
2021 static HRESULT WINAPI
2022 Thunk_IDirect3DDeviceImpl_2_Vertex(IDirect3DDevice2 *iface,
2025 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2026 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, lpVertexType);
2027 return IDirect3DDevice3_Vertex(ICOM_INTERFACE(This, IDirect3DDevice3),
2031 /*****************************************************************************
2032 * IDirect3DDevice3::Index
2034 * Specifies an index to a vertex to be drawn. The vertex array has to
2035 * be specified with BeginIndexed first.
2038 * VertexIndex: The index of the vertex to draw
2041 * D3D_OK because it's a stub
2043 *****************************************************************************/
2044 static HRESULT WINAPI
2045 IDirect3DDeviceImpl_3_Index(IDirect3DDevice3 *iface,
2048 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2049 FIXME("(%p)->(%04x): stub!\n", This, VertexIndex);
2053 static HRESULT WINAPI
2054 Thunk_IDirect3DDeviceImpl_2_Index(IDirect3DDevice2 *iface,
2057 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2058 TRACE_(ddraw_thunk)("(%p)->(%04x) thunking to IDirect3DDevice3 interface.\n", This, wVertexIndex);
2059 return IDirect3DDevice3_Index(ICOM_INTERFACE(This, IDirect3DDevice3),
2063 /*****************************************************************************
2064 * IDirect3DDevice3::End
2066 * Ends a draw begun with IDirect3DDevice3::Begin or
2067 * IDirect3DDevice::BeginIndexed. The vertices specified with
2068 * IDirect3DDevice::Vertex or IDirect3DDevice::Index are drawn using
2069 * the IDirect3DDevice7::DrawPrimitive method. So far only
2070 * non-indexed mode is supported
2075 * Flags: Some flags, as usual. Don't know which are defined
2078 * The return value of IDirect3DDevice7::DrawPrimitive
2080 *****************************************************************************/
2081 static HRESULT WINAPI
2082 IDirect3DDeviceImpl_3_End(IDirect3DDevice3 *iface,
2085 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2086 TRACE("(%p)->(%08x)\n", This, Flags);
2088 return IDirect3DDevice7_DrawPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
2089 This->primitive_type, This->vertex_type,
2090 This->vertex_buffer, This->nb_vertices,
2091 This->render_flags);
2094 static HRESULT WINAPI
2095 Thunk_IDirect3DDeviceImpl_2_End(IDirect3DDevice2 *iface,
2098 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2099 TRACE_(ddraw_thunk)("(%p)->(%08x) thunking to IDirect3DDevice3 interface.\n", This, dwFlags);
2100 return IDirect3DDevice3_End(ICOM_INTERFACE(This, IDirect3DDevice3),
2104 /*****************************************************************************
2105 * IDirect3DDevice7::GetRenderState
2107 * Returns the value of a render state. The possible render states are
2108 * defined in include/d3dtypes.h
2110 * Version 2, 3 and 7
2113 * RenderStateType: Render state to return the current setting of
2114 * Value: Address to store the value at
2117 * D3D_OK on success, for details see IWineD3DDevice::GetRenderState
2118 * DDERR_INVALIDPARAMS if Value == NULL
2120 *****************************************************************************/
2121 static HRESULT WINAPI
2122 IDirect3DDeviceImpl_7_GetRenderState(IDirect3DDevice7 *iface,
2123 D3DRENDERSTATETYPE RenderStateType,
2126 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2128 TRACE("(%p)->(%08x,%p): Relay\n", This, RenderStateType, Value);
2131 return DDERR_INVALIDPARAMS;
2133 switch(RenderStateType)
2135 case D3DRENDERSTATE_TEXTUREHANDLE:
2137 /* This state is wrapped to SetTexture in SetRenderState, so
2138 * it has to be wrapped to GetTexture here
2140 IWineD3DBaseTexture *tex = NULL;
2143 hr = IWineD3DDevice_GetTexture(This->wineD3DDevice,
2147 if(hr == WINED3D_OK && tex)
2149 IDirectDrawSurface7 *parent = NULL;
2150 hr = IWineD3DBaseTexture_GetParent(tex,
2151 (IUnknown **) &parent);
2154 /* The parent of the texture is the IDirectDrawSurface7 interface
2155 * of the ddraw surface
2157 IDirectDrawSurfaceImpl *texImpl = ICOM_OBJECT(IDirectDrawSurfaceImpl,
2158 IDirectDrawSurface7,
2160 *Value = texImpl->Handle;
2161 IDirectDrawSurface7_Release(parent);
2163 IWineD3DBaseTexture_Release(tex);
2168 case D3DRENDERSTATE_TEXTUREMAG:
2170 WINED3DTEXTUREFILTERTYPE tex_mag;
2172 hr = IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
2173 0, WINED3DSAMP_MAGFILTER,
2178 case WINED3DTEXF_POINT:
2179 *Value = D3DFILTER_NEAREST;
2181 case WINED3DTEXF_LINEAR:
2182 *Value = D3DFILTER_LINEAR;
2185 ERR("Unhandled texture mag %d !\n",tex_mag);
2191 case D3DRENDERSTATE_TEXTUREMIN:
2193 WINED3DTEXTUREFILTERTYPE tex_min;
2195 hr = IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
2196 0, WINED3DSAMP_MINFILTER,
2201 case WINED3DTEXF_POINT:
2202 *Value = D3DFILTER_NEAREST;
2204 case WINED3DTEXF_LINEAR:
2205 *Value = D3DFILTER_LINEAR;
2208 ERR("Unhandled texture mag %d !\n",tex_min);
2214 case D3DRENDERSTATE_TEXTUREADDRESS:
2215 case D3DRENDERSTATE_TEXTUREADDRESSU:
2216 return IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
2217 0, WINED3DSAMP_ADDRESSU,
2219 case D3DRENDERSTATE_TEXTUREADDRESSV:
2220 return IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
2221 0, WINED3DSAMP_ADDRESSV,
2225 /* FIXME: Unhandled: D3DRENDERSTATE_STIPPLEPATTERN00 - 31 */
2226 return IWineD3DDevice_GetRenderState(This->wineD3DDevice,
2232 static HRESULT WINAPI
2233 Thunk_IDirect3DDeviceImpl_3_GetRenderState(IDirect3DDevice3 *iface,
2234 D3DRENDERSTATETYPE dwRenderStateType,
2235 DWORD *lpdwRenderState)
2237 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2238 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, dwRenderStateType, lpdwRenderState);
2239 return IDirect3DDevice7_GetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2244 static HRESULT WINAPI
2245 Thunk_IDirect3DDeviceImpl_2_GetRenderState(IDirect3DDevice2 *iface,
2246 D3DRENDERSTATETYPE dwRenderStateType,
2247 DWORD *lpdwRenderState)
2249 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2250 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, dwRenderStateType, lpdwRenderState);
2251 return IDirect3DDevice7_GetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2256 /*****************************************************************************
2257 * IDirect3DDevice7::SetRenderState
2259 * Sets a render state. The possible render states are defined in
2260 * include/d3dtypes.h
2262 * Version 2, 3 and 7
2265 * RenderStateType: State to set
2266 * Value: Value to assign to that state
2269 * D3D_OK on success,
2270 * for details see IWineD3DDevice::SetRenderState
2272 *****************************************************************************/
2273 static HRESULT WINAPI
2274 IDirect3DDeviceImpl_7_SetRenderState(IDirect3DDevice7 *iface,
2275 D3DRENDERSTATETYPE RenderStateType,
2278 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2279 TRACE("(%p)->(%08x,%d): Relay\n", This, RenderStateType, Value);
2281 /* Some render states need special care */
2282 switch(RenderStateType)
2284 case D3DRENDERSTATE_TEXTUREHANDLE:
2288 return IWineD3DDevice_SetTexture(This->wineD3DDevice,
2293 if(Value > This->numHandles)
2295 FIXME("Specified handle %d out of range\n", Value);
2296 return DDERR_INVALIDPARAMS;
2298 if(This->Handles[Value - 1].type != DDrawHandle_Texture)
2300 FIXME("Handle %d isn't a texture handle\n", Value);
2301 return DDERR_INVALIDPARAMS;
2305 IDirectDrawSurfaceImpl *surf = (IDirectDrawSurfaceImpl *) This->Handles[Value - 1].ptr;
2306 return IWineD3DDevice_SetTexture(This->wineD3DDevice,
2308 surf->wineD3DTexture);
2312 case D3DRENDERSTATE_TEXTUREMAG:
2314 WINED3DTEXTUREFILTERTYPE tex_mag = WINED3DTEXF_NONE;
2316 switch ((D3DTEXTUREFILTER) Value)
2318 case D3DFILTER_NEAREST:
2319 case D3DFILTER_LINEARMIPNEAREST:
2320 tex_mag = WINED3DTEXF_POINT;
2322 case D3DFILTER_LINEAR:
2323 case D3DFILTER_LINEARMIPLINEAR:
2324 tex_mag = WINED3DTEXF_LINEAR;
2327 ERR("Unhandled texture mag %d !\n",Value);
2330 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
2331 0, WINED3DSAMP_MAGFILTER,
2335 case D3DRENDERSTATE_TEXTUREMIN:
2337 WINED3DTEXTUREFILTERTYPE tex_min = WINED3DTEXF_NONE;
2338 WINED3DTEXTUREFILTERTYPE tex_mip = WINED3DTEXF_NONE;
2340 switch ((D3DTEXTUREFILTER) Value)
2342 case D3DFILTER_NEAREST:
2343 tex_min = WINED3DTEXF_POINT;
2345 case D3DFILTER_LINEAR:
2346 tex_min = WINED3DTEXF_LINEAR;
2348 case D3DFILTER_MIPNEAREST:
2349 tex_min = WINED3DTEXF_NONE;
2350 tex_mip = WINED3DTEXF_POINT;
2352 case D3DFILTER_MIPLINEAR:
2353 tex_min = WINED3DTEXF_NONE;
2354 tex_mip = WINED3DTEXF_LINEAR;
2356 case D3DFILTER_LINEARMIPNEAREST:
2357 tex_min = WINED3DTEXF_POINT;
2358 tex_mip = WINED3DTEXF_LINEAR;
2360 case D3DFILTER_LINEARMIPLINEAR:
2361 tex_min = WINED3DTEXF_LINEAR;
2362 tex_mip = WINED3DTEXF_LINEAR;
2366 ERR("Unhandled texture min %d !\n",Value);
2369 IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
2370 0, WINED3DSAMP_MIPFILTER,
2372 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
2373 0, WINED3DSAMP_MINFILTER,
2377 case D3DRENDERSTATE_TEXTUREADDRESS:
2378 IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
2379 0, WINED3DSAMP_ADDRESSV,
2382 case D3DRENDERSTATE_TEXTUREADDRESSU:
2383 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
2384 0, WINED3DSAMP_ADDRESSU,
2386 case D3DRENDERSTATE_TEXTUREADDRESSV:
2387 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
2388 0, WINED3DSAMP_ADDRESSV,
2391 case D3DRENDERSTATE_TEXTUREMAPBLEND:
2393 /* Old texture combine setup style, superseded by texture stage states
2394 * in D3D7. It is safe for us to wrap it to texture stage states.
2396 switch ( (D3DTEXTUREBLEND) Value)
2398 case D3DTBLEND_MODULATE:
2399 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLORARG1, WINED3DTA_TEXTURE);
2400 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAARG1, WINED3DTA_TEXTURE);
2401 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLORARG2, WINED3DTA_CURRENT);
2402 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLOROP, WINED3DTOP_MODULATE);
2403 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAOP, WINED3DTOP_SELECTARG1);
2406 case D3DTBLEND_MODULATEALPHA:
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_COLORARG2, WINED3DTA_CURRENT);
2410 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAARG2, WINED3DTA_CURRENT);
2411 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLOROP, WINED3DTOP_MODULATE);
2412 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAOP, WINED3DTOP_MODULATE);
2415 case D3DTBLEND_DECAL:
2416 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLORARG1, WINED3DTA_TEXTURE);
2417 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAARG1, WINED3DTA_TEXTURE);
2418 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLOROP, WINED3DTOP_SELECTARG1);
2419 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAOP, WINED3DTOP_SELECTARG1);
2422 case D3DTBLEND_DECALALPHA:
2423 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLORARG1, WINED3DTA_TEXTURE);
2424 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAARG1, WINED3DTA_TEXTURE);
2425 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAARG2, WINED3DTA_CURRENT);
2426 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLOROP, WINED3DTOP_SELECTARG1);
2427 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAOP, WINED3DTOP_MODULATE);
2431 ERR("Unhandled texture environment %d !\n",Value);
2439 /* FIXME: Unhandled: D3DRENDERSTATE_STIPPLEPATTERN00 - 31 */
2441 return IWineD3DDevice_SetRenderState(This->wineD3DDevice,
2447 static HRESULT WINAPI
2448 Thunk_IDirect3DDeviceImpl_3_SetRenderState(IDirect3DDevice3 *iface,
2449 D3DRENDERSTATETYPE RenderStateType,
2452 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2453 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, RenderStateType, Value);
2454 return IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2459 static HRESULT WINAPI
2460 Thunk_IDirect3DDeviceImpl_2_SetRenderState(IDirect3DDevice2 *iface,
2461 D3DRENDERSTATETYPE RenderStateType,
2464 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2465 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, RenderStateType, Value);
2466 return IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2471 /*****************************************************************************
2472 * Direct3DDevice3::SetLightState
2474 * Sets a light state for Direct3DDevice3 and Direct3DDevice2. The
2475 * light states are forwarded to Direct3DDevice7 render states
2480 * LightStateType: The light state to change
2481 * Value: The value to assign to that light state
2485 * DDERR_INVALIDPARAMS if the parameters were incorrect
2486 * Also check IDirect3DDevice7::SetRenderState
2488 *****************************************************************************/
2489 static HRESULT WINAPI
2490 IDirect3DDeviceImpl_3_SetLightState(IDirect3DDevice3 *iface,
2491 D3DLIGHTSTATETYPE LightStateType,
2494 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2496 TRACE("(%p)->(%08x,%08x)\n", This, LightStateType, Value);
2498 if (!LightStateType && (LightStateType > D3DLIGHTSTATE_COLORVERTEX))
2500 TRACE("Unexpected Light State Type\n");
2501 return DDERR_INVALIDPARAMS;
2504 if (LightStateType == D3DLIGHTSTATE_MATERIAL /* 1 */)
2506 IDirect3DMaterialImpl *mat;
2508 if(Value == 0) mat = NULL;
2509 else if(Value > This->numHandles)
2511 ERR("Material handle out of range(%d)\n", Value);
2512 return DDERR_INVALIDPARAMS;
2514 else if(This->Handles[Value - 1].type != DDrawHandle_Material)
2516 ERR("Invalid handle %d\n", Value);
2517 return DDERR_INVALIDPARAMS;
2521 mat = (IDirect3DMaterialImpl *) This->Handles[Value - 1].ptr;
2526 TRACE(" activating material %p.\n", mat);
2531 FIXME(" D3DLIGHTSTATE_MATERIAL called with NULL material !!!\n");
2533 This->material = Value;
2535 else if (LightStateType == D3DLIGHTSTATE_COLORMODEL /* 3 */)
2540 ERR("DDCOLOR_MONO should not happen!\n");
2543 /* We are already in this mode */
2544 TRACE("Setting color model to RGB (no-op).\n");
2547 ERR("Unknown color model!\n");
2548 return DDERR_INVALIDPARAMS;
2553 D3DRENDERSTATETYPE rs;
2554 switch (LightStateType)
2556 case D3DLIGHTSTATE_AMBIENT: /* 2 */
2557 rs = D3DRENDERSTATE_AMBIENT;
2559 case D3DLIGHTSTATE_FOGMODE: /* 4 */
2560 rs = D3DRENDERSTATE_FOGVERTEXMODE;
2562 case D3DLIGHTSTATE_FOGSTART: /* 5 */
2563 rs = D3DRENDERSTATE_FOGSTART;
2565 case D3DLIGHTSTATE_FOGEND: /* 6 */
2566 rs = D3DRENDERSTATE_FOGEND;
2568 case D3DLIGHTSTATE_FOGDENSITY: /* 7 */
2569 rs = D3DRENDERSTATE_FOGDENSITY;
2571 case D3DLIGHTSTATE_COLORVERTEX: /* 8 */
2572 rs = D3DRENDERSTATE_COLORVERTEX;
2575 ERR("Unknown D3DLIGHTSTATETYPE %d.\n", LightStateType);
2576 return DDERR_INVALIDPARAMS;
2579 return IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2587 static HRESULT WINAPI
2588 Thunk_IDirect3DDeviceImpl_2_SetLightState(IDirect3DDevice2 *iface,
2589 D3DLIGHTSTATETYPE LightStateType,
2592 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2593 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x) thunking to IDirect3DDevice3 interface.\n", This, LightStateType, Value);
2594 return IDirect3DDevice3_SetLightState(ICOM_INTERFACE(This, IDirect3DDevice3),
2599 /*****************************************************************************
2600 * IDirect3DDevice3::GetLightState
2602 * Returns the current setting of a light state. The state is read from
2603 * the Direct3DDevice7 render state.
2608 * LightStateType: The light state to return
2609 * Value: The address to store the light state setting at
2613 * DDDERR_INVALIDPARAMS if the parameters were incorrect
2614 * Also see IDirect3DDevice7::GetRenderState
2616 *****************************************************************************/
2617 static HRESULT WINAPI
2618 IDirect3DDeviceImpl_3_GetLightState(IDirect3DDevice3 *iface,
2619 D3DLIGHTSTATETYPE LightStateType,
2622 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2624 TRACE("(%p)->(%08x,%p)\n", This, LightStateType, Value);
2626 if (!LightStateType && (LightStateType > D3DLIGHTSTATE_COLORVERTEX))
2628 TRACE("Unexpected Light State Type\n");
2629 return DDERR_INVALIDPARAMS;
2633 return DDERR_INVALIDPARAMS;
2635 if (LightStateType == D3DLIGHTSTATE_MATERIAL /* 1 */)
2637 *Value = This->material;
2639 else if (LightStateType == D3DLIGHTSTATE_COLORMODEL /* 3 */)
2641 *Value = D3DCOLOR_RGB;
2645 D3DRENDERSTATETYPE rs;
2646 switch (LightStateType)
2648 case D3DLIGHTSTATE_AMBIENT: /* 2 */
2649 rs = D3DRENDERSTATE_AMBIENT;
2651 case D3DLIGHTSTATE_FOGMODE: /* 4 */
2652 rs = D3DRENDERSTATE_FOGVERTEXMODE;
2654 case D3DLIGHTSTATE_FOGSTART: /* 5 */
2655 rs = D3DRENDERSTATE_FOGSTART;
2657 case D3DLIGHTSTATE_FOGEND: /* 6 */
2658 rs = D3DRENDERSTATE_FOGEND;
2660 case D3DLIGHTSTATE_FOGDENSITY: /* 7 */
2661 rs = D3DRENDERSTATE_FOGDENSITY;
2663 case D3DLIGHTSTATE_COLORVERTEX: /* 8 */
2664 rs = D3DRENDERSTATE_COLORVERTEX;
2667 ERR("Unknown D3DLIGHTSTATETYPE %d.\n", LightStateType);
2668 return DDERR_INVALIDPARAMS;
2671 return IDirect3DDevice7_GetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2679 static HRESULT WINAPI
2680 Thunk_IDirect3DDeviceImpl_2_GetLightState(IDirect3DDevice2 *iface,
2681 D3DLIGHTSTATETYPE LightStateType,
2684 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2685 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice3 interface.\n", This, LightStateType, Value);
2686 return IDirect3DDevice3_GetLightState(ICOM_INTERFACE(This, IDirect3DDevice3),
2691 /*****************************************************************************
2692 * IDirect3DDevice7::SetTransform
2694 * Assigns a D3DMATRIX to a transform type. The transform types are defined
2695 * in include/d3dtypes.h.
2696 * The D3DTRANSFORMSTATE_WORLD (=1) is translated to D3DTS_WORLDMATRIX(0)
2697 * (=255) for wined3d, because the 1 transform state was removed in d3d8
2698 * and WineD3D already understands the replacement D3DTS_WORLDMATRIX(0)
2700 * Version 2, 3 and 7
2703 * TransformStateType: transform state to set
2704 * Matrix: Matrix to assign to the state
2708 * DDERR_INVALIDPARAMS if Matrix == NULL
2709 * For details see IWineD3DDevice::SetTransform
2711 *****************************************************************************/
2712 static HRESULT WINAPI
2713 IDirect3DDeviceImpl_7_SetTransform(IDirect3DDevice7 *iface,
2714 D3DTRANSFORMSTATETYPE TransformStateType,
2717 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2718 D3DTRANSFORMSTATETYPE type = TransformStateType;
2719 TRACE("(%p)->(%08x,%p): Relay\n", This, TransformStateType, Matrix);
2722 return DDERR_INVALIDPARAMS;
2724 switch(TransformStateType)
2726 case D3DTRANSFORMSTATE_WORLD : type = WINED3DTS_WORLDMATRIX(0); break;
2727 case D3DTRANSFORMSTATE_WORLD1: type = WINED3DTS_WORLDMATRIX(1); break;
2728 case D3DTRANSFORMSTATE_WORLD2: type = WINED3DTS_WORLDMATRIX(2); break;
2729 case D3DTRANSFORMSTATE_WORLD3: type = WINED3DTS_WORLDMATRIX(3); break;
2730 default: type = TransformStateType;
2733 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
2734 return IWineD3DDevice_SetTransform(This->wineD3DDevice,
2736 (WINED3DMATRIX*) Matrix);
2739 static HRESULT WINAPI
2740 Thunk_IDirect3DDeviceImpl_3_SetTransform(IDirect3DDevice3 *iface,
2741 D3DTRANSFORMSTATETYPE TransformStateType,
2742 D3DMATRIX *D3DMatrix)
2744 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, 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 static HRESULT WINAPI
2752 Thunk_IDirect3DDeviceImpl_2_SetTransform(IDirect3DDevice2 *iface,
2753 D3DTRANSFORMSTATETYPE TransformStateType,
2754 D3DMATRIX *D3DMatrix)
2756 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2757 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2758 return IDirect3DDevice7_SetTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2763 /*****************************************************************************
2764 * IDirect3DDevice7::GetTransform
2766 * Returns the matrix assigned to a transform state
2767 * D3DTRANSFORMSTATE_WORLD is translated to D3DTS_WORLDMATRIX(0), see
2771 * TransformStateType: State to read the matrix from
2772 * Matrix: Address to store the matrix at
2776 * DDERR_INVALIDPARAMS if Matrix == NULL
2777 * For details, see IWineD3DDevice::GetTransform
2779 *****************************************************************************/
2780 static HRESULT WINAPI
2781 IDirect3DDeviceImpl_7_GetTransform(IDirect3DDevice7 *iface,
2782 D3DTRANSFORMSTATETYPE TransformStateType,
2785 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2786 D3DTRANSFORMSTATETYPE type = TransformStateType;
2787 TRACE("(%p)->(%08x,%p): Relay\n", This, TransformStateType, Matrix);
2790 return DDERR_INVALIDPARAMS;
2792 switch(TransformStateType)
2794 case D3DTRANSFORMSTATE_WORLD : type = WINED3DTS_WORLDMATRIX(0); break;
2795 case D3DTRANSFORMSTATE_WORLD1: type = WINED3DTS_WORLDMATRIX(1); break;
2796 case D3DTRANSFORMSTATE_WORLD2: type = WINED3DTS_WORLDMATRIX(2); break;
2797 case D3DTRANSFORMSTATE_WORLD3: type = WINED3DTS_WORLDMATRIX(3); break;
2798 default: type = TransformStateType;
2801 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
2802 return IWineD3DDevice_GetTransform(This->wineD3DDevice, type, (WINED3DMATRIX*) Matrix);
2805 static HRESULT WINAPI
2806 Thunk_IDirect3DDeviceImpl_3_GetTransform(IDirect3DDevice3 *iface,
2807 D3DTRANSFORMSTATETYPE TransformStateType,
2808 D3DMATRIX *D3DMatrix)
2810 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2811 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2812 return IDirect3DDevice7_GetTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2817 static HRESULT WINAPI
2818 Thunk_IDirect3DDeviceImpl_2_GetTransform(IDirect3DDevice2 *iface,
2819 D3DTRANSFORMSTATETYPE TransformStateType,
2820 D3DMATRIX *D3DMatrix)
2822 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2823 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2824 return IDirect3DDevice7_GetTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2829 /*****************************************************************************
2830 * IDirect3DDevice7::MultiplyTransform
2832 * Multiplies the already-set transform matrix of a transform state
2833 * with another matrix. For the world matrix, see SetTransform
2835 * Version 2, 3 and 7
2838 * TransformStateType: Transform state to multiply
2839 * D3DMatrix Matrix to multiply with.
2843 * DDERR_INVALIDPARAMS if D3DMatrix is NULL
2844 * For details, see IWineD3DDevice::MultiplyTransform
2846 *****************************************************************************/
2847 static HRESULT WINAPI
2848 IDirect3DDeviceImpl_7_MultiplyTransform(IDirect3DDevice7 *iface,
2849 D3DTRANSFORMSTATETYPE TransformStateType,
2850 D3DMATRIX *D3DMatrix)
2852 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2853 D3DTRANSFORMSTATETYPE type;
2854 TRACE("(%p)->(%08x,%p): Relay\n", This, TransformStateType, D3DMatrix);
2856 switch(TransformStateType)
2858 case D3DTRANSFORMSTATE_WORLD : type = WINED3DTS_WORLDMATRIX(0); break;
2859 case D3DTRANSFORMSTATE_WORLD1: type = WINED3DTS_WORLDMATRIX(1); break;
2860 case D3DTRANSFORMSTATE_WORLD2: type = WINED3DTS_WORLDMATRIX(2); break;
2861 case D3DTRANSFORMSTATE_WORLD3: type = WINED3DTS_WORLDMATRIX(3); break;
2862 default: type = TransformStateType;
2865 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
2866 return IWineD3DDevice_MultiplyTransform(This->wineD3DDevice,
2868 (WINED3DMATRIX*) D3DMatrix);
2871 static HRESULT WINAPI
2872 Thunk_IDirect3DDeviceImpl_3_MultiplyTransform(IDirect3DDevice3 *iface,
2873 D3DTRANSFORMSTATETYPE TransformStateType,
2874 D3DMATRIX *D3DMatrix)
2876 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2877 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2878 return IDirect3DDevice7_MultiplyTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2883 static HRESULT WINAPI
2884 Thunk_IDirect3DDeviceImpl_2_MultiplyTransform(IDirect3DDevice2 *iface,
2885 D3DTRANSFORMSTATETYPE TransformStateType,
2886 D3DMATRIX *D3DMatrix)
2888 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2889 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2890 return IDirect3DDevice7_MultiplyTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2895 /*****************************************************************************
2896 * IDirect3DDevice7::DrawPrimitive
2898 * Draws primitives based on vertices in an application-provided pointer
2900 * Version 2, 3 and 7. The IDirect3DDevice2 thunk converts the fixed vertex type into
2901 * an FVF format for D3D7
2904 * PrimitiveType: The type of the primitives to draw
2905 * Vertex type: Flexible vertex format vertex description
2906 * Vertices: Pointer to the vertex array
2907 * VertexCount: The number of vertices to draw
2908 * Flags: As usual a few flags
2912 * DDERR_INVALIDPARAMS if Vertices is NULL
2913 * For details, see IWineD3DDevice::DrawPrimitiveUP
2915 *****************************************************************************/
2916 static HRESULT WINAPI
2917 IDirect3DDeviceImpl_7_DrawPrimitive(IDirect3DDevice7 *iface,
2918 D3DPRIMITIVETYPE PrimitiveType,
2924 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2925 UINT PrimitiveCount, stride;
2927 TRACE("(%p)->(%08x,%08x,%p,%08x,%08x): Relay!\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Flags);
2930 return DDERR_INVALIDPARAMS;
2932 /* Get the vertex count */
2933 switch(PrimitiveType)
2935 case D3DPT_POINTLIST:
2936 PrimitiveCount = VertexCount;
2939 case D3DPT_LINELIST:
2940 PrimitiveCount = VertexCount / 2;
2943 case D3DPT_LINESTRIP:
2944 PrimitiveCount = VertexCount - 1;
2947 case D3DPT_TRIANGLELIST:
2948 PrimitiveCount = VertexCount / 3;
2951 case D3DPT_TRIANGLESTRIP:
2952 PrimitiveCount = VertexCount - 2;
2955 case D3DPT_TRIANGLEFAN:
2956 PrimitiveCount = VertexCount - 2;
2959 default: return DDERR_INVALIDPARAMS;
2962 /* Get the stride */
2963 stride = get_flexible_vertex_size(VertexType);
2966 hr = IWineD3DDevice_SetVertexDeclaration(This->wineD3DDevice,
2967 IDirectDrawImpl_FindDecl(This->ddraw, VertexType));
2968 if(hr != D3D_OK) return hr;
2970 /* This method translates to the user pointer draw of WineD3D */
2971 return IWineD3DDevice_DrawPrimitiveUP(This->wineD3DDevice,
2978 static HRESULT WINAPI
2979 Thunk_IDirect3DDeviceImpl_3_DrawPrimitive(IDirect3DDevice3 *iface,
2980 D3DPRIMITIVETYPE PrimitiveType,
2986 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2987 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Flags);
2988 return IDirect3DDevice7_DrawPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
2996 static HRESULT WINAPI
2997 Thunk_IDirect3DDeviceImpl_2_DrawPrimitive(IDirect3DDevice2 *iface,
2998 D3DPRIMITIVETYPE PrimitiveType,
2999 D3DVERTEXTYPE VertexType,
3004 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
3006 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Flags);
3010 case D3DVT_VERTEX: FVF = D3DFVF_VERTEX; break;
3011 case D3DVT_LVERTEX: FVF = D3DFVF_LVERTEX; break;
3012 case D3DVT_TLVERTEX: FVF = D3DFVF_TLVERTEX; break;
3014 ERR("Unexpected vertex type %d\n", VertexType);
3015 return DDERR_INVALIDPARAMS; /* Should never happen */
3018 return IDirect3DDevice7_DrawPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
3026 /*****************************************************************************
3027 * IDirect3DDevice7::DrawIndexedPrimitive
3029 * Draws vertices from an application-provided pointer, based on the index
3030 * numbers in a WORD array.
3032 * Version 2, 3 and 7. The version 7 thunk translates the vertex type into
3033 * an FVF format for D3D7
3036 * PrimitiveType: The primitive type to draw
3037 * VertexType: The FVF vertex description
3038 * Vertices: Pointer to the vertex array
3040 * Indices: Pointer to the index array
3041 * IndexCount: Number of indices = Number of vertices to draw
3042 * Flags: As usual, some flags
3046 * DDERR_INVALIDPARAMS if Vertices or Indices is NULL
3047 * For details, see IWineD3DDevice::DrawIndexedPrimitiveUP
3049 *****************************************************************************/
3050 static HRESULT WINAPI
3051 IDirect3DDeviceImpl_7_DrawIndexedPrimitive(IDirect3DDevice7 *iface,
3052 D3DPRIMITIVETYPE PrimitiveType,
3060 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3061 UINT PrimitiveCount = 0;
3063 TRACE("(%p)->(%08x,%08x,%p,%08x,%p,%08x,%08x): Relay!\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Indices, IndexCount, Flags);
3064 /* Get the primitive number */
3065 switch(PrimitiveType)
3067 case D3DPT_POINTLIST:
3068 PrimitiveCount = IndexCount;
3071 case D3DPT_LINELIST:
3072 PrimitiveCount = IndexCount / 2;
3075 case D3DPT_LINESTRIP:
3076 PrimitiveCount = IndexCount - 1;
3079 case D3DPT_TRIANGLELIST:
3080 PrimitiveCount = IndexCount / 3;
3083 case D3DPT_TRIANGLESTRIP:
3084 PrimitiveCount = IndexCount - 2;
3087 case D3DPT_TRIANGLEFAN:
3088 PrimitiveCount = IndexCount - 2;
3091 default: return DDERR_INVALIDPARAMS;
3094 /* Set the D3DDevice's FVF */
3095 hr = IWineD3DDevice_SetVertexDeclaration(This->wineD3DDevice,
3096 IDirectDrawImpl_FindDecl(This->ddraw, VertexType));
3099 ERR(" (%p) Setting the FVF failed, hr = %x!\n", This, hr);
3103 return IWineD3DDevice_DrawIndexedPrimitiveUP(This->wineD3DDevice,
3105 0 /* MinVertexIndex */,
3106 VertexCount /* UINT NumVertexIndex */,
3111 get_flexible_vertex_size(VertexType));
3114 static HRESULT WINAPI
3115 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitive(IDirect3DDevice3 *iface,
3116 D3DPRIMITIVETYPE PrimitiveType,
3124 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3125 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Indices, IndexCount, Flags);
3126 return IDirect3DDevice7_DrawIndexedPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
3136 static HRESULT WINAPI
3137 Thunk_IDirect3DDeviceImpl_2_DrawIndexedPrimitive(IDirect3DDevice2 *iface,
3138 D3DPRIMITIVETYPE PrimitiveType,
3139 D3DVERTEXTYPE VertexType,
3147 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
3148 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Indices, IndexCount, Flags);
3152 case D3DVT_VERTEX: FVF = D3DFVF_VERTEX; break;
3153 case D3DVT_LVERTEX: FVF = D3DFVF_LVERTEX; break;
3154 case D3DVT_TLVERTEX: FVF = D3DFVF_TLVERTEX; break;
3156 ERR("Unexpected vertex type %d\n", VertexType);
3157 return DDERR_INVALIDPARAMS; /* Should never happen */
3160 return IDirect3DDevice7_DrawIndexedPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
3170 /*****************************************************************************
3171 * IDirect3DDevice7::SetClipStatus
3173 * Sets the clip status. This defines things as clipping conditions and
3174 * the extents of the clipping region.
3176 * Version 2, 3 and 7
3182 * D3D_OK because it's a stub
3183 * (DDERR_INVALIDPARAMS if ClipStatus == NULL)
3185 *****************************************************************************/
3186 static HRESULT WINAPI
3187 IDirect3DDeviceImpl_7_SetClipStatus(IDirect3DDevice7 *iface,
3188 D3DCLIPSTATUS *ClipStatus)
3190 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3191 FIXME("(%p)->(%p): Stub!\n", This, ClipStatus);
3193 /* D3DCLIPSTATUS and WINED3DCLIPSTATUS are different. I don't know how to convert them
3194 * Perhaps this needs a new data type and an additional IWineD3DDevice method
3196 /* return IWineD3DDevice_SetClipStatus(This->wineD3DDevice, ClipStatus);*/
3200 static HRESULT WINAPI
3201 Thunk_IDirect3DDeviceImpl_3_SetClipStatus(IDirect3DDevice3 *iface,
3202 D3DCLIPSTATUS *ClipStatus)
3204 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3205 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, ClipStatus);
3206 return IDirect3DDevice7_SetClipStatus(ICOM_INTERFACE(This, IDirect3DDevice7),
3210 static HRESULT WINAPI
3211 Thunk_IDirect3DDeviceImpl_2_SetClipStatus(IDirect3DDevice2 *iface,
3212 D3DCLIPSTATUS *ClipStatus)
3214 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
3215 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, ClipStatus);
3216 return IDirect3DDevice7_SetClipStatus(ICOM_INTERFACE(This, IDirect3DDevice7),
3220 /*****************************************************************************
3221 * IDirect3DDevice7::GetClipStatus
3223 * Returns the clip status
3226 * ClipStatus: Address to write the clip status to
3229 * D3D_OK because it's a stub
3231 *****************************************************************************/
3232 static HRESULT WINAPI
3233 IDirect3DDeviceImpl_7_GetClipStatus(IDirect3DDevice7 *iface,
3234 D3DCLIPSTATUS *ClipStatus)
3236 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3237 FIXME("(%p)->(%p): Stub!\n", This, ClipStatus);
3239 /* D3DCLIPSTATUS and WINED3DCLIPSTATUS are different. I don't know how to convert them */
3240 /* return IWineD3DDevice_GetClipStatus(This->wineD3DDevice, ClipStatus);*/
3244 static HRESULT WINAPI
3245 Thunk_IDirect3DDeviceImpl_3_GetClipStatus(IDirect3DDevice3 *iface,
3246 D3DCLIPSTATUS *ClipStatus)
3248 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3249 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, ClipStatus);
3250 return IDirect3DDevice7_GetClipStatus(ICOM_INTERFACE(This, IDirect3DDevice7),
3254 static HRESULT WINAPI
3255 Thunk_IDirect3DDeviceImpl_2_GetClipStatus(IDirect3DDevice2 *iface,
3256 D3DCLIPSTATUS *ClipStatus)
3258 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
3259 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, ClipStatus);
3260 return IDirect3DDevice7_GetClipStatus(ICOM_INTERFACE(This, IDirect3DDevice7),
3264 /*****************************************************************************
3265 * IDirect3DDevice::DrawPrimitiveStrided
3267 * Draws vertices described by a D3DDRAWPRIMITIVESTRIDEDDATA structure.
3272 * PrimitiveType: The primitive type to draw
3273 * VertexType: The FVF description of the vertices to draw (for the stride??)
3274 * D3DDrawPrimStrideData: A D3DDRAWPRIMITIVESTRIDEDDATA structure describing
3275 * the vertex data locations
3276 * VertexCount: The number of vertices to draw
3280 * D3D_OK, because it's a stub
3281 * (DDERR_INVALIDPARAMS if D3DDrawPrimStrideData is NULL)
3282 * (For details, see IWineD3DDevice::DrawPrimitiveStrided)
3284 *****************************************************************************/
3285 static HRESULT WINAPI
3286 IDirect3DDeviceImpl_7_DrawPrimitiveStrided(IDirect3DDevice7 *iface,
3287 D3DPRIMITIVETYPE PrimitiveType,
3289 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3293 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3294 WineDirect3DVertexStridedData WineD3DStrided;
3296 UINT PrimitiveCount;
3298 TRACE("(%p)->(%08x,%08x,%p,%08x,%08x): stub!\n", This, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Flags);
3300 memset(&WineD3DStrided, 0, sizeof(WineD3DStrided));
3301 /* Get the strided data right. the wined3d structure is a bit bigger
3302 * Watch out: The contents of the strided data are determined by the fvf,
3303 * not by the members set in D3DDrawPrimStrideData. So it's valid
3304 * to have diffuse.lpvData set to 0xdeadbeef if the diffuse flag is
3305 * not set in the fvf.
3307 if(VertexType & D3DFVF_POSITION_MASK)
3309 WineD3DStrided.u.s.position.lpData = D3DDrawPrimStrideData->position.lpvData;
3310 WineD3DStrided.u.s.position.dwStride = D3DDrawPrimStrideData->position.dwStride;
3311 WineD3DStrided.u.s.position.dwType = WINED3DDECLTYPE_FLOAT3;
3312 if (VertexType & D3DFVF_XYZRHW)
3314 WineD3DStrided.u.s.position.dwType = WINED3DDECLTYPE_FLOAT4;
3315 WineD3DStrided.u.s.position_transformed = TRUE;
3317 WineD3DStrided.u.s.position_transformed = FALSE;
3320 if(VertexType & D3DFVF_NORMAL)
3322 WineD3DStrided.u.s.normal.lpData = D3DDrawPrimStrideData->normal.lpvData;
3323 WineD3DStrided.u.s.normal.dwStride = D3DDrawPrimStrideData->normal.dwStride;
3324 WineD3DStrided.u.s.normal.dwType = WINED3DDECLTYPE_FLOAT3;
3327 if(VertexType & D3DFVF_DIFFUSE)
3329 WineD3DStrided.u.s.diffuse.lpData = D3DDrawPrimStrideData->diffuse.lpvData;
3330 WineD3DStrided.u.s.diffuse.dwStride = D3DDrawPrimStrideData->diffuse.dwStride;
3331 WineD3DStrided.u.s.diffuse.dwType = WINED3DDECLTYPE_SHORT4;
3334 if(VertexType & D3DFVF_SPECULAR)
3336 WineD3DStrided.u.s.specular.lpData = D3DDrawPrimStrideData->specular.lpvData;
3337 WineD3DStrided.u.s.specular.dwStride = D3DDrawPrimStrideData->specular.dwStride;
3338 WineD3DStrided.u.s.specular.dwType = WINED3DDECLTYPE_SHORT4;
3341 for( i = 0; i < GET_TEXCOUNT_FROM_FVF(VertexType); i++)
3343 WineD3DStrided.u.s.texCoords[i].lpData = D3DDrawPrimStrideData->textureCoords[i].lpvData;
3344 WineD3DStrided.u.s.texCoords[i].dwStride = D3DDrawPrimStrideData->textureCoords[i].dwStride;
3345 switch(GET_TEXCOORD_SIZE_FROM_FVF(VertexType, i))
3347 case 1: WineD3DStrided.u.s.texCoords[i].dwType = WINED3DDECLTYPE_FLOAT1; break;
3348 case 2: WineD3DStrided.u.s.texCoords[i].dwType = WINED3DDECLTYPE_FLOAT2; break;
3349 case 3: WineD3DStrided.u.s.texCoords[i].dwType = WINED3DDECLTYPE_FLOAT3; break;
3350 case 4: WineD3DStrided.u.s.texCoords[i].dwType = WINED3DDECLTYPE_FLOAT4; break;
3351 default: ERR("Unexpected texture coordinate size %d\n",
3352 GET_TEXCOORD_SIZE_FROM_FVF(VertexType, i));
3356 /* Get the primitive count */
3357 switch(PrimitiveType)
3359 case D3DPT_POINTLIST:
3360 PrimitiveCount = VertexCount;
3363 case D3DPT_LINELIST:
3364 PrimitiveCount = VertexCount / 2;
3367 case D3DPT_LINESTRIP:
3368 PrimitiveCount = VertexCount - 1;
3371 case D3DPT_TRIANGLELIST:
3372 PrimitiveCount = VertexCount / 3;
3375 case D3DPT_TRIANGLESTRIP:
3376 PrimitiveCount = VertexCount - 2;
3379 case D3DPT_TRIANGLEFAN:
3380 PrimitiveCount = VertexCount - 2;
3383 default: return DDERR_INVALIDPARAMS;
3386 /* WineD3D doesn't need the FVF here */
3387 return IWineD3DDevice_DrawPrimitiveStrided(This->wineD3DDevice,
3393 static HRESULT WINAPI
3394 Thunk_IDirect3DDeviceImpl_3_DrawPrimitiveStrided(IDirect3DDevice3 *iface,
3395 D3DPRIMITIVETYPE PrimitiveType,
3397 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3401 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3402 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Flags);
3403 return IDirect3DDevice7_DrawPrimitiveStrided(ICOM_INTERFACE(This, IDirect3DDevice7),
3406 D3DDrawPrimStrideData,
3411 /*****************************************************************************
3412 * IDirect3DDevice7::DrawIndexedPrimitiveStrided
3414 * Draws primitives specified by strided data locations based on indices
3422 * D3D_OK, because it's a stub
3423 * (DDERR_INVALIDPARAMS if D3DDrawPrimStrideData is NULL)
3424 * (DDERR_INVALIDPARAMS if Indices is NULL)
3425 * (For more details, see IWineD3DDevice::DrawIndexedPrimitiveStrided)
3427 *****************************************************************************/
3428 static HRESULT WINAPI
3429 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveStrided(IDirect3DDevice7 *iface,
3430 D3DPRIMITIVETYPE PrimitiveType,
3432 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3438 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3439 FIXME("(%p)->(%08x,%08x,%p,%08x,%p,%08x,%08x): stub!\n", This, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Indices, IndexCount, Flags);
3441 /* I'll implement it as soon as I find a app to test it.
3442 * This needs an additional method in IWineD3DDevice.
3447 static HRESULT WINAPI
3448 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitiveStrided(IDirect3DDevice3 *iface,
3449 D3DPRIMITIVETYPE PrimitiveType,
3451 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3457 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3458 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", iface, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Indices, IndexCount, Flags);
3459 return IDirect3DDevice7_DrawIndexedPrimitiveStrided(ICOM_INTERFACE(This, IDirect3DDevice7),
3462 D3DDrawPrimStrideData,
3469 /*****************************************************************************
3470 * IDirect3DDevice7::DrawPrimitiveVB
3472 * Draws primitives from a vertex buffer to the screen.
3477 * PrimitiveType: Type of primitive to be rendered.
3478 * D3DVertexBuf: Source Vertex Buffer
3479 * StartVertex: Index of the first vertex from the buffer to be rendered
3480 * NumVertices: Number of vertices to be rendered
3481 * Flags: Can be D3DDP_WAIT to wait until rendering has finished
3485 * DDERR_INVALIDPARAMS if D3DVertexBuf is NULL
3487 *****************************************************************************/
3488 static HRESULT WINAPI
3489 IDirect3DDeviceImpl_7_DrawPrimitiveVB(IDirect3DDevice7 *iface,
3490 D3DPRIMITIVETYPE PrimitiveType,
3491 IDirect3DVertexBuffer7 *D3DVertexBuf,
3496 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3497 IDirect3DVertexBufferImpl *vb = ICOM_OBJECT(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, D3DVertexBuf);
3498 UINT PrimitiveCount;
3501 WINED3DVERTEXBUFFER_DESC Desc;
3503 TRACE("(%p)->(%08x,%p,%08x,%08x,%08x)\n", This, PrimitiveType, D3DVertexBuf, StartVertex, NumVertices, Flags);
3508 ERR("(%p) No Vertex buffer specified\n", This);
3509 return DDERR_INVALIDPARAMS;
3512 /* Get the primitive count */
3513 switch(PrimitiveType)
3515 case D3DPT_POINTLIST:
3516 PrimitiveCount = NumVertices;
3519 case D3DPT_LINELIST:
3520 PrimitiveCount = NumVertices / 2;
3523 case D3DPT_LINESTRIP:
3524 PrimitiveCount = NumVertices - 1;
3527 case D3DPT_TRIANGLELIST:
3528 PrimitiveCount = NumVertices / 3;
3531 case D3DPT_TRIANGLESTRIP:
3532 PrimitiveCount = NumVertices - 2;
3535 case D3DPT_TRIANGLEFAN:
3536 PrimitiveCount = NumVertices - 2;
3539 default: return DDERR_INVALIDPARAMS;
3542 /* Get the FVF of the vertex buffer, and its stride */
3543 hr = IWineD3DVertexBuffer_GetDesc(vb->wineD3DVertexBuffer,
3547 ERR("(%p) IWineD3DVertexBuffer::GetDesc failed with hr = %08x\n", This, hr);
3550 stride = get_flexible_vertex_size(Desc.FVF);
3552 hr = IWineD3DDevice_SetVertexDeclaration(This->wineD3DDevice,
3553 vb->wineD3DVertexDeclaration);
3556 ERR(" (%p) Setting the FVF failed, hr = %x!\n", This, hr);
3560 /* Set the vertex stream source */
3561 hr = IWineD3DDevice_SetStreamSource(This->wineD3DDevice,
3562 0 /* StreamNumber */,
3563 vb->wineD3DVertexBuffer,
3564 0 /* StartVertex - we pass this to DrawPrimitive */,
3568 ERR("(%p) IDirect3DDevice::SetStreamSource failed with hr = %08x\n", This, hr);
3572 /* Now draw the primitives */
3573 return IWineD3DDevice_DrawPrimitive(This->wineD3DDevice,
3579 static HRESULT WINAPI
3580 Thunk_IDirect3DDeviceImpl_3_DrawPrimitiveVB(IDirect3DDevice3 *iface,
3581 D3DPRIMITIVETYPE PrimitiveType,
3582 IDirect3DVertexBuffer *D3DVertexBuf,
3587 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3588 IDirect3DVertexBufferImpl *vb = ICOM_OBJECT(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, D3DVertexBuf);
3589 TRACE_(ddraw_thunk)("(%p)->(%08x,%p,%08x,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, vb, StartVertex, NumVertices, Flags);
3590 return IDirect3DDevice7_DrawPrimitiveVB(ICOM_INTERFACE(This, IDirect3DDevice7),
3592 ICOM_INTERFACE(vb, IDirect3DVertexBuffer7),
3599 /*****************************************************************************
3600 * IDirect3DDevice7::DrawIndexedPrimitiveVB
3602 * Draws primitives from a vertex buffer to the screen
3605 * PrimitiveType: Type of primitive to be rendered.
3606 * D3DVertexBuf: Source Vertex Buffer
3607 * StartVertex: Index of the first vertex from the buffer to be rendered
3608 * NumVertices: Number of vertices to be rendered
3609 * Indices: Array of DWORDs used to index into the Vertices
3610 * IndexCount: Number of indices in Indices
3611 * Flags: Can be D3DDP_WAIT to wait until rendering has finished
3615 *****************************************************************************/
3616 static HRESULT WINAPI
3617 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface,
3618 D3DPRIMITIVETYPE PrimitiveType,
3619 IDirect3DVertexBuffer7 *D3DVertexBuf,
3626 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3627 IDirect3DVertexBufferImpl *vb = ICOM_OBJECT(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, D3DVertexBuf);
3629 UINT PrimitiveCount;
3630 WORD *LockedIndices;
3632 WINED3DVERTEXBUFFER_DESC Desc;
3634 TRACE("(%p)->(%08x,%p,%d,%d,%p,%d,%08x)\n", This, PrimitiveType, vb, StartVertex, NumVertices, Indices, IndexCount, Flags);
3637 * 1) Calculate some things: Vertex count -> Primitive count, stride, ...
3638 * 2) Upload the Indices to the index buffer
3639 * 3) Set the index source
3640 * 4) Set the Vertex Buffer as the Stream source
3641 * 5) Call IWineD3DDevice::DrawIndexedPrimitive
3644 /* Get the primitive count */
3645 switch(PrimitiveType)
3647 case D3DPT_POINTLIST:
3648 PrimitiveCount = IndexCount;
3651 case D3DPT_LINELIST:
3652 PrimitiveCount = IndexCount / 2;
3655 case D3DPT_LINESTRIP:
3656 PrimitiveCount = IndexCount - 1;
3659 case D3DPT_TRIANGLELIST:
3660 PrimitiveCount = IndexCount / 3;
3663 case D3DPT_TRIANGLESTRIP:
3664 PrimitiveCount = IndexCount - 2;
3667 case D3DPT_TRIANGLEFAN:
3668 PrimitiveCount = IndexCount - 2;
3671 default: return DDERR_INVALIDPARAMS;
3674 /* Get the FVF of the vertex buffer, and its stride */
3675 hr = IWineD3DVertexBuffer_GetDesc(vb->wineD3DVertexBuffer,
3679 ERR("(%p) IWineD3DVertexBuffer::GetDesc failed with hr = %08x\n", This, hr);
3682 stride = get_flexible_vertex_size(Desc.FVF);
3683 TRACE("Vertex buffer FVF = %08x, stride=%d\n", Desc.FVF, stride);
3685 hr = IWineD3DDevice_SetVertexDeclaration(This->wineD3DDevice,
3686 vb->wineD3DVertexDeclaration);
3689 ERR(" (%p) Setting the FVF failed, hr = %x!\n", This, hr);
3693 /* copy the index stream into the index buffer.
3694 * A new IWineD3DDevice method could be created
3695 * which takes an user pointer containing the indices
3696 * or a SetData-Method for the index buffer, which
3697 * overrides the index buffer data with our pointer.
3699 hr = IWineD3DIndexBuffer_Lock(This->indexbuffer,
3700 0 /* OffSetToLock */,
3701 IndexCount * sizeof(WORD),
3702 (BYTE **) &LockedIndices,
3704 assert(IndexCount < 0x100000);
3707 ERR("(%p) IWineD3DIndexBuffer::Lock failed with hr = %08x\n", This, hr);
3710 memcpy(LockedIndices, Indices, IndexCount * sizeof(WORD));
3711 hr = IWineD3DIndexBuffer_Unlock(This->indexbuffer);
3714 ERR("(%p) IWineD3DIndexBuffer::Unlock failed with hr = %08x\n", This, hr);
3718 /* Set the index stream */
3719 hr = IWineD3DDevice_SetIndices(This->wineD3DDevice,
3723 /* Set the vertex stream source */
3724 hr = IWineD3DDevice_SetStreamSource(This->wineD3DDevice,
3725 0 /* StreamNumber */,
3726 vb->wineD3DVertexBuffer,
3727 0 /* offset, we pass this to DrawIndexedPrimitive */,
3731 ERR("(%p) IDirect3DDevice::SetStreamSource failed with hr = %08x\n", This, hr);
3736 hr = IWineD3DDevice_DrawIndexedPrimitive(This->wineD3DDevice,
3746 static HRESULT WINAPI
3747 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitiveVB(IDirect3DDevice3 *iface,
3748 D3DPRIMITIVETYPE PrimitiveType,
3749 IDirect3DVertexBuffer *D3DVertexBuf,
3754 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3755 IDirect3DVertexBufferImpl *VB = ICOM_OBJECT(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, D3DVertexBuf);
3756 TRACE_(ddraw_thunk)("(%p)->(%08x,%p,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VB, Indices, IndexCount, Flags);
3758 return IDirect3DDevice7_DrawIndexedPrimitiveVB(ICOM_INTERFACE(This, IDirect3DDevice7),
3760 ICOM_INTERFACE(VB, IDirect3DVertexBuffer7),
3768 /*****************************************************************************
3769 * IDirect3DDevice7::ComputeSphereVisibility
3771 * Calculates the visibility of spheres in the current viewport. The spheres
3772 * are passed in the Centers and Radii arrays, the results are passed back
3773 * in the ReturnValues array. Return values are either completely visible,
3774 * partially visible or completely invisible.
3775 * The return value consist of a combination of D3DCLIP_* flags, or it's
3776 * 0 if the sphere is completely visible(according to the SDK, not checked)
3778 * Sounds like an overdose of math ;)
3783 * Centers: Array containing the sphere centers
3784 * Radii: Array containing the sphere radii
3785 * NumSpheres: The number of centers and radii in the arrays
3787 * ReturnValues: Array to write the results to
3790 * D3D_OK because it's a stub
3791 * (DDERR_INVALIDPARAMS if Centers, Radii or ReturnValues are NULL)
3792 * (D3DERR_INVALIDMATRIX if the combined world, view and proj matrix
3795 *****************************************************************************/
3796 static HRESULT WINAPI
3797 IDirect3DDeviceImpl_7_ComputeSphereVisibility(IDirect3DDevice7 *iface,
3802 DWORD *ReturnValues)
3804 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3805 FIXME("(%p)->(%p,%p,%08x,%08x,%p): stub!\n", This, Centers, Radii, NumSpheres, Flags, ReturnValues);
3807 /* the DirectX 7 sdk says that the visibility is computed by
3808 * back-transforming the viewing frustum to model space
3809 * using the inverse of the combined world, view and projection
3810 * matrix. If the matrix can't be reversed, D3DERR_INVALIDMATRIX
3813 * Basic implementation idea:
3814 * 1) Check if the center is in the viewing frustum
3815 * 2) Cut the sphere with the planes of the viewing
3818 * ->Center inside the frustum, no intersections:
3820 * ->Center outside the frustum, no intersections:
3822 * ->Some intersections: Partially visible
3824 * Implement this call in WineD3D. Either implement the
3825 * matrix and vector stuff in WineD3D, or use some external
3832 static HRESULT WINAPI
3833 Thunk_IDirect3DDeviceImpl_3_ComputeSphereVisibility(IDirect3DDevice3 *iface,
3838 DWORD *ReturnValues)
3840 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3841 TRACE_(ddraw_thunk)("(%p)->(%p,%p,%08x,%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, Centers, Radii, NumSpheres, Flags, ReturnValues);
3842 return IDirect3DDevice7_ComputeSphereVisibility(ICOM_INTERFACE(This, IDirect3DDevice7),
3850 /*****************************************************************************
3851 * IDirect3DDevice7::GetTexture
3853 * Returns the texture interface handle assigned to a texture stage.
3854 * The returned texture is AddRefed. This is taken from old ddraw,
3855 * not checked in Windows.
3860 * Stage: Texture stage to read the texture from
3861 * Texture: Address to store the interface pointer at
3865 * DDERR_INVALIDPARAMS if Texture is NULL
3866 * For details, see IWineD3DDevice::GetTexture
3868 *****************************************************************************/
3869 static HRESULT WINAPI
3870 IDirect3DDeviceImpl_7_GetTexture(IDirect3DDevice7 *iface,
3872 IDirectDrawSurface7 **Texture)
3874 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3875 IWineD3DBaseTexture *Surf;
3877 TRACE("(%p)->(%d,%p): Relay\n", This, Stage, Texture);
3881 TRACE("Texture == NULL, failing with DDERR_INVALIDPARAMS\n");
3882 return DDERR_INVALIDPARAMS;
3885 hr = IWineD3DDevice_GetTexture(This->wineD3DDevice, Stage, (IWineD3DBaseTexture **) &Surf);
3886 if( (hr != D3D_OK) || (!Surf) )
3892 /* GetParent AddRef()s, which is perfectly OK.
3893 * We have passed the IDirectDrawSurface7 interface to WineD3D, so that's OK too.
3895 return IWineD3DBaseTexture_GetParent(Surf,
3896 (IUnknown **) Texture);
3899 static HRESULT WINAPI
3900 Thunk_IDirect3DDeviceImpl_3_GetTexture(IDirect3DDevice3 *iface,
3902 IDirect3DTexture2 **Texture2)
3904 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3906 IDirectDrawSurface7 *ret_val;
3908 TRACE_(ddraw_thunk)("(%p)->(%d,%p) thunking to IDirect3DDevice7 interface.\n", This, Stage, Texture2);
3909 ret = IDirect3DDevice7_GetTexture(ICOM_INTERFACE(This, IDirect3DDevice7),
3913 *Texture2 = COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7, IDirect3DTexture2, ret_val);
3915 TRACE_(ddraw_thunk)(" returning interface %p.\n", *Texture2);
3920 /*****************************************************************************
3921 * IDirect3DDevice7::SetTexture
3923 * Assigns a texture to a texture stage. Is the texture AddRef-ed?
3928 * Stage: The stage to assign the texture to
3929 * Texture: Interface pointer to the texture surface
3933 * For details, see IWineD3DDevice::SetTexture
3935 *****************************************************************************/
3936 static HRESULT WINAPI
3937 IDirect3DDeviceImpl_7_SetTexture(IDirect3DDevice7 *iface,
3939 IDirectDrawSurface7 *Texture)
3941 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3942 IDirectDrawSurfaceImpl *surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Texture);
3943 TRACE("(%p)->(%08x,%p): Relay!\n", This, Stage, surf);
3945 /* Texture may be NULL here */
3946 return IWineD3DDevice_SetTexture(This->wineD3DDevice,
3948 surf ? surf->wineD3DTexture : NULL);
3951 static HRESULT WINAPI
3952 Thunk_IDirect3DDeviceImpl_3_SetTexture(IDirect3DDevice3 *iface,
3954 IDirect3DTexture2 *Texture2)
3956 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3957 IDirectDrawSurfaceImpl *tex = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture2, Texture2);
3958 TRACE_(ddraw_thunk)("(%p)->(%d,%p) thunking to IDirect3DDevice7 interface.\n", This, Stage, tex);
3959 return IDirect3DDevice7_SetTexture(ICOM_INTERFACE(This, IDirect3DDevice7),
3961 ICOM_INTERFACE(tex, IDirectDrawSurface7));
3964 /*****************************************************************************
3965 * IDirect3DDevice7::GetTextureStageState
3967 * Retrieves a state from a texture stage.
3972 * Stage: The stage to retrieve the state from
3973 * TexStageStateType: The state type to retrieve
3974 * State: Address to store the state's value at
3978 * DDERR_INVALIDPARAMS if State is NULL
3979 * For details, see IWineD3DDevice::GetTextureStageState
3981 *****************************************************************************/
3982 static HRESULT WINAPI
3983 IDirect3DDeviceImpl_7_GetTextureStageState(IDirect3DDevice7 *iface,
3985 D3DTEXTURESTAGESTATETYPE TexStageStateType,
3988 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3989 TRACE("(%p)->(%08x,%08x,%p): Relay!\n", This, Stage, TexStageStateType, State);
3992 return DDERR_INVALIDPARAMS;
3994 switch(TexStageStateType)
3996 /* Mipfilter is a sampler state with different values */
3997 case D3DTSS_MIPFILTER:
4000 WINED3DTEXTUREFILTERTYPE value;
4002 hr = IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
4004 WINED3DSAMP_MIPFILTER,
4008 case WINED3DTEXF_NONE: *State = D3DTFP_NONE; break;
4009 case WINED3DTEXF_POINT: *State = D3DTFP_POINT; break;
4010 case WINED3DTEXF_LINEAR: *State = D3DTFP_LINEAR; break;
4012 ERR("Unexpected mipfilter value %d\n", value);
4013 *State = D3DTFP_NONE;
4018 /* Minfilter is a sampler state too, equal values */
4019 case D3DTSS_MINFILTER:
4020 return IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
4022 WINED3DSAMP_MINFILTER,
4024 /* Same for MAGFILTER */
4025 case D3DTSS_MAGFILTER:
4026 return IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
4028 WINED3DSAMP_MAGFILTER,
4031 case D3DTSS_ADDRESS:
4032 case D3DTSS_ADDRESSU:
4033 return IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
4035 WINED3DSAMP_ADDRESSU,
4037 case D3DTSS_ADDRESSV:
4038 return IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
4040 WINED3DSAMP_ADDRESSV,
4043 return IWineD3DDevice_GetTextureStageState(This->wineD3DDevice,
4050 static HRESULT WINAPI
4051 Thunk_IDirect3DDeviceImpl_3_GetTextureStageState(IDirect3DDevice3 *iface,
4053 D3DTEXTURESTAGESTATETYPE TexStageStateType,
4056 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
4057 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, Stage, TexStageStateType, State);
4058 return IDirect3DDevice7_GetTextureStageState(ICOM_INTERFACE(This, IDirect3DDevice7),
4064 /*****************************************************************************
4065 * IDirect3DDevice7::SetTextureStageState
4067 * Sets a texture stage state. Some stage types need to be handled specially,
4068 * because they do not exist in WineD3D and were moved to another place
4073 * Stage: The stage to modify
4074 * TexStageStateType: The state to change
4075 * State: The new value for the state
4079 * For details, see IWineD3DDevice::SetTextureStageState
4081 *****************************************************************************/
4082 static HRESULT WINAPI
4083 IDirect3DDeviceImpl_7_SetTextureStageState(IDirect3DDevice7 *iface,
4085 D3DTEXTURESTAGESTATETYPE TexStageStateType,
4088 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4089 TRACE("(%p)->(%08x,%08x,%08x): Relay!\n", This, Stage, TexStageStateType, State);
4090 switch(TexStageStateType)
4092 /* Mipfilter is a sampler state with different values */
4093 case D3DTSS_MIPFILTER:
4095 WINED3DTEXTUREFILTERTYPE value;
4098 case D3DTFP_NONE: value = WINED3DTEXF_NONE; break;
4099 case D3DTFP_POINT: value = WINED3DTEXF_POINT; break;
4100 case 0: /* Unchecked */
4101 case D3DTFP_LINEAR: value = WINED3DTEXF_LINEAR; break;
4103 ERR("Unexpected mipfilter value %d\n", State);
4104 value = WINED3DTEXF_NONE;
4106 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
4108 WINED3DSAMP_MIPFILTER,
4112 /* Minfilter is a sampler state too, equal values */
4113 case D3DTSS_MINFILTER:
4114 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
4116 WINED3DSAMP_MINFILTER,
4118 /* Same for MAGFILTER */
4119 case D3DTSS_MAGFILTER:
4120 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
4122 WINED3DSAMP_MAGFILTER,
4125 case D3DTSS_ADDRESS:
4126 IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
4128 WINED3DSAMP_ADDRESSV,
4131 case D3DTSS_ADDRESSU:
4132 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
4134 WINED3DSAMP_ADDRESSU,
4136 case D3DTSS_ADDRESSV:
4137 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
4139 WINED3DSAMP_ADDRESSV,
4143 return IWineD3DDevice_SetTextureStageState(This->wineD3DDevice,
4150 static HRESULT WINAPI
4151 Thunk_IDirect3DDeviceImpl_3_SetTextureStageState(IDirect3DDevice3 *iface,
4153 D3DTEXTURESTAGESTATETYPE TexStageStateType,
4156 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
4157 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, Stage, TexStageStateType, State);
4158 return IDirect3DDevice7_SetTextureStageState(ICOM_INTERFACE(This, IDirect3DDevice7),
4164 /*****************************************************************************
4165 * IDirect3DDevice7::ValidateDevice
4167 * SDK: "Reports the device's ability to render the currently set
4168 * texture-blending operations in a single pass". Whatever that means
4174 * NumPasses: Address to write the number of necessary passes for the
4175 * desired effect to.
4179 * See IWineD3DDevice::ValidateDevice for more details
4181 *****************************************************************************/
4182 static HRESULT WINAPI
4183 IDirect3DDeviceImpl_7_ValidateDevice(IDirect3DDevice7 *iface,
4186 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4187 TRACE("(%p)->(%p): Relay\n", This, NumPasses);
4189 return IWineD3DDevice_ValidateDevice(This->wineD3DDevice, NumPasses);
4192 static HRESULT WINAPI
4193 Thunk_IDirect3DDeviceImpl_3_ValidateDevice(IDirect3DDevice3 *iface,
4196 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
4197 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, Passes);
4198 return IDirect3DDevice7_ValidateDevice(ICOM_INTERFACE(This, IDirect3DDevice7),
4202 /*****************************************************************************
4203 * IDirect3DDevice7::Clear
4205 * Fills the render target, the z buffer and the stencil buffer with a
4206 * clear color / value
4211 * Count: Number of rectangles in Rects must be 0 if Rects is NULL
4212 * Rects: Rectangles to clear. If NULL, the whole surface is cleared
4213 * Flags: Some flags, as usual
4214 * Color: Clear color for the render target
4215 * Z: Clear value for the Z buffer
4216 * Stencil: Clear value to store in each stencil buffer entry
4220 * For details, see IWineD3DDevice::Clear
4222 *****************************************************************************/
4223 static HRESULT WINAPI
4224 IDirect3DDeviceImpl_7_Clear(IDirect3DDevice7 *iface,
4232 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4233 TRACE("(%p)->(%08x,%p,%08x,%08x,%f,%08x): Relay\n", This, Count, Rects, Flags, (DWORD) Color, Z, Stencil);
4235 /* Note; D3DRECT is compatible with WINED3DRECT */
4236 return IWineD3DDevice_Clear(This->wineD3DDevice, Count, (WINED3DRECT*) Rects, Flags, Color, Z, Stencil);
4239 /*****************************************************************************
4240 * IDirect3DDevice7::SetViewport
4242 * Sets the current viewport.
4244 * Version 7 only, but IDirect3DViewport uses this call for older
4248 * Data: The new viewport to set
4252 * DDERR_INVALIDPARAMS if Data is NULL
4253 * For more details, see IWineDDDevice::SetViewport
4255 *****************************************************************************/
4256 static HRESULT WINAPI
4257 IDirect3DDeviceImpl_7_SetViewport(IDirect3DDevice7 *iface,
4260 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4261 TRACE("(%p)->(%p) Relay!\n", This, Data);
4264 return DDERR_INVALIDPARAMS;
4266 /* Note: D3DVIEWPORT7 is compatible with WINED3DVIEWPORT */
4267 return IWineD3DDevice_SetViewport(This->wineD3DDevice,
4268 (WINED3DVIEWPORT*) Data);
4271 /*****************************************************************************
4272 * IDirect3DDevice::GetViewport
4274 * Returns the current viewport
4279 * Data: D3D7Viewport structure to write the viewport information to
4283 * DDERR_INVALIDPARAMS if Data is NULL
4284 * For more details, see IWineD3DDevice::GetViewport
4286 *****************************************************************************/
4287 static HRESULT WINAPI
4288 IDirect3DDeviceImpl_7_GetViewport(IDirect3DDevice7 *iface,
4291 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4293 TRACE("(%p)->(%p) Relay!\n", This, Data);
4296 return DDERR_INVALIDPARAMS;
4298 /* Note: D3DVIEWPORT7 is compatible with WINED3DVIEWPORT */
4299 hr = IWineD3DDevice_GetViewport(This->wineD3DDevice,
4300 (WINED3DVIEWPORT*) Data);
4302 return hr_ddraw_from_wined3d(hr);
4305 /*****************************************************************************
4306 * IDirect3DDevice7::SetMaterial
4313 * Mat: The material to set
4317 * DDERR_INVALIDPARAMS if Mat is NULL.
4318 * For more details, see IWineD3DDevice::SetMaterial
4320 *****************************************************************************/
4321 static HRESULT WINAPI
4322 IDirect3DDeviceImpl_7_SetMaterial(IDirect3DDevice7 *iface,
4325 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4327 TRACE("(%p)->(%p): Relay!\n", This, Mat);
4329 /* Note: D3DMATERIAL7 is compatible with WINED3DMATERIAL */
4330 hr = IWineD3DDevice_SetMaterial(This->wineD3DDevice,
4331 (WINED3DMATERIAL*) Mat);
4333 return hr_ddraw_from_wined3d(hr);
4336 /*****************************************************************************
4337 * IDirect3DDevice7::GetMaterial
4339 * Returns the current material
4344 * Mat: D3DMATERIAL7 structure to write the material parameters to
4348 * DDERR_INVALIDPARAMS if Mat is NULL
4349 * For more details, see IWineD3DDevice::GetMaterial
4351 *****************************************************************************/
4352 static HRESULT WINAPI
4353 IDirect3DDeviceImpl_7_GetMaterial(IDirect3DDevice7 *iface,
4356 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4358 TRACE("(%p)->(%p): Relay!\n", This, Mat);
4360 /* Note: D3DMATERIAL7 is compatible with WINED3DMATERIAL */
4361 hr = IWineD3DDevice_GetMaterial(This->wineD3DDevice,
4362 (WINED3DMATERIAL*) Mat);
4364 return hr_ddraw_from_wined3d(hr);
4367 /*****************************************************************************
4368 * IDirect3DDevice7::SetLight
4370 * Assigns a light to a light index, but doesn't activate it yet.
4372 * Version 7, IDirect3DLight uses this method for older versions
4375 * LightIndex: The index of the new light
4376 * Light: A D3DLIGHT7 structure describing the light
4380 * For more details, see IWineD3DDevice::SetLight
4382 *****************************************************************************/
4383 static HRESULT WINAPI
4384 IDirect3DDeviceImpl_7_SetLight(IDirect3DDevice7 *iface,
4388 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4390 TRACE("(%p)->(%08x,%p): Relay!\n", This, LightIndex, Light);
4392 /* Note: D3DLIGHT7 is compatible with WINED3DLIGHT */
4393 hr = IWineD3DDevice_SetLight(This->wineD3DDevice,
4395 (WINED3DLIGHT*) Light);
4397 return hr_ddraw_from_wined3d(hr);
4400 /*****************************************************************************
4401 * IDirect3DDevice7::GetLight
4403 * Returns the light assigned to a light index
4406 * Light: Structure to write the light information to
4410 * DDERR_INVALIDPARAMS if Light is NULL
4411 * For details, see IWineD3DDevice::GetLight
4413 *****************************************************************************/
4414 static HRESULT WINAPI
4415 IDirect3DDeviceImpl_7_GetLight(IDirect3DDevice7 *iface,
4419 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4421 TRACE("(%p)->(%08x,%p): Relay!\n", This, LightIndex, Light);
4423 /* Note: D3DLIGHT7 is compatible with WINED3DLIGHT */
4424 rc = IWineD3DDevice_GetLight(This->wineD3DDevice,
4426 (WINED3DLIGHT*) Light);
4428 /* Translate the result. WineD3D returns other values than D3D7 */
4429 return hr_ddraw_from_wined3d(rc);
4432 /*****************************************************************************
4433 * IDirect3DDevice7::BeginStateBlock
4435 * Begins recording to a stateblock
4441 * For details see IWineD3DDevice::BeginStateBlock
4443 *****************************************************************************/
4444 static HRESULT WINAPI
4445 IDirect3DDeviceImpl_7_BeginStateBlock(IDirect3DDevice7 *iface)
4447 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4449 TRACE("(%p)->(): Relay!\n", This);
4451 hr = IWineD3DDevice_BeginStateBlock(This->wineD3DDevice);
4452 return hr_ddraw_from_wined3d(hr);
4455 /*****************************************************************************
4456 * IDirect3DDevice7::EndStateBlock
4458 * Stops recording to a state block and returns the created stateblock
4464 * BlockHandle: Address to store the stateblock's handle to
4468 * DDERR_INVALIDPARAMS if BlockHandle is NULL
4469 * See IWineD3DDevice::EndStateBlock for more details
4471 *****************************************************************************/
4472 static HRESULT WINAPI
4473 IDirect3DDeviceImpl_7_EndStateBlock(IDirect3DDevice7 *iface,
4476 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4478 TRACE("(%p)->(%p): Relay!\n", This, BlockHandle);
4482 WARN("BlockHandle == NULL, returning DDERR_INVALIDPARAMS\n");
4483 return DDERR_INVALIDPARAMS;
4486 *BlockHandle = IDirect3DDeviceImpl_CreateHandle(This);
4489 ERR("Cannot get a handle number for the stateblock\n");
4490 return DDERR_OUTOFMEMORY;
4492 This->Handles[*BlockHandle - 1].type = DDrawHandle_StateBlock;
4493 hr = IWineD3DDevice_EndStateBlock(This->wineD3DDevice,
4494 (IWineD3DStateBlock **) &This->Handles[*BlockHandle - 1].ptr);
4495 return hr_ddraw_from_wined3d(hr);
4498 /*****************************************************************************
4499 * IDirect3DDevice7::PreLoad
4501 * Allows the app to signal that a texture will be used soon, to allow
4502 * the Direct3DDevice to load it to the video card in the meantime.
4507 * Texture: The texture to preload
4511 * DDERR_INVALIDPARAMS if Texture is NULL
4512 * See IWineD3DSurface::PreLoad for details
4514 *****************************************************************************/
4515 static HRESULT WINAPI
4516 IDirect3DDeviceImpl_7_PreLoad(IDirect3DDevice7 *iface,
4517 IDirectDrawSurface7 *Texture)
4519 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4520 IDirectDrawSurfaceImpl *surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Texture);
4522 TRACE("(%p)->(%p): Relay!\n", This, surf);
4525 return DDERR_INVALIDPARAMS;
4527 IWineD3DSurface_PreLoad(surf->WineD3DSurface);
4531 /*****************************************************************************
4532 * IDirect3DDevice7::ApplyStateBlock
4534 * Activates the state stored in a state block handle.
4537 * BlockHandle: The stateblock handle to activate
4541 * D3DERR_INVALIDSTATEBLOCK if BlockHandle is NULL
4543 *****************************************************************************/
4544 static HRESULT WINAPI
4545 IDirect3DDeviceImpl_7_ApplyStateBlock(IDirect3DDevice7 *iface,
4548 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4550 TRACE("(%p)->(%08x): Relay!\n", This, BlockHandle);
4552 if(!BlockHandle || BlockHandle > This->numHandles)
4554 WARN("Out of range handle %d, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
4555 return D3DERR_INVALIDSTATEBLOCK;
4557 if(This->Handles[BlockHandle - 1].type != DDrawHandle_StateBlock)
4559 WARN("Handle %d is not a stateblock, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
4560 return D3DERR_INVALIDSTATEBLOCK;
4563 hr = IWineD3DStateBlock_Apply((IWineD3DStateBlock *) This->Handles[BlockHandle - 1].ptr);
4564 return hr_ddraw_from_wined3d(hr);
4567 /*****************************************************************************
4568 * IDirect3DDevice7::CaptureStateBlock
4570 * Updates a stateblock's values to the values currently set for the device
4575 * BlockHandle: Stateblock to update
4579 * D3DERR_INVALIDSTATEBLOCK if BlockHandle is NULL
4580 * See IWineD3DDevice::CaptureStateBlock for more details
4582 *****************************************************************************/
4583 static HRESULT WINAPI
4584 IDirect3DDeviceImpl_7_CaptureStateBlock(IDirect3DDevice7 *iface,
4587 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4589 TRACE("(%p)->(%08x): Relay!\n", This, BlockHandle);
4591 if(BlockHandle == 0 || BlockHandle > This->numHandles)
4593 WARN("Out of range handle %d, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
4594 return D3DERR_INVALIDSTATEBLOCK;
4596 if(This->Handles[BlockHandle - 1].type != DDrawHandle_StateBlock)
4598 WARN("Handle %d is not a stateblock, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
4599 return D3DERR_INVALIDSTATEBLOCK;
4602 hr = IWineD3DStateBlock_Capture((IWineD3DStateBlock *) This->Handles[BlockHandle - 1].ptr);
4603 return hr_ddraw_from_wined3d(hr);
4606 /*****************************************************************************
4607 * IDirect3DDevice7::DeleteStateBlock
4609 * Deletes a stateblock handle. This means releasing the WineD3DStateBlock
4614 * BlockHandle: Stateblock handle to delete
4618 * D3DERR_INVALIDSTATEBLOCK if BlockHandle is 0
4620 *****************************************************************************/
4621 static HRESULT WINAPI
4622 IDirect3DDeviceImpl_7_DeleteStateBlock(IDirect3DDevice7 *iface,
4625 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4627 TRACE("(%p)->(%08x): Relay!\n", This, BlockHandle);
4629 if(BlockHandle == 0 || BlockHandle > This->numHandles)
4631 WARN("Out of range handle %d, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
4632 return D3DERR_INVALIDSTATEBLOCK;
4634 if(This->Handles[BlockHandle - 1].type != DDrawHandle_StateBlock)
4636 WARN("Handle %d is not a stateblock, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
4637 return D3DERR_INVALIDSTATEBLOCK;
4640 ref = IWineD3DStateBlock_Release((IWineD3DStateBlock *) This->Handles[BlockHandle - 1].ptr);
4643 ERR("Something is still holding the stateblock %p(Handle %d). Ref = %d\n", This->Handles[BlockHandle - 1].ptr, BlockHandle, ref);
4645 This->Handles[BlockHandle - 1].ptr = NULL;
4646 This->Handles[BlockHandle - 1].type = DDrawHandle_Unknown;
4651 /*****************************************************************************
4652 * IDirect3DDevice7::CreateStateBlock
4654 * Creates a new state block handle.
4659 * Type: The state block type
4660 * BlockHandle: Address to write the created handle to
4664 * DDERR_INVALIDPARAMS if BlockHandle is NULL
4666 *****************************************************************************/
4667 static HRESULT WINAPI
4668 IDirect3DDeviceImpl_7_CreateStateBlock(IDirect3DDevice7 *iface,
4669 D3DSTATEBLOCKTYPE Type,
4672 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4674 TRACE("(%p)->(%08x,%p)!\n", This, Type, BlockHandle);
4678 WARN("BlockHandle == NULL, returning DDERR_INVALIDPARAMS\n");
4679 return DDERR_INVALIDPARAMS;
4682 *BlockHandle = IDirect3DDeviceImpl_CreateHandle(This);
4685 ERR("Cannot get a handle number for the stateblock\n");
4686 return DDERR_OUTOFMEMORY;
4688 This->Handles[*BlockHandle - 1].type = DDrawHandle_StateBlock;
4690 /* The D3DSTATEBLOCKTYPE enum is fine here */
4691 hr = IWineD3DDevice_CreateStateBlock(This->wineD3DDevice,
4693 (IWineD3DStateBlock **) &This->Handles[*BlockHandle - 1].ptr,
4694 NULL /* Parent, hope that works */);
4695 return hr_ddraw_from_wined3d(hr);
4698 /*****************************************************************************
4699 * IDirect3DDevice7::Load
4701 * Loads a rectangular area from the source into the destination texture.
4702 * It can also copy the source to the faces of a cubic environment map
4707 * DestTex: Destination texture
4708 * DestPoint: Point in the destination where the source image should be
4710 * SrcTex: Source texture
4711 * SrcRect: Source rectangle
4716 * DDERR_INVALIDPARAMS if DestTex or SrcTex are NULL
4717 * See IDirect3DTexture2::Load for details
4719 *****************************************************************************/
4720 static HRESULT WINAPI
4721 IDirect3DDeviceImpl_7_Load(IDirect3DDevice7 *iface,
4722 IDirectDrawSurface7 *DestTex,
4724 IDirectDrawSurface7 *SrcTex,
4728 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4729 IDirectDrawSurfaceImpl *dest = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DestTex);
4730 IDirectDrawSurfaceImpl *src = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, SrcTex);
4731 FIXME("(%p)->(%p,%p,%p,%p,%08x): Partially Implemented!\n", This, dest, DestPoint, src, SrcRect, Flags);
4733 if( (!src) || (!dest) )
4734 return DDERR_INVALIDPARAMS;
4736 IDirect3DTexture2_Load(ICOM_INTERFACE(dest, IDirect3DTexture2),
4737 ICOM_INTERFACE(src, IDirect3DTexture2));
4741 /*****************************************************************************
4742 * IDirect3DDevice7::LightEnable
4744 * Enables or disables a light
4746 * Version 7, IDirect3DLight uses this method too.
4749 * LightIndex: The index of the light to enable / disable
4750 * Enable: Enable or disable the light
4754 * For more details, see IWineD3DDevice::SetLightEnable
4756 *****************************************************************************/
4757 static HRESULT WINAPI
4758 IDirect3DDeviceImpl_7_LightEnable(IDirect3DDevice7 *iface,
4762 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4764 TRACE("(%p)->(%08x,%d): Relay!\n", This, LightIndex, Enable);
4766 hr = IWineD3DDevice_SetLightEnable(This->wineD3DDevice, LightIndex, Enable);
4767 return hr_ddraw_from_wined3d(hr);
4770 /*****************************************************************************
4771 * IDirect3DDevice7::GetLightEnable
4773 * Retrieves if the light with the given index is enabled or not
4778 * LightIndex: Index of desired light
4779 * Enable: Pointer to a BOOL which contains the result
4783 * DDERR_INVALIDPARAMS if Enable is NULL
4784 * See IWineD3DDevice::GetLightEnable for more details
4786 *****************************************************************************/
4787 static HRESULT WINAPI
4788 IDirect3DDeviceImpl_7_GetLightEnable(IDirect3DDevice7 *iface,
4792 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4794 TRACE("(%p)->(%08x,%p): Relay\n", This, LightIndex, Enable);
4797 return DDERR_INVALIDPARAMS;
4799 hr = IWineD3DDevice_GetLightEnable(This->wineD3DDevice, LightIndex, Enable);
4800 return hr_ddraw_from_wined3d(hr);
4803 /*****************************************************************************
4804 * IDirect3DDevice7::SetClipPlane
4806 * Sets custom clipping plane
4811 * Index: The index of the clipping plane
4812 * PlaneEquation: An equation defining the clipping plane
4816 * DDERR_INVALIDPARAMS if PlaneEquation is NULL
4817 * See IWineD3DDevice::SetClipPlane for more details
4819 *****************************************************************************/
4820 static HRESULT WINAPI
4821 IDirect3DDeviceImpl_7_SetClipPlane(IDirect3DDevice7 *iface,
4823 D3DVALUE* PlaneEquation)
4825 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4826 TRACE("(%p)->(%08x,%p): Relay!\n", This, Index, PlaneEquation);
4829 return DDERR_INVALIDPARAMS;
4831 return IWineD3DDevice_SetClipPlane(This->wineD3DDevice, Index, PlaneEquation);
4834 /*****************************************************************************
4835 * IDirect3DDevice7::GetClipPlane
4837 * Returns the clipping plane with a specific index
4840 * Index: The index of the desired plane
4841 * PlaneEquation: Address to store the plane equation to
4845 * DDERR_INVALIDPARAMS if PlaneEquation is NULL
4846 * See IWineD3DDevice::GetClipPlane for more details
4848 *****************************************************************************/
4849 static HRESULT WINAPI
4850 IDirect3DDeviceImpl_7_GetClipPlane(IDirect3DDevice7 *iface,
4852 D3DVALUE* PlaneEquation)
4854 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4855 TRACE("(%p)->(%d,%p): Relay!\n", This, Index, PlaneEquation);
4858 return DDERR_INVALIDPARAMS;
4860 return IWineD3DDevice_GetClipPlane(This->wineD3DDevice, Index, PlaneEquation);
4863 /*****************************************************************************
4864 * IDirect3DDevice7::GetInfo
4866 * Retrieves some information about the device. The DirectX sdk says that
4867 * this version returns S_FALSE for all retail builds of DirectX, that's what
4868 * this implementation does.
4871 * DevInfoID: Information type requested
4872 * DevInfoStruct: Pointer to a structure to store the info to
4873 * Size: Size of the structure
4876 * S_FALSE, because it's a non-debug driver
4878 *****************************************************************************/
4879 static HRESULT WINAPI
4880 IDirect3DDeviceImpl_7_GetInfo(IDirect3DDevice7 *iface,
4882 void *DevInfoStruct,
4885 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4886 TRACE("(%p)->(%08x,%p,%08x)\n", This, DevInfoID, DevInfoStruct, Size);
4890 TRACE(" info requested : ");
4893 case D3DDEVINFOID_TEXTUREMANAGER: TRACE("D3DDEVINFOID_TEXTUREMANAGER\n"); break;
4894 case D3DDEVINFOID_D3DTEXTUREMANAGER: TRACE("D3DDEVINFOID_D3DTEXTUREMANAGER\n"); break;
4895 case D3DDEVINFOID_TEXTURING: TRACE("D3DDEVINFOID_TEXTURING\n"); break;
4896 default: ERR(" invalid flag !!!\n"); return DDERR_INVALIDPARAMS;
4900 return S_FALSE; /* According to MSDN, this is valid for a non-debug driver */
4903 const IDirect3DDevice7Vtbl IDirect3DDevice7_Vtbl =
4905 /*** IUnknown Methods ***/
4906 IDirect3DDeviceImpl_7_QueryInterface,
4907 IDirect3DDeviceImpl_7_AddRef,
4908 IDirect3DDeviceImpl_7_Release,
4909 /*** IDirect3DDevice7 ***/
4910 IDirect3DDeviceImpl_7_GetCaps,
4911 IDirect3DDeviceImpl_7_EnumTextureFormats,
4912 IDirect3DDeviceImpl_7_BeginScene,
4913 IDirect3DDeviceImpl_7_EndScene,
4914 IDirect3DDeviceImpl_7_GetDirect3D,
4915 IDirect3DDeviceImpl_7_SetRenderTarget,
4916 IDirect3DDeviceImpl_7_GetRenderTarget,
4917 IDirect3DDeviceImpl_7_Clear,
4918 IDirect3DDeviceImpl_7_SetTransform,
4919 IDirect3DDeviceImpl_7_GetTransform,
4920 IDirect3DDeviceImpl_7_SetViewport,
4921 IDirect3DDeviceImpl_7_MultiplyTransform,
4922 IDirect3DDeviceImpl_7_GetViewport,
4923 IDirect3DDeviceImpl_7_SetMaterial,
4924 IDirect3DDeviceImpl_7_GetMaterial,
4925 IDirect3DDeviceImpl_7_SetLight,
4926 IDirect3DDeviceImpl_7_GetLight,
4927 IDirect3DDeviceImpl_7_SetRenderState,
4928 IDirect3DDeviceImpl_7_GetRenderState,
4929 IDirect3DDeviceImpl_7_BeginStateBlock,
4930 IDirect3DDeviceImpl_7_EndStateBlock,
4931 IDirect3DDeviceImpl_7_PreLoad,
4932 IDirect3DDeviceImpl_7_DrawPrimitive,
4933 IDirect3DDeviceImpl_7_DrawIndexedPrimitive,
4934 IDirect3DDeviceImpl_7_SetClipStatus,
4935 IDirect3DDeviceImpl_7_GetClipStatus,
4936 IDirect3DDeviceImpl_7_DrawPrimitiveStrided,
4937 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveStrided,
4938 IDirect3DDeviceImpl_7_DrawPrimitiveVB,
4939 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB,
4940 IDirect3DDeviceImpl_7_ComputeSphereVisibility,
4941 IDirect3DDeviceImpl_7_GetTexture,
4942 IDirect3DDeviceImpl_7_SetTexture,
4943 IDirect3DDeviceImpl_7_GetTextureStageState,
4944 IDirect3DDeviceImpl_7_SetTextureStageState,
4945 IDirect3DDeviceImpl_7_ValidateDevice,
4946 IDirect3DDeviceImpl_7_ApplyStateBlock,
4947 IDirect3DDeviceImpl_7_CaptureStateBlock,
4948 IDirect3DDeviceImpl_7_DeleteStateBlock,
4949 IDirect3DDeviceImpl_7_CreateStateBlock,
4950 IDirect3DDeviceImpl_7_Load,
4951 IDirect3DDeviceImpl_7_LightEnable,
4952 IDirect3DDeviceImpl_7_GetLightEnable,
4953 IDirect3DDeviceImpl_7_SetClipPlane,
4954 IDirect3DDeviceImpl_7_GetClipPlane,
4955 IDirect3DDeviceImpl_7_GetInfo
4958 const IDirect3DDevice3Vtbl IDirect3DDevice3_Vtbl =
4960 /*** IUnknown Methods ***/
4961 Thunk_IDirect3DDeviceImpl_3_QueryInterface,
4962 Thunk_IDirect3DDeviceImpl_3_AddRef,
4963 Thunk_IDirect3DDeviceImpl_3_Release,
4964 /*** IDirect3DDevice3 ***/
4965 IDirect3DDeviceImpl_3_GetCaps,
4966 IDirect3DDeviceImpl_3_GetStats,
4967 IDirect3DDeviceImpl_3_AddViewport,
4968 IDirect3DDeviceImpl_3_DeleteViewport,
4969 IDirect3DDeviceImpl_3_NextViewport,
4970 Thunk_IDirect3DDeviceImpl_3_EnumTextureFormats,
4971 Thunk_IDirect3DDeviceImpl_3_BeginScene,
4972 Thunk_IDirect3DDeviceImpl_3_EndScene,
4973 Thunk_IDirect3DDeviceImpl_3_GetDirect3D,
4974 IDirect3DDeviceImpl_3_SetCurrentViewport,
4975 IDirect3DDeviceImpl_3_GetCurrentViewport,
4976 Thunk_IDirect3DDeviceImpl_3_SetRenderTarget,
4977 Thunk_IDirect3DDeviceImpl_3_GetRenderTarget,
4978 IDirect3DDeviceImpl_3_Begin,
4979 IDirect3DDeviceImpl_3_BeginIndexed,
4980 IDirect3DDeviceImpl_3_Vertex,
4981 IDirect3DDeviceImpl_3_Index,
4982 IDirect3DDeviceImpl_3_End,
4983 Thunk_IDirect3DDeviceImpl_3_GetRenderState,
4984 Thunk_IDirect3DDeviceImpl_3_SetRenderState,
4985 IDirect3DDeviceImpl_3_GetLightState,
4986 IDirect3DDeviceImpl_3_SetLightState,
4987 Thunk_IDirect3DDeviceImpl_3_SetTransform,
4988 Thunk_IDirect3DDeviceImpl_3_GetTransform,
4989 Thunk_IDirect3DDeviceImpl_3_MultiplyTransform,
4990 Thunk_IDirect3DDeviceImpl_3_DrawPrimitive,
4991 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitive,
4992 Thunk_IDirect3DDeviceImpl_3_SetClipStatus,
4993 Thunk_IDirect3DDeviceImpl_3_GetClipStatus,
4994 Thunk_IDirect3DDeviceImpl_3_DrawPrimitiveStrided,
4995 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitiveStrided,
4996 Thunk_IDirect3DDeviceImpl_3_DrawPrimitiveVB,
4997 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitiveVB,
4998 Thunk_IDirect3DDeviceImpl_3_ComputeSphereVisibility,
4999 Thunk_IDirect3DDeviceImpl_3_GetTexture,
5000 Thunk_IDirect3DDeviceImpl_3_SetTexture,
5001 Thunk_IDirect3DDeviceImpl_3_GetTextureStageState,
5002 Thunk_IDirect3DDeviceImpl_3_SetTextureStageState,
5003 Thunk_IDirect3DDeviceImpl_3_ValidateDevice
5006 const IDirect3DDevice2Vtbl IDirect3DDevice2_Vtbl =
5008 /*** IUnknown Methods ***/
5009 Thunk_IDirect3DDeviceImpl_2_QueryInterface,
5010 Thunk_IDirect3DDeviceImpl_2_AddRef,
5011 Thunk_IDirect3DDeviceImpl_2_Release,
5012 /*** IDirect3DDevice2 ***/
5013 Thunk_IDirect3DDeviceImpl_2_GetCaps,
5014 IDirect3DDeviceImpl_2_SwapTextureHandles,
5015 Thunk_IDirect3DDeviceImpl_2_GetStats,
5016 Thunk_IDirect3DDeviceImpl_2_AddViewport,
5017 Thunk_IDirect3DDeviceImpl_2_DeleteViewport,
5018 Thunk_IDirect3DDeviceImpl_2_NextViewport,
5019 IDirect3DDeviceImpl_2_EnumTextureFormats,
5020 Thunk_IDirect3DDeviceImpl_2_BeginScene,
5021 Thunk_IDirect3DDeviceImpl_2_EndScene,
5022 Thunk_IDirect3DDeviceImpl_2_GetDirect3D,
5023 Thunk_IDirect3DDeviceImpl_2_SetCurrentViewport,
5024 Thunk_IDirect3DDeviceImpl_2_GetCurrentViewport,
5025 Thunk_IDirect3DDeviceImpl_2_SetRenderTarget,
5026 Thunk_IDirect3DDeviceImpl_2_GetRenderTarget,
5027 Thunk_IDirect3DDeviceImpl_2_Begin,
5028 Thunk_IDirect3DDeviceImpl_2_BeginIndexed,
5029 Thunk_IDirect3DDeviceImpl_2_Vertex,
5030 Thunk_IDirect3DDeviceImpl_2_Index,
5031 Thunk_IDirect3DDeviceImpl_2_End,
5032 Thunk_IDirect3DDeviceImpl_2_GetRenderState,
5033 Thunk_IDirect3DDeviceImpl_2_SetRenderState,
5034 Thunk_IDirect3DDeviceImpl_2_GetLightState,
5035 Thunk_IDirect3DDeviceImpl_2_SetLightState,
5036 Thunk_IDirect3DDeviceImpl_2_SetTransform,
5037 Thunk_IDirect3DDeviceImpl_2_GetTransform,
5038 Thunk_IDirect3DDeviceImpl_2_MultiplyTransform,
5039 Thunk_IDirect3DDeviceImpl_2_DrawPrimitive,
5040 Thunk_IDirect3DDeviceImpl_2_DrawIndexedPrimitive,
5041 Thunk_IDirect3DDeviceImpl_2_SetClipStatus,
5042 Thunk_IDirect3DDeviceImpl_2_GetClipStatus
5045 const IDirect3DDeviceVtbl IDirect3DDevice1_Vtbl =
5047 /*** IUnknown Methods ***/
5048 Thunk_IDirect3DDeviceImpl_1_QueryInterface,
5049 Thunk_IDirect3DDeviceImpl_1_AddRef,
5050 Thunk_IDirect3DDeviceImpl_1_Release,
5051 /*** IDirect3DDevice1 ***/
5052 IDirect3DDeviceImpl_1_Initialize,
5053 Thunk_IDirect3DDeviceImpl_1_GetCaps,
5054 Thunk_IDirect3DDeviceImpl_1_SwapTextureHandles,
5055 IDirect3DDeviceImpl_1_CreateExecuteBuffer,
5056 Thunk_IDirect3DDeviceImpl_1_GetStats,
5057 IDirect3DDeviceImpl_1_Execute,
5058 Thunk_IDirect3DDeviceImpl_1_AddViewport,
5059 Thunk_IDirect3DDeviceImpl_1_DeleteViewport,
5060 Thunk_IDirect3DDeviceImpl_1_NextViewport,
5061 IDirect3DDeviceImpl_1_Pick,
5062 IDirect3DDeviceImpl_1_GetPickRecords,
5063 Thunk_IDirect3DDeviceImpl_1_EnumTextureFormats,
5064 IDirect3DDeviceImpl_1_CreateMatrix,
5065 IDirect3DDeviceImpl_1_SetMatrix,
5066 IDirect3DDeviceImpl_1_GetMatrix,
5067 IDirect3DDeviceImpl_1_DeleteMatrix,
5068 Thunk_IDirect3DDeviceImpl_1_EndScene,
5069 Thunk_IDirect3DDeviceImpl_1_BeginScene,
5070 Thunk_IDirect3DDeviceImpl_1_GetDirect3D
5073 /*****************************************************************************
5074 * IDirect3DDeviceImpl_CreateHandle
5076 * Not called from the VTable
5078 * Some older interface versions operate with handles, which are basically
5079 * DWORDs which identify an interface, for example
5080 * IDirect3DDevice::SetRenderState with DIRECT3DRENDERSTATE_TEXTUREHANDLE
5082 * Those handle could be just casts to the interface pointers or vice versa,
5083 * but that is not 64 bit safe and would mean blindly derefering a DWORD
5084 * passed by the app. Instead there is a dynamic array in the device which
5085 * keeps a DWORD to pointer information and a type for the handle.
5087 * Basically this array only grows, when a handle is freed its pointer is
5088 * just set to NULL. There will be much more reads from the array than
5089 * insertion operations, so a dynamic array is fine.
5092 * This: D3DDevice implementation for which this handle should be created
5095 * A free handle on success
5098 *****************************************************************************/
5100 IDirect3DDeviceImpl_CreateHandle(IDirect3DDeviceImpl *This)
5103 struct HandleEntry *oldHandles = This->Handles;
5105 TRACE("(%p)\n", This);
5107 for(i = 0; i < This->numHandles; i++)
5109 if(This->Handles[i].ptr == NULL &&
5110 This->Handles[i].type == DDrawHandle_Unknown)
5112 TRACE("Reusing freed handle %d\n", i + 1);
5117 TRACE("Growing the handle array\n");
5120 This->Handles = HeapAlloc(GetProcessHeap(), 0, sizeof(struct HandleEntry) * This->numHandles);
5123 ERR("Out of memory\n");
5124 This->Handles = oldHandles;
5130 memcpy(This->Handles, oldHandles, (This->numHandles - 1) * sizeof(struct HandleEntry));
5131 HeapFree(GetProcessHeap(), 0, oldHandles);
5134 TRACE("Returning %d\n", This->numHandles);
5135 return This->numHandles;
5138 /*****************************************************************************
5139 * IDirect3DDeviceImpl_UpdateDepthStencil
5141 * Checks the current render target for attached depth stencils and sets the
5142 * WineD3D depth stencil accordingly.
5145 * The depth stencil state to set if creating the device
5147 *****************************************************************************/
5149 IDirect3DDeviceImpl_UpdateDepthStencil(IDirect3DDeviceImpl *This)
5151 IDirectDrawSurface7 *depthStencil = NULL;
5152 IDirectDrawSurfaceImpl *dsi;
5153 static DDSCAPS2 depthcaps = { DDSCAPS_ZBUFFER, 0, 0, 0 };
5155 IDirectDrawSurface7_GetAttachedSurface(ICOM_INTERFACE(This->target, IDirectDrawSurface7),
5160 TRACE("Setting wined3d depth stencil to NULL\n");
5161 IWineD3DDevice_SetDepthStencilSurface(This->wineD3DDevice,
5163 return WINED3DZB_FALSE;
5166 dsi = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, depthStencil);
5167 TRACE("Setting wined3d depth stencil to %p (wined3d %p)\n", dsi, dsi->WineD3DSurface);
5168 IWineD3DDevice_SetDepthStencilSurface(This->wineD3DDevice,
5169 dsi->WineD3DSurface);
5171 IDirectDrawSurface7_Release(depthStencil);
5172 return WINED3DZB_TRUE;