简体   繁体   中英

OES_depth_texture and glReadPixels

The open gl es 2.0 extension, OES_depth_texture , enables writing of depth information to frame buffer with an attached texture.

However, the spec not describe the usage of glReadPixels with such an extension. As far as I can tell glReadPixels will not work with such a Frame Buffer (I've tried, and get the invalid operation error).

Am I correct in this assumption? Does anyone know another reference to this issue? Or is there an alternative for reading from the attached texture to using glReadPixels?

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:

  1. Create a framebuffer the same size as the deep texture

  2. Use a shader to read the deep texture and write it in the color attachment of the frame buffer.

  3. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM