Sign in to follow this  
Stefan Fischlschweiger

[SharpDX] Question about Z-Buffer

Recommended Posts

In my game I need to render a background starsphere which obviously has to be rendered behind everything else.

With XNA it was pretty easy to do this with DepthStencilState.None before the draw call abd DepthStencilState.Default after it.

 

In SharpDX these two DepthStencilStates also exist (from looking at the source code), but somehow I can't access them.

 

So, is there an easy way to turn the Z-Buffer off and then back on, or do I need to dive deeper?

Share this post


Link to post
Share on other sites

You need to set the DepthStencilState of the DeviceContext .

For disabling DepthTesting and Writing to DepthBuffer :

DepthStencilStateDescription desc = new DepthStencilStateDescription();
desc.IsDepthEnabled=false;
desc.DepthComparison = Comparison.Always;
desc.DepthWriteMask = DepthWriteMask.Zero;
DepthStencilState state = new DepthStencilState(device, desc);
contex.OutputMerger.SetDepthStencilState(state); 

and for restarting back to default state you can just set DepthStencilState to null :

contex.OutputMerger.SetDepthStencilState(null); 

Share this post


Link to post
Share on other sites
In SharpDX these two DepthStencilStates also exist (from looking at the source code), but somehow I can't access them.

 

SharpDX is providing low-level DirectX and a higher level API with the Toolkit. I assume you are talking about the Toolkit, but please in the future, try to give more context.

 

That being said, I don't know how you are looking at the source code or even you are usually using an API, but the method GraphicsDevice.SetDepthStencilState is well defined.

 

Also, GraphicsDevice.DepthStencilStates.Default and None provides default states, and can be used like this:

GraphicsDevice.SetDepthStencilState(GraphicsDevice.DepthStencilStates.Default);
....

GraphicsDevice.SetDepthStencilState(GraphicsDevice.DepthStencilStates.None);

It is the same behavior for blend states and rasterizer states.

Share this post


Link to post
Share on other sites

 

In SharpDX these two DepthStencilStates also exist (from looking at the source code), but somehow I can't access them.

 

SharpDX is providing low-level DirectX and a higher level API with the Toolkit. I assume you are talking about the Toolkit, but please in the future, try to give more context.

 

That being said, I don't know how you are looking at the source code or even you are usually using an API, but the method GraphicsDevice.SetDepthStencilState is well defined.

 

Also, GraphicsDevice.DepthStencilStates.Default and None provides default states, and can be used like this:

GraphicsDevice.SetDepthStencilState(GraphicsDevice.DepthStencilStates.Default);
....

GraphicsDevice.SetDepthStencilState(GraphicsDevice.DepthStencilStates.None);

It is the same behavior for blend states and rasterizer states.

 

Thanks, that did the trick :) I was simply looking in the wrong place (doh).

 

Yes, I was talking about the toolkit.

 

As for the source code, I was looking here: https://github.com/sharpdx/SharpDX

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this