Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

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

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...