glReadPixels in Unity 5 always get black frame

I was following Kibsgaard’s suggestion in this link text thread using glReadPixels under Unity 4 I can get very high performance video capturing feature in our game.
The general idea is when game is running in openGL mode using glReadPixels in PostRender or EndOfFrame, the return buffer will contain the colors of screen pixels.

But recently after we upgrade project to Unity 5, we found this was no longer working, glReadPixels always returns black.

I tried add -force-opengl,let unity running in legacy mode.
Tried bindFrameBuffer, but all these were not working for me.

Anyone knows how to fix this in Unity 5? We really need very high performance video capturing feature. I tried renderTexture solution under unity 4 which was 3 times slower than glReadPixels solution.

Yes we have the Unity support helped us, it’s solved by moving the native GL calls(glReadPixels/glGetTexImage) to the GL.IssuePluginEvent, and it works fine.

We also have this issue on iOS and by calling glGetError() we get the message, GL_INVALID_FRAMEBUFFER_OPERATION.

It was so strange that before calling glReadPixels, we have check the frame buffer status and it’s GL_FRAMEBUFFER_COMPLETE.

GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
NSLog(@"Bind framebuffer : %x", status);
    NSLog(@"Bind framebuffer error! : %x", status);
  • Unity version : 5.4.1f1 (649f48bbbf0f)
  • iOS : 9.3.5
  • OpenGL ES : 3.0

Anyone knows how to fix it? or give us some tips to check this?


I’ve got what you mean @kdu_timeplay . Native glReadPixels function must be put in the callback of GL.IssuePluginEvent to ensure that it is called in the render thread. While in Unity 5.1 version it is not compulsory