Render to Texture Array with Depth?

Started by
1 comment, last by Funkymunky 12 years, 6 months ago
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?
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.
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

This topic is closed to new replies.

Advertisement