See OES_depth_texture:
This extension defines a new texture format that stores depth values in the texture. Depth texture images are widely used for shadow casting but can also be used for other effects such as image based rendering, displacement mapping etc.
There is no direct way. You can only do it indirectly. If you want to read out a deep texture, you need to do the following steps:
Create a framebuffer the same size as the deep texture
Use a shader to read the deep texture and write it in the color attachment of the frame buffer.
Use glReadPixels
to read the color buffer.
There may be an alternative for Nvidia hardware that supports the NV_read_depth extension:
Unextended OpenGL-ES 2.0 only supports using ReadPixels to read from the default color buffer of the currently-bound framebuffer. However, it is useful for debugging to be able to read from depth and stencil buffers. This extension re-introduces these features into OpenGL-ES 2.0.
Unfortunately I did not find a corresponding OES extension.
It is not possible to read the depth buffer directly. See OpenGL ES 3.2 Specification - 16.1.2 ReadPixels
[...] an implementation-chosen format from among those defined in table 8.2, excluding formats DEPTH_COMPONENT, DEPTH_STENCIL, and
STENCIL_INDEX
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…