Assuming that you're using retained backing for these views (otherwise glReadPixels()
doesn't work after you've presented to the screen), my guess is that you have a different OpenGL ES context for each view. glReadPixels()
will only pull from the currently active context, and thus the last view that was rendered.
Before you read from each view's context in the method above, you'll want to use code like the following:
[EAGLContext setCurrentContext:context];
where context is pulled from your OpenGL ES rendering UIView. You'll probably want to make that context a read-only property on your UIView subclass, and then change the above method to take in that subclass. You can then switch to the appropriate context before using glReadPixels()
.
As a side issue, you shouldn't be using glCheckFramebufferStatusOES()
in the above. That only really belongs in your framebuffer creation code, and serves no real purpose in your above method.