⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dxutsettingsdlg.cpp

📁 声音和图片的加载功能,不过运行起来有点卡
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        SetActive( false );
        return S_OK;
    }

    pAPIComboBox->SetSelectedByData( ULongToPtr(g_DeviceSettings.ver) );

    switch( g_DeviceSettings.ver )
    {
        case DXUT_D3D9_DEVICE:
        {
            // Show all D3D9-specific controls and hide controls for all other D3D versions.
            ShowControlSet( DXUT_D3D9_DEVICE );

            CD3D9Enumeration* pD3DEnum = DXUTGetD3D9Enumeration();

            // Fill the UI with the current settings
            AddDeviceType( g_DeviceSettings.d3d9.DeviceType );
            SetWindowed( FALSE != g_DeviceSettings.d3d9.pp.Windowed );
            SetDeviceClip( 0 != (g_DeviceSettings.d3d9.pp.Flags & D3DPRESENTFLAG_DEVICECLIP) );
            AddAdapterFormat( g_DeviceSettings.d3d9.AdapterFormat );
            AddResolution( g_DeviceSettings.d3d9.pp.BackBufferWidth, g_DeviceSettings.d3d9.pp.BackBufferHeight );
            AddRefreshRate( g_DeviceSettings.d3d9.pp.FullScreen_RefreshRateInHz );
            AddBackBufferFormat( g_DeviceSettings.d3d9.pp.BackBufferFormat );
            AddDepthStencilBufferFormat( g_DeviceSettings.d3d9.pp.AutoDepthStencilFormat );
            AddMultisampleType( g_DeviceSettings.d3d9.pp.MultiSampleType );
            AddMultisampleQuality( g_DeviceSettings.d3d9.pp.MultiSampleQuality );

            if( g_DeviceSettings.d3d9.BehaviorFlags & D3DCREATE_PUREDEVICE )
                AddVertexProcessingType( D3DCREATE_PUREDEVICE );
            else if( g_DeviceSettings.d3d9.BehaviorFlags & D3DCREATE_HARDWARE_VERTEXPROCESSING )
                AddVertexProcessingType( D3DCREATE_HARDWARE_VERTEXPROCESSING );
            else if( g_DeviceSettings.d3d9.BehaviorFlags & D3DCREATE_SOFTWARE_VERTEXPROCESSING )
                AddVertexProcessingType( D3DCREATE_SOFTWARE_VERTEXPROCESSING );
            else if( g_DeviceSettings.d3d9.BehaviorFlags & D3DCREATE_MIXED_VERTEXPROCESSING )
                AddVertexProcessingType( D3DCREATE_MIXED_VERTEXPROCESSING );

            CD3D9EnumDeviceSettingsCombo* pBestDeviceSettingsCombo = pD3DEnum->GetDeviceSettingsCombo( g_DeviceSettings.d3d9.AdapterOrdinal, g_DeviceSettings.d3d9.DeviceType, g_DeviceSettings.d3d9.AdapterFormat, g_DeviceSettings.d3d9.pp.BackBufferFormat, (g_DeviceSettings.d3d9.pp.Windowed != 0) );
            if( NULL == pBestDeviceSettingsCombo )
                return DXUT_ERR_MSGBOX( L"GetDeviceSettingsCombo", E_INVALIDARG );    

            // Get the adapters list from CD3D9Enumeration object
            CGrowableArray<CD3D9EnumAdapterInfo*>* pAdapterInfoList = pD3DEnum->GetAdapterInfoList();

            if( pAdapterInfoList->GetSize() == 0 )
                return DXUT_ERR_MSGBOX( L"CD3DSettingsDlg::OnCreatedDevice", DXUTERR_NOCOMPATIBLEDEVICES );
            
            CDXUTComboBox* pAdapterCombo = m_Dialog.GetComboBox( DXUTSETTINGSDLG_ADAPTER );
            pAdapterCombo->RemoveAllItems();

            // Add adapters
            for( int iAdapter=0; iAdapter<pAdapterInfoList->GetSize(); iAdapter++ )
            {
                CD3D9EnumAdapterInfo* pAdapterInfo = pAdapterInfoList->GetAt(iAdapter);
                AddAdapter( pAdapterInfo->szUniqueDescription, pAdapterInfo->AdapterOrdinal );
            }
            
            pAdapterCombo->SetSelectedByData( ULongToPtr( g_DeviceSettings.d3d9.AdapterOrdinal ) );

            hr = OnAPIVersionChanged( true );
            if( FAILED(hr) )
                return hr;

            //m_Dialog.Refresh();
            CDXUTDialog::SetRefreshTime( (float) DXUTGetTime() );
            break;
        }
        case DXUT_D3D10_DEVICE:
        {
            // Show all D3D10-specific controls and hide controls for all other D3D versions.
            ShowControlSet( DXUT_D3D10_DEVICE );

            CD3D10Enumeration* pD3DEnum = DXUTGetD3D10Enumeration();

            // Fill the UI with the current settings
            AddD3D10DeviceType( g_DeviceSettings.d3d10.DriverType );
            SetWindowed( FALSE != g_DeviceSettings.d3d10.sd.Windowed );
            CD3D10EnumOutputInfo *pOutputInfo = GetCurrentD3D10OutputInfo();
            AddD3D10AdapterOutput( pOutputInfo->Desc.DeviceName, g_DeviceSettings.d3d10.Output );
            AddD3D10Resolution( g_DeviceSettings.d3d10.sd.BufferDesc.Width, g_DeviceSettings.d3d10.sd.BufferDesc.Height );
            AddD3D10RefreshRate( g_DeviceSettings.d3d10.sd.BufferDesc.RefreshRate );
            AddD3D10BackBufferFormat( g_DeviceSettings.d3d10.sd.BufferDesc.Format );
            AddD3D10MultisampleCount( g_DeviceSettings.d3d10.sd.SampleDesc.Count );
            AddD3D10MultisampleQuality( g_DeviceSettings.d3d10.sd.SampleDesc.Quality );

            CD3D10EnumDeviceSettingsCombo* pBestDeviceSettingsCombo = pD3DEnum->GetDeviceSettingsCombo( g_DeviceSettings.d3d10.AdapterOrdinal, g_DeviceSettings.d3d10.DriverType, g_DeviceSettings.d3d10.Output, g_DeviceSettings.d3d10.sd.BufferDesc.Format, (g_DeviceSettings.d3d10.sd.Windowed != 0) );
            if( NULL == pBestDeviceSettingsCombo )
                return DXUT_ERR_MSGBOX( L"GetDeviceSettingsCombo", E_INVALIDARG );    

            // Get the adapters list from CD3D10Enumeration object
            CGrowableArray<CD3D10EnumAdapterInfo*>* pAdapterInfoList = pD3DEnum->GetAdapterInfoList();

            if( pAdapterInfoList->GetSize() == 0 )
                return DXUT_ERR_MSGBOX( L"CD3DSettingsDlg::OnCreatedDevice", DXUTERR_NOCOMPATIBLEDEVICES );

            CDXUTComboBox* pAdapterCombo = m_Dialog.GetComboBox( DXUTSETTINGSDLG_ADAPTER );
            pAdapterCombo->RemoveAllItems();

            // Add adapters
            for( int iAdapter=0; iAdapter<pAdapterInfoList->GetSize(); iAdapter++ )
            {          
                CD3D10EnumAdapterInfo* pAdapterInfo = pAdapterInfoList->GetAt(iAdapter);
                AddAdapter( pAdapterInfo->szUniqueDescription, pAdapterInfo->AdapterOrdinal );
            }

            pAdapterCombo->SetSelectedByData( ULongToPtr( g_DeviceSettings.d3d10.AdapterOrdinal ) );

            hr = OnAPIVersionChanged( true );
            if( FAILED(hr) )
                return hr;

            //m_Dialog.Refresh();
            CDXUTDialog::SetRefreshTime( (float) DXUTGetTime() );
            break;
        }
    }

    return S_OK;
}


