2003-07-01 03:09:17 +02:00
|
|
|
/*
|
|
|
|
* IDirect3DStateBlock9 implementation
|
|
|
|
*
|
|
|
|
* Copyright 2002-2003 Raphael Junqueira
|
2005-07-05 18:17:31 +02:00
|
|
|
* Copyright 2002-2003 Jason Edmeades
|
|
|
|
* Copyright 2005 Oliver Stieber
|
2003-07-01 03:09:17 +02: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
|
2003-07-01 03:09:17 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2019-01-25 09:46:52 +01:00
|
|
|
#include "wine/port.h"
|
2003-07-01 03:09:17 +02:00
|
|
|
#include "d3d9_private.h"
|
|
|
|
|
2005-08-23 11:34:57 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
|
2003-07-01 03:09:17 +02:00
|
|
|
|
2012-06-01 17:22:51 +02:00
|
|
|
static inline struct d3d9_stateblock *impl_from_IDirect3DStateBlock9(IDirect3DStateBlock9 *iface)
|
2011-04-12 04:10:34 +02:00
|
|
|
{
|
2012-06-01 17:22:51 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct d3d9_stateblock, IDirect3DStateBlock9_iface);
|
2011-04-12 04:10:34 +02:00
|
|
|
}
|
|
|
|
|
2012-06-01 17:22:51 +02:00
|
|
|
static HRESULT WINAPI d3d9_stateblock_QueryInterface(IDirect3DStateBlock9 *iface, REFIID riid, void **out)
|
2011-04-12 04:10:34 +02:00
|
|
|
{
|
2012-06-01 17:22:51 +02:00
|
|
|
TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
|
2009-10-20 11:05:02 +02:00
|
|
|
|
2012-04-01 13:12:04 +02:00
|
|
|
if (IsEqualGUID(riid, &IID_IDirect3DStateBlock9)
|
|
|
|
|| IsEqualGUID(riid, &IID_IUnknown))
|
|
|
|
{
|
2008-11-02 23:49:40 +01:00
|
|
|
IDirect3DStateBlock9_AddRef(iface);
|
2012-06-01 17:22:51 +02:00
|
|
|
*out = iface;
|
2006-06-07 15:13:29 +02:00
|
|
|
return S_OK;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
2012-04-01 13:12:04 +02:00
|
|
|
WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
|
|
|
|
|
2012-06-01 17:22:51 +02:00
|
|
|
*out = NULL;
|
2003-07-01 03:09:17 +02:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2012-06-01 17:22:51 +02:00
|
|
|
static ULONG WINAPI d3d9_stateblock_AddRef(IDirect3DStateBlock9 *iface)
|
2011-04-12 04:10:34 +02:00
|
|
|
{
|
2012-06-01 17:22:51 +02:00
|
|
|
struct d3d9_stateblock *stateblock = impl_from_IDirect3DStateBlock9(iface);
|
|
|
|
ULONG refcount = InterlockedIncrement(&stateblock->refcount);
|
2005-01-24 12:31:45 +01:00
|
|
|
|
2012-06-01 17:22:51 +02:00
|
|
|
TRACE("%p increasing refcount to %u.\n", iface, refcount);
|
2005-01-24 12:31:45 +01:00
|
|
|
|
2012-06-01 17:22:51 +02:00
|
|
|
return refcount;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
2012-06-01 17:22:51 +02:00
|
|
|
static ULONG WINAPI d3d9_stateblock_Release(IDirect3DStateBlock9 *iface)
|
2011-04-12 04:10:34 +02:00
|
|
|
{
|
2012-06-01 17:22:51 +02:00
|
|
|
struct d3d9_stateblock *stateblock = impl_from_IDirect3DStateBlock9(iface);
|
|
|
|
ULONG refcount = InterlockedDecrement(&stateblock->refcount);
|
2005-01-24 12:31:45 +01:00
|
|
|
|
2012-06-01 17:22:51 +02:00
|
|
|
TRACE("%p decreasing refcount to %u.\n", iface, refcount);
|
2005-01-24 12:31:45 +01:00
|
|
|
|
2012-06-01 17:22:51 +02:00
|
|
|
if (!refcount)
|
|
|
|
{
|
2009-08-26 10:18:09 +02:00
|
|
|
wined3d_mutex_lock();
|
2012-06-01 17:22:51 +02:00
|
|
|
wined3d_stateblock_decref(stateblock->wined3d_stateblock);
|
2009-08-26 10:18:09 +02:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2012-06-01 17:22:51 +02:00
|
|
|
IDirect3DDevice9Ex_Release(stateblock->parent_device);
|
2018-02-06 23:41:32 +01:00
|
|
|
heap_free(stateblock);
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
2012-06-01 17:22:51 +02:00
|
|
|
|
|
|
|
return refcount;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
2012-06-01 17:22:51 +02:00
|
|
|
static HRESULT WINAPI d3d9_stateblock_GetDevice(IDirect3DStateBlock9 *iface, IDirect3DDevice9 **device)
|
2009-12-04 11:50:47 +01:00
|
|
|
{
|
2012-06-01 17:22:51 +02:00
|
|
|
struct d3d9_stateblock *stateblock = impl_from_IDirect3DStateBlock9(iface);
|
2009-10-20 11:05:02 +02:00
|
|
|
|
2009-12-04 11:50:47 +01:00
|
|
|
TRACE("iface %p, device %p.\n", iface, device);
|
2007-06-12 13:50:51 +02:00
|
|
|
|
2012-06-01 17:22:51 +02:00
|
|
|
*device = (IDirect3DDevice9 *)stateblock->parent_device;
|
2009-12-04 11:50:47 +01:00
|
|
|
IDirect3DDevice9_AddRef(*device);
|
|
|
|
|
|
|
|
TRACE("Returning device %p.\n", *device);
|
2009-08-26 10:18:09 +02:00
|
|
|
|
2009-12-04 11:50:47 +01:00
|
|
|
return D3D_OK;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
2012-06-01 17:22:51 +02:00
|
|
|
static HRESULT WINAPI d3d9_stateblock_Capture(IDirect3DStateBlock9 *iface)
|
2011-04-12 04:10:34 +02:00
|
|
|
{
|
2012-06-01 17:22:51 +02:00
|
|
|
struct d3d9_stateblock *stateblock = impl_from_IDirect3DStateBlock9(iface);
|
2019-04-02 19:42:47 +02:00
|
|
|
struct d3d9_device *device;
|
2009-10-20 11:05:02 +02:00
|
|
|
|
|
|
|
TRACE("iface %p.\n", iface);
|
2007-06-12 13:50:51 +02:00
|
|
|
|
2009-08-26 10:18:09 +02:00
|
|
|
wined3d_mutex_lock();
|
2019-04-02 19:42:47 +02: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;
|
|
|
|
}
|
2012-10-04 23:42:16 +02:00
|
|
|
wined3d_stateblock_capture(stateblock->wined3d_stateblock);
|
2009-08-26 10:18:09 +02:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2012-10-04 23:42:16 +02:00
|
|
|
return D3D_OK;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
2012-06-01 17:22:51 +02:00
|
|
|
static HRESULT WINAPI d3d9_stateblock_Apply(IDirect3DStateBlock9 *iface)
|
2011-04-12 04:10:34 +02:00
|
|
|
{
|
2012-06-01 17:22:51 +02:00
|
|
|
struct d3d9_stateblock *stateblock = impl_from_IDirect3DStateBlock9(iface);
|
2019-02-11 18:21:04 +01:00
|
|
|
struct wined3d_texture *wined3d_texture;
|
|
|
|
unsigned int i, offset, stride, stage;
|
2018-12-17 20:29:21 +01:00
|
|
|
struct wined3d_buffer *wined3d_buffer;
|
|
|
|
struct d3d9_vertexbuffer *buffer;
|
2018-12-17 20:29:22 +01:00
|
|
|
enum wined3d_format_id format;
|
2019-02-11 18:21:04 +01:00
|
|
|
struct d3d9_texture *texture;
|
2018-12-17 20:29:21 +01:00
|
|
|
struct d3d9_device *device;
|
|
|
|
HRESULT hr;
|
2009-10-20 11:05:02 +02:00
|
|
|
|
|
|
|
TRACE("iface %p.\n", iface);
|
2007-06-12 13:50:51 +02:00
|
|
|
|
2009-08-26 10:18:09 +02:00
|
|
|
wined3d_mutex_lock();
|
2018-12-17 20:29:21 +01:00
|
|
|
device = impl_from_IDirect3DDevice9Ex(stateblock->parent_device);
|
2019-04-02 19:42:46 +02:00
|
|
|
if (device->recording)
|
|
|
|
{
|
|
|
|
wined3d_mutex_unlock();
|
|
|
|
WARN("Trying to apply stateblock while recording, returning D3DERR_INVALIDCALL.\n");
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
wined3d_stateblock_apply(stateblock->wined3d_stateblock);
|
2018-12-17 20:29:21 +01:00
|
|
|
device->sysmem_vb = 0;
|
|
|
|
for (i = 0; i < D3D9_MAX_STREAMS; ++i)
|
|
|
|
{
|
|
|
|
if (FAILED(hr = wined3d_device_get_stream_source(device->wined3d_device,
|
|
|
|
i, &wined3d_buffer, &offset, &stride)))
|
|
|
|
continue;
|
|
|
|
if (!wined3d_buffer || !(buffer = wined3d_buffer_get_parent(wined3d_buffer)))
|
|
|
|
continue;
|
|
|
|
if (buffer->draw_buffer)
|
|
|
|
device->sysmem_vb |= 1u << i;
|
|
|
|
}
|
2018-12-17 20:29:22 +01:00
|
|
|
device->sysmem_ib = (wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &format, &offset))
|
|
|
|
&& (buffer = wined3d_buffer_get_parent(wined3d_buffer)) && buffer->draw_buffer;
|
2019-02-11 18:21:04 +01:00
|
|
|
device->auto_mipmaps = 0;
|
|
|
|
for (i = 0; i < D3D9_MAX_TEXTURE_UNITS; ++i)
|
|
|
|
{
|
|
|
|
stage = i >= 16 ? i - 16 + D3DVERTEXTEXTURESAMPLER0 : i;
|
|
|
|
|
|
|
|
if ((wined3d_texture = wined3d_device_get_texture(device->wined3d_device, stage))
|
|
|
|
&& (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 10:18:09 +02:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2012-10-04 23:42:17 +02:00
|
|
|
return D3D_OK;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-01 17:22:51 +02:00
|
|
|
static const struct IDirect3DStateBlock9Vtbl d3d9_stateblock_vtbl =
|
2003-07-01 03:09:17 +02:00
|
|
|
{
|
2005-07-05 18:17:31 +02:00
|
|
|
/* IUnknown */
|
2012-06-01 17:22:51 +02:00
|
|
|
d3d9_stateblock_QueryInterface,
|
|
|
|
d3d9_stateblock_AddRef,
|
|
|
|
d3d9_stateblock_Release,
|
2005-07-05 18:17:31 +02:00
|
|
|
/* IDirect3DStateBlock9 */
|
2012-06-01 17:22:51 +02:00
|
|
|
d3d9_stateblock_GetDevice,
|
|
|
|
d3d9_stateblock_Capture,
|
|
|
|
d3d9_stateblock_Apply,
|
2003-07-01 03:09:17 +02:00
|
|
|
};
|
|
|
|
|
2012-06-01 17:22:51 +02:00
|
|
|
HRESULT stateblock_init(struct d3d9_stateblock *stateblock, struct d3d9_device *device,
|
2011-01-28 20:05:41 +01:00
|
|
|
D3DSTATEBLOCKTYPE type, struct wined3d_stateblock *wined3d_stateblock)
|
2009-08-28 10:23:11 +02:00
|
|
|
{
|
2007-06-12 13:50:51 +02:00
|
|
|
HRESULT hr;
|
2009-10-20 11:05:02 +02:00
|
|
|
|
2012-06-01 17:22:51 +02:00
|
|
|
stateblock->IDirect3DStateBlock9_iface.lpVtbl = &d3d9_stateblock_vtbl;
|
|
|
|
stateblock->refcount = 1;
|
2003-07-01 03:09:17 +02:00
|
|
|
|
2010-01-19 23:52:29 +01:00
|
|
|
if (wined3d_stateblock)
|
2009-08-26 10:18:09 +02:00
|
|
|
{
|
2011-01-28 20:05:41 +01:00
|
|
|
stateblock->wined3d_stateblock = wined3d_stateblock;
|
2009-08-28 10:23:11 +02:00
|
|
|
}
|
2010-01-19 23:52:29 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
wined3d_mutex_lock();
|
2011-05-16 23:01:22 +02:00
|
|
|
hr = wined3d_stateblock_create(device->wined3d_device,
|
2012-01-17 21:13:39 +01:00
|
|
|
(enum wined3d_stateblock_type)type, &stateblock->wined3d_stateblock);
|
2010-01-19 23:52:29 +01:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to create wined3d stateblock, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-01 17:22:51 +02:00
|
|
|
stateblock->parent_device = &device->IDirect3DDevice9Ex_iface;
|
|
|
|
IDirect3DDevice9Ex_AddRef(stateblock->parent_device);
|
2010-01-19 23:52:29 +01:00
|
|
|
|
2003-07-01 03:09:17 +02:00
|
|
|
return D3D_OK;
|
|
|
|
}
|