Saving the frame buffer out to a file is a very slow operation. So I am going to be assuming you don't have to do this in real time... So what you will want to do is set up two sets of shaders. One that is your normal color shader, and another that renders the depth of the object as the color. Then you will render your scene twice with both sets of shaders. From there you have two options...
- Use BGL.glReadPixels to read the screen image every frame and export them manually.
- Switchover to the standard blender renderer and render an animation with both sets of shaders.