glBlitFramebuffer vs GL_DEPTH_STENCIL_ATTACHMENT

25 Views Asked by At

I have a custom framebuffer which has a depth and stencil attachment:

glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, texId, 0);

Does the following operation blit depth and stencil or only depth ?

glBindFramebuffer(GL_READ_FRAMEBUFFER, fboId);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBlitFramebuffer(0, 0, w, h, 0, 0, w, h, GL_DEPTH_BUFFER_BIT, GL_NEAREST);

What will happen when in the above operation I replace GL_DEPTH_BUFFER_BIT with GL_STENCIL_BUFFER_BIT ?

1

There are 1 best solutions below

0
Rabbid76 On BEST ANSWER

If you call glBlitFramebuffer with GL_DEPTH_BUFFER_BIT, only the depth buffer is copied and if you call it with GL_STENCIL_BUFFER_BIT only the stencil buffer is copied. If you want to copy both buffers at once you have to set both bits:

glBlitFramebuffer(0, 0, w, h, 0, 0, w, h,
    GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST);