Difference between DepthStencilView and DepthStencilState?

Started by
5 comments, last by michaelruecker 10 years, 6 months ago

Could anyone explain the differences between those two things please?

- DepthStencilView (http://msdn.microsoft.com/en-us/library/windows/desktop/ff476507(v=vs.85).aspx)

- DepthStencilState (http://msdn.microsoft.com/en-us/library/windows/desktop/ff476506(v=vs.85).aspx)

Advertisement
View is for binding a fitting texture as a depth buffer to the device,
Depth stencil state is for setting the depth states (enable, write, ...) encapsualted in an immutable state object.

So if one would not specify the state at all and just setting the view, depth testing would still work right?

Does it load some default settings then?

Yes, setting the depth stencil state to NULL will enable the default settings. It disables stencil and has depth comparison set to less: Clear your depth stencil view to 1.0f and you're probably fine.

Alright, so lets say the engine I am working with, is not using a depth stencil state yet. But I need to set that state now for my stuff. Afterwards I would like to set it to what it was before I changed it.

To do this I would just use OMSetDepthStencilState(NULL, 0) and set the state to NULL again? Or do I actually have to create another state that with default parameters and set that active?

Also what do you exactly mean with:

Clear your depth stencil view to 1.0f and you're probably fine.

If said engine doesn't come up with some state saving of its own (or some reset functionality), you can grab any state with the corresponding Get function (in this case OMGetDepthStencilState (read the remarks: getter function usually AddRef() the object in question so don't forget to Release() when you reset it).

For your second question: When using a depth comparison of less (or less equal) it makes sense to start with a depth value at 1.0f (third parameter of ID3D11DeviceContext::ClearDepthStencilView). Depth buffer values go from 0 to 1 (inclusive) so 1 is the maximum. If your depth buffer is cleared to 0, and you use a less comparison, nothing gets drawn, since no value can be less than 0 wink.png.

But of course other stuff has to be setup properly, too, e.g. a sensible projection.

Ahh that cleared things up. Thank you very much!

This topic is closed to new replies.

Advertisement