Read The Depth Buffer Of Opengl Es On Android
I am trying to read the depth buffer in OpenGL ES on Android, but all the values are zero. Can someone explain why is that. public void onSurfaceChanged(GL10 unused, int width,
Solution 1:
OpenGL ES does not support glReadPixels()
on the depth buffer. If you call glGetError()
after your glReadPixels()
call, you should see a GL_INVALID_OPERATION
returned.
I only found a vendor specific extension for this functionality: NV_read_depth_stencil. The functionality is still not standard in the latest ES spec (3.2).
Other than this extension, I can't think of any way for reading back depth values in ES 2.0.
In ES 3.0 and later, there is at least an indirect way. These versions support depth textures. Using this, you can get the depth using the following steps.
- Render the scene to an FBO, using a texture as the depth attachment.
- Render a screen sized quad with a shader that samples the depth texture generated in the previous step, and writes the value to the color buffer.
- Use
glReadPixels()
on the color buffer.
Post a Comment for "Read The Depth Buffer Of Opengl Es On Android"