#include "StdAfx.h" #include "../eterBase/Stl.h" #include "GrpDetector.h" struct FIsEqualD3DDisplayMode { FIsEqualD3DDisplayMode(D3DDISPLAYMODE* pkD3DDMChk) { m_pkD3DDMChk=pkD3DDMChk; } BOOL operator() (D3DDISPLAYMODE& rkD3DDMTest) { if (rkD3DDMTest.Width!=m_pkD3DDMChk->Width) return FALSE; if (rkD3DDMTest.Height!=m_pkD3DDMChk->Height) return FALSE; if (rkD3DDMTest.Format!=m_pkD3DDMChk->Format) return FALSE; return TRUE; } D3DDISPLAYMODE* m_pkD3DDMChk; }; static int CompareD3DDisplayModeOrder( const VOID* arg1, const VOID* arg2 ) { D3DDISPLAYMODE* p1 = (D3DDISPLAYMODE*)arg1; D3DDISPLAYMODE* p2 = (D3DDISPLAYMODE*)arg2; if( p1->Format > p2->Format ) return -1; if( p1->Format < p2->Format ) return +1; if( p1->Width < p2->Width ) return -1; if( p1->Width > p2->Width ) return +1; if( p1->Height < p2->Height ) return -1; if( p1->Height > p2->Height ) return +1; return 0; } ///////////////////////////////////////////////////////////////////////////////// UINT D3D_CAdapterDisplayModeList::GetDisplayModeNum() { return m_uD3DDMNum; } UINT D3D_CAdapterDisplayModeList::GetPixelFormatNum() { return m_uD3DFmtNum; } const D3DDISPLAYMODE& D3D_CAdapterDisplayModeList::GetDisplayModer(UINT iD3DDM) { assert(iD3DDMappend(szText); } ///////////////////////////////////////////////////////////////////////////////// const CHAR* D3D_CDeviceInfo::msc_aszD3DDevDesc[D3DDEVICETYPE_NUM] = {"HAL", "REF"}; const D3DDEVTYPE D3D_CDeviceInfo::msc_aeD3DDevType[D3DDEVICETYPE_NUM]={D3DDEVTYPE_HAL, D3DDEVTYPE_REF}; UINT D3D_CDeviceInfo::GetD3DModeInfoNum() { return m_uD3DModeInfoNum; } D3D_SModeInfo* D3D_CDeviceInfo::GetD3DModeInfop(UINT iD3D_SModeInfo) { if (iD3D_SModeInfo >= m_uD3DModeInfoNum) return NULL; return &m_akD3DModeInfo[iD3D_SModeInfo]; } BOOL D3D_CDeviceInfo::FindDepthStencilFormat(IDirect3D8& rkD3D, UINT iD3DAdapterInfo, D3DDEVTYPE DeviceType, D3DFORMAT TargetFormat, D3DFORMAT* pDepthStencilFormat ) { UINT m_dwMinDepthBits = 16; UINT m_dwMinStencilBits = 0; if( m_dwMinDepthBits <= 16 && m_dwMinStencilBits == 0 ) { if( SUCCEEDED( rkD3D.CheckDeviceFormat( iD3DAdapterInfo, DeviceType, TargetFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D16 ) ) ) { if( SUCCEEDED( rkD3D.CheckDepthStencilMatch( iD3DAdapterInfo, DeviceType, TargetFormat, TargetFormat, D3DFMT_D16 ) ) ) { *pDepthStencilFormat = D3DFMT_D16; return TRUE; } } } if( m_dwMinDepthBits <= 15 && m_dwMinStencilBits <= 1 ) { if( SUCCEEDED( rkD3D.CheckDeviceFormat( iD3DAdapterInfo, DeviceType, TargetFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D15S1 ) ) ) { if( SUCCEEDED( rkD3D.CheckDepthStencilMatch( iD3DAdapterInfo, DeviceType, TargetFormat, TargetFormat, D3DFMT_D15S1 ) ) ) { *pDepthStencilFormat = D3DFMT_D15S1; return TRUE; } } } if( m_dwMinDepthBits <= 24 && m_dwMinStencilBits == 0 ) { if( SUCCEEDED( rkD3D.CheckDeviceFormat( iD3DAdapterInfo, DeviceType, TargetFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24X8 ) ) ) { if( SUCCEEDED( rkD3D.CheckDepthStencilMatch( iD3DAdapterInfo, DeviceType, TargetFormat, TargetFormat, D3DFMT_D24X8 ) ) ) { *pDepthStencilFormat = D3DFMT_D24X8; return TRUE; } } } if( m_dwMinDepthBits <= 24 && m_dwMinStencilBits <= 8 ) { if( SUCCEEDED( rkD3D.CheckDeviceFormat( iD3DAdapterInfo, DeviceType, TargetFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24S8 ) ) ) { if( SUCCEEDED( rkD3D.CheckDepthStencilMatch( iD3DAdapterInfo, DeviceType, TargetFormat, TargetFormat, D3DFMT_D24S8 ) ) ) { *pDepthStencilFormat = D3DFMT_D24S8; return TRUE; } } } if( m_dwMinDepthBits <= 24 && m_dwMinStencilBits <= 4 ) { if( SUCCEEDED( rkD3D.CheckDeviceFormat( iD3DAdapterInfo, DeviceType, TargetFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24X4S4 ) ) ) { if( SUCCEEDED( rkD3D.CheckDepthStencilMatch( iD3DAdapterInfo, DeviceType, TargetFormat, TargetFormat, D3DFMT_D24X4S4 ) ) ) { *pDepthStencilFormat = D3DFMT_D24X4S4; return TRUE; } } } if( m_dwMinDepthBits <= 32 && m_dwMinStencilBits == 0 ) { if( SUCCEEDED( rkD3D.CheckDeviceFormat( iD3DAdapterInfo, DeviceType, TargetFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D32 ) ) ) { if( SUCCEEDED( rkD3D.CheckDepthStencilMatch( iD3DAdapterInfo, DeviceType, TargetFormat, TargetFormat, D3DFMT_D32 ) ) ) { *pDepthStencilFormat = D3DFMT_D32; return TRUE; } } } return FALSE; } BOOL D3D_CDeviceInfo::Build(IDirect3D8& rkD3D, UINT iD3DAdapterInfo, UINT iDevType, D3D_CAdapterDisplayModeList& rkD3DADMList, BOOL (*pfnConfirmDevice)(D3DCAPS8& rkD3DCaps, UINT uBehavior, D3DFORMAT eD3DFmt)) { assert(pfnConfirmDevice!=NULL && "D3D_CDeviceInfo::Build"); const D3DDEVTYPE c_eD3DDevType=msc_aeD3DDevType[iDevType]; const TCHAR* c_szD3DDevDesc=msc_aszD3DDevDesc[iDevType]; m_eD3DDevType = c_eD3DDevType; rkD3D.GetDeviceCaps(iD3DAdapterInfo, c_eD3DDevType, &m_kD3DCaps); m_szDevDesc = c_szD3DDevDesc; m_uD3DModeInfoNum=0; m_canDoWindowed = FALSE; m_isWindowed = FALSE; m_eD3DMSTFullscreen = D3DMULTISAMPLE_NONE; m_eD3DMSTWindowed = D3DMULTISAMPLE_NONE; BOOL aisFormatConfirmed[20]; DWORD adwD3DBehavior[20]; D3DFORMAT aeD3DFmtDepthStencil[20]; BOOL isHALExists = FALSE; BOOL isHALWindowedCompatible = FALSE; BOOL isHALDesktopCompatible = FALSE; BOOL isHALSampleCompatible = FALSE; // GetFlagInfo { UINT uD3DFmtNum=rkD3DADMList.GetPixelFormatNum(); for (DWORD iFmt=0; iFmt0) return TRUE; return FALSE; } BOOL D3D_CDeviceInfo::Find(UINT uScrWidth, UINT uScrHeight, UINT uScrDepthBits, BOOL isWindowed, UINT* piD3DModeInfo) { if (isWindowed) if (!m_isWindowed) return FALSE; for (UINT iD3D_SModeInfo=0; iD3D_SModeInfoappend(szText); for (UINT iD3D_SModeInfo=0; iD3D_SModeInfoappend(szText); D3D_SModeInfo& rkModeInfo=m_akD3DModeInfo[iD3D_SModeInfo]; rkModeInfo.GetString(pstEnumList); } pstEnumList->append("\r\n"); } ///////////////////////////////////////////////////////////////////////////// D3DDISPLAYMODE& D3D_CAdapterInfo::GetDesktopD3DDisplayModer() { return m_kD3DDMDesktop; } D3DDISPLAYMODE* D3D_CAdapterInfo::GetDesktopD3DDisplayModep() { return &m_kD3DDMDesktop; } D3D_CDeviceInfo* D3D_CAdapterInfo::GetD3DDeviceInfop(UINT iD3DDevInfo) { if (iD3DDevInfo >= m_uD3DDevInfoNum) return NULL; return &m_akD3DDevInfo[iD3DDevInfo]; } D3D_SModeInfo* D3D_CAdapterInfo::GetD3DModeInfop(UINT iD3DDevInfo, UINT iD3D_SModeInfo) { D3D_CDeviceInfo* pkD3DDevInfo=GetD3DDeviceInfop(iD3DDevInfo); if (pkD3DDevInfo) { D3D_SModeInfo* pkD3DModeInfo=pkD3DDevInfo->GetD3DModeInfop(iD3D_SModeInfo); if (pkD3DModeInfo) return pkD3DModeInfo; } return NULL; } BOOL D3D_CAdapterInfo::Find(UINT uScrWidth, UINT uScrHeight, UINT uScrDepthBits, BOOL isWindowed, UINT* piD3DModeInfo, UINT* piD3DDevInfo) { for (UINT iDevInfo=0; iDevInfo0) return TRUE; return FALSE; } VOID D3D_CAdapterInfo::GetString(std::string* pstEnumList) { for (UINT iDevInfo=0; iDevInfoappend(szText); D3D_CDeviceInfo& rkD3DDevInfo=m_akD3DDevInfo[iDevInfo]; rkD3DDevInfo.GetString(pstEnumList); } } ///////////////////////////////////////////////////////////////////////////// D3D_CDisplayModeAutoDetector::D3D_CDisplayModeAutoDetector() { m_uD3DAdapterInfoCount=0; } D3D_CDisplayModeAutoDetector::~D3D_CDisplayModeAutoDetector() { } D3D_CAdapterInfo* D3D_CDisplayModeAutoDetector::GetD3DAdapterInfop(UINT iD3DAdapterInfo) { if (iD3DAdapterInfo >= m_uD3DAdapterInfoCount) return NULL; return &m_akD3DAdapterInfo[iD3DAdapterInfo]; } D3D_SModeInfo* D3D_CDisplayModeAutoDetector::GetD3DModeInfop(UINT iD3DAdapterInfo, UINT iD3DDevInfo, UINT iD3D_SModeInfo) { D3D_CAdapterInfo* pkD3DAdapterInfo=GetD3DAdapterInfop(iD3DAdapterInfo); if (pkD3DAdapterInfo) { D3D_CDeviceInfo* pkD3DDevInfo=pkD3DAdapterInfo->GetD3DDeviceInfop(iD3DDevInfo); if (pkD3DDevInfo) { D3D_SModeInfo* pkD3D_SModeInfo=pkD3DDevInfo->GetD3DModeInfop(iD3D_SModeInfo); if (pkD3D_SModeInfo) return pkD3D_SModeInfo; } } return NULL; } BOOL D3D_CDisplayModeAutoDetector::Find(UINT uScrWidth, UINT uScrHeight, UINT uScrDepthBits, BOOL isWindowed, UINT* piD3DModeInfo, UINT* piD3DDevInfo, UINT* piD3DAdapterInfo) { for (UINT iD3DAdapterInfo=0; iD3DAdapterInfo0) return TRUE; return FALSE; } VOID D3D_CDisplayModeAutoDetector::GetString(std::string* pstEnumList) { for (UINT iD3DAdapterInfo=0; iD3DAdapterInfoappend(szText); D3D_CAdapterInfo& rkAdapterInfo=m_akD3DAdapterInfo[iD3DAdapterInfo]; rkAdapterInfo.GetString(pstEnumList); } }