Hi, I want to pass depth buffer into shader, like a texture for example, but Iam still a bit confused about how the depth buffer(texture) with FBO works.
First of all I found these two different approaches:
glGenTextures(1, &depthTextureId);
glBindTexture(GL_TEXTURE_2D, depthTextureId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, windowWidth, windowHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0);
glGenFramebuffersEXT(1, &fboId);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,GL_TEXTURE_2D, depthTextureId, 0);
second:
glGenRenderbuffersEXT(1, &fbo_depth_renderbuffer);
// Adjust the depth renderbuffer to the right size
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fbo_depth_renderbuffer);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, windowWidth, windowHeight);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
// Attach the depth renderbuffer to framebuffer 0
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT, fbo_depth_renderbuffer)
1.) can someone explain me what is the difference ?
2.) When I bound a FBO to which the scene should be rendered to, after the scene rendering occurs I can find depth values of that rendered scene in texture associated with that FBO ? Or is there anything special that I should set up before this rendering ?