I have an FBO in a deferred 4.3 OpenGL renderer, in which I setup the depth buffer of that FBO like this:

GLCALL(glGenRenderbuffers(1, &mDepthbuffer));
GLCALL(glBindRenderbuffer(GL_RENDERBUFFER, mDepthbuffer));
GLCALL(glRenderbufferStorageMultisample(GL_RENDERBUFFER, 0, GL_DEPTH32F_STENCIL8, windowWidth, windowHeight));
GLCALL(glBindRenderbuffer(GL_RENDERBUFFER, 0));

Normally when I debug I can output the color attachments to screen easily, like this for normals:

GLCALL(glBlitFramebuffer(0, 0, mWindowWidth, mWindowHeight, 0, 0, mWindowWidth, mWindowHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR));

But how can I do the same for the depth buffer contents, as it is not a color buffer?


1 Answer 1


First of all if you tried to do exactly that it would not work because blitting the depth / stencil buffer using GL_LINEAR is undefined. It literally lists this very situation as the first possible error on the manual page for glBlitFramebuffer (...):


glBlitFramebuffer — copy a block of pixels from the read framebuffer to the draw framebuffer



GL_INVALID_OPERATION is generated if mask contains any of the GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT and filter is not GL_NEAREST.

More importantly, however, it is generally quicker to draw a textured quad than to do a blit from a read buffer to a draw buffer. It seems almost counter-intuitive; after all, the only reason glBlitFramebuffer (...) was created was to copy data from one framebuffer to another. But if you want the best performance just stick to textured quads.

The textured quad approach will also allow you to do linear interpolation of the depth buffer, which is a limitation you cannot work around if you do a blit.

The only real reason you would ever consider using glBlitFramebuffer (...) is if you want to do MSAA resolve of a multi-sampled renderbuffer. This is the least painful way of accomplishing that particular task, particularly if you are dealing with Shader Model 4.0 (DX10) hardware, which only supports multi-sampled color textures. You can implement MSAA resolve in shaders using texelFetch (...) but unless you have Shader Model 4.1 (DX10.1) hardware you cannot use multi-sampled depth textures.

  • \$\begingroup\$ if I glBlitFramebuffer with GL_DEPTH_BUFFER_BIT, does the depth get written to the draw FBOs depth buffer or color buffer? I assume its to the depth buffer? \$\endgroup\$ Jan 5, 2014 at 13:19
  • \$\begingroup\$ @KaiserJohaan: That is correct, if you blit the framebuffer, it will copy the contents from the corresponding read buffer into the draw buffer. In this case, the depth buffer. It will not copy the depth buffer to the draw buffer, you need to use a textured quad and sample the depth texture in order to display the depth as a color. \$\endgroup\$ Jan 5, 2014 at 19:50
  • \$\begingroup\$ But is it possible to blit from the default frame buffer into the depth buffer of an FBO? and back again? I'm getting invalid enum error using glBlitFramebuffer(srcX_1, srcY_1, srcX_2, srcY_2, destX_1, destY_1, destX_2, destY_2, GL_DEPTH_BUFFER_BIT, GL_NEAREST); \$\endgroup\$
    – livin_amuk
    Oct 19, 2022 at 5:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .