GlReadPixels gives black image only on iOS 7 device

In the OpenGL ES application I'm working on, I noticed that the function glReadPixels()does not work on all devices / simulators. To test this, I created an OpenGL application with open-end samples. I set the background color in the context of the EAGLContext and tried to read the pixels using the glReadPixels()following way:

int bytesPerPixel = 4;
int bufferSize = _backingWidth * _backingHeight * bytesPerPixel;

void* pixelBuffer = malloc(bufferSize);
glReadPixels(0, 0, _backingWidth, _backingHeight, GL_RGBA, GL_UNSIGNED_BYTE, pixelBuffer);

// pixelBuffer should now have meaningful color/pixel data, but it null for iOS 7 devices

free(pixelBuffer);

This works as expected on the simulator for iOS 6 and 7 and the iOS 6 physical device, but it does not work on the iOS 7 physical device. The test scenarios are shown in the table below (YES / NO = works / no):

Test

I am using OpenGL ES v1.1 (although v2 also does not work after a quick test).

- ? - ? , iOS 7.

GitHub . .

UPDATE

gist, GitHub . , glReadPixels.

, : EAGLContext ([self.context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)self.layer]), glReadPixels / (iOS 6 7). , GLView.m, ([self.context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:nil]), glReadPixels , ( iOS 6 sim/device, iOS 7 sim, iOS 7).

+4
2

, , . BACKING_TYPE_LAYERBACKED, .

, FBO, . FBO [self.context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:nil]. , .

+3

Matic Oblak, , ( - ) , object picking, frameBuffer, renderBuffer, renderBuffer to frameBuffer. , bindBuffers gist

- (void)bindBuffers
{
  glBindFramebufferOES(GL_FRAMEBUFFER_OES, _framebuffer);
  glBindRenderbufferOES(GL_RENDERBUFFER_OES, _renderbuffer);
  glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, _renderbuffer);
}
0

Source: https://habr.com/ru/post/1531676/


All Articles