Check out the OES_depth_texture
extension. With this you can
// generate and bind a new Framebuffer object glGenFramebuffers( ... ); glBindFramebuffer( ... ); // create a depth texture glTexImage2D(..., GL_DEPTH_COMPONENT, ...); // and attach it to the Framebuffer with glFramebufferTexture2D(..., GL_DEPTH_ATTACHMENT, ...);
Without OpenGL extensions, there is no perfect solution. You can write depth values ββto the color buffer, but there you will have limited accuracy.
This SO thread covers the same issue for WebGL that suffers from the same issue.
GLES2 covers Framebuffer and Renderbuffer objects, including extensions, in chapter 12.
umlum source share