2 * Copyright (c) 1998 Lionel ULMER
3 * Copyright (c) 2006-2007 Stefan DÖSINGER
5 * This file contains the implementation of Direct3DViewport2.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
31 #define NONAMELESSUNION
37 #include "wine/exception.h"
42 #include "ddraw_private.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(d3d7
);
47 /*****************************************************************************
49 *****************************************************************************/
51 /*****************************************************************************
54 * activates the viewport using IDirect3DDevice7::SetViewport
56 *****************************************************************************/
57 void viewport_activate(IDirect3DViewportImpl
* This
, BOOL ignore_lights
) {
58 IDirect3DLightImpl
* light
;
62 /* Activate all the lights associated with this context */
65 while (light
!= NULL
) {
66 light
->activate(light
);
71 /* And copy the values in the structure used by the device */
73 vp
.dwX
= This
->viewports
.vp2
.dwX
;
74 vp
.dwY
= This
->viewports
.vp2
.dwY
;
75 vp
.dwHeight
= This
->viewports
.vp2
.dwHeight
;
76 vp
.dwWidth
= This
->viewports
.vp2
.dwWidth
;
77 vp
.dvMinZ
= This
->viewports
.vp2
.dvMinZ
;
78 vp
.dvMaxZ
= This
->viewports
.vp2
.dvMaxZ
;
80 vp
.dwX
= This
->viewports
.vp1
.dwX
;
81 vp
.dwY
= This
->viewports
.vp1
.dwY
;
82 vp
.dwHeight
= This
->viewports
.vp1
.dwHeight
;
83 vp
.dwWidth
= This
->viewports
.vp1
.dwWidth
;
84 vp
.dvMinZ
= This
->viewports
.vp1
.dvMinZ
;
85 vp
.dvMaxZ
= This
->viewports
.vp1
.dvMaxZ
;
88 /* And also set the viewport */
89 IDirect3DDevice7_SetViewport((IDirect3DDevice7
*)This
->active_device
, &vp
);
92 /*****************************************************************************
93 * _dump_D3DVIEWPORT, _dump_D3DVIEWPORT2
95 * Writes viewport information to TRACE
97 *****************************************************************************/
98 static void _dump_D3DVIEWPORT(const D3DVIEWPORT
*lpvp
)
100 TRACE(" - dwSize = %d dwX = %d dwY = %d\n",
101 lpvp
->dwSize
, lpvp
->dwX
, lpvp
->dwY
);
102 TRACE(" - dwWidth = %d dwHeight = %d\n",
103 lpvp
->dwWidth
, lpvp
->dwHeight
);
104 TRACE(" - dvScaleX = %f dvScaleY = %f\n",
105 lpvp
->dvScaleX
, lpvp
->dvScaleY
);
106 TRACE(" - dvMaxX = %f dvMaxY = %f\n",
107 lpvp
->dvMaxX
, lpvp
->dvMaxY
);
108 TRACE(" - dvMinZ = %f dvMaxZ = %f\n",
109 lpvp
->dvMinZ
, lpvp
->dvMaxZ
);
112 static void _dump_D3DVIEWPORT2(const D3DVIEWPORT2
*lpvp
)
114 TRACE(" - dwSize = %d dwX = %d dwY = %d\n",
115 lpvp
->dwSize
, lpvp
->dwX
, lpvp
->dwY
);
116 TRACE(" - dwWidth = %d dwHeight = %d\n",
117 lpvp
->dwWidth
, lpvp
->dwHeight
);
118 TRACE(" - dvClipX = %f dvClipY = %f\n",
119 lpvp
->dvClipX
, lpvp
->dvClipY
);
120 TRACE(" - dvClipWidth = %f dvClipHeight = %f\n",
121 lpvp
->dvClipWidth
, lpvp
->dvClipHeight
);
122 TRACE(" - dvMinZ = %f dvMaxZ = %f\n",
123 lpvp
->dvMinZ
, lpvp
->dvMaxZ
);
126 /*****************************************************************************
128 *****************************************************************************/
130 /*****************************************************************************
131 * IDirect3DViewport3::QueryInterface
133 * A normal QueryInterface. Can query all interface versions and the
134 * IUnknown interface. The VTables of the different versions
138 * refiid: Interface id queried for
139 * obj: Address to write the interface pointer to
143 * E_NOINTERFACE if the requested interface wasn't found
145 *****************************************************************************/
146 static HRESULT WINAPI
147 IDirect3DViewportImpl_QueryInterface(IDirect3DViewport3
*iface
,
151 TRACE("(%p)->(%s,%p)\n", iface
, debugstr_guid(riid
), obp
);
155 if ( IsEqualGUID(&IID_IUnknown
, riid
) ||
156 IsEqualGUID(&IID_IDirect3DViewport
, riid
) ||
157 IsEqualGUID(&IID_IDirect3DViewport2
, riid
) ||
158 IsEqualGUID(&IID_IDirect3DViewport3
, riid
) ) {
159 IDirect3DViewport3_AddRef(iface
);
161 TRACE(" Creating IDirect3DViewport1/2/3 interface %p\n", *obp
);
164 FIXME("(%p): interface for IID %s NOT found!\n", iface
, debugstr_guid(riid
));
165 return E_NOINTERFACE
;
168 /*****************************************************************************
169 * IDirect3DViewport3::AddRef
171 * Increases the refcount.
176 *****************************************************************************/
178 IDirect3DViewportImpl_AddRef(IDirect3DViewport3
*iface
)
180 IDirect3DViewportImpl
*This
= (IDirect3DViewportImpl
*)iface
;
181 ULONG ref
= InterlockedIncrement(&This
->ref
);
183 TRACE("(%p)->() incrementing from %u.\n", This
, ref
- 1);
188 /*****************************************************************************
189 * IDirect3DViewport3::Release
191 * Reduces the refcount. If it falls to 0, the interface is released
196 *****************************************************************************/
198 IDirect3DViewportImpl_Release(IDirect3DViewport3
*iface
)
200 IDirect3DViewportImpl
*This
= (IDirect3DViewportImpl
*)iface
;
201 ULONG ref
= InterlockedDecrement(&This
->ref
);
203 TRACE("(%p)->() decrementing from %u.\n", This
, ref
+ 1);
206 HeapFree(GetProcessHeap(), 0, This
);
212 /*****************************************************************************
213 * IDirect3DViewport Methods.
214 *****************************************************************************/
216 /*****************************************************************************
217 * IDirect3DViewport3::Initialize
219 * No-op initialization.
222 * Direct3D: The direct3D device this viewport is assigned to
225 * DDERR_ALREADYINITIALIZED
227 *****************************************************************************/
228 static HRESULT WINAPI
229 IDirect3DViewportImpl_Initialize(IDirect3DViewport3
*iface
,
232 TRACE("(%p)->(%p) no-op...\n", iface
, Direct3D
);
233 return DDERR_ALREADYINITIALIZED
;
236 /*****************************************************************************
237 * IDirect3DViewport3::GetViewport
239 * Returns the viewport data assigned to this viewport interface
242 * Data: Address to store the data
246 * DDERR_INVALIDPARAMS if Data is NULL
248 *****************************************************************************/
249 static HRESULT WINAPI
250 IDirect3DViewportImpl_GetViewport(IDirect3DViewport3
*iface
,
253 IDirect3DViewportImpl
*This
= (IDirect3DViewportImpl
*)iface
;
255 TRACE("(%p/%p)->(%p)\n", This
, iface
, lpData
);
257 EnterCriticalSection(&ddraw_cs
);
258 if (This
->use_vp2
!= 0) {
259 ERR(" Requesting to get a D3DVIEWPORT struct where a D3DVIEWPORT2 was set !\n");
260 LeaveCriticalSection(&ddraw_cs
);
261 return DDERR_INVALIDPARAMS
;
263 dwSize
= lpData
->dwSize
;
264 memset(lpData
, 0, dwSize
);
265 memcpy(lpData
, &(This
->viewports
.vp1
), dwSize
);
267 if (TRACE_ON(d3d7
)) {
268 TRACE(" returning D3DVIEWPORT :\n");
269 _dump_D3DVIEWPORT(lpData
);
271 LeaveCriticalSection(&ddraw_cs
);
276 /*****************************************************************************
277 * IDirect3DViewport3::SetViewport
279 * Sets the viewport information for this interface
282 * lpData: Viewport to set
286 * DDERR_INVALIDPARAMS if Data is NULL
288 *****************************************************************************/
289 static HRESULT WINAPI
290 IDirect3DViewportImpl_SetViewport(IDirect3DViewport3
*iface
,
293 IDirect3DViewportImpl
*This
= (IDirect3DViewportImpl
*)iface
;
294 LPDIRECT3DVIEWPORT3 current_viewport
;
295 TRACE("(%p/%p)->(%p)\n", This
, iface
, lpData
);
297 if (TRACE_ON(d3d7
)) {
298 TRACE(" getting D3DVIEWPORT :\n");
299 _dump_D3DVIEWPORT(lpData
);
302 EnterCriticalSection(&ddraw_cs
);
304 memset(&(This
->viewports
.vp1
), 0, sizeof(This
->viewports
.vp1
));
305 memcpy(&(This
->viewports
.vp1
), lpData
, lpData
->dwSize
);
307 /* Tests on two games show that these values are never used properly so override
308 them with proper ones :-)
310 This
->viewports
.vp1
.dvMinZ
= 0.0;
311 This
->viewports
.vp1
.dvMaxZ
= 1.0;
313 if (This
->active_device
) {
314 IDirect3DDevice3
*d3d_device3
= (IDirect3DDevice3
*)&This
->active_device
->IDirect3DDevice3_vtbl
;
315 IDirect3DDevice3_GetCurrentViewport(d3d_device3
, ¤t_viewport
);
316 if (current_viewport
) {
317 if ((IDirect3DViewportImpl
*)current_viewport
== This
) This
->activate(This
, FALSE
);
318 IDirect3DViewport3_Release(current_viewport
);
321 LeaveCriticalSection(&ddraw_cs
);
326 /*****************************************************************************
327 * IDirect3DViewport3::TransformVertices
329 * Transforms vertices by the transformation matrix.
331 * This function is pretty similar to IDirect3DVertexBuffer7::ProcessVertices,
332 * so it's tempting to forward it to there. However, there are some
333 * tiny differences. First, the lpOffscreen flag that is reported back,
334 * then there is the homogeneous vertex that is generated. Also there's a lack
335 * of FVFs, but still a custom stride. Last, the d3d1 - d3d3 viewport has some
336 * settings (scale) that d3d7 and wined3d do not have. All in all wrapping to
337 * ProcessVertices doesn't pay of in terms of wrapper code needed and code
341 * dwVertexCount: The number of vertices to be transformed
342 * lpData: Pointer to the vertex data
343 * dwFlags: D3DTRANSFORM_CLIPPED or D3DTRANSFORM_UNCLIPPED
344 * lpOffScreen: Set to the clipping plane clipping the vertex, if only one
345 * vertex is transformed and clipping is on. 0 otherwise
349 * D3DERR_VIEWPORTHASNODEVICE if the viewport is not assigned to a device
350 * DDERR_INVALIDPARAMS if no clipping flag is specified
352 *****************************************************************************/
353 static HRESULT WINAPI
354 IDirect3DViewportImpl_TransformVertices(IDirect3DViewport3
*iface
,
356 D3DTRANSFORMDATA
*lpData
,
360 IDirect3DViewportImpl
*This
= (IDirect3DViewportImpl
*)iface
;
361 D3DMATRIX view_mat
, world_mat
, proj_mat
, mat
;
366 D3DVIEWPORT vp
= This
->viewports
.vp1
;
368 TRACE("(%p)->(%08x,%p,%08x,%p)\n", This
, dwVertexCount
, lpData
, dwFlags
, lpOffScreen
);
370 /* Tests on windows show that Windows crashes when this occurs,
371 * so don't return the (intuitive) return value
372 if(!This->active_device)
374 WARN("No device active, returning D3DERR_VIEWPORTHASNODEVICE\n");
375 return D3DERR_VIEWPORTHASNODEVICE;
379 if(!(dwFlags
& (D3DTRANSFORM_UNCLIPPED
| D3DTRANSFORM_CLIPPED
)))
381 WARN("No clipping flag passed, returning DDERR_INVALIDPARAMS\n");
382 return DDERR_INVALIDPARAMS
;
386 EnterCriticalSection(&ddraw_cs
);
387 IWineD3DDevice_GetTransform(This
->active_device
->wineD3DDevice
,
388 D3DTRANSFORMSTATE_VIEW
,
389 (WINED3DMATRIX
*) &view_mat
);
391 IWineD3DDevice_GetTransform(This
->active_device
->wineD3DDevice
,
392 D3DTRANSFORMSTATE_PROJECTION
,
393 (WINED3DMATRIX
*) &proj_mat
);
395 IWineD3DDevice_GetTransform(This
->active_device
->wineD3DDevice
,
396 WINED3DTS_WORLDMATRIX(0),
397 (WINED3DMATRIX
*) &world_mat
);
398 multiply_matrix(&mat
,&view_mat
,&world_mat
);
399 multiply_matrix(&mat
,&proj_mat
,&mat
);
403 outH
= lpData
->lpHOut
;
404 for(i
= 0; i
< dwVertexCount
; i
++)
406 x
= (in
[0] * mat
._11
) + (in
[1] * mat
._21
) + (in
[2] * mat
._31
) + (1.0 * mat
._41
);
407 y
= (in
[0] * mat
._12
) + (in
[1] * mat
._22
) + (in
[2] * mat
._32
) + (1.0 * mat
._42
);
408 z
= (in
[0] * mat
._13
) + (in
[1] * mat
._23
) + (in
[2] * mat
._33
) + (1.0 * mat
._43
);
409 w
= (in
[0] * mat
._14
) + (in
[1] * mat
._24
) + (in
[2] * mat
._34
) + (1.0 * mat
._44
);
411 if(dwFlags
& D3DTRANSFORM_CLIPPED
)
413 /* If clipping is enabled, Windows assumes that outH is
416 outH
[i
].u1
.hx
= x
; outH
[i
].u2
.hy
= y
; outH
[i
].u3
.hz
= z
;
419 if(x
* vp
.dvScaleX
> ((float) vp
.dwWidth
* 0.5))
420 outH
[i
].dwFlags
|= D3DCLIP_RIGHT
;
421 if(x
* vp
.dvScaleX
<= -((float) vp
.dwWidth
) * 0.5)
422 outH
[i
].dwFlags
|= D3DCLIP_LEFT
;
423 if(y
* vp
.dvScaleY
> ((float) vp
.dwHeight
* 0.5))
424 outH
[i
].dwFlags
|= D3DCLIP_TOP
;
425 if(y
* vp
.dvScaleY
<= -((float) vp
.dwHeight
) * 0.5)
426 outH
[i
].dwFlags
|= D3DCLIP_BOTTOM
;
428 outH
[i
].dwFlags
|= D3DCLIP_FRONT
;
430 outH
[i
].dwFlags
|= D3DCLIP_BACK
;
434 /* Looks like native just drops the vertex, leaves whatever data
435 * it has in the output buffer and goes on with the next vertex.
436 * The exact scheme hasn't been figured out yet, but windows
437 * definitely writes something there.
443 in
= (float *) ((char *) in
+ lpData
->dwInSize
);
444 out
= (float *) ((char *) out
+ lpData
->dwOutSize
);
450 x
*= w
; y
*= w
; z
*= w
;
452 out
[0] = vp
.dwWidth
/ 2 + vp
.dwX
+ x
* vp
.dvScaleX
;
453 out
[1] = vp
.dwHeight
/ 2 + vp
.dwY
- y
* vp
.dvScaleY
;
456 in
= (float *) ((char *) in
+ lpData
->dwInSize
);
457 out
= (float *) ((char *) out
+ lpData
->dwOutSize
);
460 /* According to the d3d test, the offscreen flag is set only
461 * if exactly one vertex is transformed. Its not documented,
462 * but the test shows that the lpOffscreen flag is set to the
463 * flag combination of clipping planes that clips the vertex.
465 * If clipping is requested, Windows assumes that the offscreen
466 * param is a valid pointer.
468 if(dwVertexCount
== 1 && dwFlags
& D3DTRANSFORM_CLIPPED
)
470 *lpOffScreen
= outH
[0].dwFlags
;
472 else if(*lpOffScreen
)
476 LeaveCriticalSection(&ddraw_cs
);
482 /*****************************************************************************
483 * IDirect3DViewport3::LightElements
485 * The DirectX 5.0 sdk says that it's not implemented
493 *****************************************************************************/
494 static HRESULT WINAPI
495 IDirect3DViewportImpl_LightElements(IDirect3DViewport3
*iface
,
496 DWORD dwElementCount
,
497 LPD3DLIGHTDATA lpData
)
499 IDirect3DViewportImpl
*This
= (IDirect3DViewportImpl
*)iface
;
500 TRACE("(%p)->(%08x,%p): Unimplemented!\n", This
, dwElementCount
, lpData
);
501 return DDERR_UNSUPPORTED
;
504 /*****************************************************************************
505 * IDirect3DViewport3::SetBackground
507 * Sets tje background material
510 * hMat: Handle from a IDirect3DMaterial interface
515 *****************************************************************************/
516 static HRESULT WINAPI
517 IDirect3DViewportImpl_SetBackground(IDirect3DViewport3
*iface
,
518 D3DMATERIALHANDLE hMat
)
520 IDirect3DViewportImpl
*This
= (IDirect3DViewportImpl
*)iface
;
521 TRACE("(%p)->(%d)\n", This
, hMat
);
523 EnterCriticalSection(&ddraw_cs
);
524 if(hMat
&& hMat
> This
->ddraw
->d3ddevice
->numHandles
)
526 WARN("Specified Handle %d out of range\n", hMat
);
527 LeaveCriticalSection(&ddraw_cs
);
528 return DDERR_INVALIDPARAMS
;
530 else if(hMat
&& This
->ddraw
->d3ddevice
->Handles
[hMat
- 1].type
!= DDrawHandle_Material
)
532 WARN("Handle %d is not a material handle\n", hMat
);
533 LeaveCriticalSection(&ddraw_cs
);
534 return DDERR_INVALIDPARAMS
;
539 This
->background
= This
->ddraw
->d3ddevice
->Handles
[hMat
- 1].ptr
;
540 TRACE(" setting background color : %f %f %f %f\n",
541 This
->background
->mat
.u
.diffuse
.u1
.r
,
542 This
->background
->mat
.u
.diffuse
.u2
.g
,
543 This
->background
->mat
.u
.diffuse
.u3
.b
,
544 This
->background
->mat
.u
.diffuse
.u4
.a
);
548 This
->background
= NULL
;
549 TRACE("Setting background to NULL\n");
552 LeaveCriticalSection(&ddraw_cs
);
556 /*****************************************************************************
557 * IDirect3DViewport3::GetBackground
559 * Returns the material handle assigned to the background of the viewport
562 * lphMat: Address to store the handle
563 * lpValid: is set to FALSE if no background is set, TRUE if one is set
568 *****************************************************************************/
569 static HRESULT WINAPI
570 IDirect3DViewportImpl_GetBackground(IDirect3DViewport3
*iface
,
571 D3DMATERIALHANDLE
*lphMat
,
574 IDirect3DViewportImpl
*This
= (IDirect3DViewportImpl
*)iface
;
575 TRACE("(%p)->(%p,%p)\n", This
, lphMat
, lpValid
);
577 EnterCriticalSection(&ddraw_cs
);
580 *lpValid
= This
->background
!= NULL
;
586 *lphMat
= This
->background
->Handle
;
593 LeaveCriticalSection(&ddraw_cs
);
598 /*****************************************************************************
599 * IDirect3DViewport3::SetBackgroundDepth
601 * Sets a surface that represents the background depth. It's contents are
602 * used to set the depth buffer in IDirect3DViewport3::Clear
605 * lpDDSurface: Surface to set
607 * Returns: D3D_OK, because it's a stub
609 *****************************************************************************/
610 static HRESULT WINAPI
611 IDirect3DViewportImpl_SetBackgroundDepth(IDirect3DViewport3
*iface
,
612 IDirectDrawSurface
*lpDDSurface
)
614 IDirect3DViewportImpl
*This
= (IDirect3DViewportImpl
*)iface
;
615 FIXME("(%p)->(%p): stub!\n", This
, lpDDSurface
);
619 /*****************************************************************************
620 * IDirect3DViewport3::GetBackgroundDepth
622 * Returns the surface that represents the depth field
625 * lplpDDSurface: Address to store the interface pointer
626 * lpValid: Set to TRUE if a depth is assigned, FALSE otherwise
629 * D3D_OK, because it's a stub
630 * (DDERR_INVALIDPARAMS if DDSurface of Valid is NULL)
632 *****************************************************************************/
633 static HRESULT WINAPI
634 IDirect3DViewportImpl_GetBackgroundDepth(IDirect3DViewport3
*iface
,
635 IDirectDrawSurface
**lplpDDSurface
,
638 IDirect3DViewportImpl
*This
= (IDirect3DViewportImpl
*)iface
;
639 FIXME("(%p)->(%p,%p): stub!\n", This
, lplpDDSurface
, lpValid
);
643 /*****************************************************************************
644 * IDirect3DViewport3::Clear
646 * Clears the render target and / or the z buffer
649 * dwCount: The amount of rectangles to clear. If 0, the whole buffer is
651 * lpRects: Pointer to the array of rectangles. If NULL, Count must be 0
652 * dwFlags: D3DCLEAR_ZBUFFER and / or D3DCLEAR_TARGET
656 * D3DERR_VIEWPORTHASNODEVICE if there's no active device
657 * The return value of IDirect3DDevice7::Clear
659 *****************************************************************************/
660 static HRESULT WINAPI
661 IDirect3DViewportImpl_Clear(IDirect3DViewport3
*iface
,
666 IDirect3DViewportImpl
*This
= (IDirect3DViewportImpl
*)iface
;
667 DWORD color
= 0x00000000;
669 LPDIRECT3DVIEWPORT3 current_viewport
;
670 IDirect3DDevice3
*d3d_device3
;
672 TRACE("(%p/%p)->(%08x,%p,%08x)\n", This
, iface
, dwCount
, lpRects
, dwFlags
);
673 if (This
->active_device
== NULL
) {
674 ERR(" Trying to clear a viewport not attached to a device !\n");
675 return D3DERR_VIEWPORTHASNODEVICE
;
677 d3d_device3
= (IDirect3DDevice3
*)&This
->active_device
->IDirect3DDevice3_vtbl
;
679 EnterCriticalSection(&ddraw_cs
);
680 if (dwFlags
& D3DCLEAR_TARGET
) {
681 if (This
->background
== NULL
) {
682 ERR(" Trying to clear the color buffer without background material !\n");
685 ((int) ((This
->background
->mat
.u
.diffuse
.u1
.r
) * 255) << 16) |
686 ((int) ((This
->background
->mat
.u
.diffuse
.u2
.g
) * 255) << 8) |
687 ((int) ((This
->background
->mat
.u
.diffuse
.u3
.b
) * 255) << 0) |
688 ((int) ((This
->background
->mat
.u
.diffuse
.u4
.a
) * 255) << 24);
692 /* Need to temporarily activate viewport to clear it. Previously active one will be restored
694 This
->activate(This
, TRUE
);
696 hr
= IDirect3DDevice7_Clear((IDirect3DDevice7
*)This
->active_device
, dwCount
, lpRects
,
697 dwFlags
& (D3DCLEAR_ZBUFFER
| D3DCLEAR_TARGET
), color
, 1.0, 0x00000000);
699 IDirect3DDevice3_GetCurrentViewport(d3d_device3
, ¤t_viewport
);
700 if(current_viewport
) {
701 IDirect3DViewportImpl
*vp
= (IDirect3DViewportImpl
*)current_viewport
;
702 vp
->activate(vp
, TRUE
);
703 IDirect3DViewport3_Release(current_viewport
);
706 LeaveCriticalSection(&ddraw_cs
);
710 /*****************************************************************************
711 * IDirect3DViewport3::AddLight
713 * Adds an light to the viewport
716 * lpDirect3DLight: Interface of the light to add
720 * DDERR_INVALIDPARAMS if Direct3DLight is NULL
721 * DDERR_INVALIDPARAMS if there are 8 lights or more
723 *****************************************************************************/
724 static HRESULT WINAPI
725 IDirect3DViewportImpl_AddLight(IDirect3DViewport3
*iface
,
726 IDirect3DLight
*lpDirect3DLight
)
728 IDirect3DViewportImpl
*This
= (IDirect3DViewportImpl
*)iface
;
729 IDirect3DLightImpl
*lpDirect3DLightImpl
= (IDirect3DLightImpl
*)lpDirect3DLight
;
731 DWORD map
= This
->map_lights
;
733 TRACE("(%p)->(%p)\n", This
, lpDirect3DLight
);
735 EnterCriticalSection(&ddraw_cs
);
736 if (This
->num_lights
>= 8)
738 LeaveCriticalSection(&ddraw_cs
);
739 return DDERR_INVALIDPARAMS
;
742 /* Find a light number and update both light and viewports objects accordingly */
747 lpDirect3DLightImpl
->dwLightIndex
= i
;
749 This
->map_lights
|= 1<<i
;
751 /* Add the light in the 'linked' chain */
752 lpDirect3DLightImpl
->next
= This
->lights
;
753 This
->lights
= lpDirect3DLightImpl
;
755 /* Attach the light to the viewport */
756 lpDirect3DLightImpl
->active_viewport
= This
;
758 /* If active, activate the light */
759 if (This
->active_device
!= NULL
) {
760 lpDirect3DLightImpl
->activate(lpDirect3DLightImpl
);
763 LeaveCriticalSection(&ddraw_cs
);
767 /*****************************************************************************
768 * IDirect3DViewport3::DeleteLight
770 * Deletes a light from the viewports' light list
773 * lpDirect3DLight: Light to delete
777 * DDERR_INVALIDPARAMS if the light wasn't found
779 *****************************************************************************/
780 static HRESULT WINAPI
781 IDirect3DViewportImpl_DeleteLight(IDirect3DViewport3
*iface
,
782 IDirect3DLight
*lpDirect3DLight
)
784 IDirect3DViewportImpl
*This
= (IDirect3DViewportImpl
*)iface
;
785 IDirect3DLightImpl
*lpDirect3DLightImpl
= (IDirect3DLightImpl
*)lpDirect3DLight
;
786 IDirect3DLightImpl
*cur_light
, *prev_light
= NULL
;
788 TRACE("(%p)->(%p)\n", This
, lpDirect3DLight
);
790 EnterCriticalSection(&ddraw_cs
);
791 cur_light
= This
->lights
;
792 while (cur_light
!= NULL
) {
793 if (cur_light
== lpDirect3DLightImpl
) {
794 lpDirect3DLightImpl
->desactivate(lpDirect3DLightImpl
);
795 if (prev_light
== NULL
) This
->lights
= cur_light
->next
;
796 else prev_light
->next
= cur_light
->next
;
797 /* Detach the light to the viewport */
798 cur_light
->active_viewport
= NULL
;
800 This
->map_lights
&= ~(1<<lpDirect3DLightImpl
->dwLightIndex
);
801 LeaveCriticalSection(&ddraw_cs
);
804 prev_light
= cur_light
;
805 cur_light
= cur_light
->next
;
807 LeaveCriticalSection(&ddraw_cs
);
809 return DDERR_INVALIDPARAMS
;
812 /*****************************************************************************
813 * IDirect3DViewport::NextLight
815 * Enumerates the lights associated with the viewport
818 * lpDirect3DLight: Light to start with
819 * lplpDirect3DLight: Address to store the successor to
822 * D3D_OK, because it's a stub
824 *****************************************************************************/
825 static HRESULT WINAPI
826 IDirect3DViewportImpl_NextLight(IDirect3DViewport3
*iface
,
827 IDirect3DLight
*lpDirect3DLight
,
828 IDirect3DLight
**lplpDirect3DLight
,
831 IDirect3DViewportImpl
*This
= (IDirect3DViewportImpl
*)iface
;
832 FIXME("(%p)->(%p,%p,%08x): stub!\n", This
, lpDirect3DLight
, lplpDirect3DLight
, dwFlags
);
836 /*****************************************************************************
837 * IDirect3DViewport2 Methods.
838 *****************************************************************************/
840 /*****************************************************************************
841 * IDirect3DViewport3::GetViewport2
843 * Returns the currently set viewport in a D3DVIEWPORT2 structure.
844 * Similar to IDirect3DViewport3::GetViewport
847 * lpData: Pointer to the structure to fill
851 * DDERR_INVALIDPARAMS if the viewport was set with
852 * IDirect3DViewport3::SetViewport
853 * DDERR_INVALIDPARAMS if Data is NULL
855 *****************************************************************************/
856 static HRESULT WINAPI
857 IDirect3DViewportImpl_GetViewport2(IDirect3DViewport3
*iface
,
858 D3DVIEWPORT2
*lpData
)
860 IDirect3DViewportImpl
*This
= (IDirect3DViewportImpl
*)iface
;
862 TRACE("(%p)->(%p)\n", This
, lpData
);
864 EnterCriticalSection(&ddraw_cs
);
865 if (This
->use_vp2
!= 1) {
866 ERR(" Requesting to get a D3DVIEWPORT2 struct where a D3DVIEWPORT was set !\n");
867 LeaveCriticalSection(&ddraw_cs
);
868 return DDERR_INVALIDPARAMS
;
870 dwSize
= lpData
->dwSize
;
871 memset(lpData
, 0, dwSize
);
872 memcpy(lpData
, &(This
->viewports
.vp2
), dwSize
);
874 if (TRACE_ON(d3d7
)) {
875 TRACE(" returning D3DVIEWPORT2 :\n");
876 _dump_D3DVIEWPORT2(lpData
);
879 LeaveCriticalSection(&ddraw_cs
);
883 /*****************************************************************************
884 * IDirect3DViewport3::SetViewport2
886 * Sets the viewport from a D3DVIEWPORT2 structure
889 * lpData: Viewport to set
894 *****************************************************************************/
895 static HRESULT WINAPI
896 IDirect3DViewportImpl_SetViewport2(IDirect3DViewport3
*iface
,
897 D3DVIEWPORT2
*lpData
)
899 IDirect3DViewportImpl
*This
= (IDirect3DViewportImpl
*)iface
;
900 LPDIRECT3DVIEWPORT3 current_viewport
;
901 TRACE("(%p/%p)->(%p)\n", This
, iface
, lpData
);
903 if (TRACE_ON(d3d7
)) {
904 TRACE(" getting D3DVIEWPORT2 :\n");
905 _dump_D3DVIEWPORT2(lpData
);
908 EnterCriticalSection(&ddraw_cs
);
910 memset(&(This
->viewports
.vp2
), 0, sizeof(This
->viewports
.vp2
));
911 memcpy(&(This
->viewports
.vp2
), lpData
, lpData
->dwSize
);
913 if (This
->active_device
) {
914 IDirect3DDevice3
*d3d_device3
= (IDirect3DDevice3
*)&This
->active_device
->IDirect3DDevice3_vtbl
;
915 IDirect3DDevice3_GetCurrentViewport(d3d_device3
, ¤t_viewport
);
916 if (current_viewport
) {
917 if ((IDirect3DViewportImpl
*)current_viewport
== This
) This
->activate(This
, FALSE
);
918 IDirect3DViewport3_Release(current_viewport
);
921 LeaveCriticalSection(&ddraw_cs
);
926 /*****************************************************************************
927 * IDirect3DViewport3 Methods.
928 *****************************************************************************/
930 /*****************************************************************************
931 * IDirect3DViewport3::SetBackgroundDepth2
933 * Sets a IDirectDrawSurface4 surface as the background depth surface
936 * lpDDS: Surface to set
939 * D3D_OK, because it's stub
941 *****************************************************************************/
942 static HRESULT WINAPI
943 IDirect3DViewportImpl_SetBackgroundDepth2(IDirect3DViewport3
*iface
,
944 IDirectDrawSurface4
*lpDDS
)
946 IDirect3DViewportImpl
*This
= (IDirect3DViewportImpl
*)iface
;
947 FIXME("(%p)->(%p): stub!\n", This
, lpDDS
);
951 /*****************************************************************************
952 * IDirect3DViewport3::GetBackgroundDepth2
954 * Returns the IDirect3DSurface4 interface to the background depth surface
957 * lplpDDS: Address to store the interface pointer at
958 * lpValid: Set to true if a surface is assigned
961 * D3D_OK because it's a stub
963 *****************************************************************************/
964 static HRESULT WINAPI
965 IDirect3DViewportImpl_GetBackgroundDepth2(IDirect3DViewport3
*iface
,
966 IDirectDrawSurface4
**lplpDDS
,
969 IDirect3DViewportImpl
*This
= (IDirect3DViewportImpl
*)iface
;
970 FIXME("(%p/%p)->(%p,%p): stub!\n", This
, iface
, lplpDDS
, lpValid
);
974 /*****************************************************************************
975 * IDirect3DViewport3::Clear2
977 * Another clearing method
980 * Count: Number of rectangles to clear
981 * Rects: Rectangle array to clear
982 * Flags: Some flags :)
983 * Color: Color to fill the render target with
984 * Z: Value to fill the depth buffer with
985 * Stencil: Value to fill the stencil bits with
989 *****************************************************************************/
990 static HRESULT WINAPI
991 IDirect3DViewportImpl_Clear2(IDirect3DViewport3
*iface
,
999 IDirect3DViewportImpl
*This
= (IDirect3DViewportImpl
*)iface
;
1001 LPDIRECT3DVIEWPORT3 current_viewport
;
1002 IDirect3DDevice3
*d3d_device3
;
1003 TRACE("(%p)->(%08x,%p,%08x,%08x,%f,%08x)\n", This
, dwCount
, lpRects
, dwFlags
, dwColor
, dvZ
, dwStencil
);
1005 EnterCriticalSection(&ddraw_cs
);
1006 if (This
->active_device
== NULL
) {
1007 ERR(" Trying to clear a viewport not attached to a device !\n");
1008 LeaveCriticalSection(&ddraw_cs
);
1009 return D3DERR_VIEWPORTHASNODEVICE
;
1011 d3d_device3
= (IDirect3DDevice3
*)&This
->active_device
->IDirect3DDevice3_vtbl
;
1012 /* Need to temporarily activate viewport to clear it. Previously active one will be restored
1014 This
->activate(This
, TRUE
);
1016 hr
= IDirect3DDevice7_Clear((IDirect3DDevice7
*)This
->active_device
,
1017 dwCount
, lpRects
, dwFlags
, dwColor
, dvZ
, dwStencil
);
1018 IDirect3DDevice3_GetCurrentViewport(d3d_device3
, ¤t_viewport
);
1019 if(current_viewport
) {
1020 IDirect3DViewportImpl
*vp
= (IDirect3DViewportImpl
*)current_viewport
;
1021 vp
->activate(vp
, TRUE
);
1022 IDirect3DViewport3_Release(current_viewport
);
1024 LeaveCriticalSection(&ddraw_cs
);
1028 /*****************************************************************************
1030 *****************************************************************************/
1032 const IDirect3DViewport3Vtbl IDirect3DViewport3_Vtbl
=
1034 /*** IUnknown Methods ***/
1035 IDirect3DViewportImpl_QueryInterface
,
1036 IDirect3DViewportImpl_AddRef
,
1037 IDirect3DViewportImpl_Release
,
1038 /*** IDirect3DViewport Methods */
1039 IDirect3DViewportImpl_Initialize
,
1040 IDirect3DViewportImpl_GetViewport
,
1041 IDirect3DViewportImpl_SetViewport
,
1042 IDirect3DViewportImpl_TransformVertices
,
1043 IDirect3DViewportImpl_LightElements
,
1044 IDirect3DViewportImpl_SetBackground
,
1045 IDirect3DViewportImpl_GetBackground
,
1046 IDirect3DViewportImpl_SetBackgroundDepth
,
1047 IDirect3DViewportImpl_GetBackgroundDepth
,
1048 IDirect3DViewportImpl_Clear
,
1049 IDirect3DViewportImpl_AddLight
,
1050 IDirect3DViewportImpl_DeleteLight
,
1051 IDirect3DViewportImpl_NextLight
,
1052 /*** IDirect3DViewport2 Methods ***/
1053 IDirect3DViewportImpl_GetViewport2
,
1054 IDirect3DViewportImpl_SetViewport2
,
1055 /*** IDirect3DViewport3 Methods ***/
1056 IDirect3DViewportImpl_SetBackgroundDepth2
,
1057 IDirect3DViewportImpl_GetBackgroundDepth2
,
1058 IDirect3DViewportImpl_Clear2
,