[SharpDX] Question about Z-Buffer

Started by
2 comments, last by Stefan Fischlschweiger 9 years, 8 months ago

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?

Advertisement

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);

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.

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

This topic is closed to new replies.

Advertisement