1999-01-03 17:00:19 +00:00
|
|
|
/* Direct3D Material
|
2002-11-21 21:04:16 +00:00
|
|
|
* Copyright (c) 2002 Lionel ULMER
|
2008-10-18 17:19:45 +00:00
|
|
|
* Copyright (c) 2006 Stefan DÖSINGER
|
2002-03-09 23:29:33 +00:00
|
|
|
*
|
2002-11-21 21:04:16 +00:00
|
|
|
* This file contains the implementation of Direct3DMaterial.
|
2002-03-09 23:29:33 +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
|
2002-03-09 23:29:33 +00:00
|
|
|
*/
|
1999-01-03 17:00:19 +00:00
|
|
|
|
2003-09-05 23:08:26 +00:00
|
|
|
#include "config.h"
|
2006-06-09 17:36:12 +00:00
|
|
|
#include "wine/port.h"
|
2003-09-05 23:08:26 +00:00
|
|
|
|
2006-06-09 17:36:12 +00:00
|
|
|
#include "ddraw_private.h"
|
1999-01-03 17:00:19 +00:00
|
|
|
|
2010-08-19 16:57:50 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
|
1999-04-19 14:56:29 +00:00
|
|
|
|
2007-04-21 21:16:34 +00:00
|
|
|
static void dump_material(const D3DMATERIAL *mat)
|
2002-11-21 21:04:16 +00:00
|
|
|
{
|
2007-12-04 22:27:33 +00:00
|
|
|
TRACE(" dwSize : %d\n", mat->dwSize);
|
1999-01-03 17:00:19 +00:00
|
|
|
}
|
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
static inline struct d3d_material *impl_from_IDirect3DMaterial(IDirect3DMaterial *iface)
|
2009-01-22 09:33:36 +00:00
|
|
|
{
|
2012-03-15 20:49:58 +00:00
|
|
|
return CONTAINING_RECORD(iface, struct d3d_material, IDirect3DMaterial_iface);
|
2009-01-22 09:33:36 +00:00
|
|
|
}
|
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
static inline struct d3d_material *impl_from_IDirect3DMaterial2(IDirect3DMaterial2 *iface)
|
2009-01-22 09:33:37 +00:00
|
|
|
{
|
2012-03-15 20:49:58 +00:00
|
|
|
return CONTAINING_RECORD(iface, struct d3d_material, IDirect3DMaterial2_iface);
|
2009-01-22 09:33:37 +00:00
|
|
|
}
|
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
static inline struct d3d_material *impl_from_IDirect3DMaterial3(IDirect3DMaterial3 *iface)
|
2011-06-08 15:38:16 +00:00
|
|
|
{
|
2012-03-15 20:49:58 +00:00
|
|
|
return CONTAINING_RECORD(iface, struct d3d_material, IDirect3DMaterial3_iface);
|
2011-06-08 15:38:16 +00:00
|
|
|
}
|
|
|
|
|
2006-06-09 17:36:12 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* IUnknown Methods.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DMaterial3::QueryInterface
|
|
|
|
*
|
|
|
|
* QueryInterface for IDirect3DMaterial. Can query all IDirect3DMaterial
|
|
|
|
* versions.
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* riid: Interface id queried for
|
|
|
|
* obj: Address to pass the interface pointer back
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* S_OK on success
|
|
|
|
* E_NOINTERFACE if the requested interface wasn't found
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-15 20:49:58 +00:00
|
|
|
static HRESULT WINAPI d3d_material3_QueryInterface(IDirect3DMaterial3 *iface, REFIID riid, void **obp)
|
1999-01-03 17:00:19 +00:00
|
|
|
{
|
2012-03-15 20:49:58 +00:00
|
|
|
struct d3d_material *material = impl_from_IDirect3DMaterial3(iface);
|
2010-08-19 16:57:50 +00:00
|
|
|
|
|
|
|
TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obp);
|
2002-11-21 21:04:16 +00:00
|
|
|
|
|
|
|
*obp = NULL;
|
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
if (IsEqualGUID(&IID_IUnknown, riid))
|
|
|
|
{
|
2012-08-27 10:27:48 +00:00
|
|
|
IDirect3DMaterial3_AddRef(iface);
|
2010-09-08 09:24:49 +00:00
|
|
|
*obp = iface;
|
|
|
|
TRACE(" Creating IUnknown interface at %p.\n", *obp);
|
|
|
|
return S_OK;
|
2002-11-21 21:04:16 +00:00
|
|
|
}
|
2012-03-15 20:49:58 +00:00
|
|
|
if (IsEqualGUID(&IID_IDirect3DMaterial, riid))
|
|
|
|
{
|
|
|
|
IDirect3DMaterial_AddRef(&material->IDirect3DMaterial_iface);
|
|
|
|
*obp = &material->IDirect3DMaterial_iface;
|
2010-09-08 09:24:49 +00:00
|
|
|
TRACE(" Creating IDirect3DMaterial interface %p\n", *obp);
|
|
|
|
return S_OK;
|
2002-11-21 21:04:16 +00:00
|
|
|
}
|
2012-03-15 20:49:58 +00:00
|
|
|
if (IsEqualGUID(&IID_IDirect3DMaterial2, riid))
|
|
|
|
{
|
|
|
|
IDirect3DMaterial2_AddRef(&material->IDirect3DMaterial2_iface);
|
|
|
|
*obp = &material->IDirect3DMaterial2_iface;
|
2010-09-08 09:24:49 +00:00
|
|
|
TRACE(" Creating IDirect3DMaterial2 interface %p\n", *obp);
|
|
|
|
return S_OK;
|
2002-11-21 21:04:16 +00:00
|
|
|
}
|
2012-03-15 20:49:58 +00:00
|
|
|
if (IsEqualGUID(&IID_IDirect3DMaterial3, riid))
|
|
|
|
{
|
|
|
|
IDirect3DMaterial3_AddRef(&material->IDirect3DMaterial3_iface);
|
|
|
|
*obp = &material->IDirect3DMaterial3_iface;
|
2010-09-08 09:24:49 +00:00
|
|
|
TRACE(" Creating IDirect3DMaterial3 interface %p\n", *obp);
|
|
|
|
return S_OK;
|
2002-11-21 21:04:16 +00:00
|
|
|
}
|
2012-03-15 20:49:58 +00:00
|
|
|
|
|
|
|
WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
|
|
|
|
|
2006-06-09 17:36:12 +00:00
|
|
|
return E_NOINTERFACE;
|
2002-11-21 21:04:16 +00:00
|
|
|
}
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2006-06-09 17:36:12 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DMaterial3::AddRef
|
|
|
|
*
|
|
|
|
* Increases the refcount.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* The new refcount
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-15 20:49:58 +00:00
|
|
|
static ULONG WINAPI d3d_material3_AddRef(IDirect3DMaterial3 *iface)
|
2002-11-21 21:04:16 +00:00
|
|
|
{
|
2012-03-15 20:49:58 +00:00
|
|
|
struct d3d_material *material = impl_from_IDirect3DMaterial3(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&material->ref);
|
2005-01-09 17:29:21 +00:00
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
TRACE("%p increasing refcount to %u.\n", material, ref);
|
2005-01-09 17:29:21 +00:00
|
|
|
|
|
|
|
return ref;
|
1999-01-03 17:00:19 +00:00
|
|
|
}
|
|
|
|
|
2006-06-09 17:36:12 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DMaterial3::Release
|
|
|
|
*
|
|
|
|
* Reduces the refcount by one. If the refcount falls to 0, the object
|
|
|
|
* is destroyed
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* The new refcount
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-15 20:49:58 +00:00
|
|
|
static ULONG WINAPI d3d_material3_Release(IDirect3DMaterial3 *iface)
|
1999-01-03 17:00:19 +00:00
|
|
|
{
|
2012-03-15 20:49:58 +00:00
|
|
|
struct d3d_material *material = impl_from_IDirect3DMaterial3(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&material->ref);
|
2005-01-09 17:29:21 +00:00
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
TRACE("%p decreasing refcount to %u.\n", material, ref);
|
2005-01-09 17:29:21 +00:00
|
|
|
|
2006-06-16 21:44:33 +00:00
|
|
|
if (!ref)
|
|
|
|
{
|
2012-03-15 20:49:58 +00:00
|
|
|
if (material->Handle)
|
2006-06-16 21:44:33 +00:00
|
|
|
{
|
2011-11-13 18:52:24 +00:00
|
|
|
wined3d_mutex_lock();
|
2012-03-15 20:49:58 +00:00
|
|
|
ddraw_free_handle(&material->ddraw->d3ddevice->handle_table, material->Handle - 1, DDRAW_HANDLE_MATERIAL);
|
2011-11-13 18:52:24 +00:00
|
|
|
wined3d_mutex_unlock();
|
2006-06-16 21:44:33 +00:00
|
|
|
}
|
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, material);
|
2002-11-21 21:04:16 +00:00
|
|
|
}
|
2012-03-15 20:49:58 +00:00
|
|
|
|
2005-01-09 17:29:21 +00:00
|
|
|
return ref;
|
2002-11-21 21:04:16 +00:00
|
|
|
}
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2006-06-09 17:36:12 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DMaterial Methods
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DMaterial::Initialize
|
|
|
|
*
|
|
|
|
* A no-op initialization
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* Direct3D: Pointer to a Direct3D interface
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* D3D_OK
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-15 20:49:58 +00:00
|
|
|
static HRESULT WINAPI d3d_material1_Initialize(IDirect3DMaterial *iface, IDirect3D *d3d)
|
2002-11-21 21:04:16 +00:00
|
|
|
{
|
2012-03-15 20:49:58 +00:00
|
|
|
TRACE("iface %p, d3d %p.\n", iface, d3d);
|
2006-06-09 17:36:12 +00:00
|
|
|
|
|
|
|
return D3D_OK;
|
2002-11-21 21:04:16 +00:00
|
|
|
}
|
1999-01-03 17:00:19 +00:00
|
|
|
|
2006-06-09 17:36:12 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DMaterial::Reserve
|
|
|
|
*
|
|
|
|
* DirectX 5 sdk: "The IDirect3DMaterial2::Reserve method is not implemented"
|
|
|
|
* Odd. They seem to have mixed their interfaces.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* DDERR_UNSUPPORTED
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-15 20:49:58 +00:00
|
|
|
static HRESULT WINAPI d3d_material1_Reserve(IDirect3DMaterial *iface)
|
2002-11-21 21:04:16 +00:00
|
|
|
{
|
2010-08-19 16:57:50 +00:00
|
|
|
TRACE("iface %p.\n", iface);
|
2006-06-09 17:36:12 +00:00
|
|
|
|
|
|
|
return DDERR_UNSUPPORTED;
|
2002-11-21 21:04:16 +00:00
|
|
|
}
|
1999-01-03 17:00:19 +00:00
|
|
|
|
2006-06-09 17:36:12 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DMaterial::Unreserve
|
|
|
|
*
|
|
|
|
* Not supported too
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* DDERR_UNSUPPORTED
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-15 20:49:58 +00:00
|
|
|
static HRESULT WINAPI d3d_material1_Unreserve(IDirect3DMaterial *iface)
|
2002-11-21 21:04:16 +00:00
|
|
|
{
|
2010-08-19 16:57:50 +00:00
|
|
|
TRACE("iface %p.\n", iface);
|
2006-06-09 17:36:12 +00:00
|
|
|
|
|
|
|
return DDERR_UNSUPPORTED;
|
2002-11-21 21:04:16 +00:00
|
|
|
}
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2006-06-09 17:36:12 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DMaterial3::SetMaterial
|
|
|
|
*
|
|
|
|
* Sets the material description
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* Mat: Material to set
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* D3D_OK on success
|
|
|
|
* DDERR_INVALIDPARAMS if Mat is NULL
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-15 20:49:58 +00:00
|
|
|
static HRESULT WINAPI d3d_material3_SetMaterial(IDirect3DMaterial3 *iface, D3DMATERIAL *mat)
|
2002-11-21 21:04:16 +00:00
|
|
|
{
|
2012-03-15 20:49:58 +00:00
|
|
|
struct d3d_material *material = impl_from_IDirect3DMaterial3(iface);
|
2010-08-19 16:57:50 +00:00
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
TRACE("iface %p, mat %p.\n", iface, mat);
|
2010-08-19 16:57:50 +00:00
|
|
|
if (TRACE_ON(ddraw))
|
2012-03-15 20:49:58 +00:00
|
|
|
dump_material(mat);
|
2002-11-21 21:04:16 +00:00
|
|
|
|
|
|
|
/* Stores the material */
|
2011-11-13 18:52:24 +00:00
|
|
|
wined3d_mutex_lock();
|
2012-03-15 20:49:58 +00:00
|
|
|
memset(&material->mat, 0, sizeof(material->mat));
|
|
|
|
memcpy(&material->mat, mat, mat->dwSize);
|
2011-11-13 18:52:24 +00:00
|
|
|
wined3d_mutex_unlock();
|
2007-05-20 22:05:06 +00:00
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
return DD_OK;
|
1999-01-03 17:00:19 +00:00
|
|
|
}
|
|
|
|
|
2006-06-09 17:36:12 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DMaterial3::GetMaterial
|
|
|
|
*
|
|
|
|
* Returns the material assigned to this interface
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* Mat: Pointer to a D3DMATERIAL structure to store the material description
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* D3D_OK on success
|
|
|
|
* DDERR_INVALIDPARAMS if Mat is NULL
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-15 20:49:58 +00:00
|
|
|
static HRESULT WINAPI d3d_material3_GetMaterial(IDirect3DMaterial3 *iface, D3DMATERIAL *mat)
|
2002-11-21 21:04:16 +00:00
|
|
|
{
|
2012-03-15 20:49:58 +00:00
|
|
|
struct d3d_material *material = impl_from_IDirect3DMaterial3(iface);
|
2002-11-21 21:04:16 +00:00
|
|
|
DWORD dwSize;
|
2010-08-19 16:57:50 +00:00
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
TRACE("iface %p, mat %p.\n", iface, mat);
|
2010-08-19 16:57:50 +00:00
|
|
|
if (TRACE_ON(ddraw))
|
|
|
|
{
|
2002-11-21 21:04:16 +00:00
|
|
|
TRACE(" Returning material : ");
|
2012-03-15 20:49:58 +00:00
|
|
|
dump_material(&material->mat);
|
2002-11-21 21:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copies the material structure */
|
2011-11-13 18:52:24 +00:00
|
|
|
wined3d_mutex_lock();
|
2012-03-15 20:49:58 +00:00
|
|
|
dwSize = mat->dwSize;
|
|
|
|
memcpy(mat, &material->mat, dwSize);
|
2011-11-13 18:52:24 +00:00
|
|
|
wined3d_mutex_unlock();
|
2002-11-21 21:04:16 +00:00
|
|
|
|
|
|
|
return DD_OK;
|
|
|
|
}
|
1999-01-03 17:00:19 +00:00
|
|
|
|
2006-06-09 17:36:12 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirect3DMaterial3::GetHandle
|
|
|
|
*
|
|
|
|
* Returns a handle for the material interface. The handle is simply a
|
|
|
|
* pointer to the material implementation
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* Direct3DDevice3: The device this handle is assigned to
|
|
|
|
* Handle: Address to write the handle to
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* D3D_OK on success
|
|
|
|
* DDERR_INVALIDPARAMS if Handle is NULL
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-15 20:49:58 +00:00
|
|
|
static HRESULT WINAPI d3d_material3_GetHandle(IDirect3DMaterial3 *iface,
|
2011-10-17 13:57:53 +00:00
|
|
|
IDirect3DDevice3 *device, D3DMATERIALHANDLE *handle)
|
1999-01-03 17:00:19 +00:00
|
|
|
{
|
2012-03-15 20:49:58 +00:00
|
|
|
struct d3d_material *material = impl_from_IDirect3DMaterial3(iface);
|
2012-04-09 18:43:40 +00:00
|
|
|
struct d3d_device *device_impl = unsafe_impl_from_IDirect3DDevice3(device);
|
2010-08-19 16:57:50 +00:00
|
|
|
|
2011-10-17 13:57:53 +00:00
|
|
|
TRACE("iface %p, device %p, handle %p.\n", iface, device, handle);
|
2006-06-16 21:44:33 +00:00
|
|
|
|
2011-11-13 18:52:24 +00:00
|
|
|
wined3d_mutex_lock();
|
2012-03-15 20:49:58 +00:00
|
|
|
material->active_device = device_impl;
|
|
|
|
if (!material->Handle)
|
2006-06-16 21:44:33 +00:00
|
|
|
{
|
2012-03-15 20:49:58 +00:00
|
|
|
DWORD h = ddraw_allocate_handle(&device_impl->handle_table, material, DDRAW_HANDLE_MATERIAL);
|
2010-07-29 10:56:57 +00:00
|
|
|
if (h == DDRAW_INVALID_HANDLE)
|
2006-06-16 21:44:33 +00:00
|
|
|
{
|
2010-07-29 10:56:57 +00:00
|
|
|
ERR("Failed to allocate a material handle.\n");
|
2011-11-13 18:52:24 +00:00
|
|
|
wined3d_mutex_unlock();
|
2006-06-16 21:44:33 +00:00
|
|
|
return DDERR_INVALIDPARAMS; /* Unchecked */
|
|
|
|
}
|
2010-07-29 10:56:57 +00:00
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
material->Handle = h + 1;
|
2006-06-16 21:44:33 +00:00
|
|
|
}
|
2012-03-15 20:49:58 +00:00
|
|
|
*handle = material->Handle;
|
2011-10-17 13:57:53 +00:00
|
|
|
TRACE(" returning handle %08x.\n", *handle);
|
2011-11-13 18:52:24 +00:00
|
|
|
wined3d_mutex_unlock();
|
2006-06-16 21:44:33 +00:00
|
|
|
|
|
|
|
return D3D_OK;
|
1999-01-03 17:00:19 +00:00
|
|
|
}
|
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
static HRESULT WINAPI d3d_material2_GetHandle(IDirect3DMaterial2 *iface,
|
2011-10-17 13:57:19 +00:00
|
|
|
IDirect3DDevice2 *device, D3DMATERIALHANDLE *handle)
|
1999-01-03 17:00:19 +00:00
|
|
|
{
|
2012-03-15 20:49:58 +00:00
|
|
|
struct d3d_material *material = impl_from_IDirect3DMaterial2(iface);
|
2012-04-09 18:43:40 +00:00
|
|
|
struct d3d_device *device_impl = unsafe_impl_from_IDirect3DDevice2(device);
|
2011-06-07 07:44:03 +00:00
|
|
|
|
2011-10-17 13:57:19 +00:00
|
|
|
TRACE("iface %p, device %p, handle %p.\n", iface, device, handle);
|
2010-08-19 16:57:50 +00:00
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
return d3d_material3_GetHandle(&material->IDirect3DMaterial3_iface,
|
|
|
|
device_impl ? &device_impl->IDirect3DDevice3_iface : NULL, handle);
|
1999-01-03 17:00:19 +00:00
|
|
|
}
|
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
static HRESULT WINAPI d3d_material1_GetHandle(IDirect3DMaterial *iface,
|
2011-10-17 13:56:43 +00:00
|
|
|
IDirect3DDevice *device, D3DMATERIALHANDLE *handle)
|
1999-01-03 17:00:19 +00:00
|
|
|
{
|
2012-03-15 20:49:58 +00:00
|
|
|
struct d3d_material *material = impl_from_IDirect3DMaterial(iface);
|
2012-04-09 18:43:40 +00:00
|
|
|
struct d3d_device *device_impl = unsafe_impl_from_IDirect3DDevice(device);
|
2011-06-07 07:54:33 +00:00
|
|
|
|
2011-10-17 13:56:43 +00:00
|
|
|
TRACE("iface %p, device %p, handle %p.\n", iface, device, handle);
|
2010-08-19 16:57:50 +00:00
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
return d3d_material3_GetHandle(&material->IDirect3DMaterial3_iface,
|
|
|
|
device_impl ? &device_impl->IDirect3DDevice3_iface : NULL, handle);
|
2002-11-21 21:04:16 +00:00
|
|
|
}
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
static HRESULT WINAPI d3d_material2_QueryInterface(IDirect3DMaterial2 *iface, REFIID riid, void **object)
|
2002-11-21 21:04:16 +00:00
|
|
|
{
|
2012-03-15 20:49:58 +00:00
|
|
|
struct d3d_material *material = impl_from_IDirect3DMaterial2(iface);
|
2011-06-07 07:44:03 +00:00
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
|
2010-08-19 16:57:50 +00:00
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
return d3d_material3_QueryInterface(&material->IDirect3DMaterial3_iface, riid, object);
|
1999-01-03 17:00:19 +00:00
|
|
|
}
|
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
static HRESULT WINAPI d3d_material1_QueryInterface(IDirect3DMaterial *iface, REFIID riid, void **object)
|
1999-01-03 17:00:19 +00:00
|
|
|
{
|
2012-03-15 20:49:58 +00:00
|
|
|
struct d3d_material *material = impl_from_IDirect3DMaterial(iface);
|
2011-06-07 07:54:33 +00:00
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
|
2010-08-19 16:57:50 +00:00
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
return d3d_material3_QueryInterface(&material->IDirect3DMaterial3_iface, riid, object);
|
1999-01-03 17:00:19 +00:00
|
|
|
}
|
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
static ULONG WINAPI d3d_material2_AddRef(IDirect3DMaterial2 *iface)
|
1999-01-03 17:00:19 +00:00
|
|
|
{
|
2012-03-15 20:49:58 +00:00
|
|
|
struct d3d_material *material = impl_from_IDirect3DMaterial2(iface);
|
2011-06-07 07:44:03 +00:00
|
|
|
|
2010-08-19 16:57:50 +00:00
|
|
|
TRACE("iface %p.\n", iface);
|
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
return d3d_material3_AddRef(&material->IDirect3DMaterial3_iface);
|
2002-11-21 21:04:16 +00:00
|
|
|
}
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
static ULONG WINAPI d3d_material1_AddRef(IDirect3DMaterial *iface)
|
2002-11-21 21:04:16 +00:00
|
|
|
{
|
2012-03-15 20:49:58 +00:00
|
|
|
struct d3d_material *material = impl_from_IDirect3DMaterial(iface);
|
2011-06-07 07:54:33 +00:00
|
|
|
|
2010-08-19 16:57:50 +00:00
|
|
|
TRACE("iface %p.\n", iface);
|
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
return d3d_material3_AddRef(&material->IDirect3DMaterial3_iface);
|
2002-11-21 21:04:16 +00:00
|
|
|
}
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
static ULONG WINAPI d3d_material2_Release(IDirect3DMaterial2 *iface)
|
2002-11-21 21:04:16 +00:00
|
|
|
{
|
2012-03-15 20:49:58 +00:00
|
|
|
struct d3d_material *material = impl_from_IDirect3DMaterial2(iface);
|
2011-06-07 07:44:03 +00:00
|
|
|
|
2010-08-19 16:57:50 +00:00
|
|
|
TRACE("iface %p.\n", iface);
|
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
return d3d_material3_Release(&material->IDirect3DMaterial3_iface);
|
1999-01-03 17:00:19 +00:00
|
|
|
}
|
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
static ULONG WINAPI d3d_material1_Release(IDirect3DMaterial *iface)
|
1999-01-03 17:00:19 +00:00
|
|
|
{
|
2012-03-15 20:49:58 +00:00
|
|
|
struct d3d_material *material = impl_from_IDirect3DMaterial(iface);
|
2011-06-07 07:54:33 +00:00
|
|
|
|
2010-08-19 16:57:50 +00:00
|
|
|
TRACE("iface %p.\n", iface);
|
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
return d3d_material3_Release(&material->IDirect3DMaterial3_iface);
|
2002-11-21 21:04:16 +00:00
|
|
|
}
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
static HRESULT WINAPI d3d_material2_SetMaterial(IDirect3DMaterial2 *iface, D3DMATERIAL *mat)
|
2002-11-21 21:04:16 +00:00
|
|
|
{
|
2012-03-15 20:49:58 +00:00
|
|
|
struct d3d_material *material = impl_from_IDirect3DMaterial2(iface);
|
2011-06-07 07:44:03 +00:00
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
TRACE("iface %p, material %p.\n", iface, mat);
|
2010-08-19 16:57:50 +00:00
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
return d3d_material3_SetMaterial(&material->IDirect3DMaterial3_iface, mat);
|
2002-11-21 21:04:16 +00:00
|
|
|
}
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
static HRESULT WINAPI d3d_material1_SetMaterial(IDirect3DMaterial *iface, D3DMATERIAL *mat)
|
2002-11-21 21:04:16 +00:00
|
|
|
{
|
2012-03-15 20:49:58 +00:00
|
|
|
struct d3d_material *material = impl_from_IDirect3DMaterial(iface);
|
2011-06-07 07:54:33 +00:00
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
TRACE("iface %p, material %p.\n", iface, mat);
|
2010-08-19 16:57:50 +00:00
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
return d3d_material3_SetMaterial(&material->IDirect3DMaterial3_iface, mat);
|
1999-01-03 17:00:19 +00:00
|
|
|
}
|
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
static HRESULT WINAPI d3d_material2_GetMaterial(IDirect3DMaterial2 *iface, D3DMATERIAL *mat)
|
2002-11-21 21:04:16 +00:00
|
|
|
{
|
2012-03-15 20:49:58 +00:00
|
|
|
struct d3d_material *material = impl_from_IDirect3DMaterial2(iface);
|
2011-06-07 07:44:03 +00:00
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
TRACE("iface %p, material %p.\n", iface, mat);
|
2010-08-19 16:57:50 +00:00
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
return d3d_material3_GetMaterial(&material->IDirect3DMaterial3_iface, mat);
|
2002-11-21 21:04:16 +00:00
|
|
|
}
|
1999-01-03 17:00:19 +00:00
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
static HRESULT WINAPI d3d_material1_GetMaterial(IDirect3DMaterial *iface, D3DMATERIAL *mat)
|
1999-01-03 17:00:19 +00:00
|
|
|
{
|
2012-03-15 20:49:58 +00:00
|
|
|
struct d3d_material *material = impl_from_IDirect3DMaterial(iface);
|
2011-06-07 07:54:33 +00:00
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
TRACE("iface %p, material %p.\n", iface, mat);
|
2010-08-19 16:57:50 +00:00
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
return d3d_material3_GetMaterial(&material->IDirect3DMaterial3_iface, mat);
|
2002-11-21 21:04:16 +00:00
|
|
|
}
|
1999-01-03 17:00:19 +00:00
|
|
|
|
2003-01-03 21:05:38 +00:00
|
|
|
|
2006-06-09 17:36:12 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* material_activate
|
|
|
|
*
|
|
|
|
* Uses IDirect3DDevice7::SetMaterial to activate the material
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* This: Pointer to the material implementation to activate
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-15 20:49:58 +00:00
|
|
|
void material_activate(struct d3d_material *material)
|
1999-01-03 17:00:19 +00:00
|
|
|
{
|
2006-06-09 17:36:12 +00:00
|
|
|
D3DMATERIAL7 d3d7mat;
|
1999-01-03 17:00:19 +00:00
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
TRACE("Activating material %p.\n", material);
|
|
|
|
|
|
|
|
d3d7mat.u.diffuse = material->mat.u.diffuse;
|
|
|
|
d3d7mat.u1.ambient = material->mat.u1.ambient;
|
|
|
|
d3d7mat.u2.specular = material->mat.u2.specular;
|
|
|
|
d3d7mat.u3.emissive = material->mat.u3.emissive;
|
|
|
|
d3d7mat.u4.power = material->mat.u4.power;
|
2006-06-09 17:36:12 +00:00
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
IDirect3DDevice7_SetMaterial(&material->active_device->IDirect3DDevice7_iface, &d3d7mat);
|
2006-06-09 17:36:12 +00:00
|
|
|
}
|
2002-11-21 21:04:16 +00:00
|
|
|
|
2010-08-18 17:26:22 +00:00
|
|
|
static const struct IDirect3DMaterial3Vtbl d3d_material3_vtbl =
|
1999-01-03 17:00:19 +00:00
|
|
|
{
|
2006-06-09 17:36:12 +00:00
|
|
|
/*** IUnknown Methods ***/
|
2012-03-15 20:49:58 +00:00
|
|
|
d3d_material3_QueryInterface,
|
|
|
|
d3d_material3_AddRef,
|
|
|
|
d3d_material3_Release,
|
2006-06-09 17:36:12 +00:00
|
|
|
/*** IDirect3DMaterial3 Methods ***/
|
2012-03-15 20:49:58 +00:00
|
|
|
d3d_material3_SetMaterial,
|
|
|
|
d3d_material3_GetMaterial,
|
|
|
|
d3d_material3_GetHandle,
|
2002-11-21 21:04:16 +00:00
|
|
|
};
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2010-08-18 17:26:22 +00:00
|
|
|
static const struct IDirect3DMaterial2Vtbl d3d_material2_vtbl =
|
1999-05-22 11:41:38 +00:00
|
|
|
{
|
2006-06-09 17:36:12 +00:00
|
|
|
/*** IUnknown Methods ***/
|
2012-03-15 20:49:58 +00:00
|
|
|
d3d_material2_QueryInterface,
|
|
|
|
d3d_material2_AddRef,
|
|
|
|
d3d_material2_Release,
|
2006-06-09 17:36:12 +00:00
|
|
|
/*** IDirect3DMaterial2 Methods ***/
|
2012-03-15 20:49:58 +00:00
|
|
|
d3d_material2_SetMaterial,
|
|
|
|
d3d_material2_GetMaterial,
|
|
|
|
d3d_material2_GetHandle,
|
1999-01-03 17:00:19 +00:00
|
|
|
};
|
|
|
|
|
2010-08-18 17:26:22 +00:00
|
|
|
static const struct IDirect3DMaterialVtbl d3d_material1_vtbl =
|
1999-05-22 11:41:38 +00:00
|
|
|
{
|
2006-06-09 17:36:12 +00:00
|
|
|
/*** IUnknown Methods ***/
|
2012-03-15 20:49:58 +00:00
|
|
|
d3d_material1_QueryInterface,
|
|
|
|
d3d_material1_AddRef,
|
|
|
|
d3d_material1_Release,
|
2006-06-09 17:36:12 +00:00
|
|
|
/*** IDirect3DMaterial1 Methods ***/
|
2012-03-15 20:49:58 +00:00
|
|
|
d3d_material1_Initialize,
|
|
|
|
d3d_material1_SetMaterial,
|
|
|
|
d3d_material1_GetMaterial,
|
|
|
|
d3d_material1_GetHandle,
|
|
|
|
d3d_material1_Reserve,
|
|
|
|
d3d_material1_Unreserve,
|
2006-06-09 17:36:12 +00:00
|
|
|
};
|
2010-08-18 17:26:22 +00:00
|
|
|
|
2012-03-15 20:49:58 +00:00
|
|
|
struct d3d_material *d3d_material_create(struct ddraw *ddraw)
|
2010-08-18 17:26:22 +00:00
|
|
|
{
|
2012-03-15 20:49:58 +00:00
|
|
|
struct d3d_material *material;
|
2011-06-08 15:29:20 +00:00
|
|
|
|
|
|
|
material = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*material));
|
|
|
|
if (!material)
|
|
|
|
return NULL;
|
|
|
|
|
2011-06-08 15:38:16 +00:00
|
|
|
material->IDirect3DMaterial3_iface.lpVtbl = &d3d_material3_vtbl;
|
2011-06-07 07:44:03 +00:00
|
|
|
material->IDirect3DMaterial2_iface.lpVtbl = &d3d_material2_vtbl;
|
2011-06-07 07:54:33 +00:00
|
|
|
material->IDirect3DMaterial_iface.lpVtbl = &d3d_material1_vtbl;
|
2010-08-18 17:26:22 +00:00
|
|
|
material->ref = 1;
|
|
|
|
material->ddraw = ddraw;
|
2011-06-08 15:29:20 +00:00
|
|
|
|
|
|
|
return material;
|
2010-08-18 17:26:22 +00:00
|
|
|
}
|