PDA

View Full Version : Depth array textures not working with FBO



debonair
04-21-2016, 09:49 PM
I am using layered depth textures with FBO. Here is my code for setup:




glBindTexture(GL_TEXTURE_2D_ARRAY, depth_texture_->id());
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage3D(GL_TEXTURE_2D_ARRAY,0,GL_DEPTH_COMPON ENT16, width,height,depth,0,GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT,NULL);
glTexParameteri(GL_TEXTURE_2D_ARRAY,GL_TEXTURE_MIN _FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D_ARRAY,GL_TEXTURE_WRA P_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D_ARRAY,GL_TEXTURE_WRA P_T, GL_REPEAT);
glBindTexture(GL_TEXTURE_2D_ARRAY, 0);


glGenFramebuffers(1, &fboId_);
glBindFramebuffer(GL_FRAMEBUFFER, fboId_);
glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
depth_texture_->id(), 0, shadowMapIndex_);

////////// Check FrameBuffer was created with success ///
int fboStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (fboStatus != GL_FRAMEBUFFER_COMPLETE) {
LOGE("Could not create FBO: %d", fboStatus);
switch(fboStatus){
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT :
LOGE("GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT");
break;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
LOGE("GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT");
break;

case GL_FRAMEBUFFER_UNSUPPORTED:
LOGE("GL_FRAMEBUFFER_UNSUPPORTED");
break;
}
throw std::exception(); // "Could not create FBO: " + fboStatus
}
In render:

GL(glBindFramebuffer(GL_FRAMEBUFFER, framebufferId));
GL(glViewport(rstate.viewportX, rstate.viewportY, rstate.viewportWidth, rstate.viewportHeight));
GL(glClear(GL_DEPTH_BUFFER_BIT ));


glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D_ARRAY, depth_texture_->id());
glPixelStorei(GL_PACK_ALIGNMENT, 1);




All my depth data is black here. If I switch to GL_TEXTURE_2D, it works fine. For the layered one, if I use color attachment, I get data but only depth attachment is black. what could be wrong here?

mamannon
04-21-2016, 11:59 PM
I think you miss one piece of your rendering system: you already have a texture array you want
to fill with depth data (depth_texture_->id()), and you have a framebuffer (fboId), but where
is your renderbuffer? I mean you need something like this:



glGenRenderbuffers(1, &renderBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, renderBuffer);
glRenderbufferStorege(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderBuffer);

GClements
04-22-2016, 02:11 AM
I think you miss one piece of your rendering system: you already have a texture array you want to fill with depth data (depth_texture_->id()), and you have a framebuffer (fboId), but where
is your renderbuffer?

He's using a texture layer as the depth attachment, he doesn't need a renderbuffer.

mamannon
04-22-2016, 03:55 AM
He's using a texture layer as the depth attachment, he doesn't need a renderbuffer.

Sorry, I missed it... I have to give up, no ideas...

arekkusu
04-22-2016, 07:51 AM
I get data but only depth attachment is black. what could be wrong here?

You haven't explained how you get "black". Via glReadPixels? Or via a sampler? When you change from 2D to 2D_ARRAY, you'll also need to change all your samplers.

debonair
04-22-2016, 10:38 AM
I am changing my sampler to sampler2DArray. I am getting it black via sampler when I read in shader. Interestingly, when I try to read data from color attachment of 2DArray which is bound to same FBO, I have all the data in place. Right now as a workaround, I am storing my depth data in color attachment.