Changing a single state setting in D3D11
Asked Answered
S

1

8

It would seem that D3D11's api is a bit clunky, or I'm not using it right.

Is it true that this is the minimum set of steps to change a single rasterizer state in D3D11 (I'm using change to wireframe mode rendering as an example)

  // 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

Seems a lot longer than 9's

  cd3d->SetRenderState( D3DRS_FILLMODE, D3DFILL_WIREFRAME ) ;
Sorayasorb answered 24/7, 2011 at 20:54 Comment(1)
don't forget to release your rState instance after calling RSSetState to avoid a memory leak.Bufford
G
7

Or you could keep the state desc 'global' to your code or class, then simply change the fillmode and set with RSSetState ( with the original state with new change)? Instead of retrieving and setting.

Garretgarreth answered 5/9, 2011 at 21:3 Comment(1)
Yes. The more I use D3D11, the more I realize they want you to manage state very carefully. Its basically forcing you to use state blocks which were available in d3d9, but I never used themSorayasorb

© 2022 - 2024 — McMap. All rights reserved.