Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

opengl es - 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?

question from:https://stackoverflow.com/questions/65855648/oes-depth-texture-and-glreadpixels

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...