1
votes

I want to render to a colour texture also populating the depth buffer. I then want to render something else to another texture but depth test against the depth buffer from the first render.

I'm not interested in writing out packed depth values to a colour texture, i want to keep the existing populated depth buffer from the first render. All in OpenGL ES 2.0 via LibGDX

So i have an FBO with a depth buffer.

  1. I set the single allowed COLOR_ATTACHMENT0 to texA
  2. glCheckFramebufferStatus returns complete
  3. Render with depth testing (This produces the values i expect)
  4. Change the COLOR_ATTACHMENT0 of the FBO to texB
  5. glCheckFramebufferStatus returns complete
  6. Render with depth testing (this behaves as if the depth from step 3 does not exist)

I suppose my query is really does changing a COLOR_ATTACHMENT clear the depth buffers? If not i must have a different issue somewhere in my code :(

1
The content of the depth buffer should persist in this scenario, unless you explicitly clear it, using a glClear() call that includes GL_DEPTH_BUFFER_BIT.Reto Koradi
Thanks Reto. I'll keep digging for my bug. Will let you know what i find.Bucket

1 Answers

1
votes

The issue was caused by some libgdx behaviour i was not expecting. The libgdx RenderContext was making this call "Gdx.gl.glDisable(GL20.GL_DEPTH_TEST);"

A libgdx ModelBatch creates it's self an instance of libgdx RenderContext if one is not provided. When begin is called on the ModelBatch instance begin is also called on the renderContext. But only if the batch created the context it's self. Inside the begin of the RenderContext it disables and switches off many gl functions including depth test.

The solution is to make to make an instance of RenderContext your self and pass this to your modelBatches. Then wrap both model batches in begin end calls to the render context. Remembering to re-enable the gl depth test before calling the batches.