Jump to content
  • Advertisement
Sign in to follow this  
Funkymunky

OpenGL Render to Texture Array with Depth?

This topic is 2569 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 notice that, at least with OpenGL, you can assign multiple color attachments, or even just a single color attachment that is a texture array. You can only assign one depth buffer though.

If I have a setup where I render to a texture with a geometry shader deciding which level in a texture array to render to, how can I perform z-testing on each level in the array?

Share this post


Link to post
Share on other sites
Advertisement
I can speak for D3D11, which I am sure is the same as OpenGL. You would bind a texture array depth target, where each element of the array would serve as a depth buffer for its corresponding color element in the render target array. In the cases where you bind multiple render targets (commonly referred to as MRT) then you bind only one depth buffer, since all render targets receive the same rasterization results - only the output fragment data is varied between them, not the 3D position data.

Share this post


Link to post
Share on other sites
oh wow, you're right! it was as simple as adding:

glGenTextures(1, &depthTexArray);
glBindTexture(GL_TEXTURE_2D_ARRAY, depthTexArray);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_DEPTH_COMPONENT32, dim, dim, numLevels, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);



and then an additional call to:

glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthTexArray, 0);


and then I had to output gl_FragDepth in my shaders (with a special shader to clear the array, including depths).

And it works! Thanks for the advice

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!