2014-07-19 18:35:47 +00:00
# include "d3d8Wrapper.h"
extern " C "
{
namespace D3D8Wrapper
{
ThreadSafePointerSet IDirect3D8 : : m_List ;
2014-07-20 02:38:57 +00:00
D3D8Wrapper : : IDirect3D8 : : IDirect3D8 ( D3D8Base : : IDirect3D8 * real ) : D3D8Wrapper : : IDirect3DUnknown ( ( IUnknown * ) real )
{
2014-08-10 21:14:29 +00:00
LOG ( " IDirect3D8::IDirect3D8( " < < real < < " ) \n " ) ;
2014-07-20 02:38:57 +00:00
m_pD3D = real ;
}
// Tries to find the real object in the pointer set, or creates a new wrapped object
2014-07-19 18:35:47 +00:00
D3D8Wrapper : : IDirect3D8 * D3D8Wrapper : : IDirect3D8 : : GetDirect3D ( D3D8Base : : IDirect3D8 * pD3D )
{
2014-08-10 21:14:29 +00:00
LOG ( " IDirect3D8::GetDirect3D( " < < pD3D < < " ) \n " ) ;
2014-07-19 18:35:47 +00:00
D3D8Wrapper : : IDirect3D8 * p = ( D3D8Wrapper : : IDirect3D8 * ) m_List . GetDataPtr ( pD3D ) ;
if ( p = = NULL )
{
p = new D3D8Wrapper : : IDirect3D8 ( pD3D ) ;
m_List . AddMember ( pD3D , p ) ;
return p ;
}
p - > m_ulRef + + ;
return p ;
}
STDMETHODIMP_ ( ULONG ) D3D8Wrapper : : IDirect3D8 : : Release ( THIS )
{
2014-08-25 22:21:59 +00:00
LOG ( " IDirect3D8::Release() [ " < < this < < " ] \n " ) ;
2014-07-19 18:35:47 +00:00
m_pUnk - > Release ( ) ;
ULONG ulRef = - - m_ulRef ;
if ( ulRef = = 0 )
{
m_List . DeleteMember ( GetDirect3D8 ( ) ) ;
delete this ;
return 0L ;
}
return ulRef ;
}
2014-07-20 02:38:57 +00:00
2014-08-10 21:14:29 +00:00
/*** IDirect3D8 methods ***/
2014-07-19 18:35:47 +00:00
STDMETHODIMP D3D8Wrapper : : IDirect3D8 : : GetAdapterDisplayMode ( THIS_ UINT Adapter , D3D8Base : : D3DDISPLAYMODE * pMode )
{
2014-08-25 22:21:59 +00:00
LOG ( " IDirect3D8::GetAdapterDisplayMode( " < < Adapter < < " , " < < pMode < < " ) [ " < < this < < " ] \n " ) ;
2014-07-20 02:38:57 +00:00
return m_pD3D - > GetAdapterDisplayMode ( Adapter , pMode ) ;
2014-07-19 18:35:47 +00:00
}
STDMETHODIMP D3D8Wrapper : : IDirect3D8 : : RegisterSoftwareDevice ( void * pInitializeFunction )
{
2014-08-25 22:21:59 +00:00
LOG ( " IDirect3D8::RegisterSoftwareDevice( " < < pInitializeFunction < < " ) [ " < < this < < " ] \n " ) ;
2014-07-20 02:38:57 +00:00
return m_pD3D - > RegisterSoftwareDevice ( pInitializeFunction ) ;
2014-07-19 18:35:47 +00:00
}
STDMETHODIMP_ ( UINT ) D3D8Wrapper : : IDirect3D8 : : GetAdapterCount ( THIS )
{
2014-08-25 22:21:59 +00:00
LOG ( " IDirect3D8::GetAdapterCount() [ " < < this < < " ] \n " ) ;
2014-07-19 18:35:47 +00:00
return m_pD3D - > GetAdapterCount ( ) ;
}
STDMETHODIMP D3D8Wrapper : : IDirect3D8 : : GetAdapterIdentifier ( UINT Adapter , DWORD Flags , D3D8Base : : D3DADAPTER_IDENTIFIER8 * pIdentifier )
{
2014-08-25 22:21:59 +00:00
LOG ( " IDirect3D8::GetAdapterIdentifier( " < < Adapter < < " , " < < Flags < < " , " < < pIdentifier < < " ) [ " < < this < < " ] \n " ) ;
2014-07-20 02:38:57 +00:00
return m_pD3D - > GetAdapterIdentifier ( Adapter , Flags , pIdentifier ) ;
2014-07-19 18:35:47 +00:00
}
STDMETHODIMP_ ( UINT ) D3D8Wrapper : : IDirect3D8 : : GetAdapterModeCount ( UINT Adapter )
{
2014-08-25 22:21:59 +00:00
LOG ( " IDirect3D8::GetAdapterModeCount( " < < Adapter < < " ) [ " < < this < < " ] \n " ) ;
2014-07-19 18:35:47 +00:00
return m_pD3D - > GetAdapterModeCount ( Adapter ) ;
}
STDMETHODIMP D3D8Wrapper : : IDirect3D8 : : EnumAdapterModes ( UINT Adapter , UINT Mode , D3D8Base : : D3DDISPLAYMODE * pMode )
{
2014-08-25 22:21:59 +00:00
LOG ( " IDirect3D8::EnumAdapterModes( " < < Adapter < < " , " < < Mode < < " , " < < pMode < < " ) [ " < < this < < " ] \n " ) ;
2014-07-20 02:38:57 +00:00
return m_pD3D - > EnumAdapterModes ( Adapter , Mode , pMode ) ;
2014-07-19 18:35:47 +00:00
}
STDMETHODIMP D3D8Wrapper : : IDirect3D8 : : CheckDeviceType ( UINT Adapter , D3D8Base : : D3DDEVTYPE CheckType , D3D8Base : : D3DFORMAT DisplayFormat , D3D8Base : : D3DFORMAT BackBufferFormat , BOOL Windowed )
{
2014-08-25 22:21:59 +00:00
LOG ( " IDirect3D8::CheckDeviceType( " < < Adapter < < " , " < < CheckType < < " , " < < DisplayFormat < < " , " < < BackBufferFormat < < " , " < < Windowed < < " ) [ " < < this < < " ] \n " ) ;
2014-07-20 02:38:57 +00:00
return m_pD3D - > CheckDeviceType ( Adapter , CheckType , DisplayFormat , BackBufferFormat , Windowed ) ;
2014-07-19 18:35:47 +00:00
}
STDMETHODIMP D3D8Wrapper : : IDirect3D8 : : CheckDeviceFormat ( UINT Adapter , D3D8Base : : D3DDEVTYPE DeviceType , D3D8Base : : D3DFORMAT AdapterFormat , DWORD Usage , D3D8Base : : D3DRESOURCETYPE RType , D3D8Base : : D3DFORMAT CheckFormat )
{
2014-08-25 22:21:59 +00:00
LOG ( " IDirect3D8::CheckDeviceFormat( " < < Adapter < < " , " < < DeviceType < < " , " < < AdapterFormat < < " , " < < Usage < < " , " < < RType < < " , " < < CheckFormat < < " ) [ " < < this < < " ] \n " ) ;
2014-07-20 02:38:57 +00:00
return m_pD3D - > CheckDeviceFormat ( Adapter , DeviceType , AdapterFormat , Usage , RType , CheckFormat ) ;
2014-07-19 18:35:47 +00:00
}
STDMETHODIMP D3D8Wrapper : : IDirect3D8 : : CheckDeviceMultiSampleType ( UINT Adapter , D3D8Base : : D3DDEVTYPE DeviceType , D3D8Base : : D3DFORMAT SurfaceFormat , BOOL Windowed , D3D8Base : : D3DMULTISAMPLE_TYPE MultiSampleType )
{
2014-08-25 22:21:59 +00:00
LOG ( " IDirect3D8::CheckDeviceMultiSampleType( " < < Adapter < < " , " < < DeviceType < < " , " < < SurfaceFormat < < " , " < < Windowed < < " , " < < MultiSampleType < < " ) [ " < < this < < " ] \n " ) ;
2014-07-20 02:38:57 +00:00
return m_pD3D - > CheckDeviceMultiSampleType ( Adapter , DeviceType , SurfaceFormat , Windowed , MultiSampleType ) ;
2014-07-19 18:35:47 +00:00
}
STDMETHODIMP D3D8Wrapper : : IDirect3D8 : : CheckDepthStencilMatch ( UINT Adapter , D3D8Base : : D3DDEVTYPE DeviceType , D3D8Base : : D3DFORMAT AdapterFormat , D3D8Base : : D3DFORMAT RenderTargetFormat , D3D8Base : : D3DFORMAT DepthStencilFormat )
{
2014-08-25 22:21:59 +00:00
LOG ( " IDirect3D8::CheckDepthStencilMatch( " < < Adapter < < " , " < < DeviceType < < " , " < < AdapterFormat < < " , " < < RenderTargetFormat < < " , " < < DepthStencilFormat < < " ) [ " < < this < < " ] \n " ) ;
2014-07-20 02:38:57 +00:00
return m_pD3D - > CheckDepthStencilMatch ( Adapter , DeviceType , AdapterFormat , RenderTargetFormat , DepthStencilFormat ) ;
2014-07-19 18:35:47 +00:00
}
STDMETHODIMP D3D8Wrapper : : IDirect3D8 : : GetDeviceCaps ( UINT Adapter , D3D8Base : : D3DDEVTYPE DeviceType , D3D8Base : : D3DCAPS8 * pCaps )
{
2014-08-25 22:21:59 +00:00
LOG ( " IDirect3D8::GetDeviceCaps( " < < Adapter < < " , " < < DeviceType < < " , " < < pCaps < < " ) [ " < < this < < " ] \n " ) ;
2014-07-20 02:38:57 +00:00
return m_pD3D - > GetDeviceCaps ( Adapter , DeviceType , pCaps ) ;
2014-07-19 18:35:47 +00:00
}
STDMETHODIMP_ ( HMONITOR ) D3D8Wrapper : : IDirect3D8 : : GetAdapterMonitor ( UINT Adapter )
{
2014-08-25 22:21:59 +00:00
LOG ( " IDirect3D8::GetAdapterMonitor( " < < Adapter < < " ) [ " < < this < < " ] \n " ) ;
2014-07-19 18:35:47 +00:00
return m_pD3D - > GetAdapterMonitor ( Adapter ) ;
}
STDMETHODIMP D3D8Wrapper : : IDirect3D8 : : CreateDevice ( UINT Adapter , D3D8Base : : D3DDEVTYPE DeviceType , HWND hFocusWindow , DWORD BehaviorFlags , D3D8Base : : D3DPRESENT_PARAMETERS * pPresentationParameters , D3D8Wrapper : : IDirect3DDevice8 * * ppReturnedDeviceInterface )
{
2015-08-20 03:20:56 +00:00
//sometimes, Intel drivers will clear the dll path. So let's save and restore it (do their job for them)
//it doesn't seem like this happens any time besides creating the D3D8 object and a device.
//If it does, then this solution isn't scalable at all.
//This is a good place to note that it appears possible that on the affected drivers, the D3D9 interface will only SetDllDirectory the first time a D3D9 object is created
char oldDllDirectory [ MAX_PATH ] ;
GetDllDirectory ( MAX_PATH , oldDllDirectory ) ;
2014-08-25 22:21:59 +00:00
LOG ( " IDirect3D8::CreateDevice( " < < Adapter < < " , " < < DeviceType < < " , " < < hFocusWindow < < " , " < < BehaviorFlags < < " , " < < pPresentationParameters < < " , " < < ppReturnedDeviceInterface < < " ) [ " < < this < < " ] \n " ) ;
2014-08-10 21:14:29 +00:00
D3D8Base : : IDirect3DDevice8 * realDevice = NULL ;
2014-07-19 18:35:47 +00:00
2014-08-10 21:14:29 +00:00
HRESULT hr = m_pD3D - > CreateDevice ( Adapter , DeviceType , hFocusWindow , BehaviorFlags , pPresentationParameters , & realDevice ) ;
2015-08-20 03:20:56 +00:00
//restore old DLL directory
SetDllDirectory ( oldDllDirectory ) ;
2014-07-26 22:50:50 +00:00
if ( FAILED ( hr ) )
{
return hr ;
}
2014-07-19 18:35:47 +00:00
2014-07-20 02:38:57 +00:00
// Wrap the real object
2014-08-10 21:14:29 +00:00
D3D8Wrapper : : IDirect3DDevice8 * wrappedDevice = D3D8Wrapper : : IDirect3DDevice8 : : GetDirect3DDevice ( realDevice ) ;
2014-07-19 18:35:47 +00:00
2014-08-10 21:14:29 +00:00
// Store this wrapped pointer for grabbing the screen later
last_device = wrappedDevice ;
2014-07-19 18:35:47 +00:00
2014-08-10 21:14:29 +00:00
// Create a new render target
D3D8Base : : IDirect3DSurface8 * realSurface = NULL ;
HRESULT hr2 = realDevice - > CreateRenderTarget ( pPresentationParameters - > BackBufferWidth , pPresentationParameters - > BackBufferHeight , D3D8Base : : D3DFMT_X8R8G8B8 , pPresentationParameters - > MultiSampleType , FALSE , & realSurface ) ;
2014-07-23 02:44:33 +00:00
2014-08-10 21:14:29 +00:00
// Store a wrapped pointer to it for grabbing the screen
render_surface = D3D8Wrapper : : IDirect3DSurface8 : : GetSurface ( realSurface ) ;
2014-07-23 02:44:33 +00:00
2014-07-20 02:38:57 +00:00
// Return our wrapped object
2014-08-10 21:14:29 +00:00
* ppReturnedDeviceInterface = wrappedDevice ;
2014-07-19 18:35:47 +00:00
return hr ;
}
}
}