2011-07-24 29 views
7

D3D11的api似乎有點笨拙,或者我沒有正確使用它。更改D3D11中的單個狀態設置

這是真的,這是步驟更改D3D11一個光柵化狀態(我的變化來線框模式渲染爲例)的最小集合

 
    // variables to hold the current rasterizer state and its description 
    ID3D11RasterizerState * rState ; 
    D3D11_RASTERIZER_DESC rDesc ; 

    // cd3d is the ID3D11DeviceContext 
    cd3d->RSGetState(&rState) ; // retrieve the current state 
    rState->GetDesc(&rDesc) ; // get the desc of the state 
    rDesc.FillMode = D3D11_FILL_WIREFRAME ; // change the ONE setting 

    // create a whole new rasterizer state 
    // d3d is the ID3D11Device 
    d3d->CreateRasterizerState(&rDesc, &rState) ; 

    cd3d->RSSetState(rState); // set the new rasterizer state 

看來很多長於9的

 
    cd3d->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME) ; 
+0

不要忘記在調用RSSetState後釋放您的rState實例以避免內存泄漏。 – mchiasson

回答

7

或者你可以保持狀態遞減「全局」到你的代碼或類,那麼簡單地改變FILLMODE與RSSetState設置(與新更改的原始狀態)?而不是檢索和設置。

+0

是的。我越使用D3D11,我越是意識到他們希望你非常小心地管理狀態。它基本上迫使你使用[狀態塊在d3d9中可用](http://msdn.microsoft.com/en-us/library/bb206121(VS.85).aspx),但我從來沒有使用它們 – bobobobo