OES_depth_texture 和 glReadPixels

OES_depth_texture and glReadPixels

open gl es 2.0 扩展, OES_depth_texture,允许将深度信息写入带有附加纹理的帧缓冲区。

但是,该规范没有描述 glReadPixels 与此类扩展的用法。据我所知,glReadPixels 将无法使用这样的帧缓冲区(我已经尝试过,并收到无效操作错误)。

我这个假设正确吗?有谁知道这个问题的另一个参考?或者是否有从附加纹理读取到使用 glReadPixels 的替代方法?

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.

没有直接的方法。你只能间接地做到这一点。如果想读出有深度的纹理,需要进行以下步骤:

  1. 创建一个与深度纹理大小相同的帧缓冲区

  2. 使用着色器读取深层纹理并将其写入帧缓冲区的颜色附件中。

  3. 使用glReadPixels读取颜色缓冲区。


可能有支持 NV_read_depth 扩展的 Nvidia 硬件替代品:

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.

很遗憾,我没有找到相应的 OES 扩展名。


无法直接读取深度缓冲区。参见 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