PDA

View Full Version : depth only draw into a texture array



michec
09-14-2010, 02:55 AM
I want to render the depth buffers of multiple views (in a single pass) into a texture array. I'm using a framebuffer with a texture2Darray attached to GL_DEPTH_ATTACHMENT. In the geometry shader I use gl_Layer to render to the different layers. It seems like although an array is attached to GL_DEPTH_ATTACHMENT, only the first 2D texture of the array receives depth information.

I don't know if this is the right behavior (OpenGL 3.3), because I read that it is possible to render into a depth cubemap in a single pass.

Here is how I create my framebuffer:


glGenFramebuffers(1, &framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
// depthArray is a GL_TEXTURE_2D_ARRAY (GL_DEPTH_COMPONENT32)
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthArray, 0);

glCheckFramebufferStatus returns GL_FRAMEBUFFER_COMPLETE.


Here is the code for drawing:


glEnable(GL_DEPTH_TEST);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glDrawBuffer(GL_NONE);
glViewport(0, 0, framebufferWidth, framebufferHeight);
glClear(GL_DEPTH_BUFFER_BIT);
glUseProgram(program);
glDrawElementsBaseVertex(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDrawBuffer(GL_BACK_LEFT);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDisable(GL_DEPTH_TEST);


Vertex shader:


#version 330

in vec4 position;

void main(void){
gl_Position = position;
}


Geometry Shader:


#version 330

layout(triangles) in;
layout(triangle_strip, max_vertices = 12) out;

void main(void){
int layer, i;
for(layer=0; layer<4; layer++){
gl_Layer = layer;
for(i=0; i<gl_in.length(); i++){
gl_Position = gl_in[i].gl_Position;
EmitVertex();
}
EndPrimitive();
}
}


The result is a texture array where the first 2D texture contains 0.0 and all others 1.0.

Am I doing something wrong or is this not possible in OpenGL 3.3? (I have an ATI HD4600 card.)

DmitryM
09-15-2010, 09:24 AM
I don't see the error in your code (maybe someone else does...).

You can share the binary so that it can be tested on different platforms and sent to ATI at some point.

You can also try posting more code (texture creation, shader linking).

michec
09-17-2010, 01:18 AM
Thanks DmitryM.

Here is the code for creating the depth array:


glGenTextures(1, &amp;texture);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D_ARRAY, texture);
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT);
glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_DEPTH_COMPONENT32, width, height, 4, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);

I also attached a simple program (win7 64bit, opengl 3.3, debug mode). It should draw a rectangle onto all layers of the depth texture array (depth 0.0). The depth array is then drawn onto the screen. Every view seconds another texture of the depth array is presented.
On my computer only the first texture of this array is gray. All others are black. If all textures of the array had the same color (gray) it would be correct.

It would help me if someone could test the program on nvidia hardware. Thanks.


I also did some more testing. Writing to a texture2dArray (GL_RGBA) attached to GL_COLOR_ATTACHMENT0 works.

Dark Photon
09-20-2010, 06:52 PM
It would help me if someone could test the program on nvidia hardware.
Would but I'm on Linux and you didn't provide source. So we can't even look through to verify the basics such as that you are calling glFramebufferTexture and not glFramebufferTextureLayer.

somboon
09-20-2010, 08:28 PM
Can you post the release mode binary with required DLL (dont have visual studio 2010 here).

I also experience somewhat similar problem.



http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&amp;Number=281864#Post2818 64

michec
09-21-2010, 11:46 AM
Thanks for your replies.

My project consists of several sub projects. I will try to create a simplified project. I will upload it as soon as I can. But I am busy until friday.

I also got a reply at the AMD forums:
"it seems that layered depth has an issue in our latest driver, where layered color rendering is correct. we will fix it asap"
AMD forums thread (http://forums.amd.com/devforum/messageview.cfm?catid=392&amp;threadid=139672&amp;enterthr ead=y)

It seems like this is a bug (10.9 drivers).