Jump to content
  • Advertisement
Sign in to follow this  
jdub

OpenGL Writing my own Depth Buffer Functionality.

This topic is 1365 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am taking a graphics class at my University.  For the latest assignment, we are required to implement the functionality of a depth buffer for rendering our geometry.  However, this assignment is supposed to be implemented in OpenGL using a separate set of skeleton code.  Because I am more familiar with DirectX I would like to implement it in that API.  That being said, I am wondering if there is a way to replace the standard depth-stencil functionality of DirectX with my own code (which will do the same thing) in order to complete the requirements of the assignment?

 

 

Share this post


Link to post
Share on other sites
Advertisement

Would recommend against it if you have an OpenGL skeleton set up for it already.

 

You need a buffer that you can both write to and read from manually in the shader.. so unordered access view of a 2D surface, calculate the depth manually in the pixel shader and compare it to what is currently in the surface and either discard the pixel or output its color. https://msdn.microsoft.com/en-us/library/windows/desktop/ff476335(v=vs.85).aspx has some info.

You probably want https://msdn.microsoft.com/en-us/library/windows/desktop/ff471409%28v=vs.85%29.aspx to compare and set the depth atomically.

Share this post


Link to post
Share on other sites

There is no way to reach in and replace the depth buffer functionality from the API.  However, like Erik mentioned you can use the API to allow you to write shaders that perform more or less the same operations.  You have to note that it isn't possible to render directly to a depth stencil view though - only the fixed functionality of the API can do that.

 

One other alternative that I would find more interesting is to write the whole thing in some compute shaders.  That would require you to do the rasterization yourself, but there is publicly available code that you can reference for that.  I would find that more compelling than working through the existing pipeline, but that may be beyond what your assignment is asking for.

Share this post


Link to post
Share on other sites

This is sounds bit odd assignment. Depth buffers are super simple in theory but quite quirky to implement with API like openGL. But maybe the idea is to learn API and not theory.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!