//--------------------------------------------------------------------------------------
HRESULT CD3DSettingsDlg::OnD3D9ResetDevice()
{
    const D3DSURFACE_DESC* pDesc = DXUTGetD3D9BackBufferSurfaceDesc();
    m_Dialog.SetLocation( 0, 0 );
    m_Dialog.SetSize( pDesc->Width, pDesc->Height );
    m_Dialog.SetBackgroundColors( D3DCOLOR_ARGB(255, 98, 138, 206),
                                  D3DCOLOR_ARGB(255, 54, 105, 192),
                                  D3DCOLOR_ARGB(255, 54, 105, 192),
                                  D3DCOLOR_ARGB(255, 10,  73, 179) );

    m_RevertModeDialog.SetLocation( 0, 0 );
    m_RevertModeDialog.SetSize( pDesc->Width, pDesc->Height );
    m_RevertModeDialog.SetBackgroundColors( D3DCOLOR_ARGB(255, 98, 138, 206),
                                            D3DCOLOR_ARGB(255, 54, 105, 192),
                                            D3DCOLOR_ARGB(255, 54, 105, 192),
                                            D3DCOLOR_ARGB(255, 10,  73, 179) );

    IDirect3DDevice9* pd3dDevice = DXUTGetD3D9Device();
    pd3dDevice->BeginStateBlock();
    pd3dDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID );
    pd3dDevice->EndStateBlock( &m_pStateBlock );

    return S_OK;
}


