2 * Copyright (c) 1998-2004 Lionel Ulmer
3 * Copyright (c) 2002-2005 Christian Costa
4 * Copyright (c) 2006 Stefan Dösinger
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * IDirect3DDevice implementation, version 1, 2, 3 and 7. Rendering is relayed
21 * to WineD3D, some minimal DirectDraw specific management is handled here.
22 * The Direct3DDevice is NOT the parent of the WineD3DDevice, because d3d
23 * is initialized when DirectDraw creates the primary surface.
24 * Some type management is necessary, because some D3D types changed between
30 #include "wine/port.h"
31 #include "wine/debug.h"
45 #include "wine/exception.h"
51 #include "ddraw_private.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(d3d7);
54 WINE_DECLARE_DEBUG_CHANNEL(ddraw_thunk);
57 const GUID IID_D3DDEVICE_WineD3D = {
61 { 0xb7,0x98,0xc6,0x8a,0x77,0x2d,0x72,0x2a }
64 /*****************************************************************************
65 * IUnknown Methods. Common for Version 1, 2, 3 and 7
66 *****************************************************************************/
68 /*****************************************************************************
69 * IDirect3DDevice7::QueryInterface
71 * Used to query other interfaces from a Direct3DDevice interface.
72 * It can return interface pointers to all Direct3DDevice versions as well
73 * as IDirectDraw and IDirect3D. For a link to QueryInterface
74 * rules see ddraw.c, IDirectDraw7::QueryInterface
76 * Exists in Version 1, 2, 3 and 7
79 * refiid: Interface ID queried for
80 * obj: Used to return the interface pointer
83 * D3D_OK or E_NOINTERFACE
85 *****************************************************************************/
87 IDirect3DDeviceImpl_7_QueryInterface(IDirect3DDevice7 *iface,
91 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
92 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(refiid), obj);
94 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
98 return DDERR_INVALIDPARAMS;
100 if ( IsEqualGUID( &IID_IUnknown, refiid ) )
102 *obj = ICOM_INTERFACE(This, IDirect3DDevice7);
105 /* Check DirectDraw Interfac
\ 1s */
106 else if( IsEqualGUID( &IID_IDirectDraw7, refiid ) )
108 *obj = ICOM_INTERFACE(This->ddraw, IDirectDraw7);
109 TRACE("(%p) Returning IDirectDraw7 interface at %p\n", This, *obj);
111 else if ( IsEqualGUID( &IID_IDirectDraw4, refiid ) )
113 *obj = ICOM_INTERFACE(This->ddraw, IDirectDraw4);
114 TRACE("(%p) Returning IDirectDraw4 interface at %p\n", This, *obj);
116 else if ( IsEqualGUID( &IID_IDirectDraw2, refiid ) )
118 *obj = ICOM_INTERFACE(This->ddraw, IDirectDraw2);
119 TRACE("(%p) Returning IDirectDraw2 interface at %p\n", This, *obj);
121 else if( IsEqualGUID( &IID_IDirectDraw, refiid ) )
123 *obj = ICOM_INTERFACE(This->ddraw, IDirectDraw);
124 TRACE("(%p) Returning IDirectDraw interface at %p\n", This, *obj);
128 else if ( IsEqualGUID( &IID_IDirect3D , refiid ) )
130 *obj = ICOM_INTERFACE(This->ddraw, IDirect3D);
131 TRACE("(%p) Returning IDirect3D interface at %p\n", This, *obj);
133 else if ( IsEqualGUID( &IID_IDirect3D2 , refiid ) )
135 *obj = ICOM_INTERFACE(This->ddraw, IDirect3D2);
136 TRACE("(%p) Returning IDirect3D2 interface at %p\n", This, *obj);
138 else if ( IsEqualGUID( &IID_IDirect3D3 , refiid ) )
140 *obj = ICOM_INTERFACE(This->ddraw, IDirect3D3);
141 TRACE("(%p) Returning IDirect3D3 interface at %p\n", This, *obj);
143 else if ( IsEqualGUID( &IID_IDirect3D7 , refiid ) )
145 *obj = ICOM_INTERFACE(This->ddraw, IDirect3D7);
146 TRACE("(%p) Returning IDirect3D7 interface at %p\n", This, *obj);
150 else if ( IsEqualGUID( &IID_IDirect3DDevice , refiid ) )
152 *obj = ICOM_INTERFACE(This, IDirect3DDevice);
153 TRACE("(%p) Returning IDirect3DDevice interface at %p\n", This, *obj);
155 else if ( IsEqualGUID( &IID_IDirect3DDevice2 , refiid ) ) {
156 *obj = ICOM_INTERFACE(This, IDirect3DDevice2);
157 TRACE("(%p) Returning IDirect3DDevice2 interface at %p\n", This, *obj);
159 else if ( IsEqualGUID( &IID_IDirect3DDevice3 , refiid ) ) {
160 *obj = ICOM_INTERFACE(This, IDirect3DDevice3);
161 TRACE("(%p) Returning IDirect3DDevice3 interface at %p\n", This, *obj);
163 else if ( IsEqualGUID( &IID_IDirect3DDevice7 , refiid ) ) {
164 *obj = ICOM_INTERFACE(This, IDirect3DDevice7);
165 TRACE("(%p) Returning IDirect3DDevice7 interface at %p\n", This, *obj);
168 /* Unknown interface */
171 ERR("(%p)->(%s, %p): No interface found\n", This, debugstr_guid(refiid), obj);
172 return E_NOINTERFACE;
175 /* AddRef the returned interface */
176 IUnknown_AddRef( (IUnknown *) *obj);
180 static HRESULT WINAPI
181 Thunk_IDirect3DDeviceImpl_3_QueryInterface(IDirect3DDevice3 *iface,
185 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
186 TRACE_(ddraw_thunk)("(%p)->(%s,%p) thunking to IDirect3DDevice7 interface.\n", This, debugstr_guid(riid), obj);
187 return IDirect3DDevice7_QueryInterface(ICOM_INTERFACE(This, IDirect3DDevice7),
192 static HRESULT WINAPI
193 Thunk_IDirect3DDeviceImpl_2_QueryInterface(IDirect3DDevice2 *iface,
197 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
198 TRACE_(ddraw_thunk)("(%p)->(%s,%p) thunking to IDirect3DDevice7 interface.\n", This, debugstr_guid(riid), obj);
199 return IDirect3DDevice7_QueryInterface(ICOM_INTERFACE(This, IDirect3DDevice7),
204 static HRESULT WINAPI
205 Thunk_IDirect3DDeviceImpl_1_QueryInterface(IDirect3DDevice *iface,
209 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
210 TRACE_(ddraw_thunk)("(%p)->(%s,%p) thunking to IDirect3DDevice7 interface.\n", This, debugstr_guid(riid), obp);
211 return IDirect3DDevice7_QueryInterface(ICOM_INTERFACE(This, IDirect3DDevice7),
216 /*****************************************************************************
217 * IDirect3DDevice7::AddRef
219 * Increases the refcount....
220 * The most exciting Method, definitely
222 * Exists in Version 1, 2, 3 and 7
227 *****************************************************************************/
229 IDirect3DDeviceImpl_7_AddRef(IDirect3DDevice7 *iface)
231 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
232 ULONG ref = InterlockedIncrement(&This->ref);
234 TRACE("(%p) : incrementing from %u.\n", This, ref -1);
240 Thunk_IDirect3DDeviceImpl_3_AddRef(IDirect3DDevice3 *iface)
242 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
243 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
244 return IDirect3DDevice7_AddRef(ICOM_INTERFACE(This, IDirect3DDevice7));
248 Thunk_IDirect3DDeviceImpl_2_AddRef(IDirect3DDevice2 *iface)
250 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
251 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
252 return IDirect3DDevice7_AddRef(ICOM_INTERFACE(This, IDirect3DDevice7));
256 Thunk_IDirect3DDeviceImpl_1_AddRef(IDirect3DDevice *iface)
258 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", iface);
259 return IDirect3DDevice7_AddRef(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice, IDirect3DDevice7, iface));
262 /*****************************************************************************
263 * IDirect3DDevice7::Release
265 * Decreases the refcount of the interface
266 * When the refcount is reduced to 0, the object is destroyed.
268 * Exists in Version 1, 2, 3 and 7
273 *****************************************************************************/
275 IDirect3DDeviceImpl_7_Release(IDirect3DDevice7 *iface)
277 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
278 ULONG ref = InterlockedDecrement(&This->ref);
280 TRACE("(%p)->() decrementing from %u.\n", This, ref +1);
282 /* This method doesn't destroy the WineD3DDevice, because it's still in use for
283 * 2D rendering. IDirectDrawSurface7::Release will destroy the WineD3DDevice
284 * when the render target is released
288 IParent *IndexBufferParent;
291 /* Free the index buffer. */
292 IWineD3DDevice_SetIndices(This->wineD3DDevice,
295 IWineD3DIndexBuffer_GetParent(This->indexbuffer,
296 (IUnknown **) &IndexBufferParent);
297 IParent_Release(IndexBufferParent); /* Once for the getParent */
298 if( IParent_Release(IndexBufferParent) != 0) /* And now to destroy it */
300 ERR(" (%p) Something is still holding the index buffer parent %p\n", This, IndexBufferParent);
303 /* There is no need to unset the vertex buffer here, IWineD3DDevice_Uninit3D will do that when
304 * destroying the primary stateblock. If a vertex buffer is destroyed while it is bound
305 * IDirect3DVertexBuffer::Release will unset it.
308 /* Restore the render targets */
309 if(This->OffScreenTarget)
311 /* Set the device up to render to the front buffer since the back buffer will
314 IWineD3DDevice_SetRenderTarget(This->wineD3DDevice, 0,
315 This->ddraw->d3d_target->WineD3DSurface);
316 /* This->target is the offscreen target.
317 * This->ddraw->d3d_target is the target used by DDraw
319 TRACE("(%p) Release: Using %p as front buffer, %p as back buffer\n", This, This->ddraw->d3d_target, NULL);
320 IWineD3DDevice_SetFrontBackBuffers(This->wineD3DDevice,
321 This->ddraw->d3d_target->WineD3DSurface,
325 /* Release the WineD3DDevice. This won't destroy it */
326 if(IWineD3DDevice_Release(This->wineD3DDevice) <= 0)
328 ERR(" (%p) The wineD3D device %p was destroyed unexpectadely. Prepare for trouble\n", This, This->wineD3DDevice);
331 /* The texture handles should be unset by now, but there might be some bits
332 * missing in our reference counting(needs test). Do a sanity check
334 for(i = 0; i < This->numHandles; i++)
336 if(This->Handles[i].ptr)
338 switch(This->Handles[i].type)
340 case DDrawHandle_Texture:
342 IDirectDrawSurfaceImpl *surf = (IDirectDrawSurfaceImpl *) This->Handles[i].ptr;
343 FIXME("Texture Handle %d not unset properly\n", i + 1);
348 case DDrawHandle_Material:
350 IDirect3DMaterialImpl *mat = (IDirect3DMaterialImpl *) This->Handles[i].ptr;
351 FIXME("Material handle %d not unset properly\n", i + 1);
356 case DDrawHandle_Matrix:
358 /* No fixme here because this might happen because of sloppy apps */
359 WARN("Leftover matrix handle %d, deleting\n", i + 1);
360 IDirect3DDevice_DeleteMatrix(ICOM_INTERFACE(This, IDirect3DDevice),
365 case DDrawHandle_StateBlock:
367 /* No fixme here because this might happen because of sloppy apps */
368 WARN("Leftover stateblock handle %d, deleting\n", i + 1);
369 IDirect3DDevice7_DeleteStateBlock(ICOM_INTERFACE(This, IDirect3DDevice7),
375 FIXME("Unknown handle %d not unset properly\n", i + 1);
380 HeapFree(GetProcessHeap(), 0, This->Handles);
382 TRACE("Releasing target %p %p\n", This->target, This->ddraw->d3d_target);
383 /* Release the render target and the WineD3D render target
384 * (See IDirect3D7::CreateDevice for more comments on this)
386 IDirectDrawSurface7_Release(ICOM_INTERFACE(This->target, IDirectDrawSurface7));
387 IDirectDrawSurface7_Release(ICOM_INTERFACE(This->ddraw->d3d_target,IDirectDrawSurface7));
388 TRACE("Target release done\n");
390 This->ddraw->d3ddevice = NULL;
392 /* Now free the structure */
393 HeapFree(GetProcessHeap(), 0, This);
401 Thunk_IDirect3DDeviceImpl_3_Release(IDirect3DDevice3 *iface)
403 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
404 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
405 return IDirect3DDevice7_Release(ICOM_INTERFACE(This, IDirect3DDevice7));
409 Thunk_IDirect3DDeviceImpl_2_Release(IDirect3DDevice2 *iface)
411 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
412 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
413 return IDirect3DDevice7_Release(ICOM_INTERFACE(This, IDirect3DDevice7));
417 Thunk_IDirect3DDeviceImpl_1_Release(IDirect3DDevice *iface)
419 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
420 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
421 return IDirect3DDevice7_Release(ICOM_INTERFACE(This, IDirect3DDevice7));
424 /*****************************************************************************
425 * IDirect3DDevice Methods
426 *****************************************************************************/
428 /*****************************************************************************
429 * IDirect3DDevice::Initialize
431 * Initializes a Direct3DDevice. This implementation is a no-op, as all
432 * initialization is done at create time.
434 * Exists in Version 1
437 * No idea what they mean, as the MSDN page is gone
441 *****************************************************************************/
442 static HRESULT WINAPI
443 IDirect3DDeviceImpl_1_Initialize(IDirect3DDevice *iface,
444 IDirect3D *Direct3D, GUID *guid,
447 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
449 /* It shouldn't be crucial, but print a FIXME, I'm interested if
450 * any game calls it and when
452 FIXME("(%p)->(%p,%p,%p): No-op!\n", This, Direct3D, guid, Desc);
457 /*****************************************************************************
458 * IDirect3DDevice7::GetCaps
460 * Retrieves the device's capabilities
462 * This implementation is used for Version 7 only, the older versions have
463 * their own implementation.
466 * Desc: Pointer to a D3DDEVICEDESC7 structure to fill
470 * D3DERR_* if a problem occurs. See WineD3D
472 *****************************************************************************/
473 static HRESULT WINAPI
474 IDirect3DDeviceImpl_7_GetCaps(IDirect3DDevice7 *iface,
475 D3DDEVICEDESC7 *Desc)
477 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
478 D3DDEVICEDESC OldDesc;
479 TRACE("(%p)->(%p)\n", This, Desc);
481 /* Call the same function used by IDirect3D, this saves code */
482 return IDirect3DImpl_GetCaps(This->ddraw->wineD3D, &OldDesc, Desc);
485 /*****************************************************************************
486 * IDirect3DDevice3::GetCaps
488 * Retrieves the capabilities of the hardware device and the emulation
489 * device. For Wine, hardware and emulation are the same (it's all HW).
491 * This implementation is used for Version 1, 2, and 3. Version 7 has its own
494 * HWDesc: Structure to fill with the HW caps
495 * HelDesc: Structure to fill with the hardare emulation caps
499 * D3DERR_* if a problem occurs. See WineD3D
501 *****************************************************************************/
502 static HRESULT WINAPI
503 IDirect3DDeviceImpl_3_GetCaps(IDirect3DDevice3 *iface,
504 D3DDEVICEDESC *HWDesc,
505 D3DDEVICEDESC *HelDesc)
507 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
508 D3DDEVICEDESC7 newDesc;
510 TRACE("(%p)->(%p,%p)\n", iface, HWDesc, HelDesc);
512 hr = IDirect3DImpl_GetCaps(This->ddraw->wineD3D, HWDesc, &newDesc);
513 if(hr != D3D_OK) return hr;
519 static HRESULT WINAPI
520 Thunk_IDirect3DDeviceImpl_2_GetCaps(IDirect3DDevice2 *iface,
521 D3DDEVICEDESC *D3DHWDevDesc,
522 D3DDEVICEDESC *D3DHELDevDesc)
524 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
525 TRACE_(ddraw_thunk)("(%p)->(%p,%p) thunking to IDirect3DDevice3 interface.\n", This, D3DHWDevDesc, D3DHELDevDesc);
526 return IDirect3DDevice3_GetCaps(ICOM_INTERFACE(This, IDirect3DDevice3),
531 static HRESULT WINAPI
532 Thunk_IDirect3DDeviceImpl_1_GetCaps(IDirect3DDevice *iface,
533 D3DDEVICEDESC *D3DHWDevDesc,
534 D3DDEVICEDESC *D3DHELDevDesc)
536 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
537 TRACE_(ddraw_thunk)("(%p)->(%p,%p) thunking to IDirect3DDevice3 interface.\n", This, D3DHWDevDesc, D3DHELDevDesc);
538 return IDirect3DDevice3_GetCaps(ICOM_INTERFACE(This, IDirect3DDevice3),
543 /*****************************************************************************
544 * IDirect3DDevice2::SwapTextureHandles
546 * Swaps the texture handles of 2 Texture interfaces. Version 1 and 2
549 * Tex1, Tex2: The 2 Textures to swap
554 *****************************************************************************/
555 static HRESULT WINAPI
556 IDirect3DDeviceImpl_2_SwapTextureHandles(IDirect3DDevice2 *iface,
557 IDirect3DTexture2 *Tex1,
558 IDirect3DTexture2 *Tex2)
560 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
562 IDirectDrawSurfaceImpl *surf1 = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture2, Tex1);
563 IDirectDrawSurfaceImpl *surf2 = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture2, Tex2);
564 TRACE("(%p)->(%p,%p)\n", This, surf1, surf2);
566 This->Handles[surf1->Handle - 1].ptr = surf2;
567 This->Handles[surf2->Handle - 1].ptr = surf1;
569 swap = surf2->Handle;
570 surf2->Handle = surf1->Handle;
571 surf1->Handle = swap;
576 static HRESULT WINAPI
577 Thunk_IDirect3DDeviceImpl_1_SwapTextureHandles(IDirect3DDevice *iface,
578 IDirect3DTexture *D3DTex1,
579 IDirect3DTexture *D3DTex2)
581 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
582 IDirectDrawSurfaceImpl *surf1 = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture, D3DTex1);
583 IDirectDrawSurfaceImpl *surf2 = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture, D3DTex2);
584 TRACE_(ddraw_thunk)("(%p)->(%p,%p) thunking to IDirect3DDevice2 interface.\n", This, surf1, surf2);
585 return IDirect3DDevice2_SwapTextureHandles(ICOM_INTERFACE(This, IDirect3DDevice2),
586 ICOM_INTERFACE(surf1, IDirect3DTexture2),
587 ICOM_INTERFACE(surf2, IDirect3DTexture2));
590 /*****************************************************************************
591 * IDirect3DDevice3::GetStats
593 * This method seems to retrieve some stats from the device.
594 * The MSDN documentation doesn't exist any more, but the D3DSTATS
595 * structure suggests that the amout of drawn primitives and processed
596 * vertices is returned.
598 * Exists in Version 1, 2 and 3
601 * Stats: Pointer to a D3DSTATS structure to be filled
605 * DDERR_INVALIDPARAMS if Stats == NULL
607 *****************************************************************************/
608 static HRESULT WINAPI
609 IDirect3DDeviceImpl_3_GetStats(IDirect3DDevice3 *iface,
612 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
613 FIXME("(%p)->(%p): Stub!\n", This, Stats);
616 return DDERR_INVALIDPARAMS;
618 /* Fill the Stats with 0 */
619 Stats->dwTrianglesDrawn = 0;
620 Stats->dwLinesDrawn = 0;
621 Stats->dwPointsDrawn = 0;
622 Stats->dwSpansDrawn = 0;
623 Stats->dwVerticesProcessed = 0;
628 static HRESULT WINAPI
629 Thunk_IDirect3DDeviceImpl_2_GetStats(IDirect3DDevice2 *iface,
632 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
633 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, Stats);
634 return IDirect3DDevice3_GetStats(ICOM_INTERFACE(This, IDirect3DDevice3),
638 static HRESULT WINAPI
639 Thunk_IDirect3DDeviceImpl_1_GetStats(IDirect3DDevice *iface,
642 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
643 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, Stats);
644 return IDirect3DDevice3_GetStats(ICOM_INTERFACE(This, IDirect3DDevice3),
648 /*****************************************************************************
649 * IDirect3DDevice::CreateExecuteBuffer
651 * Creates an IDirect3DExecuteBuffer, used for rendering with a
657 * Desc: Buffer description
658 * ExecuteBuffer: Address to return the Interface pointer at
659 * UnkOuter: Must be NULL. Basically for aggregation, which ddraw doesn't
663 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
664 * DDERR_OUTOFMEMORY if we ran out of memory
667 *****************************************************************************/
668 static HRESULT WINAPI
669 IDirect3DDeviceImpl_1_CreateExecuteBuffer(IDirect3DDevice *iface,
670 D3DEXECUTEBUFFERDESC *Desc,
671 IDirect3DExecuteBuffer **ExecuteBuffer,
674 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
675 IDirect3DExecuteBufferImpl* object;
676 TRACE("(%p)->(%p,%p,%p)!\n", This, Desc, ExecuteBuffer, UnkOuter);
679 return CLASS_E_NOAGGREGATION;
681 /* Allocate the new Execute Buffer */
682 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DExecuteBufferImpl));
685 ERR("Out of memory when allocating a IDirect3DExecuteBufferImpl structure\n");
686 return DDERR_OUTOFMEMORY;
689 ICOM_INIT_INTERFACE(object, IDirect3DExecuteBuffer, IDirect3DExecuteBuffer_Vtbl);
692 object->d3ddev = This;
694 /* Initializes memory */
695 memcpy(&object->desc, Desc, Desc->dwSize);
697 /* No buffer given */
698 if ((object->desc.dwFlags & D3DDEB_LPDATA) == 0)
699 object->desc.lpData = NULL;
701 /* No buffer size given */
702 if ((object->desc.dwFlags & D3DDEB_BUFSIZE) == 0)
703 object->desc.dwBufferSize = 0;
705 /* Create buffer if asked */
706 if ((object->desc.lpData == NULL) && (object->desc.dwBufferSize > 0))
708 object->need_free = TRUE;
709 object->desc.lpData = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,object->desc.dwBufferSize);
710 if(!object->desc.lpData)
712 ERR("Out of memory when allocating the execute buffer data\n");
713 HeapFree(GetProcessHeap(), 0, object);
714 return DDERR_OUTOFMEMORY;
719 object->need_free = FALSE;
722 /* No vertices for the moment */
723 object->vertex_data = NULL;
725 object->desc.dwFlags |= D3DDEB_LPDATA;
727 object->indices = NULL;
728 object->nb_indices = 0;
730 *ExecuteBuffer = ICOM_INTERFACE(object, IDirect3DExecuteBuffer);
732 TRACE(" Returning IDirect3DExecuteBuffer at %p, implementation is at %p\n", *ExecuteBuffer, object);
737 /*****************************************************************************
738 * IDirect3DDevice::Execute
740 * Executes all the stuff in an execute buffer.
743 * ExecuteBuffer: The buffer to execute
744 * Viewport: The viewport used for rendering
748 * DDERR_INVALIDPARAMS if ExecuteBuffer == NULL
751 *****************************************************************************/
752 static HRESULT WINAPI
753 IDirect3DDeviceImpl_1_Execute(IDirect3DDevice *iface,
754 IDirect3DExecuteBuffer *ExecuteBuffer,
755 IDirect3DViewport *Viewport,
758 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
759 IDirect3DExecuteBufferImpl *Direct3DExecuteBufferImpl = ICOM_OBJECT(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, ExecuteBuffer);
760 IDirect3DViewportImpl *Direct3DViewportImpl = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport);
762 TRACE("(%p)->(%p,%p,%08x)\n", This, Direct3DExecuteBufferImpl, Direct3DViewportImpl, Flags);
764 if(!Direct3DExecuteBufferImpl)
765 return DDERR_INVALIDPARAMS;
768 IDirect3DExecuteBufferImpl_Execute(Direct3DExecuteBufferImpl, This, Direct3DViewportImpl);
773 /*****************************************************************************
774 * IDirect3DDevice3::AddViewport
776 * Add a Direct3DViewport to the device's viewport list. These viewports
777 * are wrapped to IDirect3DDevice7 viewports in viewport.c
779 * Exists in Version 1, 2 and 3. Note that IDirect3DViewport 1, 2 and 3
780 * are the same interfaces.
783 * Viewport: The viewport to add
786 * DDERR_INVALIDPARAMS if Viewport == NULL
789 *****************************************************************************/
790 static HRESULT WINAPI
791 IDirect3DDeviceImpl_3_AddViewport(IDirect3DDevice3 *iface,
792 IDirect3DViewport3 *Viewport)
794 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
795 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport);
797 TRACE("(%p)->(%p)\n", This, vp);
801 return DDERR_INVALIDPARAMS;
803 vp->next = This->viewport_list;
804 This->viewport_list = vp;
809 static HRESULT WINAPI
810 Thunk_IDirect3DDeviceImpl_2_AddViewport(IDirect3DDevice2 *iface,
811 IDirect3DViewport2 *Direct3DViewport2)
813 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
814 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport2);
815 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, vp);
816 return IDirect3DDevice3_AddViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
817 ICOM_INTERFACE(vp, IDirect3DViewport3));
820 static HRESULT WINAPI
821 Thunk_IDirect3DDeviceImpl_1_AddViewport(IDirect3DDevice *iface,
822 IDirect3DViewport *Direct3DViewport)
824 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
825 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport);
826 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, vp);
827 return IDirect3DDevice3_AddViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
828 ICOM_INTERFACE(vp, IDirect3DViewport3));
831 /*****************************************************************************
832 * IDirect3DDevice3::DeleteViewport
834 * Deletes a Direct3DViewport from the device's viewport list.
836 * Exists in Version 1, 2 and 3. Note that all Viewport interface versions
840 * Viewport: The viewport to delete
844 * DDERR_INVALIDPARAMS if the viewport wasn't found in the list
846 *****************************************************************************/
847 static HRESULT WINAPI
848 IDirect3DDeviceImpl_3_DeleteViewport(IDirect3DDevice3 *iface,
849 IDirect3DViewport3 *Viewport)
851 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
852 IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *) Viewport;
853 IDirect3DViewportImpl *cur_viewport, *prev_viewport = NULL;
855 TRACE("(%p)->(%p)\n", This, vp);
857 cur_viewport = This->viewport_list;
858 while (cur_viewport != NULL)
860 if (cur_viewport == vp)
862 if (prev_viewport == NULL) This->viewport_list = cur_viewport->next;
863 else prev_viewport->next = cur_viewport->next;
864 /* TODO : add desactivate of the viewport and all associated lights... */
867 prev_viewport = cur_viewport;
868 cur_viewport = cur_viewport->next;
871 return DDERR_INVALIDPARAMS;
874 static HRESULT WINAPI
875 Thunk_IDirect3DDeviceImpl_2_DeleteViewport(IDirect3DDevice2 *iface,
876 IDirect3DViewport2 *Direct3DViewport2)
878 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
879 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport2);
880 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, vp);
881 return IDirect3DDevice3_DeleteViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
882 ICOM_INTERFACE(vp, IDirect3DViewport3));
885 static HRESULT WINAPI
886 Thunk_IDirect3DDeviceImpl_1_DeleteViewport(IDirect3DDevice *iface,
887 IDirect3DViewport *Direct3DViewport)
889 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
890 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport);
891 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, vp);
892 return IDirect3DDevice3_DeleteViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
893 ICOM_INTERFACE(vp, IDirect3DViewport3));
896 /*****************************************************************************
897 * IDirect3DDevice3::NextViewport
899 * Returns a viewport from the viewport list, depending on the
900 * passed viewport and the flags.
902 * Exists in Version 1, 2 and 3. Note that all Viewport interface versions
906 * Viewport: Viewport to use for beginning the search
907 * Flags: D3DNEXT_NEXT, D3DNEXT_HEAD or D3DNEXT_TAIL
911 * DDERR_INVALIDPARAMS if the flags were wrong, or Viewport was NULL
913 *****************************************************************************/
914 static HRESULT WINAPI
915 IDirect3DDeviceImpl_3_NextViewport(IDirect3DDevice3 *iface,
916 IDirect3DViewport3 *Viewport3,
917 IDirect3DViewport3 **lplpDirect3DViewport3,
920 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
921 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport3);
922 IDirect3DViewportImpl *res = NULL;
924 TRACE("(%p)->(%p,%p,%08x)\n", This, vp, lplpDirect3DViewport3, Flags);
928 *lplpDirect3DViewport3 = NULL;
929 return DDERR_INVALIDPARAMS;
942 res = This->viewport_list;
947 IDirect3DViewportImpl *cur_viewport = This->viewport_list;
948 if (cur_viewport != NULL)
950 while (cur_viewport->next != NULL) cur_viewport = cur_viewport->next;
956 *lplpDirect3DViewport3 = NULL;
957 return DDERR_INVALIDPARAMS;
960 *lplpDirect3DViewport3 = ICOM_INTERFACE(res, IDirect3DViewport3);
964 static HRESULT WINAPI
965 Thunk_IDirect3DDeviceImpl_2_NextViewport(IDirect3DDevice2 *iface,
966 IDirect3DViewport2 *Viewport2,
967 IDirect3DViewport2 **lplpDirect3DViewport2,
970 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
971 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport2);
972 IDirect3DViewport3 *res;
974 TRACE_(ddraw_thunk)("(%p)->(%p,%p,%08x) thunking to IDirect3DDevice3 interface.\n", This, vp, lplpDirect3DViewport2, Flags);
975 hr = IDirect3DDevice3_NextViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
976 ICOM_INTERFACE(vp, IDirect3DViewport3),
979 *lplpDirect3DViewport2 = (IDirect3DViewport2 *) COM_INTERFACE_CAST(IDirect3DViewportImpl, IDirect3DViewport3, IDirect3DViewport3, res);
983 static HRESULT WINAPI
984 Thunk_IDirect3DDeviceImpl_1_NextViewport(IDirect3DDevice *iface,
985 IDirect3DViewport *Viewport,
986 IDirect3DViewport **lplpDirect3DViewport,
989 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
990 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport);
991 IDirect3DViewport3 *res;
993 TRACE_(ddraw_thunk)("(%p)->(%p,%p,%08x) thunking to IDirect3DDevice3 interface.\n", This, vp, lplpDirect3DViewport, Flags);
994 hr = IDirect3DDevice3_NextViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
995 ICOM_INTERFACE(vp, IDirect3DViewport3),
998 *lplpDirect3DViewport = (IDirect3DViewport *) COM_INTERFACE_CAST(IDirect3DViewportImpl, IDirect3DViewport3, IDirect3DViewport3, res);
1002 /*****************************************************************************
1003 * IDirect3DDevice::Pick
1005 * Executes an execute buffer without performing rendering. Instead, a
1006 * list of primitives that intersect with (x1,y1) of the passed rectangle
1007 * is created. IDirect3DDevice::GetPickRecords can be used to retrieve
1013 * ExecuteBuffer: Buffer to execute
1014 * Viewport: Viewport to use for execution
1015 * Flags: None are defined, according to the SDK
1016 * Rect: Specifies the coordinates to be picked. Only x1 and y2 are used,
1017 * x2 and y2 are ignored.
1020 * D3D_OK because it's a stub
1022 *****************************************************************************/
1023 static HRESULT WINAPI
1024 IDirect3DDeviceImpl_1_Pick(IDirect3DDevice *iface,
1025 IDirect3DExecuteBuffer *ExecuteBuffer,
1026 IDirect3DViewport *Viewport,
1030 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1031 IDirect3DExecuteBufferImpl *execbuf = ICOM_OBJECT(IDirect3DExecuteBufferImpl, IDirect3DExecuteBuffer, ExecuteBuffer);
1032 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Viewport);
1033 FIXME("(%p)->(%p,%p,%08x,%p): stub!\n", This, execbuf, vp, Flags, Rect);
1038 /*****************************************************************************
1039 * IDirect3DDevice::GetPickRecords
1041 * Retrieves the pick records generated by IDirect3DDevice::GetPickRecords
1046 * Count: Pointer to a DWORD containing the numbers of pick records to
1048 * D3DPickRec: Address to store the resulting D3DPICKRECORD arry.
1051 * D3D_OK, because it's a stub
1053 *****************************************************************************/
1054 static HRESULT WINAPI
1055 IDirect3DDeviceImpl_1_GetPickRecords(IDirect3DDevice *iface,
1057 D3DPICKRECORD *D3DPickRec)
1059 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1060 FIXME("(%p)->(%p,%p): stub!\n", This, Count, D3DPickRec);
1065 /*****************************************************************************
1066 * IDirect3DDevice7::EnumTextureformats
1068 * Enumerates the supported texture formats. It has a list of all possible
1069 * formats and calls IWineD3D::CheckDeviceFormat for each format to see if
1070 * WineD3D supports it. If so, then it is passed to the app.
1072 * This is for Version 7 and 3, older versions have a different
1073 * callback function and their own implementation
1076 * Callback: Callback to call for each enumerated format
1077 * Arg: Argument to pass to the callback
1081 * DDERR_INVALIDPARAMS if Callback == NULL
1083 *****************************************************************************/
1084 static HRESULT WINAPI
1085 IDirect3DDeviceImpl_7_EnumTextureFormats(IDirect3DDevice7 *iface,
1086 LPD3DENUMPIXELFORMATSCALLBACK Callback,
1089 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1093 WINED3DFORMAT FormatList[] = {
1095 WINED3DFMT_A8R8G8B8,
1096 WINED3DFMT_X8R8G8B8,
1100 WINED3DFMT_A1R5G5B5,
1101 WINED3DFMT_A4R4G4B4,
1103 WINED3DFMT_X1R5G5B5,
1113 TRACE("(%p)->(%p,%p): Relay\n", This, Callback, Arg);
1116 return DDERR_INVALIDPARAMS;
1118 for(i = 0; i < sizeof(FormatList) / sizeof(WINED3DFORMAT); i++)
1120 hr = IWineD3D_CheckDeviceFormat(This->ddraw->wineD3D,
1123 0 /* AdapterFormat */,
1125 0 /* ResourceType */,
1129 DDPIXELFORMAT pformat;
1131 memset(&pformat, 0, sizeof(pformat));
1132 pformat.dwSize = sizeof(pformat);
1133 PixelFormat_WineD3DtoDD(&pformat, FormatList[i]);
1135 TRACE("Enumerating WineD3DFormat %d\n", FormatList[i]);
1136 hr = Callback(&pformat, Arg);
1137 if(hr != DDENUMRET_OK)
1139 TRACE("Format enumeration cancelled by application\n");
1144 TRACE("End of enumeration\n");
1148 static HRESULT WINAPI
1149 Thunk_IDirect3DDeviceImpl_3_EnumTextureFormats(IDirect3DDevice3 *iface,
1150 LPD3DENUMPIXELFORMATSCALLBACK Callback,
1153 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1154 TRACE_(ddraw_thunk)("(%p)->(%p,%p) thunking to IDirect3DDevice7 interface.\n", This, Callback, Arg);
1155 return IDirect3DDevice7_EnumTextureFormats(ICOM_INTERFACE(This, IDirect3DDevice7),
1160 /*****************************************************************************
1161 * IDirect3DDevice2::EnumTextureformats
1163 * EnumTextureFormats for Version 1 and 2, see
1164 * IDirect3DDevice7::EnumTexureFormats for a more detailed description.
1166 * This version has a different callback and does not enumerate FourCC
1169 *****************************************************************************/
1170 static HRESULT WINAPI
1171 IDirect3DDeviceImpl_2_EnumTextureFormats(IDirect3DDevice2 *iface,
1172 LPD3DENUMTEXTUREFORMATSCALLBACK Callback,
1175 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1179 WINED3DFORMAT FormatList[] = {
1181 WINED3DFMT_A8R8G8B8,
1182 WINED3DFMT_X8R8G8B8,
1186 WINED3DFMT_A1R5G5B5,
1187 WINED3DFMT_A4R4G4B4,
1189 WINED3DFMT_X1R5G5B5,
1193 /* FOURCC codes - Not in this version*/
1196 TRACE("(%p)->(%p,%p): Relay\n", This, Callback, Arg);
1199 return DDERR_INVALIDPARAMS;
1201 for(i = 0; i < sizeof(FormatList) / sizeof(WINED3DFORMAT); i++)
1203 hr = IWineD3D_CheckDeviceFormat(This->ddraw->wineD3D,
1206 0 /* AdapterFormat */,
1208 0 /* ResourceType */,
1212 DDSURFACEDESC sdesc;
1214 memset(&sdesc, 0, sizeof(sdesc));
1215 sdesc.dwSize = sizeof(sdesc);
1216 sdesc.dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
1217 sdesc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
1218 sdesc.ddpfPixelFormat.dwSize = sizeof(sdesc.ddpfPixelFormat);
1219 PixelFormat_WineD3DtoDD(&sdesc.ddpfPixelFormat, FormatList[i]);
1221 TRACE("Enumerating WineD3DFormat %d\n", FormatList[i]);
1222 hr = Callback(&sdesc, Arg);
1223 if(hr != DDENUMRET_OK)
1225 TRACE("Format enumeration cancelled by application\n");
1230 TRACE("End of enumeration\n");
1234 static HRESULT WINAPI
1235 Thunk_IDirect3DDeviceImpl_1_EnumTextureFormats(IDirect3DDevice *iface,
1236 LPD3DENUMTEXTUREFORMATSCALLBACK Callback,
1239 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1240 TRACE_(ddraw_thunk)("(%p)->(%p,%p) thunking to IDirect3DDevice2 interface.\n", This, Callback, Arg);
1241 return IDirect3DDevice2_EnumTextureFormats(ICOM_INTERFACE(This, IDirect3DDevice2),
1246 /*****************************************************************************
1247 * IDirect3DDevice::CreateMatrix
1249 * Creates a matrix handle. A handle is created and memory for a D3DMATRIX is
1250 * allocated for the handle.
1255 * D3DMatHandle: Address to return the handle at
1259 * DDERR_INVALIDPARAMS if D3DMatHandle = NULL
1261 *****************************************************************************/
1262 static HRESULT WINAPI
1263 IDirect3DDeviceImpl_1_CreateMatrix(IDirect3DDevice *iface, D3DMATRIXHANDLE *D3DMatHandle)
1265 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1267 TRACE("(%p)->(%p)\n", This, D3DMatHandle);
1270 return DDERR_INVALIDPARAMS;
1272 Matrix = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(D3DMATRIX));
1275 ERR("Out of memory when allocating a D3DMATRIX\n");
1276 return DDERR_OUTOFMEMORY;
1278 *D3DMatHandle = IDirect3DDeviceImpl_CreateHandle(This);
1279 if(!(*D3DMatHandle))
1281 ERR("Failed to create a matrix handle\n");
1282 HeapFree(GetProcessHeap(), 0, Matrix);
1283 return DDERR_OUTOFMEMORY;
1285 This->Handles[(DWORD) *D3DMatHandle - 1].ptr = Matrix;
1286 This->Handles[(DWORD) *D3DMatHandle - 1].type = DDrawHandle_Matrix;
1287 TRACE(" returning matrix handle %d\n", *D3DMatHandle);
1292 /*****************************************************************************
1293 * IDirect3DDevice::SetMatrix
1295 * Sets a matrix for a matrix handle. The matrix is copied into the memory
1296 * allocated for the handle
1301 * D3DMatHandle: Handle to set the matrix to
1302 * D3DMatrix: Matrix to set
1306 * DDERR_INVALIDPARAMS if the handle of the matrix is invalid or the matrix
1309 *****************************************************************************/
1310 static HRESULT WINAPI
1311 IDirect3DDeviceImpl_1_SetMatrix(IDirect3DDevice *iface,
1312 D3DMATRIXHANDLE D3DMatHandle,
1313 D3DMATRIX *D3DMatrix)
1315 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1316 TRACE("(%p)->(%08x,%p)\n", This, (DWORD) D3DMatHandle, D3DMatrix);
1318 if( (!D3DMatHandle) || (!D3DMatrix) )
1319 return DDERR_INVALIDPARAMS;
1321 if(D3DMatHandle > This->numHandles)
1323 ERR("Handle %d out of range\n", D3DMatHandle);
1324 return DDERR_INVALIDPARAMS;
1326 else if(This->Handles[D3DMatHandle - 1].type != DDrawHandle_Matrix)
1328 ERR("Handle %d is not a matrix handle\n", D3DMatHandle);
1329 return DDERR_INVALIDPARAMS;
1333 dump_D3DMATRIX(D3DMatrix);
1335 *((D3DMATRIX *) This->Handles[D3DMatHandle - 1].ptr) = *D3DMatrix;
1340 /*****************************************************************************
1341 * IDirect3DDevice::SetMatrix
1343 * Returns the content of a D3DMATRIX handle
1348 * D3DMatHandle: Matrix handle to read the content from
1349 * D3DMatrix: Address to store the content at
1353 * DDERR_INVALIDPARAMS if D3DMatHandle is invalid or D3DMatrix is NULL
1355 *****************************************************************************/
1356 static HRESULT WINAPI
1357 IDirect3DDeviceImpl_1_GetMatrix(IDirect3DDevice *iface,
1358 D3DMATRIXHANDLE D3DMatHandle,
1359 D3DMATRIX *D3DMatrix)
1361 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1362 TRACE("(%p)->(%08x,%p)\n", This, (DWORD) D3DMatHandle, D3DMatrix);
1365 return DDERR_INVALIDPARAMS;
1367 return DDERR_INVALIDPARAMS;
1369 if(D3DMatHandle > This->numHandles)
1371 ERR("Handle %d out of range\n", D3DMatHandle);
1372 return DDERR_INVALIDPARAMS;
1374 else if(This->Handles[D3DMatHandle - 1].type != DDrawHandle_Matrix)
1376 ERR("Handle %d is not a matrix handle\n", D3DMatHandle);
1377 return DDERR_INVALIDPARAMS;
1380 /* The handle is simply a pointer to a D3DMATRIX structure */
1381 *D3DMatrix = *((D3DMATRIX *) This->Handles[D3DMatHandle - 1].ptr);
1386 /*****************************************************************************
1387 * IDirect3DDevice::DeleteMatrix
1389 * Destroys a Matrix handle. Frees the memory and unsets the handle data
1394 * D3DMatHandle: Handle to destroy
1398 * DDERR_INVALIDPARAMS if D3DMatHandle is invalid
1400 *****************************************************************************/
1401 static HRESULT WINAPI
1402 IDirect3DDeviceImpl_1_DeleteMatrix(IDirect3DDevice *iface,
1403 D3DMATRIXHANDLE D3DMatHandle)
1405 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1406 TRACE("(%p)->(%08x)\n", This, (DWORD) D3DMatHandle);
1409 return DDERR_INVALIDPARAMS;
1411 if(D3DMatHandle > This->numHandles)
1413 ERR("Handle %d out of range\n", D3DMatHandle);
1414 return DDERR_INVALIDPARAMS;
1416 else if(This->Handles[D3DMatHandle - 1].type != DDrawHandle_Matrix)
1418 ERR("Handle %d is not a matrix handle\n", D3DMatHandle);
1419 return DDERR_INVALIDPARAMS;
1422 HeapFree(GetProcessHeap(), 0, This->Handles[D3DMatHandle - 1].ptr);
1423 This->Handles[D3DMatHandle - 1].ptr = NULL;
1424 This->Handles[D3DMatHandle - 1].type = DDrawHandle_Unknown;
1429 /*****************************************************************************
1430 * IDirect3DDevice7::BeginScene
1432 * This method must be called before any rendering is performed.
1433 * IDirect3DDevice::EndScene has to be called after the scene is complete
1435 * Version 1, 2, 3 and 7
1438 * D3D_OK on success, for details see IWineD3DDevice::BeginScene
1439 * D3DERR_SCENE_IN_SCENE if WineD3D returns an error(Only in case of an already
1442 *****************************************************************************/
1443 static HRESULT WINAPI
1444 IDirect3DDeviceImpl_7_BeginScene(IDirect3DDevice7 *iface)
1446 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1448 TRACE("(%p): Relay\n", This);
1450 hr = IWineD3DDevice_BeginScene(This->wineD3DDevice);
1451 if(hr == WINED3D_OK) return D3D_OK;
1452 else return D3DERR_SCENE_IN_SCENE; /* TODO: Other possible causes of failure */
1455 static HRESULT WINAPI
1456 Thunk_IDirect3DDeviceImpl_3_BeginScene(IDirect3DDevice3 *iface)
1458 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1459 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1460 return IDirect3DDevice7_BeginScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1463 static HRESULT WINAPI
1464 Thunk_IDirect3DDeviceImpl_2_BeginScene(IDirect3DDevice2 *iface)
1466 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1467 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1468 return IDirect3DDevice7_BeginScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1471 static HRESULT WINAPI
1472 Thunk_IDirect3DDeviceImpl_1_BeginScene(IDirect3DDevice *iface)
1474 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1475 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1476 return IDirect3DDevice7_BeginScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1479 /*****************************************************************************
1480 * IDirect3DDevice7::EndScene
1482 * Ends a scene that has been begun with IDirect3DDevice7::BeginScene.
1483 * This method must be called after rendering is finished.
1485 * Version 1, 2, 3 and 7
1488 * D3D_OK on success, for details see IWineD3DDevice::EndScene
1489 * D3DERR_SCENE_NOT_IN_SCENE is returned if WineD3D returns an error. It does
1490 * that only if the scene was already ended.
1492 *****************************************************************************/
1493 static HRESULT WINAPI
1494 IDirect3DDeviceImpl_7_EndScene(IDirect3DDevice7 *iface)
1496 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1498 TRACE("(%p): Relay\n", This);
1500 hr = IWineD3DDevice_EndScene(This->wineD3DDevice);
1501 if(hr == WINED3D_OK) return D3D_OK;
1502 else return D3DERR_SCENE_NOT_IN_SCENE;
1505 static HRESULT WINAPI
1506 Thunk_IDirect3DDeviceImpl_3_EndScene(IDirect3DDevice3 *iface)
1508 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1509 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1510 return IDirect3DDevice7_EndScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1513 static HRESULT WINAPI
1514 Thunk_IDirect3DDeviceImpl_2_EndScene(IDirect3DDevice2 *iface)
1516 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1517 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1518 return IDirect3DDevice7_EndScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1521 static HRESULT WINAPI
1522 Thunk_IDirect3DDeviceImpl_1_EndScene(IDirect3DDevice *iface)
1524 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1525 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DDevice7 interface.\n", This);
1526 return IDirect3DDevice7_EndScene(ICOM_INTERFACE(This, IDirect3DDevice7));
1529 /*****************************************************************************
1530 * IDirect3DDevice7::GetDirect3D
1532 * Returns the IDirect3D(= interface to the DirectDraw object) used to create
1536 * Direct3D7: Address to store the interface pointer at
1540 * DDERR_INVALIDPARAMS if Direct3D7 == NULL
1542 *****************************************************************************/
1543 static HRESULT WINAPI
1544 IDirect3DDeviceImpl_7_GetDirect3D(IDirect3DDevice7 *iface,
1545 IDirect3D7 **Direct3D7)
1547 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1548 TRACE("(%p)->(%p)\n", This, Direct3D7);
1551 return DDERR_INVALIDPARAMS;
1553 *Direct3D7 = ICOM_INTERFACE(This->ddraw, IDirect3D7);
1554 IDirect3D7_AddRef(*Direct3D7);
1556 TRACE(" returning interface %p\n", *Direct3D7);
1560 static HRESULT WINAPI
1561 Thunk_IDirect3DDeviceImpl_3_GetDirect3D(IDirect3DDevice3 *iface,
1562 IDirect3D3 **Direct3D3)
1564 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1566 IDirect3D7 *ret_ptr;
1568 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, Direct3D3);
1569 ret = IDirect3DDevice7_GetDirect3D(ICOM_INTERFACE(This, IDirect3DDevice7),
1573 *Direct3D3 = COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D7, IDirect3D3, ret_ptr);
1574 TRACE(" returning interface %p\n", *Direct3D3);
1578 static HRESULT WINAPI
1579 Thunk_IDirect3DDeviceImpl_2_GetDirect3D(IDirect3DDevice2 *iface,
1580 IDirect3D2 **Direct3D2)
1582 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1584 IDirect3D7 *ret_ptr;
1586 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, Direct3D2);
1587 ret = IDirect3DDevice7_GetDirect3D(ICOM_INTERFACE(This, IDirect3DDevice7),
1591 *Direct3D2 = COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D7, IDirect3D2, ret_ptr);
1592 TRACE(" returning interface %p\n", *Direct3D2);
1596 static HRESULT WINAPI
1597 Thunk_IDirect3DDeviceImpl_1_GetDirect3D(IDirect3DDevice *iface,
1598 IDirect3D **Direct3D)
1600 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice, iface);
1602 IDirect3D7 *ret_ptr;
1604 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, Direct3D);
1605 ret = IDirect3DDevice7_GetDirect3D(ICOM_INTERFACE(This, IDirect3DDevice7),
1609 *Direct3D = COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D7, IDirect3D, ret_ptr);
1610 TRACE(" returning interface %p\n", *Direct3D);
1614 /*****************************************************************************
1615 * IDirect3DDevice3::SetCurrentViewport
1617 * Sets a Direct3DViewport as the current viewport.
1618 * For the thunks note that all viewport interface versions are equal
1621 * Direct3DViewport3: The viewport to set
1627 * (Is a NULL viewport valid?)
1629 *****************************************************************************/
1630 static HRESULT WINAPI
1631 IDirect3DDeviceImpl_3_SetCurrentViewport(IDirect3DDevice3 *iface,
1632 IDirect3DViewport3 *Direct3DViewport3)
1634 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1635 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport3);
1636 TRACE("(%p)->(%p)\n", This, Direct3DViewport3);
1638 /* Do nothing if the specified viewport is the same as the current one */
1639 if (This->current_viewport == vp )
1642 /* Should check if the viewport was added or not */
1644 /* Release previous viewport and AddRef the new one */
1645 if (This->current_viewport)
1647 TRACE("ViewportImpl is at %p, interface is at %p\n", This->current_viewport, ICOM_INTERFACE(This->current_viewport, IDirect3DViewport3));
1648 IDirect3DViewport3_Release( ICOM_INTERFACE(This->current_viewport, IDirect3DViewport3) );
1650 IDirect3DViewport3_AddRef(Direct3DViewport3);
1652 /* Set this viewport as the current viewport */
1653 This->current_viewport = vp;
1655 /* Activate this viewport */
1656 This->current_viewport->active_device = This;
1657 This->current_viewport->activate(This->current_viewport);
1662 static HRESULT WINAPI
1663 Thunk_IDirect3DDeviceImpl_2_SetCurrentViewport(IDirect3DDevice2 *iface,
1664 IDirect3DViewport2 *Direct3DViewport2)
1666 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1667 IDirect3DViewportImpl *vp = ICOM_OBJECT(IDirect3DViewportImpl, IDirect3DViewport3, Direct3DViewport2);
1668 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, vp);
1669 return IDirect3DDevice3_SetCurrentViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
1670 ICOM_INTERFACE(vp, IDirect3DViewport3));
1673 /*****************************************************************************
1674 * IDirect3DDevice3::GetCurrentViewport
1676 * Returns the currently active viewport.
1681 * Direct3DViewport3: Address to return the interface pointer at
1685 * DDERR_INVALIDPARAMS if Direct3DViewport == NULL
1687 *****************************************************************************/
1688 static HRESULT WINAPI
1689 IDirect3DDeviceImpl_3_GetCurrentViewport(IDirect3DDevice3 *iface,
1690 IDirect3DViewport3 **Direct3DViewport3)
1692 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1693 TRACE("(%p)->(%p)\n", This, Direct3DViewport3);
1695 if(!Direct3DViewport3)
1696 return DDERR_INVALIDPARAMS;
1698 *Direct3DViewport3 = ICOM_INTERFACE(This->current_viewport, IDirect3DViewport3);
1700 /* AddRef the returned viewport */
1701 if(*Direct3DViewport3) IDirect3DViewport3_AddRef(*Direct3DViewport3);
1703 TRACE(" returning interface %p\n", *Direct3DViewport3);
1708 static HRESULT WINAPI
1709 Thunk_IDirect3DDeviceImpl_2_GetCurrentViewport(IDirect3DDevice2 *iface,
1710 IDirect3DViewport2 **Direct3DViewport2)
1712 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1714 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, Direct3DViewport2);
1715 hr = IDirect3DDevice3_GetCurrentViewport(ICOM_INTERFACE(This, IDirect3DDevice3),
1716 (IDirect3DViewport3 **) Direct3DViewport2);
1717 if(hr != D3D_OK) return hr;
1718 *Direct3DViewport2 = (IDirect3DViewport2 *) COM_INTERFACE_CAST(IDirect3DViewportImpl, IDirect3DViewport3, IDirect3DViewport3, *Direct3DViewport2);
1722 /*****************************************************************************
1723 * IDirect3DDevice7::SetRenderTarget
1725 * Sets the render target for the Direct3DDevice.
1726 * For the thunks note that IDirectDrawSurface7 == IDirectDrawSurface4 and
1727 * IDirectDrawSurface3 == IDirectDrawSurface
1729 * Version 2, 3 and 7
1732 * NewTarget: Pointer to an IDirectDrawSurface7 interface to set as the new
1737 * D3D_OK on success, for details see IWineD3DDevice::SetRenderTarget
1739 *****************************************************************************/
1740 static HRESULT WINAPI
1741 IDirect3DDeviceImpl_7_SetRenderTarget(IDirect3DDevice7 *iface,
1742 IDirectDrawSurface7 *NewTarget,
1745 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1746 IDirectDrawSurfaceImpl *Target = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, NewTarget);
1747 TRACE("(%p)->(%p,%08x): Relay\n", This, NewTarget, Flags);
1749 /* Flags: Not used */
1751 return IWineD3DDevice_SetRenderTarget(This->wineD3DDevice,
1753 Target ? Target->WineD3DSurface : NULL);
1756 static HRESULT WINAPI
1757 Thunk_IDirect3DDeviceImpl_3_SetRenderTarget(IDirect3DDevice3 *iface,
1758 IDirectDrawSurface4 *NewRenderTarget,
1761 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1762 IDirectDrawSurfaceImpl *Target = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, NewRenderTarget);
1763 TRACE_(ddraw_thunk)("(%p)->(%p,%08x) thunking to IDirect3DDevice7 interface.\n", This, Target, Flags);
1764 return IDirect3DDevice7_SetRenderTarget(ICOM_INTERFACE(This, IDirect3DDevice7),
1765 ICOM_INTERFACE(Target, IDirectDrawSurface7),
1769 static HRESULT WINAPI
1770 Thunk_IDirect3DDeviceImpl_2_SetRenderTarget(IDirect3DDevice2 *iface,
1771 IDirectDrawSurface *NewRenderTarget,
1774 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1775 IDirectDrawSurfaceImpl *Target = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface3, NewRenderTarget);
1776 TRACE_(ddraw_thunk)("(%p)->(%p,%08x) thunking to IDirect3DDevice7 interface.\n", This, Target, Flags);
1777 return IDirect3DDevice7_SetRenderTarget(ICOM_INTERFACE(This, IDirect3DDevice7),
1778 ICOM_INTERFACE(Target, IDirectDrawSurface7),
1782 /*****************************************************************************
1783 * IDirect3DDevice7::GetRenderTarget
1785 * Returns the current render target.
1786 * This is handled locally, because the WineD3D render target's parent
1789 * Version 2, 3 and 7
1792 * RenderTarget: Address to store the surface interface pointer
1796 * DDERR_INVALIDPARAMS if RenderTarget == NULL
1798 *****************************************************************************/
1799 static HRESULT WINAPI
1800 IDirect3DDeviceImpl_7_GetRenderTarget(IDirect3DDevice7 *iface,
1801 IDirectDrawSurface7 **RenderTarget)
1803 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
1804 TRACE("(%p)->(%p): Relay\n", This, RenderTarget);
1807 return DDERR_INVALIDPARAMS;
1809 *RenderTarget = ICOM_INTERFACE(This->target, IDirectDrawSurface7);
1810 IDirectDrawSurface7_AddRef(*RenderTarget);
1815 static HRESULT WINAPI
1816 Thunk_IDirect3DDeviceImpl_3_GetRenderTarget(IDirect3DDevice3 *iface,
1817 IDirectDrawSurface4 **RenderTarget)
1819 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1821 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, RenderTarget);
1822 hr = IDirect3DDevice7_GetRenderTarget(ICOM_INTERFACE(This, IDirect3DDevice7),
1823 (IDirectDrawSurface7 **) RenderTarget);
1824 if(hr != D3D_OK) return hr;
1825 *RenderTarget = (IDirectDrawSurface4 *) COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7, IDirectDrawSurface7, *RenderTarget);
1829 static HRESULT WINAPI
1830 Thunk_IDirect3DDeviceImpl_2_GetRenderTarget(IDirect3DDevice2 *iface,
1831 IDirectDrawSurface **RenderTarget)
1833 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1835 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, RenderTarget);
1836 hr = IDirect3DDevice7_GetRenderTarget(ICOM_INTERFACE(This, IDirect3DDevice7),
1837 (IDirectDrawSurface7 **) RenderTarget);
1838 if(hr != D3D_OK) return hr;
1839 *RenderTarget = (IDirectDrawSurface *) COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7, IDirectDrawSurface3, *RenderTarget);
1843 /*****************************************************************************
1844 * IDirect3DDevice3::Begin
1846 * Begins a description block of vertices. This is similar to glBegin()
1847 * and glEnd(). After a call to IDirect3DDevice3::End, the vertices
1848 * described with IDirect3DDevice::Vertex are drawn.
1853 * PrimitiveType: The type of primitives to draw
1854 * VertexTypeDesc: A flexible vertex format description of the vertices
1855 * Flags: Some flags..
1860 *****************************************************************************/
1861 static HRESULT WINAPI
1862 IDirect3DDeviceImpl_3_Begin(IDirect3DDevice3 *iface,
1863 D3DPRIMITIVETYPE PrimitiveType,
1864 DWORD VertexTypeDesc,
1867 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1868 TRACE("(%p)->(%d,%d,%08x)\n", This, PrimitiveType, VertexTypeDesc, Flags);
1870 This->primitive_type = PrimitiveType;
1871 This->vertex_type = VertexTypeDesc;
1872 This->render_flags = Flags;
1873 This->vertex_size = get_flexible_vertex_size(This->vertex_type);
1874 This->nb_vertices = 0;
1879 static HRESULT WINAPI
1880 Thunk_IDirect3DDeviceImpl_2_Begin(IDirect3DDevice2 *iface,
1881 D3DPRIMITIVETYPE d3dpt,
1882 D3DVERTEXTYPE dwVertexTypeDesc,
1886 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1887 TRACE_(ddraw_thunk)("(%p/%p)->(%08x,%08x,%08x): Thunking to IDirect3DDevice3\n", This, iface, d3dpt, dwVertexTypeDesc, dwFlags);
1889 switch(dwVertexTypeDesc)
1891 case D3DVT_VERTEX: FVF = D3DFVF_VERTEX; break;
1892 case D3DVT_LVERTEX: FVF = D3DFVF_LVERTEX; break;
1893 case D3DVT_TLVERTEX: FVF = D3DFVF_TLVERTEX; break;
1895 ERR("Unexpected vertex type %d\n", dwVertexTypeDesc);
1896 return DDERR_INVALIDPARAMS; /* Should never happen */
1899 return IDirect3DDevice3_Begin(ICOM_INTERFACE(This, IDirect3DDevice3),
1905 /*****************************************************************************
1906 * IDirect3DDevice3::BeginIndexed
1908 * Draws primitives based on vertices in a vertex array which are specified
1914 * PrimitiveType: Primitive type to draw
1915 * VertexType: A FVF description of the vertex format
1916 * Vertices: pointer to an array containing the vertices
1917 * NumVertices: The number of vertices in the vertex array
1918 * Flags: Some flags ...
1921 * D3D_OK, because it's a stub
1923 *****************************************************************************/
1924 static HRESULT WINAPI
1925 IDirect3DDeviceImpl_3_BeginIndexed(IDirect3DDevice3 *iface,
1926 D3DPRIMITIVETYPE PrimitiveType,
1932 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1933 FIXME("(%p)->(%08x,%08x,%p,%08x,%08x): stub!\n", This, PrimitiveType, VertexType, Vertices, NumVertices, Flags);
1938 static HRESULT WINAPI
1939 Thunk_IDirect3DDeviceImpl_2_BeginIndexed(IDirect3DDevice2 *iface,
1940 D3DPRIMITIVETYPE d3dptPrimitiveType,
1941 D3DVERTEXTYPE d3dvtVertexType,
1943 DWORD dwNumVertices,
1947 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
1948 TRACE_(ddraw_thunk)("(%p/%p)->(%08x,%08x,%p,%08x,%08x): Thunking to IDirect3DDevice3\n", This, iface, d3dptPrimitiveType, d3dvtVertexType, lpvVertices, dwNumVertices, dwFlags);
1950 switch(d3dvtVertexType)
1952 case D3DVT_VERTEX: FVF = D3DFVF_VERTEX; break;
1953 case D3DVT_LVERTEX: FVF = D3DFVF_LVERTEX; break;
1954 case D3DVT_TLVERTEX: FVF = D3DFVF_TLVERTEX; break;
1956 ERR("Unexpected vertex type %d\n", d3dvtVertexType);
1957 return DDERR_INVALIDPARAMS; /* Should never happen */
1960 return IDirect3DDevice3_BeginIndexed(ICOM_INTERFACE(This,IDirect3DDevice3),
1968 /*****************************************************************************
1969 * IDirect3DDevice3::Vertex
1971 * Draws a vertex as described by IDirect3DDevice3::Begin. It places all
1972 * drawn vertices in a vertex buffer. If the buffer is too small, its
1973 * size is increased.
1978 * Vertex: Pointer to the vertex
1981 * D3D_OK, on success
1982 * DDERR_INVALIDPARAMS if Vertex is NULL
1984 *****************************************************************************/
1985 static HRESULT WINAPI
1986 IDirect3DDeviceImpl_3_Vertex(IDirect3DDevice3 *iface,
1989 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
1990 TRACE("(%p)->(%p)\n", This, Vertex);
1993 return DDERR_INVALIDPARAMS;
1995 if ((This->nb_vertices+1)*This->vertex_size > This->buffer_size)
1998 This->buffer_size = This->buffer_size ? This->buffer_size * 2 : This->vertex_size * 3;
1999 old_buffer = This->vertex_buffer;
2000 This->vertex_buffer = HeapAlloc(GetProcessHeap(), 0, This->buffer_size);
2003 CopyMemory(This->vertex_buffer, old_buffer, This->nb_vertices * This->vertex_size);
2004 HeapFree(GetProcessHeap(), 0, old_buffer);
2008 CopyMemory(This->vertex_buffer + This->nb_vertices++ * This->vertex_size, Vertex, This->vertex_size);
2013 static HRESULT WINAPI
2014 Thunk_IDirect3DDeviceImpl_2_Vertex(IDirect3DDevice2 *iface,
2017 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2018 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice3 interface.\n", This, lpVertexType);
2019 return IDirect3DDevice3_Vertex(ICOM_INTERFACE(This, IDirect3DDevice3),
2023 /*****************************************************************************
2024 * IDirect3DDevice3::Index
2026 * Specifies an index to a vertex to be drawn. The vertex array has to
2027 * be specified with BeginIndexed first.
2030 * VertexIndex: The index of the vertex to draw
2033 * D3D_OK because it's a stub
2035 *****************************************************************************/
2036 static HRESULT WINAPI
2037 IDirect3DDeviceImpl_3_Index(IDirect3DDevice3 *iface,
2040 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2041 FIXME("(%p)->(%04x): stub!\n", This, VertexIndex);
2045 static HRESULT WINAPI
2046 Thunk_IDirect3DDeviceImpl_2_Index(IDirect3DDevice2 *iface,
2049 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2050 TRACE_(ddraw_thunk)("(%p)->(%04x) thunking to IDirect3DDevice3 interface.\n", This, wVertexIndex);
2051 return IDirect3DDevice3_Index(ICOM_INTERFACE(This, IDirect3DDevice3),
2055 /*****************************************************************************
2056 * IDirect3DDevice3::End
2058 * Ends a draw begun with IDirect3DDevice3::Begin or
2059 * IDirect3DDevice::BeginIndexed. The vertices specified with
2060 * IDirect3DDevice::Vertex or IDirect3DDevice::Index are drawn using
2061 * the IDirect3DDevice7::DrawPrimitive method. So far only
2062 * non-indexed mode is supported
2067 * Flags: Some flags, as usual. Don't know which are defined
2070 * The return value of IDirect3DDevice7::DrawPrimitive
2072 *****************************************************************************/
2073 static HRESULT WINAPI
2074 IDirect3DDeviceImpl_3_End(IDirect3DDevice3 *iface,
2077 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2078 TRACE("(%p)->(%08x)\n", This, Flags);
2080 return IDirect3DDevice7_DrawPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
2081 This->primitive_type, This->vertex_type,
2082 This->vertex_buffer, This->nb_vertices,
2083 This->render_flags);
2086 static HRESULT WINAPI
2087 Thunk_IDirect3DDeviceImpl_2_End(IDirect3DDevice2 *iface,
2090 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2091 TRACE_(ddraw_thunk)("(%p)->(%08x) thunking to IDirect3DDevice3 interface.\n", This, dwFlags);
2092 return IDirect3DDevice3_End(ICOM_INTERFACE(This, IDirect3DDevice3),
2096 /*****************************************************************************
2097 * IDirect3DDevice7::GetRenderState
2099 * Returns the value of a render state. The possible render states are
2100 * defined in include/d3dtypes.h
2102 * Version 2, 3 and 7
2105 * RenderStateType: Render state to return the current setting of
2106 * Value: Address to store the value at
2109 * D3D_OK on success, for details see IWineD3DDevice::GetRenderState
2110 * DDERR_INVALIDPARAMS if Value == NULL
2112 *****************************************************************************/
2113 static HRESULT WINAPI
2114 IDirect3DDeviceImpl_7_GetRenderState(IDirect3DDevice7 *iface,
2115 D3DRENDERSTATETYPE RenderStateType,
2118 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2120 TRACE("(%p)->(%08x,%p): Relay\n", This, RenderStateType, Value);
2123 return DDERR_INVALIDPARAMS;
2125 switch(RenderStateType)
2127 case D3DRENDERSTATE_TEXTUREHANDLE:
2129 /* This state is wrapped to SetTexture in SetRenderState, so
2130 * it has to be wrapped to GetTexture here
2132 IWineD3DBaseTexture *tex = NULL;
2135 hr = IWineD3DDevice_GetTexture(This->wineD3DDevice,
2139 if(hr == WINED3D_OK && tex)
2141 IDirectDrawSurface7 *parent = NULL;
2142 hr = IWineD3DBaseTexture_GetParent(tex,
2143 (IUnknown **) &parent);
2146 /* The parent of the texture is the IDirectDrawSurface7 interface
2147 * of the ddraw surface
2149 IDirectDrawSurfaceImpl *texImpl = ICOM_OBJECT(IDirectDrawSurfaceImpl,
2150 IDirectDrawSurface7,
2152 *Value = texImpl->Handle;
2153 IDirectDrawSurface7_Release(parent);
2155 IWineD3DBaseTexture_Release(tex);
2160 case D3DRENDERSTATE_TEXTUREMAG:
2162 WINED3DTEXTUREFILTERTYPE tex_mag;
2164 hr = IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
2165 0, WINED3DSAMP_MAGFILTER,
2170 case WINED3DTEXF_POINT:
2171 *Value = D3DFILTER_NEAREST;
2173 case WINED3DTEXF_LINEAR:
2174 *Value = D3DFILTER_LINEAR;
2177 ERR("Unhandled texture mag %d !\n",tex_mag);
2183 case D3DRENDERSTATE_TEXTUREMIN:
2185 WINED3DTEXTUREFILTERTYPE tex_min;
2187 hr = IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
2188 0, WINED3DSAMP_MINFILTER,
2193 case WINED3DTEXF_POINT:
2194 *Value = D3DFILTER_NEAREST;
2196 case WINED3DTEXF_LINEAR:
2197 *Value = D3DFILTER_LINEAR;
2200 ERR("Unhandled texture mag %d !\n",tex_min);
2206 case D3DRENDERSTATE_TEXTUREADDRESS:
2207 case D3DRENDERSTATE_TEXTUREADDRESSU:
2208 return IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
2209 0, WINED3DSAMP_ADDRESSU,
2211 case D3DRENDERSTATE_TEXTUREADDRESSV:
2212 return IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
2213 0, WINED3DSAMP_ADDRESSV,
2217 /* FIXME: Unhandled: D3DRENDERSTATE_STIPPLEPATTERN00 - 31 */
2218 return IWineD3DDevice_GetRenderState(This->wineD3DDevice,
2224 static HRESULT WINAPI
2225 Thunk_IDirect3DDeviceImpl_3_GetRenderState(IDirect3DDevice3 *iface,
2226 D3DRENDERSTATETYPE dwRenderStateType,
2227 DWORD *lpdwRenderState)
2229 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2230 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, dwRenderStateType, lpdwRenderState);
2231 return IDirect3DDevice7_GetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2236 static HRESULT WINAPI
2237 Thunk_IDirect3DDeviceImpl_2_GetRenderState(IDirect3DDevice2 *iface,
2238 D3DRENDERSTATETYPE dwRenderStateType,
2239 DWORD *lpdwRenderState)
2241 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2242 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, dwRenderStateType, lpdwRenderState);
2243 return IDirect3DDevice7_GetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2248 /*****************************************************************************
2249 * IDirect3DDevice7::SetRenderState
2251 * Sets a render state. The possible render states are defined in
2252 * include/d3dtypes.h
2254 * Version 2, 3 and 7
2257 * RenderStateType: State to set
2258 * Value: Value to assign to that state
2261 * D3D_OK on success,
2262 * for details see IWineD3DDevice::SetRenderState
2264 *****************************************************************************/
2265 static HRESULT WINAPI
2266 IDirect3DDeviceImpl_7_SetRenderState(IDirect3DDevice7 *iface,
2267 D3DRENDERSTATETYPE RenderStateType,
2270 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2271 TRACE("(%p)->(%08x,%d): Relay\n", This, RenderStateType, Value);
2273 /* Some render states need special care */
2274 switch(RenderStateType)
2276 case D3DRENDERSTATE_TEXTUREHANDLE:
2280 return IWineD3DDevice_SetTexture(This->wineD3DDevice,
2285 if(Value > This->numHandles)
2287 FIXME("Specified handle %d out of range\n", Value);
2288 return DDERR_INVALIDPARAMS;
2290 if(This->Handles[Value - 1].type != DDrawHandle_Texture)
2292 FIXME("Handle %d isn't a texture handle\n", Value);
2293 return DDERR_INVALIDPARAMS;
2297 IDirectDrawSurfaceImpl *surf = (IDirectDrawSurfaceImpl *) This->Handles[Value - 1].ptr;
2298 return IWineD3DDevice_SetTexture(This->wineD3DDevice,
2300 (IWineD3DBaseTexture *) surf->wineD3DTexture);
2304 case D3DRENDERSTATE_TEXTUREMAG:
2306 WINED3DTEXTUREFILTERTYPE tex_mag = WINED3DTEXF_NONE;
2308 switch ((D3DTEXTUREFILTER) Value)
2310 case D3DFILTER_NEAREST:
2311 case D3DFILTER_LINEARMIPNEAREST:
2312 tex_mag = WINED3DTEXF_POINT;
2314 case D3DFILTER_LINEAR:
2315 case D3DFILTER_LINEARMIPLINEAR:
2316 tex_mag = WINED3DTEXF_LINEAR;
2319 ERR("Unhandled texture mag %d !\n",Value);
2322 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
2323 0, WINED3DSAMP_MAGFILTER,
2327 case D3DRENDERSTATE_TEXTUREMIN:
2329 WINED3DTEXTUREFILTERTYPE tex_min = WINED3DTEXF_NONE;
2330 WINED3DTEXTUREFILTERTYPE tex_mip = WINED3DTEXF_NONE;
2332 switch ((D3DTEXTUREFILTER) Value)
2334 case D3DFILTER_NEAREST:
2335 tex_min = WINED3DTEXF_POINT;
2337 case D3DFILTER_LINEAR:
2338 tex_min = WINED3DTEXF_LINEAR;
2340 case D3DFILTER_MIPNEAREST:
2341 tex_min = WINED3DTEXF_NONE;
2342 tex_mip = WINED3DTEXF_POINT;
2344 case D3DFILTER_MIPLINEAR:
2345 tex_min = WINED3DTEXF_NONE;
2346 tex_mip = WINED3DTEXF_LINEAR;
2348 case D3DFILTER_LINEARMIPNEAREST:
2349 tex_min = WINED3DTEXF_POINT;
2350 tex_mip = WINED3DTEXF_LINEAR;
2352 case D3DFILTER_LINEARMIPLINEAR:
2353 tex_min = WINED3DTEXF_LINEAR;
2354 tex_mip = WINED3DTEXF_LINEAR;
2358 ERR("Unhandled texture min %d !\n",Value);
2361 IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
2362 0, WINED3DSAMP_MIPFILTER,
2364 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
2365 0, WINED3DSAMP_MINFILTER,
2369 case D3DRENDERSTATE_TEXTUREADDRESS:
2370 IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
2371 0, WINED3DSAMP_ADDRESSV,
2374 case D3DRENDERSTATE_TEXTUREADDRESSU:
2375 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
2376 0, WINED3DSAMP_ADDRESSU,
2378 case D3DRENDERSTATE_TEXTUREADDRESSV:
2379 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
2380 0, WINED3DSAMP_ADDRESSV,
2383 case D3DRENDERSTATE_TEXTUREMAPBLEND:
2385 /* Old texture combine setup style, superseded by texture stage states
2386 * in D3D7. It is safe for us to wrap it to texture stage states.
2388 switch ( (D3DTEXTUREBLEND) Value)
2390 case D3DTBLEND_MODULATE:
2391 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLORARG1, WINED3DTA_TEXTURE);
2392 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAARG1, WINED3DTA_TEXTURE);
2393 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLORARG2, WINED3DTA_CURRENT);
2394 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLOROP, WINED3DTOP_MODULATE);
2395 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAOP, WINED3DTOP_SELECTARG1);
2398 case D3DTBLEND_MODULATEALPHA:
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_ALPHAARG2, WINED3DTA_CURRENT);
2403 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLOROP, WINED3DTOP_MODULATE);
2404 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAOP, WINED3DTOP_MODULATE);
2407 case D3DTBLEND_DECAL:
2408 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLORARG1, WINED3DTA_TEXTURE);
2409 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAARG1, WINED3DTA_TEXTURE);
2410 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLOROP, WINED3DTOP_SELECTARG1);
2411 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAOP, WINED3DTOP_SELECTARG1);
2414 case D3DTBLEND_DECALALPHA:
2415 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLORARG1, WINED3DTA_TEXTURE);
2416 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAARG1, WINED3DTA_TEXTURE);
2417 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAARG2, WINED3DTA_CURRENT);
2418 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_COLOROP, WINED3DTOP_SELECTARG1);
2419 IWineD3DDevice_SetTextureStageState(This->wineD3DDevice, 0, WINED3DTSS_ALPHAOP, WINED3DTOP_MODULATE);
2423 ERR("Unhandled texture environment %d !\n",Value);
2431 /* FIXME: Unhandled: D3DRENDERSTATE_STIPPLEPATTERN00 - 31 */
2433 return IWineD3DDevice_SetRenderState(This->wineD3DDevice,
2439 static HRESULT WINAPI
2440 Thunk_IDirect3DDeviceImpl_3_SetRenderState(IDirect3DDevice3 *iface,
2441 D3DRENDERSTATETYPE RenderStateType,
2444 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2445 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, RenderStateType, Value);
2446 return IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2451 static HRESULT WINAPI
2452 Thunk_IDirect3DDeviceImpl_2_SetRenderState(IDirect3DDevice2 *iface,
2453 D3DRENDERSTATETYPE RenderStateType,
2456 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2457 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, RenderStateType, Value);
2458 return IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2463 /*****************************************************************************
2464 * Direct3DDevice3::SetLightState
2466 * Sets a light state for Direct3DDevice3 and Direct3DDevice2. The
2467 * light states are forwarded to Direct3DDevice7 render states
2472 * LightStateType: The light state to change
2473 * Value: The value to assign to that light state
2477 * DDERR_INVALIDPARAMS if the parameters were incorrect
2478 * Also check IDirect3DDevice7::SetRenderState
2480 *****************************************************************************/
2481 static HRESULT WINAPI
2482 IDirect3DDeviceImpl_3_SetLightState(IDirect3DDevice3 *iface,
2483 D3DLIGHTSTATETYPE LightStateType,
2486 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2488 TRACE("(%p)->(%08x,%08x)\n", This, LightStateType, Value);
2490 if (!LightStateType && (LightStateType > D3DLIGHTSTATE_COLORVERTEX))
2492 TRACE("Unexpected Light State Type\n");
2493 return DDERR_INVALIDPARAMS;
2496 if (LightStateType == D3DLIGHTSTATE_MATERIAL /* 1 */)
2498 IDirect3DMaterialImpl *mat;
2500 if(Value == 0) mat = NULL;
2501 else if(Value > This->numHandles)
2503 ERR("Material handle out of range(%d)\n", Value);
2504 return DDERR_INVALIDPARAMS;
2506 else if(This->Handles[Value - 1].type != DDrawHandle_Material)
2508 ERR("Invalid handle %d\n", Value);
2509 return DDERR_INVALIDPARAMS;
2513 mat = (IDirect3DMaterialImpl *) This->Handles[Value - 1].ptr;
2518 TRACE(" activating material %p.\n", mat);
2523 FIXME(" D3DLIGHTSTATE_MATERIAL called with NULL material !!!\n");
2525 This->material = Value;
2527 else if (LightStateType == D3DLIGHTSTATE_COLORMODEL /* 3 */)
2532 ERR("DDCOLOR_MONO should not happen!\n");
2535 /* We are already in this mode */
2536 TRACE("Setting color model to RGB (no-op).\n");
2539 ERR("Unknown color model!\n");
2540 return DDERR_INVALIDPARAMS;
2545 D3DRENDERSTATETYPE rs;
2546 switch (LightStateType)
2548 case D3DLIGHTSTATE_AMBIENT: /* 2 */
2549 rs = D3DRENDERSTATE_AMBIENT;
2551 case D3DLIGHTSTATE_FOGMODE: /* 4 */
2552 rs = D3DRENDERSTATE_FOGVERTEXMODE;
2554 case D3DLIGHTSTATE_FOGSTART: /* 5 */
2555 rs = D3DRENDERSTATE_FOGSTART;
2557 case D3DLIGHTSTATE_FOGEND: /* 6 */
2558 rs = D3DRENDERSTATE_FOGEND;
2560 case D3DLIGHTSTATE_FOGDENSITY: /* 7 */
2561 rs = D3DRENDERSTATE_FOGDENSITY;
2563 case D3DLIGHTSTATE_COLORVERTEX: /* 8 */
2564 rs = D3DRENDERSTATE_COLORVERTEX;
2567 ERR("Unknown D3DLIGHTSTATETYPE %d.\n", LightStateType);
2568 return DDERR_INVALIDPARAMS;
2571 return IDirect3DDevice7_SetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2579 static HRESULT WINAPI
2580 Thunk_IDirect3DDeviceImpl_2_SetLightState(IDirect3DDevice2 *iface,
2581 D3DLIGHTSTATETYPE LightStateType,
2584 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2585 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x) thunking to IDirect3DDevice3 interface.\n", This, LightStateType, Value);
2586 return IDirect3DDevice3_SetLightState(ICOM_INTERFACE(This, IDirect3DDevice3),
2591 /*****************************************************************************
2592 * IDirect3DDevice3::GetLightState
2594 * Returns the current setting of a light state. The state is read from
2595 * the Direct3DDevice7 render state.
2600 * LightStateType: The light state to return
2601 * Value: The address to store the light state setting at
2605 * DDDERR_INVALIDPARAMS if the parameters were incorrect
2606 * Also see IDirect3DDevice7::GetRenderState
2608 *****************************************************************************/
2609 static HRESULT WINAPI
2610 IDirect3DDeviceImpl_3_GetLightState(IDirect3DDevice3 *iface,
2611 D3DLIGHTSTATETYPE LightStateType,
2614 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2616 TRACE("(%p)->(%08x,%p)\n", This, LightStateType, Value);
2618 if (!LightStateType && (LightStateType > D3DLIGHTSTATE_COLORVERTEX))
2620 TRACE("Unexpected Light State Type\n");
2621 return DDERR_INVALIDPARAMS;
2625 return DDERR_INVALIDPARAMS;
2627 if (LightStateType == D3DLIGHTSTATE_MATERIAL /* 1 */)
2629 *Value = This->material;
2631 else if (LightStateType == D3DLIGHTSTATE_COLORMODEL /* 3 */)
2633 *Value = D3DCOLOR_RGB;
2637 D3DRENDERSTATETYPE rs;
2638 switch (LightStateType)
2640 case D3DLIGHTSTATE_AMBIENT: /* 2 */
2641 rs = D3DRENDERSTATE_AMBIENT;
2643 case D3DLIGHTSTATE_FOGMODE: /* 4 */
2644 rs = D3DRENDERSTATE_FOGVERTEXMODE;
2646 case D3DLIGHTSTATE_FOGSTART: /* 5 */
2647 rs = D3DRENDERSTATE_FOGSTART;
2649 case D3DLIGHTSTATE_FOGEND: /* 6 */
2650 rs = D3DRENDERSTATE_FOGEND;
2652 case D3DLIGHTSTATE_FOGDENSITY: /* 7 */
2653 rs = D3DRENDERSTATE_FOGDENSITY;
2655 case D3DLIGHTSTATE_COLORVERTEX: /* 8 */
2656 rs = D3DRENDERSTATE_COLORVERTEX;
2659 ERR("Unknown D3DLIGHTSTATETYPE %d.\n", LightStateType);
2660 return DDERR_INVALIDPARAMS;
2663 return IDirect3DDevice7_GetRenderState(ICOM_INTERFACE(This, IDirect3DDevice7),
2671 static HRESULT WINAPI
2672 Thunk_IDirect3DDeviceImpl_2_GetLightState(IDirect3DDevice2 *iface,
2673 D3DLIGHTSTATETYPE LightStateType,
2676 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2677 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice3 interface.\n", This, LightStateType, Value);
2678 return IDirect3DDevice3_GetLightState(ICOM_INTERFACE(This, IDirect3DDevice3),
2683 /*****************************************************************************
2684 * IDirect3DDevice7::SetTransform
2686 * Assigns a D3DMATRIX to a transform type. The transform types are defined
2687 * in include/d3dtypes.h.
2688 * The D3DTRANSFORMSTATE_WORLD (=1) is translated to D3DTS_WORLDMATRIX(0)
2689 * (=255) for wined3d, because the 1 transform state was removed in d3d8
2690 * and WineD3D already understands the replacement D3DTS_WORLDMATRIX(0)
2692 * Version 2, 3 and 7
2695 * TransformStateType: transform state to set
2696 * Matrix: Matrix to assign to the state
2700 * DDERR_INVALIDPARAMS if Matrix == NULL
2701 * For details see IWineD3DDevice::SetTransform
2703 *****************************************************************************/
2704 static HRESULT WINAPI
2705 IDirect3DDeviceImpl_7_SetTransform(IDirect3DDevice7 *iface,
2706 D3DTRANSFORMSTATETYPE TransformStateType,
2709 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2710 D3DTRANSFORMSTATETYPE type = TransformStateType;
2711 TRACE("(%p)->(%08x,%p): Relay\n", This, TransformStateType, Matrix);
2714 return DDERR_INVALIDPARAMS;
2716 /* D3DTRANSFORMSTATE_WORLD doesn't exist in WineD3D,
2717 * use D3DTS_WORLDMATRIX(0) instead
2718 * D3DTS_WORLDMATRIX(index) is (D3DTRANSFORMSTATETYPE)(index + 256)
2720 if(TransformStateType == D3DTRANSFORMSTATE_WORLD)
2721 type = (D3DTRANSFORMSTATETYPE)(0 + 256);
2724 Unhandled: D3DTRANSFORMSTATE_WORLD1
2725 Unhandled: D3DTRANSFORMSTATE_WORLD2
2726 Unhandled: D3DTRANSFORMSTATE_WORLD3
2729 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
2730 return IWineD3DDevice_SetTransform(This->wineD3DDevice,
2732 (WINED3DMATRIX*) Matrix);
2735 static HRESULT WINAPI
2736 Thunk_IDirect3DDeviceImpl_3_SetTransform(IDirect3DDevice3 *iface,
2737 D3DTRANSFORMSTATETYPE TransformStateType,
2738 D3DMATRIX *D3DMatrix)
2740 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2741 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2742 return IDirect3DDevice7_SetTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2747 static HRESULT WINAPI
2748 Thunk_IDirect3DDeviceImpl_2_SetTransform(IDirect3DDevice2 *iface,
2749 D3DTRANSFORMSTATETYPE TransformStateType,
2750 D3DMATRIX *D3DMatrix)
2752 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2753 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2754 return IDirect3DDevice7_SetTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2759 /*****************************************************************************
2760 * IDirect3DDevice7::GetTransform
2762 * Returns the matrix assigned to a transform state
2763 * D3DTRANSFORMSTATE_WORLD is translated to D3DTS_WORLDMATRIX(0), see
2767 * TransformStateType: State to read the matrix from
2768 * Matrix: Address to store the matrix at
2772 * DDERR_INVALIDPARAMS if Matrix == NULL
2773 * For details, see IWineD3DDevice::GetTransform
2775 *****************************************************************************/
2776 static HRESULT WINAPI
2777 IDirect3DDeviceImpl_7_GetTransform(IDirect3DDevice7 *iface,
2778 D3DTRANSFORMSTATETYPE TransformStateType,
2781 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2782 D3DTRANSFORMSTATETYPE type = TransformStateType;
2783 TRACE("(%p)->(%08x,%p): Relay\n", This, TransformStateType, Matrix);
2786 return DDERR_INVALIDPARAMS;
2788 /* D3DTRANSFORMSTATE_WORLD doesn't exist in WineD3D,
2789 * use D3DTS_WORLDMATRIX(0) instead
2790 * D3DTS_WORLDMATRIX(index) is (D3DTRANSFORMSTATETYPE)(index + 256)
2792 if(TransformStateType == D3DTRANSFORMSTATE_WORLD)
2793 type = (D3DTRANSFORMSTATETYPE)(0 + 256);
2796 Unhandled: D3DTRANSFORMSTATE_WORLD1
2797 Unhandled: D3DTRANSFORMSTATE_WORLD2
2798 Unhandled: D3DTRANSFORMSTATE_WORLD3
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 TRACE("(%p)->(%08x,%p): Relay\n", This, TransformStateType, D3DMatrix);
2855 /* D3DTRANSFORMSTATE_WORLD doesn't exist in WineD3D,
2856 * use D3DTS_WORLDMATRIX(0) instead
2857 * D3DTS_WORLDMATRIX(index) is (D3DTRANSFORMSTATETYPE)(index + 256)
2859 if(TransformStateType == D3DTRANSFORMSTATE_WORLD)
2860 TransformStateType = (D3DTRANSFORMSTATETYPE)(0 + 256);
2863 Unhandled: D3DTRANSFORMSTATE_WORLD1
2864 Unhandled: D3DTRANSFORMSTATE_WORLD2
2865 Unhandled: D3DTRANSFORMSTATE_WORLD3
2868 /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
2869 return IWineD3DDevice_MultiplyTransform(This->wineD3DDevice,
2871 (WINED3DMATRIX*) D3DMatrix);
2874 static HRESULT WINAPI
2875 Thunk_IDirect3DDeviceImpl_3_MultiplyTransform(IDirect3DDevice3 *iface,
2876 D3DTRANSFORMSTATETYPE TransformStateType,
2877 D3DMATRIX *D3DMatrix)
2879 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2880 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2881 return IDirect3DDevice7_MultiplyTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2886 static HRESULT WINAPI
2887 Thunk_IDirect3DDeviceImpl_2_MultiplyTransform(IDirect3DDevice2 *iface,
2888 D3DTRANSFORMSTATETYPE TransformStateType,
2889 D3DMATRIX *D3DMatrix)
2891 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
2892 TRACE_(ddraw_thunk)("(%p)->(%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, TransformStateType, D3DMatrix);
2893 return IDirect3DDevice7_MultiplyTransform(ICOM_INTERFACE(This, IDirect3DDevice7),
2898 /*****************************************************************************
2899 * IDirect3DDevice7::DrawPrimitive
2901 * Draws primitives based on vertices in an application-provided pointer
2903 * Version 2, 3 and 7. The IDirect3DDevice2 thunk converts the fixed vertex type into
2904 * an FVF format for D3D7
2907 * PrimitiveType: The type of the primitives to draw
2908 * Vertex type: Flexible vertex format vertex description
2909 * Vertices: Pointer to the vertex array
2910 * VertexCount: The number of vertices to draw
2911 * Flags: As usual a few flags
2915 * DDERR_INVALIDPARAMS if Vertices is NULL
2916 * For details, see IWineD3DDevice::DrawPrimitiveUP
2918 *****************************************************************************/
2919 static HRESULT WINAPI
2920 IDirect3DDeviceImpl_7_DrawPrimitive(IDirect3DDevice7 *iface,
2921 D3DPRIMITIVETYPE PrimitiveType,
2927 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
2928 UINT PrimitiveCount, stride;
2930 TRACE("(%p)->(%08x,%08x,%p,%08x,%08x): Relay!\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Flags);
2933 return DDERR_INVALIDPARAMS;
2935 /* Get the vertex count */
2936 switch(PrimitiveType)
2938 case D3DPT_POINTLIST:
2939 PrimitiveCount = VertexCount;
2942 case D3DPT_LINELIST:
2943 PrimitiveCount = VertexCount / 2;
2946 case D3DPT_LINESTRIP:
2947 PrimitiveCount = VertexCount - 1;
2950 case D3DPT_TRIANGLELIST:
2951 PrimitiveCount = VertexCount / 3;
2954 case D3DPT_TRIANGLESTRIP:
2955 PrimitiveCount = VertexCount - 2;
2958 case D3DPT_TRIANGLEFAN:
2959 PrimitiveCount = VertexCount - 2;
2962 default: return DDERR_INVALIDPARAMS;
2965 /* Get the stride */
2966 stride = get_flexible_vertex_size(VertexType);
2969 hr = IWineD3DDevice_SetVertexDeclaration(This->wineD3DDevice,
2970 IDirectDrawImpl_FindDecl(This->ddraw, VertexType));
2971 if(hr != D3D_OK) return hr;
2973 /* This method translates to the user pointer draw of WineD3D */
2974 return IWineD3DDevice_DrawPrimitiveUP(This->wineD3DDevice,
2981 static HRESULT WINAPI
2982 Thunk_IDirect3DDeviceImpl_3_DrawPrimitive(IDirect3DDevice3 *iface,
2983 D3DPRIMITIVETYPE PrimitiveType,
2989 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
2990 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Flags);
2991 return IDirect3DDevice7_DrawPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
2999 static HRESULT WINAPI
3000 Thunk_IDirect3DDeviceImpl_2_DrawPrimitive(IDirect3DDevice2 *iface,
3001 D3DPRIMITIVETYPE PrimitiveType,
3002 D3DVERTEXTYPE VertexType,
3007 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
3009 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Flags);
3013 case D3DVT_VERTEX: FVF = D3DFVF_VERTEX; break;
3014 case D3DVT_LVERTEX: FVF = D3DFVF_LVERTEX; break;
3015 case D3DVT_TLVERTEX: FVF = D3DFVF_TLVERTEX; break;
3017 ERR("Unexpected vertex type %d\n", VertexType);
3018 return DDERR_INVALIDPARAMS; /* Should never happen */
3021 return IDirect3DDevice7_DrawPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
3029 /*****************************************************************************
3030 * IDirect3DDevice7::DrawIndexedPrimitive
3032 * Draws vertices from an application-provided pointer, based on the index
3033 * numbers in a WORD array.
3035 * Version 2, 3 and 7. The version 7 thunk translates the vertex type into
3036 * an FVF format for D3D7
3039 * PrimitiveType: The primitive type to draw
3040 * VertexType: The FVF vertex description
3041 * Vertices: Pointer to the vertex array
3043 * Indices: Pointer to the index array
3044 * IndexCount: Number of indices = Number of vertices to draw
3045 * Flags: As usual, some flags
3049 * DDERR_INVALIDPARAMS if Vertices or Indices is NULL
3050 * For details, see IWineD3DDevice::DrawIndexedPrimitiveUP
3052 *****************************************************************************/
3053 static HRESULT WINAPI
3054 IDirect3DDeviceImpl_7_DrawIndexedPrimitive(IDirect3DDevice7 *iface,
3055 D3DPRIMITIVETYPE PrimitiveType,
3063 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3064 UINT PrimitiveCount = 0;
3066 TRACE("(%p)->(%08x,%08x,%p,%08x,%p,%08x,%08x): Relay!\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Indices, IndexCount, Flags);
3067 /* Get the primitive number */
3068 switch(PrimitiveType)
3070 case D3DPT_POINTLIST:
3071 PrimitiveCount = IndexCount;
3074 case D3DPT_LINELIST:
3075 PrimitiveCount = IndexCount / 2;
3078 case D3DPT_LINESTRIP:
3079 PrimitiveCount = IndexCount - 1;
3082 case D3DPT_TRIANGLELIST:
3083 PrimitiveCount = IndexCount / 3;
3086 case D3DPT_TRIANGLESTRIP:
3087 PrimitiveCount = IndexCount - 2;
3090 case D3DPT_TRIANGLEFAN:
3091 PrimitiveCount = IndexCount - 2;
3094 default: return DDERR_INVALIDPARAMS;
3097 /* Set the D3DDevice's FVF */
3098 hr = IWineD3DDevice_SetVertexDeclaration(This->wineD3DDevice,
3099 IDirectDrawImpl_FindDecl(This->ddraw, VertexType));
3102 ERR(" (%p) Setting the FVF failed, hr = %x!\n", This, hr);
3106 return IWineD3DDevice_DrawIndexedPrimitiveUP(This->wineD3DDevice,
3108 0 /* MinVertexIndex */,
3109 VertexCount /* UINT NumVertexIndex */,
3114 get_flexible_vertex_size(VertexType));
3117 static HRESULT WINAPI
3118 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitive(IDirect3DDevice3 *iface,
3119 D3DPRIMITIVETYPE PrimitiveType,
3127 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3128 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Indices, IndexCount, Flags);
3129 return IDirect3DDevice7_DrawIndexedPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
3139 static HRESULT WINAPI
3140 Thunk_IDirect3DDeviceImpl_2_DrawIndexedPrimitive(IDirect3DDevice2 *iface,
3141 D3DPRIMITIVETYPE PrimitiveType,
3142 D3DVERTEXTYPE VertexType,
3150 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
3151 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, Vertices, VertexCount, Indices, IndexCount, Flags);
3155 case D3DVT_VERTEX: FVF = D3DFVF_VERTEX; break;
3156 case D3DVT_LVERTEX: FVF = D3DFVF_LVERTEX; break;
3157 case D3DVT_TLVERTEX: FVF = D3DFVF_TLVERTEX; break;
3159 ERR("Unexpected vertex type %d\n", VertexType);
3160 return DDERR_INVALIDPARAMS; /* Should never happen */
3163 return IDirect3DDevice7_DrawIndexedPrimitive(ICOM_INTERFACE(This, IDirect3DDevice7),
3173 /*****************************************************************************
3174 * IDirect3DDevice7::SetClipStatus
3176 * Sets the clip status. This defines things as clipping conditions and
3177 * the extents of the clipping region.
3179 * Version 2, 3 and 7
3185 * D3D_OK because it's a stub
3186 * (DDERR_INVALIDPARAMS if ClipStatus == NULL)
3188 *****************************************************************************/
3189 static HRESULT WINAPI
3190 IDirect3DDeviceImpl_7_SetClipStatus(IDirect3DDevice7 *iface,
3191 D3DCLIPSTATUS *ClipStatus)
3193 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3194 FIXME("(%p)->(%p): Stub!\n", This, ClipStatus);
3196 /* D3DCLIPSTATUS and WINED3DCLIPSTATUS are different. I don't know how to convert them
3197 * Perhaps this needs a new data type and an additional IWineD3DDevice method
3199 /* return IWineD3DDevice_SetClipStatus(This->wineD3DDevice, ClipStatus);*/
3203 static HRESULT WINAPI
3204 Thunk_IDirect3DDeviceImpl_3_SetClipStatus(IDirect3DDevice3 *iface,
3205 D3DCLIPSTATUS *ClipStatus)
3207 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3208 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, ClipStatus);
3209 return IDirect3DDevice7_SetClipStatus(ICOM_INTERFACE(This, IDirect3DDevice7),
3213 static HRESULT WINAPI
3214 Thunk_IDirect3DDeviceImpl_2_SetClipStatus(IDirect3DDevice2 *iface,
3215 D3DCLIPSTATUS *ClipStatus)
3217 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
3218 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, ClipStatus);
3219 return IDirect3DDevice7_SetClipStatus(ICOM_INTERFACE(This, IDirect3DDevice7),
3223 /*****************************************************************************
3224 * IDirect3DDevice7::GetClipStatus
3226 * Returns the clip status
3229 * ClipStatus: Address to write the clip status to
3232 * D3D_OK because it's a stub
3234 *****************************************************************************/
3235 static HRESULT WINAPI
3236 IDirect3DDeviceImpl_7_GetClipStatus(IDirect3DDevice7 *iface,
3237 D3DCLIPSTATUS *ClipStatus)
3239 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3240 FIXME("(%p)->(%p): Stub!\n", This, ClipStatus);
3242 /* D3DCLIPSTATUS and WINED3DCLIPSTATUS are different. I don't know how to convert them */
3243 /* return IWineD3DDevice_GetClipStatus(This->wineD3DDevice, ClipStatus);*/
3247 static HRESULT WINAPI
3248 Thunk_IDirect3DDeviceImpl_3_GetClipStatus(IDirect3DDevice3 *iface,
3249 D3DCLIPSTATUS *ClipStatus)
3251 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3252 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, ClipStatus);
3253 return IDirect3DDevice7_GetClipStatus(ICOM_INTERFACE(This, IDirect3DDevice7),
3257 static HRESULT WINAPI
3258 Thunk_IDirect3DDeviceImpl_2_GetClipStatus(IDirect3DDevice2 *iface,
3259 D3DCLIPSTATUS *ClipStatus)
3261 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice2, iface);
3262 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, ClipStatus);
3263 return IDirect3DDevice7_GetClipStatus(ICOM_INTERFACE(This, IDirect3DDevice7),
3267 /*****************************************************************************
3268 * IDirect3DDevice::DrawPrimitiveStrided
3270 * Draws vertices described by a D3DDRAWPRIMITIVESTRIDEDDATA structure.
3275 * PrimitiveType: The primitive type to draw
3276 * VertexType: The FVF description of the vertices to draw (for the stride??)
3277 * D3DDrawPrimStrideData: A D3DDRAWPRIMITIVESTRIDEDDATA structure describing
3278 * the vertex data locations
3279 * VertexCount: The number of vertices to draw
3283 * D3D_OK, because it's a stub
3284 * (DDERR_INVALIDPARAMS if D3DDrawPrimStrideData is NULL)
3285 * (For details, see IWineD3DDevice::DrawPrimitiveStrided)
3287 *****************************************************************************/
3288 static HRESULT WINAPI
3289 IDirect3DDeviceImpl_7_DrawPrimitiveStrided(IDirect3DDevice7 *iface,
3290 D3DPRIMITIVETYPE PrimitiveType,
3292 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3296 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3297 WineDirect3DVertexStridedData WineD3DStrided;
3299 UINT PrimitiveCount;
3301 TRACE("(%p)->(%08x,%08x,%p,%08x,%08x): stub!\n", This, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Flags);
3303 memset(&WineD3DStrided, 0, sizeof(WineD3DStrided));
3304 /* Get the strided data right. the wined3d structure is a bit bigger
3305 * Watch out: The contents of the strided data are determined by the fvf,
3306 * not by the members set in D3DDrawPrimStrideData. So it's valid
3307 * to have diffuse.lpvData set to 0xdeadbeef if the diffuse flag is
3308 * not set in the fvf.
3310 if(VertexType & D3DFVF_POSITION_MASK)
3312 WineD3DStrided.u.s.position.lpData = D3DDrawPrimStrideData->position.lpvData;
3313 WineD3DStrided.u.s.position.dwStride = D3DDrawPrimStrideData->position.dwStride;
3314 WineD3DStrided.u.s.position.dwType = WINED3DDECLTYPE_FLOAT3;
3315 if (VertexType & D3DFVF_XYZRHW)
3317 WineD3DStrided.u.s.position.dwType = WINED3DDECLTYPE_FLOAT4;
3318 WineD3DStrided.u.s.position_transformed = TRUE;
3320 WineD3DStrided.u.s.position_transformed = FALSE;
3323 if(VertexType & D3DFVF_NORMAL)
3325 WineD3DStrided.u.s.normal.lpData = D3DDrawPrimStrideData->normal.lpvData;
3326 WineD3DStrided.u.s.normal.dwStride = D3DDrawPrimStrideData->normal.dwStride;
3327 WineD3DStrided.u.s.normal.dwType = WINED3DDECLTYPE_FLOAT3;
3330 if(VertexType & D3DFVF_DIFFUSE)
3332 WineD3DStrided.u.s.diffuse.lpData = D3DDrawPrimStrideData->diffuse.lpvData;
3333 WineD3DStrided.u.s.diffuse.dwStride = D3DDrawPrimStrideData->diffuse.dwStride;
3334 WineD3DStrided.u.s.diffuse.dwType = WINED3DDECLTYPE_SHORT4;
3337 if(VertexType & D3DFVF_SPECULAR)
3339 WineD3DStrided.u.s.specular.lpData = D3DDrawPrimStrideData->specular.lpvData;
3340 WineD3DStrided.u.s.specular.dwStride = D3DDrawPrimStrideData->specular.dwStride;
3341 WineD3DStrided.u.s.specular.dwType = WINED3DDECLTYPE_SHORT4;
3344 for( i = 0; i < GET_TEXCOUNT_FROM_FVF(VertexType); i++)
3346 WineD3DStrided.u.s.texCoords[i].lpData = D3DDrawPrimStrideData->textureCoords[i].lpvData;
3347 WineD3DStrided.u.s.texCoords[i].dwStride = D3DDrawPrimStrideData->textureCoords[i].dwStride;
3348 switch(GET_TEXCOORD_SIZE_FROM_FVF(VertexType, i))
3350 case 1: WineD3DStrided.u.s.texCoords[i].dwType = WINED3DDECLTYPE_FLOAT1; break;
3351 case 2: WineD3DStrided.u.s.texCoords[i].dwType = WINED3DDECLTYPE_FLOAT2; break;
3352 case 3: WineD3DStrided.u.s.texCoords[i].dwType = WINED3DDECLTYPE_FLOAT3; break;
3353 case 4: WineD3DStrided.u.s.texCoords[i].dwType = WINED3DDECLTYPE_FLOAT4; break;
3354 default: ERR("Unexpected texture coordinate size %d\n",
3355 GET_TEXCOORD_SIZE_FROM_FVF(VertexType, i));
3359 /* Get the primitive count */
3360 switch(PrimitiveType)
3362 case D3DPT_POINTLIST:
3363 PrimitiveCount = VertexCount;
3366 case D3DPT_LINELIST:
3367 PrimitiveCount = VertexCount / 2;
3370 case D3DPT_LINESTRIP:
3371 PrimitiveCount = VertexCount - 1;
3374 case D3DPT_TRIANGLELIST:
3375 PrimitiveCount = VertexCount / 3;
3378 case D3DPT_TRIANGLESTRIP:
3379 PrimitiveCount = VertexCount - 2;
3382 case D3DPT_TRIANGLEFAN:
3383 PrimitiveCount = VertexCount - 2;
3386 default: return DDERR_INVALIDPARAMS;
3389 /* WineD3D doesn't need the FVF here */
3390 return IWineD3DDevice_DrawPrimitiveStrided(This->wineD3DDevice,
3396 static HRESULT WINAPI
3397 Thunk_IDirect3DDeviceImpl_3_DrawPrimitiveStrided(IDirect3DDevice3 *iface,
3398 D3DPRIMITIVETYPE PrimitiveType,
3400 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3404 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3405 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Flags);
3406 return IDirect3DDevice7_DrawPrimitiveStrided(ICOM_INTERFACE(This, IDirect3DDevice7),
3409 D3DDrawPrimStrideData,
3414 /*****************************************************************************
3415 * IDirect3DDevice7::DrawIndexedPrimitiveStrided
3417 * Draws primitives specified by strided data locations based on indices
3425 * D3D_OK, because it's a stub
3426 * (DDERR_INVALIDPARAMS if D3DDrawPrimStrideData is NULL)
3427 * (DDERR_INVALIDPARAMS if Indices is NULL)
3428 * (For more details, see IWineD3DDevice::DrawIndexedPrimitiveStrided)
3430 *****************************************************************************/
3431 static HRESULT WINAPI
3432 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveStrided(IDirect3DDevice7 *iface,
3433 D3DPRIMITIVETYPE PrimitiveType,
3435 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3441 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3442 FIXME("(%p)->(%08x,%08x,%p,%08x,%p,%08x,%08x): stub!\n", This, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Indices, IndexCount, Flags);
3444 /* I'll implement it as soon as I find a app to test it.
3445 * This needs an additional method in IWineD3DDevice.
3450 static HRESULT WINAPI
3451 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitiveStrided(IDirect3DDevice3 *iface,
3452 D3DPRIMITIVETYPE PrimitiveType,
3454 D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData,
3460 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3461 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p,%08x,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", iface, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Indices, IndexCount, Flags);
3462 return IDirect3DDevice7_DrawIndexedPrimitiveStrided(ICOM_INTERFACE(This, IDirect3DDevice7),
3465 D3DDrawPrimStrideData,
3472 /*****************************************************************************
3473 * IDirect3DDevice7::DrawPrimitiveVB
3475 * Draws primitives from a vertex buffer to the screen.
3480 * PrimitiveType: Type of primitive to be rendered.
3481 * D3DVertexBuf: Source Vertex Buffer
3482 * StartVertex: Index of the first vertex from the buffer to be rendered
3483 * NumVertices: Number of vertices to be rendered
3484 * Flags: Can be D3DDP_WAIT to wait until rendering has finished
3488 * DDERR_INVALIDPARAMS if D3DVertexBuf is NULL
3490 *****************************************************************************/
3491 static HRESULT WINAPI
3492 IDirect3DDeviceImpl_7_DrawPrimitiveVB(IDirect3DDevice7 *iface,
3493 D3DPRIMITIVETYPE PrimitiveType,
3494 IDirect3DVertexBuffer7 *D3DVertexBuf,
3499 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3500 IDirect3DVertexBufferImpl *vb = ICOM_OBJECT(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, D3DVertexBuf);
3501 UINT PrimitiveCount;
3504 WINED3DVERTEXBUFFER_DESC Desc;
3506 TRACE("(%p)->(%08x,%p,%08x,%08x,%08x)\n", This, PrimitiveType, D3DVertexBuf, StartVertex, NumVertices, Flags);
3511 ERR("(%p) No Vertex buffer specified\n", This);
3512 return DDERR_INVALIDPARAMS;
3515 /* Get the primitive count */
3516 switch(PrimitiveType)
3518 case D3DPT_POINTLIST:
3519 PrimitiveCount = NumVertices;
3522 case D3DPT_LINELIST:
3523 PrimitiveCount = NumVertices / 2;
3526 case D3DPT_LINESTRIP:
3527 PrimitiveCount = NumVertices - 1;
3530 case D3DPT_TRIANGLELIST:
3531 PrimitiveCount = NumVertices / 3;
3534 case D3DPT_TRIANGLESTRIP:
3535 PrimitiveCount = NumVertices - 2;
3538 case D3DPT_TRIANGLEFAN:
3539 PrimitiveCount = NumVertices - 2;
3542 default: return DDERR_INVALIDPARAMS;
3545 /* Get the FVF of the vertex buffer, and its stride */
3546 hr = IWineD3DVertexBuffer_GetDesc(vb->wineD3DVertexBuffer,
3550 ERR("(%p) IWineD3DVertexBuffer::GetDesc failed with hr = %08x\n", This, hr);
3553 stride = get_flexible_vertex_size(Desc.FVF);
3555 hr = IWineD3DDevice_SetVertexDeclaration(This->wineD3DDevice,
3556 vb->wineD3DVertexDeclaration);
3559 ERR(" (%p) Setting the FVF failed, hr = %x!\n", This, hr);
3563 /* Set the vertex stream source */
3564 hr = IWineD3DDevice_SetStreamSource(This->wineD3DDevice,
3565 0 /* StreamNumber */,
3566 vb->wineD3DVertexBuffer,
3567 0 /* StartVertex - we pass this to DrawPrimitive */,
3571 ERR("(%p) IDirect3DDevice::SetStreamSource failed with hr = %08x\n", This, hr);
3575 /* Now draw the primitives */
3576 return IWineD3DDevice_DrawPrimitive(This->wineD3DDevice,
3582 static HRESULT WINAPI
3583 Thunk_IDirect3DDeviceImpl_3_DrawPrimitiveVB(IDirect3DDevice3 *iface,
3584 D3DPRIMITIVETYPE PrimitiveType,
3585 IDirect3DVertexBuffer *D3DVertexBuf,
3590 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3591 IDirect3DVertexBufferImpl *vb = ICOM_OBJECT(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, D3DVertexBuf);
3592 TRACE_(ddraw_thunk)("(%p)->(%08x,%p,%08x,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, vb, StartVertex, NumVertices, Flags);
3593 return IDirect3DDevice7_DrawPrimitiveVB(ICOM_INTERFACE(This, IDirect3DDevice7),
3595 ICOM_INTERFACE(vb, IDirect3DVertexBuffer7),
3602 /*****************************************************************************
3603 * IDirect3DDevice7::DrawIndexedPrimitiveVB
3605 * Draws primitives from a vertex buffer to the screen
3608 * PrimitiveType: Type of primitive to be rendered.
3609 * D3DVertexBuf: Source Vertex Buffer
3610 * StartVertex: Index of the first vertex from the buffer to be rendered
3611 * NumVertices: Number of vertices to be rendered
3612 * Indices: Array of DWORDs used to index into the Vertices
3613 * IndexCount: Number of indices in Indices
3614 * Flags: Can be D3DDP_WAIT to wait until rendering has finished
3618 *****************************************************************************/
3619 static HRESULT WINAPI
3620 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface,
3621 D3DPRIMITIVETYPE PrimitiveType,
3622 IDirect3DVertexBuffer7 *D3DVertexBuf,
3629 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3630 IDirect3DVertexBufferImpl *vb = ICOM_OBJECT(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer7, D3DVertexBuf);
3632 UINT PrimitiveCount;
3633 WORD *LockedIndices;
3635 WINED3DVERTEXBUFFER_DESC Desc;
3637 TRACE("(%p)->(%08x,%p,%d,%d,%p,%d,%08x)\n", This, PrimitiveType, vb, StartVertex, NumVertices, Indices, IndexCount, Flags);
3640 * 1) Calculate some things: Vertex count -> Primitive count, stride, ...
3641 * 2) Upload the Indices to the index buffer
3642 * 3) Set the index source
3643 * 4) Set the Vertex Buffer as the Stream source
3644 * 5) Call IWineD3DDevice::DrawIndexedPrimitive
3647 /* Get the primitive count */
3648 switch(PrimitiveType)
3650 case D3DPT_POINTLIST:
3651 PrimitiveCount = IndexCount;
3654 case D3DPT_LINELIST:
3655 PrimitiveCount = IndexCount / 2;
3658 case D3DPT_LINESTRIP:
3659 PrimitiveCount = IndexCount - 1;
3662 case D3DPT_TRIANGLELIST:
3663 PrimitiveCount = IndexCount / 3;
3666 case D3DPT_TRIANGLESTRIP:
3667 PrimitiveCount = IndexCount - 2;
3670 case D3DPT_TRIANGLEFAN:
3671 PrimitiveCount = IndexCount - 2;
3674 default: return DDERR_INVALIDPARAMS;
3677 /* Get the FVF of the vertex buffer, and its stride */
3678 hr = IWineD3DVertexBuffer_GetDesc(vb->wineD3DVertexBuffer,
3682 ERR("(%p) IWineD3DVertexBuffer::GetDesc failed with hr = %08x\n", This, hr);
3685 stride = get_flexible_vertex_size(Desc.FVF);
3686 TRACE("Vertex buffer FVF = %08x, stride=%d\n", Desc.FVF, stride);
3688 hr = IWineD3DDevice_SetVertexDeclaration(This->wineD3DDevice,
3689 vb->wineD3DVertexDeclaration);
3692 ERR(" (%p) Setting the FVF failed, hr = %x!\n", This, hr);
3696 /* copy the index stream into the index buffer.
3697 * A new IWineD3DDevice method could be created
3698 * which takes an user pointer containing the indices
3699 * or a SetData-Method for the index buffer, which
3700 * overrides the index buffer data with our pointer.
3702 hr = IWineD3DIndexBuffer_Lock(This->indexbuffer,
3703 0 /* OffSetToLock */,
3704 IndexCount * sizeof(WORD),
3705 (BYTE **) &LockedIndices,
3707 assert(IndexCount < 0x100000);
3710 ERR("(%p) IWineD3DIndexBuffer::Lock failed with hr = %08x\n", This, hr);
3713 memcpy(LockedIndices, Indices, IndexCount * sizeof(WORD));
3714 hr = IWineD3DIndexBuffer_Unlock(This->indexbuffer);
3717 ERR("(%p) IWineD3DIndexBuffer::Unlock failed with hr = %08x\n", This, hr);
3721 /* Set the index stream */
3722 hr = IWineD3DDevice_SetIndices(This->wineD3DDevice,
3726 /* Set the vertex stream source */
3727 hr = IWineD3DDevice_SetStreamSource(This->wineD3DDevice,
3728 0 /* StreamNumber */,
3729 vb->wineD3DVertexBuffer,
3730 0 /* offset, we pass this to DrawIndexedPrimitive */,
3734 ERR("(%p) IDirect3DDevice::SetStreamSource failed with hr = %08x\n", This, hr);
3739 hr = IWineD3DDevice_DrawIndexedPrimitive(This->wineD3DDevice,
3749 static HRESULT WINAPI
3750 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitiveVB(IDirect3DDevice3 *iface,
3751 D3DPRIMITIVETYPE PrimitiveType,
3752 IDirect3DVertexBuffer *D3DVertexBuf,
3757 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3758 IDirect3DVertexBufferImpl *VB = ICOM_OBJECT(IDirect3DVertexBufferImpl, IDirect3DVertexBuffer, D3DVertexBuf);
3759 TRACE_(ddraw_thunk)("(%p)->(%08x,%p,%p,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, PrimitiveType, VB, Indices, IndexCount, Flags);
3761 return IDirect3DDevice7_DrawIndexedPrimitiveVB(ICOM_INTERFACE(This, IDirect3DDevice7),
3763 ICOM_INTERFACE(VB, IDirect3DVertexBuffer7),
3771 /*****************************************************************************
3772 * IDirect3DDevice7::ComputeSphereVisibility
3774 * Calculates the visibility of spheres in the current viewport. The spheres
3775 * are passed in the Centers and Radii arrays, the results are passed back
3776 * in the ReturnValues array. Return values are either completely visible,
3777 * partially visible or completely invisible.
3778 * The return value consist of a combination of D3DCLIP_* flags, or it's
3779 * 0 if the sphere is completely visible(according to the SDK, not checked)
3781 * Sounds like an overdose of math ;)
3786 * Centers: Array containing the sphere centers
3787 * Radii: Array containing the sphere radii
3788 * NumSpheres: The number of centers and radii in the arrays
3790 * ReturnValues: Array to write the results to
3793 * D3D_OK because it's a stub
3794 * (DDERR_INVALIDPARAMS if Centers, Radii or ReturnValues are NULL)
3795 * (D3DERR_INVALIDMATRIX if the combined world, view and proj matrix
3798 *****************************************************************************/
3799 static HRESULT WINAPI
3800 IDirect3DDeviceImpl_7_ComputeSphereVisibility(IDirect3DDevice7 *iface,
3805 DWORD *ReturnValues)
3807 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3808 FIXME("(%p)->(%p,%p,%08x,%08x,%p): stub!\n", This, Centers, Radii, NumSpheres, Flags, ReturnValues);
3810 /* the DirectX 7 sdk says that the visibility is computed by
3811 * back-transforming the viewing frustum to model space
3812 * using the inverse of the combined world, view and projection
3813 * matrix. If the matrix can't be reversed, D3DERR_INVALIDMATRIX
3816 * Basic implementation idea:
3817 * 1) Check if the center is in the viewing frustum
3818 * 2) Cut the sphere with the planes of the viewing
3821 * ->Center inside the frustum, no intersections:
3823 * ->Center outside the frustum, no intersections:
3825 * ->Some intersections: Partially visible
3827 * Implement this call in WineD3D. Either implement the
3828 * matrix and vector stuff in WineD3D, or use some external
3835 static HRESULT WINAPI
3836 Thunk_IDirect3DDeviceImpl_3_ComputeSphereVisibility(IDirect3DDevice3 *iface,
3841 DWORD *ReturnValues)
3843 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3844 TRACE_(ddraw_thunk)("(%p)->(%p,%p,%08x,%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, Centers, Radii, NumSpheres, Flags, ReturnValues);
3845 return IDirect3DDevice7_ComputeSphereVisibility(ICOM_INTERFACE(This, IDirect3DDevice7),
3853 /*****************************************************************************
3854 * IDirect3DDevice7::GetTexture
3856 * Returns the texture interface handle assigned to a texture stage.
3857 * The returned texture is AddRefed. This is taken from old ddraw,
3858 * not checked in Windows.
3863 * Stage: Texture stage to read the texture from
3864 * Texture: Address to store the interface pointer at
3868 * DDERR_INVALIDPARAMS if Texture is NULL
3869 * For details, see IWineD3DDevice::GetTexture
3871 *****************************************************************************/
3872 static HRESULT WINAPI
3873 IDirect3DDeviceImpl_7_GetTexture(IDirect3DDevice7 *iface,
3875 IDirectDrawSurface7 **Texture)
3877 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3878 IWineD3DBaseTexture *Surf;
3880 TRACE("(%p)->(%d,%p): Relay\n", This, Stage, Texture);
3884 TRACE("Texture == NULL, failing with DDERR_INVALIDPARAMS\n");
3885 return DDERR_INVALIDPARAMS;
3888 hr = IWineD3DDevice_GetTexture(This->wineD3DDevice, Stage, (IWineD3DBaseTexture **) &Surf);
3889 if( (hr != D3D_OK) || (!Surf) )
3895 /* GetParent AddRef()s, which is perfectly OK.
3896 * We have passed the IDirectDrawSurface7 interface to WineD3D, so that's OK too.
3898 return IWineD3DBaseTexture_GetParent(Surf,
3899 (IUnknown **) Texture);
3902 static HRESULT WINAPI
3903 Thunk_IDirect3DDeviceImpl_3_GetTexture(IDirect3DDevice3 *iface,
3905 IDirect3DTexture2 **Texture2)
3907 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3909 IDirectDrawSurface7 *ret_val;
3911 TRACE_(ddraw_thunk)("(%p)->(%d,%p) thunking to IDirect3DDevice7 interface.\n", This, Stage, Texture2);
3912 ret = IDirect3DDevice7_GetTexture(ICOM_INTERFACE(This, IDirect3DDevice7),
3916 *Texture2 = COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirectDrawSurface7, IDirect3DTexture2, ret_val);
3918 TRACE_(ddraw_thunk)(" returning interface %p.\n", *Texture2);
3923 /*****************************************************************************
3924 * IDirect3DDevice7::SetTexture
3926 * Assigns a texture to a texture stage. Is the texture AddRef-ed?
3931 * Stage: The stage to assign the texture to
3932 * Texture: Interface pointer to the texture surface
3936 * For details, see IWineD3DDevice::SetTexture
3938 *****************************************************************************/
3939 static HRESULT WINAPI
3940 IDirect3DDeviceImpl_7_SetTexture(IDirect3DDevice7 *iface,
3942 IDirectDrawSurface7 *Texture)
3944 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3945 IDirectDrawSurfaceImpl *surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Texture);
3946 TRACE("(%p)->(%08x,%p): Relay!\n", This, Stage, surf);
3948 /* Texture may be NULL here */
3949 return IWineD3DDevice_SetTexture(This->wineD3DDevice,
3951 surf ? (IWineD3DBaseTexture * ) surf->wineD3DTexture : NULL);
3954 static HRESULT WINAPI
3955 Thunk_IDirect3DDeviceImpl_3_SetTexture(IDirect3DDevice3 *iface,
3957 IDirect3DTexture2 *Texture2)
3959 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
3960 IDirectDrawSurfaceImpl *tex = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture2, Texture2);
3961 TRACE_(ddraw_thunk)("(%p)->(%d,%p) thunking to IDirect3DDevice7 interface.\n", This, Stage, tex);
3962 return IDirect3DDevice7_SetTexture(ICOM_INTERFACE(This, IDirect3DDevice7),
3964 ICOM_INTERFACE(tex, IDirectDrawSurface7));
3967 /*****************************************************************************
3968 * IDirect3DDevice7::GetTextureStageState
3970 * Retrieves a state from a texture stage.
3975 * Stage: The stage to retrieve the state from
3976 * TexStageStateType: The state type to retrieve
3977 * State: Address to store the state's value at
3981 * DDERR_INVALIDPARAMS if State is NULL
3982 * For details, see IWineD3DDevice::GetTextureStageState
3984 *****************************************************************************/
3985 static HRESULT WINAPI
3986 IDirect3DDeviceImpl_7_GetTextureStageState(IDirect3DDevice7 *iface,
3988 D3DTEXTURESTAGESTATETYPE TexStageStateType,
3991 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
3992 TRACE("(%p)->(%08x,%08x,%p): Relay!\n", This, Stage, TexStageStateType, State);
3995 return DDERR_INVALIDPARAMS;
3997 switch(TexStageStateType)
3999 /* Mipfilter is a sampler state with different values */
4000 case D3DTSS_MIPFILTER:
4003 WINED3DTEXTUREFILTERTYPE value;
4005 hr = IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
4007 WINED3DSAMP_MIPFILTER,
4011 case WINED3DTEXF_NONE: *State = D3DTFP_NONE; break;
4012 case WINED3DTEXF_POINT: *State = D3DTFP_POINT; break;
4013 case WINED3DTEXF_LINEAR: *State = D3DTFP_LINEAR; break;
4015 ERR("Unexpected mipfilter value %d\n", value);
4016 *State = D3DTFP_NONE;
4021 /* Minfilter is a sampler state too, equal values */
4022 case D3DTSS_MINFILTER:
4023 return IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
4025 WINED3DSAMP_MINFILTER,
4027 /* Same for MAGFILTER */
4028 case D3DTSS_MAGFILTER:
4029 return IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
4031 WINED3DSAMP_MAGFILTER,
4034 case D3DTSS_ADDRESS:
4035 case D3DTSS_ADDRESSU:
4036 return IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
4038 WINED3DSAMP_ADDRESSU,
4040 case D3DTSS_ADDRESSV:
4041 return IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
4043 WINED3DSAMP_ADDRESSV,
4046 return IWineD3DDevice_GetTextureStageState(This->wineD3DDevice,
4053 static HRESULT WINAPI
4054 Thunk_IDirect3DDeviceImpl_3_GetTextureStageState(IDirect3DDevice3 *iface,
4056 D3DTEXTURESTAGESTATETYPE TexStageStateType,
4059 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
4060 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%p) thunking to IDirect3DDevice7 interface.\n", This, Stage, TexStageStateType, State);
4061 return IDirect3DDevice7_GetTextureStageState(ICOM_INTERFACE(This, IDirect3DDevice7),
4067 /*****************************************************************************
4068 * IDirect3DDevice7::SetTextureStageState
4070 * Sets a texture stage state. Some stage types need to be handled specially,
4071 * because they do not exist in WineD3D and were moved to another place
4076 * Stage: The stage to modify
4077 * TexStageStateType: The state to change
4078 * State: The new value for the state
4082 * For details, see IWineD3DDevice::SetTextureStageState
4084 *****************************************************************************/
4085 static HRESULT WINAPI
4086 IDirect3DDeviceImpl_7_SetTextureStageState(IDirect3DDevice7 *iface,
4088 D3DTEXTURESTAGESTATETYPE TexStageStateType,
4091 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4092 TRACE("(%p)->(%08x,%08x,%08x): Relay!\n", This, Stage, TexStageStateType, State);
4093 switch(TexStageStateType)
4095 /* Mipfilter is a sampler state with different values */
4096 case D3DTSS_MIPFILTER:
4098 WINED3DTEXTUREFILTERTYPE value;
4101 case D3DTFP_NONE: value = WINED3DTEXF_NONE; break;
4102 case D3DTFP_POINT: value = WINED3DTEXF_POINT; break;
4103 case 0: /* Unchecked */
4104 case D3DTFP_LINEAR: value = WINED3DTEXF_LINEAR; break;
4106 ERR("Unexpected mipfilter value %d\n", State);
4107 value = WINED3DTEXF_NONE;
4109 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
4111 WINED3DSAMP_MIPFILTER,
4115 /* Minfilter is a sampler state too, equal values */
4116 case D3DTSS_MINFILTER:
4117 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
4119 WINED3DSAMP_MINFILTER,
4121 /* Same for MAGFILTER */
4122 case D3DTSS_MAGFILTER:
4123 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
4125 WINED3DSAMP_MAGFILTER,
4128 case D3DTSS_ADDRESS:
4129 IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
4131 WINED3DSAMP_ADDRESSV,
4134 case D3DTSS_ADDRESSU:
4135 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
4137 WINED3DSAMP_ADDRESSU,
4139 case D3DTSS_ADDRESSV:
4140 return IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
4142 WINED3DSAMP_ADDRESSV,
4146 return IWineD3DDevice_SetTextureStageState(This->wineD3DDevice,
4153 static HRESULT WINAPI
4154 Thunk_IDirect3DDeviceImpl_3_SetTextureStageState(IDirect3DDevice3 *iface,
4156 D3DTEXTURESTAGESTATETYPE TexStageStateType,
4159 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
4160 TRACE_(ddraw_thunk)("(%p)->(%08x,%08x,%08x) thunking to IDirect3DDevice7 interface.\n", This, Stage, TexStageStateType, State);
4161 return IDirect3DDevice7_SetTextureStageState(ICOM_INTERFACE(This, IDirect3DDevice7),
4167 /*****************************************************************************
4168 * IDirect3DDevice7::ValidateDevice
4170 * SDK: "Reports the device's ability to render the currently set
4171 * texture-blending operations in a single pass". Whatever that means
4177 * NumPasses: Address to write the number of necessary passes for the
4178 * desired effect to.
4182 * See IWineD3DDevice::ValidateDevice for more details
4184 *****************************************************************************/
4185 static HRESULT WINAPI
4186 IDirect3DDeviceImpl_7_ValidateDevice(IDirect3DDevice7 *iface,
4189 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4190 TRACE("(%p)->(%p): Relay\n", This, NumPasses);
4192 return IWineD3DDevice_ValidateDevice(This->wineD3DDevice, NumPasses);
4195 static HRESULT WINAPI
4196 Thunk_IDirect3DDeviceImpl_3_ValidateDevice(IDirect3DDevice3 *iface,
4199 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice3, iface);
4200 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", This, Passes);
4201 return IDirect3DDevice7_ValidateDevice(ICOM_INTERFACE(This, IDirect3DDevice7),
4205 /*****************************************************************************
4206 * IDirect3DDevice7::Clear
4208 * Fills the render target, the z buffer and the stencil buffer with a
4209 * clear color / value
4214 * Count: Number of rectangles in Rects must be 0 if Rects is NULL
4215 * Rects: Rectangles to clear. If NULL, the whole surface is cleared
4216 * Flags: Some flags, as usual
4217 * Color: Clear color for the render target
4218 * Z: Clear value for the Z buffer
4219 * Stencil: Clear value to store in each stencil buffer entry
4223 * For details, see IWineD3DDevice::Clear
4225 *****************************************************************************/
4226 static HRESULT WINAPI
4227 IDirect3DDeviceImpl_7_Clear(IDirect3DDevice7 *iface,
4235 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4236 TRACE("(%p)->(%08x,%p,%08x,%08x,%f,%08x): Relay\n", This, Count, Rects, Flags, (DWORD) Color, Z, Stencil);
4238 /* Note; D3DRECT is compatible with WINED3DRECT */
4239 return IWineD3DDevice_Clear(This->wineD3DDevice, Count, (WINED3DRECT*) Rects, Flags, Color, Z, Stencil);
4242 /*****************************************************************************
4243 * IDirect3DDevice7::SetViewport
4245 * Sets the current viewport.
4247 * Version 7 only, but IDirect3DViewport uses this call for older
4251 * Data: The new viewport to set
4255 * DDERR_INVALIDPARAMS if Data is NULL
4256 * For more details, see IWineDDDevice::SetViewport
4258 *****************************************************************************/
4259 static HRESULT WINAPI
4260 IDirect3DDeviceImpl_7_SetViewport(IDirect3DDevice7 *iface,
4263 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4264 TRACE("(%p)->(%p) Relay!\n", This, Data);
4267 return DDERR_INVALIDPARAMS;
4269 /* Note: D3DVIEWPORT7 is compatible with WINED3DVIEWPORT */
4270 return IWineD3DDevice_SetViewport(This->wineD3DDevice,
4271 (WINED3DVIEWPORT*) Data);
4274 /*****************************************************************************
4275 * IDirect3DDevice::GetViewport
4277 * Returns the current viewport
4282 * Data: D3D7Viewport structure to write the viewport information to
4286 * DDERR_INVALIDPARAMS if Data is NULL
4287 * For more details, see IWineD3DDevice::GetViewport
4289 *****************************************************************************/
4290 static HRESULT WINAPI
4291 IDirect3DDeviceImpl_7_GetViewport(IDirect3DDevice7 *iface,
4294 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4296 TRACE("(%p)->(%p) Relay!\n", This, Data);
4299 return DDERR_INVALIDPARAMS;
4301 /* Note: D3DVIEWPORT7 is compatible with WINED3DVIEWPORT */
4302 hr = IWineD3DDevice_GetViewport(This->wineD3DDevice,
4303 (WINED3DVIEWPORT*) Data);
4305 return hr_ddraw_from_wined3d(hr);
4308 /*****************************************************************************
4309 * IDirect3DDevice7::SetMaterial
4316 * Mat: The material to set
4320 * DDERR_INVALIDPARAMS if Mat is NULL.
4321 * For more details, see IWineD3DDevice::SetMaterial
4323 *****************************************************************************/
4324 static HRESULT WINAPI
4325 IDirect3DDeviceImpl_7_SetMaterial(IDirect3DDevice7 *iface,
4328 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4330 TRACE("(%p)->(%p): Relay!\n", This, Mat);
4332 /* Note: D3DMATERIAL7 is compatible with WINED3DMATERIAL */
4333 hr = IWineD3DDevice_SetMaterial(This->wineD3DDevice,
4334 (WINED3DMATERIAL*) Mat);
4336 return hr_ddraw_from_wined3d(hr);
4339 /*****************************************************************************
4340 * IDirect3DDevice7::GetMaterial
4342 * Returns the current material
4347 * Mat: D3DMATERIAL7 structure to write the material parameters to
4351 * DDERR_INVALIDPARAMS if Mat is NULL
4352 * For more details, see IWineD3DDevice::GetMaterial
4354 *****************************************************************************/
4355 static HRESULT WINAPI
4356 IDirect3DDeviceImpl_7_GetMaterial(IDirect3DDevice7 *iface,
4359 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4361 TRACE("(%p)->(%p): Relay!\n", This, Mat);
4363 /* Note: D3DMATERIAL7 is compatible with WINED3DMATERIAL */
4364 hr = IWineD3DDevice_GetMaterial(This->wineD3DDevice,
4365 (WINED3DMATERIAL*) Mat);
4367 return hr_ddraw_from_wined3d(hr);
4370 /*****************************************************************************
4371 * IDirect3DDevice7::SetLight
4373 * Assigns a light to a light index, but doesn't activate it yet.
4375 * Version 7, IDirect3DLight uses this method for older versions
4378 * LightIndex: The index of the new light
4379 * Light: A D3DLIGHT7 structure describing the light
4383 * For more details, see IWineD3DDevice::SetLight
4385 *****************************************************************************/
4386 static HRESULT WINAPI
4387 IDirect3DDeviceImpl_7_SetLight(IDirect3DDevice7 *iface,
4391 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4393 TRACE("(%p)->(%08x,%p): Relay!\n", This, LightIndex, Light);
4395 /* Note: D3DLIGHT7 is compatible with WINED3DLIGHT */
4396 hr = IWineD3DDevice_SetLight(This->wineD3DDevice,
4398 (WINED3DLIGHT*) Light);
4400 return hr_ddraw_from_wined3d(hr);
4403 /*****************************************************************************
4404 * IDirect3DDevice7::GetLight
4406 * Returns the light assigned to a light index
4409 * Light: Structure to write the light information to
4413 * DDERR_INVALIDPARAMS if Light is NULL
4414 * For details, see IWineD3DDevice::GetLight
4416 *****************************************************************************/
4417 static HRESULT WINAPI
4418 IDirect3DDeviceImpl_7_GetLight(IDirect3DDevice7 *iface,
4422 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4424 TRACE("(%p)->(%08x,%p): Relay!\n", This, LightIndex, Light);
4426 /* Note: D3DLIGHT7 is compatible with WINED3DLIGHT */
4427 rc = IWineD3DDevice_GetLight(This->wineD3DDevice,
4429 (WINED3DLIGHT*) Light);
4431 /* Translate the result. WineD3D returns other values than D3D7 */
4432 return hr_ddraw_from_wined3d(rc);
4435 /*****************************************************************************
4436 * IDirect3DDevice7::BeginStateBlock
4438 * Begins recording to a stateblock
4444 * For details see IWineD3DDevice::BeginStateBlock
4446 *****************************************************************************/
4447 static HRESULT WINAPI
4448 IDirect3DDeviceImpl_7_BeginStateBlock(IDirect3DDevice7 *iface)
4450 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4452 TRACE("(%p)->(): Relay!\n", This);
4454 hr = IWineD3DDevice_BeginStateBlock(This->wineD3DDevice);
4455 return hr_ddraw_from_wined3d(hr);
4458 /*****************************************************************************
4459 * IDirect3DDevice7::EndStateBlock
4461 * Stops recording to a state block and returns the created stateblock
4467 * BlockHandle: Address to store the stateblock's handle to
4471 * DDERR_INVALIDPARAMS if BlockHandle is NULL
4472 * See IWineD3DDevice::EndStateBlock for more details
4474 *****************************************************************************/
4475 static HRESULT WINAPI
4476 IDirect3DDeviceImpl_7_EndStateBlock(IDirect3DDevice7 *iface,
4479 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4481 TRACE("(%p)->(%p): Relay!\n", This, BlockHandle);
4485 WARN("BlockHandle == NULL, returning DDERR_INVALIDPARAMS\n");
4486 return DDERR_INVALIDPARAMS;
4489 *BlockHandle = IDirect3DDeviceImpl_CreateHandle(This);
4492 ERR("Cannot get a handle number for the stateblock\n");
4493 return DDERR_OUTOFMEMORY;
4495 This->Handles[*BlockHandle - 1].type = DDrawHandle_StateBlock;
4496 hr = IWineD3DDevice_EndStateBlock(This->wineD3DDevice,
4497 (IWineD3DStateBlock **) &This->Handles[*BlockHandle - 1].ptr);
4498 return hr_ddraw_from_wined3d(hr);
4501 /*****************************************************************************
4502 * IDirect3DDevice7::PreLoad
4504 * Allows the app to signal that a texture will be used soon, to allow
4505 * the Direct3DDevice to load it to the video card in the meantime.
4510 * Texture: The texture to preload
4514 * DDERR_INVALIDPARAMS if Texture is NULL
4515 * See IWineD3DSurface::PreLoad for details
4517 *****************************************************************************/
4518 static HRESULT WINAPI
4519 IDirect3DDeviceImpl_7_PreLoad(IDirect3DDevice7 *iface,
4520 IDirectDrawSurface7 *Texture)
4522 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4523 IDirectDrawSurfaceImpl *surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Texture);
4525 TRACE("(%p)->(%p): Relay!\n", This, surf);
4528 return DDERR_INVALIDPARAMS;
4530 IWineD3DSurface_PreLoad(surf->WineD3DSurface);
4534 /*****************************************************************************
4535 * IDirect3DDevice7::ApplyStateBlock
4537 * Activates the state stored in a state block handle.
4540 * BlockHandle: The stateblock handle to activate
4544 * D3DERR_INVALIDSTATEBLOCK if BlockHandle is NULL
4546 *****************************************************************************/
4547 static HRESULT WINAPI
4548 IDirect3DDeviceImpl_7_ApplyStateBlock(IDirect3DDevice7 *iface,
4551 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4553 TRACE("(%p)->(%08x): Relay!\n", This, BlockHandle);
4555 if(!BlockHandle || BlockHandle > This->numHandles)
4557 WARN("Out of range handle %d, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
4558 return D3DERR_INVALIDSTATEBLOCK;
4560 if(This->Handles[BlockHandle - 1].type != DDrawHandle_StateBlock)
4562 WARN("Handle %d is not a stateblock, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
4563 return D3DERR_INVALIDSTATEBLOCK;
4566 hr = IWineD3DStateBlock_Apply((IWineD3DStateBlock *) This->Handles[BlockHandle - 1].ptr);
4567 return hr_ddraw_from_wined3d(hr);
4570 /*****************************************************************************
4571 * IDirect3DDevice7::CaptureStateBlock
4573 * Updates a stateblock's values to the values currently set for the device
4578 * BlockHandle: Stateblock to update
4582 * D3DERR_INVALIDSTATEBLOCK if BlockHandle is NULL
4583 * See IWineD3DDevice::CaptureStateBlock for more details
4585 *****************************************************************************/
4586 static HRESULT WINAPI
4587 IDirect3DDeviceImpl_7_CaptureStateBlock(IDirect3DDevice7 *iface,
4590 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4592 TRACE("(%p)->(%08x): Relay!\n", This, BlockHandle);
4594 if(BlockHandle == 0 || BlockHandle > This->numHandles)
4596 WARN("Out of range handle %d, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
4597 return D3DERR_INVALIDSTATEBLOCK;
4599 if(This->Handles[BlockHandle - 1].type != DDrawHandle_StateBlock)
4601 WARN("Handle %d is not a stateblock, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
4602 return D3DERR_INVALIDSTATEBLOCK;
4605 hr = IWineD3DStateBlock_Capture((IWineD3DStateBlock *) This->Handles[BlockHandle - 1].ptr);
4606 return hr_ddraw_from_wined3d(hr);
4609 /*****************************************************************************
4610 * IDirect3DDevice7::DeleteStateBlock
4612 * Deletes a stateblock handle. This means releasing the WineD3DStateBlock
4617 * BlockHandle: Stateblock handle to delete
4621 * D3DERR_INVALIDSTATEBLOCK if BlockHandle is 0
4623 *****************************************************************************/
4624 static HRESULT WINAPI
4625 IDirect3DDeviceImpl_7_DeleteStateBlock(IDirect3DDevice7 *iface,
4628 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4630 TRACE("(%p)->(%08x): Relay!\n", This, BlockHandle);
4632 if(BlockHandle == 0 || BlockHandle > This->numHandles)
4634 WARN("Out of range handle %d, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
4635 return D3DERR_INVALIDSTATEBLOCK;
4637 if(This->Handles[BlockHandle - 1].type != DDrawHandle_StateBlock)
4639 WARN("Handle %d is not a stateblock, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
4640 return D3DERR_INVALIDSTATEBLOCK;
4643 ref = IWineD3DStateBlock_Release((IWineD3DStateBlock *) This->Handles[BlockHandle - 1].ptr);
4646 ERR("Something is still holding the stateblock %p(Handle %d). Ref = %d\n", This->Handles[BlockHandle - 1].ptr, BlockHandle, ref);
4648 This->Handles[BlockHandle - 1].ptr = NULL;
4649 This->Handles[BlockHandle - 1].type = DDrawHandle_Unknown;
4654 /*****************************************************************************
4655 * IDirect3DDevice7::CreateStateBlock
4657 * Creates a new state block handle.
4662 * Type: The state block type
4663 * BlockHandle: Address to write the created handle to
4667 * DDERR_INVALIDPARAMS if BlockHandle is NULL
4669 *****************************************************************************/
4670 static HRESULT WINAPI
4671 IDirect3DDeviceImpl_7_CreateStateBlock(IDirect3DDevice7 *iface,
4672 D3DSTATEBLOCKTYPE Type,
4675 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4677 TRACE("(%p)->(%08x,%p)!\n", This, Type, BlockHandle);
4681 WARN("BlockHandle == NULL, returning DDERR_INVALIDPARAMS\n");
4682 return DDERR_INVALIDPARAMS;
4685 *BlockHandle = IDirect3DDeviceImpl_CreateHandle(This);
4688 ERR("Cannot get a handle number for the stateblock\n");
4689 return DDERR_OUTOFMEMORY;
4691 This->Handles[*BlockHandle - 1].type = DDrawHandle_StateBlock;
4693 /* The D3DSTATEBLOCKTYPE enum is fine here */
4694 hr = IWineD3DDevice_CreateStateBlock(This->wineD3DDevice,
4696 (IWineD3DStateBlock **) &This->Handles[*BlockHandle - 1].ptr,
4697 NULL /* Parent, hope that works */);
4698 return hr_ddraw_from_wined3d(hr);
4701 /*****************************************************************************
4702 * IDirect3DDevice7::Load
4704 * Loads a rectangular area from the source into the destination texture.
4705 * It can also copy the source to the faces of a cubic environment map
4710 * DestTex: Destination texture
4711 * DestPoint: Point in the destination where the source image should be
4713 * SrcTex: Source texture
4714 * SrcRect: Source rectangle
4719 * DDERR_INVALIDPARAMS if DestTex or SrcTex are NULL
4720 * See IDirect3DTexture2::Load for details
4722 *****************************************************************************/
4723 static HRESULT WINAPI
4724 IDirect3DDeviceImpl_7_Load(IDirect3DDevice7 *iface,
4725 IDirectDrawSurface7 *DestTex,
4727 IDirectDrawSurface7 *SrcTex,
4731 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4732 IDirectDrawSurfaceImpl *dest = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, DestTex);
4733 IDirectDrawSurfaceImpl *src = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, SrcTex);
4734 FIXME("(%p)->(%p,%p,%p,%p,%08x): Partially Implemented!\n", This, dest, DestPoint, src, SrcRect, Flags);
4736 if( (!src) || (!dest) )
4737 return DDERR_INVALIDPARAMS;
4739 IDirect3DTexture2_Load(ICOM_INTERFACE(dest, IDirect3DTexture2),
4740 ICOM_INTERFACE(src, IDirect3DTexture2));
4744 /*****************************************************************************
4745 * IDirect3DDevice7::LightEnable
4747 * Enables or disables a light
4749 * Version 7, IDirect3DLight uses this method too.
4752 * LightIndex: The index of the light to enable / disable
4753 * Enable: Enable or disable the light
4757 * For more details, see IWineD3DDevice::SetLightEnable
4759 *****************************************************************************/
4760 static HRESULT WINAPI
4761 IDirect3DDeviceImpl_7_LightEnable(IDirect3DDevice7 *iface,
4765 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4767 TRACE("(%p)->(%08x,%d): Relay!\n", This, LightIndex, Enable);
4769 hr = IWineD3DDevice_SetLightEnable(This->wineD3DDevice, LightIndex, Enable);
4770 return hr_ddraw_from_wined3d(hr);
4773 /*****************************************************************************
4774 * IDirect3DDevice7::GetLightEnable
4776 * Retrieves if the light with the given index is enabled or not
4781 * LightIndex: Index of desired light
4782 * Enable: Pointer to a BOOL which contains the result
4786 * DDERR_INVALIDPARAMS if Enable is NULL
4787 * See IWineD3DDevice::GetLightEnable for more details
4789 *****************************************************************************/
4790 static HRESULT WINAPI
4791 IDirect3DDeviceImpl_7_GetLightEnable(IDirect3DDevice7 *iface,
4795 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4797 TRACE("(%p)->(%08x,%p): Relay\n", This, LightIndex, Enable);
4800 return DDERR_INVALIDPARAMS;
4802 hr = IWineD3DDevice_GetLightEnable(This->wineD3DDevice, LightIndex, Enable);
4803 return hr_ddraw_from_wined3d(hr);
4806 /*****************************************************************************
4807 * IDirect3DDevice7::SetClipPlane
4809 * Sets custom clipping plane
4814 * Index: The index of the clipping plane
4815 * PlaneEquation: An equation defining the clipping plane
4819 * DDERR_INVALIDPARAMS if PlaneEquation is NULL
4820 * See IWineD3DDevice::SetClipPlane for more details
4822 *****************************************************************************/
4823 static HRESULT WINAPI
4824 IDirect3DDeviceImpl_7_SetClipPlane(IDirect3DDevice7 *iface,
4826 D3DVALUE* PlaneEquation)
4828 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4829 TRACE("(%p)->(%08x,%p): Relay!\n", This, Index, PlaneEquation);
4832 return DDERR_INVALIDPARAMS;
4834 return IWineD3DDevice_SetClipPlane(This->wineD3DDevice, Index, PlaneEquation);
4837 /*****************************************************************************
4838 * IDirect3DDevice7::GetClipPlane
4840 * Returns the clipping plane with a specific index
4843 * Index: The index of the desired plane
4844 * PlaneEquation: Address to store the plane equation to
4848 * DDERR_INVALIDPARAMS if PlaneEquation is NULL
4849 * See IWineD3DDevice::GetClipPlane for more details
4851 *****************************************************************************/
4852 static HRESULT WINAPI
4853 IDirect3DDeviceImpl_7_GetClipPlane(IDirect3DDevice7 *iface,
4855 D3DVALUE* PlaneEquation)
4857 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4858 TRACE("(%p)->(%d,%p): Relay!\n", This, Index, PlaneEquation);
4861 return DDERR_INVALIDPARAMS;
4863 return IWineD3DDevice_GetClipPlane(This->wineD3DDevice, Index, PlaneEquation);
4866 /*****************************************************************************
4867 * IDirect3DDevice7::GetInfo
4869 * Retrieves some information about the device. The DirectX sdk says that
4870 * this version returns S_FALSE for all retail builds of DirectX, that's what
4871 * this implementation does.
4874 * DevInfoID: Information type requested
4875 * DevInfoStruct: Pointer to a structure to store the info to
4876 * Size: Size of the structure
4879 * S_FALSE, because it's a non-debug driver
4881 *****************************************************************************/
4882 static HRESULT WINAPI
4883 IDirect3DDeviceImpl_7_GetInfo(IDirect3DDevice7 *iface,
4885 void *DevInfoStruct,
4888 ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
4889 TRACE("(%p)->(%08x,%p,%08x)\n", This, DevInfoID, DevInfoStruct, Size);
4893 TRACE(" info requested : ");
4896 case D3DDEVINFOID_TEXTUREMANAGER: TRACE("D3DDEVINFOID_TEXTUREMANAGER\n"); break;
4897 case D3DDEVINFOID_D3DTEXTUREMANAGER: TRACE("D3DDEVINFOID_D3DTEXTUREMANAGER\n"); break;
4898 case D3DDEVINFOID_TEXTURING: TRACE("D3DDEVINFOID_TEXTURING\n"); break;
4899 default: ERR(" invalid flag !!!\n"); return DDERR_INVALIDPARAMS;
4903 return S_FALSE; /* According to MSDN, this is valid for a non-debug driver */
4906 const IDirect3DDevice7Vtbl IDirect3DDevice7_Vtbl =
4908 /*** IUnknown Methods ***/
4909 IDirect3DDeviceImpl_7_QueryInterface,
4910 IDirect3DDeviceImpl_7_AddRef,
4911 IDirect3DDeviceImpl_7_Release,
4912 /*** IDirect3DDevice7 ***/
4913 IDirect3DDeviceImpl_7_GetCaps,
4914 IDirect3DDeviceImpl_7_EnumTextureFormats,
4915 IDirect3DDeviceImpl_7_BeginScene,
4916 IDirect3DDeviceImpl_7_EndScene,
4917 IDirect3DDeviceImpl_7_GetDirect3D,
4918 IDirect3DDeviceImpl_7_SetRenderTarget,
4919 IDirect3DDeviceImpl_7_GetRenderTarget,
4920 IDirect3DDeviceImpl_7_Clear,
4921 IDirect3DDeviceImpl_7_SetTransform,
4922 IDirect3DDeviceImpl_7_GetTransform,
4923 IDirect3DDeviceImpl_7_SetViewport,
4924 IDirect3DDeviceImpl_7_MultiplyTransform,
4925 IDirect3DDeviceImpl_7_GetViewport,
4926 IDirect3DDeviceImpl_7_SetMaterial,
4927 IDirect3DDeviceImpl_7_GetMaterial,
4928 IDirect3DDeviceImpl_7_SetLight,
4929 IDirect3DDeviceImpl_7_GetLight,
4930 IDirect3DDeviceImpl_7_SetRenderState,
4931 IDirect3DDeviceImpl_7_GetRenderState,
4932 IDirect3DDeviceImpl_7_BeginStateBlock,
4933 IDirect3DDeviceImpl_7_EndStateBlock,
4934 IDirect3DDeviceImpl_7_PreLoad,
4935 IDirect3DDeviceImpl_7_DrawPrimitive,
4936 IDirect3DDeviceImpl_7_DrawIndexedPrimitive,
4937 IDirect3DDeviceImpl_7_SetClipStatus,
4938 IDirect3DDeviceImpl_7_GetClipStatus,
4939 IDirect3DDeviceImpl_7_DrawPrimitiveStrided,
4940 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveStrided,
4941 IDirect3DDeviceImpl_7_DrawPrimitiveVB,
4942 IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB,
4943 IDirect3DDeviceImpl_7_ComputeSphereVisibility,
4944 IDirect3DDeviceImpl_7_GetTexture,
4945 IDirect3DDeviceImpl_7_SetTexture,
4946 IDirect3DDeviceImpl_7_GetTextureStageState,
4947 IDirect3DDeviceImpl_7_SetTextureStageState,
4948 IDirect3DDeviceImpl_7_ValidateDevice,
4949 IDirect3DDeviceImpl_7_ApplyStateBlock,
4950 IDirect3DDeviceImpl_7_CaptureStateBlock,
4951 IDirect3DDeviceImpl_7_DeleteStateBlock,
4952 IDirect3DDeviceImpl_7_CreateStateBlock,
4953 IDirect3DDeviceImpl_7_Load,
4954 IDirect3DDeviceImpl_7_LightEnable,
4955 IDirect3DDeviceImpl_7_GetLightEnable,
4956 IDirect3DDeviceImpl_7_SetClipPlane,
4957 IDirect3DDeviceImpl_7_GetClipPlane,
4958 IDirect3DDeviceImpl_7_GetInfo
4961 const IDirect3DDevice3Vtbl IDirect3DDevice3_Vtbl =
4963 /*** IUnknown Methods ***/
4964 Thunk_IDirect3DDeviceImpl_3_QueryInterface,
4965 Thunk_IDirect3DDeviceImpl_3_AddRef,
4966 Thunk_IDirect3DDeviceImpl_3_Release,
4967 /*** IDirect3DDevice3 ***/
4968 IDirect3DDeviceImpl_3_GetCaps,
4969 IDirect3DDeviceImpl_3_GetStats,
4970 IDirect3DDeviceImpl_3_AddViewport,
4971 IDirect3DDeviceImpl_3_DeleteViewport,
4972 IDirect3DDeviceImpl_3_NextViewport,
4973 Thunk_IDirect3DDeviceImpl_3_EnumTextureFormats,
4974 Thunk_IDirect3DDeviceImpl_3_BeginScene,
4975 Thunk_IDirect3DDeviceImpl_3_EndScene,
4976 Thunk_IDirect3DDeviceImpl_3_GetDirect3D,
4977 IDirect3DDeviceImpl_3_SetCurrentViewport,
4978 IDirect3DDeviceImpl_3_GetCurrentViewport,
4979 Thunk_IDirect3DDeviceImpl_3_SetRenderTarget,
4980 Thunk_IDirect3DDeviceImpl_3_GetRenderTarget,
4981 IDirect3DDeviceImpl_3_Begin,
4982 IDirect3DDeviceImpl_3_BeginIndexed,
4983 IDirect3DDeviceImpl_3_Vertex,
4984 IDirect3DDeviceImpl_3_Index,
4985 IDirect3DDeviceImpl_3_End,
4986 Thunk_IDirect3DDeviceImpl_3_GetRenderState,
4987 Thunk_IDirect3DDeviceImpl_3_SetRenderState,
4988 IDirect3DDeviceImpl_3_GetLightState,
4989 IDirect3DDeviceImpl_3_SetLightState,
4990 Thunk_IDirect3DDeviceImpl_3_SetTransform,
4991 Thunk_IDirect3DDeviceImpl_3_GetTransform,
4992 Thunk_IDirect3DDeviceImpl_3_MultiplyTransform,
4993 Thunk_IDirect3DDeviceImpl_3_DrawPrimitive,
4994 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitive,
4995 Thunk_IDirect3DDeviceImpl_3_SetClipStatus,
4996 Thunk_IDirect3DDeviceImpl_3_GetClipStatus,
4997 Thunk_IDirect3DDeviceImpl_3_DrawPrimitiveStrided,
4998 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitiveStrided,
4999 Thunk_IDirect3DDeviceImpl_3_DrawPrimitiveVB,
5000 Thunk_IDirect3DDeviceImpl_3_DrawIndexedPrimitiveVB,
5001 Thunk_IDirect3DDeviceImpl_3_ComputeSphereVisibility,
5002 Thunk_IDirect3DDeviceImpl_3_GetTexture,
5003 Thunk_IDirect3DDeviceImpl_3_SetTexture,
5004 Thunk_IDirect3DDeviceImpl_3_GetTextureStageState,
5005 Thunk_IDirect3DDeviceImpl_3_SetTextureStageState,
5006 Thunk_IDirect3DDeviceImpl_3_ValidateDevice
5009 const IDirect3DDevice2Vtbl IDirect3DDevice2_Vtbl =
5011 /*** IUnknown Methods ***/
5012 Thunk_IDirect3DDeviceImpl_2_QueryInterface,
5013 Thunk_IDirect3DDeviceImpl_2_AddRef,
5014 Thunk_IDirect3DDeviceImpl_2_Release,
5015 /*** IDirect3DDevice2 ***/
5016 Thunk_IDirect3DDeviceImpl_2_GetCaps,
5017 IDirect3DDeviceImpl_2_SwapTextureHandles,
5018 Thunk_IDirect3DDeviceImpl_2_GetStats,
5019 Thunk_IDirect3DDeviceImpl_2_AddViewport,
5020 Thunk_IDirect3DDeviceImpl_2_DeleteViewport,
5021 Thunk_IDirect3DDeviceImpl_2_NextViewport,
5022 IDirect3DDeviceImpl_2_EnumTextureFormats,
5023 Thunk_IDirect3DDeviceImpl_2_BeginScene,
5024 Thunk_IDirect3DDeviceImpl_2_EndScene,
5025 Thunk_IDirect3DDeviceImpl_2_GetDirect3D,
5026 Thunk_IDirect3DDeviceImpl_2_SetCurrentViewport,
5027 Thunk_IDirect3DDeviceImpl_2_GetCurrentViewport,
5028 Thunk_IDirect3DDeviceImpl_2_SetRenderTarget,
5029 Thunk_IDirect3DDeviceImpl_2_GetRenderTarget,
5030 Thunk_IDirect3DDeviceImpl_2_Begin,
5031 Thunk_IDirect3DDeviceImpl_2_BeginIndexed,
5032 Thunk_IDirect3DDeviceImpl_2_Vertex,
5033 Thunk_IDirect3DDeviceImpl_2_Index,
5034 Thunk_IDirect3DDeviceImpl_2_End,
5035 Thunk_IDirect3DDeviceImpl_2_GetRenderState,
5036 Thunk_IDirect3DDeviceImpl_2_SetRenderState,
5037 Thunk_IDirect3DDeviceImpl_2_GetLightState,
5038 Thunk_IDirect3DDeviceImpl_2_SetLightState,
5039 Thunk_IDirect3DDeviceImpl_2_SetTransform,
5040 Thunk_IDirect3DDeviceImpl_2_GetTransform,
5041 Thunk_IDirect3DDeviceImpl_2_MultiplyTransform,
5042 Thunk_IDirect3DDeviceImpl_2_DrawPrimitive,
5043 Thunk_IDirect3DDeviceImpl_2_DrawIndexedPrimitive,
5044 Thunk_IDirect3DDeviceImpl_2_SetClipStatus,
5045 Thunk_IDirect3DDeviceImpl_2_GetClipStatus
5048 const IDirect3DDeviceVtbl IDirect3DDevice1_Vtbl =
5050 /*** IUnknown Methods ***/
5051 Thunk_IDirect3DDeviceImpl_1_QueryInterface,
5052 Thunk_IDirect3DDeviceImpl_1_AddRef,
5053 Thunk_IDirect3DDeviceImpl_1_Release,
5054 /*** IDirect3DDevice1 ***/
5055 IDirect3DDeviceImpl_1_Initialize,
5056 Thunk_IDirect3DDeviceImpl_1_GetCaps,
5057 Thunk_IDirect3DDeviceImpl_1_SwapTextureHandles,
5058 IDirect3DDeviceImpl_1_CreateExecuteBuffer,
5059 Thunk_IDirect3DDeviceImpl_1_GetStats,
5060 IDirect3DDeviceImpl_1_Execute,
5061 Thunk_IDirect3DDeviceImpl_1_AddViewport,
5062 Thunk_IDirect3DDeviceImpl_1_DeleteViewport,
5063 Thunk_IDirect3DDeviceImpl_1_NextViewport,
5064 IDirect3DDeviceImpl_1_Pick,
5065 IDirect3DDeviceImpl_1_GetPickRecords,
5066 Thunk_IDirect3DDeviceImpl_1_EnumTextureFormats,
5067 IDirect3DDeviceImpl_1_CreateMatrix,
5068 IDirect3DDeviceImpl_1_SetMatrix,
5069 IDirect3DDeviceImpl_1_GetMatrix,
5070 IDirect3DDeviceImpl_1_DeleteMatrix,
5071 Thunk_IDirect3DDeviceImpl_1_EndScene,
5072 Thunk_IDirect3DDeviceImpl_1_BeginScene,
5073 Thunk_IDirect3DDeviceImpl_1_GetDirect3D
5076 /*****************************************************************************
5077 * IDirect3DDeviceImpl_CreateHandle
5079 * Not called from the VTable
5081 * Some older interface versions operate with handles, which are basically
5082 * DWORDs which identify an interface, for example
5083 * IDirect3DDevice::SetRenderState with DIRECT3DRENDERSTATE_TEXTUREHANDLE
5085 * Those handle could be just casts to the interface pointers or vice versa,
5086 * but that is not 64 bit safe and would mean blindly derefering a DWORD
5087 * passed by the app. Instead there is a dynamic array in the device which
5088 * keeps a DWORD to pointer information and a type for the handle.
5090 * Basically this array only grows, when a handle is freed its pointer is
5091 * just set to NULL. There will be much more reads from the array than
5092 * insertion operations, so a dynamic array is fine.
5095 * This: D3DDevice implementation for which this handle should be created
5098 * A free handle on success
5101 *****************************************************************************/
5103 IDirect3DDeviceImpl_CreateHandle(IDirect3DDeviceImpl *This)
5106 struct HandleEntry *oldHandles = This->Handles;
5108 TRACE("(%p)\n", This);
5110 for(i = 0; i < This->numHandles; i++)
5112 if(This->Handles[i].ptr == NULL &&
5113 This->Handles[i].type == DDrawHandle_Unknown)
5115 TRACE("Reusing freed handle %d\n", i + 1);
5120 TRACE("Growing the handle array\n");
5123 This->Handles = HeapAlloc(GetProcessHeap(), 0, sizeof(struct HandleEntry) * This->numHandles);
5126 ERR("Out of memory\n");
5127 This->Handles = oldHandles;
5133 memcpy(This->Handles, oldHandles, (This->numHandles - 1) * sizeof(struct HandleEntry));
5134 HeapFree(GetProcessHeap(), 0, oldHandles);
5137 TRACE("Returning %d\n", This->numHandles);
5138 return This->numHandles;