3
\$\begingroup\$

I want to render my scene to a framebuffer and store the RGBA values in a texture. For this, I attach a texture to GL_COLOR_ATTACHMENT0. When I define a GL_DEPTH_ATTACHMENT texture as well, everything is rendered with the correct depth. However, if I leave out the depth attachment (because I don't need it in a later stage), wrong depth values are output, if I further use the RGBA texture (e.g. when blitting the framebuffer to another one).

Is this correct behavior, i.e. do I always need to specify a depth attachment?

edit: wrong depth values: By attaching a GL_COLOR_ATTACHMENT0, a color texture (e.g. RGBA) is output. Without a depth attachment, the colors are at the wrong "depth", in the sense that the pixels of an object behind a wall are rendered, although the corresponding pixels of the wall should be rendered instead.

Regards, bobbel

\$\endgroup\$
2
  • \$\begingroup\$ If you don't have a depth attachment, how are incorrect depth values output? There's nowhere for those depth values to be output to.. \$\endgroup\$ Commented Mar 24, 2014 at 23:29
  • \$\begingroup\$ This is indeed a good argument :D I edited the question appropriately. \$\endgroup\$
    – bobbel
    Commented Mar 25, 2014 at 19:15

1 Answer 1

4
\$\begingroup\$

You need to attach something to GL_DEPTH_ATTACHMENT if you want to render with depth testing and writing, but it doesn't have to be a texture. If you don't need to read the contents of the depth buffer in a shader (e.g. for shadow mapping), you can use a Renderbuffer object instead. Using a Renderbuffer object for the depth buffer may offer a performance benefit over using a texture.

\$\endgroup\$

You must log in to answer this question.

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