PDA

View Full Version : Copy Texture to Depth Buffer?



PickleWorld
05-26-2005, 09:22 AM
If I have a depth texture that I want to use as a start point for various rendering stages is there any way for me to quickly copy the texture into the depth buffer at the start of each stage?

(ie faster than using glReadPixels followed by glDrawPixels, like a glCopyTexSubImage that works in reverse.)

Aeluned
05-26-2005, 11:13 AM
not only is there no quick way, but I believe you can't do it at all...you can't write directly to the z-buffer.

I suppose you could hack it by doing the following though:

- write a vertex program that just performs an ftransform() - you don't need lighting or anything else.

- disable writing to the color buffer (glColorMask)

- Draw a full scene quad textured with your depth texture.

- In your fragment shader set the fragment z position to the value of the lookup in the texture (set it to either the r,g or b value - they should all be the same).

after that executes, your depth buffer should contain the values in your depth texture...I think.

PickleWorld
05-26-2005, 11:49 AM
Ya I was thinking about that, just using gl_FragDepth and setting it manually.

However having to write a GLSL shader just to copy from a texture to the buffer seemed like a lot of work.

Guess I will give it a go.