Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

glReadPixels doesn't read depth buffer values on iOS

I can't seem to read the depth buffer values in OpenGL ES2 on iOS 4.3

afDepthPixels = (float*)malloc(sizeof(float) * iScreenWidth * iScreenHeight);
glReadPixels(0, 0, iScreenWidth, iScreenHeight, GL_DEPTH_COMPONENT, GL_FLOAT, afDepthPixels);

My depth buffer is currently bound in place and operational, however that function reads nothing but 0 values, and it seems to return almost immediately. If I give it a GL_RGBA, it will take quite a while, and will indeed return results. Is this functionality just not supported in ES2 on iOS?

Thanks!

like image 640
Kalen Avatar asked Jul 03 '11 15:07

Kalen


1 Answers

As you guess, reading the depth buffer isn't supported in ES 2.x. Per the glReadPixels man page (direct from Khronos) the only permissible values for 'format' in ES 2 are GL_ALPHA, GL_RGBA and GL_RGB.

From memory, depth textures are supported on recent versions of iOS, so it should be possible to run a pixel shader to convert a depth buffer into something you can read as RGBA if you're otherwise at a dead end.

like image 145
Tommy Avatar answered Sep 23 '22 07:09

Tommy