0
\$\begingroup\$

I know there are four different render states. They are

Blend State 
Depth Stencil State 
Rasterizer State 
Sampler State 

One of my Direct3D reference books say that Direct3D is a state machine. But how, where do we use these in game development?

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

This is quite broad.

  • Blend state is used by the Output merger and you can configure it however you want to blend together outputs from a pixel shader and the render target or backbuffer.
  • Depth stencil state is used if you have a depth stencil view bound to your rendertarget or backbuffer. You can configure it if you want depth or stencil test functionality.
  • Rasterizer state describes the rasterizer fuctionality which occurs between primitive outputting shaders and pixel shaders and decides which pixels will be executed the pixels shader on.
  • Sampler state is a texture sampler state which holds information how to sample a given texture resource.


You can usually create these by

ID3D11DeviceContext::CreateXYZState(state_description,state_pointer);

where XYZ is your 'Sampler', 'Rasterizer', etc., state_description is a D3D11_SAMPLER_DESC (or rasterizer, etc.) structure object's address which you fill in with the desired parameters. state_pointer is the address of your state which you want to create.
You can use these states by enabling them before a draw call by calling the relevant method of the device context such as ID3D11DeviceContext::RSSetState(rasterizerstate); for example.


There is much more to this topic, you should try them out one by one to understand it completely.

\$\endgroup\$
0
\$\begingroup\$

Direct3D 11 is a 'state machine' in the same way as all modern graphic APIs. The full state is much more complicated than these four objects. Here's a list of basic Direct3D 11 state (ignoring optional stuff like Geometry Shader, Stream Out, Tessellation Domain/Hull Shaders, DirectCompute Shaders/Resources, and Queries):

Input Assembler

  • Input layout
  • 1 or more vertex buffers
  • 0 or 1 index buffer
  • index buffer format (16-bit or 32-bit)
  • primitive topology setting

Vertex Shader

  • Vertex shader program
  • up to 16 constant buffers
  • up to 128 textures (shader resource view + texture resource)
  • up to 16 samplers (ID3D11SamplerState)

Rasterizer

  • rasterizer state (ID3D11RasterizerState)
  • up to 16 viewports
  • up to 16 scissor rectangles

Pixel Shader

  • Pixel shader program
  • up to 16 constant buffers
  • up to 128 textures (shader resource view + texture resource)
  • up to 16 samplers (ID3D11SamplerState)

Output Merger

  • blend state (ID3D11BlendState)
  • depth/stencil state (ID3D11DepthStencilState)
  • up to 8 render targets (render target resource view + texture resource)

So to draw anything, you have to set all this state before you call Draw or DrawIndexed.

\$\endgroup\$

You must log in to answer this question.

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