2

I have a problem with FBO and depth in openGL. I am passing projection, view and model matrices to a shader that writes to the g buffer. When I unbind the FBO and write to gl_FragColor the scene displays as it ought. But when I write to gl_FragData[0] then write the accompanying texture to a screen aligned quad, objects are drawn according to inverse order processed rather than depth... I can see through objects processed first to objects processed after. Has anyone had the same problem and do they know a fix? Or could someone provide syntax on reading depth values from the vertex shader, querying the current depth, then writing to the depth buffer depending on a comparison, ie, handling the operation manually in the fragment shader.

ste3e
  • 995
  • 1
  • 9
  • 18
  • 2
    Your theory all sounds correct, so more than likely, it's just a bug in your code. Without that code, we can't really say. – Nicol Bolas Oct 13 '11 at 16:58

1 Answers1

4

Your main frame-buffer most likely has the depth, while your manually created FBO might not have it. Therefore, when drawing to the screen you have depth-sorted geometry, while your FBO can not provide that and internally works with disabled depth testing having no storage associated with it.

kvark
  • 5,291
  • 2
  • 24
  • 33
  • You're right kvark. I didn't realize attaching a depth buffer to the fbo was a requirement for depth culling on fbo bound textures. Also found out that gl_FraDepth[i] is deprecated in favor of defining your own out variables. – ste3e Oct 15 '11 at 08:35
  • `gl_FragData`is deprecated, not `gl_FraDepth[]`. There is also a button in the stackoverflow interface designed for marking the right answer :) – kvark Oct 15 '11 at 13:59