2003-07-01 01:09:17 +00:00
|
|
|
/*
|
|
|
|
* IDirect3DStateBlock9 implementation
|
|
|
|
*
|
|
|
|
* Copyright 2002-2003 Raphael Junqueira
|
2005-07-05 16:17:31 +00:00
|
|
|
* Copyright 2002-2003 Jason Edmeades
|
|
|
|
* Copyright 2005 Oliver Stieber
|
2003-07-01 01:09:17 +00: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 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-07-01 01:09:17 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "d3d9_private.h"
|
|
|
|
|
2005-08-23 09:34:57 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
|
2003-07-01 01:09:17 +00:00
|
|
|
|
2012-06-01 15:22:51 +00:00
|
|
|
static inline struct d3d9_stateblock *impl_from_IDirect3DStateBlock9(IDirect3DStateBlock9 *iface)
|
2011-04-12 02:10:34 +00:00
|
|
|
{
|
2012-06-01 15:22:51 +00:00
|
|
|
return CONTAINING_RECORD(iface, struct d3d9_stateblock, IDirect3DStateBlock9_iface);
|
2011-04-12 02:10:34 +00:00
|
|
|
}
|
|
|
|
|
2012-06-01 15:22:51 +00:00
|
|
|
static HRESULT WINAPI d3d9_stateblock_QueryInterface(IDirect3DStateBlock9 *iface, REFIID riid, void **out)
|
2011-04-12 02:10:34 +00:00
|
|
|
{
|
2012-06-01 15:22:51 +00:00
|
|
|
TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
|
2009-10-20 09:05:02 +00:00
|
|
|
|
2012-04-01 11:12:04 +00:00
|
|
|
if (IsEqualGUID(riid, &IID_IDirect3DStateBlock9)
|
|
|
|
|| IsEqualGUID(riid, &IID_IUnknown))
|
|
|
|
{
|
2008-11-02 22:49:40 +00:00
|
|
|
IDirect3DStateBlock9_AddRef(iface);
|
2012-06-01 15:22:51 +00:00
|
|
|
*out = iface;
|
2006-06-07 13:13:29 +00:00
|
|
|
return S_OK;
|
2003-07-01 01:09:17 +00:00
|
|
|
}
|
|
|
|
|
2012-04-01 11:12:04 +00:00
|
|
|
WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
|
|
|
|
|
2012-06-01 15:22:51 +00:00
|
|
|
*out = NULL;
|
2003-07-01 01:09:17 +00:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2012-06-01 15:22:51 +00:00
|
|
|
static ULONG WINAPI d3d9_stateblock_AddRef(IDirect3DStateBlock9 *iface)
|
2011-04-12 02:10:34 +00:00
|
|
|
{
|
2012-06-01 15:22:51 +00:00
|
|
|
struct d3d9_stateblock *stateblock = impl_from_IDirect3DStateBlock9(iface);
|
|
|
|
ULONG refcount = InterlockedIncrement(&stateblock->refcount);
|
2005-01-24 11:31:45 +00:00
|
|
|
|
2022-09-19 03:57:13 +00:00
|
|
|
TRACE("%p increasing refcount to %lu.\n", iface, refcount);
|
2005-01-24 11:31:45 +00:00
|
|
|
|
2012-06-01 15:22:51 +00:00
|
|
|
return refcount;
|
2003-07-01 01:09:17 +00:00
|
|
|
}
|
|
|
|
|
2012-06-01 15:22:51 +00:00
|
|
|
static ULONG WINAPI d3d9_stateblock_Release(IDirect3DStateBlock9 *iface)
|
2011-04-12 02:10:34 +00:00
|
|
|
{
|
2012-06-01 15:22:51 +00:00
|
|
|
struct d3d9_stateblock *stateblock = impl_from_IDirect3DStateBlock9(iface);
|
|
|
|
ULONG refcount = InterlockedDecrement(&stateblock->refcount);
|
2005-01-24 11:31:45 +00:00
|
|
|
|
2022-09-19 03:57:13 +00:00
|
|
|
TRACE("%p decreasing refcount to %lu.\n", iface, refcount);
|
2005-01-24 11:31:45 +00:00
|
|
|
|
2012-06-01 15:22:51 +00:00
|
|
|
if (!refcount)
|
|
|
|
{
|
|
|
|
wined3d_stateblock_decref(stateblock->wined3d_stateblock);
|
2009-08-26 08:18:09 +00:00
|
|
|
|
2012-06-01 15:22:51 +00:00
|
|
|
IDirect3DDevice9Ex_Release(stateblock->parent_device);
|
2023-10-29 17:42:13 +00:00
|
|
|
free(stateblock);
|
2003-07-01 01:09:17 +00:00
|
|
|
}
|
2012-06-01 15:22:51 +00:00
|
|
|
|
|
|
|
return refcount;
|
2003-07-01 01:09:17 +00:00
|
|
|
}
|
|
|
|
|
2012-06-01 15:22:51 +00:00
|
|
|
static HRESULT WINAPI d3d9_stateblock_GetDevice(IDirect3DStateBlock9 *iface, IDirect3DDevice9 **device)
|
2009-12-04 10:50:47 +00:00
|
|
|
{
|
2012-06-01 15:22:51 +00:00
|
|
|
struct d3d9_stateblock *stateblock = impl_from_IDirect3DStateBlock9(iface);
|
2009-10-20 09:05:02 +00:00
|
|
|
|
2009-12-04 10:50:47 +00:00
|
|
|
TRACE("iface %p, device %p.\n", iface, device);
|
2007-06-12 11:50:51 +00:00
|
|
|
|
2012-06-01 15:22:51 +00:00
|
|
|
*device = (IDirect3DDevice9 *)stateblock->parent_device;
|
2009-12-04 10:50:47 +00:00
|
|
|
IDirect3DDevice9_AddRef(*device);
|
|
|
|
|
|
|
|
TRACE("Returning device %p.\n", *device);
|
2009-08-26 08:18:09 +00:00
|
|
|
|
2009-12-04 10:50:47 +00:00
|
|
|
return D3D_OK;
|
2003-07-01 01:09:17 +00:00
|
|
|
}
|
|
|
|
|
2012-06-01 15:22:51 +00:00
|
|
|
static HRESULT WINAPI d3d9_stateblock_Capture(IDirect3DStateBlock9 *iface)
|
2011-04-12 02:10:34 +00:00
|
|
|
{
|
2012-06-01 15:22:51 +00:00
|
|
|
struct d3d9_stateblock *stateblock = impl_from_IDirect3DStateBlock9(iface);
|
2019-04-02 17:42:47 +00:00
|
|
|
struct d3d9_device *device;
|
2009-10-20 09:05:02 +00:00
|
|
|
|
|
|
|
TRACE("iface %p.\n", iface);
|
2007-06-12 11:50:51 +00:00
|
|
|
|
2009-08-26 08:18:09 +00:00
|
|
|
wined3d_mutex_lock();
|
2019-04-02 17:42:47 +00:00
|
|
|
device = impl_from_IDirect3DDevice9Ex(stateblock->parent_device);
|
|
|
|
if (device->recording)
|
|
|
|
{
|
|
|
|
wined3d_mutex_unlock();
|
|
|
|
WARN("Trying to capture stateblock while recording, returning D3DERR_INVALIDCALL.\n");
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
}
|
2019-11-27 04:58:26 +00:00
|
|
|
wined3d_stateblock_capture(stateblock->wined3d_stateblock, device->state);
|
2009-08-26 08:18:09 +00:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2012-10-04 21:42:16 +00:00
|
|
|
return D3D_OK;
|
2003-07-01 01:09:17 +00:00
|
|
|
}
|
|
|
|
|
2012-06-01 15:22:51 +00:00
|
|
|
static HRESULT WINAPI d3d9_stateblock_Apply(IDirect3DStateBlock9 *iface)
|
2011-04-12 02:10:34 +00:00
|
|
|
{
|
2012-06-01 15:22:51 +00:00
|
|
|
struct d3d9_stateblock *stateblock = impl_from_IDirect3DStateBlock9(iface);
|
2022-07-18 19:48:52 +00:00
|
|
|
struct d3d9_vertexbuffer *vertex_buffer;
|
2019-02-11 17:21:04 +00:00
|
|
|
struct wined3d_texture *wined3d_texture;
|
2022-07-18 19:48:52 +00:00
|
|
|
struct d3d9_indexbuffer *index_buffer;
|
2018-12-17 19:29:21 +00:00
|
|
|
struct wined3d_buffer *wined3d_buffer;
|
2019-02-11 17:21:04 +00:00
|
|
|
struct d3d9_texture *texture;
|
2018-12-17 19:29:21 +00:00
|
|
|
struct d3d9_device *device;
|
2020-03-06 11:33:13 +00:00
|
|
|
unsigned int i;
|
2009-10-20 09:05:02 +00:00
|
|
|
|
|
|
|
TRACE("iface %p.\n", iface);
|
2007-06-12 11:50:51 +00:00
|
|
|
|
2009-08-26 08:18:09 +00:00
|
|
|
wined3d_mutex_lock();
|
2018-12-17 19:29:21 +00:00
|
|
|
device = impl_from_IDirect3DDevice9Ex(stateblock->parent_device);
|
2019-04-02 17:42:46 +00:00
|
|
|
if (device->recording)
|
|
|
|
{
|
|
|
|
wined3d_mutex_unlock();
|
|
|
|
WARN("Trying to apply stateblock while recording, returning D3DERR_INVALIDCALL.\n");
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
}
|
2019-11-27 04:58:26 +00:00
|
|
|
wined3d_stateblock_apply(stateblock->wined3d_stateblock, device->state);
|
2018-12-17 19:29:21 +00:00
|
|
|
device->sysmem_vb = 0;
|
|
|
|
for (i = 0; i < D3D9_MAX_STREAMS; ++i)
|
|
|
|
{
|
2020-03-06 11:33:13 +00:00
|
|
|
if (!(wined3d_buffer = device->stateblock_state->streams[i].buffer))
|
2018-12-17 19:29:21 +00:00
|
|
|
continue;
|
2022-07-18 19:48:52 +00:00
|
|
|
if (!(vertex_buffer = wined3d_buffer_get_parent(wined3d_buffer)))
|
2018-12-17 19:29:21 +00:00
|
|
|
continue;
|
2022-07-18 19:48:52 +00:00
|
|
|
if (vertex_buffer->draw_buffer)
|
2018-12-17 19:29:21 +00:00
|
|
|
device->sysmem_vb |= 1u << i;
|
|
|
|
}
|
2020-03-06 11:33:13 +00:00
|
|
|
device->sysmem_ib = (wined3d_buffer = device->stateblock_state->index_buffer)
|
2022-07-18 19:48:52 +00:00
|
|
|
&& (index_buffer = wined3d_buffer_get_parent(wined3d_buffer)) && index_buffer->sysmem;
|
2019-02-11 17:21:04 +00:00
|
|
|
device->auto_mipmaps = 0;
|
|
|
|
for (i = 0; i < D3D9_MAX_TEXTURE_UNITS; ++i)
|
|
|
|
{
|
2020-03-06 11:33:12 +00:00
|
|
|
if ((wined3d_texture = device->stateblock_state->textures[i])
|
2019-02-11 17:21:04 +00:00
|
|
|
&& (texture = wined3d_texture_get_parent(wined3d_texture))
|
|
|
|
&& texture->usage & D3DUSAGE_AUTOGENMIPMAP)
|
|
|
|
device->auto_mipmaps |= 1u << i;
|
|
|
|
else
|
|
|
|
device->auto_mipmaps &= ~(1u << i);
|
|
|
|
}
|
2009-08-26 08:18:09 +00:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2012-10-04 21:42:17 +00:00
|
|
|
return D3D_OK;
|
2003-07-01 01:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-01 15:22:51 +00:00
|
|
|
static const struct IDirect3DStateBlock9Vtbl d3d9_stateblock_vtbl =
|
2003-07-01 01:09:17 +00:00
|
|
|
{
|
2005-07-05 16:17:31 +00:00
|
|
|
/* IUnknown */
|
2012-06-01 15:22:51 +00:00
|
|
|
d3d9_stateblock_QueryInterface,
|
|
|
|
d3d9_stateblock_AddRef,
|
|
|
|
d3d9_stateblock_Release,
|
2005-07-05 16:17:31 +00:00
|
|
|
/* IDirect3DStateBlock9 */
|
2012-06-01 15:22:51 +00:00
|
|
|
d3d9_stateblock_GetDevice,
|
|
|
|
d3d9_stateblock_Capture,
|
|
|
|
d3d9_stateblock_Apply,
|
2003-07-01 01:09:17 +00:00
|
|
|
};
|
|
|
|
|
2012-06-01 15:22:51 +00:00
|
|
|
HRESULT stateblock_init(struct d3d9_stateblock *stateblock, struct d3d9_device *device,
|
2011-01-28 19:05:41 +00:00
|
|
|
D3DSTATEBLOCKTYPE type, struct wined3d_stateblock *wined3d_stateblock)
|
2009-08-28 08:23:11 +00:00
|
|
|
{
|
2007-06-12 11:50:51 +00:00
|
|
|
HRESULT hr;
|
2009-10-20 09:05:02 +00:00
|
|
|
|
2012-06-01 15:22:51 +00:00
|
|
|
stateblock->IDirect3DStateBlock9_iface.lpVtbl = &d3d9_stateblock_vtbl;
|
|
|
|
stateblock->refcount = 1;
|
2003-07-01 01:09:17 +00:00
|
|
|
|
2010-01-19 22:52:29 +00:00
|
|
|
if (wined3d_stateblock)
|
2009-08-26 08:18:09 +00:00
|
|
|
{
|
2011-01-28 19:05:41 +00:00
|
|
|
stateblock->wined3d_stateblock = wined3d_stateblock;
|
2009-08-28 08:23:11 +00:00
|
|
|
}
|
2010-01-19 22:52:29 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
wined3d_mutex_lock();
|
2019-11-27 04:58:26 +00:00
|
|
|
hr = wined3d_stateblock_create(device->wined3d_device, device->state,
|
2012-01-17 20:13:39 +00:00
|
|
|
(enum wined3d_stateblock_type)type, &stateblock->wined3d_stateblock);
|
2010-01-19 22:52:29 +00:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-09-19 03:57:13 +00:00
|
|
|
WARN("Failed to create wined3d stateblock, hr %#lx.\n", hr);
|
2010-01-19 22:52:29 +00:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-01 15:22:51 +00:00
|
|
|
stateblock->parent_device = &device->IDirect3DDevice9Ex_iface;
|
|
|
|
IDirect3DDevice9Ex_AddRef(stateblock->parent_device);
|
2010-01-19 22:52:29 +00:00
|
|
|
|
2003-07-01 01:09:17 +00:00
|
|
|
return D3D_OK;
|
|
|
|
}
|