Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


[SharpDX] Question about Z-Buffer


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Lordadmiral Drake   Members   -  Reputation: 202

Like
0Likes
Like

Posted 20 August 2014 - 04:35 AM

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?



Sponsor:

#2 BlackBrain   Members   -  Reputation: 340

Like
0Likes
Like

Posted 20 August 2014 - 06:05 AM

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



#3 xoofx   Members   -  Reputation: 887

Like
2Likes
Like

Posted 20 August 2014 - 06:20 AM

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.



#4 Lordadmiral Drake   Members   -  Reputation: 202

Like
0Likes
Like

Posted 20 August 2014 - 05:20 PM

 

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS