Reputation: 651
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.
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 :(
Upvotes: 1
Views: 433
Reputation: 651
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.
Upvotes: 1