0
\$\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\$
  • \$\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\$ – Trevor Powell Mar 24 '14 at 23:29
  • \$\begingroup\$ This is indeed a good argument :D I edited the question appropriately. \$\endgroup\$ – bobbel Mar 25 '14 at 19:15
2
\$\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\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.