The CommonStates class is a factory which simplifies setting the most common combinations of Direct3D rendering states.
For exception safety, it is recommended you make use of the C++ RAII pattern and use a std::unique_ptr or std::shared_ptr
http://msdn.microsoft.com/en-us/library/windows/desktop/ff476087.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/hh404435.aspx
For standard drawing, typically you should make use of Opaque().
For drawing alpha-blended objects, you should use AlphaBlend() if using premultiplied alpha, or
NonPremultiplied() if using 'straight' alpha.
For multipass rendering, you'd typically use Additive().
http://msdn.microsoft.com/en-us/library/windows/desktop/ff476110.aspx
For standard rendering with a z-buffer, you should use DepthDefault().
For drawing alpha blended objects (which is typically done after all opaque objects have been draw), use DepthRead() which will respect the existing z-buffer values, but will not update them with 'closer' pixels.
For drawing objects without any depth-sort at all, use DepthNone().
http://msdn.microsoft.com/en-us/library/windows/desktop/ff476198.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/hh404489.aspx
For default geometry winding uses CullCounterClockwise(). For inverted winding (typically when using assets designed for left-handed coordinates but rendering with right-handed coordinates or vice-versa), use CullClockwise().
For "double-sided" geometry, use CullNone(). Keep in mind this is a potentially large performance hit, so use it sparingly.
Wireframe() is self-explanatory.
http://msdn.microsoft.com/en-us/library/windows/desktop/ff476207.aspx
Usually LinearWrap() is the assume default setting, and covers a large number of cases. For improved mipmap filtering quality use the Ansiotropic settings.
Initialization
The CommonStates constructor requires a Direct3D 11 device.
std::unique_ptr<CommonStates> states(new CommonStates(device));
Using this helper to set device state
deviceContext->OMSetBlendState(states->Opaque(), Colors::Black, 0xFFFFFFFF);
deviceContext->OMSetDepthStencilState(states->DepthDefault(), 0);
deviceContext->RSSetState(states->CullCounterClockwise());
auto samplerState = states->LinearWrap();
deviceContext->PSSetSamplers(0, 1, &samplerState);
Blending State
http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.blendstate_fields.aspxhttp://msdn.microsoft.com/en-us/library/windows/desktop/ff476087.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/hh404435.aspx
- ID3D11BlendState* Opaque();
- ID3D11BlendState* AlphaBlend();
- ID3D11BlendState* Additive();
- ID3D11BlendState* NonPremultiplied();
For standard drawing, typically you should make use of Opaque().
For drawing alpha-blended objects, you should use AlphaBlend() if using premultiplied alpha, or
NonPremultiplied() if using 'straight' alpha.
For multipass rendering, you'd typically use Additive().
Depth/Stencil State
http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.depthstencilstate_fields.aspxhttp://msdn.microsoft.com/en-us/library/windows/desktop/ff476110.aspx
- ID3D11DepthStencilState* DepthNone();
- ID3D11DepthStencilState* DepthDefault();
- ID3D11DepthStencilState* DepthRead();
For standard rendering with a z-buffer, you should use DepthDefault().
For drawing alpha blended objects (which is typically done after all opaque objects have been draw), use DepthRead() which will respect the existing z-buffer values, but will not update them with 'closer' pixels.
For drawing objects without any depth-sort at all, use DepthNone().
Rasterizer State
http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.rasterizerstate_fields.aspxhttp://msdn.microsoft.com/en-us/library/windows/desktop/ff476198.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/hh404489.aspx
- ID3D11RasterizerState* CullNone();
- ID3D11RasterizerState* CullClockwise();
- ID3D11RasterizerState* CullCounterClockwise();
- ID3D11RasterizerState* Wireframe();
For default geometry winding uses CullCounterClockwise(). For inverted winding (typically when using assets designed for left-handed coordinates but rendering with right-handed coordinates or vice-versa), use CullClockwise().
For "double-sided" geometry, use CullNone(). Keep in mind this is a potentially large performance hit, so use it sparingly.
Wireframe() is self-explanatory.
Sampler State
http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.samplerstate_fields.aspxhttp://msdn.microsoft.com/en-us/library/windows/desktop/ff476207.aspx
- ID3D11SamplerState* PointWrap();
- ID3D11SamplerState* PointClamp();
- ID3D11SamplerState* LinearWrap();
- ID3D11SamplerState* LinearClamp();
- ID3D11SamplerState* AnisotropicWrap();
- ID3D11SamplerState* AnisotropicClamp();
Usually LinearWrap() is the assume default setting, and covers a large number of cases. For improved mipmap filtering quality use the Ansiotropic settings.