| 11 | cycrow | 1 | #pragma once
 | 
        
           |  |  | 2 |   | 
        
           |  |  | 3 | #include "MyDirect3DDevice9.h"
 | 
        
           |  |  | 4 |   | 
        
           |  |  | 5 | class MyDirect3D9 : public IDirect3D9
 | 
        
           |  |  | 6 | {
 | 
        
           |  |  | 7 | public:
 | 
        
           |  |  | 8 | 	MyDirect3D9(IDirect3D9* d3d, COverlay *o) : m_d3d(d3d), m_pOverlay(o)
 | 
        
           |  |  | 9 | 	{
 | 
        
           |  |  | 10 | 	}
 | 
        
           |  |  | 11 |   | 
        
           |  |  | 12 | 	/*** IUnknown methods ***/
 | 
        
           |  |  | 13 |     HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObj)
 | 
        
           |  |  | 14 | 	{
 | 
        
           |  |  | 15 | 		return m_d3d->QueryInterface(riid, ppvObj);
 | 
        
           |  |  | 16 | 	}
 | 
        
           |  |  | 17 |   | 
        
           |  |  | 18 |     ULONG STDMETHODCALLTYPE AddRef()
 | 
        
           |  |  | 19 | 	{
 | 
        
           |  |  | 20 | 		return m_d3d->AddRef();
 | 
        
           |  |  | 21 | 	}
 | 
        
           |  |  | 22 |   | 
        
           |  |  | 23 |     ULONG STDMETHODCALLTYPE Release()
 | 
        
           |  |  | 24 | 	{
 | 
        
           |  |  | 25 | 		ULONG count = m_d3d->Release();
 | 
        
           |  |  | 26 | 		if(0 == count)
 | 
        
           |  |  | 27 | 			delete this;
 | 
        
           |  |  | 28 |   | 
        
           |  |  | 29 | 		return count;
 | 
        
           |  |  | 30 | 	}
 | 
        
           |  |  | 31 |   | 
        
           |  |  | 32 |     /*** IDirect3D9 methods ***/
 | 
        
           |  |  | 33 |     HRESULT STDMETHODCALLTYPE RegisterSoftwareDevice(void* pInitializeFunction)
 | 
        
           |  |  | 34 | 	{
 | 
        
           |  |  | 35 | 		return m_d3d->RegisterSoftwareDevice(pInitializeFunction);
 | 
        
           |  |  | 36 | 	}
 | 
        
           |  |  | 37 |   | 
        
           |  |  | 38 |     UINT STDMETHODCALLTYPE GetAdapterCount()
 | 
        
           |  |  | 39 | 	{
 | 
        
           |  |  | 40 | 		return m_d3d->GetAdapterCount();
 | 
        
           |  |  | 41 | 	}
 | 
        
           |  |  | 42 |   | 
        
           |  |  | 43 |     HRESULT STDMETHODCALLTYPE GetAdapterIdentifier( UINT Adapter,DWORD Flags,D3DADAPTER_IDENTIFIER9* pIdentifier)
 | 
        
           |  |  | 44 | 	{
 | 
        
           |  |  | 45 | 		return m_d3d->GetAdapterIdentifier(Adapter, Flags, pIdentifier);
 | 
        
           |  |  | 46 | 	}
 | 
        
           |  |  | 47 |   | 
        
           |  |  | 48 |     UINT STDMETHODCALLTYPE GetAdapterModeCount( UINT Adapter,D3DFORMAT Format)
 | 
        
           |  |  | 49 | 	{
 | 
        
           |  |  | 50 | 		return m_d3d->GetAdapterModeCount(Adapter, Format);
 | 
        
           |  |  | 51 | 	}
 | 
        
           |  |  | 52 |   | 
        
           |  |  | 53 |     HRESULT STDMETHODCALLTYPE EnumAdapterModes( UINT Adapter,D3DFORMAT Format,UINT Mode,D3DDISPLAYMODE* pMode)
 | 
        
           |  |  | 54 | 	{
 | 
        
           |  |  | 55 | 		return m_d3d->EnumAdapterModes(Adapter, Format, Mode, pMode);
 | 
        
           |  |  | 56 | 	}
 | 
        
           |  |  | 57 |   | 
        
           |  |  | 58 |     HRESULT STDMETHODCALLTYPE GetAdapterDisplayMode( UINT Adapter,D3DDISPLAYMODE* pMode)
 | 
        
           |  |  | 59 | 	{
 | 
        
           |  |  | 60 | 		return m_d3d->GetAdapterDisplayMode(Adapter, pMode);
 | 
        
           |  |  | 61 | 	}
 | 
        
           |  |  | 62 |   | 
        
           |  |  | 63 |     HRESULT STDMETHODCALLTYPE CheckDeviceType( UINT Adapter,D3DDEVTYPE DevType,D3DFORMAT AdapterFormat,D3DFORMAT BackBufferFormat,BOOL bWindowed)
 | 
        
           |  |  | 64 | 	{
 | 
        
           |  |  | 65 | 		return m_d3d->CheckDeviceType(Adapter, DevType, AdapterFormat, BackBufferFormat, bWindowed);
 | 
        
           |  |  | 66 | 	}
 | 
        
           |  |  | 67 |   | 
        
           |  |  | 68 |     HRESULT STDMETHODCALLTYPE CheckDeviceFormat( UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,DWORD Usage,D3DRESOURCETYPE RType,D3DFORMAT CheckFormat)
 | 
        
           |  |  | 69 | 	{
 | 
        
           |  |  | 70 | 		return m_d3d->CheckDeviceFormat(Adapter, DeviceType, AdapterFormat, Usage, RType, CheckFormat);
 | 
        
           |  |  | 71 | 	}
 | 
        
           |  |  | 72 |   | 
        
           |  |  | 73 |     HRESULT STDMETHODCALLTYPE CheckDeviceMultiSampleType( UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT SurfaceFormat,BOOL Windowed,D3DMULTISAMPLE_TYPE MultiSampleType,DWORD* pQualityLevels)
 | 
        
           |  |  | 74 | 	{
 | 
        
           |  |  | 75 | 		return m_d3d->CheckDeviceMultiSampleType(Adapter, DeviceType, SurfaceFormat, Windowed, MultiSampleType, pQualityLevels);
 | 
        
           |  |  | 76 | 	}
 | 
        
           |  |  | 77 |   | 
        
           |  |  | 78 |     HRESULT STDMETHODCALLTYPE CheckDepthStencilMatch( UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,D3DFORMAT RenderTargetFormat,D3DFORMAT DepthStencilFormat)
 | 
        
           |  |  | 79 | 	{
 | 
        
           |  |  | 80 | 		return m_d3d->CheckDepthStencilMatch(Adapter, DeviceType, AdapterFormat, RenderTargetFormat, DepthStencilFormat);
 | 
        
           |  |  | 81 | 	}
 | 
        
           |  |  | 82 |   | 
        
           |  |  | 83 |     HRESULT STDMETHODCALLTYPE CheckDeviceFormatConversion( UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT SourceFormat,D3DFORMAT TargetFormat)
 | 
        
           |  |  | 84 | 	{
 | 
        
           |  |  | 85 | 		return m_d3d->CheckDeviceFormatConversion(Adapter, DeviceType, SourceFormat, TargetFormat);
 | 
        
           |  |  | 86 | 	}
 | 
        
           |  |  | 87 |   | 
        
           |  |  | 88 |     HRESULT STDMETHODCALLTYPE GetDeviceCaps( UINT Adapter,D3DDEVTYPE DeviceType,D3DCAPS9* pCaps)
 | 
        
           |  |  | 89 | 	{
 | 
        
           |  |  | 90 | 		return m_d3d->GetDeviceCaps(Adapter, DeviceType, pCaps);
 | 
        
           |  |  | 91 | 	}
 | 
        
           |  |  | 92 |   | 
        
           |  |  | 93 |     HMONITOR STDMETHODCALLTYPE GetAdapterMonitor( UINT Adapter)
 | 
        
           |  |  | 94 | 	{
 | 
        
           |  |  | 95 | 		return m_d3d->GetAdapterMonitor(Adapter);
 | 
        
           |  |  | 96 | 	}
 | 
        
           |  |  | 97 |   | 
        
           |  |  | 98 |     HRESULT STDMETHODCALLTYPE CreateDevice( UINT Adapter,D3DDEVTYPE DeviceType,HWND hFocusWindow,DWORD BehaviorFlags,D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DDevice9** ppReturnedDeviceInterface)
 | 
        
           |  |  | 99 | 	{
 | 
        
           |  |  | 100 | 		HRESULT hr = m_d3d->CreateDevice(Adapter, DeviceType, hFocusWindow, BehaviorFlags,
 | 
        
           |  |  | 101 | 			pPresentationParameters, ppReturnedDeviceInterface);
 | 
        
           |  |  | 102 |   | 
        
           |  |  | 103 | 		if(SUCCEEDED(hr))
 | 
        
           |  |  | 104 | 		{
 | 
        
           |  |  | 105 | 			m_pOverlay->SetWindowSize ( pPresentationParameters->BackBufferWidth, pPresentationParameters->BackBufferHeight );
 | 
        
           |  |  | 106 |   | 
        
           |  |  | 107 | 			// Return our device
 | 
        
           |  |  | 108 | 			*ppReturnedDeviceInterface = new MyDirect3DDevice9(this, *ppReturnedDeviceInterface, m_pOverlay);
 | 
        
           |  |  | 109 |   | 
        
           |  |  | 110 | 		}
 | 
        
           |  |  | 111 |   | 
        
           |  |  | 112 | 		return hr;
 | 
        
           |  |  | 113 | 	}
 | 
        
           |  |  | 114 |   | 
        
           |  |  | 115 | private:
 | 
        
           |  |  | 116 | 	IDirect3D9* m_d3d;
 | 
        
           |  |  | 117 | 	COverlay *m_pOverlay;
 | 
        
           |  |  | 118 | };
 |