//--------------------------------------------------------------------------------------
void CD3DSettingsDlg::OnRender( float fElapsedTime )
{
    if( DXUTGetD3D10Device() )
        OnRender10( fElapsedTime );
    else
        OnRender9( fElapsedTime );
}


//--------------------------------------------------------------------------------------
void CD3DSettingsDlg::OnRender9( float fElapsedTime )
{
    IDirect3DDevice9* pd3dDevice = DXUTGetD3D9Device();

    // Clear the render target and the zbuffer 
    pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, 0x00003F3F, 1.0f, 0);

    // Render the scene
    if( SUCCEEDED( pd3dDevice->BeginScene() ) )
    {
        m_pStateBlock->Capture();
        pd3dDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID ); 
        m_pActiveDialog->OnRender( fElapsedTime );
        m_pStateBlock->Apply();
        pd3dDevice->EndScene();
    }
}


//--------------------------------------------------------------------------------------
void CD3DSettingsDlg::OnRender10( float fElapsedTime )
{
    // Render the scene
    m_pStateBlock10->Capture();
//    pd3dDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID );
    m_pActiveDialog->OnRender( fElapsedTime );
    m_pStateBlock10->Apply();
}


//--------------------------------------------------------------------------------------
LRESULT CD3DSettingsDlg::MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
    m_pActiveDialog->MsgProc( hWnd, uMsg, wParam, lParam );
    if( uMsg == WM_KEYDOWN && wParam == VK_F2 )
        SetActive( false );
    return 0;
}


//--------------------------------------------------------------------------------------
void CD3DSettingsDlg::OnD3D9LostDevice()
{
    SAFE_RELEASE( m_pStateBlock );
}


//--------------------------------------------------------------------------------------
void CD3DSettingsDlg::OnD3D9DestroyDevice()
{
}


//--------------------------------------------------------------------------------------
HRESULT CD3DSettingsDlg::OnD3D10CreateDevice( ID3D10Device* pd3dDevice )
{
    HRESULT hr;

    if( pd3dDevice == NULL )
        return DXUT_ERR_MSGBOX( L"CD3DSettingsDlg::OnCreatedDevice", E_INVALIDARG );

    // Create the fonts/textures 
    m_Dialog.SetCallback( StaticOnEvent, (void*) this );
    m_RevertModeDialog.SetCallback( StaticOnEvent, (void*) this );

    D3D10_STATE_BLOCK_MASK SBM;
    DXUT_Dynamic_D3D10StateBlockMaskDisableAll( &SBM );
    DXUT_Dynamic_D3D10StateBlockMaskEnableCapture( &SBM, D3D10_DST_RS_RASTERIZER_STATE, 0, 1 );
    V_RETURN(DXUT_Dynamic_D3D10CreateStateBlock( pd3dDevice, &SBM, &m_pStateBlock10 ));

    return S_OK;
}


