0
\$\begingroup\$

I'm implementing a D3D10 version of my renderer (not porting to avoid losing Windows XP support). I didn't go straight to D3D11 because MSDN and other sources recommend upgrading to 10 and then to 11.

From what I've read so far, what used to be done with IDirect3D9::SetRenderState is done in D3D10 with ID3D10RasterizerState, ID3D10BlendState and ID3D10DepthStencilState. You declare and fill a descriptor structure, tell the device to create a state object, and then bind it to the device. For example:

//D3D9
m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );

//D3D10
//This defines the ID3D10RasterizerStatePtr type used below
_COM_SMARTPTR_TYPEDEF(ID3D10RasterizerState, __uuidof(ID3D10RasterizerState) );
//...
ID3D10RasterizerStatePtr pRasterState;
D3D10_RASTERIZER_DESC rasterDesc;
rasterDesc.CullMode = D3D10_CULL_NONE;
if( !CheckErrorCode( m_pImpl->pDevice->CreateRasterizerState( &rasterDesc, &pRasterState ), "InitDevice", "CreateRasterizerState" ) )
    return false;
m_pImpl->pDevice->RSSetState( pRasterState );

However, now that I have to "port" the line...

 m_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );

... I cannot find a related property in any of the descriptors. From what I've seen, most examples implement lighting in HLSL, so perhaps I don't need to explicitly disable lighting, because my shaders don't do it?

This is a desktop app, no fancy Metro stuff. Using unmanaged C++.

\$\endgroup\$
2
  • \$\begingroup\$ The jump from Direct3D 9 to Direct3D 10 or 11 is about the same. The MSDN recommendation is that to go from Direct3D 9 to Direct3D 11, you should read, understand, and follow the porting advice to go from Direct3D 9 to Direct3D 10 which maps directly to Direct3D 11. That said, you shouldn't actually port the project from D3D9 to D3D10, and then port from D3D10 to D3D11 because of all the intermediate support stuff. From a logical perspective, you should convert your Direct3D 9 fixed-function app to use shaders, then port to 10, then to 11. \$\endgroup\$ Sep 5, 2014 at 4:58
  • \$\begingroup\$ In other words, use the Direct3D 9 to Direct3D 10 Considerations but where it says to use Direct3D 10, use the Direct3D 11 equivalent instead which you can find in Migrating to Direct3D 11 \$\endgroup\$ Sep 5, 2014 at 5:04

2 Answers 2

3
\$\begingroup\$

Direct3D 10.x and Direct3D 11.x do not support the 'legacy fixed-function' pipeline that your Direct3D 9 code is using. Preparing to move to Direct3D 10 or 11 means eliminating all fixed-function usage and moving to programmable shaders.

It is also apparent from your code snippet that you are not using the state objects correctly. In Direct3D 9, you set hundreds of individual settings. In Direct3D 10 and Direct3D 11, you manage all state through a few objects and a few simple individual switches such as primitive topology.

You have really need to take a step back and understand the major shifts in technology here. All fixed-function rendering needs to be replaced with programmable shaders, state management needs to be changed from a 'lazy-evaluation 'model to a 'known groups' model. In other words, you cannot meanigfully translate the single line: m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ); by itself to Direct3D 10.x or 11.x. You need to know the state it is grouped with and how you are using them all together to render your scene.

ID3D10RasterizerStatePtr pRasterState;
D3D10_RASTERIZER_DESC rasterDesc;
rasterDesc.CullMode = D3D10_CULL_NONE;
if( !CheckErrorCode( m_pImpl->pDevice->CreateRasterizerState( &rasterDesc, &pRasterState ), "InitDevice", "CreateRasterizerState" ) )
    return false;

This code will always fail because you did not fully initialize the rasterizer state object which also sets fill mode, winding mode, depth bias/clamp, depth clipping, scissors, and MSAA line AA modes all together. And once you create that state object, it is immutable. To change any setting in that object, you create a new one with all the states specified.

The DirectX Tool Kit for Direct3D 11 provides a lot of basic functionality that you may find useful for replacing old D3DX9 and concepts like "Draw*UP", common used state object combinations, and a bunch of stock programmable shaders you can start learning from. Take some time to really learn the Direct3D 11 API basics before jumping into a porting job for an old codebase that is not even really up to the programmable shader model for Direct3D 9.0 (circa 2004).

Start with the resources at Getting Started with Direct3D 11 and the samples on MSDN Code Gallery. When you've got a good understanding of how to program for Direct3D 11, then take a look at the seminal 'porting from Direct3D 9' presentation Windows to Reality: Getting the Most out of Direct3D 10 Graphics in Your Games. All those recommendations would apply to moving from Direct3D 9 to Direct3D 11.x as well.

\$\endgroup\$
3
  • \$\begingroup\$ Note that this may seem a bit daunting, but it will be a whole lot easier to move from Direct3D 9 fixed-function to Direct3D 11 than if you tried to wait for Direct3D 12 :) \$\endgroup\$ Sep 5, 2014 at 5:23
  • \$\begingroup\$ I thought that the fields I didn't set were left with their default values, do I really need to set them all? Thanks for the resources, I had already read some of them but it's always good to have another view. \$\endgroup\$ Sep 5, 2014 at 13:09
  • 2
    \$\begingroup\$ D3D10_RASTERIZER_DESC and D3D11_RASTERIZER_DESC are C structs and not C++ classes, so they have no defaults. In D3D11.H there is a C++ version of it called CD3D11_RASTERIZER_DESC which has a constructor that will set defaults: CD3D11_RASTERIZER_DESC rasterDesc( CD3D11_DEFAULT );. See MSDN. \$\endgroup\$ Sep 5, 2014 at 18:40
1
\$\begingroup\$

You're right, there is no lighting in D3D10 unless you implement it yourself in shaders.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .