SwapChain unter DirectX9



  • Hi!

    Ich wollte mal testen, wie man SwapChains unter DirectX9 verwendet und habe gleich damit angefangen zu schreiben. Bisher klappt das auch ganz gut.
    Mein Problem ist, ich weiß nicht wie ich auf das Device vom SwapChain zugreifen kann. Sprich Clear oder BeginScene und EndScene.

    Wie bekomm ich es zu stande etwas zu rendern ? Bye.

    .................
    :Aktueller Code:
    .................

    BOOL CSwapChain_Test_Dlg::InitD3D( HWND hWnd )
    {
        if( NULL == ( m_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
            return FALSE;
    
        ZeroMemory( &m_d3dpp, sizeof(m_d3dpp) );
    
        ZeroMemory( &m_d3dppView[0], sizeof(m_d3dppView[0]) );
        ZeroMemory( &m_d3dppView[1], sizeof(m_d3dppView[1]) );
    
        m_d3dpp.Windowed            = TRUE;
        m_d3dpp.SwapEffect          = D3DSWAPEFFECT_DISCARD;
        m_d3dpp.BackBufferFormat    = D3DFMT_UNKNOWN;
        m_d3dpp.hDeviceWindow       = hWnd;
    
        m_d3dppView[0] = m_d3dppView[1] = m_d3dpp;
    
        if( FAILED( m_pD3D->CreateDevice(    D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL,
                                            D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                            &m_d3dpp, &m_pd3dDevice ) ) )
            return FALSE;
    
        m_pd3dSwapChain[0] = NULL;
        m_pd3dSwapChain[1] = NULL;
        return TRUE;
    }
    
    BOOL CSwapChain_Test_Dlg::CreateSwapChains()
    {
        HRESULT hr;
    
        m_d3dppView[0].hDeviceWindow = GetDlgItem( VIEW_1 )->m_hWnd;
        m_d3dppView[1].hDeviceWindow = GetDlgItem( VIEW_2 )->m_hWnd;
    
        if( FAILED( m_pd3dDevice->CreateAdditionalSwapChain( &m_d3dppView[0], &m_pd3dSwapChain[0] ) ) )
            return FALSE;
        if( FAILED( m_pd3dDevice->CreateAdditionalSwapChain( &m_d3dppView[1], &m_pd3dSwapChain[1] ) ) )
            return FALSE;
    
        return TRUE;
    }
    
    BOOL CSwapChain_Test_Dlg::RenderSwapChains( int sw )
    {
        IDirect3DDevice9 *pDevice;
        m_pd3dSwapChain[sw]->GetDevice( &pDevice );
    
        m_pd3dSwapChain[sw]->Present( NULL, NULL, NULL, NULL, NULL );
        return TRUE;
    }
    
    BOOL CSwapChain_Test_Dlg::DeleteSwapChains( int sw )
    {
        if( m_pd3dSwapChain[sw] != NULL )
            m_pd3dSwapChain[sw]->Release();
    
        return TRUE;
    }
    
    BOOL CSwapChain_Test_Dlg::ReleaseD3D()
    {
        if( m_pD3D != NULL )
            m_pD3D->Release();
    
        if( m_pd3dDevice != NULL )
            m_pd3dDevice->Release();
    
        if( m_pd3dSwapChain[0] != NULL )
            m_pd3dSwapChain[0]->Release();
    
        if( m_pd3dSwapChain[1] != NULL )
            m_pd3dSwapChain[1]->Release();
    
        m_pD3D = NULL;
        m_pd3dDevice = NULL;
        m_pd3dSwapChain[0] = NULL;
        m_pd3dSwapChain[1] = NULL;
    
        return TRUE;
    }
    
    BOOL CSwapChain_Test_Dlg::RenderDevice( IDirect3DDevice9 *swapDev )
    {
    
        if( swapDev != NULL )
        {
            swapDev->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );
            swapDev->BeginScene();
            // Render Scene 
            swapDev->EndScene();
            swapDev->Present( NULL, NULL, NULL, NULL );
        }
    
        return TRUE;
    }
    
    BOOL CSwapChain_Test_Dlg::RenderD3D()
    {
        if( m_pd3dDevice != NULL )
        {
            m_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );
            m_pd3dDevice->BeginScene();
            // Render Scene 
            m_pd3dDevice->EndScene();
            m_pd3dDevice->Present( NULL, NULL, NULL, NULL );
        }
        return TRUE;
    }
    
    void CSwapChain_Test_Dlg::OnBnClickedButton1()
    {
        // TODO: Add your control notification handler code here
        if( !InitD3D( m_hWnd ) )
            MessageBox( "Direct3D konnte nicht richtig initalisiert werden!", "ERROR", MB_OK );
    }
    
    void CSwapChain_Test_Dlg::OnBnClickedButton2()
    {
        RenderSwapChains( 0 );
        // TODO: Add your control notification handler code here
    }
    
    void CSwapChain_Test_Dlg::OnBnClickedButton4()
    {
        ReleaseD3D();
        // TODO: Add your control notification handler code here
    }
    
    void CSwapChain_Test_Dlg::OnBnClickedButton5()
    {
        // TODO: Add your control notification handler code here
        RenderD3D();
    }
    
    void CSwapChain_Test_Dlg::OnBnClickedButton3()
    {
        RenderSwapChains( 1 );
        // TODO: Add your control notification handler code here
    }
    
    void CSwapChain_Test_Dlg::OnBnClickedButton6()
    {
        // TODO: Add your control notification handler code here
        CreateSwapChains();
    }
    
    void CSwapChain_Test_Dlg::OnBnClickedButton7()
    {
        // TODO: Add your control notification handler code here
        DeleteSwapChains( 0 );
        DeleteSwapChains( 1 );
    }
    

    😕



  • Schau dir doch mal die Tutorials des DirectX-SDK dazu an 🙂
    Imho musst du dich gar nicht selber um die SwapChain kümmern, bin mir aber nicht sicher 🙄



  • Hi!
    Du hast keine Ahung oder ?
    Sry, wenn ich das sage, aber ich möchte gerne 4 Views haben.
    Und da es mit 4 Devices zu langsam ist, wollte ich es mit dem IDirect3DSwapChain9 machen, aber wie ich gerade beschrieben habe, habe ich ein Problem ..
    Bye



  • Such du etwa IDirect3DDevice9::SetRenderTarget (?!)

    M.T.

    [ Dieser Beitrag wurde am 09.03.2003 um 14:26 Uhr von Manuel editiert. ]



  • Nein



  • Dann stell die Frage genauer! Noch n Tipp - im ZFX-Forum gibts z.z.T nen ähnlichen Thread

    M.T.


Anmelden zum Antworten