1999-01-03 18:00:19 +01:00
|
|
|
/* Direct3D Viewport
|
2002-03-10 00:29:33 +01:00
|
|
|
* Copyright (c) 1998 Lionel ULMER
|
2008-10-18 19:19:45 +02:00
|
|
|
* Copyright (c) 2006-2007 Stefan DÖSINGER
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-10 00:29:33 +01:00
|
|
|
*/
|
1999-01-03 18:00:19 +01:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "config.h"
|
2006-06-09 19:36:12 +02:00
|
|
|
#include "wine/port.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
#include "ddraw_private.h"
|
1999-01-03 18:00:19 +01:00
|
|
|
|
2010-08-19 18:57:50 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
|
1999-01-03 18:00:19 +01:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* Helper functions
|
|
|
|
*****************************************************************************/
|
1999-04-19 16:56:29 +02:00
|
|
|
|
2012-04-09 20:43:40 +02:00
|
|
|
static void update_clip_space(struct d3d_device *device,
|
2011-12-21 21:34:56 +01:00
|
|
|
struct wined3d_vec3 *scale, struct wined3d_vec3 *offset)
|
|
|
|
{
|
|
|
|
D3DMATRIX clip_space =
|
|
|
|
{
|
|
|
|
scale->x, 0.0f, 0.0f, 0.0f,
|
|
|
|
0.0f, scale->y, 0.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, scale->z, 0.0f,
|
|
|
|
offset->x, offset->y, offset->z, 1.0f,
|
|
|
|
};
|
|
|
|
D3DMATRIX projection;
|
|
|
|
|
|
|
|
multiply_matrix(&projection, &clip_space, &device->legacy_projection);
|
2012-09-12 11:30:52 +02:00
|
|
|
wined3d_device_set_transform(device->wined3d_device,
|
2012-01-11 21:27:32 +01:00
|
|
|
WINED3D_TS_PROJECTION, (struct wined3d_matrix *)&projection);
|
2012-09-12 11:30:52 +02:00
|
|
|
device->legacy_clipspace = clip_space;
|
2011-12-21 21:34:56 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* viewport_activate
|
|
|
|
*
|
|
|
|
* activates the viewport using IDirect3DDevice7::SetViewport
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-14 22:04:32 +01:00
|
|
|
void viewport_activate(struct d3d_viewport *This, BOOL ignore_lights)
|
2011-04-21 22:39:28 +02:00
|
|
|
{
|
2011-12-21 21:34:56 +01:00
|
|
|
struct wined3d_vec3 scale, offset;
|
2003-05-20 01:03:38 +02:00
|
|
|
D3DVIEWPORT7 vp;
|
1999-01-03 18:00:19 +01:00
|
|
|
|
2011-04-21 22:39:28 +02:00
|
|
|
if (!ignore_lights)
|
|
|
|
{
|
2012-03-13 20:31:37 +01:00
|
|
|
struct d3d_light *light;
|
2008-04-10 22:11:36 +02:00
|
|
|
|
2011-04-21 22:39:28 +02:00
|
|
|
/* Activate all the lights associated with this context */
|
2012-03-13 20:31:37 +01:00
|
|
|
LIST_FOR_EACH_ENTRY(light, &This->light_list, struct d3d_light, entry)
|
2010-08-17 19:03:23 +02:00
|
|
|
{
|
|
|
|
light_activate(light);
|
2008-04-10 22:11:36 +02:00
|
|
|
}
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
2003-05-20 01:03:38 +02:00
|
|
|
|
2018-11-12 15:13:06 +01:00
|
|
|
if (This->version == DDRAW_VIEWPORT_VERSION_NONE)
|
|
|
|
{
|
|
|
|
TRACE("Viewport data was not set.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-05-20 01:03:38 +02:00
|
|
|
/* And copy the values in the structure used by the device */
|
2018-11-12 15:13:05 +01:00
|
|
|
if (This->version == DDRAW_VIEWPORT_VERSION_2)
|
2010-09-08 11:24:49 +02:00
|
|
|
{
|
2003-05-20 01:03:38 +02:00
|
|
|
vp.dwX = This->viewports.vp2.dwX;
|
2010-09-08 11:24:49 +02:00
|
|
|
vp.dwY = This->viewports.vp2.dwY;
|
|
|
|
vp.dwHeight = This->viewports.vp2.dwHeight;
|
|
|
|
vp.dwWidth = This->viewports.vp2.dwWidth;
|
2011-12-21 21:34:56 +01:00
|
|
|
vp.dvMinZ = 0.0f;
|
|
|
|
vp.dvMaxZ = 1.0f;
|
|
|
|
|
|
|
|
scale.x = 2.0f / This->viewports.vp2.dvClipWidth;
|
|
|
|
scale.y = 2.0f / This->viewports.vp2.dvClipHeight;
|
|
|
|
scale.z = 1.0f / (This->viewports.vp2.dvMaxZ - This->viewports.vp2.dvMinZ);
|
|
|
|
offset.x = -2.0f * This->viewports.vp2.dvClipX / This->viewports.vp2.dvClipWidth - 1.0f;
|
|
|
|
offset.y = -2.0f * This->viewports.vp2.dvClipY / This->viewports.vp2.dvClipHeight + 1.0f;
|
|
|
|
offset.z = -This->viewports.vp2.dvMinZ / (This->viewports.vp2.dvMaxZ - This->viewports.vp2.dvMinZ);
|
2010-09-08 11:24:49 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-05-20 01:03:38 +02:00
|
|
|
vp.dwX = This->viewports.vp1.dwX;
|
2010-09-08 11:24:49 +02:00
|
|
|
vp.dwY = This->viewports.vp1.dwY;
|
|
|
|
vp.dwHeight = This->viewports.vp1.dwHeight;
|
|
|
|
vp.dwWidth = This->viewports.vp1.dwWidth;
|
2011-12-21 21:34:56 +01:00
|
|
|
vp.dvMinZ = 0.0f;
|
|
|
|
vp.dvMaxZ = 1.0f;
|
|
|
|
|
|
|
|
scale.x = 2.0f * This->viewports.vp1.dvScaleX / This->viewports.vp1.dwWidth;
|
|
|
|
scale.y = 2.0f * This->viewports.vp1.dvScaleY / This->viewports.vp1.dwHeight;
|
|
|
|
scale.z = 1.0f;
|
|
|
|
offset.x = 0.0f;
|
|
|
|
offset.y = 0.0f;
|
|
|
|
offset.z = 0.0f;
|
2003-05-20 01:03:38 +02:00
|
|
|
}
|
2009-09-01 09:09:37 +02:00
|
|
|
|
2011-12-21 21:34:56 +01:00
|
|
|
update_clip_space(This->active_device, &scale, &offset);
|
2011-10-17 15:58:51 +02:00
|
|
|
IDirect3DDevice7_SetViewport(&This->active_device->IDirect3DDevice7_iface, &vp);
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* _dump_D3DVIEWPORT, _dump_D3DVIEWPORT2
|
|
|
|
*
|
|
|
|
* Writes viewport information to TRACE
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2007-04-21 23:16:34 +02:00
|
|
|
static void _dump_D3DVIEWPORT(const D3DVIEWPORT *lpvp)
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
2006-10-10 19:23:27 +02:00
|
|
|
TRACE(" - dwSize = %d dwX = %d dwY = %d\n",
|
2010-09-08 11:24:49 +02:00
|
|
|
lpvp->dwSize, lpvp->dwX, lpvp->dwY);
|
2006-10-10 19:23:27 +02:00
|
|
|
TRACE(" - dwWidth = %d dwHeight = %d\n",
|
2010-09-08 11:24:49 +02:00
|
|
|
lpvp->dwWidth, lpvp->dwHeight);
|
2002-11-21 22:04:16 +01:00
|
|
|
TRACE(" - dvScaleX = %f dvScaleY = %f\n",
|
2010-09-08 11:24:49 +02:00
|
|
|
lpvp->dvScaleX, lpvp->dvScaleY);
|
2002-11-21 22:04:16 +01:00
|
|
|
TRACE(" - dvMaxX = %f dvMaxY = %f\n",
|
2010-09-08 11:24:49 +02:00
|
|
|
lpvp->dvMaxX, lpvp->dvMaxY);
|
2002-11-21 22:04:16 +01:00
|
|
|
TRACE(" - dvMinZ = %f dvMaxZ = %f\n",
|
2010-09-08 11:24:49 +02:00
|
|
|
lpvp->dvMinZ, lpvp->dvMaxZ);
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2007-04-21 23:16:34 +02:00
|
|
|
static void _dump_D3DVIEWPORT2(const D3DVIEWPORT2 *lpvp)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2006-10-10 19:23:27 +02:00
|
|
|
TRACE(" - dwSize = %d dwX = %d dwY = %d\n",
|
2010-09-08 11:24:49 +02:00
|
|
|
lpvp->dwSize, lpvp->dwX, lpvp->dwY);
|
2006-10-10 19:23:27 +02:00
|
|
|
TRACE(" - dwWidth = %d dwHeight = %d\n",
|
2010-09-08 11:24:49 +02:00
|
|
|
lpvp->dwWidth, lpvp->dwHeight);
|
2002-11-21 22:04:16 +01:00
|
|
|
TRACE(" - dvClipX = %f dvClipY = %f\n",
|
2010-09-08 11:24:49 +02:00
|
|
|
lpvp->dvClipX, lpvp->dvClipY);
|
2002-11-21 22:04:16 +01:00
|
|
|
TRACE(" - dvClipWidth = %f dvClipHeight = %f\n",
|
2010-09-08 11:24:49 +02:00
|
|
|
lpvp->dvClipWidth, lpvp->dvClipHeight);
|
2002-11-21 22:04:16 +01:00
|
|
|
TRACE(" - dvMinZ = %f dvMaxZ = %f\n",
|
2010-09-08 11:24:49 +02:00
|
|
|
lpvp->dvMinZ, lpvp->dvMaxZ);
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2012-03-14 22:04:32 +01:00
|
|
|
static inline struct d3d_viewport *impl_from_IDirect3DViewport3(IDirect3DViewport3 *iface)
|
2011-10-04 00:14:42 +02:00
|
|
|
{
|
2012-03-14 22:04:32 +01:00
|
|
|
return CONTAINING_RECORD(iface, struct d3d_viewport, IDirect3DViewport3_iface);
|
2011-10-04 00:14:42 +02:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IUnknown Methods.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DViewport3::QueryInterface
|
|
|
|
*
|
|
|
|
* A normal QueryInterface. Can query all interface versions and the
|
|
|
|
* IUnknown interface. The VTables of the different versions
|
|
|
|
* are equal
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* refiid: Interface id queried for
|
|
|
|
* obj: Address to write the interface pointer to
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* S_OK on success.
|
|
|
|
* E_NOINTERFACE if the requested interface wasn't found
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-14 22:04:32 +01:00
|
|
|
static HRESULT WINAPI d3d_viewport_QueryInterface(IDirect3DViewport3 *iface, REFIID riid, void **object)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2010-09-08 11:24:49 +02:00
|
|
|
TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
|
2002-11-21 22:04:16 +01:00
|
|
|
|
2010-09-08 11:24:49 +02:00
|
|
|
if (IsEqualGUID(&IID_IDirect3DViewport3, riid)
|
|
|
|
|| IsEqualGUID(&IID_IDirect3DViewport2, riid)
|
|
|
|
|| IsEqualGUID(&IID_IDirect3DViewport, riid)
|
|
|
|
|| IsEqualGUID(&IID_IUnknown, riid))
|
|
|
|
{
|
2009-01-21 09:56:13 +01:00
|
|
|
IDirect3DViewport3_AddRef(iface);
|
2010-09-08 11:24:49 +02:00
|
|
|
*object = iface;
|
|
|
|
return S_OK;
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
2010-09-08 11:24:49 +02:00
|
|
|
|
|
|
|
WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
|
|
|
|
|
|
|
|
*object = NULL;
|
2006-06-09 19:36:12 +02:00
|
|
|
return E_NOINTERFACE;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DViewport3::AddRef
|
|
|
|
*
|
|
|
|
* Increases the refcount.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* The new refcount
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-14 22:04:32 +01:00
|
|
|
static ULONG WINAPI d3d_viewport_AddRef(IDirect3DViewport3 *iface)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2012-03-14 22:04:32 +01:00
|
|
|
struct d3d_viewport *viewport = impl_from_IDirect3DViewport3(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&viewport->ref);
|
2005-01-09 18:29:21 +01:00
|
|
|
|
2012-03-14 22:04:32 +01:00
|
|
|
TRACE("%p increasing refcount to %u.\n", viewport, ref);
|
2005-01-09 18:29:21 +01:00
|
|
|
|
|
|
|
return ref;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DViewport3::Release
|
|
|
|
*
|
|
|
|
* Reduces the refcount. If it falls to 0, the interface is released
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* The new refcount
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-14 22:04:32 +01:00
|
|
|
static ULONG WINAPI d3d_viewport_Release(IDirect3DViewport3 *iface)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2012-03-14 22:04:32 +01:00
|
|
|
struct d3d_viewport *viewport = impl_from_IDirect3DViewport3(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&viewport->ref);
|
2005-01-09 18:29:21 +01:00
|
|
|
|
2012-03-14 22:04:32 +01:00
|
|
|
TRACE("%p decreasing refcount to %u.\n", viewport, ref);
|
|
|
|
|
|
|
|
if (!ref)
|
2018-02-13 10:32:47 +01:00
|
|
|
heap_free(viewport);
|
2005-01-09 18:29:21 +01:00
|
|
|
|
|
|
|
return ref;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DViewport Methods.
|
|
|
|
*****************************************************************************/
|
1999-01-03 18:00:19 +01:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DViewport3::Initialize
|
|
|
|
*
|
|
|
|
* No-op initialization.
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* Direct3D: The direct3D device this viewport is assigned to
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* DDERR_ALREADYINITIALIZED
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-14 22:04:32 +01:00
|
|
|
static HRESULT WINAPI d3d_viewport_Initialize(IDirect3DViewport3 *iface, IDirect3D *d3d)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2012-03-14 22:04:32 +01:00
|
|
|
TRACE("iface %p, d3d %p.\n", iface, d3d);
|
2010-08-19 18:57:50 +02:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
return DDERR_ALREADYINITIALIZED;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2018-04-13 00:07:42 +02:00
|
|
|
static HRESULT WINAPI d3d_viewport_GetViewport(IDirect3DViewport3 *iface, D3DVIEWPORT *vp)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2018-04-13 00:07:42 +02:00
|
|
|
struct d3d_viewport *viewport = impl_from_IDirect3DViewport3(iface);
|
|
|
|
DWORD size;
|
2010-08-19 18:57:50 +02:00
|
|
|
|
2018-04-13 00:07:42 +02:00
|
|
|
TRACE("iface %p, vp %p.\n", iface, vp);
|
|
|
|
|
|
|
|
if (!vp)
|
|
|
|
return DDERR_INVALIDPARAMS;
|
2007-05-30 16:27:23 +02:00
|
|
|
|
2018-11-12 15:13:05 +01:00
|
|
|
if (viewport->version == DDRAW_VIEWPORT_VERSION_NONE)
|
|
|
|
{
|
|
|
|
WARN("Viewport data was not set.\n");
|
|
|
|
return D3DERR_VIEWPORTDATANOTSET;
|
|
|
|
}
|
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
|
|
|
|
2018-04-13 00:07:42 +02:00
|
|
|
size = vp->dwSize;
|
2018-11-12 15:13:05 +01:00
|
|
|
if (viewport->version == DDRAW_VIEWPORT_VERSION_1)
|
2018-04-13 00:07:42 +02:00
|
|
|
{
|
|
|
|
memcpy(vp, &viewport->viewports.vp1, size);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-02-15 09:49:16 +01:00
|
|
|
D3DVIEWPORT vp1;
|
2018-04-13 00:07:42 +02:00
|
|
|
|
2010-02-15 09:49:16 +01:00
|
|
|
vp1.dwSize = sizeof(vp1);
|
2018-04-13 00:07:42 +02:00
|
|
|
vp1.dwX = viewport->viewports.vp2.dwX;
|
|
|
|
vp1.dwY = viewport->viewports.vp2.dwY;
|
|
|
|
vp1.dwWidth = viewport->viewports.vp2.dwWidth;
|
|
|
|
vp1.dwHeight = viewport->viewports.vp2.dwHeight;
|
2018-11-12 15:13:05 +01:00
|
|
|
vp1.dvMaxX = 0.0f;
|
|
|
|
vp1.dvMaxY = 0.0f;
|
|
|
|
vp1.dvScaleX = 0.0f;
|
|
|
|
vp1.dvScaleY = 0.0f;
|
2018-04-13 00:07:42 +02:00
|
|
|
vp1.dvMinZ = viewport->viewports.vp2.dvMinZ;
|
|
|
|
vp1.dvMaxZ = viewport->viewports.vp2.dvMaxZ;
|
|
|
|
memcpy(vp, &vp1, size);
|
2010-02-15 09:49:16 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2010-08-19 18:57:50 +02:00
|
|
|
if (TRACE_ON(ddraw))
|
|
|
|
{
|
2002-11-30 20:12:32 +01:00
|
|
|
TRACE(" returning D3DVIEWPORT :\n");
|
2018-04-13 00:07:42 +02:00
|
|
|
_dump_D3DVIEWPORT(vp);
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
2011-11-13 19:52:24 +01:00
|
|
|
|
|
|
|
wined3d_mutex_unlock();
|
2007-05-30 16:27:23 +02:00
|
|
|
|
2018-04-13 00:07:42 +02:00
|
|
|
return D3D_OK;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2018-04-13 00:07:42 +02:00
|
|
|
static HRESULT WINAPI d3d_viewport_SetViewport(IDirect3DViewport3 *iface, D3DVIEWPORT *vp)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2018-04-13 00:07:42 +02:00
|
|
|
struct d3d_viewport *viewport = impl_from_IDirect3DViewport3(iface);
|
|
|
|
struct d3d_device *device = viewport->active_device;
|
2018-04-20 00:55:40 +02:00
|
|
|
struct wined3d_sub_resource_desc rt_desc;
|
|
|
|
struct wined3d_rendertarget_view *rtv;
|
2011-10-04 00:14:42 +02:00
|
|
|
IDirect3DViewport3 *current_viewport;
|
2018-04-20 00:55:40 +02:00
|
|
|
struct ddraw_surface *surface;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2018-04-13 00:07:42 +02:00
|
|
|
TRACE("iface %p, vp %p.\n", iface, vp);
|
|
|
|
|
|
|
|
if (!vp)
|
|
|
|
return DDERR_INVALIDPARAMS;
|
2010-08-19 18:57:50 +02:00
|
|
|
|
2018-11-12 15:13:03 +01:00
|
|
|
if (vp->dwSize != sizeof(*vp))
|
|
|
|
{
|
|
|
|
WARN("Invalid D3DVIEWPORT size %u.\n", vp->dwSize);
|
|
|
|
return DDERR_INVALIDPARAMS;
|
|
|
|
}
|
|
|
|
|
2010-08-19 18:57:50 +02:00
|
|
|
if (TRACE_ON(ddraw))
|
|
|
|
{
|
2002-11-21 22:04:16 +01:00
|
|
|
TRACE(" getting D3DVIEWPORT :\n");
|
2018-04-13 00:07:42 +02:00
|
|
|
_dump_D3DVIEWPORT(vp);
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
1999-01-03 18:00:19 +01:00
|
|
|
|
2018-04-20 00:55:40 +02:00
|
|
|
if (!device)
|
|
|
|
{
|
|
|
|
WARN("Viewport not bound to a device, returning D3DERR_VIEWPORTHASNODEVICE.\n");
|
|
|
|
return D3DERR_VIEWPORTHASNODEVICE;
|
|
|
|
}
|
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
|
|
|
|
2018-04-20 00:55:40 +02:00
|
|
|
if (device->version > 1)
|
|
|
|
{
|
|
|
|
if (!(rtv = wined3d_device_get_rendertarget_view(device->wined3d_device, 0)))
|
|
|
|
{
|
|
|
|
wined3d_mutex_unlock();
|
|
|
|
return DDERR_INVALIDCAPS;
|
|
|
|
}
|
|
|
|
surface = wined3d_rendertarget_view_get_sub_resource_parent(rtv);
|
|
|
|
wined3d_texture_get_sub_resource_desc(surface->wined3d_texture, surface->sub_resource_idx, &rt_desc);
|
|
|
|
|
|
|
|
if (vp->dwX > rt_desc.width || vp->dwWidth > rt_desc.width - vp->dwX
|
|
|
|
|| vp->dwY > rt_desc.height || vp->dwHeight > rt_desc.height - vp->dwY)
|
|
|
|
{
|
|
|
|
WARN("Invalid viewport, returning DDERR_INVALIDPARAMS.\n");
|
|
|
|
wined3d_mutex_unlock();
|
|
|
|
return DDERR_INVALIDPARAMS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-12 15:13:05 +01:00
|
|
|
viewport->version = DDRAW_VIEWPORT_VERSION_1;
|
2018-11-12 15:13:03 +01:00
|
|
|
viewport->viewports.vp1 = *vp;
|
2003-06-05 01:39:13 +02:00
|
|
|
|
2018-04-13 00:07:42 +02:00
|
|
|
/* Empirical testing on a couple of d3d1 games showed that these values
|
|
|
|
* should be ignored. */
|
2018-11-12 15:13:03 +01:00
|
|
|
viewport->viewports.vp1.dvMinZ = 0.0f;
|
|
|
|
viewport->viewports.vp1.dvMaxZ = 1.0f;
|
2003-10-14 03:16:42 +02:00
|
|
|
|
2018-04-20 00:55:40 +02:00
|
|
|
if (SUCCEEDED(IDirect3DDevice3_GetCurrentViewport(&device->IDirect3DDevice3_iface, ¤t_viewport)))
|
2013-01-26 13:39:42 +01:00
|
|
|
{
|
2018-04-20 00:55:40 +02:00
|
|
|
if (current_viewport == iface)
|
|
|
|
viewport_activate(viewport, FALSE);
|
|
|
|
IDirect3DViewport3_Release(current_viewport);
|
2003-10-14 03:16:42 +02:00
|
|
|
}
|
2011-11-13 19:52:24 +01:00
|
|
|
|
|
|
|
wined3d_mutex_unlock();
|
2003-10-14 03:16:42 +02:00
|
|
|
|
2018-04-13 00:07:42 +02:00
|
|
|
return D3D_OK;
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DViewport3::TransformVertices
|
|
|
|
*
|
|
|
|
* Transforms vertices by the transformation matrix.
|
|
|
|
*
|
2007-07-31 18:57:34 +02:00
|
|
|
* This function is pretty similar to IDirect3DVertexBuffer7::ProcessVertices,
|
|
|
|
* so it's tempting to forward it to there. However, there are some
|
2007-07-01 20:23:02 +02:00
|
|
|
* tiny differences. First, the lpOffscreen flag that is reported back,
|
2008-01-23 15:16:30 +01:00
|
|
|
* then there is the homogeneous vertex that is generated. Also there's a lack
|
2007-07-01 20:23:02 +02:00
|
|
|
* of FVFs, but still a custom stride. Last, the d3d1 - d3d3 viewport has some
|
2007-07-31 18:57:34 +02:00
|
|
|
* settings (scale) that d3d7 and wined3d do not have. All in all wrapping to
|
2007-07-01 20:23:02 +02:00
|
|
|
* ProcessVertices doesn't pay of in terms of wrapper code needed and code
|
|
|
|
* reused.
|
|
|
|
*
|
2006-06-09 19:36:12 +02:00
|
|
|
* Params:
|
|
|
|
* dwVertexCount: The number of vertices to be transformed
|
2016-08-31 23:01:26 +02:00
|
|
|
* data: Pointer to the vertex input / output data.
|
2006-06-09 19:36:12 +02:00
|
|
|
* dwFlags: D3DTRANSFORM_CLIPPED or D3DTRANSFORM_UNCLIPPED
|
2016-08-31 23:01:25 +02:00
|
|
|
* offscreen: Logical AND of the planes that clipped the vertices if clipping
|
|
|
|
* is on. 0 if clipping is off.
|
2006-06-09 19:36:12 +02:00
|
|
|
*
|
|
|
|
* Returns:
|
2007-07-01 20:23:02 +02:00
|
|
|
* D3D_OK on success
|
|
|
|
* D3DERR_VIEWPORTHASNODEVICE if the viewport is not assigned to a device
|
|
|
|
* DDERR_INVALIDPARAMS if no clipping flag is specified
|
2006-06-09 19:36:12 +02:00
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2016-08-31 23:01:24 +02:00
|
|
|
struct transform_vertices_vertex
|
|
|
|
{
|
|
|
|
float x, y, z, w; /* w is unused in input data. */
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
DWORD p[4];
|
|
|
|
} payload;
|
|
|
|
};
|
|
|
|
|
2012-03-14 22:04:32 +01:00
|
|
|
static HRESULT WINAPI d3d_viewport_TransformVertices(IDirect3DViewport3 *iface,
|
2016-08-31 23:01:26 +02:00
|
|
|
DWORD dwVertexCount, D3DTRANSFORMDATA *data, DWORD dwFlags, DWORD *offscreen)
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
2012-03-14 22:04:32 +01:00
|
|
|
struct d3d_viewport *viewport = impl_from_IDirect3DViewport3(iface);
|
|
|
|
D3DVIEWPORT vp = viewport->viewports.vp1;
|
2016-10-01 19:39:31 +02:00
|
|
|
D3DMATRIX view_mat, world_mat, proj_mat, mat;
|
2016-08-31 23:01:24 +02:00
|
|
|
struct transform_vertices_vertex *in, *out;
|
2007-07-01 20:23:02 +02:00
|
|
|
float x, y, z, w;
|
|
|
|
unsigned int i;
|
|
|
|
D3DHVERTEX *outH;
|
2016-10-01 19:39:31 +02:00
|
|
|
struct d3d_device *device = viewport->active_device;
|
|
|
|
BOOL activate = device->current_viewport != viewport;
|
2010-08-19 18:57:50 +02:00
|
|
|
|
2016-08-31 23:01:26 +02:00
|
|
|
TRACE("iface %p, vertex_count %u, data %p, flags %#x, offscreen %p.\n",
|
|
|
|
iface, dwVertexCount, data, dwFlags, offscreen);
|
2007-07-01 20:23:02 +02:00
|
|
|
|
|
|
|
/* Tests on windows show that Windows crashes when this occurs,
|
|
|
|
* so don't return the (intuitive) return value
|
2016-10-01 19:39:31 +02:00
|
|
|
if (!device)
|
2007-07-01 20:23:02 +02:00
|
|
|
{
|
|
|
|
WARN("No device active, returning D3DERR_VIEWPORTHASNODEVICE\n");
|
|
|
|
return D3DERR_VIEWPORTHASNODEVICE;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2016-08-31 23:01:26 +02:00
|
|
|
if (!data || data->dwSize != sizeof(*data))
|
|
|
|
{
|
|
|
|
WARN("Transform data is NULL or size is incorrect, returning DDERR_INVALIDPARAMS\n");
|
|
|
|
return DDERR_INVALIDPARAMS;
|
|
|
|
}
|
|
|
|
if (!(dwFlags & (D3DTRANSFORM_UNCLIPPED | D3DTRANSFORM_CLIPPED)))
|
2007-07-01 20:23:02 +02:00
|
|
|
{
|
|
|
|
WARN("No clipping flag passed, returning DDERR_INVALIDPARAMS\n");
|
|
|
|
return DDERR_INVALIDPARAMS;
|
|
|
|
}
|
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
2016-10-01 19:39:31 +02:00
|
|
|
if (activate)
|
|
|
|
viewport_activate(viewport, TRUE);
|
|
|
|
|
|
|
|
wined3d_device_get_transform(device->wined3d_device,
|
2011-11-17 20:11:41 +01:00
|
|
|
D3DTRANSFORMSTATE_VIEW, (struct wined3d_matrix *)&view_mat);
|
2016-10-01 19:39:31 +02:00
|
|
|
wined3d_device_get_transform(device->wined3d_device,
|
2012-01-11 21:27:32 +01:00
|
|
|
WINED3D_TS_WORLD_MATRIX(0), (struct wined3d_matrix *)&world_mat);
|
2016-10-01 19:39:31 +02:00
|
|
|
wined3d_device_get_transform(device->wined3d_device,
|
|
|
|
WINED3D_TS_PROJECTION, (struct wined3d_matrix *)&proj_mat);
|
2011-12-21 21:34:56 +01:00
|
|
|
multiply_matrix(&mat, &view_mat, &world_mat);
|
2016-10-01 19:39:31 +02:00
|
|
|
multiply_matrix(&mat, &proj_mat, &mat);
|
2007-07-01 20:23:02 +02:00
|
|
|
|
2016-08-31 23:01:25 +02:00
|
|
|
/* The pointer is not tested against NULL on Windows. */
|
|
|
|
if (dwFlags & D3DTRANSFORM_CLIPPED)
|
|
|
|
*offscreen = ~0U;
|
|
|
|
else
|
|
|
|
*offscreen = 0;
|
|
|
|
|
2016-08-31 23:01:26 +02:00
|
|
|
outH = data->lpHOut;
|
2007-07-01 20:23:02 +02:00
|
|
|
for(i = 0; i < dwVertexCount; i++)
|
|
|
|
{
|
2016-08-31 23:01:26 +02:00
|
|
|
in = (struct transform_vertices_vertex *)((char *)data->lpIn + data->dwInSize * i);
|
|
|
|
out = (struct transform_vertices_vertex *)((char *)data->lpOut + data->dwOutSize * i);
|
2016-08-31 23:01:24 +02:00
|
|
|
|
|
|
|
x = (in->x * mat._11) + (in->y * mat._21) + (in->z * mat._31) + mat._41;
|
|
|
|
y = (in->x * mat._12) + (in->y * mat._22) + (in->z * mat._32) + mat._42;
|
|
|
|
z = (in->x * mat._13) + (in->y * mat._23) + (in->z * mat._33) + mat._43;
|
|
|
|
w = (in->x * mat._14) + (in->y * mat._24) + (in->z * mat._34) + mat._44;
|
2007-07-01 20:23:02 +02:00
|
|
|
|
|
|
|
if(dwFlags & D3DTRANSFORM_CLIPPED)
|
|
|
|
{
|
|
|
|
/* If clipping is enabled, Windows assumes that outH is
|
2016-10-01 19:39:31 +02:00
|
|
|
* a valid pointer. */
|
|
|
|
outH[i].u1.hx = (x - device->legacy_clipspace._41 * w) / device->legacy_clipspace._11;
|
|
|
|
outH[i].u2.hy = (y - device->legacy_clipspace._42 * w) / device->legacy_clipspace._22;
|
|
|
|
outH[i].u3.hz = (z - device->legacy_clipspace._43 * w) / device->legacy_clipspace._33;
|
2007-07-01 20:23:02 +02:00
|
|
|
|
|
|
|
outH[i].dwFlags = 0;
|
2016-10-01 19:39:31 +02:00
|
|
|
if (x > w)
|
2007-07-01 20:23:02 +02:00
|
|
|
outH[i].dwFlags |= D3DCLIP_RIGHT;
|
2016-10-01 19:39:31 +02:00
|
|
|
if (x < -w)
|
2007-07-01 20:23:02 +02:00
|
|
|
outH[i].dwFlags |= D3DCLIP_LEFT;
|
2016-10-01 19:39:31 +02:00
|
|
|
if (y > w)
|
2007-07-01 20:23:02 +02:00
|
|
|
outH[i].dwFlags |= D3DCLIP_TOP;
|
2016-10-01 19:39:31 +02:00
|
|
|
if (y < -w)
|
2007-07-01 20:23:02 +02:00
|
|
|
outH[i].dwFlags |= D3DCLIP_BOTTOM;
|
2016-10-01 19:39:31 +02:00
|
|
|
if (z < 0.0f)
|
2007-07-01 20:23:02 +02:00
|
|
|
outH[i].dwFlags |= D3DCLIP_FRONT;
|
2016-10-01 19:39:31 +02:00
|
|
|
if (z > w)
|
2007-07-01 20:23:02 +02:00
|
|
|
outH[i].dwFlags |= D3DCLIP_BACK;
|
|
|
|
|
2016-08-31 23:01:25 +02:00
|
|
|
*offscreen &= outH[i].dwFlags;
|
|
|
|
|
2007-07-01 20:23:02 +02:00
|
|
|
if(outH[i].dwFlags)
|
|
|
|
{
|
|
|
|
/* Looks like native just drops the vertex, leaves whatever data
|
|
|
|
* it has in the output buffer and goes on with the next vertex.
|
|
|
|
* The exact scheme hasn't been figured out yet, but windows
|
2007-07-31 18:57:34 +02:00
|
|
|
* definitely writes something there.
|
2007-07-01 20:23:02 +02:00
|
|
|
*/
|
2016-08-31 23:01:24 +02:00
|
|
|
out->x = x;
|
|
|
|
out->y = y;
|
|
|
|
out->z = z;
|
|
|
|
out->w = w;
|
2007-07-01 20:23:02 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
w = 1 / w;
|
|
|
|
x *= w; y *= w; z *= w;
|
|
|
|
|
2016-10-01 19:39:31 +02:00
|
|
|
out->x = (x + 1.0f) * vp.dwWidth * 0.5 + vp.dwX;
|
|
|
|
out->y = (-y + 1.0f) * vp.dwHeight * 0.5 + vp.dwY;
|
2016-08-31 23:01:24 +02:00
|
|
|
out->z = z;
|
|
|
|
out->w = w;
|
|
|
|
out->payload = in->payload;
|
2007-07-01 20:23:02 +02:00
|
|
|
}
|
|
|
|
|
2016-10-01 19:39:31 +02:00
|
|
|
if (activate && device->current_viewport)
|
|
|
|
viewport_activate(device->current_viewport, TRUE);
|
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
2007-07-01 20:23:02 +02:00
|
|
|
|
|
|
|
TRACE("All done\n");
|
2002-11-21 22:04:16 +01:00
|
|
|
return DD_OK;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DViewport3::LightElements
|
|
|
|
*
|
|
|
|
* The DirectX 5.0 sdk says that it's not implemented
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* ?
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* DDERR_UNSUPPORTED
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-14 22:04:32 +01:00
|
|
|
static HRESULT WINAPI d3d_viewport_LightElements(IDirect3DViewport3 *iface,
|
|
|
|
DWORD element_count, D3DLIGHTDATA *data)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2012-03-14 22:04:32 +01:00
|
|
|
TRACE("iface %p, element_count %u, data %p.\n", iface, element_count, data);
|
2010-08-19 18:57:50 +02:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
return DDERR_UNSUPPORTED;
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
1999-01-03 18:00:19 +01:00
|
|
|
|
2014-04-29 22:02:47 +02:00
|
|
|
static HRESULT WINAPI d3d_viewport_SetBackground(IDirect3DViewport3 *iface, D3DMATERIALHANDLE material)
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
2012-03-14 22:04:32 +01:00
|
|
|
struct d3d_viewport *viewport = impl_from_IDirect3DViewport3(iface);
|
2012-03-15 21:49:58 +01:00
|
|
|
struct d3d_material *m;
|
2010-07-29 12:56:57 +02:00
|
|
|
|
2014-04-29 22:02:47 +02:00
|
|
|
TRACE("iface %p, material %#x.\n", iface, material);
|
2006-06-16 23:44:33 +02:00
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
2010-07-29 12:56:57 +02:00
|
|
|
|
2014-04-29 22:02:47 +02:00
|
|
|
if (!(m = ddraw_get_object(&viewport->ddraw->d3ddevice->handle_table, material - 1, DDRAW_HANDLE_MATERIAL)))
|
2006-06-16 23:44:33 +02:00
|
|
|
{
|
2014-04-29 22:02:47 +02:00
|
|
|
WARN("Invalid material handle %#x.\n", material);
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
2006-06-16 23:44:33 +02:00
|
|
|
return DDERR_INVALIDPARAMS;
|
|
|
|
}
|
|
|
|
|
2010-07-29 12:56:57 +02:00
|
|
|
TRACE("Setting background color : %.8e %.8e %.8e %.8e.\n",
|
|
|
|
m->mat.u.diffuse.u1.r, m->mat.u.diffuse.u2.g,
|
|
|
|
m->mat.u.diffuse.u3.b, m->mat.u.diffuse.u4.a);
|
2012-03-14 22:04:32 +01:00
|
|
|
viewport->background = m;
|
2002-12-24 02:07:21 +01:00
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
return D3D_OK;
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DViewport3::GetBackground
|
|
|
|
*
|
|
|
|
* Returns the material handle assigned to the background of the viewport
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* lphMat: Address to store the handle
|
|
|
|
* lpValid: is set to FALSE if no background is set, TRUE if one is set
|
|
|
|
*
|
|
|
|
* Returns:
|
2006-06-16 23:44:33 +02:00
|
|
|
* D3D_OK
|
2006-06-09 19:36:12 +02:00
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-14 22:04:32 +01:00
|
|
|
static HRESULT WINAPI d3d_viewport_GetBackground(IDirect3DViewport3 *iface,
|
|
|
|
D3DMATERIALHANDLE *material, BOOL *valid)
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
2012-03-14 22:04:32 +01:00
|
|
|
struct d3d_viewport *viewport = impl_from_IDirect3DViewport3(iface);
|
2010-08-19 18:57:50 +02:00
|
|
|
|
2012-03-14 22:04:32 +01:00
|
|
|
TRACE("iface %p, material %p, valid %p.\n", iface, material, valid);
|
2006-06-16 23:44:33 +02:00
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
2012-03-14 22:04:32 +01:00
|
|
|
if (valid)
|
|
|
|
*valid = !!viewport->background;
|
|
|
|
if (material)
|
|
|
|
*material = viewport->background ? viewport->background->Handle : 0;
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
2006-06-16 23:44:33 +02:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
return D3D_OK;
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
1999-01-23 13:33:16 +01:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DViewport3::SetBackgroundDepth
|
|
|
|
*
|
2016-08-02 00:10:08 +02:00
|
|
|
* Sets a surface that represents the background depth. Its contents are
|
2006-06-09 19:36:12 +02:00
|
|
|
* used to set the depth buffer in IDirect3DViewport3::Clear
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* lpDDSurface: Surface to set
|
|
|
|
*
|
|
|
|
* Returns: D3D_OK, because it's a stub
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-14 22:04:32 +01:00
|
|
|
static HRESULT WINAPI d3d_viewport_SetBackgroundDepth(IDirect3DViewport3 *iface, IDirectDrawSurface *surface)
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
2012-03-14 22:04:32 +01:00
|
|
|
FIXME("iface %p, surface %p stub!\n", iface, surface);
|
2010-08-19 18:57:50 +02:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
return D3D_OK;
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DViewport3::GetBackgroundDepth
|
|
|
|
*
|
|
|
|
* Returns the surface that represents the depth field
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* lplpDDSurface: Address to store the interface pointer
|
2008-04-02 21:26:42 +02:00
|
|
|
* lpValid: Set to TRUE if a depth is assigned, FALSE otherwise
|
2006-06-09 19:36:12 +02:00
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* D3D_OK, because it's a stub
|
|
|
|
* (DDERR_INVALIDPARAMS if DDSurface of Valid is NULL)
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-14 22:04:32 +01:00
|
|
|
static HRESULT WINAPI d3d_viewport_GetBackgroundDepth(IDirect3DViewport3 *iface,
|
|
|
|
IDirectDrawSurface **surface, BOOL *valid)
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
2012-03-14 22:04:32 +01:00
|
|
|
FIXME("iface %p, surface %p, valid %p stub!\n", iface, surface, valid);
|
2010-08-19 18:57:50 +02:00
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
return DD_OK;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DViewport3::Clear
|
|
|
|
*
|
|
|
|
* Clears the render target and / or the z buffer
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* dwCount: The amount of rectangles to clear. If 0, the whole buffer is
|
|
|
|
* cleared
|
|
|
|
* lpRects: Pointer to the array of rectangles. If NULL, Count must be 0
|
|
|
|
* dwFlags: D3DCLEAR_ZBUFFER and / or D3DCLEAR_TARGET
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* D3D_OK on success
|
|
|
|
* D3DERR_VIEWPORTHASNODEVICE if there's no active device
|
|
|
|
* The return value of IDirect3DDevice7::Clear
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-14 22:04:32 +01:00
|
|
|
static HRESULT WINAPI d3d_viewport_Clear(IDirect3DViewport3 *iface,
|
|
|
|
DWORD rect_count, D3DRECT *rects, DWORD flags)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2012-03-14 22:04:32 +01:00
|
|
|
struct d3d_viewport *This = impl_from_IDirect3DViewport3(iface);
|
2002-12-24 02:07:21 +01:00
|
|
|
DWORD color = 0x00000000;
|
2007-05-30 16:27:23 +02:00
|
|
|
HRESULT hr;
|
2011-10-04 00:14:42 +02:00
|
|
|
IDirect3DViewport3 *current_viewport;
|
2009-01-21 09:56:13 +01:00
|
|
|
IDirect3DDevice3 *d3d_device3;
|
2007-05-30 16:27:23 +02:00
|
|
|
|
2012-03-14 22:04:32 +01:00
|
|
|
TRACE("iface %p, rect_count %u, rects %p, flags %#x.\n", iface, rect_count, rects, flags);
|
2010-08-19 18:57:50 +02:00
|
|
|
|
2013-01-23 15:02:45 +01:00
|
|
|
if (!rects || !rect_count)
|
|
|
|
{
|
|
|
|
WARN("rect_count = %u, rects = %p, ignoring clear\n", rect_count, rects);
|
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
2002-12-24 02:03:04 +01:00
|
|
|
if (This->active_device == NULL) {
|
2014-01-22 12:25:54 +01:00
|
|
|
ERR(" Trying to clear a viewport not attached to a device!\n");
|
2010-09-08 11:24:49 +02:00
|
|
|
return D3DERR_VIEWPORTHASNODEVICE;
|
2002-12-24 02:03:04 +01:00
|
|
|
}
|
2011-10-17 15:58:11 +02:00
|
|
|
d3d_device3 = &This->active_device->IDirect3DDevice3_iface;
|
2007-05-30 16:27:23 +02:00
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
|
|
|
|
2012-03-14 22:04:32 +01:00
|
|
|
if (flags & D3DCLEAR_TARGET)
|
|
|
|
{
|
2014-04-29 22:02:48 +02:00
|
|
|
if (!This->background)
|
|
|
|
WARN("No background material set.\n");
|
2009-09-01 09:09:37 +02:00
|
|
|
else
|
2014-04-29 22:02:48 +02:00
|
|
|
color = D3DRGBA(This->background->mat.u.diffuse.u1.r,
|
|
|
|
This->background->mat.u.diffuse.u2.g,
|
|
|
|
This->background->mat.u.diffuse.u3.b,
|
|
|
|
This->background->mat.u.diffuse.u4.a);
|
2002-12-24 02:07:21 +01:00
|
|
|
}
|
2006-06-09 19:36:12 +02:00
|
|
|
|
2015-03-30 20:18:01 +02:00
|
|
|
/* Need to temporarily activate the viewport to clear it. The previously
|
|
|
|
* active one will be restored afterwards. */
|
2010-08-17 19:03:25 +02:00
|
|
|
viewport_activate(This, TRUE);
|
2008-04-10 22:12:13 +02:00
|
|
|
|
2012-03-14 22:04:32 +01:00
|
|
|
hr = IDirect3DDevice7_Clear(&This->active_device->IDirect3DDevice7_iface, rect_count, rects,
|
|
|
|
flags & (D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET), color, 1.0, 0x00000000);
|
2008-04-10 22:12:13 +02:00
|
|
|
|
2013-01-26 13:39:42 +01:00
|
|
|
if (SUCCEEDED(IDirect3DDevice3_GetCurrentViewport(d3d_device3, ¤t_viewport)))
|
2012-03-14 22:04:32 +01:00
|
|
|
{
|
|
|
|
struct d3d_viewport *vp = impl_from_IDirect3DViewport3(current_viewport);
|
2010-08-17 19:03:25 +02:00
|
|
|
viewport_activate(vp, TRUE);
|
2008-04-10 22:12:13 +02:00
|
|
|
IDirect3DViewport3_Release(current_viewport);
|
|
|
|
}
|
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2007-05-30 16:27:23 +02:00
|
|
|
return hr;
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DViewport3::AddLight
|
|
|
|
*
|
|
|
|
* Adds an light to the viewport
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* lpDirect3DLight: Interface of the light to add
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* D3D_OK on success
|
|
|
|
* DDERR_INVALIDPARAMS if Direct3DLight is NULL
|
|
|
|
* DDERR_INVALIDPARAMS if there are 8 lights or more
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-14 22:04:32 +01:00
|
|
|
static HRESULT WINAPI d3d_viewport_AddLight(IDirect3DViewport3 *iface, IDirect3DLight *lpDirect3DLight)
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
2012-03-14 22:04:32 +01:00
|
|
|
struct d3d_viewport *This = impl_from_IDirect3DViewport3(iface);
|
2012-03-13 20:31:37 +01:00
|
|
|
struct d3d_light *light_impl = unsafe_impl_from_IDirect3DLight(lpDirect3DLight);
|
2003-01-21 00:24:05 +01:00
|
|
|
DWORD i = 0;
|
|
|
|
DWORD map = This->map_lights;
|
2009-09-01 09:09:37 +02:00
|
|
|
|
2010-08-19 18:57:50 +02:00
|
|
|
TRACE("iface %p, light %p.\n", iface, lpDirect3DLight);
|
2007-05-30 16:27:23 +02:00
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
|
|
|
|
2003-01-21 00:24:05 +01:00
|
|
|
if (This->num_lights >= 8)
|
2007-05-30 16:27:23 +02:00
|
|
|
{
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
2003-01-21 00:24:05 +01:00
|
|
|
return DDERR_INVALIDPARAMS;
|
2007-05-30 16:27:23 +02:00
|
|
|
}
|
2003-01-21 00:24:05 +01:00
|
|
|
|
2019-03-22 12:17:46 +01:00
|
|
|
if (light_impl->active_viewport)
|
|
|
|
{
|
|
|
|
wined3d_mutex_unlock();
|
|
|
|
WARN("Light %p is active in viewport %p.\n", light_impl, light_impl->active_viewport);
|
|
|
|
return D3DERR_LIGHTHASVIEWPORT;
|
|
|
|
}
|
|
|
|
|
2003-01-21 00:24:05 +01:00
|
|
|
/* Find a light number and update both light and viewports objects accordingly */
|
2010-09-08 11:24:49 +02:00
|
|
|
while (map & 1)
|
|
|
|
{
|
|
|
|
map >>= 1;
|
|
|
|
++i;
|
2003-01-21 00:24:05 +01:00
|
|
|
}
|
2012-03-13 20:31:37 +01:00
|
|
|
light_impl->dwLightIndex = i;
|
2003-01-21 00:24:05 +01:00
|
|
|
This->num_lights++;
|
|
|
|
This->map_lights |= 1<<i;
|
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
/* Add the light in the 'linked' chain */
|
2012-03-13 20:31:37 +01:00
|
|
|
list_add_head(&This->light_list, &light_impl->entry);
|
2009-04-20 21:19:28 +02:00
|
|
|
IDirect3DLight_AddRef(lpDirect3DLight);
|
2002-11-21 22:04:16 +01:00
|
|
|
|
2003-01-21 00:24:05 +01:00
|
|
|
/* Attach the light to the viewport */
|
2012-03-13 20:31:37 +01:00
|
|
|
light_impl->active_viewport = This;
|
2009-09-01 09:09:37 +02:00
|
|
|
|
2002-11-21 22:04:16 +01:00
|
|
|
/* If active, activate the light */
|
2015-03-30 20:18:01 +02:00
|
|
|
if (This->active_device && light_impl->light.dwFlags & D3DLIGHT_ACTIVE)
|
|
|
|
{
|
|
|
|
/* Disable the flag so that light_activate actually does its job. */
|
|
|
|
light_impl->light.dwFlags &= ~D3DLIGHT_ACTIVE;
|
2012-03-13 20:31:37 +01:00
|
|
|
light_activate(light_impl);
|
2015-03-30 20:18:01 +02:00
|
|
|
}
|
2007-05-30 16:27:23 +02:00
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
return D3D_OK;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DViewport3::DeleteLight
|
|
|
|
*
|
|
|
|
* Deletes a light from the viewports' light list
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* lpDirect3DLight: Light to delete
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* D3D_OK on success
|
|
|
|
* DDERR_INVALIDPARAMS if the light wasn't found
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-14 22:04:32 +01:00
|
|
|
static HRESULT WINAPI d3d_viewport_DeleteLight(IDirect3DViewport3 *iface, IDirect3DLight *lpDirect3DLight)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2012-03-14 22:04:32 +01:00
|
|
|
struct d3d_viewport *viewport = impl_from_IDirect3DViewport3(iface);
|
2012-03-13 20:31:37 +01:00
|
|
|
struct d3d_light *l = unsafe_impl_from_IDirect3DLight(lpDirect3DLight);
|
2009-09-01 09:09:37 +02:00
|
|
|
|
2010-08-19 18:57:50 +02:00
|
|
|
TRACE("iface %p, light %p.\n", iface, lpDirect3DLight);
|
2007-05-30 16:27:23 +02:00
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
2011-04-21 22:39:28 +02:00
|
|
|
|
2012-03-14 22:04:32 +01:00
|
|
|
if (l->active_viewport != viewport)
|
2011-04-21 22:39:28 +02:00
|
|
|
{
|
|
|
|
WARN("Light %p active viewport is %p.\n", l, l->active_viewport);
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
2011-04-21 22:39:28 +02:00
|
|
|
return DDERR_INVALIDPARAMS;
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
2011-04-21 22:39:28 +02:00
|
|
|
|
|
|
|
light_deactivate(l);
|
|
|
|
list_remove(&l->entry);
|
|
|
|
l->active_viewport = NULL;
|
|
|
|
IDirect3DLight_Release(lpDirect3DLight);
|
2012-03-14 22:04:32 +01:00
|
|
|
--viewport->num_lights;
|
|
|
|
viewport->map_lights &= ~(1 << l->dwLightIndex);
|
2011-04-21 22:39:28 +02:00
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
2007-05-30 16:27:23 +02:00
|
|
|
|
2011-04-21 22:39:28 +02:00
|
|
|
return D3D_OK;
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DViewport::NextLight
|
|
|
|
*
|
|
|
|
* Enumerates the lights associated with the viewport
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* lpDirect3DLight: Light to start with
|
|
|
|
* lplpDirect3DLight: Address to store the successor to
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* D3D_OK, because it's a stub
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-14 22:04:32 +01:00
|
|
|
static HRESULT WINAPI d3d_viewport_NextLight(IDirect3DViewport3 *iface,
|
|
|
|
IDirect3DLight *lpDirect3DLight, IDirect3DLight **lplpDirect3DLight, DWORD flags)
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
2012-03-14 22:04:32 +01:00
|
|
|
struct d3d_viewport *viewport = impl_from_IDirect3DViewport3(iface);
|
2012-03-13 20:31:37 +01:00
|
|
|
struct d3d_light *l = unsafe_impl_from_IDirect3DLight(lpDirect3DLight);
|
2011-04-21 22:39:28 +02:00
|
|
|
struct list *entry;
|
|
|
|
HRESULT hr;
|
2009-03-03 22:45:21 +01:00
|
|
|
|
2010-08-19 18:57:50 +02:00
|
|
|
TRACE("iface %p, light %p, next_light %p, flags %#x.\n",
|
2012-03-14 22:04:32 +01:00
|
|
|
iface, lpDirect3DLight, lplpDirect3DLight, flags);
|
2009-03-03 22:45:21 +01:00
|
|
|
|
|
|
|
if (!lplpDirect3DLight)
|
|
|
|
return DDERR_INVALIDPARAMS;
|
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
2009-03-03 22:45:21 +01:00
|
|
|
|
2012-03-14 22:04:32 +01:00
|
|
|
switch (flags)
|
2011-04-21 22:39:28 +02:00
|
|
|
{
|
2009-03-03 22:45:21 +01:00
|
|
|
case D3DNEXT_NEXT:
|
2012-03-14 22:04:32 +01:00
|
|
|
if (!l || l->active_viewport != viewport)
|
2011-04-21 22:39:28 +02:00
|
|
|
{
|
|
|
|
if (l)
|
|
|
|
WARN("Light %p active viewport is %p.\n", l, l->active_viewport);
|
|
|
|
entry = NULL;
|
2009-03-03 22:45:21 +01:00
|
|
|
}
|
2011-04-21 22:39:28 +02:00
|
|
|
else
|
2012-03-14 22:04:32 +01:00
|
|
|
entry = list_next(&viewport->light_list, &l->entry);
|
2009-03-03 22:45:21 +01:00
|
|
|
break;
|
2011-04-21 22:39:28 +02:00
|
|
|
|
2009-03-03 22:45:21 +01:00
|
|
|
case D3DNEXT_HEAD:
|
2012-03-14 22:04:32 +01:00
|
|
|
entry = list_head(&viewport->light_list);
|
2009-03-03 22:45:21 +01:00
|
|
|
break;
|
2011-04-21 22:39:28 +02:00
|
|
|
|
2009-03-03 22:45:21 +01:00
|
|
|
case D3DNEXT_TAIL:
|
2012-03-14 22:04:32 +01:00
|
|
|
entry = list_tail(&viewport->light_list);
|
2009-03-03 22:45:21 +01:00
|
|
|
break;
|
2011-04-21 22:39:28 +02:00
|
|
|
|
2009-03-03 22:45:21 +01:00
|
|
|
default:
|
2011-04-21 22:39:28 +02:00
|
|
|
entry = NULL;
|
2012-03-14 22:04:32 +01:00
|
|
|
WARN("Invalid flags %#x.\n", flags);
|
2009-03-03 22:45:21 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-04-21 22:39:28 +02:00
|
|
|
if (entry)
|
|
|
|
{
|
2012-03-13 20:31:37 +01:00
|
|
|
*lplpDirect3DLight = (IDirect3DLight *)LIST_ENTRY(entry, struct d3d_light, entry);
|
2009-04-20 21:19:28 +02:00
|
|
|
IDirect3DLight_AddRef(*lplpDirect3DLight);
|
2011-04-21 22:39:28 +02:00
|
|
|
hr = D3D_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*lplpDirect3DLight = NULL;
|
|
|
|
hr = DDERR_INVALIDPARAMS;
|
|
|
|
}
|
2009-04-20 21:19:28 +02:00
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
2009-03-03 22:45:21 +01:00
|
|
|
|
2011-04-21 22:39:28 +02:00
|
|
|
return hr;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DViewport2 Methods.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2018-04-13 00:07:42 +02:00
|
|
|
static HRESULT WINAPI d3d_viewport_GetViewport2(IDirect3DViewport3 *iface, D3DVIEWPORT2 *vp)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2018-04-13 00:07:42 +02:00
|
|
|
struct d3d_viewport *viewport = impl_from_IDirect3DViewport3(iface);
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
TRACE("iface %p, vp %p.\n", iface, vp);
|
2010-08-19 18:57:50 +02:00
|
|
|
|
2018-04-13 00:07:42 +02:00
|
|
|
if (!vp)
|
|
|
|
return DDERR_INVALIDPARAMS;
|
2007-05-30 16:27:23 +02:00
|
|
|
|
2018-11-12 15:13:05 +01:00
|
|
|
if (viewport->version == DDRAW_VIEWPORT_VERSION_NONE)
|
|
|
|
{
|
|
|
|
WARN("Viewport data was not set.\n");
|
|
|
|
return D3DERR_VIEWPORTDATANOTSET;
|
|
|
|
}
|
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
2018-04-13 00:07:42 +02:00
|
|
|
size = vp->dwSize;
|
2018-11-12 15:13:05 +01:00
|
|
|
if (viewport->version == DDRAW_VIEWPORT_VERSION_2)
|
2018-04-13 00:07:42 +02:00
|
|
|
{
|
|
|
|
memcpy(vp, &viewport->viewports.vp2, size);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-02-15 09:49:16 +01:00
|
|
|
D3DVIEWPORT2 vp2;
|
2018-04-13 00:07:42 +02:00
|
|
|
|
2010-02-15 09:49:16 +01:00
|
|
|
vp2.dwSize = sizeof(vp2);
|
2018-04-13 00:07:42 +02:00
|
|
|
vp2.dwX = viewport->viewports.vp1.dwX;
|
|
|
|
vp2.dwY = viewport->viewports.vp1.dwY;
|
|
|
|
vp2.dwWidth = viewport->viewports.vp1.dwWidth;
|
|
|
|
vp2.dwHeight = viewport->viewports.vp1.dwHeight;
|
2018-11-12 15:13:05 +01:00
|
|
|
vp2.dvClipX = 0.0f;
|
|
|
|
vp2.dvClipY = 0.0f;
|
|
|
|
vp2.dvClipWidth = 0.0f;
|
|
|
|
vp2.dvClipHeight = 0.0f;
|
2018-04-13 00:07:42 +02:00
|
|
|
vp2.dvMinZ = viewport->viewports.vp1.dvMinZ;
|
|
|
|
vp2.dvMaxZ = viewport->viewports.vp1.dvMaxZ;
|
|
|
|
memcpy(vp, &vp2, size);
|
2010-02-15 09:49:16 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2010-08-19 18:57:50 +02:00
|
|
|
if (TRACE_ON(ddraw))
|
|
|
|
{
|
2002-11-30 20:12:32 +01:00
|
|
|
TRACE(" returning D3DVIEWPORT2 :\n");
|
2018-04-13 00:07:42 +02:00
|
|
|
_dump_D3DVIEWPORT2(vp);
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
2007-05-30 16:27:23 +02:00
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
return D3D_OK;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2018-04-13 00:07:42 +02:00
|
|
|
static HRESULT WINAPI d3d_viewport_SetViewport2(IDirect3DViewport3 *iface, D3DVIEWPORT2 *vp)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2018-04-13 00:07:42 +02:00
|
|
|
struct d3d_viewport *viewport = impl_from_IDirect3DViewport3(iface);
|
|
|
|
struct d3d_device *device = viewport->active_device;
|
2018-04-13 00:07:43 +02:00
|
|
|
struct wined3d_sub_resource_desc rt_desc;
|
|
|
|
struct wined3d_rendertarget_view *rtv;
|
2011-10-04 00:14:42 +02:00
|
|
|
IDirect3DViewport3 *current_viewport;
|
2018-04-13 00:07:43 +02:00
|
|
|
struct ddraw_surface *surface;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2018-04-13 00:07:42 +02:00
|
|
|
TRACE("iface %p, vp %p.\n", iface, vp);
|
|
|
|
|
|
|
|
if (!vp)
|
|
|
|
return DDERR_INVALIDPARAMS;
|
2010-08-19 18:57:50 +02:00
|
|
|
|
2018-11-12 15:13:03 +01:00
|
|
|
if (vp->dwSize != sizeof(*vp))
|
|
|
|
{
|
|
|
|
WARN("Invalid D3DVIEWPORT2 size %u.\n", vp->dwSize);
|
|
|
|
return DDERR_INVALIDPARAMS;
|
|
|
|
}
|
|
|
|
|
2010-08-19 18:57:50 +02:00
|
|
|
if (TRACE_ON(ddraw))
|
|
|
|
{
|
2002-11-21 22:04:16 +01:00
|
|
|
TRACE(" getting D3DVIEWPORT2 :\n");
|
2018-04-13 00:07:42 +02:00
|
|
|
_dump_D3DVIEWPORT2(vp);
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
|
|
|
|
2018-04-13 00:07:43 +02:00
|
|
|
if (!device)
|
|
|
|
{
|
|
|
|
WARN("Viewport not bound to a device, returning D3DERR_VIEWPORTHASNODEVICE.\n");
|
|
|
|
return D3DERR_VIEWPORTHASNODEVICE;
|
|
|
|
}
|
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
|
|
|
|
2018-04-13 00:07:43 +02:00
|
|
|
if (device->version > 1)
|
|
|
|
{
|
|
|
|
if (!(rtv = wined3d_device_get_rendertarget_view(device->wined3d_device, 0)))
|
|
|
|
{
|
|
|
|
wined3d_mutex_unlock();
|
|
|
|
return DDERR_INVALIDCAPS;
|
|
|
|
}
|
|
|
|
surface = wined3d_rendertarget_view_get_sub_resource_parent(rtv);
|
|
|
|
wined3d_texture_get_sub_resource_desc(surface->wined3d_texture, surface->sub_resource_idx, &rt_desc);
|
|
|
|
|
|
|
|
if (vp->dwX > rt_desc.width || vp->dwWidth > rt_desc.width - vp->dwX
|
|
|
|
|| vp->dwY > rt_desc.height || vp->dwHeight > rt_desc.height - vp->dwY)
|
|
|
|
{
|
|
|
|
WARN("Invalid viewport, returning DDERR_INVALIDPARAMS.\n");
|
|
|
|
wined3d_mutex_unlock();
|
|
|
|
return DDERR_INVALIDPARAMS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-12 15:13:05 +01:00
|
|
|
viewport->version = DDRAW_VIEWPORT_VERSION_2;
|
2018-11-12 15:13:03 +01:00
|
|
|
viewport->viewports.vp2 = *vp;
|
2003-10-14 03:16:42 +02:00
|
|
|
|
2018-04-13 00:07:43 +02:00
|
|
|
if (SUCCEEDED(IDirect3DDevice3_GetCurrentViewport(&device->IDirect3DDevice3_iface, ¤t_viewport)))
|
2013-01-26 13:39:42 +01:00
|
|
|
{
|
2018-04-13 00:07:43 +02:00
|
|
|
if (current_viewport == iface)
|
|
|
|
viewport_activate(viewport, FALSE);
|
|
|
|
IDirect3DViewport3_Release(current_viewport);
|
2003-10-14 03:16:42 +02:00
|
|
|
}
|
2011-11-13 19:52:24 +01:00
|
|
|
|
|
|
|
wined3d_mutex_unlock();
|
2003-10-14 03:16:42 +02:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
return D3D_OK;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DViewport3 Methods.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DViewport3::SetBackgroundDepth2
|
|
|
|
*
|
|
|
|
* Sets a IDirectDrawSurface4 surface as the background depth surface
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* lpDDS: Surface to set
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* D3D_OK, because it's stub
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-14 22:04:32 +01:00
|
|
|
static HRESULT WINAPI d3d_viewport_SetBackgroundDepth2(IDirect3DViewport3 *iface,
|
|
|
|
IDirectDrawSurface4 *surface)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2012-03-14 22:04:32 +01:00
|
|
|
FIXME("iface %p, surface %p stub!\n", iface, surface);
|
2010-08-19 18:57:50 +02:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
return D3D_OK;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DViewport3::GetBackgroundDepth2
|
|
|
|
*
|
|
|
|
* Returns the IDirect3DSurface4 interface to the background depth surface
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* lplpDDS: Address to store the interface pointer at
|
|
|
|
* lpValid: Set to true if a surface is assigned
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* D3D_OK because it's a stub
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-14 22:04:32 +01:00
|
|
|
static HRESULT WINAPI d3d_viewport_GetBackgroundDepth2(IDirect3DViewport3 *iface,
|
|
|
|
IDirectDrawSurface4 **surface, BOOL *valid)
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2012-03-14 22:04:32 +01:00
|
|
|
FIXME("iface %p, surface %p, valid %p stub!\n", iface, surface, valid);
|
2010-08-19 18:57:50 +02:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
return D3D_OK;
|
2002-11-21 22:04:16 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DViewport3::Clear2
|
|
|
|
*
|
|
|
|
* Another clearing method
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* Count: Number of rectangles to clear
|
|
|
|
* Rects: Rectangle array to clear
|
|
|
|
* Flags: Some flags :)
|
|
|
|
* Color: Color to fill the render target with
|
|
|
|
* Z: Value to fill the depth buffer with
|
|
|
|
* Stencil: Value to fill the stencil bits with
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-14 22:04:32 +01:00
|
|
|
static HRESULT WINAPI d3d_viewport_Clear2(IDirect3DViewport3 *iface, DWORD rect_count,
|
|
|
|
D3DRECT *rects, DWORD flags, DWORD color, D3DVALUE depth, DWORD stencil)
|
2002-11-21 22:04:16 +01:00
|
|
|
{
|
2012-03-14 22:04:32 +01:00
|
|
|
struct d3d_viewport *viewport = impl_from_IDirect3DViewport3(iface);
|
2007-05-30 16:27:23 +02:00
|
|
|
HRESULT hr;
|
2011-10-04 00:14:42 +02:00
|
|
|
IDirect3DViewport3 *current_viewport;
|
2009-01-21 09:56:13 +01:00
|
|
|
IDirect3DDevice3 *d3d_device3;
|
2010-08-19 18:57:50 +02:00
|
|
|
|
|
|
|
TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, depth %.8e, stencil %u.\n",
|
2012-03-14 22:04:32 +01:00
|
|
|
iface, rect_count, rects, flags, color, depth, stencil);
|
2007-05-30 16:27:23 +02:00
|
|
|
|
2013-01-23 15:02:45 +01:00
|
|
|
if (!rects || !rect_count)
|
|
|
|
{
|
|
|
|
WARN("rect_count = %u, rects = %p, ignoring clear\n", rect_count, rects);
|
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
|
|
|
|
2012-03-14 22:04:32 +01:00
|
|
|
if (!viewport->active_device)
|
|
|
|
{
|
|
|
|
WARN("Trying to clear a viewport not attached to a device.\n");
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
2007-05-30 16:27:23 +02:00
|
|
|
return D3DERR_VIEWPORTHASNODEVICE;
|
2002-09-29 20:00:43 +02:00
|
|
|
}
|
2012-03-14 22:04:32 +01:00
|
|
|
d3d_device3 = &viewport->active_device->IDirect3DDevice3_iface;
|
2010-08-17 19:03:25 +02:00
|
|
|
/* Need to temporarily activate viewport to clear it. Previously active
|
|
|
|
* one will be restored afterwards. */
|
2012-03-14 22:04:32 +01:00
|
|
|
viewport_activate(viewport, TRUE);
|
2008-04-10 22:12:13 +02:00
|
|
|
|
2012-03-14 22:04:32 +01:00
|
|
|
hr = IDirect3DDevice7_Clear(&viewport->active_device->IDirect3DDevice7_iface,
|
|
|
|
rect_count, rects, flags, color, depth, stencil);
|
2013-01-26 13:39:42 +01:00
|
|
|
if (SUCCEEDED(IDirect3DDevice3_GetCurrentViewport(d3d_device3, ¤t_viewport)))
|
2012-03-14 22:04:32 +01:00
|
|
|
{
|
|
|
|
struct d3d_viewport *vp = impl_from_IDirect3DViewport3(current_viewport);
|
2010-08-17 19:03:25 +02:00
|
|
|
viewport_activate(vp, TRUE);
|
2008-04-10 22:12:13 +02:00
|
|
|
IDirect3DViewport3_Release(current_viewport);
|
|
|
|
}
|
2011-11-13 19:52:24 +01:00
|
|
|
|
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2007-05-30 16:27:23 +02:00
|
|
|
return hr;
|
1999-01-03 18:00:19 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* The VTable
|
|
|
|
*****************************************************************************/
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2010-08-18 19:26:23 +02:00
|
|
|
static const struct IDirect3DViewport3Vtbl d3d_viewport_vtbl =
|
1999-01-03 18:00:19 +01:00
|
|
|
{
|
2006-06-09 19:36:12 +02:00
|
|
|
/*** IUnknown Methods ***/
|
2012-03-14 22:04:32 +01:00
|
|
|
d3d_viewport_QueryInterface,
|
|
|
|
d3d_viewport_AddRef,
|
|
|
|
d3d_viewport_Release,
|
2006-06-09 19:36:12 +02:00
|
|
|
/*** IDirect3DViewport Methods */
|
2012-03-14 22:04:32 +01:00
|
|
|
d3d_viewport_Initialize,
|
|
|
|
d3d_viewport_GetViewport,
|
|
|
|
d3d_viewport_SetViewport,
|
|
|
|
d3d_viewport_TransformVertices,
|
|
|
|
d3d_viewport_LightElements,
|
|
|
|
d3d_viewport_SetBackground,
|
|
|
|
d3d_viewport_GetBackground,
|
|
|
|
d3d_viewport_SetBackgroundDepth,
|
|
|
|
d3d_viewport_GetBackgroundDepth,
|
|
|
|
d3d_viewport_Clear,
|
|
|
|
d3d_viewport_AddLight,
|
|
|
|
d3d_viewport_DeleteLight,
|
|
|
|
d3d_viewport_NextLight,
|
2006-06-09 19:36:12 +02:00
|
|
|
/*** IDirect3DViewport2 Methods ***/
|
2012-03-14 22:04:32 +01:00
|
|
|
d3d_viewport_GetViewport2,
|
|
|
|
d3d_viewport_SetViewport2,
|
2006-06-09 19:36:12 +02:00
|
|
|
/*** IDirect3DViewport3 Methods ***/
|
2012-03-14 22:04:32 +01:00
|
|
|
d3d_viewport_SetBackgroundDepth2,
|
|
|
|
d3d_viewport_GetBackgroundDepth2,
|
|
|
|
d3d_viewport_Clear2,
|
2002-11-21 22:04:16 +01:00
|
|
|
};
|
2010-08-18 19:26:23 +02:00
|
|
|
|
2012-03-14 22:04:32 +01:00
|
|
|
struct d3d_viewport *unsafe_impl_from_IDirect3DViewport3(IDirect3DViewport3 *iface)
|
2011-10-04 00:14:37 +02:00
|
|
|
{
|
|
|
|
if (!iface) return NULL;
|
|
|
|
assert(iface->lpVtbl == &d3d_viewport_vtbl);
|
2012-03-14 22:04:32 +01:00
|
|
|
return CONTAINING_RECORD(iface, struct d3d_viewport, IDirect3DViewport3_iface);
|
2011-10-04 00:14:37 +02:00
|
|
|
}
|
|
|
|
|
2012-03-14 22:04:32 +01:00
|
|
|
struct d3d_viewport *unsafe_impl_from_IDirect3DViewport2(IDirect3DViewport2 *iface)
|
2011-10-04 00:14:59 +02:00
|
|
|
{
|
|
|
|
/* IDirect3DViewport and IDirect3DViewport3 use the same iface. */
|
|
|
|
if (!iface) return NULL;
|
|
|
|
assert(iface->lpVtbl == (IDirect3DViewport2Vtbl *)&d3d_viewport_vtbl);
|
2012-03-14 22:04:32 +01:00
|
|
|
return CONTAINING_RECORD(iface, struct d3d_viewport, IDirect3DViewport3_iface);
|
2011-10-04 00:14:59 +02:00
|
|
|
}
|
|
|
|
|
2012-03-14 22:04:32 +01:00
|
|
|
struct d3d_viewport *unsafe_impl_from_IDirect3DViewport(IDirect3DViewport *iface)
|
2011-10-04 00:14:54 +02:00
|
|
|
{
|
|
|
|
/* IDirect3DViewport and IDirect3DViewport3 use the same iface. */
|
|
|
|
if (!iface) return NULL;
|
|
|
|
assert(iface->lpVtbl == (IDirect3DViewportVtbl *)&d3d_viewport_vtbl);
|
2012-03-14 22:04:32 +01:00
|
|
|
return CONTAINING_RECORD(iface, struct d3d_viewport, IDirect3DViewport3_iface);
|
2011-10-04 00:14:54 +02:00
|
|
|
}
|
|
|
|
|
2012-03-14 22:04:32 +01:00
|
|
|
void d3d_viewport_init(struct d3d_viewport *viewport, struct ddraw *ddraw)
|
2010-08-18 19:26:23 +02:00
|
|
|
{
|
2011-10-04 00:14:51 +02:00
|
|
|
viewport->IDirect3DViewport3_iface.lpVtbl = &d3d_viewport_vtbl;
|
2010-08-18 19:26:23 +02:00
|
|
|
viewport->ref = 1;
|
|
|
|
viewport->ddraw = ddraw;
|
2018-11-12 15:13:05 +01:00
|
|
|
viewport->version = DDRAW_VIEWPORT_VERSION_NONE;
|
2011-04-21 22:39:28 +02:00
|
|
|
list_init(&viewport->light_list);
|
2010-08-18 19:26:23 +02:00
|
|
|
}
|