//--------------------------------------------------------------------------------------
HRESULT CD3DSettingsDlg::OnD3D10ResizedSwapChain( ID3D10Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc )
{
    m_Dialog.SetLocation( 0, 0 );
    m_Dialog.SetSize( pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height );
    m_Dialog.SetBackgroundColors( D3DCOLOR_ARGB(255, 98, 138, 206),
                                  D3DCOLOR_ARGB(255, 54, 105, 192),
                                  D3DCOLOR_ARGB(255, 54, 105, 192),
                                  D3DCOLOR_ARGB(255, 10,  73, 179) );

    m_RevertModeDialog.SetLocation( 0, 0 );
    m_RevertModeDialog.SetSize( pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height );
    m_RevertModeDialog.SetBackgroundColors( D3DCOLOR_ARGB(255, 98, 138, 206),
                                  D3DCOLOR_ARGB(255, 54, 105, 192),
                                  D3DCOLOR_ARGB(255, 54, 105, 192),
                                  D3DCOLOR_ARGB(255, 10,  73, 179) );

    return S_OK;
}


//--------------------------------------------------------------------------------------
void CD3DSettingsDlg::OnD3D10DestroyDevice()
{
    SAFE_RELEASE( m_pStateBlock10 );
}


//--------------------------------------------------------------------------------------
void CD3DSettingsDlg::ShowControlSet( DXUTDeviceVersion ver )
{
    switch( ver )
    {
        case DXUT_D3D9_DEVICE:
            m_Dialog.GetControl( DXUTSETTINGSDLG_ADAPTER_FORMAT )->SetVisible( true );
            m_Dialog.GetControl( DXUTSETTINGSDLG_ADAPTER_FORMAT_LABEL )->SetVisible( true );
            m_Dialog.GetControl( DXUTSETTINGSDLG_RESOLUTION )->SetVisible( true );
            m_Dialog.GetControl( DXUTSETTINGSDLG_RESOLUTION_LABEL )->SetVisible( true );
            m_Dialog.GetControl( DXUTSETTINGSDLG_REFRESH_RATE )->SetVisible( true );
            m_Dialog.GetControl( DXUTSETTINGSDLG_REFRESH_RATE_LABEL )->SetVisible( true );
            m_Dialog.GetControl( DXUTSETTINGSDLG_BACK_BUFFER_FORMAT )->SetVisible( true );
            m_Dialog.GetControl( DXUTSETTINGSDLG_BACK_BUFFER_FORMAT_LABEL )->SetVisible( true );
            m_Dialog.GetControl( DXUTSETTINGSDLG_DEPTH_STENCIL )->SetVisible( true );
            m_Dialog.GetControl( DXUTSETTINGSDLG_DEPTH_STENCIL_LABEL )->SetVisible( true );
            m_Dialog.GetControl( DXUTSETTINGSDLG_MULTISAMPLE_TYPE )->SetVisible( true );
            m_Dialog.GetControl( DXUTSETTINGSDLG_MULTISAMPLE_TYPE_LABEL )->SetVisible( true );
            m_Dialog.GetControl( DXUTSETTINGSDLG_MULTISAMPLE_QUALITY )->SetVisible( true );
            m_Dialog.GetControl( DXUTSETTINGSDLG_MULTISAMPLE_QUALITY_LABEL )->SetVisible( true );
            m_Dialog.GetControl( DXUTSETTINGSDLG_VERTEX_PROCESSING )->SetVisible( true );
            m_Dialog.GetControl( DXUTSETTINGSDLG_VERTEX_PROCESSING_LABEL )->SetVisible( true );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -